@agent-compose/sdk 0.8.1 → 0.8.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.
Files changed (48) hide show
  1. package/dist/agent/__tests__/perf-sampler.test.d.ts +10 -0
  2. package/dist/agent/agent-context.d.ts +1 -1
  3. package/dist/agent/agent-loop.d.ts +5 -1
  4. package/dist/agent/desktop-open.d.ts +184 -0
  5. package/dist/agent/perf-sampler.d.ts +99 -0
  6. package/dist/agent/services-manifest.d.ts +88 -0
  7. package/dist/agent/services-restore.d.ts +58 -0
  8. package/dist/client.d.ts +189 -15
  9. package/dist/display.d.ts +17 -0
  10. package/dist/index.d.ts +14 -5
  11. package/dist/index.js +1625 -120
  12. package/dist/runtimes/_cli-agent.d.ts +372 -2
  13. package/dist/runtimes/claude-code.d.ts +12 -0
  14. package/dist/runtimes/codex.buildcommand.test.d.ts +9 -0
  15. package/dist/runtimes/codex.d.ts +8 -0
  16. package/dist/runtimes/openai-desktop.js +1555 -120
  17. package/dist/runtimes/session-env.test.d.ts +14 -0
  18. package/dist/sandbox/sizes.d.ts +120 -30
  19. package/dist/sandbox.d.ts +1 -1
  20. package/dist/types/api-conversations.d.ts +476 -1
  21. package/dist/types/api-factory.d.ts +164 -7
  22. package/dist/types/api-runs.d.ts +23 -1
  23. package/dist/types/protocol.d.ts +32 -1
  24. package/dist/types/runtime.d.ts +120 -0
  25. package/dist/types/workflow-metadata.d.ts +6 -5
  26. package/package.json +1 -1
  27. package/src/agent/agent-context.ts +128 -28
  28. package/src/agent/agent-loop.ts +10 -3
  29. package/src/agent/desktop-open.ts +418 -0
  30. package/src/agent/perf-sampler.ts +202 -0
  31. package/src/agent/services-manifest.ts +356 -0
  32. package/src/agent/services-restore.ts +195 -0
  33. package/src/client.ts +384 -32
  34. package/src/display.ts +44 -1
  35. package/src/index.ts +74 -7
  36. package/src/runtimes/_cli-agent.ts +1160 -67
  37. package/src/runtimes/claude-code.ts +187 -12
  38. package/src/runtimes/codex.ts +65 -2
  39. package/src/sandbox/providers/e2b.ts +8 -4
  40. package/src/sandbox/providers/local.ts +16 -4
  41. package/src/sandbox/sizes.ts +127 -44
  42. package/src/sandbox.ts +8 -0
  43. package/src/types/api-conversations.ts +461 -2
  44. package/src/types/api-factory.ts +165 -7
  45. package/src/types/api-runs.ts +25 -1
  46. package/src/types/protocol.ts +30 -1
  47. package/src/types/runtime.ts +122 -0
  48. package/src/types/workflow-metadata.ts +6 -5
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Session env sourcing (session secrets) — the turn-launch half of the
3
+ * contract. The server writes `$HOME/.agent-compose/session-env.sh` at
4
+ * sandbox acquire; the detached JSONL launch sources it fresh EVERY turn
5
+ * via `sessionEnvSourceFragment`. Pinned here:
6
+ *
7
+ * - the fragment sources exactly the configured $HOME-relative path,
8
+ * silently, and never fails the turn when the file is absent;
9
+ * - hostile/malformed paths (quotes, spaces, `..`, absolute) are DROPPED
10
+ * — a bad option must not break the launch or escape $HOME;
11
+ * - no option ⇒ empty fragment (local/BYOM runs never read a user's
12
+ * dotfiles by surprise).
13
+ */
14
+ export {};
@@ -1,19 +1,78 @@
1
1
  /**
2
- * Sandbox machine sizes + the E2B template aliases derived from them.
2
+ * Sandbox machine sizes — THE single source of the size vocabulary.
3
3
  *
4
- * A coarse hardware knob that maps to provider machine specs at create time:
5
- * Vercel honours it natively via `resources.vcpus`; E2B sizing is baked into
6
- * the template, so on E2B a size resolves to a pre-built per-size template.
4
+ * Everything that names a size (the server's `SANDBOX_DEFAULT_SIZE` env enum,
5
+ * the register/invoke zod schemas, the run + session row types, the CLI's
6
+ * `--size` flag, the dashboard pickers via `GET /v1/sandbox-sizes`) derives
7
+ * from `SANDBOX_SIZES` / `SandboxSize` here. Adding a size is a ONE-LINE edit
8
+ * to `SANDBOX_MACHINES`: the type, the enums, the E2B build matrix and the
9
+ * pickers all follow. Do NOT re-declare the union inline anywhere.
10
+ *
11
+ * A size is a coarse hardware knob that maps to provider machine specs:
12
+ * Vercel honours it natively via `resources.vcpus`; E2B sizing is BAKED INTO
13
+ * THE TEMPLATE (e2b 2.30.5 has no create-time cpu/mem knob — `NewSandbox`
14
+ * carries only `templateID`), so on E2B a size resolves to a pre-built
15
+ * per-size template.
7
16
  */
