@daytonaio/sdk 0.7.2 → 0.9.0
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/Daytona.d.ts +11 -1
- package/dist/Daytona.js +25 -19
- package/dist/Process.d.ts +17 -4
- package/dist/Process.js +23 -3
- package/dist/Workspace.d.ts +73 -0
- package/dist/Workspace.js +99 -0
- package/package.json +2 -2
package/dist/Daytona.d.ts
CHANGED
|
@@ -84,6 +84,11 @@ export declare class Daytona {
|
|
|
84
84
|
* @returns {Promise<Workspace>} The workspace instance
|
|
85
85
|
*/
|
|
86
86
|
get(workspaceId: string): Promise<Workspace>;
|
|
87
|
+
/**
|
|
88
|
+
* Lists all workspaces
|
|
89
|
+
* @returns {Promise<Workspace[]>} The list of workspaces
|
|
90
|
+
*/
|
|
91
|
+
list(): Promise<Workspace[]>;
|
|
87
92
|
/**
|
|
88
93
|
* Starts a workspace
|
|
89
94
|
* @param {Workspace} workspace - The workspace to start
|
|
@@ -101,6 +106,11 @@ export declare class Daytona {
|
|
|
101
106
|
* @returns {Promise<void>}
|
|
102
107
|
*/
|
|
103
108
|
remove(workspace: Workspace): Promise<void>;
|
|
104
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Gets the current workspace by ID
|
|
111
|
+
* @param {string} workspaceId - The ID of the workspace to retrieve
|
|
112
|
+
* @returns {Promise<Workspace>} The workspace instance
|
|
113
|
+
*/
|
|
114
|
+
getCurrentWorkspace(workspaceId: string): Promise<Workspace>;
|
|
105
115
|
private getCodeToolbox;
|
|
106
116
|
}
|
package/dist/Daytona.js
CHANGED
|
@@ -69,7 +69,7 @@ class Daytona {
|
|
|
69
69
|
const workspaceInstance = reponse.data;
|
|
70
70
|
const workspace = new Workspace_1.Workspace(workspaceId, workspaceInstance, this.workspaceApi, this.toolboxApi, codeToolbox);
|
|
71
71
|
if (!(params === null || params === void 0 ? void 0 : params.async)) {
|
|
72
|
-
await
|
|
72
|
+
await workspace.waitUntilStarted();
|
|
73
73
|
}
|
|
74
74
|
return workspace;
|
|
75
75
|
}
|
|
@@ -85,12 +85,27 @@ class Daytona {
|
|
|
85
85
|
const codeToolbox = this.getCodeToolbox(language);
|
|
86
86
|
return new Workspace_1.Workspace(workspaceId, workspaceInstance, this.workspaceApi, this.toolboxApi, codeToolbox);
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Lists all workspaces
|
|
90
|
+
* @returns {Promise<Workspace[]>} The list of workspaces
|
|
91
|
+
*/
|
|
92
|
+
async list() {
|
|
93
|
+
const response = await this.workspaceApi.listWorkspaces();
|
|
94
|
+
return response.data.map((workspace) => {
|
|
95
|
+
var _a;
|
|
96
|
+
const language = (_a = workspace.labels) === null || _a === void 0 ? void 0 : _a[`code-toolbox-language`];
|
|
97
|
+
if (language && !['python', 'javascript', 'typescript'].includes(language)) {
|
|
98
|
+
throw new Error(`Invalid code-toolbox-language: ${language}`);
|
|
99
|
+
}
|
|
100
|
+
return new Workspace_1.Workspace(workspace.id, workspace, this.workspaceApi, this.toolboxApi, this.getCodeToolbox(language));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
88
103
|
/**
|
|
89
104
|
* Starts a workspace
|
|
90
105
|
* @param {Workspace} workspace - The workspace to start
|
|
91
106
|
*/
|
|
92
107
|
async start(workspace) {
|
|
93
|
-
await
|
|
108
|
+
await workspace.start();
|
|
94
109
|
}
|
|
95
110
|
/**
|
|
96
111
|
* Stops a workspace
|
|
@@ -98,7 +113,7 @@ class Daytona {
|
|
|
98
113
|
* @returns {Promise<void>}
|
|
99
114
|
*/
|
|
100
115
|
async stop(workspace) {
|
|
101
|
-
await
|
|
116
|
+
await workspace.stop();
|
|
102
117
|
}
|
|
103
118
|
/**
|
|
104
119
|
* Removes a workspace
|
|
@@ -108,22 +123,13 @@ class Daytona {
|
|
|
108
123
|
async remove(workspace) {
|
|
109
124
|
await this.workspaceApi.deleteWorkspace(workspace.id, true);
|
|
110
125
|
}
|
|
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');
|
|
126
|
+
/**
|
|
127
|
+
* Gets the current workspace by ID
|
|
128
|
+
* @param {string} workspaceId - The ID of the workspace to retrieve
|
|
129
|
+
* @returns {Promise<Workspace>} The workspace instance
|
|
130
|
+
*/
|
|
131
|
+
async getCurrentWorkspace(workspaceId) {
|
|
132
|
+
return this.get(workspaceId);
|
|
127
133
|
}
|
|
128
134
|
getCodeToolbox(language) {
|
|
129
135
|
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,31 @@ 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(): 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(): 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>;
|
|
53
126
|
}
|
package/dist/Workspace.js
CHANGED
|
@@ -47,5 +47,104 @@ 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() {
|
|
62
|
+
await this.workspaceApi.startWorkspace(this.instance.id);
|
|
63
|
+
await this.waitUntilStarted();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Stops the workspace
|
|
67
|
+
* @returns {Promise<void>}
|
|
68
|
+
*/
|
|
69
|
+
async stop() {
|
|
70
|
+
await this.workspaceApi.stopWorkspace(this.instance.id);
|
|
71
|
+
await this.waitUntilStopped();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Deletes the workspace
|
|
75
|
+
* @returns {Promise<void>}
|
|
76
|
+
*/
|
|
77
|
+
async delete() {
|
|
78
|
+
await this.workspaceApi.deleteWorkspace(this.instance.id, true);
|
|
79
|
+
}
|
|
80
|
+
async waitUntilStarted() {
|
|
81
|
+
const maxAttempts = 600;
|
|
82
|
+
let attempts = 0;
|
|
83
|
+
while (attempts < maxAttempts) {
|
|
84
|
+
const response = await this.workspaceApi.getWorkspace(this.id);
|
|
85
|
+
const state = response.data.state;
|
|
86
|
+
if (state === 'started') {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (state === 'error') {
|
|
90
|
+
throw new Error(`Workspace failed to start with status: ${status}`);
|
|
91
|
+
}
|
|
92
|
+
await new Promise(resolve => setTimeout(resolve, 100)); // Wait 100 ms between checks
|
|
93
|
+
attempts++;
|
|
94
|
+
}
|
|
95
|
+
throw new Error('Workspace failed to become ready within the timeout period');
|
|
96
|
+
}
|
|
97
|
+
async waitUntilStopped() {
|
|
98
|
+
const maxAttempts = 600;
|
|
99
|
+
let attempts = 0;
|
|
100
|
+
while (attempts < maxAttempts) {
|
|
101
|
+
const response = await this.workspaceApi.getWorkspace(this.id);
|
|
102
|
+
const state = response.data.state;
|
|
103
|
+
if (state === 'stopped') {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (state === 'error') {
|
|
107
|
+
throw new Error(`Workspace failed to stop with status: ${status}`);
|
|
108
|
+
}
|
|
109
|
+
await new Promise(resolve => setTimeout(resolve, 100)); // Wait 100 ms between checks
|
|
110
|
+
attempts++;
|
|
111
|
+
}
|
|
112
|
+
throw new Error('Workspace failed to become stopped within the timeout period');
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get structured information about the workspace
|
|
116
|
+
* @returns {Promise<WorkspaceInfo>} Structured workspace information
|
|
117
|
+
*/
|
|
118
|
+
async info() {
|
|
119
|
+
var _a;
|
|
120
|
+
const response = await this.workspaceApi.getWorkspace(this.id);
|
|
121
|
+
const instance = response.data;
|
|
122
|
+
const providerMetadata = JSON.parse(((_a = instance.info) === null || _a === void 0 ? void 0 : _a.providerMetadata) || '{}');
|
|
123
|
+
// Extract resources with defaults
|
|
124
|
+
const resourcesData = providerMetadata.resources || {};
|
|
125
|
+
const resources = {
|
|
126
|
+
cpu: String(resourcesData.cpu || '1'),
|
|
127
|
+
gpu: resourcesData.gpu ? String(resourcesData.gpu) : null,
|
|
128
|
+
memory: String(resourcesData.memory || '2Gi'),
|
|
129
|
+
disk: String(resourcesData.disk || '10Gi')
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
id: instance.id,
|
|
133
|
+
name: instance.name,
|
|
134
|
+
image: instance.image,
|
|
135
|
+
user: instance.user,
|
|
136
|
+
env: instance.env || {},
|
|
137
|
+
labels: instance.labels || {},
|
|
138
|
+
public: instance.public || false,
|
|
139
|
+
target: instance.target,
|
|
140
|
+
resources,
|
|
141
|
+
state: providerMetadata.state || '',
|
|
142
|
+
errorReason: providerMetadata.errorReason || null,
|
|
143
|
+
snapshotState: providerMetadata.snapshotState || null,
|
|
144
|
+
snapshotStateCreatedAt: providerMetadata.snapshotStateCreatedAt
|
|
145
|
+
? new Date(providerMetadata.snapshotStateCreatedAt)
|
|
146
|
+
: null
|
|
147
|
+
};
|
|
148
|
+
}
|
|
50
149
|
}
|
|
51
150
|
exports.Workspace = Workspace;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daytonaio/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Daytona client library for AI Agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
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.
|
|
32
|
+
"@daytonaio/api-client": "~0.12.2",
|
|
33
33
|
"jest": "^29.5.0",
|
|
34
34
|
"ts-jest": "^29.1.0",
|
|
35
35
|
"typescript": "^5.0.0",
|