The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(usage): distinguish unknown costs from zero
Steven Enamakelf391262be5d7
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsxindex a80956bde5..6277e517e8 100644--- a/app/src/features/conversations/Conversations.tsx+++ b/app/src/features/conversations/Conversations.tsx@@ -823,6 +823,7 @@ const Conversations = ({outputTokens: u.outputTokens,cachedTokens: u.cachedInputTokens,costUsd: u.costUsd,+ costSource: u.costSource,turns: u.turnCount,contextWindow: u.contextWindow,lastTurnInputTokens: u.lastTurnInputTokens,diff --git a/app/src/providers/ChatRuntimeProvider.tsx b/app/src/providers/ChatRuntimeProvider.tsxindex f89e690cd4..56808815cd 100644--- a/app/src/providers/ChatRuntimeProvider.tsx+++ b/app/src/providers/ChatRuntimeProvider.tsx@@ -363,7 +363,8 @@ function chatTurnUsagePayload(event: ChatDoneEvent): {inputTokens: number;outputTokens: number;cachedTokens?: number;- costUsd?: number;+ costUsd?: number | null;+ costSource?: CostSource;contextWindow?: number;contextTokens?: number;threadId?: string;@@ -371,7 +372,7 @@ function chatTurnUsagePayload(event: ChatDoneEvent): {agentId: string;inputTokens: number;outputTokens: number;- costUsd: number;+ costUsd: number | null;}>;} {const u = event.usage;@@ -381,6 +382,7 @@ function chatTurnUsagePayload(event: ChatDoneEvent): {outputTokens: u.output_tokens,cachedTokens: u.cached_input_tokens,costUsd: u.cost_usd,+ costSource: u.cost_source,contextWindow: u.context_window,contextTokens: u.context_tokens,threadId: event.thread_id,@@ -1032,14 +1034,17 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {inputTokens: childInput ?? 0,outputTokens: childOutput ?? 0,cachedTokens: event.subagent?.cached_input_tokens ?? 0,- costUsd: event.subagent?.cost_usd ?? 0,+ // `null` (cost not known) is kept so the thread shows no+ // price; an absent field means "nothing to add".+ costUsd: event.subagent?.cost_usd === undefined ? 0 : event.subagent.cost_usd,subAgentSpendOnly: true,subAgents: [{agentId: event.tool_name ?? 'subagent',inputTokens: childInput ?? 0,outputTokens: childOutput ?? 0,- costUsd: event.subagent?.cost_usd ?? 0,+ costUsd:+ event.subagent?.cost_usd === undefined ? 0 : event.subagent.cost_usd,},],})diff --git a/app/src/services/api/threadUsageApi.ts b/app/src/services/api/threadUsageApi.tsindex b23d8283b0..4a9dab64ae 100644--- a/app/src/services/api/threadUsageApi.ts+++ b/app/src/services/api/threadUsageApi.ts@@ -1,3 +1,4 @@+import type { CostSource } from '../chatService';import { callCoreRpc } from '../coreRpcClient';/** One sub-agent archetype's contribution within a thread. */@@ -5,7 +6,8 @@ interface ThreadSubagentUsage {agentId: string;inputTokens: number;outputTokens: number;- costUsd: number;+ /** `null` when this archetype's cost is not known. */+ costUsd: number | null;runs: number;}@@ -15,7 +17,9 @@ interface ThreadTokenUsage {inputTokens: number;outputTokens: number;cachedInputTokens: number;- costUsd: number;+ /** `null` when some turn's cost is not known; never a guessed rate. */+ costUsd: number | null;+ costSource: CostSource;turnCount: number;lastTurnInputTokens: number;lastTurnOutputTokens: number;@@ -34,7 +38,7 @@ interface ThreadSubagentUsageWire {agent_id: string;input_tokens: number;output_tokens: number;- cost_usd: number;+ cost_usd: number | null;runs: number;}@@ -43,7 +47,9 @@ interface ThreadTokenUsageWire {input_tokens: number;output_tokens: number;cached_input_tokens: number;- cost_usd: number;+ cost_usd: number | null;+ /** Absent from a core that predates it (whose `cost_usd` is a number). */+ cost_source?: CostSource;turn_count: number;last_turn_input_tokens: number;last_turn_output_tokens: number;@@ -78,6 +84,7 @@ export async function fetchThreadTokenUsage(threadId: string): Promise<ThreadTokoutputTokens: d.output_tokens,cachedInputTokens: d.cached_input_tokens,costUsd: d.cost_usd,+ costSource: d.cost_usd === null ? 'unknown' : (d.cost_source ?? 'charged'),turnCount: d.turn_count,lastTurnInputTokens: d.last_turn_input_tokens,lastTurnOutputTokens: d.last_turn_output_tokens,