mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 13:26:04 -06:00
fix(usage): preserve partial footer counts
This commit is contained in:
@@ -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" }],
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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}" },
|
||||
|
||||
Reference in New Issue
Block a user