@cloudflare/sandbox 0.5.1 → 0.5.3
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/.turbo/turbo-build.log +17 -9
- package/CHANGELOG.md +18 -0
- package/dist/dist-gVyG2H2h.js +612 -0
- package/dist/dist-gVyG2H2h.js.map +1 -0
- package/dist/index.d.ts +14 -1720
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -698
- package/dist/index.js.map +1 -1
- package/dist/openai/index.d.ts +67 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/index.js +362 -0
- package/dist/openai/index.js.map +1 -0
- package/dist/sandbox-HQazw9bn.d.ts +1741 -0
- package/dist/sandbox-HQazw9bn.d.ts.map +1 -0
- package/package.json +15 -1
- package/src/clients/command-client.ts +31 -13
- package/src/clients/process-client.ts +20 -2
- package/src/openai/index.ts +465 -0
- package/src/sandbox.ts +103 -47
- package/src/version.ts +1 -1
- package/tests/git-client.test.ts +7 -39
- package/tests/openai-shell-editor.test.ts +434 -0
- package/tests/port-client.test.ts +25 -35
- package/tests/process-client.test.ts +73 -107
- package/tests/sandbox.test.ts +65 -35
- package/tsconfig.json +2 -2
- package/tsdown.config.ts +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { t as Sandbox } from "../sandbox-HQazw9bn.js";
|
|
2
|
+
import { ApplyPatchOperation, ApplyPatchResult, Editor as Editor$1, Shell as Shell$1, ShellAction, ShellResult } from "@openai/agents";
|
|
3
|
+
|
|
4
|
+
//#region src/openai/index.d.ts
|
|
5
|
+
|
|
6
|
+
interface CommandResult {
|
|
7
|
+
command: string;
|
|
8
|
+
stdout: string;
|
|
9
|
+
stderr: string;
|
|
10
|
+
exitCode: number | null;
|
|
11
|
+
timestamp: number;
|
|
12
|
+
}
|
|
13
|
+
interface FileOperationResult {
|
|
14
|
+
operation: 'create' | 'update' | 'delete';
|
|
15
|
+
path: string;
|
|
16
|
+
status: 'completed' | 'failed';
|
|
17
|
+
output: string;
|
|
18
|
+
error?: string;
|
|
19
|
+
timestamp: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Shell implementation that adapts Cloudflare Sandbox exec calls to the
|
|
23
|
+
* OpenAI Agents `Shell` contract, including structured result collection.
|
|
24
|
+
*/
|
|
25
|
+
declare class Shell implements Shell$1 {
|
|
26
|
+
private readonly sandbox;
|
|
27
|
+
private cwd;
|
|
28
|
+
results: CommandResult[];
|
|
29
|
+
private readonly logger;
|
|
30
|
+
constructor(sandbox: Sandbox);
|
|
31
|
+
run(action: ShellAction): Promise<ShellResult>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Editor implementation that projects applyPatch operations from Agents
|
|
35
|
+
* into calls against the sandbox filesystem APIs.
|
|
36
|
+
*/
|
|
37
|
+
declare class Editor implements Editor$1 {
|
|
38
|
+
private readonly sandbox;
|
|
39
|
+
private readonly root;
|
|
40
|
+
results: FileOperationResult[];
|
|
41
|
+
private readonly logger;
|
|
42
|
+
constructor(sandbox: Sandbox, root?: string);
|
|
43
|
+
/**
|
|
44
|
+
* Create a new file inside the sandbox by applying the provided diff.
|
|
45
|
+
*/
|
|
46
|
+
createFile(operation: Extract<ApplyPatchOperation, {
|
|
47
|
+
type: 'create_file';
|
|
48
|
+
}>): Promise<ApplyPatchResult | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Update an existing file by reading its content, applying a diff, and
|
|
51
|
+
* writing the patched output back to the sandbox.
|
|
52
|
+
*/
|
|
53
|
+
updateFile(operation: Extract<ApplyPatchOperation, {
|
|
54
|
+
type: 'update_file';
|
|
55
|
+
}>): Promise<ApplyPatchResult | undefined>;
|
|
56
|
+
/**
|
|
57
|
+
* Delete a file that was previously created through applyPatch calls.
|
|
58
|
+
*/
|
|
59
|
+
deleteFile(operation: Extract<ApplyPatchOperation, {
|
|
60
|
+
type: 'delete_file';
|
|
61
|
+
}>): Promise<ApplyPatchResult | undefined>;
|
|
62
|
+
private resolve;
|
|
63
|
+
private getDirname;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { CommandResult, Editor, FileOperationResult, Shell };
|
|
67
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/openai/index.ts"],"sourcesContent":[],"mappings":";;;;;AAyBiB,UATA,aAAA,CASmB;EA2CvB,OAAA,EAAM,MAAA;EAED,MAAA,EAAA,MAAA;EAGsB,MAAA,EAAA,MAAA;EAOpB,QAAA,EAAA,MAAA,GAAA,IAAA;EAAsB,SAAA,EAAA,MAAA;;AAZZ,UA3Cb,mBAAA,CA2Ca;EAAW,SAAA,EAAA,QAAA,GAAA,QAAA,GAAA,QAAA;EAyI5B,IAAA,EAAA,MAAO;EACF,MAAA,EAAA,WAAA,GAAA,QAAA;EAIY,MAAA,EAAA,MAAA;EAaP,KAAA,CAAA,EAAA,MAAA;EAAR,SAAA,EAAA,MAAA;;;;;;AAmJQ,cA9SV,KAAA,YAAiB,OA8SP,CAAA;EAAR,iBAAA,OAAA;EACF,QAAA,GAAA;EAAR,OAAA,EA7Sa,aA6Sb,EAAA;EAtK0B,iBAAA,MAAA;EAAa,WAAA,CAAA,OAAA,EApIJ,OAoII;cA7HxB,cAAc,QAAQ;;;;;;cA6H7B,MAAA,YAAkB;;;WACb;;uBAIY;;;;wBAaf,QAAQ;;OAClB,QAAQ;;;;;wBA4DE,QAAQ;;OAClB,QAAQ;;;;wBAqFE,QAAQ;;OAClB,QAAQ"}
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { a as createLogger } from "../dist-gVyG2H2h.js";
|
|
2
|
+
import { applyDiff } from "@openai/agents";
|
|
3
|
+
|
|
4
|
+
//#region src/openai/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* OpenAI Agents adapters for executing shell commands and file operations
|
|
7
|
+
* inside a Cloudflare Sandbox.
|
|
8
|
+
*/
|
|
9
|
+
function isErrorWithProperties(error) {
|
|
10
|
+
return typeof error === "object" && error !== null;
|
|
11
|
+
}
|
|
12
|
+
function getErrorMessage(error) {
|
|
13
|
+
if (isErrorWithProperties(error) && typeof error.message === "string") return error.message;
|
|
14
|
+
return String(error);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Convert unknown values to Error instances when possible so downstream
|
|
18
|
+
* loggers can include stack traces without losing type safety.
|
|
19
|
+
*/
|
|
20
|
+
function toError(error) {
|
|
21
|
+
return error instanceof Error ? error : void 0;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Shell implementation that adapts Cloudflare Sandbox exec calls to the
|
|
25
|
+
* OpenAI Agents `Shell` contract, including structured result collection.
|
|
26
|
+
*/
|
|
27
|
+
var Shell = class {
|
|
28
|
+
cwd = "/workspace";
|
|
29
|
+
results = [];
|
|
30
|
+
logger;
|
|
31
|
+
constructor(sandbox) {
|
|
32
|
+
this.sandbox = sandbox;
|
|
33
|
+
this.logger = createLogger({
|
|
34
|
+
component: "sandbox-do",
|
|
35
|
+
operation: "openai-shell"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async run(action) {
|
|
39
|
+
this.logger.debug("SandboxShell.run called", {
|
|
40
|
+
commands: action.commands,
|
|
41
|
+
timeout: action.timeoutMs
|
|
42
|
+
});
|
|
43
|
+
const output = [];
|
|
44
|
+
for (const command of action.commands) {
|
|
45
|
+
this.logger.debug("Executing command", {
|
|
46
|
+
command,
|
|
47
|
+
cwd: this.cwd
|
|
48
|
+
});
|
|
49
|
+
let stdout = "";
|
|
50
|
+
let stderr = "";
|
|
51
|
+
let exitCode = 0;
|
|
52
|
+
let outcome = {
|
|
53
|
+
type: "exit",
|
|
54
|
+
exitCode: 0
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
const result = await this.sandbox.exec(command, {
|
|
58
|
+
timeout: action.timeoutMs,
|
|
59
|
+
cwd: this.cwd
|
|
60
|
+
});
|
|
61
|
+
stdout = result.stdout;
|
|
62
|
+
stderr = result.stderr;
|
|
63
|
+
exitCode = result.exitCode;
|
|
64
|
+
outcome = {
|
|
65
|
+
type: "exit",
|
|
66
|
+
exitCode
|
|
67
|
+
};
|
|
68
|
+
this.logger.debug("Command executed successfully", {
|
|
69
|
+
command,
|
|
70
|
+
exitCode,
|
|
71
|
+
stdoutLength: stdout.length,
|
|
72
|
+
stderrLength: stderr.length
|
|
73
|
+
});
|
|
74
|
+
if (exitCode !== 0) this.logger.warn(`Command failed with exit code ${exitCode}`, {
|
|
75
|
+
command,
|
|
76
|
+
stderr
|
|
77
|
+
});
|
|
78
|
+
else if (stderr) this.logger.warn(`Command produced stderr output`, {
|
|
79
|
+
command,
|
|
80
|
+
stderr
|
|
81
|
+
});
|
|
82
|
+
else this.logger.info(`Command completed successfully`, { command });
|
|
83
|
+
} catch (error) {
|
|
84
|
+
const errorObj = isErrorWithProperties(error) ? error : {};
|
|
85
|
+
exitCode = typeof errorObj.exitCode === "number" ? errorObj.exitCode : null;
|
|
86
|
+
stdout = typeof errorObj.stdout === "string" ? errorObj.stdout : "";
|
|
87
|
+
stderr = typeof errorObj.stderr === "string" ? errorObj.stderr : "";
|
|
88
|
+
const errorMessage = getErrorMessage(error);
|
|
89
|
+
if (errorMessage.includes("timeout") || errorMessage.includes("Timeout") || errorMessage.includes("timed out")) {
|
|
90
|
+
this.logger.error(`Command timed out`, void 0, {
|
|
91
|
+
command,
|
|
92
|
+
timeout: action.timeoutMs
|
|
93
|
+
});
|
|
94
|
+
outcome = { type: "timeout" };
|
|
95
|
+
} else {
|
|
96
|
+
this.logger.error(`Error executing command`, toError(error), {
|
|
97
|
+
command,
|
|
98
|
+
error: errorMessage || error,
|
|
99
|
+
exitCode
|
|
100
|
+
});
|
|
101
|
+
outcome = {
|
|
102
|
+
type: "exit",
|
|
103
|
+
exitCode: exitCode ?? 1
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
output.push({
|
|
108
|
+
command,
|
|
109
|
+
stdout,
|
|
110
|
+
stderr,
|
|
111
|
+
outcome
|
|
112
|
+
});
|
|
113
|
+
const collectedExitCode = outcome.type === "exit" ? outcome.exitCode : null;
|
|
114
|
+
const timestamp = Date.now();
|
|
115
|
+
this.results.push({
|
|
116
|
+
command: String(command),
|
|
117
|
+
stdout: String(stdout),
|
|
118
|
+
stderr: String(stderr),
|
|
119
|
+
exitCode: collectedExitCode,
|
|
120
|
+
timestamp
|
|
121
|
+
});
|
|
122
|
+
this.logger.debug("Result collected", {
|
|
123
|
+
command,
|
|
124
|
+
exitCode: collectedExitCode,
|
|
125
|
+
timestamp
|
|
126
|
+
});
|
|
127
|
+
if (outcome.type === "timeout") {
|
|
128
|
+
this.logger.warn("Breaking command loop due to timeout");
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.logger.debug("SandboxShell.run completed", {
|
|
133
|
+
totalCommands: action.commands.length,
|
|
134
|
+
resultsCount: this.results.length
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
output,
|
|
138
|
+
providerData: { working_directory: this.cwd }
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Editor implementation that projects applyPatch operations from Agents
|
|
144
|
+
* into calls against the sandbox filesystem APIs.
|
|
145
|
+
*/
|
|
146
|
+
var Editor = class {
|
|
147
|
+
results = [];
|
|
148
|
+
logger;
|
|
149
|
+
constructor(sandbox, root = "/workspace") {
|
|
150
|
+
this.sandbox = sandbox;
|
|
151
|
+
this.root = root;
|
|
152
|
+
this.logger = createLogger({
|
|
153
|
+
component: "sandbox-do",
|
|
154
|
+
operation: "openai-editor"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create a new file inside the sandbox by applying the provided diff.
|
|
159
|
+
*/
|
|
160
|
+
async createFile(operation) {
|
|
161
|
+
const targetPath = this.resolve(operation.path);
|
|
162
|
+
this.logger.debug("WorkspaceEditor.createFile called", {
|
|
163
|
+
path: operation.path,
|
|
164
|
+
targetPath
|
|
165
|
+
});
|
|
166
|
+
try {
|
|
167
|
+
const dirPath = this.getDirname(targetPath);
|
|
168
|
+
if (dirPath !== this.root && dirPath !== "/") {
|
|
169
|
+
this.logger.debug("Creating parent directory", { dirPath });
|
|
170
|
+
await this.sandbox.mkdir(dirPath, { recursive: true });
|
|
171
|
+
}
|
|
172
|
+
const content = applyDiff("", operation.diff, "create");
|
|
173
|
+
this.logger.debug("Writing file content", {
|
|
174
|
+
path: targetPath,
|
|
175
|
+
contentLength: content.length
|
|
176
|
+
});
|
|
177
|
+
await this.sandbox.writeFile(targetPath, content, { encoding: "utf-8" });
|
|
178
|
+
const timestamp = Date.now();
|
|
179
|
+
const result = {
|
|
180
|
+
operation: "create",
|
|
181
|
+
path: operation.path,
|
|
182
|
+
status: "completed",
|
|
183
|
+
output: `Created ${operation.path}`,
|
|
184
|
+
timestamp
|
|
185
|
+
};
|
|
186
|
+
this.results.push(result);
|
|
187
|
+
this.logger.info("File created successfully", {
|
|
188
|
+
path: operation.path,
|
|
189
|
+
timestamp
|
|
190
|
+
});
|
|
191
|
+
return {
|
|
192
|
+
status: "completed",
|
|
193
|
+
output: `Created ${operation.path}`
|
|
194
|
+
};
|
|
195
|
+
} catch (error) {
|
|
196
|
+
const timestamp = Date.now();
|
|
197
|
+
const errorMessage = getErrorMessage(error);
|
|
198
|
+
const result = {
|
|
199
|
+
operation: "create",
|
|
200
|
+
path: operation.path,
|
|
201
|
+
status: "failed",
|
|
202
|
+
output: `Failed to create ${operation.path}`,
|
|
203
|
+
error: errorMessage,
|
|
204
|
+
timestamp
|
|
205
|
+
};
|
|
206
|
+
this.results.push(result);
|
|
207
|
+
this.logger.error("Failed to create file", toError(error), {
|
|
208
|
+
path: operation.path,
|
|
209
|
+
error: errorMessage
|
|
210
|
+
});
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Update an existing file by reading its content, applying a diff, and
|
|
216
|
+
* writing the patched output back to the sandbox.
|
|
217
|
+
*/
|
|
218
|
+
async updateFile(operation) {
|
|
219
|
+
const targetPath = this.resolve(operation.path);
|
|
220
|
+
this.logger.debug("WorkspaceEditor.updateFile called", {
|
|
221
|
+
path: operation.path,
|
|
222
|
+
targetPath
|
|
223
|
+
});
|
|
224
|
+
try {
|
|
225
|
+
let original;
|
|
226
|
+
try {
|
|
227
|
+
this.logger.debug("Reading original file", { path: targetPath });
|
|
228
|
+
original = (await this.sandbox.readFile(targetPath, { encoding: "utf-8" })).content;
|
|
229
|
+
this.logger.debug("Original file read", {
|
|
230
|
+
path: targetPath,
|
|
231
|
+
originalLength: original.length
|
|
232
|
+
});
|
|
233
|
+
} catch (error) {
|
|
234
|
+
const errorObj = isErrorWithProperties(error) ? error : {};
|
|
235
|
+
const errorMessage = getErrorMessage(error);
|
|
236
|
+
if (errorMessage.includes("not found") || errorMessage.includes("ENOENT") || errorObj.status === 404) {
|
|
237
|
+
this.logger.error("Cannot update missing file", void 0, { path: operation.path });
|
|
238
|
+
throw new Error(`Cannot update missing file: ${operation.path}`);
|
|
239
|
+
}
|
|
240
|
+
this.logger.error("Error reading file", toError(error), {
|
|
241
|
+
path: operation.path,
|
|
242
|
+
error: errorMessage
|
|
243
|
+
});
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
const patched = applyDiff(original, operation.diff);
|
|
247
|
+
this.logger.debug("Applied diff", {
|
|
248
|
+
path: targetPath,
|
|
249
|
+
originalLength: original.length,
|
|
250
|
+
patchedLength: patched.length
|
|
251
|
+
});
|
|
252
|
+
await this.sandbox.writeFile(targetPath, patched, { encoding: "utf-8" });
|
|
253
|
+
const timestamp = Date.now();
|
|
254
|
+
const result = {
|
|
255
|
+
operation: "update",
|
|
256
|
+
path: operation.path,
|
|
257
|
+
status: "completed",
|
|
258
|
+
output: `Updated ${operation.path}`,
|
|
259
|
+
timestamp
|
|
260
|
+
};
|
|
261
|
+
this.results.push(result);
|
|
262
|
+
this.logger.info("File updated successfully", {
|
|
263
|
+
path: operation.path,
|
|
264
|
+
timestamp
|
|
265
|
+
});
|
|
266
|
+
return {
|
|
267
|
+
status: "completed",
|
|
268
|
+
output: `Updated ${operation.path}`
|
|
269
|
+
};
|
|
270
|
+
} catch (error) {
|
|
271
|
+
const timestamp = Date.now();
|
|
272
|
+
const errorMessage = getErrorMessage(error);
|
|
273
|
+
const result = {
|
|
274
|
+
operation: "update",
|
|
275
|
+
path: operation.path,
|
|
276
|
+
status: "failed",
|
|
277
|
+
output: `Failed to update ${operation.path}`,
|
|
278
|
+
error: errorMessage,
|
|
279
|
+
timestamp
|
|
280
|
+
};
|
|
281
|
+
this.results.push(result);
|
|
282
|
+
this.logger.error("Failed to update file", toError(error), {
|
|
283
|
+
path: operation.path,
|
|
284
|
+
error: errorMessage
|
|
285
|
+
});
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Delete a file that was previously created through applyPatch calls.
|
|
291
|
+
*/
|
|
292
|
+
async deleteFile(operation) {
|
|
293
|
+
const targetPath = this.resolve(operation.path);
|
|
294
|
+
this.logger.debug("WorkspaceEditor.deleteFile called", {
|
|
295
|
+
path: operation.path,
|
|
296
|
+
targetPath
|
|
297
|
+
});
|
|
298
|
+
try {
|
|
299
|
+
await this.sandbox.deleteFile(targetPath);
|
|
300
|
+
const timestamp = Date.now();
|
|
301
|
+
const result = {
|
|
302
|
+
operation: "delete",
|
|
303
|
+
path: operation.path,
|
|
304
|
+
status: "completed",
|
|
305
|
+
output: `Deleted ${operation.path}`,
|
|
306
|
+
timestamp
|
|
307
|
+
};
|
|
308
|
+
this.results.push(result);
|
|
309
|
+
this.logger.info("File deleted successfully", {
|
|
310
|
+
path: operation.path,
|
|
311
|
+
timestamp
|
|
312
|
+
});
|
|
313
|
+
return {
|
|
314
|
+
status: "completed",
|
|
315
|
+
output: `Deleted ${operation.path}`
|
|
316
|
+
};
|
|
317
|
+
} catch (error) {
|
|
318
|
+
const timestamp = Date.now();
|
|
319
|
+
const errorMessage = getErrorMessage(error);
|
|
320
|
+
const result = {
|
|
321
|
+
operation: "delete",
|
|
322
|
+
path: operation.path,
|
|
323
|
+
status: "failed",
|
|
324
|
+
output: `Failed to delete ${operation.path}`,
|
|
325
|
+
error: errorMessage,
|
|
326
|
+
timestamp
|
|
327
|
+
};
|
|
328
|
+
this.results.push(result);
|
|
329
|
+
this.logger.error("Failed to delete file", toError(error), {
|
|
330
|
+
path: operation.path,
|
|
331
|
+
error: errorMessage
|
|
332
|
+
});
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
resolve(relativePath) {
|
|
337
|
+
let pathToProcess = relativePath;
|
|
338
|
+
if (relativePath.startsWith(this.root)) {
|
|
339
|
+
pathToProcess = relativePath.slice(this.root.length);
|
|
340
|
+
pathToProcess = pathToProcess.replace(/^\//, "");
|
|
341
|
+
}
|
|
342
|
+
const normalized = pathToProcess.replace(/^\.\//, "").replace(/^\//, "");
|
|
343
|
+
const segments = (normalized ? `${this.root}/${normalized}` : this.root).replace(/\/+/g, "/").split("/").filter((s) => s && s !== ".");
|
|
344
|
+
const stack = [];
|
|
345
|
+
for (const segment of segments) if (segment === "..") {
|
|
346
|
+
if (stack.length === 0) throw new Error(`Operation outside workspace: ${relativePath}`);
|
|
347
|
+
stack.pop();
|
|
348
|
+
} else stack.push(segment);
|
|
349
|
+
const normalizedPath = `/${stack.join("/")}`;
|
|
350
|
+
if (!normalizedPath.startsWith(this.root)) throw new Error(`Operation outside workspace: ${relativePath}`);
|
|
351
|
+
return normalizedPath;
|
|
352
|
+
}
|
|
353
|
+
getDirname(filePath) {
|
|
354
|
+
const lastSlash = filePath.lastIndexOf("/");
|
|
355
|
+
if (lastSlash === -1) return "/";
|
|
356
|
+
return filePath.substring(0, lastSlash) || "/";
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
//#endregion
|
|
361
|
+
export { Editor, Shell };
|
|
362
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["sandbox: Sandbox","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 Logger } from '@repo/shared';\nimport type { Sandbox } from '../sandbox';\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: Sandbox) {\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 result = await this.sandbox.exec(command, {\n timeout: action.timeoutMs,\n cwd: this.cwd\n });\n stdout = result.stdout;\n stderr = result.stderr;\n exitCode = result.exitCode;\n // exec returns a result even for failed commands, so check success field\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: Sandbox,\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":";;;;;;;;AAsCA,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,SAAkB;EAAlB;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,I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