wuying-agentbay-sdk 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -11
- package/dist/chunk-HKUD6LHR.mjs +612 -0
- package/dist/chunk-HKUD6LHR.mjs.map +1 -0
- package/dist/chunk-KOCCRN77.cjs +601 -0
- package/dist/chunk-KOCCRN77.cjs.map +1 -0
- package/dist/index.cjs +4504 -2730
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +857 -276
- package/dist/index.d.ts +857 -276
- package/dist/index.mjs +4369 -2597
- package/dist/index.mjs.map +1 -1
- package/dist/window-ATD33TEL.cjs +7 -0
- package/dist/window-ATD33TEL.cjs.map +1 -0
- package/dist/window-TMK7MJI6.mjs +16 -0
- package/dist/window-TMK7MJI6.mjs.map +1 -0
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ async function main() {
|
|
|
24
24
|
// Create session
|
|
25
25
|
const agentBay = new AgentBay();
|
|
26
26
|
const result = await agentBay.create();
|
|
27
|
+
// Verified: ✓ Client initialized and session created successfully
|
|
27
28
|
|
|
28
29
|
if (result.success) {
|
|
29
30
|
const session = result.session;
|
|
@@ -31,11 +32,15 @@ async function main() {
|
|
|
31
32
|
// Execute command
|
|
32
33
|
const cmdResult = await session.command.executeCommand("ls -la");
|
|
33
34
|
console.log(cmdResult.output);
|
|
35
|
+
// Verified: ✓ Command executed successfully
|
|
36
|
+
// Sample output: "总计 100\ndrwxr-x--- 16 wuying wuying 4096..."
|
|
34
37
|
|
|
35
38
|
// File operations
|
|
36
39
|
await session.fileSystem.writeFile("/tmp/test.txt", "Hello World");
|
|
37
40
|
const content = await session.fileSystem.readFile("/tmp/test.txt");
|
|
38
|
-
console.log(content.
|
|
41
|
+
console.log(content.content);
|
|
42
|
+
// Verified: ✓ File written and read successfully
|
|
43
|
+
// Output: "Hello World"
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
|
|
@@ -47,15 +52,20 @@ main().catch(console.error);
|
|
|
47
52
|
### 🆕 New Users
|
|
48
53
|
- [📚 Quick Start Tutorial](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/quickstart/README.md) - Get started in 5 minutes
|
|
49
54
|
- [🎯 Core Concepts](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/quickstart/basic-concepts.md) - Understanding cloud environments and sessions
|
|
50
|
-
- [💡 Best Practices](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/quickstart/best-practices.md) - Common patterns and techniques
|
|
51
55
|
|
|
52
56
|
### 🚀 Experienced Users
|
|
57
|
+
**Choose Your Cloud Environment:**
|
|
58
|
+
- 🌐 [Browser Use](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/guides/browser-use/README.md) - Web scraping, browser testing, form automation
|
|
59
|
+
- 🖥️ [Computer Use](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/guides/computer-use/README.md) - Windows desktop automation, UI testing
|
|
60
|
+
- 📱 [Mobile Use](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/guides/mobile-use/README.md) - Android UI testing, mobile app automation
|
|
61
|
+
- 💻 [CodeSpace](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/guides/codespace/README.md) - Code execution, development environments
|
|
62
|
+
|
|
63
|
+
**Additional Resources:**
|
|
53
64
|
- [📖 Feature Guides](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/guides/README.md) - Complete feature introduction
|
|
54
65
|
- [🔧 TypeScript API Reference](docs/api/README.md) - Detailed API documentation
|
|
55
|
-
- [💻 TypeScript Examples](docs/examples/) - Complete example code
|
|
66
|
+
- [💻 TypeScript Examples](docs/examples/README.md) - Complete example code
|
|
56
67
|
|
|
57
68
|
### 🆘 Need Help
|
|
58
|
-
- [🔧 Troubleshooting](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/quickstart/troubleshooting.md) - Problem diagnosis
|
|
59
69
|
- [🔧 TypeScript API Reference](docs/api/README.md) - Local API documentation
|
|
60
70
|
- [💡 TypeScript Examples](docs/examples/README.md) - Local example code
|
|
61
71
|
|
|
@@ -65,12 +75,7 @@ main().catch(console.error);
|
|
|
65
75
|
```typescript
|
|
66
76
|
// Create session
|
|
67
77
|
const session = (await agentBay.create()).session;
|
|
68
|
-
|
|
69
|
-
// List sessions
|
|
70
|
-
const sessions = await agentBay.list();
|
|
71
|
-
|
|
72
|
-
// Connect to existing session
|
|
73
|
-
const session = await agentBay.connect("session_id");
|
|
78
|
+
// Verified: ✓ Session created successfully
|
|
74
79
|
```
|
|
75
80
|
|
|
76
81
|
### File Operations
|
|
@@ -78,9 +83,12 @@ const session = await agentBay.connect("session_id");
|
|
|
78
83
|
// Read and write files
|
|
79
84
|
await session.fileSystem.writeFile("/path/file.txt", "content");
|
|
80
85
|
const content = await session.fileSystem.readFile("/path/file.txt");
|
|
86
|
+
// Verified: ✓ File operations work correctly
|
|
87
|
+
// content.content contains the file's text content
|
|
81
88
|
|
|
82
89
|
// List directory
|
|
83
90
|
const files = await session.fileSystem.listDirectory("/path");
|
|
91
|
+
// Verified: ✓ Returns list of file/directory information
|
|
84
92
|
```
|
|
85
93
|
|
|
86
94
|
### Command Execution
|
|
@@ -88,12 +96,15 @@ const files = await session.fileSystem.listDirectory("/path");
|
|
|
88
96
|
// Execute command
|
|
89
97
|
const result = await session.command.executeCommand("node script.js");
|
|
90
98
|
console.log(result.output);
|
|
99
|
+
// Verified: ✓ Command executed successfully
|
|
100
|
+
// result.output contains the command's stdout
|
|
91
101
|
```
|
|
92
102
|
|
|
93
103
|
### Data Persistence
|
|
94
104
|
```typescript
|
|
95
105
|
// Create context
|
|
96
106
|
const context = (await agentBay.context.get("my-project", true)).context;
|
|
107
|
+
// Verified: ✓ Context created or retrieved successfully
|
|
97
108
|
|
|
98
109
|
// Create session with context
|
|
99
110
|
import { ContextSync, SyncPolicy } from 'wuying-agentbay-sdk';
|
|
@@ -103,6 +114,8 @@ const contextSync = new ContextSync({
|
|
|
103
114
|
policy: SyncPolicy.default()
|
|
104
115
|
});
|
|
105
116
|
const session = (await agentBay.create({ contextSync: [contextSync] })).session;
|
|
117
|
+
// Verified: ✓ Session created with context synchronization
|
|
118
|
+
// Data in /tmp/data will be synchronized to the context
|
|
106
119
|
```
|
|
107
120
|
|
|
108
121
|
## 🆘 Get Help
|
|
@@ -112,4 +125,4 @@ const session = (await agentBay.create({ contextSync: [contextSync] })).session;
|
|
|
112
125
|
|
|
113
126
|
## 📄 License
|
|
114
127
|
|
|
115
|
-
This project is licensed under the Apache License 2.0 - see the [LICENSE](../LICENSE) file for details.
|
|
128
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](../LICENSE) file for details.
|
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
(function() {
|
|
5
|
+
if (typeof OpenApi !== 'undefined' && !OpenApi.default) {
|
|
6
|
+
OpenApi.default = OpenApi;
|
|
7
|
+
}
|
|
8
|
+
})();
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
18
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
19
|
+
}) : x)(function(x) {
|
|
20
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
21
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
22
|
+
});
|
|
23
|
+
var __esm = (fn, res) => function __init() {
|
|
24
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
25
|
+
};
|
|
26
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
27
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
+
mod
|
|
44
|
+
));
|
|
45
|
+
|
|
46
|
+
// node_modules/tsup/assets/esm_shims.js
|
|
47
|
+
import path from "path";
|
|
48
|
+
import { fileURLToPath } from "url";
|
|
49
|
+
var init_esm_shims = __esm({
|
|
50
|
+
"node_modules/tsup/assets/esm_shims.js"() {
|
|
51
|
+
"use strict";
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// src/window/window.ts
|
|
56
|
+
init_esm_shims();
|
|
57
|
+
var _WindowManager = class _WindowManager {
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new WindowManager instance.
|
|
60
|
+
* @param session The session object that provides access to the AgentBay API.
|
|
61
|
+
*/
|
|
62
|
+
constructor(session) {
|
|
63
|
+
this.session = session;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Helper method to parse JSON string into Window objects
|
|
67
|
+
* @param jsonStr - JSON string to parse
|
|
68
|
+
* @returns Array of Window objects or single Window object
|
|
69
|
+
*/
|
|
70
|
+
parseWindowsFromJSON(jsonStr) {
|
|
71
|
+
try {
|
|
72
|
+
const parsed = JSON.parse(jsonStr);
|
|
73
|
+
return Array.isArray(parsed) ? parsed : [parsed];
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw new Error(`Failed to parse window data: ${error}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Lists all root windows in the system.
|
|
80
|
+
* Corresponds to Python's list_root_windows() method
|
|
81
|
+
*
|
|
82
|
+
* @param timeoutMs - The timeout in milliseconds. Default is 3000ms.
|
|
83
|
+
* @returns WindowListResult with windows array and requestId
|
|
84
|
+
*
|
|
85
|
+
* @deprecated Use session.computer.listRootWindows() instead.
|
|
86
|
+
*/
|
|
87
|
+
async listRootWindows(timeoutMs = 3e3) {
|
|
88
|
+
console.warn("\u26A0\uFE0F WindowManager.listRootWindows() is deprecated. Use session.computer.listRootWindows() instead.");
|
|
89
|
+
try {
|
|
90
|
+
const args = {
|
|
91
|
+
timeout_ms: timeoutMs
|
|
92
|
+
};
|
|
93
|
+
const response = await this.session.callMcpTool(
|
|
94
|
+
"list_root_windows",
|
|
95
|
+
args
|
|
96
|
+
);
|
|
97
|
+
if (!response.success) {
|
|
98
|
+
return {
|
|
99
|
+
requestId: response.requestId,
|
|
100
|
+
success: false,
|
|
101
|
+
windows: [],
|
|
102
|
+
errorMessage: response.errorMessage
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const windows = response.data ? this.parseWindowsFromJSON(response.data) : [];
|
|
106
|
+
return {
|
|
107
|
+
requestId: response.requestId,
|
|
108
|
+
success: true,
|
|
109
|
+
windows
|
|
110
|
+
};
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return {
|
|
113
|
+
requestId: "",
|
|
114
|
+
success: false,
|
|
115
|
+
windows: [],
|
|
116
|
+
errorMessage: `Failed to list root windows: ${error}`
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Lists all windows in the system.
|
|
122
|
+
* Corresponds to Python's list_all_windows() method
|
|
123
|
+
*
|
|
124
|
+
* @param timeoutMs - The timeout in milliseconds. Default is 3000ms.
|
|
125
|
+
* @returns WindowListResult with windows array and requestId
|
|
126
|
+
*
|
|
127
|
+
* @deprecated Use session.computer.listAllWindows() instead.
|
|
128
|
+
*/
|
|
129
|
+
async listAllWindows(timeoutMs = 3e3) {
|
|
130
|
+
console.warn("\u26A0\uFE0F WindowManager.listAllWindows() is deprecated. Use session.computer.listAllWindows() instead.");
|
|
131
|
+
try {
|
|
132
|
+
const args = {
|
|
133
|
+
timeout_ms: timeoutMs
|
|
134
|
+
};
|
|
135
|
+
const response = await this.session.callMcpTool(
|
|
136
|
+
"list_all_windows",
|
|
137
|
+
args
|
|
138
|
+
);
|
|
139
|
+
if (!response.success) {
|
|
140
|
+
return {
|
|
141
|
+
requestId: response.requestId,
|
|
142
|
+
success: false,
|
|
143
|
+
windows: [],
|
|
144
|
+
errorMessage: response.errorMessage
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const windows = response.data ? this.parseWindowsFromJSON(response.data) : [];
|
|
148
|
+
return {
|
|
149
|
+
requestId: response.requestId,
|
|
150
|
+
success: true,
|
|
151
|
+
windows
|
|
152
|
+
};
|
|
153
|
+
} catch (error) {
|
|
154
|
+
return {
|
|
155
|
+
requestId: "",
|
|
156
|
+
success: false,
|
|
157
|
+
windows: [],
|
|
158
|
+
errorMessage: `Failed to list all windows: ${error}`
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Gets information about a specific window.
|
|
164
|
+
* Corresponds to Python's get_window_info() method
|
|
165
|
+
*
|
|
166
|
+
* @param windowId - The ID of the window to get information for.
|
|
167
|
+
* @returns WindowInfoResult with window information and requestId
|
|
168
|
+
*
|
|
169
|
+
* @deprecated Use session.computer.getWindowInfo() instead.
|
|
170
|
+
*/
|
|
171
|
+
async getWindowInfo(windowId) {
|
|
172
|
+
console.warn("\u26A0\uFE0F WindowManager.getWindowInfo() is deprecated. Use session.computer.getWindowInfo() instead.");
|
|
173
|
+
try {
|
|
174
|
+
const args = {
|
|
175
|
+
window_id: windowId
|
|
176
|
+
};
|
|
177
|
+
const response = await this.session.callMcpTool(
|
|
178
|
+
"get_window_info",
|
|
179
|
+
args
|
|
180
|
+
);
|
|
181
|
+
if (!response.success) {
|
|
182
|
+
return {
|
|
183
|
+
requestId: response.requestId,
|
|
184
|
+
success: false,
|
|
185
|
+
errorMessage: response.errorMessage
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
let window = void 0;
|
|
189
|
+
if (response.data) {
|
|
190
|
+
const windows = this.parseWindowsFromJSON(response.data);
|
|
191
|
+
window = windows.length > 0 ? windows[0] : void 0;
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
requestId: response.requestId,
|
|
195
|
+
success: true,
|
|
196
|
+
window
|
|
197
|
+
};
|
|
198
|
+
} catch (error) {
|
|
199
|
+
return {
|
|
200
|
+
requestId: "",
|
|
201
|
+
success: false,
|
|
202
|
+
errorMessage: `Failed to get window info: ${error}`
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Activates a window by bringing it to the foreground.
|
|
208
|
+
* Corresponds to Python's activate_window() method
|
|
209
|
+
*
|
|
210
|
+
* @param windowId - The ID of the window to activate.
|
|
211
|
+
* @returns BoolResult with success status and requestId
|
|
212
|
+
*
|
|
213
|
+
* @deprecated Use session.computer.activateWindow() instead.
|
|
214
|
+
*/
|
|
215
|
+
async activateWindow(windowId) {
|
|
216
|
+
console.warn("\u26A0\uFE0F WindowManager.activateWindow() is deprecated. Use session.computer.activateWindow() instead.");
|
|
217
|
+
try {
|
|
218
|
+
const args = {
|
|
219
|
+
window_id: windowId
|
|
220
|
+
};
|
|
221
|
+
const response = await this.session.callMcpTool(
|
|
222
|
+
"activate_window",
|
|
223
|
+
args
|
|
224
|
+
);
|
|
225
|
+
if (!response.success) {
|
|
226
|
+
return {
|
|
227
|
+
requestId: response.requestId,
|
|
228
|
+
success: false,
|
|
229
|
+
errorMessage: response.errorMessage
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
requestId: response.requestId,
|
|
234
|
+
success: true,
|
|
235
|
+
data: true
|
|
236
|
+
};
|
|
237
|
+
} catch (error) {
|
|
238
|
+
return {
|
|
239
|
+
requestId: "",
|
|
240
|
+
success: false,
|
|
241
|
+
errorMessage: `Failed to activate window: ${error}`
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Maximizes a window.
|
|
247
|
+
* Corresponds to Python's maximize_window() method
|
|
248
|
+
*
|
|
249
|
+
* @param windowId - The ID of the window to maximize.
|
|
250
|
+
* @returns BoolResult with success status and requestId
|
|
251
|
+
*
|
|
252
|
+
* @deprecated Use session.computer.maximizeWindow() instead.
|
|
253
|
+
*/
|
|
254
|
+
async maximizeWindow(windowId) {
|
|
255
|
+
console.warn("\u26A0\uFE0F WindowManager.maximizeWindow() is deprecated. Use session.computer.maximizeWindow() instead.");
|
|
256
|
+
try {
|
|
257
|
+
const args = {
|
|
258
|
+
window_id: windowId
|
|
259
|
+
};
|
|
260
|
+
const response = await this.session.callMcpTool(
|
|
261
|
+
"maximize_window",
|
|
262
|
+
args
|
|
263
|
+
);
|
|
264
|
+
if (!response.success) {
|
|
265
|
+
return {
|
|
266
|
+
requestId: response.requestId,
|
|
267
|
+
success: false,
|
|
268
|
+
errorMessage: response.errorMessage
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
requestId: response.requestId,
|
|
273
|
+
success: true,
|
|
274
|
+
data: true
|
|
275
|
+
};
|
|
276
|
+
} catch (error) {
|
|
277
|
+
return {
|
|
278
|
+
requestId: "",
|
|
279
|
+
success: false,
|
|
280
|
+
errorMessage: `Failed to maximize window: ${error}`
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Minimizes a window.
|
|
286
|
+
* Corresponds to Python's minimize_window() method
|
|
287
|
+
*
|
|
288
|
+
* @param windowId - The ID of the window to minimize.
|
|
289
|
+
* @returns BoolResult with success status and requestId
|
|
290
|
+
*
|
|
291
|
+
* @deprecated Use session.computer.minimizeWindow() instead.
|
|
292
|
+
*/
|
|
293
|
+
async minimizeWindow(windowId) {
|
|
294
|
+
console.warn("\u26A0\uFE0F WindowManager.minimizeWindow() is deprecated. Use session.computer.minimizeWindow() instead.");
|
|
295
|
+
try {
|
|
296
|
+
const args = {
|
|
297
|
+
window_id: windowId
|
|
298
|
+
};
|
|
299
|
+
const response = await this.session.callMcpTool(
|
|
300
|
+
"minimize_window",
|
|
301
|
+
args
|
|
302
|
+
);
|
|
303
|
+
if (!response.success) {
|
|
304
|
+
return {
|
|
305
|
+
requestId: response.requestId,
|
|
306
|
+
success: false,
|
|
307
|
+
errorMessage: response.errorMessage
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
requestId: response.requestId,
|
|
312
|
+
success: true,
|
|
313
|
+
data: true
|
|
314
|
+
};
|
|
315
|
+
} catch (error) {
|
|
316
|
+
return {
|
|
317
|
+
requestId: "",
|
|
318
|
+
success: false,
|
|
319
|
+
errorMessage: `Failed to minimize window: ${error}`
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Restores a window by ID.
|
|
325
|
+
* Corresponds to Python's restore_window() method
|
|
326
|
+
*
|
|
327
|
+
* @param windowId The ID of the window to restore.
|
|
328
|
+
* @returns BoolResult with requestId
|
|
329
|
+
*/
|
|
330
|
+
async restoreWindow(windowId) {
|
|
331
|
+
try {
|
|
332
|
+
const args = {
|
|
333
|
+
window_id: windowId
|
|
334
|
+
};
|
|
335
|
+
const response = await this.session.callMcpTool(
|
|
336
|
+
"restore_window",
|
|
337
|
+
args
|
|
338
|
+
);
|
|
339
|
+
if (!response.success) {
|
|
340
|
+
return {
|
|
341
|
+
requestId: response.requestId,
|
|
342
|
+
success: false,
|
|
343
|
+
errorMessage: response.errorMessage
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
requestId: response.requestId,
|
|
348
|
+
success: true,
|
|
349
|
+
data: true
|
|
350
|
+
};
|
|
351
|
+
} catch (error) {
|
|
352
|
+
return {
|
|
353
|
+
requestId: "",
|
|
354
|
+
success: false,
|
|
355
|
+
errorMessage: `Failed to restore window: ${error}`
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Closes a window.
|
|
361
|
+
* Corresponds to Python's close_window() method
|
|
362
|
+
*
|
|
363
|
+
* @param windowId - The ID of the window to close.
|
|
364
|
+
* @returns BoolResult with success status and requestId
|
|
365
|
+
*
|
|
366
|
+
* @deprecated Use session.computer.closeWindow() instead.
|
|
367
|
+
*/
|
|
368
|
+
async closeWindow(windowId) {
|
|
369
|
+
console.warn("\u26A0\uFE0F WindowManager.closeWindow() is deprecated. Use session.computer.closeWindow() instead.");
|
|
370
|
+
try {
|
|
371
|
+
const args = {
|
|
372
|
+
window_id: windowId
|
|
373
|
+
};
|
|
374
|
+
const response = await this.session.callMcpTool(
|
|
375
|
+
"close_window",
|
|
376
|
+
args
|
|
377
|
+
);
|
|
378
|
+
if (!response.success) {
|
|
379
|
+
return {
|
|
380
|
+
requestId: response.requestId,
|
|
381
|
+
success: false,
|
|
382
|
+
errorMessage: response.errorMessage
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
requestId: response.requestId,
|
|
387
|
+
success: true,
|
|
388
|
+
data: true
|
|
389
|
+
};
|
|
390
|
+
} catch (error) {
|
|
391
|
+
return {
|
|
392
|
+
requestId: "",
|
|
393
|
+
success: false,
|
|
394
|
+
errorMessage: `Failed to close window: ${error}`
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Sets a window to fullscreen by ID.
|
|
400
|
+
* Corresponds to Python's fullscreen_window() method
|
|
401
|
+
*
|
|
402
|
+
* @param windowId The ID of the window to set to fullscreen.
|
|
403
|
+
* @returns BoolResult with requestId
|
|
404
|
+
*/
|
|
405
|
+
async fullscreenWindow(windowId) {
|
|
406
|
+
try {
|
|
407
|
+
const args = {
|
|
408
|
+
window_id: windowId
|
|
409
|
+
};
|
|
410
|
+
const response = await this.session.callMcpTool(
|
|
411
|
+
"fullscreen_window",
|
|
412
|
+
args
|
|
413
|
+
);
|
|
414
|
+
if (!response.success) {
|
|
415
|
+
return {
|
|
416
|
+
requestId: response.requestId,
|
|
417
|
+
success: false,
|
|
418
|
+
errorMessage: response.errorMessage
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
requestId: response.requestId,
|
|
423
|
+
success: true,
|
|
424
|
+
data: true
|
|
425
|
+
};
|
|
426
|
+
} catch (error) {
|
|
427
|
+
return {
|
|
428
|
+
requestId: "",
|
|
429
|
+
success: false,
|
|
430
|
+
errorMessage: `Failed to make window fullscreen: ${error}`
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Resizes a window to the specified dimensions.
|
|
436
|
+
* Corresponds to Python's resize_window() method
|
|
437
|
+
*
|
|
438
|
+
* @param windowId - The ID of the window to resize.
|
|
439
|
+
* @param width - The new width of the window.
|
|
440
|
+
* @param height - The new height of the window.
|
|
441
|
+
* @returns BoolResult with success status and requestId
|
|
442
|
+
*
|
|
443
|
+
* @deprecated Use session.computer.resizeWindow() instead.
|
|
444
|
+
*/
|
|
445
|
+
async resizeWindow(windowId, width, height) {
|
|
446
|
+
console.warn("\u26A0\uFE0F WindowManager.resizeWindow() is deprecated. Use session.computer.resizeWindow() instead.");
|
|
447
|
+
try {
|
|
448
|
+
const args = {
|
|
449
|
+
window_id: windowId,
|
|
450
|
+
width,
|
|
451
|
+
height
|
|
452
|
+
};
|
|
453
|
+
const response = await this.session.callMcpTool(
|
|
454
|
+
"resize_window",
|
|
455
|
+
args
|
|
456
|
+
);
|
|
457
|
+
if (!response.success) {
|
|
458
|
+
return {
|
|
459
|
+
requestId: response.requestId,
|
|
460
|
+
success: false,
|
|
461
|
+
errorMessage: response.errorMessage
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
requestId: response.requestId,
|
|
466
|
+
success: true,
|
|
467
|
+
data: true
|
|
468
|
+
};
|
|
469
|
+
} catch (error) {
|
|
470
|
+
return {
|
|
471
|
+
requestId: "",
|
|
472
|
+
success: false,
|
|
473
|
+
errorMessage: `Failed to resize window: ${error}`
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Moves a window to the specified position.
|
|
479
|
+
* Corresponds to Python's move_window() method
|
|
480
|
+
*
|
|
481
|
+
* @param windowId - The ID of the window to move.
|
|
482
|
+
* @param x - The new x coordinate of the window.
|
|
483
|
+
* @param y - The new y coordinate of the window.
|
|
484
|
+
* @returns BoolResult with success status and requestId
|
|
485
|
+
*
|
|
486
|
+
* @deprecated Use session.computer.moveWindow() instead.
|
|
487
|
+
*/
|
|
488
|
+
async moveWindow(windowId, x, y) {
|
|
489
|
+
console.warn("\u26A0\uFE0F WindowManager.moveWindow() is deprecated. Use session.computer.moveWindow() instead.");
|
|
490
|
+
try {
|
|
491
|
+
const args = {
|
|
492
|
+
window_id: windowId,
|
|
493
|
+
x,
|
|
494
|
+
y
|
|
495
|
+
};
|
|
496
|
+
const response = await this.session.callMcpTool(
|
|
497
|
+
"move_window",
|
|
498
|
+
args
|
|
499
|
+
);
|
|
500
|
+
if (!response.success) {
|
|
501
|
+
return {
|
|
502
|
+
requestId: response.requestId,
|
|
503
|
+
success: false,
|
|
504
|
+
errorMessage: response.errorMessage
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
return {
|
|
508
|
+
requestId: response.requestId,
|
|
509
|
+
success: true,
|
|
510
|
+
data: true
|
|
511
|
+
};
|
|
512
|
+
} catch (error) {
|
|
513
|
+
return {
|
|
514
|
+
requestId: "",
|
|
515
|
+
success: false,
|
|
516
|
+
errorMessage: `Failed to move window: ${error}`
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Enables or disables focus mode.
|
|
522
|
+
* Corresponds to Python's focus_mode() method
|
|
523
|
+
*
|
|
524
|
+
* @param on Whether to enable focus mode.
|
|
525
|
+
* @returns BoolResult with requestId
|
|
526
|
+
*/
|
|
527
|
+
async focusMode(on) {
|
|
528
|
+
try {
|
|
529
|
+
const args = {
|
|
530
|
+
on
|
|
531
|
+
};
|
|
532
|
+
const response = await this.session.callMcpTool(
|
|
533
|
+
"focus_mode",
|
|
534
|
+
args
|
|
535
|
+
);
|
|
536
|
+
if (!response.success) {
|
|
537
|
+
return {
|
|
538
|
+
requestId: response.requestId,
|
|
539
|
+
success: false,
|
|
540
|
+
errorMessage: response.errorMessage
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
return {
|
|
544
|
+
requestId: response.requestId,
|
|
545
|
+
success: true,
|
|
546
|
+
data: true
|
|
547
|
+
};
|
|
548
|
+
} catch (error) {
|
|
549
|
+
return {
|
|
550
|
+
requestId: "",
|
|
551
|
+
success: false,
|
|
552
|
+
errorMessage: `Failed to toggle focus mode: ${error}`
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Gets the currently active window.
|
|
558
|
+
* Corresponds to Python's get_active_window() method
|
|
559
|
+
*
|
|
560
|
+
* @param timeoutMs - The timeout in milliseconds. Default is 3000ms.
|
|
561
|
+
* @returns WindowInfoResult with active window information and requestId
|
|
562
|
+
*
|
|
563
|
+
* @deprecated Use session.computer.getActiveWindow() instead.
|
|
564
|
+
*/
|
|
565
|
+
async getActiveWindow(timeoutMs = 3e3) {
|
|
566
|
+
console.warn("\u26A0\uFE0F WindowManager.getActiveWindow() is deprecated. Use session.computer.getActiveWindow() instead.");
|
|
567
|
+
try {
|
|
568
|
+
const args = {
|
|
569
|
+
timeout_ms: timeoutMs
|
|
570
|
+
};
|
|
571
|
+
const response = await this.session.callMcpTool(
|
|
572
|
+
"get_active_window",
|
|
573
|
+
args
|
|
574
|
+
);
|
|
575
|
+
if (!response.success) {
|
|
576
|
+
return {
|
|
577
|
+
requestId: response.requestId,
|
|
578
|
+
success: false,
|
|
579
|
+
errorMessage: response.errorMessage
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
let activeWindow = void 0;
|
|
583
|
+
if (response.data) {
|
|
584
|
+
const windows = this.parseWindowsFromJSON(response.data);
|
|
585
|
+
activeWindow = windows.length > 0 ? windows[0] : void 0;
|
|
586
|
+
}
|
|
587
|
+
return {
|
|
588
|
+
requestId: response.requestId,
|
|
589
|
+
success: true,
|
|
590
|
+
window: activeWindow
|
|
591
|
+
};
|
|
592
|
+
} catch (error) {
|
|
593
|
+
return {
|
|
594
|
+
requestId: "",
|
|
595
|
+
success: false,
|
|
596
|
+
errorMessage: `Failed to get active window: ${error}`
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
__name(_WindowManager, "WindowManager");
|
|
602
|
+
var WindowManager = _WindowManager;
|
|
603
|
+
|
|
604
|
+
export {
|
|
605
|
+
__name,
|
|
606
|
+
__require,
|
|
607
|
+
__commonJS,
|
|
608
|
+
__toESM,
|
|
609
|
+
init_esm_shims,
|
|
610
|
+
WindowManager
|
|
611
|
+
};
|
|
612
|
+
//# sourceMappingURL=chunk-HKUD6LHR.mjs.map
|