@@ -11,7 +11,7 @@ import type {ElementHandle, Page} from '../third_party/index.js';
1111import { parseKey } from '../utils/keyboard.js' ;
1212
1313import { ToolCategory } from './categories.js' ;
14- import { defineTool , isolatedContextSchema } from './ToolDefinition.js' ;
14+ import { defineTool , pageIdSchema } from './ToolDefinition.js' ;
1515
1616const dblClickSchema = zod
1717 . boolean ( )
@@ -83,16 +83,14 @@ export const clickAt = defineTool({
8383 conditions : [ 'computerVision' ] ,
8484 } ,
8585 schema : {
86- ...isolatedContextSchema ,
86+ ...pageIdSchema ,
8787 x : zod . number ( ) . describe ( 'The x coordinate' ) ,
8888 y : zod . number ( ) . describe ( 'The y coordinate' ) ,
8989 dblClick : dblClickSchema ,
9090 includeSnapshot : includeSnapshotSchema ,
9191 } ,
9292 handler : async ( request , response , context ) => {
93- const page = context . resolvePageByContext (
94- request . params . isolatedContext ,
95- ) ;
93+ const page = context . resolvePageById ( request . params . pageId ) ;
9694 await context . waitForEventsAfterAction ( async ( ) => {
9795 await page . mouse . click ( request . params . x , request . params . y , {
9896 clickCount : request . params . dblClick ? 2 : 1 ,
@@ -104,7 +102,7 @@ export const clickAt = defineTool({
104102 : `Successfully clicked at the coordinates` ,
105103 ) ;
106104 if ( request . params . includeSnapshot ) {
107- response . includeSnapshot ( { page } ) ;
105+ response . includeSnapshot ( { page} ) ;
108106 }
109107 } ,
110108} ) ;
@@ -202,8 +200,7 @@ async function fillFormElement(
202200 const timeoutPerChar = 10 ; // ms
203201 const targetPage = page ?? context . getSelectedPage ( ) ;
204202 const fillTimeout =
205- targetPage . getDefaultTimeout ( ) +
206- value . length * timeoutPerChar ;
203+ targetPage . getDefaultTimeout ( ) + value . length * timeoutPerChar ;
207204 await handle . asLocator ( ) . setTimeout ( fillTimeout ) . fill ( value ) ;
208205 }
209206 } catch ( error ) {
@@ -221,7 +218,7 @@ export const fill = defineTool({
221218 readOnlyHint : false ,
222219 } ,
223220 schema : {
224- ...isolatedContextSchema ,
221+ ...pageIdSchema ,
225222 uid : zod
226223 . string ( )
227224 . describe (
@@ -231,9 +228,7 @@ export const fill = defineTool({
231228 includeSnapshot : includeSnapshotSchema ,
232229 } ,
233230 handler : async ( request , response , context ) => {
234- const page = context . resolvePageByContext (
235- request . params . isolatedContext ,
236- ) ;
231+ const page = context . resolvePageById ( request . params . pageId ) ;
237232 await context . waitForEventsAfterAction ( async ( ) => {
238233 await fillFormElement (
239234 request . params . uid ,
@@ -244,7 +239,7 @@ export const fill = defineTool({
244239 } ) ;
245240 response . appendResponseLine ( `Successfully filled out the element` ) ;
246241 if ( request . params . includeSnapshot ) {
247- response . includeSnapshot ( { page } ) ;
242+ response . includeSnapshot ( { page} ) ;
248243 }
249244 } ,
250245} ) ;
@@ -289,7 +284,7 @@ export const fillForm = defineTool({
289284 readOnlyHint : false ,
290285 } ,
291286 schema : {
292- ...isolatedContextSchema ,
287+ ...pageIdSchema ,
293288 elements : zod
294289 . array (
295290 zod . object ( {
@@ -301,9 +296,7 @@ export const fillForm = defineTool({
301296 includeSnapshot : includeSnapshotSchema ,
302297 } ,
303298 handler : async ( request , response , context ) => {
304- const page = context . resolvePageByContext (
305- request . params . isolatedContext ,
306- ) ;
299+ const page = context . resolvePageById ( request . params . pageId ) ;
307300 for ( const element of request . params . elements ) {
308301 await context . waitForEventsAfterAction ( async ( ) => {
309302 await fillFormElement (
@@ -316,7 +309,7 @@ export const fillForm = defineTool({
316309 }
317310 response . appendResponseLine ( `Successfully filled out the form` ) ;
318311 if ( request . params . includeSnapshot ) {
319- response . includeSnapshot ( { page } ) ;
312+ response . includeSnapshot ( { page} ) ;
320313 }
321314 } ,
322315} ) ;
@@ -329,7 +322,7 @@ export const uploadFile = defineTool({
329322 readOnlyHint : false ,
330323 } ,
331324 schema : {
332- ...isolatedContextSchema ,
325+ ...pageIdSchema ,
333326 uid : zod
334327 . string ( )
335328 . describe (
@@ -351,9 +344,7 @@ export const uploadFile = defineTool({
351344 // a type=file element. In this case, we want to default to
352345 // Page.waitForFileChooser() and upload the file this way.
353346 try {
354- const page = context . resolvePageByContext (
355- request . params . isolatedContext ,
356- ) ;
347+ const page = context . resolvePageById ( request . params . pageId ) ;
357348 const [ fileChooser ] = await Promise . all ( [
358349 page . waitForFileChooser ( { timeout : 3000 } ) ,
359350 handle . asLocator ( ) . click ( ) ,
@@ -366,10 +357,8 @@ export const uploadFile = defineTool({
366357 }
367358 }
368359 if ( request . params . includeSnapshot ) {
369- const page = context . resolvePageByContext (
370- request . params . isolatedContext ,
371- ) ;
372- response . includeSnapshot ( { page } ) ;
360+ const page = context . resolvePageById ( request . params . pageId ) ;
361+ response . includeSnapshot ( { page} ) ;
373362 }
374363 response . appendResponseLine ( `File uploaded from ${ filePath } .` ) ;
375364 } finally {
@@ -386,7 +375,7 @@ export const pressKey = defineTool({
386375 readOnlyHint : false ,
387376 } ,
388377 schema : {
389- ...isolatedContextSchema ,
378+ ...pageIdSchema ,
390379 key : zod
391380 . string ( )
392381 . describe (
@@ -395,9 +384,7 @@ export const pressKey = defineTool({
395384 includeSnapshot : includeSnapshotSchema ,
396385 } ,
397386 handler : async ( request , response , context ) => {
398- const page = context . resolvePageByContext (
399- request . params . isolatedContext ,
400- ) ;
387+ const page = context . resolvePageById ( request . params . pageId ) ;
401388 const tokens = parseKey ( request . params . key ) ;
402389 const [ key , ...modifiers ] = tokens ;
403390
@@ -415,7 +402,7 @@ export const pressKey = defineTool({
415402 `Successfully pressed key: ${ request . params . key } ` ,
416403 ) ;
417404 if ( request . params . includeSnapshot ) {
418- response . includeSnapshot ( { page } ) ;
405+ response . includeSnapshot ( { page} ) ;
419406 }
420407 } ,
421408} ) ;
0 commit comments