@linxin666/dsh-remote-bridge 0.4.15 → 0.4.16

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.
@@ -12,9 +12,7 @@
12
12
  * rather than the socket: with no paired connection on the wire but a device on
13
13
  * the roster that registered for pushes, the question is claimed for that phone
14
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.
15
+ * device that is reachable right now receive a question card".
18
16
  *
19
17
  * The claim on `user-questions/request` follows the same rules, with three
20
18
  * differences that belong to the host's own semantics: delegating is not a
@@ -24,6 +22,14 @@
24
22
  * to answer with; and the claim outlives the last paired device by a grace
25
23
  * window, because a phone whose app the system suspended has refused nothing.
26
24
  *
25
+ * Claiming is not swallowing any more. Both claims hand the same question to the
26
+ * host's own answerer chain the instant they exist, so the phone and the host's
27
+ * own panel hold one card each and the first answer settles it. Yielding is not
28
+ * delegating: the phone's card is only over once the other side really answered,
29
+ * which is why a question chain that rejects and an approval chain that falls
30
+ * through to its fail-closed `'unavailable'` end nothing here — the claim stays
31
+ * exactly as answerable as it was before the other surface existed.
32
+ *
27
33
  * A presented page (`ui_present`, protocol §35) is the second claim that takes a
28
34
  * grace window, and it takes the same one: the tool call it blocks is the agent's
29
35
  * own wait, the card is the only place its answer can come from, and a phone that
@@ -57,12 +63,22 @@ export interface ApprovalRequestLike {
57
63
  }
58
64
  /** The summary line a phone shows for one question. */
59
65
  export declare function approvalSummary(request: ApprovalRequestLike): string;
66
+ /**
67
+ * Whether an approval card is still the phone's to answer, or already over.
68
+ *
69
+ * A field of the payload rather than a second topic: a client written before it
70
+ * knows no such key, so it reads exactly the frame it always read and the
71
+ * question simply stays on screen until it is answered or refused.
72
+ */
73
+ export type ApprovalState = 'open' | 'settled';
60
74
  /** The `approval.request` payload one claim is published with. */
61
75
  export interface ApprovalRequestPayload {
62
76
  readonly sessionId: string;
63
77
  readonly id: string;
64
78
  readonly summary: string;
65
79
  readonly toolName: string;
80
+ /** Absent means `open`, which is what every frame published before this field carries. */
81
+ readonly state?: ApprovalState;
66
82
  }
67
83
  /**
68
84
  * How long a user question outlives the last paired device, in milliseconds.
@@ -79,28 +95,12 @@ export interface ApprovalRequestPayload {
79
95
  */
80
96
  export declare const QUESTION_CLAIM_GRACE_MS = 60000;
81
97
  /**
82
- * How long a user question is held for a phone this bridge reached by
83
- * notification only, in milliseconds (§32.2).
98
+ * What the hub is built with: the bridge's shared options.
84
99
  *
85
- * Inside this window the question exists only on the phone's side: the alert is
86
- * out, no socket has it, and the host's own answerer chain has not been started.
87
- * When it runs out the claim is withdrawn and delegated, so the agent behind a
88
- * timed ask waits at most this long past its own deadline and the agent behind a
89
- * blocking ask (no call id, no deadline) waits at most this long in total — an
90
- * accepted cost, because the alternative is a question that vanished while the
91
- * phone was asleep. The window is the bridge's own constant and not the host's:
92
- * a deployment overrides it, the host never sees it.
100
+ * A named type of its own so a suite can build a hub without the whole plugin,
101
+ * and so the options this class reads stay one declaration.
93
102
  */
94
- export declare const OFFLINE_QUESTION_CLAIM_TTL_MS = 600000;
95
- /** What the hub is built with: the bridge's shared options plus the windows it owns. */
96
103
  export interface BridgeHubOptions extends BridgeConnectionOptions {
97
- /**
98
- * The offline claim window, in milliseconds.
99
- *
100
- * Defaults to {@link OFFLINE_QUESTION_CLAIM_TTL_MS}; a deployment knob, and the
101
- * seam a suite uses to move the window instead of waiting it out.
102
- */
103
- readonly offlineClaimTtlMs?: number;
104
104
  }
