@hanzo/runtime 0.0.0-dev
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/LICENSE +190 -0
- package/README.md +147 -0
- package/hanzo-runtime-0.0.0-dev.tgz +0 -0
- package/hooks/typedoc-custom.mjs +640 -0
- package/jest.config.js +15 -0
- package/package.json +24 -0
- package/project.json +57 -0
- package/src/ComputerUse.ts +618 -0
- package/src/Daytona.ts +644 -0
- package/src/FileSystem.ts +414 -0
- package/src/Git.ts +303 -0
- package/src/Image.ts +643 -0
- package/src/LspServer.ts +245 -0
- package/src/ObjectStorage.ts +232 -0
- package/src/Process.ts +357 -0
- package/src/Sandbox.ts +478 -0
- package/src/Snapshot.ts +260 -0
- package/src/Volume.ts +110 -0
- package/src/code-toolbox/SandboxPythonCodeToolbox.ts +366 -0
- package/src/code-toolbox/SandboxTsCodeToolbox.ts +17 -0
- package/src/errors/DaytonaError.ts +15 -0
- package/src/index.ts +50 -0
- package/src/types/Charts.ts +193 -0
- package/src/types/ExecuteResponse.ts +33 -0
- package/src/utils/ArtifactParser.ts +58 -0
- package/src/utils/Path.ts +25 -0
- package/src/utils/Stream.ts +89 -0
- package/tsconfig.json +16 -0
- package/tsconfig.lib.json +16 -0
- package/tsconfig.spec.json +12 -0
- package/typedoc.json +33 -0
package/project.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sdk-typescript",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"projectType": "library",
|
|
5
|
+
"sourceRoot": "libs/sdk-typescript",
|
|
6
|
+
"targets": {
|
|
7
|
+
"docs": {
|
|
8
|
+
"executor": "nx:run-commands",
|
|
9
|
+
"options": {
|
|
10
|
+
"cwd": "{projectRoot}",
|
|
11
|
+
"command": "npm run docs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"build": {
|
|
15
|
+
"executor": "@nx/js:tsc",
|
|
16
|
+
"inputs": ["default", "{projectRoot}/package.json"],
|
|
17
|
+
"outputs": ["{options.outputPath}"],
|
|
18
|
+
"options": {
|
|
19
|
+
"outputPath": "dist/libs/sdk-typescript",
|
|
20
|
+
"tsConfig": "{projectRoot}/tsconfig.lib.json",
|
|
21
|
+
"packageJson": "{projectRoot}/package.json",
|
|
22
|
+
"main": "{projectRoot}/src/index.ts",
|
|
23
|
+
"updateBuildableProjectDepsInPackageJson": true,
|
|
24
|
+
"assets": ["{projectRoot}/README.md"]
|
|
25
|
+
},
|
|
26
|
+
"dependsOn": [
|
|
27
|
+
{
|
|
28
|
+
"target": "build",
|
|
29
|
+
"projects": ["api-client"]
|
|
30
|
+
},
|
|
31
|
+
"set-version"
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"set-version": {
|
|
35
|
+
"executor": "nx:run-commands",
|
|
36
|
+
"options": {
|
|
37
|
+
"cwd": "{projectRoot}",
|
|
38
|
+
"command": "if [ -n \"$NPM_PKG_VERSION\" ] || [ -n \"$DEFAULT_PACKAGE_VERSION\" ]; then VER=${NPM_PKG_VERSION:-$DEFAULT_PACKAGE_VERSION}; npm version \"$VER\" --allow-same-version && echo \"Changed version to $VER\"; else echo \"Using version from package.json\"; fi"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"publish": {
|
|
42
|
+
"executor": "nx:run-commands",
|
|
43
|
+
"options": {
|
|
44
|
+
"cwd": "{workspaceRoot}/dist/libs/sdk-typescript",
|
|
45
|
+
"command": "npm publish --tag $NPM_TAG --access public --registry https://registry.npmjs.org/ --//registry.npmjs.org/:_authToken=$NPM_TOKEN",
|
|
46
|
+
"parallel": false
|
|
47
|
+
},
|
|
48
|
+
"dependsOn": [
|
|
49
|
+
"build",
|
|
50
|
+
{
|
|
51
|
+
"target": "publish",
|
|
52
|
+
"projects": ["api-client"]
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ToolboxApi,
|
|
8
|
+
MousePosition,
|
|
9
|
+
MouseMoveRequest,
|
|
10
|
+
MouseMoveResponse,
|
|
11
|
+
MouseClickRequest,
|
|
12
|
+
MouseClickResponse,
|
|
13
|
+
MouseDragRequest,
|
|
14
|
+
MouseDragResponse,
|
|
15
|
+
MouseScrollRequest,
|
|
16
|
+
KeyboardTypeRequest,
|
|
17
|
+
KeyboardPressRequest,
|
|
18
|
+
KeyboardHotkeyRequest,
|
|
19
|
+
ScreenshotResponse,
|
|
20
|
+
RegionScreenshotResponse,
|
|
21
|
+
CompressedScreenshotResponse,
|
|
22
|
+
DisplayInfoResponse,
|
|
23
|
+
WindowsResponse,
|
|
24
|
+
ComputerUseStartResponse,
|
|
25
|
+
ComputerUseStopResponse,
|
|
26
|
+
ComputerUseStatusResponse,
|
|
27
|
+
ProcessStatusResponse,
|
|
28
|
+
ProcessRestartResponse,
|
|
29
|
+
ProcessLogsResponse,
|
|
30
|
+
ProcessErrorsResponse,
|
|
31
|
+
} from '@daytonaio/api-client'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Interface for region coordinates used in screenshot operations
|
|
35
|
+
*/
|
|
36
|
+
export interface ScreenshotRegion {
|
|
37
|
+
x: number
|
|
38
|
+
y: number
|
|
39
|
+
width: number
|
|
40
|
+
height: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Interface for screenshot compression options
|
|
45
|
+
*/
|
|
46
|
+
export interface ScreenshotOptions {
|
|
47
|
+
showCursor?: boolean
|
|
48
|
+
format?: string
|
|
49
|
+
quality?: number
|
|
50
|
+
scale?: number
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Mouse operations for computer use functionality
|
|
55
|
+
*/
|
|
56
|
+
export class Mouse {
|
|
57
|
+
constructor(
|
|
58
|
+
private readonly sandboxId: string,
|
|
59
|
+
private readonly toolboxApi: ToolboxApi,
|
|
60
|
+
) {}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Gets the current mouse cursor position
|
|
64
|
+
*
|
|
65
|
+
* @returns {Promise<MousePosition>} Current mouse position with x and y coordinates
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const position = await sandbox.computerUse.mouse.getPosition();
|
|
70
|
+
* console.log(`Mouse is at: ${position.x}, ${position.y}`);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
public async getPosition(): Promise<MousePosition> {
|
|
74
|
+
const response = await this.toolboxApi.getMousePosition(this.sandboxId)
|
|
75
|
+
return response.data
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Moves the mouse cursor to the specified coordinates
|
|
80
|
+
*
|
|
81
|
+
* @param {number} x - The x coordinate to move to
|
|
82
|
+
* @param {number} y - The y coordinate to move to
|
|
83
|
+
* @returns {Promise<MouseMoveResponse>} Move operation result
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const result = await sandbox.computerUse.mouse.move(100, 200);
|
|
88
|
+
* console.log(`Mouse moved to: ${result.x}, ${result.y}`);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
public async move(x: number, y: number): Promise<MouseMoveResponse> {
|
|
92
|
+
const request: MouseMoveRequest = { x, y }
|
|
93
|
+
const response = await this.toolboxApi.moveMouse(this.sandboxId, request)
|
|
94
|
+
return response.data
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Clicks the mouse at the specified coordinates
|
|
99
|
+
*
|
|
100
|
+
* @param {number} x - The x coordinate to click at
|
|
101
|
+
* @param {number} y - The y coordinate to click at
|
|
102
|
+
* @param {string} [button='left'] - The mouse button to click ('left', 'right', 'middle')
|
|
103
|
+
* @param {boolean} [double=false] - Whether to perform a double-click
|
|
104
|
+
* @returns {Promise<MouseClickResponse>} Click operation result
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // Single left click
|
|
109
|
+
* const result = await sandbox.computerUse.mouse.click(100, 200);
|
|
110
|
+
*
|
|
111
|
+
* // Double click
|
|
112
|
+
* const doubleClick = await sandbox.computerUse.mouse.click(100, 200, 'left', true);
|
|
113
|
+
*
|
|
114
|
+
* // Right click
|
|
115
|
+
* const rightClick = await sandbox.computerUse.mouse.click(100, 200, 'right');
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
public async click(x: number, y: number, button = 'left', double = false): Promise<MouseClickResponse> {
|
|
119
|
+
const request: MouseClickRequest = { x, y, button, double }
|
|
120
|
+
const response = await this.toolboxApi.clickMouse(this.sandboxId, request)
|
|
121
|
+
return response.data
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Drags the mouse from start coordinates to end coordinates
|
|
126
|
+
*
|
|
127
|
+
* @param {number} startX - The starting x coordinate
|
|
128
|
+
* @param {number} startY - The starting y coordinate
|
|
129
|
+
* @param {number} endX - The ending x coordinate
|
|
130
|
+
* @param {number} endY - The ending y coordinate
|
|
131
|
+
* @param {string} [button='left'] - The mouse button to use for dragging
|
|
132
|
+
* @returns {Promise<MouseDragResponse>} Drag operation result
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const result = await sandbox.computerUse.mouse.drag(50, 50, 150, 150);
|
|
137
|
+
* console.log(`Dragged from ${result.from.x},${result.from.y} to ${result.to.x},${result.to.y}`);
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
public async drag(
|
|
141
|
+
startX: number,
|
|
142
|
+
startY: number,
|
|
143
|
+
endX: number,
|
|
144
|
+
endY: number,
|
|
145
|
+
button = 'left',
|
|
146
|
+
): Promise<MouseDragResponse> {
|
|
147
|
+
const request: MouseDragRequest = { startX, startY, endX, endY, button }
|
|
148
|
+
const response = await this.toolboxApi.dragMouse(this.sandboxId, request)
|
|
149
|
+
return response.data
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Scrolls the mouse wheel at the specified coordinates
|
|
154
|
+
*
|
|
155
|
+
* @param {number} x - The x coordinate to scroll at
|
|
156
|
+
* @param {number} y - The y coordinate to scroll at
|
|
157
|
+
* @param {'up' | 'down'} direction - The direction to scroll
|
|
158
|
+
* @param {number} [amount=1] - The amount to scroll
|
|
159
|
+
* @returns {Promise<boolean>} Whether the scroll operation was successful
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* // Scroll up
|
|
164
|
+
* const scrollUp = await sandbox.computerUse.mouse.scroll(100, 200, 'up', 3);
|
|
165
|
+
*
|
|
166
|
+
* // Scroll down
|
|
167
|
+
* const scrollDown = await sandbox.computerUse.mouse.scroll(100, 200, 'down', 5);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
public async scroll(x: number, y: number, direction: 'up' | 'down', amount = 1): Promise<boolean> {
|
|
171
|
+
const request: MouseScrollRequest = { x, y, direction, amount }
|
|
172
|
+
const response = await this.toolboxApi.scrollMouse(this.sandboxId, request)
|
|
173
|
+
return response.data.success
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Keyboard operations for computer use functionality
|
|
179
|
+
*/
|
|
180
|
+
export class Keyboard {
|
|
181
|
+
constructor(
|
|
182
|
+
private readonly sandboxId: string,
|
|
183
|
+
private readonly toolboxApi: ToolboxApi,
|
|
184
|
+
) {}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Types the specified text
|
|
188
|
+
*
|
|
189
|
+
* @param {string} text - The text to type
|
|
190
|
+
* @param {number} [delay=0] - Delay between characters in milliseconds
|
|
191
|
+
* @throws {DaytonaError} If the type operation fails
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* try {
|
|
196
|
+
* await sandbox.computerUse.keyboard.type('Hello, World!');
|
|
197
|
+
* console.log('Operation success');
|
|
198
|
+
* } catch (e) {
|
|
199
|
+
* console.log('Operation failed:', e);
|
|
200
|
+
* }
|
|
201
|
+
*
|
|
202
|
+
* // With delay between characters
|
|
203
|
+
* try {
|
|
204
|
+
* await sandbox.computerUse.keyboard.type('Slow typing', 100);
|
|
205
|
+
* console.log('Operation success');
|
|
206
|
+
* } catch (e) {
|
|
207
|
+
* console.log('Operation failed:', e);
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
public async type(text: string, delay?: number): Promise<void> {
|
|
212
|
+
const request: KeyboardTypeRequest = { text, delay }
|
|
213
|
+
await this.toolboxApi.typeText(this.sandboxId, request)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Presses a key with optional modifiers
|
|
218
|
+
*
|
|
219
|
+
* @param {string} key - The key to press (e.g., 'Enter', 'Escape', 'Tab', 'a', 'A')
|
|
220
|
+
* @param {string[]} [modifiers=[]] - Modifier keys ('ctrl', 'alt', 'meta', 'shift')
|
|
221
|
+
* @throws {DaytonaError} If the press operation fails
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* // Press Enter
|
|
226
|
+
* try {
|
|
227
|
+
* await sandbox.computerUse.keyboard.press('Return');
|
|
228
|
+
* console.log('Operation success');
|
|
229
|
+
* } catch (e) {
|
|
230
|
+
* console.log('Operation failed:', e);
|
|
231
|
+
* }
|
|
232
|
+
*
|
|
233
|
+
* // Press Ctrl+C
|
|
234
|
+
* try {
|
|
235
|
+
* await sandbox.computerUse.keyboard.press('c', ['ctrl']);
|
|
236
|
+
* console.log('Operation success');
|
|
237
|
+
* } catch (e) {
|
|
238
|
+
* console.log('Operation failed:', e);
|
|
239
|
+
* }
|
|
240
|
+
*
|
|
241
|
+
* // Press Ctrl+Shift+T
|
|
242
|
+
* try {
|
|
243
|
+
* await sandbox.computerUse.keyboard.press('t', ['ctrl', 'shift']);
|
|
244
|
+
* console.log('Operation success');
|
|
245
|
+
* } catch (e) {
|
|
246
|
+
* console.log('Operation failed:', e);
|
|
247
|
+
* }
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
public async press(key: string, modifiers: string[] = []): Promise<void> {
|
|
251
|
+
const request: KeyboardPressRequest = { key, modifiers }
|
|
252
|
+
await this.toolboxApi.pressKey(this.sandboxId, request)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Presses a hotkey combination
|
|
257
|
+
*
|
|
258
|
+
* @param {string} keys - The hotkey combination (e.g., 'ctrl+c', 'alt+tab', 'cmd+shift+t')
|
|
259
|
+
* @throws {DaytonaError} If the hotkey operation fails
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* // Copy
|
|
264
|
+
* try {
|
|
265
|
+
* await sandbox.computerUse.keyboard.hotkey('ctrl+c');
|
|
266
|
+
* console.log('Operation success');
|
|
267
|
+
* } catch (e) {
|
|
268
|
+
* console.log('Operation failed:', e);
|
|
269
|
+
* }
|
|
270
|
+
*
|
|
271
|
+
* // Paste
|
|
272
|
+
* try {
|
|
273
|
+
* await sandbox.computerUse.keyboard.hotkey('ctrl+v');
|
|
274
|
+
* console.log('Operation success');
|
|
275
|
+
* } catch (e) {
|
|
276
|
+
* console.log('Operation failed:', e);
|
|
277
|
+
* }
|
|
278
|
+
*
|
|
279
|
+
* // Alt+Tab
|
|
280
|
+
* try {
|
|
281
|
+
* await sandbox.computerUse.keyboard.hotkey('alt+tab');
|
|
282
|
+
* console.log('Operation success');
|
|
283
|
+
* } catch (e) {
|
|
284
|
+
* console.log('Operation failed:', e);
|
|
285
|
+
* }
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
public async hotkey(keys: string): Promise<void> {
|
|
289
|
+
const request: KeyboardHotkeyRequest = { keys }
|
|
290
|
+
await this.toolboxApi.pressHotkey(this.sandboxId, request)
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Screenshot operations for computer use functionality
|
|
296
|
+
*/
|
|
297
|
+
export class Screenshot {
|
|
298
|
+
constructor(
|
|
299
|
+
private readonly sandboxId: string,
|
|
300
|
+
private readonly toolboxApi: ToolboxApi,
|
|
301
|
+
) {}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Takes a screenshot of the entire screen
|
|
305
|
+
*
|
|
306
|
+
* @param {boolean} [showCursor=false] - Whether to show the cursor in the screenshot
|
|
307
|
+
* @returns {Promise<ScreenshotResponse>} Screenshot data with base64 encoded image
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```typescript
|
|
311
|
+
* const screenshot = await sandbox.computerUse.screenshot.takeFullScreen();
|
|
312
|
+
* console.log(`Screenshot size: ${screenshot.width}x${screenshot.height}`);
|
|
313
|
+
*
|
|
314
|
+
* // With cursor visible
|
|
315
|
+
* const withCursor = await sandbox.computerUse.screenshot.takeFullScreen(true);
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
public async takeFullScreen(showCursor = false): Promise<ScreenshotResponse> {
|
|
319
|
+
const response = await this.toolboxApi.takeScreenshot(this.sandboxId, undefined, showCursor)
|
|
320
|
+
return response.data
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Takes a screenshot of a specific region
|
|
325
|
+
*
|
|
326
|
+
* @param {ScreenshotRegion} region - The region to capture
|
|
327
|
+
* @param {boolean} [showCursor=false] - Whether to show the cursor in the screenshot
|
|
328
|
+
* @returns {Promise<RegionScreenshotResponse>} Screenshot data with base64 encoded image
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```typescript
|
|
332
|
+
* const region = { x: 100, y: 100, width: 300, height: 200 };
|
|
333
|
+
* const screenshot = await sandbox.computerUse.screenshot.takeRegion(region);
|
|
334
|
+
* console.log(`Captured region: ${screenshot.region.width}x${screenshot.region.height}`);
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
public async takeRegion(region: ScreenshotRegion, showCursor = false): Promise<RegionScreenshotResponse> {
|
|
338
|
+
const response = await this.toolboxApi.takeRegionScreenshot(
|
|
339
|
+
this.sandboxId,
|
|
340
|
+
region.height,
|
|
341
|
+
region.width,
|
|
342
|
+
region.y,
|
|
343
|
+
region.x,
|
|
344
|
+
undefined,
|
|
345
|
+
showCursor,
|
|
346
|
+
)
|
|
347
|
+
return response.data
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Takes a compressed screenshot of the entire screen
|
|
352
|
+
*
|
|
353
|
+
* @param {ScreenshotOptions} [options={}] - Compression and display options
|
|
354
|
+
* @returns {Promise<CompressedScreenshotResponse>} Compressed screenshot data
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```typescript
|
|
358
|
+
* // Default compression
|
|
359
|
+
* const screenshot = await sandbox.computerUse.screenshot.takeCompressed();
|
|
360
|
+
*
|
|
361
|
+
* // High quality JPEG
|
|
362
|
+
* const jpeg = await sandbox.computerUse.screenshot.takeCompressed({
|
|
363
|
+
* format: 'jpeg',
|
|
364
|
+
* quality: 95,
|
|
365
|
+
* showCursor: true
|
|
366
|
+
* });
|
|
367
|
+
*
|
|
368
|
+
* // Scaled down PNG
|
|
369
|
+
* const scaled = await sandbox.computerUse.screenshot.takeCompressed({
|
|
370
|
+
* format: 'png',
|
|
371
|
+
* scale: 0.5
|
|
372
|
+
* });
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
public async takeCompressed(options: ScreenshotOptions = {}): Promise<CompressedScreenshotResponse> {
|
|
376
|
+
const response = await this.toolboxApi.takeCompressedScreenshot(
|
|
377
|
+
this.sandboxId,
|
|
378
|
+
undefined,
|
|
379
|
+
options.scale,
|
|
380
|
+
options.quality,
|
|
381
|
+
options.format,
|
|
382
|
+
options.showCursor,
|
|
383
|
+
)
|
|
384
|
+
return response.data
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Takes a compressed screenshot of a specific region
|
|
389
|
+
*
|
|
390
|
+
* @param {ScreenshotRegion} region - The region to capture
|
|
391
|
+
* @param {ScreenshotOptions} [options={}] - Compression and display options
|
|
392
|
+
* @returns {Promise<CompressedScreenshotResponse>} Compressed screenshot data
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* const region = { x: 0, y: 0, width: 800, height: 600 };
|
|
397
|
+
* const screenshot = await sandbox.computerUse.screenshot.takeCompressedRegion(region, {
|
|
398
|
+
* format: 'webp',
|
|
399
|
+
* quality: 80,
|
|
400
|
+
* showCursor: true
|
|
401
|
+
* });
|
|
402
|
+
* console.log(`Compressed size: ${screenshot.size_bytes} bytes`);
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
public async takeCompressedRegion(
|
|
406
|
+
region: ScreenshotRegion,
|
|
407
|
+
options: ScreenshotOptions = {},
|
|
408
|
+
): Promise<CompressedScreenshotResponse> {
|
|
409
|
+
const response = await this.toolboxApi.takeCompressedRegionScreenshot(
|
|
410
|
+
this.sandboxId,
|
|
411
|
+
region.height,
|
|
412
|
+
region.width,
|
|
413
|
+
region.y,
|
|
414
|
+
region.x,
|
|
415
|
+
undefined,
|
|
416
|
+
options.scale,
|
|
417
|
+
options.quality,
|
|
418
|
+
options.format,
|
|
419
|
+
options.showCursor,
|
|
420
|
+
)
|
|
421
|
+
return response.data
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Display operations for computer use functionality
|
|
427
|
+
*/
|
|
428
|
+
export class Display {
|
|
429
|
+
constructor(
|
|
430
|
+
private readonly sandboxId: string,
|
|
431
|
+
private readonly toolboxApi: ToolboxApi,
|
|
432
|
+
) {}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Gets information about the displays
|
|
436
|
+
*
|
|
437
|
+
* @returns {Promise<DisplayInfoResponse>} Display information including primary display and all available displays
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```typescript
|
|
441
|
+
* const info = await sandbox.computerUse.display.getInfo();
|
|
442
|
+
* console.log(`Primary display: ${info.primary_display.width}x${info.primary_display.height}`);
|
|
443
|
+
* console.log(`Total displays: ${info.total_displays}`);
|
|
444
|
+
* info.displays.forEach((display, index) => {
|
|
445
|
+
* console.log(`Display ${index}: ${display.width}x${display.height} at ${display.x},${display.y}`);
|
|
446
|
+
* });
|
|
447
|
+
* ```
|
|
448
|
+
*/
|
|
449
|
+
public async getInfo(): Promise<DisplayInfoResponse> {
|
|
450
|
+
const response = await this.toolboxApi.getDisplayInfo(this.sandboxId)
|
|
451
|
+
return response.data
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Gets the list of open windows
|
|
456
|
+
*
|
|
457
|
+
* @returns {Promise<WindowsResponse>} List of open windows with their IDs and titles
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* ```typescript
|
|
461
|
+
* const windows = await sandbox.computerUse.display.getWindows();
|
|
462
|
+
* console.log(`Found ${windows.count} open windows:`);
|
|
463
|
+
* windows.windows.forEach(window => {
|
|
464
|
+
* console.log(`- ${window.title} (ID: ${window.id})`);
|
|
465
|
+
* });
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
public async getWindows(): Promise<WindowsResponse> {
|
|
469
|
+
const response = await this.toolboxApi.getWindows(this.sandboxId)
|
|
470
|
+
return response.data
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Computer Use functionality for interacting with the desktop environment.
|
|
476
|
+
*
|
|
477
|
+
* Provides access to mouse, keyboard, screenshot, and display operations
|
|
478
|
+
* for automating desktop interactions within a sandbox.
|
|
479
|
+
*
|
|
480
|
+
* @property {Mouse} mouse - Mouse operations interface
|
|
481
|
+
* @property {Keyboard} keyboard - Keyboard operations interface
|
|
482
|
+
* @property {Screenshot} screenshot - Screenshot operations interface
|
|
483
|
+
* @property {Display} display - Display operations interface
|
|
484
|
+
*
|
|
485
|
+
* @class
|
|
486
|
+
*/
|
|
487
|
+
export class ComputerUse {
|
|
488
|
+
public readonly mouse: Mouse
|
|
489
|
+
public readonly keyboard: Keyboard
|
|
490
|
+
public readonly screenshot: Screenshot
|
|
491
|
+
public readonly display: Display
|
|
492
|
+
|
|
493
|
+
constructor(
|
|
494
|
+
private readonly sandboxId: string,
|
|
495
|
+
private readonly toolboxApi: ToolboxApi,
|
|
496
|
+
) {
|
|
497
|
+
this.mouse = new Mouse(sandboxId, toolboxApi)
|
|
498
|
+
this.keyboard = new Keyboard(sandboxId, toolboxApi)
|
|
499
|
+
this.screenshot = new Screenshot(sandboxId, toolboxApi)
|
|
500
|
+
this.display = new Display(sandboxId, toolboxApi)
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Starts all computer use processes (Xvfb, xfce4, x11vnc, novnc)
|
|
505
|
+
*
|
|
506
|
+
* @returns {Promise<ComputerUseStartResponse>} Computer use start response
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* ```typescript
|
|
510
|
+
* const result = await sandbox.computerUse.start();
|
|
511
|
+
* console.log('Computer use processes started:', result.message);
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
public async start(): Promise<ComputerUseStartResponse> {
|
|
515
|
+
const response = await this.toolboxApi.startComputerUse(this.sandboxId)
|
|
516
|
+
return response.data
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Stops all computer use processes
|
|
521
|
+
*
|
|
522
|
+
* @returns {Promise<ComputerUseStopResponse>} Computer use stop response
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
* ```typescript
|
|
526
|
+
* const result = await sandbox.computerUse.stop();
|
|
527
|
+
* console.log('Computer use processes stopped:', result.message);
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
public async stop(): Promise<ComputerUseStopResponse> {
|
|
531
|
+
const response = await this.toolboxApi.stopComputerUse(this.sandboxId)
|
|
532
|
+
return response.data
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Gets the status of all computer use processes
|
|
537
|
+
*
|
|
538
|
+
* @returns {Promise<ComputerUseStatusResponse>} Status information about all VNC desktop processes
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* ```typescript
|
|
542
|
+
* const status = await sandbox.computerUse.getStatus();
|
|
543
|
+
* console.log('Computer use status:', status.status);
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
public async getStatus(): Promise<ComputerUseStatusResponse> {
|
|
547
|
+
const response = await this.toolboxApi.getComputerUseStatus(this.sandboxId)
|
|
548
|
+
return response.data
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Gets the status of a specific VNC process
|
|
553
|
+
*
|
|
554
|
+
* @param {string} processName - Name of the process to check
|
|
555
|
+
* @returns {Promise<ProcessStatusResponse>} Status information about the specific process
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```typescript
|
|
559
|
+
* const xvfbStatus = await sandbox.computerUse.getProcessStatus('xvfb');
|
|
560
|
+
* const noVncStatus = await sandbox.computerUse.getProcessStatus('novnc');
|
|
561
|
+
* ```
|
|
562
|
+
*/
|
|
563
|
+
public async getProcessStatus(processName: string): Promise<ProcessStatusResponse> {
|
|
564
|
+
const response = await this.toolboxApi.getProcessStatus(processName, this.sandboxId)
|
|
565
|
+
return response.data
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Restarts a specific VNC process
|
|
570
|
+
*
|
|
571
|
+
* @param {string} processName - Name of the process to restart
|
|
572
|
+
* @returns {Promise<ProcessRestartResponse>} Process restart response
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```typescript
|
|
576
|
+
* const result = await sandbox.computerUse.restartProcess('xfce4');
|
|
577
|
+
* console.log('XFCE4 process restarted:', result.message);
|
|
578
|
+
* ```
|
|
579
|
+
*/
|
|
580
|
+
public async restartProcess(processName: string): Promise<ProcessRestartResponse> {
|
|
581
|
+
const response = await this.toolboxApi.restartProcess(processName, this.sandboxId)
|
|
582
|
+
return response.data
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Gets logs for a specific VNC process
|
|
587
|
+
*
|
|
588
|
+
* @param {string} processName - Name of the process to get logs for
|
|
589
|
+
* @returns {Promise<ProcessLogsResponse>} Process logs
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```typescript
|
|
593
|
+
* const logsResp = await sandbox.computerUse.getProcessLogs('novnc');
|
|
594
|
+
* console.log('NoVNC logs:', logsResp.logs);
|
|
595
|
+
* ```
|
|
596
|
+
*/
|
|
597
|
+
public async getProcessLogs(processName: string): Promise<ProcessLogsResponse> {
|
|
598
|
+
const response = await this.toolboxApi.getProcessLogs(processName, this.sandboxId)
|
|
599
|
+
return response.data
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Gets error logs for a specific VNC process
|
|
604
|
+
*
|
|
605
|
+
* @param {string} processName - Name of the process to get error logs for
|
|
606
|
+
* @returns {Promise<ProcessErrorsResponse>} Process error logs
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```typescript
|
|
610
|
+
* const errorsResp = await sandbox.computerUse.getProcessErrors('x11vnc');
|
|
611
|
+
* console.log('X11VNC errors:', errorsResp.errors);
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
public async getProcessErrors(processName: string): Promise<ProcessErrorsResponse> {
|
|
615
|
+
const response = await this.toolboxApi.getProcessErrors(processName, this.sandboxId)
|
|
616
|
+
return response.data
|
|
617
|
+
}
|
|
618
|
+
}
|