@denieler/e2b-codex 0.1.2 → 0.1.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/README.md +18 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/sandbox.d.ts +8 -2
- package/dist/sandbox.js +24 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ What this does:
|
|
|
45
45
|
### Create a ready sandbox in code
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
|
-
import { createReadyCodexSandbox } from "@denieler/
|
|
48
|
+
import { createReadyCodexSandbox } from "@denieler/e2b-codex";
|
|
49
49
|
|
|
50
50
|
const ready = await createReadyCodexSandbox({
|
|
51
51
|
e2bApiKey: process.env.E2B_API_KEY!,
|
|
@@ -62,10 +62,25 @@ The returned object includes:
|
|
|
62
62
|
- `authToken`
|
|
63
63
|
- `workspaceRoot`
|
|
64
64
|
|
|
65
|
+
### Connect to an existing sandbox in code
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { connectCodexSandbox } from "@denieler/e2b-codex";
|
|
69
|
+
|
|
70
|
+
const ready = await connectCodexSandbox({
|
|
71
|
+
e2bApiKey: process.env.E2B_API_KEY!,
|
|
72
|
+
sandboxId: "sandbox-id",
|
|
73
|
+
openAiApiKey: process.env.OPENAI_API_KEY!,
|
|
74
|
+
userId: "user-123",
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Use this when you already persisted `sandboxId` and want to reconnect to the same sandbox instead of creating a new one.
|
|
79
|
+
|
|
65
80
|
### Connect to Codex over websocket
|
|
66
81
|
|
|
67
82
|
```ts
|
|
68
|
-
import { connectCodexClient } from "@denieler/
|
|
83
|
+
import { connectCodexClient } from "@denieler/e2b-codex";
|
|
69
84
|
|
|
70
85
|
const client = await connectCodexClient(ready);
|
|
71
86
|
```
|
|
@@ -113,7 +128,7 @@ If your websocket connection drops, reconnect using the same `websocketUrl` and
|
|
|
113
128
|
If you want one fresh sandbox and one prompt, use:
|
|
114
129
|
|
|
115
130
|
```ts
|
|
116
|
-
import { createReadyCodexSandbox, runPrompt } from "@denieler/
|
|
131
|
+
import { createReadyCodexSandbox, runPrompt } from "@denieler/e2b-codex";
|
|
117
132
|
|
|
118
133
|
const sandbox = await createReadyCodexSandbox({
|
|
119
134
|
e2bApiKey: process.env.E2B_API_KEY!,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { CodexAppServerClient } from "./codex-app-server.js";
|
|
2
2
|
export { loadLocalEnvFile, requireEnvVar } from "./env.js";
|
|
3
3
|
export { template } from "./template.js";
|
|
4
|
-
export { connectCodexClient, createReadyCodexSandbox, runPrompt, } from "./sandbox.js";
|
|
5
|
-
export type { CreateCodexSandboxOptions, ReadyCodexSandbox } from "./sandbox.js";
|
|
4
|
+
export { connectCodexSandbox, connectCodexClient, createReadyCodexSandbox, runPrompt, } from "./sandbox.js";
|
|
5
|
+
export type { CodexSandboxOptions, ConnectCodexSandboxOptions, CreateCodexSandboxOptions, ReadyCodexSandbox, } from "./sandbox.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { CodexAppServerClient } from "./codex-app-server.js";
|
|
2
2
|
export { loadLocalEnvFile, requireEnvVar } from "./env.js";
|
|
3
3
|
export { template } from "./template.js";
|
|
4
|
-
export { connectCodexClient, createReadyCodexSandbox, runPrompt, } from "./sandbox.js";
|
|
4
|
+
export { connectCodexSandbox, connectCodexClient, createReadyCodexSandbox, runPrompt, } from "./sandbox.js";
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Sandbox } from "e2b";
|
|
2
2
|
import { CodexAppServerClient } from "./codex-app-server.js";
|
|
3
|
-
export type
|
|
3
|
+
export type CodexSandboxOptions = {
|
|
4
4
|
e2bApiKey: string;
|
|
5
|
-
templateId: string;
|
|
6
5
|
openAiApiKey: string;
|
|
7
6
|
userId: string;
|
|
8
7
|
timeoutMs?: number;
|
|
@@ -11,6 +10,12 @@ export type CreateCodexSandboxOptions = {
|
|
|
11
10
|
workspaceRoot?: string;
|
|
12
11
|
metadata?: Record<string, string>;
|
|
13
12
|
};
|
|
13
|
+
export type CreateCodexSandboxOptions = CodexSandboxOptions & {
|
|
14
|
+
templateId: string;
|
|
15
|
+
};
|
|
16
|
+
export type ConnectCodexSandboxOptions = Omit<CodexSandboxOptions, "allowInternetAccess" | "metadata"> & {
|
|
17
|
+
sandboxId: string;
|
|
18
|
+
};
|
|
14
19
|
export type ReadyCodexSandbox = {
|
|
15
20
|
sandbox: Sandbox;
|
|
16
21
|
sandboxId: string;
|
|
@@ -20,6 +25,7 @@ export type ReadyCodexSandbox = {
|
|
|
20
25
|
workspaceRoot: string;
|
|
21
26
|
};
|
|
22
27
|
export declare function createReadyCodexSandbox(options: CreateCodexSandboxOptions): Promise<ReadyCodexSandbox>;
|
|
28
|
+
export declare function connectCodexSandbox(options: ConnectCodexSandboxOptions): Promise<ReadyCodexSandbox>;
|
|
23
29
|
export declare function connectCodexClient(readySandbox: Pick<ReadyCodexSandbox, "websocketUrl" | "authToken">): Promise<CodexAppServerClient>;
|
|
24
30
|
export declare function runPrompt(options: {
|
|
25
31
|
sandbox: ReadyCodexSandbox;
|
package/dist/sandbox.js
CHANGED
|
@@ -73,6 +73,30 @@ export async function createReadyCodexSandbox(options) {
|
|
|
73
73
|
workspaceRoot,
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
+
export async function connectCodexSandbox(options) {
|
|
77
|
+
const port = options.port ?? 4571;
|
|
78
|
+
const workspaceRoot = options.workspaceRoot ?? "/workspace";
|
|
79
|
+
const sandbox = await Sandbox.connect(options.sandboxId, {
|
|
80
|
+
apiKey: options.e2bApiKey,
|
|
81
|
+
});
|
|
82
|
+
if (options.timeoutMs) {
|
|
83
|
+
await sandbox.setTimeout(options.timeoutMs);
|
|
84
|
+
}
|
|
85
|
+
await ensureAppServerRunning(sandbox, {
|
|
86
|
+
openAiApiKey: options.openAiApiKey,
|
|
87
|
+
port,
|
|
88
|
+
workspaceRoot,
|
|
89
|
+
userId: options.userId,
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
sandbox,
|
|
93
|
+
sandboxId: sandbox.sandboxId,
|
|
94
|
+
websocketUrl: `wss://${sandbox.getHost(port)}`,
|
|
95
|
+
authToken: createAppServerToken(options.userId),
|
|
96
|
+
port,
|
|
97
|
+
workspaceRoot,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
76
100
|
export async function connectCodexClient(readySandbox) {
|
|
77
101
|
let lastError = null;
|
|
78
102
|
for (let attempt = 0; attempt < 20; attempt += 1) {
|