@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.
package/README.i18n.yaml CHANGED
@@ -2,5 +2,5 @@
2
2
  # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
3
  # after editing either side, bring the other along and re-record with:
4
4
  # node scripts/verify-docs.mjs --write <dir>
5
- README.md: ce70588a1ac33a05084dd22daaf15f62be8d0f62
6
- README.zh.md: 8bad871cc6d2021b108e1d07807caaa6daa59f12
5
+ README.md: 697ff27093520de35e6fa631fcb50581daeff7a5
6
+ README.zh.md: 1c1a6d7ea5df84a6044b1a83009c8160b1bf3600
package/README.md CHANGED
@@ -135,7 +135,7 @@ A compact listing is the roster's other form, and it takes both halves to appear
135
135
 
136
136
  An `approval.request` carries a summary taken from the harness's display reason in the client's language, falling back to English and then to the tool name, plus the tool name itself. The client answers it with `approval.resolve`, whose `decision` is either `allowed-once` or `rejected`; an unknown or expired `id` is refused, and a request nobody answers is resolved after two minutes as unavailable, which the harness reads as a rejection. Every paired connection receives the event the moment the tool asks — the first broadcast is behind no capability — and a connection that declared `approvals.v1` in `hello` is handed every still-waiting request again, so a phone that reconnected, or a session screen opened after the fact, still holds a card. Only an unsettled request is replayed: one that was answered, timed out or withdrawn is gone from the claim registry, and re-handing a request never moves its two-minute deadline. The capability gates that second delivery and nothing else, which is why it is absent from `hello`'s `capabilities` and leaves `minor` alone: the handshake answers every client the same frame. The bridge claims an approval request only while a paired client is connected: with none, the request is left to the next answerer instead of waiting out a phone that is not there.
137
137
 
138
- The question channel is the one claim that outlives the socket. A question arrives as a `question.request` event under the host's own call id, or under one this bridge mints when a blocking ask carries none, and `question.answer` settles the host's ask: while that ask is still open the answer resolves the promise the bridge holds, and once the host's deadline has released the model a late answer takes the host's Remote `answer` path instead. `question.list` answers the questions the bridge is still holding, which is what a phone reconciles the cards it carries against. With no paired connection on the wire, but a device on the roster that registered for push, the bridge claims the question for that phone and the alert is its delivery: for one bridge-owned window the question exists only on the phone's side, and when the window ends it goes back to the host's own answerer chain. The window is `OFFLINE_QUESTION_CLAIM_TTL_MS`, ten minutes, overridable with `DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TTL_MS`. Inside it a phone that reconnects and declares `questions.v1` is handed the live claim and the window ends there; a phone that answers settles it, and the host's chain is then never started; and a hello from a paired connection that did not declare the channel releases the claim at once, because a claim nobody on the wire can receive is not kept. A blocking ask — no call id, no deadline — is claimed the same way, and its cost is stated rather than hidden: the agent behind it waits at most that window. Approvals keep the stricter rule above, where nothing is ever held for a phone that is not on the wire.
138
+ The question channel is the one claim that outlives the socket. A question arrives as a `question.request` event under the host's own call id, or under one this bridge mints when a blocking ask carries none, and `question.answer` settles the host's ask: while that ask is still open the answer resolves the promise the bridge holds, and once the host's deadline has released the model a late answer takes the host's Remote `answer` path instead. Claiming yields to the host's own answerer chain the instant the claim exists, so both sides hold the card and the first answer wins: a host answer broadcasts `question.request` with `state:"settled"` and releases the claim, while a phone answer resolves the bridge's promise and leaves a later host settlement ignored; a host chain that rejects is not a verdict and leaves the claim answerable. `question.list` answers the questions the bridge is still holding, which is what a phone reconciles the cards it carries against. With no paired connection on the wire, but a device on the roster that registered for push, the bridge still claims the question, sends the alert when no live browser client is connected, and yields to the host's answerer chain at once: the claim lives until it is answered, the host's deadline ends it, or the bridge unloads, and it is given up if APNs refuses every registered token on the roster. Approvals keep the stricter rule above, where nothing is ever claimed for a phone that is not on the wire.
139
139
 
140
140
  The interactive-reply channel is the one place a page travels instead of a question. `ui_present` is this bridge's own model tool: the agent writes one whole self-contained document (`<!doctype html>` first, at most 256 KiB of UTF-8) and it crosses as a `ui.request` event under the host's own `ToolCallId`, so the card hangs on the same tool-call row the transcript already draws. The call then blocks until the user's FIRST action inside the page arrives, and that action — `{type, payload?}` with `type` the page's own closed set and `payload` at most 8 KiB — is the tool call's result: one card settles one action, and a page that should keep taking them is presented again. The card is announced over as `state:"settled"` to every client that declared `ui.v1`, including the one that acted, so a second tap on the phone and a second phone both learn it is over. `ui.list` answers the cards this bridge still holds, which is what a phone reconciles against after a restart, and only a complete answer may retire one. A card never carries `expiresAt`: the tool schema declares no `timeout`, so this bridge invents no deadline, and it takes the same grace window as a question instead — a page nobody can answer any more is released to the agent as a timeout when the window the last paired device left behind runs out, and a phone that declares the channel inside that window is handed the live card and cancels the release. With no paired connection that declared `ui.v1`, `ui_present` answers `{ok:false, reason:"unavailable"}` at once instead of holding the agent. Every result of a page that did reach the wire carries the presentation payload as `meta.ui` — `{key, title?, html, height?, state}` with `key` spelled `"<sessionId>/<callId>"` — for a client that renders the card out of the transcript and holds no `ui.request` socket; the body of the result stays one human sentence.
