zeitlich 0.2.41 → 0.2.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/dist/{activities-qUflxmfS.d.cts → activities-Coafq5zr.d.cts} +2 -2
  2. package/dist/{activities-D_g13S3y.d.ts → activities-CrN-ghLo.d.ts} +2 -2
  3. package/dist/adapters/sandbox/daytona/index.cjs +4 -23
  4. package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
  5. package/dist/adapters/sandbox/daytona/index.d.cts +18 -86
  6. package/dist/adapters/sandbox/daytona/index.d.ts +18 -86
  7. package/dist/adapters/sandbox/daytona/index.js +4 -23
  8. package/dist/adapters/sandbox/daytona/index.js.map +1 -1
  9. package/dist/adapters/sandbox/daytona/workflow.cjs +1 -7
  10. package/dist/adapters/sandbox/daytona/workflow.cjs.map +1 -1
  11. package/dist/adapters/sandbox/daytona/workflow.d.cts +9 -2
  12. package/dist/adapters/sandbox/daytona/workflow.d.ts +9 -2
  13. package/dist/adapters/sandbox/daytona/workflow.js +1 -7
  14. package/dist/adapters/sandbox/daytona/workflow.js.map +1 -1
  15. package/dist/adapters/sandbox/e2b/index.cjs +9 -0
  16. package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
  17. package/dist/adapters/sandbox/e2b/index.d.cts +13 -5
  18. package/dist/adapters/sandbox/e2b/index.d.ts +13 -5
  19. package/dist/adapters/sandbox/e2b/index.js +9 -1
  20. package/dist/adapters/sandbox/e2b/index.js.map +1 -1
  21. package/dist/adapters/sandbox/e2b/workflow.cjs.map +1 -1
  22. package/dist/adapters/sandbox/e2b/workflow.d.cts +4 -2
  23. package/dist/adapters/sandbox/e2b/workflow.d.ts +4 -2
  24. package/dist/adapters/sandbox/e2b/workflow.js.map +1 -1
  25. package/dist/adapters/sandbox/inmemory/index.cjs +11 -0
  26. package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
  27. package/dist/adapters/sandbox/inmemory/index.d.cts +11 -3
  28. package/dist/adapters/sandbox/inmemory/index.d.ts +11 -3
  29. package/dist/adapters/sandbox/inmemory/index.js +11 -1
  30. package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
  31. package/dist/adapters/sandbox/inmemory/workflow.cjs.map +1 -1
  32. package/dist/adapters/sandbox/inmemory/workflow.d.cts +4 -2
  33. package/dist/adapters/sandbox/inmemory/workflow.d.ts +4 -2
  34. package/dist/adapters/sandbox/inmemory/workflow.js.map +1 -1
  35. package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
  36. package/dist/adapters/thread/anthropic/index.d.cts +5 -5
  37. package/dist/adapters/thread/anthropic/index.d.ts +5 -5
  38. package/dist/adapters/thread/anthropic/index.js.map +1 -1
  39. package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
  40. package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
  41. package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
  42. package/dist/adapters/thread/google-genai/index.d.cts +5 -5
  43. package/dist/adapters/thread/google-genai/index.d.ts +5 -5
  44. package/dist/adapters/thread/google-genai/index.js.map +1 -1
  45. package/dist/adapters/thread/google-genai/workflow.d.cts +5 -5
  46. package/dist/adapters/thread/google-genai/workflow.d.ts +5 -5
  47. package/dist/adapters/thread/langchain/index.cjs.map +1 -1
  48. package/dist/adapters/thread/langchain/index.d.cts +5 -5
  49. package/dist/adapters/thread/langchain/index.d.ts +5 -5
  50. package/dist/adapters/thread/langchain/index.js.map +1 -1
  51. package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
  52. package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
  53. package/dist/index.cjs +224 -70
  54. package/dist/index.cjs.map +1 -1
  55. package/dist/index.d.cts +66 -16
  56. package/dist/index.d.ts +66 -16
  57. package/dist/index.js +224 -70
  58. package/dist/index.js.map +1 -1
  59. package/dist/{proxy-D7mvDEO6.d.cts → proxy-Bf7uI-Hw.d.cts} +1 -1
  60. package/dist/{proxy-BbcgoXg1.d.ts → proxy-COqA95FW.d.ts} +1 -1
  61. package/dist/{thread-manager-CTXPCu9W.d.ts → thread-manager-BhkOyQ1I.d.ts} +2 -2
  62. package/dist/{thread-manager-Dqstsw4i.d.ts → thread-manager-Bi1XlbpJ.d.ts} +2 -2
  63. package/dist/{thread-manager-cLhDhRRc.d.cts → thread-manager-BsLO3Fgc.d.cts} +2 -2
  64. package/dist/{thread-manager-DrWfVjlj.d.cts → thread-manager-wRVVBFgj.d.cts} +2 -2
  65. package/dist/{types-CjF1_Idx.d.ts → types-BkX4HLzi.d.ts} +1 -1
  66. package/dist/{types-CdvcmXb6.d.cts → types-C66-BVBr.d.cts} +1 -1
  67. package/dist/types-CJ7tCdl6.d.cts +266 -0
  68. package/dist/types-CJ7tCdl6.d.ts +266 -0
  69. package/dist/{types-DjaQKUJx.d.cts → types-CdALEF3z.d.cts} +300 -20
  70. package/dist/{types-BqTmyH31.d.ts → types-ChAy_jSP.d.ts} +300 -20
  71. package/dist/types-CjY93AWZ.d.cts +84 -0
  72. package/dist/types-gVa5XCWD.d.ts +84 -0
  73. package/dist/{workflow-N1MNDoul.d.ts → workflow-BwT5EybR.d.ts} +7 -6
  74. package/dist/{workflow-CuqxgS6X.d.cts → workflow-DMmiaw6w.d.cts} +7 -6
  75. package/dist/workflow.cjs +99 -46
  76. package/dist/workflow.cjs.map +1 -1
  77. package/dist/workflow.d.cts +4 -4
  78. package/dist/workflow.d.ts +4 -4
  79. package/dist/workflow.js +99 -46
  80. package/dist/workflow.js.map +1 -1
  81. package/package.json +7 -32
  82. package/src/adapters/sandbox/daytona/index.ts +25 -48
  83. package/src/adapters/sandbox/daytona/proxy.ts +7 -8
  84. package/src/adapters/sandbox/e2b/index.ts +21 -6
  85. package/src/adapters/sandbox/e2b/proxy.ts +3 -2
  86. package/src/adapters/sandbox/inmemory/index.ts +21 -1
  87. package/src/adapters/sandbox/inmemory/proxy.ts +7 -3
  88. package/src/lib/activity.ts +5 -0
  89. package/src/lib/sandbox/capability-types.test.ts +859 -0
  90. package/src/lib/sandbox/index.ts +1 -0
  91. package/src/lib/sandbox/manager.ts +187 -31
  92. package/src/lib/sandbox/types.ts +189 -46
  93. package/src/lib/session/index.ts +1 -0
  94. package/src/lib/session/session.ts +97 -35
  95. package/src/lib/session/types.ts +181 -5
  96. package/src/lib/subagent/handler.ts +66 -43
  97. package/src/lib/subagent/types.ts +484 -16
  98. package/src/workflow.ts +3 -0
  99. package/tsup.config.ts +0 -4
  100. package/dist/adapters/sandbox/bedrock/index.cjs +0 -457
  101. package/dist/adapters/sandbox/bedrock/index.cjs.map +0 -1
  102. package/dist/adapters/sandbox/bedrock/index.d.cts +0 -25
  103. package/dist/adapters/sandbox/bedrock/index.d.ts +0 -25
  104. package/dist/adapters/sandbox/bedrock/index.js +0 -454
  105. package/dist/adapters/sandbox/bedrock/index.js.map +0 -1
  106. package/dist/adapters/sandbox/bedrock/workflow.cjs +0 -36
  107. package/dist/adapters/sandbox/bedrock/workflow.cjs.map +0 -1
  108. package/dist/adapters/sandbox/bedrock/workflow.d.cts +0 -29
  109. package/dist/adapters/sandbox/bedrock/workflow.d.ts +0 -29
  110. package/dist/adapters/sandbox/bedrock/workflow.js +0 -34
  111. package/dist/adapters/sandbox/bedrock/workflow.js.map +0 -1
  112. package/dist/types-DAsQ21Rt.d.ts +0 -74
  113. package/dist/types-lm8tMNJQ.d.cts +0 -74
  114. package/dist/types-yx0LzPGn.d.cts +0 -173
  115. package/dist/types-yx0LzPGn.d.ts +0 -173
  116. package/src/adapters/sandbox/bedrock/filesystem.ts +0 -340
  117. package/src/adapters/sandbox/bedrock/index.ts +0 -274
  118. package/src/adapters/sandbox/bedrock/proxy.ts +0 -59
  119. package/src/adapters/sandbox/bedrock/types.ts +0 -24
