@linxin666/dsh-remote-bridge 0.0.0-stage → 0.4.7
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/LICENSE +202 -0
- package/README.i18n.yaml +6 -0
- package/README.md +243 -2
- package/README.zh.md +244 -0
- package/cordis.patch.yml +17 -0
- package/lib/client.js +1830 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +3744 -0
- package/lib/types/client/PairEntry.d.ts +16 -0
- package/lib/types/client/PairPanel.d.ts +55 -0
- package/lib/types/client/icons.d.ts +18 -0
- package/lib/types/client/index.d.ts +35 -0
- package/lib/types/client/locales.d.ts +42 -0
- package/lib/types/client/pair-token.d.ts +73 -0
- package/lib/types/client/semantic.d.ts +28 -0
- package/lib/types/core/approvals.d.ts +75 -0
- package/lib/types/core/connection.d.ts +119 -0
- package/lib/types/core/crypto.d.ts +48 -0
- package/lib/types/core/devices.d.ts +72 -0
- package/lib/types/core/dsh-frames.d.ts +181 -0
- package/lib/types/core/envelope.d.ts +98 -0
- package/lib/types/core/gateway-errors.d.ts +49 -0
- package/lib/types/core/hub.d.ts +101 -0
- package/lib/types/core/loopback.d.ts +35 -0
- package/lib/types/core/owner-peer.d.ts +49 -0
- package/lib/types/core/pairing.d.ts +61 -0
- package/lib/types/core/protocol.d.ts +89 -0
- package/lib/types/core/questions.d.ts +246 -0
- package/lib/types/core/session-meta.d.ts +105 -0
- package/lib/types/core/session-permissions.d.ts +134 -0
- package/lib/types/core/wire.d.ts +115 -0
- package/lib/types/core/ws-frames.d.ts +61 -0
- package/lib/types/host/dsh-home.d.ts +16 -0
- package/lib/types/host/pair-origin.d.ts +44 -0
- package/lib/types/host/routes.d.ts +27 -0
- package/lib/types/host/websocket.d.ts +104 -0
- package/lib/types/index.d.ts +40 -0
- package/package.json +87 -3
- package/src/client/PairEntry.tsx +151 -0
- package/src/client/PairPanel.tsx +183 -0
- package/src/client/icons.tsx +72 -0
- package/src/client/index.ts +81 -0
- package/src/client/locales.ts +72 -0
- package/src/client/pair-token.ts +104 -0
- package/src/client/panel.module.css +344 -0
- package/src/client/semantic.ts +37 -0
- package/src/core/approvals.ts +142 -0
- package/src/core/connection.ts +1090 -0
- package/src/core/crypto.ts +113 -0
- package/src/core/devices.ts +209 -0
- package/src/core/dsh-frames.ts +486 -0
- package/src/core/envelope.ts +173 -0
- package/src/core/gateway-errors.ts +92 -0
- package/src/core/hub.ts +238 -0
- package/src/core/loopback.ts +60 -0
- package/src/core/owner-peer.ts +70 -0
- package/src/core/pairing.ts +113 -0
- package/src/core/protocol.ts +120 -0
- package/src/core/questions.ts +454 -0
- package/src/core/session-meta.ts +176 -0
- package/src/core/session-permissions.ts +266 -0
- package/src/core/wire.ts +155 -0
- package/src/core/ws-frames.ts +125 -0
- package/src/css-modules.d.ts +6 -0
- package/src/host/dsh-home.ts +42 -0
- package/src/host/pair-origin.ts +77 -0
- package/src/host/routes.ts +85 -0
- package/src/host/websocket.ts +325 -0
- package/src/index.ts +205 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge's claims on `user-questions/request`: which questions a phone may
|
|
3
|
+
* answer, and the one path an answer travels back into the host.
|
|
4
|
+
*
|
|
5
|
+
* The host asks in two shapes, and they are two shapes of the SAME channel:
|
|
6
|
+
*
|
|
7
|
+
* - a timed ask (`askTimed`, the tool schema that declares a `timeout`) rides
|
|
8
|
+
* the waterfall with a `wait.callId`. While it is open the bridge HOLDS the
|
|
9
|
+
* host's promise, so the answer is that promise's resolution — exactly what an
|
|
10
|
+
* in-process answerer does, and the only way an open question can be answered
|
|
11
|
+
* at all (`ctx.userQuestions.answer` refuses an open question by returning
|
|
12
|
+
* false). Once the host's own deadline released the model, the ask is gone and
|
|
13
|
+
* the question can only be answered through the host's Remote `answer`, which
|
|
14
|
+
* steers the reply into the agent as a queued user message.
|
|
15
|
+
* - a blocking ask (the schema without `timeout`, which is the `ask_user_question`
|
|
16
|
+
* a phone actually shows) carries NO `wait` at all, and the host assigns no
|
|
17
|
+
* call id. It is still claimed, and the bridge mints its own opaque id for the
|
|
18
|
+
* wire — resolving the promise it holds needs no host identity at all. Such a
|
|
19
|
+
* question is only ever `open`: the host has no deadline for it, so it never
|
|
20
|
+
* becomes `continued` and never takes the Remote `answer` path.
|
|
21
|
+
*
|
|
22
|
+
* Every claim is one record keyed by the id published on the wire, so an answer
|
|
23
|
+
* that arrives late still lands, and an answer for an id this bridge never
|
|
24
|
+
* claimed is refused instead of being forwarded to the host blindly.
|
|
25
|
+
*
|
|
26
|
+
* The bridge invents no deadline, for either shape: a timed ask's deadline is
|
|
27
|
+
* the host's own and is only propagated here, and a blocking ask simply has
|
|
28
|
+
* none — a phone that never answers leaves it open for as long as the asker
|
|
29
|
+
* waits. It also never fabricates a refusal: a question nobody can answer is
|
|
30
|
+
* delegated to `next()`, never answered with a decision the operator did not
|
|
31
|
+
* make.
|
|
32
|
+
*
|
|
33
|
+
* The types below mirror `@deepseek-ai/dsh-user-questions` field for field. The
|
|
34
|
+
* package is not a dependency of this one (it is the host's, not the bridge's),
|
|
35
|
+
* so the contract is declared locally instead of imported.
|
|
36
|
+
* @module dsh-remote-bridge/core/questions
|
|
37
|
+
*/
|
|
38
|
+
import { type BridgeGateway, type GatewayPeer } from './wire.ts';
|
|
39
|
+
/** One selectable answer offered by the asker. */
|
|
40
|
+
export interface QuestionOption {
|
|
41
|
+
readonly label: string;
|
|
42
|
+
readonly description?: string;
|
|
43
|
+
}
|
|
44
|
+
/** One question, in the field names protocol v1 publishes. */
|
|
45
|
+
export interface QuestionItem {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly question: string;
|
|
48
|
+
readonly header?: string;
|
|
49
|
+
readonly detail?: string;
|
|
50
|
+
readonly options?: readonly QuestionOption[];
|
|
51
|
+
readonly multiSelect?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/** One item of the answer batch. */
|
|
54
|
+
export interface QuestionAnswerItem {
|
|
55
|
+
readonly id: string;
|
|
56
|
+
readonly selected: readonly string[];
|
|
57
|
+
readonly custom?: string;
|
|
58
|
+
}
|
|
59
|
+
/** The whole answer batch the host's ask is settled with. */
|
|
60
|
+
export interface QuestionAnswer {
|
|
61
|
+
readonly answers: readonly QuestionAnswerItem[];
|
|
62
|
+
}
|
|
63
|
+
/** Whether a question still holds the foreground ask, or only its late reply. */
|
|
64
|
+
/**
|
|
65
|
+
* `open` while the ask is still waiting, `continued` once the host's foreground
|
|
66
|
+
* wait ended but a late answer can still be steered in, and `settled` as the
|
|
67
|
+
* one-way notice that the phone's card is over — the host's own UI answered it or
|
|
68
|
+
* the last paired client left. `settled` is published, never held.
|
|
69
|
+
*/
|
|
70
|
+
export type QuestionState = 'open' | 'continued' | 'settled';
|
|
71
|
+
/** `question.request`'s payload, as frozen by the contract. */
|
|
72
|
+
export interface QuestionRequestPayload {
|
|
73
|
+
readonly sessionId: string;
|
|
74
|
+
readonly callId: string;
|
|
75
|
+
readonly state: QuestionState;
|
|
76
|
+
readonly questions: readonly QuestionItem[];
|
|
77
|
+
/** Epoch milliseconds; absent when the host published no readable deadline. */
|
|
78
|
+
readonly expiresAt?: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The fields of a host question request this bridge reads.
|
|
82
|
+
*
|
|
83
|
+
* Structural on purpose, for the reason the approval listener is: the event's
|
|
84
|
+
* own type is not reachable from here, and only these fields are ever touched.
|
|
85
|
+
* `wait` is the host's own field for the timed schema — it is what carries the
|
|
86
|
+
* call id, and it is absent for a legacy blocking ask, which this bridge
|
|
87
|
+
* therefore delegates rather than claims.
|
|
88
|
+
*/
|
|
89
|
+
export interface UserQuestionRequestLike {
|
|
90
|
+
readonly questions: readonly QuestionItem[];
|
|
91
|
+
/** The agent asking; its id IS the session id (the event carries no session field). */
|
|
92
|
+
readonly agent?: {
|
|
93
|
+
readonly id: string;
|
|
94
|
+
};
|
|
95
|
+
readonly signal?: AbortSignal;
|
|
96
|
+
readonly wait?: {
|
|
97
|
+
readonly callId?: string;
|
|
98
|
+
readonly timed?: boolean;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** The identity and content of one claim, as the hub publishes it. */
|
|
102
|
+
export interface ClaimedQuestionView {
|
|
103
|
+
readonly sessionId: string;
|
|
104
|
+
readonly callId: string;
|
|
105
|
+
readonly questions: readonly QuestionItem[];
|
|
106
|
+
}
|
|
107
|
+
/** One claim the hub holds while the host's ask is still open. */
|
|
108
|
+
export interface ClaimedQuestion extends ClaimedQuestionView {
|
|
109
|
+
/** The host's ask: the phone's answer, or whatever the next answerer says. */
|
|
110
|
+
readonly answer: Promise<QuestionAnswer>;
|
|
111
|
+
}
|
|
112
|
+
/** What one `question.answer` produced: acknowledgement, or the refusal to send. */
|
|
113
|
+
export type QuestionReply = {
|
|
114
|
+
readonly ok: true;
|
|
115
|
+
} | {
|
|
116
|
+
readonly ok: false;
|
|
117
|
+
readonly code: string;
|
|
118
|
+
readonly msg: string;
|
|
119
|
+
};
|
|
120
|
+
/** The code the host raises when its own foreground deadline ends the ask. */
|
|
121
|
+
export declare const QUESTION_TIMED_OUT_CODE = "ASK_TIMED_OUT";
|
|
122
|
+
/**
|
|
123
|
+
* Prefix of a call id this bridge minted for a question the host never named.
|
|
124
|
+
*
|
|
125
|
+
* A blocking ask has no host call id, but the phone still needs one opaque
|
|
126
|
+
* handle to answer with. The prefix keeps that handle in a namespace of its own,
|
|
127
|
+
* so a minted id can never be mistaken for a host `ToolCallId` — by this bridge
|
|
128
|
+
* or by anything reading the wire.
|
|
129
|
+
*/
|
|
130
|
+
export declare const MINTED_CALL_ID_PREFIX = "bridge:";
|
|
131
|
+
/** Entropy of one minted call id. */
|
|
132
|
+
export declare const MINTED_CALL_ID_BYTES = 16;
|
|
133
|
+
export interface OpenQuestionInput {
|
|
134
|
+
readonly sessionId: string;
|
|
135
|
+
/** The id published on the wire: the host's own, or one this bridge minted. */
|
|
136
|
+
readonly callId: string;
|
|
137
|
+
/**
|
|
138
|
+
* Whether `callId` is the host's own tool call identity.
|
|
139
|
+
*
|
|
140
|
+
* Only a hosted claim can ever be `continued`: the state is what a host
|
|
141
|
+
* deadline produces, and the late-answer path needs a real call id to address.
|
|
142
|
+
*/
|
|
143
|
+
readonly hosted: boolean;
|
|
144
|
+
readonly questions: readonly QuestionItem[];
|
|
145
|
+
/** The rest of the answerer chain, used when the bridge withdraws. */
|
|
146
|
+
readonly next: () => Promise<QuestionAnswer>;
|
|
147
|
+
/** The host's own cancellation lifetime for this ask. */
|
|
148
|
+
readonly signal?: AbortSignal;
|
|
149
|
+
/** Called once when the host's deadline released the model but the question stayed answerable. */
|
|
150
|
+
readonly onContinued?: (question: ClaimedQuestionView) => void;
|
|
151
|
+
/**
|
|
152
|
+
* Called when the claim leaves this bridge without the phone answering it — the
|
|
153
|
+
* host's own UI answered first, or the last paired client went away. The phone
|
|
154
|
+
* still holds a card for it and has to be told, or it keeps offering a question
|
|
155
|
+
* that no longer exists.
|
|
156
|
+
*/
|
|
157
|
+
readonly onSettled?: (question: ClaimedQuestionView) => void;
|
|
158
|
+
}
|
|
159
|
+
export interface QuestionClaimsOptions {
|
|
160
|
+
readonly gateway: BridgeGateway;
|
|
161
|
+
/** The in-process owner peer every gateway call speaks for; the bridge never derives it from a client frame. */
|
|
162
|
+
readonly peer: GatewayPeer;
|
|
163
|
+
readonly log: (message: string) => void;
|
|
164
|
+
/** Id source, injectable so a test can answer the exact id it was given. */
|
|
165
|
+
readonly random?: (byteLength: number) => string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Project a host question into the contract's own fields.
|
|
169
|
+
*
|
|
170
|
+
* Explicitly field by field: the host's items carry presentation intents this
|
|
171
|
+
* protocol does not publish, and a payload that grew a key the contract does
|
|
172
|
+
* not declare would be a wire change nobody agreed to.
|
|
173
|
+
* @param items - the host's question batch.
|
|
174
|
+
* @returns the same questions in protocol vocabulary.
|
|
175
|
+
*/
|
|
176
|
+
export declare function projectQuestions(items: readonly QuestionItem[]): readonly QuestionItem[];
|
|
177
|
+
/**
|
|
178
|
+
* Pending questions of one bridge process.
|
|
179
|
+
*
|
|
180
|
+
* One record per id published on the wire — the host's own, or one minted here
|
|
181
|
+
* for a blocking ask — and one settle for every path (answer, the host's
|
|
182
|
+
* deadline, the last phone leaving, bridge unload), so a question can never be
|
|
183
|
+
* settled twice and a withdrawn claim leaves no abort listener behind.
|
|
184
|
+
*/
|
|
185
|
+
export declare class QuestionClaims {
|
|
186
|
+
#private;
|
|
187
|
+
constructor(options: QuestionClaimsOptions);
|
|
188
|
+
/** @returns how many questions this bridge currently holds. */
|
|
189
|
+
get size(): number;
|
|
190
|
+
/**
|
|
191
|
+
* Mint the opaque wire id of a question the host never named.
|
|
192
|
+
* @returns an id in this bridge's own namespace.
|
|
193
|
+
*/
|
|
194
|
+
mintCallId(): string;
|
|
195
|
+
/** @returns the state of one claimed call, or undefined when it is not claimed. */
|
|
196
|
+
stateOf(callId: string): QuestionState | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Claim one question.
|
|
199
|
+
* @param input - session identity, wire call id and its provenance, questions, the rest of the chain, and the host's lifetime.
|
|
200
|
+
* @returns the claim the hub publishes, or undefined when this call id is already claimed.
|
|
201
|
+
*/
|
|
202
|
+
open(input: OpenQuestionInput): ClaimedQuestion | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Answer one claimed question.
|
|
205
|
+
*
|
|
206
|
+
* An open claim is settled by resolving the host's own ask; a continued one
|
|
207
|
+
* only through the host's Remote `answer`, whose result and failures cross
|
|
208
|
+
* unchanged.
|
|
209
|
+
* @param sessionId - the session the client believes owns the question.
|
|
210
|
+
* @param callId - the wire call id the client was shown.
|
|
211
|
+
* @param answer - the complete answer batch.
|
|
212
|
+
*/
|
|
213
|
+
answer(sessionId: string, callId: string, answer: QuestionAnswer): Promise<QuestionReply>;
|
|
214
|
+
/**
|
|
215
|
+
* Every claim still waiting on an answer.
|
|
216
|
+
*
|
|
217
|
+
* A phone that connects after the question was raised never saw the original
|
|
218
|
+
* broadcast, so it has to be handed the live claims again — otherwise the
|
|
219
|
+
* question sits on the host with an answerable card nowhere.
|
|
220
|
+
*/
|
|
221
|
+
openClaims(): readonly ClaimedQuestionView[];
|
|
222
|
+
/**
|
|
223
|
+
* Withdraw the named questions, delegating each to the next answerer.
|
|
224
|
+
* @returns how many were still open and therefore delegated.
|
|
225
|
+
*/
|
|
226
|
+
withdraw(callIds: readonly string[]): number;
|
|
227
|
+
/**
|
|
228
|
+
* Withdraw every claim, delegating each open question to the next answerer.
|
|
229
|
+
* Called when the last paired phone goes away and when the bridge unloads: a
|
|
230
|
+
* question nobody can answer must not hold the agent until its own deadline.
|
|
231
|
+
* @returns how many questions were still open.
|
|
232
|
+
*/
|
|
233
|
+
withdrawAll(): number;
|
|
234
|
+
}
|
|
235
|
+
declare module '@deepseek-ai/cordis' {
|
|
236
|
+
interface Events {
|
|
237
|
+
/**
|
|
238
|
+
* Ask composed answerers for structured user input; the bridge claims it
|
|
239
|
+
* while a paired phone is connected, and delegates every other case. The
|
|
240
|
+
* parameters are the ones this package reads — the host's own declaration
|
|
241
|
+
* is not reachable from here.
|
|
242
|
+
* @mode waterfall
|
|
243
|
+
*/
|
|
244
|
+
'user-questions/request'(this: unknown, request: UserQuestionRequestLike, next: () => Promise<QuestionAnswer>): Promise<QuestionAnswer>;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-local session metadata the roster rows carry beyond the gateway's own
|
|
3
|
+
* summary, and the cache that keeps a phone's title lookups off the title
|
|
4
|
+
* service's hot path.
|
|
5
|
+
*
|
|
6
|
+
* Every read here goes to a service of the host process the bridge already runs
|
|
7
|
+
* in, so nothing in this module opens a follow stream, waits on a socket or
|
|
8
|
+
* touches persistence: a title is a synchronous read like a map lookup, which
|
|
9
|
+
* is what makes a batch of them cheap enough to serve on request.
|
|
10
|
+
*
|
|
11
|
+
* The services are reached through structural faces rather than the SDK's own
|
|
12
|
+
* service types, for the reason `wire.ts` states for the gateway: the live
|
|
13
|
+
* objects carry far more than this package calls, and a face keeps a test
|
|
14
|
+
* double down to what is actually read.
|
|
15
|
+
* @module dsh-remote-bridge/core/session-meta
|
|
16
|
+
*/
|
|
17
|
+
/** One live session, as far as the title service needs to see it. */
|
|
18
|
+
export interface LiveSessionFace {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
}
|
|
21
|
+
/** The slice of `ctx.sessions` this package reads: the live session for an id. */
|
|
22
|
+
export interface SessionStoreFace {
|
|
23
|
+
get(id: string): LiveSessionFace | undefined;
|
|
24
|
+
}
|
|
25
|
+
/** The slice of `ctx.sessionTitle` this package reads. */
|
|
26
|
+
export interface SessionTitleFace {
|
|
27
|
+
get(session: LiveSessionFace): {
|
|
28
|
+
readonly title: string;
|
|
29
|
+
} | undefined;
|
|
30
|
+
}
|
|
31
|
+
/** The slice of `ctx.workspaceRegistry` this package reads: the host's archive set. */
|
|
32
|
+
export interface ArchiveSetFace {
|
|
33
|
+
readonly archivedSessionIds: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The in-process services one metadata read may use.
|
|
37
|
+
*
|
|
38
|
+
* Every field is optional on purpose. The bridge does not require the title or
|
|
39
|
+
* workspace plugins to be installed — the protocol's roster and title methods
|
|
40
|
+
* stay answerable with them absent, and a field that is missing degrades one
|
|
41
|
+
* key of one row instead of failing a method.
|
|
42
|
+
*/
|
|
43
|
+
export interface SessionMetaFaces {
|
|
44
|
+
readonly sessions?: SessionStoreFace | undefined;
|
|
45
|
+
readonly titles?: SessionTitleFace | undefined;
|
|
46
|
+
readonly archive?: ArchiveSetFace | undefined;
|
|
47
|
+
}
|
|
48
|
+
/** Largest id batch one `session.titles` call accepts. */
|
|
49
|
+
export declare const TITLES_MAX_IDS = 100;
|
|
50
|
+
/** How long one resolved title is served before the service is asked again. */
|
|
51
|
+
export declare const TITLE_CACHE_TTL_MS = 10000;
|
|
52
|
+
/** How many ids the title cache remembers before the oldest entry is dropped. */
|
|
53
|
+
export declare const TITLE_CACHE_LIMIT = 512;
|
|
54
|
+
/**
|
|
55
|
+
* The bridge's session-metadata reads: live titles with a bounded cache, and
|
|
56
|
+
* the host's archive set.
|
|
57
|
+
*
|
|
58
|
+
* One instance is built per host mount and shared by every connection, because
|
|
59
|
+
* a title is a fact about the host's session, not about the device that asked.
|
|
60
|
+
*
|
|
61
|
+
* The cache is time-bounded rather than event-invalidated: a title change is a
|
|
62
|
+
* `session/title` *log* event, which no cordis event announces, so an
|
|
63
|
+
* invalidation hook would mean plumbing a listener into every live session. A
|
|
64
|
+
* short TTL bounds how stale a served title can be while keeping the read off
|
|
65
|
+
* the service for every repeat, and each batch call is itself a refresh point.
|
|
66
|
+
*/
|
|
67
|
+
export declare class SessionMeta {
|
|
68
|
+
#private;
|
|
69
|
+
/**
|
|
70
|
+
* @param faces - resolves the host services now; called per read, never captured once, so a service that mounts later is still picked up.
|
|
71
|
+
* @param now - the clock the cache window is measured on.
|
|
72
|
+
* @param log - where a failed metadata read is reported.
|
|
73
|
+
* @param ttlMs - cache window; the default is {@link TITLE_CACHE_TTL_MS}.
|
|
74
|
+
*/
|
|
75
|
+
constructor(faces: () => SessionMetaFaces, now: () => number, log: (message: string) => void, ttlMs?: number);
|
|
76
|
+
/**
|
|
77
|
+
* Latest title this host knows for one session.
|
|
78
|
+
*
|
|
79
|
+
* Synchronous by construction: the title service folds titles out of the
|
|
80
|
+
* session log it already holds. An id that is not live here, a session whose
|
|
81
|
+
* title has not landed yet, and a host without the title service all answer
|
|
82
|
+
* `""`, which is the protocol's "no title" value rather than a failure.
|
|
83
|
+
* @param id - session to read.
|
|
84
|
+
* @returns the title, or an empty string when there is none to read.
|
|
85
|
+
*/
|
|
86
|
+
title(id: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* The title already resolved for one id, without reading any service.
|
|
89
|
+
*
|
|
90
|
+
* `session.list` uses this to fill a row it can fill for free; a roster must
|
|
91
|
+
* not put one title read on the path of every row it lists.
|
|
92
|
+
* @param id - session to look up.
|
|
93
|
+
* @returns the cached title while the cache window is open, else undefined.
|
|
94
|
+
*/
|
|
95
|
+
cachedTitle(id: string): string | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* The host's archive set, or undefined when it cannot be read.
|
|
98
|
+
*
|
|
99
|
+
* Reading it is the only way a row can carry `archived`: the key is omitted
|
|
100
|
+
* rather than guessed when the workspace registry is not mounted, so a client
|
|
101
|
+
* never reads "not archived" out of a bridge that simply could not tell.
|
|
102
|
+
* @returns the archived session ids, or undefined when the registry is unavailable.
|
|
103
|
+
*/
|
|
104
|
+
archiveSet(): ReadonlySet<string> | undefined;
|
|
105
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host's permission presets, projected into the shape `session.permissions`
|
|
3
|
+
* and `session.setPermission` publish.
|
|
4
|
+
*
|
|
5
|
+
* The services are reached through structural faces for the reason
|
|
6
|
+
* `session-meta.ts` states: the live objects carry far more than this package
|
|
7
|
+
* calls, and a face keeps a test double down to what is actually read.
|
|
8
|
+
*
|
|
9
|
+
* Two facts of the real service shape this module:
|
|
10
|
+
*
|
|
11
|
+
* - `current` and `set` take the LIVE `Session` object, never an id, so a
|
|
12
|
+
* session this host process does not hold — a cold, disk-only roster entry —
|
|
13
|
+
* has no truthful answer at all. That case is refused by name instead of
|
|
14
|
+
* being reported as an empty or defaulted mode.
|
|
15
|
+
* - `custom` is DERIVED state, never a switch target: it can be the current
|
|
16
|
+
* value and must never be offered as an option.
|
|
17
|
+
* @module dsh-remote-bridge/core/session-permissions
|
|
18
|
+
*/
|
|
19
|
+
import type { LiveSessionFace, SessionStoreFace } from './session-meta.ts';
|
|
20
|
+
/** The permission service's name for "no preset matches the two knobs". */
|
|
21
|
+
export declare const CUSTOM_PRESET = "custom";
|
|
22
|
+
/**
|
|
23
|
+
* The code the harness raises for a session it has no live instance of.
|
|
24
|
+
* Verbatim from the harness's own error table, not a bridge-invented one.
|
|
25
|
+
*/
|
|
26
|
+
export declare const CODE_SESSION_NOT_FOUND = "session/not-found";
|
|
27
|
+
/** One preset as the permission service advertises it. */
|
|
28
|
+
export interface PresetOptionFace {
|
|
29
|
+
/** The switch target's stable value. */
|
|
30
|
+
readonly value: string;
|
|
31
|
+
/** The label a client shows. */
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly description?: string;
|
|
34
|
+
}
|
|
35
|
+
/** The slice of `ctx.permissionPresets` this package reads and writes. */
|
|
36
|
+
export interface PermissionPresetsFace {
|
|
37
|
+
catalog(): {
|
|
38
|
+
readonly options: readonly PresetOptionFace[];
|
|
39
|
+
} | undefined;
|
|
40
|
+
/** The preset matching the session's folded knobs, or `custom`. */
|
|
41
|
+
current(session: LiveSessionFace): string;
|
|
42
|
+
/** Switch one live session; unknown names throw. */
|
|
43
|
+
set(session: LiveSessionFace, name: string): void;
|
|
44
|
+
/** The client option for a preset or the derived `custom`. */
|
|
45
|
+
optionOf(name: string): PresetOptionFace;
|
|
46
|
+
}
|
|
47
|
+
/** The slice of `ctx.sandboxPolicy` this package reads. */
|
|
48
|
+
export interface SandboxPolicyFace {
|
|
49
|
+
/** The deployment default a session inherits without its own override. */
|
|
50
|
+
readonly defaultMode?: string;
|
|
51
|
+
/** The session's own last logged mode, or undefined without one. */
|
|
52
|
+
overrideOf(session: LiveSessionFace): string | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** The slice of `ctx.approval` this package reads. */
|
|
55
|
+
export interface ApprovalPolicyFace {
|
|
56
|
+
/** The deployment's configured default policy. */
|
|
57
|
+
readonly config?: {
|
|
58
|
+
readonly policy?: string;
|
|
59
|
+
};
|
|
60
|
+
/** The session's own last logged policy, or undefined without one. */
|
|
61
|
+
overrideOf(session: LiveSessionFace): string | undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The in-process services one permission read may use.
|
|
65
|
+
*
|
|
66
|
+
* Every field is optional on purpose: on a host that does not compose the
|
|
67
|
+
* permission plugin the method answers `unknown-method`, which is the signal a
|
|
68
|
+
* client already uses to disable the control instead of offering a dead switch.
|
|
69
|
+
*/
|
|
70
|
+
export interface PermissionFaces {
|
|
71
|
+
readonly sessions?: SessionStoreFace | undefined;
|
|
72
|
+
readonly presets?: PermissionPresetsFace | undefined;
|
|
73
|
+
readonly sandbox?: SandboxPolicyFace | undefined;
|
|
74
|
+
readonly approval?: ApprovalPolicyFace | undefined;
|
|
75
|
+
}
|
|
76
|
+
/** One selectable preset, in the protocol's own field names. */
|
|
77
|
+
export interface PermissionOption {
|
|
78
|
+
readonly id: string;
|
|
79
|
+
readonly name: string;
|
|
80
|
+
readonly description?: string;
|
|
81
|
+
}
|
|
82
|
+
/** The session's current permission mode. */
|
|
83
|
+
export interface PermissionCurrent {
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly name: string;
|
|
86
|
+
/** The effective sandbox knob; present only while {@link PermissionCurrent.id} is `custom`. */
|
|
87
|
+
readonly sandbox?: string;
|
|
88
|
+
/** The effective approval knob; present only while {@link PermissionCurrent.id} is `custom`. */
|
|
89
|
+
readonly approval?: string;
|
|
90
|
+
}
|
|
91
|
+
/** One `session.permissions` answer. */
|
|
92
|
+
export interface PermissionsAnswer {
|
|
93
|
+
readonly current: PermissionCurrent;
|
|
94
|
+
readonly options: readonly PermissionOption[];
|
|
95
|
+
readonly custom: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** One permission refusal, in the shape the dispatcher answers with. */
|
|
98
|
+
export interface PermissionRefusal {
|
|
99
|
+
readonly code: string;
|
|
100
|
+
readonly msg: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The bridge's permission reads and writes.
|
|
104
|
+
*
|
|
105
|
+
* One instance is built per host mount and shared by every connection, because a
|
|
106
|
+
* preset table is a fact about the deployment, not about the device that asked.
|
|
107
|
+
*/
|
|
108
|
+
export declare class SessionPermissions {
|
|
109
|
+
#private;
|
|
110
|
+
/**
|
|
111
|
+
* @param faces - resolves the host services now; called per read, never captured once, so a service that mounts later is still picked up.
|
|
112
|
+
* @param log - where an unreadable preset state is reported.
|
|
113
|
+
*/
|
|
114
|
+
constructor(faces: () => PermissionFaces, log: (message: string) => void);
|
|
115
|
+
/**
|
|
116
|
+
* Describe one session's permission modes.
|
|
117
|
+
*
|
|
118
|
+
* `current` is the service's own folded value: the preset the session's two
|
|
119
|
+
* knobs currently match, or `custom` with both knobs' real values. It is never
|
|
120
|
+
* the deployment default dressed up as the current mode.
|
|
121
|
+
* @param sessionId - the session the client is looking at.
|
|
122
|
+
*/
|
|
123
|
+
describe(sessionId: string): PermissionsAnswer | PermissionRefusal;
|
|
124
|
+
/**
|
|
125
|
+
* Switch one session to a preset this host offers.
|
|
126
|
+
*
|
|
127
|
+
* The id is validated against the same option list `describe` publishes before
|
|
128
|
+
* the service is touched at all, so an unknown id changes nothing — the switch
|
|
129
|
+
* appends durable events and must never run on a rejected argument.
|
|
130
|
+
* @param sessionId - the session to switch.
|
|
131
|
+
* @param id - one of `describe(sessionId).options`' ids.
|
|
132
|
+
*/
|
|
133
|
+
set(sessionId: string, id: string): PermissionsAnswer | PermissionRefusal;
|
|
134
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The exact `args` layout of every DSH Remote endpoint this package may call.
|
|
3
|
+
*
|
|
4
|
+
* A descriptor declares one parameter name per wire key, and the gateway
|
|
5
|
+
* asserts the argument object is EXACTLY that set — one extra or one missing
|
|
6
|
+
* key throws `gateway/arguments-invalid`. The asymmetry is real and belongs to
|
|
7
|
+
* the endpoint owners, so it is tabulated here instead of guessed at the call
|
|
8
|
+
* site:
|
|
9
|
+
*
|
|
10
|
+
* - `session/list` is the only endpoint whose single parameter is named
|
|
11
|
+
* `_request` (the underscore is part of the wire name);
|
|
12
|
+
* - three endpoints take NO parameters at all and must be called with `{}`;
|
|
13
|
+
* - every other endpoint names its single parameter `request`.
|
|
14
|
+
* @module dsh-remote-bridge/core/wire
|
|
15
|
+
*/
|
|
16
|
+
import type { InvokeRemoteRequest } from '@deepseek-ai/dsh-api-gateway';
|
|
17
|
+
/**
|
|
18
|
+
* The peer every gateway request names: derived from the public
|
|
19
|
+
* `InvokeRemoteRequest` type so this package needs no direct dependency on
|
|
20
|
+
* `@deepseek-ai/dsh-typert-protocol` for the shape.
|
|
21
|
+
*/
|
|
22
|
+
export type GatewayPeer = InvokeRemoteRequest['peer'];
|
|
23
|
+
/** One Remote call after the carrier has decoded its envelope. */
|
|
24
|
+
export interface GatewayInvokeRequest {
|
|
25
|
+
readonly namespace: string;
|
|
26
|
+
readonly method: string;
|
|
27
|
+
readonly args: Readonly<Record<string, unknown>>;
|
|
28
|
+
/**
|
|
29
|
+
* The caller this call speaks for. The bridge mints this peer in-process
|
|
30
|
+
* (`core/owner-peer.ts`) and attaches it to every gateway call itself; no
|
|
31
|
+
* field of a client frame is ever read into it.
|
|
32
|
+
*/
|
|
33
|
+
readonly peer: GatewayPeer;
|
|
34
|
+
readonly signal?: AbortSignal;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The subset of `ctx.typertGateway` this package consumes. Structural on
|
|
38
|
+
* purpose: the live service also carries the wire-stream adapter and the
|
|
39
|
+
* forwarded-event registry, none of which the bridge uses, so a test fake only
|
|
40
|
+
* has to implement what is called.
|
|
41
|
+
*/
|
|
42
|
+
export interface BridgeGateway {
|
|
43
|
+
invoke(request: GatewayInvokeRequest): Promise<unknown>;
|
|
44
|
+
stream(request: GatewayInvokeRequest): Promise<AsyncIterable<unknown>>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Durable identity of one ordinary Session or one direct subagent child.
|
|
48
|
+
*
|
|
49
|
+
* `session/follow` and `session/page` take this instead of a bare id, and the
|
|
50
|
+
* harness refuses a delegated child addressed as an ordinary session with
|
|
51
|
+
* `session/agent-busy` — "subagent Sessions require their durable parent
|
|
52
|
+
* address" — so the bridge must send the child's own kind for those sessions.
|
|
53
|
+
*/
|
|
54
|
+
export type SessionAddress = {
|
|
55
|
+
readonly kind: 'session';
|
|
56
|
+
readonly sessionId: string;
|
|
57
|
+
} | {
|
|
58
|
+
readonly kind: 'subagent';
|
|
59
|
+
readonly parentSessionId: string;
|
|
60
|
+
readonly childSessionId: string;
|
|
61
|
+
readonly mode: SubagentMode;
|
|
62
|
+
};
|
|
63
|
+
/** How long a delegated child may be continued; `unknown` is checked against nothing. */
|
|
64
|
+
export type SubagentMode = 'one-shot' | 'continuable' | 'unknown';
|
|
65
|
+
/** The durable address of one ordinary session. */
|
|
66
|
+
export declare function sessionAddress(sessionId: string): SessionAddress;
|
|
67
|
+
/**
|
|
68
|
+
* The durable address of one delegated child.
|
|
69
|
+
*
|
|
70
|
+
* The mode is always `unknown`: the bridge has no reliable way to read a
|
|
71
|
+
* child's mode before the call, and the harness accepts `unknown` for every
|
|
72
|
+
* child while checking a claimed mode against the descriptor.
|
|
73
|
+
*/
|
|
74
|
+
export declare function subagentAddress(parentSessionId: string, childSessionId: string): SessionAddress;
|
|
75
|
+
/** The failure code the harness raises for a child addressed as an ordinary session. */
|
|
76
|
+
export declare const CODE_SUBAGENT_ADDRESS_REQUIRED = "session/agent-busy";
|
|
77
|
+
/**
|
|
78
|
+
* One endpoint's declared argument names: the name of its single parameter, the
|
|
79
|
+
* empty declaration of a parameterless endpoint, or the exact names of an
|
|
80
|
+
* endpoint that takes several.
|
|
81
|
+
*/
|
|
82
|
+
export type WireName = 'request' | '_request' | 'none' | {
|
|
83
|
+
readonly names: readonly string[];
|
|
84
|
+
};
|
|
85
|
+
/** One endpoint's declared wire layout. */
|
|
86
|
+
export interface WireRow {
|
|
87
|
+
readonly namespace: string;
|
|
88
|
+
readonly method: string;
|
|
89
|
+
readonly wire: WireName;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Every endpoint of the frozen mapping table, in the order the parent card
|
|
93
|
+
* lists them. Rows whose endpoint no method of protocol v1 exposes yet
|
|
94
|
+
* (`pluginInventory/list`, `pluginManager/listPlugins`) stay in the table: they
|
|
95
|
+
* are the layout a future method must not get wrong, and the table is the
|
|
96
|
+
* single place it is written.
|
|
97
|
+
*/
|
|
98
|
+
export declare const WIRE_TABLE: readonly WireRow[];
|
|
99
|
+
/** @returns the declared row for an endpoint, or undefined when it is not tabulated. */
|
|
100
|
+
export declare function wireRowFor(namespace: string, method: string): WireRow | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Build the `args` object for one endpoint.
|
|
103
|
+
*
|
|
104
|
+
* An untabulated endpoint falls back to `{ request }`: that is the layout of
|
|
105
|
+
* every tabulated endpoint but a few, and a wrong guess fails loudly at the
|
|
106
|
+
* gateway with `arguments-invalid` rather than silently invoking the wrong
|
|
107
|
+
* shape. A multi-parameter endpoint carries one key per declared name, and a
|
|
108
|
+
* name the caller left out stays out — the gateway refuses it by name, which is
|
|
109
|
+
* the failure a caller should see.
|
|
110
|
+
* @param namespace - Remote namespace.
|
|
111
|
+
* @param method - Service method name.
|
|
112
|
+
* @param request - the endpoint's request payload.
|
|
113
|
+
* @returns the exact named-argument object.
|
|
114
|
+
*/
|
|
115
|
+
export declare function wireArgs(namespace: string, method: string, request?: Readonly<Record<string, unknown>>): Record<string, unknown>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 6455 server-side framing, kept as pure functions so the length, mask and
|
|
3
|
+
* opcode rules are unit-tested without a socket.
|
|
4
|
+
*
|
|
5
|
+
* Only what a server must accept is implemented: client frames are always
|
|
6
|
+
* masked, one logical message may arrive as a text frame or as a fragmented
|
|
7
|
+
* sequence, and anything the protocol forbids answers with the close code that
|
|
8
|
+
* names the violation instead of being ignored.
|
|
9
|
+
* @module dsh-remote-bridge/core/ws-frames
|
|
10
|
+
*/
|
|
11
|
+
/** The magic GUID every WebSocket handshake is keyed with. */
|
|
12
|
+
export declare const WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
13
|
+
export declare const OPCODE_CONTINUATION = 0;
|
|
14
|
+
export declare const OPCODE_TEXT = 1;
|
|
15
|
+
export declare const OPCODE_BINARY = 2;
|
|
16
|
+
export declare const OPCODE_CLOSE = 8;
|
|
17
|
+
export declare const OPCODE_PING = 9;
|
|
18
|
+
export declare const OPCODE_PONG = 10;
|
|
19
|
+
/** Close code for a protocol violation. */
|
|
20
|
+
export declare const CLOSE_PROTOCOL_ERROR = 1002;
|
|
21
|
+
/** Close code for a message this bridge will not carry. */
|
|
22
|
+
export declare const CLOSE_UNSUPPORTED_DATA = 1003;
|
|
23
|
+
/** Close code for a message past the size this bridge will carry. */
|
|
24
|
+
export declare const CLOSE_TOO_LARGE = 1009;
|
|
25
|
+
/** @returns the `Sec-WebSocket-Accept` value for a client's key. */
|
|
26
|
+
export declare function webSocketAccept(secWebSocketKey: string): string;
|
|
27
|
+
/** One decoded frame header plus its payload. */
|
|
28
|
+
export interface DecodedFrame {
|
|
29
|
+
readonly fin: boolean;
|
|
30
|
+
readonly opcode: number;
|
|
31
|
+
readonly payload: Buffer;
|
|
32
|
+
/** Bytes this frame occupies in the stream. */
|
|
33
|
+
readonly consumed: number;
|
|
34
|
+
}
|
|
35
|
+
export type FrameParseOutcome = {
|
|
36
|
+
readonly status: 'incomplete';
|
|
37
|
+
} | {
|
|
38
|
+
readonly status: 'frame';
|
|
39
|
+
readonly frame: DecodedFrame;
|
|
40
|
+
} | {
|
|
41
|
+
readonly status: 'fault';
|
|
42
|
+
readonly closeCode: number;
|
|
43
|
+
readonly reason: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Decode one frame from the head of a buffer.
|
|
47
|
+
* @param buffer - the bytes received so far.
|
|
48
|
+
* @param maxBytes - largest payload this bridge accepts.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseClientFrame(buffer: Buffer, maxBytes: number): FrameParseOutcome;
|
|
51
|
+
/**
|
|
52
|
+
* Encode one server frame. Server frames are never masked.
|
|
53
|
+
* @param opcode - the frame opcode.
|
|
54
|
+
* @param payload - already-serialized payload bytes.
|
|
55
|
+
* @param fin - whether this frame completes the message.
|
|
56
|
+
*/
|
|
57
|
+
export declare function encodeServerFrame(opcode: number, payload: Buffer, fin?: boolean): Buffer;
|
|
58
|
+
/** Encode one text message. */
|
|
59
|
+
export declare function encodeTextFrame(text: string): Buffer;
|
|
60
|
+
/** Encode one close frame with a code and a short reason. */
|
|
61
|
+
export declare function encodeCloseFrame(code: number, reason: string): Buffer;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH_HOME resolution shared by the plugin family's Host halves: the
|
|
3
|
+
* environment override wins, the platform home fallback follows. Mirrors
|
|
4
|
+
* what dsh-pet and dsh-liangshen each used to implement locally.
|
|
5
|
+
*/
|
|
6
|
+
/** Expand a leading ~ (or ~user) in a path, platform-style. */
|
|
7
|
+
export declare function expandHome(path: string, home?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the DSH home directory.
|
|
10
|
+
* @param env - process environment to read DSH_HOME from.
|
|
11
|
+
* @param home - platform home directory fallback (test seam).
|
|
12
|
+
* @returns the absolute DSH home path.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveDshHome(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
15
|
+
/** Resolve the DSH home directory from the live environment. */
|
|
16
|
+
export declare function dshHome(): string;
|