@cmdop/sdk 1.1.0 → 2.0.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 CHANGED
@@ -1,160 +1,133 @@
1
- # @cmdop/sdk (Node)
1
+ # @cmdop/sdk 2.0 (Node)
2
2
 
3
- ![@cmdop/sdk — Node SDK for CMDOP](https://raw.githubusercontent.com/commandoperator/cmdop-sdk/main/assets/hero-cmdop-node.webp)
4
-
5
- Typed Node SDK for CMDOP — manage your machines, fleets, tunnels, and schedules,
6
- stream a machine's AI agent, and drive the skills marketplace, all from typed
7
- TypeScript.
8
-
9
- 📚 **Docs: [docs.cmdop.com](https://docs.cmdop.com)** · [SDK](https://cmdop.com/sdk) ·
10
- [Bots](https://cmdop.com/bots) · [Connect](https://cmdop.com/connect)
11
-
12
- ![How the CMDOP SDK connects your app to your machines](https://raw.githubusercontent.com/commandoperator/cmdop-sdk/main/assets/diagram-cmdop-sdk.webp)
13
-
14
- - **One install, zero dependencies** — `npm i @cmdop/sdk` is everything. No
15
- native build step, no `optionalDependencies`, nothing fetched on first run.
16
- - **Works anywhere, offline-ready** — a single self-contained package runs the
17
- same on macOS, Linux, and Windows, including air-gapped hosts.
18
- - **Typed end to end** — full TypeScript types for every resource and response,
19
- with one clean async streaming API for live agent output.
3
+ Typed Node SDK for the current Cmdop machine roster, agent stream, and durable
4
+ messages. Requires Node 18 or newer.
20
5
 
21
6
  ## Install
22
7
 
23
8
  ```bash
24
- npm i @cmdop/sdk # or: pnpm add @cmdop/sdk / yarn add @cmdop/sdk
9
+ npm install @cmdop/sdk
25
10
  ```
26
11
 
27
- ESM + CJS, Node ≥ 18.
12
+ The package includes `cmdop-core` for supported macOS, Linux, and Windows
13
+ hosts. It does not download a runtime on first use.
28
14
 
29
15
  ## Quick start
30
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
+
31
20
  ```ts
32
21
  import { Client } from "@cmdop/sdk";
33
22
 
34
- const c = new Client({ token: "..." }); // or Client.fromEnv()
35
-
36
- const page = await c.machines.list({ presence: "online" });
37
- for (const m of page.items) console.log(m.hostname, m.presence);
38
-
39
- const text = await c.machines.ask(machineId, "uptime").collect();
40
- console.log(text);
23
+ const client = new Client();
24
+ try {
25
+ const bootstrap = await client.system.bootstrap();
26
+ console.log(bootstrap.version, bootstrap.capabilities);
41
27
 
42
- await c.close(); // release resources
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
+ }
43
35
  ```
44
36
 
45
- `await using c = new Client(...)` works too (`Symbol.asyncDispose`).
37
+ For an explicit remote relay, provide both its URL and bearer token. Constructor
38
+ options take precedence over environment variables.
46
39
 
47
- ## Namespaces
48
-
49
- The same surface as the relay, mirrored exactly by the Python SDK (camelCase
50
- here, snake_case there):
40
+ ```ts
41
+ const client = new Client({ baseUrl: "https://relay.example.com", token: "..." });
42
+ ```
51
43
 
52
- | Namespace | Methods |
53
- |---|---|
54
- | `machines` | `list · get · update · disable · info · spend · ask · messages · clearMessages · activeSession` |
55
- | `fleets` | `list · get · create · update · disable` |
56
- | `fleets.members` | `list · add · setRole · remove` |
57
- | `fleets.machines` | `list · attach · detach` |
58
- | `tunnels` | `open · close · list · get · sessions` |
59
- | `schedules` | `list · get · create · update · delete · trigger · runs` |
60
- | `keys` | `list · issue · revoke` |
61
- | `skills` | `list · get · my · install · star · versions · reviews · create · update · delete · publish · publishStatus · categories · tags` |
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.
62
47
 
63
- List endpoints also expose `iter(...)` (an async generator over every item,
64
- following cursors) and `pages(...)` (an async generator over each page).
48
+ ## Public API
65
49
 
66
- > **Two planes, one client.** `machines / fleets / tunnels / schedules / keys`
67
- > use your relay token (`CMDOP_TOKEN`); the **`skills`** marketplace uses your
68
- > platform API key (`CMDOP_API_KEY`). Set whichever you need — the client routes
69
- > each call to the right plane for you.
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` |
70
56
 
71
- ## Streaming: `machines.ask()`
57
+ ## Ask streaming and PIN
72
58
 
73
- `ask()` returns an `AskStream` — an async iterable of typed frames with `pin()` /
74
- `confirm()` / `collect()`:
59
+ Pass a connection PIN up front, before consuming the headless stream.
75
60
 
76
61
  ```ts
77
- const stream = c.machines.ask(machineId, "df -h", { sessionId: "s1" });
62
+ const stream = client.machines.ask(
63
+ machineId,
64
+ "Summarize the current system load.",
65
+ { pin: "1234", session: "2" },
66
+ );
67
+
78
68
  for await (const frame of stream) {
79
- if (frame.type === "event") {
80
- process.stdout.write(String((frame.payload as { delta?: string })?.delta ?? ""));
81
- } else if (frame.type === "pin_required") { // machine asked for its connect PIN
82
- await stream.pin(frame.challengeId, "1234");
83
- } else if (frame.type === "confirm_required") { // a dangerous plan awaits approval
84
- await stream.confirm(frame.token, true);
85
- } else if (frame.type === "pin_denied") {
86
- console.log("PIN rejected:", frame.reason);
87
- } else if (frame.type === "done") {
88
- console.log("\n->", frame.text);
89
- }
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);
90
72
  }
91
-
92
- // one-shot: drain to the final text
93
- const text = await c.machines.ask(machineId, "uptime").collect();
94
73
  ```
95
74
 
96
- **Connection PIN.** If a machine requires a PIN, pass it **upfront** — the SDK is
97
- headless, so there's no prompt to answer:
75
+ For the common one-shot case, `collect()` drains the stream and returns final
76
+ text. An unsuccessful `done` throws `AgentStreamError`.
98
77
 
99
78
  ```ts
100
- const text = await c.machines.ask(machineId, "uptime", { pin: "1234" }).collect();
79
+ const text = await client.machines.ask(
80
+ machineId,
81
+ "Reply with: pong",
82
+ { pin: "1234" },
83
+ ).collect();
101
84
  ```
102
85
 
103
- A wrong PIN throws `PinDeniedError`; an unverified one throws `PinTimeoutError`
104
- (both extend `PermissionError`, non-retryable). The reactive `stream.pin(...)`
105
- callback above is for interactive use (a human at a prompt). The relay never
106
- stores the PIN — it forwards it once to the target, which verifies it locally.
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
+ ```
107
98
 
108
- Frame types: `event · done · error · confirm_required · pin_required ·
109
- pin_denied`. An `error` outcome throws `AgentStreamError`.
99
+ `limit` must be between 1 and 500.
110
100
 
111
- ## Environment variables
101
+ ## Configuration
112
102
 
113
- | Var | Meaning | Default |
114
- |---|---|---|
115
- | `CMDOP_TOKEN` | relay Bearer token (machines/fleets/…) | — (required for relay ops) |
116
- | `CMDOP_BASE_URL` | relay REST root | `https://cloud.cmdop.com` |
117
- | `CMDOP_API_KEY` | platform `UserAPIKey` (for `skills`) | — (required for skills) |
118
- | `CMDOP_API_BASE_URL` | platform REST root | `https://api.cmdop.com` |
119
- | `CMDOP_FLEET_ID` | default fleet for fleet-scoped ops | none |
120
- | `CMDOP_TIMEOUT_MS` | per-call timeout | `30000` |
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 |
121
109
 
122
- Precedence is always explicit option > env var > default. Pass a string to the
123
- constructor (`new Client("token")`) as a shorthand for `{ token }`.
110
+ Call `await client.close()` when finished. `await using` is also supported on
111
+ runtimes configured for explicit resource management.
124
112
 
125
- ## Error handling
113
+ ## Typed errors
126
114
 
127
- Every failure surfaces as a typed error carrying a stable `code` (all extend
128
- `CmdopError`):
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`.
129
119
 
130
120
  ```ts
131
- import {
132
- AuthError, PermissionError, NotFoundError, ConflictError,
133
- ValidationError, RateLimitError, ServerError, ConnectionError,
134
- TimeoutError, UnavailableError, AgentStreamError, CmdopError,
135
- } from "@cmdop/sdk";
121
+ import { CmdopError } from "@cmdop/sdk";
136
122
 
137
123
  try {
138
- await c.machines.get("missing-id");
139
- } catch (e) {
140
- if (e instanceof NotFoundError) { /* ... */ }
141
- else if (e instanceof CmdopError) {
142
- if (e.retryable) { /* true on TimeoutError — safe to retry */ }
143
- console.log(e.code, e.message);
124
+ await client.machines.messages("missing");
125
+ } catch (error) {
126
+ if (error instanceof CmdopError) {
127
+ console.log(error.code, error.status, error.retryable);
144
128
  }
145
129
  }
146
130
  ```
147
131
 
148
- `ConnectionError` covers a lost connection mid-call (pending promises reject);
149
- `TimeoutError` (a retryable subclass) is a deadline/handshake timeout;
150
- `UnavailableError` means the relay is up but the target agent/machine is offline.
151
- `AgentStreamError` is the streaming-`ask` error outcome.
152
-
153
- ## Links
154
-
155
- - **Docs** → [docs.cmdop.com](https://docs.cmdop.com)
156
- - **SDK** → [cmdop.com/sdk](https://cmdop.com/sdk) · **Bots** →
157
- [cmdop.com/bots](https://cmdop.com/bots) · **Connect** →
158
- [cmdop.com/connect](https://cmdop.com/connect)
159
- - [`@cmdop/sdk` on npm](https://www.npmjs.com/package/@cmdop/sdk) ·
160
- [source](https://github.com/commandoperator/cmdop-sdk)
132
+ Documentation: [docs.cmdop.com](https://docs.cmdop.com) · Source:
133
+ [commandoperator/cmdop-sdk](https://github.com/commandoperator/cmdop-sdk)
Binary file
Binary file
Binary file
Binary file
Binary file