@alineo-labs/core 0.4.2 → 0.6.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/index.d.mts +211 -69
- package/dist/index.mjs +343 -170
- package/package.json +4 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { ConsoleLogger, ILogger, LogLevel, noopLogger } from "@alineo-labs/logger";
|
|
2
|
-
import {
|
|
2
|
+
import { AlineoError, AlineoError as AlineoError$1, AlineoErrorOptions, ErrorCode, ErrorCode as ErrorCode$1, errorCodeOf, isRetryable } from "@alineo-labs/errors";
|
|
3
|
+
import { CodeContext, CodeLanguage, DiagnosticEvent, DiagnosticEvent as DiagnosticEvent$1, DiagnosticLog, DiagnosticLog as DiagnosticLog$1, EgressPolicyStatus, ExecChannel, ExecEvent, FileInfo, FileInfo as FileInfo$1, Metrics, Metrics as Metrics$1, NetworkPolicy, NetworkRule, PtyChannel, SandboxProvider, SandboxProviderCapabilities } from "@alineo-labs/provider";
|
|
4
|
+
import { LedgerEnvelope } from "@alineo-labs/schema/types";
|
|
3
5
|
//#region src/ledger.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The provider a ledger row belongs to when it records none. Rows written before provider ids
|
|
8
|
+
* existed all came from OpenSandbox, so an absent `provider` means this. Readers apply it on
|
|
9
|
+
* read; nothing in the ledger is migrated.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_PROVIDER_ID = "opensandbox";
|
|
4
12
|
/** Status of a sandbox session derived from its ledger events. */
|
|
5
13
|
export declare enum SandboxStatus {
|
|
6
14
|
Running = "running",
|
|
@@ -23,7 +31,7 @@ interface SandboxDetails {
|
|
|
23
31
|
* `crypto.randomUUID()` if the caller didn't supply one via `SandboxOptions.runId`.
|
|
24
32
|
* A resumed, forked, or restored-from-snapshot sandbox always inherits its origin's
|
|
25
33
|
* `runId` rather than getting a new one, so every sandbox descended from the same
|
|
26
|
-
* root call (directly or via `sb.fork()`/`Alineo.spawn()`/`alineo
|
|
34
|
+
* root call (directly or via `sb.fork()`/`Alineo.spawn()`/`alineo spawn`) shares it —
|
|
27
35
|
* the mechanism `client.sandboxes.list({ runId })` correlates on.
|
|
28
36
|
*/
|
|
29
37
|
runId: string;
|
|
@@ -53,6 +61,12 @@ interface SandboxDetails {
|
|
|
53
61
|
* `episodicRecall`) walk a fork lineage rather than only seeing one flat session.
|
|
54
62
|
*/
|
|
55
63
|
parentSandboxId?: string;
|
|
64
|
+
/**
|
|
65
|
+
* The sandbox provider that owns `sandboxId` (`"opensandbox"`). Always set by the official
|
|
66
|
+
* adapters, which apply {@link DEFAULT_PROVIDER_ID} to rows that recorded none. Optional in
|
|
67
|
+
* the type so a third-party `IStorageAdapter` written before this field still compiles.
|
|
68
|
+
*/
|
|
69
|
+
provider?: string;
|
|
56
70
|
}
|
|
57
71
|
/** Options for filtering session listings. */
|
|
58
72
|
interface ListSandboxOptions {
|
|
@@ -67,71 +81,70 @@ interface ListSandboxOptions {
|
|
|
67
81
|
resourceId?: string;
|
|
68
82
|
/** Return only sessions scoped to this team — see `SandboxDetails.teamId`. */
|
|
69
83
|
teamId?: string;
|
|
84
|
+
/** Return only sessions owned by this sandbox provider — see `SandboxDetails.provider`. */
|
|
85
|
+
provider?: string;
|
|
70
86
|
}
|
|
71
87
|
/** Events emitted during execution and stored in the ledger. */
|
|
72
88
|
export declare enum LedgerEvent {
|
|
73
89
|
/** Emitted when a sandbox is created and reaches Running state. */
|
|
74
|
-
SandboxCreated = "
|
|
90
|
+
SandboxCreated = "sandbox.created",
|
|
75
91
|
/** Emitted at the start of each exec() or execCode() call. */
|
|
76
|
-
ExecStart = "
|
|
92
|
+
ExecStart = "exec.started",
|
|
77
93
|
/** Streaming output chunk from exec() or execCode(). */
|
|
78
|
-
ExecEvent = "
|
|
94
|
+
ExecEvent = "exec.output",
|
|
79
95
|
/** Emitted when an exec() or execCode() call completes. */
|
|
80
|
-
ExecComplete = "
|
|
96
|
+
ExecComplete = "exec.completed",
|
|
81
97
|
/** Emitted when checkpoint() captures a snapshot. */
|
|
82
|
-
CheckpointCreated = "checkpoint_created",
|
|
98
|
+
CheckpointCreated = "sandbox.checkpoint_created",
|
|
83
99
|
/** Emitted when a sandbox is closed. */
|
|
84
|
-
SandboxClosed = "
|
|
100
|
+
SandboxClosed = "sandbox.closed",
|
|
85
101
|
/** Emitted when pause() freezes the container. */
|
|
86
|
-
SandboxPaused = "
|
|
102
|
+
SandboxPaused = "sandbox.paused",
|
|
87
103
|
/** Emitted when resume() restores the container to Running. */
|
|
88
|
-
SandboxResumed = "
|
|
104
|
+
SandboxResumed = "sandbox.resumed",
|
|
89
105
|
/**
|
|
90
106
|
* Emitted by `sb.credentials.set()`/`.patch()`. Payload is binding metadata only
|
|
91
107
|
* (name, host, injection type) — the credential value is never written to the ledger.
|
|
92
108
|
*/
|
|
93
|
-
CredentialBound = "
|
|
109
|
+
CredentialBound = "credential.bound",
|
|
94
110
|
/** Emitted by `sb.credentials.remove()`. */
|
|
95
|
-
CredentialRevoked = "
|
|
111
|
+
CredentialRevoked = "credential.revoked",
|
|
96
112
|
/**
|
|
97
113
|
* Emitted by `sb.egress.patch()`. Payload is `{ rules: NetworkRule[] }` — the exact rules
|
|
98
114
|
* passed to the sidecar, so `Sandbox.resume()` can fold a still-wanted allowance back into
|
|
99
115
|
* the resumed sandbox's boot policy (egress policy is sidecar-local and does not survive a
|
|
100
116
|
* resume). `sb.fork()` does not carry these.
|
|
101
117
|
*/
|
|
102
|
-
EgressRuleAdded = "
|
|
118
|
+
EgressRuleAdded = "egress.rule_added",
|
|
103
119
|
/** Emitted by `sb.egress.delete()`. Payload is `{ targets: string[] }`. */
|
|
104
|
-
EgressRuleRemoved = "
|
|
120
|
+
EgressRuleRemoved = "egress.rule_removed",
|
|
105
121
|
/**
|
|
106
122
|
* Emitted when the permission gate pauses a tool call for human approval. Payload is
|
|
107
123
|
* `{ requestId, tool, target }` — metadata only; the raw tool arguments (which can carry
|
|
108
124
|
* secrets in a bash command or a file write) are never written to the ledger.
|
|
109
125
|
*/
|
|
110
|
-
PermissionRequested = "
|
|
126
|
+
PermissionRequested = "permission.requested",
|
|
127
|
+
/**
|
|
128
|
+
* Emitted when a `PermissionRequested` reaches a final state — answered by a caller, a
|
|
129
|
+
* batched always/reject decision, a timeout, or a session resume dropping it. Payload is
|
|
130
|
+
* `{ requestId, decision }`. `decision.kind` is one of `PermissionDecision`'s real answers
|
|
131
|
+
* (`once`/`always`/`reject`) for every case except the dropped one, which is `"dropped"` —
|
|
132
|
+
* deliberately not a `PermissionDecision`, because nobody answered it.
|
|
133
|
+
*/
|
|
134
|
+
PermissionResolved = "permission.resolved",
|
|
111
135
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* `
|
|
136
|
+
* durability-roadmap M3, 3.2: emitted by the agent SDK after a turn-level checkpoint
|
|
137
|
+
* (workspace + session-file tarball, NOT `sb.checkpoint()`'s OpenSandbox snapshot — see
|
|
138
|
+
* `CheckpointCreated` above and `packages/agent/src/checkpoint.ts`'s doc comment for why the
|
|
139
|
+
* two are deliberately separate mechanisms) is captured and durably stored. Payload is
|
|
140
|
+
* `{ turn, snapshotRef, remoteRef?, uploadError? }` — `snapshotRef` is the host file and `remoteRef`
|
|
141
|
+
* the same tarball in object storage, when a store was given and the upload worked. Written only
|
|
142
|
+
* once the tarball is confirmed stored, since a
|
|
143
|
+
* snapshot without this event pointing at it is unreachable garbage. Shares the same
|
|
144
|
+
* `IStorageAdapter`-backed ledger `PermissionRequested`/`PermissionResolved` already use, so
|
|
145
|
+
* a standalone SDK caller and alineod both read it back the same way (`adapter.readAll`).
|
|
115
146
|
*/
|
|
116
|
-
|
|
117
|
-
/** Emitted once when a workflow run starts, before any steps execute. */
|
|
118
|
-
RunStarted = "run_started",
|
|
119
|
-
/** Emitted at the beginning of each step. */
|
|
120
|
-
StepStart = "step_start",
|
|
121
|
-
/** Emitted when a step finishes successfully. */
|
|
122
|
-
StepComplete = "step_complete",
|
|
123
|
-
/** Emitted when a step throws an unrecoverable error. */
|
|
124
|
-
StepFailed = "step_failed",
|
|
125
|
-
/** Emitted when a step's rollback handler completes during saga compensation. */
|
|
126
|
-
StepRolledBack = "step_rolled_back",
|
|
127
|
-
/** Emitted after all steps finish without error. */
|
|
128
|
-
WorkflowComplete = "workflow_complete",
|
|
129
|
-
/** Emitted after rollback completes following a step failure. */
|
|
130
|
-
WorkflowFailed = "workflow_failed",
|
|
131
|
-
/** Durable resumption point written after each successful step. */
|
|
132
|
-
Checkpoint = "checkpoint",
|
|
133
|
-
/** Emitted when a sandbox snapshot is captured mid-run. */
|
|
134
|
-
Snapshot = "snapshot"
|
|
147
|
+
AgentCheckpointed = "agent.checkpointed"
|
|
135
148
|
}
|
|
136
149
|
/** A single event record written to the storage adapter during a session. */
|
|
137
150
|
interface LedgerEntry {
|
|
@@ -147,7 +160,7 @@ interface LedgerEntry {
|
|
|
147
160
|
event: LedgerEvent;
|
|
148
161
|
/** Event-specific data (step output, snapshot ID, exec text, etc.). */
|
|
149
162
|
payload?: unknown;
|
|
150
|
-
/** Error message when
|
|
163
|
+
/** Error message, when the event records a failure. */
|
|
151
164
|
error?: string;
|
|
152
165
|
}
|
|
153
166
|
/** A recorded checkpoint for a sandbox session. */
|
|
@@ -173,6 +186,49 @@ interface EnvironmentRecord {
|
|
|
173
186
|
/** Unix timestamp (ms) when the environment was last built. */
|
|
174
187
|
builtAt: number;
|
|
175
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* One entry in a generic, two-level-partition append-only ledger — the shared primitive
|
|
191
|
+
* durability-roadmap.md's M3 (3.1b) introduces so a second consumer (alineod's swarm ledger,
|
|
192
|
+
* `apps/alineod/src/state/db.ts`) can depend on the same package the sandbox SDK's own ledger
|
|
193
|
+
* already does, instead of each hand-rolling `bun:sqlite`. Deliberately narrower than
|
|
194
|
+
* `IStorageAdapter`/`LedgerEntry` above: no derived-aggregation methods (`listSandboxDetails`
|
|
195
|
+
* and friends stay specific to the sandbox SDK's own shape), and ordering is always by `seq`
|
|
196
|
+
* (true write order) — never by `ts`, which stays a per-consumer concern. `scope` and `subScope`
|
|
197
|
+
* are deliberately generic names: the sandbox SDK's shape is `(name, sandboxId)`; alineod's is
|
|
198
|
+
* `(runId, agentId)`. Only the access patterns alineod's existing `ledger` table actually uses
|
|
199
|
+
* are supported (filter by `scope` alone, filter by `subScope` alone plus an event filter, or a
|
|
200
|
+
* full unfiltered replay) — not the sandbox SDK's combined `(scope, subScope)` filter, which
|
|
201
|
+
* stays on `IStorageAdapter.readAll()` as it is today.
|
|
202
|
+
*/
|
|
203
|
+
interface EngineLedgerEntry {
|
|
204
|
+
/** Primary partition key — e.g. a run id. Required on every entry. */
|
|
205
|
+
scope: string;
|
|
206
|
+
/** Secondary partition key — e.g. an agent id. Omitted/null for a scope-level event. */
|
|
207
|
+
subScope?: string | null;
|
|
208
|
+
ts: number;
|
|
209
|
+
event: string;
|
|
210
|
+
payload?: unknown;
|
|
211
|
+
}
|
|
212
|
+
/** A stored `EngineLedgerEntry`, with the monotonic sequence number assigned on append. */
|
|
213
|
+
interface EngineLedgerRow extends EngineLedgerEntry {
|
|
214
|
+
seq: number;
|
|
215
|
+
}
|
|
216
|
+
interface IEngineLedger {
|
|
217
|
+
/** Run migrations / open connections. Must be called before first use. */
|
|
218
|
+
connect?(): Promise<void>;
|
|
219
|
+
/** Release connections and resources. Call on graceful shutdown. */
|
|
220
|
+
close?(): Promise<void>;
|
|
221
|
+
/** Append one entry and return it with its assigned `seq`. */
|
|
222
|
+
append(entry: EngineLedgerEntry): Promise<EngineLedgerRow>;
|
|
223
|
+
/** Every entry for one `scope`, in `seq` order, optionally only those after a given `seq`. */
|
|
224
|
+
readByScope(scope: string, opts?: {
|
|
225
|
+
afterSeq?: number;
|
|
226
|
+
}): Promise<EngineLedgerRow[]>;
|
|
227
|
+
/** Every entry for one `subScope`, in `seq` order, optionally filtered to one `event` type. */
|
|
228
|
+
readBySubScope(subScope: string, event?: string): Promise<EngineLedgerRow[]>;
|
|
229
|
+
/** Every entry across every scope, in `seq` order — for a full replay at boot. */
|
|
230
|
+
readAll(): Promise<EngineLedgerRow[]>;
|
|
231
|
+
}
|
|
176
232
|
/**
|
|
177
233
|
* Persistence interface for session event storage.
|
|
178
234
|
*
|
|
@@ -352,11 +408,29 @@ interface ExecResult {
|
|
|
352
408
|
stdout: string;
|
|
353
409
|
stderr: string;
|
|
354
410
|
exitCode: number;
|
|
411
|
+
/** How long the command ran, in milliseconds, measured by the client. */
|
|
412
|
+
durationMs?: number;
|
|
413
|
+
/** True when the command was ended by a signal (a timeout, a `kill`, the OOM killer). */
|
|
414
|
+
killed?: boolean;
|
|
415
|
+
/** The signal that ended it, as the server reported it (`"killed"`). Set with `killed`. */
|
|
416
|
+
signal?: string;
|
|
417
|
+
/**
|
|
418
|
+
* True when the command was killed after running for about as long as `timeoutMs` allowed.
|
|
419
|
+
*
|
|
420
|
+
* **A best guess, not a report.** A timeout and a kill from inside the sandbox (the OOM
|
|
421
|
+
* killer, a `kill -9`) look the same on the wire: both are `signal: killed`, exit code -1. So
|
|
422
|
+
* this is inferred from the elapsed time, and a kill that lands close to the limit reads as a
|
|
423
|
+
* timeout. Use it to explain a failure to a person, not to decide whether a retry is safe.
|
|
424
|
+
* Never set for a command that had no limit.
|
|
425
|
+
*/
|
|
426
|
+
timedOut?: boolean;
|
|
355
427
|
}
|
|
356
428
|
type ExecDriver = {
|
|
357
429
|
type: "stream";
|
|
358
|
-
gen: AsyncGenerator<
|
|
430
|
+
gen: AsyncGenerator<ExecEvent>;
|
|
359
431
|
onDone: (r: ExecResult) => Promise<void>;
|
|
432
|
+
/** The `timeoutMs` the command was started with, so a timeout can be told from a kill. */
|
|
433
|
+
timeoutMs?: number;
|
|
360
434
|
} | {
|
|
361
435
|
type: "replay";
|
|
362
436
|
result: ExecResult;
|
|
@@ -472,6 +546,12 @@ interface ExecOptions {
|
|
|
472
546
|
env?: Record<string, string>;
|
|
473
547
|
/** Abort the command after this many milliseconds. */
|
|
474
548
|
timeoutMs?: number;
|
|
549
|
+
/**
|
|
550
|
+
* Abort the command. On abort the call rejects with the signal's reason (an `AbortError` by
|
|
551
|
+
* default) and the command is interrupted in the sandbox, best effort. A signal that is already
|
|
552
|
+
* aborted rejects before anything is sent.
|
|
553
|
+
*/
|
|
554
|
+
signal?: AbortSignal;
|
|
475
555
|
/**
|
|
476
556
|
* Throw `CommandError` if the command exits with a non-zero code.
|
|
477
557
|
* Defaults to `true`.
|
|
@@ -524,8 +604,20 @@ interface SandboxHooks {
|
|
|
524
604
|
}
|
|
525
605
|
/** Internal dependencies injected by `Sandbox`. */
|
|
526
606
|
interface SandboxDeps {
|
|
527
|
-
|
|
607
|
+
/** The sandbox provider that owns this sandbox. */
|
|
608
|
+
provider: SandboxProvider;
|
|
528
609
|
adapter: IStorageAdapter;
|
|
610
|
+
/**
|
|
611
|
+
* Receives a `LedgerEnvelope` for every event this sandbox emits, beside the ledger write.
|
|
612
|
+
*
|
|
613
|
+
* Synchronous and must not throw — it runs on the write path of a sandbox operation, so an
|
|
614
|
+
* async sink would become backpressure and a throwing one would fail the very operation
|
|
615
|
+
* being recorded. Deliberately NOT joined to `_ledgerQueue` for the same reason.
|
|
616
|
+
*
|
|
617
|
+
* @internal Sinks are an export path and the ledger is the system of record; the public
|
|
618
|
+
* shape of this belongs with the work that owns export.
|
|
619
|
+
*/
|
|
620
|
+
sink?: (envelope: LedgerEnvelope) => void;
|
|
529
621
|
hooks?: SandboxHooks;
|
|
530
622
|
/** Broker for `sb.credentials.*` — undefined unless the sandbox was created with `credentialProxy: true`. */
|
|
531
623
|
credentialBroker?: CredentialBroker;
|
|
@@ -550,8 +642,6 @@ interface SandboxDeps {
|
|
|
550
642
|
resourceId?: string;
|
|
551
643
|
teamId?: string;
|
|
552
644
|
}) => Promise<SandboxHandle>;
|
|
553
|
-
/** Route execd and proxy calls through the OpenSandbox server. Required when the server runs in Docker. */
|
|
554
|
-
useServerProxy?: boolean;
|
|
555
645
|
}
|
|
556
646
|
//#endregion
|
|
557
647
|
//#region src/sandbox/internal.d.ts
|
|
@@ -568,7 +658,7 @@ interface SandboxInternal {
|
|
|
568
658
|
readonly name: string;
|
|
569
659
|
readonly deps: SandboxDeps;
|
|
570
660
|
readonly openSessionClosers: Set<() => Promise<void>>;
|
|
571
|
-
getExecClient(): Promise<
|
|
661
|
+
getExecClient(signal?: AbortSignal): Promise<ExecChannel>;
|
|
572
662
|
emit(event: LedgerEvent, stepIndex: number, payload?: unknown): Promise<void>;
|
|
573
663
|
waitForRunning(timeoutMs?: number): Promise<void>;
|
|
574
664
|
waitForSnapshot(snapshotId: string, timeoutMs?: number): Promise<void>;
|
|
@@ -625,6 +715,8 @@ export declare class BashSession {
|
|
|
625
715
|
*/
|
|
626
716
|
declare class SandboxCore implements SandboxInternal {
|
|
627
717
|
readonly sandboxId: string;
|
|
718
|
+
/** The id of the sandbox provider that owns this sandbox (`"opensandbox"`). */
|
|
719
|
+
get provider(): string;
|
|
628
720
|
readonly name: string;
|
|
629
721
|
readonly deps: SandboxDeps;
|
|
630
722
|
/** Cached exec results for replay mode (populated by `Sandbox.resume()`). */
|
|
@@ -658,9 +750,14 @@ declare class SandboxCore implements SandboxInternal {
|
|
|
658
750
|
*/
|
|
659
751
|
disposeExecClient(): void;
|
|
660
752
|
nextSeq(): number;
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
753
|
+
/**
|
|
754
|
+
* The channel to this sandbox's `execd`, connecting if there is none yet. `signal` stops the
|
|
755
|
+
* wait for a sandbox that is slow to accept a connection. It does not close a channel that was
|
|
756
|
+
* already connected.
|
|
757
|
+
*/
|
|
758
|
+
getExecClient(signal?: AbortSignal): Promise<ExecChannel>;
|
|
759
|
+
/** Resolve a fresh terminal channel for a new interactive session. Reuses `getExecClient()`'s readiness wait. */
|
|
760
|
+
resolvePtyClient(): Promise<PtyChannel>;
|
|
664
761
|
waitForRunning(timeoutMs?: number): Promise<void>;
|
|
665
762
|
waitForSnapshot(snapshotId: string, timeoutMs?: number): Promise<void>;
|
|
666
763
|
emit(event: LedgerEvent, stepIndex: number, payload?: unknown): Promise<void>;
|
|
@@ -767,8 +864,14 @@ declare class SandboxCore implements SandboxInternal {
|
|
|
767
864
|
export declare class SandboxHandle extends SandboxCore {
|
|
768
865
|
/** Write a file into the sandbox. */
|
|
769
866
|
writeFile(path: string, content: string): Promise<void>;
|
|
867
|
+
/** Write raw bytes into the sandbox — for binary content `writeFile`'s string-typed
|
|
868
|
+
* signature isn't safe for (a gzip tarball, an image). */
|
|
869
|
+
writeFileBytes(path: string, bytes: Uint8Array): Promise<void>;
|
|
770
870
|
/** Read a file from the sandbox as a UTF-8 string. */
|
|
771
871
|
readFile(path: string): Promise<string>;
|
|
872
|
+
/** Read a file from the sandbox as raw bytes — for binary content `readFile`'s UTF-8
|
|
873
|
+
* decode would corrupt (a gzip tarball, an image). */
|
|
874
|
+
readFileBytes(path: string): Promise<Uint8Array>;
|
|
772
875
|
/** Delete a file from the sandbox. */
|
|
773
876
|
deleteFile(path: string): Promise<void>;
|
|
774
877
|
/** Move or rename a file inside the sandbox. */
|
|
@@ -973,22 +1076,33 @@ export declare class SandboxHandle extends SandboxCore {
|
|
|
973
1076
|
//#endregion
|
|
974
1077
|
//#region src/sandbox/resolve.d.ts
|
|
975
1078
|
/**
|
|
976
|
-
*
|
|
977
|
-
* returns a different ephemeral proxy port) then polls listContexts until
|
|
978
|
-
* execd is ready to accept connections.
|
|
1079
|
+
* A channel to run commands in a sandbox, from its provider.
|
|
979
1080
|
*
|
|
980
|
-
*
|
|
981
|
-
*
|
|
982
|
-
*
|
|
983
|
-
*
|
|
984
|
-
* budget before the exec daemon inside it had actually started accepting connections. An
|
|
985
|
-
* isolated repro of the identical fork (same snapshot, but from an idle parent with no
|
|
986
|
-
* concurrent browser load) reached execd-ready in under 400ms -- the parent's own host-resource
|
|
987
|
-
* contention at fork time, not snapshot size, is what actually eats the budget. This can't be
|
|
988
|
-
* fixed by scheduling around it from here, so it's addressed by simply affording much more
|
|
989
|
-
* patience before giving up.
|
|
1081
|
+
* The provider owns the wait: it resolves once the sandbox accepts a connection, and rejects with
|
|
1082
|
+
* `EXEC_NOT_READY` when it never does. That failure is re-thrown as `ExecConnectionError`, with
|
|
1083
|
+
* the cause, the attempt count, and the wait the provider recorded, because that class is the
|
|
1084
|
+
* one callers have been catching and it extends `WorkflowError`.
|
|
990
1085
|
*/
|
|
991
|
-
export declare function
|
|
1086
|
+
export declare function resolveExecChannel(provider: SandboxProvider, sandboxId: string, options?: {
|
|
1087
|
+
signal?: AbortSignal;
|
|
1088
|
+
}): Promise<ExecChannel>;
|
|
1089
|
+
//#endregion
|
|
1090
|
+
//#region src/sandbox/capabilities.d.ts
|
|
1091
|
+
/** The capabilities a caller can require of a provider. */
|
|
1092
|
+
type RequiredCapability = keyof SandboxProviderCapabilities;
|
|
1093
|
+
/**
|
|
1094
|
+
* Throw `CAPABILITY_UNSUPPORTED`, naming the capability and the provider, when the provider
|
|
1095
|
+
* declares it cannot do something.
|
|
1096
|
+
*
|
|
1097
|
+
* Only an explicit `false` is a refusal. `"unverified"` (configured, not proven) goes ahead and
|
|
1098
|
+
* may still fail at the call, and a provider with no descriptor, which is what a test double
|
|
1099
|
+
* usually is, is not second-guessed.
|
|
1100
|
+
*
|
|
1101
|
+
* This is the early failure: a spec that needs egress, or a `checkpoint()` on a provider that
|
|
1102
|
+
* cannot snapshot, is refused before anything is created or sent, with a message that names the
|
|
1103
|
+
* missing capability instead of a failure three calls later that reads like a bad spec.
|
|
1104
|
+
*/
|
|
1105
|
+
export declare function requireCapability(provider: SandboxProvider, capability: RequiredCapability, sandboxId?: string): void;
|
|
992
1106
|
//#endregion
|
|
993
1107
|
//#region src/sandbox/hooks.d.ts
|
|
994
1108
|
interface ComposeHooksOptions {
|
|
@@ -1025,9 +1139,14 @@ interface ComposeHooksOptions {
|
|
|
1025
1139
|
export declare function composeHooks(hooks: (SandboxHooks | undefined)[], opts?: ComposeHooksOptions): SandboxHooks;
|
|
1026
1140
|
//#endregion
|
|
1027
1141
|
//#region src/errors.d.ts
|
|
1028
|
-
/**
|
|
1029
|
-
|
|
1030
|
-
|
|
1142
|
+
/**
|
|
1143
|
+
* Base class for all alineo workflow runtime errors.
|
|
1144
|
+
*
|
|
1145
|
+
* An {@link AlineoError}, so every subclass carries a stable `code`. A subclass that has not
|
|
1146
|
+
* been given a more specific code reports `INTERNAL`.
|
|
1147
|
+
*/
|
|
1148
|
+
export declare class WorkflowError extends AlineoError$1 {
|
|
1149
|
+
constructor(message: string, code?: ErrorCode$1, options?: AlineoErrorOptions);
|
|
1031
1150
|
}
|
|
1032
1151
|
/**
|
|
1033
1152
|
* Thrown for sandbox lifecycle failures — failing to create, boot, or reach
|
|
@@ -1039,21 +1158,39 @@ export declare class SandboxError extends WorkflowError {
|
|
|
1039
1158
|
readonly sandboxId?: string | undefined;
|
|
1040
1159
|
constructor(message: string,
|
|
1041
1160
|
/** The sandbox ID, if one was assigned before the failure. */
|
|
1042
|
-
sandboxId?: string | undefined);
|
|
1161
|
+
sandboxId?: string | undefined, code?: ErrorCode$1, options?: AlineoErrorOptions);
|
|
1162
|
+
}
|
|
1163
|
+
/** What `ExecConnectionError` knows about the readiness probe that gave up. */
|
|
1164
|
+
interface ExecConnectionFailure {
|
|
1165
|
+
/** The last error the readiness probe saw. */
|
|
1166
|
+
cause?: unknown;
|
|
1167
|
+
/** How many probes ran. */
|
|
1168
|
+
attempts?: number;
|
|
1169
|
+
/** How long the probe waited in total, in milliseconds. */
|
|
1170
|
+
waitedMs?: number;
|
|
1043
1171
|
}
|
|
1044
1172
|
/**
|
|
1045
1173
|
* Thrown when execd inside a sandbox never becomes ready within the retry window.
|
|
1046
1174
|
* The sandbox is `Running` from the control plane's perspective, but the exec
|
|
1047
1175
|
* daemon is not accepting connections.
|
|
1176
|
+
*
|
|
1177
|
+
* Code `EXEC_NOT_READY`. The message keeps its original leading text, and adds how long the
|
|
1178
|
+
* probe waited and the last error it saw, so a failure on a fresh machine says why.
|
|
1048
1179
|
*/
|
|
1049
1180
|
export declare class ExecConnectionError extends WorkflowError {
|
|
1050
1181
|
readonly sandboxId: string;
|
|
1051
|
-
constructor(sandboxId: string);
|
|
1182
|
+
constructor(sandboxId: string, failure?: ExecConnectionFailure);
|
|
1183
|
+
/** How many readiness probes ran before giving up. */
|
|
1184
|
+
readonly attempts?: number;
|
|
1185
|
+
/** How long the readiness probe waited in total, in milliseconds. */
|
|
1186
|
+
readonly waitedMs?: number;
|
|
1052
1187
|
}
|
|
1053
1188
|
/**
|
|
1054
1189
|
* Thrown when a command exits with a non-zero exit code. Carries the exit
|
|
1055
|
-
* code
|
|
1056
|
-
*
|
|
1190
|
+
* code, the original command, and the command's output: `stderr` and `stdout`
|
|
1191
|
+
* hold all of it, and the message ends with the last 2000 characters of `stderr`
|
|
1192
|
+
* (or of `stdout` when `stderr` is empty). For `SandboxHandle.exec()`, only thrown
|
|
1193
|
+
* when `strict` is enabled (the default — pass `{ strict: false }` to opt out). For
|
|
1057
1194
|
* `BashSession.exec()` (a persistent session from `createSession()`), always
|
|
1058
1195
|
* thrown on non-zero exit; there is no `strict` option for session execs.
|
|
1059
1196
|
*/
|
|
@@ -1061,7 +1198,12 @@ export declare class CommandError extends WorkflowError {
|
|
|
1061
1198
|
readonly exitCode: number;
|
|
1062
1199
|
readonly command: string;
|
|
1063
1200
|
readonly sandboxId: string;
|
|
1064
|
-
|
|
1201
|
+
readonly stdout: string;
|
|
1202
|
+
readonly stderr: string;
|
|
1203
|
+
constructor(exitCode: number, command: string, sandboxId: string, output?: {
|
|
1204
|
+
stdout?: string;
|
|
1205
|
+
stderr?: string;
|
|
1206
|
+
});
|
|
1065
1207
|
}
|
|
1066
1208
|
/**
|
|
1067
1209
|
* Reserved for a per-step timeout mechanism — not currently thrown anywhere
|
|
@@ -1074,4 +1216,4 @@ export declare class StepTimeoutError extends WorkflowError {
|
|
|
1074
1216
|
constructor(stepId: string, timeoutMs: number);
|
|
1075
1217
|
}
|
|
1076
1218
|
//#endregion
|
|
1077
|
-
export { type AttachableSource, type BoundCredential, type CheckpointInfo, type ComposeHooksOptions, ConsoleLogger, type CredentialBinding, type CredentialBroker, type CredentialInjection, type CredentialResolver, type CredentialSource, type DiagnosticEvent, type DiagnosticLog, type EnvironmentRecord, type ExecCodeOptions, type ExecOptions, type ExecResult, type FileInfo, type ILogger, type IStorageAdapter, type LedgerEntry, type ListSandboxOptions, LogLevel, type Metrics, type PendingInteractiveExec, type PtyControls, type ReconstructedEgress, type SandboxDeps, type SandboxDetails, type SandboxHooks, noopLogger };
|
|
1219
|
+
export { AlineoError, type AttachableSource, type BoundCredential, type CheckpointInfo, type ComposeHooksOptions, ConsoleLogger, type CredentialBinding, type CredentialBroker, type CredentialInjection, type CredentialResolver, type CredentialSource, type DiagnosticEvent, type DiagnosticLog, type EngineLedgerEntry, type EngineLedgerRow, type EnvironmentRecord, type ErrorCode, type ExecCodeOptions, type ExecConnectionFailure, type ExecOptions, type ExecResult, type FileInfo, type IEngineLedger, type ILogger, type IStorageAdapter, type LedgerEntry, type ListSandboxOptions, LogLevel, type Metrics, type PendingInteractiveExec, type PtyControls, type ReconstructedEgress, type SandboxDeps, type SandboxDetails, type SandboxHooks, errorCodeOf, isRetryable, noopLogger };
|