|
5 | 5 | // Install it with: npm install ai |
6 | 6 |
|
7 | 7 | import type { L0Event, L0Adapter } from "../types/l0"; |
8 | | -import type { StreamTextResult, TextStreamPart, ToolSet } from "ai"; |
| 8 | +import type { TextStreamPart, ToolSet } from "ai"; |
9 | 9 |
|
10 | 10 | /** |
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. |
12 | 15 | */ |
13 | | -export type VercelStreamTextResult = StreamTextResult<ToolSet, never>; |
| 16 | +export type VercelStreamChunk = TextStreamPart<ToolSet>; |
14 | 17 |
|
15 | 18 | /** |
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`. |
17 | 28 | */ |
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 | +} |
19 | 43 |
|
20 | 44 | /** |
21 | 45 | * Options for wrapping Vercel AI streams |
|
0 commit comments