@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.
- package/cjs/CodeInterpreter.d.ts +3 -2
- package/cjs/CodeInterpreter.js.map +1 -1
- package/cjs/ComputerUse.d.ts +104 -2
- package/cjs/ComputerUse.js +851 -763
- package/cjs/ComputerUse.js.map +1 -1
- package/cjs/Daytona.d.ts +4 -3
- package/cjs/Daytona.js +429 -443
- package/cjs/Daytona.js.map +1 -1
- package/cjs/FileSystem.d.ts +2 -2
- package/cjs/FileSystem.js +491 -521
- package/cjs/FileSystem.js.map +1 -1
- package/cjs/Git.d.ts +2 -1
- package/cjs/Git.js +287 -310
- package/cjs/Git.js.map +1 -1
- package/cjs/LspServer.d.ts +2 -1
- package/cjs/LspServer.js +209 -226
- package/cjs/LspServer.js.map +1 -1
- package/cjs/ObjectStorage.js +170 -166
- package/cjs/ObjectStorage.js.map +1 -1
- package/cjs/Process.d.ts +4 -3
- package/cjs/Process.js +562 -600
- package/cjs/Process.js.map +1 -1
- package/cjs/PtyHandle.d.ts +2 -2
- package/cjs/PtyHandle.js +327 -338
- package/cjs/PtyHandle.js.map +1 -1
- package/cjs/Sandbox.d.ts +4 -3
- package/cjs/Sandbox.js +756 -821
- package/cjs/Sandbox.js.map +1 -1
- package/cjs/Snapshot.d.ts +3 -2
- package/cjs/Snapshot.js +203 -213
- package/cjs/Snapshot.js.map +1 -1
- package/cjs/Volume.d.ts +2 -1
- package/cjs/Volume.js +90 -92
- package/cjs/Volume.js.map +1 -1
- package/cjs/errors/DaytonaError.d.ts +2 -1
- package/cjs/errors/DaytonaError.js.map +1 -1
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +2 -1
- package/cjs/index.js.map +1 -1
- package/cjs/types/CodeInterpreter.d.ts +1 -1
- package/cjs/utils/Binary.js +14 -2
- package/cjs/utils/Binary.js.map +1 -1
- package/cjs/utils/otel.decorator.d.ts +7 -8
- package/cjs/utils/otel.decorator.js +24 -30
- package/cjs/utils/otel.decorator.js.map +1 -1
- package/esm/CodeInterpreter.d.ts +3 -2
- package/esm/CodeInterpreter.js.map +1 -1
- package/esm/ComputerUse.d.ts +104 -2
- package/esm/ComputerUse.js +857 -763
- package/esm/ComputerUse.js.map +1 -1
- package/esm/Daytona.d.ts +4 -3
- package/esm/Daytona.js +431 -444
- package/esm/Daytona.js.map +1 -1
- package/esm/FileSystem.d.ts +2 -2
- package/esm/FileSystem.js +493 -522
- package/esm/FileSystem.js.map +1 -1
- package/esm/Git.d.ts +2 -1
- package/esm/Git.js +289 -311
- package/esm/Git.js.map +1 -1
- package/esm/LspServer.d.ts +2 -1
- package/esm/LspServer.js +211 -227
- package/esm/LspServer.js.map +1 -1
- package/esm/ObjectStorage.js +172 -167
- package/esm/ObjectStorage.js.map +1 -1
- package/esm/Process.d.ts +4 -3
- package/esm/Process.js +564 -601
- package/esm/Process.js.map +1 -1
- package/esm/PtyHandle.d.ts +2 -2
- package/esm/PtyHandle.js +329 -339
- package/esm/PtyHandle.js.map +1 -1
- package/esm/Sandbox.d.ts +4 -3
- package/esm/Sandbox.js +759 -823
- package/esm/Sandbox.js.map +1 -1
- package/esm/Snapshot.d.ts +3 -2
- package/esm/Snapshot.js +206 -215
- package/esm/Snapshot.js.map +1 -1
- package/esm/Volume.d.ts +2 -1
- package/esm/Volume.js +92 -93
- package/esm/Volume.js.map +1 -1
- package/esm/errors/DaytonaError.d.ts +2 -1
- package/esm/errors/DaytonaError.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/types/CodeInterpreter.d.ts +1 -1
- package/esm/utils/Binary.js +14 -2
- package/esm/utils/Binary.js.map +1 -1
- package/esm/utils/otel.decorator.d.ts +7 -8
- package/esm/utils/otel.decorator.js +26 -32
- package/esm/utils/otel.decorator.js.map +1 -1
- 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 {
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this
|
|
85
|
-
this.
|
|
86
|
-
this.
|
|
87
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
(!
|
|
226
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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 (
|
|
250
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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
|