Skip to content

Commit a20a176

Browse files
feat: AI SDK v5 beta (#77)
BREAKING CHANGE: Updated OpenRouter provider to implement LanguageModelV2 interface - Updated both chat and completion models to use LanguageModelV2 - Added supportedUrls property with empty object for proxy compatibility - Changed specificationVersion from 'v1' to 'v2' - Refactored the whole project's organization Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Louis <[email protected]>
1 parent ea7197d commit a20a176

36 files changed

+1395
-1675
lines changed

.vscode/settings.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
},
2222
"editor.formatOnSave": true,
2323
"files.insertFinalNewline": true,
24-
"editor.defaultFormatter": "esbenp.prettier-vscode",
25-
"[typescript]": {
26-
"editor.defaultFormatter": "esbenp.prettier-vscode"
24+
"editor.defaultFormatter": "biomejs.biome",
25+
"editor.codeActionsOnSave": {
26+
"source.organizeImports.biome": "explicit",
27+
"source.fixAll.biome": "explicit"
2728
}
2829
}

biome.json

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.0.5/schema.json",
33
"vcs": {
44
"enabled": true,
55
"clientKind": "git",
66
"useIgnoreFile": true
77
},
8+
"assist": {
9+
"actions": {
10+
"source": {
11+
"organizeImports": {
12+
"level": "on",
13+
"options": {
14+
"groups": [
15+
{ "type": true },
16+
":BLANK_LINE:",
17+
{ "type": false },
18+
":BLANK_LINE:",
19+
":ALIAS:"
20+
]
21+
}
22+
}
23+
}
24+
}
25+
},
826
"formatter": {
927
"enabled": true,
1028
"indentStyle": "space",
1129
"indentWidth": 2,
1230
"lineWidth": 80
1331
},
14-
"organizeImports": {
15-
"enabled": true
16-
},
1732
"linter": {
1833
"enabled": true,
1934
"rules": {
@@ -34,21 +49,28 @@
3449
"useTemplate": "off",
3550
"useBlockStatements": "error",
3651
"noParameterAssign": "error",
37-
"useConst": "error"
52+
"useConst": "error",
53+
"useImportType": {
54+
"level": "on",
55+
"options": {
56+
"style": "separatedType"
57+
}
58+
}
3859
},
3960
"correctness": {
61+
"noUnsafeFinally": "error",
4062
"noUnusedImports": "error",
4163
"useExhaustiveDependencies": "off",
4264
"noUnknownFunction": "off",
4365
"noChildrenProp": "off",
4466
"noInnerDeclarations": "error"
4567
},
4668
"suspicious": {
47-
"noExplicitAny": "off",
69+
"noExplicitAny": "error",
4870
"noArrayIndexKey": "off",
4971
"noAssignInExpressions": "error",
5072
"noAsyncPromiseExecutor": "off",
51-
"noFallthroughSwitchClause": "off",
73+
"noFallthroughSwitchClause": "error",
5274
"noConsole": "error",
5375
"noDoubleEquals": {
5476
"level": "error",

e2e/cache-control.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { createOpenRouter } from '@/src';
21
import { streamText } from 'ai';
32
import { it, vi } from 'vitest';
3+
import { createOpenRouter } from '@/src';
44

55
vi.setConfig({
66
testTimeout: 42_000,

e2e/pdf-blob/index.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { CoreMessage } from 'ai';
1+
import type { ModelMessage } from 'ai';
22

3-
import { writeFile } from 'fs/promises';
4-
import { createOpenRouter } from '@/src';
53
import { generateText } from 'ai';
4+
import { writeFile } from 'fs/promises';
65
import { test, vi } from 'vitest';
6+
import { createOpenRouter } from '@/src';
77

88
vi.setConfig({
99
testTimeout: 42_000,
@@ -27,7 +27,7 @@ test('sending pdf base64 blob', async () => {
2727

2828
const pdfBase64 = Buffer.from(pdfBlob).toString('base64');
2929

30-
const messageHistory: CoreMessage[] = [];
30+
const messageHistory: ModelMessage[] = [];
3131
messageHistory.push({
3232
role: 'user',
3333
content: [
@@ -38,15 +38,14 @@ test('sending pdf base64 blob', async () => {
3838
{
3939
type: 'file',
4040
data: `data:application/pdf;base64,${pdfBase64}`,
41-
mimeType: 'application/pdf',
41+
mediaType: 'application/pdf',
4242
},
4343
],
4444
});
4545

4646
const response = await generateText({
4747
model,
4848
messages: messageHistory,
49-
maxSteps: 10,
5049
providerOptions: {
5150
openrouter: {
5251
reasoning: {

e2e/pdf-url/index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { CoreMessage } from 'ai';
1+
import type { ModelMessage } from 'ai';
22

3-
import { writeFile } from 'fs/promises';
4-
import { createOpenRouter } from '@/src';
53
import { generateText } from 'ai';
4+
import { writeFile } from 'fs/promises';
65
import { test, vi } from 'vitest';
6+
import { createOpenRouter } from '@/src';
77

88
vi.setConfig({
99
testTimeout: 42_000,
@@ -20,7 +20,7 @@ test('send pdf urls', async () => {
2020
include: true,
2121
},
2222
});
23-
const messageHistory: CoreMessage[] = [];
23+
const messageHistory: ModelMessage[] = [];
2424
messageHistory.push({
2525
role: 'user',
2626
content: [
@@ -31,7 +31,7 @@ test('send pdf urls', async () => {
3131
{
3232
type: 'file',
3333
data: new URL('https://bitcoin.org/bitcoin.pdf'),
34-
mimeType: 'application/pdf',
34+
mediaType: 'application/pdf',
3535
},
3636
],
3737
});

e2e/tools-with-reasoning.test.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import type { UIMessage } from 'ai';
1+
import type { ModelMessage } from 'ai';
22

3+
import { generateText } from 'ai';
4+
import { it, vi } from 'vitest';
35
import {
46
executeCommandInTerminalTool,
57
readSMSTool,
68
sendSMSTool,
79
} from '@/e2e/tools';
810
import { createOpenRouter } from '@/src';
9-
import { generateText } from 'ai';
10-
import { it, vi } from 'vitest';
1111

1212
vi.setConfig({
1313
testTimeout: 42_000,
@@ -30,13 +30,11 @@ describe('Vercel AI SDK tools call with reasoning', () => {
3030
include: true,
3131
},
3232
});
33-
const messageHistory: UIMessage[] = [];
33+
const messageHistory: ModelMessage[] = [];
3434
for (const prompt of prompts) {
3535
messageHistory.push({
36-
id: crypto.randomUUID(),
3736
role: 'user',
38-
content: prompt,
39-
parts: [
37+
content: [
4038
{
4139
type: 'text',
4240
text: prompt,
@@ -54,7 +52,6 @@ describe('Vercel AI SDK tools call with reasoning', () => {
5452
sendSMS: sendSMSTool,
5553
executeCommand: executeCommandInTerminalTool,
5654
},
57-
maxSteps: 10,
5855
providerOptions: {
5956
openrouter: {
6057
reasoning: {
@@ -64,19 +61,14 @@ describe('Vercel AI SDK tools call with reasoning', () => {
6461
},
6562
});
6663

67-
const parts = response.steps.map(
68-
(step) =>
69-
({
70-
type: 'text' as const,
71-
text: step.text,
72-
}) satisfies UIMessage['parts'][number],
73-
) satisfies UIMessage['parts'];
64+
const content = response.steps.map((step) => ({
65+
type: 'text' as const,
66+
text: step.text,
67+
}));
7468

7569
messageHistory.push({
76-
id: crypto.randomUUID(),
7770
role: 'assistant',
78-
content: response.text,
79-
parts,
71+
content,
8072
});
8173
}
8274
});

e2e/tools.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ref: https://github.com/t3dotgg/SnitchScript/blob/main/tools.ts
22

3-
import { createOpenRouter } from '@/src';
43
import { generateText, tool } from 'ai';
5-
import { z } from 'zod';
4+
import { z } from 'zod/v4';
5+
import { createOpenRouter } from '@/src';
66

77
const openrouter = createOpenRouter({
88
apiKey: process.env.OPENROUTER_API_KEY,
@@ -11,7 +11,7 @@ const openrouter = createOpenRouter({
1111

1212
export const sendSMSTool = tool({
1313
description: 'Send an SMS to any phone number',
14-
parameters: z.object({
14+
inputSchema: z.object({
1515
to: z.string(),
1616
body: z.string(),
1717
}),
@@ -26,7 +26,7 @@ export const sendSMSTool = tool({
2626

2727
export const readSMSTool = tool({
2828
description: 'Read the nth SMS from a phone number',
29-
parameters: z.object({
29+
inputSchema: z.object({
3030
phoneNumber: z.string(),
3131
index: z.number(),
3232
}),
@@ -41,7 +41,7 @@ export const readSMSTool = tool({
4141

4242
export const executeCommandInTerminalTool = tool({
4343
description: 'Execute a command in the terminal',
44-
parameters: z.object({
44+
inputSchema: z.object({
4545
command: z.string(),
4646
}),
4747
execute: async ({ command }) => {

e2e/usage-accounting.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { createOpenRouter } from '@/src';
21
import { streamText } from 'ai';
32
import { it } from 'vitest';
3+
import { createOpenRouter } from '@/src';
44

55
it('receive usage accounting', async () => {
66
const openrouter = createOpenRouter({

package.json

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openrouter/ai-sdk-provider",
3-
"version": "0.7.2",
3+
"version": "1.0.0-beta.0",
44
"license": "Apache-2.0",
55
"sideEffects": false,
66
"main": "./dist/index.js",
@@ -13,10 +13,9 @@
1313
"build": "tsup",
1414
"clean": "rm -rf dist && rm -rf internal/dist",
1515
"dev": "tsup --watch",
16-
"lint": "pnpm biome lint",
16+
"lint": "biome lint",
1717
"typecheck": "tsc --noEmit",
18-
"stylecheck": "prettier --check \"**/*.{ts,mts,tsx,md,mdx,mjs}\"",
19-
"format": "prettier --write \"**/*.{ts,mts,tsx,md,mdx,mjs}\"",
18+
"format": "biome format --write",
2019
"prepublish": "pnpm run build",
2120
"test": "pnpm test:node && pnpm test:edge",
2221
"test:edge": "vitest --config vitest.edge.config.ts --run",
@@ -37,28 +36,24 @@
3736
"require": "./dist/internal/index.js"
3837
}
3938
},
40-
"dependencies": {
41-
"@ai-sdk/provider": "1.1.3",
42-
"@ai-sdk/provider-utils": "2.2.8"
43-
},
4439
"devDependencies": {
40+
"@ai-sdk/provider": "2.0.0-beta.1",
41+
"@ai-sdk/provider-utils": "3.0.0-beta.2",
4542
"@biomejs/biome": "2.1.1",
4643
"@edge-runtime/vm": "5.0.0",
47-
"@ianvs/prettier-plugin-sort-imports": "4.4.2",
4844
"@types/jest": "29.5.14",
4945
"@types/node": "22.15.24",
50-
"ai": "4.3.17",
46+
"ai": "5.0.0-beta.12",
5147
"dotenv": "16.5.0",
52-
"prettier": "3.5.3",
5348
"tsup": "8.5.0",
5449
"typescript": "5.8.3",
5550
"vite-tsconfig-paths": "5.1.4",
5651
"vitest": "3.2.4",
57-
"zod": "3.25.34"
52+
"zod": "3.25.74"
5853
},
5954
"peerDependencies": {
60-
"zod": "^3.25.34",
61-
"ai": "^4.3.17"
55+
"ai": "^5.0.0-beta.12",
56+
"zod": "^3.25.74"
6257
},
6358
"engines": {
6459
"node": ">=18"

0 commit comments

Comments
 (0)