141
141
 
@@ -276,7 +276,7 @@ The plugin is configured through profile YAML (`cordis.patch.yml` or profile con
276
276
 
277
277
  ## Web GUI pairing panel
278
278
 
279
- The browser half exists so that an operator who never opens a terminal still has a way to start pairing. It follows the family's sidebar-foot convention: the trigger registers into the official `sidebar.footer.action` list slot (declared by ui-sidebar, sharing this list slot with `dsh-update`'s updater) and opens the official `Modal`, whose headless card this package fills. Every control it renders is a library primitive — the dialog, the three actions and their glyphs — so the mask, the card, the focus trap, Escape, focus restoration and each hover/focus/disabled state are the shell's behavior rather than a copy of it. It is delivered by the same plugin row: `exports["./client"]` is the artifact and `dsh.client` declares the client modules that must be live first.
279
+ The browser half exists so that an operator who never opens a terminal still has a way to start pairing. It follows the family's sidebar-foot convention: the trigger registers into the official `sidebar.footer.action` list slot (declared by ui-sidebar, the same list slot the family's other foot triggers use) and opens the official `Modal`, whose headless card this package fills. Every control it renders is a library primitive — the dialog, the three actions and their glyphs — so the mask, the card, the focus trap, Escape, focus restoration and each hover/focus/disabled state are the shell's behavior rather than a copy of it. It is delivered by the same plugin row: `exports["./client"]` is the artifact and `dsh.client` declares the client modules that must be live first.
280
280
 
281
281
  The panel has one job — put the live one-time code in front of the operator, in one reading order:
282
282
 
package/README.zh.md CHANGED
@@ -132,7 +132,7 @@ fork 的方法同样什么都不解释。`session.fork` 把 `sessionId` 与客
132
132
 
133
133
  `approval.request` 的摘要取自宿主按客户端语言给出的显示理由,缺失时回落英文、再回落工具名,并附带工具名本身。客户端用 `approval.resolve` 作答,`decision` 取 `allowed-once` 或 `rejected`;未知或过期的 `id` 会被拒绝,而无人应答的请求在两分钟后按 unavailable 结算,宿主视之为拒绝。工具发起请求的那一刻,每一条已配对连接都会收到该事件——首播不在任何能力名之后——而声明了 `approvals.v1` 的连接会在 `hello` 之后再次收到所有仍在等待的请求,因此重连过的手机、或事后才打开该会话的界面,手里依然有卡片。只有未结算的请求会被重放:已作答、已超时、已撤回的请求早已离开认领表,而重新递一次请求绝不会挪动它的两分钟截止时间。该能力只门控这第二次送达,因此它不出现在 `hello` 的 `capabilities` 里、也不改动 `minor`:握手对每个客户端都回同一个帧。桥只在下游有已配对客户端连接时才认领审批请求:一个都没有时,请求交给下一个应答者,而不是干等一台不在场的手机。
134
134
 
135
- 提问通道是唯一一条能比套接字活得久的认领。提问以 `question.request` 事件到达手机,call id 用宿主自己的;阻塞式提问没有 call id,就由本桥另铸一个。手机用 `question.answer` 结算宿主的询问:询问仍然开着时,答案直接解开本桥手里的 promise;宿主自己的截止时间已经放走模型之后,迟到的答案改走宿主的 Remote `answer`。`question.list` 回答本桥此刻仍持有的提问,手机据此与手里的卡对账。没有任何已配对连接在线、但设备名册里有登记过推送令牌时,桥替那台手机认领这道题,推送就是它的送达:在桥自有的一个窗口内,这道题只存在于手机侧,窗口结束即回到宿主自己的应答者链。这个窗口是 `OFFLINE_QUESTION_CLAIM_TTL_MS`,十分钟,可用 `DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TTL_MS` 覆盖。窗口内重连并声明 `questions.v1` 的手机直接拿到这条仍然有效的认领,窗口到此为止;手机作答即结算,宿主链于是从未启动;而已配对连接完成 `hello` 却没有声明这条通道时,认领立刻被撤回——线上没人能收的认领不留。阻塞式提问(无 call id、无 deadline)同样认领,代价写在明处:它背后的 agent 最多白等这一个窗口。审批沿用上面更严的那条规则:永远不为不在线上的手机持有任何东西。
135
+ 提问通道是唯一一条能比套接字活得久的认领。提问以 `question.request` 事件到达手机,call id 用宿主自己的;阻塞式提问没有 call id,就由本桥另铸一个。手机用 `question.answer` 结算宿主的询问:询问仍然开着时,答案直接解开本桥手里的 promise;宿主自己的截止时间已经放走模型之后,迟到的答案改走宿主的 Remote `answer`。认领成立即刻让位给宿主自己的应答者链,两端同时持有卡片,先答者胜:宿主链先答时,桥向已声明 `questions.v1` 的连接广播 `state:"settled"` 的 `question.request` 并释放认领;手机先答时,桥返回手机的答案并忽略宿主链随后到达的结算;宿主链 reject 不是判决,认领保留,手机仍可作答。`question.list` 回答本桥此刻仍持有的提问,手机据此与手里的卡对账。没有任何已配对连接在线、但设备名册里有登记过推送令牌的设备时,桥照旧替那台手机认领这道题、在宿主没有在线浏览器客户端时发推送,并立刻让位给宿主自己的应答者链:认领活到被答、宿主自己的截止时间到点或本桥卸载;若 APNs 对名册上每个已登记令牌都拒绝,则放弃这次认领。审批沿用上面更严的那条规则:永远不为不在线上的手机认领任何东西。
136
136
 
