@daytonaio/sdk 0.201.0 → 0.203.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/cjs/CodeInterpreter.js +1 -1
- package/cjs/CodeInterpreter.js.map +1 -1
- package/cjs/Daytona.d.ts +32 -6
- package/cjs/Daytona.js +35 -21
- package/cjs/Daytona.js.map +1 -1
- package/cjs/Image.js +14 -14
- package/cjs/Image.js.map +1 -1
- package/cjs/LspServer.js +1 -1
- package/cjs/LspServer.js.map +1 -1
- package/cjs/Process.d.ts +9 -3
- package/cjs/Process.js +26 -5
- package/cjs/Process.js.map +1 -1
- package/cjs/README.md +43 -0
- package/cjs/Sandbox.d.ts +23 -11
- package/cjs/Sandbox.js +54 -35
- package/cjs/Sandbox.js.map +1 -1
- package/cjs/Secret.d.ts +4 -4
- package/cjs/Secret.js +4 -4
- package/cjs/Snapshot.d.ts +3 -3
- package/cjs/Snapshot.js +3 -3
- package/cjs/errors/DaytonaError.d.ts +50 -4
- package/cjs/errors/DaytonaError.js +74 -7
- package/cjs/errors/DaytonaError.js.map +1 -1
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +6 -2
- package/cjs/index.js.map +1 -1
- package/esm/CodeInterpreter.js +2 -2
- package/esm/CodeInterpreter.js.map +1 -1
- package/esm/Daytona.d.ts +32 -6
- package/esm/Daytona.js +36 -22
- package/esm/Daytona.js.map +1 -1
- package/esm/Image.js +15 -15
- package/esm/Image.js.map +1 -1
- package/esm/LspServer.js +2 -2
- package/esm/LspServer.js.map +1 -1
- package/esm/Process.d.ts +9 -3
- package/esm/Process.js +26 -5
- package/esm/Process.js.map +1 -1
- package/esm/README.md +43 -0
- package/esm/Sandbox.d.ts +23 -11
- package/esm/Sandbox.js +55 -36
- package/esm/Sandbox.js.map +1 -1
- package/esm/Secret.d.ts +4 -4
- package/esm/Secret.js +4 -4
- package/esm/Snapshot.d.ts +3 -3
- package/esm/Snapshot.js +3 -3
- package/esm/errors/DaytonaError.d.ts +50 -4
- package/esm/errors/DaytonaError.js +70 -6
- package/esm/errors/DaytonaError.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.js +3 -1
- package/esm/index.js.map +1 -1
- package/esm/utils/Import.js +1 -1
- package/package.json +5 -5
package/esm/Process.d.ts
CHANGED
|
@@ -38,14 +38,18 @@ export declare class Process {
|
|
|
38
38
|
private readonly apiClient;
|
|
39
39
|
private readonly getPreviewToken;
|
|
40
40
|
private readonly language?;
|
|
41
|
-
|
|
41
|
+
private readonly requestTimeoutMs?;
|
|
42
|
+
constructor(clientConfig: Configuration, apiClient: ProcessApi, getPreviewToken: () => Promise<string>, language?: string, requestTimeoutMs?: number);
|
|
43
|
+
private execRequestOptions;
|
|
42
44
|
/**
|
|
43
45
|
* Executes a shell command in the Sandbox.
|
|
44
46
|
*
|
|
45
47
|
* @param {string} command - Shell command to execute
|
|
46
48
|
* @param {string} [cwd] - Working directory for command execution. If not specified, uses the sandbox working directory.
|
|
47
49
|
* @param {Record<string, string>} [env] - Environment variables to set for the command
|
|
48
|
-
* @param {number} [timeout] - Maximum time in seconds to wait for the command to complete.
|
|
50
|
+
* @param {number} [timeout] - Maximum time in seconds to wait for the command to complete. The command is
|
|
51
|
+
* terminated when it elapses. The HTTP request waits for the full timeout, even beyond
|
|
52
|
+
* the client-wide `requestTimeoutMs`; `0` disables the server-side limit.
|
|
49
53
|
* @returns {Promise<ExecuteResponse>} Command execution results containing:
|
|
50
54
|
* - exitCode: The command's exit status
|
|
51
55
|
* - result: Standard output from the command
|
|
@@ -70,7 +74,9 @@ export declare class Process {
|
|
|
70
74
|
*
|
|
71
75
|
* @param {string} code - Code to execute
|
|
72
76
|
* @param {CodeRunParams} params - Parameters for code execution
|
|
73
|
-
* @param {number} [timeout] - Maximum time in seconds to wait for execution to complete
|
|
77
|
+
* @param {number} [timeout] - Maximum time in seconds to wait for execution to complete. The execution is
|
|
78
|
+
* terminated when it elapses. The HTTP request waits for the full timeout, even beyond
|
|
79
|
+
* the client-wide `requestTimeoutMs`; `0` disables the server-side limit.
|
|
74
80
|
* @returns {Promise<ExecuteResponse>} Code execution results containing:
|
|
75
81
|
* - exitCode: The execution's exit status
|
|
76
82
|
* - result: Standard output from the code
|
package/esm/Process.js
CHANGED
|
@@ -16,6 +16,9 @@ export const MAX_PREFIX_LEN = Math.max(STDOUT_PREFIX_BYTES.length, STDERR_PREFIX
|
|
|
16
16
|
// Capability token advertised on PTY WebSocket connects so the daemon sends the
|
|
17
17
|
// "exited" control message; clients that don't send it only get the close frame.
|
|
18
18
|
const PTY_EXIT_CONTROL_SUBPROTOCOL = 'X-Daytona-Pty-Exit-Control';
|
|
19
|
+
// Pads the per-request HTTP deadline over the server-side execution timeout,
|
|
20
|
+
// mirroring Go's execContext (timeout + 5s) and Python's `_request_timeout = timeout + 5`.
|
|
21
|
+
const EXEC_TIMEOUT_BUFFER_MS = 5000;
|
|
19
22
|
/**
|
|
20
23
|
* Parameters for code execution.
|
|
21
24
|
*/
|
|
@@ -90,11 +93,25 @@ let Process = (() => {
|
|
|
90
93
|
apiClient;
|
|
91
94
|
getPreviewToken;
|
|
92
95
|
language;
|
|
93
|
-
|
|
96
|
+
requestTimeoutMs;
|
|
97
|
+
constructor(clientConfig, apiClient, getPreviewToken, language, requestTimeoutMs) {
|
|
94
98
|
this.clientConfig = clientConfig;
|
|
95
99
|
this.apiClient = apiClient;
|
|
96
100
|
this.getPreviewToken = getPreviewToken;
|
|
97
101
|
this.language = language;
|
|
102
|
+
this.requestTimeoutMs = requestTimeoutMs;
|
|
103
|
+
}
|
|
104
|
+
// With an explicit execution timeout the HTTP wait must not be capped by a
|
|
105
|
+
// configured bounded DaytonaConfig.requestTimeoutMs: the request is bounded by
|
|
106
|
+
// the execution timeout + buffer instead. A non-positive execution timeout
|
|
107
|
+
// leaves the wait uncapped (0 disables the server-side limit; negatives fail
|
|
108
|
+
// fast at the API). Without a configured positive requestTimeoutMs no override
|
|
109
|
+
// is applied, preserving the client-wide default deadline as-is.
|
|
110
|
+
execRequestOptions(timeout) {
|
|
111
|
+
if (timeout === undefined || this.requestTimeoutMs === undefined || this.requestTimeoutMs <= 0) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
return { timeout: timeout > 0 ? timeout * 1000 + EXEC_TIMEOUT_BUFFER_MS : 0 };
|
|
98
115
|
}
|
|
99
116
|
/**
|
|
100
117
|
* Executes a shell command in the Sandbox.
|
|
@@ -102,7 +119,9 @@ let Process = (() => {
|
|
|
102
119
|
* @param {string} command - Shell command to execute
|
|
103
120
|
* @param {string} [cwd] - Working directory for command execution. If not specified, uses the sandbox working directory.
|
|
104
121
|
* @param {Record<string, string>} [env] - Environment variables to set for the command
|
|
105
|
-
* @param {number} [timeout] - Maximum time in seconds to wait for the command to complete.
|
|
122
|
+
* @param {number} [timeout] - Maximum time in seconds to wait for the command to complete. The command is
|
|
123
|
+
* terminated when it elapses. The HTTP request waits for the full timeout, even beyond
|
|
124
|
+
* the client-wide `requestTimeoutMs`; `0` disables the server-side limit.
|
|
106
125
|
* @returns {Promise<ExecuteResponse>} Command execution results containing:
|
|
107
126
|
* - exitCode: The command's exit status
|
|
108
127
|
* - result: Standard output from the command
|
|
@@ -127,7 +146,7 @@ let Process = (() => {
|
|
|
127
146
|
timeout,
|
|
128
147
|
cwd: cwd,
|
|
129
148
|
envs: env && Object.keys(env).length ? env : undefined,
|
|
130
|
-
});
|
|
149
|
+
}, this.execRequestOptions(timeout));
|
|
131
150
|
const result = response.data.result ?? '';
|
|
132
151
|
return {
|
|
133
152
|
exitCode: response.data.exitCode ?? response.data.code,
|
|
@@ -142,7 +161,9 @@ let Process = (() => {
|
|
|
142
161
|
*
|
|
143
162
|
* @param {string} code - Code to execute
|
|
144
163
|
* @param {CodeRunParams} params - Parameters for code execution
|
|
145
|
-
* @param {number} [timeout] - Maximum time in seconds to wait for execution to complete
|
|
164
|
+
* @param {number} [timeout] - Maximum time in seconds to wait for execution to complete. The execution is
|
|
165
|
+
* terminated when it elapses. The HTTP request waits for the full timeout, even beyond
|
|
166
|
+
* the client-wide `requestTimeoutMs`; `0` disables the server-side limit.
|
|
146
167
|
* @returns {Promise<ExecuteResponse>} Code execution results containing:
|
|
147
168
|
* - exitCode: The execution's exit status
|
|
148
169
|
* - result: Standard output from the code
|
|
@@ -206,7 +227,7 @@ let Process = (() => {
|
|
|
206
227
|
envs: params?.env,
|
|
207
228
|
timeout,
|
|
208
229
|
};
|
|
209
|
-
const response = await this.apiClient.codeRun(request);
|
|
230
|
+
const response = await this.apiClient.codeRun(request, this.execRequestOptions(timeout));
|
|
210
231
|
const data = response.data;
|
|
211
232
|
const charts = data.artifacts?.charts?.map(parseChart) ?? [];
|
|
212
233
|
return {
|
package/esm/Process.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Process.js","sourceRoot":"","sources":["../../../../sdk-typescript/src/Process.ts"],"names":[],"mappings":"AAAA;;;GAGG;;
|
|
1
|
+
{"version":3,"file":"Process.js","sourceRoot":"","sources":["../../../../sdk-typescript/src/Process.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAaH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAE5D,6DAA6D;AAC7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AACrE,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CA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,MAAM,CAAC,UAAU,EAAE,CAAA;gBACzB,MAAM,CAAC,CAAA;YACT,CAAC;YACD,OAAO,MAAM,CAAA;QACf,CAAC;QAED;;;;;;;;;;;;;;;;;;;WAmBG;QAEI,KAAK,CAAC,eAAe;YAC1B,OAAO,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAA;QAC/D,CAAC;QAED;;;;;;;;;;;;;;;;;;;;;;;WAuBG;QAEI,KAAK,CAAC,iBAAiB,CAAC,SAAiB;YAC9C,OAAO,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;QAC7D,CAAC;QAED;;;;;;;;;;;;;;;;;;;;;;;;WAwBG;QAEI,KAAK,CAAC,cAAc,CAAC,SAAiB;YAC3C,MAAM,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAA;QAClD,CAAC;QAED;;;;;;;;;;;;;;;;;;;;;;;;WAwBG;QAEI,KAAK,CAAC,gBAAgB,CAAC,SAAiB,EAAE,IAAY,EAAE,IAAY;YACzE,OAAO,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;QAChF,CAAC;;;SA7sBU,OAAO"}
|
package/esm/README.md
CHANGED
|
@@ -174,3 +174,46 @@ const completions = await lsp.completions('path/to/file.ts', {
|
|
|
174
174
|
character: 15,
|
|
175
175
|
})
|
|
176
176
|
```
|
|
177
|
+
|
|
178
|
+
## List method return shapes
|
|
179
|
+
|
|
180
|
+
Each `list` method returns a different shape depending on the resource. The table below shows the exact return type and how to access the elements.
|
|
181
|
+
|
|
182
|
+
| Method | Return type | Shape | Access elements |
|
|
183
|
+
| --- | --- | --- | --- |
|
|
184
|
+
| `daytona.snapshot.list(page?, limit?)` | `Promise<PaginatedSnapshots>` | Paginated wrapper | `result.items.forEach(...)` |
|
|
185
|
+
| `daytona.secret.list(query?)` | `Promise<ListSecretsResponse>` | Cursor-paginated wrapper | `page.items.forEach(...)` |
|
|
186
|
+
| `daytona.volume.list()` | `Promise<Volume[]>` | Bare array | `volumes.forEach(...)` |
|
|
187
|
+
| `daytona.list(query?)` | `AsyncIterableIterator<Sandbox>` | Lazy iterator | `for await (const s of daytona.list())` |
|
|
188
|
+
|
|
189
|
+
`PaginatedSnapshots` and `ListSecretsResponse` are **wrapper objects**, not arrays. Calling `.map()` or `.forEach()` directly on them throws `TypeError: result.map is not a function`. Always go through `.items`:
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
// snapshots — page-number pagination
|
|
193
|
+
const result = await daytona.snapshot.list(1, 20)
|
|
194
|
+
// result.items → Snapshot[]
|
|
195
|
+
// result.total → number (total across all pages)
|
|
196
|
+
// result.page → number (current page, 1-indexed)
|
|
197
|
+
// result.totalPages → number
|
|
198
|
+
result.items.forEach(snapshot => console.log(snapshot.name))
|
|
199
|
+
|
|
200
|
+
// secrets — cursor pagination
|
|
201
|
+
let cursor: string | undefined
|
|
202
|
+
do {
|
|
203
|
+
const page = await daytona.secret.list({ cursor, limit: 50 })
|
|
204
|
+
// page.items → Secret[]
|
|
205
|
+
// page.total → number
|
|
206
|
+
// page.nextCursor → string | null (null = no more pages)
|
|
207
|
+
page.items.forEach(secret => console.log(secret.name))
|
|
208
|
+
cursor = page.nextCursor ?? undefined
|
|
209
|
+
} while (cursor)
|
|
210
|
+
|
|
211
|
+
// volumes — bare array, iterate directly
|
|
212
|
+
const volumes = await daytona.volume.list()
|
|
213
|
+
volumes.forEach(vol => console.log(vol.name))
|
|
214
|
+
|
|
215
|
+
// sandboxes — lazy async iterator, fetches pages on demand
|
|
216
|
+
for await (const sandbox of daytona.list({ labels: { env: 'dev' } })) {
|
|
217
|
+
console.log(sandbox.id)
|
|
218
|
+
}
|
|
219
|
+
```
|
package/esm/Sandbox.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SandboxState, SandboxApi, SandboxBackupStateEnum, Configuration } from '@daytona/api-client';
|
|
2
2
|
import type { Sandbox as SandboxDto, SandboxListItem as SandboxListItemDto, PortPreviewUrl, SandboxVolume, BuildInfo, SshAccessDto, SshAccessValidationDto, SignedPortPreviewUrl, UpdateSandboxNetworkSettings, SandboxListSortField, SandboxListSortDirection } from '@daytona/api-client';
|
|
3
|
-
import type { Resources } from './Daytona.js';
|
|
3
|
+
import type { ForkSandboxParams, Resources } from './Daytona.js';
|
|
4
4
|
import { FileSystem } from './FileSystem.js';
|
|
5
5
|
import { Git } from './Git.js';
|
|
6
6
|
import { Process } from './Process.js';
|
|
@@ -66,6 +66,7 @@ export declare class Sandbox {
|
|
|
66
66
|
private readonly sandboxApi;
|
|
67
67
|
private readonly getAnalyticsApiUrl;
|
|
68
68
|
private readonly subscriptionManager;
|
|
69
|
+
private readonly requestTimeoutMs?;
|
|
69
70
|
readonly fs: FileSystem;
|
|
70
71
|
readonly git: Git;
|
|
71
72
|
readonly process: Process;
|
|
@@ -123,7 +124,7 @@ export declare class Sandbox {
|
|
|
123
124
|
* @param {InfoApi} infoApi - API client for info operations
|
|
124
125
|
* @param {EventSubscriptionManager} subscriptionManager - Event subscription manager for real-time updates
|
|
125
126
|
*/
|
|
126
|
-
constructor(sandboxDto: SandboxDto | SandboxListItemDto, clientConfig: Configuration, axiosInstance: AxiosInstance, sandboxApi: SandboxApi, getAnalyticsApiUrl: () => Promise<string | undefined>, subscriptionManager: EventSubscriptionManager);
|
|
127
|
+
constructor(sandboxDto: SandboxDto | SandboxListItemDto, clientConfig: Configuration, axiosInstance: AxiosInstance, sandboxApi: SandboxApi, getAnalyticsApiUrl: () => Promise<string | undefined>, subscriptionManager: EventSubscriptionManager, requestTimeoutMs?: number);
|
|
127
128
|
/**
|
|
128
129
|
* Gets the user's home directory path for the logged in user inside the Sandbox.
|
|
129
130
|
*
|
|
@@ -260,22 +261,25 @@ export declare class Sandbox {
|
|
|
260
261
|
* The forked Sandbox is a copy-on-write clone of the original. It starts
|
|
261
262
|
* with the same disk contents but operates independently from that point on.
|
|
262
263
|
*
|
|
263
|
-
* @param {
|
|
264
|
+
* @param {ForkSandboxParams} [params] - Fork parameters
|
|
264
265
|
* @param {string} [params.name] - Optional name for the forked Sandbox. If not provided, a unique name will be generated.
|
|
265
266
|
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
266
267
|
* Defaults to 60-second timeout.
|
|
267
268
|
* @returns {Promise<Sandbox>} The forked Sandbox.
|
|
268
|
-
* @throws {
|
|
269
|
+
* @throws {DaytonaInvalidArgumentError} - If timeout is a negative number
|
|
269
270
|
* @throws {DaytonaError} - If the fork operation fails or times out
|
|
270
271
|
*
|
|
271
272
|
* @example
|
|
272
273
|
* const sandbox = await daytona.get('my-sandbox');
|
|
273
|
-
* const forked = await sandbox.
|
|
274
|
+
* const forked = await sandbox.fork({ name: 'my-fork' });
|
|
274
275
|
* console.log(`Forked sandbox: ${forked.id}`);
|
|
275
276
|
*/
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
fork(params?: ForkSandboxParams, timeout?: number): Promise<Sandbox>;
|
|
278
|
+
/**
|
|
279
|
+
* @deprecated Use `fork` instead. This method will be removed in a future version.
|
|
280
|
+
* @see {@link Sandbox.fork}
|
|
281
|
+
*/
|
|
282
|
+
_experimental_fork(params?: ForkSandboxParams, timeout?: number): Promise<Sandbox>;
|
|
279
283
|
/**
|
|
280
284
|
* Creates a snapshot from the current state of the Sandbox.
|
|
281
285
|
*
|
|
@@ -287,14 +291,22 @@ export declare class Sandbox {
|
|
|
287
291
|
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
288
292
|
* Defaults to 60-second timeout.
|
|
289
293
|
* @returns {Promise<void>}
|
|
290
|
-
* @throws {
|
|
294
|
+
* @throws {DaytonaInvalidArgumentError} - If timeout is a negative number
|
|
291
295
|
* @throws {DaytonaError} - If the snapshot operation fails or times out
|
|
292
296
|
*
|
|
293
297
|
* @example
|
|
294
298
|
* const sandbox = await daytona.get('my-sandbox');
|
|
295
|
-
* await sandbox.
|
|
299
|
+
* await sandbox.createSnapshot('my-snapshot');
|
|
296
300
|
* console.log('Snapshot created successfully');
|
|
297
301
|
*/
|
|
302
|
+
createSnapshot(name: string, timeout?: number): Promise<void>;
|
|
303
|
+
/**
|
|
304
|
+
* @param {string} name - Name for the new snapshot
|
|
305
|
+
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
306
|
+
* Defaults to 60-second timeout.
|
|
307
|
+
* @deprecated Use `createSnapshot` instead. This method will be removed in a future version.
|
|
308
|
+
* @see {@link Sandbox.createSnapshot}
|
|
309
|
+
*/
|
|
298
310
|
_experimental_createSnapshot(name: string, timeout?: number): Promise<void>;
|
|
299
311
|
private waitForSnapshotComplete;
|
|
300
312
|
/**
|
|
@@ -307,7 +319,7 @@ export declare class Sandbox {
|
|
|
307
319
|
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
308
320
|
* Defaults to 60-second timeout.
|
|
309
321
|
* @returns {Promise<void>}
|
|
310
|
-
* @throws {
|
|
322
|
+
* @throws {DaytonaInvalidArgumentError} - If timeout is a negative number
|
|
311
323
|
* @throws {DaytonaError} - If the pause operation fails or times out
|
|
312
324
|
*
|
|
313
325
|
* @example
|
package/esm/Sandbox.js
CHANGED
|
@@ -11,7 +11,7 @@ import { FileSystem } from './FileSystem.js';
|
|
|
11
11
|
import { Git } from './Git.js';
|
|
12
12
|
import { Process } from './Process.js';
|
|
13
13
|
import { LspServer } from './LspServer.js';
|
|
14
|
-
import { DaytonaError, DaytonaNotFoundError, DaytonaTimeoutError,
|
|
14
|
+
import { DaytonaError, DaytonaInvalidArgumentError, DaytonaNotFoundError, DaytonaTimeoutError, } from './errors/DaytonaError.js';
|
|
15
15
|
import { CODE_TOOLBOX_LANGUAGE_LABEL } from './Daytona.js';
|
|
16
16
|
import { ComputerUse } from './ComputerUse.js';
|
|
17
17
|
import { CodeInterpreter } from './CodeInterpreter.js';
|
|
@@ -87,8 +87,8 @@ let Sandbox = (() => {
|
|
|
87
87
|
let _start_decorators;
|
|
88
88
|
let _recover_decorators;
|
|
89
89
|
let _stop_decorators;
|
|
90
|
-
let
|
|
91
|
-
let
|
|
90
|
+
let _fork_decorators;
|
|
91
|
+
let _createSnapshot_decorators;
|
|
92
92
|
let _pause_decorators;
|
|
93
93
|
let _delete_decorators;
|
|
94
94
|
let _waitUntilStarted_decorators;
|
|
@@ -128,8 +128,8 @@ let Sandbox = (() => {
|
|
|
128
128
|
_start_decorators = [WithInstrumentation(), withEvents];
|
|
129
129
|
_recover_decorators = [withEvents];
|
|
130
130
|
_stop_decorators = [WithInstrumentation(), withEvents];
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
_fork_decorators = [WithInstrumentation(), withEvents];
|
|
132
|
+
_createSnapshot_decorators = [WithInstrumentation(), withEvents];
|
|
133
133
|
_pause_decorators = [WithInstrumentation(), withEvents];
|
|
134
134
|
_delete_decorators = [WithInstrumentation(), withEvents];
|
|
135
135
|
_waitUntilStarted_decorators = [WithInstrumentation(), withEvents];
|
|
@@ -166,8 +166,8 @@ let Sandbox = (() => {
|
|
|
166
166
|
__esDecorate(this, null, _start_decorators, { kind: "method", name: "start", static: false, private: false, access: { has: obj => "start" in obj, get: obj => obj.start }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
167
167
|
__esDecorate(this, null, _recover_decorators, { kind: "method", name: "recover", static: false, private: false, access: { has: obj => "recover" in obj, get: obj => obj.recover }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
168
168
|
__esDecorate(this, null, _stop_decorators, { kind: "method", name: "stop", static: false, private: false, access: { has: obj => "stop" in obj, get: obj => obj.stop }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
169
|
-
__esDecorate(this, null,
|
|
170
|
-
__esDecorate(this, null,
|
|
169
|
+
__esDecorate(this, null, _fork_decorators, { kind: "method", name: "fork", static: false, private: false, access: { has: obj => "fork" in obj, get: obj => obj.fork }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
170
|
+
__esDecorate(this, null, _createSnapshot_decorators, { kind: "method", name: "createSnapshot", static: false, private: false, access: { has: obj => "createSnapshot" in obj, get: obj => obj.createSnapshot }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
171
171
|
__esDecorate(this, null, _pause_decorators, { kind: "method", name: "pause", static: false, private: false, access: { has: obj => "pause" in obj, get: obj => obj.pause }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
172
172
|
__esDecorate(this, null, _delete_decorators, { kind: "method", name: "delete", static: false, private: false, access: { has: obj => "delete" in obj, get: obj => obj.delete }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
173
173
|
__esDecorate(this, null, _waitUntilStarted_decorators, { kind: "method", name: "waitUntilStarted", static: false, private: false, access: { has: obj => "waitUntilStarted" in obj, get: obj => obj.waitUntilStarted }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
@@ -201,6 +201,7 @@ let Sandbox = (() => {
|
|
|
201
201
|
sandboxApi;
|
|
202
202
|
getAnalyticsApiUrl;
|
|
203
203
|
subscriptionManager;
|
|
204
|
+
requestTimeoutMs;
|
|
204
205
|
fs;
|
|
205
206
|
git;
|
|
206
207
|
process;
|
|
@@ -258,18 +259,19 @@ let Sandbox = (() => {
|
|
|
258
259
|
* @param {InfoApi} infoApi - API client for info operations
|
|
259
260
|
* @param {EventSubscriptionManager} subscriptionManager - Event subscription manager for real-time updates
|
|
260
261
|
*/
|
|
261
|
-
constructor(sandboxDto, clientConfig, axiosInstance, sandboxApi, getAnalyticsApiUrl, subscriptionManager) {
|
|
262
|
+
constructor(sandboxDto, clientConfig, axiosInstance, sandboxApi, getAnalyticsApiUrl, subscriptionManager, requestTimeoutMs) {
|
|
262
263
|
this.clientConfig = clientConfig;
|
|
263
264
|
this.axiosInstance = axiosInstance;
|
|
264
265
|
this.sandboxApi = sandboxApi;
|
|
265
266
|
this.getAnalyticsApiUrl = getAnalyticsApiUrl;
|
|
266
267
|
this.subscriptionManager = subscriptionManager;
|
|
268
|
+
this.requestTimeoutMs = requestTimeoutMs;
|
|
267
269
|
this.processSandboxDto(sandboxDto);
|
|
268
270
|
const getPreviewToken = async () => (await this.getPreviewLink(1)).token;
|
|
269
271
|
this.fs = new FileSystem(this.clientConfig, new FileSystemApi(this.clientConfig, '', this.axiosInstance));
|
|
270
272
|
this.git = new Git(new GitApi(this.clientConfig, '', this.axiosInstance));
|
|
271
273
|
const language = sandboxDto.labels?.[CODE_TOOLBOX_LANGUAGE_LABEL];
|
|
272
|
-
this.process = new Process(this.clientConfig, new ProcessApi(this.clientConfig, '', this.axiosInstance), getPreviewToken, language);
|
|
274
|
+
this.process = new Process(this.clientConfig, new ProcessApi(this.clientConfig, '', this.axiosInstance), getPreviewToken, language, this.requestTimeoutMs);
|
|
273
275
|
this.codeInterpreter = new CodeInterpreter(this.clientConfig, new InterpreterApi(this.clientConfig, '', this.axiosInstance), getPreviewToken);
|
|
274
276
|
this.computerUse = new ComputerUse(new ComputerUseApi(this.clientConfig, '', this.axiosInstance));
|
|
275
277
|
this.infoApi = new InfoApi(this.clientConfig, '', this.axiosInstance);
|
|
@@ -335,7 +337,7 @@ let Sandbox = (() => {
|
|
|
335
337
|
basePath: analyticsApiUrl,
|
|
336
338
|
apiKey: this.clientConfig.baseOptions?.headers?.Authorization,
|
|
337
339
|
});
|
|
338
|
-
return new AnalyticsTelemetryApi(analyticsConfig, undefined, Daytona.createAxiosInstance());
|
|
340
|
+
return new AnalyticsTelemetryApi(analyticsConfig, undefined, Daytona.createAxiosInstance(this.requestTimeoutMs));
|
|
339
341
|
}
|
|
340
342
|
/**
|
|
341
343
|
* @deprecated Use `getUserHomeDir` instead. This method will be removed in a future version.
|
|
@@ -410,7 +412,7 @@ let Sandbox = (() => {
|
|
|
410
412
|
*/
|
|
411
413
|
async start(timeout = 60) {
|
|
412
414
|
if (timeout < 0) {
|
|
413
|
-
throw new
|
|
415
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
414
416
|
}
|
|
415
417
|
const startTime = Date.now();
|
|
416
418
|
const response = await this.sandboxApi.startSandbox(this.id, undefined, { timeout: timeout * 1000 });
|
|
@@ -433,7 +435,7 @@ let Sandbox = (() => {
|
|
|
433
435
|
*/
|
|
434
436
|
async recover(timeout = 60) {
|
|
435
437
|
if (timeout < 0) {
|
|
436
|
-
throw new
|
|
438
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
437
439
|
}
|
|
438
440
|
const startTime = Date.now();
|
|
439
441
|
const response = await this.sandboxApi.recoverSandbox(this.id, undefined, undefined, { timeout: timeout * 1000 });
|
|
@@ -458,7 +460,7 @@ let Sandbox = (() => {
|
|
|
458
460
|
*/
|
|
459
461
|
async stop(timeout = 60, force = false) {
|
|
460
462
|
if (timeout < 0) {
|
|
461
|
-
throw new
|
|
463
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
462
464
|
}
|
|
463
465
|
const startTime = Date.now();
|
|
464
466
|
await this.sandboxApi.stopSandbox(this.id, undefined, force, { timeout: timeout * 1000 });
|
|
@@ -472,22 +474,22 @@ let Sandbox = (() => {
|
|
|
472
474
|
* The forked Sandbox is a copy-on-write clone of the original. It starts
|
|
473
475
|
* with the same disk contents but operates independently from that point on.
|
|
474
476
|
*
|
|
475
|
-
* @param {
|
|
477
|
+
* @param {ForkSandboxParams} [params] - Fork parameters
|
|
476
478
|
* @param {string} [params.name] - Optional name for the forked Sandbox. If not provided, a unique name will be generated.
|
|
477
479
|
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
478
480
|
* Defaults to 60-second timeout.
|
|
479
481
|
* @returns {Promise<Sandbox>} The forked Sandbox.
|
|
480
|
-
* @throws {
|
|
482
|
+
* @throws {DaytonaInvalidArgumentError} - If timeout is a negative number
|
|
481
483
|
* @throws {DaytonaError} - If the fork operation fails or times out
|
|
482
484
|
*
|
|
483
485
|
* @example
|
|
484
486
|
* const sandbox = await daytona.get('my-sandbox');
|
|
485
|
-
* const forked = await sandbox.
|
|
487
|
+
* const forked = await sandbox.fork({ name: 'my-fork' });
|
|
486
488
|
* console.log(`Forked sandbox: ${forked.id}`);
|
|
487
489
|
*/
|
|
488
|
-
async
|
|
490
|
+
async fork(params, timeout = 60) {
|
|
489
491
|
if (timeout < 0) {
|
|
490
|
-
throw new
|
|
492
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
491
493
|
}
|
|
492
494
|
const startTime = Date.now();
|
|
493
495
|
const response = await this.sandboxApi.forkSandbox(this.id, { name: params?.name }, undefined, {
|
|
@@ -500,12 +502,19 @@ let Sandbox = (() => {
|
|
|
500
502
|
...sandboxDto,
|
|
501
503
|
toolboxProxyUrl: (await this.sandboxApi.getToolboxProxyUrl(sandboxDto.id)).data.url,
|
|
502
504
|
};
|
|
503
|
-
const forkedSandbox = new Sandbox(sandboxWithProxyUrl, structuredClone(this.clientConfig), Daytona.createAxiosInstance(), this.sandboxApi, this.getAnalyticsApiUrl, this.subscriptionManager);
|
|
505
|
+
const forkedSandbox = new Sandbox(sandboxWithProxyUrl, structuredClone(this.clientConfig), Daytona.createAxiosInstance(this.requestTimeoutMs), this.sandboxApi, this.getAnalyticsApiUrl, this.subscriptionManager, this.requestTimeoutMs);
|
|
504
506
|
const timeElapsed = Date.now() - startTime;
|
|
505
507
|
const remainingTimeout = timeout ? Math.max(0.001, timeout - timeElapsed / 1000) : timeout;
|
|
506
508
|
await forkedSandbox.waitUntilStarted(remainingTimeout);
|
|
507
509
|
return forkedSandbox;
|
|
508
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* @deprecated Use `fork` instead. This method will be removed in a future version.
|
|
513
|
+
* @see {@link Sandbox.fork}
|
|
514
|
+
*/
|
|
515
|
+
async _experimental_fork(params, timeout = 60) {
|
|
516
|
+
return this.fork(params, timeout);
|
|
517
|
+
}
|
|
509
518
|
/**
|
|
510
519
|
* Creates a snapshot from the current state of the Sandbox.
|
|
511
520
|
*
|
|
@@ -517,17 +526,17 @@ let Sandbox = (() => {
|
|
|
517
526
|
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
518
527
|
* Defaults to 60-second timeout.
|
|
519
528
|
* @returns {Promise<void>}
|
|
520
|
-
* @throws {
|
|
529
|
+
* @throws {DaytonaInvalidArgumentError} - If timeout is a negative number
|
|
521
530
|
* @throws {DaytonaError} - If the snapshot operation fails or times out
|
|
522
531
|
*
|
|
523
532
|
* @example
|
|
524
533
|
* const sandbox = await daytona.get('my-sandbox');
|
|
525
|
-
* await sandbox.
|
|
534
|
+
* await sandbox.createSnapshot('my-snapshot');
|
|
526
535
|
* console.log('Snapshot created successfully');
|
|
527
536
|
*/
|
|
528
|
-
async
|
|
537
|
+
async createSnapshot(name, timeout = 60) {
|
|
529
538
|
if (timeout < 0) {
|
|
530
|
-
throw new
|
|
539
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
531
540
|
}
|
|
532
541
|
const startTime = Date.now();
|
|
533
542
|
const req = { name };
|
|
@@ -539,6 +548,16 @@ let Sandbox = (() => {
|
|
|
539
548
|
const remainingTimeout = timeout ? Math.max(0.001, timeout - timeElapsed / 1000) : timeout;
|
|
540
549
|
await this.waitForSnapshotComplete(remainingTimeout);
|
|
541
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* @param {string} name - Name for the new snapshot
|
|
553
|
+
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
554
|
+
* Defaults to 60-second timeout.
|
|
555
|
+
* @deprecated Use `createSnapshot` instead. This method will be removed in a future version.
|
|
556
|
+
* @see {@link Sandbox.createSnapshot}
|
|
557
|
+
*/
|
|
558
|
+
async _experimental_createSnapshot(name, timeout = 60) {
|
|
559
|
+
return this.createSnapshot(name, timeout);
|
|
560
|
+
}
|
|
542
561
|
async waitForSnapshotComplete(timeout) {
|
|
543
562
|
const errorStates = [SandboxState.ERROR, SandboxState.BUILD_FAILED];
|
|
544
563
|
const excludeStates = new Set([SandboxState.SNAPSHOTTING, ...errorStates]);
|
|
@@ -555,7 +574,7 @@ let Sandbox = (() => {
|
|
|
555
574
|
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
556
575
|
* Defaults to 60-second timeout.
|
|
557
576
|
* @returns {Promise<void>}
|
|
558
|
-
* @throws {
|
|
577
|
+
* @throws {DaytonaInvalidArgumentError} - If timeout is a negative number
|
|
559
578
|
* @throws {DaytonaError} - If the pause operation fails or times out
|
|
560
579
|
*
|
|
561
580
|
* @example
|
|
@@ -565,7 +584,7 @@ let Sandbox = (() => {
|
|
|
565
584
|
*/
|
|
566
585
|
async pause(timeout = 60) {
|
|
567
586
|
if (timeout < 0) {
|
|
568
|
-
throw new
|
|
587
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
569
588
|
}
|
|
570
589
|
const startTime = Date.now();
|
|
571
590
|
await this.sandboxApi.pauseSandbox(this.id, undefined, {
|
|
@@ -596,7 +615,7 @@ let Sandbox = (() => {
|
|
|
596
615
|
*/
|
|
597
616
|
async delete(timeout = 60, wait = false) {
|
|
598
617
|
if (timeout < 0) {
|
|
599
|
-
throw new
|
|
618
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
600
619
|
}
|
|
601
620
|
const startTime = Date.now();
|
|
602
621
|
const response = await this.sandboxApi.deleteSandbox(this.id, undefined, { timeout: timeout * 1000 });
|
|
@@ -629,7 +648,7 @@ let Sandbox = (() => {
|
|
|
629
648
|
*/
|
|
630
649
|
async waitUntilStarted(timeout = 60) {
|
|
631
650
|
if (timeout < 0) {
|
|
632
|
-
throw new
|
|
651
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
633
652
|
}
|
|
634
653
|
if (this.state === SandboxState.STARTED) {
|
|
635
654
|
return;
|
|
@@ -649,7 +668,7 @@ let Sandbox = (() => {
|
|
|
649
668
|
*/
|
|
650
669
|
async waitUntilStopped(timeout = 60) {
|
|
651
670
|
if (timeout < 0) {
|
|
652
|
-
throw new
|
|
671
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
653
672
|
}
|
|
654
673
|
// Treat destroyed as stopped to cover ephemeral sandboxes that are automatically deleted after stopping
|
|
655
674
|
if (this.state === SandboxState.STOPPED || this.state === SandboxState.DESTROYED) {
|
|
@@ -707,7 +726,7 @@ let Sandbox = (() => {
|
|
|
707
726
|
*/
|
|
708
727
|
async setAutostopInterval(interval) {
|
|
709
728
|
if (!Number.isInteger(interval) || interval < 0) {
|
|
710
|
-
throw new
|
|
729
|
+
throw new DaytonaInvalidArgumentError('autoStopInterval must be a non-negative integer');
|
|
711
730
|
}
|
|
712
731
|
await this.sandboxApi.setAutostopInterval(this.id, interval);
|
|
713
732
|
this.autoStopInterval = interval;
|
|
@@ -737,7 +756,7 @@ let Sandbox = (() => {
|
|
|
737
756
|
*/
|
|
738
757
|
async setAutoPauseInterval(interval) {
|
|
739
758
|
if (!Number.isInteger(interval) || interval < 0) {
|
|
740
|
-
throw new
|
|
759
|
+
throw new DaytonaInvalidArgumentError('autoPauseInterval must be a non-negative integer');
|
|
741
760
|
}
|
|
742
761
|
await this.sandboxApi.setAutoPauseInterval(this.id, interval);
|
|
743
762
|
this.autoPauseInterval = interval;
|
|
@@ -762,7 +781,7 @@ let Sandbox = (() => {
|
|
|
762
781
|
*/
|
|
763
782
|
async setTtl(ttlMinutes) {
|
|
764
783
|
if (!Number.isInteger(ttlMinutes) || ttlMinutes < 0) {
|
|
765
|
-
throw new
|
|
784
|
+
throw new DaytonaInvalidArgumentError('ttlMinutes must be a non-negative integer');
|
|
766
785
|
}
|
|
767
786
|
await this.sandboxApi.setTtl(this.id, ttlMinutes);
|
|
768
787
|
}
|
|
@@ -784,7 +803,7 @@ let Sandbox = (() => {
|
|
|
784
803
|
*/
|
|
785
804
|
async setAutoArchiveInterval(interval) {
|
|
786
805
|
if (!Number.isInteger(interval) || interval < 0) {
|
|
787
|
-
throw new
|
|
806
|
+
throw new DaytonaInvalidArgumentError('autoArchiveInterval must be a non-negative integer');
|
|
788
807
|
}
|
|
789
808
|
await this.sandboxApi.setAutoArchiveInterval(this.id, interval);
|
|
790
809
|
this.autoArchiveInterval = interval;
|
|
@@ -834,7 +853,7 @@ let Sandbox = (() => {
|
|
|
834
853
|
if (settings.networkBlockAll === undefined &&
|
|
835
854
|
settings.networkAllowList === undefined &&
|
|
836
855
|
settings.domainAllowList === undefined) {
|
|
837
|
-
throw new
|
|
856
|
+
throw new DaytonaInvalidArgumentError('At least one of networkBlockAll, networkAllowList or domainAllowList must be set');
|
|
838
857
|
}
|
|
839
858
|
const response = await this.sandboxApi.updateNetworkSettings(this.id, settings);
|
|
840
859
|
this.processSandboxDto(response.data);
|
|
@@ -1007,10 +1026,10 @@ let Sandbox = (() => {
|
|
|
1007
1026
|
*/
|
|
1008
1027
|
async resize(resources, timeout = 60) {
|
|
1009
1028
|
if (timeout < 0) {
|
|
1010
|
-
throw new
|
|
1029
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
1011
1030
|
}
|
|
1012
1031
|
if ('gpu' in resources || 'gpuType' in resources) {
|
|
1013
|
-
throw new
|
|
1032
|
+
throw new DaytonaInvalidArgumentError('Resize does not support changes to gpu or gpuType — to change GPU, create a new Sandbox');
|
|
1014
1033
|
}
|
|
1015
1034
|
const startTime = Date.now();
|
|
1016
1035
|
const resizeRequest = {
|
|
@@ -1036,7 +1055,7 @@ let Sandbox = (() => {
|
|
|
1036
1055
|
*/
|
|
1037
1056
|
async waitForResizeComplete(timeout = 60) {
|
|
1038
1057
|
if (timeout < 0) {
|
|
1039
|
-
throw new
|
|
1058
|
+
throw new DaytonaInvalidArgumentError('Timeout must be a non-negative number');
|
|
1040
1059
|
}
|
|
1041
1060
|
if (this.state !== SandboxState.RESIZING) {
|
|
1042
1061
|
return;
|