8
- /** Sandbox hardware SKU. Named for the actual machine spec (vCPU + RAM) rather
9
- * than abstract t-shirt sizes. Memory is always 2048 MB per vCPU:
10
- * 2vcpu-4gb = 2 vCPU / 4 GiB (Vercel's own default machine)
11
- * 4vcpu-8gb = 4 vCPU / 8 GiB
12
- * 8vcpu-16gb = 8 vCPU / 16 GiB (per-sandbox ceiling on STANDARD accounts —
13
- * probed live: 16 & 32 vCPU 400 on dev)
14
- * 32vcpu-64gb = 32 vCPU / 64 GiB (ENTERPRISE ONLY — standard accounts reject >8 vCPU) */
15
- export type SandboxSize = "2vcpu-4gb" | "4vcpu-8gb" | "8vcpu-16gb" | "32vcpu-64gb";
16
- /** SKU → Vercel vCPU count (RAM follows at 2048 MB/vCPU). */
17
+ /** Every sandbox hardware SKU, with its real machine spec. Named for the
18
+ * machine (vCPU + RAM) rather than abstract t-shirt sizes, so a size can
19
+ * never quietly mean something different than it says.
20
+ *
21
+ * RAM is 2048 MB/vCPU everywhere EXCEPT `8vcpu-8gb`, which exists because
22
+ * E2B caps a sandbox at 8 vCPU / 8192 MB (e2b.dev/docs/billing: Hobby and
23
+ * Pro both "8 vCPU / 8 GB", raised only by arrangement): 8 vCPU at the 2 GB
24
+ * rule would need 16 GiB and cannot be built. `8vcpu-8gb` is the CPU ceiling
25
+ * at the memory ceiling — the only way to get 8 cores on E2B today, and a
26
+ * spec already proven bakeable by the devbox (`E2B_DEVBOX_SPEC`).
27
+ *
28
+ * Adding an entry here automatically: widens `SandboxSize`, widens every
29
+ * derived enum, and — if it fits under the E2B caps — adds it to
30
+ * `E2B_TEMPLATE_SIZES`, which is what `infra/e2b-template/build.ts` and the
31
+ * `sandbox-images` CI job loop over. Two templates get baked per size, so
32
+ * the matrix is not free; see that workflow's header. */
33
+ export declare const SANDBOX_MACHINES: {
34
+ /** 1 vCPU / 2 GiB — the cheap floor. Plenty for a terminal session or a
35
+ * shell-shaped agent; tight for a big `bun install` or a browser. */
36
+ readonly "1vcpu-2gb": {
37
+ readonly vcpus: 1;
38
+ readonly memoryMB: 2048;
39
+ };
40
+ /** 2 vCPU / 4 GiB — the default (Vercel's own default machine too). */
41
+ readonly "2vcpu-4gb": {
42
+ readonly vcpus: 2;
43
+ readonly memoryMB: 4096;
44
+ };
45
+ /** 4 vCPU / 8 GiB — comfortable for builds and multi-tool agent turns. */
46
+ readonly "4vcpu-8gb": {
47
+ readonly vcpus: 4;
48
+ readonly memoryMB: 8192;
49
+ };
50
+ /** 8 vCPU / 8 GiB — E2B's per-sandbox CEILING (cores maxed at the memory
51
+ * cap). NOT expressible on Vercel, whose RAM follows vCPUs at 2 GB each. */
52
+ readonly "8vcpu-8gb": {
53
+ readonly vcpus: 8;
54
+ readonly memoryMB: 8192;
55
+ };
56
+ /** 8 vCPU / 16 GiB — Vercel only; exceeds E2B's 8 GiB memory cap. */
57
+ readonly "8vcpu-16gb": {
58
+ readonly vcpus: 8;
59
+ readonly memoryMB: 16384;
60
+ };
61
+ /** 32 vCPU / 64 GiB — Vercel Enterprise only; far past every E2B cap. */
62
+ readonly "32vcpu-64gb": {
63
+ readonly vcpus: 32;
64
+ readonly memoryMB: 65536;
65
+ };
66
+ };
67
+ /** Sandbox hardware SKU. Derived from `SANDBOX_MACHINES` — never re-spelled
68
+ * as an inline union. */
69
+ export type SandboxSize = keyof typeof SANDBOX_MACHINES;
70
+ /** The vocabulary as an ordered, smallest-first array — the shape zod
71
+ * (`z.enum`), the CLI's `--size` validation, and the wire catalogue want.
72
+ * Ordering is the pickers' display order, so keep it ascending. */
73
+ export declare const SANDBOX_SIZES: readonly [SandboxSize, ...SandboxSize[]];
74
+ /** SKU → Vercel vCPU count (Vercel's RAM follows automatically at 2048
75
+ * MB/vCPU — which is why `isVercelSupportedSize` exists). */
17
76
  export declare const SANDBOX_VCPUS: Record<SandboxSize, number>;