137
137
  可交互回复是唯一一条「走一整页而不是走一个问题」的通道。`ui_present` 是本桥自己的模型工具:agent 写一整份自包含文档(以 `<!doctype html>` 开头,UTF-8 最多 256 KiB),它作为 `ui.request` 事件、用宿主自己的 `ToolCallId` 下发,于是这张卡正好挂在转录里那条工具调用行上。随后这次调用阻塞,直到用户在页面里的**第一条**动作为止——那个动作 `{type, payload?}`(`type` 是页面自己的闭集,`payload` 最多 8 KiB)就是这次工具调用的返回值:一张卡结算一个动作,需要继续接受动作就让 agent 再呈现一次。结算时这条卡以 `state:"settled"` 对每个声明了 `ui.v1` 的客户端再公告一次(包括刚作答的那台),所以手机上重复的第二次点击、以及第二台手机都能读到它已结束。`ui.list` 回答本桥此刻仍持有的卡,是手机重启后的对账依据,且只有 `complete` 的应答才允许退休一张卡。卡永不携带 `expiresAt`:工具 schema 不声明 `timeout`,本桥也就不发明超时;它拿的是与提问同一个宽限窗口——再没有人能作答的卡在「最后一次配对设备离开」留下的窗口到期时,以超时交还给 agent,而在这个窗口内声明了通道的手机则被重放活卡、并取消这次释放。没有任何声明了 `ui.v1` 的已配对连接时,`ui_present` 立即回 `{ok:false, reason:"unavailable"}`,不占用宿主的等待。真的到过线缆上的那次呈现,其结果在 `meta.ui` 里带着同一份展示载荷——`{key, title?, html, height?, state}`,`key` 是 `"<sessionId>/<callId>"` 拼法——供从转录渲染、手里没有 `ui.request` socket 的客户端使用;结果正文仍是一句人可读的话。
138
138
 
@@ -273,7 +273,7 @@ curl -s http://127.0.0.1:3080/remote-bridge/pair/token
273
273
 
274
274
  ## Web GUI 配对面板
275
275
 
276
- 浏览器半区存在的理由,是让从不开终端的操作者也有一条发起配对的路径。它沿用家族在侧栏底部的惯例:触发器注册进官方 `sidebar.footer.action` 列表槽位(由 ui-sidebar 声明,与 `dsh-update` 的更新器共用该列表槽位),点开后是官方 `Modal`,这张无头卡片由本包填充。它渲染的每个控件都是库里已有的 primitive——弹窗、三个动作与它们的字形——因此遮罩、卡片、焦点圈定、Esc、焦点归还,以及每个 hover/focus/disabled 状态都是官方壳自己的行为,而不是本包的一份复制品。它由同一插件行承载:产物是 `exports["./client"]`,`dsh.client` 声明必须先就位的 client 模块。
276
+ 浏览器半区存在的理由,是让从不开终端的操作者也有一条发起配对的路径。它沿用家族在侧栏底部的惯例:触发器注册进官方 `sidebar.footer.action` 列表槽位(由 ui-sidebar 声明,与家族其它脚部触发器共用该列表槽位),点开后是官方 `Modal`,这张无头卡片由本包填充。它渲染的每个控件都是库里已有的 primitive——弹窗、三个动作与它们的字形——因此遮罩、卡片、焦点圈定、Esc、焦点归还,以及每个 hover/focus/disabled 状态都是官方壳自己的行为,而不是本包的一份复制品。它由同一插件行承载:产物是 `exports["./client"]`,`dsh.client` 声明必须先就位的 client 模块。
277
277
 
278
278
  面板只做一件事——把活着的那个一次性配对码摆到操作者面前,且只有这一个阅读顺序:
279
279
 
package/lib/index.js CHANGED
@@ -215,6 +215,18 @@ var ApprovalRegistry = class {
215
215
  return this.#settle(id, decision) !== void 0;
216
216
  }
217
217
  /**
218
+ * Release one question the host's own panel answered first.
219
+ *
220
+ * The release is not a decision: the panel's answer travels back through the
221
+ * answerer chain it came from, so the claim only has to stop being pending —
222
+ * which is what also makes a later answer from the phone refuse as unknown
223
+ * instead of settling a question that is already over.
224
+ * @returns whether this call released it; false when the phone already had.
225
+ */
226
+ releaseToHost(id) {
227
+ return this.#settle(id, void 0) === true;
228
+ }
229
+ /**
218
230
  * Withdraw the named questions, delegating each to the next answerer.
219
231
  * @returns how many were still pending.
220
232
  */
@@ -8105,6 +8117,19 @@ var QuestionClaims = class {
8105
8117
  resolveDeadline(void 0);
8106
8118
  }
8107
8119
  };
