@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 +87 -114
- package/bin/cmdop-core-darwin-arm64 +0 -0
- package/bin/cmdop-core-darwin-x64 +0 -0
- package/bin/cmdop-core-linux-arm64 +0 -0
- package/bin/cmdop-core-linux-x64 +0 -0
- package/bin/cmdop-core-win32-x64.exe +0 -0
- package/dist/index.cjs +388 -959
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +573 -3859
- package/dist/index.d.ts +573 -3859
- package/dist/index.js +374 -861
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/dist/chunk-HVTWZ3OM.js +0 -63
- package/dist/chunk-HVTWZ3OM.js.map +0 -1
- package/dist/errors-4ITNIIVL.js +0 -3
- package/dist/errors-4ITNIIVL.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,160 +1,133 @@
|
|
|
1
|
-
# @cmdop/sdk (Node)
|
|
1
|
+
# @cmdop/sdk 2.0 (Node)
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-

|
|
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
|
|
9
|
+
npm install @cmdop/sdk
|
|
25
10
|
```
|
|
26
11
|
|
|
27
|
-
|
|
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
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
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
|
|
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
|
-
|
|
37
|
+
For an explicit remote relay, provide both its URL and bearer token. Constructor
|
|
38
|
+
options take precedence over environment variables.
|
|
46
39
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
here, snake_case there):
|
|
40
|
+
```ts
|
|
41
|
+
const client = new Client({ baseUrl: "https://relay.example.com", token: "..." });
|
|
42
|
+
```
|
|
51
43
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
64
|
-
following cursors) and `pages(...)` (an async generator over each page).
|
|
48
|
+
## Public API
|
|
65
49
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
##
|
|
57
|
+
## Ask streaming and PIN
|
|
72
58
|
|
|
73
|
-
|
|
74
|
-
`confirm()` / `collect()`:
|
|
59
|
+
Pass a connection PIN up front, before consuming the headless stream.
|
|
75
60
|
|
|
76
61
|
```ts
|
|
77
|
-
const stream =
|
|
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
|
-
|
|
81
|
-
|
|
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
|
-
|
|
97
|
-
|
|
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
|
|
79
|
+
const text = await client.machines.ask(
|
|
80
|
+
machineId,
|
|
81
|
+
"Reply with: pong",
|
|
82
|
+
{ pin: "1234" },
|
|
83
|
+
).collect();
|
|
101
84
|
```
|
|
102
85
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
109
|
-
pin_denied`. An `error` outcome throws `AgentStreamError`.
|
|
99
|
+
`limit` must be between 1 and 500.
|
|
110
100
|
|
|
111
|
-
##
|
|
101
|
+
## Configuration
|
|
112
102
|
|
|
113
|
-
|
|
|
114
|
-
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
|
|
|
118
|
-
|
|
|
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
|
-
|
|
123
|
-
|
|
110
|
+
Call `await client.close()` when finished. `await using` is also supported on
|
|
111
|
+
runtimes configured for explicit resource management.
|
|
124
112
|
|
|
125
|
-
##
|
|
113
|
+
## Typed errors
|
|
126
114
|
|
|
127
|
-
Every failure
|
|
128
|
-
`
|
|
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
|
|
139
|
-
} catch (
|
|
140
|
-
if (
|
|
141
|
-
|
|
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
|
-
|
|
149
|
-
|
|
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
|
package/bin/cmdop-core-linux-x64
CHANGED
|
Binary file
|
|
Binary file
|