1
>
/*---------------------------------------------------------------------------------------------
claudeJsonSchemaToZod.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { z, type ZodTypeAny } from 'zod';
7
>
import type { ToolDefinition } from '../../../common/state/protocol/state.js';
8
>
9
>
/**
10
>
* Converts the narrow JSON Schema subset that
11
>
* {@link ToolDefinition.inputSchema} carries into the `Record<string, ZodType>`
12
>
* "raw shape" expected by the Anthropic SDK's `tool()` factory
13
>
* (`AnyZodRawShape`).
14
>
*
15
>
* Per-property failures fall back to {@link z.any} so a single malformed
16
>
* property never rejects an entire tool — clients always get *some* tool
17
>
* surface to bind against.
18
>
*/
19
>
export function jsonSchemaToZodRawShape(
20
inputSchema: ToolDefinition['inputSchema'] | undefined
21
): Record<string, ZodTypeAny> {