fix(usage): preserve partial footer counts

This commit is contained in:
Ayaan Zaidi
2026-06-13 18:15:39 +05:30
parent 5892dc8522
commit 84cbaf1832
3 changed files with 33 additions and 4 deletions
@@ -2707,6 +2707,28 @@ describe("runReplyAgent response usage footer", () => {
expect(text).not.toContain("· session ");
});
it("keeps partial token counts in the built-in full footer", async () => {
runEmbeddedAgentMock.mockResolvedValueOnce({
payloads: [{ text: "ok" }],
meta: {
agentMeta: {
provider: "anthropic",
model: "claude",
usage: { output: 125 },
},
},
});
const res = await createRun({
responseUsage: "full",
sessionKey: "agent:main:whatsapp:dm:+1000",
});
const payload = Array.isArray(res) ? res[0] : res;
const text = payload?.text ?? "";
expect(text).toContain("↕️ ?/125");
expect(text).not.toContain("Usage:");
});
it("shows configured costs for aws-sdk providers when responseUsage=full", async () => {
runEmbeddedAgentMock.mockResolvedValueOnce({
payloads: [{ text: "ok" }],
+7
View File
@@ -11,6 +11,12 @@ export function buildUsageContract(
const cacheRead = usage.cacheRead;
const cacheWrite = usage.cacheWrite;
const total = usage.total;
const hasTokens =
input !== undefined ||
output !== undefined ||
cacheRead !== undefined ||
cacheWrite !== undefined ||
total !== undefined;
const promptTotal = (cacheRead ?? 0) + (cacheWrite ?? 0) + (input ?? 0);
const cacheHitPct =
@@ -70,6 +76,7 @@ export function buildUsageContract(
cache_write_tokens: cacheWrite,
total_tokens: total,
cache_hit_pct: cacheHitPct,
has_tokens: hasTokens,
last: last
? {
input_tokens: last.input,
+4 -4
View File
@@ -35,8 +35,8 @@ export const DEFAULT_USAGE_BAR_TEMPLATE: UsageBarTemplate = {
text: " | 📚 [{context.pct_used|meter:5:braille}]{context.max_tokens|num}",
},
{
when: "usage.input_tokens",
text: " ↕️ {usage.input_tokens|num}/{usage.output_tokens|num}",
when: "usage.has_tokens",
text: " ↕️ {usage.input_tokens|num|?}/{usage.output_tokens|num|?}",
},
{ when: "usage.cache_hit_pct", text: " 🗄 {usage.cache_hit_pct|pct}" },
{ when: "cost.turn_usd", text: " 💰{cost.turn_usd|fixed:4}" },
@@ -54,8 +54,8 @@ export const DEFAULT_USAGE_BAR_TEMPLATE: UsageBarTemplate = {
text: " | 📚 [{context.pct_used|meter:5:braille}]{context.max_tokens|num}",
},
{
when: "usage.input_tokens",
text: " ↕️ {usage.input_tokens|num}/{usage.output_tokens|num}",
when: "usage.has_tokens",
text: " ↕️ {usage.input_tokens|num|?}/{usage.output_tokens|num|?}",
},
{ when: "usage.cache_hit_pct", text: " 🗄 {usage.cache_hit_pct|pct}" },
{ when: "cost.turn_usd", text: " 💰{cost.turn_usd|fixed:4}" },