test-wuying-agentbay-sdk 0.13.0-beta.20251218180112 → 0.13.0-beta.20251219095412
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 +90 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +121 -44
- package/dist/index.d.ts +121 -44
- package/dist/index.mjs +90 -15
- package/dist/index.mjs.map +1 -1
- package/docs/api/common-features/basics/filesystem.md +36 -0
- package/docs/api/computer-use/computer.md +24 -24
- package/docs/examples/common-features/basics/filesystem-example/filesystem-example.ts +13 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -11532,6 +11532,38 @@ _chunk4IPTHWLMcjs.init_cjs_shims.call(void 0, );
|
|
|
11532
11532
|
|
|
11533
11533
|
// src/computer/computer.ts
|
|
11534
11534
|
_chunk4IPTHWLMcjs.init_cjs_shims.call(void 0, );
|
|
11535
|
+
|
|
11536
|
+
// src/utils/field-converter.ts
|
|
11537
|
+
_chunk4IPTHWLMcjs.init_cjs_shims.call(void 0, );
|
|
11538
|
+
function snakeToCamel(str) {
|
|
11539
|
+
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
11540
|
+
}
|
|
11541
|
+
_chunk4IPTHWLMcjs.__name.call(void 0, snakeToCamel, "snakeToCamel");
|
|
11542
|
+
function convertObjectKeys(obj) {
|
|
11543
|
+
if (obj === null || obj === void 0) {
|
|
11544
|
+
return obj;
|
|
11545
|
+
}
|
|
11546
|
+
if (Array.isArray(obj)) {
|
|
11547
|
+
return obj.map((item) => convertObjectKeys(item));
|
|
11548
|
+
}
|
|
11549
|
+
if (typeof obj === "object" && obj.constructor === Object) {
|
|
11550
|
+
const converted = {};
|
|
11551
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
11552
|
+
const camelKey = snakeToCamel(key);
|
|
11553
|
+
converted[camelKey] = convertObjectKeys(value);
|
|
11554
|
+
}
|
|
11555
|
+
return converted;
|
|
11556
|
+
}
|
|
11557
|
+
return obj;
|
|
11558
|
+
}
|
|
11559
|
+
_chunk4IPTHWLMcjs.__name.call(void 0, convertObjectKeys, "convertObjectKeys");
|
|
11560
|
+
function convertWindowData(rawWindow) {
|
|
11561
|
+
if (!rawWindow) return rawWindow;
|
|
11562
|
+
return convertObjectKeys(rawWindow);
|
|
11563
|
+
}
|
|
11564
|
+
_chunk4IPTHWLMcjs.__name.call(void 0, convertWindowData, "convertWindowData");
|
|
11565
|
+
|
|
11566
|
+
// src/computer/computer.ts
|
|
11535
11567
|
var MouseButton = /* @__PURE__ */ ((MouseButton2) => {
|
|
11536
11568
|
MouseButton2["LEFT"] = "left";
|
|
11537
11569
|
MouseButton2["RIGHT"] = "right";
|
|
@@ -12036,7 +12068,8 @@ var _Computer = class _Computer {
|
|
|
12036
12068
|
errorMessage: response.errorMessage
|
|
12037
12069
|
};
|
|
12038
12070
|
}
|
|
12039
|
-
const
|
|
12071
|
+
const rawWindows = response.data ? JSON.parse(response.data) : [];
|
|
12072
|
+
const windows = convertWindowData(rawWindows);
|
|
12040
12073
|
return {
|
|
12041
12074
|
requestId: response.requestId,
|
|
12042
12075
|
success: true,
|
|
@@ -12068,19 +12101,20 @@ var _Computer = class _Computer {
|
|
|
12068
12101
|
* }
|
|
12069
12102
|
* ```
|
|
12070
12103
|
*/
|
|
12071
|
-
async getActiveWindow(
|
|
12104
|
+
async getActiveWindow() {
|
|
12072
12105
|
try {
|
|
12073
|
-
const args = {
|
|
12106
|
+
const args = {};
|
|
12074
12107
|
const response = await this.session.callMcpTool("get_active_window", args);
|
|
12075
12108
|
if (!response.success) {
|
|
12076
12109
|
return {
|
|
12077
12110
|
requestId: response.requestId,
|
|
12078
12111
|
success: false,
|
|
12079
|
-
window:
|
|
12112
|
+
window: [],
|
|
12080
12113
|
errorMessage: response.errorMessage
|
|
12081
12114
|
};
|
|
12082
12115
|
}
|
|
12083
|
-
const
|
|
12116
|
+
const rawWindow = response.data ? JSON.parse(response.data) : null;
|
|
12117
|
+
const window = convertWindowData(rawWindow);
|
|
12084
12118
|
return {
|
|
12085
12119
|
requestId: response.requestId,
|
|
12086
12120
|
success: true,
|
|
@@ -12090,7 +12124,7 @@ var _Computer = class _Computer {
|
|
|
12090
12124
|
return {
|
|
12091
12125
|
requestId: "",
|
|
12092
12126
|
success: false,
|
|
12093
|
-
window:
|
|
12127
|
+
window: [],
|
|
12094
12128
|
errorMessage: `Failed to get active window: ${error}`
|
|
12095
12129
|
};
|
|
12096
12130
|
}
|
|
@@ -12396,7 +12430,6 @@ var _Computer = class _Computer {
|
|
|
12396
12430
|
* }
|
|
12397
12431
|
* ```
|
|
12398
12432
|
*/
|
|
12399
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12400
12433
|
async getInstalledApps(startMenu = true, desktop = false, ignoreSystemApps = true) {
|
|
12401
12434
|
try {
|
|
12402
12435
|
const args = {
|
|
@@ -12413,7 +12446,8 @@ var _Computer = class _Computer {
|
|
|
12413
12446
|
errorMessage: response.errorMessage
|
|
12414
12447
|
};
|
|
12415
12448
|
}
|
|
12416
|
-
const
|
|
12449
|
+
const rawApps = response.data ? JSON.parse(response.data) : [];
|
|
12450
|
+
const apps = convertObjectKeys(rawApps);
|
|
12417
12451
|
return {
|
|
12418
12452
|
requestId: response.requestId,
|
|
12419
12453
|
success: true,
|
|
@@ -12447,7 +12481,6 @@ var _Computer = class _Computer {
|
|
|
12447
12481
|
* }
|
|
12448
12482
|
* ```
|
|
12449
12483
|
*/
|
|
12450
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12451
12484
|
async startApp(startCmd, workDirectory = "", activity = "") {
|
|
12452
12485
|
try {
|
|
12453
12486
|
const args = { start_cmd: startCmd };
|
|
@@ -12462,7 +12495,8 @@ var _Computer = class _Computer {
|
|
|
12462
12495
|
errorMessage: response.errorMessage
|
|
12463
12496
|
};
|
|
12464
12497
|
}
|
|
12465
|
-
const
|
|
12498
|
+
const rawProcesses = response.data ? JSON.parse(response.data) : [];
|
|
12499
|
+
const processes = convertObjectKeys(rawProcesses);
|
|
12466
12500
|
return {
|
|
12467
12501
|
requestId: response.requestId,
|
|
12468
12502
|
success: true,
|
|
@@ -12494,7 +12528,6 @@ var _Computer = class _Computer {
|
|
|
12494
12528
|
* }
|
|
12495
12529
|
* ```
|
|
12496
12530
|
*/
|
|
12497
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12498
12531
|
async stopAppByPName(pname) {
|
|
12499
12532
|
try {
|
|
12500
12533
|
const args = { pname };
|
|
@@ -12530,7 +12563,6 @@ var _Computer = class _Computer {
|
|
|
12530
12563
|
* }
|
|
12531
12564
|
* ```
|
|
12532
12565
|
*/
|
|
12533
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12534
12566
|
async stopAppByPID(pid) {
|
|
12535
12567
|
try {
|
|
12536
12568
|
const args = { pid };
|
|
@@ -12565,7 +12597,6 @@ var _Computer = class _Computer {
|
|
|
12565
12597
|
* }
|
|
12566
12598
|
* ```
|
|
12567
12599
|
*/
|
|
12568
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12569
12600
|
async stopAppByCmd(cmd) {
|
|
12570
12601
|
try {
|
|
12571
12602
|
const args = { stop_cmd: cmd };
|
|
@@ -12599,7 +12630,6 @@ var _Computer = class _Computer {
|
|
|
12599
12630
|
* }
|
|
12600
12631
|
* ```
|
|
12601
12632
|
*/
|
|
12602
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12603
12633
|
async listVisibleApps() {
|
|
12604
12634
|
try {
|
|
12605
12635
|
const response = await this.session.callMcpTool("list_visible_apps", {});
|
|
@@ -12611,7 +12641,8 @@ var _Computer = class _Computer {
|
|
|
12611
12641
|
errorMessage: response.errorMessage
|
|
12612
12642
|
};
|
|
12613
12643
|
}
|
|
12614
|
-
const
|
|
12644
|
+
const rawProcesses = response.data ? JSON.parse(response.data) : [];
|
|
12645
|
+
const processes = convertObjectKeys(rawProcesses);
|
|
12615
12646
|
return {
|
|
12616
12647
|
requestId: response.requestId,
|
|
12617
12648
|
success: true,
|
|
@@ -13694,6 +13725,50 @@ var _FileSystem = class _FileSystem {
|
|
|
13694
13725
|
};
|
|
13695
13726
|
}
|
|
13696
13727
|
}
|
|
13728
|
+
/**
|
|
13729
|
+
* Deletes a file at the specified path.
|
|
13730
|
+
* Corresponds to Python's delete_file() method
|
|
13731
|
+
*
|
|
13732
|
+
* @param path - Path to the file to delete.
|
|
13733
|
+
* @returns BoolResult with deletion result and requestId
|
|
13734
|
+
*
|
|
13735
|
+
* @example
|
|
13736
|
+
* ```typescript
|
|
13737
|
+
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
13738
|
+
* const result = await agentBay.create();
|
|
13739
|
+
* if (result.success) {
|
|
13740
|
+
* const session = result.session;
|
|
13741
|
+
* await session.fileSystem.writeFile('/tmp/to_delete.txt', 'hello');
|
|
13742
|
+
* const deleteResult = await session.fileSystem.deleteFile('/tmp/to_delete.txt');
|
|
13743
|
+
* console.log('File deleted:', deleteResult.success);
|
|
13744
|
+
* await session.delete();
|
|
13745
|
+
* }
|
|
13746
|
+
* ```
|
|
13747
|
+
*/
|
|
13748
|
+
async deleteFile(path6) {
|
|
13749
|
+
try {
|
|
13750
|
+
const args = { path: path6 };
|
|
13751
|
+
const result = await this.session.callMcpTool("delete_file", args);
|
|
13752
|
+
if (!result.success) {
|
|
13753
|
+
return {
|
|
13754
|
+
requestId: result.requestId,
|
|
13755
|
+
success: false,
|
|
13756
|
+
errorMessage: result.errorMessage
|
|
13757
|
+
};
|
|
13758
|
+
}
|
|
13759
|
+
return {
|
|
13760
|
+
requestId: result.requestId,
|
|
13761
|
+
success: true,
|
|
13762
|
+
data: true
|
|
13763
|
+
};
|
|
13764
|
+
} catch (error) {
|
|
13765
|
+
return {
|
|
13766
|
+
requestId: "",
|
|
13767
|
+
success: false,
|
|
13768
|
+
errorMessage: `Failed to delete file: ${error}`
|
|
13769
|
+
};
|
|
13770
|
+
}
|
|
13771
|
+
}
|
|
13697
13772
|
/**
|
|
13698
13773
|
* Edits a file by replacing occurrences of oldText with newText.
|
|
13699
13774
|
* Corresponds to Python's edit_file() method
|