@playwright/mcp 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,14 +49,17 @@ var __importStar = (this && this.__importStar) || (function () {
49
49
  })();
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
51
  const zod_1 = require("zod");
52
- const zod_to_json_schema_1 = require("zod-to-json-schema");
52
+ const tool_1 = require("./tool");
53
53
  const javascript = __importStar(require("../javascript"));
54
- const screenshot = {
54
+ const elementSchema = zod_1.z.object({
55
+ element: zod_1.z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
56
+ });
57
+ const screenshot = (0, tool_1.defineTool)({
55
58
  capability: 'core',
56
59
  schema: {
57
60
  name: 'browser_screen_capture',
58
61
  description: 'Take a screenshot of the current page',
59
- inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(zod_1.z.object({})),
62
+ inputSchema: zod_1.z.object({}),
60
63
  },
61
64
  handle: async (context) => {
62
65
  const tab = await context.ensureTab();
@@ -77,29 +80,24 @@ const screenshot = {
77
80
  waitForNetwork: false
78
81
  };
79
82
  },
80
- };
81
- const elementSchema = zod_1.z.object({
82
- element: zod_1.z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
83
- });
84
- const moveMouseSchema = elementSchema.extend({
85
- x: zod_1.z.number().describe('X coordinate'),
86
- y: zod_1.z.number().describe('Y coordinate'),
87
83
  });
88
- const moveMouse = {
84
+ const moveMouse = (0, tool_1.defineTool)({
89
85
  capability: 'core',
90
86
  schema: {
91
87
  name: 'browser_screen_move_mouse',
92
88
  description: 'Move mouse to a given position',
93
- inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(moveMouseSchema),
89
+ inputSchema: elementSchema.extend({
90
+ x: zod_1.z.number().describe('X coordinate'),
91
+ y: zod_1.z.number().describe('Y coordinate'),
92
+ }),
94
93
  },
95
94
  handle: async (context, params) => {
96
- const validatedParams = moveMouseSchema.parse(params);
97
95
  const tab = context.currentTabOrDie();
98
96
  const code = [
99
- `// Move mouse to (${validatedParams.x}, ${validatedParams.y})`,
100
- `await page.mouse.move(${validatedParams.x}, ${validatedParams.y});`,
97
+ `// Move mouse to (${params.x}, ${params.y})`,
98
+ `await page.mouse.move(${params.x}, ${params.y});`,
101
99
  ];
102
- const action = () => tab.page.mouse.move(validatedParams.x, validatedParams.y);
100
+ const action = () => tab.page.mouse.move(params.x, params.y);
103
101
  return {
104
102
  code,
105
103
  action,
@@ -107,29 +105,27 @@ const moveMouse = {
107
105
  waitForNetwork: false
108
106
  };
109
107
  },
110
- };
111
- const clickSchema = elementSchema.extend({
112
- x: zod_1.z.number().describe('X coordinate'),
113
- y: zod_1.z.number().describe('Y coordinate'),
114
108
  });
115
- const click = {
109
+ const click = (0, tool_1.defineTool)({
116
110
  capability: 'core',
117
111
  schema: {
118
112
  name: 'browser_screen_click',
119
113
  description: 'Click left mouse button',
120
- inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(clickSchema),
114
+ inputSchema: elementSchema.extend({
115
+ x: zod_1.z.number().describe('X coordinate'),
116
+ y: zod_1.z.number().describe('Y coordinate'),
117
+ }),
121
118
  },
122
119
  handle: async (context, params) => {
123
- const validatedParams = clickSchema.parse(params);
124
120
  const tab = context.currentTabOrDie();
125
121
  const code = [
126
- `// Click mouse at coordinates (${validatedParams.x}, ${validatedParams.y})`,
127
- `await page.mouse.move(${validatedParams.x}, ${validatedParams.y});`,
122
+ `// Click mouse at coordinates (${params.x}, ${params.y})`,
123
+ `await page.mouse.move(${params.x}, ${params.y});`,
128
124
  `await page.mouse.down();`,
129
125
  `await page.mouse.up();`,
130
126
  ];
131
127
  const action = async () => {
132
- await tab.page.mouse.move(validatedParams.x, validatedParams.y);
128
+ await tab.page.mouse.move(params.x, params.y);
133
129
  await tab.page.mouse.down();
134
130
  await tab.page.mouse.up();
135
131
  };
@@ -140,34 +136,32 @@ const click = {
140
136
  waitForNetwork: true,
141
137
  };
142
138
  },
143
- };
144
- const dragSchema = elementSchema.extend({
145
- startX: zod_1.z.number().describe('Start X coordinate'),
146
- startY: zod_1.z.number().describe('Start Y coordinate'),
147
- endX: zod_1.z.number().describe('End X coordinate'),
148
- endY: zod_1.z.number().describe('End Y coordinate'),
149
139
  });
150
- const drag = {
140
+ const drag = (0, tool_1.defineTool)({
151
141
  capability: 'core',
152
142
  schema: {
153
143
  name: 'browser_screen_drag',
154
144
  description: 'Drag left mouse button',
155
- inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(dragSchema),
145
+ inputSchema: elementSchema.extend({
146
+ startX: zod_1.z.number().describe('Start X coordinate'),
147
+ startY: zod_1.z.number().describe('Start Y coordinate'),
148
+ endX: zod_1.z.number().describe('End X coordinate'),
149
+ endY: zod_1.z.number().describe('End Y coordinate'),
150
+ }),
156
151
  },
157
152
  handle: async (context, params) => {
158
- const validatedParams = dragSchema.parse(params);
159
153
  const tab = context.currentTabOrDie();
160
154
  const code = [
161
- `// Drag mouse from (${validatedParams.startX}, ${validatedParams.startY}) to (${validatedParams.endX}, ${validatedParams.endY})`,
162
- `await page.mouse.move(${validatedParams.startX}, ${validatedParams.startY});`,
155
+ `// Drag mouse from (${params.startX}, ${params.startY}) to (${params.endX}, ${params.endY})`,
156
+ `await page.mouse.move(${params.startX}, ${params.startY});`,
163
157
  `await page.mouse.down();`,
164
- `await page.mouse.move(${validatedParams.endX}, ${validatedParams.endY});`,
158
+ `await page.mouse.move(${params.endX}, ${params.endY});`,
165
159
  `await page.mouse.up();`,
166
160
  ];
167
161
  const action = async () => {
168
- await tab.page.mouse.move(validatedParams.startX, validatedParams.startY);
162
+ await tab.page.mouse.move(params.startX, params.startY);
169
163
  await tab.page.mouse.down();
170
- await tab.page.mouse.move(validatedParams.endX, validatedParams.endY);
164
+ await tab.page.mouse.move(params.endX, params.endY);
171
165
  await tab.page.mouse.up();
172
166
  };
173
167
  return {
@@ -177,31 +171,29 @@ const drag = {
177
171
  waitForNetwork: true,
178
172
  };
179
173
  },
180
- };
181
- const typeSchema = zod_1.z.object({
182
- text: zod_1.z.string().describe('Text to type into the element'),
183
- submit: zod_1.z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
184
174
  });
185
- const type = {
175
+ const type = (0, tool_1.defineTool)({
186
176
  capability: 'core',
187
177
  schema: {
188
178
  name: 'browser_screen_type',
189
179
  description: 'Type text',
190
- inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(typeSchema),
180
+ inputSchema: zod_1.z.object({
181
+ text: zod_1.z.string().describe('Text to type into the element'),
182
+ submit: zod_1.z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
183
+ }),
191
184
  },
192
185
  handle: async (context, params) => {
193
- const validatedParams = typeSchema.parse(params);
194
186
  const tab = context.currentTabOrDie();
195
187
  const code = [
196
- `// Type ${validatedParams.text}`,
197
- `await page.keyboard.type('${validatedParams.text}');`,
188
+ `// Type ${params.text}`,
189
+ `await page.keyboard.type('${params.text}');`,
198
190
  ];
199
191
  const action = async () => {
200
- await tab.page.keyboard.type(validatedParams.text);
201
- if (validatedParams.submit)
192
+ await tab.page.keyboard.type(params.text);
193
+ if (params.submit)
202
194
  await tab.page.keyboard.press('Enter');
203
195
  };
204
- if (validatedParams.submit) {
196
+ if (params.submit) {
205
197
  code.push(`// Submit text`);
206
198
  code.push(`await page.keyboard.press('Enter');`);
207
199
  }
@@ -212,7 +204,7 @@ const type = {
212
204
  waitForNetwork: true,
213
205
  };
214
206
  },
215
- };
207
+ });
216
208
  exports.default = [
217
209
  screenshot,
218
210
  moveMouse,
@@ -47,23 +47,18 @@ var __importStar = (this && this.__importStar) || (function () {
47
47
  return result;
48
48
  };
49
49
  })();
50
- var __importDefault = (this && this.__importDefault) || function (mod) {
51
- return (mod && mod.__esModule) ? mod : { "default": mod };
52
- };
53
50
  Object.defineProperty(exports, "__esModule", { value: true });
54
- const path_1 = __importDefault(require("path"));
55
- const os_1 = __importDefault(require("os"));
51
+ exports.generateLocator = generateLocator;
56
52
  const zod_1 = require("zod");
57
- const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
58
- const utils_1 = require("./utils");
59
- const context_1 = require("../context");
53
+ const tool_1 = require("./tool");
60
54
  const javascript = __importStar(require("../javascript"));
61
- const snapshot = {
55
+ const config_1 = require("../config");
56
+ const snapshot = (0, tool_1.defineTool)({
62
57
  capability: 'core',
63
58
  schema: {
64
59
  name: 'browser_snapshot',
65
60
  description: 'Capture accessibility snapshot of the current page, this is better than screenshot',
66
- inputSchema: (0, zod_to_json_schema_1.default)(zod_1.z.object({})),
61
+ inputSchema: zod_1.z.object({}),
67
62
  },
68
63
  handle: async (context) => {
69
64
  await context.ensureTab();
@@ -73,25 +68,24 @@ const snapshot = {
73
68
  waitForNetwork: false,
74
69
  };
75
70
  },
76
- };
71
+ });
77
72
  const elementSchema = zod_1.z.object({
78
73
  element: zod_1.z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
79
74
  ref: zod_1.z.string().describe('Exact target element reference from the page snapshot'),
80
75
  });
81
- const click = {
76
+ const click = (0, tool_1.defineTool)({
82
77
  capability: 'core',
83
78
  schema: {
84
79
  name: 'browser_click',
85
80
  description: 'Perform click on a web page',
86
- inputSchema: (0, zod_to_json_schema_1.default)(elementSchema),
81
+ inputSchema: elementSchema,
87
82
  },
88
83
  handle: async (context, params) => {
89
- const validatedParams = elementSchema.parse(params);
90
84
  const tab = context.currentTabOrDie();
91
- const locator = tab.snapshotOrDie().refLocator(validatedParams.ref);
85
+ const locator = tab.snapshotOrDie().refLocator(params.ref);
92
86
  const code = [
93
- `// Click ${validatedParams.element}`,
94
- `await page.${await (0, context_1.generateLocator)(locator)}.click();`
87
+ `// Click ${params.element}`,
88
+ `await page.${await generateLocator(locator)}.click();`
95
89
  ];
96
90
  return {
97
91
  code,
@@ -100,28 +94,26 @@ const click = {
100
94
  waitForNetwork: true,
101
95
  };
102
96
  },
103
- };
104
- const dragSchema = zod_1.z.object({
105
- startElement: zod_1.z.string().describe('Human-readable source element description used to obtain the permission to interact with the element'),
106
- startRef: zod_1.z.string().describe('Exact source element reference from the page snapshot'),
107
- endElement: zod_1.z.string().describe('Human-readable target element description used to obtain the permission to interact with the element'),
108
- endRef: zod_1.z.string().describe('Exact target element reference from the page snapshot'),
109
97
  });
110
- const drag = {
98
+ const drag = (0, tool_1.defineTool)({
111
99
  capability: 'core',
112
100
  schema: {
113
101
  name: 'browser_drag',
114
102
  description: 'Perform drag and drop between two elements',
115
- inputSchema: (0, zod_to_json_schema_1.default)(dragSchema),
103
+ inputSchema: zod_1.z.object({
104
+ startElement: zod_1.z.string().describe('Human-readable source element description used to obtain the permission to interact with the element'),
105
+ startRef: zod_1.z.string().describe('Exact source element reference from the page snapshot'),
106
+ endElement: zod_1.z.string().describe('Human-readable target element description used to obtain the permission to interact with the element'),
107
+ endRef: zod_1.z.string().describe('Exact target element reference from the page snapshot'),
108
+ }),
116
109
  },
117
110
  handle: async (context, params) => {
118
- const validatedParams = dragSchema.parse(params);
119
111
  const snapshot = context.currentTabOrDie().snapshotOrDie();
120
- const startLocator = snapshot.refLocator(validatedParams.startRef);
121
- const endLocator = snapshot.refLocator(validatedParams.endRef);
112
+ const startLocator = snapshot.refLocator(params.startRef);
113
+ const endLocator = snapshot.refLocator(params.endRef);
122
114
  const code = [
123
- `// Drag ${validatedParams.startElement} to ${validatedParams.endElement}`,
124
- `await page.${await (0, context_1.generateLocator)(startLocator)}.dragTo(page.${await (0, context_1.generateLocator)(endLocator)});`
115
+ `// Drag ${params.startElement} to ${params.endElement}`,
116
+ `await page.${await generateLocator(startLocator)}.dragTo(page.${await generateLocator(endLocator)});`
125
117
  ];
126
118
  return {
127
119
  code,
@@ -130,21 +122,20 @@ const drag = {
130
122
  waitForNetwork: true,
131
123
  };
132
124
  },
133
- };
134
- const hover = {
125
+ });
126
+ const hover = (0, tool_1.defineTool)({
135
127
  capability: 'core',
136
128
  schema: {
137
129
  name: 'browser_hover',
138
130
  description: 'Hover over element on page',
139
- inputSchema: (0, zod_to_json_schema_1.default)(elementSchema),
131
+ inputSchema: elementSchema,
140
132
  },
141
133
  handle: async (context, params) => {
142
- const validatedParams = elementSchema.parse(params);
143
134
  const snapshot = context.currentTabOrDie().snapshotOrDie();
144
- const locator = snapshot.refLocator(validatedParams.ref);
135
+ const locator = snapshot.refLocator(params.ref);
145
136
  const code = [
146
- `// Hover over ${validatedParams.element}`,
147
- `await page.${await (0, context_1.generateLocator)(locator)}.hover();`
137
+ `// Hover over ${params.element}`,
138
+ `await page.${await generateLocator(locator)}.hover();`
148
139
  ];
149
140
  return {
150
141
  code,
@@ -153,38 +144,37 @@ const hover = {
153
144
  waitForNetwork: true,
154
145
  };
155
146
  },
156
- };
147
+ });
157
148
  const typeSchema = elementSchema.extend({
158
149
  text: zod_1.z.string().describe('Text to type into the element'),
159
150
  submit: zod_1.z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
160
151
  slowly: zod_1.z.boolean().optional().describe('Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.'),
161
152
  });
162
- const type = {
153
+ const type = (0, tool_1.defineTool)({
163
154
  capability: 'core',
164
155
  schema: {
165
156
  name: 'browser_type',
166
157
  description: 'Type text into editable element',
167
- inputSchema: (0, zod_to_json_schema_1.default)(typeSchema),
158
+ inputSchema: typeSchema,
168
159
  },
169
160
  handle: async (context, params) => {
170
- const validatedParams = typeSchema.parse(params);
171
161
  const snapshot = context.currentTabOrDie().snapshotOrDie();
172
- const locator = snapshot.refLocator(validatedParams.ref);
162
+ const locator = snapshot.refLocator(params.ref);
173
163
  const code = [];
174
164
  const steps = [];
175
- if (validatedParams.slowly) {
176
- code.push(`// Press "${validatedParams.text}" sequentially into "${validatedParams.element}"`);
177
- code.push(`await page.${await (0, context_1.generateLocator)(locator)}.pressSequentially(${javascript.quote(validatedParams.text)});`);
178
- steps.push(() => locator.pressSequentially(validatedParams.text));
165
+ if (params.slowly) {
166
+ code.push(`// Press "${params.text}" sequentially into "${params.element}"`);
167
+ code.push(`await page.${await generateLocator(locator)}.pressSequentially(${javascript.quote(params.text)});`);
168
+ steps.push(() => locator.pressSequentially(params.text));
179
169
  }
180
170
  else {
181
- code.push(`// Fill "${validatedParams.text}" into "${validatedParams.element}"`);
182
- code.push(`await page.${await (0, context_1.generateLocator)(locator)}.fill(${javascript.quote(validatedParams.text)});`);
183
- steps.push(() => locator.fill(validatedParams.text));
171
+ code.push(`// Fill "${params.text}" into "${params.element}"`);
172
+ code.push(`await page.${await generateLocator(locator)}.fill(${javascript.quote(params.text)});`);
173
+ steps.push(() => locator.fill(params.text));
184
174
  }
185
- if (validatedParams.submit) {
175
+ if (params.submit) {
186
176
  code.push(`// Submit text`);
187
- code.push(`await page.${await (0, context_1.generateLocator)(locator)}.press('Enter');`);
177
+ code.push(`await page.${await generateLocator(locator)}.press('Enter');`);
188
178
  steps.push(() => locator.press('Enter'));
189
179
  }
190
180
  return {
@@ -194,33 +184,32 @@ const type = {
194
184
  waitForNetwork: true,
195
185
  };
196
186
  },
197
- };
187
+ });
198
188
  const selectOptionSchema = elementSchema.extend({
199
189
  values: zod_1.z.array(zod_1.z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'),
200
190
  });
201
- const selectOption = {
191
+ const selectOption = (0, tool_1.defineTool)({
202
192
  capability: 'core',
203
193
  schema: {
204
194
  name: 'browser_select_option',
205
195
  description: 'Select an option in a dropdown',
206
- inputSchema: (0, zod_to_json_schema_1.default)(selectOptionSchema),
196
+ inputSchema: selectOptionSchema,
207
197
  },
208
198
  handle: async (context, params) => {
209
- const validatedParams = selectOptionSchema.parse(params);
210
199
  const snapshot = context.currentTabOrDie().snapshotOrDie();
211
- const locator = snapshot.refLocator(validatedParams.ref);
200
+ const locator = snapshot.refLocator(params.ref);
212
201
  const code = [
213
- `// Select options [${validatedParams.values.join(', ')}] in ${validatedParams.element}`,
214
- `await page.${await (0, context_1.generateLocator)(locator)}.selectOption(${javascript.formatObject(validatedParams.values)});`
202
+ `// Select options [${params.values.join(', ')}] in ${params.element}`,
203
+ `await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(params.values)});`
215
204
  ];
216
205
  return {
217
206
  code,
218
- action: () => locator.selectOption(validatedParams.values).then(() => { }),
207
+ action: () => locator.selectOption(params.values).then(() => { }),
219
208
  captureSnapshot: true,
220
209
  waitForNetwork: true,
221
210
  };
222
211
  },
223
- };
212
+ });
224
213
  const screenshotSchema = zod_1.z.object({
225
214
  raw: zod_1.z.boolean().optional().describe('Whether to return without compression (in PNG format). Default is false, which returns a JPEG image.'),
226
215
  element: zod_1.z.string().optional().describe('Human-readable element description used to obtain permission to screenshot the element. If not provided, the screenshot will be taken of viewport. If element is provided, ref must be provided too.'),
@@ -231,37 +220,37 @@ const screenshotSchema = zod_1.z.object({
231
220
  message: 'Both element and ref must be provided or neither.',
232
221
  path: ['ref', 'element']
233
222
  });
234
- const screenshot = {
223
+ const screenshot = (0, tool_1.defineTool)({
235
224
  capability: 'core',
236
225
  schema: {
237
226
  name: 'browser_take_screenshot',
238
227
  description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
239
- inputSchema: (0, zod_to_json_schema_1.default)(screenshotSchema),
228
+ inputSchema: screenshotSchema,
240
229
  },
241
230
  handle: async (context, params) => {
242
- const validatedParams = screenshotSchema.parse(params);
243
231
  const tab = context.currentTabOrDie();
244
232
  const snapshot = tab.snapshotOrDie();
245
- const fileType = validatedParams.raw ? 'png' : 'jpeg';
246
- const fileName = path_1.default.join(os_1.default.tmpdir(), (0, utils_1.sanitizeForFilePath)(`page-${new Date().toISOString()}`)) + `.${fileType}`;
233
+ const fileType = params.raw ? 'png' : 'jpeg';
234
+ const fileName = await (0, config_1.outputFile)(context.config, `page-${new Date().toISOString()}.${fileType}`);
247
235
  const options = { type: fileType, quality: fileType === 'png' ? undefined : 50, scale: 'css', path: fileName };
248
- const isElementScreenshot = validatedParams.element && validatedParams.ref;
236
+ const isElementScreenshot = params.element && params.ref;
249
237
  const code = [
250
- `// Screenshot ${isElementScreenshot ? validatedParams.element : 'viewport'} and save it as ${fileName}`,
238
+ `// Screenshot ${isElementScreenshot ? params.element : 'viewport'} and save it as ${fileName}`,
251
239
  ];
252
- const locator = validatedParams.ref ? snapshot.refLocator(validatedParams.ref) : null;
240
+ const locator = params.ref ? snapshot.refLocator(params.ref) : null;
253
241
  if (locator)
254
- code.push(`await page.${await (0, context_1.generateLocator)(locator)}.screenshot(${javascript.formatObject(options)});`);
242
+ code.push(`await page.${await generateLocator(locator)}.screenshot(${javascript.formatObject(options)});`);
255
243
  else
256
244
  code.push(`await page.screenshot(${javascript.formatObject(options)});`);
245
+ const includeBase64 = !context.config.tools?.browser_take_screenshot?.omitBase64;
257
246
  const action = async () => {
258
247
  const screenshot = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
259
248
  return {
260
- content: [{
249
+ content: includeBase64 ? [{
261
250
  type: 'image',
262
251
  data: screenshot.toString('base64'),
263
252
  mimeType: fileType === 'png' ? 'image/png' : 'image/jpeg',
264
- }]
253
+ }] : []
265
254
  };
266
255
  };
267
256
  return {
@@ -271,7 +260,10 @@ const screenshot = {
271
260
  waitForNetwork: false,
272
261
  };
273
262
  }
274
- };
263
+ });
264
+ async function generateLocator(locator) {
265
+ return locator._generateLocatorString();
266
+ }
275
267
  exports.default = [
276
268
  snapshot,
277
269
  click,
package/lib/tools/tabs.js CHANGED
@@ -16,13 +16,13 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const zod_1 = require("zod");
19
- const zod_to_json_schema_1 = require("zod-to-json-schema");
20
- const listTabs = {
19
+ const tool_1 = require("./tool");
20
+ const listTabs = (0, tool_1.defineTool)({
21
21
  capability: 'tabs',
22
22
  schema: {
23
23
  name: 'browser_tab_list',
24
24
  description: 'List browser tabs',
25
- inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(zod_1.z.object({})),
25
+ inputSchema: zod_1.z.object({}),
26
26
  },
27
27
  handle: async (context) => {
28
28
  await context.ensureTab();
@@ -38,22 +38,20 @@ const listTabs = {
38
38
  },
39
39
  };
40
40
  },
41
- };
42
- const selectTabSchema = zod_1.z.object({
43
- index: zod_1.z.number().describe('The index of the tab to select'),
44
41
  });
45
- const selectTab = captureSnapshot => ({
42
+ const selectTab = captureSnapshot => (0, tool_1.defineTool)({
46
43
  capability: 'tabs',
47
44
  schema: {
48
45
  name: 'browser_tab_select',
49
46
  description: 'Select a tab by index',
50
- inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(selectTabSchema),
47
+ inputSchema: zod_1.z.object({
48
+ index: zod_1.z.number().describe('The index of the tab to select'),
49
+ }),
51
50
  },
52
51
  handle: async (context, params) => {
53
- const validatedParams = selectTabSchema.parse(params);
54
- await context.selectTab(validatedParams.index);
52
+ await context.selectTab(params.index);
55
53
  const code = [
56
- `// <internal code to select tab ${validatedParams.index}>`,
54
+ `// <internal code to select tab ${params.index}>`,
57
55
  ];
58
56
  return {
59
57
  code,
@@ -62,21 +60,19 @@ const selectTab = captureSnapshot => ({
62
60
  };
63
61
  },
64
62
  });
65
- const newTabSchema = zod_1.z.object({
66
- url: zod_1.z.string().optional().describe('The URL to navigate to in the new tab. If not provided, the new tab will be blank.'),
67
- });
68
- const newTab = captureSnapshot => ({
63
+ const newTab = captureSnapshot => (0, tool_1.defineTool)({
69
64
  capability: 'tabs',
70
65
  schema: {
71
66
  name: 'browser_tab_new',
72
67
  description: 'Open a new tab',
73
- inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(newTabSchema),
68
+ inputSchema: zod_1.z.object({
69
+ url: zod_1.z.string().optional().describe('The URL to navigate to in the new tab. If not provided, the new tab will be blank.'),
70
+ }),
74
71
  },
75
72
  handle: async (context, params) => {
76
- const validatedParams = newTabSchema.parse(params);
77
73
  await context.newTab();
78
- if (validatedParams.url)
79
- await context.currentTabOrDie().navigate(validatedParams.url);
74
+ if (params.url)
75
+ await context.currentTabOrDie().navigate(params.url);
80
76
  const code = [
81
77
  `// <internal code to open a new tab>`,
82
78
  ];
@@ -87,21 +83,19 @@ const newTab = captureSnapshot => ({
87
83
  };
88
84
  },
89
85
  });
90
- const closeTabSchema = zod_1.z.object({
91
- index: zod_1.z.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'),
92
- });
93
- const closeTab = captureSnapshot => ({
86
+ const closeTab = captureSnapshot => (0, tool_1.defineTool)({
94
87
  capability: 'tabs',
95
88
  schema: {
96
89
  name: 'browser_tab_close',
97
90
  description: 'Close a tab',
98
- inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(closeTabSchema),
91
+ inputSchema: zod_1.z.object({
92
+ index: zod_1.z.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'),
93
+ }),
99
94
  },
100
95
  handle: async (context, params) => {
101
- const validatedParams = closeTabSchema.parse(params);
102
- await context.closeTab(validatedParams.index);
96
+ await context.closeTab(params.index);
103
97
  const code = [
104
- `// <internal code to close tab ${validatedParams.index}>`,
98
+ `// <internal code to close tab ${params.index}>`,
105
99
  ];
106
100
  return {
107
101
  code,
package/lib/tools/tool.js CHANGED
@@ -15,3 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.defineTool = defineTool;
19
+ function defineTool(tool) {
20
+ return tool;
21
+ }