8120
+ /**
8121
+ * Hand this claim to the host's own answerers, once.
8122
+ *
8123
+ * Both surfaces are shown the question and the first answer settles it: an
8124
+ * answer from the chain ends the claim here, and an answer from the phone
8125
+ * ends it in {@link answer} — which leaves the chain's later answer ignored
8126
+ * instead of settling or broadcasting a second time.
8127
+ */
8128
+ const startHostChain = () => {
8129
+ startNext().then((answer) => {
8130
+ this.#settleFromHost(input.callId, answer);
8131
+ }, () => void 0);
8132
+ };
8108
8133
  this.#claims.set(input.callId, record);
8109
8134
  if (signal?.aborted === true) onAbort();
8110
8135
  else signal?.addEventListener("abort", onAbort, { once: true });
@@ -8113,7 +8138,8 @@ var QuestionClaims = class {
8113
8138
  return {
8114
8139
  ...viewOf(record),
8115
8140
  answer,
8116
- deadline
8141
+ deadline,
8142
+ startHostChain
8117
8143
  };
8118
8144
  }
8119
8145
  /**
@@ -8232,6 +8258,26 @@ var QuestionClaims = class {
8232
8258
  }
8233
8259
  }
8234
8260
  /**
8261
+ * Settle one claim from the host's own answerer chain.
8262
+ *
8263
+ * Only a claim this bridge still holds can be ended this way: a phone that
8264
+ * answered first deletes it, and the chain's late answer must not settle it a
8265
+ * second time or announce a card that is already gone. A claim the host's own
8266
+ * deadline turned into `continued` is left alone as well — its answer promise
8267
+ * is that deadline, and the phone's late answer still has its own road.
8268
+ * @param callId - the claim the host answered.
8269
+ * @param answer - the host's own answer.
8270
+ */
8271
+ #settleFromHost(callId, answer) {
8272
+ const record = this.#claims.get(callId);
8273
+ if (record === void 0 || record.state !== "open") return;
8274
+ this.#claims.delete(callId);
8275
+ record.detach();
8276
+ record.stopWait();
8277
+ record.notifySettled();
8278
+ record.settle(answer);
8279
+ }
8280
+ /**
8235
8281
  * Settle one open claim from the host's own cancellation lifetime.
8236
8282
  *
8237
8283
  * The reason is propagated verbatim, so the host's deadline still maps to its
@@ -8261,17 +8307,22 @@ function approvalSummary(request) {
8261
8307
  /**
8262
8308
  * The `approval.request` payload for one claim.
8263
8309
  *
8264
- * The first broadcast and the replay of a still-open claim go through this one
8265
- * function, so the card a phone was originally shown and the same card handed to
8266
- * it again after a reconnect cannot drift apart.
8310
+ * The first broadcast, the replay of a still-open claim and the notice that the
8311
+ * host's own panel answered it all go through this one function, so the card a
8312
+ * phone was originally shown and the same card handed to it again after a
8313
+ * reconnect cannot drift apart. `state` is published only when it is not the
8314
+ * default, so every frame that existed before it is byte for byte what it was.
8267
8315
  * @param prompt - the claim being published.
8316
+ * @param state - `open` for a question a phone can answer, `settled` for the
8317
+ * notice that the host's own panel answered it first.
8268
8318
  */
