@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/README.md +25 -0
- package/dist/index.cjs +90 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/instabox/SKILL.md +1 -1
package/README.md
CHANGED
|
@@ -358,6 +358,31 @@ await sandbox.desktop.revokeStreamUrls() // every link stops working; open viewe
|
|
|
358
358
|
|
|
359
359
|
`streamUrl` needs no instabox account to open: anyone with the link can connect until `expiresAt` (60 s to 24 h, default 1 h). Expiry stops new connections; revoke ends open sessions: a viewer already watching stays until they leave or you call `revokeStreamUrls()`, which ends every link of the sandbox and disconnects its viewers within a few seconds. Revoke when someone's access should end, for example when a tenant's session or subscription ends. Links are view-only by default, enforced by the server; `viewOnly: false` lets the viewer use the mouse and keyboard. The sandbox and its desktop must be running when the link is opened.
|
|
360
360
|
|
|
361
|
+
### Computer use: apps, windows and accessibility trees
|
|
362
|
+
|
|
363
|
+
`sandbox.computerUse` calls the tools of the sandbox's computer-use MCP server, on Linux, macOS and Windows sandboxes (`desktop` input above is Linux only). The tool names are the server's: `tools()` lists them; the examples are cua-driver's, the server of current templates. Its tools list windows and apps, read a window's accessibility tree, take screenshots, and click and type into a window by element or by pixel.
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
const tools = await sandbox.computerUse.tools() // [{ name, description, inputSchema }]
|
|
367
|
+
|
|
368
|
+
const shot = await sandbox.computerUse.call('get_desktop_state')
|
|
369
|
+
shot.text // what the tool wrote: the screen size and the windows, with pid and window_id
|
|
370
|
+
shot.images[0] // { mimeType: 'image/png', data: Uint8Array }
|
|
371
|
+
|
|
372
|
+
const r = await sandbox.computerUse.call('run_steps', {
|
|
373
|
+
pid: 1234,
|
|
374
|
+
window_id: 5678,
|
|
375
|
+
steps: [
|
|
376
|
+
{ tool: 'type_text', args: { text: 'hello' } },
|
|
377
|
+
{ tool: 'press_key', args: { key: 'return' } },
|
|
378
|
+
],
|
|
379
|
+
observe: { include_screenshot: true },
|
|
380
|
+
})
|
|
381
|
+
if (r.isError) console.error(r.text)
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
`call(name, args?, { timeoutMs })` resolves with `{ text, images, isError, structuredContent }`; a tool that fails resolves with `isError: true` and says why in `text`, a protocol error throws `InstaboxError` with code `computer_use_error`, a call past `timeoutMs` throws `InstaboxTimeoutError`, and a sandbox without the server throws `InstaboxError` with code `computer_use_unavailable`. Each call starts the server anew in the sandbox, so what one call read (element tokens, a window's screenshot for pixel clicks) does not carry to the next: run the actions in one call with the `run_steps` tool, whose steps can name their target by role and name, and its `observe` reads the window after them. Calls run as commands, so they need the `machines:exec` (or `machines:write`) scope. On Linux, while a person controls the desktop from the dashboard, only the tools that look at it work.
|
|
385
|
+
|
|
361
386
|
### One sandbox per user, shown over VNC
|
|
362
387
|
|
|
363
388
|
A product that gives each of its users a computer they watch, or drive, in its own page:
|
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
CommandExitError: () => CommandExitError,
|
|
34
34
|
Commands: () => Commands,
|
|
35
|
+
ComputerUse: () => ComputerUse,
|
|
35
36
|
DEFAULT_API_URL: () => DEFAULT_API_URL,
|
|
36
37
|
DEFAULT_TEMPLATE: () => DEFAULT_TEMPLATE,
|
|
37
38
|
DESKTOP_DISPLAY: () => DESKTOP_DISPLAY,
|
|
@@ -671,6 +672,92 @@ ${value}`;
|
|
|
671
672
|
}
|
|
672
673
|
};
|
|
673
674
|
|
|
675
|
+
// src/computer-use.ts
|
|
676
|
+
var ComputerUse = class {
|
|
677
|
+
/** @internal */
|
|
678
|
+
constructor(commands) {
|
|
679
|
+
this.commands = commands;
|
|
680
|
+
}
|
|
681
|
+
commands;
|
|
682
|
+
/** The server's tools, with their argument schemas. */
|
|
683
|
+
async tools(opts = {}) {
|
|
684
|
+
const r = await this.request("tools/list", void 0, opts);
|
|
685
|
+
return r.tools ?? [];
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Calls one tool, for example `call('get_desktop_state')` for a screenshot of the whole screen or
|
|
689
|
+
* `call('list_windows')`. A tool that fails resolves with `isError: true`; it does not throw.
|
|
690
|
+
*/
|
|
691
|
+
async call(name, args = {}, opts = {}) {
|
|
692
|
+
if (typeof name !== "string" || !name) {
|
|
693
|
+
throw new InstaboxError("call needs a tool name", { code: "bad_request" });
|
|
694
|
+
}
|
|
695
|
+
if (typeof args !== "object" || args === null || Array.isArray(args)) {
|
|
696
|
+
throw new InstaboxError("a tool's arguments must be an object", { code: "bad_request" });
|
|
697
|
+
}
|
|
698
|
+
const r = await this.request("tools/call", { name, arguments: args }, opts);
|
|
699
|
+
const content = r.content ?? [];
|
|
700
|
+
const out = {
|
|
701
|
+
text: content.filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n"),
|
|
702
|
+
images: content.filter((c) => c.type === "image").map((c) => ({ mimeType: c.mimeType ?? "", data: base64ToBytes(c.data ?? "") })),
|
|
703
|
+
isError: r.isError === true
|
|
704
|
+
};
|
|
705
|
+
if (r.structuredContent !== void 0) out.structuredContent = r.structuredContent;
|
|
706
|
+
return out;
|
|
707
|
+
}
|
|
708
|
+
/** One request to a server started for it: the handshake and the request go in as stdin. */
|
|
709
|
+
async request(method, params, opts) {
|
|
710
|
+
const msgs = [
|
|
711
|
+
{
|
|
712
|
+
jsonrpc: "2.0",
|
|
713
|
+
id: 1,
|
|
714
|
+
method: "initialize",
|
|
715
|
+
params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "instabox-sdk", version: "1" } }
|
|
716
|
+
},
|
|
717
|
+
{ jsonrpc: "2.0", method: "notifications/initialized" },
|
|
718
|
+
{ jsonrpc: "2.0", id: 2, method, ...params === void 0 ? {} : { params } }
|
|
719
|
+
];
|
|
720
|
+
let stdout;
|
|
721
|
+
let stderr = "";
|
|
722
|
+
try {
|
|
723
|
+
const r = await this.commands.run("instabox-computer-use mcp", {
|
|
724
|
+
stdin: msgs.map((m) => JSON.stringify(m)).join("\n") + "\n",
|
|
725
|
+
onStdout: () => {
|
|
726
|
+
},
|
|
727
|
+
timeoutMs: opts.timeoutMs,
|
|
728
|
+
signal: opts.signal
|
|
729
|
+
});
|
|
730
|
+
stdout = r.stdout;
|
|
731
|
+
} catch (e) {
|
|
732
|
+
if (!(e instanceof CommandExitError)) throw e;
|
|
733
|
+
if (e.timedOut) {
|
|
734
|
+
throw new InstaboxTimeoutError(`the computer-use call ran past its timeout`, { code: "command_timeout" });
|
|
735
|
+
}
|
|
736
|
+
stdout = e.stdout;
|
|
737
|
+
stderr = e.stderr;
|
|
738
|
+
}
|
|
739
|
+
for (const line of stdout.split("\n")) {
|
|
740
|
+
let msg;
|
|
741
|
+
try {
|
|
742
|
+
msg = JSON.parse(line);
|
|
743
|
+
} catch {
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
if (msg?.id !== 2 || msg.method !== void 0) continue;
|
|
747
|
+
if (msg.error) {
|
|
748
|
+
throw new InstaboxError(`computer-use server: ${msg.error.message} (code ${msg.error.code})`, {
|
|
749
|
+
code: "computer_use_error"
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
return msg.result ?? {};
|
|
753
|
+
}
|
|
754
|
+
throw new InstaboxError(
|
|
755
|
+
`the sandbox's computer-use server ended without answering; is its template one with computer use?${stderr ? ` ${stderr.trim().slice(-500)}` : ""}`,
|
|
756
|
+
{ code: "computer_use_unavailable" }
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
|
|
674
761
|
// src/desktop.ts
|
|
675
762
|
var DESKTOP_DISPLAY = ":1";
|
|
676
763
|
var BUTTONS = { left: 1, middle: 2, right: 3 };
|
|
@@ -2625,6 +2712,7 @@ var Sandbox = class _Sandbox {
|
|
|
2625
2712
|
this.files = new Files(this.commands, http, machine.id);
|
|
2626
2713
|
this.commands.stageStdin = (bytes, signal) => this.files.stageStdin(bytes, signal);
|
|
2627
2714
|
this.desktop = new Desktop(http, machine.id, this.commands, this.files);
|
|
2715
|
+
this.computerUse = new ComputerUse(this.commands);
|
|
2628
2716
|
this.ports = new Ports(http, machine.id);
|
|
2629
2717
|
}
|
|
2630
2718
|
http;
|
|
@@ -2636,6 +2724,8 @@ var Sandbox = class _Sandbox {
|
|
|
2636
2724
|
files;
|
|
2637
2725
|
/** See and control the sandbox's graphical desktop (screenshots, mouse, keyboard, a link to watch it). */
|
|
2638
2726
|
desktop;
|
|
2727
|
+
/** The sandbox's computer-use MCP tools: accessibility trees, screenshots, clicks and typing in apps. */
|
|
2728
|
+
computerUse;
|
|
2639
2729
|
/** Publish a port at an HTTPS URL, list published ports, unpublish them. */
|
|
2640
2730
|
ports;
|
|
2641
2731
|
machine;
|