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.d.mts CHANGED
@@ -6836,7 +6836,7 @@ interface CreateSessionParamsConfig {
6836
6836
  isVpc?: boolean;
6837
6837
  /** Policy id to apply when creating the session. */
6838
6838
  policyId?: string;
6839
- /** Whether to enable browser recording for the session. Defaults to false. */
6839
+ /** Whether to enable browser recording for the session. Defaults to true. */
6840
6840
  enableBrowserReplay?: boolean;
6841
6841
  /** Extra configuration settings for different session types (e.g., mobile) */
6842
6842
  extraConfigs?: ExtraConfigs;
@@ -6863,7 +6863,7 @@ declare class CreateSessionParams implements CreateSessionParamsConfig {
6863
6863
  isVpc: boolean;
6864
6864
  /** Policy id to apply when creating the session. */
6865
6865
  policyId?: string;
6866
- /** Whether to enable browser recording for the session. Defaults to undefined (use default behavior, enabled by default). */
6866
+ /** Whether to enable browser recording for the session. Defaults to true. */
6867
6867
  enableBrowserReplay?: boolean;
6868
6868
  /** Extra configuration settings for different session types (e.g., mobile) */
6869
6869
  extraConfigs?: ExtraConfigs;
@@ -7222,6 +7222,12 @@ declare class AgentBay {
7222
7222
  * @see {@link pauseAsync}, {@link Session.resumeAsync}
7223
7223
  */
7224
7224
  resumeAsync(session: Session, timeout?: number, pollInterval?: number): Promise<SessionResumeResult>;
7225
+ /**
7226
+ * Creates a deep copy of CreateSessionParams to avoid modifying the original object.
7227
+ * @param params - The original params object to copy
7228
+ * @returns A deep copy of the params object
7229
+ */
7230
+ private deepCopyParams;
7225
7231
  }
7226
7232
 
7227
7233
  /**
package/dist/index.d.ts CHANGED
@@ -6836,7 +6836,7 @@ interface CreateSessionParamsConfig {
6836
6836
  isVpc?: boolean;
6837
6837
  /** Policy id to apply when creating the session. */
6838
6838
  policyId?: string;
6839
- /** Whether to enable browser recording for the session. Defaults to false. */
6839
+ /** Whether to enable browser recording for the session. Defaults to true. */
6840
6840
  enableBrowserReplay?: boolean;
6841
6841
  /** Extra configuration settings for different session types (e.g., mobile) */
6842
6842
  extraConfigs?: ExtraConfigs;
@@ -6863,7 +6863,7 @@ declare class CreateSessionParams implements CreateSessionParamsConfig {
6863
6863
  isVpc: boolean;
6864
6864
  /** Policy id to apply when creating the session. */
6865
6865
  policyId?: string;
6866
- /** Whether to enable browser recording for the session. Defaults to undefined (use default behavior, enabled by default). */
6866
+ /** Whether to enable browser recording for the session. Defaults to true. */
6867
6867
  enableBrowserReplay?: boolean;
6868
6868
  /** Extra configuration settings for different session types (e.g., mobile) */
6869
6869
  extraConfigs?: ExtraConfigs;
@@ -7222,6 +7222,12 @@ declare class AgentBay {
7222
7222
  * @see {@link pauseAsync}, {@link Session.resumeAsync}
7223
7223
  */
7224
7224
  resumeAsync(session: Session, timeout?: number, pollInterval?: number): Promise<SessionResumeResult>;
7225
+ /**
7226
+ * Creates a deep copy of CreateSessionParams to avoid modifying the original object.
7227
+ * @param params - The original params object to copy
7228
+ * @returns A deep copy of the params object
7229
+ */
7230
+ private deepCopyParams;
7225
7231
  }
7226
7232
 
7227
7233
  /**
package/dist/index.mjs CHANGED
@@ -566,7 +566,7 @@ function getVersionFromPackageJson() {
566
566
  }
567
567
  } catch (error) {
568
568
  }
569
- return "0.13.0";
569
+ return "0.13.1";
570
570
  }
571
571
  __name(getVersionFromPackageJson, "getVersionFromPackageJson");
572
572
  function isReleaseBuild() {
@@ -17244,50 +17244,51 @@ var _AgentBay = class _AgentBay {
17244
17244
  */
17245
17245
  async create(params) {
17246
17246
  try {
17247
- logDebug(`default context syncs length: ${params.contextSync?.length}`);
17248
- if (params.extraConfigs?.mobile?.simulateConfig) {
17249
- const mobileSimContextId = params.extraConfigs.mobile.simulateConfig.simulatedContextId;
17247
+ const paramsCopy = this.deepCopyParams(params);
17248
+ logDebug(`default context syncs length: ${paramsCopy.contextSync?.length}`);
17249
+ if (paramsCopy.extraConfigs?.mobile?.simulateConfig) {
17250
+ const mobileSimContextId = paramsCopy.extraConfigs.mobile.simulateConfig.simulatedContextId;
17250
17251
  if (mobileSimContextId) {
17251
17252
  const mobileSimContextSync = new ContextSync(
17252
17253
  mobileSimContextId,
17253
17254
  "/data/agentbay_mobile_info"
17254
17255
  );
17255
- if (!params.contextSync) {
17256
- params.contextSync = [];
17256
+ if (!paramsCopy.contextSync) {
17257
+ paramsCopy.contextSync = [];
17257
17258
  }
17258
17259
  logInfo(`Adding context sync for mobile simulate: ${JSON.stringify(mobileSimContextSync)}`);
17259
- params.contextSync.push(mobileSimContextSync);
17260
+ paramsCopy.contextSync.push(mobileSimContextSync);
17260
17261
  }
17261
17262
  }
17262
17263
  const request = new CreateMcpSessionRequest({
17263
17264
  authorization: "Bearer " + this.apiKey
17264
17265
  });
17265
- if (params.enableBrowserReplay === false) {
17266
+ if (paramsCopy.enableBrowserReplay === false) {
17266
17267
  request.enableRecord = false;
17267
17268
  }
17268
- const framework = params?.framework || "";
17269
+ const framework = paramsCopy?.framework || "";
17269
17270
  const sdkStatsJson = `{"source":"sdk","sdk_language":"typescript","sdk_version":"${VERSION}","is_release":${IS_RELEASE},"framework":"${framework}"}`;
17270
17271
  request.sdkStats = sdkStatsJson;
17271
17272
  if (this.config.region_id) {
17272
17273
  request.loginRegionId = this.config.region_id;
17273
17274
  }
17274
- if (params.labels) {
17275
- request.labels = JSON.stringify(params.labels);
17275
+ if (paramsCopy.labels) {
17276
+ request.labels = JSON.stringify(paramsCopy.labels);
17276
17277
  }
17277
- if (params.imageId) {
17278
- request.imageId = params.imageId;
17278
+ if (paramsCopy.imageId) {
17279
+ request.imageId = paramsCopy.imageId;
17279
17280
  }
17280
- if (params.policyId) {
17281
- request.mcpPolicyId = params.policyId;
17281
+ if (paramsCopy.policyId) {
17282
+ request.mcpPolicyId = paramsCopy.policyId;
17282
17283
  }
17283
- request.vpcResource = params.isVpc || false;
17284
+ request.vpcResource = paramsCopy.isVpc || false;
17284
17285
  let needsContextSync = false;
17285
17286
  let needsMobileSim = false;
17286
17287
  let mobileSimMode = void 0;
17287
17288
  let mobileSimPath = void 0;
17288
- if (params.contextSync && params.contextSync.length > 0) {
17289
+ if (paramsCopy.contextSync && paramsCopy.contextSync.length > 0) {
17289
17290
  const persistenceDataList = [];
17290
- for (const contextSync of params.contextSync) {
17291
+ for (const contextSync of paramsCopy.contextSync) {
17291
17292
  const persistenceItem = new CreateMcpSessionRequestPersistenceDataList({
17292
17293
  contextId: contextSync.contextId,
17293
17294
  path: contextSync.path
@@ -17300,16 +17301,16 @@ var _AgentBay = class _AgentBay {
17300
17301
  request.persistenceDataList = persistenceDataList;
17301
17302
  needsContextSync = persistenceDataList.length > 0;
17302
17303
  }
17303
- if (params.browserContext) {
17304
+ if (paramsCopy.browserContext) {
17304
17305
  const syncPolicy = {
17305
- uploadPolicy: { autoUpload: params.browserContext.autoUpload },
17306
+ uploadPolicy: { autoUpload: paramsCopy.browserContext.autoUpload },
17306
17307
  downloadPolicy: null,
17307
17308
  deletePolicy: null,
17308
17309
  bwList: null,
17309
17310
  recyclePolicy: null
17310
17311
  };
17311
17312
  const browserContextSync = new CreateMcpSessionRequestPersistenceDataList({
17312
- contextId: params.browserContext.contextId,
17313
+ contextId: paramsCopy.browserContext.contextId,
17313
17314
  path: BROWSER_DATA_PATH2,
17314
17315
  // Using a constant path for browser data
17315
17316
  policy: JSON.stringify(syncPolicy)
@@ -17320,24 +17321,24 @@ var _AgentBay = class _AgentBay {
17320
17321
  request.persistenceDataList.push(browserContextSync);
17321
17322
  needsContextSync = true;
17322
17323
  }
17323
- if (params.extraConfigs) {
17324
- request.extraConfigs = JSON.stringify(params.extraConfigs);
17325
- if (params.extraConfigs.mobile?.simulateConfig?.simulate) {
17326
- mobileSimPath = params.extraConfigs.mobile.simulateConfig.simulatePath;
17324
+ if (paramsCopy.extraConfigs) {
17325
+ request.extraConfigs = JSON.stringify(paramsCopy.extraConfigs);
17326
+ if (paramsCopy.extraConfigs.mobile?.simulateConfig?.simulate) {
17327
+ mobileSimPath = paramsCopy.extraConfigs.mobile.simulateConfig.simulatePath;
17327
17328
  if (!mobileSimPath) {
17328
17329
  logInfo("mobile_sim_path is not set now, skip mobile simulate operation");
17329
17330
  } else {
17330
17331
  needsMobileSim = true;
17331
- mobileSimMode = params.extraConfigs.mobile.simulateConfig.simulateMode;
17332
+ mobileSimMode = paramsCopy.extraConfigs.mobile.simulateConfig.simulateMode;
17332
17333
  }
17333
17334
  }
17334
17335
  }
17335
17336
  logAPICall("CreateMcpSession", {
17336
- labels: params.labels,
17337
- imageId: params.imageId,
17338
- policyId: params.policyId,
17339
- isVpc: params.isVpc,
17340
- persistenceDataCount: params.contextSync ? params.contextSync.length : 0
17337
+ labels: paramsCopy.labels,
17338
+ imageId: paramsCopy.imageId,
17339
+ policyId: paramsCopy.policyId,
17340
+ isVpc: paramsCopy.isVpc,
17341
+ persistenceDataCount: paramsCopy.contextSync ? paramsCopy.contextSync.length : 0
17341
17342
  });
17342
17343
  const response = await this.client.createMcpSession(request);
17343
17344
  const requestId = extractRequestId(response) || "";
@@ -17433,7 +17434,7 @@ var _AgentBay = class _AgentBay {
17433
17434
  }
17434
17435
  );
17435
17436
  const session = new Session(this, sessionId);
17436
- session.isVpc = params.isVpc || false;
17437
+ session.isVpc = paramsCopy.isVpc || false;
17437
17438
  if (data.networkInterfaceIp) {
17438
17439
  session.networkInterfaceIp = data.networkInterfaceIp;
17439
17440
  }
@@ -17444,12 +17445,12 @@ var _AgentBay = class _AgentBay {
17444
17445
  session.token = data.token;
17445
17446
  }
17446
17447
  session.resourceUrl = resourceUrl;
17447
- session.enableBrowserReplay = params.enableBrowserReplay || false;
17448
- session.imageId = params.imageId;
17449
- if (params.extraConfigs && params.extraConfigs.mobile) {
17448
+ session.enableBrowserReplay = paramsCopy.enableBrowserReplay || false;
17449
+ session.imageId = paramsCopy.imageId;
17450
+ if (paramsCopy.extraConfigs && paramsCopy.extraConfigs.mobile) {
17450
17451
  log("Applying mobile configuration...");
17451
17452
  try {
17452
- const configResult = await session.mobile.configure(params.extraConfigs.mobile);
17453
+ const configResult = await session.mobile.configure(paramsCopy.extraConfigs.mobile);
17453
17454
  if (configResult.success) {
17454
17455
  log("Mobile configuration applied successfully");
17455
17456
  } else {
@@ -17459,7 +17460,7 @@ var _AgentBay = class _AgentBay {
17459
17460
  logError(`Warning: Failed to apply mobile configuration: ${error}`);
17460
17461
  }
17461
17462
  }
17462
- if (params.isVpc) {
17463
+ if (paramsCopy.isVpc) {
17463
17464
  logDebug("VPC session detected, automatically fetching MCP tools...");
17464
17465
  try {
17465
17466
  const toolsResult = await session.listMcpTools();
@@ -17970,6 +17971,40 @@ var _AgentBay = class _AgentBay {
17970
17971
  };
17971
17972
  }
17972
17973
  }
17974
+ /**
17975
+ * Creates a deep copy of CreateSessionParams to avoid modifying the original object.
17976
+ * @param params - The original params object to copy
17977
+ * @returns A deep copy of the params object
17978
+ */
17979
+ deepCopyParams(params) {
17980
+ const copied = JSON.parse(JSON.stringify(params));
17981
+ if (copied.contextSync && Array.isArray(copied.contextSync)) {
17982
+ copied.contextSync = copied.contextSync.map((cs) => {
17983
+ return new ContextSync(cs.contextId, cs.path, cs.policy);
17984
+ });
17985
+ }
17986
+ if (copied.browserContext) {
17987
+ const bc = copied.browserContext;
17988
+ copied.browserContext = {
17989
+ contextId: bc.contextId,
17990
+ autoUpload: bc.autoUpload,
17991
+ fingerprintContext: bc.fingerprintContext,
17992
+ fingerprintContextId: bc.fingerprintContextId,
17993
+ fingerprintContextSync: bc.fingerprintContextSync ? new ContextSync(
17994
+ bc.fingerprintContextSync.contextId,
17995
+ bc.fingerprintContextSync.path,
17996
+ bc.fingerprintContextSync.policy
17997
+ ) : void 0,
17998
+ extensionOption: bc.extensionOption,
17999
+ extensionContextId: bc.extensionContextId,
18000
+ extensionIds: bc.extensionIds ? [...bc.extensionIds] : void 0,
18001
+ extensionContextSyncs: bc.extensionContextSyncs ? bc.extensionContextSyncs.map(
18002
+ (cs) => new ContextSync(cs.contextId, cs.path, cs.policy)
18003
+ ) : void 0
18004
+ };
18005
+ }
18006
+ return copied;
18007
+ }
17973
18008
  };
17974
18009
  __name(_AgentBay, "AgentBay");
17975
18010
  var AgentBay = _AgentBay;
@@ -18943,7 +18978,7 @@ var _CreateSessionParams = class _CreateSessionParams {
18943
18978
  this.labels = {};
18944
18979
  this.contextSync = [];
18945
18980
  this.isVpc = false;
18946
- this.enableBrowserReplay = void 0;
18981
+ this.enableBrowserReplay = true;
18947
18982
  }
18948
18983
  /**
18949
18984
  * WithLabels sets the labels for the session parameters and returns the updated parameters.