test-wuying-agentbay-sdk 0.13.1-beta.20251224091333 → 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
@@ -2311,11 +2311,20 @@ var LOG_LEVEL_VALUES = {
2311
2311
  };
2312
2312
  var currentRequestId = "";
2313
2313
  var currentLogLevel = process.env.LOG_LEVEL || process.env.AGENTBAY_LOG_LEVEL || "INFO";
2314
+ var currentLogFormat = process.env.AGENTBAY_LOG_FORMAT || "pretty";
2315
+ if (["sls", "compact"].includes(String(currentLogFormat).toLowerCase())) {
2316
+ currentLogFormat = "sls";
2317
+ } else {
2318
+ currentLogFormat = "pretty";
2319
+ }
2314
2320
  var fileLoggingEnabled = false;
2315
2321
  var logFilePath = null;
2316
2322
  var logFileMaxSize = 10 * 1024 * 1024;
2317
2323
  var consoleLoggingEnabled = true;
2318
2324
  function shouldUseColors() {
2325
+ if (currentLogFormat === "sls") {
2326
+ return false;
2327
+ }
2319
2328
  if (process.env.DISABLE_COLORS === "true") {
2320
2329
  return false;
2321
2330
  }
@@ -2357,6 +2366,9 @@ var SENSITIVE_FIELDS = [
2357
2366
  "authorization"
2358
2367
  ];
2359
2368
  function getLogLevelEmoji(level) {
2369
+ if (currentLogFormat === "sls") {
2370
+ return level;
2371
+ }
2360
2372
  switch (level) {
2361
2373
  case "DEBUG":
2362
2374
  return "\u{1F41B} DEBUG";
@@ -2376,6 +2388,13 @@ function shouldLog(level) {
2376
2388
  }
2377
2389
  _chunk4IPTHWLMcjs.__name.call(void 0, shouldLog, "shouldLog");
2378
2390
  function formatLogMessage(level, message, forFile = false) {
2391
+ if (currentLogFormat === "sls") {
2392
+ let formattedMessage2 = `${level}: ${message}`;
2393
+ if (currentRequestId) {
2394
+ formattedMessage2 += ` [RequestId=${currentRequestId}]`;
2395
+ }
2396
+ return formattedMessage2;
2397
+ }
2379
2398
  let formattedMessage = `${getLogLevelEmoji(level)}: ${message}`;
2380
2399
  if (currentRequestId) {
2381
2400
  formattedMessage += ` [RequestId=${currentRequestId}]`;
@@ -2523,6 +2542,23 @@ function setupLogger(config) {
2523
2542
  if (config.enableConsole !== void 0) {
2524
2543
  consoleLoggingEnabled = config.enableConsole;
2525
2544
  }
2545
+ if (config.format) {
2546
+ if (["sls", "compact"].includes(String(config.format).toLowerCase())) {
2547
+ currentLogFormat = "sls";
2548
+ } else {
2549
+ currentLogFormat = "pretty";
2550
+ }
2551
+ } else {
2552
+ const envFormat = process.env.AGENTBAY_LOG_FORMAT;
2553
+ if (envFormat) {
2554
+ if (["sls", "compact"].includes(String(envFormat).toLowerCase())) {
2555
+ currentLogFormat = "sls";
2556
+ } else {
2557
+ currentLogFormat = "pretty";
2558
+ }
2559
+ }
2560
+ }
2561
+ useColors = shouldUseColors();
2526
2562
  }
2527
2563
  _chunk4IPTHWLMcjs.__name.call(void 0, setupLogger, "setupLogger");
2528
2564
  function log(message, ...args) {
@@ -2630,6 +2666,22 @@ ${error.stack}`;
2630
2666
  _chunk4IPTHWLMcjs.__name.call(void 0, logError, "logError");
2631
2667
  function logAPICall(apiName, requestData) {
2632
2668
  if (!shouldLog("INFO")) return;
2669
+ if (currentLogFormat === "sls") {
2670
+ let message2 = `API Call: ${apiName}`;
2671
+ if (requestData) {
2672
+ const maskedData = maskSensitiveData(requestData);
2673
+ if (typeof maskedData === "string") {
2674
+ message2 += `, ${maskedData}`;
2675
+ } else {
2676
+ message2 += `, ${JSON.stringify(maskedData)}`;
2677
+ }
2678
+ }
2679
+ if (consoleLoggingEnabled) {
2680
+ process.stdout.write(message2 + "\n");
2681
+ }
2682
+ writeToFile(message2);
2683
+ return;
2684
+ }
2633
2685
  const message = `\u{1F517} API Call: ${apiName}`;
2634
2686
  const savedRequestId = currentRequestId;
2635
2687
  currentRequestId = "";
@@ -2647,6 +2699,35 @@ function logAPICall(apiName, requestData) {
2647
2699
  }
2648
2700
  _chunk4IPTHWLMcjs.__name.call(void 0, logAPICall, "logAPICall");
2649
2701
  function logAPIResponseWithDetails(apiName, requestId, success = true, keyFields, fullResponse) {
2702
+ if (currentLogFormat === "sls") {
2703
+ if (!shouldLog(success ? "INFO" : "ERROR")) return;
2704
+ const status = success ? "API Response" : "API Response Failed";
2705
+ let msg = `${status}: ${apiName}`;
2706
+ if (requestId) {
2707
+ msg += `, RequestId=${requestId}`;
2708
+ }
2709
+ if (keyFields) {
2710
+ for (const [key, value] of Object.entries(keyFields)) {
2711
+ const maskedValue = maskSensitiveData({ [key]: value });
2712
+ msg += `, ${key}=${maskedValue[key]}`;
2713
+ }
2714
+ }
2715
+ if (success) {
2716
+ if (consoleLoggingEnabled) {
2717
+ process.stdout.write(msg + "\n");
2718
+ }
2719
+ writeToFile(msg);
2720
+ } else {
2721
+ if (consoleLoggingEnabled) {
2722
+ process.stderr.write(msg + "\n");
2723
+ }
2724
+ writeToFile(msg);
2725
+ }
2726
+ if (fullResponse && shouldLog("DEBUG")) {
2727
+ logDebug(`Full Response: ${fullResponse}`);
2728
+ }
2729
+ return;
2730
+ }
2650
2731
  if (success) {
2651
2732
  if (shouldLog("INFO")) {
2652
2733
  let mainMessage = `\u2705 API Response: ${apiName}`;
@@ -2718,6 +2799,16 @@ function logCodeExecutionOutput(requestId, rawOutput) {
2718
2799
  return;
2719
2800
  }
2720
2801
  const actualOutput = texts.join("");
2802
+ if (currentLogFormat === "sls") {
2803
+ const header2 = `Code Execution Output (RequestID: ${requestId}):`;
2804
+ if (consoleLoggingEnabled) {
2805
+ process.stdout.write(header2 + "\n");
2806
+ process.stdout.write(actualOutput + "\n");
2807
+ }
2808
+ writeToFile(header2);
2809
+ writeToFile(actualOutput);
2810
+ return;
2811
+ }
2721
2812
  const header = `\u{1F4CB} Code Execution Output (RequestID: ${requestId}):`;
2722
2813
  if (useColors) {
2723
2814
  process.stdout.write(`${ANSI_GREEN}\u2139\uFE0F INFO: ${header}${ANSI_RESET}
@@ -2747,6 +2838,10 @@ function logCodeExecutionOutput(requestId, rawOutput) {
2747
2838
  _chunk4IPTHWLMcjs.__name.call(void 0, logCodeExecutionOutput, "logCodeExecutionOutput");
2748
2839
  function logInfoWithColor(message, color = ANSI_RED) {
2749
2840
  if (!shouldLog("INFO")) return;
2841
+ if (currentLogFormat === "sls") {
2842
+ logInfo(message);
2843
+ return;
2844
+ }
2750
2845
  const emoji = "\u2139\uFE0F INFO";
2751
2846
  const fullMessage = `${emoji}: ${message}`;
2752
2847
  if (useColors) {
@@ -14213,43 +14308,107 @@ var _FileSystem = class _FileSystem {
14213
14308
  * @param path - Path to the file to read.
14214
14309
  * @param offset - Optional: Byte offset to start reading from (0-based).
14215
14310
  * @param length - Optional: Number of bytes to read. If 0, reads the entire file from offset.
14216
- * @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
14217
14313
  */
14218
- async readFileChunk(path6, offset = 0, length = 0) {
14314
+ async readFileChunk(path6, offset = 0, length = 0, formatType = "text") {
14219
14315
  try {
14220
14316
  const args = {
14221
14317
  path: path6
14222
14318
  };
14223
- if (offset > 0) {
14319
+ if (offset >= 0) {
14224
14320
  args.offset = offset;
14225
14321
  }
14226
- if (length > 0) {
14322
+ if (length >= 0) {
14227
14323
  args.length = length;
14228
14324
  }
14325
+ if (formatType === "binary") {
14326
+ args.format = "binary";
14327
+ }
14229
14328
  const result = await this.session.callMcpTool(
14230
14329
  "read_file",
14231
14330
  args
14232
14331
  );
14233
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 {
14234
14390
  return {
14235
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: "",
14236
14407
  success: false,
14237
14408
  content: "",
14238
- errorMessage: result.errorMessage
14409
+ errorMessage: `Failed to read file: ${error}`
14239
14410
  };
14240
14411
  }
14241
- return {
14242
- requestId: result.requestId,
14243
- success: true,
14244
- content: result.data || ""
14245
- };
14246
- } catch (error) {
14247
- return {
14248
- requestId: "",
14249
- success: false,
14250
- content: "",
14251
- errorMessage: `Failed to read file: ${error}`
14252
- };
14253
14412
  }
14254
14413
  }
14255
14414
  /**
@@ -14447,120 +14606,178 @@ var _FileSystem = class _FileSystem {
14447
14606
  };
14448
14607
  }
14449
14608
  }
14450
- /**
14451
- * Reads the contents of a file. Automatically handles large files by chunking.
14452
- *
14453
- * @param path - Path to the file to read.
14454
- * @returns FileContentResult with complete file content and requestId
14455
- */
14456
- /**
14457
- * Reads the entire content of a file.
14458
- *
14459
- * @param path - Absolute path to the file to read.
14460
- *
14461
- * @returns Promise resolving to FileContentResult containing:
14462
- * - success: Whether the read operation succeeded
14463
- * - content: String content of the file
14464
- * - requestId: Unique identifier for this API request
14465
- * - errorMessage: Error description if read failed
14466
- *
14467
- * @throws Error if the API call fails.
14468
- *
14469
- * @example
14470
- * ```typescript
14471
- * import { AgentBay } from 'wuying-agentbay-sdk';
14472
- *
14473
- * const agentBay = new AgentBay({ apiKey: 'your_api_key' });
14474
- * const result = await agentBay.create();
14475
- *
14476
- * if (result.success) {
14477
- * const session = result.session;
14478
- *
14479
- * // Read a text file
14480
- * const fileResult = await session.fileSystem.readFile('/etc/hostname');
14481
- * if (fileResult.success) {
14482
- * console.log(`Content: ${fileResult.content}`);
14483
- * // Output: Content: agentbay-session-xyz
14484
- * }
14485
- *
14486
- * await session.delete();
14487
- * }
14488
- * ```
14489
- *
14490
- * @remarks
14491
- * **Behavior:**
14492
- * - Automatically handles large files by reading in 60KB chunks
14493
- * - Returns empty string for empty files
14494
- * - Fails if path is a directory or doesn't exist
14495
- * - Content is returned as UTF-8 string
14496
- *
14497
- * @see {@link writeFile}, {@link listDirectory}
14498
- */
14499
- async readFile(path6) {
14609
+ async readFile(path6, opts) {
14610
+ const format = _optionalChain([opts, 'optionalAccess', _157 => _157.format]) || "text";
14500
14611
  const chunkSize = DEFAULT_CHUNK_SIZE;
14501
14612
  try {
14502
14613
  const fileInfoResult = await this.getFileInfo(path6);
14503
14614
  if (!fileInfoResult.success) {
14504
- return {
14505
- requestId: fileInfoResult.requestId,
14506
- success: false,
14507
- content: "",
14508
- errorMessage: fileInfoResult.errorMessage
14509
- };
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
+ }
14510
14630
  }
14511
14631
  if (!fileInfoResult.fileInfo || fileInfoResult.fileInfo.isDirectory) {
14512
- return {
14513
- requestId: fileInfoResult.requestId,
14514
- success: false,
14515
- content: "",
14516
- errorMessage: `Path does not exist or is a directory: ${path6}`
14517
- };
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
+ }
14518
14648
  }
14519
14649
  const fileSize = fileInfoResult.fileInfo.size || 0;
14520
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
+ }
14521
14713
  return {
14522
14714
  requestId: fileInfoResult.requestId,
14523
14715
  success: true,
14524
- content: ""
14716
+ content: finalContent,
14717
+ size: finalContent.length
14525
14718
  };
14526
- }
14527
- let result = "";
14528
- let offset = 0;
14529
- let chunkCount = 0;
14530
- while (offset < fileSize) {
14531
- let length = chunkSize;
14532
- if (offset + length > fileSize) {
14533
- length = fileSize - offset;
14534
- }
14535
- try {
14536
- const chunkResult = await this.readFileChunk(path6, offset, length);
14537
- if (!chunkResult.success) {
14538
- 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
+ };
14539
14757
  }
14540
- result += chunkResult.content;
14541
- offset += length;
14542
- chunkCount++;
14543
- } catch (error) {
14544
- return {
14545
- requestId: fileInfoResult.requestId,
14546
- success: false,
14547
- content: "",
14548
- errorMessage: `Error reading chunk at offset ${offset}: ${error}`
14549
- };
14550
14758
  }
14759
+ return {
14760
+ requestId: fileInfoResult.requestId,
14761
+ success: true,
14762
+ content: result
14763
+ };
14551
14764
  }
14552
- return {
14553
- requestId: fileInfoResult.requestId,
14554
- success: true,
14555
- content: result
14556
- };
14557
14765
  } catch (error) {
14558
- return {
14559
- requestId: "",
14560
- success: false,
14561
- content: "",
14562
- errorMessage: `Failed to read large file: ${error}`
14563
- };
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
+ }
14564
14781
  }
14565
14782
  }
14566
14783
  /**
@@ -14757,7 +14974,7 @@ var _FileSystem = class _FileSystem {
14757
14974
  console.log(`Starting directory monitoring for: ${path6}`);
14758
14975
  console.log(`Polling interval: ${interval} ms`);
14759
14976
  const monitor = /* @__PURE__ */ _chunk4IPTHWLMcjs.__name.call(void 0, async () => {
14760
- while (!_optionalChain([signal, 'optionalAccess', _157 => _157.aborted])) {
14977
+ while (!_optionalChain([signal, 'optionalAccess', _158 => _158.aborted])) {
14761
14978
  try {
14762
14979
  if (this.session._isExpired && this.session._isExpired()) {
14763
14980
  console.log(`Session expired, stopping directory monitoring for: ${path6}`);
@@ -14784,7 +15001,7 @@ var _FileSystem = class _FileSystem {
14784
15001
  }
14785
15002
  await new Promise((resolve2) => {
14786
15003
  const timeoutId = setTimeout(resolve2, interval);
14787
- _optionalChain([signal, 'optionalAccess', _158 => _158.addEventListener, 'call', _159 => _159("abort", () => {
15004
+ _optionalChain([signal, 'optionalAccess', _159 => _159.addEventListener, 'call', _160 => _160("abort", () => {
14788
15005
  clearTimeout(timeoutId);
14789
15006
  resolve2(void 0);
14790
15007
  })]);
@@ -15406,8 +15623,8 @@ var _Mobile = class _Mobile {
15406
15623
  url: adbUrl
15407
15624
  };
15408
15625
  } else {
15409
- const errorMsg = _optionalChain([response, 'access', _160 => _160.body, 'optionalAccess', _161 => _161.message]) || "Unknown error";
15410
- 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]) || "";
15411
15628
  logError(`\u274C Failed to get ADB URL: ${errorMsg}`);
15412
15629
  return {
15413
15630
  success: false,
@@ -15679,11 +15896,11 @@ var _Mobile = class _Mobile {
15679
15896
  errorMessage: ""
15680
15897
  };
15681
15898
  } else {
15682
- 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}`;
15683
15900
  logError(`Failed to execute ${description}: ${errorMessage}`);
15684
15901
  return {
15685
15902
  success: false,
15686
- requestId: _optionalChain([result, 'optionalAccess', _165 => _165.requestId]) || "",
15903
+ requestId: _optionalChain([result, 'optionalAccess', _166 => _166.requestId]) || "",
15687
15904
  errorMessage
15688
15905
  };
15689
15906
  }
@@ -16214,9 +16431,9 @@ var _Session = class _Session {
16214
16431
  );
16215
16432
  const requestId = extractRequestId(response) || "";
16216
16433
  const responseBody = response.body;
16217
- const success = _optionalChain([responseBody, 'optionalAccess', _166 => _166.success]) !== false;
16434
+ const success = _optionalChain([responseBody, 'optionalAccess', _167 => _167.success]) !== false;
16218
16435
  if (!success) {
16219
- 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"}`;
16220
16437
  logAPIResponseWithDetails(
16221
16438
  "DeleteSessionAsync",
16222
16439
  requestId,
@@ -16408,9 +16625,9 @@ var _Session = class _Session {
16408
16625
  });
16409
16626
  const response = await this.getClient().getLabel(request);
16410
16627
  const requestId = extractRequestId(response) || "";
16411
- const responseBody = _optionalChain([response, 'optionalAccess', _169 => _169.body]);
16412
- const data = _optionalChain([responseBody, 'optionalAccess', _170 => _170.data]);
16413
- 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]);
16414
16631
  let labels = {};
16415
16632
  if (labelsJSON) {
16416
16633
  labels = JSON.parse(labelsJSON);
@@ -16483,7 +16700,7 @@ var _Session = class _Session {
16483
16700
  logDebug(`Request: SessionId=${this.sessionId}`);
16484
16701
  const response = await this.getClient().getMcpResource(request);
16485
16702
  const requestId = extractRequestId(response) || "";
16486
- 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])) {
16487
16704
  const errorMessage = `[${response.body.code}] ${response.body.message || "Unknown error"}`;
16488
16705
  const fullResponse2 = response.body ? JSON.stringify(response.body, null, 2) : "";
16489
16706
  logAPIResponseWithDetails(
@@ -16500,15 +16717,15 @@ var _Session = class _Session {
16500
16717
  };
16501
16718
  }
16502
16719
  const responseBody = response.body;
16503
- const data = _optionalChain([responseBody, 'optionalAccess', _176 => _176.data]);
16720
+ const data = _optionalChain([responseBody, 'optionalAccess', _177 => _177.data]);
16504
16721
  const sessionInfo = new SessionInfoClass();
16505
- if (_optionalChain([data, 'optionalAccess', _177 => _177.sessionId])) {
16722
+ if (_optionalChain([data, 'optionalAccess', _178 => _178.sessionId])) {
16506
16723
  sessionInfo.sessionId = data.sessionId;
16507
16724
  }
16508
- if (_optionalChain([data, 'optionalAccess', _178 => _178.resourceUrl])) {
16725
+ if (_optionalChain([data, 'optionalAccess', _179 => _179.resourceUrl])) {
16509
16726
  sessionInfo.resourceUrl = data.resourceUrl;
16510
16727
  }
16511
- if (_optionalChain([data, 'optionalAccess', _179 => _179.desktopInfo])) {
16728
+ if (_optionalChain([data, 'optionalAccess', _180 => _180.desktopInfo])) {
16512
16729
  const desktopInfo = data.desktopInfo;
16513
16730
  if (desktopInfo.appId) {
16514
16731
  sessionInfo.appId = desktopInfo.appId;
@@ -16553,7 +16770,7 @@ var _Session = class _Session {
16553
16770
  };
16554
16771
  } catch (error) {
16555
16772
  const errorStr = String(error);
16556
- 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]) || "";
16557
16774
  if (errorCode === "InvalidMcpSession.NotFound" || errorStr.includes("NotFound")) {
16558
16775
  logInfoWithColor(`Session not found: ${this.sessionId}`);
16559
16776
  logDebug(`GetMcpResource error details: ${errorStr}`);
@@ -16711,13 +16928,13 @@ var _Session = class _Session {
16711
16928
  });
16712
16929
  const response = await this.agentBay.getClient().getLink(request);
16713
16930
  const requestId = extractRequestId(response) || "";
16714
- const responseBody = _optionalChain([response, 'optionalAccess', _183 => _183.body]);
16931
+ const responseBody = _optionalChain([response, 'optionalAccess', _184 => _184.body]);
16715
16932
  if (typeof responseBody !== "object") {
16716
16933
  throw new Error(
16717
16934
  "Invalid response format: expected a dictionary from response body"
16718
16935
  );
16719
16936
  }
16720
- let data = _optionalChain([responseBody, 'optionalAccess', _184 => _184.data]) || {};
16937
+ let data = _optionalChain([responseBody, 'optionalAccess', _185 => _185.data]) || {};
16721
16938
  logDebug(`Data: ${JSON.stringify(data)}`);
16722
16939
  if (typeof data !== "object") {
16723
16940
  try {
@@ -16773,7 +16990,7 @@ var _Session = class _Session {
16773
16990
  logDebug(`Request: ImageId=${imageId}`);
16774
16991
  const response = await this.getClient().listMcpTools(request);
16775
16992
  const requestId = extractRequestId(response) || "";
16776
- 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])) {
16777
16994
  const errorMessage = `[${response.body.code}] ${response.body.message || "Unknown error"}`;
16778
16995
  const fullResponse2 = response.body ? JSON.stringify(response.body, null, 2) : "";
16779
16996
  logAPIResponseWithDetails(
@@ -16944,7 +17161,7 @@ var _Session = class _Session {
16944
17161
  autoGenSession
16945
17162
  });
16946
17163
  const response = await this.getClient().callMcpTool(callToolRequest);
16947
- if (!_optionalChain([response, 'access', _189 => _189.body, 'optionalAccess', _190 => _190.data])) {
17164
+ if (!_optionalChain([response, 'access', _190 => _190.body, 'optionalAccess', _191 => _191.data])) {
16948
17165
  return {
16949
17166
  success: false,
16950
17167
  data: "",
@@ -17455,8 +17672,8 @@ var _AgentBay = class _AgentBay {
17455
17672
  async create(params) {
17456
17673
  try {
17457
17674
  const paramsCopy = this.deepCopyParams(params);
17458
- logDebug(`default context syncs length: ${_optionalChain([paramsCopy, 'access', _191 => _191.contextSync, 'optionalAccess', _192 => _192.length])}`);
17459
- 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])) {
17460
17677
  const mobileSimContextId = paramsCopy.extraConfigs.mobile.simulateConfig.simulatedContextId;
17461
17678
  if (mobileSimContextId) {
17462
17679
  const mobileSimContextSync = new ContextSync(
@@ -17476,7 +17693,7 @@ var _AgentBay = class _AgentBay {
17476
17693
  if (paramsCopy.enableBrowserReplay === false) {
17477
17694
  request.enableRecord = false;
17478
17695
  }
17479
- const framework = _optionalChain([paramsCopy, 'optionalAccess', _196 => _196.framework]) || "";
17696
+ const framework = _optionalChain([paramsCopy, 'optionalAccess', _197 => _197.framework]) || "";
17480
17697
  const sdkStatsJson = `{"source":"sdk","sdk_language":"typescript","sdk_version":"${VERSION}","is_release":${IS_RELEASE},"framework":"${framework}"}`;
17481
17698
  request.sdkStats = sdkStatsJson;
17482
17699
  if (this.config.region_id) {
@@ -17533,7 +17750,7 @@ var _AgentBay = class _AgentBay {
17533
17750
  }
17534
17751
  if (paramsCopy.extraConfigs) {
17535
17752
  request.extraConfigs = JSON.stringify(paramsCopy.extraConfigs);
17536
- 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])) {
17537
17754
  mobileSimPath = paramsCopy.extraConfigs.mobile.simulateConfig.simulatePath;
17538
17755
  if (!mobileSimPath) {
17539
17756
  logInfo("mobile_sim_path is not set now, skip mobile simulate operation");
@@ -17776,9 +17993,9 @@ var _AgentBay = class _AgentBay {
17776
17993
  }
17777
17994
  const response2 = await this.client.listSession(request2);
17778
17995
  const requestId2 = extractRequestId(response2) || "";
17779
- if (!_optionalChain([response2, 'access', _201 => _201.body, 'optionalAccess', _202 => _202.success])) {
17780
- const code = _optionalChain([response2, 'access', _203 => _203.body, 'optionalAccess', _204 => _204.code]) || "Unknown";
17781
- 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";
17782
17999
  return {
17783
18000
  requestId: requestId2,
17784
18001
  success: false,
@@ -17820,9 +18037,9 @@ var _AgentBay = class _AgentBay {
17820
18037
  const response = await this.client.listSession(request);
17821
18038
  const requestId = extractRequestId(response) || "";
17822
18039
  setRequestId(requestId);
17823
- if (!_optionalChain([response, 'access', _207 => _207.body, 'optionalAccess', _208 => _208.success])) {
17824
- const code = _optionalChain([response, 'access', _209 => _209.body, 'optionalAccess', _210 => _210.code]) || "Unknown";
17825
- 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";
17826
18043
  logAPIResponseWithDetails(
17827
18044
  "ListSession",
17828
18045
  requestId,
@@ -17930,7 +18147,7 @@ var _AgentBay = class _AgentBay {
17930
18147
  const requestId = extractRequestId(response) || "";
17931
18148
  const body = response.body;
17932
18149
  setRequestId(requestId);
17933
- if (_optionalChain([body, 'optionalAccess', _213 => _213.success]) === false && body.code) {
18150
+ if (_optionalChain([body, 'optionalAccess', _214 => _214.success]) === false && body.code) {
17934
18151
  logAPIResponseWithDetails(
17935
18152
  "GetSession",
17936
18153
  requestId,
@@ -17949,12 +18166,12 @@ var _AgentBay = class _AgentBay {
17949
18166
  }
17950
18167
  const result = {
17951
18168
  requestId,
17952
- httpStatusCode: _optionalChain([body, 'optionalAccess', _214 => _214.httpStatusCode]) || 0,
17953
- code: _optionalChain([body, 'optionalAccess', _215 => _215.code]) || "",
17954
- 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,
17955
18172
  errorMessage: ""
17956
18173
  };
17957
- if (_optionalChain([body, 'optionalAccess', _217 => _217.data])) {
18174
+ if (_optionalChain([body, 'optionalAccess', _218 => _218.data])) {
17958
18175
  const contextsList = body.data.contexts || [];
17959
18176
  const contexts = [];
17960
18177
  if (Array.isArray(contextsList)) {
@@ -17994,7 +18211,7 @@ var _AgentBay = class _AgentBay {
17994
18211
  return result;
17995
18212
  } catch (error) {
17996
18213
  const errorStr = String(error);
17997
- 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]) || "";
17998
18215
  if (errorCode === "InvalidMcpSession.NotFound" || errorStr.includes("NotFound")) {
17999
18216
  logInfo(`Session not found: ${sessionId}`);
18000
18217
  logDebug(`GetSession error details: ${errorStr}`);
@@ -18032,9 +18249,9 @@ var _AgentBay = class _AgentBay {
18032
18249
  });
18033
18250
  const response = await this.client.getSessionDetail(request);
18034
18251
  const body = response.body;
18035
- const requestId = extractRequestId(response) || _optionalChain([body, 'optionalAccess', _221 => _221.requestId]) || "";
18252
+ const requestId = extractRequestId(response) || _optionalChain([body, 'optionalAccess', _222 => _222.requestId]) || "";
18036
18253
  setRequestId(requestId);
18037
- if (_optionalChain([body, 'optionalAccess', _222 => _222.success]) === false && body.code) {
18254
+ if (_optionalChain([body, 'optionalAccess', _223 => _223.success]) === false && body.code) {
18038
18255
  logAPIResponseWithDetails(
18039
18256
  "GetSessionDetail",
18040
18257
  requestId,
@@ -18056,12 +18273,12 @@ var _AgentBay = class _AgentBay {
18056
18273
  }
18057
18274
  const result = {
18058
18275
  requestId,
18059
- httpStatusCode: _optionalChain([body, 'optionalAccess', _223 => _223.httpStatusCode]) || 0,
18060
- code: _optionalChain([body, 'optionalAccess', _224 => _224.code]) || "",
18061
- 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,
18062
18279
  errorMessage: ""
18063
18280
  };
18064
- if (_optionalChain([body, 'optionalAccess', _226 => _226.data])) {
18281
+ if (_optionalChain([body, 'optionalAccess', _227 => _227.data])) {
18065
18282
  result.data = {
18066
18283
  aliuid: body.data.aliuid || "",
18067
18284
  apikeyId: body.data.apikeyId || "",
@@ -19048,7 +19265,7 @@ var _MobileSimulateService = class _MobileSimulateService {
19048
19265
  if (!contextSync) {
19049
19266
  throw new Error("contextSync is required for external context");
19050
19267
  }
19051
- 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])) {
19052
19269
  const exists = contextSync.policy.bwList.whiteLists.some(
19053
19270
  (whiteList) => whiteList.path === MOBILE_INFO_SUB_PATH
19054
19271
  );