@linxin666/dsh-remote-bridge 0.4.14 → 0.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +5 -5
- package/README.zh.md +5 -5
- package/lib/client.js +55 -26
- package/lib/client.js.map +1 -1
- package/lib/index.js +2758 -5317
- package/lib/types/client/PairPanel.d.ts +6 -1
- package/lib/types/client/locales.d.ts +10 -5
- package/lib/types/client/pair-token.d.ts +7 -0
- package/lib/types/core/pair-address.d.ts +25 -0
- package/package.json +16 -16
- package/src/client/PairEntry.tsx +1 -0
- package/src/client/PairPanel.tsx +23 -5
- package/src/client/locales.ts +12 -6
- package/src/client/pair-token.ts +17 -2
- package/src/core/pair-address.ts +50 -0
- package/src/host/routes.ts +12 -5
|
@@ -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,
|
|
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
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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.
|
|
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. */
|
|
@@ -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;
|
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.
|
|
4
|
+
"version": "0.4.15",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": "
|
|
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.
|
|
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.
|
|
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
|
|
66
|
-
"@deepseek-ai/dsh-api-gateway": "^0.2.
|
|
67
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.
|
|
68
|
-
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.
|
|
69
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.
|
|
70
|
-
"@deepseek-ai/dsh-client-ui-sidebar": "^0.2.
|
|
71
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.
|
|
72
|
-
"@deepseek-ai/dsh-host-webserver": "^0.2.
|
|
73
|
-
"@deepseek-ai/dsh-session": "^0.2.
|
|
74
|
-
"@deepseek-ai/dsh-tools": "^0.2.
|
|
75
|
-
"@deepseek-ai/dsh-typert-protocol": "^0.2.
|
|
76
|
-
"@deepseek-ai/dsh-user-approval": "^0.2.
|
|
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",
|
package/src/client/PairEntry.tsx
CHANGED
|
@@ -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' }
|
package/src/client/PairPanel.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The protocol v1 pairing panel: the QR symbol, the countdown with its expiry
|
|
3
|
-
* state, the
|
|
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
|
-
| {
|
|
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.
|
|
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>
|
package/src/client/locales.ts
CHANGED
|
@@ -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,
|
|
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
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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.
|
|
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.
|
|
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',
|
package/src/client/pair-token.ts
CHANGED
|
@@ -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
|
-
| {
|
|
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
|
-
|
|
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
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
|
|
18
|
+
/** Where the host's own answer says a located origin came from. */
|
|
19
|
+
export type PairOriginSource = 'realtime' | 'env' | 'lan'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Hosts a phone can only reach from the same network: the private IPv4 ranges,
|
|
23
|
+
* the unspecified address, and the IPv6 loopback, unique-local and link-local
|
|
24
|
+
* prefixes. IPv4-mapped IPv6 and anything else this does not place stays public,
|
|
25
|
+
* because the failure this predicate may never have is printing a name the host
|
|
26
|
+
* did not vouch for.
|
|
27
|
+
*/
|
|
28
|
+
const LAN_HOST_RE = /^(?:localhost|0\.0\.0\.0|(?:(?:10|127)(?:\.\d{1,3}){3}|192\.168(?:\.\d{1,3}){2}|172\.(?:1[6-9]|2\d|3[01])(?:\.\d{1,3}){2}|169\.254(?:\.\d{1,3}){2})|\[(?:::1|f[cd][0-9a-f]{2}:|fe[89ab][0-9a-f]:)[0-9a-f:]*\])$/i
|
|
29
|
+
|
|
30
|
+
/** The hostname a URL carries, or null when the value is not a URL at all. */
|
|
31
|
+
function hostnameOf(origin: string): string | null {
|
|
32
|
+
try {
|
|
33
|
+
return new URL(origin).hostname
|
|
34
|
+
} catch {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether a located origin answers only inside this network.
|
|
41
|
+
* @param origin - the located origin, or null when there is none.
|
|
42
|
+
* @param source - where the host said that origin came from.
|
|
43
|
+
* @returns true when a phone must be on the same network to dial it.
|
|
44
|
+
*/
|
|
45
|
+
export function isLanOrigin(origin: string | null, source: PairOriginSource | null): boolean {
|
|
46
|
+
if (source === 'lan') return true
|
|
47
|
+
if (origin === null) return false
|
|
48
|
+
const host = hostnameOf(origin)
|
|
49
|
+
return host !== null && LAN_HOST_RE.test(host)
|
|
50
|
+
}
|
package/src/host/routes.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
13
13
|
import type { WebRoute } from '@deepseek-ai/dsh-host-webserver'
|
|
14
14
|
import { loopbackDenialOf } from '../core/loopback.ts'
|
|
15
|
+
import { isLanOrigin } from '../core/pair-address.ts'
|
|
15
16
|
import { PAIR_TOKEN_PATH, WS_PATH } from '../core/protocol.ts'
|
|
16
17
|
import type { PairingService } from '../core/pairing.ts'
|
|
17
18
|
import { discoverPairOrigin, type PairOriginFacts } from './pair-origin.ts'
|
|
@@ -118,11 +119,17 @@ export function makePairTokenHandler(deps: PairTokenRouteDeps): WebRoute['handle
|
|
|
118
119
|
const pairingUrl = discovered === undefined
|
|
119
120
|
? undefined
|
|
120
121
|
: pairingDialUrlOf(discovered.origin, ticket.value)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
// The log names the machine-local link and, when there is one, only the KIND
|
|
123
|
+
// of phone-facing address — the same rule the panel states it with, so the two
|
|
124
|
+
// surfaces can never disagree about one configuration. The public hostname is
|
|
125
|
+
// a durable fact that a log line is likely to be pasted with, and the phone
|
|
126
|
+
// reads the address off the QR anyway; the LAN literal is left out for the
|
|
127
|
+
// same reason, because the panel already states it where the operator can see
|
|
128
|
+
// the code.
|
|
129
|
+
const phone = discovered === undefined
|
|
130
|
+
? ''
|
|
131
|
+
: ` (phone: ${isLanOrigin(discovered.origin, discovered.source) ? 'lan' : 'public'})`
|
|
132
|
+
deps.log(`pair a device with ${url}${phone}`)
|
|
126
133
|
writeJson(res, 200, {
|
|
127
134
|
token: ticket.value,
|
|
128
135
|
expiresAt: ticket.expiresAt,
|