@cloudflare/sandbox 0.9.4 → 0.10.1
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/Dockerfile +9 -5
- package/dist/bridge/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/openai/index.d.ts +1 -1
- package/dist/opencode/index.d.ts +1 -1
- package/dist/opencode/index.d.ts.map +1 -1
- package/dist/{sandbox-C-AzrX_L.d.ts → sandbox-BVgScWy9.d.ts} +72 -26
- package/dist/sandbox-BVgScWy9.d.ts.map +1 -0
- package/dist/{sandbox-CdWjEUHl.js → sandbox-uC1vzWtG.js} +62 -41
- package/dist/sandbox-uC1vzWtG.js.map +1 -0
- package/package.json +2 -2
- package/dist/sandbox-C-AzrX_L.d.ts.map +0 -1
- package/dist/sandbox-CdWjEUHl.js.map +0 -1
|
@@ -2050,13 +2050,8 @@ var FileClient = class extends BaseHttpClient {
|
|
|
2050
2050
|
};
|
|
2051
2051
|
return await this.post("/api/write", data);
|
|
2052
2052
|
}
|
|
2053
|
-
/**
|
|
2054
|
-
* Read content from a file
|
|
2055
|
-
* @param path - File path to read from
|
|
2056
|
-
* @param sessionId - The session ID for this operation
|
|
2057
|
-
* @param options - Optional settings (encoding)
|
|
2058
|
-
*/
|
|
2059
2053
|
async readFile(path$1, sessionId, options) {
|
|
2054
|
+
if (options?.encoding === "none") throw new Error("readFile with encoding: 'none' requires the rpc transport. Set SANDBOX_TRANSPORT=rpc.");
|
|
2060
2055
|
const data = {
|
|
2061
2056
|
path: path$1,
|
|
2062
2057
|
sessionId,
|
|
@@ -2143,6 +2138,13 @@ var FileClient = class extends BaseHttpClient {
|
|
|
2143
2138
|
};
|
|
2144
2139
|
return await this.post("/api/exists", data);
|
|
2145
2140
|
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Write a file via a raw binary stream over the RPC transport.
|
|
2143
|
+
* Throws on HTTP and WebSocket transports — use writeFile() with a string instead.
|
|
2144
|
+
*/
|
|
2145
|
+
writeFileStream(_path, _content, _sessionId) {
|
|
2146
|
+
throw new Error("writeFileStream requires the rpc transport. Set SANDBOX_TRANSPORT=rpc.");
|
|
2147
|
+
}
|
|
2146
2148
|
};
|
|
2147
2149
|
|
|
2148
2150
|
//#endregion
|
|
@@ -2706,16 +2708,6 @@ var SandboxClient = class {
|
|
|
2706
2708
|
return this.transport?.isConnected() ?? false;
|
|
2707
2709
|
}
|
|
2708
2710
|
/**
|
|
2709
|
-
* Stream a file directly to the container over a binary RPC channel.
|
|
2710
|
-
*
|
|
2711
|
-
* Requires the container-control path (`transport: 'rpc'`). Calling this
|
|
2712
|
-
* method with the HTTP or WebSocket route transports throws an error because
|
|
2713
|
-
* those transports do not support binary streaming.
|
|
2714
|
-
*/
|
|
2715
|
-
writeFileStream(_path, _content, _sessionId) {
|
|
2716
|
-
throw new Error("writeFileStream requires the RPC transport. Enable it with transport: \"rpc\" in sandbox options.");
|
|
2717
|
-
}
|
|
2718
|
-
/**
|
|
2719
2711
|
* Connect WebSocket transport (no-op in HTTP mode)
|
|
2720
2712
|
* Called automatically on first request, but can be called explicitly
|
|
2721
2713
|
* to establish connection upfront.
|
|
@@ -3300,9 +3292,6 @@ var ContainerControlClient = class {
|
|
|
3300
3292
|
disconnect() {
|
|
3301
3293
|
this.destroyConnection();
|
|
3302
3294
|
}
|
|
3303
|
-
async writeFileStream(path$1, stream, sessionId) {
|
|
3304
|
-
return this.files.writeFileStream(path$1, stream, sessionId);
|
|
3305
|
-
}
|
|
3306
3295
|
};
|
|
3307
3296
|
|
|
3308
3297
|
//#endregion
|
|
@@ -4257,7 +4246,7 @@ function isLocalhostPattern(hostname) {
|
|
|
4257
4246
|
* This file is auto-updated by .github/changeset-version.ts during releases
|
|
4258
4247
|
* DO NOT EDIT MANUALLY - Changes will be overwritten on the next version bump
|
|
4259
4248
|
*/
|
|
4260
|
-
const SDK_VERSION = "0.
|
|
4249
|
+
const SDK_VERSION = "0.10.1";
|
|
4261
4250
|
|
|
4262
4251
|
//#endregion
|
|
4263
4252
|
//#region src/sandbox.ts
|
|
@@ -6081,7 +6070,7 @@ var Sandbox = class Sandbox extends Container {
|
|
|
6081
6070
|
}
|
|
6082
6071
|
async writeFile(path$1, content, options = {}) {
|
|
6083
6072
|
const session = options.sessionId ?? await this.ensureDefaultSession();
|
|
6084
|
-
if (content instanceof ReadableStream) return this.client.writeFileStream(path$1, content, session);
|
|
6073
|
+
if (content instanceof ReadableStream) return this.client.files.writeFileStream(path$1, content, session);
|
|
6085
6074
|
return this.client.files.writeFile(path$1, content, session, { encoding: options.encoding });
|
|
6086
6075
|
}
|
|
6087
6076
|
async deleteFile(path$1, sessionId) {
|
|
@@ -6098,6 +6087,7 @@ var Sandbox = class Sandbox extends Container {
|
|
|
6098
6087
|
}
|
|
6099
6088
|
async readFile(path$1, options = {}) {
|
|
6100
6089
|
const session = options.sessionId ?? await this.ensureDefaultSession();
|
|
6090
|
+
if (options.encoding === "none") return this.client.files.readFile(path$1, session, { encoding: "none" });
|
|
6101
6091
|
return this.client.files.readFile(path$1, session, { encoding: options.encoding });
|
|
6102
6092
|
}
|
|
6103
6093
|
/**
|
|
@@ -6472,9 +6462,16 @@ var Sandbox = class Sandbox extends Container {
|
|
|
6472
6462
|
...options,
|
|
6473
6463
|
sessionId
|
|
6474
6464
|
}),
|
|
6475
|
-
readFile: (path$1, options) =>
|
|
6476
|
-
|
|
6477
|
-
|
|
6465
|
+
readFile: ((path$1, options) => {
|
|
6466
|
+
const encoding = options?.encoding;
|
|
6467
|
+
if (encoding === "none") return this.readFile(path$1, {
|
|
6468
|
+
encoding: "none",
|
|
6469
|
+
sessionId
|
|
6470
|
+
});
|
|
6471
|
+
return this.readFile(path$1, {
|
|
6472
|
+
encoding,
|
|
6473
|
+
sessionId
|
|
6474
|
+
});
|
|
6478
6475
|
}),
|
|
6479
6476
|
readFileStream: (path$1) => this.readFileStream(path$1, { sessionId }),
|
|
6480
6477
|
watch: (path$1, options) => this.watch(path$1, {
|
|
@@ -7232,9 +7229,18 @@ var Sandbox = class Sandbox extends Container {
|
|
|
7232
7229
|
sizeBytes = createResult.sizeBytes;
|
|
7233
7230
|
const r2Key = `${BACKUP_STORAGE_PREFIX}/${backupId}/${BACKUP_ARCHIVE_OBJECT_NAME}`;
|
|
7234
7231
|
const metaKey = `${BACKUP_STORAGE_PREFIX}/${backupId}/${BACKUP_METADATA_OBJECT_NAME}`;
|
|
7235
|
-
const
|
|
7236
|
-
const
|
|
7237
|
-
|
|
7232
|
+
const archiveStream = await this.client.files.readFileStream(archivePath, backupSession);
|
|
7233
|
+
const sseDecoded = new ReadableStream({ async start(controller) {
|
|
7234
|
+
try {
|
|
7235
|
+
for await (const chunk of streamFile(archiveStream)) if (chunk instanceof Uint8Array) controller.enqueue(chunk);
|
|
7236
|
+
controller.close();
|
|
7237
|
+
} catch (err) {
|
|
7238
|
+
controller.error(err);
|
|
7239
|
+
}
|
|
7240
|
+
} });
|
|
7241
|
+
const fixedStream = new FixedLengthStream(createResult.sizeBytes);
|
|
7242
|
+
sseDecoded.pipeTo(fixedStream.writable).catch(() => {});
|
|
7243
|
+
await bucket.put(r2Key, fixedStream.readable);
|
|
7238
7244
|
const head = await bucket.head(r2Key);
|
|
7239
7245
|
if (!head || head.size !== createResult.sizeBytes) throw new BackupCreateError({
|
|
7240
7246
|
message: `Upload verification failed: expected ${createResult.sizeBytes} bytes, got ${head?.size ?? 0}`,
|
|
@@ -7512,20 +7518,35 @@ var Sandbox = class Sandbox extends Container {
|
|
|
7512
7518
|
});
|
|
7513
7519
|
backupSession = await this.ensureBackupSession();
|
|
7514
7520
|
const archivePath = `${BACKUP_CONTAINER_DIR}/${id}.sqsh`;
|
|
7515
|
-
const archiveBuffer = await archiveObject.arrayBuffer();
|
|
7516
|
-
const base64Content = Buffer.from(archiveBuffer).toString("base64");
|
|
7517
7521
|
await this.execWithSession(`mkdir -p ${BACKUP_CONTAINER_DIR}`, backupSession, { origin: "internal" });
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7522
|
+
if (this.transport === "rpc") {
|
|
7523
|
+
const body = archiveObject.body;
|
|
7524
|
+
if (!body) throw new BackupRestoreError({
|
|
7525
|
+
message: `R2 archive object has no body stream for backup ${id}`,
|
|
7526
|
+
code: ErrorCode.BACKUP_RESTORE_FAILED,
|
|
7527
|
+
httpStatus: 500,
|
|
7528
|
+
context: {
|
|
7529
|
+
dir,
|
|
7530
|
+
backupId: id
|
|
7531
|
+
},
|
|
7532
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
7533
|
+
});
|
|
7534
|
+
await this.client.files.writeFileStream(archivePath, body, backupSession);
|
|
7535
|
+
} else {
|
|
7536
|
+
const archiveBuffer = await archiveObject.arrayBuffer();
|
|
7537
|
+
const base64Content = Buffer.from(archiveBuffer).toString("base64");
|
|
7538
|
+
const writeResult = await this.client.files.writeFile(archivePath, base64Content, backupSession, { encoding: "base64" });
|
|
7539
|
+
if (!writeResult.success) throw new BackupRestoreError({
|
|
7540
|
+
message: `Failed to write backup archive to ${archivePath}: ${"error" in writeResult && typeof writeResult.error === "object" && writeResult.error !== null && "message" in writeResult.error && typeof writeResult.error.message === "string" ? writeResult.error.message : `File write returned success: false for '${archivePath}'`}`,
|
|
7541
|
+
code: ErrorCode.BACKUP_RESTORE_FAILED,
|
|
7542
|
+
httpStatus: 500,
|
|
7543
|
+
context: {
|
|
7544
|
+
dir,
|
|
7545
|
+
backupId: id
|
|
7546
|
+
},
|
|
7547
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
7548
|
+
});
|
|
7549
|
+
}
|
|
7529
7550
|
const extractResult = await this.execWithSession(`/usr/bin/unsquashfs -f -d ${shellEscape(dir)} ${shellEscape(archivePath)}`, backupSession, { origin: "internal" });
|
|
7530
7551
|
if (extractResult.exitCode !== 0) throw new BackupRestoreError({
|
|
7531
7552
|
message: `unsquashfs extraction failed (exit code ${extractResult.exitCode}): ${extractResult.stderr}`,
|
|
@@ -7568,4 +7589,4 @@ var Sandbox = class Sandbox extends Container {
|
|
|
7568
7589
|
|
|
7569
7590
|
//#endregion
|
|
7570
7591
|
export { DesktopInvalidOptionsError as A, CommandClient as C, BackupNotFoundError as D, BackupExpiredError as E, InvalidBackupConfigError as F, ProcessExitedBeforeReadyError as I, ProcessReadyTimeoutError as L, DesktopProcessCrashedError as M, DesktopStartFailedError as N, BackupRestoreError as O, DesktopUnavailableError as P, RPCTransportError as R, DesktopClient as S, BackupCreateError as T, UtilityClient as _, BucketMountError as a, GitClient as b, MissingCredentialsError as c, parseSSEStream as d, responseToAsyncIterable as f, SandboxClient as g, streamFile as h, proxyTerminal as i, DesktopNotStartedError as j, DesktopInvalidCoordinatesError as k, S3FSMountError as l, collectFile as m, getSandbox as n, BucketUnmountError as o, CodeInterpreter as p, proxyToSandbox as r, InvalidMountConfigError as s, Sandbox as t, asyncIterableToSSEStream as u, ProcessClient as v, BackupClient as w, FileClient as x, PortClient as y, SessionTerminatedError as z };
|
|
7571
|
-
//# sourceMappingURL=sandbox-
|
|
7592
|
+
//# sourceMappingURL=sandbox-uC1vzWtG.js.map
|