105
105
  /**
106
106
  * What one `ui_present` call ended as, with the count of connections that took
@@ -193,9 +193,14 @@ export declare class BridgeHub {
193
193
  broadcastTo(capability: string, topic: string, payload: unknown): number;
194
194
  /**
195
195
  * The body of this plugin's `approval/request` listener.
196
+ *
197
+ * The claim yields the moment it exists: the host's own panel is offered the
198
+ * same question, so the phone and the panel hold one card each and the first
199
+ * answer decides. A panel that answers first ends the phone's claim and the phone
200
+ * is told; a phone that answers first leaves the panel's later answer ignored.
196
201
  * @param request - the pending question.
197
202
  * @param next - the rest of the answerer chain.
198
- * @returns a claimed decision, or whatever the next answerer says.
203
+ * @returns the first decision, or whatever the next answerer says.
199
204
  */
200
205
  approve(request: ApprovalRequestLike, next: () => Promise<ApprovalOutcome>): Promise<ApprovalOutcome>;
201
206
  /**
@@ -209,9 +214,11 @@ export declare class BridgeHub {
209
214
  * host's own when the ask is timed, and minted here when it is blocking and the
210
215
  * host assigned none — either way the phone answers the id it was shown. A claim
211
216
  * nobody received is withdrawn at once instead of holding the agent until the
212
- * host's deadline. For a timed ask the host's own remaining wait travels with
213
- * the first frame as `expiresAt`, and every later move of that deadline is
214
- * re-published under the same call id.
217
+ * host's deadline. The host's own answerer chain is entered the instant the
218
+ * claim exists, in every mode, so the host's panel shows the same question and
219
+ * the first answer settles both. For a timed ask the host's own remaining wait
220
+ * travels with the first frame as `expiresAt`, and every later move of that
221
+ * deadline is re-published under the same call id.
215
222
  * @param request - the pending question batch.
216
223
  * @param next - the rest of the answerer chain.
217
224
  * @returns the phone's answer, the host's own deadline outcome, or whatever the next answerer says.
@@ -57,15 +57,23 @@ export interface QuestionItem {
57
57
  readonly options?: readonly QuestionOption[];
58
58
  readonly multiSelect?: boolean;
59
59
  }
60
- /** One item of the answer batch. */
60
+ /**
61
+ * One item of the answer batch. `selected` is a mutable array because the host's
62
+ * own answer item declares it mutable, and a readonly array is not assignable to
63
+ * a mutable one - the host's `user-questions/request` handler is typed with its
64
+ * own answer type, so this mirror has to stay assignable to it.
65
+ */
61
66
  export interface QuestionAnswerItem {
62
67
  readonly id: string;
63
- readonly selected: readonly string[];
68
+ readonly selected: string[];
64
69
  readonly custom?: string;
65
70
  }
66
- /** The whole answer batch the host's ask is settled with. */
71
+ /**
72
+ * The whole answer batch the host's ask is settled with. `answers` is mutable for
73
+ * the same reason {@link QuestionAnswerItem} keeps `selected` mutable.
74
+ */
67
75
  export interface QuestionAnswer {
68
- readonly answers: readonly QuestionAnswerItem[];
76
+ readonly answers: QuestionAnswerItem[];
69
77
  }
70
78
  /**
71
79
  * The `question.request` payload for one claim, and the `payload` of every
@@ -170,6 +178,14 @@ export interface ClaimedQuestionView {
170
178
  export interface ClaimedQuestion extends ClaimedQuestionView {
171
179
  /** The host's ask: the phone's answer, or whatever the next answerer says. */
172
180
  readonly answer: Promise<QuestionAnswer>;
