Skip to content

Commit 26331c4

Browse files
chore(deps): update dependency ai to v7 (#1907)
* chore(deps): update dependency ai to v7 * fix(api): read usage token details from ai v7 shape * chore(deps): dedupe @ai-sdk/provider and provider-utils --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Elliott de Launay <[email protected]>
1 parent 285f668 commit 26331c4

5 files changed

Lines changed: 86 additions & 47 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
"rollup": "4.60.4",
6969
"vite": "8.1.0",
7070
"undici": "6.28.1",
71+
"@ai-sdk/provider@3": "3.0.13",
72+
"@ai-sdk/provider-utils@4": "4.0.35",
7173
"form-data": ">=4.0.4",
7274
"bluebird": ">=3.7.2",
7375
"glob": "11.1.0",

‎pnpm-lock.yaml‎

Lines changed: 49 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/api/providers/__tests__/openai-compatible.spec.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,36 @@ describe("OpenAICompatibleHandler", () => {
120120
expect(textChunks[0].text).toBe("Test response")
121121
})
122122

123+
it("should map cache read and reasoning tokens from ai v7 usage details", async () => {
124+
async function* mockFullStream() {
125+
yield { type: "text-delta", text: "ok" }
126+
}
127+
128+
mockStreamText.mockReturnValue({
129+
fullStream: mockFullStream(),
130+
usage: Promise.resolve({
131+
inputTokens: 20,
132+
outputTokens: 10,
133+
inputTokenDetails: { cacheReadTokens: 7 },
134+
outputTokenDetails: { reasoningTokens: 4 },
135+
raw: {},
136+
}),
137+
})
138+
139+
const chunks: ApiStreamChunk[] = []
140+
for await (const chunk of handler.createMessage(systemPrompt, messages)) {
141+
chunks.push(chunk)
142+
}
143+
144+
expect(chunks.find((chunk) => chunk.type === "usage")).toEqual({
145+
type: "usage",
146+
inputTokens: 20,
147+
outputTokens: 10,
148+
cacheReadTokens: 7,
149+
reasoningTokens: 4,
150+
})
151+
})
152+
123153
it("should handle multiple stream parts and yield usage metrics", async () => {
124154
async function* mockFullStream() {
125155
yield { type: "text-delta", text: "First part" }

‎src/api/providers/openai-compatible.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,16 @@ export abstract class OpenAICompatibleHandler extends BaseProvider implements Si
8989
protected processUsageMetrics(usage: {
9090
inputTokens?: number
9191
outputTokens?: number
92-
details?: {
93-
cachedInputTokens?: number
94-
reasoningTokens?: number
95-
}
92+
inputTokenDetails?: { cacheReadTokens?: number }
93+
outputTokenDetails?: { reasoningTokens?: number }
9694
raw?: Record<string, unknown>
9795
}): ApiStreamUsageChunk {
9896
return {
9997
type: "usage",
10098
inputTokens: usage.inputTokens || 0,
10199
outputTokens: usage.outputTokens || 0,
102-
cacheReadTokens: usage.details?.cachedInputTokens,
103-
reasoningTokens: usage.details?.reasoningTokens,
100+
cacheReadTokens: usage.inputTokenDetails?.cacheReadTokens,
101+
reasoningTokens: usage.outputTokenDetails?.reasoningTokens,
104102
}
105103
}
106104

‎src/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@
559559
"@types/vscode": "1.100.0",
560560
"@vitest/coverage-v8": "4.1.9",
561561
"@vscode/vsce": "3.9.2",
562-
"ai": "6.0.218",
562+
"ai": "7.0.137",
563563
"esbuild-wasm": "0.28.1",
564564
"execa": "9.6.1",
565565
"mkdirp": "3.0.1",

0 commit comments

Comments
 (0)