@linxin666/dsh-remote-bridge 0.4.7 → 0.4.8
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 +48 -14
- package/README.zh.md +46 -14
- package/icon.svg +3 -0
- package/lib/client.js.map +1 -1
- package/lib/index.js +2388 -343
- package/lib/types/core/approvals.d.ts +24 -0
- package/lib/types/core/connection.d.ts +59 -8
- package/lib/types/core/delta.d.ts +101 -0
- 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 +31 -5
- package/lib/types/core/jobs.d.ts +204 -0
- package/lib/types/core/protocol.d.ts +232 -2
- package/lib/types/core/questions.d.ts +48 -0
- package/lib/types/core/wire.d.ts +1 -1
- package/lib/types/core/ws-frames.d.ts +11 -0
- package/lib/types/host/websocket.d.ts +8 -1
- package/lib/types/index.d.ts +16 -1
- 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 +8 -2
- package/src/core/approvals.ts +32 -1
- package/src/core/connection.ts +837 -21
- package/src/core/delta.ts +204 -0
- 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 +91 -19
- package/src/core/jobs.ts +372 -0
- package/src/core/protocol.ts +263 -2
- package/src/core/questions.ts +186 -10
- package/src/core/wire.ts +5 -1
- package/src/core/ws-frames.ts +14 -0
- package/src/host/websocket.ts +37 -3
- package/src/index.ts +53 -1
- package/src/mount-once.ts +142 -0
package/lib/types/core/hub.d.ts
CHANGED
|
@@ -39,6 +39,13 @@ export interface ApprovalRequestLike {
|
|
|
39
39
|
}
|
|
40
40
|
/** The summary line a phone shows for one question. */
|
|
41
41
|
export declare function approvalSummary(request: ApprovalRequestLike): string;
|
|
42
|
+
/** The `approval.request` payload one claim is published with. */
|
|
43
|
+
export interface ApprovalRequestPayload {
|
|
44
|
+
readonly sessionId: string;
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly summary: string;
|
|
47
|
+
readonly toolName: string;
|
|
48
|
+
}
|
|
42
49
|
/** The bridge's live connections plus the answerer it composes onto the approval chain. */
|
|
43
50
|
export declare class BridgeHub {
|
|
44
51
|
#private;
|
|
@@ -61,10 +68,6 @@ export declare class BridgeHub {
|
|
|
61
68
|
* @returns how many connections actually took the frame.
|
|
62
69
|
*/
|
|
63
70
|
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
71
|
/**
|
|
69
72
|
* Hand one freshly declared connection the questions it can now answer.
|
|
70
73
|
*
|
|
@@ -73,6 +76,27 @@ export declare class BridgeHub {
|
|
|
73
76
|
* to clients that had already announced the channel.
|
|
74
77
|
*/
|
|
75
78
|
replayQuestions(connection: BridgeConnection): void;
|
|
79
|
+
/**
|
|
80
|
+
* Hand one freshly declared connection the approvals it can now answer.
|
|
81
|
+
*
|
|
82
|
+
* The same shape as {@link replayQuestions} and for the same reason: the first
|
|
83
|
+
* `approval.request` of a question was broadcast to the phones that were
|
|
84
|
+
* connected at that instant, so a phone that reconnected — or a session screen
|
|
85
|
+
* opened after the fact — holds no card and has no other way to learn the
|
|
86
|
+
* question exists. Only unsettled questions are in the registry, so one that
|
|
87
|
+
* was answered, one the bridge timed out and one withdrawn with the last phone
|
|
88
|
+
* cannot be replayed.
|
|
89
|
+
*
|
|
90
|
+
* The replay emits a frame and nothing else: the claim keeps the deadline it
|
|
91
|
+
* was opened with, so re-handing a question never lengthens how long the agent
|
|
92
|
+
* waits for it.
|
|
93
|
+
* @param connection - the connection that just declared its capabilities.
|
|
94
|
+
*/
|
|
95
|
+
replayApprovals(connection: BridgeConnection): void;
|
|
96
|
+
/**
|
|
97
|
+
* Publish one event to every paired device that announced a capability.
|
|
98
|
+
* @returns how many connections actually took the frame.
|
|
99
|
+
*/
|
|
76
100
|
broadcastTo(capability: string, topic: string, payload: unknown): number;
|
|
77
101
|
/**
|
|
78
102
|
* The body of this plugin's `approval/request` listener.
|
|
@@ -90,7 +114,9 @@ export declare class BridgeHub {
|
|
|
90
114
|
* when the ask is timed, and minted here when it is blocking and the host
|
|
91
115
|
* assigned none — either way the phone answers the id it was shown. A claim
|
|
92
116
|
* nobody received is withdrawn at once instead of holding the agent until the
|
|
93
|
-
* host's deadline.
|
|
117
|
+
* host's deadline. For a timed ask the host's own remaining wait travels with
|
|
118
|
+
* the first frame as `expiresAt`, and every later move of that deadline is
|
|
119
|
+
* re-published under the same call id.
|
|
94
120
|
* @param request - the pending question batch.
|
|
95
121
|
* @param next - the rest of the answerer chain.
|
|
96
122
|
* @returns the phone's answer, the host's own deadline outcome, or whatever the next answerer says.
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge's read-only window on the host's background jobs: one minimal
|
|
3
|
+
* projection per job, and the change notification a phone's navigation bar
|
|
4
|
+
* needs to keep a count honest.
|
|
5
|
+
*
|
|
6
|
+
* There is exactly one source of truth here and it is the host's own job
|
|
7
|
+
* registry (`ctx.jobs`, the service the `dsh-api-job-controller` Remote
|
|
8
|
+
* namespace is itself a projection of). This module adds no second store, no
|
|
9
|
+
* polling loop and no invented status vocabulary: it reads `list()`, publishes
|
|
10
|
+
* the host's own `kind` and `status` strings verbatim, and hears changes from
|
|
11
|
+
* the registry's own event stream.
|
|
12
|
+
*
|
|
13
|
+
* Two shapes of the host's API matter to what a phone can be shown:
|
|
14
|
+
*
|
|
15
|
+
* - `list(caller)` is owner-fenced. Naming a session returns that session's own
|
|
16
|
+
* jobs plus every job no session owns; naming no session returns only the
|
|
17
|
+
* unowned jobs. Those are TWO truthful scopes, not one global view, and the
|
|
18
|
+
* host has no global view to offer: a job list is never "every job in the
|
|
19
|
+
* process" unless every job in the process happens to be unowned.
|
|
20
|
+
* - The event stream reports `output` appends as well as lifecycle commits. An
|
|
21
|
+
* append says nothing about the SET, so it is dropped here: this channel
|
|
22
|
+
* never publishes per output byte, which is the whole reason the roster is
|
|
23
|
+
* not a projection of `job/follow`.
|
|
24
|
+
*
|
|
25
|
+
* The types below mirror `@deepseek-ai/dsh-jobs` field for field. That package
|
|
26
|
+
* is the host's, not this one's, so the contract is declared structurally
|
|
27
|
+
* instead of imported — the same rule `questions.ts` and `wire.ts` follow, and
|
|
28
|
+
* what keeps a test double down to the two members actually called.
|
|
29
|
+
* @module dsh-remote-bridge/core/jobs
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* The slice of the host's `JobView` this bridge reads.
|
|
33
|
+
*
|
|
34
|
+
* Deliberately not the whole view: `output` (the ring's offsets and spill
|
|
35
|
+
* paths), `progress`, `detail` and `outputLimitBytes` are host bookkeeping a
|
|
36
|
+
* phone neither shows nor needs, and a projection that read them would tempt a
|
|
37
|
+
* later change into publishing bytes.
|
|
38
|
+
*/
|
|
39
|
+
export interface JobViewLike {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly kind: string;
|
|
42
|
+
readonly label: string;
|
|
43
|
+
/** Owning session; absent for an unowned job, which every caller can see. */
|
|
44
|
+
readonly owner?: string;
|
|
45
|
+
readonly status: string;
|
|
46
|
+
/** Epoch milliseconds. */
|
|
47
|
+
readonly startedAt: number;
|
|
48
|
+
/** Epoch milliseconds; absent while the job is live. */
|
|
49
|
+
readonly finishedAt?: number;
|
|
50
|
+
}
|
|
51
|
+
/** One lifecycle event of the host's event stream, as far as this bridge reads it. */
|
|
52
|
+
export interface JobEventLike {
|
|
53
|
+
/** `output` is the one type this bridge drops without reading further. */
|
|
54
|
+
readonly type: string;
|
|
55
|
+
/** The job's projection after the commit; absent on an `output` append. */
|
|
56
|
+
readonly job?: JobViewLike;
|
|
57
|
+
/** Owning session, carried by `output` events, which carry no projection. */
|
|
58
|
+
readonly owner?: string;
|
|
59
|
+
}
|
|
60
|
+
/** Who a subscription hears about. `all` is what a bridge serving every session asks for. */
|
|
61
|
+
export type JobEventFilterLike = {
|
|
62
|
+
readonly owners: 'all' | 'scope';
|
|
63
|
+
} | {
|
|
64
|
+
readonly owner: string;
|
|
65
|
+
};
|
|
66
|
+
/** The host registry's event stream. */
|
|
67
|
+
export interface JobEventsFace {
|
|
68
|
+
subscribe(filter: JobEventFilterLike, listener: (event: JobEventLike) => void): () => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The slice of `ctx.jobs` this package reads.
|
|
72
|
+
*
|
|
73
|
+
* Optional in the plugin's faces for the reason the metadata faces are: the
|
|
74
|
+
* registry is not in this plugin's `inject` list, and a host that composes no
|
|
75
|
+
* job plugin answers `jobs-unavailable` instead of failing to start.
|
|
76
|
+
*/
|
|
77
|
+
export interface JobRegistryFace {
|
|
78
|
+
list(caller?: string): readonly JobViewLike[];
|
|
79
|
+
readonly events: JobEventsFace;
|
|
80
|
+
}
|
|
81
|
+
/** Which truthful scope one roster answer covers. */
|
|
82
|
+
export type JobScope = 'session' | 'unowned';
|
|
83
|
+
/**
|
|
84
|
+
* One job in protocol v1 vocabulary: the minimal, stable view.
|
|
85
|
+
*
|
|
86
|
+
* `kind` and `status` are the host's own strings, verbatim — this protocol
|
|
87
|
+
* publishes no enum of its own, so a producer kind or a lifecycle status added
|
|
88
|
+
* in the host crosses unchanged instead of being flattened into a guess.
|
|
89
|
+
* Every optional key is omitted when the host omitted it, never filled in.
|
|
90
|
+
*/
|
|
91
|
+
export interface JobRow {
|
|
92
|
+
readonly id: string;
|
|
93
|
+
readonly kind: string;
|
|
94
|
+
readonly status: string;
|
|
95
|
+
/** The host's `label`: its own one-line description, the field a phone renders as the job's title. */
|
|
96
|
+
readonly label?: string;
|
|
97
|
+
/** The host's `owner`, verbatim, under a name that cannot be read as an object. */
|
|
98
|
+
readonly ownerSessionId?: string;
|
|
99
|
+
readonly startedAt?: number;
|
|
100
|
+
readonly finishedAt?: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The body of one `jobs.list` answer and of one `jobs.changed` event.
|
|
104
|
+
*
|
|
105
|
+
* One box for both, so a client parses its navigation-bar count out of the same
|
|
106
|
+
* shape it refreshes through, and so a client holding two scopes open can tell
|
|
107
|
+
* whose set moved. `sessionId` is present exactly when the scope is `session`.
|
|
108
|
+
*/
|
|
109
|
+
export interface JobsPayload {
|
|
110
|
+
readonly sessionId?: string;
|
|
111
|
+
readonly scope: JobScope;
|
|
112
|
+
readonly jobs: readonly JobRow[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Coalescing window of one roster publish, in milliseconds.
|
|
116
|
+
*
|
|
117
|
+
* The host registry announces every commit synchronously, so a job that
|
|
118
|
+
* registers, reports progress and settles in one turn is three events for one
|
|
119
|
+
* fact a phone renders as one row. This window folds a burst into a single
|
|
120
|
+
* whole-set read, which is why the topic can never turn into a stream of
|
|
121
|
+
* frames. It matches the job controller's own `observeFlushMs` default, so a
|
|
122
|
+
* browser and a phone watching the same set refresh at the same cadence.
|
|
123
|
+
*/
|
|
124
|
+
export declare const JOBS_FLUSH_MS = 100;
|
|
125
|
+
/** Largest number of job rows one payload carries before it risks the frame budget. */
|
|
126
|
+
export declare const JOBS_MAX_ROWS = 200;
|
|
127
|
+
/**
|
|
128
|
+
* Project one host job into the protocol's own fields.
|
|
129
|
+
*
|
|
130
|
+
* Explicitly field by field: an unknown key the host adds later must not reach
|
|
131
|
+
* the wire, and a value of the wrong type is dropped rather than coerced — the
|
|
132
|
+
* key is simply absent, which a client already has to handle.
|
|
133
|
+
* @param job - the host's projection.
|
|
134
|
+
* @returns the minimal row, or undefined when the host gave no usable id.
|
|
135
|
+
*/
|
|
136
|
+
export declare function projectJob(job: JobViewLike): JobRow | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Project a whole host roster.
|
|
139
|
+
* @param jobs - the host's projections.
|
|
140
|
+
* @returns the rows, in the host's own order, bounded by {@link JOBS_MAX_ROWS}.
|
|
141
|
+
*/
|
|
142
|
+
export declare function projectJobs(jobs: readonly JobViewLike[]): readonly JobRow[];
|
|
143
|
+
/** The key one scope is subscribed and deduplicated under. */
|
|
144
|
+
export declare function scopeKey(sessionId?: string): string;
|
|
145
|
+
/**
|
|
146
|
+
* Whether one job belongs in one scope's visible set.
|
|
147
|
+
*
|
|
148
|
+
* This is the host's own fence, restated for routing events: a session sees its
|
|
149
|
+
* own jobs plus every unowned one, and the unowned scope sees exactly the jobs
|
|
150
|
+
* no session owns.
|
|
151
|
+
* @param owner - the job's owning session, when it has one.
|
|
152
|
+
* @param sessionId - the scope's session; omitted for the unowned scope.
|
|
153
|
+
*/
|
|
154
|
+
export declare function inScope(owner: string | undefined, sessionId?: string): boolean;
|
|
155
|
+
/** Everything one mount's roster was built with. */
|
|
156
|
+
export interface JobRosterOptions {
|
|
157
|
+
/** Resolves the host registry now; called per read, never captured once, so a registry that mounts later is still picked up. */
|
|
158
|
+
readonly faces: () => {
|
|
159
|
+
readonly jobs?: JobRegistryFace | undefined;
|
|
160
|
+
};
|
|
161
|
+
readonly log: (message: string) => void;
|
|
162
|
+
/** Coalescing window; the default is {@link JOBS_FLUSH_MS}. */
|
|
163
|
+
readonly flushMs?: number;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The bridge's background-job reads and change notifications.
|
|
167
|
+
*
|
|
168
|
+
* One instance is built per host mount and shared by every connection, because
|
|
169
|
+
* a job is a fact about the host, not about the device that asked. Scopes are
|
|
170
|
+
* reference-counted by their listeners: a scope nobody watches holds no timer,
|
|
171
|
+
* and the registry subscription itself exists only while at least one scope
|
|
172
|
+
* does. That is what makes "a connection that never asked receives nothing"
|
|
173
|
+
* structural rather than a filter someone has to remember to apply.
|
|
174
|
+
*/
|
|
175
|
+
export declare class JobRoster {
|
|
176
|
+
#private;
|
|
177
|
+
constructor(options: JobRosterOptions);
|
|
178
|
+
/** @returns whether this host composes a job registry at all. */
|
|
179
|
+
get available(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Read one scope's visible set.
|
|
182
|
+
*
|
|
183
|
+
* Synchronous, because the host registry projects in memory: no stream is
|
|
184
|
+
* opened and no socket is waited on, which is what makes this cheap enough to
|
|
185
|
+
* answer on request and again after every coalesced burst.
|
|
186
|
+
* @param sessionId - the scope's session; omitted for the unowned scope.
|
|
187
|
+
* @returns the payload, or undefined when this host has no job registry.
|
|
188
|
+
*/
|
|
189
|
+
read(sessionId?: string): JobsPayload | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Watch one scope, and publish each coalesced change to every watcher of it.
|
|
192
|
+
*
|
|
193
|
+
* Watching is what a `jobs.list` call earns: a scope nobody listed is never
|
|
194
|
+
* read again, so a phone that declared the capability and asked for nothing
|
|
195
|
+
* receives no `jobs.changed` — the requirement that keeps N open sessions
|
|
196
|
+
* from becoming N sets streaming at a phone that asked for none.
|
|
197
|
+
* @param sessionId - the scope's session; omitted for the unowned scope.
|
|
198
|
+
* @param listener - receives one whole-set payload per coalesced change.
|
|
199
|
+
* @returns the disposer, or undefined when this host has no job registry.
|
|
200
|
+
*/
|
|
201
|
+
watch(sessionId: string | undefined, listener: (payload: JobsPayload) => void): (() => void) | undefined;
|
|
202
|
+
/** Stop every watch and clear every timer. Idempotent. */
|
|
203
|
+
dispose(): void;
|
|
204
|
+
}
|
|
@@ -9,6 +9,7 @@ export declare const METHOD_SESSION_LIST = "session.list";
|
|
|
9
9
|
export declare const METHOD_SESSION_TITLES = "session.titles";
|
|
10
10
|
export declare const METHOD_SESSION_SNAPSHOT = "session.snapshot";
|
|
11
11
|
export declare const METHOD_SESSION_HISTORY = "session.history";
|
|
12
|
+
export declare const METHOD_SESSION_HISTORY_DEEP = "session.history.deep";
|
|
12
13
|
export declare const METHOD_SESSION_PROMPT = "session.prompt";
|
|
13
14
|
export declare const METHOD_SESSION_INTERRUPT = "session.interrupt";
|
|
14
15
|
export declare const METHOD_SESSION_ATTACHMENT = "session.attachment";
|
|
@@ -16,14 +17,19 @@ export declare const METHOD_SESSION_PERMISSIONS = "session.permissions";
|
|
|
16
17
|
export declare const METHOD_SESSION_SET_PERMISSION = "session.setPermission";
|
|
17
18
|
export declare const METHOD_SESSION_MODELS = "session.models";
|
|
18
19
|
export declare const METHOD_SESSION_SET_MODEL = "session.setModel";
|
|
20
|
+
export declare const METHOD_SESSION_CREATE = "session.create";
|
|
21
|
+
export declare const METHOD_SESSION_FORK = "session.fork";
|
|
22
|
+
export declare const METHOD_PRESETS_LIST = "presets.list";
|
|
19
23
|
export declare const METHOD_PAIR_BEGIN = "pair.begin";
|
|
20
24
|
export declare const METHOD_PAIR_FINISH = "pair.finish";
|
|
21
25
|
export declare const METHOD_APPROVAL_RESOLVE = "approval.resolve";
|
|
22
26
|
export declare const METHOD_QUESTION_ANSWER = "question.answer";
|
|
27
|
+
export declare const METHOD_JOBS_LIST = "jobs.list";
|
|
23
28
|
/** Server-pushed topics of protocol v1. */
|
|
24
29
|
export declare const TOPIC_SESSION_DELTA = "session.delta";
|
|
25
30
|
export declare const TOPIC_APPROVAL_REQUEST = "approval.request";
|
|
26
31
|
export declare const TOPIC_QUESTION_REQUEST = "question.request";
|
|
32
|
+
export declare const TOPIC_JOBS_CHANGED = "jobs.changed";
|
|
27
33
|
/**
|
|
28
34
|
* Capability a client declares in `hello`'s `cap` array to ask for a trimmed
|
|
29
35
|
* `session.snapshot` baseline. A client that does not declare it — including
|
|
@@ -40,6 +46,25 @@ export declare const CAP_SESSION_SNAPSHOT_TRIM = "session.snapshot.trim.v1";
|
|
|
40
46
|
* snapshot protocol v1 always served.
|
|
41
47
|
*/
|
|
42
48
|
export declare const CAP_SESSION_SNAPSHOT_PAGE = "session.snapshot.page.v1";
|
|
49
|
+
/**
|
|
50
|
+
* Capability a client declares in `hello`'s `cap` array to have
|
|
51
|
+
* `session.snapshot` answer a reconnect with only what it missed.
|
|
52
|
+
*
|
|
53
|
+
* The declaration and the request's `sinceSeq` are what it takes together: a
|
|
54
|
+
* snapshot that carries no `sinceSeq` is answered, byte for byte, the body
|
|
55
|
+
* protocol v1 always served, whether or not the client declared this. Behind
|
|
56
|
+
* both, the client names the durable `lastSeq` of a snapshot it already holds
|
|
57
|
+
* and the answer is either that same reply in an incremental form —
|
|
58
|
+
* `{turns, lastSeq, mode:"since", reset:false}` carrying only the entries above
|
|
59
|
+
* that watermark — or a full baseline with `mode:"full"` and `reset:true`,
|
|
60
|
+
* which is the one answer that tells a client to throw its copy away. The
|
|
61
|
+
* estimate is only served when the bridge can PROVE nothing was lost: the
|
|
62
|
+
* current follow window's oldest entry must sit at or below `sinceSeq + 1`, so a
|
|
63
|
+
* window that has already scrolled past the watermark answers the baseline
|
|
64
|
+
* instead of a delta with a hole in it. It exists because a reconnect on the
|
|
65
|
+
* phone re-paid 0.86-1.06 s of baseline five times in one measured run.
|
|
66
|
+
*/
|
|
67
|
+
export declare const CAP_SESSION_SNAPSHOT_SINCE = "session.snapshot.since.v1";
|
|
43
68
|
/**
|
|
44
69
|
* Capability a client declares in `hello`'s `cap` array to be shown the
|
|
45
70
|
* host's pending user questions and to answer them with `question.answer`.
|
|
@@ -51,6 +76,147 @@ export declare const CAP_SESSION_SNAPSHOT_PAGE = "session.snapshot.page.v1";
|
|
|
51
76
|
* exactly as that frame was refused before.
|
|
52
77
|
*/
|
|
53
78
|
export declare const CAP_QUESTIONS = "questions.v1";
|
|
79
|
+
/**
|
|
80
|
+
* Capability a client declares in `hello`'s `cap` array to be handed the
|
|
81
|
+
* approval questions this bridge is already holding for it.
|
|
82
|
+
*
|
|
83
|
+
* Unlike every channel capability beside it, this one gates a second delivery
|
|
84
|
+
* rather than the channel: `approval.request` still reaches every paired
|
|
85
|
+
* connection the moment a tool asks, exactly as it did before this name
|
|
86
|
+
* existed, because gating the first broadcast would take approvals away from
|
|
87
|
+
* every client written before the capability. What the declaration buys is the
|
|
88
|
+
* replay — after a reconnect, or on a session screen opened late, the client is
|
|
89
|
+
* handed the questions that are still waiting instead of a card it never saw.
|
|
90
|
+
* Only a live claim is replayed: a question that was answered, that the bridge
|
|
91
|
+
* timed out, or that was withdrawn with the last phone is gone from the claim
|
|
92
|
+
* registry before the replay reads it.
|
|
93
|
+
*
|
|
94
|
+
* It is deliberately absent from {@link SERVED_CAPABILITIES}: that list is what
|
|
95
|
+
* `hello` advertises as served, advertising a capability is a minor-version
|
|
96
|
+
* addition (see {@link MINOR}), and this channel changes nothing a client can
|
|
97
|
+
* observe in the handshake — no answer, no field and no method behind it. The
|
|
98
|
+
* declaration is the whole switch, and the name reaches a client through this
|
|
99
|
+
* bridge's own protocol documentation.
|
|
100
|
+
*/
|
|
101
|
+
export declare const CAP_APPROVALS = "approvals.v1";
|
|
102
|
+
/**
|
|
103
|
+
* Capability a client declares in `hello`'s `cap` array to be told where a
|
|
104
|
+
* message came from and that an agent spawned a child session.
|
|
105
|
+
*
|
|
106
|
+
* Declaring it is what makes the `subagent` delta part of that client's
|
|
107
|
+
* protocol: a client that does not declare it — including every client written
|
|
108
|
+
* before this channel existed — receives no such event, exactly as that frame
|
|
109
|
+
* was dropped before. The `actor` of a `user-message` is not gated: it is an
|
|
110
|
+
* additive field a client that does not read it ignores.
|
|
111
|
+
*/
|
|
112
|
+
export declare const CAP_SUBAGENT_THREAD = "subagent.thread.v1";
|
|
113
|
+
/**
|
|
114
|
+
* Capability a client declares in `hello`'s `cap` array to see the host's
|
|
115
|
+
* background jobs and to be told when the set changes.
|
|
116
|
+
*
|
|
117
|
+
* Declaring it is what makes `jobs.list` reachable, and `jobs.list` is the only
|
|
118
|
+
* thing that opens a roster: a connection that declares this capability but
|
|
119
|
+
* never asks for a scope receives no `jobs.changed` at all. A client that does
|
|
120
|
+
* not declare it — including every client written before this channel existed —
|
|
121
|
+
* receives no such event, and its `jobs.list` is refused as an unknown method,
|
|
122
|
+
* exactly as that frame was refused before.
|
|
123
|
+
*/
|
|
124
|
+
export declare const CAP_JOBS = "jobs.v1";
|
|
125
|
+
/**
|
|
126
|
+
* Capability a client declares in `hello`'s `cap` array to read the host's
|
|
127
|
+
* Agent presets and to instantiate one as a session.
|
|
128
|
+
*
|
|
129
|
+
* Declaring it is what makes `presets.list` and `session.create` part of that
|
|
130
|
+
* client's protocol at all: a client that does not declare it — including every
|
|
131
|
+
* client written before this channel existed — is refused both as unknown
|
|
132
|
+
* methods, exactly as those frames were refused before. Neither method is
|
|
133
|
+
* called on a connection's behalf either, so a client that never asks sends the
|
|
134
|
+
* host no request.
|
|
135
|
+
*/
|
|
136
|
+
export declare const CAP_AGENTS = "agents.v1";
|
|
137
|
+
/**
|
|
138
|
+
* Capability a client declares in `hello`'s `cap` array to be answered with
|
|
139
|
+
* byte-level increments instead of the whole roster or the whole board.
|
|
140
|
+
*
|
|
141
|
+
* Behind it, `session.list` and `board.snapshot` (the latter through the board
|
|
142
|
+
* plugin, §15) accept an opaque `since` token and answer either the whole set
|
|
143
|
+
* (`mode:"reset"`) or only what changed since the set that token names. A
|
|
144
|
+
* client that does not declare it — including every client written before this
|
|
145
|
+
* channel existed — is answered today's body plus the ignorable `mode` and
|
|
146
|
+
* `token` keys, with `mode` always `"reset"`.
|
|
147
|
+
*/
|
|
148
|
+
export declare const CAP_DELTA = "delta.v1";
|
|
149
|
+
/**
|
|
150
|
+
* Capability a client declares in `hello`'s `cap` array to be told that an
|
|
151
|
+
* archived session is not in the roster at all.
|
|
152
|
+
*
|
|
153
|
+
* Unlike every capability beside it this one negotiates nothing: the bridge
|
|
154
|
+
* never transfers an archived session, whether or not a client declares it, so
|
|
155
|
+
* an older client simply receives the shorter roster it would have hidden
|
|
156
|
+
* anyway. The name is an announcement of that fact, so a client can stop
|
|
157
|
+
* filtering for itself: behind it, no `session.list` row is a session the
|
|
158
|
+
* host's archive set names, a row that does survive still carries
|
|
159
|
+
* `archived: false` under the same schema, and a live child of an archived
|
|
160
|
+
* parent still crosses with its `parentSessionId` — the parent id, not the
|
|
161
|
+
* parent row.
|
|
162
|
+
*/
|
|
163
|
+
export declare const CAP_ROSTER_OMITS_ARCHIVED = "session.list.omit-archived.v1";
|
|
164
|
+
/**
|
|
165
|
+
* Capability a client declares in `hello`'s `cap` array to be answered a
|
|
166
|
+
* compact roster it can page.
|
|
167
|
+
*
|
|
168
|
+
* The declaration alone changes nothing: a listing that carries none of the
|
|
169
|
+
* compact parameters (`cwd`, `maxRows`, `after`) is answered exactly the body
|
|
170
|
+
* protocol v1 always served, so a client can opt into the name before it
|
|
171
|
+
* relies on any of it. Behind the parameters, a row drops its absolute `cwd`
|
|
172
|
+
* unless the request asks for it, drops its `updatedAt` when this connection
|
|
173
|
+
* already sent that id the same value, and a `maxRows`/`after` pair cuts the
|
|
174
|
+
* roster into pages ordered most recent first. The roster is the most repeated
|
|
175
|
+
* large reply on the link, so this is what lets a reconnect pay for the newest
|
|
176
|
+
* screenful plus a cursor instead of the whole list again.
|
|
177
|
+
*/
|
|
178
|
+
export declare const CAP_ROSTER_COMPACT = "session.list.compact.v1";
|
|
179
|
+
/**
|
|
180
|
+
* Capability a client declares in `hello`'s `cap` array to be told that this
|
|
181
|
+
* bridge can page a session's durable history down to its oldest entry.
|
|
182
|
+
*
|
|
183
|
+
* The capability is an announcement and nothing more. `session.history.deep` is
|
|
184
|
+
* open to every paired connection, exactly as `session.history` is, because it
|
|
185
|
+
* is a pure read of the session store that costs no other client anything;
|
|
186
|
+
* declaring the capability is how a client learns the method exists, and a
|
|
187
|
+
* client that does not declare it loses only that knowledge.
|
|
188
|
+
*/
|
|
189
|
+
export declare const CAP_SESSION_DEEP_HISTORY = "session.deep-history.v1";
|
|
190
|
+
/**
|
|
191
|
+
* Capability a client declares in `hello`'s `cap` array to fork a session.
|
|
192
|
+
*
|
|
193
|
+
* Declaring it is what makes `session.fork` part of that client's protocol at
|
|
194
|
+
* all: a client that does not declare it — including every client written
|
|
195
|
+
* before this channel existed — is refused `unknown-method`, and no fork is
|
|
196
|
+
* asked of the host on its behalf. Behind the name the bridge forwards one
|
|
197
|
+
* `SessionForkRequest` to the host's `session/fork` and hands back the host's
|
|
198
|
+
* own `SessionForkValue`, so what a fork point means stays the host's: an
|
|
199
|
+
* `atSeq` is the source event seq the fork includes, an omitted one is the
|
|
200
|
+
* newest finished turn, and a cut the host opens itself is closed by the host's
|
|
201
|
+
* own synthetic finishing event. Nothing about a fork is modelled or
|
|
202
|
+
* re-derived here.
|
|
203
|
+
*/
|
|
204
|
+
export declare const CAP_SESSION_FORK = "session.fork.v1";
|
|
205
|
+
/**
|
|
206
|
+
* Capability a client declares in `hello`'s `cap` array to be sent frames
|
|
207
|
+
* compressed instead of as plain text.
|
|
208
|
+
*
|
|
209
|
+
* Declaring it is what allows the host to compress at all: a frame whose JSON
|
|
210
|
+
* text is at least 1024 UTF-8 bytes crosses as one WebSocket binary frame
|
|
211
|
+
* carrying raw DEFLATE (RFC 1951) of exactly that text, and a frame that does
|
|
212
|
+
* not get smaller still crosses as the text frame it always was. A client that
|
|
213
|
+
* does not declare it — including every client written before this capability
|
|
214
|
+
* existed — receives byte for byte the text frames protocol v1 always wrote.
|
|
215
|
+
*
|
|
216
|
+
* The direction is one way: a client still sends text frames only, and the
|
|
217
|
+
* 10 MiB frame cap stays measured on the text, before inflation.
|
|
218
|
+
*/
|
|
219
|
+
export declare const CAP_FRAME_DEFLATE = "frame.deflate.v1";
|
|
54
220
|
/**
|
|
55
221
|
* Methods an unpaired connection may still call: the handshake itself and the
|
|
56
222
|
* two pairing steps. Everything else answers `unpaired` — a caller can pair
|
|
@@ -74,13 +240,77 @@ export declare const CODE_APPROVAL_UNKNOWN = "approval-unknown";
|
|
|
74
240
|
* failures crossing this method keep their own codes instead.
|
|
75
241
|
*/
|
|
76
242
|
export declare const CODE_QUESTION_UNKNOWN = "question-unknown";
|
|
243
|
+
/**
|
|
244
|
+
* The named session is a delegated child whose durable parent is not a session
|
|
245
|
+
* this connection may read. The bridge follows an addressable child and refuses
|
|
246
|
+
* an unaddressable one, rather than reading it blind.
|
|
247
|
+
*/
|
|
248
|
+
export declare const CODE_SESSION_NOT_FOLLOWABLE = "session-not-followable";
|
|
77
249
|
export declare const CODE_SNAPSHOT_UNAVAILABLE = "snapshot-unavailable";
|
|
250
|
+
/**
|
|
251
|
+
* This host composes no job registry, so it has no background jobs to publish.
|
|
252
|
+
* The capability stays advertised — it is a fact about this bridge, not about
|
|
253
|
+
* what a particular host mounts — and only a call that needs the registry fails.
|
|
254
|
+
*/
|
|
255
|
+
export declare const CODE_JOBS_UNAVAILABLE = "jobs-unavailable";
|
|
78
256
|
export declare const CODE_SNAPSHOT_TOO_LARGE = "snapshot-too-large";
|
|
79
257
|
export declare const CODE_INTERNAL = "internal";
|
|
80
258
|
/** Protocol version this package speaks. */
|
|
81
259
|
export declare const PROTO = 1;
|
|
82
|
-
/**
|
|
83
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Minor version this package speaks.
|
|
262
|
+
*
|
|
263
|
+
* 11 when the fork channel shipped: behind {@link CAP_SESSION_FORK} a client may
|
|
264
|
+
* call {@link METHOD_SESSION_FORK} and receive the host's own fork answer, so a
|
|
265
|
+
* phone branches a session that inherits the context of the one it forked. This
|
|
266
|
+
* is the second of two appends cut from 9 — the snapshot-`since` channel took
|
|
267
|
+
* 10 on the integration branch first — so the number steps over the one already
|
|
268
|
+
* on `dev`: the minor counts additions to this protocol, and a later landing
|
|
269
|
+
* steps over the earlier one instead of reusing its number.
|
|
270
|
+
* 10 when the snapshot became incremental on request: behind
|
|
271
|
+
* {@link CAP_SESSION_SNAPSHOT_SINCE} a `session.snapshot` that names `sinceSeq`
|
|
272
|
+
* is answered either the entries above that watermark or a full baseline
|
|
273
|
+
* carrying `mode` and `reset`, so a client reads a new reply shape off the
|
|
274
|
+
* wire and the number rises with it.
|
|
275
|
+
* 9 when the compact roster shipped: behind {@link CAP_ROSTER_COMPACT} a
|
|
276
|
+
* `session.list` that names one of the compact parameters is answered a
|
|
277
|
+
* shorter row and may be cut into pages, so a client reads a new row schema
|
|
278
|
+
* off the wire and the number rises with it.
|
|
279
|
+
* 8 when the outbound frame form became a capability: behind
|
|
280
|
+
* {@link CAP_FRAME_DEFLATE} a declaring client may be answered in binary
|
|
281
|
+
* frames carrying raw DEFLATE of the text, so the minor is raised for a change
|
|
282
|
+
* a client reads off the wire rather than for a name alone.
|
|
283
|
+
* 7 when the two channels met: the agent channel and the durable history
|
|
284
|
+
* channel each raised 5 to 6 on its own branch, so the protocol that carries
|
|
285
|
+
* both is 7. 6 when the agent channel shipped: behind {@link CAP_AGENTS}
|
|
286
|
+
* `presets.list` forwards the host's Agent-preset roster and `session.create`
|
|
287
|
+
* hands the host one creation request, both verbatim. 6 was also the durable
|
|
288
|
+
* history channel on its own: behind {@link CAP_SESSION_DEEP_HISTORY} a client
|
|
289
|
+
* may call {@link METHOD_SESSION_HISTORY_DEEP} and walk a session's store back
|
|
290
|
+
* to its oldest entry, below the follow window `session.history` slices. 5 when
|
|
291
|
+
* the roster stopped carrying archived sessions: behind
|
|
292
|
+
* {@link CAP_ROSTER_OMITS_ARCHIVED} `session.list` names no session the host's
|
|
293
|
+
* archive set holds, so a session archived between two listings arrives as a
|
|
294
|
+
* removal and one restored as a change. 4 when byte-level increments shipped:
|
|
295
|
+
* behind {@link CAP_DELTA} `session.list` and `board.snapshot` answer a reset
|
|
296
|
+
* or a delta against a `since` token. 3 was
|
|
297
|
+
* the background-job channel — behind {@link CAP_JOBS} a client may call
|
|
298
|
+
* `jobs.list` and receive `jobs.changed`. 2 was the subagent thread —
|
|
299
|
+
* a `user-message` delta may carry an `actor` and a `subagent` delta exists
|
|
300
|
+
* behind {@link CAP_SUBAGENT_THREAD}. 1 was the extension seam — a mounted
|
|
301
|
+
* plugin may answer methods outside {@link KNOWN_METHODS} once the client
|
|
302
|
+
* declares the capability that plugin requires. No addition changed the major
|
|
303
|
+
* version, a frozen field, or an existing method or topic name.
|
|
304
|
+
*/
|
|
305
|
+
export declare const MINOR = 11;
|
|
306
|
+
/**
|
|
307
|
+
* The capabilities this bridge itself serves, as `hello` advertises them.
|
|
308
|
+
*
|
|
309
|
+
* A capability a mounted plugin adds is not listed here: the bridge cannot know
|
|
310
|
+
* what it is not the author of. A client learns such a capability from the
|
|
311
|
+
* plugin's own documentation, exactly as it did before this list existed.
|
|
312
|
+
*/
|
|
313
|
+
export declare const SERVED_CAPABILITIES: readonly string[];
|
|
84
314
|
/** `server` field of the hello response. */
|
|
85
315
|
export declare const SERVER_ID = "dsh-remote-bridge";
|
|
86
316
|
/** Exact route path of the bridge's WebSocket endpoint. */
|
|
@@ -30,6 +30,13 @@
|
|
|
30
30
|
* delegated to `next()`, never answered with a decision the operator did not
|
|
31
31
|
* make.
|
|
32
32
|
*
|
|
33
|
+
* A timed ask's deadline is read back from the host itself
|
|
34
|
+
* (`userQuestions/attachWait`) and published as `expiresAt`, so the phone can
|
|
35
|
+
* count down the wait the host is actually serving. Holding that subscription
|
|
36
|
+
* parks the host's own deadline timer, so this module also has to let go at the
|
|
37
|
+
* instant the deadline it learned has passed: only then does the host raise
|
|
38
|
+
* `ASK_TIMED_OUT` and hand the claim its `continued` state.
|
|
39
|
+
*
|
|
33
40
|
* The types below mirror `@deepseek-ai/dsh-user-questions` field for field. The
|
|
34
41
|
* package is not a dependency of this one (it is the host's, not the bridge's),
|
|
35
42
|
* so the contract is declared locally instead of imported.
|
|
@@ -103,11 +110,29 @@ export interface ClaimedQuestionView {
|
|
|
103
110
|
readonly sessionId: string;
|
|
104
111
|
readonly callId: string;
|
|
105
112
|
readonly questions: readonly QuestionItem[];
|
|
113
|
+
/**
|
|
114
|
+
* Epoch milliseconds at which the host's own deadline falls — the absolute
|
|
115
|
+
* form of the remaining wait the host reported through `attachWait`.
|
|
116
|
+
*
|
|
117
|
+
* Absent when the host said nothing: a blocking ask has no deadline at all,
|
|
118
|
+
* and a timed one is only known once a wait frame arrived.
|
|
119
|
+
*/
|
|
120
|
+
readonly expiresAt?: number;
|
|
106
121
|
}
|
|
107
122
|
/** One claim the hub holds while the host's ask is still open. */
|
|
108
123
|
export interface ClaimedQuestion extends ClaimedQuestionView {
|
|
109
124
|
/** The host's ask: the phone's answer, or whatever the next answerer says. */
|
|
110
125
|
readonly answer: Promise<QuestionAnswer>;
|
|
126
|
+
/**
|
|
127
|
+
* Epoch milliseconds at which the host's own deadline falls, from the first
|
|
128
|
+
* wait frame of this claim.
|
|
129
|
+
*
|
|
130
|
+
* Resolves undefined when there is no deadline to publish — a blocking ask, a
|
|
131
|
+
* failed subscription, or a stream that ended before its first frame — and
|
|
132
|
+
* never rejects: a phone must be shown the question whether or not the host
|
|
133
|
+
* would say how long it has.
|
|
134
|
+
*/
|
|
135
|
+
readonly deadline: Promise<number | undefined>;
|
|
111
136
|
}
|
|
112
137
|
/** What one `question.answer` produced: acknowledgement, or the refusal to send. */
|
|
113
138
|
export type QuestionReply = {
|
|
@@ -130,6 +155,15 @@ export declare const QUESTION_TIMED_OUT_CODE = "ASK_TIMED_OUT";
|
|
|
130
155
|
export declare const MINTED_CALL_ID_PREFIX = "bridge:";
|
|
131
156
|
/** Entropy of one minted call id. */
|
|
132
157
|
export declare const MINTED_CALL_ID_BYTES = 16;
|
|
158
|
+
/**
|
|
159
|
+
* How often at most a phone is told that the host's deadline moved, in
|
|
160
|
+
* milliseconds.
|
|
161
|
+
*
|
|
162
|
+
* The host re-reports its remaining wait on every touch of the wait, which can
|
|
163
|
+
* be far more often than a countdown needs; one update per second keeps the
|
|
164
|
+
* wire quiet without the phone ever showing a stale second.
|
|
165
|
+
*/
|
|
166
|
+
export declare const QUESTION_WAIT_BROADCAST_MIN_INTERVAL_MS = 1000;
|
|
133
167
|
export interface OpenQuestionInput {
|
|
134
168
|
readonly sessionId: string;
|
|
135
169
|
/** The id published on the wire: the host's own, or one this bridge minted. */
|
|
@@ -148,6 +182,15 @@ export interface OpenQuestionInput {
|
|
|
148
182
|
readonly signal?: AbortSignal;
|
|
149
183
|
/** Called once when the host's deadline released the model but the question stayed answerable. */
|
|
150
184
|
readonly onContinued?: (question: ClaimedQuestionView) => void;
|
|
185
|
+
/**
|
|
186
|
+
* Called when a later wait frame moved the host's deadline, so a phone that
|
|
187
|
+
* already holds the card can update it in place.
|
|
188
|
+
*
|
|
189
|
+
* The first frame is not reported here: it is what {@link ClaimedQuestion.deadline}
|
|
190
|
+
* hands the hub for the question's own first broadcast, so reporting it would
|
|
191
|
+
* publish the same deadline twice.
|
|
192
|
+
*/
|
|
193
|
+
readonly onDeadline?: (question: ClaimedQuestionView) => void;
|
|
151
194
|
/**
|
|
152
195
|
* Called when the claim leaves this bridge without the phone answering it — the
|
|
153
196
|
* host's own UI answered first, or the last paired client went away. The phone
|
|
@@ -163,6 +206,11 @@ export interface QuestionClaimsOptions {
|
|
|
163
206
|
readonly log: (message: string) => void;
|
|
164
207
|
/** Id source, injectable so a test can answer the exact id it was given. */
|
|
165
208
|
readonly random?: (byteLength: number) => string;
|
|
209
|
+
/**
|
|
210
|
+
* Clock the deadline bookkeeping reads, injectable so a suite can move the
|
|
211
|
+
* remaining wait instead of sleeping through it.
|
|
212
|
+
*/
|
|
213
|
+
readonly now?: () => number;
|
|
166
214
|
}
|
|
167
215
|
/**
|
|
168
216
|
* Project a host question into the contract's own fields.
|
package/lib/types/core/wire.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* - `session/list` is the only endpoint whose single parameter is named
|
|
11
11
|
* `_request` (the underscore is part of the wire name);
|
|
12
|
-
* -
|
|
12
|
+
* - four endpoints take NO parameters at all and must be called with `{}`;
|
|
13
13
|
* - every other endpoint names its single parameter `request`.
|
|
14
14
|
* @module dsh-remote-bridge/core/wire
|
|
15
15
|
*/
|
|
@@ -22,6 +22,15 @@ export declare const CLOSE_PROTOCOL_ERROR = 1002;
|
|
|
22
22
|
export declare const CLOSE_UNSUPPORTED_DATA = 1003;
|
|
23
23
|
/** Close code for a message past the size this bridge will carry. */
|
|
24
24
|
export declare const CLOSE_TOO_LARGE = 1009;
|
|
25
|
+
/**
|
|
26
|
+
* Close code for a peer that stopped answering: a liveness ping went out and no
|
|
27
|
+
* frame at all came back before its deadline.
|
|
28
|
+
*
|
|
29
|
+
* It is an application-range code (4000-4999), so a client can tell a peer that
|
|
30
|
+
* went silent from a protocol fault, from a frame this bridge will not carry,
|
|
31
|
+
* and from the ordinary 1001 teardown of a bridge that is unloading.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CLOSE_LIVENESS_TIMEOUT = 4000;
|
|
25
34
|
/** @returns the `Sec-WebSocket-Accept` value for a client's key. */
|
|
26
35
|
export declare function webSocketAccept(secWebSocketKey: string): string;
|
|
27
36
|
/** One decoded frame header plus its payload. */
|
|
@@ -57,5 +66,7 @@ export declare function parseClientFrame(buffer: Buffer, maxBytes: number): Fram
|
|
|
57
66
|
export declare function encodeServerFrame(opcode: number, payload: Buffer, fin?: boolean): Buffer;
|
|
58
67
|
/** Encode one text message. */
|
|
59
68
|
export declare function encodeTextFrame(text: string): Buffer;
|
|
69
|
+
/** Encode one binary message: already-encoded payload bytes, never a text frame. */
|
|
70
|
+
export declare function encodeBinaryFrame(payload: Buffer): Buffer;
|
|
60
71
|
/** Encode one close frame with a code and a short reason. */
|
|
61
72
|
export declare function encodeCloseFrame(code: number, reason: string): Buffer;
|