@insforge/instabox-sdk 0.3.0 → 0.5.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.cts CHANGED
@@ -79,10 +79,6 @@ interface Machine {
79
79
  snapshot?: {
80
80
  id: string;
81
81
  };
82
- forkedFrom?: {
83
- machineId: string;
84
- snapshotSeq: number;
85
- };
86
82
  spec: MachineSpec;
87
83
  storage: {
88
84
  sizeGiB: number;
@@ -162,7 +158,7 @@ interface MachineList {
162
158
  interface Operation {
163
159
  id: string;
164
160
  machineId: string;
165
- type: 'create' | 'start' | 'stop' | 'suspend' | 'resume' | 'delete' | 'fork';
161
+ type: 'create' | 'start' | 'stop' | 'suspend' | 'resume' | 'delete';
166
162
  state: 'queued' | 'running' | 'succeeded' | 'failed';
167
163
  phase?: string;
168
164
  error: ApiError | null;
@@ -213,6 +209,75 @@ interface Connection {
213
209
  expiresAt: string;
214
210
  hostTrust: HostTrust;
215
211
  }
212
+ /** One sample of `GET /v1/machines/{id}/metrics`. Bytes throughout. */
213
+ interface MachineMetric {
214
+ timestamp: string;
215
+ cpuUsedPct: number;
216
+ cpuCount: number;
217
+ memUsed: number;
218
+ memTotal: number;
219
+ /** Not reported yet; absent. */
220
+ diskUsed?: number;
221
+ diskTotal: number;
222
+ }
223
+ /** Response of `GET /v1/machines/{id}/metrics`. */
224
+ interface MachineMetrics {
225
+ metrics: MachineMetric[];
226
+ }
227
+ /** Response of `GET /v1/machines/{id}/usage`. */
228
+ interface MachineUsage {
229
+ from: string;
230
+ to: string;
231
+ runningSeconds: number;
232
+ vcpuSeconds: number;
233
+ memGiBSeconds: number;
234
+ diskGiBSeconds: number;
235
+ }
236
+ /** One sandbox's share of `Usage.storedBytes`. */
237
+ interface UsageMachineStorage {
238
+ id: string;
239
+ name: string;
240
+ state: MachineState;
241
+ /** Size of its /data disk. */
242
+ sizeBytes: number;
243
+ /** Its saved disks' share of stored bytes. */
244
+ diskBytes: number;
245
+ snapshots: number;
246
+ snapshotBytes: number;
247
+ }
248
+ interface UsageStorage {
249
+ machines: UsageMachineStorage[];
250
+ deletedMachineSnapshots: number;
251
+ deletedMachineSnapshotBytes: number;
252
+ }
253
+ interface UsageLimits {
254
+ maxMachines: number;
255
+ machineSpec?: MachineSpec;
256
+ maxSnapshots: number;
257
+ maxStoredGiB: number;
258
+ /** @deprecated read `maxSnapshots`. */
259
+ maxImages: number;
260
+ liveSnapshots?: boolean;
261
+ vault?: {
262
+ maxItems: number;
263
+ maxBytes: number;
264
+ };
265
+ }
266
+ /** Response of `GET /v1/usage`: your counts, stored bytes (measured about hourly) and limits. */
267
+ interface Usage {
268
+ /** When the byte figures were measured; null before your first measurement. */
269
+ computedAt: string | null;
270
+ logicalBytes: number;
271
+ storedBytes: number;
272
+ exclusiveBytes: number;
273
+ machines: number;
274
+ snapshots: number;
275
+ /** @deprecated read `snapshots`. */
276
+ images: number;
277
+ limits: UsageLimits;
278
+ /** `storedBytes` by sandbox. Absent before your first measurement. */
279
+ storage?: UsageStorage;
280
+ }
216
281
  /** Response of `POST /v1/machines/{id}/exec`. */
217
282
  interface ExecResponse {
218
283
  stdout: string;
@@ -232,7 +297,7 @@ interface ConnectionOptions {
232
297
  apiUrl?: string;
233
298
  /** Timeout of a single HTTP request in ms. Default 60 000; exec defaults to its command timeout plus 30 000. */
234
299
  requestTimeoutMs?: number;
235
- /** Max time to wait for a lifecycle operation (create, pause, resume, fork, kill) in ms. Default 600 000. */
300
+ /** Max time to wait for a lifecycle operation (create, pause, resume, kill) in ms. Default 600 000. */
236
301
  operationTimeoutMs?: number;
237
302
  /** Custom fetch implementation (tests, proxies). Default: global `fetch`. */
238
303
  fetch?: typeof fetch;
@@ -515,37 +580,49 @@ interface SandboxInfo {
515
580
  /** The raw machine object from the API. */
516
581
  machine: Machine;
517
582
  }
518
- interface ForkOpts {
519
- /** Name of the new sandbox. Default `<name>-fork-<random>`. */
520
- name?: string;
521
- vcpus?: number;
522
- memMiB?: number;
523
- /** May only grow. */
524
- diskGiB?: number;
525
- /** Root disk size in GiB; may only grow. */
526
- rootDiskGiB?: number;
527
- /** Timeout of the copy, as in `SandboxOpts.timeoutMs`. Default: none (the source's is not copied). */
528
- timeoutMs?: number;
529
- onTimeout?: OnTimeout;
530
- /** Idle pause of the copy, as in `SandboxOpts.autoSuspendMs`. Default: 30 minutes (the source's is not copied); `0`: never. */
531
- autoSuspendMs?: number;
532
- /** Metadata of the copy. Default: the source's; `{}` for none. */
533
- metadata?: Record<string, string>;
534
- /** `false`: the copy never gets the account's Vault items (a copy of a sandbox without the Vault never does). */
535
- vault?: boolean;
536
- /**
537
- * A fork needs a stopped source. When true (default), `fork()` stops the source first if needed
538
- * (running processes end, `/data` is kept) and leaves it stopped; call `resume()` to start it again.
539
- * When false, a source that is not stopped makes the call fail.
540
- */
541
- stopSource?: boolean;
542
- }
543
583
  interface CreateSnapshotOpts {
544
584
  name: string;
545
585
  description?: string;
546
586
  /** Save only the root disk; omit the persistent /data disk. */
547
587
  rootOnly?: boolean;
548
588
  }
589
+ /** One load sample of a sandbox, 30 s apart. Measured on the host; bytes throughout. */
590
+ interface SandboxMetrics {
591
+ timestamp: Date;
592
+ /** CPU time used over the sandbox's vCPUs, 0-100. */
593
+ cpuUsedPct: number;
594
+ cpuCount: number;
595
+ /** Guest memory touched (drops only when memory is reclaimed). */
596
+ memUsed: number;
597
+ memTotal: number;
598
+ /** Not reported yet; absent. */
599
+ diskUsed?: number;
600
+ /** System disk plus /data disk size. */
601
+ diskTotal: number;
602
+ }
603
+ interface SandboxMetricsOpts {
604
+ /** Start of the samples, at most 24 h ago. Default: 5 minutes ago. */
605
+ since?: Date;
606
+ }
607
+ /** What a sandbox used between `from` and `to`, for billing. */
608
+ interface SandboxUsage {
609
+ from: Date;
610
+ to: Date;
611
+ /** Seconds in state running (not paused or stopped). */
612
+ runningSeconds: number;
613
+ /** vCPUs times running seconds. */
614
+ vcpuSeconds: number;
615
+ /** Memory GiB times running seconds. */
616
+ memGiBSeconds: number;
617
+ /** Disk size (system disk plus /data) times the seconds the sandbox existed in the window. */
618
+ diskGiBSeconds: number;
619
+ }
620
+ interface SandboxUsageOpts {
621
+ /** Default: the start of the current calendar month (UTC). */
622
+ from?: Date;
623
+ /** Default: now. At most 366 days after `from`. */
624
+ to?: Date;
625
+ }
549
626
  interface SshCredentials {
550
627
  host: string;
551
628
  port: number;
@@ -587,6 +664,12 @@ declare class Sandbox {
587
664
  static list(opts?: SandboxListOpts): Promise<SandboxInfo[]>;
588
665
  /** Deletes a sandbox and its disks. Returns false if it did not exist. */
589
666
  static kill(sandboxId: string, opts?: ConnectionOptions): Promise<boolean>;
667
+ /** A sandbox's recent CPU and memory samples, oldest first (empty while it is not running). Requires machines:read. */
668
+ static getMetrics(sandboxId: string, opts?: SandboxMetricsOpts & ConnectionOptions): Promise<SandboxMetrics[]>;
669
+ /** What a sandbox used over a window (default: this calendar month); works for a deleted one by ID. Requires machines:read. */
670
+ static getUsage(sandboxId: string, opts?: SandboxUsageOpts & ConnectionOptions): Promise<SandboxUsage>;
671
+ /** Your account's counts, stored bytes (per sandbox in `storage`) and limits. Requires machines:read or images:read. */
672
+ static usage(opts?: ConnectionOptions): Promise<Usage>;
590
673
  /** Lists the caller's private snapshots. Requires images:read. */
591
674
  static listSnapshots(opts?: ConnectionOptions): Promise<Snapshot[]>;
592
675
  /** Fetches a snapshot by ID. Requires images:read. */
@@ -599,6 +682,10 @@ declare class Sandbox {
599
682
  * sandbox it waits first for a recent stop's upload to object storage (see `untilSynced`).
600
683
  */
601
684
  createSnapshot(opts: CreateSnapshotOpts): Promise<Snapshot>;
685
+ /** This sandbox's recent CPU and memory samples; see `Sandbox.getMetrics`. */
686
+ getMetrics(opts?: SandboxMetricsOpts): Promise<SandboxMetrics[]>;
687
+ /** What this sandbox used over a window; see `Sandbox.getUsage`. */
688
+ getUsage(opts?: SandboxUsageOpts): Promise<SandboxUsage>;
602
689
  /** Fetches the current state of the sandbox. */
603
690
  getInfo(): Promise<SandboxInfo>;
604
691
  /**
@@ -641,8 +728,6 @@ declare class Sandbox {
641
728
  private wake;
642
729
  /** Stops the sandbox (guest shutdown; processes end, `/data` is kept). */
643
730
  stop(): Promise<void>;
644
- /** Copies this sandbox (root disk and `/data`) into a new sandbox and waits until it runs. */
645
- fork(opts?: ForkOpts): Promise<Sandbox>;
646
731
  /** Deletes the sandbox and its disks. Returns false if it was already gone. */
647
732
  kill(): Promise<boolean>;
648
733
  /**
@@ -662,7 +747,7 @@ declare class Sandbox {
662
747
  private settle;
663
748
  /**
664
749
  * Waits until a stopped sandbox's disks are in object storage (`storage.synced`). A stop returns
665
- * once the host has the snapshot and uploads it after, so a fork or snapshot right after a stop
750
+ * once the host has the snapshot and uploads it after, so a snapshot right after a stop
666
751
  * was refused ("not uploaded to object storage"), which took long enough after a pause and resume
667
752
  * to fail every time. Only a stopped sandbox is waited for; the server says what else is wrong.
668
753
  */
@@ -670,4 +755,4 @@ declare class Sandbox {
670
755
  private mutate;
671
756
  }
672
757
 
673
- export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, Files, type ForkOpts, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxQuotaError, InstaboxTimeoutError, MAX_FILE_BYTES, MAX_STDIN_BYTES, type Machine, type MachineList, type MachineSpec, type MachineState, type MachineVault, type MachineVaultItem, type MouseButton, type OnTimeout, type Operation, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxOpts, type ScrollDirection, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type VaultApplied, type VaultFile, type VaultKept, type WriteInfo };
758
+ export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, Files, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxQuotaError, InstaboxTimeoutError, MAX_FILE_BYTES, MAX_STDIN_BYTES, type Machine, type MachineList, type MachineMetric, type MachineMetrics, type MachineSpec, type MachineState, type MachineUsage, type MachineVault, type MachineVaultItem, type MouseButton, type OnTimeout, type Operation, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxMetrics, type SandboxMetricsOpts, type SandboxOpts, type SandboxUsage, type SandboxUsageOpts, type ScrollDirection, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type Usage, type UsageLimits, type UsageMachineStorage, type UsageStorage, type VaultApplied, type VaultFile, type VaultKept, type WriteInfo };
package/dist/index.d.ts CHANGED
@@ -79,10 +79,6 @@ interface Machine {
79
79
  snapshot?: {
80
80
  id: string;
81
81
  };
82
- forkedFrom?: {
83
- machineId: string;
84
- snapshotSeq: number;
85
- };
86
82
  spec: MachineSpec;
87
83
  storage: {
88
84
  sizeGiB: number;
@@ -162,7 +158,7 @@ interface MachineList {
162
158
  interface Operation {
163
159
  id: string;
164
160
  machineId: string;
165
- type: 'create' | 'start' | 'stop' | 'suspend' | 'resume' | 'delete' | 'fork';
161
+ type: 'create' | 'start' | 'stop' | 'suspend' | 'resume' | 'delete';
166
162
  state: 'queued' | 'running' | 'succeeded' | 'failed';
167
163
  phase?: string;
168
164
  error: ApiError | null;
@@ -213,6 +209,75 @@ interface Connection {
213
209
  expiresAt: string;
214
210
  hostTrust: HostTrust;
215
211
  }
212
+ /** One sample of `GET /v1/machines/{id}/metrics`. Bytes throughout. */
213
+ interface MachineMetric {
214
+ timestamp: string;
215
+ cpuUsedPct: number;
216
+ cpuCount: number;
217
+ memUsed: number;
218
+ memTotal: number;
219
+ /** Not reported yet; absent. */
220
+ diskUsed?: number;
221
+ diskTotal: number;
222
+ }
223
+ /** Response of `GET /v1/machines/{id}/metrics`. */
224
+ interface MachineMetrics {
225
+ metrics: MachineMetric[];
226
+ }
227
+ /** Response of `GET /v1/machines/{id}/usage`. */
228
+ interface MachineUsage {
229
+ from: string;
230
+ to: string;
231
+ runningSeconds: number;
232
+ vcpuSeconds: number;
233
+ memGiBSeconds: number;
234
+ diskGiBSeconds: number;
235
+ }
236
+ /** One sandbox's share of `Usage.storedBytes`. */
237
+ interface UsageMachineStorage {
238
+ id: string;
239
+ name: string;
240
+ state: MachineState;
241
+ /** Size of its /data disk. */
242
+ sizeBytes: number;
243
+ /** Its saved disks' share of stored bytes. */
244
+ diskBytes: number;
245
+ snapshots: number;
246
+ snapshotBytes: number;
247
+ }
248
+ interface UsageStorage {
249
+ machines: UsageMachineStorage[];
250
+ deletedMachineSnapshots: number;
251
+ deletedMachineSnapshotBytes: number;
252
+ }
253
+ interface UsageLimits {
254
+ maxMachines: number;
255
+ machineSpec?: MachineSpec;
256
+ maxSnapshots: number;
257
+ maxStoredGiB: number;
258
+ /** @deprecated read `maxSnapshots`. */
259
+ maxImages: number;
260
+ liveSnapshots?: boolean;
261
+ vault?: {
262
+ maxItems: number;
263
+ maxBytes: number;
264
+ };
265
+ }
266
+ /** Response of `GET /v1/usage`: your counts, stored bytes (measured about hourly) and limits. */
267
+ interface Usage {
268
+ /** When the byte figures were measured; null before your first measurement. */
269
+ computedAt: string | null;
270
+ logicalBytes: number;
271
+ storedBytes: number;
272
+ exclusiveBytes: number;
273
+ machines: number;
274
+ snapshots: number;
275
+ /** @deprecated read `snapshots`. */
276
+ images: number;
277
+ limits: UsageLimits;
278
+ /** `storedBytes` by sandbox. Absent before your first measurement. */
279
+ storage?: UsageStorage;
280
+ }
216
281
  /** Response of `POST /v1/machines/{id}/exec`. */
217
282
  interface ExecResponse {
218
283
  stdout: string;
@@ -232,7 +297,7 @@ interface ConnectionOptions {
232
297
  apiUrl?: string;
233
298
  /** Timeout of a single HTTP request in ms. Default 60 000; exec defaults to its command timeout plus 30 000. */
234
299
  requestTimeoutMs?: number;
235
- /** Max time to wait for a lifecycle operation (create, pause, resume, fork, kill) in ms. Default 600 000. */
300
+ /** Max time to wait for a lifecycle operation (create, pause, resume, kill) in ms. Default 600 000. */
236
301
  operationTimeoutMs?: number;
237
302
  /** Custom fetch implementation (tests, proxies). Default: global `fetch`. */
238
303
  fetch?: typeof fetch;
@@ -515,37 +580,49 @@ interface SandboxInfo {
515
580
  /** The raw machine object from the API. */
516
581
  machine: Machine;
517
582
  }
518
- interface ForkOpts {
519
- /** Name of the new sandbox. Default `<name>-fork-<random>`. */
520
- name?: string;
521
- vcpus?: number;
522
- memMiB?: number;
523
- /** May only grow. */
524
- diskGiB?: number;
525
- /** Root disk size in GiB; may only grow. */
526
- rootDiskGiB?: number;
527
- /** Timeout of the copy, as in `SandboxOpts.timeoutMs`. Default: none (the source's is not copied). */
528
- timeoutMs?: number;
529
- onTimeout?: OnTimeout;
530
- /** Idle pause of the copy, as in `SandboxOpts.autoSuspendMs`. Default: 30 minutes (the source's is not copied); `0`: never. */
531
- autoSuspendMs?: number;
532
- /** Metadata of the copy. Default: the source's; `{}` for none. */
533
- metadata?: Record<string, string>;
534
- /** `false`: the copy never gets the account's Vault items (a copy of a sandbox without the Vault never does). */
535
- vault?: boolean;
536
- /**
537
- * A fork needs a stopped source. When true (default), `fork()` stops the source first if needed
538
- * (running processes end, `/data` is kept) and leaves it stopped; call `resume()` to start it again.
539
- * When false, a source that is not stopped makes the call fail.
540
- */
541
- stopSource?: boolean;
542
- }
543
583
  interface CreateSnapshotOpts {
544
584
  name: string;
545
585
  description?: string;
546
586
  /** Save only the root disk; omit the persistent /data disk. */
547
587
  rootOnly?: boolean;
548
588
  }
589
+ /** One load sample of a sandbox, 30 s apart. Measured on the host; bytes throughout. */
590
+ interface SandboxMetrics {
591
+ timestamp: Date;
592
+ /** CPU time used over the sandbox's vCPUs, 0-100. */
593
+ cpuUsedPct: number;
594
+ cpuCount: number;
595
+ /** Guest memory touched (drops only when memory is reclaimed). */
596
+ memUsed: number;
597
+ memTotal: number;
598
+ /** Not reported yet; absent. */
599
+ diskUsed?: number;
600
+ /** System disk plus /data disk size. */
601
+ diskTotal: number;
602
+ }
603
+ interface SandboxMetricsOpts {
604
+ /** Start of the samples, at most 24 h ago. Default: 5 minutes ago. */
605
+ since?: Date;
606
+ }
607
+ /** What a sandbox used between `from` and `to`, for billing. */
608
+ interface SandboxUsage {
609
+ from: Date;
610
+ to: Date;
611
+ /** Seconds in state running (not paused or stopped). */
612
+ runningSeconds: number;
613
+ /** vCPUs times running seconds. */
614
+ vcpuSeconds: number;
615
+ /** Memory GiB times running seconds. */
616
+ memGiBSeconds: number;
617
+ /** Disk size (system disk plus /data) times the seconds the sandbox existed in the window. */
618
+ diskGiBSeconds: number;
619
+ }
620
+ interface SandboxUsageOpts {
621
+ /** Default: the start of the current calendar month (UTC). */
622
+ from?: Date;
623
+ /** Default: now. At most 366 days after `from`. */
624
+ to?: Date;
625
+ }
549
626
  interface SshCredentials {
550
627
  host: string;
551
628
  port: number;
@@ -587,6 +664,12 @@ declare class Sandbox {
587
664
  static list(opts?: SandboxListOpts): Promise<SandboxInfo[]>;
588
665
  /** Deletes a sandbox and its disks. Returns false if it did not exist. */
589
666
  static kill(sandboxId: string, opts?: ConnectionOptions): Promise<boolean>;
667
+ /** A sandbox's recent CPU and memory samples, oldest first (empty while it is not running). Requires machines:read. */
668
+ static getMetrics(sandboxId: string, opts?: SandboxMetricsOpts & ConnectionOptions): Promise<SandboxMetrics[]>;
669
+ /** What a sandbox used over a window (default: this calendar month); works for a deleted one by ID. Requires machines:read. */
670
+ static getUsage(sandboxId: string, opts?: SandboxUsageOpts & ConnectionOptions): Promise<SandboxUsage>;
671
+ /** Your account's counts, stored bytes (per sandbox in `storage`) and limits. Requires machines:read or images:read. */
672
+ static usage(opts?: ConnectionOptions): Promise<Usage>;
590
673
  /** Lists the caller's private snapshots. Requires images:read. */
591
674
  static listSnapshots(opts?: ConnectionOptions): Promise<Snapshot[]>;
592
675
  /** Fetches a snapshot by ID. Requires images:read. */
@@ -599,6 +682,10 @@ declare class Sandbox {
599
682
  * sandbox it waits first for a recent stop's upload to object storage (see `untilSynced`).
600
683
  */
601
684
  createSnapshot(opts: CreateSnapshotOpts): Promise<Snapshot>;
685
+ /** This sandbox's recent CPU and memory samples; see `Sandbox.getMetrics`. */
686
+ getMetrics(opts?: SandboxMetricsOpts): Promise<SandboxMetrics[]>;
687
+ /** What this sandbox used over a window; see `Sandbox.getUsage`. */
688
+ getUsage(opts?: SandboxUsageOpts): Promise<SandboxUsage>;
602
689
  /** Fetches the current state of the sandbox. */
603
690
  getInfo(): Promise<SandboxInfo>;
604
691
  /**
@@ -641,8 +728,6 @@ declare class Sandbox {
641
728
  private wake;
642
729
  /** Stops the sandbox (guest shutdown; processes end, `/data` is kept). */
643
730
  stop(): Promise<void>;
644
- /** Copies this sandbox (root disk and `/data`) into a new sandbox and waits until it runs. */
645
- fork(opts?: ForkOpts): Promise<Sandbox>;
646
731
  /** Deletes the sandbox and its disks. Returns false if it was already gone. */
647
732
  kill(): Promise<boolean>;
648
733
  /**
@@ -662,7 +747,7 @@ declare class Sandbox {
662
747
  private settle;
663
748
  /**
664
749
  * Waits until a stopped sandbox's disks are in object storage (`storage.synced`). A stop returns
665
- * once the host has the snapshot and uploads it after, so a fork or snapshot right after a stop
750
+ * once the host has the snapshot and uploads it after, so a snapshot right after a stop
666
751
  * was refused ("not uploaded to object storage"), which took long enough after a pause and resume
667
752
  * to fail every time. Only a stopped sandbox is waited for; the server says what else is wrong.
668
753
  */
@@ -670,4 +755,4 @@ declare class Sandbox {
670
755
  private mutate;
671
756
  }
672
757
 
673
- export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, Files, type ForkOpts, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxQuotaError, InstaboxTimeoutError, MAX_FILE_BYTES, MAX_STDIN_BYTES, type Machine, type MachineList, type MachineSpec, type MachineState, type MachineVault, type MachineVaultItem, type MouseButton, type OnTimeout, type Operation, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxOpts, type ScrollDirection, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type VaultApplied, type VaultFile, type VaultKept, type WriteInfo };
758
+ export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, Files, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxQuotaError, InstaboxTimeoutError, MAX_FILE_BYTES, MAX_STDIN_BYTES, type Machine, type MachineList, type MachineMetric, type MachineMetrics, type MachineSpec, type MachineState, type MachineUsage, type MachineVault, type MachineVaultItem, type MouseButton, type OnTimeout, type Operation, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxMetrics, type SandboxMetricsOpts, type SandboxOpts, type SandboxUsage, type SandboxUsageOpts, type ScrollDirection, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type Usage, type UsageLimits, type UsageMachineStorage, type UsageStorage, type VaultApplied, type VaultFile, type VaultKept, type WriteInfo };
package/dist/index.js CHANGED
@@ -793,6 +793,18 @@ var Sandbox = class _Sandbox {
793
793
  static async kill(sandboxId, opts = {}) {
794
794
  return killMachine(new HttpClient(opts), sandboxId);
795
795
  }
796
+ /** A sandbox's recent CPU and memory samples, oldest first (empty while it is not running). Requires machines:read. */
797
+ static async getMetrics(sandboxId, opts = {}) {
798
+ return getMetrics(new HttpClient(opts), sandboxId, opts);
799
+ }
800
+ /** What a sandbox used over a window (default: this calendar month); works for a deleted one by ID. Requires machines:read. */
801
+ static async getUsage(sandboxId, opts = {}) {
802
+ return getUsage(new HttpClient(opts), sandboxId, opts);
803
+ }
804
+ /** Your account's counts, stored bytes (per sandbox in `storage`) and limits. Requires machines:read or images:read. */
805
+ static async usage(opts = {}) {
806
+ return new HttpClient(opts).request("GET", "/v1/usage");
807
+ }
796
808
  /** Lists the caller's private snapshots. Requires images:read. */
797
809
  static async listSnapshots(opts = {}) {
798
810
  const result = await new HttpClient(opts).request("GET", "/v1/snapshots");
@@ -822,6 +834,14 @@ var Sandbox = class _Sandbox {
822
834
  await this.untilSynced();
823
835
  return this.http.request("POST", `/v1/machines/${enc2(this.sandboxId)}/snapshots`, { body: opts });
824
836
  }
837
+ /** This sandbox's recent CPU and memory samples; see `Sandbox.getMetrics`. */
838
+ async getMetrics(opts = {}) {
839
+ return getMetrics(this.http, this.sandboxId, opts);
840
+ }
841
+ /** What this sandbox used over a window; see `Sandbox.getUsage`. */
842
+ async getUsage(opts = {}) {
843
+ return getUsage(this.http, this.sandboxId, opts);
844
+ }
825
845
  /** Fetches the current state of the sandbox. */
826
846
  async getInfo() {
827
847
  this.machine = await getMachine(this.http, this.sandboxId);
@@ -899,34 +919,6 @@ var Sandbox = class _Sandbox {
899
919
  if (this.machine.state === "suspended") await this.mutate("POST", "start");
900
920
  await this.mutate("POST", "stop");
901
921
  }
902
- /** Copies this sandbox (root disk and `/data`) into a new sandbox and waits until it runs. */
903
- async fork(opts = {}) {
904
- if (opts.timeoutMs !== void 0) toSeconds(opts.timeoutMs);
905
- if (opts.autoSuspendMs !== void 0) toIdleSeconds(opts.autoSuspendMs);
906
- await this.settle();
907
- if (this.machine.state !== "stopped") {
908
- if (opts.stopSource === false) {
909
- throw new InstaboxError(`fork needs a stopped sandbox; ${this.sandboxId} is ${this.machine.state}`, {
910
- code: "operation_conflict"
911
- });
912
- }
913
- await this.stop();
914
- }
915
- await this.untilSynced();
916
- const body = { name: opts.name ?? `${this.machine.name}-fork-${randomSuffix(4)}` };
917
- if (opts.vcpus !== void 0) body.vcpus = opts.vcpus;
918
- if (opts.memMiB !== void 0) body.memMiB = opts.memMiB;
919
- if (opts.diskGiB !== void 0) body.persistentDiskGiB = opts.diskGiB;
920
- if (opts.rootDiskGiB !== void 0) body.rootDiskGiB = opts.rootDiskGiB;
921
- if (opts.timeoutMs !== void 0) body.timeoutSeconds = toSeconds(opts.timeoutMs);
922
- if (opts.onTimeout) body.onTimeout = opts.onTimeout;
923
- if (opts.autoSuspendMs !== void 0) body.autoSuspendAfterSeconds = toIdleSeconds(opts.autoSuspendMs);
924
- if (opts.metadata) body.metadata = opts.metadata;
925
- if (opts.vault === false) body.vault = false;
926
- const op = await this.http.request("POST", `/v1/machines/${enc2(this.sandboxId)}/fork`, { body });
927
- const done = await this.http.waitForOperation(op);
928
- return new _Sandbox(this.http, await getMachine(this.http, done.machineId));
929
- }
930
922
  /** Deletes the sandbox and its disks. Returns false if it was already gone. */
931
923
  async kill() {
932
924
  return killMachine(this.http, this.sandboxId);
@@ -973,7 +965,7 @@ var Sandbox = class _Sandbox {
973
965
  }
974
966
  /**
975
967
  * Waits until a stopped sandbox's disks are in object storage (`storage.synced`). A stop returns
976
- * once the host has the snapshot and uploads it after, so a fork or snapshot right after a stop
968
+ * once the host has the snapshot and uploads it after, so a snapshot right after a stop
977
969
  * was refused ("not uploaded to object storage"), which took long enough after a pause and resume
978
970
  * to fail every time. Only a stopped sandbox is waited for; the server says what else is wrong.
979
971
  */
@@ -1001,6 +993,18 @@ var Sandbox = class _Sandbox {
1001
993
  async function getMachine(http, id) {
1002
994
  return http.request("GET", `/v1/machines/${enc2(id)}`);
1003
995
  }
996
+ async function getMetrics(http, id, opts) {
997
+ const out = await http.request("GET", `/v1/machines/${enc2(id)}/metrics`, {
998
+ query: { since: opts.since?.toISOString() }
999
+ });
1000
+ return out.metrics.map((s) => ({ ...s, timestamp: new Date(s.timestamp) }));
1001
+ }
1002
+ async function getUsage(http, id, opts) {
1003
+ const u = await http.request("GET", `/v1/machines/${enc2(id)}/usage`, {
1004
+ query: { from: opts.from?.toISOString(), to: opts.to?.toISOString() }
1005
+ });
1006
+ return { ...u, from: new Date(u.from), to: new Date(u.to) };
1007
+ }
1004
1008
  async function killMachine(http, id) {
1005
1009
  try {
1006
1010
  const op = await http.request("DELETE", `/v1/machines/${enc2(id)}`);