chore: introduce capabilities argument (#135)
This commit is contained in:
@@ -24,6 +24,7 @@ const waitSchema = z.object({
|
||||
});
|
||||
|
||||
const wait: Tool = {
|
||||
capability: 'wait',
|
||||
schema: {
|
||||
name: 'browser_wait',
|
||||
description: 'Wait for a specified time in seconds',
|
||||
@@ -44,6 +45,7 @@ const wait: Tool = {
|
||||
const closeSchema = z.object({});
|
||||
|
||||
const close: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_close',
|
||||
description: 'Close the page',
|
||||
|
||||
@@ -19,18 +19,19 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
|
||||
|
||||
import type { ToolFactory } from './tool';
|
||||
|
||||
const chooseFileSchema = z.object({
|
||||
const uploadFileSchema = z.object({
|
||||
paths: z.array(z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'),
|
||||
});
|
||||
|
||||
const chooseFile: ToolFactory = captureSnapshot => ({
|
||||
const uploadFile: ToolFactory = captureSnapshot => ({
|
||||
capability: 'files',
|
||||
schema: {
|
||||
name: 'browser_choose_file',
|
||||
description: 'Choose one or multiple files to upload',
|
||||
inputSchema: zodToJsonSchema(chooseFileSchema),
|
||||
name: 'browser_file_upload',
|
||||
description: 'Upload one or multiple files',
|
||||
inputSchema: zodToJsonSchema(uploadFileSchema),
|
||||
},
|
||||
handle: async (context, params) => {
|
||||
const validatedParams = chooseFileSchema.parse(params);
|
||||
const validatedParams = uploadFileSchema.parse(params);
|
||||
const tab = context.currentTab();
|
||||
return await tab.runAndWait(async () => {
|
||||
await tab.submitFileChooser(validatedParams.paths);
|
||||
@@ -43,5 +44,5 @@ const chooseFile: ToolFactory = captureSnapshot => ({
|
||||
});
|
||||
|
||||
export default (captureSnapshot: boolean) => [
|
||||
chooseFile(captureSnapshot),
|
||||
uploadFile(captureSnapshot),
|
||||
];
|
||||
@@ -23,6 +23,7 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
|
||||
import type { Tool } from './tool';
|
||||
|
||||
const install: Tool = {
|
||||
capability: 'install',
|
||||
schema: {
|
||||
name: 'browser_install',
|
||||
description: 'Install the browser specified in the config. Call this if you get an error about the browser not being installed.',
|
||||
|
||||
@@ -24,6 +24,7 @@ const pressKeySchema = z.object({
|
||||
});
|
||||
|
||||
const pressKey: ToolFactory = captureSnapshot => ({
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_press_key',
|
||||
description: 'Press a key on the keyboard',
|
||||
|
||||
@@ -24,6 +24,7 @@ const navigateSchema = z.object({
|
||||
});
|
||||
|
||||
const navigate: ToolFactory = captureSnapshot => ({
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_navigate',
|
||||
description: 'Navigate to a URL',
|
||||
@@ -44,6 +45,7 @@ const navigate: ToolFactory = captureSnapshot => ({
|
||||
const goBackSchema = z.object({});
|
||||
|
||||
const goBack: ToolFactory = snapshot => ({
|
||||
capability: 'history',
|
||||
schema: {
|
||||
name: 'browser_navigate_back',
|
||||
description: 'Go back to the previous page',
|
||||
@@ -62,6 +64,7 @@ const goBack: ToolFactory = snapshot => ({
|
||||
const goForwardSchema = z.object({});
|
||||
|
||||
const goForward: ToolFactory = snapshot => ({
|
||||
capability: 'history',
|
||||
schema: {
|
||||
name: 'browser_navigate_forward',
|
||||
description: 'Go forward to the next page',
|
||||
|
||||
@@ -27,6 +27,7 @@ import type { Tool } from './tool';
|
||||
const pdfSchema = z.object({});
|
||||
|
||||
const pdf: Tool = {
|
||||
capability: 'pdf',
|
||||
schema: {
|
||||
name: 'browser_pdf_save',
|
||||
description: 'Save page as PDF',
|
||||
|
||||
@@ -20,6 +20,7 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
|
||||
import type { Tool } from './tool';
|
||||
|
||||
const screenshot: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_screen_capture',
|
||||
description: 'Take a screenshot of the current page',
|
||||
@@ -45,6 +46,7 @@ const moveMouseSchema = elementSchema.extend({
|
||||
});
|
||||
|
||||
const moveMouse: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_screen_move_mouse',
|
||||
description: 'Move mouse to a given position',
|
||||
@@ -67,6 +69,7 @@ const clickSchema = elementSchema.extend({
|
||||
});
|
||||
|
||||
const click: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_screen_click',
|
||||
description: 'Click left mouse button',
|
||||
@@ -93,6 +96,7 @@ const dragSchema = elementSchema.extend({
|
||||
});
|
||||
|
||||
const drag: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_screen_drag',
|
||||
description: 'Drag left mouse button',
|
||||
@@ -118,6 +122,7 @@ const typeSchema = z.object({
|
||||
});
|
||||
|
||||
const type: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_screen_type',
|
||||
description: 'Type text',
|
||||
|
||||
@@ -21,6 +21,7 @@ import type * as playwright from 'playwright';
|
||||
import type { Tool } from './tool';
|
||||
|
||||
const snapshot: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_snapshot',
|
||||
description: 'Capture accessibility snapshot of the current page, this is better than screenshot',
|
||||
@@ -38,6 +39,7 @@ const elementSchema = z.object({
|
||||
});
|
||||
|
||||
const click: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_click',
|
||||
description: 'Perform click on a web page',
|
||||
@@ -63,6 +65,7 @@ const dragSchema = z.object({
|
||||
});
|
||||
|
||||
const drag: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_drag',
|
||||
description: 'Perform drag and drop between two elements',
|
||||
@@ -82,6 +85,7 @@ const drag: Tool = {
|
||||
};
|
||||
|
||||
const hover: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_hover',
|
||||
description: 'Hover over element on page',
|
||||
@@ -106,6 +110,7 @@ const typeSchema = elementSchema.extend({
|
||||
});
|
||||
|
||||
const type: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_type',
|
||||
description: 'Type text into editable element',
|
||||
@@ -133,6 +138,7 @@ const selectOptionSchema = elementSchema.extend({
|
||||
});
|
||||
|
||||
const selectOption: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_select_option',
|
||||
description: 'Select an option in a dropdown',
|
||||
@@ -155,6 +161,7 @@ const screenshotSchema = z.object({
|
||||
});
|
||||
|
||||
const screenshot: Tool = {
|
||||
capability: 'core',
|
||||
schema: {
|
||||
name: 'browser_take_screenshot',
|
||||
description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
|
||||
|
||||
@@ -20,6 +20,7 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
|
||||
import type { ToolFactory, Tool } from './tool';
|
||||
|
||||
const listTabs: Tool = {
|
||||
capability: 'tabs',
|
||||
schema: {
|
||||
name: 'browser_tab_list',
|
||||
description: 'List browser tabs',
|
||||
@@ -40,6 +41,7 @@ const selectTabSchema = z.object({
|
||||
});
|
||||
|
||||
const selectTab: ToolFactory = captureSnapshot => ({
|
||||
capability: 'tabs',
|
||||
schema: {
|
||||
name: 'browser_tab_select',
|
||||
description: 'Select a tab by index',
|
||||
@@ -58,6 +60,7 @@ const newTabSchema = z.object({
|
||||
});
|
||||
|
||||
const newTab: Tool = {
|
||||
capability: 'tabs',
|
||||
schema: {
|
||||
name: 'browser_tab_new',
|
||||
description: 'Open a new tab',
|
||||
@@ -77,6 +80,7 @@ const closeTabSchema = z.object({
|
||||
});
|
||||
|
||||
const closeTab: ToolFactory = captureSnapshot => ({
|
||||
capability: 'tabs',
|
||||
schema: {
|
||||
name: 'browser_tab_close',
|
||||
description: 'Close a tab',
|
||||
|
||||
@@ -18,6 +18,8 @@ import type { ImageContent, TextContent } from '@modelcontextprotocol/sdk/types'
|
||||
import type { JsonSchema7Type } from 'zod-to-json-schema';
|
||||
import type { Context } from '../context';
|
||||
|
||||
export type ToolCapability = 'core' | 'tabs' | 'pdf' | 'history' | 'wait' | 'files' | 'install';
|
||||
|
||||
export type ToolSchema = {
|
||||
name: string;
|
||||
description: string;
|
||||
@@ -30,6 +32,7 @@ export type ToolResult = {
|
||||
};
|
||||
|
||||
export type Tool = {
|
||||
capability: ToolCapability;
|
||||
schema: ToolSchema;
|
||||
handle: (context: Context, params?: Record<string, any>) => Promise<ToolResult>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user