@cloudflare/sandbox 0.13.0-next.769.1 → 1.0.0-rc.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.
Files changed (63) hide show
  1. package/README.md +62 -219
  2. package/dist/index.d.mts +548 -0
  3. package/dist/index.mjs +2452 -0
  4. package/package.json +17 -118
  5. package/Dockerfile +0 -327
  6. package/dist/bridge/index.d.ts +0 -181
  7. package/dist/bridge/index.d.ts.map +0 -1
  8. package/dist/bridge/index.js +0 -3053
  9. package/dist/bridge/index.js.map +0 -1
  10. package/dist/contexts-1EsLHByO.d.ts +0 -463
  11. package/dist/contexts-1EsLHByO.d.ts.map +0 -1
  12. package/dist/dist-Duor5GbS.js +0 -752
  13. package/dist/dist-Duor5GbS.js.map +0 -1
  14. package/dist/errors/index.d.ts +0 -4
  15. package/dist/errors/index.js +0 -4
  16. package/dist/errors-CXR0xBpw.js +0 -285
  17. package/dist/errors-CXR0xBpw.js.map +0 -1
  18. package/dist/errors-QYlSkVGz.js +0 -893
  19. package/dist/errors-QYlSkVGz.js.map +0 -1
  20. package/dist/extensions/index.d.ts +0 -4
  21. package/dist/extensions/index.js +0 -6
  22. package/dist/extensions-CFB2xHqY.js +0 -1023
  23. package/dist/extensions-CFB2xHqY.js.map +0 -1
  24. package/dist/filesystem-BWAZCZER.d.ts +0 -732
  25. package/dist/filesystem-BWAZCZER.d.ts.map +0 -1
  26. package/dist/git/index.d.ts +0 -63
  27. package/dist/git/index.d.ts.map +0 -1
  28. package/dist/git/index.js +0 -338
  29. package/dist/git/index.js.map +0 -1
  30. package/dist/index-Bs4bqXDR.d.ts +0 -438
  31. package/dist/index-Bs4bqXDR.d.ts.map +0 -1
  32. package/dist/index-HNYBk-az.d.ts +0 -444
  33. package/dist/index-HNYBk-az.d.ts.map +0 -1
  34. package/dist/index.d.ts +0 -576
  35. package/dist/index.d.ts.map +0 -1
  36. package/dist/index.js +0 -33
  37. package/dist/index.js.map +0 -1
  38. package/dist/interpreter/index.d.ts +0 -311
  39. package/dist/interpreter/index.d.ts.map +0 -1
  40. package/dist/interpreter/index.js +0 -292
  41. package/dist/interpreter/index.js.map +0 -1
  42. package/dist/openai/index.d.ts +0 -68
  43. package/dist/openai/index.d.ts.map +0 -1
  44. package/dist/openai/index.js +0 -367
  45. package/dist/openai/index.js.map +0 -1
  46. package/dist/opencode/index.d.ts +0 -182
  47. package/dist/opencode/index.d.ts.map +0 -1
  48. package/dist/opencode/index.js +0 -454
  49. package/dist/opencode/index.js.map +0 -1
  50. package/dist/process-types-GStiZ8f8.d.ts +0 -73
  51. package/dist/process-types-GStiZ8f8.d.ts.map +0 -1
  52. package/dist/sandbox-BbAabq93.d.ts +0 -42
  53. package/dist/sandbox-BbAabq93.d.ts.map +0 -1
  54. package/dist/sandbox-cmlgGVYX.js +0 -10056
  55. package/dist/sandbox-cmlgGVYX.js.map +0 -1
  56. package/dist/sidecar/index.d.ts +0 -77
  57. package/dist/sidecar/index.d.ts.map +0 -1
  58. package/dist/sidecar/index.js +0 -201
  59. package/dist/sidecar/index.js.map +0 -1
  60. package/dist/xterm/index.d.ts +0 -93
  61. package/dist/xterm/index.d.ts.map +0 -1
  62. package/dist/xterm/index.js +0 -220
  63. package/dist/xterm/index.js.map +0 -1
