@qlairoslabs/acp-client 0.3.0 → 0.3.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 +18 -9
- package/package.json +1 -1
- package/src/activity.ts +38 -11
- package/src/adapters.ts +1 -1
package/README.md
CHANGED
|
@@ -145,9 +145,10 @@ input resend the whole value each time.
|
|
|
145
145
|
### Sending activity over a wire
|
|
146
146
|
|
|
147
147
|
For a hub forwarding activity to a browser, send `wireFrames(result)` and fold with
|
|
148
|
-
`foldFrame`. Thinking crosses as
|
|
149
|
-
|
|
150
|
-
crosses as a
|
|
148
|
+
`foldFrame`. Thinking crosses as a full record on the chunk that OPENS a block and as an
|
|
149
|
+
incremental `delta` for every chunk after it (re-sending the accumulated block per chunk is
|
|
150
|
+
quadratic — ~4 KB of text becomes ~800 KB over 400 chunks); everything else crosses as a
|
|
151
|
+
full record.
|
|
151
152
|
|
|
152
153
|
```ts
|
|
153
154
|
// hub
|
|
@@ -162,9 +163,16 @@ let records = new Map<string, AggregatedRecord>();
|
|
|
162
163
|
socket.onmessage = (e) => { records = foldFrame(records, JSON.parse(e.data)); };
|
|
163
164
|
```
|
|
164
165
|
|
|
165
|
-
Send `wireFrames(result)`, not `delta ?? current
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
Send `wireFrames(result)`, not `delta ?? current`, and don't reach past it into `result`:
|
|
167
|
+
|
|
168
|
+
- When a thinking block ends because a tool call started, that close rides in `emitted`
|
|
169
|
+
while `current` is the tool — a client sending only the latter never learns the block
|
|
170
|
+
finished and renders a bubble that never stops.
|
|
171
|
+
- `foldFrame` drops a delta whose base it has never seen (guessing at one is how you get
|
|
172
|
+
text stitched onto the wrong block). `wireFrames` sends the base first, so that never
|
|
173
|
+
happens on a subscriber who has been listening from the start.
|
|
174
|
+
- It never sends a record and a delta for the same `recordId` in one call. `foldFrame` has
|
|
175
|
+
no seq guard, so a consumer would append the same text twice.
|
|
168
176
|
|
|
169
177
|
The `/activity` subpath has **no runtime imports**, so it is safe to pull into a browser
|
|
170
178
|
bundle. Type-only imports work anywhere today; importing the *functions* needs a bundler
|
|
@@ -180,9 +188,10 @@ records = foldRecords(snap.records);
|
|
|
180
188
|
// then drop any streamed frame with frame.seq <= snap.seq — already reflected above
|
|
181
189
|
```
|
|
182
190
|
|
|
183
|
-
`seq` never restarts, so that threshold stays valid across turns.
|
|
184
|
-
`activitySnapshot()` reports `active: false` with no records: a settled turn
|
|
185
|
-
transcript, not to a replay.
|
|
191
|
+
`seq` never restarts, so that threshold stays valid across turns. Before the first turn and
|
|
192
|
+
between turns `activitySnapshot()` reports `active: false` with no records: a settled turn
|
|
193
|
+
belongs to the transcript, not to a replay. `active` only knows what the aggregator has
|
|
194
|
+
been told — a hub that separately tracks which sessions are busy should trust itself.
|
|
186
195
|
|
|
187
196
|
### Debugging: the raw protocol
|
|
188
197
|
|
package/package.json
CHANGED
package/src/activity.ts
CHANGED
|
@@ -52,6 +52,10 @@ export interface AggregatedRecord {
|
|
|
52
52
|
* agent resends the whole `content` each time — so a full record costs no more than the
|
|
53
53
|
* raw event. Thinking arrives as many small chunks, where re-sending the accumulated
|
|
54
54
|
* block per chunk is quadratic: ~4 KB of text becomes ~800 KB over 400 chunks.
|
|
55
|
+
*
|
|
56
|
+
* Never produced for the chunk that OPENS a block: a delta is an increment on state the
|
|
57
|
+
* consumer already has, and on the opening chunk there is none. That chunk's `current` is
|
|
58
|
+
* the base record, and it is exactly as small as the delta would have been.
|
|
55
59
|
*/
|
|
56
60
|
export interface ActivityDelta {
|
|
57
61
|
recordId: string;
|
|
@@ -66,7 +70,11 @@ export type ActivityFrame = AggregatedRecord | ActivityDelta;
|
|
|
66
70
|
export interface ApplyResult {
|
|
67
71
|
/** Full state of whatever this event touched. Null only if it produced no record. */
|
|
68
72
|
current: AggregatedRecord | null;
|
|
69
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Set for accumulating kinds, EXCEPT on the event that opens the record. When present,
|
|
75
|
+
* prefer it over `current` on the wire; when null, `current` is what has to go, or the
|
|
76
|
+
* consumer never gets a base to append to.
|
|
77
|
+
*/
|
|
70
78
|
delta: ActivityDelta | null;
|
|
71
79
|
/** Checkpoints worth persisting. Usually empty. */
|
|
72
80
|
emitted: AggregatedRecord[];
|
|
@@ -75,10 +83,13 @@ export interface ApplyResult {
|
|
|
75
83
|
/** Everything known about the turn IN FLIGHT — for replaying to a late subscriber. */
|
|
76
84
|
export interface ActivitySnapshot {
|
|
77
85
|
/**
|
|
78
|
-
* Whether a turn is in flight. False between turns, when
|
|
86
|
+
* Whether a turn is in flight. False before the first one and between turns, when
|
|
87
|
+
* `records` is empty.
|
|
79
88
|
*
|
|
80
89
|
* Distinguishes "no turn running" from "a turn that has not produced anything yet" —
|
|
81
|
-
* both return no records, but only the second means frames are coming.
|
|
90
|
+
* both return no records, but only the second means frames are coming. It reflects what
|
|
91
|
+
* this aggregator has been told: a caller that knows more (a hub tracking which sessions
|
|
92
|
+
* are busy, say) should trust itself over this.
|
|
82
93
|
*/
|
|
83
94
|
active: boolean;
|
|
84
95
|
/**
|
|
@@ -143,7 +154,10 @@ function hasInput(rawInput: unknown): boolean {
|
|
|
143
154
|
export class ActivityAggregator {
|
|
144
155
|
private checkpointOnInput: boolean;
|
|
145
156
|
private idPrefix: string;
|
|
146
|
-
|
|
157
|
+
// False until the first event or `startTurn()`. A freshly constructed aggregator has not
|
|
158
|
+
// seen a turn, and saying otherwise puts a spinner in front of any client that connects
|
|
159
|
+
// while the session is still coming up — with no `flush()` ever coming to end it.
|
|
160
|
+
private turnOpen = false;
|
|
147
161
|
private seq = 0;
|
|
148
162
|
private records = new Map<string, AggregatedRecord>();
|
|
149
163
|
private calls = new Map<string, ToolActivity>();
|
|
@@ -161,6 +175,8 @@ export class ActivityAggregator {
|
|
|
161
175
|
/** Fold one live event. */
|
|
162
176
|
apply(event: ActivityEvent): ApplyResult {
|
|
163
177
|
this.seq++;
|
|
178
|
+
this.turnOpen = true; // an event IS a turn in flight, `startTurn()` or not
|
|
179
|
+
|
|
164
180
|
const emitted: AggregatedRecord[] = [];
|
|
165
181
|
|
|
166
182
|
// A thinking block ends when something else happens. Emit its close BEFORE the
|
|
@@ -273,7 +289,7 @@ export class ActivityAggregator {
|
|
|
273
289
|
reset(): void {
|
|
274
290
|
this.clearTurn();
|
|
275
291
|
this.seq = 0;
|
|
276
|
-
this.turnOpen =
|
|
292
|
+
this.turnOpen = false;
|
|
277
293
|
}
|
|
278
294
|
|
|
279
295
|
private clearTurn(): void {
|
|
@@ -292,6 +308,11 @@ export class ActivityAggregator {
|
|
|
292
308
|
event: Extract<ActivityEvent, { kind: "thinking" }>,
|
|
293
309
|
emitted: AggregatedRecord[],
|
|
294
310
|
): ApplyResult {
|
|
311
|
+
// The opening chunk sends the RECORD, not a delta. A delta is an increment on state
|
|
312
|
+
// the consumer already has, and here it has none: `foldFrame` correctly drops a delta
|
|
313
|
+
// whose base it never saw, so opening with one means the whole block streams to
|
|
314
|
+
// nobody — it only appears once it closes and the settled record goes out.
|
|
315
|
+
const opening = !this.thinking;
|
|
295
316
|
if (!this.thinking) {
|
|
296
317
|
// `messageId` identifies the block when the agent sends one — most don't, so fall
|
|
297
318
|
// back to a per-turn counter. This is the instance-local id the one-aggregator
|
|
@@ -310,12 +331,14 @@ export class ActivityAggregator {
|
|
|
310
331
|
|
|
311
332
|
return {
|
|
312
333
|
current: this.put(this.thinking.recordId, "announced", full),
|
|
313
|
-
delta:
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
334
|
+
delta: opening
|
|
335
|
+
? null
|
|
336
|
+
: {
|
|
337
|
+
recordId: this.thinking.recordId,
|
|
338
|
+
seq: this.seq,
|
|
339
|
+
kind: "thinking",
|
|
340
|
+
append: event.text,
|
|
341
|
+
},
|
|
319
342
|
emitted,
|
|
320
343
|
};
|
|
321
344
|
}
|
|
@@ -504,6 +527,10 @@ export function foldFrame(
|
|
|
504
527
|
* `delta ?? current` alone is not enough: when a thinking block closes because a tool
|
|
505
528
|
* call arrived, the close is in `emitted` while `current` is the tool — a subscriber
|
|
506
529
|
* would never learn the block ended. Records already in `emitted` are not repeated.
|
|
530
|
+
*
|
|
531
|
+
* Never sends a record and a delta for the same `recordId` in one call: `foldFrame` has
|
|
532
|
+
* no seq guard, so the consumer would apply the same text twice. The opening chunk of a
|
|
533
|
+
* thinking block is a record (`delta` is null there); every chunk after it is a delta.
|
|
507
534
|
*/
|
|
508
535
|
export function wireFrames(result: ApplyResult): ActivityFrame[] {
|
|
509
536
|
const frames: ActivityFrame[] = [...result.emitted];
|
package/src/adapters.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface Adapter {
|
|
|
22
22
|
*/
|
|
23
23
|
export const ADAPTERS = {
|
|
24
24
|
kimi: { command: ["kimi", "acp"], ptyCommand: ["kimi"], displayName: "Kimi" },
|
|
25
|
-
claude: { command: ["claude-
|
|
25
|
+
claude: { command: ["claude-code-acp"], ptyCommand: ["claude"], displayName: "Claude" },
|
|
26
26
|
codex: { command: ["codex-acp"], ptyCommand: ["codex"], displayName: "Codex" },
|
|
27
27
|
gemini: { command: ["gemini", "--acp", "--stdio"], ptyCommand: ["gemini"], displayName: "Gemini" },
|
|
28
28
|
copilot: { command: ["copilot", "--acp", "--stdio"], ptyCommand: ["copilot"], displayName: "Copilot" },
|