@miosa/sdk 3.2.3 → 3.2.5
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.ts +107 -22
- package/dist/index.js +218 -75
- package/dist/index.js.map +1 -1
- package/package.json +12 -13
package/dist/index.d.ts
CHANGED
|
@@ -5219,6 +5219,8 @@ interface MiosaErrorBody {
|
|
|
5219
5219
|
message?: string;
|
|
5220
5220
|
details?: unknown;
|
|
5221
5221
|
retryable?: boolean;
|
|
5222
|
+
request_id?: string;
|
|
5223
|
+
retry_after_ms?: number;
|
|
5222
5224
|
};
|
|
5223
5225
|
message?: string;
|
|
5224
5226
|
code?: string;
|
|
@@ -5227,6 +5229,7 @@ interface MiosaErrorBody {
|
|
|
5227
5229
|
reason?: string;
|
|
5228
5230
|
request_id?: string;
|
|
5229
5231
|
retryable?: boolean;
|
|
5232
|
+
retry_after_ms?: number;
|
|
5230
5233
|
}
|
|
5231
5234
|
declare class MiosaError extends Error {
|
|
5232
5235
|
readonly status: number;
|
|
@@ -5234,8 +5237,21 @@ declare class MiosaError extends Error {
|
|
|
5234
5237
|
readonly details: unknown;
|
|
5235
5238
|
readonly requestId: string | undefined;
|
|
5236
5239
|
readonly retryable: boolean;
|
|
5237
|
-
|
|
5238
|
-
|
|
5240
|
+
/**
|
|
5241
|
+
* Server-supplied retry hint in milliseconds, taken from the canonical
|
|
5242
|
+
* error shape's `retry_after_ms` (nested under `error` or top-level) or,
|
|
5243
|
+
* failing that, the HTTP `Retry-After` header. `undefined` when the
|
|
5244
|
+
* response carried neither, in which case a caller should fall back to
|
|
5245
|
+
* its own backoff policy.
|
|
5246
|
+
*/
|
|
5247
|
+
retryAfterMs: number | undefined;
|
|
5248
|
+
constructor(message: string, status: number, code: string, details?: unknown, requestId?: string, retryable?: boolean, retryAfterMs?: number);
|
|
5249
|
+
/**
|
|
5250
|
+
* @param retryAfterHeaderMs The `Retry-After` header value, already
|
|
5251
|
+
* converted to milliseconds by the caller. Used only when the body does
|
|
5252
|
+
* not carry the more precise `retry_after_ms`.
|
|
5253
|
+
*/
|
|
5254
|
+
static fromResponse(status: number, body: MiosaErrorBody, requestId?: string, retryAfterHeaderMs?: number): MiosaError;
|
|
5239
5255
|
}
|
|
5240
5256
|
declare class AuthError extends MiosaError {
|
|
5241
5257
|
constructor(message: string, status?: number, code?: string, details?: unknown, requestId?: string, retryable?: boolean);
|
|
@@ -6732,7 +6748,7 @@ type SandboxSize = "xs" | "small" | "medium" | "large" | "xl";
|
|
|
6732
6748
|
type SandboxId = string & {
|
|
6733
6749
|
readonly __brand: "SandboxId";
|
|
6734
6750
|
};
|
|
6735
|
-
type SandboxState = "provisioning" | "running" | "paused" | "destroying" | "destroyed" | "error";
|
|
6751
|
+
type SandboxState = "provisioning" | "running" | "pausing" | "paused" | "resuming" | "stopped" | "destroying" | "destroyed" | "error";
|
|
6736
6752
|
interface SandboxCreateParams {
|
|
6737
6753
|
templateId?: string;
|
|
6738
6754
|
template_id?: string;
|
|
@@ -6827,8 +6843,18 @@ interface SandboxCreateParams {
|
|
|
6827
6843
|
}
|
|
6828
6844
|
interface SandboxGetOrCreateParams extends SandboxCreateParams {
|
|
6829
6845
|
name: string;
|
|
6830
|
-
/**
|
|
6846
|
+
/**
|
|
6847
|
+
* Resume an existing sandbox before returning it, when it is `paused`,
|
|
6848
|
+
* `stopped` (persistent sandboxes only), or - after a bounded wait - lands
|
|
6849
|
+
* in one of those states from `pausing`. Defaults to true.
|
|
6850
|
+
*/
|
|
6831
6851
|
resume?: boolean;
|
|
6852
|
+
/**
|
|
6853
|
+
* Bound on how long to wait out an in-progress `pausing` transition before
|
|
6854
|
+
* attempting resume, in seconds. The server's own pause work is typically
|
|
6855
|
+
* well under this. Defaults to 30.
|
|
6856
|
+
*/
|
|
6857
|
+
pausingWaitTimeoutSec?: number;
|
|
6832
6858
|
/**
|
|
6833
6859
|
* Wait for readiness before returning a created/resumed sandbox. Defaults to false.
|
|
6834
6860
|
*
|
|
@@ -6861,6 +6887,18 @@ interface SandboxExecOptions {
|
|
|
6861
6887
|
timeout?: number;
|
|
6862
6888
|
timeoutSec?: number;
|
|
6863
6889
|
timeout_sec?: number;
|
|
6890
|
+
/**
|
|
6891
|
+
* `exec.stream` only. Budget (seconds) reserved for the sandbox to wake
|
|
6892
|
+
* and resume before the command's own `timeoutSec` starts counting down,
|
|
6893
|
+
* separate from it. The server opens the SSE response, runs
|
|
6894
|
+
* `ensure_running` (which resumes a paused sandbox), and only then starts
|
|
6895
|
+
* the command's own timeout - so without a separate budget a slow resume
|
|
6896
|
+
* could abort a command client-side while it is still within its own
|
|
6897
|
+
* server-side deadline. Defaults to {@link DEFAULT_EXEC_WAKE_BUDGET_SEC}.
|
|
6898
|
+
* Has no effect when `timeoutSec` is omitted (the stream is unbounded).
|
|
6899
|
+
*/
|
|
6900
|
+
wakeTimeoutSec?: number;
|
|
6901
|
+
wake_timeout_sec?: number;
|
|
6864
6902
|
}
|
|
6865
6903
|
interface SandboxExecResult {
|
|
6866
6904
|
stdout: string;
|
|
@@ -6869,6 +6907,14 @@ interface SandboxExecResult {
|
|
|
6869
6907
|
exit_code: number;
|
|
6870
6908
|
durationMs?: number;
|
|
6871
6909
|
duration_ms?: number;
|
|
6910
|
+
/**
|
|
6911
|
+
* True when the server killed the command for exceeding its timeout.
|
|
6912
|
+
* Without this, a timeout was indistinguishable from the infra error
|
|
6913
|
+
* frame, which also reports `exitCode: -1`. Absent when the server did
|
|
6914
|
+
* not report it (older servers, or a non-timeout exit).
|
|
6915
|
+
*/
|
|
6916
|
+
timedOut?: boolean;
|
|
6917
|
+
timed_out?: boolean;
|
|
6872
6918
|
}
|
|
6873
6919
|
interface SandboxExportFile {
|
|
6874
6920
|
path: string;
|
|
@@ -6902,7 +6948,10 @@ interface SandboxExportParams {
|
|
|
6902
6948
|
* The server tags each SSE frame with an `event:` name (`stdout` / `stderr` /
|
|
6903
6949
|
* `exit`); the SDK maps that name onto `type`. For output frames `data` (and
|
|
6904
6950
|
* its legacy alias `line`) carry the text chunk. The exit frame carries the
|
|
6905
|
-
* process exit code as both `exit_code` and its camelCase alias `exitCode
|
|
6951
|
+
* process exit code as both `exit_code` and its camelCase alias `exitCode`,
|
|
6952
|
+
* plus `timed_out`/`timedOut` when the server reports it (see B1-9: without
|
|
6953
|
+
* this a timeout was indistinguishable from the infra error frame, which
|
|
6954
|
+
* also reports `exit_code: -1`).
|
|
6906
6955
|
*/
|
|
6907
6956
|
type SandboxExecEvent = {
|
|
6908
6957
|
type: "stdout";
|
|
@@ -6916,6 +6965,8 @@ type SandboxExecEvent = {
|
|
|
6916
6965
|
type: "exit";
|
|
6917
6966
|
exit_code: number;
|
|
6918
6967
|
exitCode: number;
|
|
6968
|
+
timed_out?: boolean;
|
|
6969
|
+
timedOut?: boolean;
|
|
6919
6970
|
};
|
|
6920
6971
|
interface SandboxExecRunner {
|
|
6921
6972
|
(command: string, options?: SandboxExecOptions): Promise<SandboxExecResult>;
|
|
@@ -7457,6 +7508,17 @@ declare class Sandbox {
|
|
|
7457
7508
|
[key: string]: unknown;
|
|
7458
7509
|
}>;
|
|
7459
7510
|
pause(): Promise<Sandbox>;
|
|
7511
|
+
/**
|
|
7512
|
+
* Resume a paused (or persistent-stopped) sandbox.
|
|
7513
|
+
*
|
|
7514
|
+
* Always sends an `Idempotency-Key`, generating a fresh one when the
|
|
7515
|
+
* caller doesn't supply one - same rationale as {@link generateIdempotencyKey}
|
|
7516
|
+
* for create(): the key is built once here and threaded through a single
|
|
7517
|
+
* `HttpClient.request` call, whose headers are fixed before its retry loop
|
|
7518
|
+
* runs, so every retry of *this* resume replays the same key. Without this,
|
|
7519
|
+
* a client-side retry of a slow resume could dispatch a second full resume
|
|
7520
|
+
* execution (re-running host reservation) instead of deduping server-side.
|
|
7521
|
+
*/
|
|
7460
7522
|
resume(idempotencyKey?: string): Promise<Sandbox>;
|
|
7461
7523
|
deploy(params?: SandboxDeployParams): Promise<Record<string, unknown>>;
|
|
7462
7524
|
deployDocker(params?: SandboxDeployParams): Promise<Record<string, unknown>>;
|
|
@@ -7468,30 +7530,39 @@ declare class Sandbox {
|
|
|
7468
7530
|
/** Check readiness of the sandbox (GET /sandboxes/:id/readiness). */
|
|
7469
7531
|
readiness(): Promise<Record<string, unknown>>;
|
|
7470
7532
|
/**
|
|
7471
|
-
* Block until the sandbox reports ready, or *timeout* seconds
|
|
7533
|
+
* Block until the sandbox reports ready, or the caller's *timeout* seconds
|
|
7534
|
+
* (the full deadline budget) elapse.
|
|
7472
7535
|
*
|
|
7473
|
-
* When `stream` is `true` (the default) this opens an SSE connection
|
|
7474
|
-
*
|
|
7475
|
-
* `event: ready` frame.
|
|
7476
|
-
*
|
|
7477
|
-
*
|
|
7536
|
+
* When `stream` is `true` (the default) this opens an SSE connection to
|
|
7537
|
+
* `GET /sandboxes/:id/readiness/stream?timeout=<window>` and waits for an
|
|
7538
|
+
* `event: ready` frame. `<window>` is the caller's remaining budget clamped
|
|
7539
|
+
* to {@link READINESS_STREAM_MAX_TIMEOUT_SEC}, the server's own maximum
|
|
7540
|
+
* lease for a single stream connection — a long-restoring persistent
|
|
7541
|
+
* sandbox (e.g. Docker restore, 60-90 s) legitimately outlives one lease.
|
|
7542
|
+
* The server emits `ready` immediately if the sandbox is already ready,
|
|
7543
|
+
* `event: timeout` when *that connection's* window elapses without a
|
|
7544
|
+
* verdict, and `event: error` on a terminal boot failure.
|
|
7478
7545
|
*
|
|
7479
|
-
*
|
|
7480
|
-
*
|
|
7546
|
+
* An `event: timeout` (or the stream closing without a verdict) is NOT
|
|
7547
|
+
* treated as the final answer while the caller's overall deadline still has
|
|
7548
|
+
* budget left — that would silently truncate a 180 s wait down to the
|
|
7549
|
+
* server's lease window and return `false` while the sandbox was still
|
|
7550
|
+
* mid-restore. Instead this reconnects the stream (or falls back to
|
|
7551
|
+
* polling) for the remaining budget. `false` is only returned once the
|
|
7552
|
+
* caller's full deadline has elapsed.
|
|
7481
7553
|
*
|
|
7482
7554
|
* Throws {@link MiosaError} with code `SANDBOX_BOOT_FAILED` as soon as the
|
|
7483
7555
|
* sandbox is observed in a terminal failure state (`error` or `destroyed`)
|
|
7484
7556
|
* while waiting, instead of silently exhausting the timeout and returning
|
|
7485
7557
|
* `false` — a permanent boot failure and "still booting, keep waiting" must
|
|
7486
|
-
* never look the same to the caller.
|
|
7487
|
-
*
|
|
7488
|
-
*
|
|
7489
|
-
* authoritative {@link readiness} check before giving up, to catch a
|
|
7490
|
-
* failure that landed right at the boundary.
|
|
7558
|
+
* never look the same to the caller. On each `event: timeout` boundary this
|
|
7559
|
+
* also makes one authoritative {@link readiness} check before deciding to
|
|
7560
|
+
* reconnect or stop, to catch a failure that landed right at the boundary.
|
|
7491
7561
|
*
|
|
7492
7562
|
* If the SSE endpoint returns 404 (server pre-dates the streaming
|
|
7493
7563
|
* endpoint) this transparently falls back to polling {@link readiness}
|
|
7494
|
-
* every 10 ms until ready,
|
|
7564
|
+
* every 10 ms until ready, the caller's deadline elapses, or terminal
|
|
7565
|
+
* failure.
|
|
7495
7566
|
*/
|
|
7496
7567
|
waitUntilReady(options?: {
|
|
7497
7568
|
timeout?: number;
|
|
@@ -7522,6 +7593,15 @@ declare class Sandbox {
|
|
|
7522
7593
|
* stream endpoint is unavailable (404 or transport error) so callers
|
|
7523
7594
|
* can fall back to polling.
|
|
7524
7595
|
*/
|
|
7596
|
+
/**
|
|
7597
|
+
* Opens one readiness SSE connection for at most *windowSec* seconds (this
|
|
7598
|
+
* is a single lease, not the caller's overall {@link waitUntilReady}
|
|
7599
|
+
* budget — see there for how leases are chained). *windowSec* is sent to
|
|
7600
|
+
* the server as `?timeout=<seconds>` so the server's own stream deadline
|
|
7601
|
+
* matches what was actually requested instead of always falling back to
|
|
7602
|
+
* its 30 s default, which is what let a 180 s `waitUntilReady` call get
|
|
7603
|
+
* cut short at 30 s.
|
|
7604
|
+
*/
|
|
7525
7605
|
private tryReadinessStream;
|
|
7526
7606
|
destroy(): Promise<void>;
|
|
7527
7607
|
delete(): Promise<void>;
|
|
@@ -7557,9 +7637,14 @@ declare class Sandboxes {
|
|
|
7557
7637
|
/**
|
|
7558
7638
|
* Idempotently obtain a persistent sandbox by stable name.
|
|
7559
7639
|
*
|
|
7560
|
-
* If the sandbox exists, it is returned.
|
|
7561
|
-
*
|
|
7562
|
-
*
|
|
7640
|
+
* If the sandbox exists, it is returned. Unless `resume === false`: a
|
|
7641
|
+
* `paused` or persistent `stopped` sandbox is resumed; a `pausing`
|
|
7642
|
+
* sandbox is waited out (bounded by `pausingWaitTimeoutSec`) and then
|
|
7643
|
+
* resumed if it landed on `paused`/`stopped`; a resume answered with a
|
|
7644
|
+
* 409 the server marks `retryable: true` (e.g. a concurrent pause still
|
|
7645
|
+
* finishing) is retried using the server's `retry_after_ms` hint. If the
|
|
7646
|
+
* sandbox does not exist, it is created with the supplied params.
|
|
7647
|
+
* Destroyed sandboxes are permanent and are not resumed by this helper.
|
|
7563
7648
|
*/
|
|
7564
7649
|
getOrCreate(params: SandboxGetOrCreateParams): Promise<Sandbox>;
|
|
7565
7650
|
delete(id: SandboxId | string): Promise<void>;
|