@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.
- package/README.i18n.yaml +2 -2
- package/README.md +7 -7
- package/README.zh.md +7 -7
- package/lib/client.js +55 -26
- package/lib/client.js.map +1 -1
- package/lib/index.js +2744 -5296
- 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/approvals.d.ts +10 -0
- package/lib/types/core/hub.d.ts +33 -26
- package/lib/types/core/pair-address.d.ts +25 -0
- package/lib/types/core/questions.d.ts +20 -4
- package/lib/types/index.d.ts +2 -16
- 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/approvals.ts +13 -0
- package/src/core/connection.ts +1 -1
- package/src/core/hub.ts +155 -156
- package/src/core/pair-address.ts +50 -0
- package/src/core/questions.ts +61 -14
- package/src/host/routes.ts +12 -5
- package/src/index.ts +3 -25
package/src/core/questions.ts
CHANGED
|
@@ -64,16 +64,24 @@ export interface QuestionItem {
|
|
|
64
64
|
readonly multiSelect?: boolean
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* One item of the answer batch. `selected` is a mutable array because the host's
|
|
69
|
+
* own answer item declares it mutable, and a readonly array is not assignable to
|
|
70
|
+
* a mutable one - the host's `user-questions/request` handler is typed with its
|
|
71
|
+
* own answer type, so this mirror has to stay assignable to it.
|
|
72
|
+
*/
|
|
68
73
|
export interface QuestionAnswerItem {
|
|
69
74
|
readonly id: string
|
|
70
|
-
readonly selected:
|
|
75
|
+
readonly selected: string[]
|
|
71
76
|
readonly custom?: string
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* The whole answer batch the host's ask is settled with. `answers` is mutable for
|
|
81
|
+
* the same reason {@link QuestionAnswerItem} keeps `selected` mutable.
|
|
82
|
+
*/
|
|
75
83
|
export interface QuestionAnswer {
|
|
76
|
-
readonly answers:
|
|
84
|
+
readonly answers: QuestionAnswerItem[]
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
/**
|
|
@@ -192,6 +200,14 @@ export interface ClaimedQuestionView {
|
|
|
192
200
|
export interface ClaimedQuestion extends ClaimedQuestionView {
|
|
193
201
|
/** The host's ask: the phone's answer, or whatever the next answerer says. */
|
|
194
202
|
readonly answer: Promise<QuestionAnswer>
|
|
203
|
+
/**
|
|
204
|
+
* Hand the same question to the host's own answerer chain, once.
|
|
205
|
+
*
|
|
206
|
+
* Called by the hub the instant a claim exists, in every mode: the phone is
|
|
207
|
+
* not the only surface any more, so the host's own panel shows the card too
|
|
208
|
+
* and the first answer settles it.
|
|
209
|
+
*/
|
|
210
|
+
readonly startHostChain: () => void
|
|
195
211
|
/**
|
|
196
212
|
* Epoch milliseconds at which the host's own deadline falls, from the first
|
|
197
213
|
* wait frame of this claim.
|
|
@@ -417,11 +433,11 @@ export class QuestionClaims {
|
|
|
417
433
|
})
|
|
418
434
|
const signal = input.signal
|
|
419
435
|
const onAbort = (): void => { this.#expire(input.callId, signal?.reason) }
|
|
420
|
-
// The rest of the answerer chain is the host's own UI
|
|
421
|
-
//
|
|
422
|
-
//
|
|
423
|
-
// A rejection is not a verdict
|
|
424
|
-
//
|
|
436
|
+
// The rest of the answerer chain is the host's own UI. Started once and
|
|
437
|
+
// memoized, because both paths that yield to it — the claim itself, and the
|
|
438
|
+
// withdraw that hands a question back — have to reach the same panel rather
|
|
439
|
+
// than open a second one. A rejection is not a verdict (the phone may still
|
|
440
|
+
// answer), so only the withdraw path turns one into this claim's failure.
|
|
425
441
|
let nextStarted: Promise<QuestionAnswer> | undefined
|
|
426
442
|
const startNext = (): Promise<QuestionAnswer> => {
|
|
427
443
|
if (nextStarted === undefined) {
|
|
@@ -539,17 +555,27 @@ export class QuestionClaims {
|
|
|
539
555
|
resolveDeadline(undefined)
|
|
540
556
|
}
|
|
541
557
|
}
|
|
558
|
+
/**
|
|
559
|
+
* Hand this claim to the host's own answerers, once.
|
|
560
|
+
*
|
|
561
|
+
* Both surfaces are shown the question and the first answer settles it: an
|
|
562
|
+
* answer from the chain ends the claim here, and an answer from the phone
|
|
563
|
+
* ends it in {@link answer} — which leaves the chain's later answer ignored
|
|
564
|
+
* instead of settling or broadcasting a second time.
|
|
565
|
+
*/
|
|
566
|
+
const startHostChain = (): void => {
|
|
567
|
+
void startNext().then(answer => { this.#settleFromHost(input.callId, answer) }, () => undefined)
|
|
568
|
+
}
|
|
542
569
|
this.#claims.set(input.callId, record)
|
|
543
|
-
// The
|
|
544
|
-
//
|
|
545
|
-
//
|
|
546
|
-
// A phone that is absent, or a claim that is withdrawn, still delegates.
|
|
570
|
+
// The chain itself is started by the hub through {@link startHostChain} the
|
|
571
|
+
// instant this claim exists, so the panel and the phone are shown the same
|
|
572
|
+
// question and whichever answers first settles both.
|
|
547
573
|
if (signal?.aborted === true) onAbort()
|
|
548
574
|
else signal?.addEventListener('abort', onAbort, { once: true })
|
|
549
575
|
if (input.hosted) void trackWait()
|
|
550
576
|
// A blocking ask carries no host deadline at all: nothing to follow, nothing to publish.
|
|
551
577
|
else resolveDeadline(undefined)
|
|
552
|
-
return { ...viewOf(record), answer, deadline }
|
|
578
|
+
return { ...viewOf(record), answer, deadline, startHostChain }
|
|
553
579
|
}
|
|
554
580
|
|
|
555
581
|
/**
|
|
@@ -662,6 +688,27 @@ export class QuestionClaims {
|
|
|
662
688
|
}
|
|
663
689
|
}
|
|
664
690
|
|
|
691
|
+
/**
|
|
692
|
+
* Settle one claim from the host's own answerer chain.
|
|
693
|
+
*
|
|
694
|
+
* Only a claim this bridge still holds can be ended this way: a phone that
|
|
695
|
+
* answered first deletes it, and the chain's late answer must not settle it a
|
|
696
|
+
* second time or announce a card that is already gone. A claim the host's own
|
|
697
|
+
* deadline turned into `continued` is left alone as well — its answer promise
|
|
698
|
+
* is that deadline, and the phone's late answer still has its own road.
|
|
699
|
+
* @param callId - the claim the host answered.
|
|
700
|
+
* @param answer - the host's own answer.
|
|
701
|
+
*/
|
|
702
|
+
#settleFromHost(callId: string, answer: QuestionAnswer): void {
|
|
703
|
+
const record = this.#claims.get(callId)
|
|
704
|
+
if (record === undefined || record.state !== 'open') return
|
|
705
|
+
this.#claims.delete(callId)
|
|
706
|
+
record.detach()
|
|
707
|
+
record.stopWait()
|
|
708
|
+
record.notifySettled()
|
|
709
|
+
record.settle(answer)
|
|
710
|
+
}
|
|
711
|
+
|
|
665
712
|
/**
|
|
666
713
|
* Settle one open claim from the host's own cancellation lifetime.
|
|
667
714
|
*
|
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,
|
package/src/index.ts
CHANGED
|
@@ -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,
|
|
28
|
-
*
|
|
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
|
|
@@ -51,7 +50,7 @@ import { DeviceRoster } from './core/devices.ts'
|
|
|
51
50
|
import { createRemoteBridgeFace, RemoteBridgeRegistry, REMOTE_BRIDGE_SERVICE } from './core/extension.ts'
|
|
52
51
|
import { JobRoster, type JobRegistryFace } from './core/jobs.ts'
|
|
53
52
|
import { ModelEffortPreferences } from './core/model-efforts.ts'
|
|
54
|
-
import { BridgeHub
|
|
53
|
+
import { BridgeHub } from './core/hub.ts'
|
|
55
54
|
import { createOwnerPeer } from './core/owner-peer.ts'
|
|
56
55
|
import { PairingService } from './core/pairing.ts'
|
|
57
56
|
import { LiveActivityNotifier } from './core/liveactivity.ts'
|
|
@@ -151,24 +150,6 @@ export const ROSTER_PATH = 'remote-bridge/devices.json'
|
|
|
151
150
|
*/
|
|
152
151
|
export const EFFORT_PATH = 'remote-bridge/model-efforts.json'
|
|
153
152
|
|
|
154
|
-
/** The environment variable that moves the offline claim window (§32.2). */
|
|
155
|
-
export const OFFLINE_CLAIM_TTL_ENV = 'DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TTL_MS'
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* The offline claim window this process runs with.
|
|
159
|
-
*
|
|
160
|
-
* The window is the bridge's own constant and never a host fact, so a deployment
|
|
161
|
-
* moves it here. A value that is missing, unreadable or not positive falls back to
|
|
162
|
-
* the constant instead of closing the window: a zero window would silently switch
|
|
163
|
-
* the channel off, and an operator who wanted that would be turning off push.
|
|
164
|
-
* @param env - the process environment, injectable for a suite.
|
|
165
|
-
* @returns the window in milliseconds.
|
|
166
|
-
*/
|
|
167
|
-
export function offlineClaimTtl(env: NodeJS.ProcessEnv = process.env): number {
|
|
168
|
-
const configured = Number(env[OFFLINE_CLAIM_TTL_ENV])
|
|
169
|
-
return Number.isFinite(configured) && configured > 0 ? configured : OFFLINE_QUESTION_CLAIM_TTL_MS
|
|
170
|
-
}
|
|
171
|
-
|
|
172
153
|
/**
|
|
173
154
|
* The environment variable that moves when a still-waiting turn end is reported (§28).
|
|
174
155
|
*
|
|
@@ -1586,8 +1567,6 @@ function applyImpl(ctx: Context, config?: unknown): void {
|
|
|
1586
1567
|
log,
|
|
1587
1568
|
})
|
|
1588
1569
|
const extensions = new RemoteBridgeRegistry()
|
|
1589
|
-
// 离线认领的窗口归桥所有,宿主从不认识它(§32.2):常量是默认值,部署可用环境变量覆盖。
|
|
1590
|
-
const offlineClaimTtlMs = offlineClaimTtl()
|
|
1591
1570
|
/**
|
|
1592
1571
|
* 第二会合点在协议面上的两处接线:`hello` 的公告与 `relay.grant` 的收帧。
|
|
1593
1572
|
*
|
|
@@ -1652,7 +1631,6 @@ function applyImpl(ctx: Context, config?: unknown): void {
|
|
|
1652
1631
|
push,
|
|
1653
1632
|
liveActivity,
|
|
1654
1633
|
turnEndQuiet,
|
|
1655
|
-
offlineClaimTtlMs,
|
|
1656
1634
|
onPushRegistered: () => { watchers.sync() },
|
|
1657
1635
|
...(relayFace === undefined ? {} : { relay: relayFace }),
|
|
1658
1636
|
onDeviceEnrolled: () => { wakeRelay() },
|