Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@
"zod": "catalog:prod"
},
"devDependencies": {
"@ai-sdk/provider": "catalog:dev",
"@ai-sdk/provider-utils": "catalog:dev",
"@fast-check/vitest": "catalog:dev",
"@hono/mcp": "catalog:dev",
"@types/node": "catalog:dev",
"@typescript/native-preview": "catalog:dev",
"@vitest/coverage-v8": "catalog:dev",
"ai": "catalog:peer",
"ai": "catalog:dev",
"hono": "catalog:dev",
"knip": "catalog:dev",
"lefthook": "catalog:dev",
Expand Down
111 changes: 67 additions & 44 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ catalogMode: strict

catalogs:
dev:
'@ai-sdk/openai': ^2.0.80
'@ai-sdk/provider': ^2.0.0
'@ai-sdk/openai': ^3.0.2
ai: ^6.0.7
'@fast-check/vitest': ^0.2.0
'@ai-sdk/provider-utils': ^3.0.18
'@clack/prompts': ^0.11.0
'@hono/mcp': ^0.1.4
'@types/node': ^22.13.5
Expand All @@ -34,7 +33,7 @@ catalogs:
'@tanstack/ai-openai': ^0.0.3
peer:
'@anthropic-ai/sdk': ^0.52.0
ai: ^5.0.108
ai: '>=5.0.108 <7.0.0'
openai: ^6.2.0
prod:
'@modelcontextprotocol/sdk': ^1.24.3
Expand All @@ -47,9 +46,14 @@ enablePrePostScripts: true
minimumReleaseAge: 1440

minimumReleaseAgeExclude:
- '@ai-sdk/gateway'
- '@ai-sdk/openai'
- '@ai-sdk/provider'
- '@ai-sdk/provider-utils'
- '@anthropic-ai/claude-agent-sdk'
- '@tanstack/ai'
- '@tanstack/ai-openai'
- ai

onlyBuiltDependencies:
- esbuild
Expand Down
25 changes: 18 additions & 7 deletions src/tool.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { JSONSchema7 as AISDKJSONSchema } from '@ai-sdk/provider';
import type { JSONSchema7 as AISDKJSONSchema } from 'ai';
import type { Tool as AnthropicTool } from '@anthropic-ai/sdk/resources';
import * as orama from '@orama/orama';
import type { ChatCompletionFunctionTool } from 'openai/resources/chat/completions';
import type { FunctionTool as OpenAIResponsesFunctionTool } from 'openai/resources/responses/responses';
import type { OverrideProperties } from 'type-fest';
import { peerDependencies } from '../package.json';
import { DEFAULT_HYBRID_ALPHA } from './consts';
import { RequestBuilder } from './requestBuilder';
import type {
Expand Down Expand Up @@ -52,7 +53,9 @@ export class BaseTool {
method: this.executeConfig.method,
url: this.executeConfig.url,
bodyType: this.executeConfig.bodyType,
params: this.executeConfig.params.map((param) => ({ ...param })),
params: this.executeConfig.params.map((param) => ({
...param,
})),
} satisfies HttpExecuteConfig;
case 'rpc':
return {
Expand Down Expand Up @@ -145,7 +148,9 @@ export class BaseTool {
typeof inputParams !== 'object'
) {
throw new StackOneError(
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(inputParams)}`,
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(
inputParams,
)}`,
);
}

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

Expand All @@ -257,7 +262,9 @@ export class BaseTool {
try {
return await this.execute(args as JsonObject);
} catch (error) {
return `Error executing tool: ${error instanceof Error ? error.message : String(error)}`;
return `Error executing tool: ${
error instanceof Error ? error.message : String(error)
}`;
}
}
: undefined,
Expand Down Expand Up @@ -582,7 +589,9 @@ function metaSearchTools(
typeof inputParams !== 'object'
) {
throw new StackOneError(
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(inputParams)}`,
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(
inputParams,
)}`,
);
}

Expand Down Expand Up @@ -712,7 +721,9 @@ function metaExecuteTool(tools: Tools): BaseTool {
typeof inputParams !== 'object'
) {
throw new StackOneError(
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(inputParams)}`,
`Invalid parameters type. Expected object or string, got ${typeof inputParams}. Parameters: ${JSON.stringify(
inputParams,
)}`,
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Common type definitions for the StackOne SDK
*/

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

Expand Down Expand Up @@ -176,7 +176,7 @@ export interface ToolDefinition {

/**
* Extended AI SDK tool definition with StackOne-specific execution metadata.
* Extends the base Tool type from @ai-sdk/provider-utils.
* Extends the base Tool type from the 'ai' package.
*
* NOTE: We avoid defining our own types as much as possible and use existing
* types from dependencies. This type only extends the AI SDK Tool type with
Expand Down
2 changes: 1 addition & 1 deletion src/utils/try-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { StackOneError } from './error-stackone';
*
* @example
* ```ts
* const ai = await tryImport('ai', 'npm install ai@4.x|5.x');
* const ai = await tryImport('ai', 'npm install ai');
* const { jsonSchema } = ai;
* ```
*/
Expand Down
2 changes: 1 addition & 1 deletion tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineConfig({
treeshake: true,
dts: {
tsgo: true,
resolve: [/^@types\//, 'type-fest', 'ai', '@ai-sdk/provider-utils'],
resolve: [/^@types\//, 'type-fest', 'ai'],
},
publint: true,
unused: true,
Expand Down
Loading