@daytonaio/sdk 0.9.0 → 0.9.2
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 +4 -4
- package/dist/Daytona.d.ts +5 -1
- package/dist/Daytona.js +12 -5
- package/dist/Workspace.d.ts +8 -2
- package/dist/Workspace.js +27 -10
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -34,13 +34,13 @@ To use the SDK, you'll need two essential pieces of information:
|
|
|
34
34
|
You can install the package using npm:
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
npm install @
|
|
37
|
+
npm install @daytonaio/sdk
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
Or using yarn:
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
|
-
yarn add @
|
|
43
|
+
yarn add @daytonaio/sdk
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
## Quick Start
|
|
@@ -48,7 +48,7 @@ yarn add @daytona/sdk
|
|
|
48
48
|
Here's a simple example of using the SDK:
|
|
49
49
|
|
|
50
50
|
```typescript
|
|
51
|
-
import { Daytona } from '@
|
|
51
|
+
import { Daytona } from '@daytonaio/sdk'
|
|
52
52
|
|
|
53
53
|
// Initialize the Daytona client
|
|
54
54
|
const daytona = new Daytona()
|
|
@@ -76,7 +76,7 @@ console.log(response.result)
|
|
|
76
76
|
The SDK can be configured using environment variables or by passing a configuration object:
|
|
77
77
|
|
|
78
78
|
```typescript
|
|
79
|
-
import { Daytona, DaytonaConfig } from '@
|
|
79
|
+
import { Daytona, DaytonaConfig } from '@daytonaio/sdk'
|
|
80
80
|
|
|
81
81
|
const config: DaytonaConfig = {
|
|
82
82
|
apiKey: 'your-api-key',
|
package/dist/Daytona.d.ts
CHANGED
|
@@ -55,6 +55,10 @@ export type CreateWorkspaceParams = {
|
|
|
55
55
|
resources?: WorkspaceResources;
|
|
56
56
|
/** If true, will not wait for the workspace to be ready before returning */
|
|
57
57
|
async?: boolean;
|
|
58
|
+
/** Timeout in seconds, for the workspace to be ready (0 means no timeout) */
|
|
59
|
+
timeout?: number;
|
|
60
|
+
/** Auto-stop interval in minutes (0 means disabled) (must be a non-negative integer) */
|
|
61
|
+
autoStopInterval?: number;
|
|
58
62
|
};
|
|
59
63
|
/**
|
|
60
64
|
* Main class for interacting with Daytona Server API
|
|
@@ -93,7 +97,7 @@ export declare class Daytona {
|
|
|
93
97
|
* Starts a workspace
|
|
94
98
|
* @param {Workspace} workspace - The workspace to start
|
|
95
99
|
*/
|
|
96
|
-
start(workspace: Workspace): Promise<void>;
|
|
100
|
+
start(workspace: Workspace, timeout?: number): Promise<void>;
|
|
97
101
|
/**
|
|
98
102
|
* Stops a workspace
|
|
99
103
|
* @param {Workspace} workspace - The workspace to stop
|
package/dist/Daytona.js
CHANGED
|
@@ -48,13 +48,19 @@ class Daytona {
|
|
|
48
48
|
*/
|
|
49
49
|
async create(params) {
|
|
50
50
|
var _a, _b, _c, _d;
|
|
51
|
+
if ((params === null || params === void 0 ? void 0 : params.autoStopInterval) !== undefined && (!Number.isInteger(params.autoStopInterval) || params.autoStopInterval < 0)) {
|
|
52
|
+
throw new Error('autoStopInterval must be a non-negative integer');
|
|
53
|
+
}
|
|
51
54
|
const workspaceId = (params === null || params === void 0 ? void 0 : params.id) || `sandbox-${(0, uuid_1.v4)().slice(0, 8)}`;
|
|
52
55
|
const codeToolbox = this.getCodeToolbox(params === null || params === void 0 ? void 0 : params.language);
|
|
53
56
|
const labels = (params === null || params === void 0 ? void 0 : params.labels) || {};
|
|
54
57
|
if (params === null || params === void 0 ? void 0 : params.language) {
|
|
55
58
|
labels[`code-toolbox-language`] = params.language;
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
if ((params === null || params === void 0 ? void 0 : params.timeout) && params.timeout < 0) {
|
|
61
|
+
throw new Error('Timeout must be a non-negative number');
|
|
62
|
+
}
|
|
63
|
+
const response = await this.workspaceApi.createWorkspace({
|
|
58
64
|
id: workspaceId,
|
|
59
65
|
name: workspaceId, // todo: remove this after project refactor
|
|
60
66
|
image: params === null || params === void 0 ? void 0 : params.image,
|
|
@@ -65,11 +71,12 @@ class Daytona {
|
|
|
65
71
|
gpu: (_b = params === null || params === void 0 ? void 0 : params.resources) === null || _b === void 0 ? void 0 : _b.gpu,
|
|
66
72
|
memory: (_c = params === null || params === void 0 ? void 0 : params.resources) === null || _c === void 0 ? void 0 : _c.memory,
|
|
67
73
|
disk: (_d = params === null || params === void 0 ? void 0 : params.resources) === null || _d === void 0 ? void 0 : _d.disk,
|
|
74
|
+
autoStopInterval: params === null || params === void 0 ? void 0 : params.autoStopInterval,
|
|
68
75
|
});
|
|
69
|
-
const workspaceInstance =
|
|
76
|
+
const workspaceInstance = response.data;
|
|
70
77
|
const workspace = new Workspace_1.Workspace(workspaceId, workspaceInstance, this.workspaceApi, this.toolboxApi, codeToolbox);
|
|
71
78
|
if (!(params === null || params === void 0 ? void 0 : params.async)) {
|
|
72
|
-
await workspace.waitUntilStarted();
|
|
79
|
+
await workspace.waitUntilStarted(params === null || params === void 0 ? void 0 : params.timeout);
|
|
73
80
|
}
|
|
74
81
|
return workspace;
|
|
75
82
|
}
|
|
@@ -104,8 +111,8 @@ class Daytona {
|
|
|
104
111
|
* Starts a workspace
|
|
105
112
|
* @param {Workspace} workspace - The workspace to start
|
|
106
113
|
*/
|
|
107
|
-
async start(workspace) {
|
|
108
|
-
await workspace.start();
|
|
114
|
+
async start(workspace, timeout) {
|
|
115
|
+
await workspace.start(timeout);
|
|
109
116
|
}
|
|
110
117
|
/**
|
|
111
118
|
* Stops a workspace
|
package/dist/Workspace.d.ts
CHANGED
|
@@ -105,7 +105,7 @@ export declare class Workspace {
|
|
|
105
105
|
* Starts the workspace
|
|
106
106
|
* @returns {Promise<void>}
|
|
107
107
|
*/
|
|
108
|
-
start(): Promise<void>;
|
|
108
|
+
start(timeout?: number): Promise<void>;
|
|
109
109
|
/**
|
|
110
110
|
* Stops the workspace
|
|
111
111
|
* @returns {Promise<void>}
|
|
@@ -116,11 +116,17 @@ export declare class Workspace {
|
|
|
116
116
|
* @returns {Promise<void>}
|
|
117
117
|
*/
|
|
118
118
|
delete(): Promise<void>;
|
|
119
|
-
waitUntilStarted(): Promise<void>;
|
|
119
|
+
waitUntilStarted(timeout?: number): Promise<void>;
|
|
120
120
|
waitUntilStopped(): Promise<void>;
|
|
121
121
|
/**
|
|
122
122
|
* Get structured information about the workspace
|
|
123
123
|
* @returns {Promise<WorkspaceInfo>} Structured workspace information
|
|
124
124
|
*/
|
|
125
125
|
info(): Promise<WorkspaceInfo>;
|
|
126
|
+
/**
|
|
127
|
+
* Sets the auto-stop interval for the workspace
|
|
128
|
+
* @param {number} interval - Number of minutes after which the workspace will automatically stop (must be an integer). Set to 0 to disable auto-stop.
|
|
129
|
+
* @throws {Error} If interval is negative
|
|
130
|
+
*/
|
|
131
|
+
setAutostopInterval(interval: number): Promise<void>;
|
|
126
132
|
}
|
package/dist/Workspace.js
CHANGED
|
@@ -58,9 +58,12 @@ class Workspace {
|
|
|
58
58
|
* Starts the workspace
|
|
59
59
|
* @returns {Promise<void>}
|
|
60
60
|
*/
|
|
61
|
-
async start() {
|
|
61
|
+
async start(timeout) {
|
|
62
|
+
if (timeout != undefined && timeout < 0) {
|
|
63
|
+
throw new Error('Timeout must be a non-negative number');
|
|
64
|
+
}
|
|
62
65
|
await this.workspaceApi.startWorkspace(this.instance.id);
|
|
63
|
-
await this.waitUntilStarted();
|
|
66
|
+
await this.waitUntilStarted(timeout);
|
|
64
67
|
}
|
|
65
68
|
/**
|
|
66
69
|
* Stops the workspace
|
|
@@ -77,20 +80,22 @@ class Workspace {
|
|
|
77
80
|
async delete() {
|
|
78
81
|
await this.workspaceApi.deleteWorkspace(this.instance.id, true);
|
|
79
82
|
}
|
|
80
|
-
async waitUntilStarted() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
async waitUntilStarted(timeout = 60) {
|
|
84
|
+
if (timeout < 0) {
|
|
85
|
+
throw new Error('Timeout must be a non-negative number');
|
|
86
|
+
}
|
|
87
|
+
const checkInterval = 100; // Wait 100 ms between checks
|
|
88
|
+
const startTime = Date.now();
|
|
89
|
+
while (timeout === 0 || (Date.now() - startTime) < (timeout * 1000)) {
|
|
84
90
|
const response = await this.workspaceApi.getWorkspace(this.id);
|
|
85
91
|
const state = response.data.state;
|
|
86
92
|
if (state === 'started') {
|
|
87
93
|
return;
|
|
88
94
|
}
|
|
89
95
|
if (state === 'error') {
|
|
90
|
-
throw new Error(`Workspace failed to start with status: ${
|
|
96
|
+
throw new Error(`Workspace failed to start with status: ${state}`);
|
|
91
97
|
}
|
|
92
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
93
|
-
attempts++;
|
|
98
|
+
await new Promise(resolve => setTimeout(resolve, checkInterval));
|
|
94
99
|
}
|
|
95
100
|
throw new Error('Workspace failed to become ready within the timeout period');
|
|
96
101
|
}
|
|
@@ -104,7 +109,7 @@ class Workspace {
|
|
|
104
109
|
return;
|
|
105
110
|
}
|
|
106
111
|
if (state === 'error') {
|
|
107
|
-
throw new Error(`Workspace failed to stop with status: ${
|
|
112
|
+
throw new Error(`Workspace failed to stop with status: ${state}`);
|
|
108
113
|
}
|
|
109
114
|
await new Promise(resolve => setTimeout(resolve, 100)); // Wait 100 ms between checks
|
|
110
115
|
attempts++;
|
|
@@ -146,5 +151,17 @@ class Workspace {
|
|
|
146
151
|
: null
|
|
147
152
|
};
|
|
148
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Sets the auto-stop interval for the workspace
|
|
156
|
+
* @param {number} interval - Number of minutes after which the workspace will automatically stop (must be an integer). Set to 0 to disable auto-stop.
|
|
157
|
+
* @throws {Error} If interval is negative
|
|
158
|
+
*/
|
|
159
|
+
async setAutostopInterval(interval) {
|
|
160
|
+
if (!Number.isInteger(interval) || interval < 0) {
|
|
161
|
+
throw new Error('autoStopInterval must be a non-negative integer');
|
|
162
|
+
}
|
|
163
|
+
await this.workspaceApi.setAutostopInterval(this.id, interval);
|
|
164
|
+
this.instance.autoStopInterval = interval;
|
|
165
|
+
}
|
|
149
166
|
}
|
|
150
167
|
exports.Workspace = Workspace;
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daytonaio/sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "Daytona client library for AI Agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/daytonaio/
|
|
9
|
+
"url": "git+https://github.com/daytonaio/sdk.git"
|
|
10
10
|
},
|
|
11
11
|
"author": "",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"bugs": {
|
|
14
|
-
"url": "https://github.com/daytonaio/
|
|
14
|
+
"url": "https://github.com/daytonaio/sdk/issues"
|
|
15
15
|
},
|
|
16
|
-
"homepage": "https://github.com/daytonaio/
|
|
16
|
+
"homepage": "https://github.com/daytonaio/sdk#readme",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "tsc",
|
|
19
19
|
"test": "jest",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"@babel/preset-typescript": "^7.22.0",
|
|
30
30
|
"@types/jest": "^29.5.0",
|
|
31
31
|
"@types/node": "^22.10.0",
|
|
32
|
-
"@daytonaio/api-client": "~0.12.2",
|
|
33
32
|
"jest": "^29.5.0",
|
|
34
33
|
"ts-jest": "^29.1.0",
|
|
35
34
|
"typescript": "^5.0.0",
|
|
@@ -37,6 +36,7 @@
|
|
|
37
36
|
"typedoc-plugin-markdown": "^3.17.1"
|
|
38
37
|
},
|
|
39
38
|
"dependencies": {
|
|
40
|
-
"uuid": "^11.0.3"
|
|
39
|
+
"uuid": "^11.0.3",
|
|
40
|
+
"@daytonaio/api-client": "~0.13.0"
|
|
41
41
|
}
|
|
42
42
|
}
|