@mirasoth/soothe-client 0.2.1 → 0.4.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
@@ -2,17 +2,16 @@
2
2
 
3
3
  TypeScript WebSocket client for the [Soothe](https://github.com/mirasoth/soothe) daemon.
4
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.
5
+ Provides a typed protocol-1 message stack, session bootstrap, reconnect/reattach,
6
+ appkit (connection pool, turn runner, event classifier), and a dual-socket
7
+ `DaemonSession` for streamed turns — matching the production Go and Python clients.
7
8
 
8
9
  ## Install
9
10
 
10
11
  ```bash
11
12
  npm install @mirasoth/soothe-client
12
- # or
13
- pnpm add @mirasoth/soothe-client
14
- # or
15
- yarn add @mirasoth/soothe-client
13
+ # optional: real image downscale for CompactAttachmentsBeforeSend
14
+ npm install sharp
16
15
  ```
17
16
 
18
17
  Requires Node.js `>=19`.
@@ -20,64 +19,81 @@ Requires Node.js `>=19`.
20
19
  ## Quick start
21
20
 
22
21
  ```ts
23
- import { Client, bootstrapLoopSession, defaultConfig } from '@mirasoth/soothe-client';
22
+ import { DaemonSession } from '@mirasoth/soothe-client';
24
23
 
25
- const config = defaultConfig();
26
- const client = new Client(config.daemonURL, config);
24
+ const session = new DaemonSession('ws://127.0.0.1:8765');
25
+ await session.connect();
26
+ await session.sendTurn('summarize this repo');
27
27
 
28
- await client.connect();
29
- const loopId = await bootstrapLoopSession(client, null, config);
28
+ for await (const [namespace, mode, data] of session.iterTurnChunks()) {
29
+ console.log(mode, data);
30
+ }
30
31
 
31
- client.on('message', (msg) => {
32
- console.log('event:', msg);
33
- });
34
-
35
- await client.sendMessage({
36
- type: 'loop_input',
37
- loop_id: loopId,
38
- input: 'hello soothe',
39
- });
32
+ await session.close();
40
33
  ```
41
34
 
35
+ ## What you get
36
+
37
+ | Need | Use |
38
+ |------|-----|
39
+ | One conversation, stream replies | `DaemonSession` |
40
+ | Jobs / cron one-shots | `CommandClient` |
41
+ | Raw WebSocket / custom RPCs | `Client` |
42
+ | Many users / HTTP backend | `ConnectionPool` + `TurnRunner` |
43
+
44
+ `iterTurnChunks` peels leftover prior-goal terminals at turn start, ignores
45
+ premature `soothe.stream.end` until the turn has real progress, and drains a
46
+ short post-idle window before returning. Terminal stream frames send
47
+ `delivery_ack` (daemon drain gating).
48
+
49
+ ## Appkit TurnRunner
50
+
51
+ Product backends that pool connections per chat session use `ConnectionPool` +
52
+ `QueryGate` + `TurnRunner` + `EventClassifier` (RFC-629 Layer 1).
53
+
54
+ Lifecycle knobs (all opt-in; defaults match historical fail-on-timeout behaviour):
55
+
56
+ | Knob | Default | Notes |
57
+ |------|---------|--------|
58
+ | `idleTimeout` | off (`0`) | Silence watchdog between events (ms) |
59
+ | `minIdleTimeoutWithAttachments` | off | Floor when attachments are present |
60
+ | `onIdleTimeout` / `onQueryTimeout` / `onStreamClose` | `Fail` | Or `SoftComplete` |
61
+ | `compactAttachmentsBeforeSend` | `false` | Needs optional `sharp` for real downscale |
62
+ | `treatStatusIdleAsComplete` (classifier) | `false` | Opt-in idle deliverable |
63
+
42
64
  ## Configuration
43
65
 
44
- `defaultConfig()` returns a `Config` object with sensible defaults. `loadConfigFromEnv()` reads
45
- overrides from these environment variables:
66
+ `defaultConfig()` / `loadConfigFromEnv()`:
46
67
 
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) |
68
+ | Variable | Default | Description |
69
+ |----------|---------|-------------|
70
+ | `SOOTHE_DAEMON_URL` | `ws://localhost:8765` | Daemon WebSocket URL |
71
+ | `SOOTHE_VERBOSITY` | `normal` | quiet / minimal / normal / detailed / debug |
72
+ | `SOOTHE_MAX_RETRIES` | `5` | Reconnect attempts |
73
+ | `SOOTHE_DAEMON_READY_TIMEOUT_SEC` | `20` | Handshake timeout |
74
+ | `SOOTHE_LOOP_STATUS_TIMEOUT_SEC` | `60` | Loop status wait |
75
+ | `SOOTHE_SUBSCRIPTION_TIMEOUT_SEC` | `10` | Subscription confirmation |
55
76
 
56
77
  ## API surface
57
78
 
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`
79
+ - **`Client`** — WebSocket session, RPC, reconnect/reattach, peel stale pending frames
80
+ - **`DaemonSession`** — dual-socket loop session + `iterTurnChunks`
81
+ - **`TurnRunner` / `ConnectionPool` / `QueryGate` / `EventClassifier` / `SSEBroadcaster`** — appkit
82
+ - **`connectedWebsocket` / `protocol1Rpc`** — oneshot CLI-style helpers
83
+ - **`bootstrapLoopSession`**, **`connectWithRetries`**session helpers
65
84
 
66
- See `dist/index.d.ts` (published) or `src/index.ts` (source) for the full export list.
85
+ See `dist/index.d.ts` or `src/index.ts` for the full export list.
67
86
 
68
87
  ## Development
69
88
 
70
89
  ```bash
71
- make help # list all targets
90
+ make help # list targets
72
91
  make install # install dependencies
73
92
  make build # compile to dist/
74
- make test # run unit tests
93
+ make test # unit tests
75
94
  make verify # full pre-publish verification
76
- make publish # publish to npm (after verify)
77
95
  ```
78
96
 
79
- See [`Makefile`](./Makefile) for the complete list of targets.
80
-
81
97
  ## License
82
98
 
83
99
  MIT — see [LICENSE](./LICENSE).