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.mjs
CHANGED
|
@@ -129,10 +129,10 @@ var require_main = __commonJS({
|
|
|
129
129
|
"node_modules/dotenv/lib/main.js"(exports, module) {
|
|
130
130
|
"use strict";
|
|
131
131
|
init_esm_shims();
|
|
132
|
-
var
|
|
133
|
-
var
|
|
132
|
+
var fs3 = __require("fs");
|
|
133
|
+
var path4 = __require("path");
|
|
134
134
|
var os = __require("os");
|
|
135
|
-
var
|
|
135
|
+
var crypto2 = __require("crypto");
|
|
136
136
|
var packageJson = require_package();
|
|
137
137
|
var version = packageJson.version;
|
|
138
138
|
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
@@ -245,7 +245,7 @@ var require_main = __commonJS({
|
|
|
245
245
|
if (options && options.path && options.path.length > 0) {
|
|
246
246
|
if (Array.isArray(options.path)) {
|
|
247
247
|
for (const filepath of options.path) {
|
|
248
|
-
if (
|
|
248
|
+
if (fs3.existsSync(filepath)) {
|
|
249
249
|
possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
250
250
|
}
|
|
251
251
|
}
|
|
@@ -253,16 +253,16 @@ var require_main = __commonJS({
|
|
|
253
253
|
possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
|
254
254
|
}
|
|
255
255
|
} else {
|
|
256
|
-
possibleVaultPath =
|
|
256
|
+
possibleVaultPath = path4.resolve(process.cwd(), ".env.vault");
|
|
257
257
|
}
|
|
258
|
-
if (
|
|
258
|
+
if (fs3.existsSync(possibleVaultPath)) {
|
|
259
259
|
return possibleVaultPath;
|
|
260
260
|
}
|
|
261
261
|
return null;
|
|
262
262
|
}
|
|
263
263
|
__name(_vaultPath, "_vaultPath");
|
|
264
264
|
function _resolveHome(envPath) {
|
|
265
|
-
return envPath[0] === "~" ?
|
|
265
|
+
return envPath[0] === "~" ? path4.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
266
266
|
}
|
|
267
267
|
__name(_resolveHome, "_resolveHome");
|
|
268
268
|
function _configVault(options) {
|
|
@@ -281,7 +281,7 @@ var require_main = __commonJS({
|
|
|
281
281
|
}
|
|
282
282
|
__name(_configVault, "_configVault");
|
|
283
283
|
function configDotenv(options) {
|
|
284
|
-
const dotenvPath =
|
|
284
|
+
const dotenvPath = path4.resolve(process.cwd(), ".env");
|
|
285
285
|
let encoding = "utf8";
|
|
286
286
|
const debug = Boolean(options && options.debug);
|
|
287
287
|
const quiet = options && "quiet" in options ? options.quiet : true;
|
|
@@ -305,13 +305,13 @@ var require_main = __commonJS({
|
|
|
305
305
|
}
|
|
306
306
|
let lastError;
|
|
307
307
|
const parsedAll = {};
|
|
308
|
-
for (const
|
|
308
|
+
for (const path5 of optionPaths) {
|
|
309
309
|
try {
|
|
310
|
-
const parsed = DotenvModule.parse(
|
|
310
|
+
const parsed = DotenvModule.parse(fs3.readFileSync(path5, { encoding }));
|
|
311
311
|
DotenvModule.populate(parsedAll, parsed, options);
|
|
312
312
|
} catch (e) {
|
|
313
313
|
if (debug) {
|
|
314
|
-
_debug(`Failed to load ${
|
|
314
|
+
_debug(`Failed to load ${path5} ${e.message}`);
|
|
315
315
|
}
|
|
316
316
|
lastError = e;
|
|
317
317
|
}
|
|
@@ -326,7 +326,7 @@ var require_main = __commonJS({
|
|
|
326
326
|
const shortPaths = [];
|
|
327
327
|
for (const filePath of optionPaths) {
|
|
328
328
|
try {
|
|
329
|
-
const relative =
|
|
329
|
+
const relative = path4.relative(process.cwd(), filePath);
|
|
330
330
|
shortPaths.push(relative);
|
|
331
331
|
} catch (e) {
|
|
332
332
|
if (debug) {
|
|
@@ -363,7 +363,7 @@ var require_main = __commonJS({
|
|
|
363
363
|
const authTag = ciphertext.subarray(-16);
|
|
364
364
|
ciphertext = ciphertext.subarray(12, -16);
|
|
365
365
|
try {
|
|
366
|
-
const aesgcm =
|
|
366
|
+
const aesgcm = crypto2.createDecipheriv("aes-256-gcm", key, nonce);
|
|
367
367
|
aesgcm.setAuthTag(authTag);
|
|
368
368
|
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
369
369
|
} catch (error) {
|
|
@@ -3096,7 +3096,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3096
3096
|
);
|
|
3097
3097
|
}
|
|
3098
3098
|
/**
|
|
3099
|
-
*
|
|
3099
|
+
* Call MCP tool
|
|
3100
3100
|
*
|
|
3101
3101
|
* @param request - CallMcpToolRequest
|
|
3102
3102
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3149,7 +3149,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3149
3149
|
);
|
|
3150
3150
|
}
|
|
3151
3151
|
/**
|
|
3152
|
-
*
|
|
3152
|
+
* Call MCP tool
|
|
3153
3153
|
*
|
|
3154
3154
|
* @param request - CallMcpToolRequest
|
|
3155
3155
|
* @returns CallMcpToolResponse
|
|
@@ -3159,7 +3159,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3159
3159
|
return await this.callMcpToolWithOptions(request, runtime);
|
|
3160
3160
|
}
|
|
3161
3161
|
/**
|
|
3162
|
-
*
|
|
3162
|
+
* Create MCP session
|
|
3163
3163
|
*
|
|
3164
3164
|
* @param tmpReq - CreateMcpSessionRequest
|
|
3165
3165
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3224,7 +3224,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3224
3224
|
);
|
|
3225
3225
|
}
|
|
3226
3226
|
/**
|
|
3227
|
-
*
|
|
3227
|
+
* Create MCP session
|
|
3228
3228
|
*
|
|
3229
3229
|
* @param request - CreateMcpSessionRequest
|
|
3230
3230
|
* @returns CreateMcpSessionResponse
|
|
@@ -3234,7 +3234,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3234
3234
|
return await this.createMcpSessionWithOptions(request, runtime);
|
|
3235
3235
|
}
|
|
3236
3236
|
/**
|
|
3237
|
-
*
|
|
3237
|
+
* Delete persistent context
|
|
3238
3238
|
*
|
|
3239
3239
|
* @param request - DeleteContextRequest
|
|
3240
3240
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3269,7 +3269,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3269
3269
|
);
|
|
3270
3270
|
}
|
|
3271
3271
|
/**
|
|
3272
|
-
*
|
|
3272
|
+
* Delete persistent context
|
|
3273
3273
|
*
|
|
3274
3274
|
* @param request - DeleteContextRequest
|
|
3275
3275
|
* @returns DeleteContextResponse
|
|
@@ -3279,7 +3279,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3279
3279
|
return await this.deleteContextWithOptions(request, runtime);
|
|
3280
3280
|
}
|
|
3281
3281
|
/**
|
|
3282
|
-
*
|
|
3282
|
+
* Get context
|
|
3283
3283
|
*
|
|
3284
3284
|
* @param request - GetContextRequest
|
|
3285
3285
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3317,7 +3317,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3317
3317
|
);
|
|
3318
3318
|
}
|
|
3319
3319
|
/**
|
|
3320
|
-
*
|
|
3320
|
+
* Get context
|
|
3321
3321
|
*
|
|
3322
3322
|
* @param request - GetContextRequest
|
|
3323
3323
|
* @returns GetContextResponse
|
|
@@ -3327,7 +3327,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3327
3327
|
return await this.getContextWithOptions(request, runtime);
|
|
3328
3328
|
}
|
|
3329
3329
|
/**
|
|
3330
|
-
*
|
|
3330
|
+
* Get context information
|
|
3331
3331
|
*
|
|
3332
3332
|
* @param request - GetContextInfoRequest
|
|
3333
3333
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3371,7 +3371,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3371
3371
|
);
|
|
3372
3372
|
}
|
|
3373
3373
|
/**
|
|
3374
|
-
*
|
|
3374
|
+
* Get context information
|
|
3375
3375
|
*
|
|
3376
3376
|
* @param request - GetContextInfoRequest
|
|
3377
3377
|
* @returns GetContextInfoResponse
|
|
@@ -3381,7 +3381,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3381
3381
|
return await this.getContextInfoWithOptions(request, runtime);
|
|
3382
3382
|
}
|
|
3383
3383
|
/**
|
|
3384
|
-
*
|
|
3384
|
+
* Get labels
|
|
3385
3385
|
*
|
|
3386
3386
|
* @param request - GetLabelRequest
|
|
3387
3387
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3422,7 +3422,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3422
3422
|
);
|
|
3423
3423
|
}
|
|
3424
3424
|
/**
|
|
3425
|
-
*
|
|
3425
|
+
* Get labels
|
|
3426
3426
|
*
|
|
3427
3427
|
* @param request - GetLabelRequest
|
|
3428
3428
|
* @returns GetLabelResponse
|
|
@@ -3432,7 +3432,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3432
3432
|
return await this.getLabelWithOptions(request, runtime);
|
|
3433
3433
|
}
|
|
3434
3434
|
/**
|
|
3435
|
-
*
|
|
3435
|
+
* Get forwarding link for specific port
|
|
3436
3436
|
*
|
|
3437
3437
|
* @param request - GetLinkRequest
|
|
3438
3438
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3473,7 +3473,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3473
3473
|
);
|
|
3474
3474
|
}
|
|
3475
3475
|
/**
|
|
3476
|
-
*
|
|
3476
|
+
* Get forwarding link for specific port
|
|
3477
3477
|
*
|
|
3478
3478
|
* @param request - GetLinkRequest
|
|
3479
3479
|
* @returns GetLinkResponse
|
|
@@ -3483,7 +3483,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3483
3483
|
return await this.getLinkWithOptions(request, runtime);
|
|
3484
3484
|
}
|
|
3485
3485
|
/**
|
|
3486
|
-
*
|
|
3486
|
+
* Get MCP resource information
|
|
3487
3487
|
*
|
|
3488
3488
|
* @param request - GetMcpResourceRequest
|
|
3489
3489
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3518,7 +3518,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3518
3518
|
);
|
|
3519
3519
|
}
|
|
3520
3520
|
/**
|
|
3521
|
-
*
|
|
3521
|
+
* Get MCP resource information
|
|
3522
3522
|
*
|
|
3523
3523
|
* @param request - GetMcpResourceRequest
|
|
3524
3524
|
* @returns GetMcpResourceResponse
|
|
@@ -3528,7 +3528,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3528
3528
|
return await this.getMcpResourceWithOptions(request, runtime);
|
|
3529
3529
|
}
|
|
3530
3530
|
/**
|
|
3531
|
-
*
|
|
3531
|
+
* Get context list
|
|
3532
3532
|
*
|
|
3533
3533
|
* @param request - ListContextsRequest
|
|
3534
3534
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3566,7 +3566,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3566
3566
|
);
|
|
3567
3567
|
}
|
|
3568
3568
|
/**
|
|
3569
|
-
*
|
|
3569
|
+
* Get context list
|
|
3570
3570
|
*
|
|
3571
3571
|
* @param request - ListContextsRequest
|
|
3572
3572
|
* @returns ListContextsResponse
|
|
@@ -3621,7 +3621,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3621
3621
|
return await this.listMcpToolsWithOptions(request, runtime);
|
|
3622
3622
|
}
|
|
3623
3623
|
/**
|
|
3624
|
-
*
|
|
3624
|
+
* Query session list by label
|
|
3625
3625
|
*
|
|
3626
3626
|
* @param request - ListSessionRequest
|
|
3627
3627
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3662,7 +3662,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3662
3662
|
);
|
|
3663
3663
|
}
|
|
3664
3664
|
/**
|
|
3665
|
-
*
|
|
3665
|
+
* Query session list by label
|
|
3666
3666
|
*
|
|
3667
3667
|
* @param request - ListSessionRequest
|
|
3668
3668
|
* @returns ListSessionResponse
|
|
@@ -3672,7 +3672,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3672
3672
|
return await this.listSessionWithOptions(request, runtime);
|
|
3673
3673
|
}
|
|
3674
3674
|
/**
|
|
3675
|
-
*
|
|
3675
|
+
* Modify context
|
|
3676
3676
|
*
|
|
3677
3677
|
* @param request - ModifyContextRequest
|
|
3678
3678
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3710,7 +3710,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3710
3710
|
);
|
|
3711
3711
|
}
|
|
3712
3712
|
/**
|
|
3713
|
-
*
|
|
3713
|
+
* Modify context
|
|
3714
3714
|
*
|
|
3715
3715
|
* @param request - ModifyContextRequest
|
|
3716
3716
|
* @returns ModifyContextResponse
|
|
@@ -3720,7 +3720,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3720
3720
|
return await this.modifyContextWithOptions(request, runtime);
|
|
3721
3721
|
}
|
|
3722
3722
|
/**
|
|
3723
|
-
*
|
|
3723
|
+
* Release MCP session
|
|
3724
3724
|
*
|
|
3725
3725
|
* @param request - ReleaseMcpSessionRequest
|
|
3726
3726
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3755,7 +3755,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3755
3755
|
);
|
|
3756
3756
|
}
|
|
3757
3757
|
/**
|
|
3758
|
-
*
|
|
3758
|
+
* Release MCP session
|
|
3759
3759
|
*
|
|
3760
3760
|
* @param request - ReleaseMcpSessionRequest
|
|
3761
3761
|
* @returns ReleaseMcpSessionResponse
|
|
@@ -3765,7 +3765,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3765
3765
|
return await this.releaseMcpSessionWithOptions(request, runtime);
|
|
3766
3766
|
}
|
|
3767
3767
|
/**
|
|
3768
|
-
*
|
|
3768
|
+
* Set labels
|
|
3769
3769
|
*
|
|
3770
3770
|
* @param request - SetLabelRequest
|
|
3771
3771
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3803,7 +3803,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3803
3803
|
);
|
|
3804
3804
|
}
|
|
3805
3805
|
/**
|
|
3806
|
-
*
|
|
3806
|
+
* Set labels
|
|
3807
3807
|
*
|
|
3808
3808
|
* @param request - SetLabelRequest
|
|
3809
3809
|
* @returns SetLabelResponse
|
|
@@ -3813,7 +3813,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3813
3813
|
return await this.setLabelWithOptions(request, runtime);
|
|
3814
3814
|
}
|
|
3815
3815
|
/**
|
|
3816
|
-
*
|
|
3816
|
+
* Sync context
|
|
3817
3817
|
*
|
|
3818
3818
|
* @param request - SyncContextRequest
|
|
3819
3819
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3859,7 +3859,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3859
3859
|
);
|
|
3860
3860
|
}
|
|
3861
3861
|
/**
|
|
3862
|
-
*
|
|
3862
|
+
* Sync context
|
|
3863
3863
|
*
|
|
3864
3864
|
* @param request - SyncContextRequest
|
|
3865
3865
|
* @returns SyncContextResponse
|
|
@@ -3869,7 +3869,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3869
3869
|
return await this.syncContextWithOptions(request, runtime);
|
|
3870
3870
|
}
|
|
3871
3871
|
/**
|
|
3872
|
-
*
|
|
3872
|
+
* Initialize browser
|
|
3873
3873
|
*
|
|
3874
3874
|
* @param tmpReq - InitBrowserRequest
|
|
3875
3875
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3910,7 +3910,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3910
3910
|
);
|
|
3911
3911
|
}
|
|
3912
3912
|
/**
|
|
3913
|
-
*
|
|
3913
|
+
* Initialize browser
|
|
3914
3914
|
*
|
|
3915
3915
|
* @param request - InitBrowserRequest
|
|
3916
3916
|
* @returns InitBrowserResponse
|
|
@@ -3920,7 +3920,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3920
3920
|
return await this.initBrowserWithOptions(request, runtime);
|
|
3921
3921
|
}
|
|
3922
3922
|
/**
|
|
3923
|
-
*
|
|
3923
|
+
* Initialize browser (sync version)
|
|
3924
3924
|
*
|
|
3925
3925
|
* @param request - InitBrowserRequest
|
|
3926
3926
|
* @returns InitBrowserResponse
|
|
@@ -3961,7 +3961,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3961
3961
|
);
|
|
3962
3962
|
}
|
|
3963
3963
|
/**
|
|
3964
|
-
*
|
|
3964
|
+
* Get context file upload URL
|
|
3965
3965
|
*
|
|
3966
3966
|
* @param request - DeleteContextFileRequest
|
|
3967
3967
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -3999,7 +3999,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
3999
3999
|
);
|
|
4000
4000
|
}
|
|
4001
4001
|
/**
|
|
4002
|
-
*
|
|
4002
|
+
* Get context file upload URL
|
|
4003
4003
|
*
|
|
4004
4004
|
* @param request - DeleteContextFileRequest
|
|
4005
4005
|
* @returns DeleteContextFileResponse
|
|
@@ -4009,7 +4009,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
4009
4009
|
return await this.deleteContextFileWithOptions(request, runtime);
|
|
4010
4010
|
}
|
|
4011
4011
|
/**
|
|
4012
|
-
*
|
|
4012
|
+
* Query context specific directory files
|
|
4013
4013
|
*
|
|
4014
4014
|
* @param request - DescribeContextFilesRequest
|
|
4015
4015
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -4053,7 +4053,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
4053
4053
|
);
|
|
4054
4054
|
}
|
|
4055
4055
|
/**
|
|
4056
|
-
*
|
|
4056
|
+
* Query context specific directory files
|
|
4057
4057
|
*
|
|
4058
4058
|
* @param request - DescribeContextFilesRequest
|
|
4059
4059
|
* @returns DescribeContextFilesResponse
|
|
@@ -4063,7 +4063,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
4063
4063
|
return await this.describeContextFilesWithOptions(request, runtime);
|
|
4064
4064
|
}
|
|
4065
4065
|
/**
|
|
4066
|
-
*
|
|
4066
|
+
* Get context file upload URL
|
|
4067
4067
|
*
|
|
4068
4068
|
* @param request - GetContextFileDownloadUrlRequest
|
|
4069
4069
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -4101,7 +4101,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
4101
4101
|
);
|
|
4102
4102
|
}
|
|
4103
4103
|
/**
|
|
4104
|
-
*
|
|
4104
|
+
* Get context file upload URL
|
|
4105
4105
|
*
|
|
4106
4106
|
* @param request - GetContextFileDownloadUrlRequest
|
|
4107
4107
|
* @returns GetContextFileDownloadUrlResponse
|
|
@@ -4111,7 +4111,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
4111
4111
|
return await this.getContextFileDownloadUrlWithOptions(request, runtime);
|
|
4112
4112
|
}
|
|
4113
4113
|
/**
|
|
4114
|
-
*
|
|
4114
|
+
* Get context file upload URL
|
|
4115
4115
|
*
|
|
4116
4116
|
* @param request - GetContextFileUploadUrlRequest
|
|
4117
4117
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
@@ -4149,7 +4149,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
4149
4149
|
);
|
|
4150
4150
|
}
|
|
4151
4151
|
/**
|
|
4152
|
-
*
|
|
4152
|
+
* Get context file upload URL
|
|
4153
4153
|
*
|
|
4154
4154
|
* @param request - GetContextFileUploadUrlRequest
|
|
4155
4155
|
* @returns GetContextFileUploadUrlResponse
|
|
@@ -4209,6 +4209,28 @@ function defaultConfig() {
|
|
|
4209
4209
|
};
|
|
4210
4210
|
}
|
|
4211
4211
|
__name(defaultConfig, "defaultConfig");
|
|
4212
|
+
var dotEnvLoaded = false;
|
|
4213
|
+
function loadDotEnv() {
|
|
4214
|
+
if (dotEnvLoaded) {
|
|
4215
|
+
return;
|
|
4216
|
+
}
|
|
4217
|
+
try {
|
|
4218
|
+
const envPath = path2.resolve(process.cwd(), ".env");
|
|
4219
|
+
if (fs.existsSync(envPath)) {
|
|
4220
|
+
const envConfig = dotenv.parse(fs.readFileSync(envPath));
|
|
4221
|
+
for (const k in envConfig) {
|
|
4222
|
+
if (!process.env.hasOwnProperty(k)) {
|
|
4223
|
+
process.env[k] = envConfig[k];
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
log(`Loaded .env file at: ${envPath}`);
|
|
4227
|
+
dotEnvLoaded = true;
|
|
4228
|
+
}
|
|
4229
|
+
} catch (error) {
|
|
4230
|
+
log(`Warning: Failed to load .env file: ${error}`);
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
__name(loadDotEnv, "loadDotEnv");
|
|
4212
4234
|
function loadConfig(customConfig) {
|
|
4213
4235
|
if (customConfig) {
|
|
4214
4236
|
return customConfig;
|
|
@@ -4229,16 +4251,16 @@ function loadConfig(customConfig) {
|
|
|
4229
4251
|
const envPath = path2.resolve(process.cwd(), ".env");
|
|
4230
4252
|
if (fs.existsSync(envPath)) {
|
|
4231
4253
|
const envConfig = dotenv.parse(fs.readFileSync(envPath));
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4254
|
+
if (!process.env.AGENTBAY_REGION_ID && envConfig.AGENTBAY_REGION_ID) {
|
|
4255
|
+
config.region_id = envConfig.AGENTBAY_REGION_ID;
|
|
4256
|
+
}
|
|
4257
|
+
if (!process.env.AGENTBAY_ENDPOINT && envConfig.AGENTBAY_ENDPOINT) {
|
|
4258
|
+
config.endpoint = envConfig.AGENTBAY_ENDPOINT;
|
|
4259
|
+
}
|
|
4260
|
+
if (!process.env.AGENTBAY_TIMEOUT_MS && envConfig.AGENTBAY_TIMEOUT_MS) {
|
|
4261
|
+
const timeout = parseInt(envConfig.AGENTBAY_TIMEOUT_MS, 10);
|
|
4262
|
+
if (!isNaN(timeout) && timeout > 0) {
|
|
4263
|
+
config.timeout_ms = timeout;
|
|
4242
4264
|
}
|
|
4243
4265
|
}
|
|
4244
4266
|
log(`Loaded .env file at: ${envPath}`);
|
|
@@ -4714,7 +4736,7 @@ var _Agent = class _Agent {
|
|
|
4714
4736
|
*/
|
|
4715
4737
|
async executeTask(task, maxTryTimes) {
|
|
4716
4738
|
try {
|
|
4717
|
-
const args = { task };
|
|
4739
|
+
const args = { task, max_try_times: maxTryTimes };
|
|
4718
4740
|
const result = await this.session.callMcpTool("flux_execute_task", args);
|
|
4719
4741
|
if (!result.success) {
|
|
4720
4742
|
return {
|
|
@@ -5329,7 +5351,7 @@ var _ContextManager = class _ContextManager {
|
|
|
5329
5351
|
async info() {
|
|
5330
5352
|
return this.infoWithParams();
|
|
5331
5353
|
}
|
|
5332
|
-
async infoWithParams(contextId,
|
|
5354
|
+
async infoWithParams(contextId, path4, taskType) {
|
|
5333
5355
|
const request = new GetContextInfoRequest({
|
|
5334
5356
|
authorization: `Bearer ${this.session.getAPIKey()}`,
|
|
5335
5357
|
sessionId: this.session.getSessionId()
|
|
@@ -5337,8 +5359,8 @@ var _ContextManager = class _ContextManager {
|
|
|
5337
5359
|
if (contextId) {
|
|
5338
5360
|
request.contextId = contextId;
|
|
5339
5361
|
}
|
|
5340
|
-
if (
|
|
5341
|
-
request.path =
|
|
5362
|
+
if (path4) {
|
|
5363
|
+
request.path = path4;
|
|
5342
5364
|
}
|
|
5343
5365
|
if (taskType) {
|
|
5344
5366
|
request.taskType = taskType;
|
|
@@ -5388,7 +5410,7 @@ var _ContextManager = class _ContextManager {
|
|
|
5388
5410
|
async sync() {
|
|
5389
5411
|
return this.syncWithParams();
|
|
5390
5412
|
}
|
|
5391
|
-
async syncWithParams(contextId,
|
|
5413
|
+
async syncWithParams(contextId, path4, mode) {
|
|
5392
5414
|
const request = new SyncContextRequest({
|
|
5393
5415
|
authorization: `Bearer ${this.session.getAPIKey()}`,
|
|
5394
5416
|
sessionId: this.session.getSessionId()
|
|
@@ -5396,8 +5418,8 @@ var _ContextManager = class _ContextManager {
|
|
|
5396
5418
|
if (contextId) {
|
|
5397
5419
|
request.contextId = contextId;
|
|
5398
5420
|
}
|
|
5399
|
-
if (
|
|
5400
|
-
request.path =
|
|
5421
|
+
if (path4) {
|
|
5422
|
+
request.path = path4;
|
|
5401
5423
|
}
|
|
5402
5424
|
if (mode) {
|
|
5403
5425
|
request.mode = mode;
|
|
@@ -5444,6 +5466,43 @@ __name(newContextManager, "newContextManager");
|
|
|
5444
5466
|
// src/filesystem/filesystem.ts
|
|
5445
5467
|
init_esm_shims();
|
|
5446
5468
|
var DEFAULT_CHUNK_SIZE = 60 * 1024;
|
|
5469
|
+
var _FileChangeEventHelper = class _FileChangeEventHelper {
|
|
5470
|
+
static toString(event) {
|
|
5471
|
+
return `FileChangeEvent(eventType='${event.eventType}', path='${event.path}', pathType='${event.pathType}')`;
|
|
5472
|
+
}
|
|
5473
|
+
static toDict(event) {
|
|
5474
|
+
return {
|
|
5475
|
+
eventType: event.eventType,
|
|
5476
|
+
path: event.path,
|
|
5477
|
+
pathType: event.pathType
|
|
5478
|
+
};
|
|
5479
|
+
}
|
|
5480
|
+
static fromDict(data) {
|
|
5481
|
+
return {
|
|
5482
|
+
eventType: data.eventType || "",
|
|
5483
|
+
path: data.path || "",
|
|
5484
|
+
pathType: data.pathType || ""
|
|
5485
|
+
};
|
|
5486
|
+
}
|
|
5487
|
+
};
|
|
5488
|
+
__name(_FileChangeEventHelper, "FileChangeEventHelper");
|
|
5489
|
+
var FileChangeEventHelper = _FileChangeEventHelper;
|
|
5490
|
+
var _FileChangeResultHelper = class _FileChangeResultHelper {
|
|
5491
|
+
static hasChanges(result) {
|
|
5492
|
+
return result.events.length > 0;
|
|
5493
|
+
}
|
|
5494
|
+
static getModifiedFiles(result) {
|
|
5495
|
+
return result.events.filter((event) => event.eventType === "modify" && event.pathType === "file").map((event) => event.path);
|
|
5496
|
+
}
|
|
5497
|
+
static getCreatedFiles(result) {
|
|
5498
|
+
return result.events.filter((event) => event.eventType === "create" && event.pathType === "file").map((event) => event.path);
|
|
5499
|
+
}
|
|
5500
|
+
static getDeletedFiles(result) {
|
|
5501
|
+
return result.events.filter((event) => event.eventType === "delete" && event.pathType === "file").map((event) => event.path);
|
|
5502
|
+
}
|
|
5503
|
+
};
|
|
5504
|
+
__name(_FileChangeResultHelper, "FileChangeResultHelper");
|
|
5505
|
+
var FileChangeResultHelper = _FileChangeResultHelper;
|
|
5447
5506
|
function parseFileInfo(fileInfoStr) {
|
|
5448
5507
|
const result = {
|
|
5449
5508
|
name: "",
|
|
@@ -5527,10 +5586,10 @@ var _FileSystem = class _FileSystem {
|
|
|
5527
5586
|
* @param path - Path to the directory to create.
|
|
5528
5587
|
* @returns BoolResult with creation result and requestId
|
|
5529
5588
|
*/
|
|
5530
|
-
async createDirectory(
|
|
5589
|
+
async createDirectory(path4) {
|
|
5531
5590
|
try {
|
|
5532
5591
|
const args = {
|
|
5533
|
-
path:
|
|
5592
|
+
path: path4
|
|
5534
5593
|
};
|
|
5535
5594
|
const result = await this.session.callMcpTool(
|
|
5536
5595
|
"create_directory",
|
|
@@ -5565,10 +5624,10 @@ var _FileSystem = class _FileSystem {
|
|
|
5565
5624
|
* @param dryRun - Optional: If true, preview changes without applying them.
|
|
5566
5625
|
* @returns BoolResult with edit result and requestId
|
|
5567
5626
|
*/
|
|
5568
|
-
async editFile(
|
|
5627
|
+
async editFile(path4, edits, dryRun = false) {
|
|
5569
5628
|
try {
|
|
5570
5629
|
const args = {
|
|
5571
|
-
path:
|
|
5630
|
+
path: path4,
|
|
5572
5631
|
edits,
|
|
5573
5632
|
dryRun
|
|
5574
5633
|
};
|
|
@@ -5603,10 +5662,10 @@ var _FileSystem = class _FileSystem {
|
|
|
5603
5662
|
* @param path - Path to the file or directory to inspect.
|
|
5604
5663
|
* @returns FileInfoResult with file info and requestId
|
|
5605
5664
|
*/
|
|
5606
|
-
async getFileInfo(
|
|
5665
|
+
async getFileInfo(path4) {
|
|
5607
5666
|
try {
|
|
5608
5667
|
const args = {
|
|
5609
|
-
path:
|
|
5668
|
+
path: path4
|
|
5610
5669
|
};
|
|
5611
5670
|
const result = await this.session.callMcpTool(
|
|
5612
5671
|
"get_file_info",
|
|
@@ -5649,10 +5708,10 @@ var _FileSystem = class _FileSystem {
|
|
|
5649
5708
|
* @param path - Path to the directory to list.
|
|
5650
5709
|
* @returns DirectoryListResult with directory entries and requestId
|
|
5651
5710
|
*/
|
|
5652
|
-
async listDirectory(
|
|
5711
|
+
async listDirectory(path4) {
|
|
5653
5712
|
try {
|
|
5654
5713
|
const args = {
|
|
5655
|
-
path:
|
|
5714
|
+
path: path4
|
|
5656
5715
|
};
|
|
5657
5716
|
const result = await this.session.callMcpTool(
|
|
5658
5717
|
"list_directory",
|
|
@@ -5720,18 +5779,17 @@ var _FileSystem = class _FileSystem {
|
|
|
5720
5779
|
}
|
|
5721
5780
|
}
|
|
5722
5781
|
/**
|
|
5723
|
-
*
|
|
5724
|
-
* Corresponds to Python's read_file() method
|
|
5782
|
+
* Internal method to read a file chunk. Used for chunked file operations.
|
|
5725
5783
|
*
|
|
5726
5784
|
* @param path - Path to the file to read.
|
|
5727
5785
|
* @param offset - Optional: Byte offset to start reading from (0-based).
|
|
5728
5786
|
* @param length - Optional: Number of bytes to read. If 0, reads the entire file from offset.
|
|
5729
5787
|
* @returns FileContentResult with file content and requestId
|
|
5730
5788
|
*/
|
|
5731
|
-
async
|
|
5789
|
+
async readFileChunk(path4, offset = 0, length = 0) {
|
|
5732
5790
|
try {
|
|
5733
5791
|
const args = {
|
|
5734
|
-
path:
|
|
5792
|
+
path: path4
|
|
5735
5793
|
};
|
|
5736
5794
|
if (offset > 0) {
|
|
5737
5795
|
args.offset = offset;
|
|
@@ -5797,8 +5855,8 @@ var _FileSystem = class _FileSystem {
|
|
|
5797
5855
|
for (const line of lines) {
|
|
5798
5856
|
const colonIndex = line.indexOf(":");
|
|
5799
5857
|
if (colonIndex > 0 && currentPath === "" && !line.substring(0, colonIndex).includes(" ")) {
|
|
5800
|
-
const
|
|
5801
|
-
currentPath =
|
|
5858
|
+
const path4 = line.substring(0, colonIndex).trim();
|
|
5859
|
+
currentPath = path4;
|
|
5802
5860
|
if (line.length > colonIndex + 1) {
|
|
5803
5861
|
const contentStart = line.substring(colonIndex + 1).trim();
|
|
5804
5862
|
if (contentStart) {
|
|
@@ -5818,8 +5876,8 @@ var _FileSystem = class _FileSystem {
|
|
|
5818
5876
|
if (currentPath) {
|
|
5819
5877
|
fileContents[currentPath] = currentContent.join("\n");
|
|
5820
5878
|
}
|
|
5821
|
-
for (const
|
|
5822
|
-
fileContents[
|
|
5879
|
+
for (const path4 in fileContents) {
|
|
5880
|
+
fileContents[path4] = fileContents[path4].replace(/\n+$/, "");
|
|
5823
5881
|
}
|
|
5824
5882
|
}
|
|
5825
5883
|
return {
|
|
@@ -5845,10 +5903,10 @@ var _FileSystem = class _FileSystem {
|
|
|
5845
5903
|
* @param excludePatterns - Optional: Array of patterns to exclude.
|
|
5846
5904
|
* @returns FileSearchResult with search results and requestId
|
|
5847
5905
|
*/
|
|
5848
|
-
async searchFiles(
|
|
5906
|
+
async searchFiles(path4, pattern, excludePatterns = []) {
|
|
5849
5907
|
try {
|
|
5850
5908
|
const args = {
|
|
5851
|
-
path:
|
|
5909
|
+
path: path4,
|
|
5852
5910
|
pattern
|
|
5853
5911
|
};
|
|
5854
5912
|
if (excludePatterns.length > 0) {
|
|
@@ -5885,15 +5943,14 @@ var _FileSystem = class _FileSystem {
|
|
|
5885
5943
|
}
|
|
5886
5944
|
}
|
|
5887
5945
|
/**
|
|
5888
|
-
*
|
|
5889
|
-
* Corresponds to Python's write_file() method
|
|
5946
|
+
* Internal method to write a file chunk. Used for chunked file operations.
|
|
5890
5947
|
*
|
|
5891
5948
|
* @param path - Path to the file to write.
|
|
5892
5949
|
* @param content - Content to write to the file.
|
|
5893
5950
|
* @param mode - Optional: Write mode. One of "overwrite", "append", or "create_new". Default is "overwrite".
|
|
5894
5951
|
* @returns BoolResult with write result and requestId
|
|
5895
5952
|
*/
|
|
5896
|
-
async
|
|
5953
|
+
async writeFileChunk(path4, content, mode = "overwrite") {
|
|
5897
5954
|
try {
|
|
5898
5955
|
const validModes = ["overwrite", "append", "create_new"];
|
|
5899
5956
|
if (!validModes.includes(mode)) {
|
|
@@ -5906,7 +5963,7 @@ var _FileSystem = class _FileSystem {
|
|
|
5906
5963
|
};
|
|
5907
5964
|
}
|
|
5908
5965
|
const args = {
|
|
5909
|
-
path:
|
|
5966
|
+
path: path4,
|
|
5910
5967
|
content,
|
|
5911
5968
|
mode
|
|
5912
5969
|
};
|
|
@@ -5935,16 +5992,15 @@ var _FileSystem = class _FileSystem {
|
|
|
5935
5992
|
}
|
|
5936
5993
|
}
|
|
5937
5994
|
/**
|
|
5938
|
-
* Reads
|
|
5939
|
-
* Corresponds to Python's read_large_file() method
|
|
5995
|
+
* Reads the contents of a file. Automatically handles large files by chunking.
|
|
5940
5996
|
*
|
|
5941
5997
|
* @param path - Path to the file to read.
|
|
5942
|
-
* @param chunkSize - Optional: Size of each chunk in bytes. Default is 60KB.
|
|
5943
5998
|
* @returns FileContentResult with complete file content and requestId
|
|
5944
5999
|
*/
|
|
5945
|
-
async
|
|
6000
|
+
async readFile(path4) {
|
|
6001
|
+
const chunkSize = DEFAULT_CHUNK_SIZE;
|
|
5946
6002
|
try {
|
|
5947
|
-
const fileInfoResult = await this.getFileInfo(
|
|
6003
|
+
const fileInfoResult = await this.getFileInfo(path4);
|
|
5948
6004
|
if (!fileInfoResult.success) {
|
|
5949
6005
|
return {
|
|
5950
6006
|
requestId: fileInfoResult.requestId,
|
|
@@ -5958,7 +6014,7 @@ var _FileSystem = class _FileSystem {
|
|
|
5958
6014
|
requestId: fileInfoResult.requestId,
|
|
5959
6015
|
success: false,
|
|
5960
6016
|
content: "",
|
|
5961
|
-
errorMessage: `Path does not exist or is a directory: ${
|
|
6017
|
+
errorMessage: `Path does not exist or is a directory: ${path4}`
|
|
5962
6018
|
};
|
|
5963
6019
|
}
|
|
5964
6020
|
const fileSize = fileInfoResult.fileInfo.size || 0;
|
|
@@ -5978,7 +6034,7 @@ var _FileSystem = class _FileSystem {
|
|
|
5978
6034
|
length = fileSize - offset;
|
|
5979
6035
|
}
|
|
5980
6036
|
try {
|
|
5981
|
-
const chunkResult = await this.
|
|
6037
|
+
const chunkResult = await this.readFileChunk(path4, offset, length);
|
|
5982
6038
|
if (!chunkResult.success) {
|
|
5983
6039
|
return chunkResult;
|
|
5984
6040
|
}
|
|
@@ -6009,25 +6065,25 @@ var _FileSystem = class _FileSystem {
|
|
|
6009
6065
|
}
|
|
6010
6066
|
}
|
|
6011
6067
|
/**
|
|
6012
|
-
* Writes a
|
|
6013
|
-
* Corresponds to Python's write_large_file() method
|
|
6068
|
+
* Writes content to a file. Automatically handles large files by chunking.
|
|
6014
6069
|
*
|
|
6015
6070
|
* @param path - Path to the file to write.
|
|
6016
6071
|
* @param content - Content to write to the file.
|
|
6017
|
-
* @param
|
|
6072
|
+
* @param mode - Optional: Write mode. One of "overwrite", "append", or "create_new". Default is "overwrite".
|
|
6018
6073
|
* @returns BoolResult indicating success or failure with requestId
|
|
6019
6074
|
*/
|
|
6020
|
-
async
|
|
6075
|
+
async writeFile(path4, content, mode = "overwrite") {
|
|
6076
|
+
const chunkSize = DEFAULT_CHUNK_SIZE;
|
|
6021
6077
|
try {
|
|
6022
6078
|
const contentLen = content.length;
|
|
6023
6079
|
if (contentLen <= chunkSize) {
|
|
6024
|
-
return await this.
|
|
6080
|
+
return await this.writeFileChunk(path4, content, mode);
|
|
6025
6081
|
}
|
|
6026
6082
|
const firstChunkEnd = Math.min(chunkSize, contentLen);
|
|
6027
|
-
const firstResult = await this.
|
|
6028
|
-
|
|
6083
|
+
const firstResult = await this.writeFileChunk(
|
|
6084
|
+
path4,
|
|
6029
6085
|
content.substring(0, firstChunkEnd),
|
|
6030
|
-
|
|
6086
|
+
mode
|
|
6031
6087
|
);
|
|
6032
6088
|
if (!firstResult.success) {
|
|
6033
6089
|
return firstResult;
|
|
@@ -6035,8 +6091,8 @@ var _FileSystem = class _FileSystem {
|
|
|
6035
6091
|
let chunkCount = 1;
|
|
6036
6092
|
for (let offset = firstChunkEnd; offset < contentLen; ) {
|
|
6037
6093
|
const end = Math.min(offset + chunkSize, contentLen);
|
|
6038
|
-
const chunkResult = await this.
|
|
6039
|
-
|
|
6094
|
+
const chunkResult = await this.writeFileChunk(
|
|
6095
|
+
path4,
|
|
6040
6096
|
content.substring(offset, end),
|
|
6041
6097
|
"append"
|
|
6042
6098
|
);
|
|
@@ -6059,6 +6115,98 @@ var _FileSystem = class _FileSystem {
|
|
|
6059
6115
|
};
|
|
6060
6116
|
}
|
|
6061
6117
|
}
|
|
6118
|
+
/**
|
|
6119
|
+
* Get file change information for the specified directory path
|
|
6120
|
+
*/
|
|
6121
|
+
async getFileChange(path4) {
|
|
6122
|
+
try {
|
|
6123
|
+
const args = { path: path4 };
|
|
6124
|
+
const result = await this.session.callMcpTool("get_file_change", args);
|
|
6125
|
+
if (!result.success) {
|
|
6126
|
+
return {
|
|
6127
|
+
requestId: result.requestId,
|
|
6128
|
+
success: false,
|
|
6129
|
+
events: [],
|
|
6130
|
+
rawData: result.data || "",
|
|
6131
|
+
errorMessage: result.errorMessage
|
|
6132
|
+
};
|
|
6133
|
+
}
|
|
6134
|
+
const events = this.parseFileChangeData(result.data);
|
|
6135
|
+
return {
|
|
6136
|
+
requestId: result.requestId,
|
|
6137
|
+
success: true,
|
|
6138
|
+
events,
|
|
6139
|
+
rawData: result.data
|
|
6140
|
+
};
|
|
6141
|
+
} catch (error) {
|
|
6142
|
+
return {
|
|
6143
|
+
requestId: "",
|
|
6144
|
+
success: false,
|
|
6145
|
+
events: [],
|
|
6146
|
+
rawData: "",
|
|
6147
|
+
errorMessage: `Failed to get file change: ${error}`
|
|
6148
|
+
};
|
|
6149
|
+
}
|
|
6150
|
+
}
|
|
6151
|
+
/**
|
|
6152
|
+
* Parse raw JSON data into FileChangeEvent array
|
|
6153
|
+
*/
|
|
6154
|
+
parseFileChangeData(rawData) {
|
|
6155
|
+
const events = [];
|
|
6156
|
+
try {
|
|
6157
|
+
const changeData = JSON.parse(rawData);
|
|
6158
|
+
if (Array.isArray(changeData)) {
|
|
6159
|
+
for (const eventDict of changeData) {
|
|
6160
|
+
if (typeof eventDict === "object" && eventDict !== null) {
|
|
6161
|
+
const event = FileChangeEventHelper.fromDict(eventDict);
|
|
6162
|
+
events.push(event);
|
|
6163
|
+
}
|
|
6164
|
+
}
|
|
6165
|
+
}
|
|
6166
|
+
} catch (error) {
|
|
6167
|
+
console.warn(`Failed to parse JSON data: ${error}`);
|
|
6168
|
+
}
|
|
6169
|
+
return events;
|
|
6170
|
+
}
|
|
6171
|
+
/**
|
|
6172
|
+
* Watch a directory for file changes and call the callback function when changes occur
|
|
6173
|
+
*/
|
|
6174
|
+
async watchDirectory(path4, callback, interval = 500, signal) {
|
|
6175
|
+
console.log(`Starting directory monitoring for: ${path4}`);
|
|
6176
|
+
console.log(`Polling interval: ${interval} ms`);
|
|
6177
|
+
const monitor = /* @__PURE__ */ __name(async () => {
|
|
6178
|
+
while (!signal?.aborted) {
|
|
6179
|
+
try {
|
|
6180
|
+
const result = await this.getFileChange(path4);
|
|
6181
|
+
if (result.success && result.events.length > 0) {
|
|
6182
|
+
console.log(`Detected ${result.events.length} file changes:`);
|
|
6183
|
+
for (const event of result.events) {
|
|
6184
|
+
console.log(` - ${FileChangeEventHelper.toString(event)}`);
|
|
6185
|
+
}
|
|
6186
|
+
try {
|
|
6187
|
+
callback(result.events);
|
|
6188
|
+
} catch (error) {
|
|
6189
|
+
console.error(`Error in callback function: ${error}`);
|
|
6190
|
+
}
|
|
6191
|
+
} else if (!result.success) {
|
|
6192
|
+
console.error(`Error monitoring directory: ${result.errorMessage}`);
|
|
6193
|
+
}
|
|
6194
|
+
await new Promise((resolve2) => {
|
|
6195
|
+
const timeoutId = setTimeout(resolve2, interval);
|
|
6196
|
+
signal?.addEventListener("abort", () => {
|
|
6197
|
+
clearTimeout(timeoutId);
|
|
6198
|
+
resolve2(void 0);
|
|
6199
|
+
});
|
|
6200
|
+
});
|
|
6201
|
+
} catch (error) {
|
|
6202
|
+
console.error(`Unexpected error in directory monitoring: ${error}`);
|
|
6203
|
+
await new Promise((resolve2) => setTimeout(resolve2, interval));
|
|
6204
|
+
}
|
|
6205
|
+
}
|
|
6206
|
+
console.log(`Stopped monitoring directory: ${path4}`);
|
|
6207
|
+
}, "monitor");
|
|
6208
|
+
return monitor();
|
|
6209
|
+
}
|
|
6062
6210
|
};
|
|
6063
6211
|
__name(_FileSystem, "FileSystem");
|
|
6064
6212
|
var FileSystem = _FileSystem;
|
|
@@ -6156,12 +6304,12 @@ var _Oss = class _Oss {
|
|
|
6156
6304
|
* @returns OSSUploadResult with upload result and requestId
|
|
6157
6305
|
* @throws APIError if the operation fails.
|
|
6158
6306
|
*/
|
|
6159
|
-
async upload(bucket, object,
|
|
6307
|
+
async upload(bucket, object, path4) {
|
|
6160
6308
|
try {
|
|
6161
6309
|
const args = {
|
|
6162
6310
|
bucket,
|
|
6163
6311
|
object,
|
|
6164
|
-
path:
|
|
6312
|
+
path: path4
|
|
6165
6313
|
};
|
|
6166
6314
|
const result = await this.session.callMcpTool("oss_upload", args);
|
|
6167
6315
|
return {
|
|
@@ -6188,11 +6336,11 @@ var _Oss = class _Oss {
|
|
|
6188
6336
|
* @returns OSSUploadResult with upload result and requestId
|
|
6189
6337
|
* @throws APIError if the operation fails.
|
|
6190
6338
|
*/
|
|
6191
|
-
async uploadAnonymous(url,
|
|
6339
|
+
async uploadAnonymous(url, path4) {
|
|
6192
6340
|
try {
|
|
6193
6341
|
const args = {
|
|
6194
6342
|
url,
|
|
6195
|
-
path:
|
|
6343
|
+
path: path4
|
|
6196
6344
|
};
|
|
6197
6345
|
const result = await this.session.callMcpTool("oss_upload_anonymous", args);
|
|
6198
6346
|
return {
|
|
@@ -6220,12 +6368,12 @@ var _Oss = class _Oss {
|
|
|
6220
6368
|
* @returns OSSDownloadResult with download result and requestId
|
|
6221
6369
|
* @throws APIError if the operation fails.
|
|
6222
6370
|
*/
|
|
6223
|
-
async download(bucket, object,
|
|
6371
|
+
async download(bucket, object, path4) {
|
|
6224
6372
|
try {
|
|
6225
6373
|
const args = {
|
|
6226
6374
|
bucket,
|
|
6227
6375
|
object,
|
|
6228
|
-
path:
|
|
6376
|
+
path: path4
|
|
6229
6377
|
};
|
|
6230
6378
|
const result = await this.session.callMcpTool("oss_download", args);
|
|
6231
6379
|
return {
|
|
@@ -6252,11 +6400,11 @@ var _Oss = class _Oss {
|
|
|
6252
6400
|
* @returns OSSDownloadResult with download result and requestId
|
|
6253
6401
|
* @throws APIError if the operation fails.
|
|
6254
6402
|
*/
|
|
6255
|
-
async downloadAnonymous(url,
|
|
6403
|
+
async downloadAnonymous(url, path4) {
|
|
6256
6404
|
try {
|
|
6257
6405
|
const args = {
|
|
6258
6406
|
url,
|
|
6259
|
-
path:
|
|
6407
|
+
path: path4
|
|
6260
6408
|
};
|
|
6261
6409
|
const result = await this.session.callMcpTool("oss_download_anonymous", args);
|
|
6262
6410
|
return {
|
|
@@ -6998,7 +7146,7 @@ var _BrowserAgent = class _BrowserAgent {
|
|
|
6998
7146
|
* Perform an action on the given Playwright Page object, using ActOptions to configure behavior.
|
|
6999
7147
|
* Returns the result of the action.
|
|
7000
7148
|
*/
|
|
7001
|
-
async act(
|
|
7149
|
+
async act(options, page) {
|
|
7002
7150
|
if (!this.browser.isInitialized()) {
|
|
7003
7151
|
throw new BrowserError("Browser must be initialized before calling act.");
|
|
7004
7152
|
}
|
|
@@ -7042,14 +7190,14 @@ var _BrowserAgent = class _BrowserAgent {
|
|
|
7042
7190
|
/**
|
|
7043
7191
|
* Async version of act method for performing actions on the given Playwright Page object.
|
|
7044
7192
|
*/
|
|
7045
|
-
async actAsync(
|
|
7046
|
-
return this.act(
|
|
7193
|
+
async actAsync(options, page) {
|
|
7194
|
+
return this.act(options, page);
|
|
7047
7195
|
}
|
|
7048
7196
|
/**
|
|
7049
7197
|
* Observe elements or state on the given Playwright Page object.
|
|
7050
7198
|
* Returns a tuple containing (success, results).
|
|
7051
7199
|
*/
|
|
7052
|
-
async observe(
|
|
7200
|
+
async observe(options, page) {
|
|
7053
7201
|
if (!this.browser.isInitialized()) {
|
|
7054
7202
|
throw new BrowserError("Browser must be initialized before calling observe.");
|
|
7055
7203
|
}
|
|
@@ -7106,13 +7254,13 @@ var _BrowserAgent = class _BrowserAgent {
|
|
|
7106
7254
|
/**
|
|
7107
7255
|
* Async version of observe method.
|
|
7108
7256
|
*/
|
|
7109
|
-
async observeAsync(
|
|
7110
|
-
return this.observe(
|
|
7257
|
+
async observeAsync(options, page) {
|
|
7258
|
+
return this.observe(options, page);
|
|
7111
7259
|
}
|
|
7112
7260
|
/**
|
|
7113
7261
|
* Extract information from the given Playwright Page object.
|
|
7114
7262
|
*/
|
|
7115
|
-
async extract(
|
|
7263
|
+
async extract(options, page) {
|
|
7116
7264
|
if (!this.browser.isInitialized()) {
|
|
7117
7265
|
throw new BrowserError("Browser must be initialized before calling extract.");
|
|
7118
7266
|
}
|
|
@@ -7173,8 +7321,8 @@ var _BrowserAgent = class _BrowserAgent {
|
|
|
7173
7321
|
/**
|
|
7174
7322
|
* Async version of extract method.
|
|
7175
7323
|
*/
|
|
7176
|
-
async extractAsync(
|
|
7177
|
-
return this.extract(
|
|
7324
|
+
async extractAsync(options, page) {
|
|
7325
|
+
return this.extract(options, page);
|
|
7178
7326
|
}
|
|
7179
7327
|
_getPageAndContextIndex(page) {
|
|
7180
7328
|
if (!page) {
|
|
@@ -7307,13 +7455,14 @@ var _BrowserProxyClass = class _BrowserProxyClass {
|
|
|
7307
7455
|
__name(_BrowserProxyClass, "BrowserProxyClass");
|
|
7308
7456
|
var BrowserProxyClass = _BrowserProxyClass;
|
|
7309
7457
|
var _BrowserOptionClass = class _BrowserOptionClass {
|
|
7310
|
-
constructor(useStealth = false, userAgent, viewport, screen, fingerprint, proxies) {
|
|
7458
|
+
constructor(useStealth = false, userAgent, viewport, screen, fingerprint, solveCaptchas = false, proxies) {
|
|
7311
7459
|
this.useStealth = useStealth;
|
|
7312
7460
|
this.userAgent = userAgent;
|
|
7313
7461
|
this.viewport = viewport;
|
|
7314
7462
|
this.screen = screen;
|
|
7315
7463
|
this.fingerprint = fingerprint;
|
|
7316
|
-
this.
|
|
7464
|
+
this.solveCaptchas = solveCaptchas;
|
|
7465
|
+
this.extensionPath = "/tmp/extensions/";
|
|
7317
7466
|
if (proxies !== void 0) {
|
|
7318
7467
|
if (!Array.isArray(proxies)) {
|
|
7319
7468
|
throw new Error("proxies must be a list");
|
|
@@ -7322,9 +7471,13 @@ var _BrowserOptionClass = class _BrowserOptionClass {
|
|
|
7322
7471
|
throw new Error("proxies list length must be limited to 1");
|
|
7323
7472
|
}
|
|
7324
7473
|
}
|
|
7474
|
+
this.proxies = proxies;
|
|
7325
7475
|
}
|
|
7326
7476
|
toMap() {
|
|
7327
7477
|
const optionMap = {};
|
|
7478
|
+
if (process.env.AGENTBAY_BROWSER_BEHAVIOR_SIMULATE) {
|
|
7479
|
+
optionMap["behaviorSimulate"] = process.env.AGENTBAY_BROWSER_BEHAVIOR_SIMULATE !== "0";
|
|
7480
|
+
}
|
|
7328
7481
|
if (this.useStealth !== void 0) {
|
|
7329
7482
|
optionMap["useStealth"] = this.useStealth;
|
|
7330
7483
|
}
|
|
@@ -7344,9 +7497,15 @@ var _BrowserOptionClass = class _BrowserOptionClass {
|
|
|
7344
7497
|
if (this.fingerprint.locales) fp["locales"] = this.fingerprint.locales;
|
|
7345
7498
|
optionMap["fingerprint"] = fp;
|
|
7346
7499
|
}
|
|
7500
|
+
if (this.solveCaptchas !== void 0) {
|
|
7501
|
+
optionMap["solveCaptchas"] = this.solveCaptchas;
|
|
7502
|
+
}
|
|
7347
7503
|
if (this.proxies !== void 0) {
|
|
7348
7504
|
optionMap["proxies"] = this.proxies.map((proxy) => proxy.toMap());
|
|
7349
7505
|
}
|
|
7506
|
+
if (this.extensionPath !== void 0) {
|
|
7507
|
+
optionMap["extensionPath"] = this.extensionPath;
|
|
7508
|
+
}
|
|
7350
7509
|
return optionMap;
|
|
7351
7510
|
}
|
|
7352
7511
|
fromMap(m) {
|
|
@@ -7372,6 +7531,9 @@ var _BrowserOptionClass = class _BrowserOptionClass {
|
|
|
7372
7531
|
if (map.fingerprint.locales) fp.locales = map.fingerprint.locales;
|
|
7373
7532
|
this.fingerprint = fp;
|
|
7374
7533
|
}
|
|
7534
|
+
if (map.solveCaptchas !== void 0) {
|
|
7535
|
+
this.solveCaptchas = map.solveCaptchas;
|
|
7536
|
+
}
|
|
7375
7537
|
if (map.proxies !== void 0) {
|
|
7376
7538
|
const proxyList = map.proxies;
|
|
7377
7539
|
if (proxyList.length > 1) {
|
|
@@ -7384,6 +7546,9 @@ var _BrowserOptionClass = class _BrowserOptionClass {
|
|
|
7384
7546
|
return BrowserProxyClass.fromMap(proxyData);
|
|
7385
7547
|
}).filter(Boolean);
|
|
7386
7548
|
}
|
|
7549
|
+
if (map.extensionPath !== void 0) {
|
|
7550
|
+
this.extensionPath = map.extensionPath;
|
|
7551
|
+
}
|
|
7387
7552
|
return this;
|
|
7388
7553
|
}
|
|
7389
7554
|
};
|
|
@@ -7544,7 +7709,6 @@ var _Session = class _Session {
|
|
|
7544
7709
|
* @param sessionId - The ID of this session.
|
|
7545
7710
|
*/
|
|
7546
7711
|
constructor(agentBay, sessionId) {
|
|
7547
|
-
this.resourceUrl = "";
|
|
7548
7712
|
// VPC-related information
|
|
7549
7713
|
this.isVpc = false;
|
|
7550
7714
|
// Whether this session uses VPC resources
|
|
@@ -7555,7 +7719,6 @@ var _Session = class _Session {
|
|
|
7555
7719
|
this.mcpTools = [];
|
|
7556
7720
|
this.agentBay = agentBay;
|
|
7557
7721
|
this.sessionId = sessionId;
|
|
7558
|
-
this.resourceUrl = "";
|
|
7559
7722
|
this.fileSystem = new FileSystem(this);
|
|
7560
7723
|
this.command = new Command(this);
|
|
7561
7724
|
this.code = new Code(this);
|
|
@@ -7845,7 +8008,6 @@ var _Session = class _Session {
|
|
|
7845
8008
|
}
|
|
7846
8009
|
if (data?.resourceUrl) {
|
|
7847
8010
|
sessionInfo.resourceUrl = data.resourceUrl;
|
|
7848
|
-
this.resourceUrl = data.resourceUrl;
|
|
7849
8011
|
}
|
|
7850
8012
|
if (data?.desktopInfo) {
|
|
7851
8013
|
const desktopInfo = data.desktopInfo;
|
|
@@ -8157,6 +8319,7 @@ var _AgentBay = class _AgentBay {
|
|
|
8157
8319
|
*/
|
|
8158
8320
|
constructor(options = {}) {
|
|
8159
8321
|
this.sessions = /* @__PURE__ */ new Map();
|
|
8322
|
+
loadDotEnv();
|
|
8160
8323
|
this.apiKey = options.apiKey || process.env.AGENTBAY_API_KEY || "";
|
|
8161
8324
|
if (!this.apiKey) {
|
|
8162
8325
|
throw new AuthenticationError(
|
|
@@ -8289,9 +8452,6 @@ var _AgentBay = class _AgentBay {
|
|
|
8289
8452
|
log("session_id =", sessionId);
|
|
8290
8453
|
log("resource_url =", resourceUrl);
|
|
8291
8454
|
const session = new Session(this, sessionId);
|
|
8292
|
-
if (resourceUrl) {
|
|
8293
|
-
session.resourceUrl = resourceUrl;
|
|
8294
|
-
}
|
|
8295
8455
|
session.isVpc = params.isVpc || false;
|
|
8296
8456
|
if (data.networkInterfaceIp) {
|
|
8297
8457
|
session.networkInterfaceIp = data.networkInterfaceIp;
|
|
@@ -8313,7 +8473,7 @@ var _AgentBay = class _AgentBay {
|
|
|
8313
8473
|
if (hasPersistenceData) {
|
|
8314
8474
|
log("Waiting for context synchronization to complete...");
|
|
8315
8475
|
const maxRetries = 150;
|
|
8316
|
-
const retryInterval =
|
|
8476
|
+
const retryInterval = 1500;
|
|
8317
8477
|
for (let retry = 0; retry < maxRetries; retry++) {
|
|
8318
8478
|
try {
|
|
8319
8479
|
const infoResult = await session.context.info();
|
|
@@ -8496,6 +8656,366 @@ var AgentBay = _AgentBay;
|
|
|
8496
8656
|
// src/agent/index.ts
|
|
8497
8657
|
init_esm_shims();
|
|
8498
8658
|
|
|
8659
|
+
// src/extension.ts
|
|
8660
|
+
init_esm_shims();
|
|
8661
|
+
import * as fs2 from "fs";
|
|
8662
|
+
import * as path3 from "path";
|
|
8663
|
+
import * as crypto from "crypto";
|
|
8664
|
+
import fetch2 from "node-fetch";
|
|
8665
|
+
var EXTENSIONS_BASE_PATH = "/tmp/extensions";
|
|
8666
|
+
var _Extension = class _Extension {
|
|
8667
|
+
/**
|
|
8668
|
+
* Initialize an Extension object.
|
|
8669
|
+
*
|
|
8670
|
+
* @param id - The unique identifier of the extension.
|
|
8671
|
+
* @param name - The name of the extension.
|
|
8672
|
+
* @param createdAt - Date and time when the extension was created.
|
|
8673
|
+
*/
|
|
8674
|
+
constructor(id, name, createdAt) {
|
|
8675
|
+
this.id = id;
|
|
8676
|
+
this.name = name;
|
|
8677
|
+
this.createdAt = createdAt;
|
|
8678
|
+
}
|
|
8679
|
+
};
|
|
8680
|
+
__name(_Extension, "Extension");
|
|
8681
|
+
var Extension = _Extension;
|
|
8682
|
+
var _ExtensionOption = class _ExtensionOption {
|
|
8683
|
+
/**
|
|
8684
|
+
* Initialize ExtensionOption with context and extension configuration.
|
|
8685
|
+
*
|
|
8686
|
+
* @param contextId - ID of the extension context for browser extensions.
|
|
8687
|
+
* This should match the context where extensions are stored.
|
|
8688
|
+
* @param extensionIds - List of extension IDs to be loaded in the browser session.
|
|
8689
|
+
* Each ID should correspond to a valid extension in the context.
|
|
8690
|
+
*
|
|
8691
|
+
* @throws {Error} If contextId is empty or extensionIds is empty.
|
|
8692
|
+
*/
|
|
8693
|
+
constructor(contextId, extensionIds) {
|
|
8694
|
+
if (!contextId || !contextId.trim()) {
|
|
8695
|
+
throw new Error("contextId cannot be empty");
|
|
8696
|
+
}
|
|
8697
|
+
if (!extensionIds || extensionIds.length === 0) {
|
|
8698
|
+
throw new Error("extensionIds cannot be empty");
|
|
8699
|
+
}
|
|
8700
|
+
this.contextId = contextId;
|
|
8701
|
+
this.extensionIds = extensionIds;
|
|
8702
|
+
}
|
|
8703
|
+
/**
|
|
8704
|
+
* String representation of ExtensionOption.
|
|
8705
|
+
*/
|
|
8706
|
+
toString() {
|
|
8707
|
+
return `ExtensionOption(contextId='${this.contextId}', extensionIds=${JSON.stringify(this.extensionIds)})`;
|
|
8708
|
+
}
|
|
8709
|
+
/**
|
|
8710
|
+
* Human-readable string representation.
|
|
8711
|
+
*/
|
|
8712
|
+
toDisplayString() {
|
|
8713
|
+
return `Extension Config: ${this.extensionIds.length} extension(s) in context '${this.contextId}'`;
|
|
8714
|
+
}
|
|
8715
|
+
/**
|
|
8716
|
+
* Validate the extension option configuration.
|
|
8717
|
+
*
|
|
8718
|
+
* @returns True if configuration is valid, false otherwise.
|
|
8719
|
+
*/
|
|
8720
|
+
validate() {
|
|
8721
|
+
try {
|
|
8722
|
+
if (!this.contextId || !this.contextId.trim()) {
|
|
8723
|
+
return false;
|
|
8724
|
+
}
|
|
8725
|
+
if (!this.extensionIds || this.extensionIds.length === 0) {
|
|
8726
|
+
return false;
|
|
8727
|
+
}
|
|
8728
|
+
for (const extId of this.extensionIds) {
|
|
8729
|
+
if (typeof extId !== "string" || !extId.trim()) {
|
|
8730
|
+
return false;
|
|
8731
|
+
}
|
|
8732
|
+
}
|
|
8733
|
+
return true;
|
|
8734
|
+
} catch (error) {
|
|
8735
|
+
return false;
|
|
8736
|
+
}
|
|
8737
|
+
}
|
|
8738
|
+
};
|
|
8739
|
+
__name(_ExtensionOption, "ExtensionOption");
|
|
8740
|
+
var ExtensionOption = _ExtensionOption;
|
|
8741
|
+
var _ExtensionsService = class _ExtensionsService {
|
|
8742
|
+
/**
|
|
8743
|
+
* Initializes the ExtensionsService with a context.
|
|
8744
|
+
*
|
|
8745
|
+
* @param agentBay - The AgentBay client instance.
|
|
8746
|
+
* @param contextId - The context ID or name. If empty or not provided,
|
|
8747
|
+
* a default context name will be generated automatically.
|
|
8748
|
+
* If the context doesn't exist, it will be automatically created.
|
|
8749
|
+
*
|
|
8750
|
+
* Note:
|
|
8751
|
+
* The service automatically detects if the context exists. If not,
|
|
8752
|
+
* it creates a new context with the provided name or a generated default name.
|
|
8753
|
+
* Context initialization is handled lazily on first use.
|
|
8754
|
+
*/
|
|
8755
|
+
constructor(agentBay, contextId = "") {
|
|
8756
|
+
this._initializationPromise = null;
|
|
8757
|
+
if (!agentBay) {
|
|
8758
|
+
throw new AgentBayError("AgentBay instance is required");
|
|
8759
|
+
}
|
|
8760
|
+
if (!agentBay.context) {
|
|
8761
|
+
throw new AgentBayError("AgentBay instance must have a context service");
|
|
8762
|
+
}
|
|
8763
|
+
this.agentBay = agentBay;
|
|
8764
|
+
this.contextService = agentBay.context;
|
|
8765
|
+
this.autoCreated = true;
|
|
8766
|
+
if (!contextId || contextId.trim() === "") {
|
|
8767
|
+
contextId = `extensions-${Math.floor(Date.now() / 1e3)}`;
|
|
8768
|
+
log(`Generated default context name: ${contextId}`);
|
|
8769
|
+
}
|
|
8770
|
+
this.contextName = contextId;
|
|
8771
|
+
this._initializationPromise = this._initializeContext();
|
|
8772
|
+
}
|
|
8773
|
+
/**
|
|
8774
|
+
* Internal method to initialize the context.
|
|
8775
|
+
* This ensures the context is ready before any operations.
|
|
8776
|
+
*/
|
|
8777
|
+
async _initializeContext() {
|
|
8778
|
+
try {
|
|
8779
|
+
const contextResult = await this.contextService.get(this.contextName, true);
|
|
8780
|
+
if (!contextResult.success || !contextResult.context) {
|
|
8781
|
+
throw new AgentBayError(`Failed to create extension repository context: ${this.contextName}`);
|
|
8782
|
+
}
|
|
8783
|
+
this.extensionContext = contextResult.context;
|
|
8784
|
+
this.contextId = this.extensionContext.id;
|
|
8785
|
+
} catch (error) {
|
|
8786
|
+
throw new AgentBayError(`Failed to initialize ExtensionsService: ${error instanceof Error ? error.message : String(error)}`);
|
|
8787
|
+
}
|
|
8788
|
+
}
|
|
8789
|
+
/**
|
|
8790
|
+
* Ensures the service is initialized before performing operations.
|
|
8791
|
+
*/
|
|
8792
|
+
async _ensureInitialized() {
|
|
8793
|
+
if (this._initializationPromise) {
|
|
8794
|
+
await this._initializationPromise;
|
|
8795
|
+
this._initializationPromise = null;
|
|
8796
|
+
}
|
|
8797
|
+
}
|
|
8798
|
+
/**
|
|
8799
|
+
* An internal helper method that encapsulates the flow of "get upload URL for a specific path and upload".
|
|
8800
|
+
* Uses the existing context service for file operations.
|
|
8801
|
+
*
|
|
8802
|
+
* @param localPath - The path to the local file.
|
|
8803
|
+
* @param remotePath - The path of the file in context storage.
|
|
8804
|
+
*
|
|
8805
|
+
* @throws {AgentBayError} If getting the credential or uploading fails.
|
|
8806
|
+
*/
|
|
8807
|
+
async _uploadToCloud(localPath, remotePath) {
|
|
8808
|
+
try {
|
|
8809
|
+
const urlResult = await this.contextService.getFileUploadUrl(this.contextId, remotePath);
|
|
8810
|
+
if (!urlResult.success || !urlResult.url) {
|
|
8811
|
+
throw new AgentBayError(`Failed to get upload URL: ${urlResult.url || "No URL returned"}`);
|
|
8812
|
+
}
|
|
8813
|
+
const preSignedUrl = urlResult.url;
|
|
8814
|
+
const fileBuffer = fs2.readFileSync(localPath);
|
|
8815
|
+
const response = await fetch2(preSignedUrl, {
|
|
8816
|
+
method: "PUT",
|
|
8817
|
+
body: fileBuffer
|
|
8818
|
+
});
|
|
8819
|
+
if (!response.ok) {
|
|
8820
|
+
throw new AgentBayError(`HTTP error uploading file: ${response.status} ${response.statusText}`);
|
|
8821
|
+
}
|
|
8822
|
+
} catch (error) {
|
|
8823
|
+
if (error instanceof AgentBayError) {
|
|
8824
|
+
throw error;
|
|
8825
|
+
}
|
|
8826
|
+
throw new AgentBayError(`An error occurred while uploading the file: ${error instanceof Error ? error.message : String(error)}`);
|
|
8827
|
+
}
|
|
8828
|
+
}
|
|
8829
|
+
/**
|
|
8830
|
+
* Lists all available browser extensions within this context from the cloud.
|
|
8831
|
+
* Uses the context service to list files under the extensions directory.
|
|
8832
|
+
*
|
|
8833
|
+
* @returns Promise that resolves to an array of Extension objects.
|
|
8834
|
+
* @throws {AgentBayError} If listing extensions fails.
|
|
8835
|
+
*/
|
|
8836
|
+
async list() {
|
|
8837
|
+
await this._ensureInitialized();
|
|
8838
|
+
try {
|
|
8839
|
+
const fileListResult = await this.contextService.listFiles(
|
|
8840
|
+
this.contextId,
|
|
8841
|
+
EXTENSIONS_BASE_PATH,
|
|
8842
|
+
1,
|
|
8843
|
+
// pageNumber
|
|
8844
|
+
100
|
|
8845
|
+
// pageSize - reasonable limit for extensions
|
|
8846
|
+
);
|
|
8847
|
+
if (!fileListResult.success) {
|
|
8848
|
+
throw new AgentBayError("Failed to list extensions: Context file listing failed.");
|
|
8849
|
+
}
|
|
8850
|
+
const extensions = [];
|
|
8851
|
+
for (const fileEntry of fileListResult.entries) {
|
|
8852
|
+
const extensionId = fileEntry.fileName || fileEntry.filePath;
|
|
8853
|
+
extensions.push(new Extension(
|
|
8854
|
+
extensionId,
|
|
8855
|
+
fileEntry.fileName || extensionId,
|
|
8856
|
+
fileEntry.gmtCreate
|
|
8857
|
+
));
|
|
8858
|
+
}
|
|
8859
|
+
return extensions;
|
|
8860
|
+
} catch (error) {
|
|
8861
|
+
if (error instanceof AgentBayError) {
|
|
8862
|
+
throw error;
|
|
8863
|
+
}
|
|
8864
|
+
throw new AgentBayError(`An error occurred while listing browser extensions: ${error instanceof Error ? error.message : String(error)}`);
|
|
8865
|
+
}
|
|
8866
|
+
}
|
|
8867
|
+
/**
|
|
8868
|
+
* Uploads a new browser extension from a local path into the current context.
|
|
8869
|
+
*
|
|
8870
|
+
* @param localPath - Path to the local extension file (must be a .zip file).
|
|
8871
|
+
* @returns Promise that resolves to an Extension object.
|
|
8872
|
+
* @throws {Error} If the local file doesn't exist.
|
|
8873
|
+
* @throws {Error} If the file format is not supported (only .zip is supported).
|
|
8874
|
+
* @throws {AgentBayError} If upload fails.
|
|
8875
|
+
*/
|
|
8876
|
+
async create(localPath) {
|
|
8877
|
+
await this._ensureInitialized();
|
|
8878
|
+
if (!fs2.existsSync(localPath)) {
|
|
8879
|
+
throw new Error(`The specified local file was not found: ${localPath}`);
|
|
8880
|
+
}
|
|
8881
|
+
const fileExtension = path3.extname(localPath).toLowerCase();
|
|
8882
|
+
if (fileExtension !== ".zip") {
|
|
8883
|
+
throw new Error(`Unsupported plugin format '${fileExtension}'. Only ZIP format (.zip) is supported.`);
|
|
8884
|
+
}
|
|
8885
|
+
const extensionId = `ext_${crypto.randomBytes(16).toString("hex")}${fileExtension}`;
|
|
8886
|
+
const extensionName = path3.basename(localPath);
|
|
8887
|
+
const remotePath = `${EXTENSIONS_BASE_PATH}/${extensionId}`;
|
|
8888
|
+
await this._uploadToCloud(localPath, remotePath);
|
|
8889
|
+
return new Extension(extensionId, extensionName);
|
|
8890
|
+
}
|
|
8891
|
+
/**
|
|
8892
|
+
* Updates an existing browser extension in the current context with a new file.
|
|
8893
|
+
*
|
|
8894
|
+
* @param extensionId - ID of the extension to update.
|
|
8895
|
+
* @param newLocalPath - Path to the new local extension file.
|
|
8896
|
+
* @returns Promise that resolves to an Extension object.
|
|
8897
|
+
* @throws {Error} If the new local file doesn't exist.
|
|
8898
|
+
* @throws {Error} If the extension doesn't exist in the context.
|
|
8899
|
+
* @throws {AgentBayError} If update fails.
|
|
8900
|
+
*/
|
|
8901
|
+
async update(extensionId, newLocalPath) {
|
|
8902
|
+
await this._ensureInitialized();
|
|
8903
|
+
if (!fs2.existsSync(newLocalPath)) {
|
|
8904
|
+
throw new Error(`The specified new local file was not found: ${newLocalPath}`);
|
|
8905
|
+
}
|
|
8906
|
+
const existingExtensions = await this.list();
|
|
8907
|
+
const extensionExists = existingExtensions.some((ext) => ext.id === extensionId);
|
|
8908
|
+
if (!extensionExists) {
|
|
8909
|
+
throw new Error(`Browser extension with ID '${extensionId}' not found in the context. Cannot update.`);
|
|
8910
|
+
}
|
|
8911
|
+
const remotePath = `${EXTENSIONS_BASE_PATH}/${extensionId}`;
|
|
8912
|
+
await this._uploadToCloud(newLocalPath, remotePath);
|
|
8913
|
+
return new Extension(extensionId, path3.basename(newLocalPath));
|
|
8914
|
+
}
|
|
8915
|
+
/**
|
|
8916
|
+
* Gets detailed information about a specific browser extension.
|
|
8917
|
+
*
|
|
8918
|
+
* @param extensionId - The ID of the extension to get info for.
|
|
8919
|
+
* @returns Promise that resolves to an Extension object if found, undefined otherwise.
|
|
8920
|
+
*/
|
|
8921
|
+
async _getExtensionInfo(extensionId) {
|
|
8922
|
+
await this._ensureInitialized();
|
|
8923
|
+
try {
|
|
8924
|
+
const extensions = await this.list();
|
|
8925
|
+
return extensions.find((ext) => ext.id === extensionId);
|
|
8926
|
+
} catch (error) {
|
|
8927
|
+
logError(`An error occurred while getting extension info for '${extensionId}':`, error);
|
|
8928
|
+
return void 0;
|
|
8929
|
+
}
|
|
8930
|
+
}
|
|
8931
|
+
/**
|
|
8932
|
+
* Cleans up the auto-created context if it was created by this service.
|
|
8933
|
+
*
|
|
8934
|
+
* @returns Promise that resolves to true if cleanup was successful or not needed, false if cleanup failed.
|
|
8935
|
+
*
|
|
8936
|
+
* Note:
|
|
8937
|
+
* This method only works if the context was auto-created by this service.
|
|
8938
|
+
* For existing contexts, no cleanup is performed.
|
|
8939
|
+
*/
|
|
8940
|
+
async cleanup() {
|
|
8941
|
+
await this._ensureInitialized();
|
|
8942
|
+
if (!this.autoCreated) {
|
|
8943
|
+
return true;
|
|
8944
|
+
}
|
|
8945
|
+
try {
|
|
8946
|
+
const deleteResult = await this.contextService.delete(this.extensionContext);
|
|
8947
|
+
if (deleteResult) {
|
|
8948
|
+
log(`Extension context deleted: ${this.contextName} (ID: ${this.contextId})`);
|
|
8949
|
+
return true;
|
|
8950
|
+
} else {
|
|
8951
|
+
logError(`Warning: Failed to delete extension context: ${this.contextName}`, new Error("Delete operation returned false"));
|
|
8952
|
+
return false;
|
|
8953
|
+
}
|
|
8954
|
+
} catch (error) {
|
|
8955
|
+
logError(`Warning: Failed to delete extension context:`, error);
|
|
8956
|
+
return false;
|
|
8957
|
+
}
|
|
8958
|
+
}
|
|
8959
|
+
/**
|
|
8960
|
+
* Deletes a browser extension from the current context.
|
|
8961
|
+
*
|
|
8962
|
+
* @param extensionId - ID of the extension to delete.
|
|
8963
|
+
* @returns Promise that resolves to true if deletion was successful, false otherwise.
|
|
8964
|
+
*/
|
|
8965
|
+
async delete(extensionId) {
|
|
8966
|
+
await this._ensureInitialized();
|
|
8967
|
+
const remotePath = `${EXTENSIONS_BASE_PATH}/${extensionId}`;
|
|
8968
|
+
try {
|
|
8969
|
+
const deleteResult = await this.contextService.deleteFile(this.contextId, remotePath);
|
|
8970
|
+
return deleteResult.success;
|
|
8971
|
+
} catch (error) {
|
|
8972
|
+
logError(`An error occurred while deleting browser extension '${extensionId}':`, error);
|
|
8973
|
+
return false;
|
|
8974
|
+
}
|
|
8975
|
+
}
|
|
8976
|
+
/**
|
|
8977
|
+
* Create an ExtensionOption for the current context with specified extension IDs.
|
|
8978
|
+
*
|
|
8979
|
+
* This is a convenience method that creates an ExtensionOption using the current
|
|
8980
|
+
* service's contextId and the provided extension IDs. This option can then be
|
|
8981
|
+
* used with BrowserContext for browser session creation.
|
|
8982
|
+
*
|
|
8983
|
+
* @param extensionIds - List of extension IDs to include in the option.
|
|
8984
|
+
* These should be extensions that exist in the current context.
|
|
8985
|
+
* @returns ExtensionOption configuration object for browser extension integration.
|
|
8986
|
+
* @throws {Error} If extensionIds is empty or invalid.
|
|
8987
|
+
*
|
|
8988
|
+
* @example
|
|
8989
|
+
* ```typescript
|
|
8990
|
+
* // Create extensions
|
|
8991
|
+
* const ext1 = await extensionsService.create("/path/to/ext1.zip");
|
|
8992
|
+
* const ext2 = await extensionsService.create("/path/to/ext2.zip");
|
|
8993
|
+
*
|
|
8994
|
+
* // Create extension option for browser integration
|
|
8995
|
+
* const extOption = extensionsService.createExtensionOption([ext1.id, ext2.id]);
|
|
8996
|
+
*
|
|
8997
|
+
* // Use with BrowserContext
|
|
8998
|
+
* const browserContext = new BrowserContext({
|
|
8999
|
+
* contextId: "browser_session",
|
|
9000
|
+
* autoUpload: true,
|
|
9001
|
+
* extensionContextId: extOption.contextId,
|
|
9002
|
+
* extensionIds: extOption.extensionIds
|
|
9003
|
+
* });
|
|
9004
|
+
* ```
|
|
9005
|
+
*/
|
|
9006
|
+
createExtensionOption(extensionIds) {
|
|
9007
|
+
if (!this.contextId) {
|
|
9008
|
+
throw new Error("Service not initialized. Please call an async method first or ensure context is created.");
|
|
9009
|
+
}
|
|
9010
|
+
return new ExtensionOption(
|
|
9011
|
+
this.contextId,
|
|
9012
|
+
extensionIds
|
|
9013
|
+
);
|
|
9014
|
+
}
|
|
9015
|
+
};
|
|
9016
|
+
__name(_ExtensionsService, "ExtensionsService");
|
|
9017
|
+
var ExtensionsService = _ExtensionsService;
|
|
9018
|
+
|
|
8499
9019
|
// src/context-sync.ts
|
|
8500
9020
|
init_esm_shims();
|
|
8501
9021
|
var UploadStrategy = /* @__PURE__ */ ((UploadStrategy2) => {
|
|
@@ -8506,12 +9026,41 @@ var DownloadStrategy = /* @__PURE__ */ ((DownloadStrategy2) => {
|
|
|
8506
9026
|
DownloadStrategy2["DownloadAsync"] = "DownloadAsync";
|
|
8507
9027
|
return DownloadStrategy2;
|
|
8508
9028
|
})(DownloadStrategy || {});
|
|
9029
|
+
var _ExtractPolicyClass = class _ExtractPolicyClass {
|
|
9030
|
+
constructor(extract = true, deleteSrcFile = true, extractToCurrentFolder = false) {
|
|
9031
|
+
this.extract = true;
|
|
9032
|
+
this.deleteSrcFile = true;
|
|
9033
|
+
this.extractToCurrentFolder = false;
|
|
9034
|
+
this.extract = extract;
|
|
9035
|
+
this.deleteSrcFile = deleteSrcFile;
|
|
9036
|
+
this.extractToCurrentFolder = extractToCurrentFolder;
|
|
9037
|
+
}
|
|
9038
|
+
/**
|
|
9039
|
+
* Creates a new extract policy with default values
|
|
9040
|
+
*/
|
|
9041
|
+
static default() {
|
|
9042
|
+
return new _ExtractPolicyClass();
|
|
9043
|
+
}
|
|
9044
|
+
/**
|
|
9045
|
+
* Converts to plain object for JSON serialization
|
|
9046
|
+
*/
|
|
9047
|
+
toDict() {
|
|
9048
|
+
return {
|
|
9049
|
+
extract: this.extract,
|
|
9050
|
+
deleteSrcFile: this.deleteSrcFile,
|
|
9051
|
+
extractToCurrentFolder: this.extractToCurrentFolder
|
|
9052
|
+
};
|
|
9053
|
+
}
|
|
9054
|
+
};
|
|
9055
|
+
__name(_ExtractPolicyClass, "ExtractPolicyClass");
|
|
9056
|
+
var ExtractPolicyClass = _ExtractPolicyClass;
|
|
8509
9057
|
var _SyncPolicyImpl = class _SyncPolicyImpl {
|
|
8510
9058
|
constructor(policy) {
|
|
8511
9059
|
if (policy) {
|
|
8512
9060
|
this.uploadPolicy = policy.uploadPolicy;
|
|
8513
9061
|
this.downloadPolicy = policy.downloadPolicy;
|
|
8514
9062
|
this.deletePolicy = policy.deletePolicy;
|
|
9063
|
+
this.extractPolicy = policy.extractPolicy;
|
|
8515
9064
|
this.bwList = policy.bwList;
|
|
8516
9065
|
}
|
|
8517
9066
|
this.ensureDefaults();
|
|
@@ -8526,6 +9075,9 @@ var _SyncPolicyImpl = class _SyncPolicyImpl {
|
|
|
8526
9075
|
if (!this.deletePolicy) {
|
|
8527
9076
|
this.deletePolicy = newDeletePolicy();
|
|
8528
9077
|
}
|
|
9078
|
+
if (!this.extractPolicy) {
|
|
9079
|
+
this.extractPolicy = newExtractPolicy();
|
|
9080
|
+
}
|
|
8529
9081
|
if (!this.bwList) {
|
|
8530
9082
|
this.bwList = {
|
|
8531
9083
|
whiteLists: [
|
|
@@ -8543,6 +9095,7 @@ var _SyncPolicyImpl = class _SyncPolicyImpl {
|
|
|
8543
9095
|
uploadPolicy: this.uploadPolicy,
|
|
8544
9096
|
downloadPolicy: this.downloadPolicy,
|
|
8545
9097
|
deletePolicy: this.deletePolicy,
|
|
9098
|
+
extractPolicy: this.extractPolicy,
|
|
8546
9099
|
bwList: this.bwList
|
|
8547
9100
|
};
|
|
8548
9101
|
}
|
|
@@ -8550,9 +9103,9 @@ var _SyncPolicyImpl = class _SyncPolicyImpl {
|
|
|
8550
9103
|
__name(_SyncPolicyImpl, "SyncPolicyImpl");
|
|
8551
9104
|
var SyncPolicyImpl = _SyncPolicyImpl;
|
|
8552
9105
|
var _ContextSync = class _ContextSync {
|
|
8553
|
-
constructor(contextId,
|
|
9106
|
+
constructor(contextId, path4, policy) {
|
|
8554
9107
|
this.contextId = contextId;
|
|
8555
|
-
this.path =
|
|
9108
|
+
this.path = path4;
|
|
8556
9109
|
this.policy = policy;
|
|
8557
9110
|
}
|
|
8558
9111
|
// WithPolicy sets the policy and returns the context sync for chaining
|
|
@@ -8585,11 +9138,20 @@ function newDeletePolicy() {
|
|
|
8585
9138
|
};
|
|
8586
9139
|
}
|
|
8587
9140
|
__name(newDeletePolicy, "newDeletePolicy");
|
|
9141
|
+
function newExtractPolicy() {
|
|
9142
|
+
return {
|
|
9143
|
+
extract: true,
|
|
9144
|
+
deleteSrcFile: true,
|
|
9145
|
+
extractToCurrentFolder: false
|
|
9146
|
+
};
|
|
9147
|
+
}
|
|
9148
|
+
__name(newExtractPolicy, "newExtractPolicy");
|
|
8588
9149
|
function newSyncPolicy() {
|
|
8589
9150
|
return {
|
|
8590
9151
|
uploadPolicy: newUploadPolicy(),
|
|
8591
9152
|
downloadPolicy: newDownloadPolicy(),
|
|
8592
9153
|
deletePolicy: newDeletePolicy(),
|
|
9154
|
+
extractPolicy: newExtractPolicy(),
|
|
8593
9155
|
bwList: {
|
|
8594
9156
|
whiteLists: [
|
|
8595
9157
|
{
|
|
@@ -8605,13 +9167,98 @@ function newSyncPolicyWithDefaults(policy) {
|
|
|
8605
9167
|
return new SyncPolicyImpl(policy).toJSON();
|
|
8606
9168
|
}
|
|
8607
9169
|
__name(newSyncPolicyWithDefaults, "newSyncPolicyWithDefaults");
|
|
8608
|
-
function newContextSync(contextId,
|
|
8609
|
-
return new ContextSync(contextId,
|
|
9170
|
+
function newContextSync(contextId, path4, policy) {
|
|
9171
|
+
return new ContextSync(contextId, path4, policy);
|
|
8610
9172
|
}
|
|
8611
9173
|
__name(newContextSync, "newContextSync");
|
|
8612
9174
|
|
|
8613
9175
|
// src/session-params.ts
|
|
8614
9176
|
init_esm_shims();
|
|
9177
|
+
var _BrowserContext = class _BrowserContext {
|
|
9178
|
+
/**
|
|
9179
|
+
* Initialize BrowserContextImpl with optional extension support.
|
|
9180
|
+
*
|
|
9181
|
+
* @param contextId - ID of the browser context to bind to the session.
|
|
9182
|
+
* This identifies the browser instance for the session.
|
|
9183
|
+
* @param autoUpload - Whether to automatically upload browser data
|
|
9184
|
+
* when the session ends. Defaults to true.
|
|
9185
|
+
* @param extensionOption - Extension configuration object containing
|
|
9186
|
+
* contextId and extensionIds. This encapsulates
|
|
9187
|
+
* all extension-related configuration.
|
|
9188
|
+
* Defaults to undefined.
|
|
9189
|
+
*
|
|
9190
|
+
* Extension Configuration:
|
|
9191
|
+
* - **ExtensionOption**: Use extensionOption parameter with an ExtensionOption object
|
|
9192
|
+
* - **No Extensions**: Don't provide extensionOption parameter
|
|
9193
|
+
*
|
|
9194
|
+
* Auto-generation:
|
|
9195
|
+
* - extensionContextSyncs is automatically generated when extensionOption is provided
|
|
9196
|
+
* - extensionContextSyncs will be undefined if no extensionOption is provided
|
|
9197
|
+
* - extensionContextSyncs will be a ContextSync[] if extensionOption is valid
|
|
9198
|
+
*/
|
|
9199
|
+
constructor(contextId, autoUpload = true, extensionOption) {
|
|
9200
|
+
this.contextId = contextId;
|
|
9201
|
+
this.autoUpload = autoUpload;
|
|
9202
|
+
this.extensionOption = extensionOption;
|
|
9203
|
+
if (extensionOption) {
|
|
9204
|
+
this.extensionContextId = extensionOption.contextId;
|
|
9205
|
+
this.extensionIds = extensionOption.extensionIds;
|
|
9206
|
+
this.extensionContextSyncs = this._createExtensionContextSyncs();
|
|
9207
|
+
} else {
|
|
9208
|
+
this.extensionContextId = void 0;
|
|
9209
|
+
this.extensionIds = [];
|
|
9210
|
+
this.extensionContextSyncs = void 0;
|
|
9211
|
+
}
|
|
9212
|
+
}
|
|
9213
|
+
/**
|
|
9214
|
+
* Create ContextSync configurations for browser extensions.
|
|
9215
|
+
*
|
|
9216
|
+
* This method is called only when extensionOption is provided and contains
|
|
9217
|
+
* valid extension configuration (contextId and extensionIds).
|
|
9218
|
+
*
|
|
9219
|
+
* @returns ContextSync[] - List of context sync configurations for extensions.
|
|
9220
|
+
* Returns empty list if extension configuration is invalid.
|
|
9221
|
+
*/
|
|
9222
|
+
_createExtensionContextSyncs() {
|
|
9223
|
+
if (!this.extensionIds || this.extensionIds.length === 0 || !this.extensionContextId) {
|
|
9224
|
+
return [];
|
|
9225
|
+
}
|
|
9226
|
+
const whiteLists = this.extensionIds.map((extId) => ({
|
|
9227
|
+
path: extId,
|
|
9228
|
+
excludePaths: []
|
|
9229
|
+
}));
|
|
9230
|
+
const syncPolicy = {
|
|
9231
|
+
uploadPolicy: {
|
|
9232
|
+
...newUploadPolicy(),
|
|
9233
|
+
autoUpload: false
|
|
9234
|
+
},
|
|
9235
|
+
extractPolicy: {
|
|
9236
|
+
...newExtractPolicy(),
|
|
9237
|
+
extract: true,
|
|
9238
|
+
deleteSrcFile: true
|
|
9239
|
+
},
|
|
9240
|
+
bwList: {
|
|
9241
|
+
whiteLists
|
|
9242
|
+
}
|
|
9243
|
+
};
|
|
9244
|
+
const extensionSync = new ContextSync(
|
|
9245
|
+
this.extensionContextId,
|
|
9246
|
+
"/tmp/extensions/",
|
|
9247
|
+
syncPolicy
|
|
9248
|
+
);
|
|
9249
|
+
return [extensionSync];
|
|
9250
|
+
}
|
|
9251
|
+
/**
|
|
9252
|
+
* Get all context syncs including extension syncs.
|
|
9253
|
+
*
|
|
9254
|
+
* @returns ContextSync[] - All context sync configurations. Returns empty list if no extensions configured.
|
|
9255
|
+
*/
|
|
9256
|
+
getAllContextSyncs() {
|
|
9257
|
+
return this.extensionContextSyncs || [];
|
|
9258
|
+
}
|
|
9259
|
+
};
|
|
9260
|
+
__name(_BrowserContext, "BrowserContext");
|
|
9261
|
+
var BrowserContext = _BrowserContext;
|
|
8615
9262
|
var _CreateSessionParams = class _CreateSessionParams {
|
|
8616
9263
|
constructor() {
|
|
8617
9264
|
this.labels = {};
|
|
@@ -8674,8 +9321,8 @@ var _CreateSessionParams = class _CreateSessionParams {
|
|
|
8674
9321
|
/**
|
|
8675
9322
|
* AddContextSync adds a context sync configuration to the session parameters.
|
|
8676
9323
|
*/
|
|
8677
|
-
addContextSync(contextId,
|
|
8678
|
-
const contextSync = new ContextSync(contextId,
|
|
9324
|
+
addContextSync(contextId, path4, policy) {
|
|
9325
|
+
const contextSync = new ContextSync(contextId, path4, policy);
|
|
8679
9326
|
this.contextSync.push(contextSync);
|
|
8680
9327
|
return this;
|
|
8681
9328
|
}
|
|
@@ -8697,10 +9344,15 @@ var _CreateSessionParams = class _CreateSessionParams {
|
|
|
8697
9344
|
* Convert to plain object for JSON serialization
|
|
8698
9345
|
*/
|
|
8699
9346
|
toJSON() {
|
|
9347
|
+
let allContextSyncs = [...this.contextSync];
|
|
9348
|
+
if (this.browserContext && "getAllContextSyncs" in this.browserContext) {
|
|
9349
|
+
const extensionSyncs = this.browserContext.getAllContextSyncs();
|
|
9350
|
+
allContextSyncs = allContextSyncs.concat(extensionSyncs);
|
|
9351
|
+
}
|
|
8700
9352
|
return {
|
|
8701
9353
|
labels: this.labels,
|
|
8702
9354
|
imageId: this.imageId,
|
|
8703
|
-
contextSync:
|
|
9355
|
+
contextSync: allContextSyncs,
|
|
8704
9356
|
browserContext: this.browserContext,
|
|
8705
9357
|
isVpc: this.isVpc,
|
|
8706
9358
|
mcpPolicyId: this.mcpPolicyId
|
|
@@ -8714,7 +9366,18 @@ var _CreateSessionParams = class _CreateSessionParams {
|
|
|
8714
9366
|
params.labels = config.labels || {};
|
|
8715
9367
|
params.imageId = config.imageId;
|
|
8716
9368
|
params.contextSync = config.contextSync || [];
|
|
8717
|
-
|
|
9369
|
+
if (config.browserContext) {
|
|
9370
|
+
if ("getAllContextSyncs" in config.browserContext) {
|
|
9371
|
+
params.browserContext = config.browserContext;
|
|
9372
|
+
} else {
|
|
9373
|
+
const bc = config.browserContext;
|
|
9374
|
+
params.browserContext = new BrowserContext(
|
|
9375
|
+
bc.contextId,
|
|
9376
|
+
bc.autoUpload,
|
|
9377
|
+
bc.extensionOption
|
|
9378
|
+
);
|
|
9379
|
+
}
|
|
9380
|
+
}
|
|
8718
9381
|
params.isVpc = config.isVpc || false;
|
|
8719
9382
|
params.mcpPolicyId = config.mcpPolicyId;
|
|
8720
9383
|
return params;
|
|
@@ -8740,6 +9403,7 @@ export {
|
|
|
8740
9403
|
AuthenticationError,
|
|
8741
9404
|
Browser,
|
|
8742
9405
|
BrowserAgent,
|
|
9406
|
+
BrowserContext,
|
|
8743
9407
|
BrowserError,
|
|
8744
9408
|
BrowserOptionClass,
|
|
8745
9409
|
BrowserProxyClass,
|
|
@@ -8770,6 +9434,12 @@ export {
|
|
|
8770
9434
|
DescribeContextFilesResponse,
|
|
8771
9435
|
DescribeContextFilesResponseBody,
|
|
8772
9436
|
DownloadStrategy,
|
|
9437
|
+
Extension,
|
|
9438
|
+
ExtensionOption,
|
|
9439
|
+
ExtensionsService,
|
|
9440
|
+
ExtractPolicyClass,
|
|
9441
|
+
FileChangeEventHelper,
|
|
9442
|
+
FileChangeResultHelper,
|
|
8773
9443
|
FileError,
|
|
8774
9444
|
FileSystem,
|
|
8775
9445
|
GetContextFileDownloadUrlRequest,
|
|
@@ -8835,6 +9505,8 @@ export {
|
|
|
8835
9505
|
UI,
|
|
8836
9506
|
UIError,
|
|
8837
9507
|
UploadStrategy,
|
|
9508
|
+
loadConfig,
|
|
9509
|
+
loadDotEnv,
|
|
8838
9510
|
log,
|
|
8839
9511
|
logError,
|
|
8840
9512
|
newContextManager,
|
|
@@ -8842,6 +9514,7 @@ export {
|
|
|
8842
9514
|
newCreateSessionParams,
|
|
8843
9515
|
newDeletePolicy,
|
|
8844
9516
|
newDownloadPolicy,
|
|
9517
|
+
newExtractPolicy,
|
|
8845
9518
|
newSyncPolicy,
|
|
8846
9519
|
newSyncPolicyWithDefaults,
|
|
8847
9520
|
newUploadPolicy
|