wuying-agentbay-sdk 0.13.0 → 0.13.1

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/index.cjs CHANGED
@@ -552,7 +552,7 @@ function getVersionFromPackageJson() {
552
552
  }
553
553
  } catch (error) {
554
554
  }
555
- return "0.13.0";
555
+ return "0.13.1";
556
556
  }
557
557
  _chunk4IPTHWLMcjs.__name.call(void 0, getVersionFromPackageJson, "getVersionFromPackageJson");
558
558
  function isReleaseBuild() {
@@ -17230,50 +17230,51 @@ var _AgentBay = class _AgentBay {
17230
17230
  */
17231
17231
  async create(params) {
17232
17232
  try {
17233
- logDebug(`default context syncs length: ${_optionalChain([params, 'access', _194 => _194.contextSync, 'optionalAccess', _195 => _195.length])}`);
17234
- if (_optionalChain([params, 'access', _196 => _196.extraConfigs, 'optionalAccess', _197 => _197.mobile, 'optionalAccess', _198 => _198.simulateConfig])) {
17235
- const mobileSimContextId = params.extraConfigs.mobile.simulateConfig.simulatedContextId;
17233
+ const paramsCopy = this.deepCopyParams(params);
17234
+ logDebug(`default context syncs length: ${_optionalChain([paramsCopy, 'access', _194 => _194.contextSync, 'optionalAccess', _195 => _195.length])}`);
17235
+ if (_optionalChain([paramsCopy, 'access', _196 => _196.extraConfigs, 'optionalAccess', _197 => _197.mobile, 'optionalAccess', _198 => _198.simulateConfig])) {
17236
+ const mobileSimContextId = paramsCopy.extraConfigs.mobile.simulateConfig.simulatedContextId;
17236
17237
  if (mobileSimContextId) {
17237
17238
  const mobileSimContextSync = new ContextSync(
17238
17239
  mobileSimContextId,
17239
17240
  "/data/agentbay_mobile_info"
17240
17241
  );
17241
- if (!params.contextSync) {
17242
- params.contextSync = [];
17242
+ if (!paramsCopy.contextSync) {
17243
+ paramsCopy.contextSync = [];
17243
17244
  }
17244
17245
  logInfo(`Adding context sync for mobile simulate: ${JSON.stringify(mobileSimContextSync)}`);
17245
- params.contextSync.push(mobileSimContextSync);
17246
+ paramsCopy.contextSync.push(mobileSimContextSync);
17246
17247
  }
17247
17248
  }
17248
17249
  const request = new (0, _chunkWVWGLZDTcjs.CreateMcpSessionRequest)({
17249
17250
  authorization: "Bearer " + this.apiKey
17250
17251
  });
17251
- if (params.enableBrowserReplay === false) {
17252
+ if (paramsCopy.enableBrowserReplay === false) {
17252
17253
  request.enableRecord = false;
17253
17254
  }
17254
- const framework = _optionalChain([params, 'optionalAccess', _199 => _199.framework]) || "";
17255
+ const framework = _optionalChain([paramsCopy, 'optionalAccess', _199 => _199.framework]) || "";
17255
17256
  const sdkStatsJson = `{"source":"sdk","sdk_language":"typescript","sdk_version":"${VERSION}","is_release":${IS_RELEASE},"framework":"${framework}"}`;
17256
17257
  request.sdkStats = sdkStatsJson;
17257
17258
  if (this.config.region_id) {
17258
17259
  request.loginRegionId = this.config.region_id;
17259
17260
  }
17260
- if (params.labels) {
17261
- request.labels = JSON.stringify(params.labels);
17261
+ if (paramsCopy.labels) {
17262
+ request.labels = JSON.stringify(paramsCopy.labels);
17262
17263
  }
17263
- if (params.imageId) {
17264
- request.imageId = params.imageId;
17264
+ if (paramsCopy.imageId) {
17265
+ request.imageId = paramsCopy.imageId;
17265
17266
  }
17266
- if (params.policyId) {
17267
- request.mcpPolicyId = params.policyId;
17267
+ if (paramsCopy.policyId) {
17268
+ request.mcpPolicyId = paramsCopy.policyId;
17268
17269
  }
17269
- request.vpcResource = params.isVpc || false;
17270
+ request.vpcResource = paramsCopy.isVpc || false;
17270
17271
  let needsContextSync = false;
17271
17272
  let needsMobileSim = false;
17272
17273
  let mobileSimMode = void 0;
17273
17274
  let mobileSimPath = void 0;
17274
- if (params.contextSync && params.contextSync.length > 0) {
17275
+ if (paramsCopy.contextSync && paramsCopy.contextSync.length > 0) {
17275
17276
  const persistenceDataList = [];
17276
- for (const contextSync of params.contextSync) {
17277
+ for (const contextSync of paramsCopy.contextSync) {
17277
17278
  const persistenceItem = new (0, _chunkWVWGLZDTcjs.CreateMcpSessionRequestPersistenceDataList)({
17278
17279
  contextId: contextSync.contextId,
17279
17280
  path: contextSync.path
@@ -17286,16 +17287,16 @@ var _AgentBay = class _AgentBay {
17286
17287
  request.persistenceDataList = persistenceDataList;
17287
17288
  needsContextSync = persistenceDataList.length > 0;
17288
17289
  }
17289
- if (params.browserContext) {
17290
+ if (paramsCopy.browserContext) {
17290
17291
  const syncPolicy = {
17291
- uploadPolicy: { autoUpload: params.browserContext.autoUpload },
17292
+ uploadPolicy: { autoUpload: paramsCopy.browserContext.autoUpload },
17292
17293
  downloadPolicy: null,
17293
17294
  deletePolicy: null,
17294
17295
  bwList: null,
17295
17296
  recyclePolicy: null
17296
17297
  };
17297
17298
  const browserContextSync = new (0, _chunkWVWGLZDTcjs.CreateMcpSessionRequestPersistenceDataList)({
17298
- contextId: params.browserContext.contextId,
17299
+ contextId: paramsCopy.browserContext.contextId,
17299
17300
  path: BROWSER_DATA_PATH2,
17300
17301
  // Using a constant path for browser data
17301
17302
  policy: JSON.stringify(syncPolicy)
@@ -17306,24 +17307,24 @@ var _AgentBay = class _AgentBay {
17306
17307
  request.persistenceDataList.push(browserContextSync);
17307
17308
  needsContextSync = true;
17308
17309
  }
17309
- if (params.extraConfigs) {
17310
- request.extraConfigs = JSON.stringify(params.extraConfigs);
17311
- if (_optionalChain([params, 'access', _200 => _200.extraConfigs, 'access', _201 => _201.mobile, 'optionalAccess', _202 => _202.simulateConfig, 'optionalAccess', _203 => _203.simulate])) {
17312
- mobileSimPath = params.extraConfigs.mobile.simulateConfig.simulatePath;
17310
+ if (paramsCopy.extraConfigs) {
17311
+ request.extraConfigs = JSON.stringify(paramsCopy.extraConfigs);
17312
+ if (_optionalChain([paramsCopy, 'access', _200 => _200.extraConfigs, 'access', _201 => _201.mobile, 'optionalAccess', _202 => _202.simulateConfig, 'optionalAccess', _203 => _203.simulate])) {
17313
+ mobileSimPath = paramsCopy.extraConfigs.mobile.simulateConfig.simulatePath;
17313
17314
  if (!mobileSimPath) {
17314
17315
  logInfo("mobile_sim_path is not set now, skip mobile simulate operation");
17315
17316
  } else {
17316
17317
  needsMobileSim = true;
17317
- mobileSimMode = params.extraConfigs.mobile.simulateConfig.simulateMode;
17318
+ mobileSimMode = paramsCopy.extraConfigs.mobile.simulateConfig.simulateMode;
17318
17319
  }
17319
17320
  }
17320
17321
  }
17321
17322
  logAPICall("CreateMcpSession", {
17322
- labels: params.labels,
17323
- imageId: params.imageId,
17324
- policyId: params.policyId,
17325
- isVpc: params.isVpc,
17326
- persistenceDataCount: params.contextSync ? params.contextSync.length : 0
17323
+ labels: paramsCopy.labels,
17324
+ imageId: paramsCopy.imageId,
17325
+ policyId: paramsCopy.policyId,
17326
+ isVpc: paramsCopy.isVpc,
17327
+ persistenceDataCount: paramsCopy.contextSync ? paramsCopy.contextSync.length : 0
17327
17328
  });
17328
17329
  const response = await this.client.createMcpSession(request);
17329
17330
  const requestId = extractRequestId(response) || "";
@@ -17419,7 +17420,7 @@ var _AgentBay = class _AgentBay {
17419
17420
  }
17420
17421
  );
17421
17422
  const session = new Session(this, sessionId);
17422
- session.isVpc = params.isVpc || false;
17423
+ session.isVpc = paramsCopy.isVpc || false;
17423
17424
  if (data.networkInterfaceIp) {
17424
17425
  session.networkInterfaceIp = data.networkInterfaceIp;
17425
17426
  }
@@ -17430,12 +17431,12 @@ var _AgentBay = class _AgentBay {
17430
17431
  session.token = data.token;
17431
17432
  }
17432
17433
  session.resourceUrl = resourceUrl;
17433
- session.enableBrowserReplay = params.enableBrowserReplay || false;
17434
- session.imageId = params.imageId;
17435
- if (params.extraConfigs && params.extraConfigs.mobile) {
17434
+ session.enableBrowserReplay = paramsCopy.enableBrowserReplay || false;
17435
+ session.imageId = paramsCopy.imageId;
17436
+ if (paramsCopy.extraConfigs && paramsCopy.extraConfigs.mobile) {
17436
17437
  log("Applying mobile configuration...");
17437
17438
  try {
17438
- const configResult = await session.mobile.configure(params.extraConfigs.mobile);
17439
+ const configResult = await session.mobile.configure(paramsCopy.extraConfigs.mobile);
17439
17440
  if (configResult.success) {
17440
17441
  log("Mobile configuration applied successfully");
17441
17442
  } else {
@@ -17445,7 +17446,7 @@ var _AgentBay = class _AgentBay {
17445
17446
  logError(`Warning: Failed to apply mobile configuration: ${error}`);
17446
17447
  }
17447
17448
  }
17448
- if (params.isVpc) {
17449
+ if (paramsCopy.isVpc) {
17449
17450
  logDebug("VPC session detected, automatically fetching MCP tools...");
17450
17451
  try {
17451
17452
  const toolsResult = await session.listMcpTools();
@@ -17956,6 +17957,40 @@ var _AgentBay = class _AgentBay {
17956
17957
  };
17957
17958
  }
17958
17959
  }
17960
+ /**
17961
+ * Creates a deep copy of CreateSessionParams to avoid modifying the original object.
17962
+ * @param params - The original params object to copy
17963
+ * @returns A deep copy of the params object
17964
+ */
17965
+ deepCopyParams(params) {
17966
+ const copied = JSON.parse(JSON.stringify(params));
17967
+ if (copied.contextSync && Array.isArray(copied.contextSync)) {
17968
+ copied.contextSync = copied.contextSync.map((cs) => {
17969
+ return new ContextSync(cs.contextId, cs.path, cs.policy);
17970
+ });
17971
+ }
17972
+ if (copied.browserContext) {
17973
+ const bc = copied.browserContext;
17974
+ copied.browserContext = {
17975
+ contextId: bc.contextId,
17976
+ autoUpload: bc.autoUpload,
17977
+ fingerprintContext: bc.fingerprintContext,
17978
+ fingerprintContextId: bc.fingerprintContextId,
17979
+ fingerprintContextSync: bc.fingerprintContextSync ? new ContextSync(
17980
+ bc.fingerprintContextSync.contextId,
17981
+ bc.fingerprintContextSync.path,
17982
+ bc.fingerprintContextSync.policy
17983
+ ) : void 0,
17984
+ extensionOption: bc.extensionOption,
17985
+ extensionContextId: bc.extensionContextId,
17986
+ extensionIds: bc.extensionIds ? [...bc.extensionIds] : void 0,
17987
+ extensionContextSyncs: bc.extensionContextSyncs ? bc.extensionContextSyncs.map(
17988
+ (cs) => new ContextSync(cs.contextId, cs.path, cs.policy)
17989
+ ) : void 0
17990
+ };
17991
+ }
17992
+ return copied;
17993
+ }
17959
17994
  };
17960
17995
  _chunk4IPTHWLMcjs.__name.call(void 0, _AgentBay, "AgentBay");
17961
17996
  var AgentBay = _AgentBay;
@@ -18929,7 +18964,7 @@ var _CreateSessionParams = class _CreateSessionParams {
18929
18964
  this.labels = {};
18930
18965
  this.contextSync = [];
18931
18966
  this.isVpc = false;
18932
- this.enableBrowserReplay = void 0;
18967
+ this.enableBrowserReplay = true;
18933
18968
  }
18934
18969
  /**
18935
18970
  * WithLabels sets the labels for the session parameters and returns the updated parameters.