@cloudflare/sandbox 0.12.10 → 0.12.12
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 +23 -10
- package/dist/bridge/index.js.map +1 -1
- package/dist/{contexts-C186NnAB.d.ts → contexts-CxAJGHFf.d.ts} +6 -1
- package/dist/contexts-CxAJGHFf.d.ts.map +1 -0
- package/dist/{dist-B_eXrP83.js → dist-CqPJfREN.js} +34 -52
- package/dist/dist-CqPJfREN.js.map +1 -0
- package/dist/{errors-CpkKPbWC.js → errors-CHhwDJNh.js} +11 -1
- package/dist/errors-CHhwDJNh.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/openai/index.d.ts +1 -1
- 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 +7 -3
- package/dist/opencode/index.d.ts.map +1 -1
- package/dist/opencode/index.js +32 -20
- package/dist/opencode/index.js.map +1 -1
- package/dist/{sandbox-Co2NYKhX.js → sandbox-BYPanejK.js} +490 -170
- package/dist/sandbox-BYPanejK.js.map +1 -0
- package/dist/{sandbox-BtaWcmmG.d.ts → sandbox-mYLglwK1.d.ts} +55 -8
- package/dist/sandbox-mYLglwK1.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/contexts-C186NnAB.d.ts.map +0 -1
- package/dist/dist-B_eXrP83.js.map +0 -1
- package/dist/errors-CpkKPbWC.js.map +0 -1
- package/dist/sandbox-BtaWcmmG.d.ts.map +0 -1
- package/dist/sandbox-Co2NYKhX.js.map +0 -1
package/dist/bridge/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../dist-
|
|
2
|
-
import "../errors-
|
|
3
|
-
import { S as validateTunnelName, r as getSandbox, w as streamFile, x as validatePort, y as SandboxSecurityError } from "../sandbox-
|
|
1
|
+
import "../dist-CqPJfREN.js";
|
|
2
|
+
import "../errors-CHhwDJNh.js";
|
|
3
|
+
import { S as validateTunnelName, r as getSandbox, w as streamFile, x as validatePort, y as SandboxSecurityError } from "../sandbox-BYPanejK.js";
|
|
4
4
|
import { DurableObject, env, tracing } from "cloudflare:workers";
|
|
5
5
|
import { Hono } from "hono";
|
|
6
6
|
|
|
@@ -115,12 +115,23 @@ function validateSessionId(id) {
|
|
|
115
115
|
/**
|
|
116
116
|
* Convert an SSE stream from readFileStream() into a raw byte stream.
|
|
117
117
|
* Decodes base64 chunks for binary files and UTF-8-encodes text chunks.
|
|
118
|
+
* Reads up to the first chunk before returning. A missing file arrives as an
|
|
119
|
+
* error event inside a successful stream, so it rejects here, while the caller
|
|
120
|
+
* can still choose the HTTP status.
|
|
118
121
|
*/
|
|
119
|
-
function sseToByteStream(sse) {
|
|
122
|
+
async function sseToByteStream(sse) {
|
|
120
123
|
const encoder = new TextEncoder();
|
|
124
|
+
const enqueue = (controller, chunk) => {
|
|
125
|
+
controller.enqueue(chunk instanceof Uint8Array ? chunk : encoder.encode(chunk));
|
|
126
|
+
};
|
|
127
|
+
const chunks = streamFile(sse);
|
|
128
|
+
const first = await chunks.next();
|
|
121
129
|
return new ReadableStream({ async start(controller) {
|
|
122
130
|
try {
|
|
123
|
-
|
|
131
|
+
if (!first.done) {
|
|
132
|
+
enqueue(controller, first.value);
|
|
133
|
+
for await (const chunk of chunks) enqueue(controller, chunk);
|
|
134
|
+
}
|
|
124
135
|
controller.close();
|
|
125
136
|
} catch (err) {
|
|
126
137
|
controller.error(err);
|
|
@@ -2056,14 +2067,16 @@ function createBridgeApp(config) {
|
|
|
2056
2067
|
executor = await sandbox.getSession(sessionId);
|
|
2057
2068
|
}
|
|
2058
2069
|
try {
|
|
2059
|
-
const
|
|
2060
|
-
return new Response(
|
|
2070
|
+
const byteStream = await sseToByteStream(await executor.readFileStream(resolvedPath));
|
|
2071
|
+
return new Response(byteStream, {
|
|
2061
2072
|
status: 200,
|
|
2062
2073
|
headers: { "Content-Type": "application/octet-stream" }
|
|
2063
2074
|
});
|
|
2064
2075
|
} catch (err) {
|
|
2065
|
-
|
|
2066
|
-
|
|
2076
|
+
const code = err.code;
|
|
2077
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2078
|
+
if (code === "FILE_NOT_FOUND" || msg.startsWith("File streaming error: File not found: ")) return errorJson(`File not found: ${resolvedPath}`, "workspace_read_not_found", 404);
|
|
2079
|
+
return errorJson(`read failed: ${msg}`, "exec_transport_error", 502);
|
|
2067
2080
|
}
|
|
2068
2081
|
}));
|
|
2069
2082
|
app.put(`${apiPrefix}/sandbox/:id/file/*`, traced("write_file", async (c) => {
|
|
@@ -2185,7 +2198,7 @@ function createBridgeApp(config) {
|
|
|
2185
2198
|
if (result.exitCode !== 0) return errorJson(`tar failed (exit ${result.exitCode}): ${result.stderr}`, "workspace_archive_read_error", 502);
|
|
2186
2199
|
const stream = await sandbox.readFileStream(tmpPath);
|
|
2187
2200
|
sandbox.exec(`rm -f ${shellQuote(tmpPath)}`).catch(() => {});
|
|
2188
|
-
return new Response(sseToByteStream(stream), {
|
|
2201
|
+
return new Response(await sseToByteStream(stream), {
|
|
2189
2202
|
status: 200,
|
|
2190
2203
|
headers: { "Content-Type": "application/octet-stream" }
|
|
2191
2204
|
});
|