@alineo-labs/core 0.4.0 → 0.4.1

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 CHANGED
@@ -1,8 +1,7 @@
1
1
  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
2
  //#region src/ledger.d.ts
4
3
  /** Status of a sandbox session derived from its ledger events. */
5
- declare enum SandboxStatus {
4
+ export declare enum SandboxStatus {
6
5
  Running = "running",
7
6
  Completed = "completed"
8
7
  }
@@ -69,7 +68,7 @@ interface ListSandboxOptions {
69
68
  teamId?: string;
70
69
  }
71
70
  /** Events emitted during execution and stored in the ledger. */
72
- declare enum LedgerEvent {
71
+ export declare enum LedgerEvent {
73
72
  /** Emitted when a sandbox is created and reaches Running state. */
74
73
  SandboxCreated = "sandbox_created",
75
74
  /** Emitted at the start of each exec() or execCode() call. */
@@ -218,7 +217,7 @@ interface IStorageAdapter {
218
217
  }
219
218
  //#endregion
220
219
  //#region src/logger.d.ts
221
- declare enum LogLevel {
220
+ export declare enum LogLevel {
222
221
  Debug = 0,
223
222
  Info = 1,
224
223
  Warn = 2,
@@ -231,7 +230,7 @@ interface ILogger {
231
230
  warn(msg: string, meta?: Record<string, unknown>): void;
232
231
  error(msg: string, meta?: Record<string, unknown>): void;
233
232
  }
234
- declare class ConsoleLogger implements ILogger {
233
+ export declare class ConsoleLogger implements ILogger {
235
234
  private readonly minLevel;
236
235
  constructor(minLevel?: LogLevel);
237
236
  private log;
@@ -240,7 +239,7 @@ declare class ConsoleLogger implements ILogger {
240
239
  warn(msg: string, meta?: Record<string, unknown>): void;
241
240
  error(msg: string, meta?: Record<string, unknown>): void;
242
241
  }
243
- declare const noopLogger: ILogger;
242
+ export declare const noopLogger: ILogger;
244
243
  //#endregion
245
244
  //#region src/credentials.d.ts
246
245
  /**
@@ -330,7 +329,7 @@ type CredentialResolver = (name: string, source: CredentialSource) => string | u
330
329
  * silently dropping the credential (the previous behavior when no resolver was supplied at
331
330
  * all — see plans/credential-injection.md).
332
331
  */
333
- declare function resolveBoundCredential(name: string, source: CredentialSource | undefined, resolver: CredentialResolver | undefined, sandboxId: string): Promise<string>;
332
+ export declare function resolveBoundCredential(name: string, source: CredentialSource | undefined, resolver: CredentialResolver | undefined, sandboxId: string): Promise<string>;
334
333
  /** One credential's reconstructed state, as recovered from ledger history by `reconstructBoundCredentials()`. */
335
334
  interface BoundCredential {
336
335
  binding: CredentialBinding;
@@ -343,7 +342,7 @@ interface BoundCredential {
343
342
  * operation. Scans the *whole* history, not just some replay window — credential bindings
344
343
  * aren't tied to specific execs the way exec replay is.
345
344
  */
346
- declare function reconstructBoundCredentials(entries: LedgerEntry[]): Map<string, BoundCredential>;
345
+ export declare function reconstructBoundCredentials(entries: LedgerEntry[]): Map<string, BoundCredential>;
347
346
  //#endregion
348
347
  //#region src/egress.d.ts
349
348
  /** The still-live outcome of a session's runtime `sb.egress.*` calls. */
@@ -370,7 +369,7 @@ interface ReconstructedEgress {
370
369
  * a re-add after a delete brings it back. Scans the whole history, like
371
370
  * `reconstructBoundCredentials`.
372
371
  */
373
- declare function reconstructEgressRules(entries: LedgerEntry[]): ReconstructedEgress;
372
+ export declare function reconstructEgressRules(entries: LedgerEntry[]): ReconstructedEgress;
374
373
  //#endregion
375
374
  //#region src/exec-handle.d.ts
376
375
  interface ExecResult {
@@ -386,8 +385,10 @@ type ExecDriver = {
386
385
  type: "replay";
387
386
  result: ExecResult;
388
387
  } | {
389
- type: "pty"; /** Output already recorded before this handle was created (e.g. resumed from ledger) — shown as scrollback before live output resumes. */
390
- seedStdout?: string; /** Wire up push-based output/exit/failure callbacks. Called once, synchronously. */
388
+ type: "pty";
389
+ /** Output already recorded before this handle was created (e.g. resumed from ledger) — shown as scrollback before live output resumes. */
390
+ seedStdout?: string;
391
+ /** Wire up push-based output/exit/failure callbacks. Called once, synchronously. */
391
392
  attach: (push: (chunk: string) => void, finish: (exitCode: number) => void, fail: (err: unknown) => void) => void;
392
393
  onDone: (r: ExecResult) => Promise<void>;
393
394
  };
@@ -416,7 +417,7 @@ interface PtyControls {
416
417
  * for await (const chunk of sb.exec("npm test").stdout()) process.stdout.write(chunk);
417
418
  * ```
418
419
  */
419
- declare class ExecHandle implements PromiseLike<ExecResult> {
420
+ export declare class ExecHandle implements PromiseLike<ExecResult> {
420
421
  private readonly _promise;
421
422
  private readonly _chunks;
422
423
  private _wakeup;
@@ -466,7 +467,7 @@ interface AttachableSource {
466
467
  * await sb.exec("bash", { interactive: true }).attach(process.stdin, process.stdout);
467
468
  * ```
468
469
  */
469
- declare class InteractiveExecHandle extends ExecHandle {
470
+ export declare class InteractiveExecHandle extends ExecHandle {
470
471
  private readonly _controls?;
471
472
  constructor(driver: ExecDriver, controls?: PtyControls);
472
473
  /** Send input to the running process. No-op if the session already ended. */
@@ -610,7 +611,7 @@ interface SandboxInternal {
610
611
  *
611
612
  * Create with `sandbox.createSession()`. Always call `close()` when done.
612
613
  */
613
- declare class BashSession {
614
+ export declare class BashSession {
614
615
  /** execd session ID. */
615
616
  readonly sessionId: string;
616
617
  private readonly _execFn;
@@ -787,7 +788,7 @@ declare class SandboxCore implements SandboxInternal {
787
788
  * await sb.close();
788
789
  * ```
789
790
  */
790
- declare class SandboxHandle extends SandboxCore {
791
+ export declare class SandboxHandle extends SandboxCore {
791
792
  /** Write a file into the sandbox. */
792
793
  writeFile(path: string, content: string): Promise<void>;
793
794
  /** Read a file from the sandbox as a UTF-8 string. */
@@ -1011,7 +1012,7 @@ declare class SandboxHandle extends SandboxCore {
1011
1012
  * fixed by scheduling around it from here, so it's addressed by simply affording much more
1012
1013
  * patience before giving up.
1013
1014
  */
1014
- declare function resolveExecClient(control: ControlClient, sandboxId: string, useServerProxy?: boolean, retries?: number, delayMs?: number): Promise<ExecClient>;
1015
+ export declare function resolveExecClient(control: ControlClient, sandboxId: string, useServerProxy?: boolean, retries?: number, delayMs?: number): Promise<ExecClient>;
1015
1016
  //#endregion
1016
1017
  //#region src/sandbox/hooks.d.ts
1017
1018
  interface ComposeHooksOptions {
@@ -1045,11 +1046,11 @@ interface ComposeHooksOptions {
1045
1046
  * });
1046
1047
  * ```
1047
1048
  */
1048
- declare function composeHooks(hooks: (SandboxHooks | undefined)[], opts?: ComposeHooksOptions): SandboxHooks;
1049
+ export declare function composeHooks(hooks: (SandboxHooks | undefined)[], opts?: ComposeHooksOptions): SandboxHooks;
1049
1050
  //#endregion
1050
1051
  //#region src/errors.d.ts
1051
1052
  /** Base class for all alineo workflow runtime errors. */
1052
- declare class WorkflowError extends Error {
1053
+ export declare class WorkflowError extends Error {
1053
1054
  constructor(message: string);
1054
1055
  }
1055
1056
  /**
@@ -1057,11 +1058,11 @@ declare class WorkflowError extends Error {
1057
1058
  * `Running` state; being paused when an operation requires a live sandbox;
1058
1059
  * `fork()` being unsupported on this sandbox; or a snapshot operation failing.
1059
1060
  */
1060
- declare class SandboxError extends WorkflowError {
1061
+ export declare class SandboxError extends WorkflowError {
1061
1062
  /** The sandbox ID, if one was assigned before the failure. */
1062
1063
  readonly sandboxId?: string | undefined;
1063
- constructor(message: string, /** The sandbox ID, if one was assigned before the failure. */
1064
-
1064
+ constructor(message: string,
1065
+ /** The sandbox ID, if one was assigned before the failure. */
1065
1066
  sandboxId?: string | undefined);
1066
1067
  }
1067
1068
  /**
@@ -1069,7 +1070,7 @@ declare class SandboxError extends WorkflowError {
1069
1070
  * The sandbox is `Running` from the control plane's perspective, but the exec
1070
1071
  * daemon is not accepting connections.
1071
1072
  */
1072
- declare class ExecConnectionError extends WorkflowError {
1073
+ export declare class ExecConnectionError extends WorkflowError {
1073
1074
  readonly sandboxId: string;
1074
1075
  constructor(sandboxId: string);
1075
1076
  }
@@ -1080,7 +1081,7 @@ declare class ExecConnectionError extends WorkflowError {
1080
1081
  * `BashSession.exec()` (a persistent session from `createSession()`), always
1081
1082
  * thrown on non-zero exit; there is no `strict` option for session execs.
1082
1083
  */
1083
- declare class CommandError extends WorkflowError {
1084
+ export declare class CommandError extends WorkflowError {
1084
1085
  readonly exitCode: number;
1085
1086
  readonly command: string;
1086
1087
  readonly sandboxId: string;
@@ -1091,10 +1092,10 @@ declare class CommandError extends WorkflowError {
1091
1092
  * in this codebase. `SandboxOptions.timeout`/`step.timeout` in `@alineo-labs/workflow`
1092
1093
  * bound sandbox container lifetime, which is a related but distinct concept.
1093
1094
  */
1094
- declare class StepTimeoutError extends WorkflowError {
1095
+ export declare class StepTimeoutError extends WorkflowError {
1095
1096
  readonly stepId: string;
1096
1097
  readonly timeoutMs: number;
1097
1098
  constructor(stepId: string, timeoutMs: number);
1098
1099
  }
1099
1100
  //#endregion
1100
- export { type AttachableSource, BashSession, type BoundCredential, type CheckpointInfo, CommandError, type ComposeHooksOptions, ConsoleLogger, type CredentialBinding, type CredentialBroker, type CredentialInjection, type CredentialResolver, type CredentialSource, type DiagnosticEvent, type DiagnosticLog, type EnvironmentRecord, type ExecCodeOptions, ExecConnectionError, ExecHandle, type ExecOptions, type ExecResult, type FileInfo, type ILogger, type IStorageAdapter, InteractiveExecHandle, type LedgerEntry, LedgerEvent, type ListSandboxOptions, LogLevel, type Metrics, type PendingInteractiveExec, type PtyControls, type ReconstructedEgress, type SandboxDeps, type SandboxDetails, SandboxError, SandboxHandle, type SandboxHooks, SandboxStatus, StepTimeoutError, WorkflowError, composeHooks, noopLogger, reconstructBoundCredentials, reconstructEgressRules, resolveBoundCredential, resolveExecClient };
1101
+ export type { AttachableSource, BoundCredential, CheckpointInfo, ComposeHooksOptions, CredentialBinding, CredentialBroker, CredentialInjection, CredentialResolver, CredentialSource, DiagnosticEvent, DiagnosticLog, EnvironmentRecord, ExecCodeOptions, ExecOptions, ExecResult, FileInfo, ILogger, IStorageAdapter, LedgerEntry, ListSandboxOptions, Metrics, PendingInteractiveExec, PtyControls, ReconstructedEgress, SandboxDeps, SandboxDetails, SandboxHooks };
package/dist/index.mjs CHANGED
@@ -469,9 +469,11 @@ var InteractiveExecHandle = class extends ExecHandle {
469
469
  */
470
470
  async function resolveExecClient(control, sandboxId, useServerProxy, retries = 45, delayMs = 2e3) {
471
471
  const ep = await control.getEndpoint(sandboxId, 44772, useServerProxy);
472
+ const baseUrl = ep.endpoint.startsWith("http") ? ep.endpoint : `http://${ep.endpoint}`;
473
+ const token = ep.headers?.["X-EXECD-ACCESS-TOKEN"] ?? "";
472
474
  const client = new ExecClient({
473
- baseUrl: ep.endpoint.startsWith("http") ? ep.endpoint : `http://${ep.endpoint}`,
474
- accessToken: ep.headers?.["X-EXECD-ACCESS-TOKEN"] ?? ""
475
+ baseUrl,
476
+ accessToken: token
475
477
  });
476
478
  let delay = Math.min(100, delayMs);
477
479
  for (let attempt = 0; attempt <= retries; attempt++) try {
@@ -597,9 +599,11 @@ var SandboxCore = class {
597
599
  if (this._paused) throw new SandboxError("sandbox is paused — call resume() first", this.sandboxId);
598
600
  await this.getExecClient();
599
601
  const ep = await this.deps.control.getEndpoint(this.sandboxId, 44772, this.deps.useServerProxy);
602
+ const baseUrl = ep.endpoint.startsWith("http") ? ep.endpoint : `http://${ep.endpoint}`;
603
+ const token = ep.headers?.["X-EXECD-ACCESS-TOKEN"] ?? "";
600
604
  return new PtyClient({
601
- baseUrl: ep.endpoint.startsWith("http") ? ep.endpoint : `http://${ep.endpoint}`,
602
- accessToken: ep.headers?.["X-EXECD-ACCESS-TOKEN"] ?? ""
605
+ baseUrl,
606
+ accessToken: token
603
607
  });
604
608
  }
605
609
  async waitForRunning(timeoutMs = 12e4) {
@@ -1116,10 +1120,11 @@ async function metrics(sb) {
1116
1120
  */
1117
1121
  async function* watchMetrics(sb) {
1118
1122
  const ec = await sb.getExecClient();
1119
- for await (const ev of ec.watchMetrics()) {
1120
- const m = ev;
1121
- if (typeof m.cpu === "number" && typeof m.memory === "number") yield m;
1122
- }
1123
+ for await (const ev of ec.watchMetrics()) if (isMetrics(ev)) yield ev;
1124
+ }
1125
+ /** `ExecClient.watchMetrics()` types every SSE payload as `SSEEvent`; this checks it's actually metrics. */
1126
+ function isMetrics(ev) {
1127
+ return "cpu" in ev && typeof ev.cpu === "number" && "memory" in ev && typeof ev.memory === "number";
1123
1128
  }
1124
1129
  /** Return sandbox diagnostic logs (names, sizes, and optional inline content). */
1125
1130
  async function diagnosticLogs(sb) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alineo-labs/core",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,9 +32,9 @@
32
32
  "@alineo-labs/opensandbox": "0.3.0"
33
33
  },
34
34
  "devDependencies": {
35
- "bun-types": "1.3.14",
36
- "tsdown": "0.22.3",
35
+ "bun-types": "1.4.2",
36
+ "tsdown": "0.23.0",
37
37
  "typescript": "6.0.3",
38
- "vitest": "4.1.9"
38
+ "vitest": "5.0.0"
39
39
  }
40
40
  }