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): show a call's arguments being written
esenginef8a1c4f970c3
diff --git a/desktop/electron/agent/anthropic.ts b/desktop/electron/agent/anthropic.tsindex 8ea1e4d4a..d6d25cfd1 100644--- a/desktop/electron/agent/anthropic.ts+++ b/desktop/electron/agent/anthropic.ts@@ -231,10 +231,28 @@ class AnthropicSession implements AgentSession {? this.client.beta.messages.stream(request as never, { signal }): this.client.messages.stream(request as never, { signal });+ // Block index → tool id: argument deltas identify their block by index, and+ // only the block's start carries the id the rest of the system speaks in.+ const toolAt = new Map<number, string>();+for await (const event of stream) {+ if (event.type === 'content_block_start') {+ const block = event.content_block;+ if (block.type === 'tool_use') {+ toolAt.set(event.index, block.id);+ // The row exists from the moment the model commits to the call, so+ // arguments are watched being written instead of appearing whole.+ yield { type: 'tool_call', call: { id: block.id, name: block.name, input: {} } };+ }+ continue;+ }if (event.type !== 'content_block_delta') continue;if (event.delta.type === 'text_delta') yield { type: 'text', delta: event.delta.text };else if (event.delta.type === 'thinking_delta') yield { type: 'thinking', delta: event.delta.thinking };+ else if (event.delta.type === 'input_json_delta') {+ const id = toolAt.get(event.index);+ if (id) yield { type: 'tool_args', id, delta: event.delta.partial_json };+ }}const message = await stream.finalMessage();@@ -249,6 +267,9 @@ class AnthropicSession implements AgentSession {};}+ // Again, now with the PARSED arguments — the streamed deltas are display+ // text, and the kernel needs a real object to dispatch. The editor treats a+ // second call for a known id as an update, not a second row.for (const block of message.content) {if (block.type !== 'tool_use') continue;yield {diff --git a/desktop/electron/agent/types.ts b/desktop/electron/agent/types.tsindex 9bc6d1ede..2fb1f85e8 100644--- a/desktop/electron/agent/types.ts+++ b/desktop/electron/agent/types.ts@@ -51,6 +51,10 @@ export type StepEvent =| { type: 'text'; delta: string }| { type: 'thinking'; delta: string }| { type: 'tool_call'; call: ToolCall }+ /** The model is still WRITING a call's arguments. Emitted before the call is+ * complete, so the editor can show it being composed rather than appearing+ * finished out of a silence. */+ | { type: 'tool_args'; id: string; delta: string }/** Why the model stopped. `refusal` is a provider-level decline, not an error. */| { type: 'stop'; reason: 'end_turn' | 'tool_use' | 'refusal' | 'max_tokens' }| { type: 'usage'; inputTokens: number; outputTokens: number };diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex ef0e17e5b..dbc68b584 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -52,7 +52,11 @@ const TOOL_ICON: Record<string, typeof Eye> = {function ToolRow({ entry, onConfirm }: { entry: AgentToolEntry; onConfirm: (allow: boolean) => void }) {const [open, setOpen] = useState(false);const Icon = TOOL_ICON[entry.effect ?? 'read'] ?? Eye;- const arg = summarizeInput(entry.input);+ // While the model is writing them, show the raw text arriving; once the call+ // is complete, the tidied summary. The switch is the point at which there is+ // something better to show, not a timer.+ const composing = entry.state === 'queued' && entry.argText !== '' && !hasInput(entry.input);+ const arg = composing ? entry.argText : summarizeInput(entry.input);const touches = entitiesInInput(entry.input);return (<>@@ -64,7 +68,7 @@ function ToolRow({ entry, onConfirm }: { entry: AgentToolEntry; onConfirm: (allo<button type="button" className="ag-call-top" onClick={() => setOpen((o) => !o)}><span className="ag-call-g"><Icon size={13} strokeWidth={1.8} /></span><span className="ag-call-nm">{entry.name}</span>- <span className="ag-call-arg">{arg}</span>+ <span className="ag-call-arg">{arg}{composing && <span className="ag-arg-caret" />}</span><span className="ag-call-out">{entry.state === 'queued' && t('agent.queued')}{entry.state === 'running' && <Loader size={11} className="ag-spin" />}@@ -562,6 +566,8 @@ function formatElapsed(ms: number): string {return `${m}m${String(Math.floor(s % 60)).padStart(2, '0')}s`;}+const hasInput = (input: Record<string, unknown>): boolean => Object.keys(input).length > 0;+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 5ededdb4e..34b472df4 100644--- a/desktop/src/store/AgentStore.ts+++ b/desktop/src/store/AgentStore.ts@@ -51,6 +51,9 @@ export interface AgentToolEntry {summary: string | null;/** A frame the call rendered — the transcript shows what the agent looked at. */image: string | null;+ /** The arguments as the model is WRITING them: raw JSON text, incomplete+ * until it stops. Display only — the kernel dispatches the parsed object. */+ argText: string;/** Why it needs saying out loud, while it is awaiting an answer. */reason: ConfirmReason | null;}@@ -262,7 +265,14 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):case 'thinking':return withEntries(turns, appendProse(open.entries, event.type, event.delta));- case 'tool_call':+ // Twice per call: once when the model commits to it (no arguments yet), and+ // again with the parsed ones. The second is an UPDATE — a second row for the+ // same call would double every tool the model uses.+ case 'tool_call': {+ const known = open.entries.some((e) => e.kind === 'tool' && e.id === event.call.id);+ if (known) {+ return withEntries(turns, patchTool(open.entries, event.call.id, { input: event.call.input }));+ }return withEntries(turns, [...open.entries, {kind: 'tool',id: event.call.id,@@ -272,8 +282,14 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):state: 'queued',summary: null,image: null,+ argText: '',reason: null,}]);+ }++ case 'tool_args':+ return withEntries(turns, open.entries.map((e) =>+ (e.kind === 'tool' && e.id === event.id ? { ...e, argText: e.argText + event.delta } : e)));case 'tool_start':return withEntries(turns, patchTool(open.entries, event.call.id, {diff --git a/desktop/src/theme/agent.css b/desktop/src/theme/agent.cssindex 1f1630f07..b5a6ca6a5 100644--- a/desktop/src/theme/agent.css+++ b/desktop/src/theme/agent.css@@ -566,3 +566,12 @@}/* The one number still moving. */.ag-stat .ag-live { color: var(--text); }+/* Arguments being written. Narrower than the prose caret — it rides a mono line. */+.ag-arg-caret {+ display: inline-block;+ width: 4px; height: 9px;+ margin-left: 1px;+ vertical-align: -1px;+ background: var(--text-dim);+ animation: ag-blink 1s steps(2) infinite;+}diff --git a/desktop/tests/agent-transcript.test.ts b/desktop/tests/agent-transcript.test.tsindex 5e02a7c50..b0244e964 100644--- a/desktop/tests/agent-transcript.test.ts+++ b/desktop/tests/agent-transcript.test.ts@@ -71,6 +71,21 @@ describe('the transcript projection', () => {expect(tools(turn)[0].image).toBe('data:image/png;base64,AAA');});+ // The provider announces the call when the model commits to it, then again+ // with the parsed arguments. Two rows for one call would double every tool.+ it('treats the second announcement of a call as an update, not a new row', () => {+ const turns = fold(+ started(),+ { type: 'tool_call', call: { id: 'c1', name: 'set_field', input: {} } },+ { type: 'tool_args', id: 'c1', delta: '{"entity"' },+ { type: 'tool_args', id: 'c1', delta: ':7}' },+ { type: 'tool_call', call: { id: 'c1', name: 'set_field', input: { entity: 7 } } },+ );+ expect(tools(turns[0])).toHaveLength(1);+ expect(tools(turns[0])[0].argText).toBe('{"entity":7}');+ expect(tools(turns[0])[0].input).toEqual({ entity: 7 });+ });+it('carries a call through to its result', () => {const [turn] = fold(started(),@@ -179,7 +194,7 @@ describe('the transcript projection', () => {describe('which entities a turn touched', () => {const toolEntry = (over: Partial<AgentToolEntry>): AgentToolEntry => ({kind: 'tool', id: 'c1', name: 'set_field', input: {}, effect: 'undoable',- state: 'ok', summary: 'ok', image: null, reason: null, ...over,+ state: 'ok', summary: 'ok', image: null, argText: '', reason: null, ...over,});const turn = (entries: AgentToolEntry[], id = 0): AgentTurn => ({id, prompt: 'p', entries, inputTokens: 0, outputTokens: 0, steps: 1, mark: { seq: 1 },