From 5e919532b35b1e18dff5eeb524d5d6938a475795 Mon Sep 17 00:00:00 2001 From: Wang Tai Date: Fri, 13 Nov 2026 20:35:11 +0800 Subject: [PATCH 1/2] feat(shell): show a turn's sub-agent spend in the child panel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R6 follow-up. The sidecar has reported the children's share of a turn since R5 (`child*Tokens`, `children[]`, `unknownUsageChildren`), but nothing in the desktop UI read it. Each child row shows only THAT child's bill, so the parent's own spend appeared nowhere and "what did this turn cost, and how much of it was sub-agents" was unanswerable from the interface. - `turn_usage` SSE event, emitted at turn end just before `message_id` — the same slot and archival rule as `turn_files`, so it lands on the persisted message and hydrates after a reload. - The card now prints one line under the child board: the turn total and the sub-agents' slice with its share. Two readings are easy to get wrong and are pinned by tests: `usage.totalTokens` is the PARENT's own bill and `childTotalTokens` is the children's; they are additive, not total-and-part-of-it. The first implementation subtracted, which under-reported every turn. Writing the test against the sidecar source caught it. A turn whose children report no tokens at all (external ACP engines) still renders the line, marked `partial` — otherwise the smaller number reads as a complete bill, and a turn that delegated looks like one that didn't. Cost is deliberately not shown: `costUsd` estimates the parent's model only, and children may run on others, so presenting it as the turn's cost would understate it. Verified: web 973 passed, agent-shell ts 1646 passed; tsc clean in both. Signed-off-by: Wang Tai --- .../ts/src/local-backend/router.ts | 32 +++- .../tests/local-backend/router-stream.test.ts | 74 ++++++++ .../src/components/chat/AssistantMessage.tsx | 10 ++ .../src/components/chat/LocalChatPanel.tsx | 9 + .../web/src/components/chat/MessageList.tsx | 18 ++ .../src/components/chat/TurnProcessGroup.tsx | 11 ++ .../components/chat/TurnUsageLine.test.tsx | 90 ++++++++++ .../web/src/components/chat/TurnUsageLine.tsx | 45 +++++ .../src/components/chat/turn-usage.test.ts | 162 +++++++++++++++++ .../web/src/components/chat/turn-usage.ts | 165 ++++++++++++++++++ .../agent-shell/web/src/pages/AgentPage.tsx | 62 +++++++ 11 files changed, 675 insertions(+), 3 deletions(-) create mode 100644 packages/agent-shell/web/src/components/chat/TurnUsageLine.test.tsx create mode 100644 packages/agent-shell/web/src/components/chat/TurnUsageLine.tsx create mode 100644 packages/agent-shell/web/src/components/chat/turn-usage.test.ts create mode 100644 packages/agent-shell/web/src/components/chat/turn-usage.ts diff --git a/packages/agent-shell/ts/src/local-backend/router.ts b/packages/agent-shell/ts/src/local-backend/router.ts index 9c99a55a..efa4875a 100644 --- a/packages/agent-shell/ts/src/local-backend/router.ts +++ b/packages/agent-shell/ts/src/local-backend/router.ts @@ -21,6 +21,7 @@ import { streamCoreLoopTurn, toTurnTool, type CoreLoopToolAction, + type CoreLoopTurnOutcome, type SkillTurnContext, type StreamCoreLoopTurnOptions, type TurnFailureInfo, @@ -2739,6 +2740,9 @@ export class LocalBackendRouter { * - 同步真实 messageId:`data: {"type":"message_id","messageId":"..."}` * - 工具执行结果(无需用户确认):`data: {"type":"executed_actions","actions":[...]}` * - 回合产物文件列表(仅非空时发,在 message_id 之前):`data: {"type":"turn_files","files":[...]}` + * - 回合账单(仅有时发,在 message_id 之前):`data: {"type":"turn_usage","usage":{...}}` + * 与 `turn_files` 同批归档:前端按 message_id 把它挂到落库消息上,刷新后 + * 从 `messageMetadata.usage` 水合。整轮总计与子代理分项只在这一次出现。 * - 错误:保留 `event:error` + `data: {"message":"..."}`(前端会忽略,但日志/未来 UI 用) * - 结束:标准 SSE `[DONE]` 串。 */ @@ -4397,6 +4401,13 @@ export class LocalBackendRouter { // `turn_active` marker survives — that marker is exactly what // `detectInterruptedTurn` reads to offer "continue" on the next open. let sidecarLost = false; + // R6: the turn's bill, lifted out of `driveWithAutoContinue` so the + // assistant row and the `turn_usage` event can carry it. It holds the + // LAST pass's figures: the turn total already lives in `usage_events` + // (the router writes one row per pass) and this is the per-turn view the + // message shows — a resumed pass re-reads what the previous one left, so + // summing passes here would double-count. + let turnUsage: CoreLoopTurnOutcome['usage']; // Every pass records its own sidecar trace; all of them are persisted // against the one assistant message this turn produces. const passTraceIds: string[] = []; @@ -4707,9 +4718,10 @@ export class LocalBackendRouter { turnPasses += 1; // W6-9 用量归因:落一条 chat 用量事件(含成本估算,无单价模型 costUsd=null)。 // 每趟各落一条——续跑的花费是真实发生的,不该被合并掉。 - // R5:子代理的花费进同一条记录(父级 + children[]),而不是散成 - // 多条——一次回合的成本归因必须能一眼加总。外部引擎子代理不报 - // token,此时 usage_note='partial',不把缺失当零。 + // R5: 子代理的花费进同一条记录。注意 `usage.totalTokens` 与 + // `childTotalTokens` 是**两份并列**的账单(父级 / 子代理),不是 + // 「总计与其中一部分」,所以相加才是整轮成本。外部引擎子代理报 + // 不出 token,此时 usage_note='partial',不把缺失当零。 if (outcome.usage) { try { await this.store.recordUsageEvent({ @@ -4745,6 +4757,7 @@ export class LocalBackendRouter { outcomeTraceId = finalOutcome.traceId; autoContinuations = finalContinuations; sidecarLost = finalOutcome.sidecarLost === true; + turnUsage = finalOutcome.usage; // 干净失败的趟(sidecar 正常收流但 status=failed,如 LLM 401/超时) // 不走下面的 catch——这里补发 error 事件,否则前端只渲染一条空消息, // 用户完全看不到失败原因。 @@ -4892,6 +4905,11 @@ export class LocalBackendRouter { ...(durationMs != null ? { durationMs } : {}), ...(autoContinuations > 0 ? { autoContinuations } : {}), ...(turnFiles.length > 0 ? { turnFiles } : {}), + // R6: the turn's bill, kept on the row so a replayed message shows + // the same figures the live turn did — the child rows only carry + // their own slice, and the per-turn total is not derivable from + // them (the parent's own spend is not in any child). + ...(turnUsage ? { usage: turnUsage } : {}), ...(failureInfo ? { failure: failureInfo } : {}), }) ); @@ -5010,6 +5028,14 @@ export class LocalBackendRouter { if (turnFiles.length > 0) { emit(this.sseData({ type: 'turn_files', files: turnFiles })); } + // R6: the turn's bill, emitted just before `message_id` so it archives + // with the rest of the turn's queues. This is the only place the parent's + // own spend and the children's share appear together — the child rows + // carry only their own slice, so a host that wants "what did this turn + // cost, and how much of it was sub-agents" cannot add them up itself. + if (turnUsage) { + emit(this.sseData({ type: 'turn_usage', usage: turnUsage })); + } if (assistant) { emit(this.sseData({ type: 'message_id', messageId: assistant.id })); } diff --git a/packages/agent-shell/ts/tests/local-backend/router-stream.test.ts b/packages/agent-shell/ts/tests/local-backend/router-stream.test.ts index 3be1c0e6..8c5b95c2 100644 --- a/packages/agent-shell/ts/tests/local-backend/router-stream.test.ts +++ b/packages/agent-shell/ts/tests/local-backend/router-stream.test.ts @@ -1928,6 +1928,80 @@ describe('回合产物文件列表', () => { } }); + // ------------------------------------------------------------------------- + // R6 回合账单(turn_usage) + // ------------------------------------------------------------------------- + + it('回合账单经 turn_usage 事件下发(先于 message_id)并落 metadata', async () => { + const { dir, chat, toolRouter } = await seedProjectChat(); + try { + installStream( + (opts) => { + opts.onText('做完了'); + }, + { + status: 'completed', + usage: { + promptTokens: 4000, + completionTokens: 1000, + totalTokens: 5000, + cachedPromptTokens: 1200, + childPromptTokens: 2400, + childCompletionTokens: 600, + childTotalTokens: 3000, + unknownUsageChildren: 1, + }, + }, + ); + const cap = makeEmitCapture(); + await makeRouter({ toolRouter }).handleStream( + { method: 'POST', path: `/api/v2/chats/${chat.id}/send`, body: { message: '派活' } }, + cap.emit, + ); + + const usageEvents = cap.byType('turn_usage'); + expect(usageEvents).toHaveLength(1); + expect((usageEvents[0].data as { usage: { totalTokens: number } }).usage.totalTokens).toBe(5000); + + // 顺序约定与 turn_files 一致:先于 message_id,前端按 message_id 归档。 + const types = cap + .events() + .map((c) => (typeof c.data === 'object' && c.data !== null ? (c.data as { type?: string }).type : null)); + expect(types.indexOf('turn_usage')).toBeLessThan(types.indexOf('message_id')); + + // 落库,刷新后水合到同一条消息上。 + const assistant = (await h.store.listMessages(chat.id, 10))[0]; + const metadata = JSON.parse(assistant.messageMetadata!); + expect(metadata.usage.totalTokens).toBe(5000); + expect(metadata.usage.childTotalTokens).toBe(3000); + // 外部引擎子代理报不出 token,这个计数是「合计只是下限」的唯一依据。 + expect(metadata.usage.unknownUsageChildren).toBe(1); + } finally { + await fs.rm(dir, { recursive: true, force: true }); + } + }); + + it('回合没有账单时不发 turn_usage,metadata 不带 usage', async () => { + const { dir, chat, toolRouter } = await seedProjectChat(); + try { + installStream((opts) => { + opts.onText('没有用量的路径'); + }); + const cap = makeEmitCapture(); + await makeRouter({ toolRouter }).handleStream( + { method: 'POST', path: `/api/v2/chats/${chat.id}/send`, body: { message: '跑一下' } }, + cap.emit, + ); + + expect(cap.byType('turn_usage')).toHaveLength(0); + const assistant = (await h.store.listMessages(chat.id, 10))[0]; + const metadata = JSON.parse(assistant.messageMetadata!); + expect(metadata.usage).toBeUndefined(); + } finally { + await fs.rm(dir, { recursive: true, force: true }); + } + }); + it('未绑定项目的会话没有扫描根,不产事件', async () => { const chat = await seedChat(); installStream((opts) => opts.onText('纯聊天')); diff --git a/packages/agent-shell/web/src/components/chat/AssistantMessage.tsx b/packages/agent-shell/web/src/components/chat/AssistantMessage.tsx index 3f7eb953..3599aa05 100644 --- a/packages/agent-shell/web/src/components/chat/AssistantMessage.tsx +++ b/packages/agent-shell/web/src/components/chat/AssistantMessage.tsx @@ -29,6 +29,7 @@ import type { TurnBlock } from './turn-timeline'; import { TurnProcessGroup } from './TurnProcessGroup'; import { TurnFilesCard } from './TurnFilesCard'; import type { TurnFile } from './turn-files'; +import type { TurnUsage } from './turn-usage'; import { stripNextStepsTags } from './next-steps-tags'; import { formatTokenSpeed, @@ -151,6 +152,13 @@ interface AssistantMessageProps { * 气泡之下,点击用系统默认应用打开。空/undefined = 不渲染。 */ turnFiles?: TurnFile[]; + /** + * R6:本回合的账单(local-backend 把 sidecar 的 `stream.done.usage` 经 + * `turn_usage` SSE + messageMetadata.usage 落库)。面板据此显示「这一轮 + * 花了多少、其中子代理占多少」;父级自己的花费不在任何子代理行里, + * 所以这份数据没有替代品。 + */ + turnUsage?: TurnUsage; /** * 分享当前对话(截图复制到剪贴板)。只传给最近一条助手消息,画在时间戳 * 行上,跟复制 / 重新生成同一排。 @@ -458,6 +466,7 @@ export function AssistantMessage({ durationMs, llmSpeed, turnFiles, + turnUsage, onShare, onInspectTask, onContinueChild, @@ -555,6 +564,7 @@ export function AssistantMessage({ chatId={chatId} onInspectTask={onInspectTask} orchestrationChildren={orchestrationChildren} + turnUsage={turnUsage} onContinueChild={onContinueChild} onStopChild={onStopChild} emptyFallback={ diff --git a/packages/agent-shell/web/src/components/chat/LocalChatPanel.tsx b/packages/agent-shell/web/src/components/chat/LocalChatPanel.tsx index 14931008..c945d1f8 100644 --- a/packages/agent-shell/web/src/components/chat/LocalChatPanel.tsx +++ b/packages/agent-shell/web/src/components/chat/LocalChatPanel.tsx @@ -18,6 +18,7 @@ import type { InspectTaskInput } from './executed-actions-model'; import type { ChildInfo } from './OrchestrationChildrenCard'; import type { TurnBlock } from './turn-timeline'; import type { TurnFile } from './turn-files'; +import type { TurnUsage } from './turn-usage'; import type { RetryState } from './RetryStatus'; import type { TurnFailureCardProps } from './TurnFailureCard'; import type { LlmSpeedSnapshot } from './process-status'; @@ -117,6 +118,10 @@ export interface LocalChatPanelProps { turnFilesByMessageId?: Record; /** 当轮产物文件(流尾声到达、尚未归档到落库 id 的尾部消息用)。 */ currentTurnFiles?: TurnFile[]; + /** R6 回合账单(按落库消息 id 键控),转发给 MessageList。 */ + turnUsageByMessageId?: Record; + /** 当轮账单:与 currentTurnFiles 同款尾部回退。 */ + currentTurnUsage?: TurnUsage; /** P3.1: in-flight child agents + per-message reconciliation map. */ currentTurnChildren?: ChildInfo[]; orchestrationChildrenByMessageId?: Record; @@ -206,6 +211,8 @@ export function LocalChatPanel({ llmSpeedByMessageId, turnFilesByMessageId, currentTurnFiles, + turnUsageByMessageId, + currentTurnUsage, currentTurnChildren, orchestrationChildrenByMessageId, currentRound, @@ -526,6 +533,8 @@ export function LocalChatPanel({ llmSpeedByMessageId={llmSpeedByMessageId} turnFilesByMessageId={turnFilesByMessageId} currentTurnFiles={currentTurnFiles} + turnUsageByMessageId={turnUsageByMessageId} + currentTurnUsage={currentTurnUsage} currentTurnChildren={currentTurnChildren} orchestrationChildrenByMessageId={orchestrationChildrenByMessageId} currentRound={currentRound} diff --git a/packages/agent-shell/web/src/components/chat/MessageList.tsx b/packages/agent-shell/web/src/components/chat/MessageList.tsx index acbd01ce..a19ade24 100644 --- a/packages/agent-shell/web/src/components/chat/MessageList.tsx +++ b/packages/agent-shell/web/src/components/chat/MessageList.tsx @@ -22,6 +22,7 @@ import type { ChildInfo } from './OrchestrationChildrenCard'; import type { ChatMode } from './ChatInput'; import type { TurnBlock } from './turn-timeline'; import { followedPreviewPath, type TurnFile } from './turn-files'; +import type { TurnUsage } from './turn-usage'; import { publishConversationPreview } from '@/layouts/conversation-preview'; import { inferDurationMs, readPersistedDurationMs } from './elapsed'; import type { LlmSpeedSnapshot } from './process-status'; @@ -138,6 +139,13 @@ interface MessageListProps { * 与 currentTurnActions 同款尾部回退。 */ currentTurnFiles?: TurnFile[]; + /** + * R6: 每回合的账单,按落库消息 id 键控(与水合/归档同 turnFiles 一路)。 + * 这是唯一同时含父级与子代理的两段数字的地方——面板行内只有子代理那一份。 + */ + turnUsageByMessageId?: Record; + /** 当轮账单:与 currentTurnFiles 同款尾部回退。 */ + currentTurnUsage?: TurnUsage; /** * Tool calls accumulated for the in-flight assistant message that the * backend hasn't assigned a DB id to yet. Rendered under the latest @@ -219,6 +227,8 @@ export function MessageList({ llmSpeedByMessageId, turnFilesByMessageId, currentTurnFiles, + turnUsageByMessageId, + currentTurnUsage, currentTurnChildren, orchestrationChildrenByMessageId, currentRound, @@ -513,6 +523,13 @@ export function MessageList({ const turnFiles = persistedTurnFiles ?? (isTurnFilesTail ? currentTurnFiles : undefined); + // R6: 同 turnFiles 的尾部回退。区别是它没有「非空才算」 + // 的条件——一份全零的账单仍然说明这一轮跑过。 + const persistedTurnUsage = turnUsageByMessageId?.[message.id]; + const isTurnUsageTail = isLast && currentTurnUsage !== undefined; + const turnUsage = + persistedTurnUsage ?? (isTurnUsageTail ? currentTurnUsage : undefined); + const metadataJson = typeof message.messageMetadata === 'string' ? message.messageMetadata @@ -567,6 +584,7 @@ export function MessageList({ durationMs={durationMs} llmSpeed={llmSpeed} turnFiles={turnFiles} + turnUsage={turnUsage} onShare={message.id === lastAssistantId ? onShare : undefined} onInspectTask={onInspectTask} onContinueChild={onContinueChild} diff --git a/packages/agent-shell/web/src/components/chat/TurnProcessGroup.tsx b/packages/agent-shell/web/src/components/chat/TurnProcessGroup.tsx index f7ce6cdc..9dce86b8 100644 --- a/packages/agent-shell/web/src/components/chat/TurnProcessGroup.tsx +++ b/packages/agent-shell/web/src/components/chat/TurnProcessGroup.tsx @@ -10,6 +10,8 @@ import { ToolsFlow } from './ExecutedActionsCard'; import type { InspectTaskInput } from './executed-actions-model'; import type { ChildInfo } from './OrchestrationChildrenCard'; import { OrchestrationChildrenCard } from './OrchestrationChildrenCard'; +import { TurnUsageLine } from './TurnUsageLine'; +import type { TurnUsage } from './turn-usage'; import { estimateReasoningDurationMs, processStatusLabel, @@ -266,6 +268,7 @@ function ProcessBlocks({ thinkingElapsedByIndex, onContinueChild, onStopChild, + turnUsage, }: { blocks: TurnBlock[]; isStreaming: boolean; @@ -279,6 +282,8 @@ function ProcessBlocks({ thinkingElapsedByIndex?: Array; onContinueChild?: (childId: string, recordId: string) => void; onStopChild?: (childId: string) => void; + /** R6:本回合账单,画在子代理看板下方。 */ + turnUsage?: TurnUsage; }) { return (
@@ -302,6 +307,8 @@ function ProcessBlocks({ onContinue={onContinueChild} onStop={onStopChild} /> + {/* R6 回合账单:紧随看板,读的是「父级 + 子代理」的整份数字。 */} +
); } @@ -316,6 +323,7 @@ export function TurnProcessGroup({ orchestrationChildren, onContinueChild, onStopChild, + turnUsage, emptyFallback, streamingHint, startedAtMs, @@ -337,6 +345,8 @@ export function TurnProcessGroup({ onContinueChild?: (childId: string, recordId: string) => void; /** 「停止」一个正在跑的子代理(R7)。 */ onStopChild?: (childId: string) => void; + /** R6:本回合账单(父级 + 子代理合计),画在子代理看板下方。 */ + turnUsage?: TurnUsage; emptyFallback: ReactNode; /** Shown while streaming after a tools row and before the summary lands. */ streamingHint?: ReactNode; @@ -472,6 +482,7 @@ export function TurnProcessGroup({ thinkingElapsedByIndex={thinkingElapsedByIndex} onContinueChild={onContinueChild} onStopChild={onStopChild} + turnUsage={turnUsage} /> )} {showStreamingHint ? streamingHint : null} diff --git a/packages/agent-shell/web/src/components/chat/TurnUsageLine.test.tsx b/packages/agent-shell/web/src/components/chat/TurnUsageLine.test.tsx new file mode 100644 index 00000000..3ac11044 --- /dev/null +++ b/packages/agent-shell/web/src/components/chat/TurnUsageLine.test.tsx @@ -0,0 +1,90 @@ +/** + * R6 回合账单行:用户问「这一轮花了多少」时,能读到的必须是**整轮**, + * 而不是把子代理那几行加起来。 + * + * 三条要锁住的行为: + * - 总计永远显示(含父级); + * - 有子代理时才拆出占比,没有就不画那一段; + * - 外部引擎子代理让合计变成下限时必须明说。 + */ +import { cleanup, render, screen } from '@testing-library/react'; +import { afterEach, describe, expect, it } from 'vitest'; + +const { TurnUsageLine } = await import('./TurnUsageLine'); + +afterEach(cleanup); + +describe('TurnUsageLine', () => { + it('没有账单就不渲染', () => { + const { container } = render(); + expect(container.firstChild).toBeNull(); + }); + + it('总计为 0 时不渲染空行', () => { + const { container } = render( + , + ); + expect(container.firstChild).toBeNull(); + }); + + it('没派子代理的回合不渲染(需求只要看子代理的用量)', () => { + const { container } = render( + , + ); + expect(container.firstChild).toBeNull(); + }); + + it('有子代理时拆出总计与占比', () => { + render( + , + ); + + expect(screen.getByTestId('turn-usage').textContent).toContain('5.0k'); + expect(screen.getByTestId('turn-usage-children').textContent).toContain('1.0k'); + expect(screen.getByTestId('turn-usage-children').textContent).toContain('20%'); + }); + + it('外部引擎子代理让合计变成下限时必须标出来', () => { + render( + , + ); + + // 这一路一个 token 都没报,但子代理确实跑了——正是最需要说明的情形。 + expect(screen.getByTestId('turn-usage')).toBeTruthy(); + expect(screen.getByTestId('turn-usage-partial')).toBeTruthy(); + }); + + it('合计完整时不加「不完整」那句', () => { + render( + , + ); + + expect(screen.queryByTestId('turn-usage-partial')).toBeNull(); + }); +}); diff --git a/packages/agent-shell/web/src/components/chat/TurnUsageLine.tsx b/packages/agent-shell/web/src/components/chat/TurnUsageLine.tsx new file mode 100644 index 00000000..aa9b16d6 --- /dev/null +++ b/packages/agent-shell/web/src/components/chat/TurnUsageLine.tsx @@ -0,0 +1,45 @@ +import { t } from '@/i18n'; +import { formatTurnTokens, summarizeTurnUsage, type TurnUsage } from './turn-usage'; + +/** + * TurnUsageLine — 本回合的账单,一行。**只在这一轮派过子代理时渲染。** + * + * 为什么不无条件显示:需求要的是「看得见子代理花了多少」,而一个没派活 + * 的回合把 token 数摆到每条消息下方只是噪音。判据是「这一轮有没有子代理 + * 的花费」,包含「有子代理但报告不出 token」那种——那正是最需要说明的情形。 + * + * 为什么不显示成本:`stream.done.usage.costUsd` 只估算父级那一份(子代理 + * 按各自 profile 的模型跑,单价不同),拿它当整轮成本会偏低。宁可只报 + * token,也不报一个错的钱。 + */ +export function TurnUsageLine({ usage }: { usage?: TurnUsage }) { + if (!usage) return null; + const breakdown = summarizeTurnUsage(usage); + if (!breakdown.hasChildren) return null; + if (breakdown.totalTokens <= 0) return null; + return ( +

+ + {t('This turn {tokens} tokens', { tokens: formatTurnTokens(breakdown.totalTokens) })} + + + {t('· sub-agents {tokens} ({percent}%)', { + tokens: formatTurnTokens(breakdown.childTokens), + percent: breakdown.childSharePercent, + })} + + {breakdown.partial ? ( + // 有子代理的引擎不报 token,合计只是下限。不加这句,偏小的数字会 + // 被读成完整账单。 + + {t('· excludes sub-agents whose engine reports no tokens')} + + ) : null} +

+ ); +} + +export default TurnUsageLine; diff --git a/packages/agent-shell/web/src/components/chat/turn-usage.test.ts b/packages/agent-shell/web/src/components/chat/turn-usage.test.ts new file mode 100644 index 00000000..f81f611f --- /dev/null +++ b/packages/agent-shell/web/src/components/chat/turn-usage.test.ts @@ -0,0 +1,162 @@ +/** + * turn-usage 前端模型测试:解析 `stream.done.usage` 的形状、拆出「父级 / + * 子代理」两段,以及两种会让合计偏小的情形必须被标出来。 + * + * 最要紧的一条是 `partial`:外部引擎子代理报不出 token,合计只是下限。 + * 少了这个标记,用户会把一个偏小的数字当成完整账单——这正是用量面板当初 + * 加 `usageNote: 'partial'` 的原因,这里是同一个判断在回合级的投影。 + */ +import { describe, expect, it } from 'vitest'; + +import { formatTurnTokens, parseTurnUsage, summarizeTurnUsage } from './turn-usage'; + +describe('parseTurnUsage', () => { + it('合法账单原样解析', () => { + expect( + parseTurnUsage({ + promptTokens: 1200, + completionTokens: 300, + totalTokens: 1500, + cachedPromptTokens: 800, + costUsd: 0.02, + }), + ).toEqual({ + promptTokens: 1200, + completionTokens: 300, + totalTokens: 1500, + cachedPromptTokens: 800, + costUsd: 0.02, + }); + }); + + it('缺 token 三项就不是账单,返回 null', () => { + expect(parseTurnUsage({ promptTokens: 1, completionTokens: 1 })).toBeNull(); + expect(parseTurnUsage({})).toBeNull(); + expect(parseTurnUsage(null)).toBeNull(); + expect(parseTurnUsage('nope')).toBeNull(); + }); + + it('负数与 NaN 视为坏数据', () => { + expect( + parseTurnUsage({ promptTokens: -1, completionTokens: 0, totalTokens: 0 }), + ).toBeNull(); + }); + + it('子代理分项解析;坏掉的一项被跳过而不是整份作废', () => { + const usage = parseTurnUsage({ + promptTokens: 100, + completionTokens: 50, + totalTokens: 150, + children: [ + { childId: '0.1', promptTokens: 60, completionTokens: 20, totalTokens: 80 }, + { childId: '0.2', promptTokens: 'oops' }, + { promptTokens: 1, completionTokens: 1, totalTokens: 2 }, + ], + }); + + expect(usage?.children).toEqual([ + { childId: '0.1', promptTokens: 60, completionTokens: 20, totalTokens: 80 }, + ]); + }); + + it('空 children 与零 unknownUsageChildren 都不落键', () => { + const usage = parseTurnUsage({ + promptTokens: 10, + completionTokens: 5, + totalTokens: 15, + children: [], + unknownUsageChildren: 0, + }); + + expect(usage).not.toHaveProperty('children'); + expect(usage).not.toHaveProperty('unknownUsageChildren'); + }); +}); + +describe('summarizeTurnUsage', () => { + it('父级与子代理是两份并列账单,整轮总计相加', () => { + // sidecar 的 usage.totalTokens 是**父代理自己的**,childTotalTokens 是 + // 子代理那一部分;两者不相交。 + const breakdown = summarizeTurnUsage({ + promptTokens: 1000, + completionTokens: 200, + totalTokens: 1200, + childTotalTokens: 900, + }); + + expect(breakdown.parentTokens).toBe(1200); + expect(breakdown.childTokens).toBe(900); + expect(breakdown.totalTokens).toBe(2100); + expect(breakdown.childSharePercent).toBe(43); + expect(breakdown.hasChildren).toBe(true); + expect(breakdown.partial).toBe(false); + }); + + it('没有子代理时总计就是父级,且不渲染子代理那一段', () => { + const breakdown = summarizeTurnUsage({ + promptTokens: 500, + completionTokens: 100, + totalTokens: 600, + }); + + expect(breakdown.parentTokens).toBe(600); + expect(breakdown.childTokens).toBe(0); + expect(breakdown.totalTokens).toBe(600); + expect(breakdown.hasChildren).toBe(false); + }); + + it('只有 children[] 没有合计时按分项求和', () => { + const breakdown = summarizeTurnUsage({ + promptTokens: 300, + completionTokens: 100, + totalTokens: 400, + children: [ + { childId: '0.1', promptTokens: 100, completionTokens: 20, totalTokens: 120 }, + { childId: '0.2', promptTokens: 150, completionTokens: 30, totalTokens: 180 }, + ], + }); + + expect(breakdown.childTokens).toBe(300); + expect(breakdown.totalTokens).toBe(700); + }); + + it('总计为 0 时占比不除零', () => { + const breakdown = summarizeTurnUsage({ + promptTokens: 0, + completionTokens: 0, + totalTokens: 0, + }); + + expect(breakdown.childSharePercent).toBe(0); + expect(breakdown.totalTokens).toBe(0); + }); + + it('外部引擎子代理让合计变成下限,必须标出来', () => { + // 这一路只有 unknownUsageChildren:子代理确实花了钱,但一个数都没报。 + const breakdown = summarizeTurnUsage({ + promptTokens: 100, + completionTokens: 20, + totalTokens: 120, + unknownUsageChildren: 2, + }); + + expect(breakdown.partial).toBe(true); + // 报不出用量不等于没派活:这一行必须出现,否则用户根本不知道有子代理。 + expect(breakdown.hasChildren).toBe(true); + expect(breakdown.childTokens).toBe(0); + expect(breakdown.totalTokens).toBe(120); + }); +}); + +describe('formatTurnTokens', () => { + it('三级精简', () => { + expect(formatTurnTokens(999)).toBe('999'); + expect(formatTurnTokens(1500)).toBe('1.5k'); + expect(formatTurnTokens(2_500_000)).toBe('2.50M'); + }); + + it('坏值渲染成 0 而不是 NaN', () => { + expect(formatTurnTokens(Number.NaN)).toBe('0'); + expect(formatTurnTokens(-5)).toBe('0'); + }); +}); diff --git a/packages/agent-shell/web/src/components/chat/turn-usage.ts b/packages/agent-shell/web/src/components/chat/turn-usage.ts new file mode 100644 index 00000000..8e374c00 --- /dev/null +++ b/packages/agent-shell/web/src/components/chat/turn-usage.ts @@ -0,0 +1,165 @@ +/** + * 回合用量(「这一轮花了多少,其中子代理占多少」)的前端模型。 + * + * 数据源:local-backend 在回合收尾时把 sidecar 的 `stream.done.usage` 原样 + * 经 `turn_usage` SSE 事件下发,并持久化进助手消息的 messageMetadata(键 + * `usage`)供刷新后水合。 + * + * 为什么要在前端再算「占比」而不是后端直接给:子代理行各自只带自己那一份 + * (`orchestration_child.usage`),父代理自己的花费不在任何子代理行里, + * 所以「本回合总计 = 父级 + 子代理」这件事只有拿到整份 usage 才成立。这里 + * 只是把同一份数字拆成可展示的两段,不是重新计费。 + */ + +/** 一个子代理的账单,与 sidecar `usage.children[]` 同形。 */ +export interface TurnChildUsage { + childId: string; + profile?: string; + promptTokens: number; + completionTokens: number; + totalTokens: number; +} + +/** + * 一份回合账单。 + * + * **读法(容易读错,所以写在这里)**:`promptTokens` / `completionTokens` / + * `totalTokens` 是**父代理自己**的花费;`child*Tokens` 与 `children[]` 是 + * 子代理那一部分,二者是**并列相加**的关系,不是「总计与其中一部分」。这是 + * sidecar `stream.done.usage` 的原有语义(R5 只在 `usage` 上追加键,没有改 + * 键的含义),所以「本回合总共花了多少」= 这两者之和。 + */ +export interface TurnUsage { + promptTokens: number; + completionTokens: number; + totalTokens: number; + cachedPromptTokens?: number; + costUsd?: number; + /** 子代理合计(与上面的父级数并列,不相交)。 */ + childPromptTokens?: number; + childCompletionTokens?: number; + childTotalTokens?: number; + /** 每个子代理一项;外部引擎子代理不在其中(它们报不出 token)。 */ + children?: TurnChildUsage[]; + /** 报了「用量未知」的子代理数量(外部引擎)。这些花费不在合计里。 */ + unknownUsageChildren?: number; +} + +function readTokenCount(raw: unknown): number | undefined { + if (typeof raw !== 'number' || !Number.isFinite(raw) || raw < 0) return undefined; + return raw; +} + +function parseChildUsage(raw: unknown): TurnChildUsage | null { + if (!raw || typeof raw !== 'object') return null; + const rec = raw as Record; + if (typeof rec.childId !== 'string' || !rec.childId) return null; + const promptTokens = readTokenCount(rec.promptTokens); + const completionTokens = readTokenCount(rec.completionTokens); + const totalTokens = readTokenCount(rec.totalTokens); + if (promptTokens === undefined || completionTokens === undefined || totalTokens === undefined) { + return null; + } + return { + childId: rec.childId, + ...(typeof rec.profile === 'string' && rec.profile ? { profile: rec.profile } : {}), + promptTokens, + completionTokens, + totalTokens, + }; +} + +/** + * 解析 SSE 事件或已落库的元数据;形状不符返回 null。 + * + * 三个 token 数是硬要求——缺了它们这条记录不构成账单;其余字段缺失只影响 + * 展示细节(`cachedPromptTokens` / `costUsd` / `children[]` 都在早期版本里 + * 不存在)。与 `parseTurnFiles` 同约定:坏数据返回 null 而不是抛。 + */ +export function parseTurnUsage(raw: unknown): TurnUsage | null { + if (!raw || typeof raw !== 'object') return null; + const rec = raw as Record; + const promptTokens = readTokenCount(rec.promptTokens); + const completionTokens = readTokenCount(rec.completionTokens); + const totalTokens = readTokenCount(rec.totalTokens); + if (promptTokens === undefined || completionTokens === undefined || totalTokens === undefined) { + return null; + } + const children = Array.isArray(rec.children) + ? rec.children.map(parseChildUsage).filter((child): child is TurnChildUsage => child !== null) + : undefined; + const cachedPromptTokens = readTokenCount(rec.cachedPromptTokens); + const costUsd = readTokenCount(rec.costUsd); + const childPromptTokens = readTokenCount(rec.childPromptTokens); + const childCompletionTokens = readTokenCount(rec.childCompletionTokens); + const childTotalTokens = readTokenCount(rec.childTotalTokens); + const unknownUsageChildren = readTokenCount(rec.unknownUsageChildren); + return { + promptTokens, + completionTokens, + totalTokens, + ...(cachedPromptTokens !== undefined ? { cachedPromptTokens } : {}), + ...(costUsd !== undefined ? { costUsd } : {}), + ...(childPromptTokens !== undefined ? { childPromptTokens } : {}), + ...(childCompletionTokens !== undefined ? { childCompletionTokens } : {}), + ...(childTotalTokens !== undefined ? { childTotalTokens } : {}), + ...(children && children.length > 0 ? { children } : {}), + ...(unknownUsageChildren !== undefined && unknownUsageChildren > 0 + ? { unknownUsageChildren } + : {}), + }; +} + +export interface TurnUsageBreakdown { + /** 父代理自己的花费(`usage.totalTokens` 原值)。 */ + parentTokens: number; + /** 子代理合计。没有子代理时为 0。 */ + childTokens: number; + /** 整轮总计:父级 + 子代理。 */ + totalTokens: number; + /** 子代理占总计的百分比;总计为 0 时为 0。 */ + childSharePercent: number; + /** 有子代理确实花了 token。 */ + hasChildren: boolean; + /** + * 有一个以上子代理未报用量(外部引擎),所以合计只是下限。 + * 前端必须据此加「不完整」标记,否则偏小的合计会被读成完整账单。 + */ + partial: boolean; +} + +/** + * 把一份 usage 折成可展示的三段。 + * + * `childTotalTokens` 缺失时退化为按 `children[]` 求和——上游在只有外部引擎 + * 子代理的路径上只填 `unknownUsageChildren`,此时子代理合计确实是 0(不是 + * 「没有子代理」),`partial` 负责说明这个 0 不代表没花钱。 + */ +export function summarizeTurnUsage(usage: TurnUsage): TurnUsageBreakdown { + const summed = usage.children?.reduce((acc, child) => acc + child.totalTokens, 0); + const childTokens = usage.childTotalTokens ?? summed ?? 0; + const parentTokens = usage.totalTokens; + // 父级与子代理是两份并列的账单(见 TurnUsage 注释),整轮总计是相加。 + const totalTokens = parentTokens + childTokens; + return { + parentTokens, + childTokens, + totalTokens, + childSharePercent: totalTokens > 0 ? Math.round((childTokens / totalTokens) * 100) : 0, + // 「派过子代理」包含报了未知用量的那些:它们一个数都没给,但确实在 + // 这一轮花了钱,所以这一行必须出现,并由 `partial` 说明合计只是下限。 + hasChildren: + childTokens > 0 || + (usage.children?.length ?? 0) > 0 || + (usage.unknownUsageChildren ?? 0) > 0, + partial: (usage.unknownUsageChildren ?? 0) > 0, + }; +} + +/** 与面板行内一致的精简 token 数(1.2k / 3.40M)。 */ +export function formatTurnTokens(n: number): string { + if (!Number.isFinite(n) || n < 0) return '0'; + if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(2)}M`; + if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k`; + return String(Math.round(n)); +} diff --git a/packages/agent-shell/web/src/pages/AgentPage.tsx b/packages/agent-shell/web/src/pages/AgentPage.tsx index 50d9ad82..3fa7a0d2 100644 --- a/packages/agent-shell/web/src/pages/AgentPage.tsx +++ b/packages/agent-shell/web/src/pages/AgentPage.tsx @@ -41,6 +41,7 @@ import { type LlmSpeedSnapshot, } from "@/components/chat/process-status"; import { parseTurnFiles, type TurnFile } from "@/components/chat/turn-files"; +import { parseTurnUsage, type TurnUsage } from "@/components/chat/turn-usage"; import { readPersistedDurationMs } from "@/components/chat/elapsed"; import { extractLatestSuggestedReplies, @@ -209,6 +210,27 @@ function extractPersistedTurnFiles( return seeded; } +/** R6: 每回合的账单,从助手消息元数据水合(与 turnFiles 同法)。 */ +function extractPersistedTurnUsage( + messages: ChatMessageWithMetadata[] | undefined, +): Record { + const seeded: Record = {}; + if (!messages || messages.length === 0) return seeded; + for (const message of messages) { + if (message.role !== "assistant" || !message.messageMetadata) continue; + try { + const metadata = JSON.parse(message.messageMetadata) as { + usage?: unknown; + }; + const usage = parseTurnUsage(metadata.usage); + if (usage) seeded[message.id] = usage; + } catch { + // Ignore malformed legacy metadata. + } + } + return seeded; +} + /** * 把注册表里的子代理并进重启后的面板(R7-2)。 * @@ -312,6 +334,9 @@ function AgentChatLoader({ const [initialTurnFiles, setInitialTurnFiles] = useState< Record >({}); + const [initialTurnUsage, setInitialTurnUsage] = useState< + Record + >({}); const [initialOrchestrationChildren, setInitialOrchestrationChildren] = useState>({}); const [initialSuggestedReplies, setInitialSuggestedReplies] = @@ -350,6 +375,7 @@ function AgentChatLoader({ setInitialTimelines(extractPersistedTimelines(response.messages)); setInitialDurations(extractPersistedDurations(response.messages)); setInitialTurnFiles(extractPersistedTurnFiles(response.messages)); + setInitialTurnUsage(extractPersistedTurnUsage(response.messages)); // R7-2:落库事件只覆盖「回合跑到了收尾」的情形。进程被杀时最后一条 // assistant 消息可能没落库,那些子代理只存在于注册表里——不合并的话 // 用户重开后看到的比实际派出去的少。 @@ -387,6 +413,7 @@ function AgentChatLoader({ setInitialTimelines({}); setInitialDurations({}); setInitialTurnFiles({}); + setInitialTurnUsage({}); setInitialOrchestrationChildren({}); setInitialSuggestedReplies(null); setInitialInterrupted(false); @@ -414,6 +441,7 @@ function AgentChatLoader({ initialTimelines={initialTimelines} initialDurations={initialDurations} initialTurnFiles={initialTurnFiles} + initialTurnUsage={initialTurnUsage} initialOrchestrationChildren={initialOrchestrationChildren} initialSuggestedReplies={initialSuggestedReplies} initialInterrupted={initialInterrupted} @@ -431,6 +459,7 @@ interface AgentChatViewProps { initialTimelines: Record; initialDurations: Record; initialTurnFiles: Record; + initialTurnUsage: Record; initialOrchestrationChildren: Record; initialSuggestedReplies: SuggestedRepliesState | null; /** W7-1: 打开会话时上一轮处于中断态(崩溃/强杀,无完成记录)。 */ @@ -448,6 +477,7 @@ function AgentChatView({ initialTimelines, initialDurations, initialTurnFiles, + initialTurnUsage, initialOrchestrationChildren, initialSuggestedReplies, initialInterrupted, @@ -571,6 +601,14 @@ function AgentChatView({ // 归档后占位 id 消息仍在屏上的这段时间,都靠它渲染尾部消息的文件列表。 const [currentTurnFiles, setCurrentTurnFiles] = useState([]); const pendingTurnFilesRef = useRef([]); + // R6 同款:turn_usage 也赶在 message_id 之前到,随同一批队列归档。 + const [turnUsageByMessageId, setTurnUsageByMessageId] = useState< + Record + >(initialTurnUsage); + const [currentTurnUsage, setCurrentTurnUsage] = useState( + undefined, + ); + const pendingTurnUsageRef = useRef(undefined); const turnStartedAtRef = useRef(null); const [currentTurnStartedAtMs, setCurrentTurnStartedAtMs] = useState< number | undefined @@ -679,6 +717,16 @@ function AgentChatView({ } return; } + if (ev.event === "turn_usage") { + // R6:同 turn_files,收尾时发一次,message_id 到达时归档到落库 id。 + // 解析失败不打断回合——账单缺一块比丢一整个回合轻。 + const usage = parseTurnUsage(ev.payload?.usage); + if (usage) { + pendingTurnUsageRef.current = usage; + setCurrentTurnUsage(usage); + } + return; + } if (ev.event === "round_end") { // chat-transport surfaces `completion executing` as round_end. Bumping // the counter here is safe even if the round emits no tools — the @@ -761,6 +809,14 @@ function AgentChatView({ })); } pendingTurnFilesRef.current = []; + const queuedTurnUsage = pendingTurnUsageRef.current; + if (queuedTurnUsage) { + setTurnUsageByMessageId((prev) => ({ + ...prev, + [messageId]: queuedTurnUsage, + })); + } + pendingTurnUsageRef.current = undefined; setTailAssistantDbId(messageId); } // AI 标题更新走的是后台 IPC 广播(chat-title-updated)而不是 SSE—— @@ -992,6 +1048,8 @@ function AgentChatView({ pendingChildSpawnsRef.current = new Map(); pendingTurnFilesRef.current = []; setCurrentTurnFiles([]); + pendingTurnUsageRef.current = undefined; + setCurrentTurnUsage(undefined); setCurrentRound(1); setRetryState(null); const started = Date.now(); @@ -1165,6 +1223,8 @@ function AgentChatView({ setCurrentTurnChildren([]); pendingTurnFilesRef.current = []; setCurrentTurnFiles([]); + pendingTurnUsageRef.current = undefined; + setCurrentTurnUsage(undefined); setCurrentRound(1); setRetryState(null); const started = Date.now(); @@ -1484,6 +1544,8 @@ function AgentChatView({ llmSpeedByMessageId={llmSpeedByMessageId} turnFilesByMessageId={turnFilesByMessageId} currentTurnFiles={currentTurnFiles} + turnUsageByMessageId={turnUsageByMessageId} + currentTurnUsage={currentTurnUsage} currentTurnChildren={effectiveCurrentTurnChildren} orchestrationChildrenByMessageId={orchestrationChildrenByMessageId} currentRound={currentRound} From 23f33a679a8a8204f79f64087ebaa980af9d4f80 Mon Sep 17 00:00:00 2001 From: Wang Tai Date: Fri, 13 Nov 2026 20:35:22 +0800 Subject: [PATCH 2/2] chore(release): v0.12.0 Signed-off-by: Wang Tai --- package.json | 2 +- packages/agent-cli/ts/package.json | 2 +- packages/agent-client/ts/package.json | 2 +- packages/agent-harness/py/pyproject.toml | 2 +- packages/agent-harness/ts/package.json | 2 +- packages/agent-protocol/py/pyproject.toml | 2 +- packages/agent-protocol/ts/package.json | 2 +- packages/agent-runtime/py/pyproject.toml | 2 +- packages/agent-runtime/ts/package.json | 2 +- packages/agent-shell/tauri/package.json | 2 +- packages/agent-shell/ts/package.json | 2 +- packages/agent-shell/web/package.json | 2 +- packages/agent-ui/ts/package.json | 2 +- packages/pack-sdk/ts/package.json | 2 +- packages/plugin-sdk/py/pyproject.toml | 2 +- packages/sidecar/py/pyproject.toml | 2 +- uv.lock | 10 +++++----- 17 files changed, 21 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 2e299ae5..23b8a57e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/monorepo", - "version": "0.11.1", + "version": "0.12.0", "private": true, "type": "module", "packageManager": "pnpm@10.23.0", diff --git a/packages/agent-cli/ts/package.json b/packages/agent-cli/ts/package.json index 31164187..c3ea5d15 100644 --- a/packages/agent-cli/ts/package.json +++ b/packages/agent-cli/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-cli", - "version": "0.11.1", + "version": "0.12.0", "description": "Product-neutral command line for a Steerable host. Products supply the bin name and brand.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-client/ts/package.json b/packages/agent-client/ts/package.json index bc42e53b..3dcc7de4 100644 --- a/packages/agent-client/ts/package.json +++ b/packages/agent-client/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-client", - "version": "0.11.1", + "version": "0.12.0", "description": "In-process client for a Steerable host: HTTP-shaped requests, turn streams, and approval replies.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-harness/py/pyproject.toml b/packages/agent-harness/py/pyproject.toml index a26a69b0..dea0756d 100644 --- a/packages/agent-harness/py/pyproject.toml +++ b/packages/agent-harness/py/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "steerable-agent-harness" -version = "0.11.1" +version = "0.12.0" description = "Steerable harness helpers for Python" license = { text = "Apache-2.0" } readme = "README.md" diff --git a/packages/agent-harness/ts/package.json b/packages/agent-harness/ts/package.json index 36bc3938..92c28703 100644 --- a/packages/agent-harness/ts/package.json +++ b/packages/agent-harness/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-harness", - "version": "0.11.1", + "version": "0.12.0", "description": "Steerable framework Tier 2 \u2014 TypeScript facade over the Python harness (policy, budget, retry, completion, tracing) used for cross-language conformance tests. Production code should depend on the Python harness.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-protocol/py/pyproject.toml b/packages/agent-protocol/py/pyproject.toml index 0abd93ad..591e9b7d 100644 --- a/packages/agent-protocol/py/pyproject.toml +++ b/packages/agent-protocol/py/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "steerable-agent-protocol" -version = "0.11.1" +version = "0.12.0" description = "Steerable protocol schemas for Python" license = { text = "Apache-2.0" } readme = "README.md" diff --git a/packages/agent-protocol/ts/package.json b/packages/agent-protocol/ts/package.json index e61601f6..774c0fac 100644 --- a/packages/agent-protocol/ts/package.json +++ b/packages/agent-protocol/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-protocol", - "version": "0.11.1", + "version": "0.12.0", "description": "Steerable framework Tier 1 \u2014 wire-format types (SSEEvent, ChatMessage, ToolCall, ToolResult, AgentSession, HarnessTrace, sidecar JSON-RPC) shared by every Steerable client and server.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-runtime/py/pyproject.toml b/packages/agent-runtime/py/pyproject.toml index 38023c36..9751b591 100644 --- a/packages/agent-runtime/py/pyproject.toml +++ b/packages/agent-runtime/py/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "steerable-agent-runtime" -version = "0.11.1" +version = "0.12.0" description = "Steerable agent runtime: LLM, tool, storage, and transport adapters." license = { text = "Apache-2.0" } readme = "README.md" diff --git a/packages/agent-runtime/ts/package.json b/packages/agent-runtime/ts/package.json index 04ef639a..51cb5a8a 100644 --- a/packages/agent-runtime/ts/package.json +++ b/packages/agent-runtime/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-runtime", - "version": "0.11.1", + "version": "0.12.0", "description": "Steerable framework \u2014 official TypeScript production runtime. Owns the embedded Python sidecar lifecycle (spawn / ready handshake / health / bounded auto-restart / graceful drain) and exposes the CoreLoop-level API over the sidecar JSON-RPC surface. There is no TS CoreLoop; this package drives the same Rust CoreLoop the server uses (via the Python sidecar facade), so cross-language conformance holds by construction.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-shell/tauri/package.json b/packages/agent-shell/tauri/package.json index ebaff95e..4bdea9c6 100644 --- a/packages/agent-shell/tauri/package.json +++ b/packages/agent-shell/tauri/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-shell-tauri", - "version": "0.11.1", + "version": "0.12.0", "description": "Reusable Tauri Rust host source for @steerable/agent-shell", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-shell/ts/package.json b/packages/agent-shell/ts/package.json index 7a0c9fc2..e9814328 100644 --- a/packages/agent-shell/ts/package.json +++ b/packages/agent-shell/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-shell", - "version": "0.11.1", + "version": "0.12.0", "description": "Steerable framework \u2014 product-neutral Node HostRuntime and headless HTTP server shared by Tauri desktop and browser deployments; scenario packs extend it through @steerable/pack-sdk.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-shell/web/package.json b/packages/agent-shell/web/package.json index ebbd08a2..6248a923 100644 --- a/packages/agent-shell/web/package.json +++ b/packages/agent-shell/web/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-shell-web", - "version": "0.11.1", + "version": "0.12.0", "type": "module", "description": "Steerable framework \u2014 product-neutral renderer SPA source for @steerable/agent-shell (React + Vite). Consumed by product web entry points via the `@/` alias (anchored at this package's src/) and the createProductViteConfig factory. Published as a source package (src/), plus the compiled vite.base config factory (vite.base.js + .d.ts) for Node-side config loading.", "license": "Apache-2.0", diff --git a/packages/agent-ui/ts/package.json b/packages/agent-ui/ts/package.json index ac0fd82b..af8409db 100644 --- a/packages/agent-ui/ts/package.json +++ b/packages/agent-ui/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-ui", - "version": "0.11.1", + "version": "0.12.0", "description": "Steerable framework Tier 4 \u2014 headless React hooks (useAgentSession, useChatStream, useToolCallStatus) and Tailwind-themed components (ChatPanel, MessageList, OrchestrationPlanCard, ToolCallRenderer, SSEStreamView) for embedding Steerable agents in any React app.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/storybook/", diff --git a/packages/pack-sdk/ts/package.json b/packages/pack-sdk/ts/package.json index 73e0620a..0fe5970c 100644 --- a/packages/pack-sdk/ts/package.json +++ b/packages/pack-sdk/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/pack-sdk", - "version": "0.11.1", + "version": "0.12.0", "type": "module", "description": "Scenario pack contract for @steerable/agent-shell (pure types, zero runtime). A scenario pack declares every extension a vertical scenario needs \u2014 services, tools, tables, skills, agent seeds, HTTP routes, renderer slots, branding \u2014 and the host composes the selected packs at build time.", "license": "Apache-2.0", diff --git a/packages/plugin-sdk/py/pyproject.toml b/packages/plugin-sdk/py/pyproject.toml index b177d41e..9d801b8d 100644 --- a/packages/plugin-sdk/py/pyproject.toml +++ b/packages/plugin-sdk/py/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "steerable-plugin-sdk" -version = "0.11.1" +version = "0.12.0" description = "Pure-Python authoring and RPC SDK for Steerable tool plugins" license = { text = "Apache-2.0" } readme = "README.md" diff --git a/packages/sidecar/py/pyproject.toml b/packages/sidecar/py/pyproject.toml index faf19d6d..b1b734f2 100644 --- a/packages/sidecar/py/pyproject.toml +++ b/packages/sidecar/py/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "steerable-sidecar" -version = "0.11.1" +version = "0.12.0" description = "Steerable agent runtime sidecar — JSON-RPC over stdio." license = { text = "Apache-2.0" } readme = "README.md" diff --git a/uv.lock b/uv.lock index 69ddcd8c..e1b650fc 100644 --- a/uv.lock +++ b/uv.lock @@ -1714,7 +1714,7 @@ wheels = [ [[package]] name = "steerable-agent-harness" -version = "0.11.1" +version = "0.12.0" source = { editable = "packages/agent-harness/py" } dependencies = [ { name = "pydantic" }, @@ -1729,7 +1729,7 @@ requires-dist = [ [[package]] name = "steerable-agent-protocol" -version = "0.11.1" +version = "0.12.0" source = { editable = "packages/agent-protocol/py" } dependencies = [ { name = "pydantic" }, @@ -1740,7 +1740,7 @@ requires-dist = [{ name = "pydantic", specifier = ">=2.10.0" }] [[package]] name = "steerable-agent-runtime" -version = "0.11.1" +version = "0.12.0" source = { editable = "packages/agent-runtime/py" } dependencies = [ { name = "httpx", extra = ["socks"] }, @@ -1869,7 +1869,7 @@ dev = [ [[package]] name = "steerable-plugin-sdk" -version = "0.11.1" +version = "0.12.0" source = { editable = "packages/plugin-sdk/py" } dependencies = [ { name = "steerable-agent-harness" }, @@ -1884,7 +1884,7 @@ requires-dist = [ [[package]] name = "steerable-sidecar" -version = "0.11.1" +version = "0.12.0" source = { editable = "packages/sidecar/py" } dependencies = [ { name = "ag-ui-protocol" },