@linxin666/dsh-remote-bridge 0.4.14 → 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.
@@ -1,4 +1,5 @@
1
1
  import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
2
+ import { type PairOriginSource } from '../core/pair-address.ts';
2
3
  /**
3
4
  * Where a reader of the beta build can reach the people running it. The URL is
4
5
  * code, not copy: the dictionaries carry the sentence, this constant carries the
@@ -17,7 +18,10 @@ export type PairPanelState =
17
18
  * public origin, is what the QR encodes: a `{token, url}` document the iOS
18
19
  * client parses into both halves of its configuration, so one scan sets the
19
20
  * address AND the token. With no origin the QR carries the bare token and the
20
- * panel says the address has to be set on the phone by hand.
21
+ * panel says the address has to be set on the phone by hand. `originSource`
22
+ * and the literal itself decide which of the two located lines renders: a
23
+ * public origin is stated as a kind and never printed, while a LAN literal is
24
+ * named because it answers only inside the network this page is already on.
21
25
  */
22
26
  | {
23
27
  kind: 'ready';
@@ -25,6 +29,7 @@ export type PairPanelState =
25
29
  issuedAt: number;
26
30
  expiresAt: number;
27
31
  origin: string | null;
32
+ originSource: PairOriginSource | null;
28
33
  pairingUrl: string | null;
29
34
  }
30
35
  /** 403 from the loopback gate: this page is not open on the machine itself. */
@@ -4,11 +4,15 @@
4
4
  *
5
5
  * The panel has one job — put the live one-shot code in front of the operator as
6
6
  * a QR symbol — so its copy carries what to do with the symbol, how long it
7
- * lives, which address the phone will actually dial, why the code is single-use,
7
+ * lives, what kind of address the phone will dial, why the code is single-use,
8
8
  * and that the app is still in testing: the reader is told what they are joining
9
- * and where to ask about it. No key states how the host finds its public
10
- * address, and no key names the wire protocol: both are implementation facts the
11
- * reader cannot act on.
9
+ * and where to ask about it. No key renders the public origin: the symbol
10
+ * already carries it, and a durable public hostname printed as text would
11
+ * outlive every screenshot it appears in. A LAN literal is not that fact — it
12
+ * answers only inside the network this page is already on — so the LAN line
13
+ * keeps naming it. No key states how the host finds either address, and no key
14
+ * names the wire protocol: both are implementation facts the reader cannot act
15
+ * on.
12
16
  *
13
17
  * The card's keys say only what the transcript row can act on: whether the page
14
18
  * is still waiting for the operator, that it is over, that this desktop renders
@@ -26,7 +30,8 @@ export declare const zh: {
26
30
  readonly 'pair.expired': "配对码已过期";
27
31
  readonly 'pair.refresh': "重新取码";
28
32
  readonly 'pair.usedHint': "配对码一次性有效:iPhone 一开始配对就作废,重新取码也会作废上一张。";
29
- readonly 'origin.located': "iPhone 将连到 {origin}";
33
+ readonly 'origin.public': "二维码已包含公网地址,扫码后 iPhone 自动连上这台电脑";
34
+ readonly 'origin.lan': "二维码指向局域网地址 {origin},iPhone 需与本机在同一网络";
30
35
  readonly 'origin.missing': "没有找到公网地址:先在 App 里把连接地址填成你的公网中继,再扫码。本页的 {host} 只有本机能连。";
31
36
  readonly 'community.invite': "iOS App 还在内测,欢迎来 Discord 交流";
32
37
  readonly 'forbidden.title': "这个页面不是从本机打开的";
@@ -12,8 +12,14 @@
12
12
  * `403` is a fact, not an error: the loopback gate in `core/loopback.ts`
13
13
  * refuses any page whose socket or `Host` is not this machine, which is exactly
14
14
  * the case the panel must name out loud.
15
+ *
16
+ * The origin's own source crosses too, and it is not decoration: it is what lets
17
+ * the panel say which kind of address the code carries without printing a
18
+ * public hostname, while still naming a LAN literal that answers only inside the
19
+ * network the page is already on.
15
20
  * @module dsh-remote-bridge/client/pair-token
16
21
  */
22
+ import type { PairOriginSource } from '../core/pair-address.ts';
17
23
  /** Document-relative form of the Host route, for a page served under any base. */
18
24
  export declare const PAIR_TOKEN_URL: string;
19
25
  /** The outcome of one token read. */
@@ -29,6 +35,7 @@ export type PairTokenOutcome =
29
35
  token: string;
30
36
  expiresAt: number;
31
37
  origin: string | null;
38
+ originSource: PairOriginSource | null;
32
39
  pairingUrl: string | null;
33
40
  }
