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
8 changes: 4 additions & 4 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lint-staged": "^15.2.0",
"mkdocs": "^0.0.1",
"msw": "^2.10.4",
"openai": "^5.7.0",
"openai": "^6.2.0",
"openapi-types": "^12.1.3",
"publint": "^0.3.12",
"tsdown": "^0.15.6",
Expand All @@ -32,8 +32,8 @@
"zod": "^3.23.8",
},
"peerDependencies": {
"ai": "^5.0.63",
"openai": "4.x|5.x",
"ai": "4.x|5.x",
"openai": "5.x|6.x",
},
},
},
Expand Down Expand Up @@ -434,7 +434,7 @@

"onetime": ["[email protected]", "", { "dependencies": { "mimic-fn": "^4.0.0" } }, "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ=="],

"openai": ["openai@5.23.2", "", { "peerDependencies": { "ws": "^8.18.0", "zod": "^3.23.8" }, "optionalPeers": ["ws", "zod"], "bin": { "openai": "bin/cli" } }, "sha512-MQBzmTulj+MM5O8SKEk/gL8a7s5mktS9zUtAkU257WjvobGc9nKcBuVwjyEEcb9SI8a8Y2G/mzn3vm9n1Jlleg=="],
"openai": ["openai@6.2.0", "", { "peerDependencies": { "ws": "^8.18.0", "zod": "^3.25 || ^4.0" }, "optionalPeers": ["ws", "zod"], "bin": { "openai": "bin/cli" } }, "sha512-qqjzHls7F5xkXNGy9P1Ei1rorI5LWupUUFWP66zPU8FlZbiITX8SFcHMKNZg/NATJ0LpIZcMUFxSwQmdeQPwSw=="],

