Skip to content

Commit 3a5eeb8

Browse files
authored
refactor(gui-agent): refactor composable gui agent with improved stability and error handling (#1556)
1 parent 6037e0e commit 3a5eeb8

File tree

16 files changed

+528
-790
lines changed

16 files changed

+528
-790
lines changed

multimodal/gui-agent/operator-aio/package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
"url": "https://github.com/bytedance/UI-TARS-desktop/issues"
1111
},
1212
"keywords": [
13-
"AI",
14-
"Core",
15-
"SDK",
16-
"Operator",
1713
"UI-TARS",
14+
"Operator",
1815
"AIO"
1916
],
2017
"main": "./dist/index.js",
@@ -36,12 +33,11 @@
3633
"registry": "https://registry.npmjs.org"
3734
},
3835
"dependencies": {
36+
"@gui-agent/shared": "workspace:*",
3937
"@agent-infra/browser": "0.1.1",
4038
"@agent-infra/logger": "0.0.2-beta.2",
4139
"@agent-infra/sandbox": "0.0.6",
42-
"@agent-infra/media-utils": "0.1.5",
43-
"@ui-tars/sdk": "1.2.3",
44-
"@ui-tars/shared": "1.2.3"
40+
"@agent-infra/media-utils": "0.1.5"
4541
},
4642
"devDependencies": {
4743
"@rslib/core": "0.10.0",

multimodal/gui-agent/operator-aio/src/AIOBrowser.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export class AIOBrowser {
4141
*/
4242
private logger: Logger;
4343

44+
private launchOptions?: LaunchOptions;
45+
4446
/**
4547
* Creates an instance of AIOBrowser
4648
* @param {AIOBrowserOptions} options - Configuration options
@@ -64,6 +66,7 @@ export class AIOBrowser {
6466
try {
6567
await this.browser.launch(options);
6668
this.logger.success('Browser launched successfully');
69+
this.launchOptions = options;
6770
} catch (error) {
6871
this.logger.error('Failed to launch browser:', error);
6972
throw error;
@@ -148,6 +151,7 @@ export class AIOBrowser {
148151
async getActivePage(): Promise<Page> {
149152
this.logger.info('Getting active page');
150153
const pages = await this.browser.getBrowser().pages();
154+
this.logger.info(`getActivePage pages length: ${pages.length}`);
151155
try {
152156
// First try to find a visible page without waiting
153157
for (const page of pages) {
@@ -192,10 +196,14 @@ export class AIOBrowser {
192196
continue;
193197
}
194198
}
195-
this.logger.success('Active original page retrieved successfully');
199+
this.logger.success('Active original page retrieved failed, fallback to active page');
196200
return this.browser.getActivePage();
197201
} catch (error) {
198202
this.logger.error('Failed to get active page:', error);
203+
if ((error as Error).message.includes('Protocol error: Connection closed')) {
204+
this.logger.error('Connection closed, reconnecting...');
205+
this.browser.launch(this.launchOptions);
206+
}
199207
throw error;
200208
}
201209
}

0 commit comments

Comments
 (0)