@@ -1,340 +0,0 @@
1
- import type {
2
- BedrockAgentCoreClient,
3
- CodeInterpreterStreamOutput,
4
- CodeInterpreterResult,
5
- ToolName as ToolNameType,
6
- ToolArguments,
7
- } from "@aws-sdk/client-bedrock-agentcore";
8
- import { InvokeCodeInterpreterCommand } from "@aws-sdk/client-bedrock-agentcore";
9
- import type {
10
- SandboxFileSystem,
11
- DirentEntry,
12
- FileStat,
13
- } from "../../../lib/sandbox/types";
14
- import { SandboxNotSupportedError } from "../../../lib/sandbox/types";
15
- import { posix } from "node:path";
16
-
17
- async function consumeStream(
18
- stream: AsyncIterable<CodeInterpreterStreamOutput>
19
- ): Promise<CodeInterpreterResult> {
20
- for await (const event of stream) {
21
- if ("result" in event && event.result) return event.result;
22
- if ("accessDeniedException" in event && event.accessDeniedException)
23
- throw new Error(event.accessDeniedException.message ?? "Access denied");
24
- if ("resourceNotFoundException" in event && event.resourceNotFoundException)
25
- throw new Error(
26
- event.resourceNotFoundException.message ?? "Resource not found"
27
- );
28
- if ("validationException" in event && event.validationException)
29
- throw new Error(event.validationException.message ?? "Validation error");
30
- if ("internalServerException" in event && event.internalServerException)
31
- throw new Error(
32
- event.internalServerException.message ?? "Internal server error"
33
- );
34
- if ("throttlingException" in event && event.throttlingException)
35
- throw new Error(event.throttlingException.message ?? "Throttled");
36
- if (
37
- "serviceQuotaExceededException" in event &&
38
- event.serviceQuotaExceededException
39
- )
40
- throw new Error(
41
- event.serviceQuotaExceededException.message ?? "Quota exceeded"
42
- );
43
- if ("conflictException" in event && event.conflictException)
44
- throw new Error(event.conflictException.message ?? "Conflict");
45
- }
46
- throw new Error("No result received from code interpreter stream");
47
- }
48
-
49
- /**
50
- * {@link SandboxFileSystem} backed by AWS Bedrock AgentCore Code Interpreter.
51
- *
52
- * Maps zeitlich's filesystem interface to Code Interpreter's
53
- * `readFiles` / `writeFiles` / `listFiles` / `removeFiles` / `executeCommand`
54
- * tool invocations.
55
- */
56
- export class BedrockSandboxFileSystem implements SandboxFileSystem {
57
- readonly workspaceBase: string;
58
-
59
- constructor(
60
- private client: BedrockAgentCoreClient,
61
- private codeInterpreterIdentifier: string,
62
- private sessionId: string,
63
- workspaceBase = "/home/user"
64
- ) {
65
- this.workspaceBase = posix.resolve("/", workspaceBase);
66
- }
67
-
68
- /**
69
- * Resolve a caller-supplied path to an absolute path within the workspace.
70
- * Used for shell commands that need full paths.
71
- */
72
- private normalisePath(path: string): string {
73
- if (
74
- posix.isAbsolute(path) &&
75
- !path.startsWith(this.workspaceBase + "/") &&
76
- path !== this.workspaceBase
77
- ) {
78
- path = path.replace(/^\/+/, "");
79
- }
80
- const resolved = posix.resolve(this.workspaceBase, path);
81
- if (
82
- !resolved.startsWith(this.workspaceBase + "/") &&
83
- resolved !== this.workspaceBase
84
- ) {
85
- throw new Error(
86
- `Invalid file path: "${resolved}" escapes workspace "${this.workspaceBase}"`
87
- );
88
- }
89
- return resolved;
90
- }
91
-
92
- /**
93
- * Return a workspace-relative path for Bedrock tool invocations
94
- * (`writeFiles`, `readFiles`, `listFiles`, `removeFiles`), which
95
- * reject absolute paths as "path traversal".
96
- */
97
- private toToolPath(path: string): string {
98
- const abs = this.normalisePath(path);
99
- const prefix = this.workspaceBase + "/";
100
- return abs.startsWith(prefix) ? abs.slice(prefix.length) : abs;
101
- }
102
-
103
- private async invoke(
104
- name: ToolNameType,
105
- args: ToolArguments
106
- ): Promise<CodeInterpreterResult> {
107
- const resp = await this.client.send(
108
- new InvokeCodeInterpreterCommand({
109
- codeInterpreterIdentifier: this.codeInterpreterIdentifier,
110
- sessionId: this.sessionId,
111
- name,
112
- arguments: args,
113
- })
114
- );
115
- if (!resp.stream) throw new Error("No stream in code interpreter response");
116
- return consumeStream(resp.stream);
117
- }
118
-
119
- private async execShell(command: string): Promise<{
120
- stdout: string;
121
- stderr: string;
122
- exitCode: number;
123
- }> {
124
- const result = await this.invoke("executeCommand" as ToolNameType, {
125
- command,
126
- });
127
- return {
128
- stdout: result.structuredContent?.stdout ?? "",
129
- stderr: result.structuredContent?.stderr ?? "",
130
- exitCode: result.structuredContent?.exitCode ?? 0,
131
- };
132
- }
133
-
134
- async readFile(path: string): Promise<string> {
135
- const rel = this.toToolPath(path);
136
- const result = await this.invoke("readFiles" as ToolNameType, {
137
- paths: [rel],
138
- });
139
-
140
- for (const block of result.content ?? []) {
141
- if (block.resource?.text != null) return block.resource.text;
142
- if (block.text != null) return block.text;
143
- }
144
- return "";
145
- }
146
-
147
- async readFileBuffer(path: string): Promise<Uint8Array> {
148
- const rel = this.toToolPath(path);
149
- const result = await this.invoke("readFiles" as ToolNameType, {
150
- paths: [rel],
151
- });
152
-
153
- for (const block of result.content ?? []) {
154
- if (block.resource?.blob) return block.resource.blob;
155
- if (block.data) return block.data;
156
- if (block.resource?.text != null)
157
- return new TextEncoder().encode(block.resource.text);
158
- if (block.text != null) return new TextEncoder().encode(block.text);
159
- }
160
- return new Uint8Array(0);
161
- }
162
-
163
- async writeFile(path: string, content: string | Uint8Array): Promise<void> {
164
- const rel = this.toToolPath(path);
165
- const isText = typeof content === "string";
166
- const result = await this.invoke("writeFiles" as ToolNameType, {
167
- content: [
168
- {
169
- path: rel,
170
- ...(isText
171
- ? { text: content as string }
172
- : { blob: content as Uint8Array }),
173
- },
174
- ],
175
- });
176
- if (result.isError) {
177
- const msg =
178
- result.content?.map((b) => b.text).join("") ?? "writeFile failed";
179
- throw new Error(msg);
180
- }
181
- }
182
-
183
- async appendFile(path: string, content: string | Uint8Array): Promise<void> {
184
- const norm = this.normalisePath(path);
185
- const addition =
186
- typeof content === "string" ? content : new TextDecoder().decode(content);
187
- const escaped = addition.replace(/'/g, "'\\''");
188
- const { exitCode, stderr } = await this.execShell(
189
- `printf '%s' '${escaped}' >> "${norm}"`
190
- );
191
- if (exitCode !== 0) throw new Error(`appendFile failed: ${stderr}`);
192
- }
193
-
194
- async exists(path: string): Promise<boolean> {
195
- const norm = this.normalisePath(path);
196
- const { exitCode } = await this.execShell(`test -e "${norm}"`);
197
- return exitCode === 0;
198
- }
199
-
200
- async stat(path: string): Promise<FileStat> {
201
- const norm = this.normalisePath(path);
202
- const { stdout, exitCode, stderr } = await this.execShell(
203
- `stat -c '%F %s %Y' "${norm}" 2>&1`
204
- );
205
- if (exitCode !== 0) throw new Error(`stat failed: ${stderr || stdout}`);
206
-
207
- const parts = stdout.trim().split(" ");
208
- const fileType = parts.slice(0, -2).join(" ");
209
- const sizeStr = parts[parts.length - 2] ?? "0";
210
- const mtimeStr = parts[parts.length - 1] ?? "0";
211
- const size = parseInt(sizeStr, 10);
212
- const mtimeEpoch = parseInt(mtimeStr, 10);
213
-
214
- return {
215
- isFile: fileType === "regular file" || fileType === "regular empty file",
216
- isDirectory: fileType === "directory",
217
- isSymbolicLink: fileType === "symbolic link",
218
- size: isNaN(size) ? 0 : size,
219
- mtime: new Date(isNaN(mtimeEpoch) ? 0 : mtimeEpoch * 1000),
220
- };
221
- }
222
-
223
- async mkdir(path: string, options?: { recursive?: boolean }): Promise<void> {
224
- const norm = this.normalisePath(path);
225
- const flag = options?.recursive ? "-p " : "";
226
- const { exitCode, stderr } = await this.execShell(`mkdir ${flag}"${norm}"`);
227
- if (exitCode !== 0) throw new Error(`mkdir failed: ${stderr}`);
228
- }
229
-
230
- async readdir(path: string): Promise<string[]> {
231
- const rel = this.toToolPath(path);
232
- const result = await this.invoke("listFiles" as ToolNameType, {
233
- directoryPath: rel,
234
- });
235
-
236
- const names: string[] = [];
237
- for (const block of result.content ?? []) {
238
- if (block.name) names.push(block.name);
239
- }
240
-
241
- if (names.length > 0) return names;
242
-
243
- const norm = this.normalisePath(path);
244
- const { stdout, exitCode, stderr } = await this.execShell(
245
- `ls -1A "${norm}"`
246
- );
247
- if (exitCode !== 0) throw new Error(`readdir failed: ${stderr}`);
248
- return stdout
249
- .trim()
250
- .split("\n")
251
- .filter((l) => l.length > 0);
252
- }
253
-
254
- async readdirWithFileTypes(path: string): Promise<DirentEntry[]> {
255
- const norm = this.normalisePath(path);
256
- const { stdout, exitCode, stderr } = await this.execShell(
257
- `find "${norm}" -maxdepth 1 -mindepth 1 -printf '%y %f\\n'`
258
- );
259
- if (exitCode !== 0)
260
- throw new Error(`readdirWithFileTypes failed: ${stderr}`);
261
-
262
- return stdout
263
- .trim()
264
- .split("\n")
265
- .filter((l) => l.length > 0)
266
- .map((line) => {
267
- const type = line.charAt(0);
268
- const name = line.slice(2);
269
- return {
270
- name,
271
- isFile: type === "f",
272
- isDirectory: type === "d",
273
- isSymbolicLink: type === "l",
274
- };
275
- });
276
- }
277
-
278
- async rm(
279
- path: string,
280
- options?: { recursive?: boolean; force?: boolean }
281
- ): Promise<void> {
282
- const norm = this.normalisePath(path);
283
- if (options?.recursive || options?.force) {
284
- const flags =
285
- `${options?.recursive ? "-r" : ""} ${options?.force ? "-f" : ""}`.trim();
286
- const { exitCode, stderr } = await this.execShell(
287
- `rm ${flags} "${norm}"`
288
- );
289
- if (exitCode !== 0 && !options?.force)
290
- throw new Error(`rm failed: ${stderr}`);
291
- return;
292
- }
293
-
294
- const rel = this.toToolPath(path);
295
- const result = await this.invoke("removeFiles" as ToolNameType, {
296
- paths: [rel],
297
- });
298
- if (result.isError) {
299
- const msg = result.content?.map((b) => b.text).join("") ?? "rm failed";
300
- throw new Error(msg);
301
- }
302
- }
303
-
304
- async cp(
305
- src: string,
306
- dest: string,
307
- options?: { recursive?: boolean }
308
- ): Promise<void> {
309
- const normSrc = this.normalisePath(src);
310
- const normDest = this.normalisePath(dest);
311
- const flag = options?.recursive ? "-r " : "";
312
- const { exitCode, stderr } = await this.execShell(
313
- `cp ${flag}"${normSrc}" "${normDest}"`
314
- );
315
- if (exitCode !== 0) throw new Error(`cp failed: ${stderr}`);
316
- }
317
-
318
- async mv(src: string, dest: string): Promise<void> {
319
- const normSrc = this.normalisePath(src);
320
- const normDest = this.normalisePath(dest);
321
- const { exitCode, stderr } = await this.execShell(
322
- `mv "${normSrc}" "${normDest}"`
323
- );
324
- if (exitCode !== 0) throw new Error(`mv failed: ${stderr}`);
325
- }
326
-
327
- async readlink(path: string): Promise<string> {
328
- const norm = this.normalisePath(path);
329
- const { stdout, exitCode, stderr } = await this.execShell(
330
- `readlink "${norm}"`
331
- );
332
- if (exitCode !== 0)
333
- throw new SandboxNotSupportedError(`readlink: ${stderr}`);
334
- return stdout.trim();
335
- }
336
-
337
- resolvePath(base: string, path: string): string {
338
- return posix.resolve(this.normalisePath(base), path);
339
- }
340
- }
@@ -1,274 +0,0 @@
1
- import {
2
- BedrockAgentCoreClient,
3
- StartCodeInterpreterSessionCommand,
4
- GetCodeInterpreterSessionCommand,
5
- StopCodeInterpreterSessionCommand,
6
- InvokeCodeInterpreterCommand,
7
- } from "@aws-sdk/client-bedrock-agentcore";
8
- import type { CodeInterpreterStreamOutput } from "@aws-sdk/client-bedrock-agentcore";
9
- import type {
10
- Sandbox,
11
- SandboxCapabilities,
12
- SandboxCreateResult,
13
- SandboxProvider,
14
- SandboxSnapshot,
15
- ExecOptions,
16
- ExecResult,
17
- } from "../../../lib/sandbox/types";
18
- import {
19
- SandboxNotFoundError,
20
- SandboxNotSupportedError,
21
- } from "../../../lib/sandbox/types";
22
- import { BedrockSandboxFileSystem } from "./filesystem";
23
- import type {
24
- BedrockSandbox,
25
- BedrockSandboxConfig,
26
- BedrockSandboxCreateOptions,
27
- } from "./types";
28
-
29
- // ============================================================================
30
- // Stream helpers
31
- // ============================================================================
32
-
33
- async function consumeExecStream(
34
- stream: AsyncIterable<CodeInterpreterStreamOutput>
35
- ): Promise<ExecResult> {
36
- for await (const event of stream) {
37
- if ("result" in event && event.result) {
38
- const sc = event.result.structuredContent;
39
- return {
40
- exitCode: sc?.exitCode ?? 0,
41
- stdout: sc?.stdout ?? "",
42
- stderr: sc?.stderr ?? "",
43
- };
44
- }
45
- if ("accessDeniedException" in event && event.accessDeniedException)
46
- throw new Error(event.accessDeniedException.message ?? "Access denied");
47
- if ("resourceNotFoundException" in event && event.resourceNotFoundException)
48
- throw new Error(
49
- event.resourceNotFoundException.message ?? "Resource not found"
50
- );
51
- if ("validationException" in event && event.validationException)
52
- throw new Error(event.validationException.message ?? "Validation error");
53
- if ("internalServerException" in event && event.internalServerException)
54
- throw new Error(
55
- event.internalServerException.message ?? "Internal server error"
56
- );
57
- if ("throttlingException" in event && event.throttlingException)
58
- throw new Error(event.throttlingException.message ?? "Throttled");
59
- if (
60
- "serviceQuotaExceededException" in event &&
61
- event.serviceQuotaExceededException
62
- )
63
- throw new Error(
64
- event.serviceQuotaExceededException.message ?? "Quota exceeded"
65
- );
66
- if ("conflictException" in event && event.conflictException)
67
- throw new Error(event.conflictException.message ?? "Conflict");
68
- }
69
- return { exitCode: 0, stdout: "", stderr: "" };
70
- }
71
-
72
- // ============================================================================
73
- // BedrockSandboxImpl
74
- // ============================================================================
75
-
76
- class BedrockSandboxImpl implements Sandbox {
77
- readonly capabilities: SandboxCapabilities = {
78
- filesystem: true,
79
- execution: true,
80
- persistence: false,
81
- };
82
-
83
- readonly fs: BedrockSandboxFileSystem;
84
-
85
- constructor(
86
- readonly id: string,
87
- private client: BedrockAgentCoreClient,
88
- private codeInterpreterIdentifier: string,
89
- private sessionId: string,
90
- workspaceBase = "/home/user"
91
- ) {
92
- this.fs = new BedrockSandboxFileSystem(
93
- client,
94
- codeInterpreterIdentifier,
95
- sessionId,
96
- workspaceBase
97
- );
98
- }
99
-
100
- async exec(command: string, options?: ExecOptions): Promise<ExecResult> {
101
- let cmd = command;
102
- if (options?.cwd) cmd = `cd "${options.cwd}" && ${cmd}`;
103
- if (options?.env) {
104
- const exports = Object.entries(options.env)
105
- .map(([k, v]) => `export ${k}="${v.replace(/"/g, '\\"')}"`)
106
- .join(" && ");
107
- cmd = `${exports} && ${cmd}`;
108
- }
109
-
110
- const resp = await this.client.send(
111
- new InvokeCodeInterpreterCommand({
112
- codeInterpreterIdentifier: this.codeInterpreterIdentifier,
113
- sessionId: this.sessionId,
114
- name: "executeCommand",
115
- arguments: { command: cmd },
116
- })
117
- );
118
-
119
- if (!resp.stream) throw new Error("No stream in code interpreter response");
120
- return consumeExecStream(resp.stream);
121
- }
122
-
123
- async destroy(): Promise<void> {
124
- await this.client.send(
125
- new StopCodeInterpreterSessionCommand({
126
- codeInterpreterIdentifier: this.codeInterpreterIdentifier,
127
- sessionId: this.sessionId,
128
- })
129
- );
130
- }
131
- }
132
-
133
- // ============================================================================
134
- // BedrockSandboxProvider
135
- // ============================================================================
136
-
137
- export class BedrockSandboxProvider implements SandboxProvider<
138
- BedrockSandboxCreateOptions,
139
- BedrockSandbox
140
- > {
141
- readonly id = "bedrock";
142
- readonly capabilities: SandboxCapabilities = {
143
- filesystem: true,
144
- execution: true,
145
- persistence: false,
146
- };
147
-
148
- private client: BedrockAgentCoreClient;
149
- private readonly codeInterpreterIdentifier: string;
150
- private readonly defaultWorkspaceBase: string;
151
-
152
- constructor(config: BedrockSandboxConfig) {
153
- this.client = new BedrockAgentCoreClient(config.clientConfig ?? {});
154
- this.codeInterpreterIdentifier = config.codeInterpreterIdentifier;
155
- this.defaultWorkspaceBase = config.workspaceBase ?? "/home/user";
156
- }
157
-
158
- async create(
159
- options?: BedrockSandboxCreateOptions
160
- ): Promise<SandboxCreateResult> {
161
- const resp = await this.client.send(
162
- new StartCodeInterpreterSessionCommand({
163
- codeInterpreterIdentifier: this.codeInterpreterIdentifier,
164
- name: options?.name,
165
- sessionTimeoutSeconds: options?.sessionTimeoutSeconds,
166
- })
167
- );
168
-
169
- const sessionId = resp.sessionId ?? "";
170
- if (!sessionId) throw new Error("No sessionId returned from Bedrock");
171
- const sandbox = new BedrockSandboxImpl(
172
- sessionId,
173
- this.client,
174
- this.codeInterpreterIdentifier,
175
- sessionId,
176
- this.defaultWorkspaceBase
177
- );
178
-
179
- if (options?.initialFiles) {
180
- for (const [path, content] of Object.entries(options.initialFiles)) {
181
- await sandbox.fs.writeFile(path, content);
182
- }
183
- }
184
-
185
- if (options?.env) {
186
- const exports = Object.entries(options.env)
187
- .map(([k, v]) => `${k}="${v.replace(/"/g, '\\"')}"`)
188
- .join(" ");
189
- await sandbox.exec(`echo '${exports}' >> ~/.bashrc`);
190
- }
191
-
192
- return { sandbox };
193
- }
194
-
195
- async get(sandboxId: string): Promise<BedrockSandbox> {
196
- try {
197
- const resp = await this.client.send(
198
- new GetCodeInterpreterSessionCommand({
199
- codeInterpreterIdentifier: this.codeInterpreterIdentifier,
200
- sessionId: sandboxId,
201
- })
202
- );
203
-
204
- if (resp.status === "TERMINATED") {
205
- throw new SandboxNotFoundError(sandboxId);
206
- }
207
-
208
- return new BedrockSandboxImpl(
209
- sandboxId,
210
- this.client,
211
- this.codeInterpreterIdentifier,
212
- sandboxId,
213
- this.defaultWorkspaceBase
214
- );
215
- } catch (err) {
216
- if (err instanceof SandboxNotFoundError) throw err;
217
- throw new SandboxNotFoundError(sandboxId);
218
- }
219
- }
220
-
221
- async destroy(sandboxId: string): Promise<void> {
222
- try {
223
- await this.client.send(
224
- new StopCodeInterpreterSessionCommand({
225
- codeInterpreterIdentifier: this.codeInterpreterIdentifier,
226
- sessionId: sandboxId,
227
- })
228
- );
229
- } catch {
230
- // Already stopped or not found
231
- }
232
- }
233
-
234
- async pause(_sandboxId: string, _ttlSeconds?: number): Promise<void> {
235
- throw new SandboxNotSupportedError("pause");
236
- }
237
-
238
- async resume(_sandboxId: string): Promise<void> {
239
- // Bedrock sandboxes don't support pause, so resume is a no-op
240
- }
241
-
242
- async snapshot(
243
- _sandboxId: string,
244
- _options?: BedrockSandboxCreateOptions
245
- ): Promise<SandboxSnapshot> {
246
- throw new SandboxNotSupportedError("snapshot");
247
- }
248
-
249
- async restore(
250
- _snapshot: SandboxSnapshot,
251
- _options?: BedrockSandboxCreateOptions
252
- ): Promise<never> {
253
- throw new SandboxNotSupportedError("restore");
254
- }
255
-
256
- async fork(
257
- _sandboxId: string,
258
- _options?: BedrockSandboxCreateOptions
259
- ): Promise<Sandbox> {
260
- throw new SandboxNotSupportedError("fork");
261
- }
262
-
263
- async deleteSnapshot(_snapshot: SandboxSnapshot): Promise<void> {
264
- throw new SandboxNotSupportedError("deleteSnapshot");
265
- }
266
- }
267
-
268
- // Re-exports
269
- export { BedrockSandboxFileSystem } from "./filesystem";
270
- export type {
271
- BedrockSandbox,
272
- BedrockSandboxConfig,
273
- BedrockSandboxCreateOptions,
274
- } from "./types";
@@ -1,59 +0,0 @@
1
- /**
2
- * Workflow-safe proxy for Bedrock sandbox operations.
3
- *
4
- * Uses longer timeouts than in-memory providers since Bedrock
5
- * sandboxes are remote and creation involves provisioning.
6
- *
7
- * Import this from `zeitlich/adapters/sandbox/bedrock/workflow`
8
- * in your Temporal workflow files.
9
- *
10
- * By default the scope is derived from `workflowInfo().workflowType`,
11
- * so activities are automatically namespaced per workflow.
12
- *
13
- * @example
14
- * ```typescript
15
- * import { proxyBedrockSandboxOps } from 'zeitlich/adapters/sandbox/bedrock/workflow';
16
- *
17
- * const sandbox = proxyBedrockSandboxOps();
18
- * ```
19
- */
20
- import { proxyActivities, workflowInfo } from "@temporalio/workflow";
21
- import type { SandboxOps } from "../../../lib/sandbox/types";
22
- import type { BedrockSandboxCreateOptions } from "./types";
23
-
24
- const ADAPTER_PREFIX = "bedrock";
25
-
26
- export function proxyBedrockSandboxOps(
27
- scope?: string,
28
- options?: Parameters<typeof proxyActivities>[0]
29
- ): SandboxOps<BedrockSandboxCreateOptions> {
30
- const resolvedScope = scope ?? workflowInfo().workflowType;
31
-
32
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
- const acts = proxyActivities<Record<string, (...args: any[]) => any>>(
34
- options ?? {
35
- startToCloseTimeout: "120s",
36
- retry: {
37
- maximumAttempts: 3,
38
- initialInterval: "5s",
39
- maximumInterval: "60s",
40
- backoffCoefficient: 3,
41
- },
42
- }
43
- );
44
-
45
- const prefix = `${ADAPTER_PREFIX}${resolvedScope.charAt(0).toUpperCase()}${resolvedScope.slice(1)}`;
46
- const p = (key: string): string =>
47
- `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;
48
-
49
- return {
50
- createSandbox: acts[p("createSandbox")],
51
- destroySandbox: acts[p("destroySandbox")],
52
- pauseSandbox: acts[p("pauseSandbox")],
53
- resumeSandbox: acts[p("resumeSandbox")],
54
- snapshotSandbox: acts[p("snapshotSandbox")],
55
- restoreSandbox: acts[p("restoreSandbox")],
56
- deleteSandboxSnapshot: acts[p("deleteSandboxSnapshot")],
57
- forkSandbox: acts[p("forkSandbox")],
58
- } as SandboxOps<BedrockSandboxCreateOptions>;
59
- }
@@ -1,24 +0,0 @@
1
- import type { Sandbox, SandboxCreateOptions } from "../../../lib/sandbox/types";
2
- import type { BedrockSandboxFileSystem } from "./filesystem";
3
- import type { BedrockAgentCoreClientConfig } from "@aws-sdk/client-bedrock-agentcore";
4
-
5
- /**
6
- * A Bedrock-backed {@link Sandbox} with its typed filesystem.
7
- */
8
- export type BedrockSandbox = Sandbox & { fs: BedrockSandboxFileSystem };
9
-
10
- export interface BedrockSandboxConfig {
11
- /** ARN or name of the Code Interpreter resource. */
12
- codeInterpreterIdentifier: string;
13
- /** AWS SDK client configuration (region, credentials, etc.). */
14
- clientConfig?: BedrockAgentCoreClientConfig;
15
- /** Default base path for resolving relative filesystem paths. */
16
- workspaceBase?: string;
17
- }
18
-
19
- export interface BedrockSandboxCreateOptions extends SandboxCreateOptions {
20
- /** Session name (human-readable, does not need to be unique). */
21
- name?: string;
22
- /** Session timeout in seconds. Default 900 (15 min). Max 28 800 (8 h). */
23
- sessionTimeoutSeconds?: number;
24
- }