03f1673fce
- Workspace, SettingsHub, SessionDetail and the Workflow sub-tab are lazy (main bundle 2,166 kB -> ~920 kB), wrapped in RouteErrorBoundary: a stale chunk after a self-update reloads once (vite:preloadError too), any other error shows a Reload panel instead of a blank page. - Live refresh: lib/throttle.ts + hooks/useLiveRefresh.ts replace trailing debounces that froze under a steady event stream; refresh skips hidden tabs and refetches after a WebSocket reconnect. Monitor loads only while shown, with one batched GET /api/agents?session_ids= instead of N+1; a failing endpoint is an inline error, not a blank Dashboard. - NeedsYouStrip on Monitor and above Analytics. Tabs, filters, page, sort and search live in the URL (Dashboard, Sessions, Activity, SessionDetail). - Sessions: tool / workspace / date-range filters, CSV/JSON export (formula-neutralised), focusable row links, Open in workspace (the dead /run links are gone), stale responses dropped, error + Retry. - Fixes: "NaNs" durations, 30/7-day charts skipping idle days, weekday labels west of UTC (now averages), cache hit rate denominator, billable tokens vs cache reads, exact tool-call counts, "To" date = end of day, invalid ?from= no longer throws, recent list no longer shrinks to 15, stable message keys, transcript switch races. - Light-theme-unreadable bg-black code panels and dark-only DAG fills use tokens; status configs and chart colours use theme tokens; Health tab and other literals translated. - Server (additive): GET /api/agents?session_ids=, GET /api/sessions awaiting=1&from=&to=, stats tool_call_count/distinct_tool_count, event rows carry session/agent labels.
99 lines
3.7 KiB
TypeScript
99 lines
3.7 KiB
TypeScript
/**
|
|
* @file NeedsYouStrip.tsx
|
|
* @description The Dashboard's pinned "Needs you" strip: every active session
|
|
* blocked on the user (`awaiting_input_since`), each linking straight to its
|
|
* workspace pane (or replay), else its analysis page. Renders nothing while no
|
|
* session is waiting. `compact` is the one-line form shown above Analytics.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
import { useCallback, useEffect, useState } from "react";
|
|
import { Link } from "react-router-dom";
|
|
import { useTranslation } from "react-i18next";
|
|
import { BellRing } from "lucide-react";
|
|
import { api, type RunHandle } from "../lib/api";
|
|
import { timeAgo } from "../lib/format";
|
|
import { useLiveRefresh } from "../hooks/useLiveRefresh";
|
|
import { workspaceHref } from "./SessionRowMenu";
|
|
import type { Session } from "../lib/types";
|
|
|
|
export function NeedsYouStrip({ compact = false }: { compact?: boolean }) {
|
|
const { t } = useTranslation("dashboard");
|
|
const [sessions, setSessions] = useState<Session[]>([]);
|
|
// The real count: only the first 20 are fetched and listed.
|
|
const [total, setTotal] = useState(0);
|
|
const [runs, setRuns] = useState<RunHandle[]>([]);
|
|
|
|
const load = useCallback(() => {
|
|
api.sessions
|
|
.list({ awaiting: true, limit: 20 })
|
|
.then((r) => {
|
|
setSessions(r.sessions);
|
|
setTotal(r.total);
|
|
})
|
|
.catch(() => undefined); // the strip is a shortcut; the pages show errors
|
|
api.run
|
|
.list()
|
|
.then((r) => setRuns(r.items))
|
|
.catch(() => undefined);
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
load();
|
|
}, [load]);
|
|
useLiveRefresh(load, {
|
|
intervalMs: 15000,
|
|
match: (msg) => msg.type === "session_updated" || msg.type === "session_created",
|
|
});
|
|
|
|
if (sessions.length === 0) return null;
|
|
|
|
return (
|
|
<section
|
|
aria-label={t("needsYou.title")}
|
|
className={`card border-status-warning/40 ${compact ? "px-3 py-2" : "p-4"}`}
|
|
>
|
|
<div className={`flex flex-wrap items-center gap-2 ${compact ? "" : "mb-3"}`}>
|
|
<BellRing className="w-4 h-4 text-status-warning flex-shrink-0" aria-hidden />
|
|
<h2 className="text-sm font-medium text-fg-primary">
|
|
{t("needsYou.title")}{" "}
|
|
<span className="text-fg-muted font-normal">({Math.max(total, sessions.length)})</span>
|
|
</h2>
|
|
{compact &&
|
|
sessions.slice(0, 5).map((s) => (
|
|
<Link
|
|
key={s.id}
|
|
to={workspaceHref(s, runs) ?? `/sessions/${s.id}`}
|
|
className="text-xs px-2 py-0.5 rounded-full bg-status-warning/10 border border-status-warning/30 text-fg-secondary hover:text-fg-primary truncate max-w-[14rem]"
|
|
>
|
|
{s.name || s.id.slice(0, 8)}
|
|
</Link>
|
|
))}
|
|
</div>
|
|
{!compact && (
|
|
<ul className="divide-y divide-border">
|
|
{sessions.map((s) => (
|
|
<li key={s.id}>
|
|
<Link
|
|
to={workspaceHref(s, runs) ?? `/sessions/${s.id}`}
|
|
className="flex items-center gap-3 py-2 px-1 hover:bg-surface-4 rounded"
|
|
>
|
|
<span className="w-2 h-2 rounded-full bg-status-warning flex-shrink-0" />
|
|
<span className="text-sm text-fg-secondary truncate flex-1">
|
|
{s.name || s.id.slice(0, 8)}
|
|
</span>
|
|
<span className="text-[11px] text-fg-muted truncate max-w-[16rem]">{s.cwd}</span>
|
|
{s.awaiting_input_since && (
|
|
<span className="text-[11px] text-fg-muted flex-shrink-0">
|
|
{t("needsYou.since", { ago: timeAgo(s.awaiting_input_since) })}
|
|
</span>
|
|
)}
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</section>
|
|
);
|
|
}
|