@effect-uai/deno 0.12.0 → 0.13.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/dist/DenoSandbox.d.mts
CHANGED
|
@@ -3,8 +3,6 @@ import { BoundSecret, CommonCreateRequest, Sandbox, SandboxHostnameAllowlist, Sa
|
|
|
3
3
|
import * as SandboxError from "@effect-uai/core/SandboxError";
|
|
4
4
|
import { Context, Effect, Layer, Redacted, Scope } from "effect";
|
|
5
5
|
import { ApiError, ConnectionClosedError, ConnectionEstablishmentError, InvalidMemoryError, InvalidTimeoutError, InvalidTokenError, MissingTokenError, SandboxCommandError, SandboxKillError } from "@deno/sandbox";
|
|
6
|
-
|
|
7
|
-
//#region src/DenoSandbox.d.ts
|
|
8
6
|
declare namespace DenoSandbox_d_exports {
|
|
9
7
|
export { ApiError, ConnectionClosedError, ConnectionEstablishmentError, DenoRegion, DenoSandbox, DenoSandboxBoundSecret, DenoSandboxConfig, DenoSandboxCreateRequest, DenoSandboxService, InvalidMemoryError, InvalidTimeoutError, InvalidTokenError, MissingTokenError, SandboxCommandError, SandboxKillError, layer };
|
|
10
8
|
}
|
|
@@ -19,13 +17,18 @@ type DenoSandboxCreateRequest = Omit<CommonCreateRequest, "secrets"> & {
|
|
|
19
17
|
* range at GA is 768 MiB – 4 GiB (default 1280 MiB).
|
|
20
18
|
*/
|
|
21
19
|
readonly memory?: Memory.Input;
|
|
22
|
-
readonly labels?: Readonly<Record<string, string>>;
|
|
20
|
+
readonly labels?: Readonly<Record<string, string>>;
|
|
21
|
+
/** Auto-expose this port at boot; the live sandbox's `url` reaches it. */
|
|
23
22
|
readonly port?: number;
|
|
24
23
|
};
|
|
25
24
|
type DenoSandboxConfig = {
|
|
26
|
-
/** Overrides `DENO_DEPLOY_TOKEN`. */
|
|
27
|
-
readonly
|
|
28
|
-
|
|
25
|
+
/** Overrides `DENO_DEPLOY_TOKEN`. */
|
|
26
|
+
readonly token?: Redacted.Redacted<string>;
|
|
27
|
+
/** Overrides `DENO_DEPLOY_ORG`. Required for personal `ddp_` tokens. */
|
|
28
|
+
readonly org?: string;
|
|
29
|
+
/** Overrides `DENO_DEPLOY_ENDPOINT`. */
|
|
30
|
+
readonly apiEndpoint?: string;
|
|
31
|
+
/** Default region when create requests omit one. */
|
|
29
32
|
readonly defaultRegion?: DenoRegion;
|
|
30
33
|
};
|
|
31
34
|
/**
|
|
@@ -70,7 +73,7 @@ declare class DenoSandbox extends DenoSandbox_base {}
|
|
|
70
73
|
* - `SandboxPauseResume` — Deno doesn't offer in-place memory-preserving pause.
|
|
71
74
|
* - `SandboxKernelSession`, `SandboxPty` — no Jupyter / no PTY.
|
|
72
75
|
*/
|
|
73
|
-
declare const layer: (config?: DenoSandboxConfig) => Layer.Layer<DenoSandbox | Sandbox | SandboxHostnameAllowlist | SandboxSecretInjection | SandboxSnapshots | SandboxVolumes
|
|
76
|
+
declare const layer: (config?: DenoSandboxConfig) => Layer.Layer<DenoSandbox | Sandbox | SandboxHostnameAllowlist | SandboxPortExposure | SandboxSecretInjection | SandboxSnapshots | SandboxVolumes, never, never>;
|
|
74
77
|
//#endregion
|
|
75
78
|
export { ApiError, ConnectionClosedError, ConnectionEstablishmentError, DenoRegion, DenoSandbox, DenoSandboxBoundSecret, DenoSandboxConfig, DenoSandboxCreateRequest, DenoSandboxService, InvalidMemoryError, InvalidTimeoutError, InvalidTokenError, MissingTokenError, SandboxCommandError, SandboxKillError, layer, DenoSandbox_d_exports as t };
|
|
76
79
|
//# sourceMappingURL=DenoSandbox.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DenoSandbox.d.mts","names":[],"sources":["../src/DenoSandbox.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DenoSandbox.d.mts","names":[],"sources":["../src/DenoSandbox.ts"],"mappings":";;;;;;;;KAoEY,yBAAyB,KAAK;KAE9B;KAEA,2BAA2B,KAAK;WACjC,UAAU,cAAc;WACxB,SAAS;;;;;;WAMT,SAAS,OAAO;WAChB,SAAS,SAAS;;WAElB;;KAGC;;WAED,QAAQ,SAAS;;WAEjB;;WAEA;;WAEA,gBAAgB;;;;;;;;;;;KAYf,qBAAqB,KAAK;WAC3B,SACP,SAAS,6BACN,OAAO,OAAO,iBAAiB,aAAa,cAAc,MAAM;;;;;;;WAO5D,iBACP,UAAU,UACV,kBACG,OAAO,OAAO,YAAY,aAAa;;;cAGjC,oBAAoB;;;;;;;;;;;;;;;;;;;;;;cAywBpB,QAAK,SAAY,sBAAiB,MAAA,MAAA,cAAA,UAAA,2BAAA,sBAAA,yBAAA,mBAAA"}
|
package/dist/DenoSandbox.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as __exportAll } from "./
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import * as Memory from "@effect-uai/core/Memory";
|
|
3
3
|
import { ExecEvent, Sandbox, SandboxHostnameAllowlist, SandboxId, SandboxPortExposure, SandboxSecretInjection, SandboxSnapshots, SandboxVolumes, SnapshotId, VolumeId } from "@effect-uai/core/Sandbox";
|
|
4
4
|
import * as SandboxError from "@effect-uai/core/SandboxError";
|
|
@@ -119,13 +119,14 @@ const volumesStep = (volumes) => {
|
|
|
119
119
|
return Effect.succeed(set("volumes", map));
|
|
120
120
|
};
|
|
121
121
|
const secretsStep = (secrets) => {
|
|
122
|
-
|
|
122
|
+
const record = Array.reduce(secrets, {}, (acc, s) => {
|
|
123
123
|
acc[s.name] = {
|
|
124
124
|
hosts: [...s.hosts],
|
|
125
125
|
value: Redacted.value(s.value)
|
|
126
126
|
};
|
|
127
127
|
return acc;
|
|
128
|
-
})
|
|
128
|
+
});
|
|
129
|
+
return set("secrets", record);
|
|
129
130
|
};
|
|
130
131
|
const baseClientOptions = (config) => ({
|
|
131
132
|
...config.token === void 0 ? {} : { token: Redacted.value(config.token) },
|
|
@@ -223,8 +224,10 @@ const adaptInstance = (sdk, portRegistry) => {
|
|
|
223
224
|
}),
|
|
224
225
|
catch: mapExecError
|
|
225
226
|
})), (c) => Effect.promise(() => c.kill("SIGKILL").catch(() => void 0)).pipe(Effect.ignore));
|
|
226
|
-
if (request.stdin !== void 0)
|
|
227
|
-
|
|
227
|
+
if (request.stdin !== void 0) {
|
|
228
|
+
if (stdinIsStream(request.stdin)) yield* Effect.forkScoped(feedStreamStdin(child, request.stdin));
|
|
229
|
+
else yield* writeStdinBytes(child, toBytes(request.stdin));
|
|
230
|
+
}
|
|
228
231
|
return {
|
|
229
232
|
child,
|
|
230
233
|
startedAt
|
|
@@ -341,10 +344,11 @@ const buildService = (config) => {
|
|
|
341
344
|
destroy: destroyById,
|
|
342
345
|
snapshotVolume: (volumeId, slug) => Effect.gen(function* () {
|
|
343
346
|
const snapSlug = slug ?? `eff-uai-snap-${yield* randomToken}`;
|
|
344
|
-
|
|
347
|
+
const snap = yield* Effect.tryPromise({
|
|
345
348
|
try: () => client.volumes.snapshot(volumeId, { slug: snapSlug }),
|
|
346
349
|
catch: mapCreateError
|
|
347
|
-
})
|
|
350
|
+
});
|
|
351
|
+
return SnapshotId(snap.slug);
|
|
348
352
|
}),
|
|
349
353
|
snapshots: {
|
|
350
354
|
create: () => Effect.fail(new SandboxError.SandboxUnsupported({
|
package/dist/DenoSandbox.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DenoSandbox.mjs","names":["Arr","CoreExecEvent","DenoSdkSandbox","CoreSandbox"],"sources":["../src/DenoSandbox.ts"],"sourcesContent":["import * as Memory from \"@effect-uai/core/Memory\"\nimport {\n ExecEvent as CoreExecEvent,\n Sandbox as CoreSandbox,\n SandboxHostnameAllowlist,\n SandboxPortExposure,\n SandboxSecretInjection,\n SandboxSnapshots,\n SandboxVolumes,\n type BoundSecret,\n type CommonCreateRequest,\n type CommonExecRequest,\n type CommonSpawnRequest,\n type ExecResult,\n type ImageRef,\n type NetworkPolicy,\n type ProcessHandle,\n SandboxId,\n type SandboxInstance,\n type SandboxRef,\n type SandboxService,\n SnapshotId,\n VolumeId,\n} from \"@effect-uai/core/Sandbox\"\nimport * as SandboxError from \"@effect-uai/core/SandboxError\"\nimport {\n Array as Arr,\n Clock,\n Context,\n Duration,\n Effect,\n Layer,\n Match,\n Option,\n Random,\n Redacted,\n Schedule,\n Scope,\n Stream,\n} from \"effect\"\nimport {\n ApiError,\n Client,\n ConnectionClosedError,\n ConnectionEstablishmentError,\n InvalidMemoryError,\n InvalidTimeoutError,\n InvalidTokenError,\n MissingTokenError,\n Sandbox as DenoSdkSandbox,\n SandboxCommandError,\n SandboxKillError,\n type ChildProcess as DenoChildProcess,\n type SandboxOptions,\n type SecretConfig,\n} from \"@deno/sandbox\"\n\nconst PROVIDER = \"deno\"\n\n// ---------------------------------------------------------------------------\n// Provider-narrowed request types.\n//\n// Deno's `secrets: Record<name, SecretConfig>` shape has no per-secret\n// custom header — substitution is always \"Authorization: Bearer <value>\".\n// We omit `header` on the typed surface (row B) and reject at the upcast\n// adapter (row D) if a caller routes through the generic `Sandbox.create`.\n// ---------------------------------------------------------------------------\n\nexport type DenoSandboxBoundSecret = Omit<BoundSecret, \"header\">\n\nexport type DenoRegion = \"ord\" | \"ams\"\n\nexport type DenoSandboxCreateRequest = Omit<CommonCreateRequest, \"secrets\"> & {\n readonly secrets?: ReadonlyArray<DenoSandboxBoundSecret>\n readonly region?: DenoRegion\n /**\n * Memory size for the sandbox. Accepts a byte count, a {@link Memory.Memory},\n * or a human string like `\"1280 MiB\"` / `\"1 GiB\"`. Deno's accepted\n * range at GA is 768 MiB – 4 GiB (default 1280 MiB).\n */\n readonly memory?: Memory.Input\n readonly labels?: Readonly<Record<string, string>>\n /** Auto-expose this port at boot; the live sandbox's `url` reaches it. */\n readonly port?: number\n}\n\nexport type DenoSandboxConfig = {\n /** Overrides `DENO_DEPLOY_TOKEN`. */\n readonly token?: Redacted.Redacted<string>\n /** Overrides `DENO_DEPLOY_ORG`. Required for personal `ddp_` tokens. */\n readonly org?: string\n /** Overrides `DENO_DEPLOY_ENDPOINT`. */\n readonly apiEndpoint?: string\n /** Default region when create requests omit one. */\n readonly defaultRegion?: DenoRegion\n}\n\n/**\n * Deno-narrowed service. `create` accepts the narrowed\n * {@link DenoSandboxCreateRequest}; every other method is identical to\n * the generic {@link SandboxService} except for the per-provider\n * `snapshotVolume` escape hatch — Deno snapshots are derived from\n * volumes, not from live sandboxes, so the generic\n * `Sandbox.snapshots.create(fromInstance)` doesn't fit and fails with\n * `SandboxUnsupported`.\n */\nexport type DenoSandboxService = Omit<SandboxService, \"create\"> & {\n readonly create: (\n request: DenoSandboxCreateRequest,\n ) => Effect.Effect<SandboxInstance, SandboxError.SandboxError, Scope.Scope>\n /**\n * Snapshot an existing volume by id/slug. Deno's snapshot model is\n * volume-derived, so the generic `Sandbox.snapshots.create` doesn't\n * apply — use this escape hatch instead. The volume must not be\n * attached to any running sandbox at the time of snapshot.\n */\n readonly snapshotVolume: (\n volumeId: VolumeId,\n slug?: string,\n ) => Effect.Effect<SnapshotId, SandboxError.SandboxError>\n}\n\nexport class DenoSandbox extends Context.Service<DenoSandbox, DenoSandboxService>()(\n \"@betalyra/effect-uai/providers/deno/DenoSandbox\",\n) {}\n\n// ---------------------------------------------------------------------------\n// Effect-native primitives\n// ---------------------------------------------------------------------------\n\n/** Random base-36 token, ~8 chars. */\nconst randomToken = Random.next.pipe(Effect.map((r) => r.toString(36).slice(2, 10)))\n\n// ---------------------------------------------------------------------------\n// Error mapping\n// ---------------------------------------------------------------------------\n\nconst reasonOf = (e: unknown) => (e instanceof Error ? { reason: e.message } : {})\n\nconst isAuthError = (e: unknown): boolean =>\n e instanceof MissingTokenError ||\n e instanceof InvalidTokenError ||\n (e instanceof ApiError && (e.status === 401 || e.status === 403)) ||\n (e instanceof ConnectionEstablishmentError && (e.status === 401 || e.status === 403))\n\nconst isQuotaError = (e: unknown): boolean =>\n (e instanceof ApiError && e.status === 429) ||\n (e instanceof ConnectionEstablishmentError && e.status === 429)\n\n/**\n * \"Sandbox is no longer reachable\" — covers both the 404 (never existed)\n * and the 400 + `SANDBOX_ALREADY_TERMINATED` case the API returns when\n * you `connect` to a sandbox after its `kill`. Both map to\n * `SandboxNotFound` so `destroy` and friends stay idempotent.\n */\nconst isNotFoundError = (e: unknown): boolean =>\n (e instanceof ApiError && (e.status === 404 || e.code === \"SANDBOX_ALREADY_TERMINATED\")) ||\n (e instanceof ConnectionEstablishmentError &&\n (e.status === 404 || e.code === \"SANDBOX_ALREADY_TERMINATED\"))\n\nconst mapCreateError = (e: unknown): SandboxError.SandboxError =>\n isAuthError(e)\n ? new SandboxError.SandboxAuthFailed({ provider: PROVIDER, subtype: \"auth\", raw: e })\n : isQuotaError(e)\n ? new SandboxError.SandboxQuotaExceeded({\n provider: PROVIDER,\n raw: e,\n ...reasonOf(e),\n })\n : e instanceof InvalidTimeoutError || e instanceof InvalidMemoryError\n ? new SandboxError.SandboxInvalidRequest({\n provider: PROVIDER,\n raw: e,\n ...reasonOf(e),\n })\n : new SandboxError.SandboxCreateFailed({\n provider: PROVIDER,\n raw: e,\n ...reasonOf(e),\n })\n\nconst mapLookupError =\n (id: string) =>\n (e: unknown): SandboxError.SandboxError =>\n isNotFoundError(e)\n ? new SandboxError.SandboxNotFound({ provider: PROVIDER, id })\n : mapCreateError(e)\n\nconst mapExecError = (e: unknown): SandboxError.SandboxError =>\n e instanceof SandboxCommandError\n ? new SandboxError.SandboxExecFailed({\n provider: PROVIDER,\n raw: e,\n reason: e.message,\n })\n : e instanceof ConnectionClosedError\n ? new SandboxError.SandboxExecFailed({\n provider: PROVIDER,\n raw: e,\n reason: e.reason ?? \"connection closed\",\n })\n : new SandboxError.SandboxExecFailed({\n provider: PROVIDER,\n raw: e,\n ...reasonOf(e),\n })\n\nconst mapFsError = (e: unknown): SandboxError.SandboxError =>\n new SandboxError.SandboxExecFailed({\n provider: PROVIDER,\n raw: e,\n ...reasonOf(e),\n })\n\n// ---------------------------------------------------------------------------\n// Transient WebSocket handshake failures.\n//\n// Empirically (SDK 0.13.2): `sdk.spawn` opens a per-process WebSocket\n// to the sandbox-side relay. The Deploy edge intermittently returns\n// `500 SANDBOX_WEBSOCKET_HANDSHAKE_ERROR` on this handshake; the next\n// attempt against the same sandbox typically succeeds. Retry narrowly\n// on that specific code rather than blanketing all 5xx — most are not\n// transient.\n//\n// Budget: 3 attempts ≈ 500+1000+2000 = 3.5s on top of the original\n// call, well under the 120s test timeout.\n// ---------------------------------------------------------------------------\n\nconst isTransientWsHandshake = (e: SandboxError.SandboxError) =>\n (e._tag === \"SandboxExecFailed\" || e._tag === \"SandboxCreateFailed\") &&\n e.raw instanceof ConnectionEstablishmentError &&\n e.raw.code === \"SANDBOX_WEBSOCKET_HANDSHAKE_ERROR\"\n\nconst wsHandshakeSchedule = Schedule.exponential(\"500 millis\")\nconst WS_HANDSHAKE_RETRIES = 3\n\nconst retryOnTransientWs = <A, R>(\n effect: Effect.Effect<A, SandboxError.SandboxError, R>,\n): Effect.Effect<A, SandboxError.SandboxError, R> =>\n Effect.retry(effect, {\n schedule: wsHandshakeSchedule,\n times: WS_HANDSHAKE_RETRIES,\n while: isTransientWsHandshake,\n })\n\n// ---------------------------------------------------------------------------\n// Builder pipeline — a `Step` mutates `SandboxOptions`. Deno's create\n// API is a plain options object (no builder fluent API), so each Step\n// returns a partial overlay; the create flow folds them into the base.\n// Keeping the same shape as microsandbox's `Step` pattern means optional\n// fields read uniformly.\n// ---------------------------------------------------------------------------\n\ntype OptionsPatch = Partial<SandboxOptions>\ntype Step = (patch: OptionsPatch) => OptionsPatch\n\nconst noop: Step = (p) => p\n\nconst when = <A>(value: A | undefined, step: (a: A) => Step): Step =>\n value === undefined ? noop : step(value)\n\nconst set =\n <K extends keyof SandboxOptions>(key: K, value: SandboxOptions[K]): Step =>\n (p) => ({ ...p, [key]: value })\n\n// ---------------------------------------------------------------------------\n// Duration → Deno timeout format (\"30s\"). Deno's `create.timeout`\n// accepts `\"session\" | \"${number}s\" | \"${number}m\"`; we always emit\n// `<seconds>s` since seconds is the most precise unit honored.\n// ---------------------------------------------------------------------------\n\nconst toDenoSeconds = (d: Duration.Input): `${number}s` => {\n const secs = Math.max(1, Math.ceil(Duration.toMillis(Duration.fromInputUnsafe(d)) / 1000))\n return `${secs}s`\n}\n\n// ---------------------------------------------------------------------------\n// ImageRef → Step. Default omits `root`; Snapshot sets it; Registry /\n// Dockerfile are unsupported and fail at decode.\n// ---------------------------------------------------------------------------\n\nconst imageStep = (image: ImageRef | undefined): Effect.Effect<Step, SandboxError.SandboxError> => {\n if (image === undefined) return Effect.succeed(noop)\n return Match.value(image).pipe(\n Match.tag(\n \"Default\",\n (): Effect.Effect<Step, SandboxError.SandboxError> => Effect.succeed(noop),\n ),\n Match.tag(\n \"Snapshot\",\n ({ id }): Effect.Effect<Step, SandboxError.SandboxError> => Effect.succeed(set(\"root\", id)),\n ),\n Match.tag(\n \"Registry\",\n (): Effect.Effect<Step, SandboxError.SandboxError> =>\n Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"image.registry\",\n reason: \"deno sandboxes do not accept OCI registry refs — boot from a snapshot instead\",\n }),\n ),\n ),\n Match.tag(\n \"Dockerfile\",\n (): Effect.Effect<Step, SandboxError.SandboxError> =>\n Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"image.dockerfile\",\n reason:\n \"deno sandboxes do not accept Dockerfiles — install software into a bootable volume then snapshot it\",\n }),\n ),\n ),\n Match.exhaustive,\n )\n}\n\n// ---------------------------------------------------------------------------\n// NetworkPolicy → Step. Deno accepts hostnames + literal IPs but no\n// CIDR ranges; reject `cidrs` rather than silently dropping. `Blocked`\n// encodes as empty allowlist; `Open` omits the field.\n// ---------------------------------------------------------------------------\n\nconst networkStep = (policy: NetworkPolicy): Effect.Effect<Step, SandboxError.SandboxError> =>\n Match.value(policy).pipe(\n Match.tag(\"Open\", (): Effect.Effect<Step, SandboxError.SandboxError> => Effect.succeed(noop)),\n Match.tag(\n \"Blocked\",\n (): Effect.Effect<Step, SandboxError.SandboxError> => Effect.succeed(set(\"allowNet\", [])),\n ),\n Match.tag(\n \"Allowlist\",\n ({ hosts, cidrs }): Effect.Effect<Step, SandboxError.SandboxError> =>\n cidrs !== undefined && cidrs.length > 0\n ? Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"network.cidrs\",\n reason:\n \"deno's allowNet accepts hostnames or literal IPs, not CIDR ranges — use hosts instead\",\n }),\n )\n : Effect.succeed(set(\"allowNet\", [...(hosts ?? [])])),\n ),\n Match.exhaustive,\n )\n\n// ---------------------------------------------------------------------------\n// Volumes → Step. Deno mounts read-write only; reject `readonly: true`.\n// ---------------------------------------------------------------------------\n\nconst volumesStep = (\n volumes: CommonCreateRequest[\"volumes\"],\n): Effect.Effect<Step, SandboxError.SandboxError> => {\n if (volumes === undefined || volumes.length === 0) return Effect.succeed(noop)\n if (volumes.some((v) => v.readonly === true)) {\n return Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"volumes.readonly\",\n reason: \"deno mounts volumes read-write — read-only mounts are not supported\",\n }),\n )\n }\n const map = Arr.reduce(volumes, {} as Record<string, string>, (acc, v) => {\n acc[v.mountPath] = v.id\n return acc\n })\n return Effect.succeed(set(\"volumes\", map))\n}\n\n// ---------------------------------------------------------------------------\n// Secrets → Step. Stays sync — no decode-time failure modes (custom\n// header is rejected upstream in the upcast).\n// ---------------------------------------------------------------------------\n\nconst secretsStep = (secrets: ReadonlyArray<DenoSandboxBoundSecret>): Step => {\n const record = Arr.reduce(secrets, {} as Record<string, SecretConfig>, (acc, s) => {\n acc[s.name] = { hosts: [...s.hosts], value: Redacted.value(s.value) }\n return acc\n })\n return set(\"secrets\", record)\n}\n\n// ---------------------------------------------------------------------------\n// Base client options used for both client construction and per-call\n// overrides. `token` is a Redacted — we unwrap at the SDK boundary.\n// ---------------------------------------------------------------------------\n\nconst baseClientOptions = (config: DenoSandboxConfig): SandboxOptions => ({\n ...(config.token === undefined ? {} : { token: Redacted.value(config.token) }),\n ...(config.org === undefined ? {} : { org: config.org }),\n ...(config.apiEndpoint === undefined ? {} : { apiEndpoint: config.apiEndpoint }),\n})\n\n// ---------------------------------------------------------------------------\n// argv splitter. Deno's `spawn(command, { args })` is direct argv only —\n// for `cmd: string` (shell semantics) we route through `bash -c`.\n// ---------------------------------------------------------------------------\n\nconst argv = (\n cmd: CommonExecRequest[\"cmd\"],\n): Effect.Effect<\n { readonly command: string; readonly args: ReadonlyArray<string> },\n SandboxError.SandboxError\n> =>\n typeof cmd === \"string\"\n ? Effect.succeed({ command: \"bash\", args: [\"-c\", cmd] })\n : Option.match(Arr.head(cmd), {\n onNone: () =>\n Effect.fail(\n new SandboxError.SandboxInvalidRequest({\n provider: PROVIDER,\n param: \"cmd\",\n reason: \"argv array must be non-empty\",\n }),\n ),\n onSome: (head) => Effect.succeed({ command: head, args: Arr.drop(cmd, 1) }),\n })\n\n// ---------------------------------------------------------------------------\n// AbortController scoped to the caller. On scope close we abort, which\n// signals the SDK to terminate the in-flight call. This is the kill-\n// switch the SDK responds to.\n// ---------------------------------------------------------------------------\n\nconst acquireAbortController: Effect.Effect<AbortController, never, Scope.Scope> =\n Effect.acquireRelease(\n Effect.sync(() => new AbortController()),\n (ac) => Effect.sync(() => ac.abort()),\n )\n\n// ---------------------------------------------------------------------------\n// stdin helpers\n// ---------------------------------------------------------------------------\n\nconst stdinIsStream = (\n stdin: CommonSpawnRequest[\"stdin\"],\n): stdin is Stream.Stream<Uint8Array, never, never> =>\n stdin !== undefined && typeof stdin !== \"string\" && !(stdin instanceof Uint8Array)\n\n/**\n * Copy into a fresh `Uint8Array<ArrayBuffer>`. The Deno SDK strictly\n * types its bytes argument as `Uint8Array<ArrayBuffer>` (not the\n * `ArrayBufferLike` upper bound), so `TextEncoder`-produced bytes and\n * caller-supplied Uint8Arrays need to be copied to a guaranteed-\n * `ArrayBuffer`-backed buffer to satisfy the type.\n */\nconst toBytes = (input: Uint8Array | string): Uint8Array<ArrayBuffer> => {\n const src = typeof input === \"string\" ? new TextEncoder().encode(input) : input\n const out = new Uint8Array(new ArrayBuffer(src.byteLength))\n out.set(src)\n return out\n}\n\n/**\n * Acquire the child's stdin writer, run `use(writer)`, then close the\n * writer on release (regardless of success / failure / interrupt).\n * Returns `Effect.void` if the child wasn't spawned with `stdin: \"piped\"`.\n */\nconst withStdinWriter = <A, E, R>(\n child: DenoChildProcess,\n use: (writer: WritableStreamDefaultWriter<Uint8Array>) => Effect.Effect<A, E, R>,\n): Effect.Effect<void | A, E | SandboxError.SandboxError, R> => {\n const stdin = child.stdin\n if (stdin === null) return Effect.void\n return Effect.acquireUseRelease(\n Effect.sync(() => stdin.getWriter()),\n use,\n (writer) => Effect.promise(() => writer.close().catch(() => undefined)).pipe(Effect.ignore),\n )\n}\n\nconst writeStdinBytes = (\n child: DenoChildProcess,\n bytes: Uint8Array,\n): Effect.Effect<void, SandboxError.SandboxError> =>\n withStdinWriter(child, (writer) =>\n Effect.tryPromise({ try: () => writer.write(bytes), catch: mapExecError }),\n ).pipe(Effect.asVoid)\n\nconst feedStreamStdin = (\n child: DenoChildProcess,\n source: Stream.Stream<Uint8Array, never, never>,\n): Effect.Effect<void, SandboxError.SandboxError> =>\n withStdinWriter(child, (writer) =>\n Stream.runForEach(source, (chunk) =>\n Effect.tryPromise({ try: () => writer.write(chunk), catch: mapExecError }),\n ),\n ).pipe(Effect.asVoid)\n\n// ---------------------------------------------------------------------------\n// ReadableStream<Uint8Array> → Stream<Uint8Array>.\n// ---------------------------------------------------------------------------\n\nconst streamFromReadable = (\n readable: ReadableStream<Uint8Array>,\n): Stream.Stream<Uint8Array, SandboxError.SandboxError> =>\n Stream.fromReadableStream({\n evaluate: () => readable,\n onError: mapExecError,\n })\n\n// ---------------------------------------------------------------------------\n// Merge stdout + stderr into a tagged ExecEvent stream terminated by a\n// single Complete event derived from `child.status`.\n// ---------------------------------------------------------------------------\n\nconst eventStream = (\n child: DenoChildProcess,\n startedAt: number,\n): Stream.Stream<CoreExecEvent, SandboxError.SandboxError> => {\n const stdout: Stream.Stream<CoreExecEvent, SandboxError.SandboxError> =\n child.stdout === null\n ? Stream.empty\n : Stream.map(streamFromReadable(child.stdout), (chunk) => CoreExecEvent.Stdout({ chunk }))\n const stderr: Stream.Stream<CoreExecEvent, SandboxError.SandboxError> =\n child.stderr === null\n ? Stream.empty\n : Stream.map(streamFromReadable(child.stderr), (chunk) => CoreExecEvent.Stderr({ chunk }))\n const complete: Stream.Stream<CoreExecEvent, SandboxError.SandboxError> = Stream.unwrap(\n Effect.gen(function* () {\n const status = yield* Effect.tryPromise({ try: () => child.status, catch: mapExecError })\n const now = yield* Clock.currentTimeMillis\n return Stream.succeed(\n CoreExecEvent.Complete({ exitCode: status.code, durationMs: now - startedAt }),\n )\n }),\n )\n return Stream.concat(Stream.merge(stdout, stderr), complete)\n}\n\n// ---------------------------------------------------------------------------\n// Per-exec timeout. Races against `Effect.sleep` so the parent scope\n// finalizers (which kill the child via `acquireRelease`) fire on breach.\n// We don't lean on `Effect.timeout` because it returns `Option`-shaped\n// fallbacks in v4; the race-based shape lets us keep the SandboxError\n// channel directly.\n// ---------------------------------------------------------------------------\n\nconst withExecTimeout = <A, R>(\n timeout: Duration.Input | undefined,\n effect: Effect.Effect<A, SandboxError.SandboxError, R>,\n): Effect.Effect<A, SandboxError.SandboxError, R> =>\n timeout === undefined\n ? effect\n : Effect.race(\n effect,\n Effect.sleep(timeout).pipe(\n Effect.andThen(\n Effect.fail(\n new SandboxError.SandboxTimeout({\n provider: PROVIDER,\n operation: \"exec\",\n budget: Duration.fromInputUnsafe(timeout),\n }),\n ),\n ),\n ),\n )\n\n// ---------------------------------------------------------------------------\n// Live SandboxInstance adapter. The `WeakMap<SandboxInstance, sdk>`\n// passed in is the back-reference used by the port-exposure sub-API\n// to recover the SDK handle from an opaque `SandboxInstance`.\n// ---------------------------------------------------------------------------\n\nconst adaptInstance = (\n sdk: DenoSdkSandbox,\n portRegistry: WeakMap<SandboxInstance, DenoSdkSandbox>,\n): SandboxInstance => {\n const id = SandboxId(sdk.id)\n\n const openProcess = (request: CommonSpawnRequest) =>\n Effect.gen(function* () {\n const { command, args } = yield* argv(request.cmd)\n const ac = yield* acquireAbortController\n const stdinMode: \"piped\" | \"null\" = request.stdin === undefined ? \"null\" : \"piped\"\n const startedAt = yield* Clock.currentTimeMillis\n const child = yield* Effect.acquireRelease(\n retryOnTransientWs(\n Effect.tryPromise({\n try: () =>\n sdk.spawn(command, {\n args: [...args],\n ...(request.cwd === undefined ? {} : { cwd: request.cwd }),\n ...(request.env === undefined ? {} : { env: { ...request.env } }),\n stdin: stdinMode,\n stdout: \"piped\",\n stderr: \"piped\",\n signal: ac.signal,\n }),\n catch: mapExecError,\n }),\n ),\n (c) => Effect.promise(() => c.kill(\"SIGKILL\").catch(() => undefined)).pipe(Effect.ignore),\n )\n if (request.stdin !== undefined) {\n if (stdinIsStream(request.stdin)) {\n yield* Effect.forkScoped(feedStreamStdin(child, request.stdin))\n } else {\n yield* writeStdinBytes(child, toBytes(request.stdin))\n }\n }\n return { child, startedAt }\n })\n\n const instance: SandboxInstance = {\n id,\n\n exec: (request) =>\n withExecTimeout(\n request.timeout,\n Effect.scoped(\n Effect.gen(function* () {\n const { child, startedAt } = yield* openProcess(request)\n const output = yield* Effect.tryPromise({\n try: () => child.output(),\n catch: mapExecError,\n })\n const completedAt = yield* Clock.currentTimeMillis\n return {\n exitCode: output.status.code,\n stdout: output.stdoutText ?? \"\",\n stderr: output.stderrText ?? \"\",\n durationMs: completedAt - startedAt,\n } satisfies ExecResult\n }),\n ),\n ),\n\n execStream: (request) =>\n Stream.unwrap(\n Effect.map(openProcess(request), ({ child, startedAt }) => eventStream(child, startedAt)),\n ),\n\n spawn: (request) =>\n Effect.map(\n openProcess(request),\n ({ child, startedAt }): ProcessHandle => ({\n pid: child.pid,\n events: eventStream(child, startedAt),\n kill: Effect.tryPromise({\n try: () => child.kill(\"SIGTERM\"),\n catch: mapExecError,\n }),\n exit: Effect.tryPromise({\n try: () => child.status,\n catch: mapExecError,\n }).pipe(Effect.map((status) => ({ exitCode: status.code }))),\n }),\n ),\n\n files: {\n read: (path) => Effect.tryPromise({ try: () => sdk.fs.readFile(path), catch: mapFsError }),\n write: (path, contents) =>\n Effect.tryPromise({\n try: () => sdk.fs.writeFile(path, toBytes(contents)),\n catch: mapFsError,\n }),\n remove: (path) => Effect.tryPromise({ try: () => sdk.fs.remove(path), catch: mapFsError }),\n mkdir: (path) =>\n Effect.tryPromise({\n try: () => sdk.fs.mkdir(path, { recursive: true }),\n catch: mapFsError,\n }),\n list: (path) =>\n Stream.fromAsyncIterable(sdk.fs.readDir(path), mapFsError).pipe(\n Stream.map((e) => ({\n path: e.name,\n kind: e.isFile\n ? (\"file\" as const)\n : e.isDirectory\n ? (\"directory\" as const)\n : e.isSymlink\n ? (\"symlink\" as const)\n : (\"other\" as const),\n })),\n Stream.runCollect,\n ),\n exists: (path) =>\n Effect.tryPromise({\n try: () => sdk.fs.stat(path),\n catch: mapFsError,\n }).pipe(\n Effect.as(true),\n Effect.catchCause(() => Effect.succeed(false)),\n ),\n },\n }\n\n portRegistry.set(instance, sdk)\n return instance\n}\n\n// ---------------------------------------------------------------------------\n// Service factory\n// ---------------------------------------------------------------------------\n\nconst buildService = (config: DenoSandboxConfig): DenoSandboxService => {\n const clientOpts = baseClientOptions(config)\n const client = new Client(clientOpts)\n const portRegistry = new WeakMap<SandboxInstance, DenoSdkSandbox>()\n\n const buildOptions = (\n request: DenoSandboxCreateRequest,\n ): Effect.Effect<SandboxOptions, SandboxError.SandboxError> =>\n Effect.gen(function* () {\n const img = yield* imageStep(request.image)\n const net = yield* request.network === undefined\n ? Effect.succeed(noop)\n : networkStep(request.network)\n const vols = yield* volumesStep(request.volumes)\n\n const steps: ReadonlyArray<Step> = [\n img,\n when(request.region ?? config.defaultRegion, (r) => set(\"region\", r)),\n when(request.env, (env) => set(\"env\", { ...env })),\n when(request.timeout, (t) => set(\"timeout\", toDenoSeconds(t))),\n when(request.memory, (m) => set(\"memory\", Memory.toBytes(m))),\n when(request.labels, (l) => set(\"labels\", { ...l })),\n net,\n vols,\n when(request.secrets, (s) => (s.length === 0 ? noop : secretsStep(s))),\n when(request.port, (p) => set(\"port\", p)),\n ]\n const overlay = Arr.reduce(steps, {} as OptionsPatch, (acc, step) => step(acc))\n return { ...clientOpts, ...overlay }\n })\n\n const acquireSdk = (request: DenoSandboxCreateRequest) =>\n Effect.flatMap(buildOptions(request), (opts) =>\n Effect.tryPromise({ try: () => DenoSdkSandbox.create(opts), catch: mapCreateError }),\n )\n\n const releaseSdk = (sdk: DenoSdkSandbox) =>\n Effect.promise(() => sdk.kill().catch(() => undefined)).pipe(Effect.ignore)\n\n const releaseAttached = (sdk: DenoSdkSandbox) =>\n Effect.promise(() => sdk.close().catch(() => undefined)).pipe(Effect.ignore)\n\n const destroyById = (id: SandboxId) =>\n Effect.tryPromise({\n try: () => DenoSdkSandbox.connect(id, clientOpts),\n catch: mapLookupError(id),\n }).pipe(\n Effect.flatMap((sdk) =>\n Effect.tryPromise({ try: () => sdk.kill(), catch: mapLookupError(id) }),\n ),\n Effect.catchTag(\"SandboxNotFound\", () => Effect.void),\n )\n\n return {\n create: (request) =>\n Effect.acquireRelease(acquireSdk(request), releaseSdk).pipe(\n Effect.map((sdk) => adaptInstance(sdk, portRegistry)),\n ),\n\n attach: (id) =>\n Effect.acquireRelease(\n Effect.tryPromise({\n try: () => DenoSdkSandbox.connect(id, clientOpts),\n catch: mapLookupError(id),\n }),\n releaseAttached,\n ).pipe(Effect.map((sdk) => adaptInstance(sdk, portRegistry))),\n\n list: Effect.tryPromise({\n try: () => client.sandboxes.list(),\n catch: mapCreateError,\n }).pipe(Effect.map(Arr.map((m): SandboxRef => ({ id: SandboxId(m.id) })))),\n\n destroy: destroyById,\n\n snapshotVolume: (volumeId, slug) =>\n Effect.gen(function* () {\n const snapSlug = slug ?? `eff-uai-snap-${yield* randomToken}`\n const snap = yield* Effect.tryPromise({\n try: () => client.volumes.snapshot(volumeId, { slug: snapSlug }),\n catch: mapCreateError,\n })\n return SnapshotId(snap.slug)\n }),\n\n snapshots: {\n create: () =>\n Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"snapshots.create\",\n reason:\n \"deno snapshots are derived from volumes, not from running sandboxes — use DenoSandbox.snapshotVolume(volumeId, slug?) instead\",\n }),\n ),\n destroy: (sid) =>\n Effect.tryPromise({\n try: () => client.snapshots.delete(sid),\n catch: mapLookupError(sid),\n }),\n list: Stream.unwrap(\n Effect.tryPromise({\n try: () => client.snapshots.list(),\n catch: mapCreateError,\n }).pipe(Effect.map((page) => Stream.fromAsyncIterable(page, mapCreateError))),\n ).pipe(\n Stream.map((snap) => ({ id: SnapshotId(snap.id), name: snap.slug })),\n Stream.runCollect,\n ),\n },\n\n volumes: {\n create: (name, options) =>\n Effect.tryPromise({\n try: () =>\n client.volumes.create({\n slug: name,\n // Volumes are only available in `ord` at the moment.\n // Callers needing a different region can pre-create via\n // the SDK directly.\n region: config.defaultRegion ?? \"ord\",\n capacity: options?.quotaBytes ?? \"1GB\",\n }),\n catch: mapCreateError,\n }).pipe(Effect.map((vol) => VolumeId(vol.slug))),\n destroy: (vid) =>\n Effect.tryPromise({\n try: () => client.volumes.delete(vid),\n catch: mapLookupError(vid),\n }),\n list: Stream.unwrap(\n Effect.tryPromise({\n try: () => client.volumes.list(),\n catch: mapCreateError,\n }).pipe(Effect.map((page) => Stream.fromAsyncIterable(page, mapCreateError))),\n ).pipe(\n Stream.map((vol) => ({ id: VolumeId(vol.slug), name: vol.slug })),\n Stream.runCollect,\n ),\n },\n\n ports: {\n expose: (instance, port) =>\n Effect.gen(function* () {\n const sdk = portRegistry.get(instance)\n if (sdk === undefined) {\n return yield* new SandboxError.SandboxNotFound({ provider: PROVIDER, id: instance.id })\n }\n const url = yield* Effect.tryPromise({\n try: () => sdk.exposeHttp({ port }),\n catch: mapExecError,\n })\n return { url }\n }),\n },\n }\n}\n\n// ---------------------------------------------------------------------------\n// Cross-provider upcast — reject custom header on BoundSecret since\n// Deno doesn't support per-secret headers.\n// ---------------------------------------------------------------------------\n\nconst rejectCustomHeader = (\n secrets: CommonCreateRequest[\"secrets\"],\n): Effect.Effect<void, SandboxError.SandboxError> =>\n secrets === undefined || !secrets.some((s) => s.header !== undefined)\n ? Effect.void\n : Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"BoundSecret.header\",\n reason:\n \"deno always injects secrets as `Authorization: Bearer <value>` — custom headers aren't supported. Use the narrowed `DenoSandbox.create` surface, which omits this field.\",\n }),\n )\n\nconst upcastService = (s: DenoSandboxService): SandboxService => ({\n ...s,\n create: (request) =>\n rejectCustomHeader(request.secrets).pipe(\n Effect.andThen(s.create(request as DenoSandboxCreateRequest)),\n ),\n})\n\n// ---------------------------------------------------------------------------\n// Layer\n// ---------------------------------------------------------------------------\n\n/**\n * Layer registering the Deno Sandbox adapter against `Sandbox`, with\n * the capability markers Deno actually supports.\n *\n * Shipped:\n * - {@link SandboxHostnameAllowlist} — `allowNet` accepts hostnames + wildcards.\n * - {@link SandboxSecretInjection} — `secrets.<name>.value` is injected\n * only on outbound HTTPS to bound hosts; in-VM env shows a placeholder.\n * - {@link SandboxSnapshots} — read-side helpers (`list`, `destroy`)\n * work. `snapshots.create(fromInstance)` fails with\n * `SandboxUnsupported`; use the per-provider\n * `DenoSandbox.snapshotVolume` escape hatch for the volume-derived\n * snapshot workflow.\n * - {@link SandboxVolumes} — `client.volumes.*` directly.\n * - {@link SandboxPortExposure} — `sandbox.exposeHttp({ port })`.\n *\n * NOT shipped (calling those helpers fails at compile time):\n * - `SandboxCustomImage` — no Dockerfile / no OCI registry refs.\n * - `SandboxPauseResume` — Deno doesn't offer in-place memory-preserving pause.\n * - `SandboxKernelSession`, `SandboxPty` — no Jupyter / no PTY.\n */\nexport const layer = (config: DenoSandboxConfig = {}) => {\n const service = buildService(config)\n return Layer.mergeAll(\n Layer.succeed(DenoSandbox, service),\n Layer.succeed(CoreSandbox, upcastService(service)),\n Layer.succeed(SandboxHostnameAllowlist, undefined),\n Layer.succeed(SandboxSecretInjection, undefined),\n Layer.succeed(SandboxSnapshots, undefined),\n Layer.succeed(SandboxVolumes, undefined),\n Layer.succeed(SandboxPortExposure, undefined),\n )\n}\n\n// Re-export SDK error classes so consumers don't need a direct\n// dependency on `@deno/sandbox` to do error-shape-narrowed handling.\nexport {\n ApiError,\n ConnectionClosedError,\n ConnectionEstablishmentError,\n InvalidMemoryError,\n InvalidTimeoutError,\n InvalidTokenError,\n MissingTokenError,\n SandboxCommandError,\n SandboxKillError,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyDA,MAAM,WAAW;AAiEjB,IAAa,cAAb,cAAiC,QAAQ,SAA0C,CACjF,kDACD,CAAC;;AAOF,MAAM,cAAc,OAAO,KAAK,KAAK,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;AAMpF,MAAM,YAAY,MAAgB,aAAa,QAAQ,EAAE,QAAQ,EAAE,SAAS,GAAG,EAAE;AAEjF,MAAM,eAAe,MACnB,aAAa,qBACb,aAAa,qBACZ,aAAa,aAAa,EAAE,WAAW,OAAO,EAAE,WAAW,QAC3D,aAAa,iCAAiC,EAAE,WAAW,OAAO,EAAE,WAAW;AAElF,MAAM,gBAAgB,MACnB,aAAa,YAAY,EAAE,WAAW,OACtC,aAAa,gCAAgC,EAAE,WAAW;;;;;;;AAQ7D,MAAM,mBAAmB,MACtB,aAAa,aAAa,EAAE,WAAW,OAAO,EAAE,SAAS,iCACzD,aAAa,iCACX,EAAE,WAAW,OAAO,EAAE,SAAS;AAEpC,MAAM,kBAAkB,MACtB,YAAY,EAAE,GACV,IAAI,aAAa,kBAAkB;CAAE,UAAU;CAAU,SAAS;CAAQ,KAAK;CAAG,CAAC,GACnF,aAAa,EAAE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AM,QAAQG,SAAa,cAAc,QAAQ,CAAC,EAClD,MAAM,QAAQ,0BAA0B,KAAA,EAAU,EAClD,MAAM,QAAQ,wBAAwB,KAAA,EAAU,EAChD,MAAM,QAAQ,kBAAkB,KAAA,EAAU,EAC1C,MAAM,QAAQ,gBAAgB,KAAA,EAAU,EACxC,MAAM,QAAQ,qBAAqB,KAAA,EAAU,CAC9C"}
|
|
1
|
+
{"version":3,"file":"DenoSandbox.mjs","names":["Arr","CoreExecEvent","DenoSdkSandbox","CoreSandbox"],"sources":["../src/DenoSandbox.ts"],"sourcesContent":["import * as Memory from \"@effect-uai/core/Memory\"\nimport {\n ExecEvent as CoreExecEvent,\n Sandbox as CoreSandbox,\n SandboxHostnameAllowlist,\n SandboxPortExposure,\n SandboxSecretInjection,\n SandboxSnapshots,\n SandboxVolumes,\n type BoundSecret,\n type CommonCreateRequest,\n type CommonExecRequest,\n type CommonSpawnRequest,\n type ExecResult,\n type ImageRef,\n type NetworkPolicy,\n type ProcessHandle,\n SandboxId,\n type SandboxInstance,\n type SandboxRef,\n type SandboxService,\n SnapshotId,\n VolumeId,\n} from \"@effect-uai/core/Sandbox\"\nimport * as SandboxError from \"@effect-uai/core/SandboxError\"\nimport {\n Array as Arr,\n Clock,\n Context,\n Duration,\n Effect,\n Layer,\n Match,\n Option,\n Random,\n Redacted,\n Schedule,\n Scope,\n Stream,\n} from \"effect\"\nimport {\n ApiError,\n Client,\n ConnectionClosedError,\n ConnectionEstablishmentError,\n InvalidMemoryError,\n InvalidTimeoutError,\n InvalidTokenError,\n MissingTokenError,\n Sandbox as DenoSdkSandbox,\n SandboxCommandError,\n SandboxKillError,\n type ChildProcess as DenoChildProcess,\n type SandboxOptions,\n type SecretConfig,\n} from \"@deno/sandbox\"\n\nconst PROVIDER = \"deno\"\n\n// ---------------------------------------------------------------------------\n// Provider-narrowed request types.\n//\n// Deno's `secrets: Record<name, SecretConfig>` shape has no per-secret\n// custom header — substitution is always \"Authorization: Bearer <value>\".\n// We omit `header` on the typed surface (row B) and reject at the upcast\n// adapter (row D) if a caller routes through the generic `Sandbox.create`.\n// ---------------------------------------------------------------------------\n\nexport type DenoSandboxBoundSecret = Omit<BoundSecret, \"header\">\n\nexport type DenoRegion = \"ord\" | \"ams\"\n\nexport type DenoSandboxCreateRequest = Omit<CommonCreateRequest, \"secrets\"> & {\n readonly secrets?: ReadonlyArray<DenoSandboxBoundSecret>\n readonly region?: DenoRegion\n /**\n * Memory size for the sandbox. Accepts a byte count, a {@link Memory.Memory},\n * or a human string like `\"1280 MiB\"` / `\"1 GiB\"`. Deno's accepted\n * range at GA is 768 MiB – 4 GiB (default 1280 MiB).\n */\n readonly memory?: Memory.Input\n readonly labels?: Readonly<Record<string, string>>\n /** Auto-expose this port at boot; the live sandbox's `url` reaches it. */\n readonly port?: number\n}\n\nexport type DenoSandboxConfig = {\n /** Overrides `DENO_DEPLOY_TOKEN`. */\n readonly token?: Redacted.Redacted<string>\n /** Overrides `DENO_DEPLOY_ORG`. Required for personal `ddp_` tokens. */\n readonly org?: string\n /** Overrides `DENO_DEPLOY_ENDPOINT`. */\n readonly apiEndpoint?: string\n /** Default region when create requests omit one. */\n readonly defaultRegion?: DenoRegion\n}\n\n/**\n * Deno-narrowed service. `create` accepts the narrowed\n * {@link DenoSandboxCreateRequest}; every other method is identical to\n * the generic {@link SandboxService} except for the per-provider\n * `snapshotVolume` escape hatch — Deno snapshots are derived from\n * volumes, not from live sandboxes, so the generic\n * `Sandbox.snapshots.create(fromInstance)` doesn't fit and fails with\n * `SandboxUnsupported`.\n */\nexport type DenoSandboxService = Omit<SandboxService, \"create\"> & {\n readonly create: (\n request: DenoSandboxCreateRequest,\n ) => Effect.Effect<SandboxInstance, SandboxError.SandboxError, Scope.Scope>\n /**\n * Snapshot an existing volume by id/slug. Deno's snapshot model is\n * volume-derived, so the generic `Sandbox.snapshots.create` doesn't\n * apply — use this escape hatch instead. The volume must not be\n * attached to any running sandbox at the time of snapshot.\n */\n readonly snapshotVolume: (\n volumeId: VolumeId,\n slug?: string,\n ) => Effect.Effect<SnapshotId, SandboxError.SandboxError>\n}\n\nexport class DenoSandbox extends Context.Service<DenoSandbox, DenoSandboxService>()(\n \"@betalyra/effect-uai/providers/deno/DenoSandbox\",\n) {}\n\n// ---------------------------------------------------------------------------\n// Effect-native primitives\n// ---------------------------------------------------------------------------\n\n/** Random base-36 token, ~8 chars. */\nconst randomToken = Random.next.pipe(Effect.map((r) => r.toString(36).slice(2, 10)))\n\n// ---------------------------------------------------------------------------\n// Error mapping\n// ---------------------------------------------------------------------------\n\nconst reasonOf = (e: unknown) => (e instanceof Error ? { reason: e.message } : {})\n\nconst isAuthError = (e: unknown): boolean =>\n e instanceof MissingTokenError ||\n e instanceof InvalidTokenError ||\n (e instanceof ApiError && (e.status === 401 || e.status === 403)) ||\n (e instanceof ConnectionEstablishmentError && (e.status === 401 || e.status === 403))\n\nconst isQuotaError = (e: unknown): boolean =>\n (e instanceof ApiError && e.status === 429) ||\n (e instanceof ConnectionEstablishmentError && e.status === 429)\n\n/**\n * \"Sandbox is no longer reachable\" — covers both the 404 (never existed)\n * and the 400 + `SANDBOX_ALREADY_TERMINATED` case the API returns when\n * you `connect` to a sandbox after its `kill`. Both map to\n * `SandboxNotFound` so `destroy` and friends stay idempotent.\n */\nconst isNotFoundError = (e: unknown): boolean =>\n (e instanceof ApiError && (e.status === 404 || e.code === \"SANDBOX_ALREADY_TERMINATED\")) ||\n (e instanceof ConnectionEstablishmentError &&\n (e.status === 404 || e.code === \"SANDBOX_ALREADY_TERMINATED\"))\n\nconst mapCreateError = (e: unknown): SandboxError.SandboxError =>\n isAuthError(e)\n ? new SandboxError.SandboxAuthFailed({ provider: PROVIDER, subtype: \"auth\", raw: e })\n : isQuotaError(e)\n ? new SandboxError.SandboxQuotaExceeded({\n provider: PROVIDER,\n raw: e,\n ...reasonOf(e),\n })\n : e instanceof InvalidTimeoutError || e instanceof InvalidMemoryError\n ? new SandboxError.SandboxInvalidRequest({\n provider: PROVIDER,\n raw: e,\n ...reasonOf(e),\n })\n : new SandboxError.SandboxCreateFailed({\n provider: PROVIDER,\n raw: e,\n ...reasonOf(e),\n })\n\nconst mapLookupError =\n (id: string) =>\n (e: unknown): SandboxError.SandboxError =>\n isNotFoundError(e)\n ? new SandboxError.SandboxNotFound({ provider: PROVIDER, id })\n : mapCreateError(e)\n\nconst mapExecError = (e: unknown): SandboxError.SandboxError =>\n e instanceof SandboxCommandError\n ? new SandboxError.SandboxExecFailed({\n provider: PROVIDER,\n raw: e,\n reason: e.message,\n })\n : e instanceof ConnectionClosedError\n ? new SandboxError.SandboxExecFailed({\n provider: PROVIDER,\n raw: e,\n reason: e.reason ?? \"connection closed\",\n })\n : new SandboxError.SandboxExecFailed({\n provider: PROVIDER,\n raw: e,\n ...reasonOf(e),\n })\n\nconst mapFsError = (e: unknown): SandboxError.SandboxError =>\n new SandboxError.SandboxExecFailed({\n provider: PROVIDER,\n raw: e,\n ...reasonOf(e),\n })\n\n// ---------------------------------------------------------------------------\n// Transient WebSocket handshake failures.\n//\n// Empirically (SDK 0.13.2): `sdk.spawn` opens a per-process WebSocket\n// to the sandbox-side relay. The Deploy edge intermittently returns\n// `500 SANDBOX_WEBSOCKET_HANDSHAKE_ERROR` on this handshake; the next\n// attempt against the same sandbox typically succeeds. Retry narrowly\n// on that specific code rather than blanketing all 5xx — most are not\n// transient.\n//\n// Budget: 3 attempts ≈ 500+1000+2000 = 3.5s on top of the original\n// call, well under the 120s test timeout.\n// ---------------------------------------------------------------------------\n\nconst isTransientWsHandshake = (e: SandboxError.SandboxError) =>\n (e._tag === \"SandboxExecFailed\" || e._tag === \"SandboxCreateFailed\") &&\n e.raw instanceof ConnectionEstablishmentError &&\n e.raw.code === \"SANDBOX_WEBSOCKET_HANDSHAKE_ERROR\"\n\nconst wsHandshakeSchedule = Schedule.exponential(\"500 millis\")\nconst WS_HANDSHAKE_RETRIES = 3\n\nconst retryOnTransientWs = <A, R>(\n effect: Effect.Effect<A, SandboxError.SandboxError, R>,\n): Effect.Effect<A, SandboxError.SandboxError, R> =>\n Effect.retry(effect, {\n schedule: wsHandshakeSchedule,\n times: WS_HANDSHAKE_RETRIES,\n while: isTransientWsHandshake,\n })\n\n// ---------------------------------------------------------------------------\n// Builder pipeline — a `Step` mutates `SandboxOptions`. Deno's create\n// API is a plain options object (no builder fluent API), so each Step\n// returns a partial overlay; the create flow folds them into the base.\n// Keeping the same shape as microsandbox's `Step` pattern means optional\n// fields read uniformly.\n// ---------------------------------------------------------------------------\n\ntype OptionsPatch = Partial<SandboxOptions>\ntype Step = (patch: OptionsPatch) => OptionsPatch\n\nconst noop: Step = (p) => p\n\nconst when = <A>(value: A | undefined, step: (a: A) => Step): Step =>\n value === undefined ? noop : step(value)\n\nconst set =\n <K extends keyof SandboxOptions>(key: K, value: SandboxOptions[K]): Step =>\n (p) => ({ ...p, [key]: value })\n\n// ---------------------------------------------------------------------------\n// Duration → Deno timeout format (\"30s\"). Deno's `create.timeout`\n// accepts `\"session\" | \"${number}s\" | \"${number}m\"`; we always emit\n// `<seconds>s` since seconds is the most precise unit honored.\n// ---------------------------------------------------------------------------\n\nconst toDenoSeconds = (d: Duration.Input): `${number}s` => {\n const secs = Math.max(1, Math.ceil(Duration.toMillis(Duration.fromInputUnsafe(d)) / 1000))\n return `${secs}s`\n}\n\n// ---------------------------------------------------------------------------\n// ImageRef → Step. Default omits `root`; Snapshot sets it; Registry /\n// Dockerfile are unsupported and fail at decode.\n// ---------------------------------------------------------------------------\n\nconst imageStep = (image: ImageRef | undefined): Effect.Effect<Step, SandboxError.SandboxError> => {\n if (image === undefined) return Effect.succeed(noop)\n return Match.value(image).pipe(\n Match.tag(\"Default\", (): Effect.Effect<Step, SandboxError.SandboxError> =>\n Effect.succeed(noop),\n ),\n Match.tag(\"Snapshot\", ({ id }): Effect.Effect<Step, SandboxError.SandboxError> =>\n Effect.succeed(set(\"root\", id)),\n ),\n Match.tag(\"Registry\", (): Effect.Effect<Step, SandboxError.SandboxError> =>\n Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"image.registry\",\n reason: \"deno sandboxes do not accept OCI registry refs — boot from a snapshot instead\",\n }),\n ),\n ),\n Match.tag(\"Dockerfile\", (): Effect.Effect<Step, SandboxError.SandboxError> =>\n Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"image.dockerfile\",\n reason:\n \"deno sandboxes do not accept Dockerfiles — install software into a bootable volume then snapshot it\",\n }),\n ),\n ),\n Match.exhaustive,\n )\n}\n\n// ---------------------------------------------------------------------------\n// NetworkPolicy → Step. Deno accepts hostnames + literal IPs but no\n// CIDR ranges; reject `cidrs` rather than silently dropping. `Blocked`\n// encodes as empty allowlist; `Open` omits the field.\n// ---------------------------------------------------------------------------\n\nconst networkStep = (policy: NetworkPolicy): Effect.Effect<Step, SandboxError.SandboxError> =>\n Match.value(policy).pipe(\n Match.tag(\"Open\", (): Effect.Effect<Step, SandboxError.SandboxError> => Effect.succeed(noop)),\n Match.tag(\"Blocked\", (): Effect.Effect<Step, SandboxError.SandboxError> =>\n Effect.succeed(set(\"allowNet\", [])),\n ),\n Match.tag(\"Allowlist\", ({ hosts, cidrs }): Effect.Effect<Step, SandboxError.SandboxError> =>\n cidrs !== undefined && cidrs.length > 0\n ? Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"network.cidrs\",\n reason:\n \"deno's allowNet accepts hostnames or literal IPs, not CIDR ranges — use hosts instead\",\n }),\n )\n : Effect.succeed(set(\"allowNet\", [...(hosts ?? [])])),\n ),\n Match.exhaustive,\n )\n\n// ---------------------------------------------------------------------------\n// Volumes → Step. Deno mounts read-write only; reject `readonly: true`.\n// ---------------------------------------------------------------------------\n\nconst volumesStep = (\n volumes: CommonCreateRequest[\"volumes\"],\n): Effect.Effect<Step, SandboxError.SandboxError> => {\n if (volumes === undefined || volumes.length === 0) return Effect.succeed(noop)\n if (volumes.some((v) => v.readonly === true)) {\n return Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"volumes.readonly\",\n reason: \"deno mounts volumes read-write — read-only mounts are not supported\",\n }),\n )\n }\n const map = Arr.reduce(volumes, {} as Record<string, string>, (acc, v) => {\n acc[v.mountPath] = v.id\n return acc\n })\n return Effect.succeed(set(\"volumes\", map))\n}\n\n// ---------------------------------------------------------------------------\n// Secrets → Step. Stays sync — no decode-time failure modes (custom\n// header is rejected upstream in the upcast).\n// ---------------------------------------------------------------------------\n\nconst secretsStep = (secrets: ReadonlyArray<DenoSandboxBoundSecret>): Step => {\n const record = Arr.reduce(secrets, {} as Record<string, SecretConfig>, (acc, s) => {\n acc[s.name] = { hosts: [...s.hosts], value: Redacted.value(s.value) }\n return acc\n })\n return set(\"secrets\", record)\n}\n\n// ---------------------------------------------------------------------------\n// Base client options used for both client construction and per-call\n// overrides. `token` is a Redacted — we unwrap at the SDK boundary.\n// ---------------------------------------------------------------------------\n\nconst baseClientOptions = (config: DenoSandboxConfig): SandboxOptions => ({\n ...(config.token === undefined ? {} : { token: Redacted.value(config.token) }),\n ...(config.org === undefined ? {} : { org: config.org }),\n ...(config.apiEndpoint === undefined ? {} : { apiEndpoint: config.apiEndpoint }),\n})\n\n// ---------------------------------------------------------------------------\n// argv splitter. Deno's `spawn(command, { args })` is direct argv only —\n// for `cmd: string` (shell semantics) we route through `bash -c`.\n// ---------------------------------------------------------------------------\n\nconst argv = (\n cmd: CommonExecRequest[\"cmd\"],\n): Effect.Effect<\n { readonly command: string; readonly args: ReadonlyArray<string> },\n SandboxError.SandboxError\n> =>\n typeof cmd === \"string\"\n ? Effect.succeed({ command: \"bash\", args: [\"-c\", cmd] })\n : Option.match(Arr.head(cmd), {\n onNone: () =>\n Effect.fail(\n new SandboxError.SandboxInvalidRequest({\n provider: PROVIDER,\n param: \"cmd\",\n reason: \"argv array must be non-empty\",\n }),\n ),\n onSome: (head) => Effect.succeed({ command: head, args: Arr.drop(cmd, 1) }),\n })\n\n// ---------------------------------------------------------------------------\n// AbortController scoped to the caller. On scope close we abort, which\n// signals the SDK to terminate the in-flight call. This is the kill-\n// switch the SDK responds to.\n// ---------------------------------------------------------------------------\n\nconst acquireAbortController: Effect.Effect<AbortController, never, Scope.Scope> =\n Effect.acquireRelease(\n Effect.sync(() => new AbortController()),\n (ac) => Effect.sync(() => ac.abort()),\n )\n\n// ---------------------------------------------------------------------------\n// stdin helpers\n// ---------------------------------------------------------------------------\n\nconst stdinIsStream = (\n stdin: CommonSpawnRequest[\"stdin\"],\n): stdin is Stream.Stream<Uint8Array, never, never> =>\n stdin !== undefined && typeof stdin !== \"string\" && !(stdin instanceof Uint8Array)\n\n/**\n * Copy into a fresh `Uint8Array<ArrayBuffer>`. The Deno SDK strictly\n * types its bytes argument as `Uint8Array<ArrayBuffer>` (not the\n * `ArrayBufferLike` upper bound), so `TextEncoder`-produced bytes and\n * caller-supplied Uint8Arrays need to be copied to a guaranteed-\n * `ArrayBuffer`-backed buffer to satisfy the type.\n */\nconst toBytes = (input: Uint8Array | string): Uint8Array<ArrayBuffer> => {\n const src = typeof input === \"string\" ? new TextEncoder().encode(input) : input\n const out = new Uint8Array(new ArrayBuffer(src.byteLength))\n out.set(src)\n return out\n}\n\n/**\n * Acquire the child's stdin writer, run `use(writer)`, then close the\n * writer on release (regardless of success / failure / interrupt).\n * Returns `Effect.void` if the child wasn't spawned with `stdin: \"piped\"`.\n */\nconst withStdinWriter = <A, E, R>(\n child: DenoChildProcess,\n use: (writer: WritableStreamDefaultWriter<Uint8Array>) => Effect.Effect<A, E, R>,\n): Effect.Effect<void | A, E | SandboxError.SandboxError, R> => {\n const stdin = child.stdin\n if (stdin === null) return Effect.void\n return Effect.acquireUseRelease(\n Effect.sync(() => stdin.getWriter()),\n use,\n (writer) => Effect.promise(() => writer.close().catch(() => undefined)).pipe(Effect.ignore),\n )\n}\n\nconst writeStdinBytes = (\n child: DenoChildProcess,\n bytes: Uint8Array,\n): Effect.Effect<void, SandboxError.SandboxError> =>\n withStdinWriter(child, (writer) =>\n Effect.tryPromise({ try: () => writer.write(bytes), catch: mapExecError }),\n ).pipe(Effect.asVoid)\n\nconst feedStreamStdin = (\n child: DenoChildProcess,\n source: Stream.Stream<Uint8Array, never, never>,\n): Effect.Effect<void, SandboxError.SandboxError> =>\n withStdinWriter(child, (writer) =>\n Stream.runForEach(source, (chunk) =>\n Effect.tryPromise({ try: () => writer.write(chunk), catch: mapExecError }),\n ),\n ).pipe(Effect.asVoid)\n\n// ---------------------------------------------------------------------------\n// ReadableStream<Uint8Array> → Stream<Uint8Array>.\n// ---------------------------------------------------------------------------\n\nconst streamFromReadable = (\n readable: ReadableStream<Uint8Array>,\n): Stream.Stream<Uint8Array, SandboxError.SandboxError> =>\n Stream.fromReadableStream({\n evaluate: () => readable,\n onError: mapExecError,\n })\n\n// ---------------------------------------------------------------------------\n// Merge stdout + stderr into a tagged ExecEvent stream terminated by a\n// single Complete event derived from `child.status`.\n// ---------------------------------------------------------------------------\n\nconst eventStream = (\n child: DenoChildProcess,\n startedAt: number,\n): Stream.Stream<CoreExecEvent, SandboxError.SandboxError> => {\n const stdout: Stream.Stream<CoreExecEvent, SandboxError.SandboxError> =\n child.stdout === null\n ? Stream.empty\n : Stream.map(streamFromReadable(child.stdout), (chunk) => CoreExecEvent.Stdout({ chunk }))\n const stderr: Stream.Stream<CoreExecEvent, SandboxError.SandboxError> =\n child.stderr === null\n ? Stream.empty\n : Stream.map(streamFromReadable(child.stderr), (chunk) => CoreExecEvent.Stderr({ chunk }))\n const complete: Stream.Stream<CoreExecEvent, SandboxError.SandboxError> = Stream.unwrap(\n Effect.gen(function* () {\n const status = yield* Effect.tryPromise({ try: () => child.status, catch: mapExecError })\n const now = yield* Clock.currentTimeMillis\n return Stream.succeed(\n CoreExecEvent.Complete({ exitCode: status.code, durationMs: now - startedAt }),\n )\n }),\n )\n return Stream.concat(Stream.merge(stdout, stderr), complete)\n}\n\n// ---------------------------------------------------------------------------\n// Per-exec timeout. Races against `Effect.sleep` so the parent scope\n// finalizers (which kill the child via `acquireRelease`) fire on breach.\n// We don't lean on `Effect.timeout` because it returns `Option`-shaped\n// fallbacks in v4; the race-based shape lets us keep the SandboxError\n// channel directly.\n// ---------------------------------------------------------------------------\n\nconst withExecTimeout = <A, R>(\n timeout: Duration.Input | undefined,\n effect: Effect.Effect<A, SandboxError.SandboxError, R>,\n): Effect.Effect<A, SandboxError.SandboxError, R> =>\n timeout === undefined\n ? effect\n : Effect.race(\n effect,\n Effect.sleep(timeout).pipe(\n Effect.andThen(\n Effect.fail(\n new SandboxError.SandboxTimeout({\n provider: PROVIDER,\n operation: \"exec\",\n budget: Duration.fromInputUnsafe(timeout),\n }),\n ),\n ),\n ),\n )\n\n// ---------------------------------------------------------------------------\n// Live SandboxInstance adapter. The `WeakMap<SandboxInstance, sdk>`\n// passed in is the back-reference used by the port-exposure sub-API\n// to recover the SDK handle from an opaque `SandboxInstance`.\n// ---------------------------------------------------------------------------\n\nconst adaptInstance = (\n sdk: DenoSdkSandbox,\n portRegistry: WeakMap<SandboxInstance, DenoSdkSandbox>,\n): SandboxInstance => {\n const id = SandboxId(sdk.id)\n\n const openProcess = (request: CommonSpawnRequest) =>\n Effect.gen(function* () {\n const { command, args } = yield* argv(request.cmd)\n const ac = yield* acquireAbortController\n const stdinMode: \"piped\" | \"null\" = request.stdin === undefined ? \"null\" : \"piped\"\n const startedAt = yield* Clock.currentTimeMillis\n const child = yield* Effect.acquireRelease(\n retryOnTransientWs(\n Effect.tryPromise({\n try: () =>\n sdk.spawn(command, {\n args: [...args],\n ...(request.cwd === undefined ? {} : { cwd: request.cwd }),\n ...(request.env === undefined ? {} : { env: { ...request.env } }),\n stdin: stdinMode,\n stdout: \"piped\",\n stderr: \"piped\",\n signal: ac.signal,\n }),\n catch: mapExecError,\n }),\n ),\n (c) => Effect.promise(() => c.kill(\"SIGKILL\").catch(() => undefined)).pipe(Effect.ignore),\n )\n if (request.stdin !== undefined) {\n if (stdinIsStream(request.stdin)) {\n yield* Effect.forkScoped(feedStreamStdin(child, request.stdin))\n } else {\n yield* writeStdinBytes(child, toBytes(request.stdin))\n }\n }\n return { child, startedAt }\n })\n\n const instance: SandboxInstance = {\n id,\n\n exec: (request) =>\n withExecTimeout(\n request.timeout,\n Effect.scoped(\n Effect.gen(function* () {\n const { child, startedAt } = yield* openProcess(request)\n const output = yield* Effect.tryPromise({\n try: () => child.output(),\n catch: mapExecError,\n })\n const completedAt = yield* Clock.currentTimeMillis\n return {\n exitCode: output.status.code,\n stdout: output.stdoutText ?? \"\",\n stderr: output.stderrText ?? \"\",\n durationMs: completedAt - startedAt,\n } satisfies ExecResult\n }),\n ),\n ),\n\n execStream: (request) =>\n Stream.unwrap(\n Effect.map(openProcess(request), ({ child, startedAt }) => eventStream(child, startedAt)),\n ),\n\n spawn: (request) =>\n Effect.map(openProcess(request), ({ child, startedAt }): ProcessHandle => ({\n pid: child.pid,\n events: eventStream(child, startedAt),\n kill: Effect.tryPromise({\n try: () => child.kill(\"SIGTERM\"),\n catch: mapExecError,\n }),\n exit: Effect.tryPromise({\n try: () => child.status,\n catch: mapExecError,\n }).pipe(Effect.map((status) => ({ exitCode: status.code }))),\n })),\n\n files: {\n read: (path) => Effect.tryPromise({ try: () => sdk.fs.readFile(path), catch: mapFsError }),\n write: (path, contents) =>\n Effect.tryPromise({\n try: () => sdk.fs.writeFile(path, toBytes(contents)),\n catch: mapFsError,\n }),\n remove: (path) => Effect.tryPromise({ try: () => sdk.fs.remove(path), catch: mapFsError }),\n mkdir: (path) =>\n Effect.tryPromise({\n try: () => sdk.fs.mkdir(path, { recursive: true }),\n catch: mapFsError,\n }),\n list: (path) =>\n Stream.fromAsyncIterable(sdk.fs.readDir(path), mapFsError).pipe(\n Stream.map((e) => ({\n path: e.name,\n kind: e.isFile\n ? (\"file\" as const)\n : e.isDirectory\n ? (\"directory\" as const)\n : e.isSymlink\n ? (\"symlink\" as const)\n : (\"other\" as const),\n })),\n Stream.runCollect,\n ),\n exists: (path) =>\n Effect.tryPromise({\n try: () => sdk.fs.stat(path),\n catch: mapFsError,\n }).pipe(\n Effect.as(true),\n Effect.catchCause(() => Effect.succeed(false)),\n ),\n },\n }\n\n portRegistry.set(instance, sdk)\n return instance\n}\n\n// ---------------------------------------------------------------------------\n// Service factory\n// ---------------------------------------------------------------------------\n\nconst buildService = (config: DenoSandboxConfig): DenoSandboxService => {\n const clientOpts = baseClientOptions(config)\n const client = new Client(clientOpts)\n const portRegistry = new WeakMap<SandboxInstance, DenoSdkSandbox>()\n\n const buildOptions = (\n request: DenoSandboxCreateRequest,\n ): Effect.Effect<SandboxOptions, SandboxError.SandboxError> =>\n Effect.gen(function* () {\n const img = yield* imageStep(request.image)\n const net = yield* request.network === undefined\n ? Effect.succeed(noop)\n : networkStep(request.network)\n const vols = yield* volumesStep(request.volumes)\n\n const steps: ReadonlyArray<Step> = [\n img,\n when(request.region ?? config.defaultRegion, (r) => set(\"region\", r)),\n when(request.env, (env) => set(\"env\", { ...env })),\n when(request.timeout, (t) => set(\"timeout\", toDenoSeconds(t))),\n when(request.memory, (m) => set(\"memory\", Memory.toBytes(m))),\n when(request.labels, (l) => set(\"labels\", { ...l })),\n net,\n vols,\n when(request.secrets, (s) => (s.length === 0 ? noop : secretsStep(s))),\n when(request.port, (p) => set(\"port\", p)),\n ]\n const overlay = Arr.reduce(steps, {} as OptionsPatch, (acc, step) => step(acc))\n return { ...clientOpts, ...overlay }\n })\n\n const acquireSdk = (request: DenoSandboxCreateRequest) =>\n Effect.flatMap(buildOptions(request), (opts) =>\n Effect.tryPromise({ try: () => DenoSdkSandbox.create(opts), catch: mapCreateError }),\n )\n\n const releaseSdk = (sdk: DenoSdkSandbox) =>\n Effect.promise(() => sdk.kill().catch(() => undefined)).pipe(Effect.ignore)\n\n const releaseAttached = (sdk: DenoSdkSandbox) =>\n Effect.promise(() => sdk.close().catch(() => undefined)).pipe(Effect.ignore)\n\n const destroyById = (id: SandboxId) =>\n Effect.tryPromise({\n try: () => DenoSdkSandbox.connect(id, clientOpts),\n catch: mapLookupError(id),\n }).pipe(\n Effect.flatMap((sdk) =>\n Effect.tryPromise({ try: () => sdk.kill(), catch: mapLookupError(id) }),\n ),\n Effect.catchTag(\"SandboxNotFound\", () => Effect.void),\n )\n\n return {\n create: (request) =>\n Effect.acquireRelease(acquireSdk(request), releaseSdk).pipe(\n Effect.map((sdk) => adaptInstance(sdk, portRegistry)),\n ),\n\n attach: (id) =>\n Effect.acquireRelease(\n Effect.tryPromise({\n try: () => DenoSdkSandbox.connect(id, clientOpts),\n catch: mapLookupError(id),\n }),\n releaseAttached,\n ).pipe(Effect.map((sdk) => adaptInstance(sdk, portRegistry))),\n\n list: Effect.tryPromise({\n try: () => client.sandboxes.list(),\n catch: mapCreateError,\n }).pipe(Effect.map(Arr.map((m): SandboxRef => ({ id: SandboxId(m.id) })))),\n\n destroy: destroyById,\n\n snapshotVolume: (volumeId, slug) =>\n Effect.gen(function* () {\n const snapSlug = slug ?? `eff-uai-snap-${yield* randomToken}`\n const snap = yield* Effect.tryPromise({\n try: () => client.volumes.snapshot(volumeId, { slug: snapSlug }),\n catch: mapCreateError,\n })\n return SnapshotId(snap.slug)\n }),\n\n snapshots: {\n create: () =>\n Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"snapshots.create\",\n reason:\n \"deno snapshots are derived from volumes, not from running sandboxes — use DenoSandbox.snapshotVolume(volumeId, slug?) instead\",\n }),\n ),\n destroy: (sid) =>\n Effect.tryPromise({\n try: () => client.snapshots.delete(sid),\n catch: mapLookupError(sid),\n }),\n list: Stream.unwrap(\n Effect.tryPromise({\n try: () => client.snapshots.list(),\n catch: mapCreateError,\n }).pipe(Effect.map((page) => Stream.fromAsyncIterable(page, mapCreateError))),\n ).pipe(\n Stream.map((snap) => ({ id: SnapshotId(snap.id), name: snap.slug })),\n Stream.runCollect,\n ),\n },\n\n volumes: {\n create: (name, options) =>\n Effect.tryPromise({\n try: () =>\n client.volumes.create({\n slug: name,\n // Volumes are only available in `ord` at the moment.\n // Callers needing a different region can pre-create via\n // the SDK directly.\n region: config.defaultRegion ?? \"ord\",\n capacity: options?.quotaBytes ?? \"1GB\",\n }),\n catch: mapCreateError,\n }).pipe(Effect.map((vol) => VolumeId(vol.slug))),\n destroy: (vid) =>\n Effect.tryPromise({\n try: () => client.volumes.delete(vid),\n catch: mapLookupError(vid),\n }),\n list: Stream.unwrap(\n Effect.tryPromise({\n try: () => client.volumes.list(),\n catch: mapCreateError,\n }).pipe(Effect.map((page) => Stream.fromAsyncIterable(page, mapCreateError))),\n ).pipe(\n Stream.map((vol) => ({ id: VolumeId(vol.slug), name: vol.slug })),\n Stream.runCollect,\n ),\n },\n\n ports: {\n expose: (instance, port) =>\n Effect.gen(function* () {\n const sdk = portRegistry.get(instance)\n if (sdk === undefined) {\n return yield* new SandboxError.SandboxNotFound({ provider: PROVIDER, id: instance.id })\n }\n const url = yield* Effect.tryPromise({\n try: () => sdk.exposeHttp({ port }),\n catch: mapExecError,\n })\n return { url }\n }),\n },\n }\n}\n\n// ---------------------------------------------------------------------------\n// Cross-provider upcast — reject custom header on BoundSecret since\n// Deno doesn't support per-secret headers.\n// ---------------------------------------------------------------------------\n\nconst rejectCustomHeader = (\n secrets: CommonCreateRequest[\"secrets\"],\n): Effect.Effect<void, SandboxError.SandboxError> =>\n secrets === undefined || !secrets.some((s) => s.header !== undefined)\n ? Effect.void\n : Effect.fail(\n new SandboxError.SandboxUnsupported({\n provider: PROVIDER,\n capability: \"BoundSecret.header\",\n reason:\n \"deno always injects secrets as `Authorization: Bearer <value>` — custom headers aren't supported. Use the narrowed `DenoSandbox.create` surface, which omits this field.\",\n }),\n )\n\nconst upcastService = (s: DenoSandboxService): SandboxService => ({\n ...s,\n create: (request) =>\n rejectCustomHeader(request.secrets).pipe(\n Effect.andThen(s.create(request as DenoSandboxCreateRequest)),\n ),\n})\n\n// ---------------------------------------------------------------------------\n// Layer\n// ---------------------------------------------------------------------------\n\n/**\n * Layer registering the Deno Sandbox adapter against `Sandbox`, with\n * the capability markers Deno actually supports.\n *\n * Shipped:\n * - {@link SandboxHostnameAllowlist} — `allowNet` accepts hostnames + wildcards.\n * - {@link SandboxSecretInjection} — `secrets.<name>.value` is injected\n * only on outbound HTTPS to bound hosts; in-VM env shows a placeholder.\n * - {@link SandboxSnapshots} — read-side helpers (`list`, `destroy`)\n * work. `snapshots.create(fromInstance)` fails with\n * `SandboxUnsupported`; use the per-provider\n * `DenoSandbox.snapshotVolume` escape hatch for the volume-derived\n * snapshot workflow.\n * - {@link SandboxVolumes} — `client.volumes.*` directly.\n * - {@link SandboxPortExposure} — `sandbox.exposeHttp({ port })`.\n *\n * NOT shipped (calling those helpers fails at compile time):\n * - `SandboxCustomImage` — no Dockerfile / no OCI registry refs.\n * - `SandboxPauseResume` — Deno doesn't offer in-place memory-preserving pause.\n * - `SandboxKernelSession`, `SandboxPty` — no Jupyter / no PTY.\n */\nexport const layer = (config: DenoSandboxConfig = {}) => {\n const service = buildService(config)\n return Layer.mergeAll(\n Layer.succeed(DenoSandbox, service),\n Layer.succeed(CoreSandbox, upcastService(service)),\n Layer.succeed(SandboxHostnameAllowlist, undefined),\n Layer.succeed(SandboxSecretInjection, undefined),\n Layer.succeed(SandboxSnapshots, undefined),\n Layer.succeed(SandboxVolumes, undefined),\n Layer.succeed(SandboxPortExposure, undefined),\n )\n}\n\n// Re-export SDK error classes so consumers don't need a direct\n// dependency on `@deno/sandbox` to do error-shape-narrowed handling.\nexport {\n ApiError,\n ConnectionClosedError,\n ConnectionEstablishmentError,\n InvalidMemoryError,\n InvalidTimeoutError,\n InvalidTokenError,\n MissingTokenError,\n SandboxCommandError,\n SandboxKillError,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyDA,MAAM,WAAW;AAiEjB,IAAa,cAAb,cAAiC,QAAQ,QAAyC,CAAC,CACjF,iDACF,CAAC,CAAC,CAAC;;AAOH,MAAM,cAAc,OAAO,KAAK,KAAK,OAAO,KAAK,MAAM,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"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Deno Sandbox provider (Firecracker microVMs on Deno Deploy) for @effect-uai/core.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@deno/sandbox": "^0.13.2",
|
|
48
|
-
"effect": "4.0.0-
|
|
49
|
-
"typescript": "^
|
|
50
|
-
"@effect-uai/core": "0.
|
|
48
|
+
"effect": "4.0.0-rc.111",
|
|
49
|
+
"typescript": "^7.0.2",
|
|
50
|
+
"@effect-uai/core": "0.13.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@deno/sandbox": "^0.13.0",
|
|
54
54
|
"@effect-uai/core": ">=0.5.0 <1",
|
|
55
|
-
"effect": ">=4.0.0-
|
|
55
|
+
"effect": ">=4.0.0-rc.111 <5.0.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsdown",
|
package/src/DenoSandbox.ts
CHANGED
|
@@ -282,36 +282,30 @@ const toDenoSeconds = (d: Duration.Input): `${number}s` => {
|
|
|
282
282
|
const imageStep = (image: ImageRef | undefined): Effect.Effect<Step, SandboxError.SandboxError> => {
|
|
283
283
|
if (image === undefined) return Effect.succeed(noop)
|
|
284
284
|
return Match.value(image).pipe(
|
|
285
|
-
Match.tag(
|
|
286
|
-
|
|
287
|
-
(): Effect.Effect<Step, SandboxError.SandboxError> => Effect.succeed(noop),
|
|
285
|
+
Match.tag("Default", (): Effect.Effect<Step, SandboxError.SandboxError> =>
|
|
286
|
+
Effect.succeed(noop),
|
|
288
287
|
),
|
|
289
|
-
Match.tag(
|
|
290
|
-
"
|
|
291
|
-
({ id }): Effect.Effect<Step, SandboxError.SandboxError> => Effect.succeed(set("root", id)),
|
|
288
|
+
Match.tag("Snapshot", ({ id }): Effect.Effect<Step, SandboxError.SandboxError> =>
|
|
289
|
+
Effect.succeed(set("root", id)),
|
|
292
290
|
),
|
|
293
|
-
Match.tag(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}),
|
|
302
|
-
),
|
|
291
|
+
Match.tag("Registry", (): Effect.Effect<Step, SandboxError.SandboxError> =>
|
|
292
|
+
Effect.fail(
|
|
293
|
+
new SandboxError.SandboxUnsupported({
|
|
294
|
+
provider: PROVIDER,
|
|
295
|
+
capability: "image.registry",
|
|
296
|
+
reason: "deno sandboxes do not accept OCI registry refs — boot from a snapshot instead",
|
|
297
|
+
}),
|
|
298
|
+
),
|
|
303
299
|
),
|
|
304
|
-
Match.tag(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}),
|
|
314
|
-
),
|
|
300
|
+
Match.tag("Dockerfile", (): Effect.Effect<Step, SandboxError.SandboxError> =>
|
|
301
|
+
Effect.fail(
|
|
302
|
+
new SandboxError.SandboxUnsupported({
|
|
303
|
+
provider: PROVIDER,
|
|
304
|
+
capability: "image.dockerfile",
|
|
305
|
+
reason:
|
|
306
|
+
"deno sandboxes do not accept Dockerfiles — install software into a bootable volume then snapshot it",
|
|
307
|
+
}),
|
|
308
|
+
),
|
|
315
309
|
),
|
|
316
310
|
Match.exhaustive,
|
|
317
311
|
)
|
|
@@ -326,23 +320,20 @@ const imageStep = (image: ImageRef | undefined): Effect.Effect<Step, SandboxErro
|
|
|
326
320
|
const networkStep = (policy: NetworkPolicy): Effect.Effect<Step, SandboxError.SandboxError> =>
|
|
327
321
|
Match.value(policy).pipe(
|
|
328
322
|
Match.tag("Open", (): Effect.Effect<Step, SandboxError.SandboxError> => Effect.succeed(noop)),
|
|
329
|
-
Match.tag(
|
|
330
|
-
"
|
|
331
|
-
(): Effect.Effect<Step, SandboxError.SandboxError> => Effect.succeed(set("allowNet", [])),
|
|
323
|
+
Match.tag("Blocked", (): Effect.Effect<Step, SandboxError.SandboxError> =>
|
|
324
|
+
Effect.succeed(set("allowNet", [])),
|
|
332
325
|
),
|
|
333
|
-
Match.tag(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
)
|
|
345
|
-
: Effect.succeed(set("allowNet", [...(hosts ?? [])])),
|
|
326
|
+
Match.tag("Allowlist", ({ hosts, cidrs }): Effect.Effect<Step, SandboxError.SandboxError> =>
|
|
327
|
+
cidrs !== undefined && cidrs.length > 0
|
|
328
|
+
? Effect.fail(
|
|
329
|
+
new SandboxError.SandboxUnsupported({
|
|
330
|
+
provider: PROVIDER,
|
|
331
|
+
capability: "network.cidrs",
|
|
332
|
+
reason:
|
|
333
|
+
"deno's allowNet accepts hostnames or literal IPs, not CIDR ranges — use hosts instead",
|
|
334
|
+
}),
|
|
335
|
+
)
|
|
336
|
+
: Effect.succeed(set("allowNet", [...(hosts ?? [])])),
|
|
346
337
|
),
|
|
347
338
|
Match.exhaustive,
|
|
348
339
|
)
|
|
@@ -637,21 +628,18 @@ const adaptInstance = (
|
|
|
637
628
|
),
|
|
638
629
|
|
|
639
630
|
spawn: (request) =>
|
|
640
|
-
Effect.map(
|
|
641
|
-
|
|
642
|
-
(
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
try: () => child.kill("SIGTERM"),
|
|
647
|
-
catch: mapExecError,
|
|
648
|
-
}),
|
|
649
|
-
exit: Effect.tryPromise({
|
|
650
|
-
try: () => child.status,
|
|
651
|
-
catch: mapExecError,
|
|
652
|
-
}).pipe(Effect.map((status) => ({ exitCode: status.code }))),
|
|
631
|
+
Effect.map(openProcess(request), ({ child, startedAt }): ProcessHandle => ({
|
|
632
|
+
pid: child.pid,
|
|
633
|
+
events: eventStream(child, startedAt),
|
|
634
|
+
kill: Effect.tryPromise({
|
|
635
|
+
try: () => child.kill("SIGTERM"),
|
|
636
|
+
catch: mapExecError,
|
|
653
637
|
}),
|
|
654
|
-
|
|
638
|
+
exit: Effect.tryPromise({
|
|
639
|
+
try: () => child.status,
|
|
640
|
+
catch: mapExecError,
|
|
641
|
+
}).pipe(Effect.map((status) => ({ exitCode: status.code }))),
|
|
642
|
+
})),
|
|
655
643
|
|
|
656
644
|
files: {
|
|
657
645
|
read: (path) => Effect.tryPromise({ try: () => sdk.fs.readFile(path), catch: mapFsError }),
|
|
File without changes
|