@cmdop/sdk 1.0.2 → 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 +90 -105
- 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,148 +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
|
|
23
|
+
const client = new Client();
|
|
24
|
+
try {
|
|
25
|
+
const bootstrap = await client.system.bootstrap();
|
|
26
|
+
console.log(bootstrap.version, bootstrap.capabilities);
|
|
35
27
|
|
|
36
|
-
const
|
|
37
|
-
for (const
|
|
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
|
+
}
|
|
35
|
+
```
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
For an explicit remote relay, provide both its URL and bearer token. Constructor
|
|
38
|
+
options take precedence over environment variables.
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
```ts
|
|
41
|
+
const client = new Client({ baseUrl: "https://relay.example.com", token: "..." });
|
|
43
42
|
```
|
|
44
43
|
|
|
45
|
-
|
|
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
|
|
49
|
+
|
|
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` |
|
|
56
|
+
|
|
57
|
+
## Ask streaming and PIN
|
|
46
58
|
|
|
47
|
-
|
|
59
|
+
Pass a connection PIN up front, before consuming the headless stream.
|
|
48
60
|
|
|
49
|
-
|
|
50
|
-
|
|
61
|
+
```ts
|
|
62
|
+
const stream = client.machines.ask(
|
|
63
|
+
machineId,
|
|
64
|
+
"Summarize the current system load.",
|
|
65
|
+
{ pin: "1234", session: "2" },
|
|
66
|
+
);
|
|
51
67
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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` |
|
|
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
|
+
```
|
|
62
74
|
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
For the common one-shot case, `collect()` drains the stream and returns final
|
|
76
|
+
text. An unsuccessful `done` throws `AgentStreamError`.
|
|
65
77
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
```ts
|
|
79
|
+
const text = await client.machines.ask(
|
|
80
|
+
machineId,
|
|
81
|
+
"Reply with: pong",
|
|
82
|
+
{ pin: "1234" },
|
|
83
|
+
).collect();
|
|
84
|
+
```
|
|
70
85
|
|
|
71
|
-
|
|
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.
|
|
72
89
|
|
|
73
|
-
|
|
74
|
-
`confirm()` / `collect()`:
|
|
90
|
+
## Durable messages
|
|
75
91
|
|
|
76
92
|
```ts
|
|
77
|
-
const
|
|
78
|
-
for
|
|
79
|
-
|
|
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
|
-
}
|
|
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);
|
|
90
96
|
}
|
|
91
|
-
|
|
92
|
-
// one-shot: drain to the final text
|
|
93
|
-
const text = await c.machines.ask(machineId, "uptime").collect();
|
|
94
97
|
```
|
|
95
98
|
|
|
96
|
-
|
|
97
|
-
pin_denied`. An `error` outcome throws `AgentStreamError`.
|
|
99
|
+
`limit` must be between 1 and 500.
|
|
98
100
|
|
|
99
|
-
##
|
|
101
|
+
## Configuration
|
|
100
102
|
|
|
101
|
-
|
|
|
102
|
-
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
|
|
|
106
|
-
|
|
|
107
|
-
| `CMDOP_FLEET_ID` | default fleet for fleet-scoped ops | none |
|
|
108
|
-
| `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 |
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
Call `await client.close()` when finished. `await using` is also supported on
|
|
111
|
+
runtimes configured for explicit resource management.
|
|
112
112
|
|
|
113
|
-
##
|
|
113
|
+
## Typed errors
|
|
114
114
|
|
|
115
|
-
Every failure
|
|
116
|
-
`
|
|
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`.
|
|
117
119
|
|
|
118
120
|
```ts
|
|
119
|
-
import {
|
|
120
|
-
AuthError, PermissionError, NotFoundError, ConflictError,
|
|
121
|
-
ValidationError, RateLimitError, ServerError, ConnectionError,
|
|
122
|
-
TimeoutError, UnavailableError, AgentStreamError, CmdopError,
|
|
123
|
-
} from "@cmdop/sdk";
|
|
121
|
+
import { CmdopError } from "@cmdop/sdk";
|
|
124
122
|
|
|
125
123
|
try {
|
|
126
|
-
await
|
|
127
|
-
} catch (
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
if (e.retryable) { /* true on TimeoutError — safe to retry */ }
|
|
131
|
-
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);
|
|
132
128
|
}
|
|
133
129
|
}
|
|
134
130
|
```
|
|
135
131
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
`UnavailableError` means the relay is up but the target agent/machine is offline.
|
|
139
|
-
`AgentStreamError` is the streaming-`ask` error outcome.
|
|
140
|
-
|
|
141
|
-
## Links
|
|
142
|
-
|
|
143
|
-
- **Docs** → [docs.cmdop.com](https://docs.cmdop.com)
|
|
144
|
-
- **SDK** → [cmdop.com/sdk](https://cmdop.com/sdk) · **Bots** →
|
|
145
|
-
[cmdop.com/bots](https://cmdop.com/bots) · **Connect** →
|
|
146
|
-
[cmdop.com/connect](https://cmdop.com/connect)
|
|
147
|
-
- [`@cmdop/sdk` on npm](https://www.npmjs.com/package/@cmdop/sdk) ·
|
|
148
|
-
[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
|