18
77
  /** SDK fallback size when neither the caller nor the deployment specifies one.
19
78
  * Deliberately conservative — the OPERATIONAL default is the server's
@@ -21,30 +80,61 @@ export declare const SANDBOX_VCPUS: Record<SandboxSize, number>;
21
80
  * small matters because Vercel rate-limits creation by vCPUs-per-window
22
81
  * (`api-sandboxes-vcpus-creation`); a large default 429s bursty/simultaneous
23
82
  * creates. Workloads that need more RAM/CPU declare `resources.size` on the
24
- * workflow rather than inflating the default for everyone. */
83
+ * workflow rather than inflating the default for everyone.
84
+ *
85
+ * NOT `1vcpu-2gb`: the floor is an opt-IN for cheap sessions, not a quiet
86
+ * downgrade of every existing run's machine. */
25
87
  export declare const DEFAULT_SANDBOX_SIZE: SandboxSize;
26
- /** The E2B sizes we pre-build a template for. E2B sizing is template-baked
27
- * (no per-create cpu/mem knob), so honouring `resources.size` on E2B means
28
- * ONE pre-built template per size. `32vcpu-64gb` is absent (E2B has no
29
- * >8-vCPU equivalent). `8vcpu-16gb` is also absent: it needs 16 GiB RAM, but
30
- * the E2B account caps memory at 8 GiB (`Template.build` 400s with
31
- * "Memory can't be higher than 8192 MiB"). Add it back here (and rebuild the
32
- * templates) only once the account's memory limit is raised. The register/
33
- * invoke guards reject an unsupported E2B size before it can reach here. */
88
+ /** SESSION default — deliberately one size up from the run default
89
+ * (2026-08-13): a session's sandbox carries the full desktop toolbelt
90
+ * (VS Code + Chromium + dockerd) plus the KasmVNC encoder at the 60fps
91
+ * cap, and that stack swap-thrashes on 4 GiB while the encoder starves on
92
+ * 2 shared vCPUs. Workflow runs keep DEFAULT_SANDBOX_SIZE — no desktop,
93
+ * no toolbelt weight. Sessions bill active time only (parked = storage),
94
+ * so the delta applies to active hours, not the fleet. */
95
+ export declare const SESSION_DEFAULT_SANDBOX_SIZE: SandboxSize;
96
+ /** E2B's per-sandbox ceiling on the plans we run (e2b.dev/docs/billing —
97
+ * Hobby: "8 vCPU / 8 GB"; Pro: the same, "8+" only by arrangement with
98
+ * support). Recorded live too: `Template.build` 400s with "Memory can't be
99
+ * higher than 8192 MiB" past the memory cap.
100
+ *
101
+ * These two numbers are the ONLY knob for which sizes get an E2B template —
102
+ * raise them after E2B raises the account limit and the build matrix (and
103
+ * therefore the session picker) widens on its own. */
104
+ export declare const E2B_MAX_VCPUS = 8;
105
+ export declare const E2B_MAX_MEMORY_MB = 8192;
106
+ /** The E2B sizes we pre-build a template for — DERIVED from the caps, not
107
+ * hand-listed, so a new `SANDBOX_MACHINES` entry can never be offered
108
+ * without a template or omitted despite fitting. E2B sizing is
109
+ * template-baked (no per-create cpu/mem knob), so honouring `resources.size`
110
+ * on E2B means ONE pre-built template per size; `infra/e2b-template/build.ts`
111
+ * loops exactly this list. The register / invoke / session-spawn / resize
112
+ * guards all reject an unsupported E2B size before it can reach a create. */
34
113
  export declare const E2B_TEMPLATE_SIZES: readonly SandboxSize[];
