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