feat(core): add per-model token usage to stream-json output (#21839)

This commit is contained in:
Yongrui Lin
2026-03-10 10:39:04 -07:00
committed by GitHub
parent 18112c474e
commit 4da0366eed
5 changed files with 87 additions and 18 deletions
@@ -154,6 +154,7 @@ describe('StreamJsonFormatter', () => {
input: 50,
duration_ms: 1200,
tool_calls: 2,
models: {},
},
};
@@ -180,6 +181,7 @@ describe('StreamJsonFormatter', () => {
input: 50,
duration_ms: 1200,
tool_calls: 0,
models: {},
},
};
@@ -304,6 +306,15 @@ describe('StreamJsonFormatter', () => {
input: 50,
duration_ms: 1200,
tool_calls: 2,
models: {
'gemini-2.0-flash': {
total_tokens: 80,
input_tokens: 50,
output_tokens: 30,
cached: 0,
input: 50,
},
},
});
});
@@ -347,6 +358,22 @@ describe('StreamJsonFormatter', () => {
input: 150,
duration_ms: 3000,
tool_calls: 5,
models: {
'gemini-pro': {
total_tokens: 80,
input_tokens: 50,
output_tokens: 30,
cached: 0,
input: 50,
},
'gemini-ultra': {
total_tokens: 170,
input_tokens: 100,
output_tokens: 70,
cached: 0,
input: 100,
},
},
});
});
@@ -376,6 +403,15 @@ describe('StreamJsonFormatter', () => {
input: 20,
duration_ms: 1200,
tool_calls: 0,
models: {
'gemini-pro': {
total_tokens: 80,
input_tokens: 50,
output_tokens: 30,
cached: 30,
input: 20,
},
},
});
});
@@ -392,6 +428,7 @@ describe('StreamJsonFormatter', () => {
input: 0,
duration_ms: 100,
tool_calls: 0,
models: {},
});
});
@@ -521,6 +558,7 @@ describe('StreamJsonFormatter', () => {
input: 0,
duration_ms: 0,
tool_calls: 0,
models: {},
},
} as ResultEvent,
];
@@ -544,6 +582,7 @@ describe('StreamJsonFormatter', () => {
input: 50,
duration_ms: 1200,
tool_calls: 2,
models: {},
},
};