35
- /** Is `size` one E2B can be built/booted at? `32vcpu-64gb` (no >8-vCPU E2B
36
- * equivalent) and `8vcpu-16gb` (exceeds the account's 8 GiB memory cap) are
37
- * not — the guards lean on this so the "no E2B equivalent" decision lives in
38
- * exactly one place. */
114
+ /** Is `size` one E2B can be built/booted at? False for the sizes past E2B's
115
+ * 8 vCPU / 8 GiB ceiling (`8vcpu-16gb`, `32vcpu-64gb`) — those run on Vercel.
116
+ * The "no E2B equivalent" decision lives in exactly one place: the caps. */
39
117
  export declare function isE2bSupportedSize(size: SandboxSize): boolean;
40
- /** Machine spec for a SandboxSize, in the shape `Template.build` wants. RAM is
41
- * always 2048 MB/vCPU, matching the size name + Vercel parity
42
- * (`SANDBOX_VCPUS` × 2048). Used by `infra/e2b-template/build.ts` to stamp the
43
- * per-size base + agent-env templates. */
118
+ /** Vercel's fixed memory-per-vCPU ratio. Vercel takes `resources.vcpus` and
119
+ * allocates RAM itself at this rate — there is no independent memory knob. */
120
+ export declare const VERCEL_MEMORY_MB_PER_VCPU = 2048;
121
+ /** Is `size` expressible on Vercel? Only when its RAM matches what Vercel
122
+ * would allocate for that vCPU count — otherwise asking for it would hand
123
+ * the caller a machine that does not match the name (`8vcpu-8gb` would come
124
+ * back with 16 GiB). Vercel's own ceiling (32 vCPU, Enterprise) is a plan
125
+ * matter, not a shape matter, so it is not encoded here. */
126
+ export declare function isVercelSupportedSize(size: SandboxSize): boolean;
127
+ /** Machine spec for a SandboxSize, in the shape `Template.build` wants. Used
128
+ * by `infra/e2b-template/build.ts` to stamp the per-size base + agent-env
129
+ * templates. Reads the explicit table rather than deriving RAM from vCPUs —
130
+ * `8vcpu-8gb` is deliberately off the 2048 MB/vCPU line. */
44
131
  export declare function e2bMachineSpec(size: SandboxSize): {
45
132
  cpuCount: number;
46
133
  memoryMB: number;
47
134
  };
135
+ /** Human label for a size — "2 vCPU · 4 GB". The wire catalogue carries it so
136
+ * the dashboard never has to parse the id back into numbers. */
137
+ export declare function sandboxSizeLabel(size: SandboxSize): string;
48
138
  /** Stable E2B template ALIAS for the platform base at a given size
49
139
  * (`agent-compose-base-<size>`). Aliases — not snapshot ids — so the refs are
50
140
  * multi-account-clean: the same string resolves in any E2B account that built
package/dist/sandbox.d.ts CHANGED
@@ -14,7 +14,7 @@ export type { SandboxProvider, DesktopSandboxProvider, SandboxCommandRunOptions,
14
14
  export type { SandboxNetworkHeaderTransform, SandboxNetworkAllowRule, SandboxNetworkSubnetPolicy, SandboxNetworkPolicy, } from "./sandbox/network-policy.js";
15
15
  export { DOT_SEGMENT_PATH_RE2, toVercelNetworkPolicy, toE2bNetwork } from "./sandbox/network-policy.js";
16
16
  export type { SandboxSize } from "./sandbox/sizes.js";
17
- export { SANDBOX_VCPUS, DEFAULT_SANDBOX_SIZE, E2B_TEMPLATE_SIZES, isE2bSupportedSize, e2bMachineSpec, e2bBaseTemplate, e2bAgentEnvTemplate, isPlatformE2bTemplateAlias, } from "./sandbox/sizes.js";
17
+ export { SANDBOX_SIZES, SANDBOX_MACHINES, SANDBOX_VCPUS, DEFAULT_SANDBOX_SIZE, SESSION_DEFAULT_SANDBOX_SIZE, E2B_TEMPLATE_SIZES, E2B_MAX_VCPUS, E2B_MAX_MEMORY_MB, VERCEL_MEMORY_MB_PER_VCPU, isE2bSupportedSize, isVercelSupportedSize, sandboxSizeLabel, e2bMachineSpec, e2bBaseTemplate, e2bAgentEnvTemplate, isPlatformE2bTemplateAlias, } from "./sandbox/sizes.js";
18
18
  export { E2B_DEVBOX_TEMPLATE, E2B_DEVBOX_SPEC, E2B_DEVBOX_RECIPE_VERSION, e2bDevboxTemplateRef, } from "./sandbox/devbox.js";
19
19
  export { AGENT_COMPOSE_TAG } from "./sandbox/provider-def.js";
20
20
  export type { SandboxCreateOpts, OwnedSandbox } from "./sandbox/provider-def.js";