@daytonaio/sdk 0.175.0 → 0.178.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.
Files changed (91) hide show
  1. package/cjs/CodeInterpreter.d.ts +3 -2
  2. package/cjs/CodeInterpreter.js.map +1 -1
  3. package/cjs/ComputerUse.d.ts +104 -2
  4. package/cjs/ComputerUse.js +851 -763
  5. package/cjs/ComputerUse.js.map +1 -1
  6. package/cjs/Daytona.d.ts +4 -3
  7. package/cjs/Daytona.js +429 -443
  8. package/cjs/Daytona.js.map +1 -1
  9. package/cjs/FileSystem.d.ts +2 -2
  10. package/cjs/FileSystem.js +491 -521
  11. package/cjs/FileSystem.js.map +1 -1
  12. package/cjs/Git.d.ts +2 -1
  13. package/cjs/Git.js +287 -310
  14. package/cjs/Git.js.map +1 -1
  15. package/cjs/LspServer.d.ts +2 -1
  16. package/cjs/LspServer.js +209 -226
  17. package/cjs/LspServer.js.map +1 -1
  18. package/cjs/ObjectStorage.js +170 -166
  19. package/cjs/ObjectStorage.js.map +1 -1
  20. package/cjs/Process.d.ts +4 -3
  21. package/cjs/Process.js +562 -600
  22. package/cjs/Process.js.map +1 -1
  23. package/cjs/PtyHandle.d.ts +2 -2
  24. package/cjs/PtyHandle.js +327 -338
  25. package/cjs/PtyHandle.js.map +1 -1
  26. package/cjs/Sandbox.d.ts +4 -3
  27. package/cjs/Sandbox.js +756 -821
  28. package/cjs/Sandbox.js.map +1 -1
  29. package/cjs/Snapshot.d.ts +3 -2
  30. package/cjs/Snapshot.js +203 -213
  31. package/cjs/Snapshot.js.map +1 -1
  32. package/cjs/Volume.d.ts +2 -1
  33. package/cjs/Volume.js +90 -92
  34. package/cjs/Volume.js.map +1 -1
  35. package/cjs/errors/DaytonaError.d.ts +2 -1
  36. package/cjs/errors/DaytonaError.js.map +1 -1
  37. package/cjs/index.d.ts +2 -2
  38. package/cjs/index.js +2 -1
  39. package/cjs/index.js.map +1 -1
  40. package/cjs/types/CodeInterpreter.d.ts +1 -1
  41. package/cjs/utils/Binary.js +14 -2
  42. package/cjs/utils/Binary.js.map +1 -1
  43. package/cjs/utils/otel.decorator.d.ts +7 -8
  44. package/cjs/utils/otel.decorator.js +24 -30
  45. package/cjs/utils/otel.decorator.js.map +1 -1
  46. package/esm/CodeInterpreter.d.ts +3 -2
  47. package/esm/CodeInterpreter.js.map +1 -1
  48. package/esm/ComputerUse.d.ts +104 -2
  49. package/esm/ComputerUse.js +857 -763
  50. package/esm/ComputerUse.js.map +1 -1
  51. package/esm/Daytona.d.ts +4 -3
  52. package/esm/Daytona.js +431 -444
  53. package/esm/Daytona.js.map +1 -1
  54. package/esm/FileSystem.d.ts +2 -2
  55. package/esm/FileSystem.js +493 -522
  56. package/esm/FileSystem.js.map +1 -1
  57. package/esm/Git.d.ts +2 -1
  58. package/esm/Git.js +289 -311
  59. package/esm/Git.js.map +1 -1
  60. package/esm/LspServer.d.ts +2 -1
  61. package/esm/LspServer.js +211 -227
  62. package/esm/LspServer.js.map +1 -1
  63. package/esm/ObjectStorage.js +172 -167
  64. package/esm/ObjectStorage.js.map +1 -1
  65. package/esm/Process.d.ts +4 -3
  66. package/esm/Process.js +564 -601
  67. package/esm/Process.js.map +1 -1
  68. package/esm/PtyHandle.d.ts +2 -2
  69. package/esm/PtyHandle.js +329 -339
  70. package/esm/PtyHandle.js.map +1 -1
  71. package/esm/Sandbox.d.ts +4 -3
  72. package/esm/Sandbox.js +759 -823
  73. package/esm/Sandbox.js.map +1 -1
  74. package/esm/Snapshot.d.ts +3 -2
  75. package/esm/Snapshot.js +206 -215
  76. package/esm/Snapshot.js.map +1 -1
  77. package/esm/Volume.d.ts +2 -1
  78. package/esm/Volume.js +92 -93
  79. package/esm/Volume.js.map +1 -1
  80. package/esm/errors/DaytonaError.d.ts +2 -1
  81. package/esm/errors/DaytonaError.js.map +1 -1
  82. package/esm/index.d.ts +2 -2
  83. package/esm/index.js +1 -1
  84. package/esm/index.js.map +1 -1
  85. package/esm/types/CodeInterpreter.d.ts +1 -1
  86. package/esm/utils/Binary.js +14 -2
  87. package/esm/utils/Binary.js.map +1 -1
  88. package/esm/utils/otel.decorator.d.ts +7 -8
  89. package/esm/utils/otel.decorator.js +26 -32
  90. package/esm/utils/otel.decorator.js.map +1 -1
  91. package/package.json +3 -3
package/esm/Daytona.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Copyright 2025 Daytona Platforms Inc.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { __decorate, __metadata } from "tslib";
5
+ import { __esDecorate, __runInitializers } from "tslib";
6
6
  import { Configuration, SnapshotsApi, ObjectStorageApi, SandboxApi, SandboxState, VolumesApi, ConfigApi, } from '@daytona/api-client';
7
7
  import axios, { AxiosError } from 'axios';
8
8
  import { DaytonaAuthenticationError, createAxiosDaytonaError, DaytonaError, DaytonaTimeoutError, DaytonaValidationError, } from './errors/DaytonaError.js';
@@ -58,473 +58,460 @@ export var CodeLanguage;
58
58
  * });
59
59
  * @class
60
60
  */
