chore: update to ai sdk v5 beta (#1074)

This commit is contained in:
Jeremy 2025-07-03 02:26:34 -07:00 committed by GitHub
parent 7d8e71383f
commit 4c281fe09d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
54 changed files with 1372 additions and 1060 deletions

View file

@ -1,13 +1,14 @@
import { simulateReadableStream } from 'ai';
import { MockLanguageModelV1 } from 'ai/test';
import { MockLanguageModelV2 } from 'ai/test';
import { getResponseChunksByPrompt } from '@/tests/prompts/utils';
export const chatModel = new MockLanguageModelV1({
export const chatModel = new MockLanguageModelV2({
doGenerate: async () => ({
rawCall: { rawPrompt: null, rawSettings: {} },
finishReason: 'stop',
usage: { promptTokens: 10, completionTokens: 20 },
text: `Hello, world!`,
usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
content: [{ type: 'text', text: 'Hello, world!' }],
warnings: [],
}),
doStream: async ({ prompt }) => ({
stream: simulateReadableStream({
@ -19,12 +20,13 @@ export const chatModel = new MockLanguageModelV1({
}),
});
export const reasoningModel = new MockLanguageModelV1({
export const reasoningModel = new MockLanguageModelV2({
doGenerate: async () => ({
rawCall: { rawPrompt: null, rawSettings: {} },
finishReason: 'stop',
usage: { promptTokens: 10, completionTokens: 20 },
text: `Hello, world!`,
usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
content: [{ type: 'text', text: 'Hello, world!' }],
warnings: [],
}),
doStream: async ({ prompt }) => ({
stream: simulateReadableStream({
@ -36,24 +38,26 @@ export const reasoningModel = new MockLanguageModelV1({
}),
});
export const titleModel = new MockLanguageModelV1({
export const titleModel = new MockLanguageModelV2({
doGenerate: async () => ({
rawCall: { rawPrompt: null, rawSettings: {} },
finishReason: 'stop',
usage: { promptTokens: 10, completionTokens: 20 },
text: `This is a test title`,
usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
content: [{ type: 'text', text: 'This is a test title' }],
warnings: [],
}),
doStream: async () => ({
stream: simulateReadableStream({
chunkDelayInMs: 500,
initialDelayInMs: 1000,
chunks: [
{ type: 'text-delta', textDelta: 'This is a test title' },
{ id: '1', type: 'text-start' },
{ id: '1', type: 'text-delta', delta: 'This is a test title' },
{ id: '1', type: 'text-end' },
{
type: 'finish',
finishReason: 'stop',
logprobs: undefined,
usage: { completionTokens: 10, promptTokens: 3 },
usage: { inputTokens: 3, outputTokens: 10, totalTokens: 13 },
},
],
}),
@ -61,12 +65,13 @@ export const titleModel = new MockLanguageModelV1({
}),
});
export const artifactModel = new MockLanguageModelV1({
export const artifactModel = new MockLanguageModelV2({
doGenerate: async () => ({
rawCall: { rawPrompt: null, rawSettings: {} },
finishReason: 'stop',
usage: { promptTokens: 10, completionTokens: 20 },
text: `Hello, world!`,
usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
content: [{ type: 'text', text: 'Hello, world!' }],
warnings: [],
}),
doStream: async ({ prompt }) => ({
stream: simulateReadableStream({