Skip to content

Commit 76643f0

Browse files
authored
Merge pull request #70 from ai-2070/support-ai-v6-and-v7
Support AI v6 and v7
2 parents 9007937 + 88db9fa commit 76643f0

3 files changed

Lines changed: 58 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,30 @@ jobs:
2929

3030
- name: Build
3131
run: npm run build
32+
33+
# Guard the lower bound of the `ai` peer range (^6.0.0 || ^7.0.0).
34+
# The main job above exercises ai v7 (the saved devDependency); this job
35+
# pins ai to v6 so the adapter's cross-version typing keeps compiling.
36+
compat-ai-v6:
37+
name: Build against ai v6
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v7
42+
43+
- name: Setup Node.js
44+
uses: actions/setup-node@v6
45+
with:
46+
node-version: 24
47+
48+
- name: Install dependencies
49+
run: npm install
50+
51+
- name: Pin ai to v6
52+
run: npm install ai@6 --no-save
53+
54+
- name: Run tests
55+
run: npm test
56+
57+
- name: Build
58+
run: npm run build

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
"@mastra/core": "^1.0.0",
158158
"@opentelemetry/api": "^1.0.0",
159159
"@sentry/node": "^10.0.0",
160-
"ai": "^6.0.0",
160+
"ai": "^6.0.0 || ^7.0.0",
161161
"effect": "^3.0.0",
162162
"openai": "^4.0.0 || ^5.0.0 || ^6.0.0",
163163
"zod": "^3.0.0 || ^4.0.0"
@@ -199,7 +199,7 @@
199199
"@types/uuid": "^11.0.0",
200200
"@vitest/coverage-v8": "^4.0.0",
201201
"@vitest/ui": "^4.0.0",
202-
"ai": "^6.0.0",
202+
"ai": "^7.0.0",
203203
"effect": "^3.19.0",
204204
"esbuild": "0.28.1",
205205
"glob": "^13.0.0",

src/adapters/vercel-ai.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,41 @@
55
// Install it with: npm install ai
66

77
import type { L0Event, L0Adapter } from "../types/l0";
8-
import type { StreamTextResult, TextStreamPart, ToolSet } from "ai";
8+
import type { TextStreamPart, ToolSet } from "ai";
99

1010
/**
11-
* Vercel AI SDK StreamTextResult with any tool set
11+
* Vercel AI SDK stream chunk type
12+
*
13+
* `TextStreamPart` is a single-argument generic in both AI SDK v6 and v7, so
14+
* this reference is version-agnostic.
1215
*/
13-
export type VercelStreamTextResult = StreamTextResult<ToolSet, never>;
16+
export type VercelStreamChunk = TextStreamPart<ToolSet>;
1417

1518
/**
16-
* Vercel AI SDK stream chunk type
19+
* Vercel AI SDK StreamTextResult, typed structurally for cross-version support.
20+
*
21+
* We deliberately avoid `import('ai').StreamTextResult` because its generic
22+
* arity changed between major versions: v6 is `StreamTextResult<TOOLS, OUTPUT>`
23+
* while v7 added a middle generic, `StreamTextResult<TOOLS, RUNTIME_CONTEXT,
24+
* OUTPUT>`. No single explicit instantiation satisfies both. Instead we declare
25+
* only the members this adapter actually reads — mirroring the minimal-interface
26+
* approach already used in vercel-ai-object.ts — so the adapter compiles against
27+
* `ai@^6 || ^7`. Detection stays runtime-based via `isVercelAIStream`.
1728
*/
18-
export type VercelStreamChunk = TextStreamPart<ToolSet>;
29+
export interface VercelStreamTextResult {
30+
/** Raw text token stream */
31+
textStream: AsyncIterable<string>;
32+
/** Full event stream including tool calls and results */
33+
fullStream: ReadableStream<VercelStreamChunk>;
34+
/** Promise resolving to the complete text */
35+
text: Promise<string>;
36+
/** Promise resolving to the tool calls made */
37+
toolCalls: Promise<unknown>;
38+
/** Promise resolving to usage information */
39+
usage: Promise<unknown>;
40+
/** Promise resolving to the finish reason */
41+
finishReason: Promise<unknown>;
42+
}
1943

2044
/**
2145
* Options for wrapping Vercel AI streams

0 commit comments

Comments
 (0)