wuying-agentbay-sdk 0.6.1 → 0.8.0
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.
- package/README.md +9 -10
- package/dist/index.cjs +837 -164
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +459 -64
- package/dist/index.d.ts +459 -64
- package/dist/index.mjs +815 -142
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -114,10 +114,10 @@ var require_main = __commonJS({
|
|
|
114
114
|
"node_modules/dotenv/lib/main.js"(exports, module) {
|
|
115
115
|
"use strict";
|
|
116
116
|
init_cjs_shims();
|
|
117
|
-
var
|
|
118
|
-
var
|
|
117
|
+
var fs3 = __require("fs");
|
|
118
|
+
var path3 = __require("path");
|
|
119
119
|
var os = __require("os");
|
|
120
|
-
var
|
|
120
|
+
var crypto2 = __require("crypto");
|
|
121
121
|
var packageJson = require_package();
|
|
122
122
|
var version = packageJson.version;
|
|
123
123
|
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
@@ -230,7 +230,7 @@ var require_main = __commonJS({
|
|
|
230
230
|
if (options && options.path && options.path.length > 0) {
|
|
231
231
|
if (Array.isArray(options.path)) {
|
|
232
232
|
for (const filepath of options.path) {
|
|
233
|
-
if (
|
|
233
|
+
if (fs3.existsSync(filepath)) {
|
|
234
234
|
possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
235
235
|
}
|
|
236
236
|
}
|
|
@@ -238,16 +238,16 @@ var require_main = __commonJS({
|
|
|
238
238
|
possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
|
239
239
|
}
|
|
240
240
|
} else {
|
|
241
|
-
possibleVaultPath =
|
|
241
|
+
possibleVaultPath = path3.resolve(process.cwd(), ".env.vault");
|
|
242
242
|
}
|
|
243
|
-
if (
|
|
243
|
+
if (fs3.existsSync(possibleVaultPath)) {
|
|
244
244
|
return possibleVaultPath;
|
|
245
245
|
}
|
|
246
246
|
return null;
|
|
247
247
|
}
|
|
248
248
|
__name(_vaultPath, "_vaultPath");
|
|
249
249
|
function _resolveHome(envPath) {
|
|
250
|
-
return envPath[0] === "~" ?
|
|
250
|
+
return envPath[0] === "~" ? path3.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
251
251
|
}
|
|
252
252
|
__name(_resolveHome, "_resolveHome");
|
|
253
253
|
function _configVault(options) {
|
|
@@ -266,7 +266,7 @@ var require_main = __commonJS({
|
|
|
266
266
|
}
|
|
267
267
|
__name(_configVault, "_configVault");
|
|
268
268
|
function configDotenv(options) {
|
|
269
|
-
const dotenvPath =
|
|
269
|
+
const dotenvPath = path3.resolve(process.cwd(), ".env");
|
|
270
270
|
let encoding = "utf8";
|
|
271
271
|
const debug = Boolean(options && options.debug);
|
|
272
272
|
const quiet = options && "quiet" in options ? options.quiet : true;
|
|
@@ -290,13 +290,13 @@ var require_main = __commonJS({
|
|
|
290
290
|
}
|
|
291
291
|
let lastError;
|
|
292
292
|
const parsedAll = {};
|
|
293
|
-
for (const
|
|
293
|
+
for (const path4 of optionPaths) {
|
|
294
294
|
try {
|
|
295
|
-
const parsed = DotenvModule.parse(
|
|
295
|
+
const parsed = DotenvModule.parse(fs3.readFileSync(path4, { encoding }));
|
|
296
296
|
DotenvModule.populate(parsedAll, parsed, options);
|
|
297
297
|
} catch (e) {
|
|
298
298
|
if (debug) {
|
|
299
|
-
_debug(`Failed to load ${
|
|
299
|
+
_debug(`Failed to load ${path4} ${e.message}`);
|
|
300
300
|
}
|
|
301
301
|
lastError = e;
|
|
302
302
|
}
|
|
@@ -311,7 +311,7 @@ var require_main = __commonJS({
|
|
|
311
311
|
const shortPaths = [];
|
|
312
312
|
for (const filePath of optionPaths) {
|
|
313
313
|
try {
|
|
314
|
-
const relative =
|
|
314
|
+
const relative = path3.relative(process.cwd(), filePath);
|
|
315
315
|
shortPaths.push(relative);
|
|
316
316
|
} catch (e) {
|
|
317
317
|
if (debug) {
|
|
@@ -348,7 +348,7 @@ var require_main = __commonJS({
|
|
|
348
348
|
const authTag = ciphertext.subarray(-16);
|
|
349
349
|
ciphertext = ciphertext.subarray(12, -16);
|
|
350
350
|
try {
|
|
351
|
-
const aesgcm =
|
|
351
|
+
const aesgcm = crypto2.createDecipheriv("aes-256-gcm", key, nonce);
|
|
352
352
|
aesgcm.setAuthTag(authTag);
|
|
353
353
|
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
354
354
|
} catch (error) {
|
|
@@ -3081,7 +3081,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3081
3081
|
);
|
|
3082
3082
|
}
|
|
3083
3083
|
/**
|
|
3084
|
-
*
|
|
3084
|
+
* Call MCP tool
|
|
3085
3085
|
*
|
|
3086
3086
|
* @param request - CallMcpToolRequest
|
|
3087
3087
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3134,7 +3134,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3134
3134
|
);
|
|
3135
3135
|
}
|
|
3136
3136
|
/**
|
|
3137
|
-
*
|
|
3137
|
+
* Call MCP tool
|
|
3138
3138
|
*
|
|
3139
3139
|
* @param request - CallMcpToolRequest
|
|
3140
3140
|
* @returns CallMcpToolResponse
|
|
@@ -3144,7 +3144,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3144
3144
|
return await this.callMcpToolWithOptions(request, runtime);
|
|
3145
3145
|
}
|
|
3146
3146
|
/**
|
|
3147
|
-
*
|
|
3147
|
+
* Create MCP session
|
|
3148
3148
|
*
|
|
3149
3149
|
* @param tmpReq - CreateMcpSessionRequest
|
|
3150
3150
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3209,7 +3209,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3209
3209
|
);
|
|
3210
3210
|
}
|
|
3211
3211
|
/**
|
|
3212
|
-
*
|
|
3212
|
+
* Create MCP session
|
|
3213
3213
|
*
|
|
3214
3214
|
* @param request - CreateMcpSessionRequest
|
|
3215
3215
|
* @returns CreateMcpSessionResponse
|
|
@@ -3219,7 +3219,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3219
3219
|
return await this.createMcpSessionWithOptions(request, runtime);
|
|
3220
3220
|
}
|
|
3221
3221
|
/**
|
|
3222
|
-
*
|
|
3222
|
+
* Delete persistent context
|
|
3223
3223
|
*
|
|
3224
3224
|
* @param request - DeleteContextRequest
|
|
3225
3225
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3254,7 +3254,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3254
3254
|
);
|
|
3255
3255
|
}
|
|
3256
3256
|
/**
|
|
3257
|
-
*
|
|
3257
|
+
* Delete persistent context
|
|
3258
3258
|
*
|
|
3259
3259
|
* @param request - DeleteContextRequest
|
|
3260
3260
|
* @returns DeleteContextResponse
|
|
@@ -3264,7 +3264,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3264
3264
|
return await this.deleteContextWithOptions(request, runtime);
|
|
3265
3265
|
}
|
|
3266
3266
|
/**
|
|
3267
|
-
*
|
|
3267
|
+
* Get context
|
|
3268
3268
|
*
|
|
3269
3269
|
* @param request - GetContextRequest
|
|
3270
3270
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3302,7 +3302,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3302
3302
|
);
|
|
3303
3303
|
}
|
|
3304
3304
|
/**
|
|
3305
|
-
*
|
|
3305
|
+
* Get context
|
|
3306
3306
|
*
|
|
3307
3307
|
* @param request - GetContextRequest
|
|
3308
3308
|
* @returns GetContextResponse
|
|
@@ -3312,7 +3312,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3312
3312
|
return await this.getContextWithOptions(request, runtime);
|
|
3313
3313
|
}
|
|
3314
3314
|
/**
|
|
3315
|
-
*
|
|
3315
|
+
* Get context information
|
|
3316
3316
|
*
|
|
3317
3317
|
* @param request - GetContextInfoRequest
|
|
3318
3318
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3356,7 +3356,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3356
3356
|
);
|
|
3357
3357
|
}
|
|
3358
3358
|
/**
|
|
3359
|
-
*
|
|
3359
|
+
* Get context information
|
|
3360
3360
|
*
|
|
3361
3361
|
* @param request - GetContextInfoRequest
|
|
3362
3362
|
* @returns GetContextInfoResponse
|
|
@@ -3366,7 +3366,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3366
3366
|
return await this.getContextInfoWithOptions(request, runtime);
|
|
3367
3367
|
}
|
|
3368
3368
|
/**
|
|
3369
|
-
*
|
|
3369
|
+
* Get labels
|
|
3370
3370
|
*
|
|
3371
3371
|
* @param request - GetLabelRequest
|
|
3372
3372
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3407,7 +3407,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3407
3407
|
);
|
|
3408
3408
|
}
|
|
3409
3409
|
/**
|
|
3410
|
-
*
|
|
3410
|
+
* Get labels
|
|
3411
3411
|
*
|
|
3412
3412
|
* @param request - GetLabelRequest
|
|
3413
3413
|
* @returns GetLabelResponse
|
|
@@ -3417,7 +3417,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3417
3417
|
return await this.getLabelWithOptions(request, runtime);
|
|
3418
3418
|
}
|
|
3419
3419
|
/**
|
|
3420
|
-
*
|
|
3420
|
+
* Get forwarding link for specific port
|
|
3421
3421
|
*
|
|
3422
3422
|
* @param request - GetLinkRequest
|
|
3423
3423
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3458,7 +3458,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3458
3458
|
);
|
|
3459
3459
|
}
|
|
3460
3460
|
/**
|
|
3461
|
-
*
|
|
3461
|
+
* Get forwarding link for specific port
|
|
3462
3462
|
*
|
|
3463
3463
|
* @param request - GetLinkRequest
|
|
3464
3464
|
* @returns GetLinkResponse
|
|
@@ -3468,7 +3468,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3468
3468
|
return await this.getLinkWithOptions(request, runtime);
|
|
3469
3469
|
}
|
|
3470
3470
|
/**
|
|
3471
|
-
*
|
|
3471
|
+
* Get MCP resource information
|
|
3472
3472
|
*
|
|
3473
3473
|
* @param request - GetMcpResourceRequest
|
|
3474
3474
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3503,7 +3503,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3503
3503
|
);
|
|
3504
3504
|
}
|
|
3505
3505
|
/**
|
|
3506
|
-
*
|
|
3506
|
+
* Get MCP resource information
|
|
3507
3507
|
*
|
|
3508
3508
|
* @param request - GetMcpResourceRequest
|
|
3509
3509
|
* @returns GetMcpResourceResponse
|
|
@@ -3513,7 +3513,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3513
3513
|
return await this.getMcpResourceWithOptions(request, runtime);
|
|
3514
3514
|
}
|
|
3515
3515
|
/**
|
|
3516
|
-
*
|
|
3516
|
+
* Get context list
|
|
3517
3517
|
*
|
|
3518
3518
|
* @param request - ListContextsRequest
|
|
3519
3519
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3551,7 +3551,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3551
3551
|
);
|
|
3552
3552
|
}
|
|
3553
3553
|
/**
|
|
3554
|
-
*
|
|
3554
|
+
* Get context list
|
|
3555
3555
|
*
|
|
3556
3556
|
* @param request - ListContextsRequest
|
|
3557
3557
|
* @returns ListContextsResponse
|
|
@@ -3606,7 +3606,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3606
3606
|
return await this.listMcpToolsWithOptions(request, runtime);
|
|
3607
3607
|
}
|
|
3608
3608
|
/**
|
|
3609
|
-
*
|
|
3609
|
+
* Query session list by label
|
|
3610
3610
|
*
|
|
3611
3611
|
* @param request - ListSessionRequest
|
|
3612
3612
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3647,7 +3647,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3647
3647
|
);
|
|
3648
3648
|
}
|
|
3649
3649
|
/**
|
|
3650
|
-
*
|
|
3650
|
+
* Query session list by label
|
|
3651
3651
|
*
|
|
3652
3652
|
* @param request - ListSessionRequest
|
|
3653
3653
|
* @returns ListSessionResponse
|
|
@@ -3657,7 +3657,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3657
3657
|
return await this.listSessionWithOptions(request, runtime);
|
|
3658
3658
|
}
|
|
3659
3659
|
/**
|
|
3660
|
-
*
|
|
3660
|
+
* Modify context
|
|
3661
3661
|
*
|
|
3662
3662
|
* @param request - ModifyContextRequest
|
|
3663
3663
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3695,7 +3695,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3695
3695
|
);
|
|
3696
3696
|
}
|
|
3697
3697
|
/**
|
|
3698
|
-
*
|
|
3698
|
+
* Modify context
|
|
3699
3699
|
*
|
|
3700
3700
|
* @param request - ModifyContextRequest
|
|
3701
3701
|
* @returns ModifyContextResponse
|
|
@@ -3705,7 +3705,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3705
3705
|
return await this.modifyContextWithOptions(request, runtime);
|
|
3706
3706
|
}
|
|
3707
3707
|
/**
|
|
3708
|
-
*
|
|
3708
|
+
* Release MCP session
|
|
3709
3709
|
*
|
|
3710
3710
|
* @param request - ReleaseMcpSessionRequest
|
|
3711
3711
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3740,7 +3740,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3740
3740
|
);
|
|
3741
3741
|
}
|
|
3742
3742
|
/**
|
|
3743
|
-
*
|
|
3743
|
+
* Release MCP session
|
|
3744
3744
|
*
|
|
3745
3745
|
* @param request - ReleaseMcpSessionRequest
|
|
3746
3746
|
* @returns ReleaseMcpSessionResponse
|
|
@@ -3750,7 +3750,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3750
3750
|
return await this.releaseMcpSessionWithOptions(request, runtime);
|
|
3751
3751
|
}
|
|
3752
3752
|
/**
|
|
3753
|
-
*
|
|
3753
|
+
* Set labels
|
|
3754
3754
|
*
|
|
3755
3755
|
* @param request - SetLabelRequest
|
|
3756
3756
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3788,7 +3788,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3788
3788
|
);
|
|
3789
3789
|
}
|
|
3790
3790
|
/**
|
|
3791
|
-
*
|
|
3791
|
+
* Set labels
|
|
3792
3792
|
*
|
|
3793
3793
|
* @param request - SetLabelRequest
|
|
3794
3794
|
* @returns SetLabelResponse
|
|
@@ -3798,7 +3798,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3798
3798
|
return await this.setLabelWithOptions(request, runtime);
|
|
3799
3799
|
}
|
|
3800
3800
|
/**
|
|
3801
|
-
*
|
|
3801
|
+
* Sync context
|
|
3802
3802
|
*
|
|
3803
3803
|
* @param request - SyncContextRequest
|
|
3804
3804
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3844,7 +3844,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3844
3844
|
);
|
|
3845
3845
|
}
|
|
3846
3846
|
/**
|
|
3847
|
-
*
|
|
3847
|
+
* Sync context
|
|
3848
3848
|
*
|
|
3849
3849
|
* @param request - SyncContextRequest
|
|
3850
3850
|
* @returns SyncContextResponse
|
|
@@ -3854,7 +3854,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3854
3854
|
return await this.syncContextWithOptions(request, runtime);
|
|
3855
3855
|
}
|
|
3856
3856
|
/**
|
|
3857
|
-
*
|
|
3857
|
+
* Initialize browser
|
|
3858
3858
|
*
|
|
3859
3859
|
* @param tmpReq - InitBrowserRequest
|
|
3860
3860
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3895,7 +3895,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3895
3895
|
);
|
|
3896
3896
|
}
|
|
3897
3897
|
/**
|
|
3898
|
-
*
|
|
3898
|
+
* Initialize browser
|
|
3899
3899
|
*
|
|
3900
3900
|
* @param request - InitBrowserRequest
|
|
3901
3901
|
* @returns InitBrowserResponse
|
|
@@ -3905,7 +3905,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3905
3905
|
return await this.initBrowserWithOptions(request, runtime);
|
|
3906
3906
|
}
|
|
3907
3907
|
/**
|
|
3908
|
-
*
|
|
3908
|
+
* Initialize browser (sync version)
|
|
3909
3909
|
*
|
|
3910
3910
|
* @param request - InitBrowserRequest
|
|
3911
3911
|
* @returns InitBrowserResponse
|
|
@@ -3946,7 +3946,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3946
3946
|
);
|
|
3947
3947
|
}
|
|
3948
3948
|
/**
|
|
3949
|
-
*
|
|
3949
|
+
* Get context file upload URL
|
|
3950
3950
|
*
|
|
3951
3951
|
* @param request - DeleteContextFileRequest
|
|
3952
3952
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3984,7 +3984,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3984
3984
|
);
|
|
3985
3985
|
}
|
|
3986
3986
|
/**
|
|
3987
|
-
*
|
|
3987
|
+
* Get context file upload URL
|
|
3988
3988
|
*
|
|
3989
3989
|
* @param request - DeleteContextFileRequest
|
|
3990
3990
|
* @returns DeleteContextFileResponse
|
|
@@ -3994,7 +3994,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
3994
3994
|
return await this.deleteContextFileWithOptions(request, runtime);
|
|
3995
3995
|
}
|
|
3996
3996
|
/**
|
|
3997
|
-
*
|
|
3997
|
+
* Query context specific directory files
|
|
3998
3998
|
*
|
|
3999
3999
|
* @param request - DescribeContextFilesRequest
|
|
4000
4000
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -4038,7 +4038,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
4038
4038
|
);
|
|
4039
4039
|
}
|
|
4040
4040
|
/**
|
|
4041
|
-
*
|
|
4041
|
+
* Query context specific directory files
|
|
4042
4042
|
*
|
|
4043
4043
|
* @param request - DescribeContextFilesRequest
|
|
4044
4044
|
* @returns DescribeContextFilesResponse
|
|
@@ -4048,7 +4048,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
4048
4048
|
return await this.describeContextFilesWithOptions(request, runtime);
|
|
4049
4049
|
}
|
|
4050
4050
|
/**
|
|
4051
|
-
*
|
|
4051
|
+
* Get context file upload URL
|
|
4052
4052
|
*
|
|
4053
4053
|
* @param request - GetContextFileDownloadUrlRequest
|
|
4054
4054
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -4086,7 +4086,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
4086
4086
|
);
|
|
4087
4087
|
}
|
|
4088
4088
|
/**
|
|
4089
|
-
*
|
|
4089
|
+
* Get context file upload URL
|
|
4090
4090
|
*
|
|
4091
4091
|
* @param request - GetContextFileDownloadUrlRequest
|
|
4092
4092
|
* @returns GetContextFileDownloadUrlResponse
|
|
@@ -4096,7 +4096,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
4096
4096
|
return await this.getContextFileDownloadUrlWithOptions(request, runtime);
|
|
4097
4097
|
}
|
|
4098
4098
|
/**
|
|
4099
|
-
*
|
|
4099
|
+
* Get context file upload URL
|
|
4100
4100
|
*
|
|
4101
4101
|
* @param request - GetContextFileUploadUrlRequest
|
|
4102
4102
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -4134,7 +4134,7 @@ var _Client = class _Client extends _openapicore2.default {
|
|
|
4134
4134
|
);
|
|
4135
4135
|
}
|
|
4136
4136
|
/**
|
|
4137
|
-
*
|
|
4137
|
+
* Get context file upload URL
|
|
4138
4138
|
*
|
|
4139
4139
|
* @param request - GetContextFileUploadUrlRequest
|
|
4140
4140
|
* @returns GetContextFileUploadUrlResponse
|
|
@@ -4150,8 +4150,8 @@ var Client = _Client;
|
|
|
4150
4150
|
// src/config.ts
|
|
4151
4151
|
init_cjs_shims();
|
|
4152
4152
|
var dotenv = __toESM(require_main());
|
|
4153
|
-
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
4154
|
-
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
4153
|
+
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs); var fs2 = _interopRequireWildcard(_fs);
|
|
4154
|
+
var _path = require('path'); var path = _interopRequireWildcard(_path); var path2 = _interopRequireWildcard(_path);
|
|
4155
4155
|
|
|
4156
4156
|
// src/utils/logger.ts
|
|
4157
4157
|
init_cjs_shims();
|
|
@@ -4194,6 +4194,28 @@ function defaultConfig() {
|
|
|
4194
4194
|
};
|
|
4195
4195
|
}
|
|
4196
4196
|
__name(defaultConfig, "defaultConfig");
|
|
4197
|
+
var dotEnvLoaded = false;
|
|
4198
|
+
function loadDotEnv() {
|
|
4199
|
+
if (dotEnvLoaded) {
|
|
4200
|
+
return;
|
|
4201
|
+
}
|
|
4202
|
+
try {
|
|
4203
|
+
const envPath = path.resolve(process.cwd(), ".env");
|
|
4204
|
+
if (fs.existsSync(envPath)) {
|
|
4205
|
+
const envConfig = dotenv.parse(fs.readFileSync(envPath));
|
|
4206
|
+
for (const k in envConfig) {
|
|
4207
|
+
if (!process.env.hasOwnProperty(k)) {
|
|
4208
|
+
process.env[k] = envConfig[k];
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4211
|
+
log(`Loaded .env file at: ${envPath}`);
|
|
4212
|
+
dotEnvLoaded = true;
|
|
4213
|
+
}
|
|
4214
|
+
} catch (error) {
|
|
4215
|
+
log(`Warning: Failed to load .env file: ${error}`);
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
__name(loadDotEnv, "loadDotEnv");
|
|
4197
4219
|
function loadConfig(customConfig) {
|
|
4198
4220
|
if (customConfig) {
|
|
4199
4221
|
return customConfig;
|
|
@@ -4214,16 +4236,16 @@ function loadConfig(customConfig) {
|
|
|
4214
4236
|
const envPath = path.resolve(process.cwd(), ".env");
|
|
4215
4237
|
if (fs.existsSync(envPath)) {
|
|
4216
4238
|
const envConfig = dotenv.parse(fs.readFileSync(envPath));
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4239
|
+
if (!process.env.AGENTBAY_REGION_ID && envConfig.AGENTBAY_REGION_ID) {
|
|
4240
|
+
config.region_id = envConfig.AGENTBAY_REGION_ID;
|
|
4241
|
+
}
|
|
4242
|
+
if (!process.env.AGENTBAY_ENDPOINT && envConfig.AGENTBAY_ENDPOINT) {
|
|
4243
|
+
config.endpoint = envConfig.AGENTBAY_ENDPOINT;
|
|
4244
|
+
}
|
|
4245
|
+
if (!process.env.AGENTBAY_TIMEOUT_MS && envConfig.AGENTBAY_TIMEOUT_MS) {
|
|
4246
|
+
const timeout = parseInt(envConfig.AGENTBAY_TIMEOUT_MS, 10);
|
|
4247
|
+
if (!isNaN(timeout) && timeout > 0) {
|
|
4248
|
+
config.timeout_ms = timeout;
|
|
4227
4249
|
}
|
|
4228
4250
|
}
|
|
4229
4251
|
log(`Loaded .env file at: ${envPath}`);
|
|
@@ -4699,7 +4721,7 @@ var _Agent = class _Agent {
|
|
|
4699
4721
|
*/
|
|
4700
4722
|
async executeTask(task, maxTryTimes) {
|
|
4701
4723
|
try {
|
|
4702
|
-
const args = { task };
|
|
4724
|
+
const args = { task, max_try_times: maxTryTimes };
|
|
4703
4725
|
const result = await this.session.callMcpTool("flux_execute_task", args);
|
|
4704
4726
|
if (!result.success) {
|
|
4705
4727
|
return {
|
|
@@ -5314,7 +5336,7 @@ var _ContextManager = class _ContextManager {
|
|
|
5314
5336
|
async info() {
|
|
5315
5337
|
return this.infoWithParams();
|
|
5316
5338
|
}
|
|
5317
|
-
async infoWithParams(contextId,
|
|
5339
|
+
async infoWithParams(contextId, path3, taskType) {
|
|
5318
5340
|
const request = new GetContextInfoRequest({
|
|
5319
5341
|
authorization: `Bearer ${this.session.getAPIKey()}`,
|
|
5320
5342
|
sessionId: this.session.getSessionId()
|
|
@@ -5322,8 +5344,8 @@ var _ContextManager = class _ContextManager {
|
|
|
5322
5344
|
if (contextId) {
|
|
5323
5345
|
request.contextId = contextId;
|
|
5324
5346
|
}
|
|
5325
|
-
if (
|
|
5326
|
-
request.path =
|
|
5347
|
+
if (path3) {
|
|
5348
|
+
request.path = path3;
|
|
5327
5349
|
}
|
|
5328
5350
|
if (taskType) {
|
|
5329
5351
|
request.taskType = taskType;
|
|
@@ -5373,7 +5395,7 @@ var _ContextManager = class _ContextManager {
|
|
|
5373
5395
|
async sync() {
|
|
5374
5396
|
return this.syncWithParams();
|
|
5375
5397
|
}
|
|
5376
|
-
async syncWithParams(contextId,
|
|
5398
|
+
async syncWithParams(contextId, path3, mode) {
|
|
5377
5399
|
const request = new SyncContextRequest({
|
|
5378
5400
|
authorization: `Bearer ${this.session.getAPIKey()}`,
|
|
5379
5401
|
sessionId: this.session.getSessionId()
|
|
@@ -5381,8 +5403,8 @@ var _ContextManager = class _ContextManager {
|
|
|
5381
5403
|
if (contextId) {
|
|
5382
5404
|
request.contextId = contextId;
|
|
5383
5405
|
}
|
|
5384
|
-
if (
|
|
5385
|
-
request.path =
|
|
5406
|
+
if (path3) {
|
|
5407
|
+
request.path = path3;
|
|
5386
5408
|
}
|
|
5387
5409
|
if (mode) {
|
|
5388
5410
|
request.mode = mode;
|
|
@@ -5429,6 +5451,43 @@ __name(newContextManager, "newContextManager");
|
|
|
5429
5451
|
// src/filesystem/filesystem.ts
|
|
5430
5452
|
init_cjs_shims();
|
|
5431
5453
|
var DEFAULT_CHUNK_SIZE = 60 * 1024;
|
|
5454
|
+
var _FileChangeEventHelper = class _FileChangeEventHelper {
|
|
5455
|
+
static toString(event) {
|
|
5456
|
+
return `FileChangeEvent(eventType='${event.eventType}', path='${event.path}', pathType='${event.pathType}')`;
|
|
5457
|
+
}
|
|
5458
|
+
static toDict(event) {
|
|
5459
|
+
return {
|
|
5460
|
+
eventType: event.eventType,
|
|
5461
|
+
path: event.path,
|
|
5462
|
+
pathType: event.pathType
|
|
5463
|
+
};
|
|
5464
|
+
}
|
|
5465
|
+
static fromDict(data) {
|
|
5466
|
+
return {
|
|
5467
|
+
eventType: data.eventType || "",
|
|
5468
|
+
path: data.path || "",
|
|
5469
|
+
pathType: data.pathType || ""
|
|
5470
|
+
};
|
|
5471
|
+
}
|
|
5472
|
+
};
|
|
5473
|
+
__name(_FileChangeEventHelper, "FileChangeEventHelper");
|
|
5474
|
+
var FileChangeEventHelper = _FileChangeEventHelper;
|
|
5475
|
+
var _FileChangeResultHelper = class _FileChangeResultHelper {
|
|
5476
|
+
static hasChanges(result) {
|
|
5477
|
+
return result.events.length > 0;
|
|
5478
|
+
}
|
|
5479
|
+
static getModifiedFiles(result) {
|
|
5480
|
+
return result.events.filter((event) => event.eventType === "modify" && event.pathType === "file").map((event) => event.path);
|
|
5481
|
+
}
|
|
5482
|
+
static getCreatedFiles(result) {
|
|
5483
|
+
return result.events.filter((event) => event.eventType === "create" && event.pathType === "file").map((event) => event.path);
|
|
5484
|
+
}
|
|
5485
|
+
static getDeletedFiles(result) {
|
|
5486
|
+
return result.events.filter((event) => event.eventType === "delete" && event.pathType === "file").map((event) => event.path);
|
|
5487
|
+
}
|
|
5488
|
+
};
|
|
5489
|
+
__name(_FileChangeResultHelper, "FileChangeResultHelper");
|
|
5490
|
+
var FileChangeResultHelper = _FileChangeResultHelper;
|
|
5432
5491
|
function parseFileInfo(fileInfoStr) {
|
|
5433
5492
|
const result = {
|
|
5434
5493
|
name: "",
|
|
@@ -5512,10 +5571,10 @@ var _FileSystem = class _FileSystem {
|
|
|
5512
5571
|
* @param path - Path to the directory to create.
|
|
5513
5572
|
* @returns BoolResult with creation result and requestId
|
|
5514
5573
|
*/
|
|
5515
|
-
async createDirectory(
|
|
5574
|
+
async createDirectory(path3) {
|
|
5516
5575
|
try {
|
|
5517
5576
|
const args = {
|
|
5518
|
-
path:
|
|
5577
|
+
path: path3
|
|
5519
5578
|
};
|
|
5520
5579
|
const result = await this.session.callMcpTool(
|
|
5521
5580
|
"create_directory",
|
|
@@ -5550,10 +5609,10 @@ var _FileSystem = class _FileSystem {
|
|
|
5550
5609
|
* @param dryRun - Optional: If true, preview changes without applying them.
|
|
5551
5610
|
* @returns BoolResult with edit result and requestId
|
|
5552
5611
|
*/
|
|
5553
|
-
async editFile(
|
|
5612
|
+
async editFile(path3, edits, dryRun = false) {
|
|
5554
5613
|
try {
|
|
5555
5614
|
const args = {
|
|
5556
|
-
path:
|
|
5615
|
+
path: path3,
|
|
5557
5616
|
edits,
|
|
5558
5617
|
dryRun
|
|
5559
5618
|
};
|
|
@@ -5588,10 +5647,10 @@ var _FileSystem = class _FileSystem {
|
|
|
5588
5647
|
* @param path - Path to the file or directory to inspect.
|
|
5589
5648
|
* @returns FileInfoResult with file info and requestId
|
|
5590
5649
|
*/
|
|
5591
|
-
async getFileInfo(
|
|
5650
|
+
async getFileInfo(path3) {
|
|
5592
5651
|
try {
|
|
5593
5652
|
const args = {
|
|
5594
|
-
path:
|
|
5653
|
+
path: path3
|
|
5595
5654
|
};
|
|
5596
5655
|
const result = await this.session.callMcpTool(
|
|
5597
5656
|
"get_file_info",
|
|
@@ -5634,10 +5693,10 @@ var _FileSystem = class _FileSystem {
|
|
|
5634
5693
|
* @param path - Path to the directory to list.
|
|
5635
5694
|
* @returns DirectoryListResult with directory entries and requestId
|
|
5636
5695
|
*/
|
|
5637
|
-
async listDirectory(
|
|
5696
|
+
async listDirectory(path3) {
|
|
5638
5697
|
try {
|
|
5639
5698
|
const args = {
|
|
5640
|
-
path:
|
|
5699
|
+
path: path3
|
|
5641
5700
|
};
|
|
5642
5701
|
const result = await this.session.callMcpTool(
|
|
5643
5702
|
"list_directory",
|
|
@@ -5705,18 +5764,17 @@ var _FileSystem = class _FileSystem {
|
|
|
5705
5764
|
}
|
|
5706
5765
|
}
|
|
5707
5766
|
/**
|
|
5708
|
-
*
|
|
5709
|
-
* Corresponds to Python's read_file() method
|
|
5767
|
+
* Internal method to read a file chunk. Used for chunked file operations.
|
|
5710
5768
|
*
|
|
5711
5769
|
* @param path - Path to the file to read.
|
|
5712
5770
|
* @param offset - Optional: Byte offset to start reading from (0-based).
|
|
5713
5771
|
* @param length - Optional: Number of bytes to read. If 0, reads the entire file from offset.
|
|
5714
5772
|
* @returns FileContentResult with file content and requestId
|
|
5715
5773
|
*/
|
|
5716
|
-
async
|
|
5774
|
+
async readFileChunk(path3, offset = 0, length = 0) {
|
|
5717
5775
|
try {
|
|
5718
5776
|
const args = {
|
|
5719
|
-
path:
|
|
5777
|
+
path: path3
|
|
5720
5778
|
};
|
|
5721
5779
|
if (offset > 0) {
|
|
5722
5780
|
args.offset = offset;
|
|
@@ -5782,8 +5840,8 @@ var _FileSystem = class _FileSystem {
|
|
|
5782
5840
|
for (const line of lines) {
|
|
5783
5841
|
const colonIndex = line.indexOf(":");
|
|
5784
5842
|
if (colonIndex > 0 && currentPath === "" && !line.substring(0, colonIndex).includes(" ")) {
|
|
5785
|
-
const
|
|
5786
|
-
currentPath =
|
|
5843
|
+
const path3 = line.substring(0, colonIndex).trim();
|
|
5844
|
+
currentPath = path3;
|
|
5787
5845
|
if (line.length > colonIndex + 1) {
|
|
5788
5846
|
const contentStart = line.substring(colonIndex + 1).trim();
|
|
5789
5847
|
if (contentStart) {
|
|
@@ -5803,8 +5861,8 @@ var _FileSystem = class _FileSystem {
|
|
|
5803
5861
|
if (currentPath) {
|
|
5804
5862
|
fileContents[currentPath] = currentContent.join("\n");
|
|
5805
5863
|
}
|
|
5806
|
-
for (const
|
|
5807
|
-
fileContents[
|
|
5864
|
+
for (const path3 in fileContents) {
|
|
5865
|
+
fileContents[path3] = fileContents[path3].replace(/\n+$/, "");
|
|
5808
5866
|
}
|
|
5809
5867
|
}
|
|
5810
5868
|
return {
|
|
@@ -5830,10 +5888,10 @@ var _FileSystem = class _FileSystem {
|
|
|
5830
5888
|
* @param excludePatterns - Optional: Array of patterns to exclude.
|
|
5831
5889
|
* @returns FileSearchResult with search results and requestId
|
|
5832
5890
|
*/
|
|
5833
|
-
async searchFiles(
|
|
5891
|
+
async searchFiles(path3, pattern, excludePatterns = []) {
|
|
5834
5892
|
try {
|
|
5835
5893
|
const args = {
|
|
5836
|
-
path:
|
|
5894
|
+
path: path3,
|
|
5837
5895
|
pattern
|
|
5838
5896
|
};
|
|
5839
5897
|
if (excludePatterns.length > 0) {
|
|
@@ -5870,15 +5928,14 @@ var _FileSystem = class _FileSystem {
|
|
|
5870
5928
|
}
|
|
5871
5929
|
}
|
|
5872
5930
|
/**
|
|
5873
|
-
*
|
|
5874
|
-
* Corresponds to Python's write_file() method
|
|
5931
|
+
* Internal method to write a file chunk. Used for chunked file operations.
|
|
5875
5932
|
*
|
|
5876
5933
|
* @param path - Path to the file to write.
|
|
5877
5934
|
* @param content - Content to write to the file.
|
|
5878
5935
|
* @param mode - Optional: Write mode. One of "overwrite", "append", or "create_new". Default is "overwrite".
|
|
5879
5936
|
* @returns BoolResult with write result and requestId
|
|
5880
5937
|
*/
|
|
5881
|
-
async
|
|
5938
|
+
async writeFileChunk(path3, content, mode = "overwrite") {
|
|
5882
5939
|
try {
|
|
5883
5940
|
const validModes = ["overwrite", "append", "create_new"];
|
|
5884
5941
|
if (!validModes.includes(mode)) {
|
|
@@ -5891,7 +5948,7 @@ var _FileSystem = class _FileSystem {
|
|
|
5891
5948
|
};
|
|
5892
5949
|
}
|
|
5893
5950
|
const args = {
|
|
5894
|
-
path:
|
|
5951
|
+
path: path3,
|
|
5895
5952
|
content,
|
|
5896
5953
|
mode
|
|
5897
5954
|
};
|
|
@@ -5920,16 +5977,15 @@ var _FileSystem = class _FileSystem {
|
|
|
5920
5977
|
}
|
|
5921
5978
|
}
|
|
5922
5979
|
/**
|
|
5923
|
-
* Reads
|
|
5924
|
-
* Corresponds to Python's read_large_file() method
|
|
5980
|
+
* Reads the contents of a file. Automatically handles large files by chunking.
|
|
5925
5981
|
*
|
|
5926
5982
|
* @param path - Path to the file to read.
|
|
5927
|
-
* @param chunkSize - Optional: Size of each chunk in bytes. Default is 60KB.
|
|
5928
5983
|
* @returns FileContentResult with complete file content and requestId
|
|
5929
5984
|
*/
|
|
5930
|
-
async
|
|
5985
|
+
async readFile(path3) {
|
|
5986
|
+
const chunkSize = DEFAULT_CHUNK_SIZE;
|
|
5931
5987
|
try {
|
|
5932
|
-
const fileInfoResult = await this.getFileInfo(
|
|
5988
|
+
const fileInfoResult = await this.getFileInfo(path3);
|
|
5933
5989
|
if (!fileInfoResult.success) {
|
|
5934
5990
|
return {
|
|
5935
5991
|
requestId: fileInfoResult.requestId,
|
|
@@ -5943,7 +5999,7 @@ var _FileSystem = class _FileSystem {
|
|
|
5943
5999
|
requestId: fileInfoResult.requestId,
|
|
5944
6000
|
success: false,
|
|
5945
6001
|
content: "",
|
|
5946
|
-
errorMessage: `Path does not exist or is a directory: ${
|
|
6002
|
+
errorMessage: `Path does not exist or is a directory: ${path3}`
|
|
5947
6003
|
};
|
|
5948
6004
|
}
|
|
5949
6005
|
const fileSize = fileInfoResult.fileInfo.size || 0;
|
|
@@ -5963,7 +6019,7 @@ var _FileSystem = class _FileSystem {
|
|
|
5963
6019
|
length = fileSize - offset;
|
|
5964
6020
|
}
|
|
5965
6021
|
try {
|
|
5966
|
-
const chunkResult = await this.
|
|
6022
|
+
const chunkResult = await this.readFileChunk(path3, offset, length);
|
|
5967
6023
|
if (!chunkResult.success) {
|
|
5968
6024
|
return chunkResult;
|
|
5969
6025
|
}
|
|
@@ -5994,25 +6050,25 @@ var _FileSystem = class _FileSystem {
|
|
|
5994
6050
|
}
|
|
5995
6051
|
}
|
|
5996
6052
|
/**
|
|
5997
|
-
* Writes a
|
|
5998
|
-
* Corresponds to Python's write_large_file() method
|
|
6053
|
+
* Writes content to a file. Automatically handles large files by chunking.
|
|
5999
6054
|
*
|
|
6000
6055
|
* @param path - Path to the file to write.
|
|
6001
6056
|
* @param content - Content to write to the file.
|
|
6002
|
-
* @param
|
|
6057
|
+
* @param mode - Optional: Write mode. One of "overwrite", "append", or "create_new". Default is "overwrite".
|
|
6003
6058
|
* @returns BoolResult indicating success or failure with requestId
|
|
6004
6059
|
*/
|
|
6005
|
-
async
|
|
6060
|
+
async writeFile(path3, content, mode = "overwrite") {
|
|
6061
|
+
const chunkSize = DEFAULT_CHUNK_SIZE;
|
|
6006
6062
|
try {
|
|
6007
6063
|
const contentLen = content.length;
|
|
6008
6064
|
if (contentLen <= chunkSize) {
|
|
6009
|
-
return await this.
|
|
6065
|
+
return await this.writeFileChunk(path3, content, mode);
|
|
6010
6066
|
}
|
|
6011
6067
|
const firstChunkEnd = Math.min(chunkSize, contentLen);
|
|
6012
|
-
const firstResult = await this.
|
|
6013
|
-
|
|
6068
|
+
const firstResult = await this.writeFileChunk(
|
|
6069
|
+
path3,
|
|
6014
6070
|
content.substring(0, firstChunkEnd),
|
|
6015
|
-
|
|
6071
|
+
mode
|
|
6016
6072
|
);
|
|
6017
6073
|
if (!firstResult.success) {
|
|
6018
6074
|
return firstResult;
|
|
@@ -6020,8 +6076,8 @@ var _FileSystem = class _FileSystem {
|
|
|
6020
6076
|
let chunkCount = 1;
|
|
6021
6077
|
for (let offset = firstChunkEnd; offset < contentLen; ) {
|
|
6022
6078
|
const end = Math.min(offset + chunkSize, contentLen);
|
|
6023
|
-
const chunkResult = await this.
|
|
6024
|
-
|
|
6079
|
+
const chunkResult = await this.writeFileChunk(
|
|
6080
|
+
path3,
|
|
6025
6081
|
content.substring(offset, end),
|
|
6026
6082
|
"append"
|
|
6027
6083
|
);
|
|
@@ -6044,6 +6100,98 @@ var _FileSystem = class _FileSystem {
|
|
|
6044
6100
|
};
|
|
6045
6101
|
}
|
|
6046
6102
|
}
|
|
6103
|
+
/**
|
|
6104
|
+
* Get file change information for the specified directory path
|
|
6105
|
+
*/
|
|
6106
|
+
async getFileChange(path3) {
|
|
6107
|
+
try {
|
|
6108
|
+
const args = { path: path3 };
|
|
6109
|
+
const result = await this.session.callMcpTool("get_file_change", args);
|
|
6110
|
+
if (!result.success) {
|
|
6111
|
+
return {
|
|
6112
|
+
requestId: result.requestId,
|
|
6113
|
+
success: false,
|
|
6114
|
+
events: [],
|
|
6115
|
+
rawData: result.data || "",
|
|
6116
|
+
errorMessage: result.errorMessage
|
|
6117
|
+
};
|
|
6118
|
+
}
|
|
6119
|
+
const events = this.parseFileChangeData(result.data);
|
|
6120
|
+
return {
|
|
6121
|
+
requestId: result.requestId,
|
|
6122
|
+
success: true,
|
|
6123
|
+
events,
|
|
6124
|
+
rawData: result.data
|
|
6125
|
+
};
|
|
6126
|
+
} catch (error) {
|
|
6127
|
+
return {
|
|
6128
|
+
requestId: "",
|
|
6129
|
+
success: false,
|
|
6130
|
+
events: [],
|
|
6131
|
+
rawData: "",
|
|
6132
|
+
errorMessage: `Failed to get file change: ${error}`
|
|
6133
|
+
};
|
|
6134
|
+
}
|
|
6135
|
+
}
|
|
6136
|
+
/**
|
|
6137
|
+
* Parse raw JSON data into FileChangeEvent array
|
|
6138
|
+
*/
|
|
6139
|
+
parseFileChangeData(rawData) {
|
|
6140
|
+
const events = [];
|
|
6141
|
+
try {
|
|
6142
|
+
const changeData = JSON.parse(rawData);
|
|
6143
|
+
if (Array.isArray(changeData)) {
|
|
6144
|
+
for (const eventDict of changeData) {
|
|
6145
|
+
if (typeof eventDict === "object" && eventDict !== null) {
|
|
6146
|
+
const event = FileChangeEventHelper.fromDict(eventDict);
|
|
6147
|
+
events.push(event);
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
}
|
|
6151
|
+
} catch (error) {
|
|
6152
|
+
console.warn(`Failed to parse JSON data: ${error}`);
|
|
6153
|
+
}
|
|
6154
|
+
return events;
|
|
6155
|
+
}
|
|
6156
|
+
/**
|
|
6157
|
+
* Watch a directory for file changes and call the callback function when changes occur
|
|
6158
|
+
*/
|
|
6159
|
+
async watchDirectory(path3, callback, interval = 500, signal) {
|
|
6160
|
+
console.log(`Starting directory monitoring for: ${path3}`);
|
|
6161
|
+
console.log(`Polling interval: ${interval} ms`);
|
|
6162
|
+
const monitor = /* @__PURE__ */ __name(async () => {
|
|
6163
|
+
while (!_optionalChain([signal, 'optionalAccess', _39 => _39.aborted])) {
|
|
6164
|
+
try {
|
|
6165
|
+
const result = await this.getFileChange(path3);
|
|
6166
|
+
if (result.success && result.events.length > 0) {
|
|
6167
|
+
console.log(`Detected ${result.events.length} file changes:`);
|
|
6168
|
+
for (const event of result.events) {
|
|
6169
|
+
console.log(` - ${FileChangeEventHelper.toString(event)}`);
|
|
6170
|
+
}
|
|
6171
|
+
try {
|
|
6172
|
+
callback(result.events);
|
|
6173
|
+
} catch (error) {
|
|
6174
|
+
console.error(`Error in callback function: ${error}`);
|
|
6175
|
+
}
|
|
6176
|
+
} else if (!result.success) {
|
|
6177
|
+
console.error(`Error monitoring directory: ${result.errorMessage}`);
|
|
6178
|
+
}
|
|
6179
|
+
await new Promise((resolve2) => {
|
|
6180
|
+
const timeoutId = setTimeout(resolve2, interval);
|
|
6181
|
+
_optionalChain([signal, 'optionalAccess', _40 => _40.addEventListener, 'call', _41 => _41("abort", () => {
|
|
6182
|
+
clearTimeout(timeoutId);
|
|
6183
|
+
resolve2(void 0);
|
|
6184
|
+
})]);
|
|
6185
|
+
});
|
|
6186
|
+
} catch (error) {
|
|
6187
|
+
console.error(`Unexpected error in directory monitoring: ${error}`);
|
|
6188
|
+
await new Promise((resolve2) => setTimeout(resolve2, interval));
|
|
6189
|
+
}
|
|
6190
|
+
}
|
|
6191
|
+
console.log(`Stopped monitoring directory: ${path3}`);
|
|
6192
|
+
}, "monitor");
|
|
6193
|
+
return monitor();
|
|
6194
|
+
}
|
|
6047
6195
|
};
|
|
6048
6196
|
__name(_FileSystem, "FileSystem");
|
|
6049
6197
|
var FileSystem = _FileSystem;
|
|
@@ -6141,12 +6289,12 @@ var _Oss = class _Oss {
|
|
|
6141
6289
|
* @returns OSSUploadResult with upload result and requestId
|
|
6142
6290
|
* @throws APIError if the operation fails.
|
|
6143
6291
|
*/
|
|
6144
|
-
async upload(bucket, object,
|
|
6292
|
+
async upload(bucket, object, path3) {
|
|
6145
6293
|
try {
|
|
6146
6294
|
const args = {
|
|
6147
6295
|
bucket,
|
|
6148
6296
|
object,
|
|
6149
|
-
path:
|
|
6297
|
+
path: path3
|
|
6150
6298
|
};
|
|
6151
6299
|
const result = await this.session.callMcpTool("oss_upload", args);
|
|
6152
6300
|
return {
|
|
@@ -6173,11 +6321,11 @@ var _Oss = class _Oss {
|
|
|
6173
6321
|
* @returns OSSUploadResult with upload result and requestId
|
|
6174
6322
|
* @throws APIError if the operation fails.
|
|
6175
6323
|
*/
|
|
6176
|
-
async uploadAnonymous(url,
|
|
6324
|
+
async uploadAnonymous(url, path3) {
|
|
6177
6325
|
try {
|
|
6178
6326
|
const args = {
|
|
6179
6327
|
url,
|
|
6180
|
-
path:
|
|
6328
|
+
path: path3
|
|
6181
6329
|
};
|
|
6182
6330
|
const result = await this.session.callMcpTool("oss_upload_anonymous", args);
|
|
6183
6331
|
return {
|
|
@@ -6205,12 +6353,12 @@ var _Oss = class _Oss {
|
|
|
6205
6353
|
* @returns OSSDownloadResult with download result and requestId
|
|
6206
6354
|
* @throws APIError if the operation fails.
|
|
6207
6355
|
*/
|
|
6208
|
-
async download(bucket, object,
|
|
6356
|
+
async download(bucket, object, path3) {
|
|
6209
6357
|
try {
|
|
6210
6358
|
const args = {
|
|
6211
6359
|
bucket,
|
|
6212
6360
|
object,
|
|
6213
|
-
path:
|
|
6361
|
+
path: path3
|
|
6214
6362
|
};
|
|
6215
6363
|
const result = await this.session.callMcpTool("oss_download", args);
|
|
6216
6364
|
return {
|
|
@@ -6237,11 +6385,11 @@ var _Oss = class _Oss {
|
|
|
6237
6385
|
* @returns OSSDownloadResult with download result and requestId
|
|
6238
6386
|
* @throws APIError if the operation fails.
|
|
6239
6387
|
*/
|
|
6240
|
-
async downloadAnonymous(url,
|
|
6388
|
+
async downloadAnonymous(url, path3) {
|
|
6241
6389
|
try {
|
|
6242
6390
|
const args = {
|
|
6243
6391
|
url,
|
|
6244
|
-
path:
|
|
6392
|
+
path: path3
|
|
6245
6393
|
};
|
|
6246
6394
|
const result = await this.session.callMcpTool("oss_download_anonymous", args);
|
|
6247
6395
|
return {
|
|
@@ -6983,7 +7131,7 @@ var _BrowserAgent = class _BrowserAgent {
|
|
|
6983
7131
|
* Perform an action on the given Playwright Page object, using ActOptions to configure behavior.
|
|
6984
7132
|
* Returns the result of the action.
|
|
6985
7133
|
*/
|
|
6986
|
-
async act(
|
|
7134
|
+
async act(options, page) {
|
|
6987
7135
|
if (!this.browser.isInitialized()) {
|
|
6988
7136
|
throw new BrowserError("Browser must be initialized before calling act.");
|
|
6989
7137
|
}
|
|
@@ -7027,14 +7175,14 @@ var _BrowserAgent = class _BrowserAgent {
|
|
|
7027
7175
|
/**
|
|
7028
7176
|
* Async version of act method for performing actions on the given Playwright Page object.
|
|
7029
7177
|
*/
|
|
7030
|
-
async actAsync(
|
|
7031
|
-
return this.act(
|
|
7178
|
+
async actAsync(options, page) {
|
|
7179
|
+
return this.act(options, page);
|
|
7032
7180
|
}
|
|
7033
7181
|
/**
|
|
7034
7182
|
* Observe elements or state on the given Playwright Page object.
|
|
7035
7183
|
* Returns a tuple containing (success, results).
|
|
7036
7184
|
*/
|
|
7037
|
-
async observe(
|
|
7185
|
+
async observe(options, page) {
|
|
7038
7186
|
if (!this.browser.isInitialized()) {
|
|
7039
7187
|
throw new BrowserError("Browser must be initialized before calling observe.");
|
|
7040
7188
|
}
|
|
@@ -7091,13 +7239,13 @@ var _BrowserAgent = class _BrowserAgent {
|
|
|
7091
7239
|
/**
|
|
7092
7240
|
* Async version of observe method.
|
|
7093
7241
|
*/
|
|
7094
|
-
async observeAsync(
|
|
7095
|
-
return this.observe(
|
|
7242
|
+
async observeAsync(options, page) {
|
|
7243
|
+
return this.observe(options, page);
|
|
7096
7244
|
}
|
|
7097
7245
|
/**
|
|
7098
7246
|
* Extract information from the given Playwright Page object.
|
|
7099
7247
|
*/
|
|
7100
|
-
async extract(
|
|
7248
|
+
async extract(options, page) {
|
|
7101
7249
|
if (!this.browser.isInitialized()) {
|
|
7102
7250
|
throw new BrowserError("Browser must be initialized before calling extract.");
|
|
7103
7251
|
}
|
|
@@ -7158,8 +7306,8 @@ var _BrowserAgent = class _BrowserAgent {
|
|
|
7158
7306
|
/**
|
|
7159
7307
|
* Async version of extract method.
|
|
7160
7308
|
*/
|
|
7161
|
-
async extractAsync(
|
|
7162
|
-
return this.extract(
|
|
7309
|
+
async extractAsync(options, page) {
|
|
7310
|
+
return this.extract(options, page);
|
|
7163
7311
|
}
|
|
7164
7312
|
_getPageAndContextIndex(page) {
|
|
7165
7313
|
if (!page) {
|
|
@@ -7292,13 +7440,14 @@ var _BrowserProxyClass = class _BrowserProxyClass {
|
|
|
7292
7440
|
__name(_BrowserProxyClass, "BrowserProxyClass");
|
|
7293
7441
|
var BrowserProxyClass = _BrowserProxyClass;
|
|
7294
7442
|
var _BrowserOptionClass = class _BrowserOptionClass {
|
|
7295
|
-
constructor(useStealth = false, userAgent, viewport, screen, fingerprint, proxies) {
|
|
7443
|
+
constructor(useStealth = false, userAgent, viewport, screen, fingerprint, solveCaptchas = false, proxies) {
|
|
7296
7444
|
this.useStealth = useStealth;
|
|
7297
7445
|
this.userAgent = userAgent;
|
|
7298
7446
|
this.viewport = viewport;
|
|
7299
7447
|
this.screen = screen;
|
|
7300
7448
|
this.fingerprint = fingerprint;
|
|
7301
|
-
this.
|
|
7449
|
+
this.solveCaptchas = solveCaptchas;
|
|
7450
|
+
this.extensionPath = "/tmp/extensions/";
|
|
7302
7451
|
if (proxies !== void 0) {
|
|
7303
7452
|
if (!Array.isArray(proxies)) {
|
|
7304
7453
|
throw new Error("proxies must be a list");
|
|
@@ -7307,9 +7456,13 @@ var _BrowserOptionClass = class _BrowserOptionClass {
|
|
|
7307
7456
|
throw new Error("proxies list length must be limited to 1");
|
|
7308
7457
|
}
|
|
7309
7458
|
}
|
|
7459
|
+
this.proxies = proxies;
|
|
7310
7460
|
}
|
|
7311
7461
|
toMap() {
|
|
7312
7462
|
const optionMap = {};
|
|
7463
|
+
if (process.env.AGENTBAY_BROWSER_BEHAVIOR_SIMULATE) {
|
|
7464
|
+
optionMap["behaviorSimulate"] = process.env.AGENTBAY_BROWSER_BEHAVIOR_SIMULATE !== "0";
|
|
7465
|
+
}
|
|
7313
7466
|
if (this.useStealth !== void 0) {
|
|
7314
7467
|
optionMap["useStealth"] = this.useStealth;
|
|
7315
7468
|
}
|
|
@@ -7329,9 +7482,15 @@ var _BrowserOptionClass = class _BrowserOptionClass {
|
|
|
7329
7482
|
if (this.fingerprint.locales) fp["locales"] = this.fingerprint.locales;
|
|
7330
7483
|
optionMap["fingerprint"] = fp;
|
|
7331
7484
|
}
|
|
7485
|
+
if (this.solveCaptchas !== void 0) {
|
|
7486
|
+
optionMap["solveCaptchas"] = this.solveCaptchas;
|
|
7487
|
+
}
|
|
7332
7488
|
if (this.proxies !== void 0) {
|
|
7333
7489
|
optionMap["proxies"] = this.proxies.map((proxy) => proxy.toMap());
|
|
7334
7490
|
}
|
|
7491
|
+
if (this.extensionPath !== void 0) {
|
|
7492
|
+
optionMap["extensionPath"] = this.extensionPath;
|
|
7493
|
+
}
|
|
7335
7494
|
return optionMap;
|
|
7336
7495
|
}
|
|
7337
7496
|
fromMap(m) {
|
|
@@ -7357,6 +7516,9 @@ var _BrowserOptionClass = class _BrowserOptionClass {
|
|
|
7357
7516
|
if (map.fingerprint.locales) fp.locales = map.fingerprint.locales;
|
|
7358
7517
|
this.fingerprint = fp;
|
|
7359
7518
|
}
|
|
7519
|
+
if (map.solveCaptchas !== void 0) {
|
|
7520
|
+
this.solveCaptchas = map.solveCaptchas;
|
|
7521
|
+
}
|
|
7360
7522
|
if (map.proxies !== void 0) {
|
|
7361
7523
|
const proxyList = map.proxies;
|
|
7362
7524
|
if (proxyList.length > 1) {
|
|
@@ -7369,6 +7531,9 @@ var _BrowserOptionClass = class _BrowserOptionClass {
|
|
|
7369
7531
|
return BrowserProxyClass.fromMap(proxyData);
|
|
7370
7532
|
}).filter(Boolean);
|
|
7371
7533
|
}
|
|
7534
|
+
if (map.extensionPath !== void 0) {
|
|
7535
|
+
this.extensionPath = map.extensionPath;
|
|
7536
|
+
}
|
|
7372
7537
|
return this;
|
|
7373
7538
|
}
|
|
7374
7539
|
};
|
|
@@ -7407,8 +7572,8 @@ var _Browser = class _Browser {
|
|
|
7407
7572
|
request.browserOption = browserOptionMap;
|
|
7408
7573
|
}
|
|
7409
7574
|
const response = this.session.getClient().initBrowserSync(request);
|
|
7410
|
-
log(`Response from init_browser data:`, _optionalChain([response, 'access',
|
|
7411
|
-
const success = _optionalChain([response, 'access',
|
|
7575
|
+
log(`Response from init_browser data:`, _optionalChain([response, 'access', _42 => _42.body, 'optionalAccess', _43 => _43.data]));
|
|
7576
|
+
const success = _optionalChain([response, 'access', _44 => _44.body, 'optionalAccess', _45 => _45.data, 'optionalAccess', _46 => _46.port]) !== null && _optionalChain([response, 'access', _47 => _47.body, 'optionalAccess', _48 => _48.data, 'optionalAccess', _49 => _49.port]) !== void 0;
|
|
7412
7577
|
if (success) {
|
|
7413
7578
|
this._initialized = true;
|
|
7414
7579
|
this._option = browserOption;
|
|
@@ -7448,8 +7613,8 @@ var _Browser = class _Browser {
|
|
|
7448
7613
|
request.browserOption = browserOptionMap;
|
|
7449
7614
|
}
|
|
7450
7615
|
const response = await this.session.getClient().initBrowser(request);
|
|
7451
|
-
log(`Response from init_browser data:`, _optionalChain([response, 'access',
|
|
7452
|
-
const success = _optionalChain([response, 'access',
|
|
7616
|
+
log(`Response from init_browser data:`, _optionalChain([response, 'access', _50 => _50.body, 'optionalAccess', _51 => _51.data]));
|
|
7617
|
+
const success = _optionalChain([response, 'access', _52 => _52.body, 'optionalAccess', _53 => _53.data, 'optionalAccess', _54 => _54.port]) !== null && _optionalChain([response, 'access', _55 => _55.body, 'optionalAccess', _56 => _56.data, 'optionalAccess', _57 => _57.port]) !== void 0;
|
|
7453
7618
|
if (success) {
|
|
7454
7619
|
this._initialized = true;
|
|
7455
7620
|
this._option = browserOption;
|
|
@@ -7529,7 +7694,6 @@ var _Session = class _Session {
|
|
|
7529
7694
|
* @param sessionId - The ID of this session.
|
|
7530
7695
|
*/
|
|
7531
7696
|
constructor(agentBay, sessionId) {
|
|
7532
|
-
this.resourceUrl = "";
|
|
7533
7697
|
// VPC-related information
|
|
7534
7698
|
this.isVpc = false;
|
|
7535
7699
|
// Whether this session uses VPC resources
|
|
@@ -7540,7 +7704,6 @@ var _Session = class _Session {
|
|
|
7540
7704
|
this.mcpTools = [];
|
|
7541
7705
|
this.agentBay = agentBay;
|
|
7542
7706
|
this.sessionId = sessionId;
|
|
7543
|
-
this.resourceUrl = "";
|
|
7544
7707
|
this.fileSystem = new FileSystem(this);
|
|
7545
7708
|
this.command = new Command(this);
|
|
7546
7709
|
this.code = new Code(this);
|
|
@@ -7666,7 +7829,7 @@ var _Session = class _Session {
|
|
|
7666
7829
|
log(`Response from release_mcp_session: ${JSON.stringify(response)}`);
|
|
7667
7830
|
const requestId = extractRequestId(response) || "";
|
|
7668
7831
|
const responseBody = response.body;
|
|
7669
|
-
const success = _optionalChain([responseBody, 'optionalAccess',
|
|
7832
|
+
const success = _optionalChain([responseBody, 'optionalAccess', _58 => _58.success]) !== false;
|
|
7670
7833
|
if (!success) {
|
|
7671
7834
|
return {
|
|
7672
7835
|
requestId,
|
|
@@ -7786,9 +7949,9 @@ var _Session = class _Session {
|
|
|
7786
7949
|
});
|
|
7787
7950
|
const response = await this.getClient().getLabel(request);
|
|
7788
7951
|
const requestId = extractRequestId(response) || "";
|
|
7789
|
-
const responseBody = _optionalChain([response, 'optionalAccess',
|
|
7790
|
-
const data = _optionalChain([responseBody, 'optionalAccess',
|
|
7791
|
-
const labelsJSON = _optionalChain([data, 'optionalAccess',
|
|
7952
|
+
const responseBody = _optionalChain([response, 'optionalAccess', _59 => _59.body]);
|
|
7953
|
+
const data = _optionalChain([responseBody, 'optionalAccess', _60 => _60.data]);
|
|
7954
|
+
const labelsJSON = _optionalChain([data, 'optionalAccess', _61 => _61.labels]);
|
|
7792
7955
|
let labels = {};
|
|
7793
7956
|
if (labelsJSON) {
|
|
7794
7957
|
labels = JSON.parse(labelsJSON);
|
|
@@ -7823,16 +7986,15 @@ var _Session = class _Session {
|
|
|
7823
7986
|
log(`Response from GetMcpResource: ${JSON.stringify(response)}`);
|
|
7824
7987
|
const requestId = extractRequestId(response) || "";
|
|
7825
7988
|
const responseBody = response.body;
|
|
7826
|
-
const data = _optionalChain([responseBody, 'optionalAccess',
|
|
7989
|
+
const data = _optionalChain([responseBody, 'optionalAccess', _62 => _62.data]);
|
|
7827
7990
|
const sessionInfo = new SessionInfoClass();
|
|
7828
|
-
if (_optionalChain([data, 'optionalAccess',
|
|
7991
|
+
if (_optionalChain([data, 'optionalAccess', _63 => _63.sessionId])) {
|
|
7829
7992
|
sessionInfo.sessionId = data.sessionId;
|
|
7830
7993
|
}
|
|
7831
|
-
if (_optionalChain([data, 'optionalAccess',
|
|
7994
|
+
if (_optionalChain([data, 'optionalAccess', _64 => _64.resourceUrl])) {
|
|
7832
7995
|
sessionInfo.resourceUrl = data.resourceUrl;
|
|
7833
|
-
this.resourceUrl = data.resourceUrl;
|
|
7834
7996
|
}
|
|
7835
|
-
if (_optionalChain([data, 'optionalAccess',
|
|
7997
|
+
if (_optionalChain([data, 'optionalAccess', _65 => _65.desktopInfo])) {
|
|
7836
7998
|
const desktopInfo = data.desktopInfo;
|
|
7837
7999
|
if (desktopInfo.appId) {
|
|
7838
8000
|
sessionInfo.appId = desktopInfo.appId;
|
|
@@ -7929,13 +8091,13 @@ var _Session = class _Session {
|
|
|
7929
8091
|
});
|
|
7930
8092
|
const response = await this.agentBay.getClient().getLink(request);
|
|
7931
8093
|
const requestId = extractRequestId(response) || "";
|
|
7932
|
-
const responseBody = _optionalChain([response, 'optionalAccess',
|
|
8094
|
+
const responseBody = _optionalChain([response, 'optionalAccess', _66 => _66.body]);
|
|
7933
8095
|
if (typeof responseBody !== "object") {
|
|
7934
8096
|
throw new Error(
|
|
7935
8097
|
"Invalid response format: expected a dictionary from response body"
|
|
7936
8098
|
);
|
|
7937
8099
|
}
|
|
7938
|
-
let data = _optionalChain([responseBody, 'optionalAccess',
|
|
8100
|
+
let data = _optionalChain([responseBody, 'optionalAccess', _67 => _67.data]) || {};
|
|
7939
8101
|
log(`Data: ${JSON.stringify(data)}`);
|
|
7940
8102
|
if (typeof data !== "object") {
|
|
7941
8103
|
try {
|
|
@@ -8087,7 +8249,7 @@ var _Session = class _Session {
|
|
|
8087
8249
|
args: argsJSON
|
|
8088
8250
|
});
|
|
8089
8251
|
const response = await this.getClient().callMcpTool(callToolRequest);
|
|
8090
|
-
if (!_optionalChain([response, 'access',
|
|
8252
|
+
if (!_optionalChain([response, 'access', _68 => _68.body, 'optionalAccess', _69 => _69.data])) {
|
|
8091
8253
|
return {
|
|
8092
8254
|
success: false,
|
|
8093
8255
|
data: "",
|
|
@@ -8142,6 +8304,7 @@ var _AgentBay = class _AgentBay {
|
|
|
8142
8304
|
*/
|
|
8143
8305
|
constructor(options = {}) {
|
|
8144
8306
|
this.sessions = /* @__PURE__ */ new Map();
|
|
8307
|
+
loadDotEnv();
|
|
8145
8308
|
this.apiKey = options.apiKey || process.env.AGENTBAY_API_KEY || "";
|
|
8146
8309
|
if (!this.apiKey) {
|
|
8147
8310
|
throw new AuthenticationError(
|
|
@@ -8242,7 +8405,7 @@ var _AgentBay = class _AgentBay {
|
|
|
8242
8405
|
log(requestLog);
|
|
8243
8406
|
const response = await this.client.createMcpSession(request);
|
|
8244
8407
|
const requestId = extractRequestId(response) || "";
|
|
8245
|
-
log("response data =", _optionalChain([response, 'access',
|
|
8408
|
+
log("response data =", _optionalChain([response, 'access', _70 => _70.body, 'optionalAccess', _71 => _71.data]));
|
|
8246
8409
|
if (requestId) {
|
|
8247
8410
|
log(`requestId = ${requestId}`);
|
|
8248
8411
|
}
|
|
@@ -8274,9 +8437,6 @@ var _AgentBay = class _AgentBay {
|
|
|
8274
8437
|
log("session_id =", sessionId);
|
|
8275
8438
|
log("resource_url =", resourceUrl);
|
|
8276
8439
|
const session = new Session(this, sessionId);
|
|
8277
|
-
if (resourceUrl) {
|
|
8278
|
-
session.resourceUrl = resourceUrl;
|
|
8279
|
-
}
|
|
8280
8440
|
session.isVpc = params.isVpc || false;
|
|
8281
8441
|
if (data.networkInterfaceIp) {
|
|
8282
8442
|
session.networkInterfaceIp = data.networkInterfaceIp;
|
|
@@ -8298,7 +8458,7 @@ var _AgentBay = class _AgentBay {
|
|
|
8298
8458
|
if (hasPersistenceData) {
|
|
8299
8459
|
log("Waiting for context synchronization to complete...");
|
|
8300
8460
|
const maxRetries = 150;
|
|
8301
|
-
const retryInterval =
|
|
8461
|
+
const retryInterval = 1500;
|
|
8302
8462
|
for (let retry = 0; retry < maxRetries; retry++) {
|
|
8303
8463
|
try {
|
|
8304
8464
|
const infoResult = await session.context.info();
|
|
@@ -8383,8 +8543,8 @@ var _AgentBay = class _AgentBay {
|
|
|
8383
8543
|
);
|
|
8384
8544
|
const response = await this.client.listSession(listSessionRequest);
|
|
8385
8545
|
const body = response.body;
|
|
8386
|
-
const requestId = extractRequestId(_optionalChain([body, 'optionalAccess',
|
|
8387
|
-
if (_optionalChain([body, 'optionalAccess',
|
|
8546
|
+
const requestId = extractRequestId(_optionalChain([body, 'optionalAccess', _72 => _72.requestId])) || "";
|
|
8547
|
+
if (_optionalChain([body, 'optionalAccess', _73 => _73.data]) && typeof body.data === "object" && body.success && body.success !== true) {
|
|
8388
8548
|
return {
|
|
8389
8549
|
requestId,
|
|
8390
8550
|
success: false,
|
|
@@ -8405,7 +8565,7 @@ var _AgentBay = class _AgentBay {
|
|
|
8405
8565
|
maxResults = parseInt(String(body.maxResults || 0)) || maxResults;
|
|
8406
8566
|
totalCount = parseInt(String(body.totalCount || 0));
|
|
8407
8567
|
}
|
|
8408
|
-
const responseData = _optionalChain([body, 'optionalAccess',
|
|
8568
|
+
const responseData = _optionalChain([body, 'optionalAccess', _74 => _74.data]);
|
|
8409
8569
|
if (Array.isArray(responseData)) {
|
|
8410
8570
|
for (const sessionData of responseData) {
|
|
8411
8571
|
if (sessionData && typeof sessionData === "object") {
|
|
@@ -8481,6 +8641,366 @@ var AgentBay = _AgentBay;
|
|
|
8481
8641
|
// src/agent/index.ts
|
|
8482
8642
|
init_cjs_shims();
|
|
8483
8643
|
|
|
8644
|
+
// src/extension.ts
|
|
8645
|
+
init_cjs_shims();
|
|
8646
|
+
|
|
8647
|
+
|
|
8648
|
+
var _crypto = require('crypto'); var crypto = _interopRequireWildcard(_crypto);
|
|
8649
|
+
var _nodefetch = require('node-fetch'); var _nodefetch2 = _interopRequireDefault(_nodefetch);
|
|
8650
|
+
var EXTENSIONS_BASE_PATH = "/tmp/extensions";
|
|
8651
|
+
var _Extension = class _Extension {
|
|
8652
|
+
/**
|
|
8653
|
+
* Initialize an Extension object.
|
|
8654
|
+
*
|
|
8655
|
+
* @param id - The unique identifier of the extension.
|
|
8656
|
+
* @param name - The name of the extension.
|
|
8657
|
+
* @param createdAt - Date and time when the extension was created.
|
|
8658
|
+
*/
|
|
8659
|
+
constructor(id, name, createdAt) {
|
|
8660
|
+
this.id = id;
|
|
8661
|
+
this.name = name;
|
|
8662
|
+
this.createdAt = createdAt;
|
|
8663
|
+
}
|
|
8664
|
+
};
|
|
8665
|
+
__name(_Extension, "Extension");
|
|
8666
|
+
var Extension = _Extension;
|
|
8667
|
+
var _ExtensionOption = class _ExtensionOption {
|
|
8668
|
+
/**
|
|
8669
|
+
* Initialize ExtensionOption with context and extension configuration.
|
|
8670
|
+
*
|
|
8671
|
+
* @param contextId - ID of the extension context for browser extensions.
|
|
8672
|
+
* This should match the context where extensions are stored.
|
|
8673
|
+
* @param extensionIds - List of extension IDs to be loaded in the browser session.
|
|
8674
|
+
* Each ID should correspond to a valid extension in the context.
|
|
8675
|
+
*
|
|
8676
|
+
* @throws {Error} If contextId is empty or extensionIds is empty.
|
|
8677
|
+
*/
|
|
8678
|
+
constructor(contextId, extensionIds) {
|
|
8679
|
+
if (!contextId || !contextId.trim()) {
|
|
8680
|
+
throw new Error("contextId cannot be empty");
|
|
8681
|
+
}
|
|
8682
|
+
if (!extensionIds || extensionIds.length === 0) {
|
|
8683
|
+
throw new Error("extensionIds cannot be empty");
|
|
8684
|
+
}
|
|
8685
|
+
this.contextId = contextId;
|
|
8686
|
+
this.extensionIds = extensionIds;
|
|
8687
|
+
}
|
|
8688
|
+
/**
|
|
8689
|
+
* String representation of ExtensionOption.
|
|
8690
|
+
*/
|
|
8691
|
+
toString() {
|
|
8692
|
+
return `ExtensionOption(contextId='${this.contextId}', extensionIds=${JSON.stringify(this.extensionIds)})`;
|
|
8693
|
+
}
|
|
8694
|
+
/**
|
|
8695
|
+
* Human-readable string representation.
|
|
8696
|
+
*/
|
|
8697
|
+
toDisplayString() {
|
|
8698
|
+
return `Extension Config: ${this.extensionIds.length} extension(s) in context '${this.contextId}'`;
|
|
8699
|
+
}
|
|
8700
|
+
/**
|
|
8701
|
+
* Validate the extension option configuration.
|
|
8702
|
+
*
|
|
8703
|
+
* @returns True if configuration is valid, false otherwise.
|
|
8704
|
+
*/
|
|
8705
|
+
validate() {
|
|
8706
|
+
try {
|
|
8707
|
+
if (!this.contextId || !this.contextId.trim()) {
|
|
8708
|
+
return false;
|
|
8709
|
+
}
|
|
8710
|
+
if (!this.extensionIds || this.extensionIds.length === 0) {
|
|
8711
|
+
return false;
|
|
8712
|
+
}
|
|
8713
|
+
for (const extId of this.extensionIds) {
|
|
8714
|
+
if (typeof extId !== "string" || !extId.trim()) {
|
|
8715
|
+
return false;
|
|
8716
|
+
}
|
|
8717
|
+
}
|
|
8718
|
+
return true;
|
|
8719
|
+
} catch (error) {
|
|
8720
|
+
return false;
|
|
8721
|
+
}
|
|
8722
|
+
}
|
|
8723
|
+
};
|
|
8724
|
+
__name(_ExtensionOption, "ExtensionOption");
|
|
8725
|
+
var ExtensionOption = _ExtensionOption;
|
|
8726
|
+
var _ExtensionsService = class _ExtensionsService {
|
|
8727
|
+
/**
|
|
8728
|
+
* Initializes the ExtensionsService with a context.
|
|
8729
|
+
*
|
|
8730
|
+
* @param agentBay - The AgentBay client instance.
|
|
8731
|
+
* @param contextId - The context ID or name. If empty or not provided,
|
|
8732
|
+
* a default context name will be generated automatically.
|
|
8733
|
+
* If the context doesn't exist, it will be automatically created.
|
|
8734
|
+
*
|
|
8735
|
+
* Note:
|
|
8736
|
+
* The service automatically detects if the context exists. If not,
|
|
8737
|
+
* it creates a new context with the provided name or a generated default name.
|
|
8738
|
+
* Context initialization is handled lazily on first use.
|
|
8739
|
+
*/
|
|
8740
|
+
constructor(agentBay, contextId = "") {
|
|
8741
|
+
this._initializationPromise = null;
|
|
8742
|
+
if (!agentBay) {
|
|
8743
|
+
throw new AgentBayError("AgentBay instance is required");
|
|
8744
|
+
}
|
|
8745
|
+
if (!agentBay.context) {
|
|
8746
|
+
throw new AgentBayError("AgentBay instance must have a context service");
|
|
8747
|
+
}
|
|
8748
|
+
this.agentBay = agentBay;
|
|
8749
|
+
this.contextService = agentBay.context;
|
|
8750
|
+
this.autoCreated = true;
|
|
8751
|
+
if (!contextId || contextId.trim() === "") {
|
|
8752
|
+
contextId = `extensions-${Math.floor(Date.now() / 1e3)}`;
|
|
8753
|
+
log(`Generated default context name: ${contextId}`);
|
|
8754
|
+
}
|
|
8755
|
+
this.contextName = contextId;
|
|
8756
|
+
this._initializationPromise = this._initializeContext();
|
|
8757
|
+
}
|
|
8758
|
+
/**
|
|
8759
|
+
* Internal method to initialize the context.
|
|
8760
|
+
* This ensures the context is ready before any operations.
|
|
8761
|
+
*/
|
|
8762
|
+
async _initializeContext() {
|
|
8763
|
+
try {
|
|
8764
|
+
const contextResult = await this.contextService.get(this.contextName, true);
|
|
8765
|
+
if (!contextResult.success || !contextResult.context) {
|
|
8766
|
+
throw new AgentBayError(`Failed to create extension repository context: ${this.contextName}`);
|
|
8767
|
+
}
|
|
8768
|
+
this.extensionContext = contextResult.context;
|
|
8769
|
+
this.contextId = this.extensionContext.id;
|
|
8770
|
+
} catch (error) {
|
|
8771
|
+
throw new AgentBayError(`Failed to initialize ExtensionsService: ${error instanceof Error ? error.message : String(error)}`);
|
|
8772
|
+
}
|
|
8773
|
+
}
|
|
8774
|
+
/**
|
|
8775
|
+
* Ensures the service is initialized before performing operations.
|
|
8776
|
+
*/
|
|
8777
|
+
async _ensureInitialized() {
|
|
8778
|
+
if (this._initializationPromise) {
|
|
8779
|
+
await this._initializationPromise;
|
|
8780
|
+
this._initializationPromise = null;
|
|
8781
|
+
}
|
|
8782
|
+
}
|
|
8783
|
+
/**
|
|
8784
|
+
* An internal helper method that encapsulates the flow of "get upload URL for a specific path and upload".
|
|
8785
|
+
* Uses the existing context service for file operations.
|
|
8786
|
+
*
|
|
8787
|
+
* @param localPath - The path to the local file.
|
|
8788
|
+
* @param remotePath - The path of the file in context storage.
|
|
8789
|
+
*
|
|
8790
|
+
* @throws {AgentBayError} If getting the credential or uploading fails.
|
|
8791
|
+
*/
|
|
8792
|
+
async _uploadToCloud(localPath, remotePath) {
|
|
8793
|
+
try {
|
|
8794
|
+
const urlResult = await this.contextService.getFileUploadUrl(this.contextId, remotePath);
|
|
8795
|
+
if (!urlResult.success || !urlResult.url) {
|
|
8796
|
+
throw new AgentBayError(`Failed to get upload URL: ${urlResult.url || "No URL returned"}`);
|
|
8797
|
+
}
|
|
8798
|
+
const preSignedUrl = urlResult.url;
|
|
8799
|
+
const fileBuffer = fs2.readFileSync(localPath);
|
|
8800
|
+
const response = await _nodefetch2.default.call(void 0, preSignedUrl, {
|
|
8801
|
+
method: "PUT",
|
|
8802
|
+
body: fileBuffer
|
|
8803
|
+
});
|
|
8804
|
+
if (!response.ok) {
|
|
8805
|
+
throw new AgentBayError(`HTTP error uploading file: ${response.status} ${response.statusText}`);
|
|
8806
|
+
}
|
|
8807
|
+
} catch (error) {
|
|
8808
|
+
if (error instanceof AgentBayError) {
|
|
8809
|
+
throw error;
|
|
8810
|
+
}
|
|
8811
|
+
throw new AgentBayError(`An error occurred while uploading the file: ${error instanceof Error ? error.message : String(error)}`);
|
|
8812
|
+
}
|
|
8813
|
+
}
|
|
8814
|
+
/**
|
|
8815
|
+
* Lists all available browser extensions within this context from the cloud.
|
|
8816
|
+
* Uses the context service to list files under the extensions directory.
|
|
8817
|
+
*
|
|
8818
|
+
* @returns Promise that resolves to an array of Extension objects.
|
|
8819
|
+
* @throws {AgentBayError} If listing extensions fails.
|
|
8820
|
+
*/
|
|
8821
|
+
async list() {
|
|
8822
|
+
await this._ensureInitialized();
|
|
8823
|
+
try {
|
|
8824
|
+
const fileListResult = await this.contextService.listFiles(
|
|
8825
|
+
this.contextId,
|
|
8826
|
+
EXTENSIONS_BASE_PATH,
|
|
8827
|
+
1,
|
|
8828
|
+
// pageNumber
|
|
8829
|
+
100
|
|
8830
|
+
// pageSize - reasonable limit for extensions
|
|
8831
|
+
);
|
|
8832
|
+
if (!fileListResult.success) {
|
|
8833
|
+
throw new AgentBayError("Failed to list extensions: Context file listing failed.");
|
|
8834
|
+
}
|
|
8835
|
+
const extensions = [];
|
|
8836
|
+
for (const fileEntry of fileListResult.entries) {
|
|
8837
|
+
const extensionId = fileEntry.fileName || fileEntry.filePath;
|
|
8838
|
+
extensions.push(new Extension(
|
|
8839
|
+
extensionId,
|
|
8840
|
+
fileEntry.fileName || extensionId,
|
|
8841
|
+
fileEntry.gmtCreate
|
|
8842
|
+
));
|
|
8843
|
+
}
|
|
8844
|
+
return extensions;
|
|
8845
|
+
} catch (error) {
|
|
8846
|
+
if (error instanceof AgentBayError) {
|
|
8847
|
+
throw error;
|
|
8848
|
+
}
|
|
8849
|
+
throw new AgentBayError(`An error occurred while listing browser extensions: ${error instanceof Error ? error.message : String(error)}`);
|
|
8850
|
+
}
|
|
8851
|
+
}
|
|
8852
|
+
/**
|
|
8853
|
+
* Uploads a new browser extension from a local path into the current context.
|
|
8854
|
+
*
|
|
8855
|
+
* @param localPath - Path to the local extension file (must be a .zip file).
|
|
8856
|
+
* @returns Promise that resolves to an Extension object.
|
|
8857
|
+
* @throws {Error} If the local file doesn't exist.
|
|
8858
|
+
* @throws {Error} If the file format is not supported (only .zip is supported).
|
|
8859
|
+
* @throws {AgentBayError} If upload fails.
|
|
8860
|
+
*/
|
|
8861
|
+
async create(localPath) {
|
|
8862
|
+
await this._ensureInitialized();
|
|
8863
|
+
if (!fs2.existsSync(localPath)) {
|
|
8864
|
+
throw new Error(`The specified local file was not found: ${localPath}`);
|
|
8865
|
+
}
|
|
8866
|
+
const fileExtension = path2.extname(localPath).toLowerCase();
|
|
8867
|
+
if (fileExtension !== ".zip") {
|
|
8868
|
+
throw new Error(`Unsupported plugin format '${fileExtension}'. Only ZIP format (.zip) is supported.`);
|
|
8869
|
+
}
|
|
8870
|
+
const extensionId = `ext_${crypto.randomBytes(16).toString("hex")}${fileExtension}`;
|
|
8871
|
+
const extensionName = path2.basename(localPath);
|
|
8872
|
+
const remotePath = `${EXTENSIONS_BASE_PATH}/${extensionId}`;
|
|
8873
|
+
await this._uploadToCloud(localPath, remotePath);
|
|
8874
|
+
return new Extension(extensionId, extensionName);
|
|
8875
|
+
}
|
|
8876
|
+
/**
|
|
8877
|
+
* Updates an existing browser extension in the current context with a new file.
|
|
8878
|
+
*
|
|
8879
|
+
* @param extensionId - ID of the extension to update.
|
|
8880
|
+
* @param newLocalPath - Path to the new local extension file.
|
|
8881
|
+
* @returns Promise that resolves to an Extension object.
|
|
8882
|
+
* @throws {Error} If the new local file doesn't exist.
|
|
8883
|
+
* @throws {Error} If the extension doesn't exist in the context.
|
|
8884
|
+
* @throws {AgentBayError} If update fails.
|
|
8885
|
+
*/
|
|
8886
|
+
async update(extensionId, newLocalPath) {
|
|
8887
|
+
await this._ensureInitialized();
|
|
8888
|
+
if (!fs2.existsSync(newLocalPath)) {
|
|
8889
|
+
throw new Error(`The specified new local file was not found: ${newLocalPath}`);
|
|
8890
|
+
}
|
|
8891
|
+
const existingExtensions = await this.list();
|
|
8892
|
+
const extensionExists = existingExtensions.some((ext) => ext.id === extensionId);
|
|
8893
|
+
if (!extensionExists) {
|
|
8894
|
+
throw new Error(`Browser extension with ID '${extensionId}' not found in the context. Cannot update.`);
|
|
8895
|
+
}
|
|
8896
|
+
const remotePath = `${EXTENSIONS_BASE_PATH}/${extensionId}`;
|
|
8897
|
+
await this._uploadToCloud(newLocalPath, remotePath);
|
|
8898
|
+
return new Extension(extensionId, path2.basename(newLocalPath));
|
|
8899
|
+
}
|
|
8900
|
+
/**
|
|
8901
|
+
* Gets detailed information about a specific browser extension.
|
|
8902
|
+
*
|
|
8903
|
+
* @param extensionId - The ID of the extension to get info for.
|
|
8904
|
+
* @returns Promise that resolves to an Extension object if found, undefined otherwise.
|
|
8905
|
+
*/
|
|
8906
|
+
async _getExtensionInfo(extensionId) {
|
|
8907
|
+
await this._ensureInitialized();
|
|
8908
|
+
try {
|
|
8909
|
+
const extensions = await this.list();
|
|
8910
|
+
return extensions.find((ext) => ext.id === extensionId);
|
|
8911
|
+
} catch (error) {
|
|
8912
|
+
logError(`An error occurred while getting extension info for '${extensionId}':`, error);
|
|
8913
|
+
return void 0;
|
|
8914
|
+
}
|
|
8915
|
+
}
|
|
8916
|
+
/**
|
|
8917
|
+
* Cleans up the auto-created context if it was created by this service.
|
|
8918
|
+
*
|
|
8919
|
+
* @returns Promise that resolves to true if cleanup was successful or not needed, false if cleanup failed.
|
|
8920
|
+
*
|
|
8921
|
+
* Note:
|
|
8922
|
+
* This method only works if the context was auto-created by this service.
|
|
8923
|
+
* For existing contexts, no cleanup is performed.
|
|
8924
|
+
*/
|
|
8925
|
+
async cleanup() {
|
|
8926
|
+
await this._ensureInitialized();
|
|
8927
|
+
if (!this.autoCreated) {
|
|
8928
|
+
return true;
|
|
8929
|
+
}
|
|
8930
|
+
try {
|
|
8931
|
+
const deleteResult = await this.contextService.delete(this.extensionContext);
|
|
8932
|
+
if (deleteResult) {
|
|
8933
|
+
log(`Extension context deleted: ${this.contextName} (ID: ${this.contextId})`);
|
|
8934
|
+
return true;
|
|
8935
|
+
} else {
|
|
8936
|
+
logError(`Warning: Failed to delete extension context: ${this.contextName}`, new Error("Delete operation returned false"));
|
|
8937
|
+
return false;
|
|
8938
|
+
}
|
|
8939
|
+
} catch (error) {
|
|
8940
|
+
logError(`Warning: Failed to delete extension context:`, error);
|
|
8941
|
+
return false;
|
|
8942
|
+
}
|
|
8943
|
+
}
|
|
8944
|
+
/**
|
|
8945
|
+
* Deletes a browser extension from the current context.
|
|
8946
|
+
*
|
|
8947
|
+
* @param extensionId - ID of the extension to delete.
|
|
8948
|
+
* @returns Promise that resolves to true if deletion was successful, false otherwise.
|
|
8949
|
+
*/
|
|
8950
|
+
async delete(extensionId) {
|
|
8951
|
+
await this._ensureInitialized();
|
|
8952
|
+
const remotePath = `${EXTENSIONS_BASE_PATH}/${extensionId}`;
|
|
8953
|
+
try {
|
|
8954
|
+
const deleteResult = await this.contextService.deleteFile(this.contextId, remotePath);
|
|
8955
|
+
return deleteResult.success;
|
|
8956
|
+
} catch (error) {
|
|
8957
|
+
logError(`An error occurred while deleting browser extension '${extensionId}':`, error);
|
|
8958
|
+
return false;
|
|
8959
|
+
}
|
|
8960
|
+
}
|
|
8961
|
+
/**
|
|
8962
|
+
* Create an ExtensionOption for the current context with specified extension IDs.
|
|
8963
|
+
*
|
|
8964
|
+
* This is a convenience method that creates an ExtensionOption using the current
|
|
8965
|
+
* service's contextId and the provided extension IDs. This option can then be
|
|
8966
|
+
* used with BrowserContext for browser session creation.
|
|
8967
|
+
*
|
|
8968
|
+
* @param extensionIds - List of extension IDs to include in the option.
|
|
8969
|
+
* These should be extensions that exist in the current context.
|
|
8970
|
+
* @returns ExtensionOption configuration object for browser extension integration.
|
|
8971
|
+
* @throws {Error} If extensionIds is empty or invalid.
|
|
8972
|
+
*
|
|
8973
|
+
* @example
|
|
8974
|
+
* ```typescript
|
|
8975
|
+
* // Create extensions
|
|
8976
|
+
* const ext1 = await extensionsService.create("/path/to/ext1.zip");
|
|
8977
|
+
* const ext2 = await extensionsService.create("/path/to/ext2.zip");
|
|
8978
|
+
*
|
|
8979
|
+
* // Create extension option for browser integration
|
|
8980
|
+
* const extOption = extensionsService.createExtensionOption([ext1.id, ext2.id]);
|
|
8981
|
+
*
|
|
8982
|
+
* // Use with BrowserContext
|
|
8983
|
+
* const browserContext = new BrowserContext({
|
|
8984
|
+
* contextId: "browser_session",
|
|
8985
|
+
* autoUpload: true,
|
|
8986
|
+
* extensionContextId: extOption.contextId,
|
|
8987
|
+
* extensionIds: extOption.extensionIds
|
|
8988
|
+
* });
|
|
8989
|
+
* ```
|
|
8990
|
+
*/
|
|
8991
|
+
createExtensionOption(extensionIds) {
|
|
8992
|
+
if (!this.contextId) {
|
|
8993
|
+
throw new Error("Service not initialized. Please call an async method first or ensure context is created.");
|
|
8994
|
+
}
|
|
8995
|
+
return new ExtensionOption(
|
|
8996
|
+
this.contextId,
|
|
8997
|
+
extensionIds
|
|
8998
|
+
);
|
|
8999
|
+
}
|
|
9000
|
+
};
|
|
9001
|
+
__name(_ExtensionsService, "ExtensionsService");
|
|
9002
|
+
var ExtensionsService = _ExtensionsService;
|
|
9003
|
+
|
|
8484
9004
|
// src/context-sync.ts
|
|
8485
9005
|
init_cjs_shims();
|
|
8486
9006
|
var UploadStrategy = /* @__PURE__ */ ((UploadStrategy2) => {
|
|
@@ -8491,12 +9011,41 @@ var DownloadStrategy = /* @__PURE__ */ ((DownloadStrategy2) => {
|
|
|
8491
9011
|
DownloadStrategy2["DownloadAsync"] = "DownloadAsync";
|
|
8492
9012
|
return DownloadStrategy2;
|
|
8493
9013
|
})(DownloadStrategy || {});
|
|
9014
|
+
var _ExtractPolicyClass = class _ExtractPolicyClass {
|
|
9015
|
+
constructor(extract = true, deleteSrcFile = true, extractToCurrentFolder = false) {
|
|
9016
|
+
this.extract = true;
|
|
9017
|
+
this.deleteSrcFile = true;
|
|
9018
|
+
this.extractToCurrentFolder = false;
|
|
9019
|
+
this.extract = extract;
|
|
9020
|
+
this.deleteSrcFile = deleteSrcFile;
|
|
9021
|
+
this.extractToCurrentFolder = extractToCurrentFolder;
|
|
9022
|
+
}
|
|
9023
|
+
/**
|
|
9024
|
+
* Creates a new extract policy with default values
|
|
9025
|
+
*/
|
|
9026
|
+
static default() {
|
|
9027
|
+
return new _ExtractPolicyClass();
|
|
9028
|
+
}
|
|
9029
|
+
/**
|
|
9030
|
+
* Converts to plain object for JSON serialization
|
|
9031
|
+
*/
|
|
9032
|
+
toDict() {
|
|
9033
|
+
return {
|
|
9034
|
+
extract: this.extract,
|
|
9035
|
+
deleteSrcFile: this.deleteSrcFile,
|
|
9036
|
+
extractToCurrentFolder: this.extractToCurrentFolder
|
|
9037
|
+
};
|
|
9038
|
+
}
|
|
9039
|
+
};
|
|
9040
|
+
__name(_ExtractPolicyClass, "ExtractPolicyClass");
|
|
9041
|
+
var ExtractPolicyClass = _ExtractPolicyClass;
|
|
8494
9042
|
var _SyncPolicyImpl = class _SyncPolicyImpl {
|
|
8495
9043
|
constructor(policy) {
|
|
8496
9044
|
if (policy) {
|
|
8497
9045
|
this.uploadPolicy = policy.uploadPolicy;
|
|
8498
9046
|
this.downloadPolicy = policy.downloadPolicy;
|
|
8499
9047
|
this.deletePolicy = policy.deletePolicy;
|
|
9048
|
+
this.extractPolicy = policy.extractPolicy;
|
|
8500
9049
|
this.bwList = policy.bwList;
|
|
8501
9050
|
}
|
|
8502
9051
|
this.ensureDefaults();
|
|
@@ -8511,6 +9060,9 @@ var _SyncPolicyImpl = class _SyncPolicyImpl {
|
|
|
8511
9060
|
if (!this.deletePolicy) {
|
|
8512
9061
|
this.deletePolicy = newDeletePolicy();
|
|
8513
9062
|
}
|
|
9063
|
+
if (!this.extractPolicy) {
|
|
9064
|
+
this.extractPolicy = newExtractPolicy();
|
|
9065
|
+
}
|
|
8514
9066
|
if (!this.bwList) {
|
|
8515
9067
|
this.bwList = {
|
|
8516
9068
|
whiteLists: [
|
|
@@ -8528,6 +9080,7 @@ var _SyncPolicyImpl = class _SyncPolicyImpl {
|
|
|
8528
9080
|
uploadPolicy: this.uploadPolicy,
|
|
8529
9081
|
downloadPolicy: this.downloadPolicy,
|
|
8530
9082
|
deletePolicy: this.deletePolicy,
|
|
9083
|
+
extractPolicy: this.extractPolicy,
|
|
8531
9084
|
bwList: this.bwList
|
|
8532
9085
|
};
|
|
8533
9086
|
}
|
|
@@ -8535,9 +9088,9 @@ var _SyncPolicyImpl = class _SyncPolicyImpl {
|
|
|
8535
9088
|
__name(_SyncPolicyImpl, "SyncPolicyImpl");
|
|
8536
9089
|
var SyncPolicyImpl = _SyncPolicyImpl;
|
|
8537
9090
|
var _ContextSync = class _ContextSync {
|
|
8538
|
-
constructor(contextId,
|
|
9091
|
+
constructor(contextId, path3, policy) {
|
|
8539
9092
|
this.contextId = contextId;
|
|
8540
|
-
this.path =
|
|
9093
|
+
this.path = path3;
|
|
8541
9094
|
this.policy = policy;
|
|
8542
9095
|
}
|
|
8543
9096
|
// WithPolicy sets the policy and returns the context sync for chaining
|
|
@@ -8570,11 +9123,20 @@ function newDeletePolicy() {
|
|
|
8570
9123
|
};
|
|
8571
9124
|
}
|
|
8572
9125
|
__name(newDeletePolicy, "newDeletePolicy");
|
|
9126
|
+
function newExtractPolicy() {
|
|
9127
|
+
return {
|
|
9128
|
+
extract: true,
|
|
9129
|
+
deleteSrcFile: true,
|
|
9130
|
+
extractToCurrentFolder: false
|
|
9131
|
+
};
|
|
9132
|
+
}
|
|
9133
|
+
__name(newExtractPolicy, "newExtractPolicy");
|
|
8573
9134
|
function newSyncPolicy() {
|
|
8574
9135
|
return {
|
|
8575
9136
|
uploadPolicy: newUploadPolicy(),
|
|
8576
9137
|
downloadPolicy: newDownloadPolicy(),
|
|
8577
9138
|
deletePolicy: newDeletePolicy(),
|
|
9139
|
+
extractPolicy: newExtractPolicy(),
|
|
8578
9140
|
bwList: {
|
|
8579
9141
|
whiteLists: [
|
|
8580
9142
|
{
|
|
@@ -8590,13 +9152,98 @@ function newSyncPolicyWithDefaults(policy) {
|
|
|
8590
9152
|
return new SyncPolicyImpl(policy).toJSON();
|
|
8591
9153
|
}
|
|
8592
9154
|
__name(newSyncPolicyWithDefaults, "newSyncPolicyWithDefaults");
|
|
8593
|
-
function newContextSync(contextId,
|
|
8594
|
-
return new ContextSync(contextId,
|
|
9155
|
+
function newContextSync(contextId, path3, policy) {
|
|
9156
|
+
return new ContextSync(contextId, path3, policy);
|
|
8595
9157
|
}
|
|
8596
9158
|
__name(newContextSync, "newContextSync");
|
|
8597
9159
|
|
|
8598
9160
|
// src/session-params.ts
|
|
8599
9161
|
init_cjs_shims();
|
|
9162
|
+
var _BrowserContext = class _BrowserContext {
|
|
9163
|
+
/**
|
|
9164
|
+
* Initialize BrowserContextImpl with optional extension support.
|
|
9165
|
+
*
|
|
9166
|
+
* @param contextId - ID of the browser context to bind to the session.
|
|
9167
|
+
* This identifies the browser instance for the session.
|
|
9168
|
+
* @param autoUpload - Whether to automatically upload browser data
|
|
9169
|
+
* when the session ends. Defaults to true.
|
|
9170
|
+
* @param extensionOption - Extension configuration object containing
|
|
9171
|
+
* contextId and extensionIds. This encapsulates
|
|
9172
|
+
* all extension-related configuration.
|
|
9173
|
+
* Defaults to undefined.
|
|
9174
|
+
*
|
|
9175
|
+
* Extension Configuration:
|
|
9176
|
+
* - **ExtensionOption**: Use extensionOption parameter with an ExtensionOption object
|
|
9177
|
+
* - **No Extensions**: Don't provide extensionOption parameter
|
|
9178
|
+
*
|
|
9179
|
+
* Auto-generation:
|
|
9180
|
+
* - extensionContextSyncs is automatically generated when extensionOption is provided
|
|
9181
|
+
* - extensionContextSyncs will be undefined if no extensionOption is provided
|
|
9182
|
+
* - extensionContextSyncs will be a ContextSync[] if extensionOption is valid
|
|
9183
|
+
*/
|
|
9184
|
+
constructor(contextId, autoUpload = true, extensionOption) {
|
|
9185
|
+
this.contextId = contextId;
|
|
9186
|
+
this.autoUpload = autoUpload;
|
|
9187
|
+
this.extensionOption = extensionOption;
|
|
9188
|
+
if (extensionOption) {
|
|
9189
|
+
this.extensionContextId = extensionOption.contextId;
|
|
9190
|
+
this.extensionIds = extensionOption.extensionIds;
|
|
9191
|
+
this.extensionContextSyncs = this._createExtensionContextSyncs();
|
|
9192
|
+
} else {
|
|
9193
|
+
this.extensionContextId = void 0;
|
|
9194
|
+
this.extensionIds = [];
|
|
9195
|
+
this.extensionContextSyncs = void 0;
|
|
9196
|
+
}
|
|
9197
|
+
}
|
|
9198
|
+
/**
|
|
9199
|
+
* Create ContextSync configurations for browser extensions.
|
|
9200
|
+
*
|
|
9201
|
+
* This method is called only when extensionOption is provided and contains
|
|
9202
|
+
* valid extension configuration (contextId and extensionIds).
|
|
9203
|
+
*
|
|
9204
|
+
* @returns ContextSync[] - List of context sync configurations for extensions.
|
|
9205
|
+
* Returns empty list if extension configuration is invalid.
|
|
9206
|
+
*/
|
|
9207
|
+
_createExtensionContextSyncs() {
|
|
9208
|
+
if (!this.extensionIds || this.extensionIds.length === 0 || !this.extensionContextId) {
|
|
9209
|
+
return [];
|
|
9210
|
+
}
|
|
9211
|
+
const whiteLists = this.extensionIds.map((extId) => ({
|
|
9212
|
+
path: extId,
|
|
9213
|
+
excludePaths: []
|
|
9214
|
+
}));
|
|
9215
|
+
const syncPolicy = {
|
|
9216
|
+
uploadPolicy: {
|
|
9217
|
+
...newUploadPolicy(),
|
|
9218
|
+
autoUpload: false
|
|
9219
|
+
},
|
|
9220
|
+
extractPolicy: {
|
|
9221
|
+
...newExtractPolicy(),
|
|
9222
|
+
extract: true,
|
|
9223
|
+
deleteSrcFile: true
|
|
9224
|
+
},
|
|
9225
|
+
bwList: {
|
|
9226
|
+
whiteLists
|
|
9227
|
+
}
|
|
9228
|
+
};
|
|
9229
|
+
const extensionSync = new ContextSync(
|
|
9230
|
+
this.extensionContextId,
|
|
9231
|
+
"/tmp/extensions/",
|
|
9232
|
+
syncPolicy
|
|
9233
|
+
);
|
|
9234
|
+
return [extensionSync];
|
|
9235
|
+
}
|
|
9236
|
+
/**
|
|
9237
|
+
* Get all context syncs including extension syncs.
|
|
9238
|
+
*
|
|
9239
|
+
* @returns ContextSync[] - All context sync configurations. Returns empty list if no extensions configured.
|
|
9240
|
+
*/
|
|
9241
|
+
getAllContextSyncs() {
|
|
9242
|
+
return this.extensionContextSyncs || [];
|
|
9243
|
+
}
|
|
9244
|
+
};
|
|
9245
|
+
__name(_BrowserContext, "BrowserContext");
|
|
9246
|
+
var BrowserContext = _BrowserContext;
|
|
8600
9247
|
var _CreateSessionParams = class _CreateSessionParams {
|
|
8601
9248
|
constructor() {
|
|
8602
9249
|
this.labels = {};
|
|
@@ -8659,8 +9306,8 @@ var _CreateSessionParams = class _CreateSessionParams {
|
|
|
8659
9306
|
/**
|
|
8660
9307
|
* AddContextSync adds a context sync configuration to the session parameters.
|
|
8661
9308
|
*/
|
|
8662
|
-
addContextSync(contextId,
|
|
8663
|
-
const contextSync = new ContextSync(contextId,
|
|
9309
|
+
addContextSync(contextId, path3, policy) {
|
|
9310
|
+
const contextSync = new ContextSync(contextId, path3, policy);
|
|
8664
9311
|
this.contextSync.push(contextSync);
|
|
8665
9312
|
return this;
|
|
8666
9313
|
}
|
|
@@ -8682,10 +9329,15 @@ var _CreateSessionParams = class _CreateSessionParams {
|
|
|
8682
9329
|
* Convert to plain object for JSON serialization
|
|
8683
9330
|
*/
|
|
8684
9331
|
toJSON() {
|
|
9332
|
+
let allContextSyncs = [...this.contextSync];
|
|
9333
|
+
if (this.browserContext && "getAllContextSyncs" in this.browserContext) {
|
|
9334
|
+
const extensionSyncs = this.browserContext.getAllContextSyncs();
|
|
9335
|
+
allContextSyncs = allContextSyncs.concat(extensionSyncs);
|
|
9336
|
+
}
|
|
8685
9337
|
return {
|
|
8686
9338
|
labels: this.labels,
|
|
8687
9339
|
imageId: this.imageId,
|
|
8688
|
-
contextSync:
|
|
9340
|
+
contextSync: allContextSyncs,
|
|
8689
9341
|
browserContext: this.browserContext,
|
|
8690
9342
|
isVpc: this.isVpc,
|
|
8691
9343
|
mcpPolicyId: this.mcpPolicyId
|
|
@@ -8699,7 +9351,18 @@ var _CreateSessionParams = class _CreateSessionParams {
|
|
|
8699
9351
|
params.labels = config.labels || {};
|
|
8700
9352
|
params.imageId = config.imageId;
|
|
8701
9353
|
params.contextSync = config.contextSync || [];
|
|
8702
|
-
|
|
9354
|
+
if (config.browserContext) {
|
|
9355
|
+
if ("getAllContextSyncs" in config.browserContext) {
|
|
9356
|
+
params.browserContext = config.browserContext;
|
|
9357
|
+
} else {
|
|
9358
|
+
const bc = config.browserContext;
|
|
9359
|
+
params.browserContext = new BrowserContext(
|
|
9360
|
+
bc.contextId,
|
|
9361
|
+
bc.autoUpload,
|
|
9362
|
+
bc.extensionOption
|
|
9363
|
+
);
|
|
9364
|
+
}
|
|
9365
|
+
}
|
|
8703
9366
|
params.isVpc = config.isVpc || false;
|
|
8704
9367
|
params.mcpPolicyId = config.mcpPolicyId;
|
|
8705
9368
|
return params;
|
|
@@ -8830,5 +9493,15 @@ __name(newCreateSessionParams, "newCreateSessionParams");
|
|
|
8830
9493
|
|
|
8831
9494
|
|
|
8832
9495
|
|
|
8833
|
-
|
|
9496
|
+
|
|
9497
|
+
|
|
9498
|
+
|
|
9499
|
+
|
|
9500
|
+
|
|
9501
|
+
|
|
9502
|
+
|
|
9503
|
+
|
|
9504
|
+
|
|
9505
|
+
|
|
9506
|
+
exports.APIError = APIError; exports.Agent = Agent; exports.AgentBay = AgentBay; exports.AgentBayError = AgentBayError; exports.Application = Application; exports.ApplicationError = ApplicationError; exports.ApplyMqttTokenRequest = ApplyMqttTokenRequest; exports.ApplyMqttTokenResponse = ApplyMqttTokenResponse; exports.ApplyMqttTokenResponseBody = ApplyMqttTokenResponseBody; exports.ApplyMqttTokenResponseBodyData = ApplyMqttTokenResponseBodyData; exports.AuthenticationError = AuthenticationError; exports.Browser = Browser; exports.BrowserAgent = BrowserAgent; exports.BrowserContext = BrowserContext; exports.BrowserError = BrowserError; exports.BrowserOptionClass = BrowserOptionClass; exports.BrowserProxyClass = BrowserProxyClass; exports.CallMcpToolRequest = CallMcpToolRequest; exports.CallMcpToolResponse = CallMcpToolResponse; exports.CallMcpToolResponseBody = CallMcpToolResponseBody; exports.Client = Client; exports.Command = Command; exports.CommandError = CommandError; exports.Context = Context; exports.ContextManager = ContextManager; exports.ContextService = ContextService; exports.ContextSync = ContextSync; exports.CreateMcpSessionRequest = CreateMcpSessionRequest; exports.CreateMcpSessionRequestPersistenceDataList = CreateMcpSessionRequestPersistenceDataList; exports.CreateMcpSessionResponse = CreateMcpSessionResponse; exports.CreateMcpSessionResponseBody = CreateMcpSessionResponseBody; exports.CreateMcpSessionResponseBodyData = CreateMcpSessionResponseBodyData; exports.CreateMcpSessionShrinkRequest = CreateMcpSessionShrinkRequest; exports.CreateSessionParams = CreateSessionParams; exports.DeleteContextFileRequest = DeleteContextFileRequest; exports.DeleteContextFileResponse = DeleteContextFileResponse; exports.DeleteContextFileResponseBody = DeleteContextFileResponseBody; exports.DeleteContextRequest = DeleteContextRequest; exports.DeleteContextResponse = DeleteContextResponse; exports.DeleteContextResponseBody = DeleteContextResponseBody; exports.DescribeContextFilesRequest = DescribeContextFilesRequest; exports.DescribeContextFilesResponse = DescribeContextFilesResponse; exports.DescribeContextFilesResponseBody = DescribeContextFilesResponseBody; exports.DownloadStrategy = DownloadStrategy; exports.Extension = Extension; exports.ExtensionOption = ExtensionOption; exports.ExtensionsService = ExtensionsService; exports.ExtractPolicyClass = ExtractPolicyClass; exports.FileChangeEventHelper = FileChangeEventHelper; exports.FileChangeResultHelper = FileChangeResultHelper; exports.FileError = FileError; exports.FileSystem = FileSystem; exports.GetContextFileDownloadUrlRequest = GetContextFileDownloadUrlRequest; exports.GetContextFileDownloadUrlResponse = GetContextFileDownloadUrlResponse; exports.GetContextFileDownloadUrlResponseBody = GetContextFileDownloadUrlResponseBody; exports.GetContextFileUploadUrlRequest = GetContextFileUploadUrlRequest; exports.GetContextFileUploadUrlResponse = GetContextFileUploadUrlResponse; exports.GetContextFileUploadUrlResponseBody = GetContextFileUploadUrlResponseBody; exports.GetContextInfoRequest = GetContextInfoRequest; exports.GetContextInfoResponse = GetContextInfoResponse; exports.GetContextInfoResponseBody = GetContextInfoResponseBody; exports.GetContextInfoResponseBodyData = GetContextInfoResponseBodyData; exports.GetContextRequest = GetContextRequest; exports.GetContextResponse = GetContextResponse; exports.GetContextResponseBody = GetContextResponseBody; exports.GetContextResponseBodyData = GetContextResponseBodyData; exports.GetLabelRequest = GetLabelRequest; exports.GetLabelResponse = GetLabelResponse; exports.GetLabelResponseBody = GetLabelResponseBody; exports.GetLabelResponseBodyData = GetLabelResponseBodyData; exports.GetLinkRequest = GetLinkRequest; exports.GetLinkResponse = GetLinkResponse; exports.GetLinkResponseBody = GetLinkResponseBody; exports.GetLinkResponseBodyData = GetLinkResponseBodyData; exports.GetMcpResourceRequest = GetMcpResourceRequest; exports.GetMcpResourceResponse = GetMcpResourceResponse; exports.GetMcpResourceResponseBody = GetMcpResourceResponseBody; exports.GetMcpResourceResponseBodyData = GetMcpResourceResponseBodyData; exports.GetMcpResourceResponseBodyDataDesktopInfo = GetMcpResourceResponseBodyDataDesktopInfo; exports.InitBrowserRequest = InitBrowserRequest; exports.InitBrowserResponse = InitBrowserResponse; exports.InitBrowserResponseBody = InitBrowserResponseBody; exports.InitBrowserResponseBodyData = InitBrowserResponseBodyData; exports.KeyCode = KeyCode; exports.ListContextsRequest = ListContextsRequest; exports.ListContextsResponse = ListContextsResponse; exports.ListContextsResponseBody = ListContextsResponseBody; exports.ListContextsResponseBodyData = ListContextsResponseBodyData; exports.ListMcpToolsRequest = ListMcpToolsRequest; exports.ListMcpToolsResponse = ListMcpToolsResponse; exports.ListMcpToolsResponseBody = ListMcpToolsResponseBody; exports.ListSessionRequest = ListSessionRequest; exports.ListSessionResponse = ListSessionResponse; exports.ListSessionResponseBody = ListSessionResponseBody; exports.ListSessionResponseBodyData = ListSessionResponseBodyData; exports.ModifyContextRequest = ModifyContextRequest; exports.ModifyContextResponse = ModifyContextResponse; exports.ModifyContextResponseBody = ModifyContextResponseBody; exports.Oss = Oss; exports.OssError = OssError; exports.ReleaseMcpSessionRequest = ReleaseMcpSessionRequest; exports.ReleaseMcpSessionResponse = ReleaseMcpSessionResponse; exports.ReleaseMcpSessionResponseBody = ReleaseMcpSessionResponseBody; exports.Session = Session; exports.SessionError = SessionError; exports.SetLabelRequest = SetLabelRequest; exports.SetLabelResponse = SetLabelResponse; exports.SetLabelResponseBody = SetLabelResponseBody; exports.SyncContextRequest = SyncContextRequest; exports.SyncContextResponse = SyncContextResponse; exports.SyncContextResponseBody = SyncContextResponseBody; exports.SyncPolicyImpl = SyncPolicyImpl; exports.UI = UI; exports.UIError = UIError; exports.UploadStrategy = UploadStrategy; exports.loadConfig = loadConfig; exports.loadDotEnv = loadDotEnv; exports.log = log; exports.logError = logError; exports.newContextManager = newContextManager; exports.newContextSync = newContextSync; exports.newCreateSessionParams = newCreateSessionParams; exports.newDeletePolicy = newDeletePolicy; exports.newDownloadPolicy = newDownloadPolicy; exports.newExtractPolicy = newExtractPolicy; exports.newSyncPolicy = newSyncPolicy; exports.newSyncPolicyWithDefaults = newSyncPolicyWithDefaults; exports.newUploadPolicy = newUploadPolicy;
|
|
8834
9507
|
//# sourceMappingURL=index.cjs.map
|