A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(editor): say how long the turn took, while it is taking it
esengine2e8d73c14269
diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex dd30289bc..ef0e17e5b 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -220,6 +220,20 @@ function Skeleton() {);}+/** Ticks while the turn runs, then freezes at what it took. A turn that takes+ * two minutes should say so as it happens, not only afterwards. */+function Elapsed({ turn }: { turn: AgentTurn }) {+ const [now, setNow] = useState(() => Date.now());+ const live = turn.endedAt === null;+ useEffect(() => {+ if (!live) return;+ const id = setInterval(() => setNow(Date.now()), 100);+ return () => clearInterval(id);+ }, [live]);+ const ms = (turn.endedAt ?? now) - turn.startedAt;+ return <span className={live ? 'ag-live' : undefined}>{formatElapsed(ms)}</span>;+}+function Turn({ turn, isLast, running }: { turn: AgentTurn; isLast: boolean; running: boolean }) {// Past runs arrive folded; the one you are in stays open. Local state so the// user's own fold survives the next event landing in the store.@@ -238,6 +252,7 @@ function Turn({ turn, isLast, running }: { turn: AgentTurn; isLast: boolean; run<span className="ag-req">{turn.prompt}</span></span><span className="ag-stat">+ <Elapsed turn={turn} />{tokens > 0 && <span>↑{compact(turn.inputTokens)} ↓{compact(turn.outputTokens)}</span>}<span className="ag-sp" />{turn.reason === 'aborted' && <span className="ag-warn">{t('agent.turn.aborted')}</span>}@@ -538,6 +553,15 @@ export function AgentDrawer() {);}+/** Seconds under a minute, m:ss above — a long turn read as "184.2s" is a number+ * you have to divide before it means anything. */+function formatElapsed(ms: number): string {+ const s = ms / 1000;+ if (s < 60) return `${s.toFixed(1)}s`;+ const m = Math.floor(s / 60);+ return `${m}m${String(Math.floor(s % 60)).padStart(2, '0')}s`;+}+const compact = (n: number): string => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n));/** One line of the call's arguments — enough to tell two calls apart. */diff --git a/desktop/src/store/AgentStore.ts b/desktop/src/store/AgentStore.tsindex 16c6cc5d9..5ededdb4e 100644--- a/desktop/src/store/AgentStore.ts+++ b/desktop/src/store/AgentStore.ts@@ -82,6 +82,10 @@ export interface AgentTurn {mark: unknown | null;/** null while the turn is still running. */reason: TurnReason | null;+ /** Wall clock, stamped here rather than in main: it is what the person waited,+ * and the person is on this side of the IPC. */+ startedAt: number;+ endedAt: number | null;}const IDLE: AgentStatus = {@@ -245,6 +249,8 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):steps: 0,mark: null,reason: null,+ startedAt: Date.now(),+ endedAt: null,}];}@@ -303,6 +309,7 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):reason: event.reason,steps: event.steps,mark: event.mark,+ endedAt: Date.now(),// Nothing will report on these now. Neither failed nor succeeded.entries: open.entries.map((e) =>(e.kind === 'tool' && !TERMINAL.has(e.state) ? { ...e, state: 'stopped' as const } : e)),diff --git a/desktop/src/theme/agent.css b/desktop/src/theme/agent.cssindex 226112652..1f1630f07 100644--- a/desktop/src/theme/agent.css+++ b/desktop/src/theme/agent.css@@ -564,3 +564,5 @@border: 1px solid var(--line);background: var(--inset);}+/* The one number still moving. */+.ag-stat .ag-live { color: var(--text); }diff --git a/desktop/tests/agent-transcript.test.ts b/desktop/tests/agent-transcript.test.tsindex fd847f920..5e02a7c50 100644--- a/desktop/tests/agent-transcript.test.ts+++ b/desktop/tests/agent-transcript.test.ts@@ -126,6 +126,15 @@ describe('the transcript projection', () => {expect(turn).toMatchObject({ inputTokens: 2600, outputTokens: 110 });});+ // Stamped on this side of the IPC because it is what the PERSON waited.+ it('stamps when the run started and when it stopped', () => {+ const [running] = fold(started());+ expect(running.startedAt).toBeGreaterThan(0);+ expect(running.endedAt).toBeNull();+ const [done] = fold(started(), ended());+ expect(done.endedAt).toBeGreaterThanOrEqual(done.startedAt);+ });+it('records what one Undo would take back, and where to', () => {const [turn] = fold(started(), ended({ steps: 7, mark: { seq: 12 } }));expect(turn).toMatchObject({ steps: 7, mark: { seq: 12 }, reason: 'end_turn' });@@ -173,7 +182,8 @@ describe('which entities a turn touched', () => {state: 'ok', summary: 'ok', image: null, reason: null, ...over,});const turn = (entries: AgentToolEntry[], id = 0): AgentTurn => ({- id, prompt: 'p', entries, inputTokens: 0, outputTokens: 0, steps: 1, mark: { seq: 1 }, reason: 'end_turn',+ id, prompt: 'p', entries, inputTokens: 0, outputTokens: 0, steps: 1, mark: { seq: 1 },+ reason: 'end_turn', startedAt: 0, endedAt: 1,});it('reads the ids out of the argument names the catalog uses', () => {