test-wuying-agentbay-sdk 0.13.1-beta.20251224094729 → 0.13.1-beta.20251224103203
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 +293 -160
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +83 -12
- package/dist/index.d.ts +83 -12
- package/dist/index.mjs +248 -115
- package/dist/index.mjs.map +1 -1
- package/docs/api/README.md +1 -0
- package/docs/api/common-features/advanced/agent.md +3 -4
- package/docs/api/common-features/advanced/browser-use-agent.md +42 -42
- package/docs/api/common-features/advanced/computer-use-agent.md +43 -43
- package/docs/api/common-features/advanced/mobile-use-agent.md +57 -71
- package/docs/api/common-features/basics/filesystem.md +91 -27
- package/docs/api/common-features/basics/logging.md +7 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2218,7 +2218,17 @@ if (!dotEnvLoaded) {
|
|
|
2218
2218
|
}
|
|
2219
2219
|
function loadConfig(customConfig, customEnvPath) {
|
|
2220
2220
|
if (customConfig) {
|
|
2221
|
-
|
|
2221
|
+
const config2 = defaultConfig();
|
|
2222
|
+
if (typeof customConfig.endpoint === "string" && customConfig.endpoint) {
|
|
2223
|
+
config2.endpoint = customConfig.endpoint;
|
|
2224
|
+
}
|
|
2225
|
+
if (typeof customConfig.timeout_ms === "number" && Number.isFinite(customConfig.timeout_ms) && customConfig.timeout_ms > 0) {
|
|
2226
|
+
config2.timeout_ms = customConfig.timeout_ms;
|
|
2227
|
+
}
|
|
2228
|
+
if (Object.prototype.hasOwnProperty.call(customConfig, "region_id")) {
|
|
2229
|
+
config2.region_id = customConfig.region_id;
|
|
2230
|
+
}
|
|
2231
|
+
return config2;
|
|
2222
2232
|
}
|
|
2223
2233
|
const config = defaultConfig();
|
|
2224
2234
|
try {
|
|
@@ -14322,43 +14332,107 @@ var _FileSystem = class _FileSystem {
|
|
|
14322
14332
|
* @param path - Path to the file to read.
|
|
14323
14333
|
* @param offset - Optional: Byte offset to start reading from (0-based).
|
|
14324
14334
|
* @param length - Optional: Number of bytes to read. If 0, reads the entire file from offset.
|
|
14325
|
-
* @
|
|
14335
|
+
* @param formatType - Optional: Format to read the file in. "text" (default) or "binary".
|
|
14336
|
+
* @returns FileContentResult for text format, BinaryFileContentResult for binary format
|
|
14326
14337
|
*/
|
|
14327
|
-
async readFileChunk(path6, offset = 0, length = 0) {
|
|
14338
|
+
async readFileChunk(path6, offset = 0, length = 0, formatType = "text") {
|
|
14328
14339
|
try {
|
|
14329
14340
|
const args = {
|
|
14330
14341
|
path: path6
|
|
14331
14342
|
};
|
|
14332
|
-
if (offset
|
|
14343
|
+
if (offset >= 0) {
|
|
14333
14344
|
args.offset = offset;
|
|
14334
14345
|
}
|
|
14335
|
-
if (length
|
|
14346
|
+
if (length >= 0) {
|
|
14336
14347
|
args.length = length;
|
|
14337
14348
|
}
|
|
14349
|
+
if (formatType === "binary") {
|
|
14350
|
+
args.format = "binary";
|
|
14351
|
+
}
|
|
14338
14352
|
const result = await this.session.callMcpTool(
|
|
14339
14353
|
"read_file",
|
|
14340
14354
|
args
|
|
14341
14355
|
);
|
|
14342
14356
|
if (!result.success) {
|
|
14357
|
+
if (formatType === "binary") {
|
|
14358
|
+
return {
|
|
14359
|
+
requestId: result.requestId,
|
|
14360
|
+
success: false,
|
|
14361
|
+
content: new Uint8Array(0),
|
|
14362
|
+
errorMessage: result.errorMessage
|
|
14363
|
+
};
|
|
14364
|
+
} else {
|
|
14365
|
+
return {
|
|
14366
|
+
requestId: result.requestId,
|
|
14367
|
+
success: false,
|
|
14368
|
+
content: "",
|
|
14369
|
+
errorMessage: result.errorMessage
|
|
14370
|
+
};
|
|
14371
|
+
}
|
|
14372
|
+
}
|
|
14373
|
+
if (formatType === "binary") {
|
|
14374
|
+
try {
|
|
14375
|
+
if (typeof Buffer !== "undefined") {
|
|
14376
|
+
const base64String = result.data || "";
|
|
14377
|
+
if (base64String) {
|
|
14378
|
+
const base64WithoutPadding = base64String.replace(/=+$/, "");
|
|
14379
|
+
if (!/^[A-Za-z0-9+/]+$/.test(base64WithoutPadding)) {
|
|
14380
|
+
throw new Error("Invalid base64 string format");
|
|
14381
|
+
}
|
|
14382
|
+
const paddingMatch = base64String.match(/=+$/);
|
|
14383
|
+
if (paddingMatch && paddingMatch[0].length > 2) {
|
|
14384
|
+
throw new Error("Invalid base64 padding format");
|
|
14385
|
+
}
|
|
14386
|
+
}
|
|
14387
|
+
const binaryContent = Buffer.from(base64String, "base64");
|
|
14388
|
+
return {
|
|
14389
|
+
requestId: result.requestId,
|
|
14390
|
+
success: true,
|
|
14391
|
+
content: new Uint8Array(binaryContent)
|
|
14392
|
+
};
|
|
14393
|
+
} else {
|
|
14394
|
+
const binaryString = atob(result.data || "");
|
|
14395
|
+
const binaryContent = new Uint8Array(binaryString.length);
|
|
14396
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
14397
|
+
binaryContent[i] = binaryString.charCodeAt(i);
|
|
14398
|
+
}
|
|
14399
|
+
return {
|
|
14400
|
+
requestId: result.requestId,
|
|
14401
|
+
success: true,
|
|
14402
|
+
content: binaryContent
|
|
14403
|
+
};
|
|
14404
|
+
}
|
|
14405
|
+
} catch (e) {
|
|
14406
|
+
return {
|
|
14407
|
+
requestId: result.requestId,
|
|
14408
|
+
success: false,
|
|
14409
|
+
content: new Uint8Array(0),
|
|
14410
|
+
errorMessage: `Failed to decode base64: ${e}`
|
|
14411
|
+
};
|
|
14412
|
+
}
|
|
14413
|
+
} else {
|
|
14343
14414
|
return {
|
|
14344
14415
|
requestId: result.requestId,
|
|
14416
|
+
success: true,
|
|
14417
|
+
content: result.data || ""
|
|
14418
|
+
};
|
|
14419
|
+
}
|
|
14420
|
+
} catch (error) {
|
|
14421
|
+
if (formatType === "binary") {
|
|
14422
|
+
return {
|
|
14423
|
+
requestId: "",
|
|
14424
|
+
success: false,
|
|
14425
|
+
content: new Uint8Array(0),
|
|
14426
|
+
errorMessage: `Failed to read file: ${error}`
|
|
14427
|
+
};
|
|
14428
|
+
} else {
|
|
14429
|
+
return {
|
|
14430
|
+
requestId: "",
|
|
14345
14431
|
success: false,
|
|
14346
14432
|
content: "",
|
|
14347
|
-
errorMessage:
|
|
14433
|
+
errorMessage: `Failed to read file: ${error}`
|
|
14348
14434
|
};
|
|
14349
14435
|
}
|
|
14350
|
-
return {
|
|
14351
|
-
requestId: result.requestId,
|
|
14352
|
-
success: true,
|
|
14353
|
-
content: result.data || ""
|
|
14354
|
-
};
|
|
14355
|
-
} catch (error) {
|
|
14356
|
-
return {
|
|
14357
|
-
requestId: "",
|
|
14358
|
-
success: false,
|
|
14359
|
-
content: "",
|
|
14360
|
-
errorMessage: `Failed to read file: ${error}`
|
|
14361
|
-
};
|
|
14362
14436
|
}
|
|
14363
14437
|
}
|
|
14364
14438
|
/**
|
|
@@ -14556,120 +14630,178 @@ var _FileSystem = class _FileSystem {
|
|
|
14556
14630
|
};
|
|
14557
14631
|
}
|
|
14558
14632
|
}
|
|
14559
|
-
|
|
14560
|
-
|
|
14561
|
-
*
|
|
14562
|
-
* @param path - Path to the file to read.
|
|
14563
|
-
* @returns FileContentResult with complete file content and requestId
|
|
14564
|
-
*/
|
|
14565
|
-
/**
|
|
14566
|
-
* Reads the entire content of a file.
|
|
14567
|
-
*
|
|
14568
|
-
* @param path - Absolute path to the file to read.
|
|
14569
|
-
*
|
|
14570
|
-
* @returns Promise resolving to FileContentResult containing:
|
|
14571
|
-
* - success: Whether the read operation succeeded
|
|
14572
|
-
* - content: String content of the file
|
|
14573
|
-
* - requestId: Unique identifier for this API request
|
|
14574
|
-
* - errorMessage: Error description if read failed
|
|
14575
|
-
*
|
|
14576
|
-
* @throws Error if the API call fails.
|
|
14577
|
-
*
|
|
14578
|
-
* @example
|
|
14579
|
-
* ```typescript
|
|
14580
|
-
* import { AgentBay } from 'wuying-agentbay-sdk';
|
|
14581
|
-
*
|
|
14582
|
-
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
14583
|
-
* const result = await agentBay.create();
|
|
14584
|
-
*
|
|
14585
|
-
* if (result.success) {
|
|
14586
|
-
* const session = result.session;
|
|
14587
|
-
*
|
|
14588
|
-
* // Read a text file
|
|
14589
|
-
* const fileResult = await session.fileSystem.readFile('/etc/hostname');
|
|
14590
|
-
* if (fileResult.success) {
|
|
14591
|
-
* console.log(`Content: ${fileResult.content}`);
|
|
14592
|
-
* // Output: Content: agentbay-session-xyz
|
|
14593
|
-
* }
|
|
14594
|
-
*
|
|
14595
|
-
* await session.delete();
|
|
14596
|
-
* }
|
|
14597
|
-
* ```
|
|
14598
|
-
*
|
|
14599
|
-
* @remarks
|
|
14600
|
-
* **Behavior:**
|
|
14601
|
-
* - Automatically handles large files by reading in 60KB chunks
|
|
14602
|
-
* - Returns empty string for empty files
|
|
14603
|
-
* - Fails if path is a directory or doesn't exist
|
|
14604
|
-
* - Content is returned as UTF-8 string
|
|
14605
|
-
*
|
|
14606
|
-
* @see {@link writeFile}, {@link listDirectory}
|
|
14607
|
-
*/
|
|
14608
|
-
async readFile(path6) {
|
|
14633
|
+
async readFile(path6, opts) {
|
|
14634
|
+
const format = opts?.format || "text";
|
|
14609
14635
|
const chunkSize = DEFAULT_CHUNK_SIZE;
|
|
14610
14636
|
try {
|
|
14611
14637
|
const fileInfoResult = await this.getFileInfo(path6);
|
|
14612
14638
|
if (!fileInfoResult.success) {
|
|
14613
|
-
|
|
14614
|
-
|
|
14615
|
-
|
|
14616
|
-
|
|
14617
|
-
|
|
14618
|
-
|
|
14639
|
+
if (format === "bytes") {
|
|
14640
|
+
return {
|
|
14641
|
+
requestId: fileInfoResult.requestId,
|
|
14642
|
+
success: false,
|
|
14643
|
+
content: new Uint8Array(0),
|
|
14644
|
+
errorMessage: fileInfoResult.errorMessage
|
|
14645
|
+
};
|
|
14646
|
+
} else {
|
|
14647
|
+
return {
|
|
14648
|
+
requestId: fileInfoResult.requestId,
|
|
14649
|
+
success: false,
|
|
14650
|
+
content: "",
|
|
14651
|
+
errorMessage: fileInfoResult.errorMessage
|
|
14652
|
+
};
|
|
14653
|
+
}
|
|
14619
14654
|
}
|
|
14620
14655
|
if (!fileInfoResult.fileInfo || fileInfoResult.fileInfo.isDirectory) {
|
|
14621
|
-
|
|
14622
|
-
|
|
14623
|
-
|
|
14624
|
-
|
|
14625
|
-
|
|
14626
|
-
|
|
14656
|
+
const errorMsg = `Path does not exist or is a directory: ${path6}`;
|
|
14657
|
+
if (format === "bytes") {
|
|
14658
|
+
return {
|
|
14659
|
+
requestId: fileInfoResult.requestId,
|
|
14660
|
+
success: false,
|
|
14661
|
+
content: new Uint8Array(0),
|
|
14662
|
+
errorMessage: errorMsg
|
|
14663
|
+
};
|
|
14664
|
+
} else {
|
|
14665
|
+
return {
|
|
14666
|
+
requestId: fileInfoResult.requestId,
|
|
14667
|
+
success: false,
|
|
14668
|
+
content: "",
|
|
14669
|
+
errorMessage: errorMsg
|
|
14670
|
+
};
|
|
14671
|
+
}
|
|
14627
14672
|
}
|
|
14628
14673
|
const fileSize = fileInfoResult.fileInfo.size || 0;
|
|
14629
14674
|
if (fileSize === 0) {
|
|
14675
|
+
if (format === "bytes") {
|
|
14676
|
+
return {
|
|
14677
|
+
requestId: fileInfoResult.requestId,
|
|
14678
|
+
success: true,
|
|
14679
|
+
content: new Uint8Array(0),
|
|
14680
|
+
size: 0
|
|
14681
|
+
};
|
|
14682
|
+
} else {
|
|
14683
|
+
return {
|
|
14684
|
+
requestId: fileInfoResult.requestId,
|
|
14685
|
+
success: true,
|
|
14686
|
+
content: ""
|
|
14687
|
+
};
|
|
14688
|
+
}
|
|
14689
|
+
}
|
|
14690
|
+
if (format === "bytes") {
|
|
14691
|
+
const contentChunks = [];
|
|
14692
|
+
let offset = 0;
|
|
14693
|
+
let chunkCount = 0;
|
|
14694
|
+
while (offset < fileSize) {
|
|
14695
|
+
let length = chunkSize;
|
|
14696
|
+
if (offset + length > fileSize) {
|
|
14697
|
+
length = fileSize - offset;
|
|
14698
|
+
}
|
|
14699
|
+
try {
|
|
14700
|
+
const chunkResult = await this.readFileChunk(
|
|
14701
|
+
path6,
|
|
14702
|
+
offset,
|
|
14703
|
+
length,
|
|
14704
|
+
"binary"
|
|
14705
|
+
);
|
|
14706
|
+
if (!chunkResult.success) {
|
|
14707
|
+
return chunkResult;
|
|
14708
|
+
}
|
|
14709
|
+
if ("content" in chunkResult && chunkResult.content instanceof Uint8Array) {
|
|
14710
|
+
contentChunks.push(chunkResult.content);
|
|
14711
|
+
} else {
|
|
14712
|
+
return {
|
|
14713
|
+
requestId: chunkResult.requestId,
|
|
14714
|
+
success: false,
|
|
14715
|
+
content: new Uint8Array(0),
|
|
14716
|
+
errorMessage: "Unexpected result type for binary format"
|
|
14717
|
+
};
|
|
14718
|
+
}
|
|
14719
|
+
offset += length;
|
|
14720
|
+
chunkCount++;
|
|
14721
|
+
} catch (error) {
|
|
14722
|
+
return {
|
|
14723
|
+
requestId: fileInfoResult.requestId,
|
|
14724
|
+
success: false,
|
|
14725
|
+
content: new Uint8Array(0),
|
|
14726
|
+
errorMessage: `Error reading chunk at offset ${offset}: ${error}`
|
|
14727
|
+
};
|
|
14728
|
+
}
|
|
14729
|
+
}
|
|
14730
|
+
const totalLength = contentChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
14731
|
+
const finalContent = new Uint8Array(totalLength);
|
|
14732
|
+
let position = 0;
|
|
14733
|
+
for (const chunk of contentChunks) {
|
|
14734
|
+
finalContent.set(chunk, position);
|
|
14735
|
+
position += chunk.length;
|
|
14736
|
+
}
|
|
14630
14737
|
return {
|
|
14631
14738
|
requestId: fileInfoResult.requestId,
|
|
14632
14739
|
success: true,
|
|
14633
|
-
content:
|
|
14740
|
+
content: finalContent,
|
|
14741
|
+
size: finalContent.length
|
|
14634
14742
|
};
|
|
14635
|
-
}
|
|
14636
|
-
|
|
14637
|
-
|
|
14638
|
-
|
|
14639
|
-
|
|
14640
|
-
|
|
14641
|
-
|
|
14642
|
-
|
|
14643
|
-
|
|
14644
|
-
|
|
14645
|
-
|
|
14646
|
-
|
|
14647
|
-
|
|
14743
|
+
} else {
|
|
14744
|
+
let result = "";
|
|
14745
|
+
let offset = 0;
|
|
14746
|
+
let chunkCount = 0;
|
|
14747
|
+
while (offset < fileSize) {
|
|
14748
|
+
let length = chunkSize;
|
|
14749
|
+
if (offset + length > fileSize) {
|
|
14750
|
+
length = fileSize - offset;
|
|
14751
|
+
}
|
|
14752
|
+
try {
|
|
14753
|
+
const chunkResult = await this.readFileChunk(
|
|
14754
|
+
path6,
|
|
14755
|
+
offset,
|
|
14756
|
+
length,
|
|
14757
|
+
"text"
|
|
14758
|
+
);
|
|
14759
|
+
if (!chunkResult.success) {
|
|
14760
|
+
return chunkResult;
|
|
14761
|
+
}
|
|
14762
|
+
if ("content" in chunkResult && typeof chunkResult.content === "string") {
|
|
14763
|
+
result += chunkResult.content;
|
|
14764
|
+
} else {
|
|
14765
|
+
return {
|
|
14766
|
+
requestId: chunkResult.requestId,
|
|
14767
|
+
success: false,
|
|
14768
|
+
content: "",
|
|
14769
|
+
errorMessage: "Unexpected result type for text format"
|
|
14770
|
+
};
|
|
14771
|
+
}
|
|
14772
|
+
offset += length;
|
|
14773
|
+
chunkCount++;
|
|
14774
|
+
} catch (error) {
|
|
14775
|
+
return {
|
|
14776
|
+
requestId: fileInfoResult.requestId,
|
|
14777
|
+
success: false,
|
|
14778
|
+
content: "",
|
|
14779
|
+
errorMessage: `Error reading chunk at offset ${offset}: ${error}`
|
|
14780
|
+
};
|
|
14648
14781
|
}
|
|
14649
|
-
result += chunkResult.content;
|
|
14650
|
-
offset += length;
|
|
14651
|
-
chunkCount++;
|
|
14652
|
-
} catch (error) {
|
|
14653
|
-
return {
|
|
14654
|
-
requestId: fileInfoResult.requestId,
|
|
14655
|
-
success: false,
|
|
14656
|
-
content: "",
|
|
14657
|
-
errorMessage: `Error reading chunk at offset ${offset}: ${error}`
|
|
14658
|
-
};
|
|
14659
14782
|
}
|
|
14783
|
+
return {
|
|
14784
|
+
requestId: fileInfoResult.requestId,
|
|
14785
|
+
success: true,
|
|
14786
|
+
content: result
|
|
14787
|
+
};
|
|
14660
14788
|
}
|
|
14661
|
-
return {
|
|
14662
|
-
requestId: fileInfoResult.requestId,
|
|
14663
|
-
success: true,
|
|
14664
|
-
content: result
|
|
14665
|
-
};
|
|
14666
14789
|
} catch (error) {
|
|
14667
|
-
|
|
14668
|
-
|
|
14669
|
-
|
|
14670
|
-
|
|
14671
|
-
|
|
14672
|
-
|
|
14790
|
+
if (format === "bytes") {
|
|
14791
|
+
return {
|
|
14792
|
+
requestId: "",
|
|
14793
|
+
success: false,
|
|
14794
|
+
content: new Uint8Array(0),
|
|
14795
|
+
errorMessage: `Failed to read large file: ${error}`
|
|
14796
|
+
};
|
|
14797
|
+
} else {
|
|
14798
|
+
return {
|
|
14799
|
+
requestId: "",
|
|
14800
|
+
success: false,
|
|
14801
|
+
content: "",
|
|
14802
|
+
errorMessage: `Failed to read large file: ${error}`
|
|
14803
|
+
};
|
|
14804
|
+
}
|
|
14673
14805
|
}
|
|
14674
14806
|
}
|
|
14675
14807
|
/**
|
|
@@ -19724,6 +19856,7 @@ export {
|
|
|
19724
19856
|
Mobile,
|
|
19725
19857
|
MobileSimulateMode,
|
|
19726
19858
|
MobileSimulateService,
|
|
19859
|
+
MobileUseAgent,
|
|
19727
19860
|
ModifyContextRequest,
|
|
19728
19861
|
ModifyContextResponse,
|
|
19729
19862
|
ModifyContextResponseBody,
|