@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.
- package/README.md +62 -219
- package/dist/index.d.mts +548 -0
- package/dist/index.mjs +2452 -0
- package/package.json +17 -118
- package/Dockerfile +0 -327
- package/dist/bridge/index.d.ts +0 -181
- package/dist/bridge/index.d.ts.map +0 -1
- package/dist/bridge/index.js +0 -3053
- package/dist/bridge/index.js.map +0 -1
- package/dist/contexts-1EsLHByO.d.ts +0 -463
- package/dist/contexts-1EsLHByO.d.ts.map +0 -1
- package/dist/dist-Duor5GbS.js +0 -752
- package/dist/dist-Duor5GbS.js.map +0 -1
- package/dist/errors/index.d.ts +0 -4
- package/dist/errors/index.js +0 -4
- package/dist/errors-CXR0xBpw.js +0 -285
- package/dist/errors-CXR0xBpw.js.map +0 -1
- package/dist/errors-QYlSkVGz.js +0 -893
- package/dist/errors-QYlSkVGz.js.map +0 -1
- package/dist/extensions/index.d.ts +0 -4
- package/dist/extensions/index.js +0 -6
- package/dist/extensions-CFB2xHqY.js +0 -1023
- package/dist/extensions-CFB2xHqY.js.map +0 -1
- package/dist/filesystem-BWAZCZER.d.ts +0 -732
- package/dist/filesystem-BWAZCZER.d.ts.map +0 -1
- package/dist/git/index.d.ts +0 -63
- package/dist/git/index.d.ts.map +0 -1
- package/dist/git/index.js +0 -338
- package/dist/git/index.js.map +0 -1
- package/dist/index-Bs4bqXDR.d.ts +0 -438
- package/dist/index-Bs4bqXDR.d.ts.map +0 -1
- package/dist/index-HNYBk-az.d.ts +0 -444
- package/dist/index-HNYBk-az.d.ts.map +0 -1
- package/dist/index.d.ts +0 -576
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -33
- package/dist/index.js.map +0 -1
- package/dist/interpreter/index.d.ts +0 -311
- package/dist/interpreter/index.d.ts.map +0 -1
- package/dist/interpreter/index.js +0 -292
- package/dist/interpreter/index.js.map +0 -1
- package/dist/openai/index.d.ts +0 -68
- package/dist/openai/index.d.ts.map +0 -1
- package/dist/openai/index.js +0 -367
- package/dist/openai/index.js.map +0 -1
- package/dist/opencode/index.d.ts +0 -182
- package/dist/opencode/index.d.ts.map +0 -1
- package/dist/opencode/index.js +0 -454
- package/dist/opencode/index.js.map +0 -1
- package/dist/process-types-GStiZ8f8.d.ts +0 -73
- package/dist/process-types-GStiZ8f8.d.ts.map +0 -1
- package/dist/sandbox-BbAabq93.d.ts +0 -42
- package/dist/sandbox-BbAabq93.d.ts.map +0 -1
- package/dist/sandbox-cmlgGVYX.js +0 -10056
- package/dist/sandbox-cmlgGVYX.js.map +0 -1
- package/dist/sidecar/index.d.ts +0 -77
- package/dist/sidecar/index.d.ts.map +0 -1
- package/dist/sidecar/index.js +0 -201
- package/dist/sidecar/index.js.map +0 -1
- package/dist/xterm/index.d.ts +0 -93
- package/dist/xterm/index.d.ts.map +0 -1
- package/dist/xterm/index.js +0 -220
- package/dist/xterm/index.js.map +0 -1
package/dist/openai/index.js
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import "../errors-CXR0xBpw.js";
|
|
2
|
-
import { r as createLogger } from "../dist-Duor5GbS.js";
|
|
3
|
-
import { applyDiff } from "@openai/agents";
|
|
4
|
-
|
|
5
|
-
//#region src/openai/index.ts
|
|
6
|
-
/**
|
|
7
|
-
* OpenAI Agents adapters for executing shell commands and file operations
|
|
8
|
-
* inside a Cloudflare Sandbox.
|
|
9
|
-
*/
|
|
10
|
-
function isErrorWithProperties(error) {
|
|
11
|
-
return typeof error === "object" && error !== null;
|
|
12
|
-
}
|
|
13
|
-
function getErrorMessage(error) {
|
|
14
|
-
if (isErrorWithProperties(error) && typeof error.message === "string") return error.message;
|
|
15
|
-
return String(error);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Convert unknown values to Error instances when possible so downstream
|
|
19
|
-
* loggers can include stack traces without losing type safety.
|
|
20
|
-
*/
|
|
21
|
-
function toError(error) {
|
|
22
|
-
return error instanceof Error ? error : void 0;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Shell implementation that adapts Cloudflare Sandbox exec calls to the
|
|
26
|
-
* OpenAI Agents `Shell` contract, including structured result collection.
|
|
27
|
-
*/
|
|
28
|
-
var Shell = class {
|
|
29
|
-
cwd = "/workspace";
|
|
30
|
-
results = [];
|
|
31
|
-
logger;
|
|
32
|
-
constructor(sandbox) {
|
|
33
|
-
this.sandbox = sandbox;
|
|
34
|
-
this.logger = createLogger({
|
|
35
|
-
component: "sandbox-do",
|
|
36
|
-
operation: "openai-shell"
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
async run(action) {
|
|
40
|
-
this.logger.debug("SandboxShell.run called", {
|
|
41
|
-
commands: action.commands,
|
|
42
|
-
timeout: action.timeoutMs
|
|
43
|
-
});
|
|
44
|
-
const output = [];
|
|
45
|
-
for (const command of action.commands) {
|
|
46
|
-
this.logger.debug("Executing command", {
|
|
47
|
-
command,
|
|
48
|
-
cwd: this.cwd
|
|
49
|
-
});
|
|
50
|
-
let stdout = "";
|
|
51
|
-
let stderr = "";
|
|
52
|
-
let exitCode = 0;
|
|
53
|
-
let outcome = {
|
|
54
|
-
type: "exit",
|
|
55
|
-
exitCode: 0
|
|
56
|
-
};
|
|
57
|
-
try {
|
|
58
|
-
const out = await (await this.sandbox.exec([
|
|
59
|
-
"/bin/bash",
|
|
60
|
-
"-lc",
|
|
61
|
-
command
|
|
62
|
-
], {
|
|
63
|
-
timeout: action.timeoutMs,
|
|
64
|
-
cwd: this.cwd
|
|
65
|
-
})).output();
|
|
66
|
-
stdout = new TextDecoder().decode(out.stdout);
|
|
67
|
-
stderr = new TextDecoder().decode(out.stderr);
|
|
68
|
-
exitCode = out.exitCode;
|
|
69
|
-
outcome = {
|
|
70
|
-
type: "exit",
|
|
71
|
-
exitCode
|
|
72
|
-
};
|
|
73
|
-
this.logger.debug("Command executed successfully", {
|
|
74
|
-
command,
|
|
75
|
-
exitCode,
|
|
76
|
-
stdoutLength: stdout.length,
|
|
77
|
-
stderrLength: stderr.length
|
|
78
|
-
});
|
|
79
|
-
if (exitCode !== 0) this.logger.warn(`Command failed with exit code ${exitCode}`, {
|
|
80
|
-
command,
|
|
81
|
-
stderr
|
|
82
|
-
});
|
|
83
|
-
else if (stderr) this.logger.warn(`Command produced stderr output`, {
|
|
84
|
-
command,
|
|
85
|
-
stderr
|
|
86
|
-
});
|
|
87
|
-
else this.logger.info(`Command completed successfully`, { command });
|
|
88
|
-
} catch (error) {
|
|
89
|
-
const errorObj = isErrorWithProperties(error) ? error : {};
|
|
90
|
-
exitCode = typeof errorObj.exitCode === "number" ? errorObj.exitCode : null;
|
|
91
|
-
stdout = typeof errorObj.stdout === "string" ? errorObj.stdout : "";
|
|
92
|
-
stderr = typeof errorObj.stderr === "string" ? errorObj.stderr : "";
|
|
93
|
-
const errorMessage = getErrorMessage(error);
|
|
94
|
-
if (errorMessage.includes("timeout") || errorMessage.includes("Timeout") || errorMessage.includes("timed out")) {
|
|
95
|
-
this.logger.error(`Command timed out`, void 0, {
|
|
96
|
-
command,
|
|
97
|
-
timeout: action.timeoutMs
|
|
98
|
-
});
|
|
99
|
-
outcome = { type: "timeout" };
|
|
100
|
-
} else {
|
|
101
|
-
this.logger.error(`Error executing command`, toError(error), {
|
|
102
|
-
command,
|
|
103
|
-
error: errorMessage || error,
|
|
104
|
-
exitCode
|
|
105
|
-
});
|
|
106
|
-
outcome = {
|
|
107
|
-
type: "exit",
|
|
108
|
-
exitCode: exitCode ?? 1
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
output.push({
|
|
113
|
-
command,
|
|
114
|
-
stdout,
|
|
115
|
-
stderr,
|
|
116
|
-
outcome
|
|
117
|
-
});
|
|
118
|
-
const collectedExitCode = outcome.type === "exit" ? outcome.exitCode : null;
|
|
119
|
-
const timestamp = Date.now();
|
|
120
|
-
this.results.push({
|
|
121
|
-
command: String(command),
|
|
122
|
-
stdout: String(stdout),
|
|
123
|
-
stderr: String(stderr),
|
|
124
|
-
exitCode: collectedExitCode,
|
|
125
|
-
timestamp
|
|
126
|
-
});
|
|
127
|
-
this.logger.debug("Result collected", {
|
|
128
|
-
command,
|
|
129
|
-
exitCode: collectedExitCode,
|
|
130
|
-
timestamp
|
|
131
|
-
});
|
|
132
|
-
if (outcome.type === "timeout") {
|
|
133
|
-
this.logger.warn("Breaking command loop due to timeout");
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
this.logger.debug("SandboxShell.run completed", {
|
|
138
|
-
totalCommands: action.commands.length,
|
|
139
|
-
resultsCount: this.results.length
|
|
140
|
-
});
|
|
141
|
-
return {
|
|
142
|
-
output,
|
|
143
|
-
providerData: { working_directory: this.cwd }
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* Editor implementation that projects applyPatch operations from Agents
|
|
149
|
-
* into calls against the sandbox filesystem APIs.
|
|
150
|
-
*/
|
|
151
|
-
var Editor = class {
|
|
152
|
-
results = [];
|
|
153
|
-
logger;
|
|
154
|
-
constructor(sandbox, root = "/workspace") {
|
|
155
|
-
this.sandbox = sandbox;
|
|
156
|
-
this.root = root;
|
|
157
|
-
this.logger = createLogger({
|
|
158
|
-
component: "sandbox-do",
|
|
159
|
-
operation: "openai-editor"
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Create a new file inside the sandbox by applying the provided diff.
|
|
164
|
-
*/
|
|
165
|
-
async createFile(operation) {
|
|
166
|
-
const targetPath = this.resolve(operation.path);
|
|
167
|
-
this.logger.debug("WorkspaceEditor.createFile called", {
|
|
168
|
-
path: operation.path,
|
|
169
|
-
targetPath
|
|
170
|
-
});
|
|
171
|
-
try {
|
|
172
|
-
const dirPath = this.getDirname(targetPath);
|
|
173
|
-
if (dirPath !== this.root && dirPath !== "/") {
|
|
174
|
-
this.logger.debug("Creating parent directory", { dirPath });
|
|
175
|
-
await this.sandbox.mkdir(dirPath, { recursive: true });
|
|
176
|
-
}
|
|
177
|
-
const content = applyDiff("", operation.diff, "create");
|
|
178
|
-
this.logger.debug("Writing file content", {
|
|
179
|
-
path: targetPath,
|
|
180
|
-
contentLength: content.length
|
|
181
|
-
});
|
|
182
|
-
await this.sandbox.writeFile(targetPath, content, { encoding: "utf-8" });
|
|
183
|
-
const timestamp = Date.now();
|
|
184
|
-
const result = {
|
|
185
|
-
operation: "create",
|
|
186
|
-
path: operation.path,
|
|
187
|
-
status: "completed",
|
|
188
|
-
output: `Created ${operation.path}`,
|
|
189
|
-
timestamp
|
|
190
|
-
};
|
|
191
|
-
this.results.push(result);
|
|
192
|
-
this.logger.info("File created successfully", {
|
|
193
|
-
path: operation.path,
|
|
194
|
-
timestamp
|
|
195
|
-
});
|
|
196
|
-
return {
|
|
197
|
-
status: "completed",
|
|
198
|
-
output: `Created ${operation.path}`
|
|
199
|
-
};
|
|
200
|
-
} catch (error) {
|
|
201
|
-
const timestamp = Date.now();
|
|
202
|
-
const errorMessage = getErrorMessage(error);
|
|
203
|
-
const result = {
|
|
204
|
-
operation: "create",
|
|
205
|
-
path: operation.path,
|
|
206
|
-
status: "failed",
|
|
207
|
-
output: `Failed to create ${operation.path}`,
|
|
208
|
-
error: errorMessage,
|
|
209
|
-
timestamp
|
|
210
|
-
};
|
|
211
|
-
this.results.push(result);
|
|
212
|
-
this.logger.error("Failed to create file", toError(error), {
|
|
213
|
-
path: operation.path,
|
|
214
|
-
error: errorMessage
|
|
215
|
-
});
|
|
216
|
-
throw error;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Update an existing file by reading its content, applying a diff, and
|
|
221
|
-
* writing the patched output back to the sandbox.
|
|
222
|
-
*/
|
|
223
|
-
async updateFile(operation) {
|
|
224
|
-
const targetPath = this.resolve(operation.path);
|
|
225
|
-
this.logger.debug("WorkspaceEditor.updateFile called", {
|
|
226
|
-
path: operation.path,
|
|
227
|
-
targetPath
|
|
228
|
-
});
|
|
229
|
-
try {
|
|
230
|
-
let original;
|
|
231
|
-
try {
|
|
232
|
-
this.logger.debug("Reading original file", { path: targetPath });
|
|
233
|
-
original = (await this.sandbox.readFile(targetPath, { encoding: "utf-8" })).content;
|
|
234
|
-
this.logger.debug("Original file read", {
|
|
235
|
-
path: targetPath,
|
|
236
|
-
originalLength: original.length
|
|
237
|
-
});
|
|
238
|
-
} catch (error) {
|
|
239
|
-
const errorObj = isErrorWithProperties(error) ? error : {};
|
|
240
|
-
const errorMessage = getErrorMessage(error);
|
|
241
|
-
if (errorMessage.includes("not found") || errorMessage.includes("ENOENT") || errorObj.status === 404) {
|
|
242
|
-
this.logger.error("Cannot update missing file", void 0, { path: operation.path });
|
|
243
|
-
throw new Error(`Cannot update missing file: ${operation.path}`);
|
|
244
|
-
}
|
|
245
|
-
this.logger.error("Error reading file", toError(error), {
|
|
246
|
-
path: operation.path,
|
|
247
|
-
error: errorMessage
|
|
248
|
-
});
|
|
249
|
-
throw error;
|
|
250
|
-
}
|
|
251
|
-
const patched = applyDiff(original, operation.diff);
|
|
252
|
-
this.logger.debug("Applied diff", {
|
|
253
|
-
path: targetPath,
|
|
254
|
-
originalLength: original.length,
|
|
255
|
-
patchedLength: patched.length
|
|
256
|
-
});
|
|
257
|
-
await this.sandbox.writeFile(targetPath, patched, { encoding: "utf-8" });
|
|
258
|
-
const timestamp = Date.now();
|
|
259
|
-
const result = {
|
|
260
|
-
operation: "update",
|
|
261
|
-
path: operation.path,
|
|
262
|
-
status: "completed",
|
|
263
|
-
output: `Updated ${operation.path}`,
|
|
264
|
-
timestamp
|
|
265
|
-
};
|
|
266
|
-
this.results.push(result);
|
|
267
|
-
this.logger.info("File updated successfully", {
|
|
268
|
-
path: operation.path,
|
|
269
|
-
timestamp
|
|
270
|
-
});
|
|
271
|
-
return {
|
|
272
|
-
status: "completed",
|
|
273
|
-
output: `Updated ${operation.path}`
|
|
274
|
-
};
|
|
275
|
-
} catch (error) {
|
|
276
|
-
const timestamp = Date.now();
|
|
277
|
-
const errorMessage = getErrorMessage(error);
|
|
278
|
-
const result = {
|
|
279
|
-
operation: "update",
|
|
280
|
-
path: operation.path,
|
|
281
|
-
status: "failed",
|
|
282
|
-
output: `Failed to update ${operation.path}`,
|
|
283
|
-
error: errorMessage,
|
|
284
|
-
timestamp
|
|
285
|
-
};
|
|
286
|
-
this.results.push(result);
|
|
287
|
-
this.logger.error("Failed to update file", toError(error), {
|
|
288
|
-
path: operation.path,
|
|
289
|
-
error: errorMessage
|
|
290
|
-
});
|
|
291
|
-
throw error;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Delete a file that was previously created through applyPatch calls.
|
|
296
|
-
*/
|
|
297
|
-
async deleteFile(operation) {
|
|
298
|
-
const targetPath = this.resolve(operation.path);
|
|
299
|
-
this.logger.debug("WorkspaceEditor.deleteFile called", {
|
|
300
|
-
path: operation.path,
|
|
301
|
-
targetPath
|
|
302
|
-
});
|
|
303
|
-
try {
|
|
304
|
-
await this.sandbox.deleteFile(targetPath);
|
|
305
|
-
const timestamp = Date.now();
|
|
306
|
-
const result = {
|
|
307
|
-
operation: "delete",
|
|
308
|
-
path: operation.path,
|
|
309
|
-
status: "completed",
|
|
310
|
-
output: `Deleted ${operation.path}`,
|
|
311
|
-
timestamp
|
|
312
|
-
};
|
|
313
|
-
this.results.push(result);
|
|
314
|
-
this.logger.info("File deleted successfully", {
|
|
315
|
-
path: operation.path,
|
|
316
|
-
timestamp
|
|
317
|
-
});
|
|
318
|
-
return {
|
|
319
|
-
status: "completed",
|
|
320
|
-
output: `Deleted ${operation.path}`
|
|
321
|
-
};
|
|
322
|
-
} catch (error) {
|
|
323
|
-
const timestamp = Date.now();
|
|
324
|
-
const errorMessage = getErrorMessage(error);
|
|
325
|
-
const result = {
|
|
326
|
-
operation: "delete",
|
|
327
|
-
path: operation.path,
|
|
328
|
-
status: "failed",
|
|
329
|
-
output: `Failed to delete ${operation.path}`,
|
|
330
|
-
error: errorMessage,
|
|
331
|
-
timestamp
|
|
332
|
-
};
|
|
333
|
-
this.results.push(result);
|
|
334
|
-
this.logger.error("Failed to delete file", toError(error), {
|
|
335
|
-
path: operation.path,
|
|
336
|
-
error: errorMessage
|
|
337
|
-
});
|
|
338
|
-
throw error;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
resolve(relativePath) {
|
|
342
|
-
let pathToProcess = relativePath;
|
|
343
|
-
if (relativePath.startsWith(this.root)) {
|
|
344
|
-
pathToProcess = relativePath.slice(this.root.length);
|
|
345
|
-
pathToProcess = pathToProcess.replace(/^\//, "");
|
|
346
|
-
}
|
|
347
|
-
const normalized = pathToProcess.replace(/^\.\//, "").replace(/^\//, "");
|
|
348
|
-
const segments = (normalized ? `${this.root}/${normalized}` : this.root).replace(/\/+/g, "/").split("/").filter((s) => s && s !== ".");
|
|
349
|
-
const stack = [];
|
|
350
|
-
for (const segment of segments) if (segment === "..") {
|
|
351
|
-
if (stack.length === 0) throw new Error(`Operation outside workspace: ${relativePath}`);
|
|
352
|
-
stack.pop();
|
|
353
|
-
} else stack.push(segment);
|
|
354
|
-
const normalizedPath = `/${stack.join("/")}`;
|
|
355
|
-
if (!normalizedPath.startsWith(this.root)) throw new Error(`Operation outside workspace: ${relativePath}`);
|
|
356
|
-
return normalizedPath;
|
|
357
|
-
}
|
|
358
|
-
getDirname(filePath) {
|
|
359
|
-
const lastSlash = filePath.lastIndexOf("/");
|
|
360
|
-
if (lastSlash === -1) return "/";
|
|
361
|
-
return filePath.substring(0, lastSlash) || "/";
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
//#endregion
|
|
366
|
-
export { Editor, Shell };
|
|
367
|
-
//# sourceMappingURL=index.js.map
|
package/dist/openai/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["sandbox: ISandbox","output: ShellResult['output']","exitCode: number | null","outcome: ShellOutputResult['outcome']","error: unknown","root: string","result: FileOperationResult","original: string","stack: string[]"],"sources":["../../src/openai/index.ts"],"sourcesContent":["/**\n * OpenAI Agents adapters for executing shell commands and file operations\n * inside a Cloudflare Sandbox.\n */\nimport {\n type ApplyPatchOperation,\n type ApplyPatchResult,\n applyDiff,\n type Editor as OpenAIEeditor,\n type Shell as OpenAIShell,\n type ShellAction,\n type ShellOutputResult,\n type ShellResult\n} from '@openai/agents';\n\n// Command result for API responses\nexport interface CommandResult {\n command: string;\n stdout: string;\n stderr: string;\n exitCode: number | null;\n timestamp: number;\n}\n\n// File operation result for API responses\nexport interface FileOperationResult {\n operation: 'create' | 'update' | 'delete';\n path: string;\n status: 'completed' | 'failed';\n output: string;\n error?: string;\n timestamp: number;\n}\n\nimport { createLogger, type ISandbox, type Logger } from '@repo/shared';\n\n// Helper functions for error handling\nfunction isErrorWithProperties(error: unknown): error is {\n message?: string;\n exitCode?: number;\n stdout?: string;\n stderr?: string;\n status?: number;\n stack?: string;\n} {\n return typeof error === 'object' && error !== null;\n}\n\nfunction getErrorMessage(error: unknown): string {\n if (isErrorWithProperties(error) && typeof error.message === 'string') {\n return error.message;\n }\n return String(error);\n}\n\n/**\n * Convert unknown values to Error instances when possible so downstream\n * loggers can include stack traces without losing type safety.\n */\nfunction toError(error: unknown): Error | undefined {\n return error instanceof Error ? error : undefined;\n}\n\n/**\n * Shell implementation that adapts Cloudflare Sandbox exec calls to the\n * OpenAI Agents `Shell` contract, including structured result collection.\n */\nexport class Shell implements OpenAIShell {\n private cwd: string = '/workspace';\n public results: CommandResult[] = [];\n private readonly logger: Logger;\n\n constructor(private readonly sandbox: ISandbox) {\n this.logger = createLogger({\n component: 'sandbox-do',\n operation: 'openai-shell'\n });\n }\n\n async run(action: ShellAction): Promise<ShellResult> {\n this.logger.debug('SandboxShell.run called', {\n commands: action.commands,\n timeout: action.timeoutMs\n });\n const output: ShellResult['output'] = [];\n\n for (const command of action.commands) {\n this.logger.debug('Executing command', { command, cwd: this.cwd });\n let stdout = '';\n let stderr = '';\n let exitCode: number | null = 0;\n let outcome: ShellOutputResult['outcome'] = {\n type: 'exit',\n exitCode: 0\n };\n try {\n const proc = await this.sandbox.exec(['/bin/bash', '-lc', command], {\n timeout: action.timeoutMs,\n cwd: this.cwd\n });\n const out = await proc.output();\n stdout = new TextDecoder().decode(out.stdout);\n stderr = new TextDecoder().decode(out.stderr);\n exitCode = out.exitCode;\n // Timeout would be indicated by a specific error or exit code\n outcome = { type: 'exit', exitCode };\n\n this.logger.debug('Command executed successfully', {\n command,\n exitCode,\n stdoutLength: stdout.length,\n stderrLength: stderr.length\n });\n\n // Log warnings for non-zero exit codes or stderr output\n if (exitCode !== 0) {\n this.logger.warn(`Command failed with exit code ${exitCode}`, {\n command,\n stderr\n });\n } else if (stderr) {\n this.logger.warn(`Command produced stderr output`, {\n command,\n stderr\n });\n } else {\n this.logger.info(`Command completed successfully`, { command });\n }\n } catch (error: unknown) {\n // Handle network/HTTP errors or timeout errors\n const errorObj = isErrorWithProperties(error) ? error : {};\n exitCode =\n typeof errorObj.exitCode === 'number' ? errorObj.exitCode : null;\n stdout = typeof errorObj.stdout === 'string' ? errorObj.stdout : '';\n stderr = typeof errorObj.stderr === 'string' ? errorObj.stderr : '';\n\n // Check if it's a timeout error\n const errorMessage = getErrorMessage(error);\n if (\n errorMessage.includes('timeout') ||\n errorMessage.includes('Timeout') ||\n errorMessage.includes('timed out')\n ) {\n this.logger.error(`Command timed out`, undefined, {\n command,\n timeout: action.timeoutMs\n });\n outcome = { type: 'timeout' };\n } else {\n this.logger.error(`Error executing command`, toError(error), {\n command,\n error: errorMessage || error,\n exitCode\n });\n outcome = { type: 'exit', exitCode: exitCode ?? 1 };\n }\n }\n output.push({\n command,\n stdout,\n stderr,\n outcome\n });\n\n // Collect results for API responses\n const collectedExitCode =\n outcome.type === 'exit' ? outcome.exitCode : null;\n const timestamp = Date.now();\n this.results.push({\n command: String(command),\n stdout: String(stdout),\n stderr: String(stderr),\n exitCode: collectedExitCode,\n timestamp\n });\n this.logger.debug('Result collected', {\n command,\n exitCode: collectedExitCode,\n timestamp\n });\n\n if (outcome.type === 'timeout') {\n this.logger.warn('Breaking command loop due to timeout');\n break;\n }\n }\n\n this.logger.debug('SandboxShell.run completed', {\n totalCommands: action.commands.length,\n resultsCount: this.results.length\n });\n return {\n output,\n providerData: {\n working_directory: this.cwd\n }\n };\n }\n}\n\n/**\n * Editor implementation that projects applyPatch operations from Agents\n * into calls against the sandbox filesystem APIs.\n */\nexport class Editor implements OpenAIEeditor {\n public results: FileOperationResult[] = [];\n private readonly logger: Logger;\n\n constructor(\n private readonly sandbox: ISandbox,\n private readonly root: string = '/workspace'\n ) {\n this.logger = createLogger({\n component: 'sandbox-do',\n operation: 'openai-editor'\n });\n }\n\n /**\n * Create a new file inside the sandbox by applying the provided diff.\n */\n async createFile(\n operation: Extract<ApplyPatchOperation, { type: 'create_file' }>\n ): Promise<ApplyPatchResult | undefined> {\n const targetPath = this.resolve(operation.path);\n this.logger.debug('WorkspaceEditor.createFile called', {\n path: operation.path,\n targetPath\n });\n\n try {\n // Create parent directory if needed\n const dirPath = this.getDirname(targetPath);\n if (dirPath !== this.root && dirPath !== '/') {\n this.logger.debug('Creating parent directory', { dirPath });\n await this.sandbox.mkdir(dirPath, { recursive: true });\n }\n\n const content = applyDiff('', operation.diff, 'create');\n this.logger.debug('Writing file content', {\n path: targetPath,\n contentLength: content.length\n });\n await this.sandbox.writeFile(targetPath, content, { encoding: 'utf-8' });\n const timestamp = Date.now();\n const result: FileOperationResult = {\n operation: 'create',\n path: operation.path,\n status: 'completed',\n output: `Created ${operation.path}`,\n timestamp\n };\n this.results.push(result);\n this.logger.info('File created successfully', {\n path: operation.path,\n timestamp\n });\n return { status: 'completed', output: `Created ${operation.path}` };\n } catch (error: unknown) {\n const timestamp = Date.now();\n const errorMessage = getErrorMessage(error);\n const result: FileOperationResult = {\n operation: 'create',\n path: operation.path,\n status: 'failed',\n output: `Failed to create ${operation.path}`,\n error: errorMessage,\n timestamp\n };\n this.results.push(result);\n this.logger.error('Failed to create file', toError(error), {\n path: operation.path,\n error: errorMessage\n });\n throw error;\n }\n }\n\n /**\n * Update an existing file by reading its content, applying a diff, and\n * writing the patched output back to the sandbox.\n */\n async updateFile(\n operation: Extract<ApplyPatchOperation, { type: 'update_file' }>\n ): Promise<ApplyPatchResult | undefined> {\n const targetPath = this.resolve(operation.path);\n this.logger.debug('WorkspaceEditor.updateFile called', {\n path: operation.path,\n targetPath\n });\n\n try {\n let original: string;\n try {\n this.logger.debug('Reading original file', { path: targetPath });\n const fileInfo = await this.sandbox.readFile(targetPath, {\n encoding: 'utf-8'\n });\n original = fileInfo.content;\n this.logger.debug('Original file read', {\n path: targetPath,\n originalLength: original.length\n });\n } catch (error: unknown) {\n // Sandbox API may throw errors for missing files\n const errorObj = isErrorWithProperties(error) ? error : {};\n const errorMessage = getErrorMessage(error);\n if (\n errorMessage.includes('not found') ||\n errorMessage.includes('ENOENT') ||\n errorObj.status === 404\n ) {\n this.logger.error('Cannot update missing file', undefined, {\n path: operation.path\n });\n throw new Error(`Cannot update missing file: ${operation.path}`);\n }\n this.logger.error('Error reading file', toError(error), {\n path: operation.path,\n error: errorMessage\n });\n throw error;\n }\n\n const patched = applyDiff(original, operation.diff);\n this.logger.debug('Applied diff', {\n path: targetPath,\n originalLength: original.length,\n patchedLength: patched.length\n });\n await this.sandbox.writeFile(targetPath, patched, { encoding: 'utf-8' });\n const timestamp = Date.now();\n const result: FileOperationResult = {\n operation: 'update',\n path: operation.path,\n status: 'completed',\n output: `Updated ${operation.path}`,\n timestamp\n };\n this.results.push(result);\n this.logger.info('File updated successfully', {\n path: operation.path,\n timestamp\n });\n return { status: 'completed', output: `Updated ${operation.path}` };\n } catch (error: unknown) {\n const timestamp = Date.now();\n const errorMessage = getErrorMessage(error);\n const result: FileOperationResult = {\n operation: 'update',\n path: operation.path,\n status: 'failed',\n output: `Failed to update ${operation.path}`,\n error: errorMessage,\n timestamp\n };\n this.results.push(result);\n this.logger.error('Failed to update file', toError(error), {\n path: operation.path,\n error: errorMessage\n });\n throw error;\n }\n }\n\n /**\n * Delete a file that was previously created through applyPatch calls.\n */\n async deleteFile(\n operation: Extract<ApplyPatchOperation, { type: 'delete_file' }>\n ): Promise<ApplyPatchResult | undefined> {\n const targetPath = this.resolve(operation.path);\n this.logger.debug('WorkspaceEditor.deleteFile called', {\n path: operation.path,\n targetPath\n });\n\n try {\n await this.sandbox.deleteFile(targetPath);\n const timestamp = Date.now();\n const result: FileOperationResult = {\n operation: 'delete',\n path: operation.path,\n status: 'completed',\n output: `Deleted ${operation.path}`,\n timestamp\n };\n this.results.push(result);\n this.logger.info('File deleted successfully', {\n path: operation.path,\n timestamp\n });\n return { status: 'completed', output: `Deleted ${operation.path}` };\n } catch (error: unknown) {\n const timestamp = Date.now();\n const errorMessage = getErrorMessage(error);\n const result: FileOperationResult = {\n operation: 'delete',\n path: operation.path,\n status: 'failed',\n output: `Failed to delete ${operation.path}`,\n error: errorMessage,\n timestamp\n };\n this.results.push(result);\n this.logger.error('Failed to delete file', toError(error), {\n path: operation.path,\n error: errorMessage\n });\n throw error;\n }\n }\n\n private resolve(relativePath: string): string {\n // If the path already starts with the root, strip it to get the relative part\n let pathToProcess = relativePath;\n if (relativePath.startsWith(this.root)) {\n pathToProcess = relativePath.slice(this.root.length);\n // Remove leading slash if present after stripping root\n pathToProcess = pathToProcess.replace(/^\\//, '');\n }\n\n // Remove leading ./ or / if present, then join with root\n const normalized = pathToProcess.replace(/^\\.\\//, '').replace(/^\\//, '');\n const resolved = normalized ? `${this.root}/${normalized}` : this.root;\n\n // Normalize path separators first\n const pathWithNormalizedSeparators = resolved.replace(/\\/+/g, '/');\n\n // Normalize .. segments by processing path segments\n const segments = pathWithNormalizedSeparators\n .split('/')\n .filter((s) => s && s !== '.');\n const stack: string[] = [];\n\n for (const segment of segments) {\n if (segment === '..') {\n if (stack.length === 0) {\n throw new Error(`Operation outside workspace: ${relativePath}`);\n }\n stack.pop();\n } else {\n stack.push(segment);\n }\n }\n\n const normalizedPath = `/${stack.join('/')}`;\n\n // Ensure the resolved path is within the workspace\n if (!normalizedPath.startsWith(this.root)) {\n throw new Error(`Operation outside workspace: ${relativePath}`);\n }\n\n return normalizedPath;\n }\n\n private getDirname(filePath: string): string {\n const lastSlash = filePath.lastIndexOf('/');\n if (lastSlash === -1) {\n return '/';\n }\n return filePath.substring(0, lastSlash) || '/';\n }\n}\n"],"mappings":";;;;;;;;;AAqCA,SAAS,sBAAsB,OAO7B;AACA,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,gBAAgB,OAAwB;AAC/C,KAAI,sBAAsB,MAAM,IAAI,OAAO,MAAM,YAAY,SAC3D,QAAO,MAAM;AAEf,QAAO,OAAO,MAAM;;;;;;AAOtB,SAAS,QAAQ,OAAmC;AAClD,QAAO,iBAAiB,QAAQ,QAAQ;;;;;;AAO1C,IAAa,QAAb,MAA0C;CACxC,AAAQ,MAAc;CACtB,AAAO,UAA2B,EAAE;CACpC,AAAiB;CAEjB,YAAY,AAAiBA,SAAmB;EAAnB;AAC3B,OAAK,SAAS,aAAa;GACzB,WAAW;GACX,WAAW;GACZ,CAAC;;CAGJ,MAAM,IAAI,QAA2C;AACnD,OAAK,OAAO,MAAM,2BAA2B;GAC3C,UAAU,OAAO;GACjB,SAAS,OAAO;GACjB,CAAC;EACF,MAAMC,SAAgC,EAAE;AAExC,OAAK,MAAM,WAAW,OAAO,UAAU;AACrC,QAAK,OAAO,MAAM,qBAAqB;IAAE;IAAS,KAAK,KAAK;IAAK,CAAC;GAClE,IAAI,SAAS;GACb,IAAI,SAAS;GACb,IAAIC,WAA0B;GAC9B,IAAIC,UAAwC;IAC1C,MAAM;IACN,UAAU;IACX;AACD,OAAI;IAKF,MAAM,MAAM,OAJC,MAAM,KAAK,QAAQ,KAAK;KAAC;KAAa;KAAO;KAAQ,EAAE;KAClE,SAAS,OAAO;KAChB,KAAK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O,SAAS,UAAU,GAAG,UAAU,IAAI"}
|
package/dist/opencode/index.d.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { D as OpenCodeStartupContext } from "../contexts-1EsLHByO.js";
|
|
2
|
-
import "../process-types-GStiZ8f8.js";
|
|
3
|
-
import "../filesystem-BWAZCZER.js";
|
|
4
|
-
import { c as SandboxExtension, l as SandboxLike } from "../index-Bs4bqXDR.js";
|
|
5
|
-
import { OpencodeClient } from "@opencode-ai/sdk/v2/client";
|
|
6
|
-
import { Config } from "@opencode-ai/sdk/v2";
|
|
7
|
-
|
|
8
|
-
//#region ../../extensions/opencode/src/types.d.ts
|
|
9
|
-
/**
|
|
10
|
-
* Configuration options for starting OpenCode server
|
|
11
|
-
*/
|
|
12
|
-
interface OpenCodeOptions {
|
|
13
|
-
/** Port for OpenCode server (default: 4096) */
|
|
14
|
-
port?: number;
|
|
15
|
-
/** Working directory for OpenCode (default: container's cwd) */
|
|
16
|
-
directory?: string;
|
|
17
|
-
/** OpenCode configuration */
|
|
18
|
-
config?: Config;
|
|
19
|
-
/** Additional environment variables to pass to the OpenCode process */
|
|
20
|
-
env?: Record<string, string>;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Server lifecycle management
|
|
24
|
-
*/
|
|
25
|
-
interface OpenCodeServer {
|
|
26
|
-
/** Port the server is running on */
|
|
27
|
-
port: number;
|
|
28
|
-
/** Base URL for SDK client (http://localhost:{port}) */
|
|
29
|
-
url: string;
|
|
30
|
-
/** Close the server gracefully */
|
|
31
|
-
close(): Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Error thrown when OpenCode server fails to start
|
|
35
|
-
*/
|
|
36
|
-
declare class OpenCodeStartupError extends Error {
|
|
37
|
-
readonly code: "OPENCODE_STARTUP_FAILED";
|
|
38
|
-
readonly context: OpenCodeStartupContext;
|
|
39
|
-
constructor(message: string, context: OpenCodeStartupContext, options?: ErrorOptions);
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region ../../extensions/opencode/src/opencode.d.ts
|
|
43
|
-
interface OpenCodeSandboxLike extends SandboxLike {
|
|
44
|
-
exec: NonNullable<SandboxLike['exec']>;
|
|
45
|
-
getProcess: NonNullable<SandboxLike['getProcess']>;
|
|
46
|
-
listProcesses: NonNullable<SandboxLike['listProcesses']>;
|
|
47
|
-
containerFetch(request: Request, port: number): Promise<Response>;
|
|
48
|
-
}
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region ../../extensions/opencode/src/lifecycle.d.ts
|
|
51
|
-
/** Resolved server metadata that is safe to return across the RPC boundary. */
|
|
52
|
-
interface OpenCodeServerInfo {
|
|
53
|
-
port: number;
|
|
54
|
-
url: string;
|
|
55
|
-
}
|
|
56
|
-
/** Snapshot of the resolved lifecycle configuration. */
|
|
57
|
-
interface OpenCodeConfig {
|
|
58
|
-
port: number;
|
|
59
|
-
directory?: string;
|
|
60
|
-
}
|
|
61
|
-
/** Current server status as observed in the container. */
|
|
62
|
-
interface OpenCodeStatus extends OpenCodeServerInfo {
|
|
63
|
-
running: boolean;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* The slice of `DurableObjectStorage` the handle uses to persist desired-state.
|
|
67
|
-
* Pass `this.ctx.storage` so the server config survives a Durable Object
|
|
68
|
-
* eviction (cold start) and is recovered lazily on the next `start()`.
|
|
69
|
-
*/
|
|
70
|
-
interface OpenCodeStateStorage {
|
|
71
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
72
|
-
put<T>(key: string, value: T): Promise<void>;
|
|
73
|
-
}
|
|
74
|
-
/** Options for {@link withOpenCode}: server defaults plus optional storage. */
|
|
75
|
-
interface WithOpenCodeOptions extends OpenCodeOptions {
|
|
76
|
-
/** Persist desired-state here so it survives DO eviction. */
|
|
77
|
-
storage?: OpenCodeStateStorage;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* DO-resident lifecycle handle for an OpenCode server. Owns the durable
|
|
81
|
-
* `opencode serve` process: start/reuse, stop, status, and request proxying.
|
|
82
|
-
*
|
|
83
|
-
* It extends {@link SandboxExtension}, so the DO stub exposes it as
|
|
84
|
-
* `sandbox.opencode` and method calls dispatch through `callExtension` — the
|
|
85
|
-
* same path the interpreter extension uses. `createOpenCodeClient` consumes the
|
|
86
|
-
* same handle from either the Worker stub or the in-DO object.
|
|
87
|
-
*
|
|
88
|
-
* The server starts lazily: nothing runs until `start()` (or `fetch()`, which
|
|
89
|
-
* calls it) is invoked. To start optimistically, call `opencode.start()` from
|
|
90
|
-
* your Sandbox subclass's `onStart`.
|
|
91
|
-
*/
|
|
92
|
-
declare class OpenCodeHandle extends SandboxExtension {
|
|
93
|
-
#private;
|
|
94
|
-
constructor(sandbox: OpenCodeSandboxLike, defaults?: OpenCodeOptions, storage?: OpenCodeStateStorage, stateIndex?: number);
|
|
95
|
-
/**
|
|
96
|
-
* Start or reuse the OpenCode server, returning RPC-safe metadata. With no
|
|
97
|
-
* options it reuses the last-used config, recovering persisted desired-state
|
|
98
|
-
* after a cold start. Retries once on a transient `CONTAINER_UNAVAILABLE`
|
|
99
|
-
* (e.g. a rollout in flight).
|
|
100
|
-
*/
|
|
101
|
-
start(options?: OpenCodeOptions): Promise<OpenCodeServerInfo>;
|
|
102
|
-
/** Stop the running server, if one was started through this handle. */
|
|
103
|
-
stop(): Promise<void>;
|
|
104
|
-
/** Report whether the named OpenCode server is currently running. */
|
|
105
|
-
status(): Promise<OpenCodeStatus>;
|
|
106
|
-
/** Snapshot of the resolved configuration the client builder reads. */
|
|
107
|
-
config(): Promise<OpenCodeConfig>;
|
|
108
|
-
/**
|
|
109
|
-
* Start the server then route a request into the container. This is the
|
|
110
|
-
* transport the SDK client's `fetch` adapter and the Worker proxy use, so it
|
|
111
|
-
* works identically from the Worker stub (one RPC hop) or in-DO (local).
|
|
112
|
-
*/
|
|
113
|
-
fetch(request: Request): Promise<Response>;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Factory — attach as a field on a Sandbox subclass:
|
|
117
|
-
* `opencode = withOpenCode(this, { directory, config, storage: this.ctx.storage })`.
|
|
118
|
-
*
|
|
119
|
-
* Pass `storage` to persist desired-state so the server is recovered after a DO
|
|
120
|
-
* eviction (cold start). The server starts lazily on first use.
|
|
121
|
-
*/
|
|
122
|
-
declare function withOpenCode(sandbox: OpenCodeSandboxLike, options?: WithOpenCodeOptions): OpenCodeHandle;
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region ../../extensions/opencode/src/client.d.ts
|
|
125
|
-
/**
|
|
126
|
-
* Build a typed OpenCode SDK client from a lifecycle handle.
|
|
127
|
-
*
|
|
128
|
-
* Works against either the Worker stub (`sandbox.opencode`) or the in-DO object
|
|
129
|
-
* (`this.opencode`): it ensures the server through the handle, reads the stored
|
|
130
|
-
* config, and routes every request through `handle.fetch`. Because the handle
|
|
131
|
-
* owns `containerFetch`, this helper never touches sandbox transport directly.
|
|
132
|
-
*
|
|
133
|
-
* The SDK is imported lazily so the peer dependency is only required when an
|
|
134
|
-
* OpenCode client is actually built.
|
|
135
|
-
*/
|
|
136
|
-
declare function createOpenCodeClient<TClient = OpencodeClient>(handle: OpenCodeHandle, options?: OpenCodeOptions): Promise<TClient>;
|
|
137
|
-
//#endregion
|
|
138
|
-
//#region ../../extensions/opencode/src/proxy.d.ts
|
|
139
|
-
/** Configuration for {@link createOpenCodeProxy}. */
|
|
140
|
-
interface OpenCodeProxyOptions {
|
|
141
|
-
/** Origin the OpenCode web UI should call back through. Defaults to the request origin. */
|
|
142
|
-
callbackOrigin?: string;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Proxy a request to the OpenCode web UI through a lifecycle handle.
|
|
146
|
-
*
|
|
147
|
-
* For an initial HTML page load that still lacks the `?url=` parameter, returns
|
|
148
|
-
* a redirect that adds it (so the OpenCode frontend calls back through the
|
|
149
|
-
* proxy instead of `127.0.0.1:4096`). Every other request is routed through
|
|
150
|
-
* `handle.fetch`, which ensures the server is running before forwarding into the
|
|
151
|
-
* container.
|
|
152
|
-
*/
|
|
153
|
-
declare function proxyToOpenCodeUI(request: Request, handle: OpenCodeHandle, options?: OpenCodeProxyOptions): Response | Promise<Response>;
|
|
154
|
-
/**
|
|
155
|
-
* Curried Worker fetch wrapper for OpenCode.
|
|
156
|
-
*
|
|
157
|
-
* `createOpenCodeProxy(resolve, options?)` captures a lazy per-request resolver
|
|
158
|
-
* for the OpenCode lifecycle handle (`sandbox.opencode`) and returns a function
|
|
159
|
-
* that wraps the user's worker entrypoint.
|
|
160
|
-
*
|
|
161
|
-
* The wrapped handler runs first. If it returns a 404 (or has no `fetch`), the
|
|
162
|
-
* request falls through to the OpenCode web-UI proxy — the redirect handshake
|
|
163
|
-
* for HTML loads and an ensure-then-forward into the container for everything
|
|
164
|
-
* else. A 404 from the user handler is the "not mine, proxy it" signal, so the
|
|
165
|
-
* handler only needs to own its own routes and `return new Response('Not
|
|
166
|
-
* found', { status: 404 })` for the rest.
|
|
167
|
-
*
|
|
168
|
-
* ```ts
|
|
169
|
-
* export default createOpenCodeProxy(
|
|
170
|
-
* (env) => getSandbox(env.Sandbox, 'my-sandbox').opencode
|
|
171
|
-
* )({
|
|
172
|
-
* async fetch(request, env) {
|
|
173
|
-
* // handle your own routes, else:
|
|
174
|
-
* return new Response('Not found', { status: 404 });
|
|
175
|
-
* }
|
|
176
|
-
* });
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
179
|
-
declare function createOpenCodeProxy<Env>(resolve: (env: Env) => OpenCodeHandle, options?: OpenCodeProxyOptions): (handler: ExportedHandler<Env>) => ExportedHandler<Env>;
|
|
180
|
-
//#endregion
|
|
181
|
-
export { type OpenCodeConfig, OpenCodeHandle, type OpenCodeOptions, type OpenCodeProxyOptions, type OpenCodeServer, type OpenCodeServerInfo, OpenCodeStartupError, type OpenCodeStateStorage, type OpenCodeStatus, type WithOpenCodeOptions, createOpenCodeClient, createOpenCodeProxy, proxyToOpenCodeUI, withOpenCode };
|
|
182
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../extensions/opencode/src/types.ts","../../../../extensions/opencode/src/opencode.ts","../../../../extensions/opencode/src/lifecycle.ts","../../../../extensions/opencode/src/client.ts","../../../../extensions/opencode/src/proxy.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;UAMiB,eAAA;;;EAAA;EAcA,SAAA,CAAA,EAAA,MAAc;EAYlB;EAEc,MAAA,CAAA,EAtBhB,MAsBgB;EAId;EACC,GAAA,CAAA,EAzBN,MAyBM,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;UAnBG,cAAA;ECDA;EACG,IAAA,EAAA,MAAA;EAAZ;EACkB,GAAA,EAAA,MAAA;EAAZ;EACe,KAAA,EAAA,EDIlB,OCJkB,CAAA,IAAA,CAAA;;;;;AAHgB,cDahC,oBAAA,SAA6B,KAAA,CCbG;EAAW,SAAA,IAAA,EAAA,yBAAA;oBDe7B;wCAId,kCACC;;;;UCpBG,mBAAA,SAA4B;QACrC,YAAY;cACN,YAAY;iBACT,YAAY;0BACH,wBAAwB,QAAQ;ADjB1D;;;;UEQiB,kBAAA;;;;AFRjB;AAciB,UEAA,cAAA,CFAc;EAYlB,IAAA,EAAA,MAAA;EAEc,SAAA,CAAA,EAAA,MAAA;;;AAFe,UENzB,cAAA,SAAuB,kBFME,CAAA;EAAK,OAAA,EAAA,OAAA;;;;ACb/C;;;AAE0B,UCcT,oBAAA,CDdS;EAAZ,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,ECeS,ODfT,CCeiB,CDfjB,GAAA,SAAA,CAAA;EACe,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,ECeA,CDfA,CAAA,ECeI,ODfJ,CAAA,IAAA,CAAA;;;AAC6B,UCkBzC,mBAAA,SAA4B,eDlBa,CAAA;EAAR;EAJL,O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