8269
- function approvalPayload(prompt) {
8319
+ function approvalPayload(prompt, state = "open") {
8270
8320
  return {
8271
8321
  sessionId: prompt.sessionId,
8272
8322
  id: prompt.id,
8273
8323
  summary: prompt.summary,
8274
- toolName: prompt.toolName
8324
+ toolName: prompt.toolName,
8325
+ ...state === "open" ? {} : { state }
8275
8326
  };
8276
8327
  }
8277
8328
  /**
@@ -8288,20 +8339,6 @@ function approvalPayload(prompt) {
8288
8339
  * expiry exactly as it was before.
8289
8340
  */
8290
8341
  const QUESTION_CLAIM_GRACE_MS = 6e4;
8291
- /**
8292
- * How long a user question is held for a phone this bridge reached by
8293
- * notification only, in milliseconds (§32.2).
8294
- *
8295
- * Inside this window the question exists only on the phone's side: the alert is
8296
- * out, no socket has it, and the host's own answerer chain has not been started.
8297
- * When it runs out the claim is withdrawn and delegated, so the agent behind a
8298
- * timed ask waits at most this long past its own deadline and the agent behind a
8299
- * blocking ask (no call id, no deadline) waits at most this long in total — an
8300
- * accepted cost, because the alternative is a question that vanished while the
8301
- * phone was asleep. The window is the bridge's own constant and not the host's:
8302
- * a deployment overrides it, the host never sees it.
8303
- */
8304
- const OFFLINE_QUESTION_CLAIM_TTL_MS = 6e5;
8305
8342
  /** The bridge's live connections plus the answerer it composes onto the approval chain. */
8306
8343
  var BridgeHub = class {
8307
8344
  #options;
@@ -8313,16 +8350,6 @@ var BridgeHub = class {
8313
8350
  */
8314
8351
  #questionReleaseTimer;
8315
8352
  /**
8316
- * The offline claims still waiting on a phone, by wire call id, each with the
8317
- * timer that holds it for its window.
8318
- *
8319
- * A question leaves this table the moment the phone takes it over, answers it,
8320
- * or the window releases it, so a call id in here is a question no reachable
8321
- * device has been shown — which is exactly what {@link #reviewOfflineClaims}
8322
- * withdraws when a hello makes that permanent.
8323
- */
8324
- #offlineClaims = /* @__PURE__ */ new Map();
8325
- /**
8326
8353
  * 整页卡(§35)的那一个释放窗口。卡表是全局的,所以一个定时器覆盖每一张卡,
8327
8354
  * 同一时刻只可能有一个;它与 {@link #questionReleaseTimer} 各管各的通道。
8328
8355
  */
@@ -8348,7 +8375,6 @@ var BridgeHub = class {
8348
8375
  this.replayQuestions(fresh);
8349
8376
  this.replayApprovals(fresh);
8350
8377
  this.replayUi(fresh);
8351
- this.#reviewOfflineClaims();
8352
8378
  }
8353
8379
  }, transport, auth);
8354
8380
  this.#connections.add(connection);
@@ -8392,7 +8418,6 @@ var BridgeHub = class {
8392
8418
  */
8393
8419
  replayQuestions(connection) {
8394
8420
  if (!connection.paired || !connection.declares("questions.v1")) return;
8395
- this.#cancelOfflineClaims();
8396
8421
  for (const held of this.#options.questions.listed()) connection.emit(TOPIC_QUESTION_REQUEST, held.payload);
8397
8422
  }
8398
8423
  /**
@@ -8449,9 +8474,14 @@ var BridgeHub = class {
8449
8474
  }
8450
8475
  /**
8451
8476
  * The body of this plugin's `approval/request` listener.
8477
+ *
8478
+ * The claim yields the moment it exists: the host's own panel is offered the
8479
+ * same question, so the phone and the panel hold one card each and the first
8480
+ * answer decides. A panel that answers first ends the phone's claim and the phone
8481
+ * is told; a phone that answers first leaves the panel's later answer ignored.
8452
8482
  * @param request - the pending question.
8453
8483
  * @param next - the rest of the answerer chain.
8454
- * @returns a claimed decision, or whatever the next answerer says.
8484
+ * @returns the first decision, or whatever the next answerer says.
8455
8485
  */
8456
8486
  async approve(request, next) {
8457
8487
  if (this.pairedClients === 0) return await next();
@@ -8464,11 +8494,12 @@ var BridgeHub = class {
8464
8494
  });
8465
8495
  if (this.broadcast("approval.request", approvalPayload(prompt)) === 0) this.#options.approvals.abandon([prompt.id]);
8466
8496
  else {
8467
- this.#options.push?.notify("approval", sessionId);
8497
+ if (!this.#hasLiveClient()) this.#options.push?.notify("approval", sessionId);
8468
8498
  this.#options.liveActivity?.noteApproval(sessionId);
8469
8499
  }
8500
+ const chain = this.#startApprovalChain(prompt, next);
8470
8501
  const answer = await prompt.answer;
8471
- return answer === void 0 ? await next() : answer;
8502
+ return answer === void 0 ? await chain : answer;
8472
8503
  }
8473
8504
  /**
8474
8505
  * The body of this plugin's `user-questions/request` listener.
@@ -8481,9 +8512,11 @@ var BridgeHub = class {
8481
8512
  * host's own when the ask is timed, and minted here when it is blocking and the
8482
8513
  * host assigned none — either way the phone answers the id it was shown. A claim
8483
8514
  * nobody received is withdrawn at once instead of holding the agent until the
8484
- * host's deadline. For a timed ask the host's own remaining wait travels with
8485
- * the first frame as `expiresAt`, and every later move of that deadline is
8486
- * re-published under the same call id.
8515
+ * host's deadline. The host's own answerer chain is entered the instant the
8516
+ * claim exists, in every mode, so the host's panel shows the same question and
8517
+ * the first answer settles both. For a timed ask the host's own remaining wait
8518
+ * travels with the first frame as `expiresAt`, and every later move of that
8519
+ * deadline is re-published under the same call id.
8487
8520
  * @param request - the pending question batch.
8488
8521
  * @param next - the rest of the answerer chain.
8489
8522
  * @returns the phone's answer, the host's own deadline outcome, or whatever the next answerer says.
@@ -8515,6 +8548,7 @@ var BridgeHub = class {
8515
8548
  }
8516
8549
  });
8517
8550
  if (claim === void 0) return await next();
8551
+ claim.startHostChain();
8518
8552
  if (mode === "offline") return await this.#holdOfflineClaim(sessionId, callId, claim);
8519
8553
  const expiresAt = await claim.deadline;
8520
8554
  if (this.#options.questions.stateOf(callId) !== "open") return await claim.answer;
@@ -8523,7 +8557,7 @@ var BridgeHub = class {
8523
8557
  expiresAt
8524
8558
  })) === 0) this.#options.questions.withdraw([callId]);
8525
8559
  else {
8526
- this.#options.push?.notify("question", sessionId);
8560
+ if (!this.#hasLiveClient()) this.#options.push?.notify("question", sessionId);
8527
8561
  const first = request.questions[0];
8528
8562
  this.#options.liveActivity?.noteQuestion(sessionId, {
8529
8563
  ...first?.header === void 0 ? {} : { header: first.header },
@@ -8596,7 +8630,6 @@ var BridgeHub = class {
8596
8630
  }
8597
8631
  /** Close every connection and withdraw every question. Idempotent. */
8598
8632
  dispose() {
8599
- this.#releaseOfflineClaims("the bridge unloaded");
8600
8633
  this.#cancelQuestionRelease();
8601
8634
  this.#cancelUiRelease();
8602
8635
  for (const connection of [...this.#connections]) {
@@ -8634,11 +8667,8 @@ var BridgeHub = class {
8634
8667
  /**
8635
8668
  * Which path a user question takes right now (§11.3).
8636
8669
  *
8637
- * The one entry, read twice: when a question arrives, and again when a paired
8638
- * connection finishes its hello while an offline claim is still held. Both
8639
- * moments ask the same thing — can a device that is reachable right now receive
8640
- * a question card — and answering it in two places is how two answers drift
8641
- * apart.
8670
+ * The one judgement behind both deliveries: can a device that is reachable
8671
+ * right now receive a question card, or does the alert have to stand in for it.
8642
8672
  * @returns `online` for the ordinary claim-and-broadcast path, `offline` for a
8643
8673
  * claim held for a phone reached by notification, and `nobody` when the question
8644
8674
  * has to go straight to the next answerer.
@@ -8651,28 +8681,23 @@ var BridgeHub = class {
8651
8681
  return (push.mode === "relay" ? this.#options.roster.relayTargets() : this.#options.roster.pushTargets()).length > 0 ? "offline" : "nobody";
8652
8682
  }
8653
8683
  /**
8654
- * Hold one question for a phone that is not on the wire (§32).
8684
+ * Claim one question for a phone that is not on the wire (§32).
8655
8685
  *
8656
8686
  * No socket is paired, so this claim's own first frame would reach nobody: the
8657
- * notification IS its delivery, and it is sent whether or not a broadcast would
8658
- * have landed. Inside the window the question exists only on the phone's side;
8659
- * the phone that comes back is handed the card by the replay in `onDeclare`,
8660
- * and the phone that answers settles it through the ordinary path.
8687
+ * notification IS its delivery. Nothing is held on the phone's behalf any more —
8688
+ * the host's own chain was offered the same question at claim time — so the
8689
+ * claim lives exactly as long as any other: until the phone answers it, the
8690
+ * host's deadline ends it, or this bridge unloads.
8661
8691
  * @param sessionId - the session that asked.
8662
8692
  * @param callId - the wire id the phone will answer under.
8663
8693
  * @param claim - the claim this bridge just opened.
8664
8694
  * @returns the phone's answer, or whatever the next answerer says.
8665
8695
  */
8666
8696
  async #holdOfflineClaim(sessionId, callId, claim) {
8667
- this.#armOfflineClaim(callId);
8668
- this.#options.push?.notify("question", sessionId, (report) => {
8697
+ if (!this.#hasLiveClient()) this.#options.push?.notify("question", sessionId, (report) => {
8669
8698
  this.#onQuestionPushed(callId, report);
8670
8699
  });
8671
- try {
8672
- return await claim.answer;
8673
- } finally {
8674
- this.#cancelOfflineClaim(callId);
8675
- }
8700
+ return await claim.answer;
8676
8701
  }
8677
8702
  /**
8678
8703
  * Read one alert's delivery report (§32.5).
@@ -8680,9 +8705,8 @@ var BridgeHub = class {
8680
8705
  * Three APNs answers are final about a registration: 410 with `Unregistered`, or
8681
8706
  * `Unregistered`/`BadDeviceToken` on any status. The device is cleaned off the
8682
8707
  * roster, and the claim is kept only while some other registered device is still
8683
- * there to be told; when the last one is gone the question cannot reach a phone
8684
- * at all, so it goes back to the host's chain now instead of at the end of a
8685
- * window nobody is left to use.
8708
+ * there to be told; when the last one is gone the claim is given up, because no
8709
+ * phone can be told this question exists.
8686
8710
  * @param callId - the offline claim this notification was about.
8687
8711
  * @param report - how the announcement ended.
8688
8712
  */
@@ -8692,7 +8716,7 @@ var BridgeHub = class {
8692
8716
  const survivors = (this.#options.push?.mode === "relay" ? this.#options.roster.relayTargets() : this.#options.roster.pushTargets()).filter(({ push }) => !dead.includes(push.deviceToken));
8693
8717
  this.#forgetDeadTokens(dead);
8694
8718
  if (survivors.length > 0) return;
8695
- this.#releaseOfflineClaim(callId, "APNs refused every device token on the roster");
8719
+ this.#releaseUnreachableClaim(callId, "APNs refused every device token on the roster");
8696
8720
  }
8697
8721
  /** Drop each dead registration from the roster, then let the watchers settle. */
8698
8722
  async #forgetDeadTokens(tokens) {
@@ -8705,73 +8729,74 @@ var BridgeHub = class {
8705
8729
  }
8706
8730
  }
8707
8731
  /**
8708
- * End every offline claim the wire has just made unreachable (§11.3).
8709
- *
8710
- * A hello that leaves no paired connection able to take a card — the client
8711
- * written before `questions.v1` going online — is the same fact the claim point
8712
- * reads, so it releases the claim at once instead of at the end of its window.
8713
- */
8714
- #reviewOfflineClaims() {
8715
- if (this.#offlineClaims.size === 0) return;
8716
- if (this.#questionMode() === "offline") return;
8717
- this.#releaseOfflineClaims("no paired connection on the wire can receive a question");
8718
- }
8719
- /**
8720
- * Arm the window that holds one offline claim.
8732
+ * Give up one claim no phone can be told about any more.
8721
8733
  *
8722
- * Deliberately a second timer beside {@link #armQuestionRelease}, never the same
8723
- * one: that window is the reconnect budget of a phone that just left, this one is
8724
- * the whole lifetime of a claim no phone ever had, and one claim can be governed
8725
- * by both in turn. Whichever is due first releases it, and the release is
8726
- * idempotent, so the later one finds no claim.
8727
- * @param callId - the claim to hold.
8728
- */
8729
- #armOfflineClaim(callId) {
8730
- if (this.#offlineClaims.has(callId)) return;
8731
- const ttl = this.#options.offlineClaimTtlMs ?? 6e5;
8732
- const timer = setTimeout(() => {
8733
- this.#releaseOfflineClaim(callId, "the offline claim window ended");
8734
- }, Math.max(0, ttl));
8735
- timer.unref?.();
8736
- this.#offlineClaims.set(callId, timer);
8737
- }
8738
- /** Drop one claim's window. The claim itself keeps whatever state it has. */
8739
- #cancelOfflineClaim(callId) {
8740
- const timer = this.#offlineClaims.get(callId);
8741
- if (timer === void 0) return;
8742
- clearTimeout(timer);
8743
- this.#offlineClaims.delete(callId);
8744
- }
8745
- /** Drop every offline window: a phone is on the wire for those claims now, or they are about to be released. */
8746
- #cancelOfflineClaims() {
8747
- for (const timer of this.#offlineClaims.values()) clearTimeout(timer);
8748
- this.#offlineClaims.clear();
8749
- }
8750
- /**
8751
- * Release one offline claim back to the host's own chain.
8752
- *
8753
- * The one entry every route uses — the window ending, a roster whose tokens are
8754
- * all dead, a hello that left nobody able to receive, the bridge unloading — so
8755
- * "the host's chain is started at most once" is a property of this entry rather
8756
- * than of its callers: `withdraw` deletes the claim before it delegates, and the
8757
- * chain a claim starts is memoized, so a second route releases nothing and starts
8758
- * nothing, and no notification is sent for a question that already left.
8734
+ * The one route for that fact — a roster whose every registered token APNs
8735
+ * refuses — so nobody settles the question twice: `withdraw` deletes the claim
8736
+ * before it hands the question to the chain that was started at claim time, and
8737
+ * the chain is memoized, so a second route releases nothing and announces
8738
+ * nothing.
8759
8739
  * @param callId - the claim to release.
8760
8740
  * @param reason - why, logged once when something really was released.
8761
8741
  */
8762
- #releaseOfflineClaim(callId, reason) {
8763
- this.#cancelOfflineClaim(callId);
8742
+ #releaseUnreachableClaim(callId, reason) {
8764
8743
  if (this.#options.questions.withdraw([callId]) > 0) this.#options.log(`an offline-claimed user question was released: ${reason}`);
8765
8744
  }
8766
- /** Release every offline claim through {@link #releaseOfflineClaim}. */
8767
- #releaseOfflineClaims(reason) {
8768
- for (const callId of [...this.#offlineClaims.keys()]) this.#releaseOfflineClaim(callId, reason);
8769
- }
8770
8745
  /** Abandon every approval: no paired device is left to answer one. */
8771
8746
  #abandonApprovals() {
8772
8747
  const withdrawn = this.#options.approvals.abandonAll();
8773
8748
  if (withdrawn > 0) this.#options.log(`${withdrawn} approval question(s) withdrew: no paired device is connected`);
8774
8749
  }
8750
+ /**
8751
+ * Hand one approval question to the host's own answerers.
8752
+ *
8753
+ * The chain is entered once, at claim time, so the panel is shown the same card
8754
+ * the phone holds. Only a real decision ends the phone's claim: a rejection is
8755
+ * not an answer, and neither is the fail-closed `'unavailable'` the chain returns
8756
+ * when no panel took the question at all — the phone may still answer either way.
8757
+ * @param prompt - the claim the chain is answering for.
8758
+ * @param next - the rest of the answerer chain.
8759
+ * @returns the chain's outcome, rejection included, for the caller that has to
8760
+ * wait on it after the phone stopped being able to answer.
8761
+ */
8762
+ #startApprovalChain(prompt, next) {
8763
+ let chain;
8764
+ try {
8765
+ chain = next();
8766
+ } catch (error) {
8767
+ chain = Promise.reject(error);
8768
+ }
8769
+ chain.then((outcome) => {
8770
+ this.#settleApprovalFromHost(prompt, outcome);
8771
+ }, () => void 0);
8772
+ return chain;
8773
+ }
8774
+ /**
8775
+ * End one claim on the decision the host's own panel gave.
8776
+ *
8777
+ * The release decides, not the outcome alone: a claim the phone already answered
8778
+ * is not pending any more, so its answer stands and nothing is announced a second
8779
+ * time. `'unavailable'` is the chain's fail-closed default rather than a decision
8780
+ * — no panel took the question — and it leaves the claim exactly as it was.
8781
+ * @param prompt - the claim the chain was started for.
8782
+ * @param outcome - what the host's own answerers decided.
8783
+ */
8784
+ #settleApprovalFromHost(prompt, outcome) {
8785
+ if (outcome === "unavailable") return;
8786
+ if (!this.#options.approvals.releaseToHost(prompt.id)) return;
8787
+ this.broadcast(TOPIC_APPROVAL_REQUEST, approvalPayload(prompt, "settled"));
8788
+ }
8789
+ /**
8790
+ * @returns whether a browser client that can answer these waterfalls is on the wire.
8791
+ *
8792
+ * The gateway's own predicate, read through the bridge's structural face. A
8793
+ * notification stands in for that panel, so it is only sent when the panel is not
8794
+ * there; a host without the Web GUI — and a capture-only test context — answers
8795
+ * `false`, which is the state in which the alert has always been the delivery.
8796
+ */
8797
+ #hasLiveClient() {
8798
+ return this.#options.gateway.hasLiveClient?.() === true;
8799
+ }
8775
8800
  /** Release every user question to the next answerer. */
8776
8801
  #releaseQuestions() {
8777
8802
  const released = this.#options.questions.withdrawAll();
@@ -33299,22 +33324,6 @@ const ROSTER_PATH = "remote-bridge/devices.json";
33299
33324
  * than to any one session, and it outlives every process (core/model-efforts.ts).
33300
33325
  */
33301
33326
  const EFFORT_PATH = "remote-bridge/model-efforts.json";
33302
- /** The environment variable that moves the offline claim window (§32.2). */
33303
- const OFFLINE_CLAIM_TTL_ENV = "DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TTL_MS";
33304
- /**
33305
- * The offline claim window this process runs with.
33306
- *
33307
- * The window is the bridge's own constant and never a host fact, so a deployment
33308
- * moves it here. A value that is missing, unreadable or not positive falls back to
33309
- * the constant instead of closing the window: a zero window would silently switch
33310
- * the channel off, and an operator who wanted that would be turning off push.
33311
- * @param env - the process environment, injectable for a suite.
33312
- * @returns the window in milliseconds.
33313
- */
33314
- function offlineClaimTtl(env = process.env) {
33315
- const configured = Number(env[OFFLINE_CLAIM_TTL_ENV]);
33316
- return Number.isFinite(configured) && configured > 0 ? configured : OFFLINE_QUESTION_CLAIM_TTL_MS;
33317
- }
33318
33327
  /**
33319
33328
  * The environment variable that moves when a still-waiting turn end is reported (§28).
33320
33329
  *
@@ -34381,7 +34390,6 @@ function applyImpl(ctx, config) {
34381
34390
  log
34382
34391
  });
34383
34392
  const extensions = new RemoteBridgeRegistry();
34384
- const offlineClaimTtlMs = offlineClaimTtl();
34385
34393
  /**
34386
34394
  * 第二会合点在协议面上的两处接线:`hello` 的公告与 `relay.grant` 的收帧。
34387
34395
  *
@@ -34428,7 +34436,6 @@ function applyImpl(ctx, config) {
34428
34436
  push,
34429
34437
  liveActivity,
34430
34438
  turnEndQuiet,
34431
- offlineClaimTtlMs,
34432
34439
  onPushRegistered: () => {
34433
34440
  watchers.sync();
34434
34441
  },
@@ -34793,4 +34800,4 @@ function applyImpl(ctx, config) {
34793
34800
  */
34794
34801
  const apply = mountOnce("@linxin666/dsh-remote-bridge", applyImpl);
34795
34802
  //#endregion
34796
- export { EFFORT_PATH, OFFLINE_CLAIM_TTL_ENV, PORT_SETTLE_RETRY_MS, ROSTER_PATH, TURN_END_QUIET_MAX_ENV, apply, bridgeWiringPlanOf, createDedupedStateLogger, createLeaseClaimer, createLegacyBlockCleaner, createPortSettleRetry, createRelayAnnouncer, createRelayHalfSwitch, disposeBridgeStack, inject, lanBasesOf, lanBindCapabilityOf, lanBindFrameOf, lanOriginOf, leaseConnectorSeams, leaseConnectorWants, livePublicOriginOf, name, offlineClaimTtl, relayAnnounceTargetOf, relayBridgeStateLine, relayStateLine, resolveBridgeConfig, retireStaleRelayHalfOf, turnEndQuietMaxWait };
34803
+ export { EFFORT_PATH, PORT_SETTLE_RETRY_MS, ROSTER_PATH, TURN_END_QUIET_MAX_ENV, apply, bridgeWiringPlanOf, createDedupedStateLogger, createLeaseClaimer, createLegacyBlockCleaner, createPortSettleRetry, createRelayAnnouncer, createRelayHalfSwitch, disposeBridgeStack, inject, lanBasesOf, lanBindCapabilityOf, lanBindFrameOf, lanOriginOf, leaseConnectorSeams, leaseConnectorWants, livePublicOriginOf, name, relayAnnounceTargetOf, relayBridgeStateLine, relayStateLine, resolveBridgeConfig, retireStaleRelayHalfOf, turnEndQuietMaxWait };
@@ -84,6 +84,16 @@ export declare class ApprovalRegistry {
84
84
  * @returns whether the id was still pending; a stale, expired or unknown id is refused.
85
85
  */
86
86
  resolve(id: string, decision: ClaimedDecision): boolean;
87
+ /**
88
+ * Release one question the host's own panel answered first.
89
+ *
90
+ * The release is not a decision: the panel's answer travels back through the
91
+ * answerer chain it came from, so the claim only has to stop being pending —
92
+ * which is what also makes a later answer from the phone refuse as unknown
93
+ * instead of settling a question that is already over.
94
+ * @returns whether this call released it; false when the phone already had.
95
+ */
96
+ releaseToHost(id: string): boolean;
87
97
  /**
88
98
  * Withdraw the named questions, delegating each to the next answerer.
89
99
  * @returns how many were still pending.