@alineo-labs/core 0.4.0 → 0.4.2
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 +24 -47
- package/dist/index.mjs +14 -48
- package/package.json +6 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { ConsoleLogger, ILogger, LogLevel, noopLogger } from "@alineo-labs/logger";
|
|
1
2
|
import { CodeContext, CodeLanguage, ControlClient, DiagnosticEvent, DiagnosticEvent as DiagnosticEvent$1, DiagnosticLog, DiagnosticLog as DiagnosticLog$1, EgressPolicyStatus, ExecClient, FileInfo, FileInfo as FileInfo$1, Metrics, Metrics as Metrics$1, NetworkPolicy, NetworkRule, PtyClient, SSEEvent } from "@alineo-labs/opensandbox";
|
|
2
|
-
|
|
3
3
|
//#region src/ledger.d.ts
|
|
4
4
|
/** Status of a sandbox session derived from its ledger events. */
|
|
5
|
-
declare enum SandboxStatus {
|
|
5
|
+
export declare enum SandboxStatus {
|
|
6
6
|
Running = "running",
|
|
7
7
|
Completed = "completed"
|
|
8
8
|
}
|
|
@@ -69,7 +69,7 @@ interface ListSandboxOptions {
|
|
|
69
69
|
teamId?: string;
|
|
70
70
|
}
|
|
71
71
|
/** Events emitted during execution and stored in the ledger. */
|
|
72
|
-
declare enum LedgerEvent {
|
|
72
|
+
export declare enum LedgerEvent {
|
|
73
73
|
/** Emitted when a sandbox is created and reaches Running state. */
|
|
74
74
|
SandboxCreated = "sandbox_created",
|
|
75
75
|
/** Emitted at the start of each exec() or execCode() call. */
|
|
@@ -217,31 +217,6 @@ interface IStorageAdapter {
|
|
|
217
217
|
listEnvironments(): Promise<EnvironmentRecord[]>;
|
|
218
218
|
}
|
|
219
219
|
//#endregion
|
|
220
|
-
//#region src/logger.d.ts
|
|
221
|
-
declare enum LogLevel {
|
|
222
|
-
Debug = 0,
|
|
223
|
-
Info = 1,
|
|
224
|
-
Warn = 2,
|
|
225
|
-
Error = 3,
|
|
226
|
-
Silent = 4
|
|
227
|
-
}
|
|
228
|
-
interface ILogger {
|
|
229
|
-
debug(msg: string, meta?: Record<string, unknown>): void;
|
|
230
|
-
info(msg: string, meta?: Record<string, unknown>): void;
|
|
231
|
-
warn(msg: string, meta?: Record<string, unknown>): void;
|
|
232
|
-
error(msg: string, meta?: Record<string, unknown>): void;
|
|
233
|
-
}
|
|
234
|
-
declare class ConsoleLogger implements ILogger {
|
|
235
|
-
private readonly minLevel;
|
|
236
|
-
constructor(minLevel?: LogLevel);
|
|
237
|
-
private log;
|
|
238
|
-
debug(msg: string, meta?: Record<string, unknown>): void;
|
|
239
|
-
info(msg: string, meta?: Record<string, unknown>): void;
|
|
240
|
-
warn(msg: string, meta?: Record<string, unknown>): void;
|
|
241
|
-
error(msg: string, meta?: Record<string, unknown>): void;
|
|
242
|
-
}
|
|
243
|
-
declare const noopLogger: ILogger;
|
|
244
|
-
//#endregion
|
|
245
220
|
//#region src/credentials.d.ts
|
|
246
221
|
/**
|
|
247
222
|
* How a credential reaches an outbound request.
|
|
@@ -330,7 +305,7 @@ type CredentialResolver = (name: string, source: CredentialSource) => string | u
|
|
|
330
305
|
* silently dropping the credential (the previous behavior when no resolver was supplied at
|
|
331
306
|
* all — see plans/credential-injection.md).
|
|
332
307
|
*/
|
|
333
|
-
declare function resolveBoundCredential(name: string, source: CredentialSource | undefined, resolver: CredentialResolver | undefined, sandboxId: string): Promise<string>;
|
|
308
|
+
export declare function resolveBoundCredential(name: string, source: CredentialSource | undefined, resolver: CredentialResolver | undefined, sandboxId: string): Promise<string>;
|
|
334
309
|
/** One credential's reconstructed state, as recovered from ledger history by `reconstructBoundCredentials()`. */
|
|
335
310
|
interface BoundCredential {
|
|
336
311
|
binding: CredentialBinding;
|
|
@@ -343,7 +318,7 @@ interface BoundCredential {
|
|
|
343
318
|
* operation. Scans the *whole* history, not just some replay window — credential bindings
|
|
344
319
|
* aren't tied to specific execs the way exec replay is.
|
|
345
320
|
*/
|
|
346
|
-
declare function reconstructBoundCredentials(entries: LedgerEntry[]): Map<string, BoundCredential>;
|
|
321
|
+
export declare function reconstructBoundCredentials(entries: LedgerEntry[]): Map<string, BoundCredential>;
|
|
347
322
|
//#endregion
|
|
348
323
|
//#region src/egress.d.ts
|
|
349
324
|
/** The still-live outcome of a session's runtime `sb.egress.*` calls. */
|
|
@@ -370,7 +345,7 @@ interface ReconstructedEgress {
|
|
|
370
345
|
* a re-add after a delete brings it back. Scans the whole history, like
|
|
371
346
|
* `reconstructBoundCredentials`.
|
|
372
347
|
*/
|
|
373
|
-
declare function reconstructEgressRules(entries: LedgerEntry[]): ReconstructedEgress;
|
|
348
|
+
export declare function reconstructEgressRules(entries: LedgerEntry[]): ReconstructedEgress;
|
|
374
349
|
//#endregion
|
|
375
350
|
//#region src/exec-handle.d.ts
|
|
376
351
|
interface ExecResult {
|
|
@@ -386,8 +361,10 @@ type ExecDriver = {
|
|
|
386
361
|
type: "replay";
|
|
387
362
|
result: ExecResult;
|
|
388
363
|
} | {
|
|
389
|
-
type: "pty";
|
|
390
|
-
|
|
364
|
+
type: "pty";
|
|
365
|
+
/** Output already recorded before this handle was created (e.g. resumed from ledger) — shown as scrollback before live output resumes. */
|
|
366
|
+
seedStdout?: string;
|
|
367
|
+
/** Wire up push-based output/exit/failure callbacks. Called once, synchronously. */
|
|
391
368
|
attach: (push: (chunk: string) => void, finish: (exitCode: number) => void, fail: (err: unknown) => void) => void;
|
|
392
369
|
onDone: (r: ExecResult) => Promise<void>;
|
|
393
370
|
};
|
|
@@ -416,7 +393,7 @@ interface PtyControls {
|
|
|
416
393
|
* for await (const chunk of sb.exec("npm test").stdout()) process.stdout.write(chunk);
|
|
417
394
|
* ```
|
|
418
395
|
*/
|
|
419
|
-
declare class ExecHandle implements PromiseLike<ExecResult> {
|
|
396
|
+
export declare class ExecHandle implements PromiseLike<ExecResult> {
|
|
420
397
|
private readonly _promise;
|
|
421
398
|
private readonly _chunks;
|
|
422
399
|
private _wakeup;
|
|
@@ -466,7 +443,7 @@ interface AttachableSource {
|
|
|
466
443
|
* await sb.exec("bash", { interactive: true }).attach(process.stdin, process.stdout);
|
|
467
444
|
* ```
|
|
468
445
|
*/
|
|
469
|
-
declare class InteractiveExecHandle extends ExecHandle {
|
|
446
|
+
export declare class InteractiveExecHandle extends ExecHandle {
|
|
470
447
|
private readonly _controls?;
|
|
471
448
|
constructor(driver: ExecDriver, controls?: PtyControls);
|
|
472
449
|
/** Send input to the running process. No-op if the session already ended. */
|
|
@@ -610,7 +587,7 @@ interface SandboxInternal {
|
|
|
610
587
|
*
|
|
611
588
|
* Create with `sandbox.createSession()`. Always call `close()` when done.
|
|
612
589
|
*/
|
|
613
|
-
declare class BashSession {
|
|
590
|
+
export declare class BashSession {
|
|
614
591
|
/** execd session ID. */
|
|
615
592
|
readonly sessionId: string;
|
|
616
593
|
private readonly _execFn;
|
|
@@ -787,7 +764,7 @@ declare class SandboxCore implements SandboxInternal {
|
|
|
787
764
|
* await sb.close();
|
|
788
765
|
* ```
|
|
789
766
|
*/
|
|
790
|
-
declare class SandboxHandle extends SandboxCore {
|
|
767
|
+
export declare class SandboxHandle extends SandboxCore {
|
|
791
768
|
/** Write a file into the sandbox. */
|
|
792
769
|
writeFile(path: string, content: string): Promise<void>;
|
|
793
770
|
/** Read a file from the sandbox as a UTF-8 string. */
|
|
@@ -1011,7 +988,7 @@ declare class SandboxHandle extends SandboxCore {
|
|
|
1011
988
|
* fixed by scheduling around it from here, so it's addressed by simply affording much more
|
|
1012
989
|
* patience before giving up.
|
|
1013
990
|
*/
|
|
1014
|
-
declare function resolveExecClient(control: ControlClient, sandboxId: string, useServerProxy?: boolean, retries?: number, delayMs?: number): Promise<ExecClient>;
|
|
991
|
+
export declare function resolveExecClient(control: ControlClient, sandboxId: string, useServerProxy?: boolean, retries?: number, delayMs?: number): Promise<ExecClient>;
|
|
1015
992
|
//#endregion
|
|
1016
993
|
//#region src/sandbox/hooks.d.ts
|
|
1017
994
|
interface ComposeHooksOptions {
|
|
@@ -1045,11 +1022,11 @@ interface ComposeHooksOptions {
|
|
|
1045
1022
|
* });
|
|
1046
1023
|
* ```
|
|
1047
1024
|
*/
|
|
1048
|
-
declare function composeHooks(hooks: (SandboxHooks | undefined)[], opts?: ComposeHooksOptions): SandboxHooks;
|
|
1025
|
+
export declare function composeHooks(hooks: (SandboxHooks | undefined)[], opts?: ComposeHooksOptions): SandboxHooks;
|
|
1049
1026
|
//#endregion
|
|
1050
1027
|
//#region src/errors.d.ts
|
|
1051
1028
|
/** Base class for all alineo workflow runtime errors. */
|
|
1052
|
-
declare class WorkflowError extends Error {
|
|
1029
|
+
export declare class WorkflowError extends Error {
|
|
1053
1030
|
constructor(message: string);
|
|
1054
1031
|
}
|
|
1055
1032
|
/**
|
|
@@ -1057,11 +1034,11 @@ declare class WorkflowError extends Error {
|
|
|
1057
1034
|
* `Running` state; being paused when an operation requires a live sandbox;
|
|
1058
1035
|
* `fork()` being unsupported on this sandbox; or a snapshot operation failing.
|
|
1059
1036
|
*/
|
|
1060
|
-
declare class SandboxError extends WorkflowError {
|
|
1037
|
+
export declare class SandboxError extends WorkflowError {
|
|
1061
1038
|
/** The sandbox ID, if one was assigned before the failure. */
|
|
1062
1039
|
readonly sandboxId?: string | undefined;
|
|
1063
|
-
constructor(message: string,
|
|
1064
|
-
|
|
1040
|
+
constructor(message: string,
|
|
1041
|
+
/** The sandbox ID, if one was assigned before the failure. */
|
|
1065
1042
|
sandboxId?: string | undefined);
|
|
1066
1043
|
}
|
|
1067
1044
|
/**
|
|
@@ -1069,7 +1046,7 @@ declare class SandboxError extends WorkflowError {
|
|
|
1069
1046
|
* The sandbox is `Running` from the control plane's perspective, but the exec
|
|
1070
1047
|
* daemon is not accepting connections.
|
|
1071
1048
|
*/
|
|
1072
|
-
declare class ExecConnectionError extends WorkflowError {
|
|
1049
|
+
export declare class ExecConnectionError extends WorkflowError {
|
|
1073
1050
|
readonly sandboxId: string;
|
|
1074
1051
|
constructor(sandboxId: string);
|
|
1075
1052
|
}
|
|
@@ -1080,7 +1057,7 @@ declare class ExecConnectionError extends WorkflowError {
|
|
|
1080
1057
|
* `BashSession.exec()` (a persistent session from `createSession()`), always
|
|
1081
1058
|
* thrown on non-zero exit; there is no `strict` option for session execs.
|
|
1082
1059
|
*/
|
|
1083
|
-
declare class CommandError extends WorkflowError {
|
|
1060
|
+
export declare class CommandError extends WorkflowError {
|
|
1084
1061
|
readonly exitCode: number;
|
|
1085
1062
|
readonly command: string;
|
|
1086
1063
|
readonly sandboxId: string;
|
|
@@ -1091,10 +1068,10 @@ declare class CommandError extends WorkflowError {
|
|
|
1091
1068
|
* in this codebase. `SandboxOptions.timeout`/`step.timeout` in `@alineo-labs/workflow`
|
|
1092
1069
|
* bound sandbox container lifetime, which is a related but distinct concept.
|
|
1093
1070
|
*/
|
|
1094
|
-
declare class StepTimeoutError extends WorkflowError {
|
|
1071
|
+
export declare class StepTimeoutError extends WorkflowError {
|
|
1095
1072
|
readonly stepId: string;
|
|
1096
1073
|
readonly timeoutMs: number;
|
|
1097
1074
|
constructor(stepId: string, timeoutMs: number);
|
|
1098
1075
|
}
|
|
1099
1076
|
//#endregion
|
|
1100
|
-
export { type AttachableSource,
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConsoleLogger, LogLevel, noopLogger } from "@alineo-labs/logger";
|
|
1
2
|
import { EgressClient, ExecClient, PtyClient, SSEEventType, SandboxState, SnapshotState } from "@alineo-labs/opensandbox";
|
|
2
3
|
//#region src/ledger.ts
|
|
3
4
|
/** Status of a sandbox session derived from its ledger events. */
|
|
@@ -73,46 +74,6 @@ let LedgerEvent = /* @__PURE__ */ function(LedgerEvent) {
|
|
|
73
74
|
return LedgerEvent;
|
|
74
75
|
}({});
|
|
75
76
|
//#endregion
|
|
76
|
-
//#region src/logger.ts
|
|
77
|
-
let LogLevel = /* @__PURE__ */ function(LogLevel) {
|
|
78
|
-
LogLevel[LogLevel["Debug"] = 0] = "Debug";
|
|
79
|
-
LogLevel[LogLevel["Info"] = 1] = "Info";
|
|
80
|
-
LogLevel[LogLevel["Warn"] = 2] = "Warn";
|
|
81
|
-
LogLevel[LogLevel["Error"] = 3] = "Error";
|
|
82
|
-
LogLevel[LogLevel["Silent"] = 4] = "Silent";
|
|
83
|
-
return LogLevel;
|
|
84
|
-
}({});
|
|
85
|
-
var ConsoleLogger = class {
|
|
86
|
-
minLevel;
|
|
87
|
-
constructor(minLevel = 1) {
|
|
88
|
-
this.minLevel = minLevel;
|
|
89
|
-
}
|
|
90
|
-
log(level, prefix, msg, meta) {
|
|
91
|
-
if (level < this.minLevel) return;
|
|
92
|
-
const out = meta ? `${prefix} ${msg} ${JSON.stringify(meta)}` : `${prefix} ${msg}`;
|
|
93
|
-
if (level >= 3) console.error(out);
|
|
94
|
-
else console.log(out);
|
|
95
|
-
}
|
|
96
|
-
debug(msg, meta) {
|
|
97
|
-
this.log(0, "[DEBUG]", msg, meta);
|
|
98
|
-
}
|
|
99
|
-
info(msg, meta) {
|
|
100
|
-
this.log(1, "[INFO]", msg, meta);
|
|
101
|
-
}
|
|
102
|
-
warn(msg, meta) {
|
|
103
|
-
this.log(2, "[WARN]", msg, meta);
|
|
104
|
-
}
|
|
105
|
-
error(msg, meta) {
|
|
106
|
-
this.log(3, "[ERROR]", msg, meta);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const noopLogger = {
|
|
110
|
-
debug: () => {},
|
|
111
|
-
info: () => {},
|
|
112
|
-
warn: () => {},
|
|
113
|
-
error: () => {}
|
|
114
|
-
};
|
|
115
|
-
//#endregion
|
|
116
77
|
//#region src/errors.ts
|
|
117
78
|
/** Base class for all alineo workflow runtime errors. */
|
|
118
79
|
var WorkflowError = class extends Error {
|
|
@@ -469,9 +430,11 @@ var InteractiveExecHandle = class extends ExecHandle {
|
|
|
469
430
|
*/
|
|
470
431
|
async function resolveExecClient(control, sandboxId, useServerProxy, retries = 45, delayMs = 2e3) {
|
|
471
432
|
const ep = await control.getEndpoint(sandboxId, 44772, useServerProxy);
|
|
433
|
+
const baseUrl = ep.endpoint.startsWith("http") ? ep.endpoint : `http://${ep.endpoint}`;
|
|
434
|
+
const token = ep.headers?.["X-EXECD-ACCESS-TOKEN"] ?? "";
|
|
472
435
|
const client = new ExecClient({
|
|
473
|
-
baseUrl
|
|
474
|
-
accessToken:
|
|
436
|
+
baseUrl,
|
|
437
|
+
accessToken: token
|
|
475
438
|
});
|
|
476
439
|
let delay = Math.min(100, delayMs);
|
|
477
440
|
for (let attempt = 0; attempt <= retries; attempt++) try {
|
|
@@ -597,9 +560,11 @@ var SandboxCore = class {
|
|
|
597
560
|
if (this._paused) throw new SandboxError("sandbox is paused — call resume() first", this.sandboxId);
|
|
598
561
|
await this.getExecClient();
|
|
599
562
|
const ep = await this.deps.control.getEndpoint(this.sandboxId, 44772, this.deps.useServerProxy);
|
|
563
|
+
const baseUrl = ep.endpoint.startsWith("http") ? ep.endpoint : `http://${ep.endpoint}`;
|
|
564
|
+
const token = ep.headers?.["X-EXECD-ACCESS-TOKEN"] ?? "";
|
|
600
565
|
return new PtyClient({
|
|
601
|
-
baseUrl
|
|
602
|
-
accessToken:
|
|
566
|
+
baseUrl,
|
|
567
|
+
accessToken: token
|
|
603
568
|
});
|
|
604
569
|
}
|
|
605
570
|
async waitForRunning(timeoutMs = 12e4) {
|
|
@@ -1116,10 +1081,11 @@ async function metrics(sb) {
|
|
|
1116
1081
|
*/
|
|
1117
1082
|
async function* watchMetrics(sb) {
|
|
1118
1083
|
const ec = await sb.getExecClient();
|
|
1119
|
-
for await (const ev of ec.watchMetrics())
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1084
|
+
for await (const ev of ec.watchMetrics()) if (isMetrics(ev)) yield ev;
|
|
1085
|
+
}
|
|
1086
|
+
/** `ExecClient.watchMetrics()` types every SSE payload as `SSEEvent`; this checks it's actually metrics. */
|
|
1087
|
+
function isMetrics(ev) {
|
|
1088
|
+
return "cpu" in ev && typeof ev.cpu === "number" && "memory" in ev && typeof ev.memory === "number";
|
|
1123
1089
|
}
|
|
1124
1090
|
/** Return sandbox diagnostic logs (names, sizes, and optional inline content). */
|
|
1125
1091
|
async function diagnosticLogs(sb) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alineo-labs/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,12 +29,13 @@
|
|
|
29
29
|
"test:watch": "vitest"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@alineo-labs/
|
|
32
|
+
"@alineo-labs/logger": "0.1.0",
|
|
33
|
+
"@alineo-labs/opensandbox": "0.3.1"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"bun-types": "1.
|
|
36
|
-
"tsdown": "0.
|
|
36
|
+
"bun-types": "1.4.2",
|
|
37
|
+
"tsdown": "0.23.0",
|
|
37
38
|
"typescript": "6.0.3",
|
|
38
|
-
"vitest": "
|
|
39
|
+
"vitest": "5.0.0"
|
|
39
40
|
}
|
|
40
41
|
}
|