61
- export class Daytona {
62
- clientConfig;
63
- sandboxApi;
64
- objectStorageApi;
65
- configApi;
66
- target;
67
- apiKey;
68
- jwtToken;
69
- organizationId;
70
- apiUrl;
71
- otelSdk;
72
- volume;
73
- snapshot;
74
- /**
75
- * Creates a new Daytona client instance.
76
- *
77
- * @param {DaytonaConfig} [config] - Configuration options
78
- * @throws {DaytonaAuthenticationError} When no credentials are provided (neither API key nor JWT token)
79
- * @throws {DaytonaAuthenticationError} When JWT token is provided without an organization ID
80
- */
81
- constructor(config) {
82
- let apiUrl;
83
- if (config) {
84
- this.apiKey = !config?.apiKey && config?.jwtToken ? undefined : config?.apiKey;
85
- this.jwtToken = config?.jwtToken;
86
- this.organizationId = config?.organizationId;
87
- apiUrl = config?.apiUrl || config?.serverUrl;
88
- this.target = config?.target;
61
+ let Daytona = (() => {
62
+ let _instanceExtraInitializers = [];
63
+ let _create_decorators;
64
+ let _get_decorators;
65
+ let _list_decorators;
66
+ let _start_decorators;
67
+ let _stop_decorators;
68
+ let __experimental_fork_decorators;
69
+ let _delete_decorators;
70
+ return class Daytona {
71
+ static {
72
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
73
+ _create_decorators = [WithInstrumentation()];
74
+ _get_decorators = [WithInstrumentation()];
75
+ _list_decorators = [WithInstrumentation()];
76
+ _start_decorators = [WithInstrumentation()];
77
+ _stop_decorators = [WithInstrumentation()];
78
+ __experimental_fork_decorators = [WithInstrumentation()];
79
+ _delete_decorators = [WithInstrumentation()];
80
+ __esDecorate(this, null, _create_decorators, { kind: "method", name: "create", static: false, private: false, access: { has: obj => "create" in obj, get: obj => obj.create }, metadata: _metadata }, null, _instanceExtraInitializers);
81
+ __esDecorate(this, null, _get_decorators, { kind: "method", name: "get", static: false, private: false, access: { has: obj => "get" in obj, get: obj => obj.get }, metadata: _metadata }, null, _instanceExtraInitializers);
82
+ __esDecorate(this, null, _list_decorators, { kind: "method", name: "list", static: false, private: false, access: { has: obj => "list" in obj, get: obj => obj.list }, metadata: _metadata }, null, _instanceExtraInitializers);
83
+ __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);
84
+ __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);
85
+ __esDecorate(this, null, __experimental_fork_decorators, { kind: "method", name: "_experimental_fork", static: false, private: false, access: { has: obj => "_experimental_fork" in obj, get: obj => obj._experimental_fork }, metadata: _metadata }, null, _instanceExtraInitializers);
86
+ __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);
87
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
89
88
  }
90
- let _envReader;
91
- const envReader = () => {
92
- if (_envReader === undefined) {
93
- _envReader = RUNTIME !== Runtime.BROWSER ? new DaytonaEnvReader() : null;
89
+ clientConfig = __runInitializers(this, _instanceExtraInitializers);
90
+ sandboxApi;
91
+ objectStorageApi;
92
+ configApi;
93
+ target;
94
+ apiKey;
95
+ jwtToken;
96
+ organizationId;
97
+ apiUrl;
98
+ otelSdk;
99
+ volume;
100
+ snapshot;
101
+ /**
102
+ * Creates a new Daytona client instance.
103
+ *
104
+ * @param {DaytonaConfig} [config] - Configuration options
105
+ * @throws {DaytonaAuthenticationError} When no credentials are provided (neither API key nor JWT token)
106
+ * @throws {DaytonaAuthenticationError} When JWT token is provided without an organization ID
107
+ */
108
+ constructor(config) {
109
+ let apiUrl;
110
+ if (config) {
111
+ this.apiKey = !config?.apiKey && config?.jwtToken ? undefined : config?.apiKey;
112
+ this.jwtToken = config?.jwtToken;
113
+ this.organizationId = config?.organizationId;
114
+ apiUrl = config?.apiUrl || config?.serverUrl;
115
+ this.target = config?.target;
94
116
  }
95
- return _envReader;
96
- };
97
- if (!config ||
98
- (!(this.apiKey && apiUrl && this.target) && !(this.jwtToken && this.organizationId && apiUrl && this.target))) {
99
- const reader = envReader();
100
- if (reader) {
101
- this.apiKey = this.apiKey || (this.jwtToken ? undefined : reader.get('DAYTONA_API_KEY'));
102
- this.jwtToken = this.jwtToken || reader.get('DAYTONA_JWT_TOKEN');
103
- this.organizationId = this.organizationId || reader.get('DAYTONA_ORGANIZATION_ID');
104
- apiUrl = apiUrl || reader.get('DAYTONA_API_URL') || reader.get('DAYTONA_SERVER_URL');
105
- this.target = this.target || reader.get('DAYTONA_TARGET');
106
- if (reader.get('DAYTONA_SERVER_URL') && !reader.get('DAYTONA_API_URL')) {
107
- console.warn('[Deprecation Warning] Environment variable `DAYTONA_SERVER_URL` is deprecated and will be removed in future versions. Use `DAYTONA_API_URL` instead.');
117
+ let _envReader;
118
+ const envReader = () => {
119
+ if (_envReader === undefined) {
120
+ _envReader = RUNTIME !== Runtime.BROWSER ? new DaytonaEnvReader() : null;
121
+ }
122
+ return _envReader;
123
+ };
124
+ if (!config ||
125
+ (!(this.apiKey && apiUrl && this.target) && !(this.jwtToken && this.organizationId && apiUrl && this.target))) {
126
+ const reader = envReader();
127
+ if (reader) {
128
+ this.apiKey = this.apiKey || (this.jwtToken ? undefined : reader.get('DAYTONA_API_KEY'));
129
+ this.jwtToken = this.jwtToken || reader.get('DAYTONA_JWT_TOKEN');
130
+ this.organizationId = this.organizationId || reader.get('DAYTONA_ORGANIZATION_ID');
131
+ apiUrl = apiUrl || reader.get('DAYTONA_API_URL') || reader.get('DAYTONA_SERVER_URL');
132
+ this.target = this.target || reader.get('DAYTONA_TARGET');
133
+ if (reader.get('DAYTONA_SERVER_URL') && !reader.get('DAYTONA_API_URL')) {
134
+ console.warn('[Deprecation Warning] Environment variable `DAYTONA_SERVER_URL` is deprecated and will be removed in future versions. Use `DAYTONA_API_URL` instead.');
135
+ }
108
136
  }
109
137
  }
110
- }
111
- this.apiUrl = apiUrl || 'https://app.daytona.io/api';
112
- if (!this.apiKey && !this.jwtToken) {
113
- throw new DaytonaAuthenticationError('Authentication credentials not found. Set DAYTONA_API_KEY, or both DAYTONA_JWT_TOKEN and DAYTONA_ORGANIZATION_ID.' +
114
- ' These can also be provided via DaytonaConfig.');
115
- }
116
- const orgHeader = {};
117
- if (!this.apiKey) {
118
- if (!this.organizationId) {
119
- throw new DaytonaAuthenticationError('DAYTONA_ORGANIZATION_ID is required when authenticating with DAYTONA_JWT_TOKEN.' +
120
- ' It can also be provided via DaytonaConfig.');
138
+ this.apiUrl = apiUrl || 'https://app.daytona.io/api';
139
+ if (!this.apiKey && !this.jwtToken) {
140
+ throw new DaytonaAuthenticationError('Authentication credentials not found. Set DAYTONA_API_KEY, or both DAYTONA_JWT_TOKEN and DAYTONA_ORGANIZATION_ID.' +
141
+ ' These can also be provided via DaytonaConfig.');
121
142
  }
122
- orgHeader['X-Daytona-Organization-ID'] = this.organizationId;
123
- }
124
- const isLegacyPackage = packageJson.name === '@daytonaio/sdk';
125
- const sdkLabel = isLegacyPackage ? 'sdk-typescript-legacy' : 'sdk-typescript';
126
- const configuration = new Configuration({
127
- basePath: this.apiUrl,
128
- baseOptions: {
129
- headers: {
130
- Authorization: `Bearer ${this.apiKey || this.jwtToken}`,
131
- 'X-Daytona-Source': sdkLabel,
132
- 'X-Daytona-SDK-Version': packageJson.version,
133
- 'User-Agent': `${sdkLabel}/${packageJson.version}`,
134
- ...orgHeader,
143
+ const orgHeader = {};
144
+ if (!this.apiKey) {
145
+ if (!this.organizationId) {
146
+ throw new DaytonaAuthenticationError('DAYTONA_ORGANIZATION_ID is required when authenticating with DAYTONA_JWT_TOKEN.' +
147
+ ' It can also be provided via DaytonaConfig.');
148
+ }
149
+ orgHeader['X-Daytona-Organization-ID'] = this.organizationId;
150
+ }
151
+ const isLegacyPackage = packageJson.name === '@daytonaio/sdk';
152
+ const sdkLabel = isLegacyPackage ? 'sdk-typescript-legacy' : 'sdk-typescript';
153
+ const configuration = new Configuration({
154
+ basePath: this.apiUrl,
155
+ baseOptions: {
156
+ headers: {
157
+ Authorization: `Bearer ${this.apiKey || this.jwtToken}`,
158
+ 'X-Daytona-Source': sdkLabel,
159
+ 'X-Daytona-SDK-Version': packageJson.version,
160
+ 'User-Agent': `${sdkLabel}/${packageJson.version}`,
161
+ ...orgHeader,
162
+ },
135
163
  },
136
- },
137
- });
138
- const axiosInstance = Daytona.createAxiosInstance();
139
- this.sandboxApi = new SandboxApi(configuration, '', axiosInstance);
140
- this.objectStorageApi = new ObjectStorageApi(configuration, '', axiosInstance);
141
- this.configApi = new ConfigApi(configuration, '', axiosInstance);
142
- this.volume = new VolumeService(new VolumesApi(configuration, '', axiosInstance));
143
- this.snapshot = new SnapshotService(configuration, new SnapshotsApi(configuration, '', axiosInstance), this.objectStorageApi, this.target);
144
- this.clientConfig = configuration;
145
- const env = envReader();
146
- const otelEnabled = config?.otelEnabled ||
147
- config?._experimental?.otelEnabled ||
148
- env?.get('DAYTONA_OTEL_ENABLED') === 'true' ||
149
- env?.get('DAYTONA_EXPERIMENTAL_OTEL_ENABLED') === 'true';
150
- if (!otelEnabled) {
151
- return;
152
- }
153
- const errPrefix = 'OpenTelemetry instrumentation is not supported: ';
154
- const { diag, DiagConsoleLogger, DiagLogLevel } = dynamicRequire('@opentelemetry/api', errPrefix);
155
- const { NodeSDK } = dynamicRequire('@opentelemetry/sdk-node', errPrefix);
156
- const { HttpInstrumentation } = dynamicRequire('@opentelemetry/instrumentation-http', errPrefix);
157
- const { BatchSpanProcessor } = dynamicRequire('@opentelemetry/sdk-trace-base', errPrefix);
158
- const { OTLPTraceExporter } = dynamicRequire('@opentelemetry/exporter-trace-otlp-http', errPrefix);
159
- const { CompressionAlgorithm } = dynamicRequire('@opentelemetry/otlp-exporter-base', errPrefix);
160
- const { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } = dynamicRequire('@opentelemetry/semantic-conventions', errPrefix);
161
- const { resourceFromAttributes } = dynamicRequire('@opentelemetry/resources', errPrefix);
162
- diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
163
- this.otelSdk = new NodeSDK({
164
- resource: resourceFromAttributes({
165
- [ATTR_SERVICE_VERSION]: packageJson.version,
166
- [ATTR_SERVICE_NAME]: 'daytona-typescript-sdk',
167
- }),
168
- instrumentations: [
169
- new HttpInstrumentation({
170
- requireParentforOutgoingSpans: false,
164
+ });
165
+ const axiosInstance = Daytona.createAxiosInstance();
166
+ this.sandboxApi = new SandboxApi(configuration, '', axiosInstance);
167
+ this.objectStorageApi = new ObjectStorageApi(configuration, '', axiosInstance);
168
+ this.configApi = new ConfigApi(configuration, '', axiosInstance);
169
+ this.volume = new VolumeService(new VolumesApi(configuration, '', axiosInstance));
170
+ this.snapshot = new SnapshotService(configuration, new SnapshotsApi(configuration, '', axiosInstance), this.objectStorageApi, this.target);
171
+ this.clientConfig = configuration;
172
+ const env = envReader();
173
+ const otelEnabled = config?.otelEnabled ||
174
+ config?._experimental?.otelEnabled ||
175
+ env?.get('DAYTONA_OTEL_ENABLED') === 'true' ||
176
+ env?.get('DAYTONA_EXPERIMENTAL_OTEL_ENABLED') === 'true';
177
+ if (!otelEnabled) {
178
+ return;
179
+ }
180
+ const errPrefix = 'OpenTelemetry instrumentation is not supported: ';
181
+ const { diag, DiagConsoleLogger, DiagLogLevel } = dynamicRequire('@opentelemetry/api', errPrefix);
182
+ const { NodeSDK } = dynamicRequire('@opentelemetry/sdk-node', errPrefix);
183
+ const { HttpInstrumentation } = dynamicRequire('@opentelemetry/instrumentation-http', errPrefix);
184
+ const { BatchSpanProcessor } = dynamicRequire('@opentelemetry/sdk-trace-base', errPrefix);
185
+ const { OTLPTraceExporter } = dynamicRequire('@opentelemetry/exporter-trace-otlp-http', errPrefix);
186
+ const { CompressionAlgorithm } = dynamicRequire('@opentelemetry/otlp-exporter-base', errPrefix);
187
+ const { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } = dynamicRequire('@opentelemetry/semantic-conventions', errPrefix);
188
+ const { resourceFromAttributes } = dynamicRequire('@opentelemetry/resources', errPrefix);
189
+ diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
190
+ this.otelSdk = new NodeSDK({
191
+ resource: resourceFromAttributes({
192
+ [ATTR_SERVICE_VERSION]: packageJson.version,
193
+ [ATTR_SERVICE_NAME]: 'daytona-typescript-sdk',
171
194
  }),
172
- ],
173
- spanProcessors: [
174
- new BatchSpanProcessor(new OTLPTraceExporter({
175
- compression: CompressionAlgorithm.GZIP,
176
- })),
177
- ],
178
- });
179
- this.otelSdk.start();
180
- // Flush and shutdown OTEL on process exit
181
- process.on('SIGTERM', async () => {
182
- await this.otelSdk?.shutdown();
183
- });
184
- }
185
- async [Symbol.asyncDispose]() {
186
- if (!this.otelSdk) {
187
- return;
188
- }
189
- await this.otelSdk.shutdown();
190
- }
191
- async create(params, options = { timeout: 60 }) {
192
- const startTime = Date.now();
193
- options = typeof options === 'number' ? { timeout: options } : { ...options };
194
- if (options.timeout == undefined || options.timeout == null) {
195
- options.timeout = 60;
196
- }
197
- if (params == null) {
198
- params = { language: 'python' };
199
- }
200
- if (!params.language) {
201
- params.language = 'python';
195
+ instrumentations: [
196
+ new HttpInstrumentation({
197
+ requireParentforOutgoingSpans: false,
198
+ }),
199
+ ],
200
+ spanProcessors: [
201
+ new BatchSpanProcessor(new OTLPTraceExporter({
202
+ compression: CompressionAlgorithm.GZIP,
203
+ })),
204
+ ],
205
+ });
206
+ this.otelSdk.start();
207
+ // Flush and shutdown OTEL on process exit
208
+ process.on('SIGTERM', async () => {
209
+ await this.otelSdk?.shutdown();
210
+ });
202
211
  }
203
- const labels = params.labels || {};
204
- if (params.language) {
205
- const validLanguages = Object.values(CodeLanguage);
206
- if (!validLanguages.includes(params.language)) {
207
- throw new DaytonaValidationError(`Invalid ${CODE_TOOLBOX_LANGUAGE_LABEL}: ${params.language}. Supported languages: ${validLanguages.join(', ')}`);
212
+ async [Symbol.asyncDispose]() {
213
+ if (!this.otelSdk) {
214
+ return;
208
215
  }
209
- labels[CODE_TOOLBOX_LANGUAGE_LABEL] = params.language;
210
- }
211
- if (options.timeout < 0) {
212
- throw new DaytonaValidationError('Timeout must be a non-negative number');
216
+ await this.otelSdk.shutdown();
213
217
  }
214
- if (params.autoStopInterval !== undefined &&
215
- (!Number.isInteger(params.autoStopInterval) || params.autoStopInterval < 0)) {
216
- throw new DaytonaValidationError('autoStopInterval must be a non-negative integer');
217
- }
218
- if (params.ephemeral) {
219
- if (params.autoDeleteInterval !== undefined && params.autoDeleteInterval !== 0) {
220
- console.warn("'ephemeral' and 'autoDeleteInterval' cannot be used together. If ephemeral is true, autoDeleteInterval will be ignored and set to 0.");
218
+ async create(params, options = { timeout: 60 }) {
219
+ const startTime = Date.now();
220
+ options = typeof options === 'number' ? { timeout: options } : { ...options };
221
+ if (options.timeout == undefined || options.timeout == null) {
222
+ options.timeout = 60;
221
223
  }
222
- params.autoDeleteInterval = 0;
223
- }
224
- if (params.autoArchiveInterval !== undefined &&
225
- (!Number.isInteger(params.autoArchiveInterval) || params.autoArchiveInterval < 0)) {
226
- throw new DaytonaValidationError('autoArchiveInterval must be a non-negative integer');
227
- }
228
- try {
229
- let buildInfo;
230
- let snapshot;
231
- let resources;
232
- if ('snapshot' in params) {
233
- snapshot = params.snapshot;
224
+ if (params == null) {
225
+ params = { language: 'python' };
226
+ }
227
+ if (!params.language) {
228
+ params.language = 'python';
234
229
  }
235
- if ('image' in params) {
236
- if (typeof params.image === 'string') {
237
- buildInfo = {
238
- dockerfileContent: Image.base(params.image).dockerfile,
239
- };
230
+ const labels = params.labels || {};
231
+ if (params.language) {
232
+ const validLanguages = Object.values(CodeLanguage);
233
+ if (!validLanguages.includes(params.language)) {
234
+ throw new DaytonaValidationError(`Invalid ${CODE_TOOLBOX_LANGUAGE_LABEL}: ${params.language}. Supported languages: ${validLanguages.join(', ')}`);
240
235
  }
241
- else if (params.image instanceof Image) {
242
- const contextHashes = await SnapshotService.processImageContext(this.objectStorageApi, params.image);
243
- buildInfo = {
244
- contextHashes,
245
- dockerfileContent: params.image.dockerfile,
246
- };
236
+ labels[CODE_TOOLBOX_LANGUAGE_LABEL] = params.language;
237
+ }
238
+ if (options.timeout < 0) {
239
+ throw new DaytonaValidationError('Timeout must be a non-negative number');
240
+ }
241
+ if (params.autoStopInterval !== undefined &&
242
+ (!Number.isInteger(params.autoStopInterval) || params.autoStopInterval < 0)) {
243
+ throw new DaytonaValidationError('autoStopInterval must be a non-negative integer');
244
+ }
245
+ if (params.ephemeral) {
246
+ if (params.autoDeleteInterval !== undefined && params.autoDeleteInterval !== 0) {
247
+ console.warn("'ephemeral' and 'autoDeleteInterval' cannot be used together. If ephemeral is true, autoDeleteInterval will be ignored and set to 0.");
247
248
  }
249
+ params.autoDeleteInterval = 0;
248
250
  }
249
- if ('resources' in params) {
250
- resources = params.resources;
251
+ if (params.autoArchiveInterval !== undefined &&
252
+ (!Number.isInteger(params.autoArchiveInterval) || params.autoArchiveInterval < 0)) {
253
+ throw new DaytonaValidationError('autoArchiveInterval must be a non-negative integer');
251
254
  }
252
- const response = await this.sandboxApi.createSandbox({
253
- name: params.name,
254
- snapshot: snapshot,
255
- buildInfo,
256
- user: params.user,
257
- env: params.envVars || {},
258
- labels: labels,
259
- public: params.public,
260
- target: this.target,
261
- cpu: resources?.cpu,
262
- gpu: resources?.gpu,
263
- memory: resources?.memory,
264
- disk: resources?.disk,
265
- autoStopInterval: params.autoStopInterval,
266
- autoArchiveInterval: params.autoArchiveInterval,
267
- autoDeleteInterval: params.autoDeleteInterval,
268
- volumes: params.volumes,
269
- networkBlockAll: params.networkBlockAll,
270
- networkAllowList: params.networkAllowList,
271
- }, undefined, {
272
- timeout: options.timeout * 1000,
273
- });
274
- let sandboxInstance = response.data;
275
- if (sandboxInstance.state === SandboxState.PENDING_BUILD && options.onSnapshotCreateLogs) {
276
- const terminalStates = [
277
- SandboxState.STARTED,
278
- SandboxState.STARTING,
279
- SandboxState.ERROR,
280
- SandboxState.BUILD_FAILED,
281
- ];
282
- while (sandboxInstance.state === SandboxState.PENDING_BUILD) {
283
- if (options.timeout) {
284
- const elapsed = (Date.now() - startTime) / 1000;
285
- if (elapsed > options.timeout) {
286
- throw new DaytonaTimeoutError(`Sandbox build has been pending for more than ${options.timeout} seconds. Please check the sandbox state again later.`);
287
- }
255
+ try {
256
+ let buildInfo;
257
+ let snapshot;
258
+ let resources;
259
+ if ('snapshot' in params) {
260
+ snapshot = params.snapshot;
261
+ }
262
+ if ('image' in params) {
263
+ if (typeof params.image === 'string') {
264
+ buildInfo = {
265
+ dockerfileContent: Image.base(params.image).dockerfile,
266
+ };
267
+ }
268
+ else if (params.image instanceof Image) {
269
+ const contextHashes = await SnapshotService.processImageContext(this.objectStorageApi, params.image);
270
+ buildInfo = {
271
+ contextHashes,
272
+ dockerfileContent: params.image.dockerfile,
273
+ };
288
274
  }
289
- await new Promise((resolve) => setTimeout(resolve, 1000));
290
- sandboxInstance = (await this.sandboxApi.getSandbox(sandboxInstance.id)).data;
291
275
  }
292
- const response = await this.sandboxApi.getBuildLogsUrl(sandboxInstance.id);
293
- await processStreamingResponse(() => fetch(response.data.url + '?follow=true', {
294
- method: 'GET',
295
- headers: this.clientConfig.baseOptions.headers,
296
- }), (chunk) => options.onSnapshotCreateLogs?.(chunk.trimEnd()), async () => {
297
- sandboxInstance = (await this.sandboxApi.getSandbox(sandboxInstance.id)).data;
298
- return sandboxInstance.state !== undefined && terminalStates.includes(sandboxInstance.state);
276
+ if ('resources' in params) {
277
+ resources = params.resources;
278
+ }
279
+ const response = await this.sandboxApi.createSandbox({
280
+ name: params.name,
281
+ snapshot: snapshot,
282
+ buildInfo,
283
+ user: params.user,
284
+ env: params.envVars || {},
285
+ labels: labels,
286
+ public: params.public,
287
+ target: this.target,
288
+ cpu: resources?.cpu,
289
+ gpu: resources?.gpu,
290
+ memory: resources?.memory,
291
+ disk: resources?.disk,
292
+ autoStopInterval: params.autoStopInterval,
293
+ autoArchiveInterval: params.autoArchiveInterval,
294
+ autoDeleteInterval: params.autoDeleteInterval,
295
+ volumes: params.volumes,
296
+ networkBlockAll: params.networkBlockAll,
297
+ networkAllowList: params.networkAllowList,
298
+ }, undefined, {
299
+ timeout: options.timeout * 1000,
299
300
  });
301
+ let sandboxInstance = response.data;
302
+ if (sandboxInstance.state === SandboxState.PENDING_BUILD && options.onSnapshotCreateLogs) {
303
+ const terminalStates = [
304
+ SandboxState.STARTED,
305
+ SandboxState.STARTING,
306
+ SandboxState.ERROR,
307
+ SandboxState.BUILD_FAILED,
308
+ ];
309
+ while (sandboxInstance.state === SandboxState.PENDING_BUILD) {
310
+ if (options.timeout) {
311
+ const elapsed = (Date.now() - startTime) / 1000;
312
+ if (elapsed > options.timeout) {
313
+ throw new DaytonaTimeoutError(`Sandbox build has been pending for more than ${options.timeout} seconds. Please check the sandbox state again later.`);
314
+ }
315
+ }
316
+ await new Promise((resolve) => setTimeout(resolve, 1000));
317
+ sandboxInstance = (await this.sandboxApi.getSandbox(sandboxInstance.id)).data;
318
+ }
319
+ const response = await this.sandboxApi.getBuildLogsUrl(sandboxInstance.id);
320
+ await processStreamingResponse(() => fetch(response.data.url + '?follow=true', {
321
+ method: 'GET',
322
+ headers: this.clientConfig.baseOptions.headers,
323
+ }), (chunk) => options.onSnapshotCreateLogs?.(chunk.trimEnd()), async () => {
324
+ sandboxInstance = (await this.sandboxApi.getSandbox(sandboxInstance.id)).data;
325
+ return sandboxInstance.state !== undefined && terminalStates.includes(sandboxInstance.state);
326
+ });
327
+ }
328
+ const sandbox = new Sandbox(sandboxInstance, new Configuration(structuredClone(this.clientConfig)), Daytona.createAxiosInstance(), this.sandboxApi);
329
+ if (sandbox.state !== 'started') {
330
+ const timeElapsed = Date.now() - startTime;
331
+ await sandbox.waitUntilStarted(options.timeout ? Math.max(0.001, options.timeout - timeElapsed / 1000) : options.timeout);
332
+ }
333
+ return sandbox;
300
334
  }
301
- const sandbox = new Sandbox(sandboxInstance, new Configuration(structuredClone(this.clientConfig)), Daytona.createAxiosInstance(), this.sandboxApi);
302
- if (sandbox.state !== 'started') {
303
- const timeElapsed = Date.now() - startTime;
304
- await sandbox.waitUntilStarted(options.timeout ? Math.max(0.001, options.timeout - timeElapsed / 1000) : options.timeout);
335
+ catch (error) {
336
+ if (error instanceof DaytonaTimeoutError) {
337
+ const errMsg = `Failed to create and start sandbox within ${options.timeout} seconds. Operation timed out.`;
338
+ throw new DaytonaTimeoutError(errMsg, error.statusCode, error.headers, error.errorCode);
339
+ }
340
+ throw error;
305
341
  }
306
- return sandbox;
307
342
  }
308
- catch (error) {
309
- if (error instanceof DaytonaTimeoutError) {
310
- const errMsg = `Failed to create and start sandbox within ${options.timeout} seconds. Operation timed out.`;
311
- throw new DaytonaTimeoutError(errMsg, error.statusCode, error.headers, error.errorCode);
312
- }
313
- throw error;
343
+ /**
344
+ * Gets a Sandbox by its ID or name.
345
+ *
346
+ * @param {string} sandboxIdOrName - The ID or name of the Sandbox to retrieve
347
+ * @returns {Promise<Sandbox>} The Sandbox
348
+ *
349
+ * @example
350
+ * const sandbox = await daytona.get('my-sandbox-id-or-name');
351
+ * console.log(`Sandbox state: ${sandbox.state}`);
352
+ */
353
+ async get(sandboxIdOrName) {
354
+ const response = await this.sandboxApi.getSandbox(sandboxIdOrName);
355
+ const sandboxInstance = response.data;
356
+ return new Sandbox(sandboxInstance, structuredClone(this.clientConfig), Daytona.createAxiosInstance(), this.sandboxApi);
314
357
  }
315
- }
316
- /**
317
- * Gets a Sandbox by its ID or name.
318
- *
319
- * @param {string} sandboxIdOrName - The ID or name of the Sandbox to retrieve
320
- * @returns {Promise<Sandbox>} The Sandbox
321
- *
322
- * @example
323
- * const sandbox = await daytona.get('my-sandbox-id-or-name');
324
- * console.log(`Sandbox state: ${sandbox.state}`);
325
- */
326
- async get(sandboxIdOrName) {
327
- const response = await this.sandboxApi.getSandbox(sandboxIdOrName);
328
- const sandboxInstance = response.data;
329
- return new Sandbox(sandboxInstance, structuredClone(this.clientConfig), Daytona.createAxiosInstance(), this.sandboxApi);
330
- }
331
- /**
332
- * Returns paginated list of Sandboxes filtered by labels.
333
- *
334
- * @param {Record<string, string>} [labels] - Labels to filter Sandboxes
335
- * @param {number} [page] - Page number for pagination (starting from 1)
336
- * @param {number} [limit] - Maximum number of items per page
337
- * @returns {Promise<PaginatedSandboxes>} Paginated list of Sandboxes that match the labels.
338
- *
339
- * @example
340
- * const result = await daytona.list({ 'my-label': 'my-value' }, 2, 10);
341
- * for (const sandbox of result.items) {
342
- * console.log(`${sandbox.id}: ${sandbox.state}`);
343
- * }
344
- */
345
- async list(labels, page, limit) {
346
- const response = await this.sandboxApi.listSandboxesPaginated(undefined, page, limit, undefined, undefined, labels ? JSON.stringify(labels) : undefined);
347
- return {
348
- items: response.data.items.map((sandbox) => {
349
- return new Sandbox(sandbox, structuredClone(this.clientConfig), Daytona.createAxiosInstance(), this.sandboxApi);
350
- }),
351
- total: response.data.total,
352
- page: response.data.page,
353
- totalPages: response.data.totalPages,
354
- };
355
- }
356
- /**
357
- * Starts a Sandbox and waits for it to be ready.
358
- *
359
- * @param {Sandbox} sandbox - The Sandbox to start
360
- * @param {number} [timeout] - Optional timeout in seconds (0 means no timeout)
361
- * @returns {Promise<void>}
362
- *
363
- * @example
364
- * const sandbox = await daytona.get('my-sandbox-id');
365
- * // Wait up to 60 seconds for the sandbox to start
366
- * await daytona.start(sandbox, 60);
367
- */
368
- async start(sandbox, timeout) {
369
- await sandbox.start(timeout);
370
- }
371
- /**
372
- * Stops a Sandbox.
373
- *
374
- * @param {Sandbox} sandbox - The Sandbox to stop
375
- * @returns {Promise<void>}
376
- *
377
- * @example
378
- * const sandbox = await daytona.get('my-sandbox-id');
379
- * await daytona.stop(sandbox);
380
- */
381
- async stop(sandbox) {
382
- await sandbox.stop();
383
- }
384
- /**
385
- * Forks a Sandbox, creating a new Sandbox with an identical filesystem.
386
- *
387
- * @param {Sandbox} sandbox - The Sandbox to fork
388
- * @param {object} [params] - Fork parameters
389
- * @param {string} [params.name] - Optional name for the forked Sandbox
390
- * @param {number} [timeout] - Timeout in seconds (0 means no timeout, default is 60)
391
- * @returns {Promise<Sandbox>} The forked Sandbox
392
- *
393
- * @example
394
- * const sandbox = await daytona.get('my-sandbox-id');
395
- * const forked = await daytona._experimental_fork(sandbox, { name: 'my-fork' });
396
- * console.log(`Forked sandbox: ${forked.id}`);
397
- */
398
- async _experimental_fork(sandbox, params, timeout = 60) {
399
- return await sandbox._experimental_fork(params, timeout);
400
- }
401
- /**
402
- * Deletes a Sandbox.
403
- *
404
- * @param {Sandbox} sandbox - The Sandbox to delete
405
- * @param {number} timeout - Timeout in seconds (0 means no timeout, default is 60)
406
- * @returns {Promise<void>}
407
- *
408
- * @example
409
- * const sandbox = await daytona.get('my-sandbox-id');
410
- * await daytona.delete(sandbox);
411
- */
412
- async delete(sandbox, timeout = 60) {
413
- await sandbox.delete(timeout);
414
- }
415
- /**
416
- * @hidden
417
- */
418
- static createAxiosInstance() {
419
- const axiosInstance = axios.create({
420
- timeout: 24 * 60 * 60 * 1000, // 24 hours
421
- });
422
- // Request interceptor: Inject trace context into headers
423
- axiosInstance.interceptors.request.use((requestConfig) => {
424
- // Get the current active context (which may contain an active span)
425
- const currentContext = context.active();
426
- // Inject trace context into HTTP headers using W3C Trace Context propagation
427
- // This adds headers like 'traceparent' and 'tracestate'
428
- propagation.inject(currentContext, requestConfig.headers);
429
- requestConfig.metadata = { startTime: Date.now() };
430
- return requestConfig;
431
- }, (error) => {
432
- return Promise.reject(error);
433
- });
434
- axiosInstance.interceptors.response.use((response) => {
435
- return response;
436
- }, (error) => {
437
- if (error instanceof AxiosError) {
438
- throw createAxiosDaytonaError(error);
439
- }
440
- throw new DaytonaError(error instanceof Error ? error.message : String(error));
441
- });
442
- axiosInstance.interceptors.response.use((response) => {
443
- const startTime = response.config.metadata?.startTime;
444
- if (startTime) {
445
- const duration = Date.now() - startTime;
446
- // Get the active span to add attributes
447
- const activeSpan = trace.getActiveSpan();
448
- // Only modify the span if it's still recording (not ended)
449
- if (activeSpan && activeSpan.isRecording()) {
450
- // Add response metadata to the span
451
- activeSpan.setAttributes({
452
- 'http.response.status_code': response.status,
453
- 'http.response.duration_ms': duration,
454
- // 'http.response.size_bytes': JSON.stringify(response.data).length,
455
- });
358
+ /**
359
+ * Returns paginated list of Sandboxes filtered by labels.
360
+ *
361
+ * @param {Record<string, string>} [labels] - Labels to filter Sandboxes
362
+ * @param {number} [page] - Page number for pagination (starting from 1)
363
+ * @param {number} [limit] - Maximum number of items per page
364
+ * @returns {Promise<PaginatedSandboxes>} Paginated list of Sandboxes that match the labels.
365
+ *
366
+ * @example
367
+ * const result = await daytona.list({ 'my-label': 'my-value' }, 2, 10);
368
+ * for (const sandbox of result.items) {
369
+ * console.log(`${sandbox.id}: ${sandbox.state}`);
370
+ * }
371
+ */
372
+ async list(labels, page, limit) {
373
+ const response = await this.sandboxApi.listSandboxesPaginated(undefined, page, limit, undefined, undefined, labels ? JSON.stringify(labels) : undefined);
374
+ return {
375
+ items: response.data.items.map((sandbox) => {
376
+ return new Sandbox(sandbox, structuredClone(this.clientConfig), Daytona.createAxiosInstance(), this.sandboxApi);
377
+ }),
378
+ total: response.data.total,
379
+ page: response.data.page,
380
+ totalPages: response.data.totalPages,
381
+ };
382
+ }
383
+ /**
384
+ * Starts a Sandbox and waits for it to be ready.
385
+ *
386
+ * @param {Sandbox} sandbox - The Sandbox to start
387
+ * @param {number} [timeout] - Optional timeout in seconds (0 means no timeout)
388
+ * @returns {Promise<void>}
389
+ *
390
+ * @example
391
+ * const sandbox = await daytona.get('my-sandbox-id');
392
+ * // Wait up to 60 seconds for the sandbox to start
393
+ * await daytona.start(sandbox, 60);
394
+ */
395
+ async start(sandbox, timeout) {
396
+ await sandbox.start(timeout);
397
+ }
398
+ /**
399
+ * Stops a Sandbox.
400
+ *
401
+ * @param {Sandbox} sandbox - The Sandbox to stop
402
+ * @returns {Promise<void>}
403
+ *
404
+ * @example
405
+ * const sandbox = await daytona.get('my-sandbox-id');
406
+ * await daytona.stop(sandbox);
407
+ */
408
+ async stop(sandbox) {
409
+ await sandbox.stop();
410
+ }
411
+ /**
412
+ * Forks a Sandbox, creating a new Sandbox with an identical filesystem.
413
+ *
414
+ * @param {Sandbox} sandbox - The Sandbox to fork
415
+ * @param {object} [params] - Fork parameters
416
+ * @param {string} [params.name] - Optional name for the forked Sandbox
417
+ * @param {number} [timeout] - Timeout in seconds (0 means no timeout, default is 60)
418
+ * @returns {Promise<Sandbox>} The forked Sandbox
419
+ *
420
+ * @example
421
+ * const sandbox = await daytona.get('my-sandbox-id');
422
+ * const forked = await daytona._experimental_fork(sandbox, { name: 'my-fork' });
423
+ * console.log(`Forked sandbox: ${forked.id}`);
424
+ */
425
+ async _experimental_fork(sandbox, params, timeout = 60) {
426
+ return await sandbox._experimental_fork(params, timeout);
427
+ }
428
+ /**
429
+ * Deletes a Sandbox.
430
+ *
431
+ * @param {Sandbox} sandbox - The Sandbox to delete
432
+ * @param {number} timeout - Timeout in seconds (0 means no timeout, default is 60)
433
+ * @returns {Promise<void>}
434
+ *
435
+ * @example
436
+ * const sandbox = await daytona.get('my-sandbox-id');
437
+ * await daytona.delete(sandbox);
438
+ */
439
+ async delete(sandbox, timeout = 60) {
440
+ await sandbox.delete(timeout);
441
+ }
442
+ /**
443
+ * @hidden
444
+ */
445
+ static createAxiosInstance() {
446
+ const axiosInstance = axios.create({
447
+ timeout: 24 * 60 * 60 * 1000, // 24 hours
448
+ });
449
+ // Request interceptor: Inject trace context into headers
450
+ axiosInstance.interceptors.request.use((requestConfig) => {
451
+ // Get the current active context (which may contain an active span)
452
+ const currentContext = context.active();
453
+ // Inject trace context into HTTP headers using W3C Trace Context propagation
454
+ // This adds headers like 'traceparent' and 'tracestate'
455
+ propagation.inject(currentContext, requestConfig.headers);
456
+ requestConfig.metadata = { startTime: Date.now() };
457
+ return requestConfig;
458
+ }, (error) => {
459
+ return Promise.reject(error);
460
+ });
461
+ axiosInstance.interceptors.response.use((response) => {
462
+ return response;
463
+ }, (error) => {
464
+ if (error instanceof AxiosError) {
465
+ throw createAxiosDaytonaError(error);
456
466
  }
457
- }
458
- return response;
459
- }, (error) => {
460
- const startTime = error.config?.metadata?.startTime;
461
- if (startTime) {
462
- const duration = Date.now() - startTime;
463
- // Get the active span to record the error
464
- const activeSpan = trace.getActiveSpan();
465
- // Only modify the span if it's still recording (not ended)
466
- if (activeSpan && activeSpan.isRecording()) {
467
- activeSpan.setStatus({
468
- code: SpanStatusCode.ERROR,
469
- message: error.message,
470
- });
471
- activeSpan.setAttributes({
472
- 'http.response.duration_ms': duration,
473
- 'error.type': error.name,
474
- 'error.message': error.message,
475
- });
476
- if (error.response) {
477
- activeSpan.setAttribute('http.response.status_code', error.response.status);
467
+ throw new DaytonaError(error instanceof Error ? error.message : String(error));
468
+ });
469
+ axiosInstance.interceptors.response.use((response) => {
470
+ const startTime = response.config.metadata?.startTime;
471
+ if (startTime) {
472
+ const duration = Date.now() - startTime;
473
+ // Get the active span to add attributes
474
+ const activeSpan = trace.getActiveSpan();
475
+ // Only modify the span if it's still recording (not ended)
476
+ if (activeSpan && activeSpan.isRecording()) {
477
+ // Add response metadata to the span
478
+ activeSpan.setAttributes({
479
+ 'http.response.status_code': response.status,
480
+ 'http.response.duration_ms': duration,
481
+ // 'http.response.size_bytes': JSON.stringify(response.data).length,
482
+ });
478
483
  }
479
- // Record the exception on the span
480
- activeSpan.recordException(error);
481
484
  }
482
- }
483
- return Promise.reject(error);
484
- });
485
- return axiosInstance;
486
- }
487
- }
488
- __decorate([
489
- WithInstrumentation(),
490
- __metadata("design:type", Function),
491
- __metadata("design:paramtypes", [Object, Object]),
492
- __metadata("design:returntype", Promise)
493
- ], Daytona.prototype, "create", null);
494
- __decorate([
495
- WithInstrumentation(),
496
- __metadata("design:type", Function),
497
- __metadata("design:paramtypes", [String]),
498
- __metadata("design:returntype", Promise)
499
- ], Daytona.prototype, "get", null);
500
- __decorate([
501
- WithInstrumentation(),
502
- __metadata("design:type", Function),
503
- __metadata("design:paramtypes", [Object, Number, Number]),
504
- __metadata("design:returntype", Promise)
505
- ], Daytona.prototype, "list", null);
506
- __decorate([
507
- WithInstrumentation(),
508
- __metadata("design:type", Function),
509
- __metadata("design:paramtypes", [Sandbox, Number]),
510
- __metadata("design:returntype", Promise)
511
- ], Daytona.prototype, "start", null);
512
- __decorate([
513
- WithInstrumentation(),
514
- __metadata("design:type", Function),
515
- __metadata("design:paramtypes", [Sandbox]),
516
- __metadata("design:returntype", Promise)
517
- ], Daytona.prototype, "stop", null);
518
- __decorate([
519
- WithInstrumentation(),
520
- __metadata("design:type", Function),
521
- __metadata("design:paramtypes", [Sandbox, Object, Object]),
522
- __metadata("design:returntype", Promise)
523
- ], Daytona.prototype, "_experimental_fork", null);
524
- __decorate([
525
- WithInstrumentation(),
526
- __metadata("design:type", Function),
527
- __metadata("design:paramtypes", [Sandbox, Object]),
528
- __metadata("design:returntype", Promise)
529
- ], Daytona.prototype, "delete", null);
485
+ return response;
486
+ }, (error) => {
487
+ const startTime = error.config?.metadata?.startTime;
488
+ if (startTime) {
489
+ const duration = Date.now() - startTime;
490
+ // Get the active span to record the error
491
+ const activeSpan = trace.getActiveSpan();
492
+ // Only modify the span if it's still recording (not ended)
493
+ if (activeSpan && activeSpan.isRecording()) {
494
+ activeSpan.setStatus({
495
+ code: SpanStatusCode.ERROR,
496
+ message: error.message,
497
+ });
498
+ activeSpan.setAttributes({
499
+ 'http.response.duration_ms': duration,
500
+ 'error.type': error.name,
501
+ 'error.message': error.message,
502
+ });
503
+ if (error.response) {
504
+ activeSpan.setAttribute('http.response.status_code', error.response.status);
505
+ }
506
+ // Record the exception on the span
507
+ activeSpan.recordException(error);
508
+ }
509
+ }
510
+ return Promise.reject(error);
511
+ });
512
+ return axiosInstance;
513
+ }
514
+ };
515
+ })();
516
+ export { Daytona };
530
517
  //# sourceMappingURL=Daytona.js.map