34
41
  /** 403: the page is not open on the machine itself, so the loopback gate refused it. */
@@ -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.
@@ -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.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Which kind of address a located pairing origin is, decided in one place
3
+ * because two halves answer with the same word: the panel states the kind to the
4
+ * operator, and the Host log names it beside the machine-local link.
5
+ *
6
+ * The host's own answer comes first, and the literal decides when it did not: a
7
+ * configured base can name a private address — the package README calls
8
+ * `DSH_REMOTE_PUBLIC_BASE_URL` a public or LAN origin — and a surface that
9
+ * called such an address public would promise a phone something it cannot reach
10
+ * from outside. The pattern is anchored to the whole hostname on purpose: a
11
+ * public name that merely starts like a private literal (`10.example.com`) is
12
+ * not one, and printing it is the one thing the address line must never do.
13
+ * Every value this module cannot place reads as public, which is the direction
14
+ * that prints nothing.
15
+ * @module dsh-remote-bridge/core/pair-address
16
+ */
17
+ /** Where the host's own answer says a located origin came from. */
18
+ export type PairOriginSource = 'realtime' | 'env' | 'lan';
19
+ /**
20
+ * Whether a located origin answers only inside this network.
21
+ * @param origin - the located origin, or null when there is none.
22
+ * @param source - where the host said that origin came from.
23
+ * @returns true when a phone must be on the same network to dial it.
24
+ */
25
+ export declare function isLanOrigin(origin: string | null, source: PairOriginSource | null): boolean;
@@ -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,11 +1,11 @@
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.14",
4
+ "version": "0.4.16",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
7
7
  "engines": {
8
- "node": "^22.19.0 || >=24.0.0"
8
+ "node": ">=24.9.0"
9
9
  },
10
10
  "main": "lib/index.js",
11
11
  "types": "lib/types/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "license": "Apache-2.0",
