@cmdop/sdk 2.0.0 → 3.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 CMDOP
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,133 +1,31 @@
1
- # @cmdop/sdk 2.0 (Node)
1
+ # @cmdop/sdk
2
2
 
3
- Typed Node SDK for the current Cmdop machine roster, agent stream, and durable
4
- messages. Requires Node 18 or newer.
5
-
6
- ## Install
3
+ Your machines' tools from a program: the same tools agents use through MCP, typed.
7
4
 
8
5
  ```bash
9
6
  npm install @cmdop/sdk
10
7
  ```
11
8
 
12
- The package includes `cmdop-core` for supported macOS, Linux, and Windows
13
- hosts. It does not download a runtime on first use.
14
-
15
- ## Quick start
16
-
17
- `new Client()` is the canonical local configuration. The core discovers the
18
- active Cmdop server and credentials from the local Cmdop configuration.
19
-
20
9
  ```ts
21
- import { Client } from "@cmdop/sdk";
10
+ import { connect } from "@cmdop/sdk";
22
11
 
23
- const client = new Client();
24
- try {
25
- const bootstrap = await client.system.bootstrap();
26
- console.log(bootstrap.version, bootstrap.capabilities);
12
+ const cmdop = connect(); // CMDOP_TOKEN, CMDOP_URL
13
+ const box = cmdop.machine("box");
14
+ console.log((await box.run("uptime")).stdout);
27
15
 
28
- const snapshot = await client.machines.list();
29
- for (const machine of snapshot.machines) {
30
- console.log(machine.machineId, machine.displayName, machine.presence);
31
- }
32
- } finally {
33
- await client.close();
34
- }
16
+ const run = box.stream("make test");
17
+ for await (const piece of run) process.stdout.write(piece.data);
18
+ console.log((await run.result).exit_code);
35
19
  ```
36
20
 
37
- For an explicit remote relay, provide both its URL and bearer token. Constructor
38
- options take precedence over environment variables.
39
-
40
- ```ts
41
- const client = new Client({ baseUrl: "https://relay.example.com", token: "..." });
42
- ```
43
-
44
- The equivalent environment variables are `CMDOP_BASE_URL` and `CMDOP_TOKEN`.
45
- A remote URL without a token fails closed. An explicit loopback URL can mint a
46
- local loopback token.
47
-
48
- ## Public API
21
+ Every tool is a typed method on a machine (`box.fs_read({ path })`, `box.task_start({ command })`, …), and
22
+ `cmdop.call(tool, args, { machine })` reaches any of them by name. A refused call throws `CmdopError` with its
23
+ `code`; `deadline` and `signal` bound and cancel any call.
49
24
 
50
- | Namespace | Method | Result |
51
- |---|---|---|
52
- | `system` | `await client.system.bootstrap()` | version, bundle, contract range, capabilities, update state |
53
- | `machines` | `await client.machines.list()` | authoritative `MachineRosterSnapshot` |
54
- | `machines` | `client.machines.ask(machineId, prompt, options)` | `AskStream` |
55
- | `machines` | `await client.machines.messages(machineId, options)` | durable `MachineMessageList` |
25
+ ## The same tools over MCP
56
26
 
