67 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-03-21 10:58:58 -07:00
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { ImageContent, TextContent } from '@modelcontextprotocol/sdk/types';
import type { z } from 'zod';
2025-03-21 10:58:58 -07:00
import type { Context } from '../context';
2025-04-16 15:21:45 -07:00
import type * as playwright from 'playwright';
export type ToolCapability = 'core' | 'tabs' | 'pdf' | 'history' | 'wait' | 'files' | 'install';
export type ToolSchema<Input extends InputType> = {
2025-03-21 10:58:58 -07:00
name: string;
description: string;
inputSchema: Input;
2025-03-21 10:58:58 -07:00
};
type InputType = z.Schema;
2025-04-16 15:21:45 -07:00
export type FileUploadModalState = {
type: 'fileChooser';
description: string;
fileChooser: playwright.FileChooser;
};
2025-04-17 14:03:13 -07:00
export type DialogModalState = {
type: 'dialog';
description: string;
dialog: playwright.Dialog;
};
export type ModalState = FileUploadModalState | DialogModalState;
export type ToolActionResult = { content?: (ImageContent | TextContent)[] } | undefined | void;
2025-04-16 15:21:45 -07:00
2025-03-21 10:58:58 -07:00
export type ToolResult = {
code: string[];
2025-04-17 14:03:13 -07:00
action?: () => Promise<ToolActionResult>;
captureSnapshot: boolean;
waitForNetwork: boolean;
2025-04-17 14:03:13 -07:00
resultOverride?: ToolActionResult;
2025-03-21 10:58:58 -07:00
};
export type Tool<Input extends InputType = InputType> = {
capability: ToolCapability;
schema: ToolSchema<Input>;
2025-04-16 15:21:45 -07:00
clearsModalState?: ModalState['type'];
handle: (context: Context, params: z.output<Input>) => Promise<ToolResult>;
2025-03-21 10:58:58 -07:00
};
export type ToolFactory = (snapshot: boolean) => Tool<any>;
export function defineTool<Input extends InputType>(tool: Tool<Input>): Tool<Input> {
return tool;
}