38
38
  "dsh": {
39
39
  "engines": {
40
- "dsh": ">=0.2.1-rc.3"
40
+ "dsh": ">=0.2.2-rc.1"
41
41
  },
42
42
  "bundle": {
43
43
  "patch": "./cordis.patch.yml"
@@ -57,23 +57,23 @@
57
57
  "yaml": "^2.8.2"
58
58
  },
59
59
  "peerDependencies": {
60
- "@deepseek-ai/dsh": ">=0.2.1-rc.3",
60
+ "@deepseek-ai/dsh": ">=0.2.2-rc.1",
61
61
  "react": "^18.2.0",
62
62
  "react-dom": "^18.2.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@deepseek-ai/cordis": "^4.0.5",
66
- "@deepseek-ai/dsh-api-gateway": "^0.2.1-rc.3",
67
- "@deepseek-ai/dsh-client-locale": "^0.2.1-rc.3",
68
- "@deepseek-ai/dsh-client-ui-primitives": "^0.2.1-rc.3",
69
- "@deepseek-ai/dsh-client-ui-renderer": "^0.2.1-rc.3",
70
- "@deepseek-ai/dsh-client-ui-sidebar": "^0.2.1-rc.3",
71
- "@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.3",
72
- "@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.3",
73
- "@deepseek-ai/dsh-session": "^0.2.1-rc.3",
74
- "@deepseek-ai/dsh-tools": "^0.2.1-rc.3",
75
- "@deepseek-ai/dsh-typert-protocol": "^0.2.1-rc.3",
76
- "@deepseek-ai/dsh-user-approval": "^0.2.1-rc.3",
65
+ "@deepseek-ai/cordis": "^4.1.0",
66
+ "@deepseek-ai/dsh-api-gateway": "^0.2.2-rc.1",
67
+ "@deepseek-ai/dsh-client-locale": "^0.2.2-rc.1",
68
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.2.2-rc.1",
69
+ "@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.1",
70
+ "@deepseek-ai/dsh-client-ui-sidebar": "^0.2.2-rc.1",
71
+ "@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.1",
72
+ "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.1",
73
+ "@deepseek-ai/dsh-session": "^0.2.2-rc.1",
74
+ "@deepseek-ai/dsh-tools": "^0.2.2-rc.1",
75
+ "@deepseek-ai/dsh-typert-protocol": "^0.2.2-rc.1",
76
+ "@deepseek-ai/dsh-user-approval": "^0.2.2-rc.1",
77
77
  "@testing-library/dom": "^10.4.1",
78
78
  "@testing-library/react": "^16.3.2",
79
79
  "@types/node": "^22.20.0",
@@ -57,6 +57,7 @@ function panelStateOf(outcome: PairTokenOutcome, issuedAt: number): PairPanelSta
57
57
  issuedAt,
58
58
  expiresAt: outcome.expiresAt,
59
59
  origin: outcome.origin,
60
+ originSource: outcome.originSource,
60
61
  pairingUrl: outcome.pairingUrl,
61
62
  }
62
63
  case 'forbidden': return { kind: 'forbidden' }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The protocol v1 pairing panel: the QR symbol, the countdown with its expiry
3
- * state, the one address fact the reader must not miss, and the two actions that
4
- * keep a fresh code on screen.
3
+ * state, the line that says which kind of address the code carries, and the two
4
+ * actions that keep a fresh code on screen.
5
5
  *
6
6
  * The shell is the official headless `Modal` and every action is the official
7
7
  * `Button`, so the overlay, the mask, the card, the focus trap, the Escape
@@ -17,6 +17,7 @@ import {
17
17
  IconRefreshOutlineRegular, IconWarningOutlineRegular, Modal,
18
18
  } from '@deepseek-ai/dsh-client-ui-primitives'
19
19
  import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
20
+ import { isLanOrigin, type PairOriginSource } from '../core/pair-address.ts'
20
21
  import {
21
22
  EXPIRED_ATTR, PART_COPY, PART_NOTICE, PART_PANEL, PART_QR, PART_REFRESH, PLUGIN_ATTR, QR_VALUE_ATTR,
22
23
  } from './semantic.ts'
@@ -42,9 +43,20 @@ export type PairPanelState =
42
43
  * public origin, is what the QR encodes: a `{token, url}` document the iOS
43
44
  * client parses into both halves of its configuration, so one scan sets the
44
45
  * address AND the token. With no origin the QR carries the bare token and the
45
- * panel says the address has to be set on the phone by hand.
46
+ * panel says the address has to be set on the phone by hand. `originSource`
47
+ * and the literal itself decide which of the two located lines renders: a
48
+ * public origin is stated as a kind and never printed, while a LAN literal is
49
+ * named because it answers only inside the network this page is already on.
46
50
  */
47
- | { kind: 'ready'; token: string; issuedAt: number; expiresAt: number; origin: string | null; pairingUrl: string | null }
51
+ | {
52
+ kind: 'ready'
53
+ token: string
54
+ issuedAt: number
55
+ expiresAt: number
56
+ origin: string | null
57
+ originSource: PairOriginSource | null
58
+ pairingUrl: string | null
59
+ }
48
60
  /** 403 from the loopback gate: this page is not open on the machine itself. */
49
61
  | { kind: 'forbidden' }
50
62
  /** The host route answered with an unexpected status or shape. */
@@ -115,6 +127,11 @@ export function PairPanel({
115
127
  // A refusal the host raised is retried; a live or expired code is minted again.
116
128
  const primaryLabel = state.kind === 'failed' || state.kind === 'unreachable' ? t('action.retry') : t('pair.refresh')
117
129
  const located = ready && state.pairingUrl !== null
130
+ // A located origin answers only inside this network when the host said so or
131
+ // the literal itself is a private one; anything else counts as public, because
132
+ // the one thing this line must never do is print a hostname the host did not
133
+ // vouch for.
134
+ const onLan = located && isLanOrigin(state.origin, state.originSource)
118
135
 
119
136
  // The library owns the enter animation and the bundler scopes its keyframe
120
137
  // name, so the leave leg cannot name it in CSS. Read the mounted dialog's own
@@ -213,7 +230,8 @@ export function PairPanel({
213
230
  </div>
214
231
 
215
232
  <p className={css.address} data-tone={located ? 'plain' : 'warning'}>
216
- {ready && located && t('origin.located', { origin: state.origin ?? '' })}
233
+ {ready && located && !onLan && t('origin.public')}
234
+ {ready && onLan && t('origin.lan', { origin: state.origin ?? '' })}
217
235
  {ready && !located && t('origin.missing', { host })}
218
236
  </p>
219
237
  <p className={css.hint}>{t('pair.usedHint')}</p>
@@ -4,11 +4,15 @@
4
4
  *
5
5
  * The panel has one job — put the live one-shot code in front of the operator as
6
6
  * a QR symbol — so its copy carries what to do with the symbol, how long it
7
- * lives, which address the phone will actually dial, why the code is single-use,
7
+ * lives, what kind of address the phone will dial, why the code is single-use,
8
8
  * and that the app is still in testing: the reader is told what they are joining
9
- * and where to ask about it. No key states how the host finds its public
10
- * address, and no key names the wire protocol: both are implementation facts the
11
- * reader cannot act on.
9
+ * and where to ask about it. No key renders the public origin: the symbol
10
+ * already carries it, and a durable public hostname printed as text would
11
+ * outlive every screenshot it appears in. A LAN literal is not that fact — it
12
+ * answers only inside the network this page is already on — so the LAN line
13
+ * keeps naming it. No key states how the host finds either address, and no key
14
+ * names the wire protocol: both are implementation facts the reader cannot act
15
+ * on.
12
16
  *
13
17
  * The card's keys say only what the transcript row can act on: whether the page
14
18
  * is still waiting for the operator, that it is over, that this desktop renders
@@ -27,7 +31,8 @@ export const zh = {
27
31
  'pair.expired': '配对码已过期',
28
32
  'pair.refresh': '重新取码',
29
33
  'pair.usedHint': '配对码一次性有效:iPhone 一开始配对就作废,重新取码也会作废上一张。',
30
- 'origin.located': 'iPhone 将连到 {origin}',
34
+ 'origin.public': '二维码已包含公网地址,扫码后 iPhone 自动连上这台电脑',
35
+ 'origin.lan': '二维码指向局域网地址 {origin},iPhone 需与本机在同一网络',
31
36
  'origin.missing': '没有找到公网地址:先在 App 里把连接地址填成你的公网中继,再扫码。本页的 {host} 只有本机能连。',
32
37
  'community.invite': 'iOS App 还在内测,欢迎来 Discord 交流',
33
38
  'forbidden.title': '这个页面不是从本机打开的',
@@ -61,7 +66,8 @@ export const en: Record<RemoteBridgeKey, string> = {
61
66
  'pair.expired': 'The pairing code expired',
62
67
  'pair.refresh': 'New code',
63
68
  'pair.usedHint': 'The code is single-use: pairing spends it, and a new code voids the previous one.',
64
- 'origin.located': 'The iPhone will dial {origin}',
69
+ 'origin.public': 'The QR code carries the public address: the iPhone connects to this computer as soon as it scans',
70
+ 'origin.lan': 'The QR code points at the LAN address {origin}: the iPhone must be on the same network',
65
71
  'origin.missing': 'No public address found: set the connection address in the app to your public relay first, then scan. {host} (this page) is reachable only from this machine.',
66
72
  'community.invite': 'The iOS app is in beta. Come talk to us on Discord',
67
73
  'forbidden.title': 'This page is not open on this machine',
@@ -12,9 +12,15 @@
12
12
  * `403` is a fact, not an error: the loopback gate in `core/loopback.ts`
13
13
  * refuses any page whose socket or `Host` is not this machine, which is exactly
14
14
  * the case the panel must name out loud.
15
+ *
16
+ * The origin's own source crosses too, and it is not decoration: it is what lets
17
+ * the panel say which kind of address the code carries without printing a
18
+ * public hostname, while still naming a LAN literal that answers only inside the
19
+ * network the page is already on.
15
20
  * @module dsh-remote-bridge/client/pair-token
16
21
  */
17
22
 
23
+ import type { PairOriginSource } from '../core/pair-address.ts'
18
24
  import { PAIR_TOKEN_PATH } from '../core/protocol.ts'
19
25
 
20
26
  /** Document-relative form of the Host route, for a page served under any base. */
@@ -28,7 +34,14 @@ export type PairTokenOutcome =
28
34
  * is the code a QR should carry: a `{token, url}` document the phone parses
29
35
  * into both halves of its configuration.
30
36
  */
31
- | { kind: 'ok'; token: string; expiresAt: number; origin: string | null; pairingUrl: string | null }
37
+ | {
38
+ kind: 'ok'
39
+ token: string
40
+ expiresAt: number
41
+ origin: string | null
42
+ originSource: PairOriginSource | null
43
+ pairingUrl: string | null
44
+ }
32
45
  /** 403: the page is not open on the machine itself, so the loopback gate refused it. */
33
46
  | { kind: 'forbidden' }
34
47
  /** The route answered with a status the panel does not know, or with a body that is not a token. */
@@ -100,5 +113,7 @@ export async function readPairToken(options: ReadPairTokenOptions = {}): Promise
100
113
  const origin = stringOrNull((body as { origin?: unknown }).origin)
101
114
  const candidate = stringOrNull((body as { pairingUrl?: unknown }).pairingUrl)
102
115
  const pairingUrl = candidate !== null && /^wss?:\/\/\S+$/.test(candidate) ? candidate : null
103
- return { kind: 'ok', token, expiresAt, origin, pairingUrl }
116
+ const source = (body as { originSource?: unknown }).originSource
117
+ const originSource = source === 'realtime' || source === 'env' || source === 'lan' ? source : null
118
+ return { kind: 'ok', token, expiresAt, origin, originSource, pairingUrl }
104
119
  }
@@ -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) {