@insforge/instabox-sdk 0.10.0 → 0.11.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
@@ -679,6 +679,52 @@ declare class Commands {
679
679
  private waitJob;
680
680
  }
681
681
 
682
+ interface ComputerUseTool {
683
+ name: string;
684
+ description?: string;
685
+ /** JSON Schema of the tool's arguments. */
686
+ inputSchema?: Record<string, unknown>;
687
+ }
688
+ interface ComputerUseImage {
689
+ mimeType: string;
690
+ data: Uint8Array;
691
+ }
692
+ interface ComputerUseResult {
693
+ /** The text parts of the result, joined by newlines. */
694
+ text: string;
695
+ /** The image parts of the result (screenshots), decoded. */
696
+ images: ComputerUseImage[];
697
+ /** The tool reported an error; `text` says what. */
698
+ isError: boolean;
699
+ /** The tool's structured result, when it returns one. */
700
+ structuredContent?: unknown;
701
+ }
702
+ interface ComputerUseCallOptions {
703
+ /** Give up after this long (at most 600 000; default 60 s). */
704
+ timeoutMs?: number;
705
+ signal?: AbortSignal;
706
+ }
707
+ /**
708
+ * The sandbox's computer-use MCP server (`instabox-computer-use mcp`, on Linux, macOS and Windows
709
+ * desktop templates): its tools read apps' accessibility trees, take screenshots, and click and type
710
+ * into windows. Each call starts the server anew in the sandbox, so what one call read does not carry
711
+ * to the next; cua-driver's `run_steps` tool runs several actions in one call.
712
+ */
713
+ declare class ComputerUse {
714
+ private readonly commands;
715
+ /** @internal */
716
+ constructor(commands: Commands);
717
+ /** The server's tools, with their argument schemas. */
718
+ tools(opts?: ComputerUseCallOptions): Promise<ComputerUseTool[]>;
719
+ /**
720
+ * Calls one tool, for example `call('get_desktop_state')` for a screenshot of the whole screen or
721
+ * `call('list_windows')`. A tool that fails resolves with `isError: true`; it does not throw.
722
+ */
723
+ call(name: string, args?: Record<string, unknown>, opts?: ComputerUseCallOptions): Promise<ComputerUseResult>;
724
+ /** One request to a server started for it: the handshake and the request go in as stdin. */
725
+ private request;
726
+ }
727
+
682
728
  /**
683
729
  * Default cap of a buffered `files.read` (raise it with `maxBytes`, or use `readStream`), and the most
684
730
  * `files.write` moves on a server without the file routes (over exec). Over the file routes `write`
@@ -1208,6 +1254,8 @@ declare class Sandbox {
1208
1254
  readonly files: Files;
1209
1255
  /** See and control the sandbox's graphical desktop (screenshots, mouse, keyboard, a link to watch it). */
1210
1256
  readonly desktop: Desktop;
1257
+ /** The sandbox's computer-use MCP tools: accessibility trees, screenshots, clicks and typing in apps. */
1258
+ readonly computerUse: ComputerUse;
1211
1259
  /** Publish a port at an HTTPS URL, list published ports, unpublish them. */
1212
1260
  readonly ports: Ports;
1213
1261
  private machine;
@@ -1346,4 +1394,4 @@ declare class Sandbox {
1346
1394
  private mutate;
1347
1395
  }
1348
1396
 
