This commit is contained in:
2026-02-25 06:59:29 +00:00
parent 88fff9efae
commit acd7713c86
37 changed files with 1581 additions and 69 deletions
+12 -6
View File
@@ -414,12 +414,18 @@ function parsePiEvent(event: Record<string, unknown>, currentStreamBuffer: strin
}
case 'agent_end': {
// Pi doesn't provide cost info in agent_end, use zeros
const cost: MessageCost = {
inputTokens: 0,
outputTokens: 0,
totalUSD: 0,
};
const cost: MessageCost = { inputTokens: 0, outputTokens: 0, totalUSD: 0 };
const messages = event.messages as Array<Record<string, unknown>> | undefined;
if (messages) {
for (const msg of messages) {
const usage = msg.usage as Record<string, unknown> | undefined;
if (!usage) continue;
cost.inputTokens += (usage.input as number) ?? 0;
cost.outputTokens += (usage.output as number) ?? 0;
const usageCost = usage.cost as Record<string, unknown> | undefined;
if (usageCost) cost.totalUSD += (usageCost.total as number) ?? 0;
}
}
return { type: 'result', cost };
}