chore: tool definition without zod (#873)

This commit is contained in:
Yury Semikhatsky
2025-08-12 13:19:25 -07:00
committed by GitHub
parent 53c6b6dcb1
commit 7c4d67b3ae
8 changed files with 77 additions and 77 deletions

View File

@@ -14,13 +14,15 @@
* limitations under the License.
*/
import { zodToJsonSchema } from 'zod-to-json-schema';
import type { z } from 'zod';
import type { Context } from '../context.js';
import type * as playwright from 'playwright';
import type { ToolCapability } from '../../config.js';
import type { Tab } from '../tab.js';
import type { Response } from '../response.js';
import type { ToolSchema } from '../mcp/server.js';
import type { ToolDefinition } from '../mcp/server.js';
export type FileUploadModalState = {
type: 'fileChooser';
@@ -36,6 +38,28 @@ export type DialogModalState = {
export type ModalState = FileUploadModalState | DialogModalState;
export type ToolSchema<Input extends z.Schema> = {
name: string;
title: string;
description: string;
inputSchema: Input;
type: 'readOnly' | 'destructive';
};
export function toToolDefinition(tool: ToolSchema<any>): ToolDefinition {
return {
name: tool.name,
description: tool.description,
inputSchema: zodToJsonSchema(tool.inputSchema, { strictUnions: true }) as ToolDefinition['inputSchema'],
annotations: {
title: tool.title,
readOnlyHint: tool.type === 'readOnly',
destructiveHint: tool.type === 'destructive',
openWorldHint: true,
},
};
}
export type Tool<Input extends z.Schema = z.Schema> = {
capability: ToolCapability;
schema: ToolSchema<Input>;