1349
- export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, type CommandWaitOptions, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type DownloadInfo, type DownloadOptions, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, type FileStream, Files, type GpuQueueEntry, type GpuQueueListOpts, type GpuQueueOpt, type GpuQueuePage, type GpuUsage, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxNotUtf8Error, InstaboxQuotaError, InstaboxTimeoutError, LIMIT_CODES, MAX_FILE_BYTES, MAX_STDIN_BYTES, MAX_UPLOAD_BYTES, type Machine, type MachineList, type MachineMetric, type MachineMetrics, type MachineQueue, type MachineSpec, type MachineState, type MachineUsage, type MachineVault, type MachineVaultItem, type MouseButton, type Operation, type PortAccess, Ports, type PublicPort, type PublishPortOpts, type ReadStreamOptions, type ResizeOpts, type ResumeOpts, 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 TemplateGpuType, type TemplateRef, type UploadInfo, type UploadOptions, type Usage, type UsageCost, type UsageLimits, type UsageMachineStorage, type UsageStorage, type VaultApplied, type VaultFile, type VaultKept, type WriteData, type WriteInfo, type WriteOptions, isLimitCode };
1397
+ export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, type CommandWaitOptions, Commands, ComputerUse, type ComputerUseCallOptions, type ComputerUseImage, type ComputerUseResult, type ComputerUseTool, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type DownloadInfo, type DownloadOptions, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, type FileStream, Files, type GpuQueueEntry, type GpuQueueListOpts, type GpuQueueOpt, type GpuQueuePage, type GpuUsage, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxNotUtf8Error, InstaboxQuotaError, InstaboxTimeoutError, LIMIT_CODES, MAX_FILE_BYTES, MAX_STDIN_BYTES, MAX_UPLOAD_BYTES, type Machine, type MachineList, type MachineMetric, type MachineMetrics, type MachineQueue, type MachineSpec, type MachineState, type MachineUsage, type MachineVault, type MachineVaultItem, type MouseButton, type Operation, type PortAccess, Ports, type PublicPort, type PublishPortOpts, type ReadStreamOptions, type ResizeOpts, type ResumeOpts, 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 TemplateGpuType, type TemplateRef, type UploadInfo, type UploadOptions, type Usage, type UsageCost, type UsageLimits, type UsageMachineStorage, type UsageStorage, type VaultApplied, type VaultFile, type VaultKept, type WriteData, type WriteInfo, type WriteOptions, isLimitCode };
package/dist/index.d.ts CHANGED
@@ -679,6 +679,52 @@ declare class Commands {
679
679
  private waitJob;
680
680
  }
681
681
 
682
+ interface ComputerUseTool {
683
+ name: string;
684
+ description?: string;
685
+ /** JSON Schema of the tool's arguments. */
686
+ inputSchema?: Record<string, unknown>;
687
+ }
688
+ interface ComputerUseImage {
689
+ mimeType: string;
690
+ data: Uint8Array;
691
+ }
692
+ interface ComputerUseResult {
693
+ /** The text parts of the result, joined by newlines. */
694
+ text: string;
695
+ /** The image parts of the result (screenshots), decoded. */
696
+ images: ComputerUseImage[];
697
+ /** The tool reported an error; `text` says what. */
698
+ isError: boolean;
699
+ /** The tool's structured result, when it returns one. */
700
+ structuredContent?: unknown;
701
+ }
702
+ interface ComputerUseCallOptions {
703
+ /** Give up after this long (at most 600 000; default 60 s). */
704
+ timeoutMs?: number;
705
+ signal?: AbortSignal;
706
+ }
707
+ /**
708
+ * The sandbox's computer-use MCP server (`instabox-computer-use mcp`, on Linux, macOS and Windows
709
+ * desktop templates): its tools read apps' accessibility trees, take screenshots, and click and type
710
+ * into windows. Each call starts the server anew in the sandbox, so what one call read does not carry
711
+ * to the next; cua-driver's `run_steps` tool runs several actions in one call.
712
+ */
713
+ declare class ComputerUse {
714
+ private readonly commands;
715
+ /** @internal */
716
+ constructor(commands: Commands);
717
+ /** The server's tools, with their argument schemas. */
718
+ tools(opts?: ComputerUseCallOptions): Promise<ComputerUseTool[]>;
719
+ /**
720
+ * Calls one tool, for example `call('get_desktop_state')` for a screenshot of the whole screen or
721
+ * `call('list_windows')`. A tool that fails resolves with `isError: true`; it does not throw.
722
+ */
723
+ call(name: string, args?: Record<string, unknown>, opts?: ComputerUseCallOptions): Promise<ComputerUseResult>;
724
+ /** One request to a server started for it: the handshake and the request go in as stdin. */
725
+ private request;
726
+ }
727
+
682
728
  /**
683
729
  * Default cap of a buffered `files.read` (raise it with `maxBytes`, or use `readStream`), and the most
684
730
  * `files.write` moves on a server without the file routes (over exec). Over the file routes `write`
@@ -1208,6 +1254,8 @@ declare class Sandbox {
1208
1254
  readonly files: Files;
1209
1255
  /** See and control the sandbox's graphical desktop (screenshots, mouse, keyboard, a link to watch it). */