"openapi-types": ["[email protected]", "", {}, "sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw=="],

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"lint-staged": "^15.2.0",
"mkdocs": "^0.0.1",
"msw": "^2.10.4",
"openai": "^5.7.0",
"openai": "^6.2.0",
"openapi-types": "^12.1.3",
"publint": "^0.3.12",
"tsdown": "^0.15.6",
Expand All @@ -65,7 +65,7 @@
},
"peerDependencies": {
"ai": "4.x|5.x",
"openai": "4.x|5.x"
"openai": "5.x|6.x"
},
"repository": {
"type": "git",
Expand Down
20 changes: 10 additions & 10 deletions src/tests/json-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,20 @@ describe('Schema Validation', () => {
expect(toolObj).toBeDefined();
expect(typeof toolObj.execute).toBe('function');

// Check that parameters and jsonSchema are properly structured
expect(toolObj.parameters).toBeDefined();
expect(toolObj.parameters.jsonSchema).toBeDefined();
expect(toolObj.parameters.jsonSchema.type).toBe('object');
expect(toolObj.parameters.jsonSchema.properties).toBeDefined();
// Check that inputSchema and jsonSchema are properly structured
expect(toolObj.inputSchema).toBeDefined();
expect(toolObj.inputSchema.jsonSchema).toBeDefined();
expect(toolObj.inputSchema.jsonSchema.type).toBe('object');
expect(toolObj.inputSchema.jsonSchema.properties).toBeDefined();

// Check array item properties specifically
// Using simpleArray which is defined in createArrayTestTool
const simpleArray = toolObj.parameters.jsonSchema.properties.simpleArray;
const simpleArray = toolObj.inputSchema.jsonSchema.properties.simpleArray;
expect(simpleArray).toBeDefined();
expect(simpleArray.type).toBe('array');

// Check that array with items is properly structured
const arrayWithItems = toolObj.parameters.jsonSchema.properties.arrayWithItems;
const arrayWithItems = toolObj.inputSchema.jsonSchema.properties.arrayWithItems;
expect(arrayWithItems).toBeDefined();
expect(arrayWithItems.type).toBe('array');
expect(arrayWithItems.items).toBeDefined();
Expand Down Expand Up @@ -310,11 +310,11 @@ describe('Schema Validation', () => {

const toolObj = aiSdkTool[tool.name];
expect(toolObj).toBeDefined();
expect(toolObj.parameters).toBeDefined();
expect(toolObj.parameters.jsonSchema).toBeDefined();
expect(toolObj.inputSchema).toBeDefined();
expect(toolObj.inputSchema.jsonSchema).toBeDefined();

// Specifically check the nested schema structure
const filterProp = toolObj.parameters.jsonSchema.properties.filter;
const filterProp = toolObj.inputSchema.jsonSchema.properties.filter;
expect(filterProp).toBeDefined();
expect(filterProp.type).toBe('object');
expect(filterProp.properties).toBeDefined();
Expand Down
14 changes: 7 additions & 7 deletions src/tests/tool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ describe('StackOneTool', () => {
expect(aiSdkTool.test_tool).toBeDefined();
expect(typeof aiSdkTool.test_tool.execute).toBe('function');
expect(aiSdkTool.test_tool.description).toBe('Test tool');
expect(aiSdkTool.test_tool.parameters).toBeDefined();
expect(aiSdkTool.test_tool.inputSchema).toBeDefined();

// The actual schema is in parameters.jsonSchema
const schema = aiSdkTool.test_tool.parameters.jsonSchema;
// The actual schema is in inputSchema.jsonSchema
const schema = aiSdkTool.test_tool.inputSchema.jsonSchema;
expect(schema).toBeDefined();
expect(schema.type).toBe('object');
expect(schema.properties.id).toBeDefined();
Expand Down Expand Up @@ -171,11 +171,11 @@ describe('StackOneTool', () => {
expect(aiSdkTool).toBeDefined();
expect(aiSdkTool.complex_tool).toBeDefined();

// Check that parameters are defined
expect(aiSdkTool.complex_tool.parameters).toBeDefined();
// Check that inputSchema is defined
expect(aiSdkTool.complex_tool.inputSchema).toBeDefined();

// The actual schema is in parameters.jsonSchema
const schema = aiSdkTool.complex_tool.parameters.jsonSchema;
// The actual schema is in inputSchema.jsonSchema
const schema = aiSdkTool.complex_tool.inputSchema.jsonSchema;
expect(schema).toBeDefined();
expect(schema.type).toBe('object');

Expand Down
12 changes: 7 additions & 5 deletions src/tool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as orama from '@orama/orama';
import { type ToolSet, jsonSchema } from 'ai';
import { jsonSchema } from 'ai';
import type { ChatCompletionTool } from 'openai/resources/chat/completions';
import { RequestBuilder } from './modules/requestBuilder';
import type {
Expand Down Expand Up @@ -185,16 +185,18 @@ export class BaseTool {
options: { executable?: boolean; execution?: ToolExecution | false } = {
executable: true,
}
): ToolSet {
) {
const schema = {
type: 'object' as const,
properties: this.parameters.properties || {},
required: this.parameters.required || [],
additionalProperties: false,
};

const schemaObject = jsonSchema(schema);
const toolDefinition: Record<string, unknown> = {
parameters: jsonSchema(schema),
inputSchema: schemaObject, // v5
parameters: schemaObject, // v4 (backward compatibility)
description: this.description,
};

Expand Down Expand Up @@ -348,8 +350,8 @@ export class Tools implements Iterable<BaseTool> {
options: { executable?: boolean; execution?: ToolExecution | false } = {
executable: true,
}
): ToolSet {
const result: ToolSet = {};
) {
const result: Record<string, unknown> = {};
for (const tool of this.tools) {
Object.assign(result, tool.toAISDK(options));
}
Expand Down
2 changes: 1 addition & 1 deletion src/toolsets/tests/stackone.mcp-fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('ToolSet.fetchTools (MCP + RPC integration)', () => {
const aiToolDefinition = aiTools.dummy_action;
expect(aiToolDefinition).toBeDefined();
expect(aiToolDefinition.description).toBe('Dummy tool');
expect(aiToolDefinition.parameters.jsonSchema.properties.foo.type).toBe('string');
expect(aiToolDefinition.inputSchema.jsonSchema.properties.foo.type).toBe('string');
expect(aiToolDefinition.execution).toBeUndefined();

const executableTool = tool.toAISDK().dummy_action;
Expand Down
Loading