1- import {
2- createExportSessionReportTool ,
3- createSessionAgentOptions ,
4- z ,
5- } from '@midscene/core' ;
1+ import { z } from '@midscene/core' ;
62import { getDebug } from '@midscene/shared/logger' ;
73import { BaseMidsceneTools , type ToolDefinition } from '@midscene/shared/mcp' ;
84import { type ComputerAgent , agentFromComputer } from './agent' ;
@@ -22,14 +18,9 @@ export class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent> {
2218
2319 protected async ensureAgent (
2420 displayId ?: string ,
25- options ?: { sessionId ?: string ; headless ?: boolean } ,
21+ headless ?: boolean ,
2622 ) : Promise < ComputerAgent > {
27- const sessionId = options ?. sessionId ;
28- const headless = options ?. headless ;
29- if (
30- this . agent &&
31- ( displayId || this . shouldResetAgentForSession ( sessionId ) )
32- ) {
23+ if ( this . agent && displayId ) {
3324 // If a specific displayId is requested and we have an agent,
3425 // destroy it to create a new one with the new display
3526 try {
@@ -45,14 +36,9 @@ export class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent> {
4536 }
4637
4738 debug ( 'Creating Computer agent with displayId:' , displayId || 'primary' ) ;
48- const sessionOptions = createSessionAgentOptions ( {
49- sessionId,
50- platform : 'computer' ,
51- } ) ;
5239 const opts = {
5340 ...( displayId ? { displayId } : { } ) ,
5441 ...( headless !== undefined ? { headless } : { } ) ,
55- ...sessionOptions ,
5642 } ;
5743 const agent = await agentFromComputer (
5844 Object . keys ( opts ) . length > 0 ? opts : undefined ,
@@ -80,22 +66,18 @@ export class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent> {
8066 . optional ( )
8167 . describe ( 'Start virtual display via Xvfb (Linux only)' ) ,
8268 } ,
83- handler : async ( args : {
84- displayId ?: string ;
85- headless ?: boolean ;
86- sessionId ?: string ;
87- } ) => {
88- const agent = await this . ensureAgent ( args . displayId , {
89- ...this . getAgentOptions ( args as Record < string , unknown > ) ,
90- headless : args . headless ,
91- } ) ;
69+ handler : async ( {
70+ displayId,
71+ headless,
72+ } : { displayId ?: string ; headless ?: boolean } ) => {
73+ const agent = await this . ensureAgent ( displayId , headless ) ;
9274 const screenshot = await agent . interface . screenshotBase64 ( ) ;
9375
9476 return {
9577 content : [
9678 {
9779 type : 'text' ,
98- text : `Connected to computer${ args . displayId ? ` (Display: ${ args . displayId } )` : ' (Primary display)' } ` ,
80+ text : `Connected to computer${ displayId ? ` (Display: ${ displayId } )` : ' (Primary display)' } ` ,
9981 } ,
10082 ...this . buildScreenshotContent ( screenshot ) ,
10183 ] ,
@@ -108,7 +90,6 @@ export class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent> {
10890 schema : { } ,
10991 handler : this . createDisconnectHandler ( 'computer' ) ,
11092 } ,
111- createExportSessionReportTool ( ) ,
11293 {
11394 name : 'computer_list_displays' ,
11495 description : 'List all available displays/monitors' ,
0 commit comments