test-wuying-agentbay-sdk 0.13.1-beta.20251224094729 → 0.13.1-beta.20251224100120

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
@@ -14308,43 +14308,107 @@ var _FileSystem = class _FileSystem {
14308
14308
  * @param path - Path to the file to read.
14309
14309
  * @param offset - Optional: Byte offset to start reading from (0-based).
14310
14310
  * @param length - Optional: Number of bytes to read. If 0, reads the entire file from offset.
14311
- * @returns FileContentResult with file content and requestId
14311
+ * @param formatType - Optional: Format to read the file in. "text" (default) or "binary".
14312
+ * @returns FileContentResult for text format, BinaryFileContentResult for binary format
14312
14313
  */
14313
- async readFileChunk(path6, offset = 0, length = 0) {
14314
+ async readFileChunk(path6, offset = 0, length = 0, formatType = "text") {
14314
14315
  try {
14315
14316
  const args = {
14316
14317
  path: path6
14317
14318
  };
14318
- if (offset > 0) {
14319
+ if (offset >= 0) {
14319
14320
  args.offset = offset;
14320
14321
  }
14321
- if (length > 0) {
14322
+ if (length >= 0) {
14322
14323
  args.length = length;
14323
14324
  }
14325
+ if (formatType === "binary") {
14326
+ args.format = "binary";
14327
+ }
14324
14328
  const result = await this.session.callMcpTool(
14325
14329
  "read_file",
14326
14330
  args
14327
14331
  );
14328
14332
  if (!result.success) {
14333
+ if (formatType === "binary") {
14334
+ return {
14335
+ requestId: result.requestId,
14336
+ success: false,
14337
+ content: new Uint8Array(0),
14338
+ errorMessage: result.errorMessage
14339
+ };
14340
+ } else {
14341
+ return {
14342
+ requestId: result.requestId,
14343
+ success: false,
14344
+ content: "",
14345
+ errorMessage: result.errorMessage
14346
+ };
14347
+ }
14348
+ }
14349
+ if (formatType === "binary") {
14350
+ try {
14351
+ if (typeof Buffer !== "undefined") {
14352
+ const base64String = result.data || "";
14353
+ if (base64String) {
14354
+ const base64WithoutPadding = base64String.replace(/=+$/, "");
14355
+ if (!/^[A-Za-z0-9+/]+$/.test(base64WithoutPadding)) {
14356
+ throw new Error("Invalid base64 string format");
14357
+ }
14358
+ const paddingMatch = base64String.match(/=+$/);
14359
+ if (paddingMatch && paddingMatch[0].length > 2) {
14360
+ throw new Error("Invalid base64 padding format");
14361
+ }
14362
+ }
14363
+ const binaryContent = Buffer.from(base64String, "base64");
14364
+ return {
14365
+ requestId: result.requestId,
14366
+ success: true,
14367
+ content: new Uint8Array(binaryContent)
14368
+ };
14369
+ } else {
14370
+ const binaryString = atob(result.data || "");
14371
+ const binaryContent = new Uint8Array(binaryString.length);
14372
+ for (let i = 0; i < binaryString.length; i++) {
14373
+ binaryContent[i] = binaryString.charCodeAt(i);
14374
+ }
14375
+ return {
14376
+ requestId: result.requestId,
14377
+ success: true,
14378
+ content: binaryContent
14379
+ };
14380
+ }
14381
+ } catch (e) {
14382
+ return {
14383
+ requestId: result.requestId,
14384
+ success: false,
14385
+ content: new Uint8Array(0),
14386
+ errorMessage: `Failed to decode base64: ${e}`
14387
+ };
14388
+ }
14389
+ } else {
14329
14390
  return {
14330
14391
  requestId: result.requestId,
14392
+ success: true,
14393
+ content: result.data || ""
14394
+ };
14395
+ }
14396
+ } catch (error) {
14397
+ if (formatType === "binary") {
14398
+ return {
14399
+ requestId: "",
14400
+ success: false,
14401
+ content: new Uint8Array(0),
14402
+ errorMessage: `Failed to read file: ${error}`
14403
+ };
14404
+ } else {
14405
+ return {
14406
+ requestId: "",
14331
14407
  success: false,
14332
14408
  content: "",
14333
- errorMessage: result.errorMessage
14409
+ errorMessage: `Failed to read file: ${error}`
14334
14410
  };
14335
14411
  }
14336
- return {
14337
- requestId: result.requestId,
14338
- success: true,
14339
- content: result.data || ""
14340
- };
14341
- } catch (error) {
14342
- return {
14343
- requestId: "",
14344
- success: false,
14345
- content: "",
14346
- errorMessage: `Failed to read file: ${error}`
14347
- };
14348
14412
  }
14349
14413
  }
14350
14414
  /**
@@ -14542,120 +14606,178 @@ var _FileSystem = class _FileSystem {
14542
14606
  };
14543
14607
  }
14544
14608
  }
14545
- /**
14546
- * Reads the contents of a file. Automatically handles large files by chunking.
14547
- *
14548
- * @param path - Path to the file to read.
14549
- * @returns FileContentResult with complete file content and requestId
14550
- */
14551
- /**
14552
- * Reads the entire content of a file.
14553
- *
14554
- * @param path - Absolute path to the file to read.
14555
- *
14556
- * @returns Promise resolving to FileContentResult containing:
14557
- * - success: Whether the read operation succeeded
14558
- * - content: String content of the file
14559
- * - requestId: Unique identifier for this API request
14560
- * - errorMessage: Error description if read failed
14561
- *
14562
- * @throws Error if the API call fails.
14563
- *
14564
- * @example
14565
- * ```typescript
14566
- * import { AgentBay } from 'wuying-agentbay-sdk';
14567
- *
14568
- * const agentBay = new AgentBay({ apiKey: 'your_api_key' });
14569
- * const result = await agentBay.create();
14570
- *
14571
- * if (result.success) {
14572
- * const session = result.session;
14573
- *
14574
- * // Read a text file
14575
- * const fileResult = await session.fileSystem.readFile('/etc/hostname');
14576
- * if (fileResult.success) {
14577
- * console.log(`Content: ${fileResult.content}`);
14578
- * // Output: Content: agentbay-session-xyz
14579
- * }
14580
- *
14581
- * await session.delete();
14582
- * }
14583
- * ```
14584
- *
14585
- * @remarks
14586
- * **Behavior:**
14587
- * - Automatically handles large files by reading in 60KB chunks
14588
- * - Returns empty string for empty files
14589
- * - Fails if path is a directory or doesn't exist
14590
- * - Content is returned as UTF-8 string
14591
- *
14592
- * @see {@link writeFile}, {@link listDirectory}
14593
- */
14594
- async readFile(path6) {
14609
+ async readFile(path6, opts) {
14610
+ const format = _optionalChain([opts, 'optionalAccess', _157 => _157.format]) || "text";
14595
14611
  const chunkSize = DEFAULT_CHUNK_SIZE;
14596
14612
  try {
14597
14613
  const fileInfoResult = await this.getFileInfo(path6);
14598
14614
  if (!fileInfoResult.success) {
14599
- return {
14600
- requestId: fileInfoResult.requestId,
14601
- success: false,
14602
- content: "",
14603
- errorMessage: fileInfoResult.errorMessage
14604
- };
14615
+ if (format === "bytes") {
14616
+ return {
14617
+ requestId: fileInfoResult.requestId,
14618
+ success: false,
14619
+ content: new Uint8Array(0),
14620
+ errorMessage: fileInfoResult.errorMessage
14621
+ };
14622
+ } else {
14623
+ return {
14624
+ requestId: fileInfoResult.requestId,
14625
+ success: false,
14626
+ content: "",
14627
+ errorMessage: fileInfoResult.errorMessage
14628
+ };
14629
+ }
14605
14630
  }
14606
14631
  if (!fileInfoResult.fileInfo || fileInfoResult.fileInfo.isDirectory) {
14607
- return {
14608
- requestId: fileInfoResult.requestId,
14609
- success: false,
14610
- content: "",
14611
- errorMessage: `Path does not exist or is a directory: ${path6}`
14612
- };
14632
+ const errorMsg = `Path does not exist or is a directory: ${path6}`;
14633
+ if (format === "bytes") {
14634
+ return {
14635
+ requestId: fileInfoResult.requestId,
14636
+ success: false,
14637
+ content: new Uint8Array(0),
14638
+ errorMessage: errorMsg
14639
+ };
14640
+ } else {
14641
+ return {
14642
+ requestId: fileInfoResult.requestId,
14643
+ success: false,
14644
+ content: "",
14645
+ errorMessage: errorMsg
14646
+ };
14647
+ }
14613
14648
  }
14614
14649
  const fileSize = fileInfoResult.fileInfo.size || 0;
14615
14650
  if (fileSize === 0) {
14651
+ if (format === "bytes") {
14652
+ return {
14653
+ requestId: fileInfoResult.requestId,
14654
+ success: true,
14655
+ content: new Uint8Array(0),
14656
+ size: 0
14657
+ };
14658
+ } else {
14659
+ return {
14660
+ requestId: fileInfoResult.requestId,
14661
+ success: true,
14662
+ content: ""
14663
+ };
14664
+ }
14665
+ }
14666
+ if (format === "bytes") {
14667
+ const contentChunks = [];
14668
+ let offset = 0;
14669
+ let chunkCount = 0;
14670
+ while (offset < fileSize) {
14671
+ let length = chunkSize;
14672
+ if (offset + length > fileSize) {
14673
+ length = fileSize - offset;
14674
+ }
14675
+ try {
14676
+ const chunkResult = await this.readFileChunk(
14677
+ path6,
14678
+ offset,
14679
+ length,
14680
+ "binary"
14681
+ );
14682
+ if (!chunkResult.success) {
14683
+ return chunkResult;
14684
+ }
14685
+ if ("content" in chunkResult && chunkResult.content instanceof Uint8Array) {
14686
+ contentChunks.push(chunkResult.content);
14687
+ } else {
14688
+ return {
14689
+ requestId: chunkResult.requestId,
14690
+ success: false,
14691
+ content: new Uint8Array(0),
14692
+ errorMessage: "Unexpected result type for binary format"
14693
+ };
14694
+ }
14695
+ offset += length;
14696
+ chunkCount++;
14697
+ } catch (error) {
14698
+ return {
14699
+ requestId: fileInfoResult.requestId,
14700
+ success: false,
14701
+ content: new Uint8Array(0),
14702
+ errorMessage: `Error reading chunk at offset ${offset}: ${error}`
14703
+ };
14704
+ }
14705
+ }
14706
+ const totalLength = contentChunks.reduce((sum, chunk) => sum + chunk.length, 0);
14707
+ const finalContent = new Uint8Array(totalLength);
14708
+ let position = 0;
14709
+ for (const chunk of contentChunks) {
14710
+ finalContent.set(chunk, position);
14711
+ position += chunk.length;
14712
+ }
14616
14713
  return {
14617
14714
  requestId: fileInfoResult.requestId,
14618
14715
  success: true,
14619
- content: ""
14716
+ content: finalContent,
14717
+ size: finalContent.length
14620
14718
  };
14621
- }
14622
- let result = "";
14623
- let offset = 0;
14624
- let chunkCount = 0;
14625
- while (offset < fileSize) {
14626
- let length = chunkSize;
14627
- if (offset + length > fileSize) {
14628
- length = fileSize - offset;
14629
- }
14630
- try {
14631
- const chunkResult = await this.readFileChunk(path6, offset, length);
14632
- if (!chunkResult.success) {
14633
- return chunkResult;
14719
+ } else {
14720
+ let result = "";
14721
+ let offset = 0;
14722
+ let chunkCount = 0;
14723
+ while (offset < fileSize) {
14724
+ let length = chunkSize;
14725
+ if (offset + length > fileSize) {
14726
+ length = fileSize - offset;
14727
+ }
14728
+ try {
14729
+ const chunkResult = await this.readFileChunk(
14730
+ path6,
14731
+ offset,
14732
+ length,
14733
+ "text"
14734
+ );
14735
+ if (!chunkResult.success) {
14736
+ return chunkResult;
14737
+ }
14738
+ if ("content" in chunkResult && typeof chunkResult.content === "string") {
14739
+ result += chunkResult.content;
14740
+ } else {
14741
+ return {
14742
+ requestId: chunkResult.requestId,
14743
+ success: false,
14744
+ content: "",
14745
+ errorMessage: "Unexpected result type for text format"
14746
+ };
14747
+ }
14748
+ offset += length;
14749
+ chunkCount++;
14750
+ } catch (error) {
14751
+ return {
14752
+ requestId: fileInfoResult.requestId,
14753
+ success: false,
14754
+ content: "",
14755
+ errorMessage: `Error reading chunk at offset ${offset}: ${error}`
14756
+ };
14634
14757
  }
14635
- result += chunkResult.content;
14636
- offset += length;
14637
- chunkCount++;
14638
- } catch (error) {
14639
- return {
14640
- requestId: fileInfoResult.requestId,
14641
- success: false,
14642
- content: "",
14643
- errorMessage: `Error reading chunk at offset ${offset}: ${error}`
14644
- };
14645
14758
  }
14759
+ return {
14760
+ requestId: fileInfoResult.requestId,
14761
+ success: true,
14762
+ content: result
14763
+ };
14646
14764
  }
14647
- return {
14648
- requestId: fileInfoResult.requestId,
14649
- success: true,
14650
- content: result
14651
- };
14652
14765
  } catch (error) {
14653
- return {
14654
- requestId: "",
14655
- success: false,
14656
- content: "",
14657
- errorMessage: `Failed to read large file: ${error}`
14658
- };
14766
+ if (format === "bytes") {
14767
+ return {
14768
+ requestId: "",
14769
+ success: false,
14770
+ content: new Uint8Array(0),
14771
+ errorMessage: `Failed to read large file: ${error}`
14772
+ };
14773
+ } else {
14774
+ return {
14775
+ requestId: "",
14776
+ success: false,
14777
+ content: "",
14778
+ errorMessage: `Failed to read large file: ${error}`
14779
+ };
14780
+ }
14659
14781
  }
14660
14782
  }
14661
14783
  /**
@@ -14852,7 +14974,7 @@ var _FileSystem = class _FileSystem {
14852
14974
  console.log(`Starting directory monitoring for: ${path6}`);
14853
14975
  console.log(`Polling interval: ${interval} ms`);
14854
14976
  const monitor = /* @__PURE__ */ _chunk4IPTHWLMcjs.__name.call(void 0, async () => {
14855
- while (!_optionalChain([signal, 'optionalAccess', _157 => _157.aborted])) {
14977
+ while (!_optionalChain([signal, 'optionalAccess', _158 => _158.aborted])) {
14856
14978
  try {
14857
14979
  if (this.session._isExpired && this.session._isExpired()) {
14858
14980
  console.log(`Session expired, stopping directory monitoring for: ${path6}`);
@@ -14879,7 +15001,7 @@ var _FileSystem = class _FileSystem {
14879
15001
  }
14880
15002
  await new Promise((resolve2) => {
14881
15003
  const timeoutId = setTimeout(resolve2, interval);
14882
- _optionalChain([signal, 'optionalAccess', _158 => _158.addEventListener, 'call', _159 => _159("abort", () => {
15004
+ _optionalChain([signal, 'optionalAccess', _159 => _159.addEventListener, 'call', _160 => _160("abort", () => {
14883
15005
  clearTimeout(timeoutId);
14884
15006
  resolve2(void 0);
14885
15007
  })]);
@@ -15501,8 +15623,8 @@ var _Mobile = class _Mobile {
15501
15623
  url: adbUrl
15502
15624
  };
15503
15625
  } else {
15504
- const errorMsg = _optionalChain([response, 'access', _160 => _160.body, 'optionalAccess', _161 => _161.message]) || "Unknown error";
15505
- const requestId = _optionalChain([response, 'access', _162 => _162.body, 'optionalAccess', _163 => _163.requestId]) || "";
15626
+ const errorMsg = _optionalChain([response, 'access', _161 => _161.body, 'optionalAccess', _162 => _162.message]) || "Unknown error";
15627
+ const requestId = _optionalChain([response, 'access', _163 => _163.body, 'optionalAccess', _164 => _164.requestId]) || "";
15506
15628
  logError(`\u274C Failed to get ADB URL: ${errorMsg}`);
15507
15629
  return {
15508
15630
  success: false,
@@ -15774,11 +15896,11 @@ var _Mobile = class _Mobile {
15774
15896
  errorMessage: ""
15775
15897
  };
15776
15898
  } else {
15777
- const errorMessage = _optionalChain([result, 'optionalAccess', _164 => _164.errorMessage]) || `Failed to execute ${description}`;
15899
+ const errorMessage = _optionalChain([result, 'optionalAccess', _165 => _165.errorMessage]) || `Failed to execute ${description}`;
15778
15900
  logError(`Failed to execute ${description}: ${errorMessage}`);
15779
15901
  return {
15780
15902
  success: false,
15781
- requestId: _optionalChain([result, 'optionalAccess', _165 => _165.requestId]) || "",
15903
+ requestId: _optionalChain([result, 'optionalAccess', _166 => _166.requestId]) || "",
15782
15904
  errorMessage
15783
15905
  };
15784
15906
  }
@@ -16309,9 +16431,9 @@ var _Session = class _Session {
16309
16431
  );
16310
16432
  const requestId = extractRequestId(response) || "";
16311
16433
  const responseBody = response.body;
16312
- const success = _optionalChain([responseBody, 'optionalAccess', _166 => _166.success]) !== false;
16434
+ const success = _optionalChain([responseBody, 'optionalAccess', _167 => _167.success]) !== false;
16313
16435
  if (!success) {
16314
- const errorMessage = `[${_optionalChain([responseBody, 'optionalAccess', _167 => _167.code]) || "Unknown"}] ${_optionalChain([responseBody, 'optionalAccess', _168 => _168.message]) || "Failed to delete session"}`;
16436
+ const errorMessage = `[${_optionalChain([responseBody, 'optionalAccess', _168 => _168.code]) || "Unknown"}] ${_optionalChain([responseBody, 'optionalAccess', _169 => _169.message]) || "Failed to delete session"}`;
16315
16437
  logAPIResponseWithDetails(
16316
16438
  "DeleteSessionAsync",
16317
16439
  requestId,
@@ -16503,9 +16625,9 @@ var _Session = class _Session {
16503
16625
  });
16504
16626
  const response = await this.getClient().getLabel(request);
16505
16627
  const requestId = extractRequestId(response) || "";
16506
- const responseBody = _optionalChain([response, 'optionalAccess', _169 => _169.body]);
16507
- const data = _optionalChain([responseBody, 'optionalAccess', _170 => _170.data]);
16508
- const labelsJSON = _optionalChain([data, 'optionalAccess', _171 => _171.labels]);
16628
+ const responseBody = _optionalChain([response, 'optionalAccess', _170 => _170.body]);
16629
+ const data = _optionalChain([responseBody, 'optionalAccess', _171 => _171.data]);
16630
+ const labelsJSON = _optionalChain([data, 'optionalAccess', _172 => _172.labels]);
16509
16631
  let labels = {};
16510
16632
  if (labelsJSON) {
16511
16633
  labels = JSON.parse(labelsJSON);
@@ -16578,7 +16700,7 @@ var _Session = class _Session {
16578
16700
  logDebug(`Request: SessionId=${this.sessionId}`);
16579
16701
  const response = await this.getClient().getMcpResource(request);
16580
16702
  const requestId = extractRequestId(response) || "";
16581
- if (_optionalChain([response, 'optionalAccess', _172 => _172.body, 'optionalAccess', _173 => _173.success]) === false && _optionalChain([response, 'access', _174 => _174.body, 'optionalAccess', _175 => _175.code])) {
16703
+ if (_optionalChain([response, 'optionalAccess', _173 => _173.body, 'optionalAccess', _174 => _174.success]) === false && _optionalChain([response, 'access', _175 => _175.body, 'optionalAccess', _176 => _176.code])) {
16582
16704
  const errorMessage = `[${response.body.code}] ${response.body.message || "Unknown error"}`;
16583
16705
  const fullResponse2 = response.body ? JSON.stringify(response.body, null, 2) : "";
16584
16706
  logAPIResponseWithDetails(
@@ -16595,15 +16717,15 @@ var _Session = class _Session {
16595
16717
  };
16596
16718
  }
16597
16719
  const responseBody = response.body;
16598
- const data = _optionalChain([responseBody, 'optionalAccess', _176 => _176.data]);
16720
+ const data = _optionalChain([responseBody, 'optionalAccess', _177 => _177.data]);
16599
16721
  const sessionInfo = new SessionInfoClass();
16600
- if (_optionalChain([data, 'optionalAccess', _177 => _177.sessionId])) {
16722
+ if (_optionalChain([data, 'optionalAccess', _178 => _178.sessionId])) {
16601
16723
  sessionInfo.sessionId = data.sessionId;
16602
16724
  }
16603
- if (_optionalChain([data, 'optionalAccess', _178 => _178.resourceUrl])) {
16725
+ if (_optionalChain([data, 'optionalAccess', _179 => _179.resourceUrl])) {
16604
16726
  sessionInfo.resourceUrl = data.resourceUrl;
16605
16727
  }
16606
- if (_optionalChain([data, 'optionalAccess', _179 => _179.desktopInfo])) {
16728
+ if (_optionalChain([data, 'optionalAccess', _180 => _180.desktopInfo])) {
16607
16729
  const desktopInfo = data.desktopInfo;
16608
16730
  if (desktopInfo.appId) {
16609
16731
  sessionInfo.appId = desktopInfo.appId;
@@ -16648,7 +16770,7 @@ var _Session = class _Session {
16648
16770
  };
16649
16771
  } catch (error) {
16650
16772
  const errorStr = String(error);
16651
- const errorCode = _optionalChain([error, 'optionalAccess', _180 => _180.data, 'optionalAccess', _181 => _181.Code]) || _optionalChain([error, 'optionalAccess', _182 => _182.code]) || "";
16773
+ const errorCode = _optionalChain([error, 'optionalAccess', _181 => _181.data, 'optionalAccess', _182 => _182.Code]) || _optionalChain([error, 'optionalAccess', _183 => _183.code]) || "";
16652
16774
  if (errorCode === "InvalidMcpSession.NotFound" || errorStr.includes("NotFound")) {
16653
16775
  logInfoWithColor(`Session not found: ${this.sessionId}`);
16654
16776
  logDebug(`GetMcpResource error details: ${errorStr}`);
@@ -16806,13 +16928,13 @@ var _Session = class _Session {
16806
16928
  });
16807
16929
  const response = await this.agentBay.getClient().getLink(request);
16808
16930
  const requestId = extractRequestId(response) || "";
16809
- const responseBody = _optionalChain([response, 'optionalAccess', _183 => _183.body]);
16931
+ const responseBody = _optionalChain([response, 'optionalAccess', _184 => _184.body]);
16810
16932
  if (typeof responseBody !== "object") {
16811
16933
  throw new Error(
16812
16934
  "Invalid response format: expected a dictionary from response body"
16813
16935
  );
16814
16936
  }
16815
- let data = _optionalChain([responseBody, 'optionalAccess', _184 => _184.data]) || {};
16937
+ let data = _optionalChain([responseBody, 'optionalAccess', _185 => _185.data]) || {};
16816
16938
  logDebug(`Data: ${JSON.stringify(data)}`);
16817
16939
  if (typeof data !== "object") {
16818
16940
  try {
@@ -16868,7 +16990,7 @@ var _Session = class _Session {
16868
16990
  logDebug(`Request: ImageId=${imageId}`);
16869
16991
  const response = await this.getClient().listMcpTools(request);
16870
16992
  const requestId = extractRequestId(response) || "";
16871
- if (_optionalChain([response, 'optionalAccess', _185 => _185.body, 'optionalAccess', _186 => _186.success]) === false && _optionalChain([response, 'access', _187 => _187.body, 'optionalAccess', _188 => _188.code])) {
16993
+ if (_optionalChain([response, 'optionalAccess', _186 => _186.body, 'optionalAccess', _187 => _187.success]) === false && _optionalChain([response, 'access', _188 => _188.body, 'optionalAccess', _189 => _189.code])) {
16872
16994
  const errorMessage = `[${response.body.code}] ${response.body.message || "Unknown error"}`;
16873
16995
  const fullResponse2 = response.body ? JSON.stringify(response.body, null, 2) : "";
16874
16996
  logAPIResponseWithDetails(
@@ -17039,7 +17161,7 @@ var _Session = class _Session {
17039
17161
  autoGenSession
17040
17162
  });
17041
17163
  const response = await this.getClient().callMcpTool(callToolRequest);
17042
- if (!_optionalChain([response, 'access', _189 => _189.body, 'optionalAccess', _190 => _190.data])) {
17164
+ if (!_optionalChain([response, 'access', _190 => _190.body, 'optionalAccess', _191 => _191.data])) {
17043
17165
  return {
17044
17166
  success: false,
17045
17167
  data: "",
@@ -17550,8 +17672,8 @@ var _AgentBay = class _AgentBay {
17550
17672
  async create(params) {
17551
17673
  try {
17552
17674
  const paramsCopy = this.deepCopyParams(params);
17553
- logDebug(`default context syncs length: ${_optionalChain([paramsCopy, 'access', _191 => _191.contextSync, 'optionalAccess', _192 => _192.length])}`);
17554
- if (_optionalChain([paramsCopy, 'access', _193 => _193.extraConfigs, 'optionalAccess', _194 => _194.mobile, 'optionalAccess', _195 => _195.simulateConfig])) {
17675
+ logDebug(`default context syncs length: ${_optionalChain([paramsCopy, 'access', _192 => _192.contextSync, 'optionalAccess', _193 => _193.length])}`);
17676
+ if (_optionalChain([paramsCopy, 'access', _194 => _194.extraConfigs, 'optionalAccess', _195 => _195.mobile, 'optionalAccess', _196 => _196.simulateConfig])) {
17555
17677
  const mobileSimContextId = paramsCopy.extraConfigs.mobile.simulateConfig.simulatedContextId;
17556
17678
  if (mobileSimContextId) {
17557
17679
  const mobileSimContextSync = new ContextSync(
@@ -17571,7 +17693,7 @@ var _AgentBay = class _AgentBay {
17571
17693
  if (paramsCopy.enableBrowserReplay === false) {
17572
17694
  request.enableRecord = false;
17573
17695
  }
17574
- const framework = _optionalChain([paramsCopy, 'optionalAccess', _196 => _196.framework]) || "";
17696
+ const framework = _optionalChain([paramsCopy, 'optionalAccess', _197 => _197.framework]) || "";
17575
17697
  const sdkStatsJson = `{"source":"sdk","sdk_language":"typescript","sdk_version":"${VERSION}","is_release":${IS_RELEASE},"framework":"${framework}"}`;
17576
17698
  request.sdkStats = sdkStatsJson;
17577
17699
  if (this.config.region_id) {
@@ -17628,7 +17750,7 @@ var _AgentBay = class _AgentBay {
17628
17750
  }
17629
17751
  if (paramsCopy.extraConfigs) {
17630
17752
  request.extraConfigs = JSON.stringify(paramsCopy.extraConfigs);
17631
- if (_optionalChain([paramsCopy, 'access', _197 => _197.extraConfigs, 'access', _198 => _198.mobile, 'optionalAccess', _199 => _199.simulateConfig, 'optionalAccess', _200 => _200.simulate])) {
17753
+ if (_optionalChain([paramsCopy, 'access', _198 => _198.extraConfigs, 'access', _199 => _199.mobile, 'optionalAccess', _200 => _200.simulateConfig, 'optionalAccess', _201 => _201.simulate])) {
17632
17754
  mobileSimPath = paramsCopy.extraConfigs.mobile.simulateConfig.simulatePath;
17633
17755
  if (!mobileSimPath) {
17634
17756
  logInfo("mobile_sim_path is not set now, skip mobile simulate operation");
@@ -17871,9 +17993,9 @@ var _AgentBay = class _AgentBay {
17871
17993
  }
17872
17994
  const response2 = await this.client.listSession(request2);
17873
17995
  const requestId2 = extractRequestId(response2) || "";
17874
- if (!_optionalChain([response2, 'access', _201 => _201.body, 'optionalAccess', _202 => _202.success])) {
17875
- const code = _optionalChain([response2, 'access', _203 => _203.body, 'optionalAccess', _204 => _204.code]) || "Unknown";
17876
- const message = _optionalChain([response2, 'access', _205 => _205.body, 'optionalAccess', _206 => _206.message]) || "Unknown error";
17996
+ if (!_optionalChain([response2, 'access', _202 => _202.body, 'optionalAccess', _203 => _203.success])) {
17997
+ const code = _optionalChain([response2, 'access', _204 => _204.body, 'optionalAccess', _205 => _205.code]) || "Unknown";
17998
+ const message = _optionalChain([response2, 'access', _206 => _206.body, 'optionalAccess', _207 => _207.message]) || "Unknown error";
17877
17999
  return {
17878
18000
  requestId: requestId2,
17879
18001
  success: false,
@@ -17915,9 +18037,9 @@ var _AgentBay = class _AgentBay {
17915
18037
  const response = await this.client.listSession(request);
17916
18038
  const requestId = extractRequestId(response) || "";
17917
18039
  setRequestId(requestId);
17918
- if (!_optionalChain([response, 'access', _207 => _207.body, 'optionalAccess', _208 => _208.success])) {
17919
- const code = _optionalChain([response, 'access', _209 => _209.body, 'optionalAccess', _210 => _210.code]) || "Unknown";
17920
- const message = _optionalChain([response, 'access', _211 => _211.body, 'optionalAccess', _212 => _212.message]) || "Unknown error";
18040
+ if (!_optionalChain([response, 'access', _208 => _208.body, 'optionalAccess', _209 => _209.success])) {
18041
+ const code = _optionalChain([response, 'access', _210 => _210.body, 'optionalAccess', _211 => _211.code]) || "Unknown";
18042
+ const message = _optionalChain([response, 'access', _212 => _212.body, 'optionalAccess', _213 => _213.message]) || "Unknown error";
17921
18043
  logAPIResponseWithDetails(
17922
18044
  "ListSession",
17923
18045
  requestId,
@@ -18025,7 +18147,7 @@ var _AgentBay = class _AgentBay {
18025
18147
  const requestId = extractRequestId(response) || "";
18026
18148
  const body = response.body;
18027
18149
  setRequestId(requestId);
18028
- if (_optionalChain([body, 'optionalAccess', _213 => _213.success]) === false && body.code) {
18150
+ if (_optionalChain([body, 'optionalAccess', _214 => _214.success]) === false && body.code) {
18029
18151
  logAPIResponseWithDetails(
18030
18152
  "GetSession",
18031
18153
  requestId,
@@ -18044,12 +18166,12 @@ var _AgentBay = class _AgentBay {
18044
18166
  }
18045
18167
  const result = {
18046
18168
  requestId,
18047
- httpStatusCode: _optionalChain([body, 'optionalAccess', _214 => _214.httpStatusCode]) || 0,
18048
- code: _optionalChain([body, 'optionalAccess', _215 => _215.code]) || "",
18049
- success: _optionalChain([body, 'optionalAccess', _216 => _216.success]) || false,
18169
+ httpStatusCode: _optionalChain([body, 'optionalAccess', _215 => _215.httpStatusCode]) || 0,
18170
+ code: _optionalChain([body, 'optionalAccess', _216 => _216.code]) || "",
18171
+ success: _optionalChain([body, 'optionalAccess', _217 => _217.success]) || false,
18050
18172
  errorMessage: ""
18051
18173
  };
18052
- if (_optionalChain([body, 'optionalAccess', _217 => _217.data])) {
18174
+ if (_optionalChain([body, 'optionalAccess', _218 => _218.data])) {
18053
18175
  const contextsList = body.data.contexts || [];
18054
18176
  const contexts = [];
18055
18177
  if (Array.isArray(contextsList)) {
@@ -18089,7 +18211,7 @@ var _AgentBay = class _AgentBay {
18089
18211
  return result;
18090
18212
  } catch (error) {
18091
18213
  const errorStr = String(error);
18092
- const errorCode = _optionalChain([error, 'optionalAccess', _218 => _218.data, 'optionalAccess', _219 => _219.Code]) || _optionalChain([error, 'optionalAccess', _220 => _220.code]) || "";
18214
+ const errorCode = _optionalChain([error, 'optionalAccess', _219 => _219.data, 'optionalAccess', _220 => _220.Code]) || _optionalChain([error, 'optionalAccess', _221 => _221.code]) || "";
18093
18215
  if (errorCode === "InvalidMcpSession.NotFound" || errorStr.includes("NotFound")) {
18094
18216
  logInfo(`Session not found: ${sessionId}`);
18095
18217
  logDebug(`GetSession error details: ${errorStr}`);
@@ -18127,9 +18249,9 @@ var _AgentBay = class _AgentBay {
18127
18249
  });
18128
18250
  const response = await this.client.getSessionDetail(request);
18129
18251
  const body = response.body;
18130
- const requestId = extractRequestId(response) || _optionalChain([body, 'optionalAccess', _221 => _221.requestId]) || "";
18252
+ const requestId = extractRequestId(response) || _optionalChain([body, 'optionalAccess', _222 => _222.requestId]) || "";
18131
18253
  setRequestId(requestId);
18132
- if (_optionalChain([body, 'optionalAccess', _222 => _222.success]) === false && body.code) {
18254
+ if (_optionalChain([body, 'optionalAccess', _223 => _223.success]) === false && body.code) {
18133
18255
  logAPIResponseWithDetails(
18134
18256
  "GetSessionDetail",
18135
18257
  requestId,
@@ -18151,12 +18273,12 @@ var _AgentBay = class _AgentBay {
18151
18273
  }
18152
18274
  const result = {
18153
18275
  requestId,
18154
- httpStatusCode: _optionalChain([body, 'optionalAccess', _223 => _223.httpStatusCode]) || 0,
18155
- code: _optionalChain([body, 'optionalAccess', _224 => _224.code]) || "",
18156
- success: _optionalChain([body, 'optionalAccess', _225 => _225.success]) || false,
18276
+ httpStatusCode: _optionalChain([body, 'optionalAccess', _224 => _224.httpStatusCode]) || 0,
18277
+ code: _optionalChain([body, 'optionalAccess', _225 => _225.code]) || "",
18278
+ success: _optionalChain([body, 'optionalAccess', _226 => _226.success]) || false,
18157
18279
  errorMessage: ""
18158
18280
  };
18159
- if (_optionalChain([body, 'optionalAccess', _226 => _226.data])) {
18281
+ if (_optionalChain([body, 'optionalAccess', _227 => _227.data])) {
18160
18282
  result.data = {
18161
18283
  aliuid: body.data.aliuid || "",
18162
18284
  apikeyId: body.data.apikeyId || "",
@@ -19143,7 +19265,7 @@ var _MobileSimulateService = class _MobileSimulateService {
19143
19265
  if (!contextSync) {
19144
19266
  throw new Error("contextSync is required for external context");
19145
19267
  }
19146
- if (_optionalChain([contextSync, 'access', _227 => _227.policy, 'optionalAccess', _228 => _228.bwList, 'optionalAccess', _229 => _229.whiteLists])) {
19268
+ if (_optionalChain([contextSync, 'access', _228 => _228.policy, 'optionalAccess', _229 => _229.bwList, 'optionalAccess', _230 => _230.whiteLists])) {
19147
19269
  const exists = contextSync.policy.bwList.whiteLists.some(
19148
19270
  (whiteList) => whiteList.path === MOBILE_INFO_SUB_PATH
19149
19271
  );