1210
1256
  readonly desktop: Desktop;
1257
+ /** The sandbox's computer-use MCP tools: accessibility trees, screenshots, clicks and typing in apps. */
1258
+ readonly computerUse: ComputerUse;
1211
1259
  /** Publish a port at an HTTPS URL, list published ports, unpublish them. */
1212
1260
  readonly ports: Ports;
1213
1261
  private machine;
@@ -1346,4 +1394,4 @@ declare class Sandbox {
1346
1394
  private mutate;
1347
1395
  }
1348
1396
 
1349
- export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, type CommandWaitOptions, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type DownloadInfo, type DownloadOptions, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, type FileStream, Files, type GpuQueueEntry, type GpuQueueListOpts, type GpuQueueOpt, type GpuQueuePage, type GpuUsage, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxNotUtf8Error, InstaboxQuotaError, InstaboxTimeoutError, LIMIT_CODES, MAX_FILE_BYTES, MAX_STDIN_BYTES, MAX_UPLOAD_BYTES, type Machine, type MachineList, type MachineMetric, type MachineMetrics, type MachineQueue, type MachineSpec, type MachineState, type MachineUsage, type MachineVault, type MachineVaultItem, type MouseButton, type Operation, type PortAccess, Ports, type PublicPort, type PublishPortOpts, type ReadStreamOptions, type ResizeOpts, type ResumeOpts, 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 TemplateGpuType, type TemplateRef, type UploadInfo, type UploadOptions, type Usage, type UsageCost, type UsageLimits, type UsageMachineStorage, type UsageStorage, type VaultApplied, type VaultFile, type VaultKept, type WriteData, type WriteInfo, type WriteOptions, isLimitCode };
1397
+ export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, type CommandWaitOptions, Commands, ComputerUse, type ComputerUseCallOptions, type ComputerUseImage, type ComputerUseResult, type ComputerUseTool, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type DownloadInfo, type DownloadOptions, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, type FileStream, Files, type GpuQueueEntry, type GpuQueueListOpts, type GpuQueueOpt, type GpuQueuePage, type GpuUsage, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxNotUtf8Error, InstaboxQuotaError, InstaboxTimeoutError, LIMIT_CODES, MAX_FILE_BYTES, MAX_STDIN_BYTES, MAX_UPLOAD_BYTES, type Machine, type MachineList, type MachineMetric, type MachineMetrics, type MachineQueue, type MachineSpec, type MachineState, type MachineUsage, type MachineVault, type MachineVaultItem, type MouseButton, type Operation, type PortAccess, Ports, type PublicPort, type PublishPortOpts, type ReadStreamOptions, type ResizeOpts, type ResumeOpts, 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 TemplateGpuType, type TemplateRef, type UploadInfo, type UploadOptions, type Usage, type UsageCost, type UsageLimits, type UsageMachineStorage, type UsageStorage, type VaultApplied, type VaultFile, type VaultKept, type WriteData, type WriteInfo, type WriteOptions, isLimitCode };
package/dist/index.js CHANGED
@@ -616,6 +616,92 @@ ${value}`;
616
616
  }
617
617
  };
618
618
 
619
+ // src/computer-use.ts
620
+ var ComputerUse = class {
621
+ /** @internal */
622
+ constructor(commands) {
623
+ this.commands = commands;
624
+ }
625
+ commands;
626
+ /** The server's tools, with their argument schemas. */
627
+ async tools(opts = {}) {
628
+ const r = await this.request("tools/list", void 0, opts);
629
+ return r.tools ?? [];
630
+ }
631
+ /**
632
+ * Calls one tool, for example `call('get_desktop_state')` for a screenshot of the whole screen or
633
+ * `call('list_windows')`. A tool that fails resolves with `isError: true`; it does not throw.
634
+ */
635
+ async call(name, args = {}, opts = {}) {
636
+ if (typeof name !== "string" || !name) {
637
+ throw new InstaboxError("call needs a tool name", { code: "bad_request" });
638
+ }
639
+ if (typeof args !== "object" || args === null || Array.isArray(args)) {
640
+ throw new InstaboxError("a tool's arguments must be an object", { code: "bad_request" });
641
+ }
642
+ const r = await this.request("tools/call", { name, arguments: args }, opts);
643
+ const content = r.content ?? [];
644
+ const out = {
645
+ text: content.filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n"),
646
+ images: content.filter((c) => c.type === "image").map((c) => ({ mimeType: c.mimeType ?? "", data: base64ToBytes(c.data ?? "") })),
647
+ isError: r.isError === true
648
+ };
649
+ if (r.structuredContent !== void 0) out.structuredContent = r.structuredContent;
650
+ return out;
651
+ }
652
+ /** One request to a server started for it: the handshake and the request go in as stdin. */
653
+ async request(method, params, opts) {
654
+ const msgs = [
655
+ {
656
+ jsonrpc: "2.0",
657
+ id: 1,
658
+ method: "initialize",
659
+ params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "instabox-sdk", version: "1" } }
660
+ },
661
+ { jsonrpc: "2.0", method: "notifications/initialized" },
662
+ { jsonrpc: "2.0", id: 2, method, ...params === void 0 ? {} : { params } }
663
+ ];
664
+ let stdout;
665
+ let stderr = "";
666
+ try {
667
+ const r = await this.commands.run("instabox-computer-use mcp", {
668
+ stdin: msgs.map((m) => JSON.stringify(m)).join("\n") + "\n",
669
+ onStdout: () => {
670
+ },
671
+ timeoutMs: opts.timeoutMs,
672
+ signal: opts.signal
673
+ });
674
+ stdout = r.stdout;
675
+ } catch (e) {
676
+ if (!(e instanceof CommandExitError)) throw e;
677
+ if (e.timedOut) {
678
+ throw new InstaboxTimeoutError(`the computer-use call ran past its timeout`, { code: "command_timeout" });
679
+ }
680
+ stdout = e.stdout;
681
+ stderr = e.stderr;
682
+ }
683
+ for (const line of stdout.split("\n")) {
684
+ let msg;
685
+ try {
686
+ msg = JSON.parse(line);
687
+ } catch {
688
+ continue;
689
+ }
690
+ if (msg?.id !== 2 || msg.method !== void 0) continue;
691
+ if (msg.error) {
692
+ throw new InstaboxError(`computer-use server: ${msg.error.message} (code ${msg.error.code})`, {
693
+ code: "computer_use_error"
694
+ });
695
+ }
696
+ return msg.result ?? {};
697
+ }
698
+ throw new InstaboxError(
699
+ `the sandbox's computer-use server ended without answering; is its template one with computer use?${stderr ? ` ${stderr.trim().slice(-500)}` : ""}`,
700
+ { code: "computer_use_unavailable" }
701
+ );
702
+ }
703
+ };
704
+
619
705
  // src/desktop.ts
