@spinabot/brigade 1.14.0 → 1.15.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/convex/logs.d.ts +6 -6
- package/convex/schema.d.ts +3 -3
- package/dist/buildstamp.json +1 -1
- package/dist/cli/commands/connect-transcript.d.ts +39 -0
- package/dist/cli/commands/connect-transcript.d.ts.map +1 -0
- package/dist/cli/commands/connect-transcript.js +60 -0
- package/dist/cli/commands/connect-transcript.js.map +1 -0
- package/dist/cli/commands/connect.d.ts.map +1 -1
- package/dist/cli/commands/connect.js +297 -169
- package/dist/cli/commands/connect.js.map +1 -1
- package/dist/core/server.d.ts.map +1 -1
- package/dist/core/server.js +170 -14
- package/dist/core/server.js.map +1 -1
- package/dist/protocol/errors.d.ts +14 -0
- package/dist/protocol/errors.d.ts.map +1 -1
- package/dist/protocol/errors.js +14 -0
- package/dist/protocol/errors.js.map +1 -1
- package/dist/protocol/handshake.d.ts +10 -0
- package/dist/protocol/handshake.d.ts.map +1 -1
- package/dist/protocol/stream-seq.d.ts +30 -0
- package/dist/protocol/stream-seq.d.ts.map +1 -0
- package/dist/protocol/stream-seq.js +38 -0
- package/dist/protocol/stream-seq.js.map +1 -0
- package/dist/protocol.d.ts +265 -6
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +95 -5
- package/dist/protocol.js.map +1 -1
- package/dist/tui/client.d.ts +67 -2
- package/dist/tui/client.d.ts.map +1 -1
- package/dist/tui/client.js +106 -2
- package/dist/tui/client.js.map +1 -1
- package/package.json +1 -1
package/dist/protocol.js
CHANGED
|
@@ -18,6 +18,86 @@
|
|
|
18
18
|
*
|
|
19
19
|
* Compatible with: any WebSocket client speaking this JSON shape.
|
|
20
20
|
*/
|
|
21
|
+
/* ─────────────────────── runtime discovery arrays ─────────────────────── */
|
|
22
|
+
/**
|
|
23
|
+
* Runtime list of every core request method, mirroring the `RequestMethod`
|
|
24
|
+
* union (types are erased at compile time, so a client can't enumerate them
|
|
25
|
+
* otherwise). The gateway advertises this (plus any plugin-registered methods)
|
|
26
|
+
* in `HelloOk.features.methods` on connect, so a web/mobile client discovers
|
|
27
|
+
* what it can call instead of hardcoding strings. `satisfies` makes adding an
|
|
28
|
+
* invalid method a compile error.
|
|
29
|
+
*/
|
|
30
|
+
export const REQUEST_METHODS = [
|
|
31
|
+
"prompt",
|
|
32
|
+
"abort",
|
|
33
|
+
"steer",
|
|
34
|
+
"set-model",
|
|
35
|
+
"switch-model-mid-turn",
|
|
36
|
+
"set-thinking",
|
|
37
|
+
"compact",
|
|
38
|
+
"approval-resolve",
|
|
39
|
+
"exec-allow-all",
|
|
40
|
+
"exec-grant-skill",
|
|
41
|
+
"list-models",
|
|
42
|
+
"refresh-models",
|
|
43
|
+
"add-provider",
|
|
44
|
+
"get-state",
|
|
45
|
+
"resume",
|
|
46
|
+
"memory-graph",
|
|
47
|
+
"memory-query",
|
|
48
|
+
"shutdown",
|
|
49
|
+
"subscribe",
|
|
50
|
+
"unsubscribe",
|
|
51
|
+
"agents.list",
|
|
52
|
+
"sessions.list",
|
|
53
|
+
"cron.status",
|
|
54
|
+
"cron.list",
|
|
55
|
+
"cron.add",
|
|
56
|
+
"cron.update",
|
|
57
|
+
"cron.remove",
|
|
58
|
+
"cron.run",
|
|
59
|
+
"cron.runs",
|
|
60
|
+
"wake",
|
|
61
|
+
"org.snapshot",
|
|
62
|
+
];
|
|
63
|
+
/**
|
|
64
|
+
* Runtime list of every server-pushed event name, mirroring `EventName`.
|
|
65
|
+
* Advertised in `HelloOk.features.events` so a client knows what to subscribe
|
|
66
|
+
* to. `satisfies` keeps it in lock-step with the union.
|
|
67
|
+
*/
|
|
68
|
+
export const EVENT_NAMES = [
|
|
69
|
+
"pi",
|
|
70
|
+
"state",
|
|
71
|
+
"error",
|
|
72
|
+
"log",
|
|
73
|
+
"system-event",
|
|
74
|
+
"approval-request",
|
|
75
|
+
];
|
|
76
|
+
/* ─────────────────────── pi inner-event contract ─────────────────────── */
|
|
77
|
+
/**
|
|
78
|
+
* The set of `pi.event.type` values the gateway forwards (mirrors Pi's
|
|
79
|
+
* `AgentSessionEvent` union). A web/mobile renderer switches on `pi.event.type`;
|
|
80
|
+
* this is the authoritative list so it can be exhaustive.
|
|
81
|
+
*/
|
|
82
|
+
export const PI_EVENT_TYPES = [
|
|
83
|
+
"agent_start",
|
|
84
|
+
"turn_start",
|
|
85
|
+
"turn_end",
|
|
86
|
+
"message_start",
|
|
87
|
+
"message_update",
|
|
88
|
+
"message_end",
|
|
89
|
+
"tool_execution_start",
|
|
90
|
+
"tool_execution_update",
|
|
91
|
+
"tool_execution_end",
|
|
92
|
+
"agent_end",
|
|
93
|
+
"queue_update",
|
|
94
|
+
"compaction_start",
|
|
95
|
+
"compaction_end",
|
|
96
|
+
"auto_retry_start",
|
|
97
|
+
"auto_retry_end",
|
|
98
|
+
"session_info_changed",
|
|
99
|
+
"thinking_level_changed",
|
|
100
|
+
];
|
|
21
101
|
export function modelToSummary(model) {
|
|
22
102
|
return {
|
|
23
103
|
provider: model.provider,
|
|
@@ -48,18 +128,28 @@ export const EXIT_FAILURE = 1;
|
|
|
48
128
|
export const EXIT_USAGE_ERROR = 2;
|
|
49
129
|
export const EXIT_CONFIG_ERROR = 78;
|
|
50
130
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
131
|
+
* Heartbeat interval. The server's keepalive today is the periodic `state`
|
|
132
|
+
* broadcast (a real frame that bumps the client's `lastFrameAt`), plus
|
|
133
|
+
* WS-protocol pings; the dedicated `TickFrame` type exists for forward-compat
|
|
134
|
+
* but is not emitted yet. The client closes + reconnects if NO frame arrives in
|
|
135
|
+
* 2× this interval (catches half-open sockets — the common backgrounded-mobile
|
|
136
|
+
* case), then `resume`s.
|
|
54
137
|
*/
|
|
55
138
|
export const TICK_INTERVAL_MS = 30_000;
|
|
56
139
|
/* ─────────────────────────── tiny runtime guards ─────────────────────────── */
|
|
57
|
-
/** Cheap shape check before routing. Avoids dragging in AJV for v1's small surface.
|
|
140
|
+
/** Cheap shape check before routing. Avoids dragging in AJV for v1's small surface.
|
|
141
|
+
* Accepts `tick`/`shutdown` too so the client never silently drops a keepalive
|
|
142
|
+
* or a graceful-shutdown notice (the old guard rejected both). */
|
|
58
143
|
export function isFrame(value) {
|
|
59
144
|
if (!value || typeof value !== "object")
|
|
60
145
|
return false;
|
|
61
146
|
const t = value.type;
|
|
62
|
-
return t === "req" ||
|
|
147
|
+
return (t === "req" ||
|
|
148
|
+
t === "res" ||
|
|
149
|
+
t === "event" ||
|
|
150
|
+
t === "tick" ||
|
|
151
|
+
t === "shutdown" ||
|
|
152
|
+
t === "hello-ok");
|
|
63
153
|
}
|
|
64
154
|
/* ─────────────────────── Step 24 protocol barrel re-export ─────────────────────── */
|
|
65
155
|
/**
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAqQH,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,QAAQ;IACR,OAAO;IACP,OAAO;IACP,WAAW;IACX,uBAAuB;IACvB,cAAc;IACd,SAAS;IACT,kBAAkB;IAClB,gBAAgB;IAChB,kBAAkB;IAClB,aAAa;IACb,gBAAgB;IAChB,cAAc;IACd,WAAW;IACX,QAAQ;IACR,cAAc;IACd,cAAc;IACd,UAAU;IACV,WAAW;IACX,aAAa;IACb,aAAa;IACb,eAAe;IACf,aAAa;IACb,WAAW;IACX,UAAU;IACV,aAAa;IACb,aAAa;IACb,UAAU;IACV,WAAW;IACX,MAAM;IACN,cAAc;CAC8B,CAAC;AAE9C;;;;GAIG;AAC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MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEvC,iFAAiF;AAEjF;;mEAEmE;AACnE,MAAM,UAAU,OAAO,CAAC,KAAc;IACrC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,CAAC,GAAI,KAAa,CAAC,IAAI,CAAC;IAC9B,OAAO,CACN,CAAC,KAAK,KAAK;QACX,CAAC,KAAK,KAAK;QACX,CAAC,KAAK,OAAO;QACb,CAAC,KAAK,MAAM;QACZ,CAAC,KAAK,UAAU;QAChB,CAAC,KAAK,UAAU,CAChB,CAAC;AACH,CAAC;AAED,uFAAuF;AACvF;;;;;;GAMG;AACH,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC"}
|
package/dist/tui/client.d.ts
CHANGED
|
@@ -17,7 +17,18 @@
|
|
|
17
17
|
* - One-shot connect: caller awaits `client.ready` before sending requests
|
|
18
18
|
*/
|
|
19
19
|
import { EventEmitter } from "node:events";
|
|
20
|
-
import { type EventName, type EventPayload, type RequestMethod, type RequestParams, type ResponseFor } from "../protocol.js";
|
|
20
|
+
import { type EventName, type EventPayload, type RequestMethod, type RequestParams, type ResponseFor, type ResumeSnapshot, type ShutdownFrame } from "../protocol.js";
|
|
21
|
+
import type { HelloOk } from "../protocol/handshake.js";
|
|
22
|
+
/** Payload of the client-emitted `"resync"` event: a seq gap was detected on a
|
|
23
|
+
* session's ordered `pi` stream, so the consumer should `resume()` to backfill. */
|
|
24
|
+
export interface ClientResyncInfo {
|
|
25
|
+
sessionId: string;
|
|
26
|
+
lastSeq: number;
|
|
27
|
+
gotSeq: number;
|
|
28
|
+
}
|
|
29
|
+
/** Connection lifecycle state, emitted as the `"connection-state"` event so a
|
|
30
|
+
* UI can bind a status indicator directly. */
|
|
31
|
+
export type ClientConnectionState = "connecting" | "connected" | "reconnecting" | "closed";
|
|
21
32
|
export interface ClientOptions {
|
|
22
33
|
/** WebSocket URL. Defaults to `ws://127.0.0.1:7777`. */
|
|
23
34
|
url?: string;
|
|
@@ -69,6 +80,20 @@ export declare class BrigadeClient extends EventEmitter {
|
|
|
69
80
|
/** Last time we received any frame from the server. Tick watchdog reads this. */
|
|
70
81
|
private lastFrameAt;
|
|
71
82
|
private tickWatchTimer;
|
|
83
|
+
/**
|
|
84
|
+
* Last `seq` seen per session on the ordered `pi` stream. Used to detect a
|
|
85
|
+
* gap: when a frame's seq isn't `last + 1`, a frame was dropped or reordered
|
|
86
|
+
* (or the gateway restarted and reset its counters), so we emit `"resync"`
|
|
87
|
+
* and the consumer issues a `resume` to backfill from the transcript. Keyed
|
|
88
|
+
* by sessionId (= sessionKey), the same key `resume` syncs. Survives
|
|
89
|
+
* reconnects so the cursor stays meaningful across a blip.
|
|
90
|
+
*/
|
|
91
|
+
private lastSeqBySession;
|
|
92
|
+
/** The most recent HelloOk frame (server connId, build version, epoch,
|
|
93
|
+
* advertised methods/events, policy limits). Undefined until first connect. */
|
|
94
|
+
private lastHelloOk;
|
|
95
|
+
/** Connection lifecycle state, mirrored by the "connection-state" event. */
|
|
96
|
+
private connState;
|
|
72
97
|
/** Reconnect state. */
|
|
73
98
|
private reconnectAttempt;
|
|
74
99
|
private reconnectTimer;
|
|
@@ -77,6 +102,16 @@ export declare class BrigadeClient extends EventEmitter {
|
|
|
77
102
|
connect(): Promise<void>;
|
|
78
103
|
/** Close the connection permanently. Cancels reconnect, rejects pending. */
|
|
79
104
|
close(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Server handshake info from the last `HelloOk` — connId, build version,
|
|
107
|
+
* `epoch` (session generation), the advertised `features.{methods,events}`,
|
|
108
|
+
* and `policy` limits. Undefined before the first connect. A web/mobile
|
|
109
|
+
* client reads this to discover what it can call/subscribe to + the limits.
|
|
110
|
+
*/
|
|
111
|
+
get server(): HelloOk | undefined;
|
|
112
|
+
/** Current connection lifecycle state (also pushed via "connection-state"). */
|
|
113
|
+
get connectionState(): ClientConnectionState;
|
|
114
|
+
private setConnState;
|
|
80
115
|
/** True if the underlying socket is currently OPEN. */
|
|
81
116
|
get isConnected(): boolean;
|
|
82
117
|
/**
|
|
@@ -85,9 +120,39 @@ export declare class BrigadeClient extends EventEmitter {
|
|
|
85
120
|
* timeout elapses, or the socket closes before a response arrives.
|
|
86
121
|
*/
|
|
87
122
|
request<M extends RequestMethod>(method: M, params?: RequestParams[M], options?: RequestOptions): Promise<ResponseFor[M]>;
|
|
88
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Type-aware event subscription. Two families:
|
|
125
|
+
* - server-pushed events, typed by `EventName` → `EventPayload[K]`
|
|
126
|
+
* - client lifecycle events BrigadeClient emits itself: `"hello"` (the
|
|
127
|
+
* server's HelloOk handshake landed), `"connection-state"` (connecting /
|
|
128
|
+
* connected / reconnecting / closed), `"reconnected"` (socket re-opened),
|
|
129
|
+
* `"resync"` (a seq gap → call `resume()`), and `"shutdown"` (the gateway
|
|
130
|
+
* sent a graceful-shutdown frame).
|
|
131
|
+
* Returns `this` for chaining (matches EventEmitter).
|
|
132
|
+
*/
|
|
89
133
|
on<K extends EventName>(event: K, listener: (payload: EventPayload[K]) => void): this;
|
|
134
|
+
on(event: "hello", listener: (hello: HelloOk) => void): this;
|
|
135
|
+
on(event: "connection-state", listener: (state: ClientConnectionState) => void): this;
|
|
136
|
+
on(event: "reconnected", listener: () => void): this;
|
|
137
|
+
on(event: "resync", listener: (info: ClientResyncInfo) => void): this;
|
|
138
|
+
on(event: "shutdown", listener: (frame: ShutdownFrame) => void): this;
|
|
90
139
|
off<K extends EventName>(event: K, listener: (payload: EventPayload[K]) => void): this;
|
|
140
|
+
off(event: "hello", listener: (hello: HelloOk) => void): this;
|
|
141
|
+
off(event: "connection-state", listener: (state: ClientConnectionState) => void): this;
|
|
142
|
+
off(event: "reconnected", listener: () => void): this;
|
|
143
|
+
off(event: "resync", listener: (info: ClientResyncInfo) => void): this;
|
|
144
|
+
off(event: "shutdown", listener: (frame: ShutdownFrame) => void): this;
|
|
145
|
+
/**
|
|
146
|
+
* Resume a session: fetch its committed transcript + head seq + header
|
|
147
|
+
* snapshot, and sync the local seq cursor so live frames continue cleanly
|
|
148
|
+
* from `headSeq + 1`. Call this on connect, on reconnect, and on a
|
|
149
|
+
* `"resync"` event. The consumer renders the returned `messages` through
|
|
150
|
+
* its identity-keyed applier (idempotent), so overlapping with live frames
|
|
151
|
+
* is harmless. This is the reliable-streaming recovery primitive — the
|
|
152
|
+
* transcript is the source of truth, so a dropped/reordered/missed frame
|
|
153
|
+
* always self-heals here.
|
|
154
|
+
*/
|
|
155
|
+
resume(params?: RequestParams["resume"]): Promise<ResumeSnapshot>;
|
|
91
156
|
private openSocket;
|
|
92
157
|
private scheduleReconnect;
|
|
93
158
|
private dispatchFrame;
|
package/dist/tui/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/tui/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,EAEN,KAAK,SAAS,EACd,KAAK,YAAY,EAGjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/tui/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,EAEN,KAAK,SAAS,EACd,KAAK,YAAY,EAGjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,aAAa,EAElB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AA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AAC,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI;IACtF,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI;IAC7D,GAAG,CAAC,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,GAAG,IAAI;IACtF,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IACrD,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI;IACtE,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,GAAG,IAAI;IAK/E;;;;;;;;;OASG;IACG,MAAM,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAevE,OAAO,CAAC,UAAU;IA+DlB,OAAO,CAAC,iBAAiB;IAmBzB,OAAO,CAAC,aAAa;IAsErB,OAAO,CAAC,cAAc;IAoBtB,OAAO,CAAC,aAAa;CAIrB"}
|
package/dist/tui/client.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import { EventEmitter } from "node:events";
|
|
20
20
|
import WebSocket from "ws";
|
|
21
21
|
import { DEFAULT_PORT, isFrame, TICK_INTERVAL_MS, } from "../protocol.js";
|
|
22
|
+
import { isSeqGap } from "../protocol/stream-seq.js";
|
|
22
23
|
import { clientAuthHeaders } from "../core/gateway-auth.js";
|
|
23
24
|
/**
|
|
24
25
|
* Brigade gateway client. Construct → `await client.connect()` → use.
|
|
@@ -48,6 +49,20 @@ export class BrigadeClient extends EventEmitter {
|
|
|
48
49
|
/** Last time we received any frame from the server. Tick watchdog reads this. */
|
|
49
50
|
lastFrameAt = 0;
|
|
50
51
|
tickWatchTimer;
|
|
52
|
+
/**
|
|
53
|
+
* Last `seq` seen per session on the ordered `pi` stream. Used to detect a
|
|
54
|
+
* gap: when a frame's seq isn't `last + 1`, a frame was dropped or reordered
|
|
55
|
+
* (or the gateway restarted and reset its counters), so we emit `"resync"`
|
|
56
|
+
* and the consumer issues a `resume` to backfill from the transcript. Keyed
|
|
57
|
+
* by sessionId (= sessionKey), the same key `resume` syncs. Survives
|
|
58
|
+
* reconnects so the cursor stays meaningful across a blip.
|
|
59
|
+
*/
|
|
60
|
+
lastSeqBySession = new Map();
|
|
61
|
+
/** The most recent HelloOk frame (server connId, build version, epoch,
|
|
62
|
+
* advertised methods/events, policy limits). Undefined until first connect. */
|
|
63
|
+
lastHelloOk;
|
|
64
|
+
/** Connection lifecycle state, mirrored by the "connection-state" event. */
|
|
65
|
+
connState = "connecting";
|
|
51
66
|
/** Reconnect state. */
|
|
52
67
|
reconnectAttempt = 0;
|
|
53
68
|
reconnectTimer;
|
|
@@ -84,6 +99,26 @@ export class BrigadeClient extends EventEmitter {
|
|
|
84
99
|
}
|
|
85
100
|
this.ws = undefined;
|
|
86
101
|
this.connected = false;
|
|
102
|
+
this.setConnState("closed");
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Server handshake info from the last `HelloOk` — connId, build version,
|
|
106
|
+
* `epoch` (session generation), the advertised `features.{methods,events}`,
|
|
107
|
+
* and `policy` limits. Undefined before the first connect. A web/mobile
|
|
108
|
+
* client reads this to discover what it can call/subscribe to + the limits.
|
|
109
|
+
*/
|
|
110
|
+
get server() {
|
|
111
|
+
return this.lastHelloOk;
|
|
112
|
+
}
|
|
113
|
+
/** Current connection lifecycle state (also pushed via "connection-state"). */
|
|
114
|
+
get connectionState() {
|
|
115
|
+
return this.connState;
|
|
116
|
+
}
|
|
117
|
+
setConnState(state) {
|
|
118
|
+
if (this.connState === state)
|
|
119
|
+
return;
|
|
120
|
+
this.connState = state;
|
|
121
|
+
super.emit("connection-state", state);
|
|
87
122
|
}
|
|
88
123
|
/** True if the underlying socket is currently OPEN. */
|
|
89
124
|
get isConnected() {
|
|
@@ -127,13 +162,34 @@ export class BrigadeClient extends EventEmitter {
|
|
|
127
162
|
}
|
|
128
163
|
});
|
|
129
164
|
}
|
|
130
|
-
/** Type-aware event subscription. Returns `this` for chaining (matches EventEmitter). */
|
|
131
165
|
on(event, listener) {
|
|
132
166
|
return super.on(event, listener);
|
|
133
167
|
}
|
|
134
168
|
off(event, listener) {
|
|
135
169
|
return super.off(event, listener);
|
|
136
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Resume a session: fetch its committed transcript + head seq + header
|
|
173
|
+
* snapshot, and sync the local seq cursor so live frames continue cleanly
|
|
174
|
+
* from `headSeq + 1`. Call this on connect, on reconnect, and on a
|
|
175
|
+
* `"resync"` event. The consumer renders the returned `messages` through
|
|
176
|
+
* its identity-keyed applier (idempotent), so overlapping with live frames
|
|
177
|
+
* is harmless. This is the reliable-streaming recovery primitive — the
|
|
178
|
+
* transcript is the source of truth, so a dropped/reordered/missed frame
|
|
179
|
+
* always self-heals here.
|
|
180
|
+
*/
|
|
181
|
+
async resume(params) {
|
|
182
|
+
// NOTE: we deliberately do NOT write `lastSeqBySession` here. The seq
|
|
183
|
+
// cursor is owned by `dispatchFrame`, which advances it to each live
|
|
184
|
+
// frame's seq as it arrives — so after a gap the cursor already reflects
|
|
185
|
+
// the last frame actually received, and the next contiguous frame won't
|
|
186
|
+
// re-trigger. Writing `headSeq` here (a snapshot that can LAG the live
|
|
187
|
+
// frames still streaming during the resume round-trip) would rewind the
|
|
188
|
+
// cursor below an already-applied frame, making the next live frame look
|
|
189
|
+
// like a fresh gap → a resync/resume storm on a busy session. resume()
|
|
190
|
+
// recovers CONTENT (the transcript); the cursor is pure live bookkeeping.
|
|
191
|
+
return this.request("resume", params);
|
|
192
|
+
}
|
|
137
193
|
/* ─────────────────────────── socket lifecycle ─────────────────────────── */
|
|
138
194
|
openSocket() {
|
|
139
195
|
return new Promise((resolve, reject) => {
|
|
@@ -144,6 +200,7 @@ export class BrigadeClient extends EventEmitter {
|
|
|
144
200
|
this.connected = true;
|
|
145
201
|
this.reconnectAttempt = 0;
|
|
146
202
|
this.lastFrameAt = Date.now();
|
|
203
|
+
this.setConnState("connected");
|
|
147
204
|
resolved = true;
|
|
148
205
|
resolve();
|
|
149
206
|
});
|
|
@@ -183,8 +240,10 @@ export class BrigadeClient extends EventEmitter {
|
|
|
183
240
|
}
|
|
184
241
|
if (!resolved)
|
|
185
242
|
reject(new Error("socket closed before open"));
|
|
186
|
-
if (!this.closed)
|
|
243
|
+
if (!this.closed) {
|
|
244
|
+
this.setConnState("reconnecting");
|
|
187
245
|
this.scheduleReconnect();
|
|
246
|
+
}
|
|
188
247
|
});
|
|
189
248
|
ws.on("error", (err) => {
|
|
190
249
|
if (!resolved) {
|
|
@@ -230,10 +289,55 @@ export class BrigadeClient extends EventEmitter {
|
|
|
230
289
|
return;
|
|
231
290
|
}
|
|
232
291
|
if (frame.type === "event") {
|
|
292
|
+
// Gap detection on the ordered stream. The server stamps a per-session
|
|
293
|
+
// monotonic `seq` on every ordered frame — `pi` (top-level),
|
|
294
|
+
// `approval-request`, and `system-event` — all sharing one counter, so
|
|
295
|
+
// any frame carrying a `seq` is part of it. If the next seq isn't
|
|
296
|
+
// `last + 1` we missed a frame (dropped by backpressure, reordered, or
|
|
297
|
+
// a gateway restart); emit `"resync"` so the consumer `resume`s and
|
|
298
|
+
// backfills (transcript + pending approvals + recent system-events).
|
|
299
|
+
// Frames without `seq` (state/error/log + sub-agent pi) are unordered
|
|
300
|
+
// side-channels and skip the check.
|
|
301
|
+
if (typeof frame.seq === "number") {
|
|
302
|
+
const sid = frame.payload?.sessionId;
|
|
303
|
+
if (sid) {
|
|
304
|
+
const last = this.lastSeqBySession.get(sid);
|
|
305
|
+
this.lastSeqBySession.set(sid, frame.seq);
|
|
306
|
+
if (isSeqGap(last, frame.seq)) {
|
|
307
|
+
super.emit("resync", { sessionId: sid, lastSeq: last, gotSeq: frame.seq });
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
233
311
|
// Re-emit with the typed event name so on() handlers fire.
|
|
234
312
|
super.emit(frame.event, frame.payload);
|
|
235
313
|
return;
|
|
236
314
|
}
|
|
315
|
+
if (frame.type === "hello-ok") {
|
|
316
|
+
// Server handshake (connId / build version / epoch / advertised
|
|
317
|
+
// methods+events / policy limits). If the `epoch` changed since the
|
|
318
|
+
// last HelloOk, the gateway restarted and its per-session seq counters
|
|
319
|
+
// reset — invalidate our cursors so the fresh low seqs aren't misread
|
|
320
|
+
// as a backwards gap; the consumer's reconnect → `resume` rebuilds.
|
|
321
|
+
const prevEpoch = this.lastHelloOk?.server.epoch;
|
|
322
|
+
this.lastHelloOk = frame;
|
|
323
|
+
if (prevEpoch !== undefined && prevEpoch !== frame.server.epoch) {
|
|
324
|
+
this.lastSeqBySession.clear();
|
|
325
|
+
}
|
|
326
|
+
super.emit("hello", frame);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (frame.type === "tick") {
|
|
330
|
+
// Keepalive — `lastFrameAt` already bumped in the message handler;
|
|
331
|
+
// receiving it is enough to keep the tick watchdog satisfied.
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (frame.type === "shutdown") {
|
|
335
|
+
// Graceful shutdown notice — surface it so the consumer can show a
|
|
336
|
+
// "gateway restarting" line instead of a bare disconnect. The socket
|
|
337
|
+
// close that follows still drives the normal reconnect+resume path.
|
|
338
|
+
super.emit("shutdown", frame);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
237
341
|
// type === "req" — server doesn't make requests of clients in v1; ignore.
|
|
238
342
|
}
|
|
239
343
|
/* ─────────────────────────── tick watchdog ─────────────────────────── */
|
package/dist/tui/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/tui/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,SAAS,MAAM,IAAI,CAAC;AAE3B,OAAO,EACN,YAAY,EAIZ,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/tui/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,SAAS,MAAM,IAAI,CAAC;AAE3B,OAAO,EACN,YAAY,EAIZ,OAAO,EAMP,gBAAgB,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAarD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AA2B5D;;;;;;;;;GASG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAY;IACtC,EAAE,CAAwB;IACjB,GAAG,CAAS;IACZ,gBAAgB,CAAS;IAC1C,uEAAuE;IACtD,KAAK,CAAqB;IAE3C,yEAAyE;IACjE,SAAS,GAAG,KAAK,CAAC;IAC1B,mDAAmD;IAC3C,MAAM,GAAG,KAAK,CAAC;IAEvB;;oEAEgE;IACxD,OAAO,GAAG,IAAI,GAAG,EAOtB,CAAC;IACI,MAAM,GAAG,CAAC,CAAC;IAEnB,iFAAiF;IACzE,WAAW,GAAG,CAAC,CAAC;IAChB,cAAc,CAA6B;IAEnD;;;;;;;OAOG;IACK,gBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAErD;oFACgF;IACxE,WAAW,CAAsB;IAEzC,4EAA4E;IACpE,SAAS,GAA0B,YAAY,CAAC;IAExD,uBAAuB;IACf,gBAAgB,GAAG,CAAC,CAAC;IACrB,cAAc,CAA6B;IAEnD,YAAY,OAAsB,EAAE;QACnC,KAAK,EAAE,CAAC;Q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