Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 45 lines 1.74 KB
Raw
1 import { zodSchema } from '@ai-sdk/provider-utils';
2 import { toJsonSchema } from '@langchain/core/utils/json_schema';
3 import { describe, expect, it } from 'vitest';
4
5 import { jsonSchemaToZod } from '../../src/v4';
6 import type { JsonSchema } from '../../src/types';
7
8 type Json = Record<string, unknown>;
9
10 const tool: JsonSchema = {
11 type: 'object',
12 description: 'Upload',
13 properties: {
14 file: { type: 'string', format: 'binary', description: 'The bytes' },
15 name: { type: 'string', default: 'upload.bin' },
16 retries: { type: 'integer', minimum: 0 },
17 },
18 required: ['file'],
19 };
20
21 describe('v4 schemas in frameworks', () => {
22 it('keeps the annotations through the AI SDK schema wrapper', () => {
23 const json = zodSchema(jsonSchemaToZod(tool)).jsonSchema as Json;
24 const properties = json.properties as Record<string, Json>;
25 expect(json.description).toBe('Upload');
26 expect(properties.file).toMatchObject({
27 type: 'string',
28 format: 'binary',
29 description: 'The bytes',
30 });
31 expect(properties.name).toMatchObject({ type: 'string', default: 'upload.bin' });
32 expect(properties.retries).toMatchObject({ type: 'integer', minimum: 0 });
33 expect(json.required).toEqual(['file']);
34 });
35
36 it('renders the output side for LangChain, where defaulted fields are required', () => {
37 const json = toJsonSchema(jsonSchemaToZod(tool)) as Json;
38 const properties = json.properties as Record<string, Json>;
39 expect(json.description).toBe('Upload');
40 expect(properties.file).toMatchObject({ type: 'string', format: 'binary' });
41 expect(properties.retries).toMatchObject({ type: 'integer', minimum: 0 });
42 expect(properties.name).not.toHaveProperty('default');
43 expect(json.required).toEqual(['file', 'name']);
44 });
45 });