@daytonaio/sdk 0.7.2 → 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 +16 -2
- package/dist/Daytona.js +35 -22
- package/dist/Process.d.ts +17 -4
- package/dist/Process.js +23 -3
- package/dist/Workspace.d.ts +79 -0
- package/dist/Workspace.js +116 -0
- 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
|
|
@@ -84,11 +88,16 @@ export declare class Daytona {
|
|
|
84
88
|
* @returns {Promise<Workspace>} The workspace instance
|
|
85
89
|
*/
|
|
86
90
|
get(workspaceId: string): Promise<Workspace>;
|
|
91
|
+
/**
|
|
92
|
+
* Lists all workspaces
|
|
93
|
+
* @returns {Promise<Workspace[]>} The list of workspaces
|
|
94
|
+
*/
|
|
95
|
+
list(): Promise<Workspace[]>;
|
|
87
96
|
/**
|
|
88
97
|
* Starts a workspace
|
|
89
98
|
* @param {Workspace} workspace - The workspace to start
|
|
90
99
|
*/
|
|
91
|
-
start(workspace: Workspace): Promise<void>;
|
|
100
|
+
start(workspace: Workspace, timeout?: number): Promise<void>;
|
|
92
101
|
/**
|
|
93
102
|
* Stops a workspace
|
|
94
103
|
* @param {Workspace} workspace - The workspace to stop
|
|
@@ -101,6 +110,11 @@ export declare class Daytona {
|
|
|
101
110
|
* @returns {Promise<void>}
|
|
102
111
|
*/
|
|
103
112
|
remove(workspace: Workspace): Promise<void>;
|
|
104
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Gets the current workspace by ID
|
|
115
|
+
* @param {string} workspaceId - The ID of the workspace to retrieve
|
|
116
|
+
* @returns {Promise<Workspace>} The workspace instance
|
|
117
|
+
*/
|
|
118
|
+
getCurrentWorkspace(workspaceId: string): Promise<Workspace>;
|
|
105
119
|
private getCodeToolbox;
|
|
106
120
|
}
|
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
|
|
79
|
+
await workspace.waitUntilStarted(params === null || params === void 0 ? void 0 : params.timeout);
|
|
73
80
|
}
|
|
74
81
|
return workspace;
|
|
75
82
|
}
|
|
@@ -85,12 +92,27 @@ class Daytona {
|
|
|
85
92
|
const codeToolbox = this.getCodeToolbox(language);
|
|
86
93
|
return new Workspace_1.Workspace(workspaceId, workspaceInstance, this.workspaceApi, this.toolboxApi, codeToolbox);
|
|
87
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Lists all workspaces
|
|
97
|
+
* @returns {Promise<Workspace[]>} The list of workspaces
|
|
98
|
+
*/
|
|
99
|
+
async list() {
|
|
100
|
+
const response = await this.workspaceApi.listWorkspaces();
|
|
101
|
+
return response.data.map((workspace) => {
|
|
102
|
+
var _a;
|
|
103
|
+
const language = (_a = workspace.labels) === null || _a === void 0 ? void 0 : _a[`code-toolbox-language`];
|
|
104
|
+
if (language && !['python', 'javascript', 'typescript'].includes(language)) {
|
|
105
|
+
throw new Error(`Invalid code-toolbox-language: ${language}`);
|
|
106
|
+
}
|
|
107
|
+
return new Workspace_1.Workspace(workspace.id, workspace, this.workspaceApi, this.toolboxApi, this.getCodeToolbox(language));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
88
110
|
/**
|
|
89
111
|
* Starts a workspace
|
|
90
112
|
* @param {Workspace} workspace - The workspace to start
|
|
91
113
|
*/
|
|
92
|
-
async start(workspace) {
|
|
93
|
-
await
|
|
114
|
+
async start(workspace, timeout) {
|
|
115
|
+
await workspace.start(timeout);
|
|
94
116
|
}
|
|
95
117
|
/**
|
|
96
118
|
* Stops a workspace
|
|
@@ -98,7 +120,7 @@ class Daytona {
|
|
|
98
120
|
* @returns {Promise<void>}
|
|
99
121
|
*/
|
|
100
122
|
async stop(workspace) {
|
|
101
|
-
await
|
|
123
|
+
await workspace.stop();
|
|
102
124
|
}
|
|
103
125
|
/**
|
|
104
126
|
* Removes a workspace
|
|
@@ -108,22 +130,13 @@ class Daytona {
|
|
|
108
130
|
async remove(workspace) {
|
|
109
131
|
await this.workspaceApi.deleteWorkspace(workspace.id, true);
|
|
110
132
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
if (state === 'error') {
|
|
121
|
-
throw new Error(`Workspace failed to start with status: ${status}`);
|
|
122
|
-
}
|
|
123
|
-
await new Promise(resolve => setTimeout(resolve, 100)); // Wait 100 ms between checks
|
|
124
|
-
attempts++;
|
|
125
|
-
}
|
|
126
|
-
throw new Error('Workspace failed to become ready within the timeout period');
|
|
133
|
+
/**
|
|
134
|
+
* Gets the current workspace by ID
|
|
135
|
+
* @param {string} workspaceId - The ID of the workspace to retrieve
|
|
136
|
+
* @returns {Promise<Workspace>} The workspace instance
|
|
137
|
+
*/
|
|
138
|
+
async getCurrentWorkspace(workspaceId) {
|
|
139
|
+
return this.get(workspaceId);
|
|
127
140
|
}
|
|
128
141
|
getCodeToolbox(language) {
|
|
129
142
|
switch (language) {
|
package/dist/Process.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExecuteResponse, Session, SessionExecuteRequest, SessionExecuteResponse, ToolboxApi, Workspace } from '@daytonaio/api-client';
|
|
1
|
+
import { Command, ExecuteResponse, Session, SessionExecuteRequest, SessionExecuteResponse, ToolboxApi, Workspace } from '@daytonaio/api-client';
|
|
2
2
|
import { WorkspaceCodeToolbox } from './Workspace';
|
|
3
3
|
/**
|
|
4
4
|
* Handles process and code execution within a workspace
|
|
@@ -14,7 +14,7 @@ export declare class Process {
|
|
|
14
14
|
* @param {string} command - Command to execute
|
|
15
15
|
* @returns {Promise<ExecuteResponse>} Command execution results
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
executeCommand(command: string, cwd?: string, timeout?: number): Promise<ExecuteResponse>;
|
|
18
18
|
/**
|
|
19
19
|
* Executes code in the workspace using the appropriate language runtime
|
|
20
20
|
* @param {string} code - Code to execute
|
|
@@ -33,14 +33,27 @@ export declare class Process {
|
|
|
33
33
|
* @param {SessionExecuteRequest} req - Command to execute and async flag
|
|
34
34
|
* @returns {Promise<SessionExecuteResponse>} Command execution results
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
executeSessionCommand(sessionId: string, req: SessionExecuteRequest): Promise<SessionExecuteResponse>;
|
|
37
37
|
/**
|
|
38
38
|
* Gets the logs for a command in the session
|
|
39
39
|
* @param {string} sessionId - Unique identifier for the session
|
|
40
40
|
* @param {string} commandId - Unique identifier for the command
|
|
41
41
|
* @returns {Promise<string>} Command logs
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
getSessionCommandLogs(sessionId: string, commandId: string): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Gets the session
|
|
46
|
+
* @param {string} sessionId - Unique identifier for the session
|
|
47
|
+
* @returns {Promise<Session>} Session
|
|
48
|
+
*/
|
|
49
|
+
getSession(sessionId: string): Promise<Session>;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the session command
|
|
52
|
+
* @param {string} sessionId - Unique identifier for the session
|
|
53
|
+
* @param {string} commandId - Unique identifier for the command
|
|
54
|
+
* @returns {Promise<Command>} Session command
|
|
55
|
+
*/
|
|
56
|
+
getSessionCommand(sessionId: string, commandId: string): Promise<Command>;
|
|
44
57
|
/**
|
|
45
58
|
* Lists all sessions in the workspace
|
|
46
59
|
* @returns {Promise<Session[]>} List of sessions
|
package/dist/Process.js
CHANGED
|
@@ -16,10 +16,11 @@ class Process {
|
|
|
16
16
|
* @param {string} command - Command to execute
|
|
17
17
|
* @returns {Promise<ExecuteResponse>} Command execution results
|
|
18
18
|
*/
|
|
19
|
-
async
|
|
19
|
+
async executeCommand(command, cwd, timeout) {
|
|
20
20
|
const response = await this.toolboxApi.executeCommand(this.instance.id, {
|
|
21
21
|
command,
|
|
22
22
|
timeout,
|
|
23
|
+
cwd,
|
|
23
24
|
});
|
|
24
25
|
return response.data;
|
|
25
26
|
}
|
|
@@ -51,7 +52,7 @@ class Process {
|
|
|
51
52
|
* @param {SessionExecuteRequest} req - Command to execute and async flag
|
|
52
53
|
* @returns {Promise<SessionExecuteResponse>} Command execution results
|
|
53
54
|
*/
|
|
54
|
-
async
|
|
55
|
+
async executeSessionCommand(sessionId, req) {
|
|
55
56
|
const response = await this.toolboxApi.executeSessionCommand(this.instance.id, sessionId, req);
|
|
56
57
|
return response.data;
|
|
57
58
|
}
|
|
@@ -61,10 +62,29 @@ class Process {
|
|
|
61
62
|
* @param {string} commandId - Unique identifier for the command
|
|
62
63
|
* @returns {Promise<string>} Command logs
|
|
63
64
|
*/
|
|
64
|
-
async
|
|
65
|
+
async getSessionCommandLogs(sessionId, commandId) {
|
|
65
66
|
const response = await this.toolboxApi.getSessionCommandLogs(this.instance.id, sessionId, commandId);
|
|
66
67
|
return response.data;
|
|
67
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the session
|
|
71
|
+
* @param {string} sessionId - Unique identifier for the session
|
|
72
|
+
* @returns {Promise<Session>} Session
|
|
73
|
+
*/
|
|
74
|
+
async getSession(sessionId) {
|
|
75
|
+
const response = await this.toolboxApi.getSession(this.instance.id, sessionId);
|
|
76
|
+
return response.data;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets the session command
|
|
80
|
+
* @param {string} sessionId - Unique identifier for the session
|
|
81
|
+
* @param {string} commandId - Unique identifier for the command
|
|
82
|
+
* @returns {Promise<Command>} Session command
|
|
83
|
+
*/
|
|
84
|
+
async getSessionCommand(sessionId, commandId) {
|
|
85
|
+
const response = await this.toolboxApi.getSessionCommand(this.instance.id, sessionId, commandId);
|
|
86
|
+
return response.data;
|
|
87
|
+
}
|
|
68
88
|
/**
|
|
69
89
|
* Lists all sessions in the workspace
|
|
70
90
|
* @returns {Promise<Session[]>} List of sessions
|
package/dist/Workspace.d.ts
CHANGED
|
@@ -4,6 +4,52 @@ import { FileSystem } from './FileSystem';
|
|
|
4
4
|
import { Git } from './Git';
|
|
5
5
|
import { Process } from './Process';
|
|
6
6
|
import { LspLanguageId, LspServer } from './LspServer';
|
|
7
|
+
/**
|
|
8
|
+
* Resources allocated to a workspace
|
|
9
|
+
* @interface WorkspaceResources
|
|
10
|
+
*/
|
|
11
|
+
export interface WorkspaceResources {
|
|
12
|
+
/** CPU allocation */
|
|
13
|
+
cpu: string;
|
|
14
|
+
/** GPU allocation */
|
|
15
|
+
gpu: string | null;
|
|
16
|
+
/** Memory allocation */
|
|
17
|
+
memory: string;
|
|
18
|
+
/** Disk allocation */
|
|
19
|
+
disk: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Structured information about a workspace
|
|
23
|
+
* @interface WorkspaceInfo
|
|
24
|
+
*/
|
|
25
|
+
export interface WorkspaceInfo {
|
|
26
|
+
/** Unique identifier */
|
|
27
|
+
id: string;
|
|
28
|
+
/** Workspace name */
|
|
29
|
+
name: string;
|
|
30
|
+
/** Docker image */
|
|
31
|
+
image: string;
|
|
32
|
+
/** OS user */
|
|
33
|
+
user: string;
|
|
34
|
+
/** Environment variables */
|
|
35
|
+
env: Record<string, string>;
|
|
36
|
+
/** Workspace labels */
|
|
37
|
+
labels: Record<string, string>;
|
|
38
|
+
/** Public access flag */
|
|
39
|
+
public: boolean;
|
|
40
|
+
/** Target location */
|
|
41
|
+
target: string;
|
|
42
|
+
/** Resource allocations */
|
|
43
|
+
resources: WorkspaceResources;
|
|
44
|
+
/** Current state */
|
|
45
|
+
state: string;
|
|
46
|
+
/** Error reason if any */
|
|
47
|
+
errorReason: string | null;
|
|
48
|
+
/** Snapshot state */
|
|
49
|
+
snapshotState: string | null;
|
|
50
|
+
/** Snapshot state creation timestamp */
|
|
51
|
+
snapshotStateCreatedAt: Date | null;
|
|
52
|
+
}
|
|
7
53
|
/**
|
|
8
54
|
* Interface defining methods that a code toolbox must implement
|
|
9
55
|
* @interface WorkspaceCodeToolbox
|
|
@@ -50,4 +96,37 @@ export declare class Workspace {
|
|
|
50
96
|
* @returns {LspServer} A new LSP server instance
|
|
51
97
|
*/
|
|
52
98
|
createLspServer(languageId: LspLanguageId, pathToProject: string): LspServer;
|
|
99
|
+
/**
|
|
100
|
+
* Sets labels for the workspace
|
|
101
|
+
* @param {Record<string, string>} labels - The labels to set
|
|
102
|
+
*/
|
|
103
|
+
setLabels(labels: Record<string, string>): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Starts the workspace
|
|
106
|
+
* @returns {Promise<void>}
|
|
107
|
+
*/
|
|
108
|
+
start(timeout?: number): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Stops the workspace
|
|
111
|
+
* @returns {Promise<void>}
|
|
112
|
+
*/
|
|
113
|
+
stop(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Deletes the workspace
|
|
116
|
+
* @returns {Promise<void>}
|
|
117
|
+
*/
|
|
118
|
+
delete(): Promise<void>;
|
|
119
|
+
waitUntilStarted(timeout?: number): Promise<void>;
|
|
120
|
+
waitUntilStopped(): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Get structured information about the workspace
|
|
123
|
+
* @returns {Promise<WorkspaceInfo>} Structured workspace information
|
|
124
|
+
*/
|
|
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>;
|
|
53
132
|
}
|
package/dist/Workspace.js
CHANGED
|
@@ -47,5 +47,121 @@ class Workspace {
|
|
|
47
47
|
createLspServer(languageId, pathToProject) {
|
|
48
48
|
return new LspServer_1.LspServer(languageId, pathToProject, this.toolboxApi, this.instance);
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Sets labels for the workspace
|
|
52
|
+
* @param {Record<string, string>} labels - The labels to set
|
|
53
|
+
*/
|
|
54
|
+
async setLabels(labels) {
|
|
55
|
+
await this.workspaceApi.replaceLabels(this.instance.id, { labels });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Starts the workspace
|
|
59
|
+
* @returns {Promise<void>}
|
|
60
|
+
*/
|
|
61
|
+
async start(timeout) {
|
|
62
|
+
if (timeout != undefined && timeout < 0) {
|
|
63
|
+
throw new Error('Timeout must be a non-negative number');
|
|
64
|
+
}
|
|
65
|
+
await this.workspaceApi.startWorkspace(this.instance.id);
|
|
66
|
+
await this.waitUntilStarted(timeout);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Stops the workspace
|
|
70
|
+
* @returns {Promise<void>}
|
|
71
|
+
*/
|
|
72
|
+
async stop() {
|
|
73
|
+
await this.workspaceApi.stopWorkspace(this.instance.id);
|
|
74
|
+
await this.waitUntilStopped();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Deletes the workspace
|
|
78
|
+
* @returns {Promise<void>}
|
|
79
|
+
*/
|
|
80
|
+
async delete() {
|
|
81
|
+
await this.workspaceApi.deleteWorkspace(this.instance.id, true);
|
|
82
|
+
}
|
|
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)) {
|
|
90
|
+
const response = await this.workspaceApi.getWorkspace(this.id);
|
|
91
|
+
const state = response.data.state;
|
|
92
|
+
if (state === 'started') {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (state === 'error') {
|
|
96
|
+
throw new Error(`Workspace failed to start with status: ${state}`);
|
|
97
|
+
}
|
|
98
|
+
await new Promise(resolve => setTimeout(resolve, checkInterval));
|
|
99
|
+
}
|
|
100
|
+
throw new Error('Workspace failed to become ready within the timeout period');
|
|
101
|
+
}
|
|
102
|
+
async waitUntilStopped() {
|
|
103
|
+
const maxAttempts = 600;
|
|
104
|
+
let attempts = 0;
|
|
105
|
+
while (attempts < maxAttempts) {
|
|
106
|
+
const response = await this.workspaceApi.getWorkspace(this.id);
|
|
107
|
+
const state = response.data.state;
|
|
108
|
+
if (state === 'stopped') {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (state === 'error') {
|
|
112
|
+
throw new Error(`Workspace failed to stop with status: ${state}`);
|
|
113
|
+
}
|
|
114
|
+
await new Promise(resolve => setTimeout(resolve, 100)); // Wait 100 ms between checks
|
|
115
|
+
attempts++;
|
|
116
|
+
}
|
|
117
|
+
throw new Error('Workspace failed to become stopped within the timeout period');
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get structured information about the workspace
|
|
121
|
+
* @returns {Promise<WorkspaceInfo>} Structured workspace information
|
|
122
|
+
*/
|
|
123
|
+
async info() {
|
|
124
|
+
var _a;
|
|
125
|
+
const response = await this.workspaceApi.getWorkspace(this.id);
|
|
126
|
+
const instance = response.data;
|
|
127
|
+
const providerMetadata = JSON.parse(((_a = instance.info) === null || _a === void 0 ? void 0 : _a.providerMetadata) || '{}');
|
|
128
|
+
// Extract resources with defaults
|
|
129
|
+
const resourcesData = providerMetadata.resources || {};
|
|
130
|
+
const resources = {
|
|
131
|
+
cpu: String(resourcesData.cpu || '1'),
|
|
132
|
+
gpu: resourcesData.gpu ? String(resourcesData.gpu) : null,
|
|
133
|
+
memory: String(resourcesData.memory || '2Gi'),
|
|
134
|
+
disk: String(resourcesData.disk || '10Gi')
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
id: instance.id,
|
|
138
|
+
name: instance.name,
|
|
139
|
+
image: instance.image,
|
|
140
|
+
user: instance.user,
|
|
141
|
+
env: instance.env || {},
|
|
142
|
+
labels: instance.labels || {},
|
|
143
|
+
public: instance.public || false,
|
|
144
|
+
target: instance.target,
|
|
145
|
+
resources,
|
|
146
|
+
state: providerMetadata.state || '',
|
|
147
|
+
errorReason: providerMetadata.errorReason || null,
|
|
148
|
+
snapshotState: providerMetadata.snapshotState || null,
|
|
149
|
+
snapshotStateCreatedAt: providerMetadata.snapshotStateCreatedAt
|
|
150
|
+
? new Date(providerMetadata.snapshotStateCreatedAt)
|
|
151
|
+
: null
|
|
152
|
+
};
|
|
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
|
+
}
|
|
50
166
|
}
|
|
51
167
|
exports.Workspace = Workspace;
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daytonaio/sdk",
|
|
3
|
-
"version": "0.
|
|
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.9.8",
|
|
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
|
}
|