620
706
  var DESKTOP_DISPLAY = ":1";
621
707
  var BUTTONS = { left: 1, middle: 2, right: 3 };
@@ -2570,6 +2656,7 @@ var Sandbox = class _Sandbox {
2570
2656
  this.files = new Files(this.commands, http, machine.id);
2571
2657
  this.commands.stageStdin = (bytes, signal) => this.files.stageStdin(bytes, signal);
2572
2658
  this.desktop = new Desktop(http, machine.id, this.commands, this.files);
2659
+ this.computerUse = new ComputerUse(this.commands);
2573
2660
  this.ports = new Ports(http, machine.id);
2574
2661
  }
2575
2662
  http;
@@ -2581,6 +2668,8 @@ var Sandbox = class _Sandbox {
2581
2668
  files;
2582
2669
  /** See and control the sandbox's graphical desktop (screenshots, mouse, keyboard, a link to watch it). */
2583
2670
  desktop;
2671
+ /** The sandbox's computer-use MCP tools: accessibility trees, screenshots, clicks and typing in apps. */
2672
+ computerUse;
2584
2673
  /** Publish a port at an HTTPS URL, list published ports, unpublish them. */
2585
2674
  ports;
2586
2675
  machine;
@@ -3023,6 +3112,7 @@ async function resolveSource(http, ref) {
3023
3112
  export {
3024
3113
  CommandExitError,
3025
3114
  Commands,
3115
+ ComputerUse,
3026
3116
  DEFAULT_API_URL,
3027
3117
  DEFAULT_TEMPLATE,
3028
3118
  DESKTOP_DISPLAY,