Skip to content

Commit 043d3b8

Browse files
authored
feat: support AI SDK v5 and v6 via unified imports [ENG-11722] (#269)
* chore: update ai sdk v6 * feat(deps): support AI SDK v5 and v6 via unified imports Remove direct dependencies on @ai-sdk/provider and @ai-sdk/provider-utils internal packages. Import JSONSchema7 and Tool types directly from the main 'ai' package instead. This change: - Removes @ai-sdk/provider and @ai-sdk/provider-utils from devDependencies - Updates peerDependencies to accept ai >=5.0.0 <7.0.0 - Simplifies the dependency tree for consumers Both AI SDK v5 and v6 export the required types from the main package, making the internal package dependencies unnecessary. * chore(deps): require ai SDK >=5.0.108
1 parent 4a5caf6 commit 043d3b8

File tree

7 files changed

+98
-62
lines changed

7 files changed

+98
-62
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@
5757
"zod": "catalog:prod"
5858
},
5959
"devDependencies": {
60-
"@ai-sdk/provider": "catalog:dev",
61-
"@ai-sdk/provider-utils": "catalog:dev",
6260
"@fast-check/vitest": "catalog:dev",
6361
"@hono/mcp": "catalog:dev",
6462
"@types/node": "catalog:dev",
6563
"@typescript/native-preview": "catalog:dev",
6664
"@vitest/coverage-v8": "catalog:dev",
67-
"ai": "catalog:peer",
65+
"ai": "catalog:dev",
6866
"hono": "catalog:dev",
6967
"knip": "catalog:dev",
7068
"lefthook": "catalog:dev",

pnpm-lock.yaml

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

pnpm-workspace.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ catalogMode: strict
66

77
catalogs:
88
dev:
9-
'@ai-sdk/openai': ^2.0.80
10-
'@ai-sdk/provider': ^2.0.0
9+
'@ai-sdk/openai': ^3.0.2
10+
ai: ^6.0.7
1111
'@fast-check/vitest': ^0.2.0
12-
'@ai-sdk/provider-utils': ^3.0.18
1312
'@clack/prompts': ^0.11.0
1413
'@hono/mcp': ^0.1.4
1514
'@types/node': ^22.13.5
@@ -34,7 +33,7 @@ catalogs:
3433
'@tanstack/ai-openai': ^0.0.3
3534
peer:
3635
'@anthropic-ai/sdk': ^0.52.0
37-
ai: ^5.0.108
36+
ai: '>=5.0.108 <7.0.0'
3837
openai: ^6.2.0
3938
prod:
4039
'@modelcontextprotocol/sdk': ^1.24.3
@@ -47,9 +46,14 @@ enablePrePostScripts: true
4746
minimumReleaseAge: 1440
4847

4948
minimumReleaseAgeExclude:
49+
- '@ai-sdk/gateway'
50+
- '@ai-sdk/openai'
51+
- '@ai-sdk/provider'
52+
- '@ai-sdk/provider-utils'
5053
- '@anthropic-ai/claude-agent-sdk'
5154
- '@tanstack/ai'
5255
- '@tanstack/ai-openai'
56+
- ai
5357

5458
onlyBuiltDependencies:
5559
- esbuild

src/tool.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type { JSONSchema7 as AISDKJSONSchema } from '@ai-sdk/provider';
1+
import type { JSONSchema7 as AISDKJSONSchema } from 'ai';
22
import type { Tool as AnthropicTool } from '@anthropic-ai/sdk/resources';
33
import * as orama from '@orama/orama';
44
import type { ChatCompletionFunctionTool } from 'openai/resources/chat/completions';
55
import type { FunctionTool as OpenAIResponsesFunctionTool } from 'openai/resources/responses/responses';
66
import type { OverrideProperties } from 'type-fest';
7+
import { peerDependencies } from '../package.json';
78
import { DEFAULT_HYBRID_ALPHA } from './consts';
89
import { RequestBuilder } from './requestBuilder';
910
import type {
@@ -52,7 +53,9 @@ export class BaseTool {
5253
method: this.executeConfig.method,
5354
url: this.executeConfig.url,
5455
bodyType: this.executeConfig.bodyType,
55-
params: this.executeConfig.params.map((param) => ({ ...param })),
56+
params: this.executeConfig.params.map((param) => ({
57+
...param,
58+
})),
5659
} satisfies HttpExecuteConfig;
5760
case 'rpc':
5861
return {
@@ -145,7 +148,9 @@ export class BaseTool {
145148
typeof inputParams !== 'object'
146149
) {
147150
throw new StackOneError(
148-
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(inputParams)}`,
151+
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(
152+
inputParams,
153+
)}`,
149154
);
150155
}
151156

@@ -236,7 +241,7 @@ export class BaseTool {
236241
/** AI SDK is optional dependency, import only when needed */
237242
const ai = await tryImport<typeof import('ai')>(
238243
'ai',
239-
'npm install ai@4.x|5.x or pnpm add [email protected]|5.x',
244+
`npm install ai (requires ${peerDependencies.ai})`,
240245
);
241246
const schemaObject = ai.jsonSchema(schema);
242247

@@ -257,7 +262,9 @@ export class BaseTool {
257262
try {
258263
return await this.execute(args as JsonObject);
259264
} catch (error) {
260-
return `Error executing tool: ${error instanceof Error ? error.message : String(error)}`;
265+
return `Error executing tool: ${
266+
error instanceof Error ? error.message : String(error)
267+
}`;
261268
}
262269
}
263270
: undefined,
@@ -582,7 +589,9 @@ function metaSearchTools(
582589
typeof inputParams !== 'object'
583590
) {
584591
throw new StackOneError(
585-
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(inputParams)}`,
592+
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(
593+
inputParams,
594+
)}`,
586595
);
587596
}
588597

@@ -712,7 +721,9 @@ function metaExecuteTool(tools: Tools): BaseTool {
712721
typeof inputParams !== 'object'
713722
) {
714723
throw new StackOneError(
715-
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(inputParams)}`,
724+
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(
725+
inputParams,
726+
)}`,
716727
);
717728
}
718729

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Common type definitions for the StackOne SDK
33
*/
44

5-
import type { Tool } from '@ai-sdk/provider-utils';
5+
import type { Tool } from 'ai';
66
import type { ToolSet } from 'ai';
77
import type { JsonObject, JsonValue, ValueOf } from 'type-fest';
88

@@ -176,7 +176,7 @@ export interface ToolDefinition {
176176

177177
/**
178178
* Extended AI SDK tool definition with StackOne-specific execution metadata.
179-
* Extends the base Tool type from @ai-sdk/provider-utils.
179+
* Extends the base Tool type from the 'ai' package.
180180
*
181181
* NOTE: We avoid defining our own types as much as possible and use existing
182182
* types from dependencies. This type only extends the AI SDK Tool type with

src/utils/try-import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { StackOneError } from './error-stackone';
1010
*
1111
* @example
1212
* ```ts
13-
* const ai = await tryImport('ai', 'npm install ai@4.x|5.x');
13+
* const ai = await tryImport('ai', 'npm install ai');
1414
* const { jsonSchema } = ai;
1515
* ```
1616
*/

tsdown.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
treeshake: true,
1010
dts: {
1111
tsgo: true,
12-
resolve: [/^@types\//, 'type-fest', 'ai', '@ai-sdk/provider-utils'],
12+
resolve: [/^@types\//, 'type-fest', 'ai'],
1313
},
1414
publint: true,
1515
unused: true,

0 commit comments

Comments
 (0)