@insforge/instabox-sdk 0.4.0 → 0.5.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/README.md +112 -11
- package/dist/index.cjs +32 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -1
- package/dist/index.d.ts +117 -1
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/instabox/SKILL.md +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -209,6 +209,75 @@ interface Connection {
|
|
|
209
209
|
expiresAt: string;
|
|
210
210
|
hostTrust: HostTrust;
|
|
211
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
|
+
}
|
|
212
281
|
/** Response of `POST /v1/machines/{id}/exec`. */
|
|
213
282
|
interface ExecResponse {
|
|
214
283
|
stdout: string;
|
|
@@ -517,6 +586,43 @@ interface CreateSnapshotOpts {
|
|
|
517
586
|
/** Save only the root disk; omit the persistent /data disk. */
|
|
518
587
|
rootOnly?: boolean;
|
|
519
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
|
+
}
|
|
520
626
|
interface SshCredentials {
|
|
521
627
|
host: string;
|
|
522
628
|
port: number;
|
|
@@ -558,6 +664,12 @@ declare class Sandbox {
|
|
|
558
664
|
static list(opts?: SandboxListOpts): Promise<SandboxInfo[]>;
|
|
559
665
|
/** Deletes a sandbox and its disks. Returns false if it did not exist. */
|
|
560
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>;
|
|
561
673
|
/** Lists the caller's private snapshots. Requires images:read. */
|
|
562
674
|
static listSnapshots(opts?: ConnectionOptions): Promise<Snapshot[]>;
|
|
563
675
|
/** Fetches a snapshot by ID. Requires images:read. */
|
|
@@ -570,6 +682,10 @@ declare class Sandbox {
|
|
|
570
682
|
* sandbox it waits first for a recent stop's upload to object storage (see `untilSynced`).
|
|
571
683
|
*/
|
|
572
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>;
|
|
573
689
|
/** Fetches the current state of the sandbox. */
|
|
574
690
|
getInfo(): Promise<SandboxInfo>;
|
|
575
691
|
/**
|
|
@@ -639,4 +755,4 @@ declare class Sandbox {
|
|
|
639
755
|
private mutate;
|
|
640
756
|
}
|
|
641
757
|
|
|
642
|
-
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 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);
|
|
@@ -973,6 +993,18 @@ var Sandbox = class _Sandbox {
|
|
|
973
993
|
async function getMachine(http, id) {
|
|
974
994
|
return http.request("GET", `/v1/machines/${enc2(id)}`);
|
|
975
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
|
+
}
|
|
976
1008
|
async function killMachine(http, id) {
|
|
977
1009
|
try {
|
|
978
1010
|
const op = await http.request("DELETE", `/v1/machines/${enc2(id)}`);
|