@cloudflare/sandbox 0.6.3 → 0.6.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/Dockerfile +24 -0
- package/dist/contexts-DeQQjsXq.d.ts +161 -0
- package/dist/contexts-DeQQjsXq.d.ts.map +1 -0
- package/dist/{dist-D0sZt0AD.js → dist-2SF6oOaz.js} +1 -1
- package/dist/{dist-D0sZt0AD.js.map → dist-2SF6oOaz.js.map} +1 -1
- package/dist/errors-BHN41iBd.js +124 -0
- package/dist/errors-BHN41iBd.js.map +1 -0
- package/dist/index.d.ts +2 -150
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -140
- package/dist/index.js.map +1 -1
- package/dist/openai/index.d.ts +1 -1
- package/dist/openai/index.js +1 -1
- package/dist/opencode/index.d.ts +149 -0
- package/dist/opencode/index.d.ts.map +1 -0
- package/dist/opencode/index.js +297 -0
- package/dist/opencode/index.js.map +1 -0
- package/dist/{sandbox-bAj-cB2H.d.ts → sandbox-C9WRqWBO.d.ts} +2 -2
- package/dist/{sandbox-bAj-cB2H.d.ts.map → sandbox-C9WRqWBO.d.ts.map} +1 -1
- package/package.json +14 -4
package/dist/openai/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Sandbox } from "../sandbox-
|
|
1
|
+
import { t as Sandbox } from "../sandbox-C9WRqWBO.js";
|
|
2
2
|
import { ApplyPatchOperation, ApplyPatchResult, Editor as Editor$1, Shell as Shell$1, ShellAction, ShellResult } from "@openai/agents";
|
|
3
3
|
|
|
4
4
|
//#region src/openai/index.d.ts
|
package/dist/openai/index.js
CHANGED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { t as Sandbox } from "../sandbox-C9WRqWBO.js";
|
|
2
|
+
import { t as OpencodeStartupContext } from "../contexts-DeQQjsXq.js";
|
|
3
|
+
import { Config } from "@opencode-ai/sdk";
|
|
4
|
+
|
|
5
|
+
//#region src/opencode/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for starting OpenCode server
|
|
8
|
+
*/
|
|
9
|
+
interface OpencodeOptions {
|
|
10
|
+
/** Port for OpenCode server (default: 4096) */
|
|
11
|
+
port?: number;
|
|
12
|
+
/** Working directory for OpenCode (default: container's cwd) */
|
|
13
|
+
directory?: string;
|
|
14
|
+
/** OpenCode configuration */
|
|
15
|
+
config?: Config;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Server lifecycle management
|
|
19
|
+
*/
|
|
20
|
+
interface OpencodeServer {
|
|
21
|
+
/** Port the server is running on */
|
|
22
|
+
port: number;
|
|
23
|
+
/** Base URL for SDK client (http://localhost:{port}) */
|
|
24
|
+
url: string;
|
|
25
|
+
/** Close the server gracefully */
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Result from createOpencode()
|
|
30
|
+
* Client type comes from @opencode-ai/sdk (user's version)
|
|
31
|
+
*/
|
|
32
|
+
interface OpencodeResult<TClient = unknown> {
|
|
33
|
+
/** OpenCode SDK client with Sandbox transport */
|
|
34
|
+
client: TClient;
|
|
35
|
+
/** Server lifecycle management */
|
|
36
|
+
server: OpencodeServer;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Error thrown when OpenCode server fails to start
|
|
40
|
+
*/
|
|
41
|
+
declare class OpencodeStartupError extends Error {
|
|
42
|
+
readonly code: "OPENCODE_STARTUP_FAILED";
|
|
43
|
+
readonly context: OpencodeStartupContext;
|
|
44
|
+
constructor(message: string, context: OpencodeStartupContext, options?: ErrorOptions);
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/opencode/opencode.d.ts
|
|
48
|
+
/**
|
|
49
|
+
* Starts an OpenCode server inside a Sandbox container.
|
|
50
|
+
*
|
|
51
|
+
* This function manages the server lifecycle only - use `createOpencode()` if you
|
|
52
|
+
* also need a typed SDK client for programmatic access.
|
|
53
|
+
*
|
|
54
|
+
* If an OpenCode server is already running on the specified port, this function
|
|
55
|
+
* will reuse it instead of starting a new one.
|
|
56
|
+
*
|
|
57
|
+
* @param sandbox - The Sandbox instance to run OpenCode in
|
|
58
|
+
* @param options - Configuration options
|
|
59
|
+
* @returns Promise resolving to server handle { port, url, close() }
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { getSandbox } from '@cloudflare/sandbox'
|
|
64
|
+
* import { createOpencodeServer } from '@cloudflare/sandbox/opencode'
|
|
65
|
+
*
|
|
66
|
+
* const sandbox = getSandbox(env.Sandbox, 'my-agent')
|
|
67
|
+
* const server = await createOpencodeServer(sandbox, {
|
|
68
|
+
* directory: '/home/user/my-project',
|
|
69
|
+
* config: { provider: { anthropic: { options: { apiKey: env.ANTHROPIC_KEY } } } }
|
|
70
|
+
* })
|
|
71
|
+
*
|
|
72
|
+
* // Proxy requests to the web UI
|
|
73
|
+
* return sandbox.containerFetch(request, server.port)
|
|
74
|
+
*
|
|
75
|
+
* // When done
|
|
76
|
+
* await server.close()
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function createOpencodeServer(sandbox: Sandbox<unknown>, options?: OpencodeOptions): Promise<OpencodeServer>;
|
|
80
|
+
/**
|
|
81
|
+
* Creates an OpenCode server inside a Sandbox container and returns a typed SDK client.
|
|
82
|
+
*
|
|
83
|
+
* This function is API-compatible with OpenCode's own createOpencode(), but uses
|
|
84
|
+
* Sandbox process management instead of Node.js spawn. The returned client uses
|
|
85
|
+
* a custom fetch adapter to route requests through the Sandbox container.
|
|
86
|
+
*
|
|
87
|
+
* If an OpenCode server is already running on the specified port, this function
|
|
88
|
+
* will reuse it instead of starting a new one.
|
|
89
|
+
*
|
|
90
|
+
* @param sandbox - The Sandbox instance to run OpenCode in
|
|
91
|
+
* @param options - Configuration options
|
|
92
|
+
* @returns Promise resolving to { client, server }
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { getSandbox } from '@cloudflare/sandbox'
|
|
97
|
+
* import { createOpencode } from '@cloudflare/sandbox/opencode'
|
|
98
|
+
*
|
|
99
|
+
* const sandbox = getSandbox(env.Sandbox, 'my-agent')
|
|
100
|
+
* const { client, server } = await createOpencode(sandbox, {
|
|
101
|
+
* directory: '/home/user/my-project',
|
|
102
|
+
* config: { provider: { anthropic: { options: { apiKey: env.ANTHROPIC_KEY } } } }
|
|
103
|
+
* })
|
|
104
|
+
*
|
|
105
|
+
* // Use the SDK client for programmatic access
|
|
106
|
+
* const session = await client.session.create()
|
|
107
|
+
*
|
|
108
|
+
* // When done
|
|
109
|
+
* await server.close()
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare function createOpencode<TClient = unknown>(sandbox: Sandbox<unknown>, options?: OpencodeOptions): Promise<OpencodeResult<TClient>>;
|
|
113
|
+
/**
|
|
114
|
+
* Proxy a request to the OpenCode web UI.
|
|
115
|
+
*
|
|
116
|
+
* This function handles the redirect and proxying only - you must start the
|
|
117
|
+
* server separately using `createOpencodeServer()`.
|
|
118
|
+
*
|
|
119
|
+
* Specifically handles:
|
|
120
|
+
* 1. Ensuring the `?url=` parameter is set (required for OpenCode's frontend to
|
|
121
|
+
* make API calls through the proxy instead of directly to localhost:4096)
|
|
122
|
+
* 2. Proxying the request to the container
|
|
123
|
+
*
|
|
124
|
+
* @param request - The incoming HTTP request
|
|
125
|
+
* @param sandbox - The Sandbox instance running OpenCode
|
|
126
|
+
* @param server - The OpenCode server handle from createOpencodeServer()
|
|
127
|
+
* @returns Response from OpenCode or a redirect response
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* import { getSandbox } from '@cloudflare/sandbox'
|
|
132
|
+
* import { createOpencodeServer, proxyToOpencode } from '@cloudflare/sandbox/opencode'
|
|
133
|
+
*
|
|
134
|
+
* export default {
|
|
135
|
+
* async fetch(request: Request, env: Env) {
|
|
136
|
+
* const sandbox = getSandbox(env.Sandbox, 'opencode')
|
|
137
|
+
* const server = await createOpencodeServer(sandbox, {
|
|
138
|
+
* directory: '/home/user/project',
|
|
139
|
+
* config: { provider: { anthropic: { options: { apiKey: env.ANTHROPIC_KEY } } } }
|
|
140
|
+
* })
|
|
141
|
+
* return proxyToOpencode(request, sandbox, server)
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
declare function proxyToOpencode(request: Request, sandbox: Sandbox<unknown>, server: OpencodeServer): Response | Promise<Response>;
|
|
147
|
+
//#endregion
|
|
148
|
+
export { type OpencodeOptions, type OpencodeResult, type OpencodeServer, OpencodeStartupError, createOpencode, createOpencodeServer, proxyToOpencode };
|
|
149
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/opencode/types.ts","../../src/opencode/opencode.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAMiB,UAAA,eAAA,CAMN;EAMM;EAaA,IAAA,CAAA,EAAA,MAAA;EAUJ;EAEc,SAAA,CAAA,EAAA,MAAA;EAId;EACC,MAAA,CAAA,EApCH,MAoCG;;;;;UA9BG,cAAA;EC8OK;EACX,IAAA,EAAA,MAAA;EACC;EACD,GAAA,EAAA,MAAA;EAAR;EAAO,KAAA,EAAA,ED3OC,OC2OD,CAAA,IAAA,CAAA;AAgDV;;;;;AAGG,UDvRc,cCuRd,CAAA,UAAA,OAAA,CAAA,CAAA;EAAO;EAqDM,MAAA,ED1UN,OC0UM;EACL;EACA,MAAA,ED1UD,cC0UC;;;;;AAEU,cDtUR,oBAAA,SAA6B,KAAA,CCsUrB;;oBDpUM;wCAId,kCACC;;;;;;;AA1Cd;AAYA;AAaA;AAUA;;;;;;;;;ACuNA;;;;;;AAmDA;;;;;;;AAwDA;;;AAGU,iBA9GY,oBAAA,CA8GZ,OAAA,EA7GC,OA6GD,CAAA,OAAA,CAAA,EAAA,OAAA,CAAA,EA5GE,eA4GF,CAAA,EA3GP,OA2GO,CA3GC,cA2GD,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA3DY,2CACX,4BACC,kBACT,QAAQ,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqDV,eAAA,UACL,kBACA,0BACD,iBACP,WAAW,QAAQ"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { o as createLogger } from "../dist-2SF6oOaz.js";
|
|
2
|
+
import { t as ErrorCode } from "../errors-BHN41iBd.js";
|
|
3
|
+
|
|
4
|
+
//#region src/opencode/types.ts
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown when OpenCode server fails to start
|
|
7
|
+
*/
|
|
8
|
+
var OpencodeStartupError = class extends Error {
|
|
9
|
+
code = ErrorCode.OPENCODE_STARTUP_FAILED;
|
|
10
|
+
context;
|
|
11
|
+
constructor(message, context, options) {
|
|
12
|
+
super(message, options);
|
|
13
|
+
this.name = "OpencodeStartupError";
|
|
14
|
+
this.context = context;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/opencode/opencode.ts
|
|
20
|
+
function getLogger() {
|
|
21
|
+
return createLogger({
|
|
22
|
+
component: "sandbox-do",
|
|
23
|
+
operation: "opencode"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const DEFAULT_PORT = 4096;
|
|
27
|
+
const OPENCODE_SERVE = (port) => `opencode serve --port ${port} --hostname 0.0.0.0`;
|
|
28
|
+
/**
|
|
29
|
+
* Build the full command, optionally with a directory prefix.
|
|
30
|
+
* If directory is provided, we cd to it first so OpenCode uses it as cwd.
|
|
31
|
+
*/
|
|
32
|
+
function buildOpencodeCommand(port, directory) {
|
|
33
|
+
const serve = OPENCODE_SERVE(port);
|
|
34
|
+
return directory ? `cd ${directory} && ${serve}` : serve;
|
|
35
|
+
}
|
|
36
|
+
let createOpencodeClient;
|
|
37
|
+
async function ensureSdkLoaded() {
|
|
38
|
+
if (createOpencodeClient) return;
|
|
39
|
+
try {
|
|
40
|
+
createOpencodeClient = (await import("@opencode-ai/sdk")).createOpencodeClient;
|
|
41
|
+
} catch {
|
|
42
|
+
throw new Error("@opencode-ai/sdk is required for OpenCode integration. Install it with: npm install @opencode-ai/sdk");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Find an existing OpenCode server process running on the specified port.
|
|
47
|
+
* Returns the process if found and still active, null otherwise.
|
|
48
|
+
* Matches by the serve command pattern since directory prefix may vary.
|
|
49
|
+
*/
|
|
50
|
+
async function findExistingOpencodeProcess(sandbox, port) {
|
|
51
|
+
const processes = await sandbox.listProcesses();
|
|
52
|
+
const serveCommand = OPENCODE_SERVE(port);
|
|
53
|
+
for (const proc of processes) if (proc.command.includes(serveCommand)) {
|
|
54
|
+
if (proc.status === "starting" || proc.status === "running") return proc;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Ensures OpenCode server is running in the container.
|
|
60
|
+
* Reuses existing process if one is already running on the specified port.
|
|
61
|
+
* Handles concurrent startup attempts gracefully by retrying on failure.
|
|
62
|
+
* Returns the process handle.
|
|
63
|
+
*/
|
|
64
|
+
async function ensureOpencodeServer(sandbox, port, directory, config) {
|
|
65
|
+
const existingProcess = await findExistingOpencodeProcess(sandbox, port);
|
|
66
|
+
if (existingProcess) {
|
|
67
|
+
if (existingProcess.status === "starting") {
|
|
68
|
+
getLogger().debug("Found starting OpenCode process, waiting for ready", {
|
|
69
|
+
port,
|
|
70
|
+
processId: existingProcess.id
|
|
71
|
+
});
|
|
72
|
+
try {
|
|
73
|
+
await existingProcess.waitForPort(port, {
|
|
74
|
+
mode: "http",
|
|
75
|
+
path: "/",
|
|
76
|
+
timeout: 6e4
|
|
77
|
+
});
|
|
78
|
+
} catch (e) {
|
|
79
|
+
const logs = await existingProcess.getLogs();
|
|
80
|
+
throw new OpencodeStartupError(`OpenCode server failed to start. Stderr: ${logs.stderr || "(empty)"}`, {
|
|
81
|
+
port,
|
|
82
|
+
stderr: logs.stderr,
|
|
83
|
+
command: existingProcess.command
|
|
84
|
+
}, { cause: e });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
getLogger().debug("Reusing existing OpenCode process", {
|
|
88
|
+
port,
|
|
89
|
+
processId: existingProcess.id
|
|
90
|
+
});
|
|
91
|
+
return existingProcess;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
return await startOpencodeServer(sandbox, port, directory, config);
|
|
95
|
+
} catch (startupError) {
|
|
96
|
+
const retryProcess = await findExistingOpencodeProcess(sandbox, port);
|
|
97
|
+
if (retryProcess) {
|
|
98
|
+
getLogger().debug("Startup failed but found concurrent process, reusing", {
|
|
99
|
+
port,
|
|
100
|
+
processId: retryProcess.id
|
|
101
|
+
});
|
|
102
|
+
if (retryProcess.status === "starting") try {
|
|
103
|
+
await retryProcess.waitForPort(port, {
|
|
104
|
+
mode: "http",
|
|
105
|
+
path: "/",
|
|
106
|
+
timeout: 6e4
|
|
107
|
+
});
|
|
108
|
+
} catch (e) {
|
|
109
|
+
const logs = await retryProcess.getLogs();
|
|
110
|
+
throw new OpencodeStartupError(`OpenCode server failed to start. Stderr: ${logs.stderr || "(empty)"}`, {
|
|
111
|
+
port,
|
|
112
|
+
stderr: logs.stderr,
|
|
113
|
+
command: retryProcess.command
|
|
114
|
+
}, { cause: e });
|
|
115
|
+
}
|
|
116
|
+
return retryProcess;
|
|
117
|
+
}
|
|
118
|
+
throw startupError;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Internal function to start a new OpenCode server process.
|
|
123
|
+
*/
|
|
124
|
+
async function startOpencodeServer(sandbox, port, directory, config) {
|
|
125
|
+
getLogger().info("Starting OpenCode server", {
|
|
126
|
+
port,
|
|
127
|
+
directory
|
|
128
|
+
});
|
|
129
|
+
const env = {};
|
|
130
|
+
if (config) {
|
|
131
|
+
env.OPENCODE_CONFIG_CONTENT = JSON.stringify(config);
|
|
132
|
+
if (config.provider && typeof config.provider === "object" && !Array.isArray(config.provider)) for (const [providerId, providerConfig] of Object.entries(config.provider)) {
|
|
133
|
+
let apiKey = providerConfig?.options?.apiKey;
|
|
134
|
+
if (!apiKey) apiKey = providerConfig?.apiKey;
|
|
135
|
+
if (typeof apiKey === "string") {
|
|
136
|
+
const envVar = `${providerId.toUpperCase()}_API_KEY`;
|
|
137
|
+
env[envVar] = apiKey;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const command = buildOpencodeCommand(port, directory);
|
|
142
|
+
const process = await sandbox.startProcess(command, { env: Object.keys(env).length > 0 ? env : void 0 });
|
|
143
|
+
try {
|
|
144
|
+
await process.waitForPort(port, {
|
|
145
|
+
mode: "http",
|
|
146
|
+
path: "/",
|
|
147
|
+
timeout: 6e4
|
|
148
|
+
});
|
|
149
|
+
getLogger().info("OpenCode server started successfully", {
|
|
150
|
+
port,
|
|
151
|
+
processId: process.id
|
|
152
|
+
});
|
|
153
|
+
} catch (e) {
|
|
154
|
+
const logs = await process.getLogs();
|
|
155
|
+
const error = e instanceof Error ? e : void 0;
|
|
156
|
+
getLogger().error("OpenCode server failed to start", error, {
|
|
157
|
+
port,
|
|
158
|
+
stderr: logs.stderr
|
|
159
|
+
});
|
|
160
|
+
throw new OpencodeStartupError(`OpenCode server failed to start. Stderr: ${logs.stderr || "(empty)"}`, {
|
|
161
|
+
port,
|
|
162
|
+
stderr: logs.stderr,
|
|
163
|
+
command
|
|
164
|
+
}, { cause: e });
|
|
165
|
+
}
|
|
166
|
+
return process;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Starts an OpenCode server inside a Sandbox container.
|
|
170
|
+
*
|
|
171
|
+
* This function manages the server lifecycle only - use `createOpencode()` if you
|
|
172
|
+
* also need a typed SDK client for programmatic access.
|
|
173
|
+
*
|
|
174
|
+
* If an OpenCode server is already running on the specified port, this function
|
|
175
|
+
* will reuse it instead of starting a new one.
|
|
176
|
+
*
|
|
177
|
+
* @param sandbox - The Sandbox instance to run OpenCode in
|
|
178
|
+
* @param options - Configuration options
|
|
179
|
+
* @returns Promise resolving to server handle { port, url, close() }
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* import { getSandbox } from '@cloudflare/sandbox'
|
|
184
|
+
* import { createOpencodeServer } from '@cloudflare/sandbox/opencode'
|
|
185
|
+
*
|
|
186
|
+
* const sandbox = getSandbox(env.Sandbox, 'my-agent')
|
|
187
|
+
* const server = await createOpencodeServer(sandbox, {
|
|
188
|
+
* directory: '/home/user/my-project',
|
|
189
|
+
* config: { provider: { anthropic: { options: { apiKey: env.ANTHROPIC_KEY } } } }
|
|
190
|
+
* })
|
|
191
|
+
*
|
|
192
|
+
* // Proxy requests to the web UI
|
|
193
|
+
* return sandbox.containerFetch(request, server.port)
|
|
194
|
+
*
|
|
195
|
+
* // When done
|
|
196
|
+
* await server.close()
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
async function createOpencodeServer(sandbox, options) {
|
|
200
|
+
const port = options?.port ?? DEFAULT_PORT;
|
|
201
|
+
const process = await ensureOpencodeServer(sandbox, port, options?.directory, options?.config);
|
|
202
|
+
return {
|
|
203
|
+
port,
|
|
204
|
+
url: `http://localhost:${port}`,
|
|
205
|
+
close: () => process.kill("SIGTERM")
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Creates an OpenCode server inside a Sandbox container and returns a typed SDK client.
|
|
210
|
+
*
|
|
211
|
+
* This function is API-compatible with OpenCode's own createOpencode(), but uses
|
|
212
|
+
* Sandbox process management instead of Node.js spawn. The returned client uses
|
|
213
|
+
* a custom fetch adapter to route requests through the Sandbox container.
|
|
214
|
+
*
|
|
215
|
+
* If an OpenCode server is already running on the specified port, this function
|
|
216
|
+
* will reuse it instead of starting a new one.
|
|
217
|
+
*
|
|
218
|
+
* @param sandbox - The Sandbox instance to run OpenCode in
|
|
219
|
+
* @param options - Configuration options
|
|
220
|
+
* @returns Promise resolving to { client, server }
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* import { getSandbox } from '@cloudflare/sandbox'
|
|
225
|
+
* import { createOpencode } from '@cloudflare/sandbox/opencode'
|
|
226
|
+
*
|
|
227
|
+
* const sandbox = getSandbox(env.Sandbox, 'my-agent')
|
|
228
|
+
* const { client, server } = await createOpencode(sandbox, {
|
|
229
|
+
* directory: '/home/user/my-project',
|
|
230
|
+
* config: { provider: { anthropic: { options: { apiKey: env.ANTHROPIC_KEY } } } }
|
|
231
|
+
* })
|
|
232
|
+
*
|
|
233
|
+
* // Use the SDK client for programmatic access
|
|
234
|
+
* const session = await client.session.create()
|
|
235
|
+
*
|
|
236
|
+
* // When done
|
|
237
|
+
* await server.close()
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
async function createOpencode(sandbox, options) {
|
|
241
|
+
await ensureSdkLoaded();
|
|
242
|
+
const server = await createOpencodeServer(sandbox, options);
|
|
243
|
+
return {
|
|
244
|
+
client: createOpencodeClient({
|
|
245
|
+
baseUrl: server.url,
|
|
246
|
+
fetch: (request) => sandbox.containerFetch(request, server.port)
|
|
247
|
+
}),
|
|
248
|
+
server
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Proxy a request to the OpenCode web UI.
|
|
253
|
+
*
|
|
254
|
+
* This function handles the redirect and proxying only - you must start the
|
|
255
|
+
* server separately using `createOpencodeServer()`.
|
|
256
|
+
*
|
|
257
|
+
* Specifically handles:
|
|
258
|
+
* 1. Ensuring the `?url=` parameter is set (required for OpenCode's frontend to
|
|
259
|
+
* make API calls through the proxy instead of directly to localhost:4096)
|
|
260
|
+
* 2. Proxying the request to the container
|
|
261
|
+
*
|
|
262
|
+
* @param request - The incoming HTTP request
|
|
263
|
+
* @param sandbox - The Sandbox instance running OpenCode
|
|
264
|
+
* @param server - The OpenCode server handle from createOpencodeServer()
|
|
265
|
+
* @returns Response from OpenCode or a redirect response
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* import { getSandbox } from '@cloudflare/sandbox'
|
|
270
|
+
* import { createOpencodeServer, proxyToOpencode } from '@cloudflare/sandbox/opencode'
|
|
271
|
+
*
|
|
272
|
+
* export default {
|
|
273
|
+
* async fetch(request: Request, env: Env) {
|
|
274
|
+
* const sandbox = getSandbox(env.Sandbox, 'opencode')
|
|
275
|
+
* const server = await createOpencodeServer(sandbox, {
|
|
276
|
+
* directory: '/home/user/project',
|
|
277
|
+
* config: { provider: { anthropic: { options: { apiKey: env.ANTHROPIC_KEY } } } }
|
|
278
|
+
* })
|
|
279
|
+
* return proxyToOpencode(request, sandbox, server)
|
|
280
|
+
* }
|
|
281
|
+
* }
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
function proxyToOpencode(request, sandbox, server) {
|
|
285
|
+
const url = new URL(request.url);
|
|
286
|
+
if (!url.searchParams.has("url") && request.method === "GET") {
|
|
287
|
+
if ((request.headers.get("accept") || "").includes("text/html") || url.pathname === "/") {
|
|
288
|
+
url.searchParams.set("url", url.origin);
|
|
289
|
+
return Response.redirect(url.toString(), 302);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return sandbox.containerFetch(request, server.port);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
//#endregion
|
|
296
|
+
export { OpencodeStartupError, createOpencode, createOpencodeServer, proxyToOpencode };
|
|
297
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["createOpencodeClient: unknown","env: Record<string, string>"],"sources":["../../src/opencode/types.ts","../../src/opencode/opencode.ts"],"sourcesContent":["import type { Config } from '@opencode-ai/sdk';\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}\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 * Result from createOpencode()\n * Client type comes from @opencode-ai/sdk (user's version)\n */\nexport interface OpencodeResult<TClient = unknown> {\n /** OpenCode SDK client with Sandbox transport */\n client: TClient;\n /** Server lifecycle management */\n server: OpencodeServer;\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 type { Config } from '@opencode-ai/sdk';\nimport { createLogger, type Logger, type Process } from '@repo/shared';\nimport type { Sandbox } from '../sandbox';\nimport type { OpencodeOptions, OpencodeResult, 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\nconst DEFAULT_PORT = 4096;\nconst OPENCODE_SERVE = (port: number) =>\n `opencode serve --port ${port} --hostname 0.0.0.0`;\n\n/**\n * Build the full command, optionally with a directory prefix.\n * If directory is provided, we cd to it first so OpenCode uses it as cwd.\n */\nfunction buildOpencodeCommand(port: number, directory?: string): string {\n const serve = OPENCODE_SERVE(port);\n return directory ? `cd ${directory} && ${serve}` : serve;\n}\n\n// Dynamic import to handle peer dependency\n// Using unknown since SDK is optional peer dep - cast at usage site\nlet createOpencodeClient: unknown;\n\nasync function ensureSdkLoaded(): Promise<void> {\n if (createOpencodeClient) return;\n\n try {\n const sdk = await import('@opencode-ai/sdk');\n createOpencodeClient = sdk.createOpencodeClient;\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 * Find an existing OpenCode server process running on the specified port.\n * Returns the process if found and still active, null otherwise.\n * Matches by the serve command pattern since directory prefix may vary.\n */\nasync function findExistingOpencodeProcess(\n sandbox: Sandbox<unknown>,\n port: number\n): Promise<Process | null> {\n const processes = await sandbox.listProcesses();\n const serveCommand = OPENCODE_SERVE(port);\n\n for (const proc of processes) {\n // Match commands that contain the serve command (with or without cd prefix)\n if (proc.command.includes(serveCommand)) {\n if (proc.status === 'starting' || proc.status === 'running') {\n return proc;\n }\n }\n }\n\n return null;\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: Sandbox<unknown>,\n port: number,\n directory?: string,\n config?: Config\n): Promise<Process> {\n // Check if OpenCode is already running on this port\n const existingProcess = await findExistingOpencodeProcess(sandbox, port);\n if (existingProcess) {\n // Reuse existing process - wait for it to be ready if still starting\n if (existingProcess.status === 'starting') {\n getLogger().debug('Found starting OpenCode process, waiting for ready', {\n port,\n processId: existingProcess.id\n });\n try {\n await existingProcess.waitForPort(port, {\n mode: 'http',\n path: '/',\n timeout: 60_000\n });\n } catch (e) {\n const logs = await existingProcess.getLogs();\n throw new OpencodeStartupError(\n `OpenCode server failed to start. Stderr: ${logs.stderr || '(empty)'}`,\n { port, stderr: logs.stderr, command: existingProcess.command },\n { cause: e }\n );\n }\n }\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(sandbox, port, directory, config);\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(sandbox, port);\n if (retryProcess) {\n getLogger().debug(\n 'Startup failed but found concurrent process, reusing',\n {\n port,\n processId: retryProcess.id\n }\n );\n // Wait for the concurrent server to be ready\n if (retryProcess.status === 'starting') {\n try {\n await retryProcess.waitForPort(port, {\n mode: 'http',\n path: '/',\n timeout: 60_000\n });\n } catch (e) {\n const logs = await retryProcess.getLogs();\n throw new OpencodeStartupError(\n `OpenCode server failed to start. Stderr: ${logs.stderr || '(empty)'}`,\n { port, stderr: logs.stderr, command: retryProcess.command },\n { cause: e }\n );\n }\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: Sandbox<unknown>,\n port: number,\n directory?: string,\n config?: Config\n): Promise<Process> {\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 // 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 }\n\n const command = buildOpencodeCommand(port, directory);\n const process = await sandbox.startProcess(command, {\n env: Object.keys(env).length > 0 ? env : undefined\n });\n\n // Wait for server to be ready\n try {\n await process.waitForPort(port, {\n mode: 'http',\n path: '/',\n timeout: 60_000\n });\n getLogger().info('OpenCode server started successfully', {\n port,\n processId: process.id\n });\n } catch (e) {\n const logs = await process.getLogs();\n const error = e instanceof Error ? e : undefined;\n getLogger().error('OpenCode server failed to start', error, {\n port,\n stderr: logs.stderr\n });\n throw new OpencodeStartupError(\n `OpenCode server failed to start. Stderr: ${logs.stderr || '(empty)'}`,\n { port, stderr: logs.stderr, command },\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 `createOpencode()` 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: { provider: { anthropic: { options: { apiKey: env.ANTHROPIC_KEY } } } }\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: Sandbox<unknown>,\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 );\n\n return {\n port,\n url: `http://localhost:${port}`,\n close: () => process.kill('SIGTERM')\n };\n}\n\n/**\n * Creates an OpenCode server inside a Sandbox container and returns a typed SDK client.\n *\n * This function is API-compatible with OpenCode's own createOpencode(), but uses\n * Sandbox process management instead of Node.js spawn. The returned client uses\n * a custom fetch adapter to route requests through the Sandbox container.\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 { client, server }\n *\n * @example\n * ```typescript\n * import { getSandbox } from '@cloudflare/sandbox'\n * import { createOpencode } from '@cloudflare/sandbox/opencode'\n *\n * const sandbox = getSandbox(env.Sandbox, 'my-agent')\n * const { client, server } = await createOpencode(sandbox, {\n * directory: '/home/user/my-project',\n * config: { provider: { anthropic: { options: { apiKey: env.ANTHROPIC_KEY } } } }\n * })\n *\n * // Use the SDK client for programmatic access\n * const session = await client.session.create()\n *\n * // When done\n * await server.close()\n * ```\n */\nexport async function createOpencode<TClient = unknown>(\n sandbox: Sandbox<unknown>,\n options?: OpencodeOptions\n): Promise<OpencodeResult<TClient>> {\n await ensureSdkLoaded();\n\n const server = await createOpencodeServer(sandbox, options);\n\n // Create SDK client with Sandbox transport\n // Cast from unknown - SDK is optional peer dependency loaded dynamically\n const clientFactory = createOpencodeClient as (options: {\n baseUrl: string;\n fetch: (request: Request) => Promise<Response>;\n }) => TClient;\n\n const client = clientFactory({\n baseUrl: server.url,\n fetch: (request: Request) => sandbox.containerFetch(request, server.port)\n });\n\n return { client, server };\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: { provider: { anthropic: { options: { apiKey: env.ANTHROPIC_KEY } } } }\n * })\n * return proxyToOpencode(request, sandbox, server)\n * }\n * }\n * ```\n */\nexport function proxyToOpencode(\n request: Request,\n sandbox: Sandbox<unknown>,\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 sandbox.containerFetch(request, server.port);\n}\n"],"mappings":";;;;;;;AAyCA,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;;;;;;AC7CnB,SAAS,YAAoB;AAC3B,QAAO,aAAa;EAAE,WAAW;EAAc,WAAW;EAAY,CAAC;;AAGzE,MAAM,eAAe;AACrB,MAAM,kBAAkB,SACtB,yBAAyB,KAAK;;;;;AAMhC,SAAS,qBAAqB,MAAc,WAA4B;CACtE,MAAM,QAAQ,eAAe,KAAK;AAClC,QAAO,YAAY,MAAM,UAAU,MAAM,UAAU;;AAKrD,IAAIA;AAEJ,eAAe,kBAAiC;AAC9C,KAAI,qBAAsB;AAE1B,KAAI;AAEF,0BADY,MAAM,OAAO,qBACE;SACrB;AACN,QAAM,IAAI,MACR,uGAED;;;;;;;;AASL,eAAe,4BACb,SACA,MACyB;CACzB,MAAM,YAAY,MAAM,QAAQ,eAAe;CAC/C,MAAM,eAAe,eAAe,KAAK;AAEzC,MAAK,MAAM,QAAQ,UAEjB,KAAI,KAAK,QAAQ,SAAS,aAAa,EACrC;MAAI,KAAK,WAAW,cAAc,KAAK,WAAW,UAChD,QAAO;;AAKb,QAAO;;;;;;;;AAST,eAAe,qBACb,SACA,MACA,WACA,QACkB;CAElB,MAAM,kBAAkB,MAAM,4BAA4B,SAAS,KAAK;AACxE,KAAI,iBAAiB;AAEnB,MAAI,gBAAgB,WAAW,YAAY;AACzC,cAAW,CAAC,MAAM,sDAAsD;IACtE;IACA,WAAW,gBAAgB;IAC5B,CAAC;AACF,OAAI;AACF,UAAM,gBAAgB,YAAY,MAAM;KACtC,MAAM;KACN,MAAM;KACN,SAAS;KACV,CAAC;YACK,GAAG;IACV,MAAM,OAAO,MAAM,gBAAgB,SAAS;AAC5C,UAAM,IAAI,qBACR,4CAA4C,KAAK,UAAU,aAC3D;KAAE;KAAM,QAAQ,KAAK;KAAQ,SAAS,gBAAgB;KAAS,EAC/D,EAAE,OAAO,GAAG,CACb;;;AAGL,aAAW,CAAC,MAAM,qCAAqC;GACrD;GACA,WAAW,gBAAgB;GAC5B,CAAC;AACF,SAAO;;AAIT,KAAI;AACF,SAAO,MAAM,oBAAoB,SAAS,MAAM,WAAW,OAAO;UAC3D,cAAc;EAGrB,MAAM,eAAe,MAAM,4BAA4B,SAAS,KAAK;AACrE,MAAI,cAAc;AAChB,cAAW,CAAC,MACV,wDACA;IACE;IACA,WAAW,aAAa;IACzB,CACF;AAED,OAAI,aAAa,WAAW,WAC1B,KAAI;AACF,UAAM,aAAa,YAAY,MAAM;KACnC,MAAM;KACN,MAAM;KACN,SAAS;KACV,CAAC;YACK,GAAG;IACV,MAAM,OAAO,MAAM,aAAa,SAAS;AACzC,UAAM,IAAI,qBACR,4CAA4C,KAAK,UAAU,aAC3D;KAAE;KAAM,QAAQ,KAAK;KAAQ,SAAS,aAAa;KAAS,EAC5D,EAAE,OAAO,GAAG,CACb;;AAGL,UAAO;;AAIT,QAAM;;;;;;AAOV,eAAe,oBACb,SACA,MACA,WACA,QACkB;AAClB,YAAW,CAAC,KAAK,4BAA4B;EAAE;EAAM;EAAW,CAAC;CAIjE,MAAMC,MAA8B,EAAE;AAEtC,KAAI,QAAQ;AACV,MAAI,0BAA0B,KAAK,UAAU,OAAO;AAIpD,MACE,OAAO,YACP,OAAO,OAAO,aAAa,YAC3B,CAAC,MAAM,QAAQ,OAAO,SAAS,CAE/B,MAAK,MAAM,CAAC,YAAY,mBAAmB,OAAO,QAChD,OAAO,SACR,EAAE;GAED,IAAI,SAAS,gBAAgB,SAAS;AAEtC,OAAI,CAAC,OACH,UAAU,gBACN;AAEN,OAAI,OAAO,WAAW,UAAU;IAC9B,MAAM,SAAS,GAAG,WAAW,aAAa,CAAC;AAC3C,QAAI,UAAU;;;;CAMtB,MAAM,UAAU,qBAAqB,MAAM,UAAU;CACrD,MAAM,UAAU,MAAM,QAAQ,aAAa,SAAS,EAClD,KAAK,OAAO,KAAK,IAAI,CAAC,SAAS,IAAI,MAAM,QAC1C,CAAC;AAGF,KAAI;AACF,QAAM,QAAQ,YAAY,MAAM;GAC9B,MAAM;GACN,MAAM;GACN,SAAS;GACV,CAAC;AACF,aAAW,CAAC,KAAK,wCAAwC;GACvD;GACA,WAAW,QAAQ;GACpB,CAAC;UACK,GAAG;EACV,MAAM,OAAO,MAAM,QAAQ,SAAS;EACpC,MAAM,QAAQ,aAAa,QAAQ,IAAI;AACvC,aAAW,CAAC,MAAM,mCAAmC,OAAO;GAC1D;GACA,QAAQ,KAAK;GACd,CAAC;AACF,QAAM,IAAI,qBACR,4CAA4C,KAAK,UAAU,aAC3D;GAAE;GAAM,QAAQ,KAAK;GAAQ;GAAS,EACtC,EAAE,OAAO,GAAG,CACb;;AAGH,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCT,eAAsB,qBACpB,SACA,SACyB;CACzB,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,UAAU,MAAM,qBACpB,SACA,MACA,SAAS,WACT,SAAS,OACV;AAED,QAAO;EACL;EACA,KAAK,oBAAoB;EACzB,aAAa,QAAQ,KAAK,UAAU;EACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCH,eAAsB,eACpB,SACA,SACkC;AAClC,OAAM,iBAAiB;CAEvB,MAAM,SAAS,MAAM,qBAAqB,SAAS,QAAQ;AAc3D,QAAO;EAAE,QAVa,qBAKO;GAC3B,SAAS,OAAO;GAChB,QAAQ,YAAqB,QAAQ,eAAe,SAAS,OAAO,KAAK;GAC1E,CAAC;EAEe;EAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoC3B,SAAgB,gBACd,SACA,SACA,QAC8B;CAC9B,MAAM,MAAM,IAAI,IAAI,QAAQ,IAAI;AAOhC,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,IAAI,OAAO;AACvC,UAAO,SAAS,SAAS,IAAI,UAAU,EAAE,IAAI;;;AAIjD,QAAO,QAAQ,eAAe,SAAS,OAAO,KAAK"}
|
|
@@ -1772,7 +1772,7 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
|
|
|
1772
1772
|
streamProcessLogs(processId: string, options?: {
|
|
1773
1773
|
signal?: AbortSignal;
|
|
1774
1774
|
}): Promise<ReadableStream<Uint8Array>>;
|
|
1775
|
-
gitCheckout(repoUrl: string, options
|
|
1775
|
+
gitCheckout(repoUrl: string, options?: {
|
|
1776
1776
|
branch?: string;
|
|
1777
1777
|
targetDir?: string;
|
|
1778
1778
|
sessionId?: string;
|
|
@@ -1865,4 +1865,4 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
|
|
|
1865
1865
|
}
|
|
1866
1866
|
//#endregion
|
|
1867
1867
|
export { ProcessInfoResult as $, RequestConfig as A, FileChunk as B, WriteFileRequest as C, ContainerStub as D, BaseApiResponse as E, BucketProvider as F, ListFilesOptions as G, FileStreamEvent as H, ExecEvent as I, PortCloseResult as J, LogEvent as K, ExecOptions as L, SessionRequest as M, BaseExecOptions as N, ErrorResponse as O, BucketCredentials as P, ProcessCleanupResult as Q, ExecResult as R, ReadFileRequest as S, ExecuteResponse as T, GitCheckoutResult as U, FileMetadata as V, ISandbox as W, PortListResult as X, PortExposeResult as Y, Process as Z, GitCheckoutRequest as _, ExecutionResult as _t, CreateSessionRequest as a, ProcessStatus as at, FileOperationRequest as b, DeleteSessionResponse as c, StreamOptions as ct, ProcessClient as d, isExecResult as dt, ProcessKillResult as et, ExposePortRequest as f, isProcess as ft, InterpreterClient as g, Execution as gt, ExecutionCallbacks as h, CreateContextOptions as ht, CommandsResponse as i, ProcessStartResult as it, ResponseHandler as j, HttpClientOptions as k, PingResponse as l, WaitForLogResult as lt, UnexposePortRequest as m, CodeContext as mt, getSandbox as n, ProcessLogsResult as nt, CreateSessionResponse as o, SandboxOptions as ot, PortClient as p, isProcessStatus as pt, MountBucketOptions as q, SandboxClient as r, ProcessOptions as rt, DeleteSessionRequest as s, SessionOptions as st, Sandbox as t, ProcessListResult as tt, UtilityClient as u, WaitForPortOptions as ut, GitClient as v, RunCodeOptions as vt, CommandClient as w, MkdirRequest as x, FileClient as y, ExecutionSession as z };
|
|
1868
|
-
//# sourceMappingURL=sandbox-
|
|
1868
|
+
//# sourceMappingURL=sandbox-C9WRqWBO.d.ts.map
|