(inputSchema: unknown)
| 26 | }; |
| 27 | |
| 28 | function jsonSchemaToToolSchemaShape(inputSchema: unknown): ToolSchemaShape { |
| 29 | if (!inputSchema || typeof inputSchema !== 'object') { |
| 30 | return {}; |
| 31 | } |
| 32 | |
| 33 | const schema = inputSchema as JsonSchemaObject; |
| 34 | const properties = schema.properties; |
| 35 | if (!properties || typeof properties !== 'object' || Array.isArray(properties)) { |
| 36 | return {}; |
| 37 | } |
| 38 | |
| 39 | const requiredFields = new Set( |
| 40 | Array.isArray(schema.required) |
| 41 | ? schema.required.filter((name): name is string => typeof name === 'string') |
| 42 | : [], |
| 43 | ); |
| 44 | |
| 45 | const shape: ToolSchemaShape = {}; |
| 46 | for (const [name, propertySchema] of Object.entries(properties)) { |
| 47 | const zodSchema = jsonSchemaToZod(propertySchema); |
| 48 | shape[name] = requiredFields.has(name) ? zodSchema : zodSchema.optional(); |
| 49 | } |
| 50 | |
| 51 | return shape; |
| 52 | } |
| 53 | |
| 54 | async function invokeRemoteToolOneShot( |
| 55 | remoteToolName: string, |
no test coverage detected