@declaw/sdk 1.1.2 → 1.1.4
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/CHANGELOG.md +20 -0
- package/dist/index.cjs +90 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -1
- package/dist/index.d.ts +33 -1
- package/dist/index.js +80 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.d.cts
CHANGED
|
@@ -993,7 +993,7 @@ interface SandboxOpts {
|
|
|
993
993
|
volumes?: VolumeAttachment[];
|
|
994
994
|
/** API key override. */
|
|
995
995
|
apiKey?: string;
|
|
996
|
-
/** Domain override (supports "host:port" format, e.g. "
|
|
996
|
+
/** Domain override (supports "host:port" format, e.g. "myhost.example.com:8080"). */
|
|
997
997
|
domain?: string;
|
|
998
998
|
/** Full API URL override. If set, domain/port/scheme are ignored. */
|
|
999
999
|
apiUrl?: string;
|
|
@@ -1186,6 +1186,22 @@ declare class Sandbox {
|
|
|
1186
1186
|
* @returns Array of Snapshot metadata objects.
|
|
1187
1187
|
*/
|
|
1188
1188
|
listSnapshots(requestTimeout?: number): Promise<Snapshot[]>;
|
|
1189
|
+
/**
|
|
1190
|
+
* Delete a single snapshot of this sandbox by ID.
|
|
1191
|
+
*
|
|
1192
|
+
* The snapshot's PG row and S3 blobs (mem / vmstate / overlay) are
|
|
1193
|
+
* removed. Idempotent: deleting an already-deleted snapshot resolves to
|
|
1194
|
+
* true without throwing.
|
|
1195
|
+
*
|
|
1196
|
+
* The pause snapshot of a currently-paused sandbox is protected — the
|
|
1197
|
+
* server returns 409 because deletion would break Resume. Resume or
|
|
1198
|
+
* kill the sandbox first.
|
|
1199
|
+
*
|
|
1200
|
+
* @param snapshotId - The snapshot to delete.
|
|
1201
|
+
* @param requestTimeout - Optional per-request timeout in milliseconds.
|
|
1202
|
+
* @returns True on success.
|
|
1203
|
+
*/
|
|
1204
|
+
deleteSnapshot(snapshotId: string, requestTimeout?: number): Promise<boolean>;
|
|
1189
1205
|
/**
|
|
1190
1206
|
* Restore a sandbox from a snapshot. The restored instance may run on a
|
|
1191
1207
|
* different worker node than the original sandbox.
|
|
@@ -1372,8 +1388,24 @@ declare class TemplateBase {
|
|
|
1372
1388
|
private _envs;
|
|
1373
1389
|
private _aptPackages;
|
|
1374
1390
|
private _startCmd?;
|
|
1391
|
+
/**
|
|
1392
|
+
* When set, the server uses this Dockerfile verbatim and ignores the
|
|
1393
|
+
* structured fields. Use for multi-stage builds, ARG, ONBUILD, etc.
|
|
1394
|
+
*/
|
|
1395
|
+
private _dockerfile?;
|
|
1375
1396
|
/** Set the base image for the template. */
|
|
1376
1397
|
fromBaseImage(image?: string): this;
|
|
1398
|
+
/**
|
|
1399
|
+
* Use a raw Dockerfile string instead of the structured helpers.
|
|
1400
|
+
*
|
|
1401
|
+
* When set, all other ``aptInstall`` / ``runCmd`` / ``setEnvs`` /
|
|
1402
|
+
* ``copy`` / ``setStartCmd`` / ``fromBaseImage`` calls on this spec
|
|
1403
|
+
* are ignored — the Dockerfile is sent to the build worker verbatim.
|
|
1404
|
+
*
|
|
1405
|
+
* @param content Full Dockerfile contents. Must contain a ``FROM``
|
|
1406
|
+
* instruction. Capped server-side at 64 KiB.
|
|
1407
|
+
*/
|
|
1408
|
+
fromDockerfile(content: string): this;
|
|
1377
1409
|
/** Add a run command (as array of command + args). */
|
|
1378
1410
|
runCmd(cmds: string[]): this;
|
|
1379
1411
|
/** Add a file copy operation. */
|
package/dist/index.d.ts
CHANGED
|
@@ -993,7 +993,7 @@ interface SandboxOpts {
|
|
|
993
993
|
volumes?: VolumeAttachment[];
|
|
994
994
|
/** API key override. */
|
|
995
995
|
apiKey?: string;
|
|
996
|
-
/** Domain override (supports "host:port" format, e.g. "
|
|
996
|
+
/** Domain override (supports "host:port" format, e.g. "myhost.example.com:8080"). */
|
|
997
997
|
domain?: string;
|
|
998
998
|
/** Full API URL override. If set, domain/port/scheme are ignored. */
|
|
999
999
|
apiUrl?: string;
|
|
@@ -1186,6 +1186,22 @@ declare class Sandbox {
|
|
|
1186
1186
|
* @returns Array of Snapshot metadata objects.
|
|
1187
1187
|
*/
|
|
1188
1188
|
listSnapshots(requestTimeout?: number): Promise<Snapshot[]>;
|
|
1189
|
+
/**
|
|
1190
|
+
* Delete a single snapshot of this sandbox by ID.
|
|
1191
|
+
*
|
|
1192
|
+
* The snapshot's PG row and S3 blobs (mem / vmstate / overlay) are
|
|
1193
|
+
* removed. Idempotent: deleting an already-deleted snapshot resolves to
|
|
1194
|
+
* true without throwing.
|
|
1195
|
+
*
|
|
1196
|
+
* The pause snapshot of a currently-paused sandbox is protected — the
|
|
1197
|
+
* server returns 409 because deletion would break Resume. Resume or
|
|
1198
|
+
* kill the sandbox first.
|
|
1199
|
+
*
|
|
1200
|
+
* @param snapshotId - The snapshot to delete.
|
|
1201
|
+
* @param requestTimeout - Optional per-request timeout in milliseconds.
|
|
1202
|
+
* @returns True on success.
|
|
1203
|
+
*/
|
|
1204
|
+
deleteSnapshot(snapshotId: string, requestTimeout?: number): Promise<boolean>;
|
|
1189
1205
|
/**
|
|
1190
1206
|
* Restore a sandbox from a snapshot. The restored instance may run on a
|
|
1191
1207
|
* different worker node than the original sandbox.
|
|
@@ -1372,8 +1388,24 @@ declare class TemplateBase {
|
|
|
1372
1388
|
private _envs;
|
|
1373
1389
|
private _aptPackages;
|
|
1374
1390
|
private _startCmd?;
|
|
1391
|
+
/**
|
|
1392
|
+
* When set, the server uses this Dockerfile verbatim and ignores the
|
|
1393
|
+
* structured fields. Use for multi-stage builds, ARG, ONBUILD, etc.
|
|
1394
|
+
*/
|
|
1395
|
+
private _dockerfile?;
|
|
1375
1396
|
/** Set the base image for the template. */
|
|
1376
1397
|
fromBaseImage(image?: string): this;
|
|
1398
|
+
/**
|
|
1399
|
+
* Use a raw Dockerfile string instead of the structured helpers.
|
|
1400
|
+
*
|
|
1401
|
+
* When set, all other ``aptInstall`` / ``runCmd`` / ``setEnvs`` /
|
|
1402
|
+
* ``copy`` / ``setStartCmd`` / ``fromBaseImage`` calls on this spec
|
|
1403
|
+
* are ignored — the Dockerfile is sent to the build worker verbatim.
|
|
1404
|
+
*
|
|
1405
|
+
* @param content Full Dockerfile contents. Must contain a ``FROM``
|
|
1406
|
+
* instruction. Capped server-side at 64 KiB.
|
|
1407
|
+
*/
|
|
1408
|
+
fromDockerfile(content: string): this;
|
|
1377
1409
|
/** Add a run command (as array of command + args). */
|
|
1378
1410
|
runCmd(cmds: string[]): this;
|
|
1379
1411
|
/** Add a file copy operation. */
|
package/dist/index.js
CHANGED
|
@@ -116,6 +116,37 @@ var CommandExitError = class extends SandboxError {
|
|
|
116
116
|
};
|
|
117
117
|
|
|
118
118
|
// src/api/client.ts
|
|
119
|
+
var _dispatcherPromise;
|
|
120
|
+
function getDispatcher() {
|
|
121
|
+
if (_dispatcherPromise) return _dispatcherPromise;
|
|
122
|
+
_dispatcherPromise = (async () => {
|
|
123
|
+
try {
|
|
124
|
+
if (typeof process === "undefined" || !process.versions?.node) {
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
if (process.env.DECLAW_SDK_DISABLE_DISPATCHER) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
const origEmit = process.emitWarning;
|
|
131
|
+
process.emitWarning = ((warning, ...rest) => {
|
|
132
|
+
if (rest[0] === "UNDICI-H2") return;
|
|
133
|
+
return origEmit.call(process, warning, ...rest);
|
|
134
|
+
});
|
|
135
|
+
const undici = await import("undici");
|
|
136
|
+
return new undici.Agent({
|
|
137
|
+
connections: 10,
|
|
138
|
+
keepAliveTimeout: 3e4,
|
|
139
|
+
keepAliveMaxTimeout: 6e4,
|
|
140
|
+
pipelining: 1,
|
|
141
|
+
allowH2: true,
|
|
142
|
+
connect: { keepAlive: true, keepAliveInitialDelay: 5e3 }
|
|
143
|
+
});
|
|
144
|
+
} catch {
|
|
145
|
+
return void 0;
|
|
146
|
+
}
|
|
147
|
+
})();
|
|
148
|
+
return _dispatcherPromise;
|
|
149
|
+
}
|
|
119
150
|
var STATUS_ERROR_MAP = {
|
|
120
151
|
401: AuthenticationError,
|
|
121
152
|
403: AuthenticationError,
|
|
@@ -226,12 +257,15 @@ var ApiClient = class {
|
|
|
226
257
|
signals.push(AbortSignal.timeout(timeoutMs));
|
|
227
258
|
}
|
|
228
259
|
const signal = signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
229
|
-
const
|
|
260
|
+
const dispatcher = await getDispatcher();
|
|
261
|
+
const fetchOpts = {
|
|
230
262
|
method,
|
|
231
263
|
headers,
|
|
232
264
|
body: fetchBody,
|
|
233
265
|
signal
|
|
234
|
-
}
|
|
266
|
+
};
|
|
267
|
+
if (dispatcher) fetchOpts.dispatcher = dispatcher;
|
|
268
|
+
const response = await fetch(url, fetchOpts);
|
|
235
269
|
if (response.status >= 500 && attempt < this.maxRetries - 1) {
|
|
236
270
|
await this.delay(attempt);
|
|
237
271
|
continue;
|
|
@@ -2119,6 +2153,27 @@ var Sandbox = class _Sandbox {
|
|
|
2119
2153
|
const raw = data.snapshots ?? [];
|
|
2120
2154
|
return raw.map((s) => parseSnapshot(s));
|
|
2121
2155
|
}
|
|
2156
|
+
/**
|
|
2157
|
+
* Delete a single snapshot of this sandbox by ID.
|
|
2158
|
+
*
|
|
2159
|
+
* The snapshot's PG row and S3 blobs (mem / vmstate / overlay) are
|
|
2160
|
+
* removed. Idempotent: deleting an already-deleted snapshot resolves to
|
|
2161
|
+
* true without throwing.
|
|
2162
|
+
*
|
|
2163
|
+
* The pause snapshot of a currently-paused sandbox is protected — the
|
|
2164
|
+
* server returns 409 because deletion would break Resume. Resume or
|
|
2165
|
+
* kill the sandbox first.
|
|
2166
|
+
*
|
|
2167
|
+
* @param snapshotId - The snapshot to delete.
|
|
2168
|
+
* @param requestTimeout - Optional per-request timeout in milliseconds.
|
|
2169
|
+
* @returns True on success.
|
|
2170
|
+
*/
|
|
2171
|
+
async deleteSnapshot(snapshotId, requestTimeout) {
|
|
2172
|
+
await this._client.delete(`/sandboxes/${this._sandboxId}/snapshots/${snapshotId}`, {
|
|
2173
|
+
timeout: requestTimeout
|
|
2174
|
+
});
|
|
2175
|
+
return true;
|
|
2176
|
+
}
|
|
2122
2177
|
/**
|
|
2123
2178
|
* Restore a sandbox from a snapshot. The restored instance may run on a
|
|
2124
2179
|
* different worker node than the original sandbox.
|
|
@@ -2303,11 +2358,30 @@ var TemplateBase = class {
|
|
|
2303
2358
|
_envs = {};
|
|
2304
2359
|
_aptPackages = [];
|
|
2305
2360
|
_startCmd;
|
|
2361
|
+
/**
|
|
2362
|
+
* When set, the server uses this Dockerfile verbatim and ignores the
|
|
2363
|
+
* structured fields. Use for multi-stage builds, ARG, ONBUILD, etc.
|
|
2364
|
+
*/
|
|
2365
|
+
_dockerfile;
|
|
2306
2366
|
/** Set the base image for the template. */
|
|
2307
2367
|
fromBaseImage(image) {
|
|
2308
2368
|
this._baseImage = image ?? "ubuntu:22.04";
|
|
2309
2369
|
return this;
|
|
2310
2370
|
}
|
|
2371
|
+
/**
|
|
2372
|
+
* Use a raw Dockerfile string instead of the structured helpers.
|
|
2373
|
+
*
|
|
2374
|
+
* When set, all other ``aptInstall`` / ``runCmd`` / ``setEnvs`` /
|
|
2375
|
+
* ``copy`` / ``setStartCmd`` / ``fromBaseImage`` calls on this spec
|
|
2376
|
+
* are ignored — the Dockerfile is sent to the build worker verbatim.
|
|
2377
|
+
*
|
|
2378
|
+
* @param content Full Dockerfile contents. Must contain a ``FROM``
|
|
2379
|
+
* instruction. Capped server-side at 64 KiB.
|
|
2380
|
+
*/
|
|
2381
|
+
fromDockerfile(content) {
|
|
2382
|
+
this._dockerfile = content;
|
|
2383
|
+
return this;
|
|
2384
|
+
}
|
|
2311
2385
|
/** Add a run command (as array of command + args). */
|
|
2312
2386
|
runCmd(cmds) {
|
|
2313
2387
|
this._runCmds.push(cmds);
|
|
@@ -2335,11 +2409,14 @@ var TemplateBase = class {
|
|
|
2335
2409
|
}
|
|
2336
2410
|
/** Serialize the template to a JSON-friendly object. */
|
|
2337
2411
|
toJSON() {
|
|
2412
|
+
if (this._dockerfile !== void 0) {
|
|
2413
|
+
return { dockerfile: this._dockerfile };
|
|
2414
|
+
}
|
|
2338
2415
|
const result = {
|
|
2339
2416
|
base_image: this._baseImage
|
|
2340
2417
|
};
|
|
2341
2418
|
if (this._runCmds.length > 0) {
|
|
2342
|
-
result.run_cmds = this._runCmds;
|
|
2419
|
+
result.run_cmds = this._runCmds.map((c) => c.join(" "));
|
|
2343
2420
|
}
|
|
2344
2421
|
if (this._copies.length > 0) {
|
|
2345
2422
|
result.copies = this._copies;
|