@mirasoth/soothe-client 0.2.1 → 0.4.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/README.md CHANGED
@@ -1,82 +1,116 @@
1
1
  # @mirasoth/soothe-client
2
2
 
3
- TypeScript WebSocket client for the [Soothe](https://github.com/mirasoth/soothe) daemon.
4
-
5
- Provides a typed message protocol, session bootstrap, event helpers, and convenience RPCs for
6
- interacting with a running `soothe-daemon` from Node.js.
7
-
8
- ## Install
3
+ Talk to a running **soothe-daemon** over WebSocket send prompts, stream agent
4
+ turns, run jobs.
9
5
 
10
6
  ```bash
11
7
  npm install @mirasoth/soothe-client
12
- # or
13
- pnpm add @mirasoth/soothe-client
14
- # or
15
- yarn add @mirasoth/soothe-client
8
+ # optional: real image downscale for CompactAttachmentsBeforeSend
9
+ npm install sharp
16
10
  ```
17
11
 
18
- Requires Node.js `>=19`.
12
+ Requires Node.js `>=19` and a local daemon (default `ws://127.0.0.1:8765`).
19
13
 
20
14
  ## Quick start
21
15
 
22
16
  ```ts
23
- import { Client, bootstrapLoopSession, defaultConfig } from '@mirasoth/soothe-client';
17
+ import { DaemonSession } from '@mirasoth/soothe-client';
18
+
19
+ const session = new DaemonSession('ws://127.0.0.1:8765');
20
+ await session.connect();
21
+ await session.sendTurn('Summarize this in one sentence: agents need tools.');
22
+
23
+ for await (const [_namespace, mode, data] of session.iterTurnChunks()) {
24
+ console.log(mode, data);
25
+ }
24
26
 
25
- const config = defaultConfig();
26
- const client = new Client(config.daemonURL, config);
27
+ await session.close();
28
+ ```
29
+
30
+ More patterns: [`examples/`](examples/) (hello → streaming → multi-turn → pool → jobs).
27
31
 
28
- await client.connect();
29
- const loopId = await bootstrapLoopSession(client, null, config);
32
+ ## What you get
30
33
 
31
- client.on('message', (msg) => {
32
- console.log('event:', msg);
33
- });
34
+ | Need | Use |
35
+ |------|-----|
36
+ | One conversation, stream replies | `DaemonSession` |
37
+ | Jobs / cron one-shots | `CommandClient` |
38
+ | Raw WebSocket / custom RPCs | `Client` |
39
+ | Many users / HTTP backend | `ConnectionPool` + `TurnRunner` |
34
40
 
35
- await client.sendMessage({
36
- type: 'loop_input',
37
- loop_id: loopId,
38
- input: 'hello soothe',
39
- });
41
+ `iterTurnChunks` peels leftover prior-goal terminals at turn start, ignores
42
+ premature `soothe.stream.end` until the turn has real progress, drains a short
43
+ post-idle window, and sends `delivery_ack` on terminal frames for daemon drain
44
+ gating.
45
+
46
+ ```ts
47
+ import { CommandClient } from '@mirasoth/soothe-client';
48
+
49
+ const cc = new CommandClient('ws://127.0.0.1:8765', { timeoutMs: 30_000 });
50
+ const created = await cc.jobCreate('Echo: smoke job', '/tmp/workspace');
51
+ await cc.jobStatus(String(created.job_id));
52
+ await cc.jobCancel(String(created.job_id));
40
53
  ```
41
54
 
55
+ ## Appkit TurnRunner
56
+
57
+ Product backends that pool connections per chat session use `ConnectionPool` +
58
+ `QueryGate` + `TurnRunner` + `EventClassifier`.
59
+
60
+ | Knob | Default | Notes |
61
+ |------|---------|--------|
62
+ | `idleTimeout` | off (`0`) | Silence watchdog between events (ms) |
63
+ | `minIdleTimeoutWithAttachments` | off | Floor when attachments are present |
64
+ | `onIdleTimeout` / `onQueryTimeout` / `onStreamClose` | `Fail` | Or `SoftComplete` |
65
+ | `compactAttachmentsBeforeSend` | `false` | Needs optional `sharp` for real downscale |
66
+ | `treatStatusIdleAsComplete` (classifier) | `false` | Opt-in idle deliverable |
67
+
42
68
  ## Configuration
43
69
 
44
- `defaultConfig()` returns a `Config` object with sensible defaults. `loadConfigFromEnv()` reads
45
- overrides from these environment variables:
70
+ `defaultConfig()` / `loadConfigFromEnv()`:
46
71
 
47
- | Variable | Default | Description |
48
- | ------------------------------------- | ------------------------ | ---------------------------------------- |
49
- | `SOOTHE_DAEMON_URL` | `ws://localhost:8765` | Daemon WebSocket URL |
50
- | `SOOTHE_VERBOSITY` | `normal` | `quiet` \| `minimal` \| `normal` \| `detailed` \| `debug` |
51
- | `SOOTHE_MAX_RETRIES` | `5` | Reconnect attempts |
52
- | `SOOTHE_DAEMON_READY_TIMEOUT_SEC` | `20` | Daemon-ready handshake timeout (seconds) |
53
- | `SOOTHE_LOOP_STATUS_TIMEOUT_SEC` | `60` | Loop status wait timeout (seconds) |
54
- | `SOOTHE_SUBSCRIPTION_TIMEOUT_SEC` | `10` | Subscription confirmation timeout (seconds) |
72
+ | Variable | Default | Description |
73
+ |----------|---------|-------------|
74
+ | `SOOTHE_DAEMON_URL` | `ws://localhost:8765` | Daemon WebSocket URL |
75
+ | `SOOTHE_VERBOSITY` | `normal` | quiet / minimal / normal / detailed / debug |
76
+ | `SOOTHE_MAX_RETRIES` | `5` | Reconnect attempts |
77
+ | `SOOTHE_DAEMON_READY_TIMEOUT_SEC` | `20` | Handshake timeout |
78
+ | `SOOTHE_LOOP_STATUS_TIMEOUT_SEC` | `60` | Loop status wait |
79
+ | `SOOTHE_SUBSCRIPTION_TIMEOUT_SEC` | `10` | Subscription confirmation |
55
80
 
56
81
  ## API surface
57
82
 
58
- - **`Client`** — WebSocket session, message I/O, request/response, RPC helpers
59
- - **`bootstrapLoopSession`**, **`waitDaemonReady`**, **`connectWithRetries`** — session helpers
60
- - **`checkDaemonStatus`**, **`fetchSkillsCatalog`**, **`fetchConfigSection`** — daemon RPCs
61
- - **`encodeMessage` / `decodeMessage`** — protocol codec
62
- - **`Event*` classes**typed event payloads (plan, explore, tacitus, tool, agent-loop)
63
- - **`VerbosityTier`**, **`classifyEventVerbosity`** — verbosity filtering
64
- - **Errors** — `ConnectionError`, `DaemonError`, `TimeoutError`
83
+ - **`DaemonSession`** — dual-socket loop session + `iterTurnChunks` (preferred for chat)
84
+ - **`CommandClient`** — ephemeral connect → one RPC → close (jobs / cron)
85
+ - **`Client`** — long-lived WebSocket, RPC, reconnect/reattach, peel-stale helpers
86
+ - **`ConnectionPool` / `TurnRunner` / `QueryGate` / `EventClassifier` / `SSEBroadcaster`** — multi-user appkit
87
+ - **`connectedWebsocket` / `protocol1Rpc`** oneshot CLI-style helpers
88
+ - **`bootstrapLoopSession` / `connectWithRetries`** — session helpers
65
89
 
66
- See `dist/index.d.ts` (published) or `src/index.ts` (source) for the full export list.
90
+ See `dist/index.d.ts` or `src/index.ts` for the full export list.
67
91
 
68
- ## Development
92
+ ## Limitations
93
+
94
+ Autopilot control is WebSocket-only (protocol-1 `autopilot_*` / `job_*`
95
+ request RPCs). Prefer `CommandClient` for job/cron/autopilot one-shots so they
96
+ do not share a streaming socket. Worker event streams use
97
+ `client.autopilotSubscribe()` on a long-lived `Client`.
98
+
99
+ ## Develop
69
100
 
70
101
  ```bash
71
- make help # list all targets
102
+ make help # list targets
72
103
  make install # install dependencies
73
104
  make build # compile to dist/
74
- make test # run unit tests
105
+ make test # unit tests
75
106
  make verify # full pre-publish verification
76
- make publish # publish to npm (after verify)
107
+ npm test -- examples/progressive # 01–06 ladder (offline)
77
108
  ```
78
109
 
79
- See [`Makefile`](./Makefile) for the complete list of targets.
110
+ ## Compatibility
111
+
112
+ Same protocol-1 WebSocket contract as `soothe-client-python` and
113
+ `soothe-client-go`.
80
114
 
81
115
  ## License
82
116