@@ -1,454 +0,0 @@
1
- import { i as ErrorCode } from "../errors-CXR0xBpw.js";
2
- import "../errors-QYlSkVGz.js";
3
- import { r as createLogger } from "../dist-Duor5GbS.js";
4
- import { n as createExtensionProcessSandbox, t as SandboxExtension } from "../extensions-CFB2xHqY.js";
5
-
6
- //#region ../../extensions/opencode/src/client.ts
7
- let createSDKClient;
8
- async function loadSDK() {
9
- if (createSDKClient) return createSDKClient;
10
- try {
11
- createSDKClient = (await import("@opencode-ai/sdk/v2/client")).createOpencodeClient;
12
- return createSDKClient;
13
- } catch {
14
- throw new Error("@opencode-ai/sdk is required for OpenCode integration. Install it with: npm install @opencode-ai/sdk");
15
- }
16
- }
17
- /**
18
- * Build a typed OpenCode SDK client from a lifecycle handle.
19
- *
20
- * Works against either the Worker stub (`sandbox.opencode`) or the in-DO object
21
- * (`this.opencode`): it ensures the server through the handle, reads the stored
22
- * config, and routes every request through `handle.fetch`. Because the handle
23
- * owns `containerFetch`, this helper never touches sandbox transport directly.
24
- *
25
- * The SDK is imported lazily so the peer dependency is only required when an
26
- * OpenCode client is actually built.
27
- */
28
- async function createOpenCodeClient(handle, options) {
29
- const server = await handle.start(options);
30
- const config = await handle.config();
31
- const directory = options?.directory ?? config.directory;
32
- return (await loadSDK())({
33
- baseUrl: server.url,
34
- fetch: (input, init) => handle.fetch(new Request(input, init)),
35
- directory
36
- });
37
- }
38
-
39
- //#endregion
40
- //#region ../../extensions/opencode/src/types.ts
41
- /**
42
- * Error thrown when OpenCode server fails to start
43
- */
44
- var OpenCodeStartupError = class extends Error {
45
- code = ErrorCode.OPENCODE_STARTUP_FAILED;
46
- context;
47
- constructor(message, context, options) {
48
- super(message, options);
49
- this.name = "OpenCodeStartupError";
50
- this.context = context;
51
- }
52
- };
53
-
54
- //#endregion
55
- //#region ../../extensions/opencode/src/opencode.ts
56
- function getLogger() {
57
- return createLogger({
58
- component: "sandbox-do",
59
- operation: "opencode"
60
- });
61
- }
62
- const DEFAULT_PORT$1 = 4096;
63
- const OPENCODE_STARTUP_TIMEOUT_MS = 18e4;
64
- function openCodeCommand(port) {
65
- return [
66
- "opencode",
67
- "serve",
68
- "--port",
69
- String(port),
70
- "--hostname",
71
- "0.0.0.0"
72
- ];
73
- }
74
- function commandsEqual(a, b) {
75
- return a.length === b.length && a.every((value, index) => value === b[index]);
76
- }
77
- /** Recover a running OpenCode process from runtime-local process status. */
78
- async function findExistingOpenCodeProcess(sandbox, port, directory) {
79
- const command = openCodeCommand(port);
80
- const processes = createExtensionProcessSandbox(sandbox);
81
- const status = (await processes.listProcesses()).find((candidate) => candidate.state === "running" && candidate.cwd === directory && commandsEqual(candidate.command, command));
82
- return status ? processes.getProcess(status.id) : null;
83
- }
84
- async function collectStderr(process) {
85
- const reader = (await process.logs({
86
- replay: true,
87
- follow: false
88
- })).getReader();
89
- const decoder = new TextDecoder();
90
- let stderr = "";
91
- try {
92
- while (true) {
93
- const { done, value } = await reader.read();
94
- if (done) break;
95
- if (value.type === "stderr") stderr += decoder.decode(value.data, { stream: true });
96
- }
97
- return stderr + decoder.decode();
98
- } finally {
99
- reader.releaseLock();
100
- }
101
- }
102
- /**
103
- * Ensures OpenCode server is running in the container.
104
- * Reuses existing process if one is already running on the specified port.
105
- * Handles concurrent startup attempts gracefully by retrying on failure.
106
- * Returns the process handle.
107
- */
108
- async function ensureOpenCodeServer(sandbox, port, directory, config, customEnv) {
109
- const existingProcess = await findExistingOpenCodeProcess(sandbox, port, directory);
110
- if (existingProcess) {
111
- getLogger().debug("Reusing existing OpenCode process", {
112
- port,
113
- processId: existingProcess.id
114
- });
115
- return existingProcess;
116
- }
117
- try {
118
- return await startOpenCodeServer(sandbox, port, directory, config, customEnv);
119
- } catch (startupError) {
120
- const retryProcess = await findExistingOpenCodeProcess(sandbox, port, directory);
121
- if (retryProcess) {
122
- getLogger().debug("Startup failed but found concurrent process, reusing", {
123
- port,
124
- processId: retryProcess.id
125
- });
126
- return retryProcess;
127
- }
128
- throw startupError;
129
- }
130
- }
131
- /**
132
- * Internal function to start a new OpenCode server process.
133
- */
134
- async function startOpenCodeServer(sandbox, port, directory, config, customEnv) {
135
- getLogger().info("Starting OpenCode server", {
136
- port,
137
- directory
138
- });
139
- const env = {};
140
- if (config) {
141
- env.OPENCODE_CONFIG_CONTENT = JSON.stringify(config);
142
- if (config.provider && typeof config.provider === "object" && !Array.isArray(config.provider)) {
143
- for (const [providerId, providerConfig] of Object.entries(config.provider)) {
144
- if (providerId === "cloudflare-ai-gateway") continue;
145
- let apiKey = providerConfig?.options?.apiKey;
146
- if (!apiKey) apiKey = providerConfig?.apiKey;
147
- if (typeof apiKey === "string") {
148
- const envVar = `${providerId.toUpperCase()}_API_KEY`;
149
- env[envVar] = apiKey;
150
- }
151
- }
152
- const aiGatewayConfig = config.provider["cloudflare-ai-gateway"];
153
- if (aiGatewayConfig?.options) {
154
- const options = aiGatewayConfig.options;
155
- if (typeof options.accountId === "string") env.CLOUDFLARE_ACCOUNT_ID = options.accountId;
156
- if (typeof options.gatewayId === "string") env.CLOUDFLARE_GATEWAY_ID = options.gatewayId;
157
- if (typeof options.apiToken === "string") env.CLOUDFLARE_API_TOKEN = options.apiToken;
158
- }
159
- }
160
- }
161
- if (customEnv) Object.assign(env, customEnv);
162
- const command = openCodeCommand(port);
163
- const process = await createExtensionProcessSandbox(sandbox).exec(command, {
164
- cwd: directory,
165
- env: Object.keys(env).length > 0 ? env : void 0
166
- });
167
- try {
168
- await process.waitForPort(port, {
169
- mode: "http",
170
- path: "/path",
171
- status: 200,
172
- timeout: OPENCODE_STARTUP_TIMEOUT_MS
173
- });
174
- getLogger().info("OpenCode server started successfully", {
175
- port,
176
- processId: process.id
177
- });
178
- } catch (e) {
179
- const stderr = await collectStderr(process);
180
- const error = e instanceof Error ? e : void 0;
181
- getLogger().error("OpenCode server failed to start", error, {
182
- port,
183
- stderr
184
- });
185
- throw new OpenCodeStartupError(`OpenCode server failed to start. Stderr: ${stderr || "(empty)"}`, {
186
- port,
187
- stderr,
188
- command: command.join(" ")
189
- }, { cause: e });
190
- }
191
- return process;
192
- }
193
- /**
194
- * Starts an OpenCode server inside a Sandbox container.
195
- *
196
- * This function manages the server lifecycle only - use `createOpenCodeClient()` if you
197
- * also need a typed SDK client for programmatic access.
198
- *
199
- * If an OpenCode server is already running on the specified port, this function
200
- * will reuse it instead of starting a new one.
201
- *
202
- * @param sandbox - The Sandbox instance to run OpenCode in
203
- * @param options - Configuration options
204
- * @returns Promise resolving to server handle { port, url, close() }
205
- *
206
- * @example
207
- * ```typescript
208
- * import { getSandbox } from '@cloudflare/sandbox'
209
- * import { createOpenCodeServer } from '@cloudflare/sandbox/opencode'
210
- *
211
- * const sandbox = getSandbox(env.Sandbox, 'my-agent')
212
- * const server = await createOpenCodeServer(sandbox, {
213
- * directory: '/home/user/my-project',
214
- * config: {
215
- * provider: {
216
- * anthropic: {
217
- * options: { apiKey: env.ANTHROPIC_KEY }
218
- * },
219
- * // Or use Cloudflare AI Gateway (with unified billing, no provider keys needed).
220
- * // 'cloudflare-ai-gateway': {
221
- * // options: {
222
- * // accountId: env.CF_ACCOUNT_ID,
223
- * // gatewayId: env.CF_GATEWAY_ID,
224
- * // apiToken: env.CF_API_TOKEN
225
- * // },
226
- * // models: { 'anthropic/claude-sonnet-4-5-20250929': {} }
227
- * // }
228
- * }
229
- * }
230
- * })
231
- *
232
- * // Proxy requests to the web UI
233
- * return sandbox.containerFetch(request, server.port)
234
- *
235
- * // When done
236
- * await server.close()
237
- * ```
238
- */
239
- async function createOpenCodeServer(sandbox, options) {
240
- const port = options?.port ?? DEFAULT_PORT$1;
241
- const process = await ensureOpenCodeServer(sandbox, port, options?.directory, options?.config, options?.env);
242
- return {
243
- port,
244
- url: `http://localhost:${port}`,
245
- close: async () => {
246
- await process.kill(15);
247
- await process.waitForExit().catch(() => {});
248
- }
249
- };
250
- }
251
-
252
- //#endregion
253
- //#region ../../extensions/opencode/src/lifecycle.ts
254
- const DEFAULT_PORT = 4096;
255
- const STATE_KEY_PREFIX = "opencode:desired-state:";
256
- /** Recognise the retryable container-unavailable error across RPC. */
257
- function isContainerUnavailable(error) {
258
- if (typeof error !== "object" || error === null) return false;
259
- return error.name === "ContainerUnavailableError";
260
- }
261
- /**
262
- * DO-resident lifecycle handle for an OpenCode server. Owns the durable
263
- * `opencode serve` process: start/reuse, stop, status, and request proxying.
264
- *
265
- * It extends {@link SandboxExtension}, so the DO stub exposes it as
266
- * `sandbox.opencode` and method calls dispatch through `callExtension` — the
267
- * same path the interpreter extension uses. `createOpenCodeClient` consumes the
268
- * same handle from either the Worker stub or the in-DO object.
269
- *
270
- * The server starts lazily: nothing runs until `start()` (or `fetch()`, which
271
- * calls it) is invoked. To start optimistically, call `opencode.start()` from
272
- * your Sandbox subclass's `onStart`.
273
- */
274
- var OpenCodeHandle = class extends SandboxExtension {
275
- #sandbox;
276
- #defaults;
277
- #storage;
278
- #stateKey;
279
- #server;
280
- #lastOptions;
281
- constructor(sandbox, defaults = {}, storage, stateIndex = 0) {
282
- super(sandbox);
283
- this.#sandbox = sandbox;
284
- this.#defaults = defaults;
285
- this.#storage = storage;
286
- this.#stateKey = `${STATE_KEY_PREFIX}${stateIndex}`;
287
- }
288
- /**
289
- * Start or reuse the OpenCode server, returning RPC-safe metadata. With no
290
- * options it reuses the last-used config, recovering persisted desired-state
291
- * after a cold start. Retries once on a transient `CONTAINER_UNAVAILABLE`
292
- * (e.g. a rollout in flight).
293
- */
294
- async start(options) {
295
- const recovered = options ?? this.#lastOptions ?? await this.#loadPersisted();
296
- const resolved = {
297
- ...this.#defaults,
298
- ...recovered
299
- };
300
- this.#lastOptions = resolved;
301
- await this.#persist(resolved);
302
- let server;
303
- try {
304
- server = await createOpenCodeServer(this.#sandbox, resolved);
305
- } catch (error) {
306
- if (!isContainerUnavailable(error)) throw error;
307
- server = await createOpenCodeServer(this.#sandbox, resolved);
308
- }
309
- this.#server = server;
310
- return {
311
- port: server.port,
312
- url: server.url
313
- };
314
- }
315
- /** Stop the running server, if one was started through this handle. */
316
- async stop() {
317
- if (!this.#server) return;
318
- await this.#server.close();
319
- this.#server = void 0;
320
- }
321
- /** Report whether the named OpenCode server is currently running. */
322
- async status() {
323
- const resolved = {
324
- ...this.#defaults,
325
- ...this.#lastOptions
326
- };
327
- const port = resolved.port ?? DEFAULT_PORT;
328
- return {
329
- running: await findExistingOpenCodeProcess(this.#sandbox, port, resolved.directory) !== null,
330
- port,
331
- url: `http://localhost:${port}`
332
- };
333
- }
334
- /** Snapshot of the resolved configuration the client builder reads. */
335
- async config() {
336
- const resolved = {
337
- ...this.#defaults,
338
- ...this.#lastOptions
339
- };
340
- return {
341
- port: resolved.port ?? DEFAULT_PORT,
342
- directory: resolved.directory
343
- };
344
- }
345
- /**
346
- * Start the server then route a request into the container. This is the
347
- * transport the SDK client's `fetch` adapter and the Worker proxy use, so it
348
- * works identically from the Worker stub (one RPC hop) or in-DO (local).
349
- */
350
- async fetch(request) {
351
- const server = await this.start();
352
- return this.#sandbox.containerFetch(request, server.port);
353
- }
354
- /**
355
- * Persist resolved desired-state so a cold DO can recover it. Best-effort.
356
- *
357
- * Secret-bearing fields (`config`, `env`) are never written to storage. They
358
- * are sourced fresh from the handle's defaults — which the Sandbox rebuilds
359
- * from the environment on every construction — so a cold start always uses
360
- * current credentials rather than a durable copy.
361
- */
362
- async #persist(options) {
363
- if (!this.#storage) return;
364
- const { config: _config, env: _env, ...safe } = options;
365
- await this.#storage.put(this.#stateKey, safe);
366
- }
367
- /** Read persisted desired-state, if any, after a DO eviction. */
368
- async #loadPersisted() {
369
- if (!this.#storage) return void 0;
370
- return this.#storage.get(this.#stateKey);
371
- }
372
- };
373
- /**
374
- * Assigns each handle a stable per-sandbox index so its persisted state key is
375
- * deterministic across DO reconstruction (field initializers run in the same
376
- * order each time). Keyed weakly so it is collected with the sandbox.
377
- */
378
- const stateIndexCounter = /* @__PURE__ */ new WeakMap();
379
- /**
380
- * Factory — attach as a field on a Sandbox subclass:
381
- * `opencode = withOpenCode(this, { directory, config, storage: this.ctx.storage })`.
382
- *
383
- * Pass `storage` to persist desired-state so the server is recovered after a DO
384
- * eviction (cold start). The server starts lazily on first use.
385
- */
386
- function withOpenCode(sandbox, options = {}) {
387
- const { storage, ...defaults } = options;
388
- const index = stateIndexCounter.get(sandbox) ?? 0;
389
- stateIndexCounter.set(sandbox, index + 1);
390
- return new OpenCodeHandle(sandbox, defaults, storage, index);
391
- }
392
-
393
- //#endregion
394
- //#region ../../extensions/opencode/src/proxy.ts
395
- /**
396
- * Proxy a request to the OpenCode web UI through a lifecycle handle.
397
- *
398
- * For an initial HTML page load that still lacks the `?url=` parameter, returns
399
- * a redirect that adds it (so the OpenCode frontend calls back through the
400
- * proxy instead of `127.0.0.1:4096`). Every other request is routed through
401
- * `handle.fetch`, which ensures the server is running before forwarding into the
402
- * container.
403
- */
404
- function proxyToOpenCodeUI(request, handle, options) {
405
- const url = new URL(request.url);
406
- if (!url.searchParams.has("url") && request.method === "GET") {
407
- if ((request.headers.get("accept") || "").includes("text/html") || url.pathname === "/") {
408
- url.searchParams.set("url", options?.callbackOrigin ?? url.origin);
409
- return Response.redirect(url.toString(), 302);
410
- }
411
- }
412
- return handle.fetch(request);
413
- }
414
- /**
415
- * Curried Worker fetch wrapper for OpenCode.
416
- *
417
- * `createOpenCodeProxy(resolve, options?)` captures a lazy per-request resolver
418
- * for the OpenCode lifecycle handle (`sandbox.opencode`) and returns a function
419
- * that wraps the user's worker entrypoint.
420
- *
421
- * The wrapped handler runs first. If it returns a 404 (or has no `fetch`), the
422
- * request falls through to the OpenCode web-UI proxy — the redirect handshake
423
- * for HTML loads and an ensure-then-forward into the container for everything
424
- * else. A 404 from the user handler is the "not mine, proxy it" signal, so the
425
- * handler only needs to own its own routes and `return new Response('Not
426
- * found', { status: 404 })` for the rest.
427
- *
428
- * ```ts
429
- * export default createOpenCodeProxy(
430
- * (env) => getSandbox(env.Sandbox, 'my-sandbox').opencode
431
- * )({
432
- * async fetch(request, env) {
433
- * // handle your own routes, else:
434
- * return new Response('Not found', { status: 404 });
435
- * }
436
- * });
437
- * ```
438
- */
439
- function createOpenCodeProxy(resolve, options) {
440
- return (handler) => ({
441
- ...handler,
442
- async fetch(request, env, ctx) {
443
- if (handler.fetch) {
444
- const response = await handler.fetch(request, env, ctx);
445
- if (response.status !== 404) return response;
446
- }
447
- return proxyToOpenCodeUI(request, resolve(env), options);
448
- }
449
- });
450
- }
451
-
452
- //#endregion
453
- export { OpenCodeHandle, OpenCodeStartupError, createOpenCodeClient, createOpenCodeProxy, proxyToOpenCodeUI, withOpenCode };
454
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["createSDKClient: OpenCodeClientFactory | undefined","DEFAULT_PORT","env: Record<string, string>","#sandbox","#defaults","#storage","#stateKey","#lastOptions","#loadPersisted","#persist","server: OpenCodeServer","#server"],"sources":["../../../../extensions/opencode/src/client.ts","../../../../extensions/opencode/src/types.ts","../../../../extensions/opencode/src/opencode.ts","../../../../extensions/opencode/src/lifecycle.ts","../../../../extensions/opencode/src/proxy.ts"],"sourcesContent":["import type { OpencodeClient } from '@opencode-ai/sdk/v2/client';\nimport type { OpenCodeHandle } from './lifecycle';\nimport type { OpenCodeOptions } from './types';\n\ntype OpenCodeClientFactory = (options: {\n baseUrl: string;\n fetch: typeof fetch;\n directory?: string;\n}) => OpencodeClient;\n\nlet createSDKClient: OpenCodeClientFactory | undefined;\n\nasync function loadSDK(): Promise<OpenCodeClientFactory> {\n if (createSDKClient) return createSDKClient;\n try {\n const sdk = await import('@opencode-ai/sdk/v2/client');\n createSDKClient = sdk.createOpencodeClient as OpenCodeClientFactory;\n return createSDKClient;\n } catch {\n throw new Error(\n '@opencode-ai/sdk is required for OpenCode integration. ' +\n 'Install it with: npm install @opencode-ai/sdk'\n );\n }\n}\n\n/**\n * Build a typed OpenCode SDK client from a lifecycle handle.\n *\n * Works against either the Worker stub (`sandbox.opencode`) or the in-DO object\n * (`this.opencode`): it ensures the server through the handle, reads the stored\n * config, and routes every request through `handle.fetch`. Because the handle\n * owns `containerFetch`, this helper never touches sandbox transport directly.\n *\n * The SDK is imported lazily so the peer dependency is only required when an\n * OpenCode client is actually built.\n */\nexport async function createOpenCodeClient<TClient = OpencodeClient>(\n handle: OpenCodeHandle,\n options?: OpenCodeOptions\n): Promise<TClient> {\n const server = await handle.start(options);\n const config = await handle.config();\n const directory = options?.directory ?? config.directory;\n\n const factory = await loadSDK();\n const client = factory({\n baseUrl: server.url,\n fetch: (input, init) => handle.fetch(new Request(input, init)),\n directory\n });\n\n return client as TClient;\n}\n","import type { Config } from '@opencode-ai/sdk/v2';\nimport { ErrorCode, type OpenCodeStartupContext } from '@repo/shared/errors';\n\n/**\n * Configuration options for starting OpenCode server\n */\nexport interface OpenCodeOptions {\n /** Port for OpenCode server (default: 4096) */\n port?: number;\n /** Working directory for OpenCode (default: container's cwd) */\n directory?: string;\n /** OpenCode configuration */\n config?: Config;\n /** Additional environment variables to pass to the OpenCode process */\n env?: Record<string, string>;\n}\n\n/**\n * Server lifecycle management\n */\nexport interface OpenCodeServer {\n /** Port the server is running on */\n port: number;\n /** Base URL for SDK client (http://localhost:{port}) */\n url: string;\n /** Close the server gracefully */\n close(): Promise<void>;\n}\n\n/**\n * Error thrown when OpenCode server fails to start\n */\nexport class OpenCodeStartupError extends Error {\n public readonly code = ErrorCode.OPENCODE_STARTUP_FAILED;\n public readonly context: OpenCodeStartupContext;\n\n constructor(\n message: string,\n context: OpenCodeStartupContext,\n options?: ErrorOptions\n ) {\n super(message, options);\n this.name = 'OpenCodeStartupError';\n this.context = context;\n }\n}\n","import {\n createExtensionProcessSandbox,\n type SandboxLike\n} from '@cloudflare/sandbox/extensions';\nimport type { Config } from '@opencode-ai/sdk/v2';\nimport {\n createLogger,\n type Logger,\n type SandboxCommand,\n type SandboxProcess\n} from '@repo/shared';\nimport type { OpenCodeOptions, OpenCodeServer } from './types';\nimport { OpenCodeStartupError } from './types';\n\n// Lazy logger creation to avoid global scope restrictions in Workers\nfunction getLogger(): Logger {\n return createLogger({ component: 'sandbox-do', operation: 'opencode' });\n}\n\nexport interface OpenCodeSandboxLike extends SandboxLike {\n exec: NonNullable<SandboxLike['exec']>;\n getProcess: NonNullable<SandboxLike['getProcess']>;\n listProcesses: NonNullable<SandboxLike['listProcesses']>;\n containerFetch(request: Request, port: number): Promise<Response>;\n}\n\nconst DEFAULT_PORT = 4096;\nconst OPENCODE_STARTUP_TIMEOUT_MS = 180_000;\nfunction openCodeCommand(port: number): SandboxCommand {\n return ['opencode', 'serve', '--port', String(port), '--hostname', '0.0.0.0'];\n}\n\nfunction commandsEqual(a: SandboxCommand, b: SandboxCommand): boolean {\n return a.length === b.length && a.every((value, index) => value === b[index]);\n}\n\n/** Recover a running OpenCode process from runtime-local process status. */\nexport async function findExistingOpenCodeProcess(\n sandbox: OpenCodeSandboxLike,\n port: number,\n directory?: string\n): Promise<SandboxProcess | null> {\n const command = openCodeCommand(port);\n const processes = createExtensionProcessSandbox(sandbox);\n const status = (await processes.listProcesses()).find(\n (candidate) =>\n candidate.state === 'running' &&\n candidate.cwd === directory &&\n commandsEqual(candidate.command, command)\n );\n return status ? processes.getProcess(status.id) : null;\n}\n\nasync function collectStderr(process: SandboxProcess): Promise<string> {\n const stream = await process.logs({ replay: true, follow: false });\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let stderr = '';\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (value.type === 'stderr') {\n stderr += decoder.decode(value.data, { stream: true });\n }\n }\n return stderr + decoder.decode();\n } finally {\n reader.releaseLock();\n }\n}\n\n/**\n * Ensures OpenCode server is running in the container.\n * Reuses existing process if one is already running on the specified port.\n * Handles concurrent startup attempts gracefully by retrying on failure.\n * Returns the process handle.\n */\nasync function ensureOpenCodeServer(\n sandbox: OpenCodeSandboxLike,\n port: number,\n directory?: string,\n config?: Config,\n customEnv?: Record<string, string>\n): Promise<SandboxProcess> {\n const existingProcess = await findExistingOpenCodeProcess(\n sandbox,\n port,\n directory\n );\n if (existingProcess) {\n getLogger().debug('Reusing existing OpenCode process', {\n port,\n processId: existingProcess.id\n });\n return existingProcess;\n }\n\n // Try to start a new OpenCode server\n try {\n return await startOpenCodeServer(\n sandbox,\n port,\n directory,\n config,\n customEnv\n );\n } catch (startupError) {\n // Startup failed - check if another concurrent request started the server\n // This handles the race condition where multiple requests try to start simultaneously\n const retryProcess = await findExistingOpenCodeProcess(\n sandbox,\n port,\n directory\n );\n if (retryProcess) {\n getLogger().debug(\n 'Startup failed but found concurrent process, reusing',\n { port, processId: retryProcess.id }\n );\n return retryProcess;\n }\n\n // No concurrent server found - the failure was genuine\n throw startupError;\n }\n}\n\n/**\n * Internal function to start a new OpenCode server process.\n */\nasync function startOpenCodeServer(\n sandbox: OpenCodeSandboxLike,\n port: number,\n directory?: string,\n config?: Config,\n customEnv?: Record<string, string>\n): Promise<SandboxProcess> {\n getLogger().info('Starting OpenCode server', { port, directory });\n\n // Pass config via OPENCODE_CONFIG_CONTENT and also extract API keys to env vars\n // because OpenCode's provider auth looks for env vars like ANTHROPIC_API_KEY\n const env: Record<string, string> = {};\n\n if (config) {\n env.OPENCODE_CONFIG_CONTENT = JSON.stringify(config);\n\n // Extract API keys from provider config\n // Support both options.apiKey (official type) and legacy top-level apiKey\n if (\n config.provider &&\n typeof config.provider === 'object' &&\n !Array.isArray(config.provider)\n ) {\n for (const [providerId, providerConfig] of Object.entries(\n config.provider\n )) {\n if (providerId === 'cloudflare-ai-gateway') {\n continue;\n }\n\n // Try options.apiKey first (official Config type)\n let apiKey = providerConfig?.options?.apiKey;\n // Fall back to top-level apiKey for convenience\n if (!apiKey) {\n apiKey = (providerConfig as Record<string, unknown> | undefined)\n ?.apiKey as string | undefined;\n }\n if (typeof apiKey === 'string') {\n const envVar = `${providerId.toUpperCase()}_API_KEY`;\n env[envVar] = apiKey;\n }\n }\n\n const aiGatewayConfig = config.provider['cloudflare-ai-gateway'];\n if (aiGatewayConfig?.options) {\n const options = aiGatewayConfig.options as Record<string, unknown>;\n\n if (typeof options.accountId === 'string') {\n env.CLOUDFLARE_ACCOUNT_ID = options.accountId;\n }\n\n if (typeof options.gatewayId === 'string') {\n env.CLOUDFLARE_GATEWAY_ID = options.gatewayId;\n }\n\n if (typeof options.apiToken === 'string') {\n env.CLOUDFLARE_API_TOKEN = options.apiToken;\n }\n }\n }\n }\n\n // Custom env vars override config-extracted ones\n if (customEnv) {\n Object.assign(env, customEnv);\n }\n\n const command = openCodeCommand(port);\n const process = await createExtensionProcessSandbox(sandbox).exec(command, {\n cwd: directory,\n env: Object.keys(env).length > 0 ? env : undefined\n });\n\n // Wait for server to be ready - check the actual health endpoint\n try {\n await process.waitForPort(port, {\n mode: 'http',\n path: '/path',\n status: 200,\n timeout: OPENCODE_STARTUP_TIMEOUT_MS\n });\n getLogger().info('OpenCode server started successfully', {\n port,\n processId: process.id\n });\n } catch (e) {\n const stderr = await collectStderr(process);\n const error = e instanceof Error ? e : undefined;\n getLogger().error('OpenCode server failed to start', error, {\n port,\n stderr\n });\n throw new OpenCodeStartupError(\n `OpenCode server failed to start. Stderr: ${stderr || '(empty)'}`,\n { port, stderr, command: command.join(' ') },\n { cause: e }\n );\n }\n\n return process;\n}\n\n/**\n * Starts an OpenCode server inside a Sandbox container.\n *\n * This function manages the server lifecycle only - use `createOpenCodeClient()` if you\n * also need a typed SDK client for programmatic access.\n *\n * If an OpenCode server is already running on the specified port, this function\n * will reuse it instead of starting a new one.\n *\n * @param sandbox - The Sandbox instance to run OpenCode in\n * @param options - Configuration options\n * @returns Promise resolving to server handle { port, url, close() }\n *\n * @example\n * ```typescript\n * import { getSandbox } from '@cloudflare/sandbox'\n * import { createOpenCodeServer } from '@cloudflare/sandbox/opencode'\n *\n * const sandbox = getSandbox(env.Sandbox, 'my-agent')\n * const server = await createOpenCodeServer(sandbox, {\n * directory: '/home/user/my-project',\n * config: {\n * provider: {\n * anthropic: {\n * options: { apiKey: env.ANTHROPIC_KEY }\n * },\n * // Or use Cloudflare AI Gateway (with unified billing, no provider keys needed).\n * // 'cloudflare-ai-gateway': {\n * // options: {\n * // accountId: env.CF_ACCOUNT_ID,\n * // gatewayId: env.CF_GATEWAY_ID,\n * // apiToken: env.CF_API_TOKEN\n * // },\n * // models: { 'anthropic/claude-sonnet-4-5-20250929': {} }\n * // }\n * }\n * }\n * })\n *\n * // Proxy requests to the web UI\n * return sandbox.containerFetch(request, server.port)\n *\n * // When done\n * await server.close()\n * ```\n */\nexport async function createOpenCodeServer(\n sandbox: OpenCodeSandboxLike,\n options?: OpenCodeOptions\n): Promise<OpenCodeServer> {\n const port = options?.port ?? DEFAULT_PORT;\n const process = await ensureOpenCodeServer(\n sandbox,\n port,\n options?.directory,\n options?.config,\n options?.env\n );\n\n return {\n port,\n url: `http://localhost:${port}`,\n close: async () => {\n await process.kill(15);\n await process.waitForExit().catch(() => {\n /* exit observed */\n });\n }\n };\n}\n\n/**\n * Proxy a request directly to the OpenCode server.\n *\n * Unlike `proxyToOpenCode()`, this helper does not apply any web UI redirects\n * or query parameter rewrites. Use it for API/CLI traffic where raw request\n * forwarding is preferred.\n */\nexport function proxyToOpenCodeServer(\n request: Request,\n sandbox: OpenCodeSandboxLike,\n server: OpenCodeServer\n): Promise<Response> {\n return sandbox.containerFetch(request, server.port);\n}\n\n/**\n * Proxy a request to the OpenCode web UI.\n *\n * This function handles the redirect and proxying only - you must start the\n * server separately using `createOpenCodeServer()`.\n *\n * Specifically handles:\n * 1. Ensuring the `?url=` parameter is set (required for OpenCode's frontend to\n * make API calls through the proxy instead of directly to localhost:4096)\n * 2. Proxying the request to the container\n *\n * @param request - The incoming HTTP request\n * @param sandbox - The Sandbox instance running OpenCode\n * @param server - The OpenCode server handle from createOpenCodeServer()\n * @returns Response from OpenCode or a redirect response\n *\n * @example\n * ```typescript\n * import { getSandbox } from '@cloudflare/sandbox'\n * import { createOpenCodeServer, proxyToOpenCode } from '@cloudflare/sandbox/opencode'\n *\n * export default {\n * async fetch(request: Request, env: Env) {\n * const sandbox = getSandbox(env.Sandbox, 'opencode')\n * const server = await createOpenCodeServer(sandbox, {\n * directory: '/home/user/project',\n * config: {\n * provider: {\n * anthropic: {\n * options: { apiKey: env.ANTHROPIC_KEY }\n * },\n * // Optional: Route all providers through Cloudflare AI Gateway\n * 'cloudflare-ai-gateway': {\n * options: {\n * accountId: env.CF_ACCOUNT_ID,\n * gatewayId: env.CF_GATEWAY_ID,\n * apiToken: env.CF_API_TOKEN\n * }\n * }\n * }\n * }\n * })\n * return proxyToOpenCode(request, sandbox, server)\n * }\n * }\n * ```\n */\nexport function proxyToOpenCode(\n request: Request,\n sandbox: OpenCodeSandboxLike,\n server: OpenCodeServer\n): Response | Promise<Response> {\n const url = new URL(request.url);\n\n // OpenCode's frontend defaults to http://127.0.0.1:4096 when hostname includes\n // \"localhost\" or \"opencode.ai\". The ?url= parameter overrides this behavior.\n // We only redirect GET requests for HTML pages (initial page load).\n // API calls (POST, PATCH, etc.) and asset requests are proxied directly\n // since redirecting POST loses the request body.\n if (!url.searchParams.has('url') && request.method === 'GET') {\n const accept = request.headers.get('accept') || '';\n const isHtmlRequest = accept.includes('text/html') || url.pathname === '/';\n if (isHtmlRequest) {\n url.searchParams.set('url', url.origin);\n return Response.redirect(url.toString(), 302);\n }\n }\n\n return proxyToOpenCodeServer(request, sandbox, server);\n}\n","import {\n SandboxExtension,\n type SandboxLike\n} from '@cloudflare/sandbox/extensions';\nimport {\n createOpenCodeServer,\n findExistingOpenCodeProcess,\n type OpenCodeSandboxLike\n} from './opencode';\nimport type { OpenCodeOptions, OpenCodeServer } from './types';\n\nconst DEFAULT_PORT = 4096;\n\n/** Resolved server metadata that is safe to return across the RPC boundary. */\nexport interface OpenCodeServerInfo {\n port: number;\n url: string;\n}\n\n/** Snapshot of the resolved lifecycle configuration. */\nexport interface OpenCodeConfig {\n port: number;\n directory?: string;\n}\n\n/** Current server status as observed in the container. */\nexport interface OpenCodeStatus extends OpenCodeServerInfo {\n running: boolean;\n}\n\n/**\n * The slice of `DurableObjectStorage` the handle uses to persist desired-state.\n * Pass `this.ctx.storage` so the server config survives a Durable Object\n * eviction (cold start) and is recovered lazily on the next `start()`.\n */\nexport interface OpenCodeStateStorage {\n get<T>(key: string): Promise<T | undefined>;\n put<T>(key: string, value: T): Promise<void>;\n}\n\n/** Options for {@link withOpenCode}: server defaults plus optional storage. */\nexport interface WithOpenCodeOptions extends OpenCodeOptions {\n /** Persist desired-state here so it survives DO eviction. */\n storage?: OpenCodeStateStorage;\n}\n\nconst STATE_KEY_PREFIX = 'opencode:desired-state:';\n\n/** Recognise the retryable container-unavailable error across RPC. */\nfunction isContainerUnavailable(error: unknown): boolean {\n if (typeof error !== 'object' || error === null) return false;\n return (error as { name?: unknown }).name === 'ContainerUnavailableError';\n}\n\n/**\n * DO-resident lifecycle handle for an OpenCode server. Owns the durable\n * `opencode serve` process: start/reuse, stop, status, and request proxying.\n *\n * It extends {@link SandboxExtension}, so the DO stub exposes it as\n * `sandbox.opencode` and method calls dispatch through `callExtension` — the\n * same path the interpreter extension uses. `createOpenCodeClient` consumes the\n * same handle from either the Worker stub or the in-DO object.\n *\n * The server starts lazily: nothing runs until `start()` (or `fetch()`, which\n * calls it) is invoked. To start optimistically, call `opencode.start()` from\n * your Sandbox subclass's `onStart`.\n */\nexport class OpenCodeHandle extends SandboxExtension {\n readonly #sandbox: OpenCodeSandboxLike;\n readonly #defaults: OpenCodeOptions;\n readonly #storage: OpenCodeStateStorage | undefined;\n readonly #stateKey: string;\n #server: OpenCodeServer | undefined;\n #lastOptions: OpenCodeOptions | undefined;\n\n constructor(\n sandbox: OpenCodeSandboxLike,\n defaults: OpenCodeOptions = {},\n storage?: OpenCodeStateStorage,\n stateIndex = 0\n ) {\n super(sandbox as SandboxLike);\n this.#sandbox = sandbox;\n this.#defaults = defaults;\n this.#storage = storage;\n this.#stateKey = `${STATE_KEY_PREFIX}${stateIndex}`;\n }\n\n /**\n * Start or reuse the OpenCode server, returning RPC-safe metadata. With no\n * options it reuses the last-used config, recovering persisted desired-state\n * after a cold start. Retries once on a transient `CONTAINER_UNAVAILABLE`\n * (e.g. a rollout in flight).\n */\n async start(options?: OpenCodeOptions): Promise<OpenCodeServerInfo> {\n const recovered =\n options ?? this.#lastOptions ?? (await this.#loadPersisted());\n const resolved = { ...this.#defaults, ...recovered };\n this.#lastOptions = resolved;\n await this.#persist(resolved);\n\n let server: OpenCodeServer;\n try {\n server = await createOpenCodeServer(this.#sandbox, resolved);\n } catch (error) {\n if (!isContainerUnavailable(error)) throw error;\n server = await createOpenCodeServer(this.#sandbox, resolved);\n }\n\n this.#server = server;\n return { port: server.port, url: server.url };\n }\n\n /** Stop the running server, if one was started through this handle. */\n async stop(): Promise<void> {\n if (!this.#server) return;\n await this.#server.close();\n this.#server = undefined;\n }\n\n /** Report whether the named OpenCode server is currently running. */\n async status(): Promise<OpenCodeStatus> {\n const resolved = { ...this.#defaults, ...this.#lastOptions };\n const port = resolved.port ?? DEFAULT_PORT;\n const process = await findExistingOpenCodeProcess(\n this.#sandbox,\n port,\n resolved.directory\n );\n return {\n running: process !== null,\n port,\n url: `http://localhost:${port}`\n };\n }\n\n /** Snapshot of the resolved configuration the client builder reads. */\n async config(): Promise<OpenCodeConfig> {\n const resolved = { ...this.#defaults, ...this.#lastOptions };\n return {\n port: resolved.port ?? DEFAULT_PORT,\n directory: resolved.directory\n };\n }\n\n /**\n * Start the server then route a request into the container. This is the\n * transport the SDK client's `fetch` adapter and the Worker proxy use, so it\n * works identically from the Worker stub (one RPC hop) or in-DO (local).\n */\n async fetch(request: Request): Promise<Response> {\n const server = await this.start();\n return this.#sandbox.containerFetch(request, server.port);\n }\n\n /**\n * Persist resolved desired-state so a cold DO can recover it. Best-effort.\n *\n * Secret-bearing fields (`config`, `env`) are never written to storage. They\n * are sourced fresh from the handle's defaults — which the Sandbox rebuilds\n * from the environment on every construction — so a cold start always uses\n * current credentials rather than a durable copy.\n */\n async #persist(options: OpenCodeOptions): Promise<void> {\n if (!this.#storage) return;\n const { config: _config, env: _env, ...safe } = options;\n await this.#storage.put(this.#stateKey, safe);\n }\n\n /** Read persisted desired-state, if any, after a DO eviction. */\n async #loadPersisted(): Promise<OpenCodeOptions | undefined> {\n if (!this.#storage) return undefined;\n return this.#storage.get<OpenCodeOptions>(this.#stateKey);\n }\n}\n\n/**\n * Assigns each handle a stable per-sandbox index so its persisted state key is\n * deterministic across DO reconstruction (field initializers run in the same\n * order each time). Keyed weakly so it is collected with the sandbox.\n */\nconst stateIndexCounter = new WeakMap<OpenCodeSandboxLike, number>();\n\n/**\n * Factory — attach as a field on a Sandbox subclass:\n * `opencode = withOpenCode(this, { directory, config, storage: this.ctx.storage })`.\n *\n * Pass `storage` to persist desired-state so the server is recovered after a DO\n * eviction (cold start). The server starts lazily on first use.\n */\nexport function withOpenCode(\n sandbox: OpenCodeSandboxLike,\n options: WithOpenCodeOptions = {}\n): OpenCodeHandle {\n const { storage, ...defaults } = options;\n const index = stateIndexCounter.get(sandbox) ?? 0;\n stateIndexCounter.set(sandbox, index + 1);\n return new OpenCodeHandle(sandbox, defaults, storage, index);\n}\n","import type { OpenCodeHandle } from './lifecycle';\n\n/** Configuration for {@link createOpenCodeProxy}. */\nexport interface OpenCodeProxyOptions {\n /** Origin the OpenCode web UI should call back through. Defaults to the request origin. */\n callbackOrigin?: string;\n}\n\n/**\n * Proxy a request to the OpenCode web UI through a lifecycle handle.\n *\n * For an initial HTML page load that still lacks the `?url=` parameter, returns\n * a redirect that adds it (so the OpenCode frontend calls back through the\n * proxy instead of `127.0.0.1:4096`). Every other request is routed through\n * `handle.fetch`, which ensures the server is running before forwarding into the\n * container.\n */\nexport function proxyToOpenCodeUI(\n request: Request,\n handle: OpenCodeHandle,\n options?: OpenCodeProxyOptions\n): Response | Promise<Response> {\n const url = new URL(request.url);\n\n // OpenCode's frontend defaults its API base to 127.0.0.1:4096; the ?url=\n // parameter overrides that. Only redirect initial HTML GET loads — redirecting\n // a POST would drop the body.\n if (!url.searchParams.has('url') && request.method === 'GET') {\n const accept = request.headers.get('accept') || '';\n const isHtmlRequest = accept.includes('text/html') || url.pathname === '/';\n if (isHtmlRequest) {\n url.searchParams.set('url', options?.callbackOrigin ?? url.origin);\n return Response.redirect(url.toString(), 302);\n }\n }\n\n // Ensure-then-forward: the handle starts the server on demand before proxying.\n return handle.fetch(request);\n}\n\n/**\n * Curried Worker fetch wrapper for OpenCode.\n *\n * `createOpenCodeProxy(resolve, options?)` captures a lazy per-request resolver\n * for the OpenCode lifecycle handle (`sandbox.opencode`) and returns a function\n * that wraps the user's worker entrypoint.\n *\n * The wrapped handler runs first. If it returns a 404 (or has no `fetch`), the\n * request falls through to the OpenCode web-UI proxy — the redirect handshake\n * for HTML loads and an ensure-then-forward into the container for everything\n * else. A 404 from the user handler is the \"not mine, proxy it\" signal, so the\n * handler only needs to own its own routes and `return new Response('Not\n * found', { status: 404 })` for the rest.\n *\n * ```ts\n * export default createOpenCodeProxy(\n * (env) => getSandbox(env.Sandbox, 'my-sandbox').opencode\n * )({\n * async fetch(request, env) {\n * // handle your own routes, else:\n * return new Response('Not found', { status: 404 });\n * }\n * });\n * ```\n */\nexport function createOpenCodeProxy<Env>(\n resolve: (env: Env) => OpenCodeHandle,\n options?: OpenCodeProxyOptions\n): (handler: ExportedHandler<Env>) => ExportedHandler<Env> {\n return (handler) => ({\n ...handler,\n async fetch(request, env, ctx) {\n if (handler.fetch) {\n const response = await handler.fetch(request, env, ctx);\n if (response.status !== 404) return response;\n }\n return proxyToOpenCodeUI(request, resolve(env), options);\n }\n });\n}\n"],"mappings":";;;;;;AAUA,IAAIA;AAEJ,eAAe,UAA0C;AACvD,KAAI,gBAAiB,QAAO;AAC5B,KAAI;AAEF,qBADY,MAAM,OAAO,+BACH;AACtB,SAAO;SACD;AACN,QAAM,IAAI,MACR,uGAED;;;;;;;;;;;;;;AAeL,eAAsB,qBACpB,QACA,SACkB;CAClB,MAAM,SAAS,MAAM,OAAO,MAAM,QAAQ;CAC1C,MAAM,SAAS,MAAM,OAAO,QAAQ;CACpC,MAAM,YAAY,SAAS,aAAa,OAAO;AAS/C,SAPgB,MAAM,SAAS,EACR;EACrB,SAAS,OAAO;EAChB,QAAQ,OAAO,SAAS,OAAO,MAAM,IAAI,QAAQ,OAAO,KAAK,CAAC;EAC9D;EACD,CAAC;;;;;;;;AClBJ,IAAa,uBAAb,cAA0C,MAAM;CAC9C,AAAgB,OAAO,UAAU;CACjC,AAAgB;CAEhB,YACE,SACA,SACA,SACA;AACA,QAAM,SAAS,QAAQ;AACvB,OAAK,OAAO;AACZ,OAAK,UAAU;;;;;;AC5BnB,SAAS,YAAoB;AAC3B,QAAO,aAAa;EAAE,WAAW;EAAc,WAAW;EAAY,CAAC;;AAUzE,MAAMC,i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AI,SAAsC;;;;;;;;AASpE,SAAgB,aACd,SACA,UAA+B,EAAE,EACjB;CAChB,MAAM,EAAE,SAAS,GAAG,aAAa;CACjC,MAAM,QAAQ,kBAAkB,IAAI,QAAQ,IAAI;AAChD,mBAAkB,IAAI,SAAS,QAAQ,EAAE;AACzC,QAAO,IAAI,eAAe,SAAS,UAAU,SAAS,MAAM;;;;;;;;;;;;;;ACpL9D,SAAgB,kBACd,SACA,QACA,SAC8B;CAC9B,MAAM,MAAM,IAAI,IAAI,QAAQ,IAAI;AAKhC,KAAI,CAAC,IAAI,aAAa,IAAI,MAAM,IAAI,QAAQ,WAAW,OAGrD;OAFe,QAAQ,QAAQ,IAAI,SAAS,IAAI,IACnB,SAAS,YAAY,IAAI,IAAI,aAAa,KACpD;AACjB,OAAI,aAAa,IAAI,OAAO,SAAS,kBAAkB,IAAI,OAAO;AAClE,UAAO,SAAS,SAAS,IAAI,UAAU,EAAE,IAAI;;;AAKjD,QAAO,OAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B9B,SAAgB,oBACd,SACA,SACyD;AACzD,SAAQ,aAAa;EACnB,GAAG;EACH,MAAM,MAAM,SAAS,KAAK,KAAK;AAC7B,OAAI,QAAQ,OAAO;IACjB,MAAM,WAAW,MAAM,QAAQ,MAAM,SAAS,KAAK,IAAI;AACvD,QAAI,SAAS,WAAW,IAAK,QAAO;;AAEtC,UAAO,kBAAkB,SAAS,QAAQ,IAAI,EAAE,QAAQ;;EAE3D"}
@@ -1,73 +0,0 @@
1
- //#region ../shared/dist/process-types.d.ts
2
- type SandboxCommand = readonly [executable: string, ...args: string[]];
3
- /**
4
- * Terminal outcome observed for the root subprocess.
5
- *
6
- * The process resource remains running until its supervised process group has
7
- * settled. Signals delivered only to descendants do not rewrite this outcome.
8
- */
9
- interface ProcessExit {
10
- code: number;
11
- signal?: number;
12
- timedOut: boolean;
13
- }
14
- interface ProcessFailure {
15
- code: string;
16
- message: string;
17
- }
18
- interface ProcessStatusBase {
19
- id: string;
20
- pid: number;
21
- command: SandboxCommand;
22
- cwd?: string;
23
- startedAt: string;
24
- }
25
- /** Lifecycle state for the complete supervised process group. */
26
- type ProcessStatus = (ProcessStatusBase & {
27
- state: 'running';
28
- }) | (ProcessStatusBase & {
29
- state: 'exited';
30
- exit: ProcessExit;
31
- endedAt: string;
32
- }) | (ProcessStatusBase & {
33
- state: 'error';
34
- error: ProcessFailure;
35
- endedAt: string;
36
- });
37
- type ProcessLogCursor = string;
38
- type ProcessLogEvent = {
39
- type: 'stdout' | 'stderr';
40
- cursor: ProcessLogCursor;
41
- timestamp: string;
42
- data: Uint8Array;
43
- } | {
44
- type: 'terminal';
45
- state: 'exited';
46
- cursor: ProcessLogCursor;
47
- timestamp: string;
48
- exit: ProcessExit;
49
- } | {
50
- type: 'terminal';
51
- state: 'error';
52
- cursor: ProcessLogCursor;
53
- timestamp: string;
54
- error: ProcessFailure;
55
- } | {
56
- type: 'truncated';
57
- cursor?: ProcessLogCursor;
58
- timestamp: string;
59
- };
60
- interface WaitForLogResult {
61
- stream: 'stdout' | 'stderr';
62
- text: string;
63
- match: string;
64
- cursor?: ProcessLogCursor;
65
- }
66
- interface ProcessLogsRPCOptions {
67
- since?: ProcessLogCursor;
68
- replay?: boolean;
69
- follow?: boolean;
70
- }
71
- //#endregion
72
- export { ProcessLogsRPCOptions as a, WaitForLogResult as c, ProcessLogEvent as i, ProcessFailure as n, ProcessStatus as o, ProcessLogCursor as r, SandboxCommand as s, ProcessExit as t };
73
- //# sourceMappingURL=process-types-GStiZ8f8.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"process-types-GStiZ8f8.d.ts","names":["SandboxCommand","ProcessExit","ProcessFailure","ProcessStatusBase","ProcessStatus","ProcessLogCursor","ProcessLogEvent","Uint8Array","WaitForLogResult","ProcessStartOptions","Record","ProcessLogsRPCOptions","ProcessLogSubscriptionAPI","ReadableStream","Promise","SandboxProcessesAPI"],"sources":["../../shared/dist/process-types.d.ts"],"sourcesContent":["export type SandboxCommand = readonly [executable: string, ...args: string[]];\n/**\n * Terminal outcome observed for the root subprocess.\n *\n * The process resource remains running until its supervised process group has\n * settled. Signals delivered only to descendants do not rewrite this outcome.\n */\nexport interface ProcessExit {\n code: number;\n signal?: number;\n timedOut: boolean;\n}\nexport interface ProcessFailure {\n code: string;\n message: string;\n}\ninterface ProcessStatusBase {\n id: string;\n pid: number;\n command: SandboxCommand;\n cwd?: string;\n startedAt: string;\n}\n/** Lifecycle state for the complete supervised process group. */\nexport type ProcessStatus = (ProcessStatusBase & {\n state: 'running';\n}) | (ProcessStatusBase & {\n state: 'exited';\n exit: ProcessExit;\n endedAt: string;\n}) | (ProcessStatusBase & {\n state: 'error';\n error: ProcessFailure;\n endedAt: string;\n});\nexport type ProcessLogCursor = string;\nexport type ProcessLogEvent = {\n type: 'stdout' | 'stderr';\n cursor: ProcessLogCursor;\n timestamp: string;\n data: Uint8Array;\n} | {\n type: 'terminal';\n state: 'exited';\n cursor: ProcessLogCursor;\n timestamp: string;\n exit: ProcessExit;\n} | {\n type: 'terminal';\n state: 'error';\n cursor: ProcessLogCursor;\n timestamp: string;\n error: ProcessFailure;\n} | {\n type: 'truncated';\n cursor?: ProcessLogCursor;\n timestamp: string;\n};\nexport interface WaitForLogResult {\n stream: 'stdout' | 'stderr';\n text: string;\n match: string;\n cursor?: ProcessLogCursor;\n}\nexport interface ProcessStartOptions {\n cwd?: string;\n env?: Record<string, string>;\n timeout?: number;\n}\nexport interface ProcessLogsRPCOptions {\n since?: ProcessLogCursor;\n replay?: boolean;\n follow?: boolean;\n}\nexport interface ProcessLogSubscriptionAPI {\n stream(): Promise<ReadableStream<ProcessLogEvent>>;\n cancel(): Promise<void>;\n [Symbol.dispose](): void;\n}\nexport interface SandboxProcessesAPI {\n start(command: SandboxCommand, options?: ProcessStartOptions): Promise<ProcessStatus>;\n get(id: string): Promise<ProcessStatus | null>;\n list(): Promise<ProcessStatus[]>;\n openLogs(id: string, options?: ProcessLogsRPCOptions): Promise<ProcessLogSubscriptionAPI>;\n kill(id: string, signal?: number): Promise<void>;\n hasActive(): Promise<boolean>;\n}\nexport {};\n//# sourceMappingURL=process-types.d.ts.map"],"mappings":";KAAYA,cAAAA;AAAZ;AAOA;AAKA;AAGC;AASD;;AAEMG,UAnBWF,WAAAA,CAmBXE;EAEIF,IAAAA,EAAAA,MAAAA;EAEJE,MAAAA,CAAAA,EAAAA,MAAAA;EAEKD,QAAAA,EAAAA,OAAAA;;AAGCG,UAvBKH,cAAAA,CAuBW;EAChBI,IAAAA,EAAAA,MAAAA;EAEAD,OAAAA,EAAAA,MAAAA;;UAtBFF,iBAAAA,CA4BEE;EAEFJ,EAAAA,EAAAA,MAAAA;EAIEI,GAAAA,EAAAA,MAAAA;EAEDH,OAAAA,EAjCEF,cAiCFE;EAGEG,GAAAA,CAAAA,EAAAA,MAAAA;EAAgB,SAAA,EAAA,MAAA;AAG7B;AAWA;KA7CYD,aAAAA,IAAiBD;;MAEvBA;;QAEIF;;MAEJE;;SAEKD;;;KAGCG,gBAAAA;KACAC,eAAAA;;UAEAD;;QAEFE;;;;UAIEF;;QAEFJ;;;;UAIEI;;SAEDH;;;WAGEG;;;UAGIG,gBAAAA;;;;WAIJH;;UAOIM,qBAAAA;UACLN"}
@@ -1,42 +0,0 @@
1
- import { o as ProcessStatus, s as SandboxCommand } from "./process-types-GStiZ8f8.js";
2
- import { A as CreateTerminalOptions, D as MountBucketOptions, M as Terminal, R as ExecOptions, S as BackupOptions, T as DirectoryBackup, _ as RenameFileResult, b as WriteFileResult, d as ListFilesOptions, f as ListFilesResult, g as ReadFileStreamResult, h as ReadFileResult, i as DeleteFileResult, k as RestoreBackupResult, m as MoveFileResult, o as FileEncoding, p as MkdirResult, q as SandboxProcess, r as CheckChangesResult, s as FileExistsResult, t as CheckChangesOptions, v as WatchOptions } from "./filesystem-BWAZCZER.js";
3
-
4
- //#region ../shared/dist/types/sandbox.d.ts
5
-
6
- interface ISandbox {
7
- exec(command: SandboxCommand, options?: ExecOptions): Promise<SandboxProcess>;
8
- getProcess(id: string): Promise<SandboxProcess | null>;
9
- listProcesses(): Promise<ProcessStatus[]>;
10
- writeFile(path: string, content: string | ReadableStream<Uint8Array>, options?: {
11
- encoding?: string;
12
- }): Promise<WriteFileResult>;
13
- readFile(path: string, options: {
14
- encoding: 'none';
15
- }): Promise<ReadFileStreamResult>;
16
- readFile(path: string, options?: {
17
- encoding?: Exclude<FileEncoding, 'none'>;
18
- }): Promise<ReadFileResult>;
19
- readFileStream(path: string): Promise<ReadableStream<Uint8Array>>;
20
- watch(path: string, options?: WatchOptions): Promise<ReadableStream<Uint8Array>>;
21
- checkChanges(path: string, options?: CheckChangesOptions): Promise<CheckChangesResult>;
22
- mkdir(path: string, options?: {
23
- recursive?: boolean;
24
- }): Promise<MkdirResult>;
25
- deleteFile(path: string): Promise<DeleteFileResult>;
26
- renameFile(oldPath: string, newPath: string, options?: Record<string, never>): Promise<RenameFileResult>;
27
- moveFile(sourcePath: string, destinationPath: string, options?: Record<string, never>): Promise<MoveFileResult>;
28
- listFiles(path: string, options?: ListFilesOptions): Promise<ListFilesResult>;
29
- exists(path: string): Promise<FileExistsResult>;
30
- setEnvVars(envVars: Record<string, string | undefined>): Promise<void>;
31
- mountBucket(bucket: string, mountPath: string, options: MountBucketOptions): Promise<void>;
32
- unmountBucket(mountPath: string): Promise<void>;
33
- createBackup(options: BackupOptions): Promise<DirectoryBackup>;
34
- restoreBackup(backup: DirectoryBackup): Promise<RestoreBackupResult>;
35
- wsConnect(request: Request, port: number): Promise<Response>;
36
- createTerminal(options: CreateTerminalOptions): Promise<Terminal>;
37
- getTerminal(id: string): Promise<Terminal | null>;
38
- listTerminals(): Promise<Terminal[]>;
39
- }
40
- //#endregion
41
- export { ISandbox as t };
42
- //# sourceMappingURL=sandbox-BbAabq93.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sandbox-BbAabq93.d.ts","names":["ProcessStatus","SandboxCommand","CreateTerminalOptions","Terminal","BackupOptions","DirectoryBackup","MountBucketOptions","RestoreBackupResult","ExecOptions","SandboxProcess","CheckChangesOptions","CheckChangesResult","DeleteFileResult","FileEncoding","FileExistsResult","ListFilesOptions","ListFilesResult","MkdirResult","MoveFileResult","ReadFileResult","ReadFileStreamResult","RenameFileResult","WatchOptions","WriteFileResult","ISandbox","Promise","Uint8Array","ReadableStream","Exclude","Record","Request","Response"],"sources":["../../shared/dist/types/sandbox.d.ts"],"sourcesContent":["import type { ProcessStatus, SandboxCommand } from '../process-types.js';\nimport type { CreateTerminalOptions, Terminal } from '../pty-types.js';\nimport type { BackupOptions, DirectoryBackup, MountBucketOptions, RestoreBackupResult } from './backup-mounts.js';\nimport type { ExecOptions, SandboxProcess } from './core.js';\nimport type { CheckChangesOptions, CheckChangesResult, DeleteFileResult, FileEncoding, FileExistsResult, ListFilesOptions, ListFilesResult, MkdirResult, MoveFileResult, ReadFileResult, ReadFileStreamResult, RenameFileResult, WatchOptions, WriteFileResult } from './filesystem.js';\nexport interface ISandbox {\n exec(command: SandboxCommand, options?: ExecOptions): Promise<SandboxProcess>;\n getProcess(id: string): Promise<SandboxProcess | null>;\n listProcesses(): Promise<ProcessStatus[]>;\n writeFile(path: string, content: string | ReadableStream<Uint8Array>, options?: {\n encoding?: string;\n }): Promise<WriteFileResult>;\n readFile(path: string, options: {\n encoding: 'none';\n }): Promise<ReadFileStreamResult>;\n readFile(path: string, options?: {\n encoding?: Exclude<FileEncoding, 'none'>;\n }): Promise<ReadFileResult>;\n readFileStream(path: string): Promise<ReadableStream<Uint8Array>>;\n watch(path: string, options?: WatchOptions): Promise<ReadableStream<Uint8Array>>;\n checkChanges(path: string, options?: CheckChangesOptions): Promise<CheckChangesResult>;\n mkdir(path: string, options?: {\n recursive?: boolean;\n }): Promise<MkdirResult>;\n deleteFile(path: string): Promise<DeleteFileResult>;\n renameFile(oldPath: string, newPath: string, options?: Record<string, never>): Promise<RenameFileResult>;\n moveFile(sourcePath: string, destinationPath: string, options?: Record<string, never>): Promise<MoveFileResult>;\n listFiles(path: string, options?: ListFilesOptions): Promise<ListFilesResult>;\n exists(path: string): Promise<FileExistsResult>;\n setEnvVars(envVars: Record<string, string | undefined>): Promise<void>;\n mountBucket(bucket: string, mountPath: string, options: MountBucketOptions): Promise<void>;\n unmountBucket(mountPath: string): Promise<void>;\n createBackup(options: BackupOptions): Promise<DirectoryBackup>;\n restoreBackup(backup: DirectoryBackup): Promise<RestoreBackupResult>;\n wsConnect(request: Request, port: number): Promise<Response>;\n createTerminal(options: CreateTerminalOptions): Promise<Terminal>;\n getTerminal(id: string): Promise<Terminal | null>;\n listTerminals(): Promise<Terminal[]>;\n}\n//# sourceMappingURL=sandbox.d.ts.map"],"mappings":";;;;;AAMkBC,UADDuB,QAAAA,CACCvB;EAA0BO,IAAAA,CAAAA,OAAAA,EAA1BP,cAA0BO,EAAAA,OAAAA,CAAAA,EAAAA,WAAAA,CAAAA,EAAciB,OAAdjB,CAAsBC,cAAtBD,CAAAA;EAAsBC,UAAAA,CAAAA,EAAAA,EAAAA,MAAAA,CAAAA,EACtCgB,OADsChB,CAC9BA,cAD8BA,GAAAA,IAAAA,CAAAA;EAARgB,aAAAA,EAAAA,EAErCA,OAFqCA,CAE7BzB,aAF6ByB,EAAAA,CAAAA;EACtBhB,SAAAA,CAAAA,IAAAA,EAAAA,MAAAA,EAAAA,OAAAA,EAAAA,MAAAA,GAEUkB,cAFVlB,CAEyBiB,UAFzBjB,CAAAA,EAAAA,OACPT,CADOS,EAAAA;IAARgB,QAAAA,CAAAA,EAAAA,MAAAA;EACCzB,CAAAA,CAAAA,EAGrByB,OAHqBzB,CAGbuB,eAHavB,CAAAA;EAARyB,QAAAA,CAAAA,IAAAA,EAAAA,MAAAA,EAAAA,OAAAA,EAAAA;IACwCC,QAAAA,EAAAA,MAAAA;EAAfC,CAAAA,CAAAA,EAKtCF,OALsCE,CAK9BP,oBAL8BO,CAAAA;EAE9BJ,QAAAA,CAAAA,IAAAA,EAA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