test-wuying-agentbay-sdk 0.13.0-beta.20251212160413 → 0.13.0-beta.20251215095254
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/dist/{chunk-W4B6JMPA.cjs → chunk-QYUGADDC.cjs} +228 -94
- package/dist/chunk-QYUGADDC.cjs.map +1 -0
- package/dist/{chunk-S7SG7CLI.mjs → chunk-VEHDE3LU.mjs} +290 -156
- package/dist/chunk-VEHDE3LU.mjs.map +1 -0
- package/dist/index.cjs +336 -332
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +108 -11
- package/dist/index.d.ts +108 -11
- package/dist/index.mjs +165 -161
- package/dist/index.mjs.map +1 -1
- package/dist/{model-5SHCBTKT.mjs → model-NXNY7XBJ.mjs} +10 -2
- package/dist/model-TL7UT6WY.cjs +208 -0
- package/dist/{model-EYDBEIKS.cjs.map → model-TL7UT6WY.cjs.map} +1 -1
- package/docs/api/common-features/basics/session.md +0 -2
- package/docs/examples/common-features/advanced/archive-upload-mode-example/README.md +1 -1
- package/docs/examples/common-features/advanced/archive-upload-mode-example/archive-upload-mode-example.ts +1 -1
- package/docs/examples/common-features/basics/archive-upload-mode-example/README.md +1 -1
- package/docs/examples/common-features/basics/archive-upload-mode-example/main.ts +1 -1
- package/docs/examples/common-features/basics/filesystem-example/filesystem-filetransfer-example.ts +6 -7
- package/docs/examples/common-features/basics/filesystem-example/watch-directory-example.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-S7SG7CLI.mjs.map +0 -1
- package/dist/chunk-W4B6JMPA.cjs.map +0 -1
- package/dist/model-EYDBEIKS.cjs +0 -200
- /package/dist/{model-5SHCBTKT.mjs.map → model-NXNY7XBJ.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -41,6 +41,10 @@ import {
|
|
|
41
41
|
GetAdbLinkResponse,
|
|
42
42
|
GetAdbLinkResponseBody,
|
|
43
43
|
GetAdbLinkResponseBodyData,
|
|
44
|
+
GetAndLoadInternalContextRequest,
|
|
45
|
+
GetAndLoadInternalContextResponse,
|
|
46
|
+
GetAndLoadInternalContextResponseBody,
|
|
47
|
+
GetAndLoadInternalContextResponseBodyData,
|
|
44
48
|
GetCdpLinkRequest,
|
|
45
49
|
GetCdpLinkResponse,
|
|
46
50
|
GetCdpLinkResponseBody,
|
|
@@ -109,7 +113,7 @@ import {
|
|
|
109
113
|
SyncContextRequest,
|
|
110
114
|
SyncContextResponse,
|
|
111
115
|
SyncContextResponseBody
|
|
112
|
-
} from "./chunk-
|
|
116
|
+
} from "./chunk-VEHDE3LU.mjs";
|
|
113
117
|
import {
|
|
114
118
|
__commonJS,
|
|
115
119
|
__dirname,
|
|
@@ -693,7 +697,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
693
697
|
}
|
|
694
698
|
/**
|
|
695
699
|
* Delete Persistent Context
|
|
696
|
-
*
|
|
700
|
+
*
|
|
697
701
|
* @param request - ClearContextRequest
|
|
698
702
|
* @param runtime - runtime options for this request RuntimeOptions
|
|
699
703
|
* @returns ClearContextResponse
|
|
@@ -725,7 +729,7 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
725
729
|
}
|
|
726
730
|
/**
|
|
727
731
|
* Delete Persistent Context
|
|
728
|
-
*
|
|
732
|
+
*
|
|
729
733
|
* @param request - ClearContextRequest
|
|
730
734
|
* @returns ClearContextResponse
|
|
731
735
|
*/
|
|
@@ -1255,6 +1259,42 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
1255
1259
|
const runtime = new $dara.RuntimeOptions({});
|
|
1256
1260
|
return await this.getMcpResourceWithOptions(request, runtime);
|
|
1257
1261
|
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Get internal context request
|
|
1264
|
+
*
|
|
1265
|
+
* @param request - GetAndLoadInternalContextRequest
|
|
1266
|
+
* @param runtime - runtime options for this request RuntimeOptions
|
|
1267
|
+
* @returns GetAndLoadInternalContextResponse
|
|
1268
|
+
*/
|
|
1269
|
+
async getAndLoadInternalContextWithOptions(request, runtime) {
|
|
1270
|
+
request.validate();
|
|
1271
|
+
let query = OpenApiUtil.query(request.toMap());
|
|
1272
|
+
let req = new $OpenApiUtil.OpenApiRequest({
|
|
1273
|
+
query: OpenApiUtil.query(query)
|
|
1274
|
+
});
|
|
1275
|
+
let params = new $OpenApiUtil.Params({
|
|
1276
|
+
action: "GetAndLoadInternalContext",
|
|
1277
|
+
version: "2025-05-06",
|
|
1278
|
+
protocol: "HTTPS",
|
|
1279
|
+
pathname: "/",
|
|
1280
|
+
method: "GET",
|
|
1281
|
+
authType: "Anonymous",
|
|
1282
|
+
style: "RPC",
|
|
1283
|
+
reqBodyType: "formData",
|
|
1284
|
+
bodyType: "json"
|
|
1285
|
+
});
|
|
1286
|
+
return $dara.cast(await this.doRPCRequest(params.action, params.version, params.protocol, params.method, params.authType, params.bodyType, req, runtime), new GetAndLoadInternalContextResponse({}));
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Get internal context request
|
|
1290
|
+
*
|
|
1291
|
+
* @param request - GetAndLoadInternalContextRequest
|
|
1292
|
+
* @returns GetAndLoadInternalContextResponse
|
|
1293
|
+
*/
|
|
1294
|
+
async getAndLoadInternalContext(request) {
|
|
1295
|
+
let runtime = new $dara.RuntimeOptions({});
|
|
1296
|
+
return await this.getAndLoadInternalContextWithOptions(request, runtime);
|
|
1297
|
+
}
|
|
1258
1298
|
/**
|
|
1259
1299
|
* Get context list
|
|
1260
1300
|
*
|
|
@@ -1274,6 +1314,12 @@ var _Client = class _Client extends (OpenApi.default || OpenApi) {
|
|
|
1274
1314
|
if (!$dara.isNull(request.nextToken)) {
|
|
1275
1315
|
body["NextToken"] = request.nextToken;
|
|
1276
1316
|
}
|
|
1317
|
+
if (!$dara.isNull(request.sessionId)) {
|
|
1318
|
+
body["SessionId"] = request.sessionId;
|
|
1319
|
+
}
|
|
1320
|
+
if (!$dara.isNull(request.type)) {
|
|
1321
|
+
body["ContextType"] = request.type;
|
|
1322
|
+
}
|
|
1277
1323
|
const req = new $OpenApiUtil.OpenApiRequest({
|
|
1278
1324
|
body: OpenApiUtil.parseToMap(body)
|
|
1279
1325
|
});
|
|
@@ -2006,7 +2052,6 @@ init_esm_shims();
|
|
|
2006
2052
|
var dotenv = __toESM(require_main());
|
|
2007
2053
|
import * as fs2 from "fs";
|
|
2008
2054
|
import * as path2 from "path";
|
|
2009
|
-
var BROWSER_RECORD_PATH = "/home/wuying/record";
|
|
2010
2055
|
function defaultConfig() {
|
|
2011
2056
|
return {
|
|
2012
2057
|
endpoint: "wuyingai.cn-shanghai.aliyuncs.com",
|
|
@@ -2701,7 +2746,8 @@ var _ContextService = class _ContextService {
|
|
|
2701
2746
|
const request = new ListContextsRequest({
|
|
2702
2747
|
authorization: `Bearer ${this.agentBay.getAPIKey()}`,
|
|
2703
2748
|
maxResults,
|
|
2704
|
-
nextToken: params?.nextToken
|
|
2749
|
+
nextToken: params?.nextToken,
|
|
2750
|
+
sessionId: params?.sessionId
|
|
2705
2751
|
});
|
|
2706
2752
|
logAPICall("ListContexts");
|
|
2707
2753
|
logDebug(`Request: MaxResults=${maxResults}`, params?.nextToken ? `, NextToken=${params.nextToken}` : "");
|
|
@@ -10880,7 +10926,7 @@ var _Browser = class _Browser {
|
|
|
10880
10926
|
logDebug(`VPC mode, endpoint_router_port: ${this.session.httpPort}`);
|
|
10881
10927
|
this._endpointUrl = `ws://${this.session.networkInterfaceIp}:${this.session.httpPort}`;
|
|
10882
10928
|
} else {
|
|
10883
|
-
const { GetCdpLinkRequest: GetCdpLinkRequest2 } = await import("./model-
|
|
10929
|
+
const { GetCdpLinkRequest: GetCdpLinkRequest2 } = await import("./model-NXNY7XBJ.mjs");
|
|
10884
10930
|
const request = new GetCdpLinkRequest2({
|
|
10885
10931
|
authorization: `Bearer ${this.session.getAPIKey()}`,
|
|
10886
10932
|
sessionId: this.session.sessionId
|
|
@@ -12932,13 +12978,14 @@ import fetch2 from "node-fetch";
|
|
|
12932
12978
|
var _FileTransfer = class _FileTransfer {
|
|
12933
12979
|
/**
|
|
12934
12980
|
* Initialize FileTransfer with AgentBay client and session.
|
|
12935
|
-
*
|
|
12981
|
+
*
|
|
12936
12982
|
* @param agentBay - AgentBay instance for context service access
|
|
12937
12983
|
* @param session - Created session object for context operations
|
|
12938
12984
|
* @param httpTimeout - HTTP request timeout in seconds (default: 60.0)
|
|
12939
12985
|
* @param followRedirects - Whether to follow HTTP redirects (default: true)
|
|
12940
12986
|
*/
|
|
12941
12987
|
constructor(agentBay, session, httpTimeout = 60, followRedirects = true) {
|
|
12988
|
+
this.contextPath = null;
|
|
12942
12989
|
// Task completion states (for compatibility)
|
|
12943
12990
|
this.finishedStates = /* @__PURE__ */ new Set(["success", "successful", "ok", "finished", "done", "completed", "complete"]);
|
|
12944
12991
|
this.agentBay = agentBay;
|
|
@@ -12946,7 +12993,60 @@ var _FileTransfer = class _FileTransfer {
|
|
|
12946
12993
|
this.session = session;
|
|
12947
12994
|
this.httpTimeout = httpTimeout;
|
|
12948
12995
|
this.followRedirects = followRedirects;
|
|
12949
|
-
this.contextId =
|
|
12996
|
+
this.contextId = "";
|
|
12997
|
+
}
|
|
12998
|
+
/**
|
|
12999
|
+
* Get the current context ID.
|
|
13000
|
+
* @returns The context ID, or empty string if not yet loaded
|
|
13001
|
+
*/
|
|
13002
|
+
getContextId() {
|
|
13003
|
+
return this.contextId;
|
|
13004
|
+
}
|
|
13005
|
+
/**
|
|
13006
|
+
* Ensure the file transfer context id is set by calling GetAndLoadInternalContext with SessionId and ContextTypes=["file_transfer"].
|
|
13007
|
+
* Returns [success: boolean, errorMessage: string] tuple.
|
|
13008
|
+
*/
|
|
13009
|
+
async ensureContextId() {
|
|
13010
|
+
if (this.contextId) {
|
|
13011
|
+
return [true, ""];
|
|
13012
|
+
}
|
|
13013
|
+
try {
|
|
13014
|
+
const sid = this.session.getSessionId();
|
|
13015
|
+
if (!sid) return [false, "No session ID"];
|
|
13016
|
+
const client = this.agentBay.getClient();
|
|
13017
|
+
let response;
|
|
13018
|
+
try {
|
|
13019
|
+
const req = {
|
|
13020
|
+
authorization: `Bearer ${this.agentBay.getAPIKey()}`,
|
|
13021
|
+
sessionId: sid,
|
|
13022
|
+
contextTypes: ["file_transfer"]
|
|
13023
|
+
};
|
|
13024
|
+
response = await client.getAndLoadInternalContext(req);
|
|
13025
|
+
} catch (e) {
|
|
13026
|
+
return [false, e?.message || String(e)];
|
|
13027
|
+
}
|
|
13028
|
+
const body = response && response.body ? response.body : {};
|
|
13029
|
+
if (body.Success === false && body.Code) {
|
|
13030
|
+
return [false, body.Message || "Unknown error"];
|
|
13031
|
+
}
|
|
13032
|
+
const data = body.Data || body.data;
|
|
13033
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
13034
|
+
for (const item of data) {
|
|
13035
|
+
if (item && typeof item === "object") {
|
|
13036
|
+
const context_id = item.ContextId || item.contextId;
|
|
13037
|
+
const context_path = item.ContextPath || item.contextPath;
|
|
13038
|
+
if (context_id && context_path) {
|
|
13039
|
+
this.contextId = context_id;
|
|
13040
|
+
this.contextPath = context_path;
|
|
13041
|
+
return [true, ""];
|
|
13042
|
+
}
|
|
13043
|
+
}
|
|
13044
|
+
}
|
|
13045
|
+
}
|
|
13046
|
+
return [false, "Response contains no data"];
|
|
13047
|
+
} catch (e) {
|
|
13048
|
+
return [false, e?.message || String(e)];
|
|
13049
|
+
}
|
|
12950
13050
|
}
|
|
12951
13051
|
/**
|
|
12952
13052
|
* Upload workflow:
|
|
@@ -12975,12 +13075,15 @@ var _FileTransfer = class _FileTransfer {
|
|
|
12975
13075
|
};
|
|
12976
13076
|
}
|
|
12977
13077
|
if (!this.contextId) {
|
|
12978
|
-
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
|
|
12983
|
-
|
|
13078
|
+
const [success, errorMsg] = await this.ensureContextId();
|
|
13079
|
+
if (!success) {
|
|
13080
|
+
return {
|
|
13081
|
+
success: false,
|
|
13082
|
+
bytesSent: 0,
|
|
13083
|
+
path: remotePath,
|
|
13084
|
+
error: errorMsg || "No context ID"
|
|
13085
|
+
};
|
|
13086
|
+
}
|
|
12984
13087
|
}
|
|
12985
13088
|
const urlRes = await this.contextSvc.getFileUploadUrl(this.contextId, remotePath);
|
|
12986
13089
|
if (!urlRes.success || !urlRes.url) {
|
|
@@ -13090,7 +13193,7 @@ var _FileTransfer = class _FileTransfer {
|
|
|
13090
13193
|
* 1) Trigger session.context.sync(mode="upload") to sync cloud disk data to OSS
|
|
13091
13194
|
* 2) Get pre-signed download URL via context.getFileDownloadUrl
|
|
13092
13195
|
* 3) Download the file and save to local localPath
|
|
13093
|
-
* 4) If wait=true, wait for download task to reach completion after step 1
|
|
13196
|
+
* 4) If wait=true, wait for download task to reach completion after step 1
|
|
13094
13197
|
* (ensuring backend has prepared the download object)
|
|
13095
13198
|
*
|
|
13096
13199
|
* Returns DownloadResult containing sync and download request_ids, HTTP status, byte count, etc.
|
|
@@ -13105,13 +13208,16 @@ var _FileTransfer = class _FileTransfer {
|
|
|
13105
13208
|
} = options || {};
|
|
13106
13209
|
try {
|
|
13107
13210
|
if (!this.contextId) {
|
|
13108
|
-
|
|
13109
|
-
|
|
13110
|
-
|
|
13111
|
-
|
|
13112
|
-
|
|
13113
|
-
|
|
13114
|
-
|
|
13211
|
+
const [success, errorMsg] = await this.ensureContextId();
|
|
13212
|
+
if (!success) {
|
|
13213
|
+
return {
|
|
13214
|
+
success: false,
|
|
13215
|
+
bytesReceived: 0,
|
|
13216
|
+
path: remotePath,
|
|
13217
|
+
localPath,
|
|
13218
|
+
error: errorMsg || "No context ID"
|
|
13219
|
+
};
|
|
13220
|
+
}
|
|
13115
13221
|
}
|
|
13116
13222
|
let reqIdSync;
|
|
13117
13223
|
try {
|
|
@@ -13470,7 +13576,7 @@ var _FileSystem = class _FileSystem {
|
|
|
13470
13576
|
}
|
|
13471
13577
|
/**
|
|
13472
13578
|
* Ensure FileTransfer is initialized with the current session.
|
|
13473
|
-
*
|
|
13579
|
+
*
|
|
13474
13580
|
* @returns The FileTransfer instance
|
|
13475
13581
|
*/
|
|
13476
13582
|
_ensureFileTransfer() {
|
|
@@ -13483,6 +13589,30 @@ var _FileSystem = class _FileSystem {
|
|
|
13483
13589
|
}
|
|
13484
13590
|
return this._fileTransfer;
|
|
13485
13591
|
}
|
|
13592
|
+
/**
|
|
13593
|
+
* Get the context path for file transfer operations.
|
|
13594
|
+
*
|
|
13595
|
+
* This method ensures the context ID is loaded and returns the associated
|
|
13596
|
+
* context path that was retrieved from GetAndLoadInternalContext API.
|
|
13597
|
+
*
|
|
13598
|
+
* @returns The context path if available, null otherwise.
|
|
13599
|
+
*
|
|
13600
|
+
* @example
|
|
13601
|
+
* ```typescript
|
|
13602
|
+
* const session = (await agentBay.create(params)).session;
|
|
13603
|
+
* const contextPath = await session.fileSystem.getFileTransferContextPath();
|
|
13604
|
+
* if (contextPath) {
|
|
13605
|
+
* console.log(`Context path: ${contextPath}`);
|
|
13606
|
+
* }
|
|
13607
|
+
* ```
|
|
13608
|
+
*/
|
|
13609
|
+
async getFileTransferContextPath() {
|
|
13610
|
+
const fileTransfer = this._ensureFileTransfer();
|
|
13611
|
+
if (!fileTransfer.getContextId()) {
|
|
13612
|
+
await fileTransfer.ensureContextId();
|
|
13613
|
+
}
|
|
13614
|
+
return fileTransfer.contextPath || null;
|
|
13615
|
+
}
|
|
13486
13616
|
/**
|
|
13487
13617
|
* Creates a new directory at the specified path.
|
|
13488
13618
|
* Corresponds to Python's create_directory() method
|
|
@@ -14382,8 +14512,8 @@ var _FileSystem = class _FileSystem {
|
|
|
14382
14512
|
try {
|
|
14383
14513
|
const fileTransfer = this._ensureFileTransfer();
|
|
14384
14514
|
const result = await fileTransfer.upload(localPath, remotePath, options);
|
|
14385
|
-
if (result.success
|
|
14386
|
-
const contextId =
|
|
14515
|
+
if (result.success) {
|
|
14516
|
+
const contextId = fileTransfer.contextId;
|
|
14387
14517
|
if (contextId) {
|
|
14388
14518
|
try {
|
|
14389
14519
|
const deleteResult = await this.session.agentBay.context.deleteFile(contextId, remotePath);
|
|
@@ -14430,8 +14560,8 @@ var _FileSystem = class _FileSystem {
|
|
|
14430
14560
|
try {
|
|
14431
14561
|
const fileTransfer = this._ensureFileTransfer();
|
|
14432
14562
|
const result = await fileTransfer.download(remotePath, localPath, options);
|
|
14433
|
-
if (result.success
|
|
14434
|
-
const contextId =
|
|
14563
|
+
if (result.success) {
|
|
14564
|
+
const contextId = fileTransfer.contextId;
|
|
14435
14565
|
if (contextId) {
|
|
14436
14566
|
try {
|
|
14437
14567
|
const deleteResult = await this.session.agentBay.context.deleteFile(contextId, remotePath);
|
|
@@ -14942,7 +15072,7 @@ var _Mobile = class _Mobile {
|
|
|
14942
15072
|
async getAdbUrl(adbkeyPub) {
|
|
14943
15073
|
try {
|
|
14944
15074
|
const optionsJson = JSON.stringify({ adbkey_pub: adbkeyPub });
|
|
14945
|
-
const { GetAdbLinkRequest: GetAdbLinkRequest2 } = await import("./model-
|
|
15075
|
+
const { GetAdbLinkRequest: GetAdbLinkRequest2 } = await import("./model-NXNY7XBJ.mjs");
|
|
14946
15076
|
const request = new GetAdbLinkRequest2({
|
|
14947
15077
|
authorization: `Bearer ${this.session.getAPIKey()}`,
|
|
14948
15078
|
sessionId: this.session.sessionId,
|
|
@@ -15551,10 +15681,6 @@ var _Session = class _Session {
|
|
|
15551
15681
|
* @param sessionId - The ID of this session.
|
|
15552
15682
|
*/
|
|
15553
15683
|
constructor(agentBay, sessionId) {
|
|
15554
|
-
// File transfer context ID
|
|
15555
|
-
this.fileTransferContextId = null;
|
|
15556
|
-
// Browser recording context ID
|
|
15557
|
-
this.recordContextId = null;
|
|
15558
15684
|
// VPC-related information
|
|
15559
15685
|
this.isVpc = false;
|
|
15560
15686
|
// Whether this session uses VPC resources
|
|
@@ -15721,32 +15847,15 @@ var _Session = class _Session {
|
|
|
15721
15847
|
*/
|
|
15722
15848
|
async delete(syncContext = false) {
|
|
15723
15849
|
try {
|
|
15724
|
-
let shouldSync = false;
|
|
15725
|
-
let syncContextId = null;
|
|
15726
15850
|
if (syncContext) {
|
|
15727
|
-
shouldSync = true;
|
|
15728
|
-
logInfo("\u{1F504} User requested context synchronization");
|
|
15729
|
-
} else if (this.enableBrowserReplay && this.recordContextId) {
|
|
15730
|
-
shouldSync = true;
|
|
15731
|
-
syncContextId = this.recordContextId;
|
|
15732
|
-
logInfo(
|
|
15733
|
-
`\u{1F3A5} Browser replay enabled - syncing recording context: ${syncContextId}`
|
|
15734
|
-
);
|
|
15735
|
-
}
|
|
15736
|
-
if (shouldSync) {
|
|
15737
15851
|
logDebug(
|
|
15738
15852
|
"Triggering context synchronization before session deletion..."
|
|
15739
15853
|
);
|
|
15740
15854
|
const syncStartTime = Date.now();
|
|
15741
15855
|
try {
|
|
15742
15856
|
let syncResult;
|
|
15743
|
-
|
|
15744
|
-
|
|
15745
|
-
logInfo(`\u{1F3A5} Synced browser recording context: ${syncContextId}`);
|
|
15746
|
-
} else {
|
|
15747
|
-
syncResult = await this.context.sync();
|
|
15748
|
-
logInfo("\u{1F504} Synced all contexts");
|
|
15749
|
-
}
|
|
15857
|
+
syncResult = await this.context.sync();
|
|
15858
|
+
logInfo("\u{1F504} Synced all contexts");
|
|
15750
15859
|
const syncDuration = Date.now() - syncStartTime;
|
|
15751
15860
|
if (syncResult.success) {
|
|
15752
15861
|
logInfo(`Context sync completed in ${syncDuration}ms`);
|
|
@@ -16819,16 +16928,6 @@ var Session = _Session;
|
|
|
16819
16928
|
|
|
16820
16929
|
// src/agent-bay.ts
|
|
16821
16930
|
var BROWSER_DATA_PATH2 = "/tmp/agentbay_browser";
|
|
16822
|
-
function generateRandomContextName(length = 8, includeTimestamp = true) {
|
|
16823
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-T:.Z]/g, "").slice(0, 14);
|
|
16824
|
-
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
16825
|
-
let randomPart = "";
|
|
16826
|
-
for (let i = 0; i < length; i++) {
|
|
16827
|
-
randomPart += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
16828
|
-
}
|
|
16829
|
-
return includeTimestamp ? `${timestamp}_${randomPart}` : randomPart;
|
|
16830
|
-
}
|
|
16831
|
-
__name(generateRandomContextName, "generateRandomContextName");
|
|
16832
16931
|
var _AgentBay = class _AgentBay {
|
|
16833
16932
|
/**
|
|
16834
16933
|
* Initialize the AgentBay client.
|
|
@@ -16839,7 +16938,6 @@ var _AgentBay = class _AgentBay {
|
|
|
16839
16938
|
* @param options.envFile - Custom path to .env file. If not provided, will search upward from current directory.
|
|
16840
16939
|
*/
|
|
16841
16940
|
constructor(options = {}) {
|
|
16842
|
-
this.fileTransferContext = null;
|
|
16843
16941
|
loadDotEnvWithFallback(options.envFile);
|
|
16844
16942
|
this.apiKey = options.apiKey || process.env.AGENTBAY_API_KEY || "";
|
|
16845
16943
|
if (!this.apiKey) {
|
|
@@ -16873,7 +16971,7 @@ var _AgentBay = class _AgentBay {
|
|
|
16873
16971
|
}
|
|
16874
16972
|
/**
|
|
16875
16973
|
* Wait for mobile simulate command to complete.
|
|
16876
|
-
*
|
|
16974
|
+
*
|
|
16877
16975
|
* @param session - The session to wait for mobile simulate
|
|
16878
16976
|
* @param mobileSimPath - The dev info path to the mobile simulate
|
|
16879
16977
|
* @param mobileSimMode - The mode of the mobile simulate. If not provided, will use the default mode.
|
|
@@ -16924,35 +17022,6 @@ var _AgentBay = class _AgentBay {
|
|
|
16924
17022
|
logInfo(`Error executing mobile simulate command: ${error}`);
|
|
16925
17023
|
}
|
|
16926
17024
|
}
|
|
16927
|
-
/**
|
|
16928
|
-
* Update browser replay context with AppInstanceId from response data.
|
|
16929
|
-
*
|
|
16930
|
-
* @param responseData - Response data containing AppInstanceId
|
|
16931
|
-
* @param recordContextId - The record context ID to update
|
|
16932
|
-
*/
|
|
16933
|
-
async _updateBrowserReplayContext(responseData, recordContextId) {
|
|
16934
|
-
if (!recordContextId) {
|
|
16935
|
-
return;
|
|
16936
|
-
}
|
|
16937
|
-
try {
|
|
16938
|
-
const appInstanceId = responseData?.appInstanceId;
|
|
16939
|
-
if (!appInstanceId) {
|
|
16940
|
-
logError("AppInstanceId not found in response data, skipping browser replay context update");
|
|
16941
|
-
return;
|
|
16942
|
-
}
|
|
16943
|
-
const contextName = `browserreplay-${appInstanceId}`;
|
|
16944
|
-
const contextObj = new Context(recordContextId, contextName);
|
|
16945
|
-
logDebug(`Updating browser replay context: ${contextName} -> ${recordContextId}`);
|
|
16946
|
-
const updateResult = await this.context.update(contextObj);
|
|
16947
|
-
if (updateResult.success) {
|
|
16948
|
-
logInfo(`\u2705 Successfully updated browser replay context: ${contextName}`);
|
|
16949
|
-
} else {
|
|
16950
|
-
logError(`\u26A0\uFE0F Failed to update browser replay context: ${updateResult.errorMessage}`);
|
|
16951
|
-
}
|
|
16952
|
-
} catch (error) {
|
|
16953
|
-
logError(`\u274C Error updating browser replay context: ${error}`);
|
|
16954
|
-
}
|
|
16955
|
-
}
|
|
16956
17025
|
/**
|
|
16957
17026
|
* Create a new session in the AgentBay cloud environment.
|
|
16958
17027
|
*
|
|
@@ -17018,20 +17087,6 @@ var _AgentBay = class _AgentBay {
|
|
|
17018
17087
|
params.contextSync.push(mobileSimContextSync);
|
|
17019
17088
|
}
|
|
17020
17089
|
}
|
|
17021
|
-
const contextName = `file-transfer-context-${Date.now()}`;
|
|
17022
|
-
const contextResult = await this.context.get(contextName, true);
|
|
17023
|
-
if (contextResult.success && contextResult.context) {
|
|
17024
|
-
this.fileTransferContext = contextResult.context;
|
|
17025
|
-
const fileTransferContextSync = new ContextSync(
|
|
17026
|
-
contextResult.context.id,
|
|
17027
|
-
"/tmp/file-transfer"
|
|
17028
|
-
);
|
|
17029
|
-
if (!params.contextSync) {
|
|
17030
|
-
params.contextSync = [];
|
|
17031
|
-
}
|
|
17032
|
-
logDebug(`Adding context sync for file transfer operations: ${fileTransferContextSync}`);
|
|
17033
|
-
params.contextSync.push(fileTransferContextSync);
|
|
17034
|
-
}
|
|
17035
17090
|
const request = new CreateMcpSessionRequest({
|
|
17036
17091
|
authorization: "Bearer " + this.apiKey
|
|
17037
17092
|
});
|
|
@@ -17090,21 +17145,6 @@ var _AgentBay = class _AgentBay {
|
|
|
17090
17145
|
request.persistenceDataList.push(browserContextSync);
|
|
17091
17146
|
needsContextSync = true;
|
|
17092
17147
|
}
|
|
17093
|
-
let recordContextId = "";
|
|
17094
|
-
if (params.enableBrowserReplay) {
|
|
17095
|
-
const recordPath = BROWSER_RECORD_PATH;
|
|
17096
|
-
const recordContextName = generateRandomContextName();
|
|
17097
|
-
const result = await this.context.get(recordContextName, true);
|
|
17098
|
-
recordContextId = result.success ? result.contextId : "";
|
|
17099
|
-
const recordPersistence = new CreateMcpSessionRequestPersistenceDataList({
|
|
17100
|
-
contextId: recordContextId,
|
|
17101
|
-
path: recordPath
|
|
17102
|
-
});
|
|
17103
|
-
if (!request.persistenceDataList) {
|
|
17104
|
-
request.persistenceDataList = [];
|
|
17105
|
-
}
|
|
17106
|
-
request.persistenceDataList.push(recordPersistence);
|
|
17107
|
-
}
|
|
17108
17148
|
if (params.extraConfigs) {
|
|
17109
17149
|
request.extraConfigs = JSON.stringify(params.extraConfigs);
|
|
17110
17150
|
if (params.extraConfigs.mobile?.simulateConfig?.simulate) {
|
|
@@ -17230,8 +17270,6 @@ var _AgentBay = class _AgentBay {
|
|
|
17230
17270
|
}
|
|
17231
17271
|
session.resourceUrl = resourceUrl;
|
|
17232
17272
|
session.enableBrowserReplay = params.enableBrowserReplay || false;
|
|
17233
|
-
session.fileTransferContextId = this.fileTransferContext ? this.fileTransferContext.id : null;
|
|
17234
|
-
session.recordContextId = recordContextId || null;
|
|
17235
17273
|
session.imageId = params.imageId;
|
|
17236
17274
|
if (params.extraConfigs && params.extraConfigs.mobile) {
|
|
17237
17275
|
log("Applying mobile configuration...");
|
|
@@ -17246,9 +17284,6 @@ var _AgentBay = class _AgentBay {
|
|
|
17246
17284
|
logError(`Warning: Failed to apply mobile configuration: ${error}`);
|
|
17247
17285
|
}
|
|
17248
17286
|
}
|
|
17249
|
-
if (params.enableBrowserReplay) {
|
|
17250
|
-
await this._updateBrowserReplayContext(data, recordContextId);
|
|
17251
|
-
}
|
|
17252
17287
|
if (params.isVpc) {
|
|
17253
17288
|
logDebug("VPC session detected, automatically fetching MCP tools...");
|
|
17254
17289
|
try {
|
|
@@ -17641,41 +17676,6 @@ var _AgentBay = class _AgentBay {
|
|
|
17641
17676
|
session.token = getResult.data.token;
|
|
17642
17677
|
session.resourceUrl = getResult.data.resourceUrl;
|
|
17643
17678
|
}
|
|
17644
|
-
if (getResult.data && getResult.data.contexts && getResult.data.contexts.length > 0) {
|
|
17645
|
-
const contexts = getResult.data.contexts;
|
|
17646
|
-
const fileTransferContexts = contexts.filter(
|
|
17647
|
-
(ctx) => ctx.name && ctx.name.startsWith("file-transfer-context-")
|
|
17648
|
-
);
|
|
17649
|
-
if (fileTransferContexts.length === 0) {
|
|
17650
|
-
const availableContexts = contexts.map((ctx) => ctx.name || "unknown");
|
|
17651
|
-
logWarn(
|
|
17652
|
-
`\u26A0\uFE0F No file-transfer-context- found in contexts list for session ${sessionId}. Available contexts: ${availableContexts.join(", ")}`
|
|
17653
|
-
);
|
|
17654
|
-
session.fileTransferContextId = null;
|
|
17655
|
-
} else if (fileTransferContexts.length === 1) {
|
|
17656
|
-
const contextId = fileTransferContexts[0].id;
|
|
17657
|
-
if (contextId) {
|
|
17658
|
-
session.fileTransferContextId = contextId;
|
|
17659
|
-
logInfo(`\u{1F4C1} Found file transfer context for recovered session: ${contextId}`);
|
|
17660
|
-
} else {
|
|
17661
|
-
logWarn(
|
|
17662
|
-
`\u26A0\uFE0F File transfer context found but missing 'id' field: ${JSON.stringify(fileTransferContexts[0])}`
|
|
17663
|
-
);
|
|
17664
|
-
session.fileTransferContextId = null;
|
|
17665
|
-
}
|
|
17666
|
-
} else {
|
|
17667
|
-
const contextNames = fileTransferContexts.map((ctx) => ctx.name || "unknown");
|
|
17668
|
-
logWarn(
|
|
17669
|
-
`\u26A0\uFE0F Multiple file-transfer-context- found in contexts list for session ${sessionId}. Found ${fileTransferContexts.length} contexts: ${contextNames.join(", ")}. Not setting fileTransferContextId.`
|
|
17670
|
-
);
|
|
17671
|
-
session.fileTransferContextId = null;
|
|
17672
|
-
}
|
|
17673
|
-
} else {
|
|
17674
|
-
logWarn(
|
|
17675
|
-
`\u26A0\uFE0F No contexts list found in GetSession response for session ${sessionId}. fileTransferContextId will remain null.`
|
|
17676
|
-
);
|
|
17677
|
-
session.fileTransferContextId = null;
|
|
17678
|
-
}
|
|
17679
17679
|
return {
|
|
17680
17680
|
requestId: getResult.requestId,
|
|
17681
17681
|
success: true,
|
|
@@ -19042,6 +19042,10 @@ export {
|
|
|
19042
19042
|
GetAdbLinkResponse,
|
|
19043
19043
|
GetAdbLinkResponseBody,
|
|
19044
19044
|
GetAdbLinkResponseBodyData,
|
|
19045
|
+
GetAndLoadInternalContextRequest,
|
|
19046
|
+
GetAndLoadInternalContextResponse,
|
|
19047
|
+
GetAndLoadInternalContextResponseBody,
|
|
19048
|
+
GetAndLoadInternalContextResponseBodyData,
|
|
19045
19049
|
GetCdpLinkRequest,
|
|
19046
19050
|
GetCdpLinkResponse,
|
|
19047
19051
|
GetCdpLinkResponseBody,
|