181
+ /**
182
+ * Hand the same question to the host's own answerer chain, once.
183
+ *
184
+ * Called by the hub the instant a claim exists, in every mode: the phone is
185
+ * not the only surface any more, so the host's own panel shows the card too
186
+ * and the first answer settles it.
187
+ */
188
+ readonly startHostChain: () => void;
173
189
  /**
174
190
  * Epoch milliseconds at which the host's own deadline falls, from the first
175
191
  * wait frame of this claim.
@@ -24,9 +24,8 @@
24
24
  * `question.answer` settles the host's own ask while it is open, or reaches a
25
25
  * continued question through the host's Remote `answer`. With no paired
26
26
  * connection on the wire the claim is still made when a roster device registered
27
- * for notifications, which is reached by the alert and holds the question for one
28
- * window before it goes back to the host's chain (§11.3, §32). Every other case
29
- * delegates, and a timed question keeps the Host's own deadline.
27
+ * for notifications, and the alert is then its delivery (§11.3, §32). Every other
28
+ * case delegates, and a timed question keeps the Host's own deadline.
30
29
  *
31
30
  * The browser half lives in `src/client/` and is declared by `dsh.client`: one
32
31
  * sidebar-foot panel that reads the same loopback-gated token route over a
@@ -67,19 +66,6 @@ export declare const ROSTER_PATH = "remote-bridge/devices.json";
67
66
  * than to any one session, and it outlives every process (core/model-efforts.ts).
68
67
  */
69
68
  export declare const EFFORT_PATH = "remote-bridge/model-efforts.json";
70
- /** The environment variable that moves the offline claim window (§32.2). */
71
- export declare const OFFLINE_CLAIM_TTL_ENV = "DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TTL_MS";
72
- /**
73
- * The offline claim window this process runs with.
74
- *
75
- * The window is the bridge's own constant and never a host fact, so a deployment
76
- * moves it here. A value that is missing, unreadable or not positive falls back to
77
- * the constant instead of closing the window: a zero window would silently switch
78
- * the channel off, and an operator who wanted that would be turning off push.
79
- * @param env - the process environment, injectable for a suite.
80
- * @returns the window in milliseconds.
81
- */
82
- export declare function offlineClaimTtl(env?: NodeJS.ProcessEnv): number;
83
69
  /**
84
70
  * The environment variable that moves when a still-waiting turn end is reported (§28).
85
71
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-remote-bridge",
3
3
  "description": "DSH remote bridge: the host half serves protocol v1 over one exact /ios/v1 WebSocket route — session roster, history baseline, prompting, live turn increments with tool activity, interrupt, and in-process agent approval — to a device paired by a one-shot bootstrap token and a P-256 challenge-response, with the token endpoint admitted only from this machine; the browser half adds one sidebar-foot panel that shows that same one-shot token as a QR symbol and draws an interactive card inside the tool row without answering it, and adds no wire surface",
4
- "version": "0.4.15",
4
+ "version": "0.4.16",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
7
7
  "engines": {
@@ -132,6 +132,19 @@ export class ApprovalRegistry {
132
132
  return this.#settle(id, decision) !== undefined
133
133
  }
134
134
 
135
+ /**
136
+ * Release one question the host's own panel answered first.
137
+ *
138
+ * The release is not a decision: the panel's answer travels back through the
139
+ * answerer chain it came from, so the claim only has to stop being pending —
140
+ * which is what also makes a later answer from the phone refuse as unknown
141
+ * instead of settling a question that is already over.
142
+ * @returns whether this call released it; false when the phone already had.
143
+ */
144
+ releaseToHost(id: string): boolean {
145
+ return this.#settle(id, undefined) === true
146
+ }
147
+
135
148
  /**
136
149
  * Withdraw the named questions, delegating each to the next answerer.
137
150
  * @returns how many were still pending.
@@ -605,7 +605,7 @@ function capabilitiesOf(value: unknown): ReadonlySet<string> {
605
605
  * @param value - the request's `answers` member, or undefined.
606
606
  * @returns the batch in protocol vocabulary, or undefined when it is not one.
607
607
  */
608
- function answersOf(value: unknown): readonly QuestionAnswerItem[] | undefined {
608
+ function answersOf(value: unknown): QuestionAnswerItem[] | undefined {
609
609
  if (!Array.isArray(value)) return undefined
610
610
  const answers: QuestionAnswerItem[] = []
611
611
  for (const entry of value) {