mirror of
https://github.com/andrewyng/openworker.git
synced 2026-11-20 20:37:44 +00:00
fix(observability): Activity has its own address; By coworker says it lists all (T3-11)
#/activity/log and #/activity/usage, so reloading stays on Activity and its tab (main had no address for it either). With a coworker picked, a line over By coworker says it lists all coworkers, for comparison.
This commit is contained in:
@@ -64,7 +64,9 @@ import type {
|
||||
import {
|
||||
hasPendingApproval,
|
||||
initialSessionId,
|
||||
initialActivityTab,
|
||||
initialSettingsTab,
|
||||
reflectActivity,
|
||||
reflectSession,
|
||||
} from "./routes";
|
||||
import { fullPersonaName, isProjectScoped } from "./personaScope";
|
||||
@@ -384,6 +386,11 @@ export function App() {
|
||||
if (surface === "session") reflectSession(sessionId);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [sessionId, surface]);
|
||||
// T3-11: Activity has its own address too, with its tab, so a reload stays on it.
|
||||
const [activityTab, setActivityTab] = useState<"log" | "usage">(initialActivityTab || "log");
|
||||
useEffect(() => {
|
||||
if (surface === "audit") reflectActivity(activityTab);
|
||||
}, [surface, activityTab]);
|
||||
// A remembered Scheduled-detail target must not outlive the surface (see the
|
||||
// scheduledOpenId comment above): nav re-entry lands on the list, never a
|
||||
// possibly-deleted automation's dead detail.
|
||||
@@ -744,6 +751,10 @@ export function App() {
|
||||
// a #/settings/{page} link opens Settings on that page.
|
||||
if (hasPendingApproval()) openSettings("machines");
|
||||
else if (initialSettingsTab) openSettings(initialSettingsTab as SetTab);
|
||||
else if (initialActivityTab) {
|
||||
setAuditCallId(undefined);
|
||||
setSurface("audit");
|
||||
}
|
||||
setModel(h.model);
|
||||
// First-run setup wizard (desktop): show until the user completes/dismisses it.
|
||||
if (isTauri()) {
|
||||
@@ -2124,6 +2135,7 @@ export function App() {
|
||||
onOpenIntegrations={() => openSettings("connectors")}
|
||||
onOpenAudit={() => {
|
||||
setAuditCallId(undefined);
|
||||
setActivityTab("log");
|
||||
setSurface("audit");
|
||||
}}
|
||||
onOpenInbox={() => setSurface("inbox")}
|
||||
@@ -2176,7 +2188,7 @@ export function App() {
|
||||
}}
|
||||
/>
|
||||
) : surface === "audit" ? (
|
||||
<AuditView callId={auditCallId} onOpenTurn={openTurnSteps} />
|
||||
<AuditView callId={auditCallId} initialTab={activityTab} onTabChange={setActivityTab} onOpenTurn={openTurnSteps} />
|
||||
) : surface === "inbox" ? (
|
||||
<InboxView onOpenSession={openSessionFromInbox} />
|
||||
) : surface === "persona" ? (
|
||||
|
||||
@@ -14,12 +14,18 @@ const BTN_ACCENT = "text-ui px-3 py-1.5 rounded-lg bg-accent text-white shrink-0
|
||||
// `callId` (OPE-238): opened from the "changes made without asking" summary — show that one
|
||||
// tool call's rows, with the filter visible and clearable.
|
||||
// Phase 3 (OB-8): the page gains a tab bar, Log | Usage. A call filter always opens the Log.
|
||||
export function AuditView({ callId, initialTab = "log", onOpenTurn }: {
|
||||
export function AuditView({ callId, initialTab = "log", onTabChange, onOpenTurn }: {
|
||||
callId?: string;
|
||||
initialTab?: "log" | "usage";
|
||||
/** T3-11: the open tab, for the page's address */
|
||||
onTabChange?: (tab: "log" | "usage") => void;
|
||||
onOpenTurn?: (sessionId: string, turnId: string) => void;
|
||||
} = {}) {
|
||||
const [tab, setTab] = useState<"log" | "usage">(callId ? "log" : initialTab);
|
||||
useEffect(() => {
|
||||
onTabChange?.(tab);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [tab]);
|
||||
const [events, setEvents] = useState<AuditEvent[]>([]);
|
||||
const [sessionFilter, setSessionFilter] = useState("");
|
||||
const [connectorFilter, setConnectorFilter] = useState("");
|
||||
|
||||
@@ -97,6 +97,12 @@ describe("UsageBody", () => {
|
||||
expect(rows.map((r) => [r.name, r.automation, r.total])).toEqual([["Cowork", false, 800_000], ["Cowork", true, 48_910]]);
|
||||
render(<UsageBody data={data()} period="7d" t={t} />);
|
||||
expect(screen.getByTestId("usage-coworkers").textContent).toContain("(automation)");
|
||||
expect(screen.queryByTestId("usage-coworkers-all")).toBeNull();
|
||||
});
|
||||
|
||||
it("with a coworker picked, says By coworker still lists them all (T3-11)", () => {
|
||||
render(<UsageBody data={data()} period="7d" t={t} picked />);
|
||||
expect(screen.getByTestId("usage-coworkers-all").textContent).toBe("All coworkers, for comparison");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -155,13 +155,17 @@ export function UsagePage({ onOpenTurn }: { onOpenTurn?: (sessionId: string, tur
|
||||
) : !data ? (
|
||||
<div className={CARD + " p-4 text-ui text-muted"}>{t("p3.usage.loading")}</div>
|
||||
) : (
|
||||
<UsageBody data={data} period={period} t={t} onOpenTurn={onOpenTurn} />
|
||||
<UsageBody data={data} period={period} t={t} onOpenTurn={onOpenTurn} picked={!!persona} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function UsageBody({ data, period, t, onOpenTurn }: { data: UsageData; period: Period; t: T; onOpenTurn?: (sessionId: string, turnId: string) => void }) {
|
||||
export function UsageBody({ data, period, t, onOpenTurn, picked = false }: {
|
||||
data: UsageData; period: Period; t: T; onOpenTurn?: (sessionId: string, turnId: string) => void;
|
||||
/** a coworker is picked: everything narrows to it but By coworker (T3-11) */
|
||||
picked?: boolean;
|
||||
}) {
|
||||
const days = useMemo(() => localDays(period), [period]);
|
||||
const all = sumAll(data.total);
|
||||
const prev = sumAll(data.prev);
|
||||
@@ -215,6 +219,7 @@ export function UsageBody({ data, period, t, onOpenTurn }: { data: UsageData; pe
|
||||
</div>
|
||||
<div className={CARD + " p3-card"}>
|
||||
<b className="p3-h">{t("p3.usage.by_coworker")}</b>
|
||||
{picked && <div className="text-meta text-faint" data-testid="usage-coworkers-all">{t("p3.usage.by_coworker_all")}</div>}
|
||||
<table className="p3-t" data-testid="usage-coworkers">
|
||||
<thead><tr><th>{t("p3.usage.coworker")}</th><th className="n">{t("p3.usage.tokens")}</th><th className="n">{t("p3.usage.with_issues")}</th></tr></thead>
|
||||
<tbody>
|
||||
|
||||
@@ -3939,6 +3939,7 @@
|
||||
"overhead_sub": "On its own scale: the tallest day is {{tokens}} tokens.",
|
||||
"point_hint": "Point at a bar to see each part's tokens.",
|
||||
"by_coworker": "By coworker",
|
||||
"by_coworker_all": "All coworkers, for comparison",
|
||||
"coworker": "Coworker",
|
||||
"automation": "(automation)",
|
||||
"unknown_coworker": "unknown coworker",
|
||||
|
||||
@@ -3880,6 +3880,7 @@
|
||||
"overhead_sub": "单独的刻度:最高的一天为 {{tokens}} 令牌。",
|
||||
"point_hint": "指向柱形可查看每一部分的令牌数。",
|
||||
"by_coworker": "按同事",
|
||||
"by_coworker_all": "所有同事,供对比",
|
||||
"coworker": "同事",
|
||||
"automation": "(自动化)",
|
||||
"unknown_coworker": "未知同事",
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// T3-11: Activity has its own address, so a reload stays on it (and on its tab).
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
async function boot(hash: string) {
|
||||
window.history.replaceState(null, "", "/" + hash);
|
||||
vi.resetModules();
|
||||
return import("./routes");
|
||||
}
|
||||
|
||||
afterEach(() => window.history.replaceState(null, "", "/"));
|
||||
|
||||
describe("#/activity", () => {
|
||||
it("reads the tab a link asks for; a bare #/activity is the Log", async () => {
|
||||
expect((await boot("#/activity/usage")).initialActivityTab).toBe("usage");
|
||||
expect((await boot("#/activity/log")).initialActivityTab).toBe("log");
|
||||
expect((await boot("#/activity")).initialActivityTab).toBe("log");
|
||||
expect((await boot("#/settings/general")).initialActivityTab).toBe("");
|
||||
});
|
||||
|
||||
it("keeps the link until Activity shows itself, then reflects the open tab", async () => {
|
||||
const r = await boot("#/activity/usage");
|
||||
r.reflectSession("s1"); // the app's mount still says "session": must not overwrite the link
|
||||
expect(window.location.hash).toBe("#/activity/usage");
|
||||
r.reflectActivity("usage");
|
||||
expect(window.location.hash).toBe("#/activity/usage");
|
||||
r.reflectActivity("log");
|
||||
expect(window.location.hash).toBe("#/activity/log");
|
||||
// leaving Activity for a session hands the address back
|
||||
r.reflectSession("s1");
|
||||
expect(window.location.hash).toBe("#/s/s1");
|
||||
});
|
||||
|
||||
it("Settings after Activity takes the address", async () => {
|
||||
const r = await boot("");
|
||||
r.reflectActivity("usage");
|
||||
r.reflectSettings("appearance");
|
||||
expect(window.location.hash).toBe("#/settings/general");
|
||||
r.reflectActivity("usage");
|
||||
expect(window.location.hash).toBe("#/activity/usage");
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,7 @@
|
||||
// #/s/{sessionId} → land on that session (bookmark/refresh)
|
||||
// #/settings/{page}?m={id} → open that Settings page; ?m= is the machine
|
||||
// scope for machine-scoped pages (UX-046)
|
||||
// #/activity/{log|usage} → open Activity on that tab (T3-11: a reload stays there)
|
||||
|
||||
const initialHash = typeof window !== "undefined" ? window.location.hash : "";
|
||||
|
||||
@@ -53,6 +54,27 @@ export const initialSettingsTab = (() => {
|
||||
// "session" at mount) and would overwrite the link before it is read.
|
||||
let settingsLinkPending = initialSettingsTab !== "";
|
||||
|
||||
/** The Activity tab a #/activity link asks for ("" = none); a bare #/activity is the Log. */
|
||||
export const initialActivityTab: "" | "log" | "usage" = (() => {
|
||||
const m = initialHash.match(/^#\/activity(?:\/(log|usage))?/);
|
||||
if (!m) return "";
|
||||
return (m[1] as "log" | "usage" | undefined) ?? "log";
|
||||
})();
|
||||
// Same as a settings link: the session reflection at mount must not overwrite it.
|
||||
let activityLinkPending = initialActivityTab !== "";
|
||||
|
||||
/** Reflect the open Activity tab in the URL (replaceState, like Settings and sessions). */
|
||||
export function reflectActivity(tab: "log" | "usage"): void {
|
||||
if (hasPendingApproval()) return;
|
||||
activityLinkPending = false;
|
||||
settingsLinkPending = false;
|
||||
try {
|
||||
window.history.replaceState(null, "", `#/activity/${tab}`);
|
||||
} catch {
|
||||
/* file:// or restricted contexts — the URL is a convenience */
|
||||
}
|
||||
}
|
||||
|
||||
/** The ?m= machine scope, read LIVE from the current hash (not the boot one):
|
||||
* reflectSettings keeps it current, so a Settings remount re-reads the scope
|
||||
* it was already showing instead of resetting to the default. */
|
||||
@@ -71,6 +93,7 @@ export function settingsMachineParam(): string {
|
||||
export function reflectSettings(tab: string, machineId?: string | null): void {
|
||||
if (hasPendingApproval()) return;
|
||||
settingsLinkPending = false;
|
||||
activityLinkPending = false;
|
||||
const slug = SLUG_BY_TAB[tab] ?? "general";
|
||||
try {
|
||||
window.history.replaceState(
|
||||
@@ -113,7 +136,7 @@ export function hasPendingApproval(): boolean {
|
||||
/** Reflect the active session in the URL so refresh and bookmarks return
|
||||
* here. replaceState: session switching must not pile up history entries. */
|
||||
export function reflectSession(sessionId: string): void {
|
||||
if (!sessionId || hasPendingApproval() || settingsLinkPending) return;
|
||||
if (!sessionId || hasPendingApproval() || settingsLinkPending || activityLinkPending) return;
|
||||
try {
|
||||
window.history.replaceState(null, "", `#/s/${sessionId}`);
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user