feat assistant context and agent trace
This commit is contained in:
1 parent
aea2832370
commit
f4f6773f26
9 files changed
+390
-44
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import {
|
||||
getAssistantContextBreakdown,
|
||||
getAssistantConversationUsage,
|
||||
getAssistantTelemetry,
|
||||
getAssistantUsage,
|
||||
@@ -262,3 +263,53 @@ describe("getAssistantConversationUsage", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("getAssistantContextBreakdown", () => {
|
||||
test("combines the latest context reading with the latest reported token categories", () => {
|
||||
const usage = getAssistantConversationUsage([
|
||||
createUsageMetadata({
|
||||
requestId: "reported",
|
||||
inputTokens: 12_777,
|
||||
outputTokens: 55,
|
||||
cost: 0.00041,
|
||||
contextUsed: 13_343,
|
||||
}),
|
||||
{
|
||||
custom: {
|
||||
telemetry: {
|
||||
requestId: "streaming",
|
||||
provider: "openrouter",
|
||||
modelId: "example/model",
|
||||
startedAt: "2026-08-04T10:00:02.000Z",
|
||||
steps: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
expect(getAssistantContextBreakdown(usage)).toMatchObject({
|
||||
contextUsed: 13_343,
|
||||
contextLength: 128_000,
|
||||
remaining: 114_657,
|
||||
percentage: 10,
|
||||
inputTokens: 12_777,
|
||||
outputTokens: 55,
|
||||
});
|
||||
});
|
||||
|
||||
test("does not report an invalid percentage for an unavailable capacity", () => {
|
||||
expect(
|
||||
getAssistantContextBreakdown({
|
||||
turns: [],
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
totalTokens: 0,
|
||||
cachedInputTokens: 0,
|
||||
reasoningTokens: 0,
|
||||
cost: 0,
|
||||
contextUsed: 10,
|
||||
contextLength: 0,
|
||||
}),
|
||||
).toEqual({});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user