57
- ## Ask streaming and PIN
58
-
59
- Pass a connection PIN up front, before consuming the headless stream.
60
-
61
- ```ts
62
- const stream = client.machines.ask(
63
- machineId,
64
- "Summarize the current system load.",
65
- { pin: "1234", session: "2" },
66
- );
67
-
68
- for await (const frame of stream) {
69
- if (frame.type === "event") console.log(frame.payload);
70
- else if (frame.type === "error") console.log(frame.code, frame.message);
71
- else console.log(frame.success, frame.text);
72
- }
73
- ```
74
-
75
- For the common one-shot case, `collect()` drains the stream and returns final
76
- text. An unsuccessful `done` throws `AgentStreamError`.
77
-
78
- ```ts
79
- const text = await client.machines.ask(
80
- machineId,
81
- "Reply with: pong",
82
- { pin: "1234" },
83
- ).collect();
84
- ```
85
-
86
- Ask options also include `attachmentIds`, `engine`, `workingDir`,
87
- `projectRootId`, and `model`. A stream is single-consumer and yields only typed
88
- `event`, `error`, and `done` frames.
89
-
90
- ## Durable messages
91
-
92
- ```ts
93
- const history = await client.machines.messages(machineId, { session: "2", limit: 100 });
94
- for (const message of history.messages) {
95
- console.log(message.seq, message.role, message.content);
96
- }
97
- ```
98
-
99
- `limit` must be between 1 and 500.
100
-
101
- ## Configuration
102
-
103
- | Setting | Constructor | Environment | Default |
104
- |---|---|---|---|
105
- | Relay URL | `baseUrl` | `CMDOP_BASE_URL` | local Cmdop config |
106
- | Bearer token | `token` | `CMDOP_TOKEN` | local Cmdop credentials |
107
- | Timeout | `timeoutMs` | `CMDOP_TIMEOUT_MS` | `30000` |
108
- | Development binary override | `binaryPath` | `CMDOP_CORE_BINARY` | packaged host binary |
109
-
110
- Call `await client.close()` when finished. `await using` is also supported on
111
- runtimes configured for explicit resource management.
112
-
113
- ## Typed errors
114
-
115
- Every protocol failure is a `CmdopError` with stable `code`, optional HTTP
116
- `status`, `retryable`, and redacted `details` fields. Common subclasses include
117
- `AuthError`, `PermissionError`, `ValidationError`, `NotFoundError`,
118
- `UnavailableError`, `TimeoutError`, `ConnectionError`, and `AgentStreamError`.
119
-
120
- ```ts
121
- import { CmdopError } from "@cmdop/sdk";
122
-
123
- try {
124
- await client.machines.messages("missing");
125
- } catch (error) {
126
- if (error instanceof CmdopError) {
127
- console.log(error.code, error.status, error.retryable);
128
- }
129
- }
130
- ```
27
+ CMDOP is an MCP server too: an agent reaches these tools at `$CMDOP_URL/mcp` (streamable HTTP) with an agent token
28
+ as `Authorization: Bearer`, the same kind of token this package takes, under the same grant and record. The
29
+ command or settings for each client: https://docs.cmdop.ai/guides/connect
131
30
 
