@linxin666/dsh-remote-bridge 0.4.7 → 0.4.9
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.i18n.yaml +2 -2
- package/README.md +93 -26
- package/README.zh.md +91 -26
- package/icon.svg +3 -0
- package/lib/client.js +274 -253
- package/lib/client.js.map +1 -1
- package/lib/index.js +8891 -2433
- package/lib/types/client/PairEntry.d.ts +2 -2
- package/lib/types/client/PairPanel.d.ts +10 -2
- package/lib/types/client/icons.d.ts +5 -13
- package/lib/types/client/locales.d.ts +10 -14
- package/lib/types/client/semantic.d.ts +9 -5
- package/lib/types/core/approvals.d.ts +24 -0
- package/lib/types/core/commands.d.ts +59 -0
- package/lib/types/core/connection.d.ts +124 -5
- package/lib/types/core/delta.d.ts +101 -0
- package/lib/types/core/devices.d.ts +98 -2
- package/lib/types/core/dsh-frames.d.ts +155 -4
- package/lib/types/core/envelope.d.ts +34 -0
- package/lib/types/core/extension.d.ts +144 -0
- package/lib/types/core/hub.d.ts +96 -20
- package/lib/types/core/jobs.d.ts +204 -0
- package/lib/types/core/liveactivity.d.ts +324 -0
- package/lib/types/core/protocol.d.ts +491 -2
- package/lib/types/core/push.d.ts +178 -0
- package/lib/types/core/questions.d.ts +109 -9
- package/lib/types/core/session-meta.d.ts +55 -1
- package/lib/types/core/squads.d.ts +130 -0
- package/lib/types/core/usage-stats.d.ts +160 -0
- package/lib/types/core/usage.d.ts +294 -0
- package/lib/types/core/wire.d.ts +1 -1
- package/lib/types/core/ws-frames.d.ts +11 -0
- package/lib/types/host/apns.d.ts +151 -0
- package/lib/types/host/squads-ledger.d.ts +39 -0
- package/lib/types/host/squads.d.ts +77 -0
- package/lib/types/host/usage-stats.d.ts +75 -0
- package/lib/types/host/watchers.d.ts +88 -0
- package/lib/types/host/websocket.d.ts +8 -1
- package/lib/types/index.d.ts +34 -3
- package/lib/types/mount-once.d.ts +55 -0
- package/locale/en.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +20 -14
- package/src/client/PairEntry.tsx +58 -31
- package/src/client/PairPanel.tsx +181 -97
- package/src/client/icons.tsx +17 -60
- package/src/client/locales.ts +15 -23
- package/src/client/panel.module.css +239 -186
- package/src/client/semantic.ts +10 -6
- package/src/core/approvals.ts +32 -1
- package/src/core/commands.ts +95 -0
- package/src/core/connection.ts +1483 -31
- package/src/core/delta.ts +204 -0
- package/src/core/devices.ts +221 -3
- package/src/core/dsh-frames.ts +365 -8
- package/src/core/envelope.ts +46 -0
- package/src/core/extension.ts +197 -0
- package/src/core/hub.ts +441 -49
- package/src/core/jobs.ts +372 -0
- package/src/core/liveactivity.ts +833 -0
- package/src/core/protocol.ts +556 -2
- package/src/core/push.ts +354 -0
- package/src/core/questions.ts +264 -17
- package/src/core/session-meta.ts +73 -1
- package/src/core/squads.ts +345 -0
- package/src/core/usage-stats.ts +424 -0
- package/src/core/usage.ts +937 -0
- package/src/core/wire.ts +13 -1
- package/src/core/ws-frames.ts +14 -0
- package/src/host/apns.ts +320 -0
- package/src/host/squads-ledger.ts +105 -0
- package/src/host/squads.ts +206 -0
- package/src/host/usage-stats.ts +155 -0
- package/src/host/watchers.ts +272 -0
- package/src/host/websocket.ts +37 -3
- package/src/index.ts +310 -9
- package/src/mount-once.ts +142 -0
|
@@ -23,6 +23,24 @@ export interface MessageUsage {
|
|
|
23
23
|
readonly cacheWriteTokens?: number;
|
|
24
24
|
readonly reasoningTokens?: number;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Where one user message came from, as the host's durable `source` says.
|
|
28
|
+
*
|
|
29
|
+
* The three kinds are the only classification this protocol makes, and they are
|
|
30
|
+
* read off `source.kind` mechanically: `user` and `user-approval` are a human,
|
|
31
|
+
* `agent-message` and `subagent-settled` are an agent, and every other kind —
|
|
32
|
+
* including one this bridge has never seen — is the system. `sourceKind` is the
|
|
33
|
+
* host's own string, verbatim, so a client can tell "the system" apart without
|
|
34
|
+
* the bridge inventing a taxonomy it cannot keep current.
|
|
35
|
+
*/
|
|
36
|
+
export interface MessageActor {
|
|
37
|
+
readonly kind: 'human' | 'agent' | 'system';
|
|
38
|
+
readonly sourceKind: string;
|
|
39
|
+
/** Durable id of the session that sent the message; only known for an agent. */
|
|
40
|
+
readonly sessionId?: string;
|
|
41
|
+
/** The host's own display label for the source, when it wrote one. */
|
|
42
|
+
readonly label?: string;
|
|
43
|
+
}
|
|
26
44
|
/** One protocol v1 delta, before the session id and event sequence are attached. */
|
|
27
45
|
export type SessionDelta = {
|
|
28
46
|
readonly kind: 'text';
|
|
@@ -50,6 +68,13 @@ export type SessionDelta = {
|
|
|
50
68
|
readonly text: string;
|
|
51
69
|
readonly messageId?: string;
|
|
52
70
|
readonly attachments?: readonly UserMessageAttachment[];
|
|
71
|
+
readonly actor?: MessageActor;
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: 'subagent';
|
|
74
|
+
readonly childId: string;
|
|
75
|
+
readonly label?: string;
|
|
76
|
+
readonly mode?: string;
|
|
77
|
+
readonly callId?: string;
|
|
53
78
|
} | {
|
|
54
79
|
readonly kind: 'usage';
|
|
55
80
|
readonly usage: MessageUsage;
|
|
@@ -62,9 +87,16 @@ export declare const TOOL_CALL_MEMORY = 512;
|
|
|
62
87
|
export declare const USER_MESSAGE_MEMORY = 512;
|
|
63
88
|
/**
|
|
64
89
|
* The durable entry types a protocol v1 client renders — `user/message`,
|
|
65
|
-
* `assistant/message`, `tool/call` and `
|
|
66
|
-
* turn's entries is the harness's own bookkeeping, which
|
|
67
|
-
* count as unknown, so a client that asks for a trimmed
|
|
90
|
+
* `assistant/message`, `tool/call`, `tool/result` and `subagent/catalog`.
|
|
91
|
+
* Everything else in a turn's entries is the harness's own bookkeeping, which
|
|
92
|
+
* the client can only count as unknown, so a client that asks for a trimmed
|
|
93
|
+
* baseline is not sent it.
|
|
94
|
+
*
|
|
95
|
+
* The catalog entry is here because it is the baseline half of the subagent
|
|
96
|
+
* thread: a phone that opens a session after children were spawned has no other
|
|
97
|
+
* way to learn that they exist, their labels, their modes or the call that
|
|
98
|
+
* spawned them. Without it the thread header can only be inferred from agent
|
|
99
|
+
* messages, and every field the catalog carries is lost.
|
|
68
100
|
*/
|
|
69
101
|
export declare const RENDERED_ENTRY_TYPES: ReadonlySet<string>;
|
|
70
102
|
/** One raw durable event inside a snapshot turn. */
|
|
@@ -73,6 +105,8 @@ export interface SnapshotEntry {
|
|
|
73
105
|
readonly time: number;
|
|
74
106
|
readonly type: string;
|
|
75
107
|
readonly data: unknown;
|
|
108
|
+
/** Where a `user/message` came from; absent on every other entry type. */
|
|
109
|
+
readonly actor?: MessageActor;
|
|
76
110
|
}
|
|
77
111
|
/** One turn of a session snapshot: the durable events from `turn/start` to `turn/end`. */
|
|
78
112
|
export interface SnapshotTurn {
|
|
@@ -122,21 +156,117 @@ export declare class MessageIndex {
|
|
|
122
156
|
/** Remember one message, evicting the oldest entry past {@link USER_MESSAGE_MEMORY}. */
|
|
123
157
|
remember(id: string): void;
|
|
124
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* The child sessions one `tool/result` payload names as spawned.
|
|
161
|
+
*
|
|
162
|
+
* A spawn answers with a handle, and the handle is the only place a durable
|
|
163
|
+
* record ties a child id to the call that made it: the catalog event names the
|
|
164
|
+
* child but not the call. Two shapes are written by this harness and both are
|
|
165
|
+
* read here, verbatim from a real session log —
|
|
166
|
+
*
|
|
167
|
+
* - the activation handle the `subagent` tool returns, alone or nested in the
|
|
168
|
+
* object a `run_code` program returns:
|
|
169
|
+
* `{"a":{"kind":"activation","subagentId":"b0a3a569-…"}}`;
|
|
170
|
+
* - the plain notice the same tool prints when it runs without PTC:
|
|
171
|
+
* `started subagent d605390b-66f6-474b-956d-0824ec2103e0`.
|
|
172
|
+
*
|
|
173
|
+
* Nothing else is accepted: a `list_agents` answer that happens to list a child
|
|
174
|
+
* (`[{"kind":"child","id":"…"}]`) carries neither signature, so it can never
|
|
175
|
+
* lend its own call id to a thread it did not spawn.
|
|
176
|
+
* @param data - one durable `tool/result` payload.
|
|
177
|
+
* @returns the child ids the payload names, in the order it names them.
|
|
178
|
+
*/
|
|
179
|
+
export declare function spawnedChildIdsOf(data: unknown): string[];
|
|
180
|
+
/**
|
|
181
|
+
* The child-to-call evidence one session's records already carry.
|
|
182
|
+
*
|
|
183
|
+
* A spawn's result can be projected after the catalog it belongs to, so a
|
|
184
|
+
* baseline reads the whole record list for this evidence before it resolves any
|
|
185
|
+
* catalog entry: the snapshot is a session that has already happened, and the
|
|
186
|
+
* answer it gives a client must not depend on where in the list it stopped
|
|
187
|
+
* looking. The live subscription feeds the same evidence in as it arrives.
|
|
188
|
+
* @param records - durable follow records, oldest first.
|
|
189
|
+
* @returns every child id a `tool/result` names, with the call that produced it.
|
|
190
|
+
*/
|
|
191
|
+
export declare function spawnCallEvidence(records: readonly unknown[]): Map<string, string>;
|
|
192
|
+
/**
|
|
193
|
+
* Correlates one `subagent/catalog` event to the tool call that spawned the
|
|
194
|
+
* child it registers.
|
|
195
|
+
*
|
|
196
|
+
* The catalog event names the child but not the call, so the call is read from
|
|
197
|
+
* two places, in this order:
|
|
198
|
+
*
|
|
199
|
+
* 1. the spawn's own `tool/result`, which names the child it started
|
|
200
|
+
* ({@link spawnedChildIdsOf}). This is the decisive one: it survives a step
|
|
201
|
+
* that issued several calls, and a step whose one call started a whole team
|
|
202
|
+
* of children, because the payload says which child it is about.
|
|
203
|
+
* 2. the nearest preceding `tool/call` of the same turn and step, which is
|
|
204
|
+
* decidable only while one call is the whole story. A step with several
|
|
205
|
+
* calls leaves two candidates, and a call that already produced a child
|
|
206
|
+
* leaves one call behind two children; a guessed id would point a thread at
|
|
207
|
+
* the wrong card.
|
|
208
|
+
*
|
|
209
|
+
* Neither holds: undefined, and the wire carries no call id at all. The same
|
|
210
|
+
* index answers both paths — a subscription as it watches, and a baseline after
|
|
211
|
+
* reading the session's records — so the two can never disagree about which rule
|
|
212
|
+
* decides a given catalog.
|
|
213
|
+
*/
|
|
214
|
+
export declare class SpawnCallIndex {
|
|
215
|
+
#private;
|
|
216
|
+
/**
|
|
217
|
+
* @param evidence - child-to-call pairs already read from the session's
|
|
218
|
+
* results, for the baseline path; empty for a live subscription.
|
|
219
|
+
*/
|
|
220
|
+
constructor(evidence?: ReadonlyMap<string, string>);
|
|
221
|
+
/**
|
|
222
|
+
* Read one durable event into the correlation state.
|
|
223
|
+
*
|
|
224
|
+
* A turn boundary or a new step is the only reset: a call belongs to the step
|
|
225
|
+
* that issued it, so a call from an earlier step can never be the nearest
|
|
226
|
+
* preceding one.
|
|
227
|
+
*/
|
|
228
|
+
observe(type: string, data: unknown): void;
|
|
229
|
+
/**
|
|
230
|
+
* The call that spawned the child a catalog event registered.
|
|
231
|
+
* @param childId - the child that catalog event carries.
|
|
232
|
+
* @returns its call id, or undefined when nothing on the wire decides it.
|
|
233
|
+
*/
|
|
234
|
+
spawnCallId(childId: string): string | undefined;
|
|
235
|
+
}
|
|
125
236
|
/**
|
|
126
237
|
* Read the opening frame of a follow stream.
|
|
127
238
|
* @returns the cursor and records, or undefined when this frame is not a snapshot.
|
|
128
239
|
*/
|
|
129
240
|
export declare function readFollowBaseline(frame: unknown): FollowBaseline | undefined;
|
|
241
|
+
/** What one follow stream remembers beyond its two bounded message indexes. */
|
|
242
|
+
export interface FollowMemory {
|
|
243
|
+
/** Whether this connection declared `subagent.thread.v1`. */
|
|
244
|
+
readonly subagentThread?: boolean;
|
|
245
|
+
/** This stream's spawning-call correlation state; absent when the kind is off. */
|
|
246
|
+
readonly spawnCalls?: SpawnCallIndex;
|
|
247
|
+
}
|
|
130
248
|
/**
|
|
131
249
|
* Map one DSH follow frame to a delta, or undefined when the frame carries no
|
|
132
250
|
* increment this protocol publishes.
|
|
133
251
|
* @param frame - one `SessionFollowFrame`.
|
|
134
252
|
* @param toolCalls - this connection's tool-call memory.
|
|
135
253
|
* @param messages - this connection's published-user-message memory.
|
|
254
|
+
* @param memory - the stream's own correlation state, and which optional kinds it declared.
|
|
255
|
+
*/
|
|
256
|
+
export declare function deltaOfFollowFrame(frame: unknown, toolCalls: ToolCallIndex, messages: MessageIndex, memory?: FollowMemory): SessionDelta | undefined;
|
|
257
|
+
/**
|
|
258
|
+
* Derive one message's actor from the host's own `source` record, mechanically.
|
|
259
|
+
* @param source - the `source` member of a durable `user/message`.
|
|
260
|
+
* @returns the actor, or undefined when the source carries no kind.
|
|
136
261
|
*/
|
|
137
|
-
export declare function
|
|
262
|
+
export declare function actorOfSource(source: unknown): MessageActor | undefined;
|
|
138
263
|
/**
|
|
139
264
|
* Project a follow baseline's records into turns.
|
|
265
|
+
*
|
|
266
|
+
* A `subagent/catalog` entry leaves here carrying the call that spawned its
|
|
267
|
+
* child in `data.callId`, decided by the same {@link SpawnCallIndex} a live
|
|
268
|
+
* subscription uses — so the baseline half and the live half of the thread
|
|
269
|
+
* cannot answer differently about one catalog.
|
|
140
270
|
* @param records - the baseline's durable records, oldest first.
|
|
141
271
|
* @returns one turn per `turn/start`, plus a lead-in turn when records precede the first one.
|
|
142
272
|
*/
|
|
@@ -179,3 +309,24 @@ export interface SnapshotPage {
|
|
|
179
309
|
* @param measure - exact encoded size of one page shape, owned by the caller.
|
|
180
310
|
*/
|
|
181
311
|
export declare function pageTurns(turns: readonly SnapshotTurn[], before: number | undefined, maxBytes: number, measure: (turns: readonly SnapshotTurn[], nextBefore: number | undefined, hasMore: boolean) => number): SnapshotPage;
|
|
312
|
+
/**
|
|
313
|
+
* Durable seq of a projection's oldest entry, or undefined when it carries none.
|
|
314
|
+
*
|
|
315
|
+
* The oldest entry is the first entry of the first turn that has one: a trimmed
|
|
316
|
+
* turn may keep no entry at all, so the scan skips those rather than reading
|
|
317
|
+
* `turns[0].entries[0]` and calling an empty-leading view an empty window.
|
|
318
|
+
* @param turns - the projection to read, in order.
|
|
319
|
+
*/
|
|
320
|
+
export declare function oldestEntrySeq(turns: readonly SnapshotTurn[]): number | undefined;
|
|
321
|
+
/**
|
|
322
|
+
* Cut a projection at a durable watermark, keeping what is strictly above it.
|
|
323
|
+
*
|
|
324
|
+
* This is the forward twin of {@link pageTurns}' own slice: the same
|
|
325
|
+
* entry-level rule (`seq` is a durable watermark, not an index), the same
|
|
326
|
+
* turn rebuild, so an incremental snapshot carries turns shaped exactly like
|
|
327
|
+
* the baseline it continues — a turn whose remaining entries are fewer keeps
|
|
328
|
+
* its own `seq`, `endSeq`, `reason` and `time`.
|
|
329
|
+
* @param turns - the projection to cut, in order.
|
|
330
|
+
* @param watermark - exclusive durable watermark; entries at or below it are dropped.
|
|
331
|
+
*/
|
|
332
|
+
export declare function turnsAbove(turns: readonly SnapshotTurn[], watermark: number): SnapshotTurn[];
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
*/
|
|
22
22
|
/** Largest single text frame either direction may carry, in UTF-8 bytes: 10 MiB. */
|
|
23
23
|
export declare const MAX_FRAME_BYTES: number;
|
|
24
|
+
/**
|
|
25
|
+
* Smallest frame the host compresses, in UTF-8 bytes. Below it the DEFLATE
|
|
26
|
+
* header alone can outweigh a small object, so such a frame is never even tried.
|
|
27
|
+
*/
|
|
28
|
+
export declare const FRAME_DEFLATE_MIN_BYTES = 1024;
|
|
24
29
|
/** Reserved response id for a frame whose own id could not be recovered. */
|
|
25
30
|
export declare const UNIDENTIFIED_FRAME_ID = 0;
|
|
26
31
|
export interface ReqFrame {
|
|
@@ -80,6 +85,35 @@ export declare const DIRECTION_VIOLATION = "direction-violation";
|
|
|
80
85
|
export declare function decodeClientFrame(text: string): DecodeOutcome;
|
|
81
86
|
/** Encode one outgoing frame. */
|
|
82
87
|
export declare function encodeFrame(frame: ServerFrame): string;
|
|
88
|
+
/**
|
|
89
|
+
* How one encoded frame crosses the wire: as the text the codec produced, or as
|
|
90
|
+
* raw DEFLATE of exactly that text.
|
|
91
|
+
*/
|
|
92
|
+
export type OutboundPayload = {
|
|
93
|
+
readonly binary: false;
|
|
94
|
+
readonly text: string;
|
|
95
|
+
} | {
|
|
96
|
+
readonly binary: true;
|
|
97
|
+
readonly deflated: Buffer;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Decide the wire form of one encoded frame.
|
|
101
|
+
*
|
|
102
|
+
* The decision is a byte-level question only, asked after the frame has been
|
|
103
|
+
* measured against {@link MAX_FRAME_BYTES}: the text is deflated exactly as it
|
|
104
|
+
* stands, so a peer that inflates gets back the frame the text path would have
|
|
105
|
+
* written. A frame below {@link FRAME_DEFLATE_MIN_BYTES}, and a frame DEFLATE
|
|
106
|
+
* does not shrink (zlib's default level), both stay text — a binary frame that
|
|
107
|
+
* is larger than the text it replaces would pay for itself in neither direction.
|
|
108
|
+
* @param text - the frame as {@link encodeFrame} produced it.
|
|
109
|
+
* @param compress - whether the peer declared the capability that permits this.
|
|
110
|
+
* @param deflate - the compressor: zlib's raw DEFLATE at its default level, unless
|
|
111
|
+
* a caller injects one. Real deflate shrinks every frame that reaches the
|
|
112
|
+
* threshold, so an injected compressor is the only way to exercise the no-gain
|
|
113
|
+
* rule with content that truly cannot be compressed.
|
|
114
|
+
* @returns the text, or raw DEFLATE of it.
|
|
115
|
+
*/
|
|
116
|
+
export declare function outboundPayloadOf(text: string, compress: boolean, deflate?: (source: Buffer) => Buffer): OutboundPayload;
|
|
83
117
|
/** One successful response frame. */
|
|
84
118
|
export declare function responseFrame(id: number, result: unknown): ResFrame;
|
|
85
119
|
/** One failed response frame. */
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge's extension seam: the one place another plugin adds methods and
|
|
3
|
+
* events to protocol v1 without the bridge learning what they mean.
|
|
4
|
+
*
|
|
5
|
+
* The bridge publishes this seam as the cordis service
|
|
6
|
+
* {@link REMOTE_BRIDGE_SERVICE}. A plugin registers a table of methods plus the
|
|
7
|
+
* capability a client must declare before those methods exist for it, and
|
|
8
|
+
* publishes events to the clients that declared the capability it names.
|
|
9
|
+
* Nothing here carries protocol vocabulary of its own: method names, payloads,
|
|
10
|
+
* topics and refusal codes belong to the registering plugin, which is why this
|
|
11
|
+
* module never appears in `KNOWN_METHODS` and never reads a payload.
|
|
12
|
+
*
|
|
13
|
+
* A connection dispatches an extension method only after the protocol's own
|
|
14
|
+
* gates: an unregistered name, a plugin that is not mounted, and a client that
|
|
15
|
+
* never declared the capability all answer `unknown-method` — the method is
|
|
16
|
+
* absent from that client's protocol, not refused by it.
|
|
17
|
+
* @module dsh-remote-bridge/core/extension
|
|
18
|
+
*/
|
|
19
|
+
import type { RemoteBridgeDeltas } from './delta.ts';
|
|
20
|
+
/** Cordis service this seam is published under. */
|
|
21
|
+
export declare const REMOTE_BRIDGE_SERVICE = "remoteBridge";
|
|
22
|
+
/**
|
|
23
|
+
* Who is calling one extension method.
|
|
24
|
+
*
|
|
25
|
+
* The bridge exposes no device or session identity here on purpose: what an
|
|
26
|
+
* extension keys by connection is its own decision.
|
|
27
|
+
*/
|
|
28
|
+
export interface RemoteBridgeCall {
|
|
29
|
+
/**
|
|
30
|
+
* Stable identity of the calling connection, unique within this bridge
|
|
31
|
+
* process. Two calls from one socket carry the same id; a reconnected socket
|
|
32
|
+
* carries a new one, because nothing proves it is the same peer.
|
|
33
|
+
*/
|
|
34
|
+
readonly connectionId: string;
|
|
35
|
+
/**
|
|
36
|
+
* @param capability - one capability name of this protocol or of the calling
|
|
37
|
+
* extension.
|
|
38
|
+
* @returns whether this connection announced it in `hello`.
|
|
39
|
+
*
|
|
40
|
+
* The seam hands handlers the same predicate the bridge itself gates on, so
|
|
41
|
+
* an extension can gate behind a bridge capability (§15's `delta.v1`) without
|
|
42
|
+
* holding a copy of the client's declaration.
|
|
43
|
+
*/
|
|
44
|
+
declares(capability: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* This connection's delta windows, released with the connection.
|
|
47
|
+
*
|
|
48
|
+
* The mechanism of §15 lives once, in this bridge, and an extension borrows it
|
|
49
|
+
* per connection: the difference is always computed where the last answer is
|
|
50
|
+
* already held, and a dropped connection takes its base with it instead of
|
|
51
|
+
* leaving one to be expired by a second registry.
|
|
52
|
+
*/
|
|
53
|
+
readonly deltas: RemoteBridgeDeltas;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* What one extension method answers: the response body, or a refusal stated in
|
|
57
|
+
* the extension's own code vocabulary. The bridge forwards either verbatim —
|
|
58
|
+
* it holds no table of extension codes and invents none.
|
|
59
|
+
*/
|
|
60
|
+
export type RemoteBridgeMethodResult = {
|
|
61
|
+
readonly ok: true;
|
|
62
|
+
readonly r?: unknown;
|
|
63
|
+
} | {
|
|
64
|
+
readonly ok: false;
|
|
65
|
+
readonly code: string;
|
|
66
|
+
readonly msg: string;
|
|
67
|
+
};
|
|
68
|
+
/** One client-callable method an extension owns. */
|
|
69
|
+
export type RemoteBridgeMethodHandler = (payload: Readonly<Record<string, unknown>>, call: RemoteBridgeCall) => RemoteBridgeMethodResult | Promise<RemoteBridgeMethodResult>;
|
|
70
|
+
/** A table of methods and the capability that admits a client to them. */
|
|
71
|
+
export interface RemoteBridgeMethods {
|
|
72
|
+
/**
|
|
73
|
+
* Capability a client declares in `hello`'s `cap` array before these methods
|
|
74
|
+
* are part of its protocol. Absent means every paired connection may call
|
|
75
|
+
* them; an unpaired connection never may, whatever it declared.
|
|
76
|
+
*/
|
|
77
|
+
readonly capability?: string;
|
|
78
|
+
/** Method name to handler; the name is the extension's, not the bridge's. */
|
|
79
|
+
readonly methods: Readonly<Record<string, RemoteBridgeMethodHandler>>;
|
|
80
|
+
}
|
|
81
|
+
/** The seam, exactly as published on {@link REMOTE_BRIDGE_SERVICE}. */
|
|
82
|
+
export interface RemoteBridgeFace {
|
|
83
|
+
/**
|
|
84
|
+
* Add methods to the protocol surface.
|
|
85
|
+
* @returns the disposer withdrawing them; afterwards they answer `unknown-method` again.
|
|
86
|
+
*/
|
|
87
|
+
registerMethods(table: RemoteBridgeMethods): () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Publish one event to the connections that are paired — and, when a
|
|
90
|
+
* capability is named, have declared it.
|
|
91
|
+
* @returns how many connections took the frame.
|
|
92
|
+
*/
|
|
93
|
+
broadcast(topic: string, payload: unknown, capability?: string): number;
|
|
94
|
+
}
|
|
95
|
+
/** The fan-out the seam publishes through; `BridgeHub` satisfies it. */
|
|
96
|
+
export interface RemoteBridgeFanout {
|
|
97
|
+
broadcast(topic: string, payload: unknown): number;
|
|
98
|
+
broadcastTo(capability: string, topic: string, payload: unknown): number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The methods extensions registered, and the capability each one needs.
|
|
102
|
+
*
|
|
103
|
+
* Every connection consults this registry; nothing else holds extension state,
|
|
104
|
+
* so unmounting one plugin withdraws exactly its own methods.
|
|
105
|
+
*/
|
|
106
|
+
export declare class RemoteBridgeRegistry {
|
|
107
|
+
#private;
|
|
108
|
+
/**
|
|
109
|
+
* Register one table of methods, all or nothing: a table naming a protocol
|
|
110
|
+
* method, an empty name or a name already taken is refused before any of its
|
|
111
|
+
* methods becomes callable.
|
|
112
|
+
* @param table - the methods and the capability they require.
|
|
113
|
+
* @returns the disposer withdrawing this table; idempotent.
|
|
114
|
+
*/
|
|
115
|
+
registerMethods(table: RemoteBridgeMethods): () => void;
|
|
116
|
+
/**
|
|
117
|
+
* @param method - the method name a client asked for.
|
|
118
|
+
* @returns whether any plugin registered it, whatever capability it requires.
|
|
119
|
+
*/
|
|
120
|
+
has(method: string): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* @param method - the method name a client asked for.
|
|
123
|
+
* @param declares - whether the calling connection declared a capability.
|
|
124
|
+
* @returns the handler when the caller may use the method, else undefined.
|
|
125
|
+
*/
|
|
126
|
+
handlerFor(method: string, declares: (capability: string) => boolean): RemoteBridgeMethodHandler | undefined;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Compose the published seam over a registry and a fan-out.
|
|
130
|
+
* @param methods - the registry this bridge owns.
|
|
131
|
+
* @param fanout - the hub's broadcast pair.
|
|
132
|
+
* @returns the face a plugin resolves from {@link REMOTE_BRIDGE_SERVICE}.
|
|
133
|
+
*/
|
|
134
|
+
export declare function createRemoteBridgeFace(methods: RemoteBridgeRegistry, fanout: RemoteBridgeFanout): RemoteBridgeFace;
|
|
135
|
+
declare module '@deepseek-ai/cordis' {
|
|
136
|
+
interface Context {
|
|
137
|
+
/**
|
|
138
|
+
* The bridge's extension seam, while this package serves protocol v1. A
|
|
139
|
+
* plugin resolves it structurally at use time: requiring it would let the
|
|
140
|
+
* bridge's absence take the registering plugin's start down with it.
|
|
141
|
+
*/
|
|
142
|
+
remoteBridge: RemoteBridgeFace;
|
|
143
|
+
}
|
|
144
|
+
}
|
package/lib/types/core/hub.d.ts
CHANGED
|
@@ -2,18 +2,27 @@
|
|
|
2
2
|
* The bridge's process-wide connection registry and its claims on
|
|
3
3
|
* `approval/request` and `user-questions/request`.
|
|
4
4
|
*
|
|
5
|
-
* The hub is what makes "phone not answering equals refusal" true:
|
|
6
|
-
* is claimed only while at least one paired device is connected, the publish
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* The hub is what makes "phone not answering equals refusal" true: an approval
|
|
6
|
+
* is claimed only while at least one paired device is connected, the publish has
|
|
7
|
+
* to actually reach someone, and every other path (timeout, agent cancellation,
|
|
8
|
+
* the last phone leaving) delegates to the next answerer, which the Host
|
|
9
|
+
* normalizes to `'unavailable'`.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* A user question adds the one case where "reach someone" is the notification
|
|
12
|
+
* rather than the socket: with no paired connection on the wire but a device on
|
|
13
|
+
* the roster that registered for pushes, the question is claimed for that phone
|
|
14
|
+
* and the alert is its delivery (§11.3, §32). One predicate decides it — "can a
|
|
15
|
+
* device that is reachable right now receive a question card" — and it is asked
|
|
16
|
+
* again every time a connection finishes its hello, because a client that never
|
|
17
|
+
* declares `questions.v1` going online turns that answer into no.
|
|
18
|
+
*
|
|
19
|
+
* The claim on `user-questions/request` follows the same rules, with three
|
|
12
20
|
* differences that belong to the host's own semantics: delegating is not a
|
|
13
21
|
* refusal, because only a phone that declares `questions.v1` is ever shown the
|
|
14
|
-
* question;
|
|
22
|
+
* question; a question is named on the wire even when the host named none,
|
|
15
23
|
* because a blocking ask carries no call id and the phone still needs a handle
|
|
16
|
-
* to answer with
|
|
24
|
+
* to answer with; and the claim outlives the last paired device by a grace
|
|
25
|
+
* window, because a phone whose app the system suspended has refused nothing.
|
|
17
26
|
* @module dsh-remote-bridge/core/hub
|
|
18
27
|
*/
|
|
19
28
|
import type { ApprovalOutcome } from '@deepseek-ai/dsh-user-approval';
|
|
@@ -39,10 +48,55 @@ export interface ApprovalRequestLike {
|
|
|
39
48
|
}
|
|
40
49
|
/** The summary line a phone shows for one question. */
|
|
41
50
|
export declare function approvalSummary(request: ApprovalRequestLike): string;
|
|
51
|
+
/** The `approval.request` payload one claim is published with. */
|
|
52
|
+
export interface ApprovalRequestPayload {
|
|
53
|
+
readonly sessionId: string;
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly summary: string;
|
|
56
|
+
readonly toolName: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* How long a user question outlives the last paired device, in milliseconds.
|
|
60
|
+
*
|
|
61
|
+
* A push notification carries a session link and nothing else: the phone can
|
|
62
|
+
* draw a question card only while this bridge still holds the claim, and it has
|
|
63
|
+
* to reconnect before it can read one. A phone whose app was suspended is gone
|
|
64
|
+
* for tens of seconds, so releasing the claim the instant its socket drops
|
|
65
|
+
* decides the question for it — the ask went back to the host's own answerer
|
|
66
|
+
* chain, the Mac showed the card, and the tap that arrived afterwards opened a
|
|
67
|
+
* session with nothing in it (measured 2026-10-23). The window is that reconnect
|
|
68
|
+
* budget, not a second deadline: a claim no phone came back for is released on
|
|
69
|
+
* expiry exactly as it was before.
|
|
70
|
+
*/
|
|
71
|
+
export declare const QUESTION_CLAIM_GRACE_MS = 60000;
|
|
72
|
+
/**
|
|
73
|
+
* How long a user question is held for a phone this bridge reached by
|
|
74
|
+
* notification only, in milliseconds (§32.2).
|
|
75
|
+
*
|
|
76
|
+
* Inside this window the question exists only on the phone's side: the alert is
|
|
77
|
+
* out, no socket has it, and the host's own answerer chain has not been started.
|
|
78
|
+
* When it runs out the claim is withdrawn and delegated, so the agent behind a
|
|
79
|
+
* timed ask waits at most this long past its own deadline and the agent behind a
|
|
80
|
+
* blocking ask (no call id, no deadline) waits at most this long in total — an
|
|
81
|
+
* accepted cost, because the alternative is a question that vanished while the
|
|
82
|
+
* phone was asleep. The window is the bridge's own constant and not the host's:
|
|
83
|
+
* a deployment overrides it, the host never sees it.
|
|
84
|
+
*/
|
|
85
|
+
export declare const OFFLINE_QUESTION_CLAIM_TTL_MS = 600000;
|
|
86
|
+
/** What the hub is built with: the bridge's shared options plus the windows it owns. */
|
|
87
|
+
export interface BridgeHubOptions extends BridgeConnectionOptions {
|
|
88
|
+
/**
|
|
89
|
+
* The offline claim window, in milliseconds.
|
|
90
|
+
*
|
|
91
|
+
* Defaults to {@link OFFLINE_QUESTION_CLAIM_TTL_MS}; a deployment knob, and the
|
|
92
|
+
* seam a suite uses to move the window instead of waiting it out.
|
|
93
|
+
*/
|
|
94
|
+
readonly offlineClaimTtlMs?: number;
|
|
95
|
+
}
|
|
42
96
|
/** The bridge's live connections plus the answerer it composes onto the approval chain. */
|
|
43
97
|
export declare class BridgeHub {
|
|
44
98
|
#private;
|
|
45
|
-
constructor(options:
|
|
99
|
+
constructor(options: BridgeHubOptions);
|
|
46
100
|
/** @returns how many paired devices could answer a question right now. */
|
|
47
101
|
get pairedClients(): number;
|
|
48
102
|
/**
|
|
@@ -53,7 +107,8 @@ export declare class BridgeHub {
|
|
|
53
107
|
attach(transport: BridgeTransport, auth?: ConnectionAuth): BridgeConnection;
|
|
54
108
|
/**
|
|
55
109
|
* Forget one connection and abort everything it owns. When it was the last
|
|
56
|
-
* paired device, every pending
|
|
110
|
+
* paired device, every pending approval is withdrawn at once and every pending
|
|
111
|
+
* user question is released when its grace window ends.
|
|
57
112
|
*/
|
|
58
113
|
detach(connection: BridgeConnection): void;
|
|
59
114
|
/**
|
|
@@ -61,10 +116,6 @@ export declare class BridgeHub {
|
|
|
61
116
|
* @returns how many connections actually took the frame.
|
|
62
117
|
*/
|
|
63
118
|
broadcast(topic: string, payload: unknown): number;
|
|
64
|
-
/**
|
|
65
|
-
* Publish one event to every paired device that announced a capability.
|
|
66
|
-
* @returns how many connections actually took the frame.
|
|
67
|
-
*/
|
|
68
119
|
/**
|
|
69
120
|
* Hand one freshly declared connection the questions it can now answer.
|
|
70
121
|
*
|
|
@@ -73,6 +124,27 @@ export declare class BridgeHub {
|
|
|
73
124
|
* to clients that had already announced the channel.
|
|
74
125
|
*/
|
|
75
126
|
replayQuestions(connection: BridgeConnection): void;
|
|
127
|
+
/**
|
|
128
|
+
* Hand one freshly declared connection the approvals it can now answer.
|
|
129
|
+
*
|
|
130
|
+
* The same shape as {@link replayQuestions} and for the same reason: the first
|
|
131
|
+
* `approval.request` of a question was broadcast to the phones that were
|
|
132
|
+
* connected at that instant, so a phone that reconnected — or a session screen
|
|
133
|
+
* opened after the fact — holds no card and has no other way to learn the
|
|
134
|
+
* question exists. Only unsettled questions are in the registry, so one that
|
|
135
|
+
* was answered, one the bridge timed out and one withdrawn with the last phone
|
|
136
|
+
* cannot be replayed.
|
|
137
|
+
*
|
|
138
|
+
* The replay emits a frame and nothing else: the claim keeps the deadline it
|
|
139
|
+
* was opened with, so re-handing a question never lengthens how long the agent
|
|
140
|
+
* waits for it.
|
|
141
|
+
* @param connection - the connection that just declared its capabilities.
|
|
142
|
+
*/
|
|
143
|
+
replayApprovals(connection: BridgeConnection): void;
|
|
144
|
+
/**
|
|
145
|
+
* Publish one event to every paired device that announced a capability.
|
|
146
|
+
* @returns how many connections actually took the frame.
|
|
147
|
+
*/
|
|
76
148
|
broadcastTo(capability: string, topic: string, payload: unknown): number;
|
|
77
149
|
/**
|
|
78
150
|
* The body of this plugin's `approval/request` listener.
|
|
@@ -84,13 +156,17 @@ export declare class BridgeHub {
|
|
|
84
156
|
/**
|
|
85
157
|
* The body of this plugin's `user-questions/request` listener.
|
|
86
158
|
*
|
|
87
|
-
* Claimed only while a
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
159
|
+
* Claimed only while a device that is reachable right now can be shown the
|
|
160
|
+
* card: a paired connection that declared `questions.v1`, or — with no phone on
|
|
161
|
+
* the wire — a roster device that registered for notifications, which the alert
|
|
162
|
+
* reaches instead of a frame (§11.3, §32). The payload has no session field of
|
|
163
|
+
* its own, so an ask that names no agent is delegated either. The wire id is the
|
|
164
|
+
* host's own when the ask is timed, and minted here when it is blocking and the
|
|
165
|
+
* host assigned none — either way the phone answers the id it was shown. A claim
|
|
92
166
|
* nobody received is withdrawn at once instead of holding the agent until the
|
|
93
|
-
* host's deadline.
|
|
167
|
+
* host's deadline. For a timed ask the host's own remaining wait travels with
|
|
168
|
+
* the first frame as `expiresAt`, and every later move of that deadline is
|
|
169
|
+
* re-published under the same call id.
|
|
94
170
|
* @param request - the pending question batch.
|
|
95
171
|
* @param next - the rest of the answerer chain.
|
|
96
172
|
* @returns the phone's answer, the host's own deadline outcome, or whatever the next answerer says.
|