mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 12:20:23 +00:00
fix(cli): preserve claude cache creation tokens
This commit is contained in:
@@ -157,6 +157,43 @@ describe("parseCliJsonl", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves Claude cache creation tokens instead of flattening them to zero", () => {
|
||||
const result = parseCliJsonl(
|
||||
[
|
||||
JSON.stringify({ type: "init", session_id: "session-cache-123" }),
|
||||
JSON.stringify({
|
||||
type: "result",
|
||||
session_id: "session-cache-123",
|
||||
result: "Claude says hello",
|
||||
usage: {
|
||||
input_tokens: 12,
|
||||
output_tokens: 3,
|
||||
cache_read_input_tokens: 4,
|
||||
cache_creation_input_tokens: 7,
|
||||
},
|
||||
}),
|
||||
].join("\n"),
|
||||
{
|
||||
command: "claude",
|
||||
output: "jsonl",
|
||||
sessionIdFields: ["session_id"],
|
||||
},
|
||||
"claude-cli",
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
text: "Claude says hello",
|
||||
sessionId: "session-cache-123",
|
||||
usage: {
|
||||
input: 12,
|
||||
output: 3,
|
||||
cacheRead: 4,
|
||||
cacheWrite: 7,
|
||||
total: undefined,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves Claude session metadata even when the final result text is empty", () => {
|
||||
const result = parseCliJsonl(
|
||||
[
|
||||
|
||||
@@ -114,7 +114,8 @@ function toCliUsage(raw: Record<string, unknown>): CliUsage | undefined {
|
||||
(Object.hasOwn(raw, "cached") && typeof totalInput === "number"
|
||||
? Math.max(0, totalInput - (cacheRead ?? 0))
|
||||
: totalInput);
|
||||
const cacheWrite = pick("cache_write_input_tokens") ?? pick("cacheWrite");
|
||||
const cacheWrite =
|
||||
pick("cache_creation_input_tokens") ?? pick("cache_write_input_tokens") ?? pick("cacheWrite");
|
||||
const total = pick("total_tokens") ?? pick("total");
|
||||
if (!input && !output && !cacheRead && !cacheWrite && !total) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user