132
- Documentation: [docs.cmdop.com](https://docs.cmdop.com) · Source:
133
- [commandoperator/cmdop-sdk](https://github.com/commandoperator/cmdop-sdk)
31
+ Website: https://cmdop.ai · Docs: https://docs.cmdop.ai/reference/sdk/typescript · License: MIT
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The client-door seam (developer SDK plan, section 4): the one interface between the client and a channel. The client
3
+ * knows the call contract (`generated/call.gen.ts`) and nothing about the channel; an adapter moves the contract's
4
+ * shapes and nothing else. A carrier defines no semantics: codes, deadlines, cancel and the order of pieces come from
5
+ * the contract, and the shared vectors (`exports/sdk/vectors/carrier`) hold every adapter to it.
6
+ */
7
+ import type { Answer, CallRequest, StreamLine } from "../generated/call.gen.ts";
8
+ export interface CallOptions {
9
+ /** Aborting it cancels the call: the adapter tells the door, the door tells the machine. */
10
+ signal?: AbortSignal;
11
+ }
12
+ /** One machine as the server lists it. Only the fields the client reads. */
13
+ export interface MachineRow {
14
+ id: string;
15
+ name: string;
16
+ online: boolean;
17
+ os?: string;
18
+ last_seen?: number | null;
19
+ /** The machine's box key and its signature by the machine's id, for end-to-end calls. */
20
+ box_key?: string | null;
21
+ box_sig?: string | null;
22
+ tools?: string[];
23
+ }
24
+ export interface Carrier {
25
+ /** `"http"`, `"memory"`; later `"ws"`, `"grpc"`. */
26
+ readonly name: string;
27
+ /** One call, answered once. A refusal is an `Answer` with `error`, never a throw. */
28
+ call(req: CallRequest, o: CallOptions): Promise<Answer>;
29
+ /** One call, its pieces as they come, its answer as the last line. */
30
+ stream(req: CallRequest, o: CallOptions): AsyncIterable<StreamLine>;
31
+ /** The machines of the contour, a server-answered operation: `ok` is a `MachineRow[]`. */
32
+ machines(o: CallOptions): Promise<Answer>;
33
+ close(): Promise<void>;
34
+ }
35
+ /** A carrier could not reach the door or read what came back: not a contract answer. */
36
+ export declare class CarrierError extends Error {
37
+ /** Written without parameter properties, so Node can run the sources with its own type stripping. */
38
+ readonly carrier: string;
39
+ constructor(carrier: string, message: string);
40
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The client-door seam (developer SDK plan, section 4): the one interface between the client and a channel. The client
3
+ * knows the call contract (`generated/call.gen.ts`) and nothing about the channel; an adapter moves the contract's
4
+ * shapes and nothing else. A carrier defines no semantics: codes, deadlines, cancel and the order of pieces come from
5
+ * the contract, and the shared vectors (`exports/sdk/vectors/carrier`) hold every adapter to it.
6
+ */
7
+ /** A carrier could not reach the door or read what came back: not a contract answer. */
8
+ export class CarrierError extends Error {
9
+ /** Written without parameter properties, so Node can run the sources with its own type stripping. */
10
+ carrier;
11
+ constructor(carrier, message) {
12
+ super(`${carrier}: ${message}`);
13
+ this.name = "CarrierError";
14
+ this.carrier = carrier;
15
+ }
16
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * HTTP + NDJSON, the first carrier: `POST /api/v1/call`, `POST /api/v1/call/stream` (one JSON value per line, the
3
+ * answer last) and `GET /api/v1/machines` on the contour's address. Every answer of these routes is shaped like the
4
+ * contract's `Answer`, refusals included, so the HTTP status is never needed to read one. Cancel is closing the
5
+ * request: the server sends the machine the contract's cancel. `gen.ts` checks these paths against `openapi.json`.
6
+ */
7
+ import { type Carrier } from "./carrier.ts";
8
+ export interface HttpOptions {
9
+ /** The contour's base URL, `https://<address>.cmdop.dev`, or a local server's. */
10
+ url: string;
11
+ token: string;
12
+ /** For tests and other runtimes; the global `fetch` by default. */
13
+ fetch?: typeof fetch;
14
+ }
15
+ export declare function httpCarrier(opts: HttpOptions): Carrier;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * HTTP + NDJSON, the first carrier: `POST /api/v1/call`, `POST /api/v1/call/stream` (one JSON value per line, the
3
+ * answer last) and `GET /api/v1/machines` on the contour's address. Every answer of these routes is shaped like the
4
+ * contract's `Answer`, refusals included, so the HTTP status is never needed to read one. Cancel is closing the
5
+ * request: the server sends the machine the contract's cancel. `gen.ts` checks these paths against `openapi.json`.
6
+ */
7
+ import { CarrierError } from "./carrier.js";
8
+ import { readNdjson } from "./ndjson.js";
9
+ function isAnswer(v) {
10
+ return typeof v === "object" && v !== null && !Array.isArray(v) && ("ok" in v || "error" in v || "sealed" in v);
11
+ }
12
+ function isRow(v) {
13
+ const r = v;
14
+ return typeof r === "object" && r !== null && typeof r.id === "string" && typeof r.name === "string" && typeof r.online === "boolean";
15
+ }
16
+ export function httpCarrier(opts) {
17
+ const base = opts.url.replace(/\/+$/, "");
18
+ const doFetch = opts.fetch ?? fetch;
19
+ const headers = {
20
+ authorization: `Bearer ${opts.token}`,
21
+ "content-type": "application/json",
22
+ // The server takes writes under /api only with this header (a browser form cannot send it).
23
+ "x-cmdop": "1",
24
+ };
25
+ const fail = (m) => new CarrierError("http", m);
26
+ async function request(method, path, body, o) {
27
+ try {
28
+ return await doFetch(`${base}${path}`, {
29
+ method,
30
+ headers,
31
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
32
+ ...(o.signal ? { signal: o.signal } : {}),
33
+ });
34
+ }
35
+ catch (e) {
36
+ if (o.signal?.aborted)
37
+ throw o.signal.reason ?? e;
38
+ throw fail(`could not reach ${base}: ${String(e)}`);
39
+ }
40
+ }
41
+ async function answerOf(res) {
42
+ let body;
43
+ try {
44
+ body = await res.json();
45
+ }
46
+ catch {
47
+ throw fail(`server answered ${res.status} without JSON`);
48
+ }
49
+ if (!isAnswer(body))
50
+ throw fail(`server answered ${res.status} without a call answer`);
51
+ return body;
52
+ }
53
+ return {
54
+ name: "http",
55
+ async call(req, o) {
56
+ return answerOf(await request("POST", "/api/v1/call", req, o));
57
+ },
58
+ async *stream(req, o) {
59
+ const res = await request("POST", "/api/v1/call/stream", req, o);
60
+ // A refusal before the call was sent comes as one JSON answer, not a stream.
61
+ if (!res.ok || !res.body) {
62
+ yield await answerOf(res);
63
+ return;
64
+ }
65
+ const lines = [];
66
+ let wake;
67
+ let done = false;
68
+ let failed;
69
+ void readNdjson(res.body, (l) => {
70
+ lines.push(l);
71
+ wake?.();
72
+ })
73
+ .catch((e) => {
74
+ failed = e;
75
+ })
76
+ .finally(() => {
77
+ done = true;
78
+ wake?.();
79
+ });
80
+ for (;;) {
81
+ const next = lines.shift();
82
+ if (next !== undefined) {
83
+ yield next;
84
+ continue;
85
+ }
86
+ if (done)
87
+ break;
88
+ await new Promise((r) => (wake = r));
89
+ wake = undefined;
90
+ }
91
+ if (failed !== undefined) {
92
+ if (o.signal?.aborted)
93
+ throw o.signal.reason ?? failed;
94
+ throw fail(`the stream broke: ${String(failed)}`);
95
+ }
96
+ },
97
+ async machines(o) {
98
+ const res = await request("GET", "/api/v1/machines", undefined, o);
99
+ let body;
100
+ try {
101
+ body = await res.json();
102
+ }
103
+ catch {
104
+ throw fail(`server answered ${res.status} without JSON for the machine list`);
105
+ }
106
+ if (isAnswer(body))
107
+ return body;
108
+ if (!res.ok || !Array.isArray(body) || !body.every(isRow))
109
+ throw fail(`server answered ${res.status} without a machine list`);
110
+ return { ok: body };
111
+ },
112
+ async close() { },
113
+ };
114
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The in-memory carrier: the contract with no channel at all, for tests and the conformance suite. `serve` plays the
3
+ * door: it gets each request and the caller's signal, and yields what the door would (pieces, then the answer).
4
+ */
5
+ import type { CallRequest, StreamLine } from "../generated/call.gen.ts";
6
+ import { type Carrier, type MachineRow } from "./carrier.ts";
7
+ export interface MemoryDoor {
8
+ serve(req: CallRequest, signal: AbortSignal | undefined): AsyncIterable<StreamLine>;
9
+ machines?: MachineRow[];
10
+ }
11
+ export declare function memoryCarrier(door: MemoryDoor): Carrier;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The in-memory carrier: the contract with no channel at all, for tests and the conformance suite. `serve` plays the
3
+ * door: it gets each request and the caller's signal, and yields what the door would (pieces, then the answer).
4
+ */
5
+ import { CarrierError } from "./carrier.js";
6
+ const isAnswer = (l) => "ok" in l || "error" in l || "sealed" in l;
7
+ export function memoryCarrier(door) {
8
+ return {
9
+ name: "memory",
10
+ async call(req, o) {
11
+ let last;
12
+ for await (const l of this.stream(req, o))
13
+ if (isAnswer(l))
14
+ last = l;
15
+ if (!last)
16
+ throw new CarrierError("memory", "the door gave no answer");
17
+ return last;
18
+ },
19
+ async *stream(req, o) {
20
+ try {
21
+ yield* door.serve(req, o.signal);
22
+ }
23
+ catch (e) {
24
+ // The caller's own abort stays theirs; anything else is the channel breaking.
25
+ if (o.signal?.aborted)
26
+ throw e;
27
+ throw new CarrierError("memory", `the door broke: ${String(e)}`);
28
+ }
29
+ },
30
+ async machines() {
31
+ return { ok: door.machines ?? [] };
32
+ },
33
+ async close() { },
34
+ };
35
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The small streaming boundary used by `/api/v1/call/stream`.
3
+ *
4
+ * The endpoint deliberately stays outside ordinary JSON code generation: its
5
+ * response is a sequence of JSON values, not one JSON document. Keeping the
6
+ * framing here gives the SDK one place to handle split UTF-8 chunks, blank
7
+ * lines and a final line without a trailing newline.
8
+ */
9
+ export type NdjsonLine<TChunk, TAnswer> = {
10
+ chunk: TChunk;
11
+ seq: number;
12
+ } | {
13
+ sealed_chunk: string;
14
+ seq: number;
15
+ } | TAnswer;
16
+ export declare function readNdjson<T>(body: ReadableStream<Uint8Array>, onLine: (line: T) => void | Promise<void>): Promise<void>;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The small streaming boundary used by `/api/v1/call/stream`.
3
+ *
4
+ * The endpoint deliberately stays outside ordinary JSON code generation: its
5
+ * response is a sequence of JSON values, not one JSON document. Keeping the
6
+ * framing here gives the SDK one place to handle split UTF-8 chunks, blank
7
+ * lines and a final line without a trailing newline.
8
+ */
9
+ export async function readNdjson(body, onLine) {
10
+ const reader = body.getReader();
11
+ const decoder = new TextDecoder();
12
+ let rest = "";
13
+ const emit = async (line) => {
14
+ const text = line.trim();
15
+ if (text)
16
+ await onLine(JSON.parse(text));
17
+ };
18
+ for (;;) {
19
+ const { done, value } = await reader.read();
20
+ if (done)
21
+ break;
22
+ rest += decoder.decode(value, { stream: true });
23
+ let newline;
24
+ while ((newline = rest.indexOf("\n")) >= 0) {
25
+ await emit(rest.slice(0, newline));
26
+ rest = rest.slice(newline + 1);
27
+ }
28
+ }
29
+ rest += decoder.decode();
30
+ await emit(rest);
31
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The cmdop client (developer SDK plan, section 4): your machines' tools from a program.
3
+ *
4
+ * ```ts
5
+ * const cmdop = connect(); // CMDOP_TOKEN and CMDOP_URL
6
+ * const box = cmdop.machine("box");
7
+ * const { exit_code, stdout } = await box.run("uptime");
8
+ * const run = box.stream("make test");
9
+ * for await (const piece of run) process.stdout.write(piece.data);
10
+ * const done = await run.result;
11
+ * ```
12
+ *
13
+ * Every tool, its arguments and result, the error codes and the call shapes are generated from the Rust workspace
14
+ * (`generated/`). This file speaks only the call contract; which channel carries it is the carrier's business
15
+ * (`carriers/`), and nothing here knows it.
16
+ *
17
+ * End-to-end calls come through a `Sealer` (`connect({ e2e })`): this file holds no key and reads no sealed text.
18
+ */
19
+ import type { Answer, CallRequest, ErrorCode, OutputChunk } from "./generated/call.gen.ts";
20
+ import { type ExecRunArgs, type ExecRunOut, type ScreenCaptureArgs, type ToolMap, type ToolName } from "./generated/tools.gen.ts";
21
+ import { type Carrier, type MachineRow } from "./carriers/carrier.ts";
22
+ import { type Screenshot } from "./screen.ts";
23
+ /**
24
+ * End-to-end calls: `connect({ e2e })` takes a sealer. It turns each call into the request to send and opens what
25
+ * comes back for it; the client sends what it is given and never reads the sealed text itself.
26
+ */
27
+ export interface Sealer {
28
+ /** The request to send for one call, and how to open what comes back for it. `machines` lists the contour's machines. */
29
+ seal(call: CallRequest, machines: () => Promise<MachineRow[]>): Promise<{
30
+ req: CallRequest;
31
+ open: Opener;
32
+ }>;
33
+ /** This client's public key, for `cmdop pair <key>` on each machine. */
34
+ publicKey(): Promise<string>;
35
+ }
36
+ /** Opens what comes back for one sealed call. Anything not sealed for it throws `CmdopError` (`not_sealed`). */
37
+ export interface Opener {
38
+ answer(sealed: string): Promise<Answer>;
39
+ piece(seq: number, sealed: string): Promise<OutputChunk>;
40
+ }
41
+ export interface ConnectOptions {
42
+ /** An agent token (held to its grant) or an owner token. Default: `CMDOP_TOKEN`. Keep it out of source and logs. */
43
+ token?: string;
44
+ /** The contour's address in full, `https://<address>.cmdop.dev` or a local server. Default: `CMDOP_URL`. */
45
+ url?: string;
46
+ /** The contour's address alone, for example `m7xg5cgy`, instead of `url`. */
47
+ contour?: string;
48
+ /** `"auto"` (default, or `CMDOP_CARRIER`), `"http"`, or a carrier of your own (tests: `memoryCarrier`). */
49
+ carrier?: "auto" | "http" | Carrier;
50
+ /** Seal every call end to end with this sealer. */
51
+ e2e?: Sealer;
52
+ /** For the HTTP carrier in tests and other runtimes; the global `fetch` by default. */
53
+ fetch?: typeof fetch;
54
+ }
55
+ export interface CallOpts {
56
+ /** Machine id or unique name; left out when exactly one machine is online. */
57
+ machine?: string;
58
+ /** How long to wait, in milliseconds. The call keeps the shorter of this and the tool's own time. */
59
+ deadline?: number;
60
+ /** Aborting it cancels the call; the answer is then `cancelled`. */
61
+ signal?: AbortSignal;
62
+ }
63
+ /** Why a call returned no result. Decide by `code`, never by `message`. */
64
+ export declare class CmdopError extends Error {
65
+ readonly code: ErrorCode | "not_sealable" | "not_sealed" | "key_changed";
66
+ /**
67
+ * Machine-readable facts that come with some codes. `permission_missing` carries
68
+ * `{ permission, state, requires_human, machine, human_action, retry }`: a person must act on that machine, do not
69
+ * retry until they have.
70
+ */
71
+ readonly details?: Record<string, unknown>;
72
+ constructor(code: CmdopError["code"], message: string, details?: Record<string, unknown>);
73
+ }
74
+ /** One piece of a running command's output, with its place in the call. */
75
+ export type Piece = OutputChunk & {
76
+ seq: number;
77
+ };
78
+ /** A call running with its output followed: iterate for the pieces, then `await run.result`. */
79
+ export interface Run<T = ExecRunOut> extends AsyncIterable<Piece> {
80
+ /** The call's result, the same as the one-shot call returns. Awaiting it without iterating skips the pieces. */
81
+ readonly result: Promise<T>;
82
+ }
83
+ type ToolMethods = {
84
+ [N in ToolName]: (args: ToolMap[N]["args"], opts?: Omit<CallOpts, "machine">) => Promise<ToolMap[N]["out"]>;
85
+ };
86
+ /** One machine: every tool as a method (`box.fs_read({ path })`) and three short forms. */
87
+ export type Machine = ToolMethods & {
88
+ /** `exec_run` with a shell command line. */
89
+ run(command: string, args?: Omit<ExecRunArgs, "command" | "argv">, opts?: Omit<CallOpts, "machine">): Promise<ExecRunOut>;
90
+ /** `exec_run` with its output as it comes. Breaking out of the loop or aborting `signal` stops the command. */
91
+ stream(command: string, args?: Omit<ExecRunArgs, "command" | "argv">, opts?: Omit<CallOpts, "machine">): Run;
92
+ /** `screen_capture` with the picture decoded. Needs the `screen` grant and `screen` in the machine's ceiling. */
93
+ screenshot(args?: ScreenCaptureArgs, opts?: Omit<CallOpts, "machine">): Promise<Screenshot>;
94
+ };
95
+ export interface Client {
96
+ /** Which carrier is in use (`"http"`, …): what `auto` picked. */
97
+ readonly carrier: string;
98
+ /** The machines of the contour: name, id, online, os, tools. */
99
+ machines(opts?: Pick<CallOpts, "signal">): Promise<MachineRow[]>;
100
+ /** One machine; no name: the one online machine (the server decides). */
101
+ machine(name?: string): Machine;
102
+ /** Runs any tool by name. */
103
+ call<N extends ToolName>(tool: N, args: ToolMap[N]["args"], opts?: CallOpts): Promise<ToolMap[N]["out"]>;
104
+ /** Runs any tool by name as a streamed call: its pieces as they come (only `exec_run` sends any), then its result. */
105
+ stream<N extends ToolName>(tool: N, args: ToolMap[N]["args"], opts?: CallOpts): Run<ToolMap[N]["out"]>;
106
+ /** With `e2e`: this client's public key, for `cmdop pair <key>` on each machine. */
107
+ publicKey(): Promise<string>;
108
+ close(): Promise<void>;
109
+ }
110
+ /** `url` as given, else `https://<contour>.cmdop.dev`; `CMDOP_URL` when neither is given. */
111
+ export declare function urlOf(opts: Pick<ConnectOptions, "url" | "contour">): string;
112
+ export declare function connect(opts?: ConnectOptions): Client;
113
+ export {};