@cloudflare/sandbox 0.13.0-next.776.1 → 0.13.0-next.797.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/dist/bridge/index.js +24 -8
- package/dist/bridge/index.js.map +1 -1
- package/dist/{dist-Duor5GbS.js → dist-n_eniPAR.js} +8 -46
- package/dist/dist-n_eniPAR.js.map +1 -0
- package/dist/extensions/index.d.ts +2 -2
- package/dist/extensions/index.js +2 -2
- package/dist/{extensions-CFB2xHqY.js → extensions-Be5HnDGt.js} +2 -2
- package/dist/{extensions-CFB2xHqY.js.map → extensions-Be5HnDGt.js.map} +1 -1
- package/dist/{filesystem-BWAZCZER.d.ts → filesystem-Y5aF3nmJ.d.ts} +7 -3
- package/dist/filesystem-Y5aF3nmJ.d.ts.map +1 -0
- package/dist/git/index.d.ts +2 -2
- package/dist/git/index.js +2 -2
- package/dist/{index-Bs4bqXDR.d.ts → index-DfXx3uZL.d.ts} +2 -2
- package/dist/{index-Bs4bqXDR.d.ts.map → index-DfXx3uZL.d.ts.map} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/interpreter/index.d.ts +2 -2
- package/dist/interpreter/index.js +2 -2
- package/dist/openai/index.d.ts +2 -2
- package/dist/openai/index.d.ts.map +1 -1
- package/dist/openai/index.js +10 -34
- package/dist/openai/index.js.map +1 -1
- package/dist/opencode/index.d.ts +2 -2
- package/dist/opencode/index.js +2 -2
- package/dist/{sandbox-cmlgGVYX.js → sandbox-BEhPgFZx.js} +127 -48
- package/dist/sandbox-BEhPgFZx.js.map +1 -0
- package/dist/{sandbox-BbAabq93.d.ts → sandbox-CBkS3tGv.d.ts} +2 -2
- package/dist/{sandbox-BbAabq93.d.ts.map → sandbox-CBkS3tGv.d.ts.map} +1 -1
- package/package.json +1 -1
- package/dist/dist-Duor5GbS.js.map +0 -1
- package/dist/filesystem-BWAZCZER.d.ts.map +0 -1
- package/dist/sandbox-cmlgGVYX.js.map +0 -1
package/dist/bridge/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "../errors-CXR0xBpw.js";
|
|
2
2
|
import "../errors-QYlSkVGz.js";
|
|
3
|
-
import "../dist-
|
|
4
|
-
import { g as validateTunnelName, h as validatePort, m as SandboxSecurityError, n as getSandbox$1, x as streamFile } from "../sandbox-
|
|
5
|
-
import "../extensions-
|
|
3
|
+
import "../dist-n_eniPAR.js";
|
|
4
|
+
import { g as validateTunnelName, h as validatePort, m as SandboxSecurityError, n as getSandbox$1, x as streamFile } from "../sandbox-BEhPgFZx.js";
|
|
5
|
+
import "../extensions-Be5HnDGt.js";
|
|
6
6
|
import { DurableObject, env } from "cloudflare:workers";
|
|
7
7
|
import { Hono } from "hono";
|
|
8
8
|
|
|
@@ -97,10 +97,23 @@ function validateTerminalId(id) {
|
|
|
97
97
|
/**
|
|
98
98
|
* Convert an SSE stream from readFileStream() into a raw byte stream.
|
|
99
99
|
* Decodes base64 chunks for binary files and UTF-8-encodes text chunks.
|
|
100
|
+
* Reads nothing from the source until the returned stream is pulled.
|
|
100
101
|
*/
|
|
101
102
|
function sseToByteStream(sse) {
|
|
102
|
-
|
|
103
|
+
return chunksToByteStream(streamFile(sse)[Symbol.asyncIterator]());
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Like sseToByteStream(), but reads up to the first chunk before returning.
|
|
107
|
+
* A missing file arrives as an error event inside a successful stream, so it
|
|
108
|
+
* rejects here, while the caller can still choose the HTTP status.
|
|
109
|
+
*/
|
|
110
|
+
async function openSSEByteStream(sse) {
|
|
103
111
|
const iterator = streamFile(sse)[Symbol.asyncIterator]();
|
|
112
|
+
return chunksToByteStream(iterator, await iterator.next());
|
|
113
|
+
}
|
|
114
|
+
function chunksToByteStream(iterator, first) {
|
|
115
|
+
const encoder = new TextEncoder();
|
|
116
|
+
let pending = first;
|
|
104
117
|
let finished = false;
|
|
105
118
|
async function finish(cancelSource) {
|
|
106
119
|
if (finished) return;
|
|
@@ -111,7 +124,8 @@ function sseToByteStream(sse) {
|
|
|
111
124
|
return new ReadableStream({
|
|
112
125
|
async pull(controller) {
|
|
113
126
|
try {
|
|
114
|
-
const result = await iterator.next();
|
|
127
|
+
const result = pending ?? await iterator.next();
|
|
128
|
+
pending = void 0;
|
|
115
129
|
if (result.done) {
|
|
116
130
|
await finish(false);
|
|
117
131
|
controller.close();
|
|
@@ -1993,13 +2007,15 @@ function registerFileRoutes(app, apiPrefix, sandboxBinding) {
|
|
|
1993
2007
|
const sandbox = getSandbox(getSandboxNs(c.env, sandboxBinding), c.get("containerUUID"));
|
|
1994
2008
|
try {
|
|
1995
2009
|
const stream = await sandbox.readFileStream(resolvedPath);
|
|
1996
|
-
return new Response(
|
|
2010
|
+
return new Response(await openSSEByteStream(stream), {
|
|
1997
2011
|
status: 200,
|
|
1998
2012
|
headers: { "Content-Type": "application/octet-stream" }
|
|
1999
2013
|
});
|
|
2000
2014
|
} catch (err) {
|
|
2001
|
-
|
|
2002
|
-
|
|
2015
|
+
const code = err.code;
|
|
2016
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2017
|
+
if (code === "FILE_NOT_FOUND" || msg.startsWith("File streaming error: File not found: ")) return errorJson(`File not found: ${resolvedPath}`, "workspace_read_not_found", 404);
|
|
2018
|
+
return errorJson(`read failed: ${msg}`, "exec_transport_error", 502);
|
|
2003
2019
|
}
|
|
2004
2020
|
});
|
|
2005
2021
|
app.put(`${apiPrefix}/sandbox/:id/file/*`, async (c) => {
|