@linxin666/dsh-remote-bridge 0.4.8 → 0.4.9
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 +50 -17
- package/README.zh.md +50 -17
- package/lib/client.js +274 -253
- package/lib/client.js.map +1 -1
- package/lib/index.js +6690 -2277
- package/lib/types/client/PairEntry.d.ts +2 -2
- package/lib/types/client/PairPanel.d.ts +10 -2
- package/lib/types/client/icons.d.ts +5 -13
- package/lib/types/client/locales.d.ts +10 -14
- package/lib/types/client/semantic.d.ts +9 -5
- package/lib/types/core/commands.d.ts +59 -0
- package/lib/types/core/connection.d.ts +68 -0
- package/lib/types/core/devices.d.ts +98 -2
- package/lib/types/core/hub.d.ts +65 -15
- package/lib/types/core/liveactivity.d.ts +324 -0
- package/lib/types/core/protocol.d.ts +260 -1
- package/lib/types/core/push.d.ts +178 -0
- package/lib/types/core/questions.d.ts +61 -9
- package/lib/types/core/session-meta.d.ts +55 -1
- package/lib/types/core/squads.d.ts +130 -0
- package/lib/types/core/usage-stats.d.ts +160 -0
- package/lib/types/core/usage.d.ts +294 -0
- package/lib/types/host/apns.d.ts +151 -0
- package/lib/types/host/squads-ledger.d.ts +39 -0
- package/lib/types/host/squads.d.ts +77 -0
- package/lib/types/host/usage-stats.d.ts +75 -0
- package/lib/types/host/watchers.d.ts +88 -0
- package/lib/types/index.d.ts +18 -2
- package/package.json +13 -13
- package/src/client/PairEntry.tsx +58 -31
- package/src/client/PairPanel.tsx +181 -97
- package/src/client/icons.tsx +17 -60
- package/src/client/locales.ts +15 -23
- package/src/client/panel.module.css +239 -186
- package/src/client/semantic.ts +10 -6
- package/src/core/commands.ts +95 -0
- package/src/core/connection.ts +646 -10
- package/src/core/devices.ts +221 -3
- package/src/core/hub.ts +362 -42
- package/src/core/liveactivity.ts +833 -0
- package/src/core/protocol.ts +294 -1
- package/src/core/push.ts +354 -0
- package/src/core/questions.ts +81 -10
- package/src/core/session-meta.ts +73 -1
- package/src/core/squads.ts +345 -0
- package/src/core/usage-stats.ts +424 -0
- package/src/core/usage.ts +937 -0
- package/src/core/wire.ts +8 -0
- package/src/host/apns.ts +320 -0
- package/src/host/squads-ledger.ts +105 -0
- package/src/host/squads.ts +206 -0
- package/src/host/usage-stats.ts +155 -0
- package/src/host/watchers.ts +272 -0
- package/src/index.ts +257 -8
|
@@ -9,8 +9,8 @@ export type PairEntryProps = PropsLocale<'remote-bridge'> & {
|
|
|
9
9
|
copy: (text: string) => Promise<boolean>;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
* Render the pairing seat trigger and,
|
|
12
|
+
* Render the pairing seat trigger and, while it is open or leaving, the panel.
|
|
13
13
|
* @param props - the footer seat's column state, the injected actions and the locale seat.
|
|
14
|
-
* @returns the trigger and the panel
|
|
14
|
+
* @returns the trigger and, when present, the official Modal holding the panel.
|
|
15
15
|
*/
|
|
16
16
|
export declare function PairEntry({ wide, read, copy, t }: PairEntryProps): import("react").JSX.Element;
|
|
@@ -43,13 +43,21 @@ export interface PairPanelProps {
|
|
|
43
43
|
/** This page's own `host:port`, named in the origin warning. */
|
|
44
44
|
host: string;
|
|
45
45
|
copy: PairCopyState;
|
|
46
|
+
/** Whether the modal is mounted at all (the entry keeps it for the leave leg). */
|
|
47
|
+
showing: boolean;
|
|
48
|
+
/** Whether the leave leg is running; the card stays mounted until it ends. */
|
|
49
|
+
closing: boolean;
|
|
50
|
+
/** The panel element's id, so the seat trigger can name what it expands. */
|
|
51
|
+
id: string;
|
|
46
52
|
onClose(): void;
|
|
53
|
+
/** The leave leg reported completion: the entry may unmount the modal now. */
|
|
54
|
+
onExited(): void;
|
|
47
55
|
onRefresh(): void;
|
|
48
|
-
onCopy(
|
|
56
|
+
onCopy(payload: string): void;
|
|
49
57
|
}
|
|
50
58
|
/**
|
|
51
59
|
* Render the pairing panel.
|
|
52
60
|
* @param props - locale seat, view state, clock, page host and actions.
|
|
53
61
|
* @returns the panel element tree.
|
|
54
62
|
*/
|
|
55
|
-
export declare function PairPanel({ t, state, now, host, copy, onClose, onRefresh, onCopy }: PairPanelProps): import("react").JSX.Element;
|
|
63
|
+
export declare function PairPanel({ t, state, now, host, copy, showing, closing, id, onClose, onExited, onRefresh, onCopy, }: PairPanelProps): import("react").JSX.Element;
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* `@deepseek-ai/dsh-client-ui-primitives`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* The pairing seat's QR glyph. It is the one icon this package draws itself
|
|
3
|
+
* (I4 exception, recorded here): the official icon set in
|
|
4
|
+
* `@deepseek-ai/dsh-client-ui-primitives` ships no QR or scan metaphor, and a
|
|
5
|
+
* text or emoji stand-in is not an icon (I1). Every other glyph this panel
|
|
6
|
+
* needs — close, copy, check, refresh, warning — comes from that set.
|
|
7
7
|
*/
|
|
8
8
|
import type { SVGProps } from 'react';
|
|
9
9
|
/** A QR-symbol glyph: three finder squares plus a payload dot. */
|
|
10
10
|
export declare function QrIcon(props: SVGProps<SVGSVGElement>): import("react").JSX.Element;
|
|
11
|
-
/** Copy glyph. */
|
|
12
|
-
export declare function CopyIcon(props: SVGProps<SVGSVGElement>): import("react").JSX.Element;
|
|
13
|
-
/** Check glyph for the transient copied state. */
|
|
14
|
-
export declare function CheckIcon(props: SVGProps<SVGSVGElement>): import("react").JSX.Element;
|
|
15
|
-
/** Close glyph for the panel header. */
|
|
16
|
-
export declare function CloseIcon(props: SVGProps<SVGSVGElement>): import("react").JSX.Element;
|
|
17
|
-
/** Refresh glyph for the mint-again action. */
|
|
18
|
-
export declare function RefreshIcon(props: SVGProps<SVGSVGElement>): import("react").JSX.Element;
|
|
@@ -1,29 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `remote-bridge` namespace dictionaries: the protocol v1 pairing panel copy.
|
|
3
3
|
*
|
|
4
|
-
* The panel has one job —
|
|
5
|
-
* QR symbol
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* The panel has one job — put the live one-shot code in front of the operator as
|
|
5
|
+
* a QR symbol — so the copy carries exactly four things: what to do with the
|
|
6
|
+
* symbol, how long it lives, which address the phone will actually dial, and why
|
|
7
|
+
* the code is single-use. No key states how the host finds its public address:
|
|
8
|
+
* that is an implementation fact the reader cannot act on.
|
|
9
9
|
*/
|
|
10
10
|
/** Simplified Chinese dictionary (the key-set source of truth). */
|
|
11
11
|
export declare const zh: {
|
|
12
12
|
readonly 'entry.label': "配对手机(协议 v1)";
|
|
13
13
|
readonly title: "协议 v1 配对";
|
|
14
|
-
readonly subtitle: "用手机 App
|
|
14
|
+
readonly subtitle: "用手机 App 扫描二维码,即可让手机以协议 v1 连上这台宿主。配对码由本机签发,只在本机显示。";
|
|
15
15
|
readonly 'state.reading': "正在取配对码…";
|
|
16
16
|
readonly 'pair.qrLabel': "配对二维码";
|
|
17
|
-
readonly 'pair.payloadLabel': "二维码内容(可复制后粘贴到手机)";
|
|
18
17
|
readonly 'pair.countdown': "剩余 {s} 秒";
|
|
19
|
-
readonly 'pair.expired': "
|
|
20
|
-
readonly 'pair.expiredHint': "过期的配对码不会被手机接受,请重新取码。";
|
|
21
|
-
readonly 'pair.usedHint': "配对码一次性:手机调用 pair.begin 的瞬间即作废,重新取码也会作废上一张。";
|
|
18
|
+
readonly 'pair.expired': "配对码已过期";
|
|
22
19
|
readonly 'pair.refresh': "重新取码";
|
|
23
|
-
readonly '
|
|
24
|
-
readonly 'origin.
|
|
25
|
-
readonly 'origin.
|
|
26
|
-
readonly 'origin.located.body': "二维码里已经带上 {origin}:手机扫一次就同时设好连接地址与配对码,不需要手填任何东西。";
|
|
20
|
+
readonly 'pair.usedHint': "配对码一次性有效:手机一开始配对即作废,重新取码也会作废上一张。";
|
|
21
|
+
readonly 'origin.located': "手机将连到 {origin}";
|
|
22
|
+
readonly 'origin.missing': "没有找到公网地址:请先在手机里把连接地址填成你的公网中继,再扫码。本页的 {host} 只有本机能连。";
|
|
27
23
|
readonly 'forbidden.title': "这个页面不是从本机打开的";
|
|
28
24
|
readonly 'forbidden.body': "配对码只能在本机 Web UI 上取。请在本机浏览器打开 http://127.0.0.1:<端口> 后重试。";
|
|
29
25
|
readonly 'failed.title': "取配对码失败";
|
|
@@ -10,11 +10,9 @@ export declare const PLUGIN_ATTR = "remote-bridge";
|
|
|
10
10
|
export declare const PART_ENTRY = "entry";
|
|
11
11
|
/** The modal panel root. */
|
|
12
12
|
export declare const PART_PANEL = "panel";
|
|
13
|
-
/** The QR symbol's
|
|
13
|
+
/** The QR symbol's box — it also mirrors the encoded string. */
|
|
14
14
|
export declare const PART_QR = "qr";
|
|
15
|
-
/**
|
|
16
|
-
export declare const PART_TOKEN = "token";
|
|
17
|
-
/** A state notice: the origin warning, or a refusal the host raised. */
|
|
15
|
+
/** A refusal the host raised. */
|
|
18
16
|
export declare const PART_NOTICE = "notice";
|
|
19
17
|
/** The mint-again button. */
|
|
20
18
|
export declare const PART_REFRESH = "refresh";
|
|
@@ -23,6 +21,12 @@ export declare const PART_COPY = "copy";
|
|
|
23
21
|
/**
|
|
24
22
|
* Attribute carrying the exact string the QR symbol encodes, so the operator
|
|
25
23
|
* (and a UI check) can compare it against the host route's answer without
|
|
26
|
-
* decoding the symbol.
|
|
24
|
+
* decoding the symbol. It is the only machine trace the panel renders.
|
|
27
25
|
*/
|
|
28
26
|
export declare const QR_VALUE_ATTR = "data-dsh-qr-value";
|
|
27
|
+
/**
|
|
28
|
+
* Marks the QR part of a code that has run out of time. Expiry is state on the
|
|
29
|
+
* existing part, not a new part value: the cross-repository part enum is frozen
|
|
30
|
+
* and a plugin may not extend it for one visual state.
|
|
31
|
+
*/
|
|
32
|
+
export declare const EXPIRED_ATTR = "data-expired";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command channel's projection: the host's slash-command registry and one
|
|
3
|
+
* session's skill catalog folded into the single flat directory a phone lists.
|
|
4
|
+
*
|
|
5
|
+
* Nothing here is stateful. Every answer is read from the host on the call that
|
|
6
|
+
* answers it — no cache, no event, no snapshot — so a command a plugin
|
|
7
|
+
* registered a moment ago and a skill the session's own preset withdrew are
|
|
8
|
+
* both reflected in the next answer, and a phone never renders a directory that
|
|
9
|
+
* this bridge remembered on its behalf.
|
|
10
|
+
*
|
|
11
|
+
* The `line` of an item is the whole text a client completes into its draft,
|
|
12
|
+
* separator space included, because both host surfaces resolve a bare gesture
|
|
13
|
+
* only when whitespace or the end of the text follows the name: the command
|
|
14
|
+
* registry splits a line into name and input at that separator, and a skill
|
|
15
|
+
* gesture is `/(^|\s)\/([a-z0-9]+(?:-[a-z0-9]+)*)(?=\s|$)/` in
|
|
16
|
+
* `@deepseek-ai/dsh-tool-skill`. A skill line is therefore text a client writes
|
|
17
|
+
* and the host reads out of the submitted prompt, never a command line: a skill
|
|
18
|
+
* is not registered with the command registry, so `commands/execute` answers
|
|
19
|
+
* `undefined` for it — which is exactly what a caller of `session.command` is
|
|
20
|
+
* told with `matched: false`.
|
|
21
|
+
* @module dsh-remote-bridge/core/commands
|
|
22
|
+
*/
|
|
23
|
+
/** One row of the directory: a slash command or a skill, as the phone renders it. */
|
|
24
|
+
export interface CommandItem {
|
|
25
|
+
/** The host's own name for the row, without a leading slash. */
|
|
26
|
+
readonly name: string;
|
|
27
|
+
/** The host's own one-line summary, verbatim. */
|
|
28
|
+
readonly description: string;
|
|
29
|
+
/** Which host catalog the row came from; the two never mix order. */
|
|
30
|
+
readonly kind: 'command' | 'skill';
|
|
31
|
+
/** The complete draft text that invokes this row. */
|
|
32
|
+
readonly line: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Fold the host's two catalogs into one directory: every command first, in the
|
|
36
|
+
* order the host listed them, then every skill, in the order the host listed
|
|
37
|
+
* them. Neither list is re-sorted, de-duplicated or cut into pages — a name
|
|
38
|
+
* both catalogs carry stays two rows, because the two rows do different things.
|
|
39
|
+
* @param commands - the `commands/list` answer, as it arrived.
|
|
40
|
+
* @param skills - the `skills/list` answer's `skills` array, as it arrived.
|
|
41
|
+
* @returns the rows a client renders, in the one order this protocol promises.
|
|
42
|
+
*/
|
|
43
|
+
export declare function commandItems(commands: readonly unknown[], skills: readonly unknown[]): readonly CommandItem[];
|
|
44
|
+
/**
|
|
45
|
+
* Whether a gateway failure means this host serves no endpoint behind the
|
|
46
|
+
* channel at all, rather than refusing this one call.
|
|
47
|
+
*
|
|
48
|
+
* The gateway reports an endpoint nothing exports as `invocation-unavailable`
|
|
49
|
+
* and a withdrawn strict definition as `definition-unavailable`; both leave the
|
|
50
|
+
* call with nowhere to go, which is the one case this bridge answers with its
|
|
51
|
+
* own `commands-unavailable`. A service that is merely still activating keeps
|
|
52
|
+
* its own code: that window is retried before it arrives here, and a retried
|
|
53
|
+
* failure is a broken deployment rather than an absent channel.
|
|
54
|
+
*
|
|
55
|
+
* Both spellings of each code are recognized, exactly as `gateway-errors.ts`
|
|
56
|
+
* recognizes them for the activation window.
|
|
57
|
+
* @param code - the failure's own code, as it crossed to the refusal.
|
|
58
|
+
*/
|
|
59
|
+
export declare function commandsUnavailable(code: string): boolean;
|
|
@@ -19,10 +19,14 @@ import type { ApprovalRegistry } from './approvals.ts';
|
|
|
19
19
|
import type { DeviceRoster } from './devices.ts';
|
|
20
20
|
import type { RemoteBridgeRegistry } from './extension.ts';
|
|
21
21
|
import { type JobRoster } from './jobs.ts';
|
|
22
|
+
import type { LiveActivityNotifier } from './liveactivity.ts';
|
|
22
23
|
import type { PairingService } from './pairing.ts';
|
|
24
|
+
import type { PushNotifier } from './push.ts';
|
|
23
25
|
import type { QuestionClaims } from './questions.ts';
|
|
26
|
+
import { type SquadTransport } from './squads.ts';
|
|
24
27
|
import { type SessionMeta } from './session-meta.ts';
|
|
25
28
|
import type { SessionPermissions } from './session-permissions.ts';
|
|
29
|
+
import { type UsageService } from './usage.ts';
|
|
26
30
|
import type { BridgeGateway, GatewayPeer } from './wire.ts';
|
|
27
31
|
/** Protocol-level heartbeat period: a frame is sent after this long without one. */
|
|
28
32
|
export declare const IDLE_PING_MS = 20000;
|
|
@@ -88,6 +92,12 @@ export interface BridgeConnectionOptions {
|
|
|
88
92
|
readonly jobs: JobRoster;
|
|
89
93
|
/** Process-local session metadata: live titles and the host's archive set. */
|
|
90
94
|
readonly sessionMeta: SessionMeta;
|
|
95
|
+
/**
|
|
96
|
+
* `usage.v1` 背后两半读数:一条会话的上下文窗口与请求组成估算,以及某条
|
|
97
|
+
* provider 路由背后账户的余额。两者都是宿主侧的事实而不是某个设备的事实,
|
|
98
|
+
* 所以一个宿主一份、所有连接共享(见 `core/usage.ts`)。
|
|
99
|
+
*/
|
|
100
|
+
readonly usage: UsageService;
|
|
91
101
|
/** Host-process permission presets, read and switched through their real service objects. */
|
|
92
102
|
readonly permissions: SessionPermissions;
|
|
93
103
|
/**
|
|
@@ -114,11 +124,69 @@ export interface BridgeConnectionOptions {
|
|
|
114
124
|
* `KNOWN_METHODS` answers `unknown-method`.
|
|
115
125
|
*/
|
|
116
126
|
readonly extensions?: RemoteBridgeRegistry;
|
|
127
|
+
/**
|
|
128
|
+
* The host's squad domain, behind the `squads.v1` channel. Absent is a host
|
|
129
|
+
* that serves no `dsh-agents` domain: the capability stays advertised and only
|
|
130
|
+
* a call that needs the domain answers `squads-unavailable`.
|
|
131
|
+
*/
|
|
132
|
+
readonly squads?: SquadTransport;
|
|
133
|
+
/**
|
|
134
|
+
* The outbound notification path, behind the `push.v1` channel. Absent is a
|
|
135
|
+
* bridge that sends nothing: `push.register` still answers `ok:true` (the
|
|
136
|
+
* device row is written either way), and no notification is ever built. That
|
|
137
|
+
* is the default, because a sender needs an Apple signing key this bridge is
|
|
138
|
+
* not shipped with.
|
|
139
|
+
*/
|
|
140
|
+
readonly push?: PushNotifier;
|
|
141
|
+
/**
|
|
142
|
+
* The lock-screen card path, behind the same `push.v1` channel. Absent — and it
|
|
143
|
+
* is absent whenever no APNs key is configured — is a bridge that never builds a
|
|
144
|
+
* card: the roster is still served and a question is still answered, because
|
|
145
|
+
* registering the phone's tokens and pushing to them are two different things
|
|
146
|
+
* (§28.3, §29).
|
|
147
|
+
*/
|
|
148
|
+
readonly liveActivity?: LiveActivityNotifier;
|
|
149
|
+
/**
|
|
150
|
+
* Called after a registration changed the device table.
|
|
151
|
+
*
|
|
152
|
+
* A session's first live-activity token is what asks this bridge to keep a
|
|
153
|
+
* follow stream of its own open for that session (`host/watchers.ts`), so the
|
|
154
|
+
* roster is the trigger. The hook is guarded at the call site: a standing
|
|
155
|
+
* watcher is this bridge's own background work and may never turn a
|
|
156
|
+
* `push.register` into a failure.
|
|
157
|
+
*/
|
|
158
|
+
readonly onPushRegistered?: () => void;
|
|
117
159
|
}
|
|
118
160
|
/** A device the connection proved itself to be, resolved from the upgrade request. */
|
|
119
161
|
export interface ConnectionAuth {
|
|
120
162
|
readonly deviceId: string;
|
|
121
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* One model selection, in the field names the protocol publishes.
|
|
166
|
+
*
|
|
167
|
+
* Exported beside {@link selectionOf} and {@link modelSelectionOf} because the
|
|
168
|
+
* host half resolves a session's current route for `usage.stats`'s neighbour
|
|
169
|
+
* key `usage.session`/`modelContextWindow` with exactly this fold: two readings
|
|
170
|
+
* of "which model is this session on" would let the two methods name different
|
|
171
|
+
* routes for the same session.
|
|
172
|
+
*/
|
|
173
|
+
export type ModelSelection = {
|
|
174
|
+
readonly provider: string;
|
|
175
|
+
readonly model: string;
|
|
176
|
+
readonly reasoningEffort?: string;
|
|
177
|
+
};
|
|
178
|
+
/** @returns the selection this value describes, or undefined when it describes none. */
|
|
179
|
+
export declare function selectionOf(value: unknown): ModelSelection | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* The durable model-selection fold of one `session/projections` answer.
|
|
182
|
+
*
|
|
183
|
+
* Both halves stay optional: a session that never ran has neither, and the
|
|
184
|
+
* catalog default is then the only truthful current value.
|
|
185
|
+
*/
|
|
186
|
+
export declare function modelSelectionOf(value: unknown): {
|
|
187
|
+
readonly next?: ModelSelection;
|
|
188
|
+
readonly lastUsed?: ModelSelection;
|
|
189
|
+
};
|
|
122
190
|
export declare class BridgeConnection {
|
|
123
191
|
#private;
|
|
124
192
|
constructor(options: BridgeConnectionOptions, transport: BridgeTransport, auth?: ConnectionAuth);
|
|
@@ -14,8 +14,57 @@
|
|
|
14
14
|
export declare const DEVICE_TOKEN_BYTES = 32;
|
|
15
15
|
/** Entropy of one device id. */
|
|
16
16
|
export declare const DEVICE_ID_BYTES = 12;
|
|
17
|
-
/**
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* On-disk schema version of the roster file.
|
|
19
|
+
*
|
|
20
|
+
* 1 carried the six identity fields only; 2 adds the optional `push` block per
|
|
21
|
+
* row (§28). The difference is additive, so a version-1 file reads as-is: no row
|
|
22
|
+
* loses a field, every paired phone stays paired, and the file is rewritten as
|
|
23
|
+
* version 2 the next time anything is written. The reader therefore accepts any
|
|
24
|
+
* version whose row table validates rather than quarantining a file it merely
|
|
25
|
+
* does not recognise — a downgrade must never un-pair every phone.
|
|
26
|
+
*/
|
|
27
|
+
export declare const ROSTER_VERSION = 2;
|
|
28
|
+
/** The APNs environments a device may register for. */
|
|
29
|
+
export type PushEnvironment = 'sandbox' | 'production';
|
|
30
|
+
/** One Live Activity push token, with the session the card belongs to. */
|
|
31
|
+
export interface PushLiveActivityToken {
|
|
32
|
+
readonly activityId: string;
|
|
33
|
+
readonly token: string;
|
|
34
|
+
/**
|
|
35
|
+
* The session this card belongs to (§29.9).
|
|
36
|
+
*
|
|
37
|
+
* A card is about one session, and a token without this field cannot be
|
|
38
|
+
* addressed at all: this bridge has nothing to put on it. Absent is therefore
|
|
39
|
+
* "never pushed to", not "pushed to with whatever is at hand" — the other
|
|
40
|
+
* reading would put one session's state on another session's lock screen.
|
|
41
|
+
*/
|
|
42
|
+
readonly sessionId?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What one device registered so this bridge can notify it.
|
|
46
|
+
*
|
|
47
|
+
* Stored beside the device's identity in the same row: it is a fact about that
|
|
48
|
+
* device, so it disappears with the row when the device is revoked and it never
|
|
49
|
+
* becomes a second identity. Nothing here is a secret of the bridge's — an APNs
|
|
50
|
+
* token is the phone's, and holding it grants nothing without the signing key,
|
|
51
|
+
* which never touches this file.
|
|
52
|
+
*/
|
|
53
|
+
export interface PushRegistration {
|
|
54
|
+
/** APNs device token, as the hex string the system handed the app. */
|
|
55
|
+
readonly deviceToken: string;
|
|
56
|
+
readonly environment: PushEnvironment;
|
|
57
|
+
/** The app's bundle id, used verbatim as `apns-topic`. */
|
|
58
|
+
readonly bundle: string;
|
|
59
|
+
readonly locale?: string;
|
|
60
|
+
readonly liveActivityTokens?: readonly PushLiveActivityToken[];
|
|
61
|
+
readonly registeredAt: number;
|
|
62
|
+
}
|
|
63
|
+
/** One device a notification can be addressed to. */
|
|
64
|
+
export interface PushTargetView {
|
|
65
|
+
readonly deviceId: string;
|
|
66
|
+
readonly push: PushRegistration;
|
|
67
|
+
}
|
|
19
68
|
/** One paired device as the bridge keeps it. */
|
|
20
69
|
export interface DeviceRecord {
|
|
21
70
|
readonly deviceId: string;
|
|
@@ -25,6 +74,12 @@ export interface DeviceRecord {
|
|
|
25
74
|
readonly fingerprint: string;
|
|
26
75
|
readonly createdAt: number;
|
|
27
76
|
readonly lastSeenAt: number;
|
|
77
|
+
/**
|
|
78
|
+
* The device's APNs registration, absent until it calls `push.register`.
|
|
79
|
+
* A row without it is a paired phone that asks for no notification, which is
|
|
80
|
+
* every phone that predates the channel.
|
|
81
|
+
*/
|
|
82
|
+
readonly push?: PushRegistration;
|
|
28
83
|
}
|
|
29
84
|
/** What one successful enrollment hands back to the caller exactly once. */
|
|
30
85
|
export interface EnrollmentResult {
|
|
@@ -69,4 +124,45 @@ export declare class DeviceRoster {
|
|
|
69
124
|
enroll(pubKey: string): Promise<EnrollmentResult | undefined>;
|
|
70
125
|
/** Record that a device just reconnected; the file is refreshed at most once per call. */
|
|
71
126
|
touch(deviceId: string): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Record this device's APNs registration, replacing any it had.
|
|
129
|
+
*
|
|
130
|
+
* Registering twice is what a token rotation looks like from here, so this is
|
|
131
|
+
* a plain overwrite rather than a merge: the newest complete registration is
|
|
132
|
+
* the only one worth sending to, and a half-merged pair of rows would send to
|
|
133
|
+
* a token the phone already retired.
|
|
134
|
+
* @param deviceId - the device that just registered.
|
|
135
|
+
* @param registration - what it registered.
|
|
136
|
+
* @returns false when no such device is paired.
|
|
137
|
+
*/
|
|
138
|
+
registerPush(deviceId: string, registration: PushRegistration): Promise<boolean>;
|
|
139
|
+
/**
|
|
140
|
+
* Forget one Live Activity token the phone no longer holds.
|
|
141
|
+
*
|
|
142
|
+
* APNs answers 410 (or 400 `BadDeviceToken`) for the token of a card the app
|
|
143
|
+
* already ended, and such a token never works again: the next card arrives as a
|
|
144
|
+
* new activity with a new token through `push.register`, which is a complete
|
|
145
|
+
* replacement of this set. Dropping it here is therefore the whole recovery —
|
|
146
|
+
* retrying would only repeat the same refusal (§29 token lifecycle).
|
|
147
|
+
* @param activityId - the card the token belonged to.
|
|
148
|
+
* @param token - the token APNs refused.
|
|
149
|
+
* @returns whether any row changed.
|
|
150
|
+
*/
|
|
151
|
+
removeLiveActivityToken(activityId: string, token: string): Promise<boolean>;
|
|
152
|
+
/**
|
|
153
|
+
* Forget one device's notification registration for a token APNs will never
|
|
154
|
+
* accept again.
|
|
155
|
+
*
|
|
156
|
+
* A dead alert token is the whole app install's refusal: the phone was restored,
|
|
157
|
+
* reinstalled, or the token belongs to another environment or bundle, so the
|
|
158
|
+
* Live Activity tokens that same install registered are dead by the same fact
|
|
159
|
+
* and go with it. The next `push.register` — which a live app performs on launch
|
|
160
|
+
* — writes a complete new block. The device itself stays paired: revoking a
|
|
161
|
+
* phone is a roster edit, never something a push refusal may do.
|
|
162
|
+
* @param deviceToken - the token APNs refused.
|
|
163
|
+
* @returns whether any row changed.
|
|
164
|
+
*/
|
|
165
|
+
removePush(deviceToken: string): Promise<boolean>;
|
|
166
|
+
/** @returns every paired device that registered for notifications. */
|
|
167
|
+
pushTargets(): readonly PushTargetView[];
|
|
72
168
|
}
|
package/lib/types/core/hub.d.ts
CHANGED
|
@@ -2,18 +2,27 @@
|
|
|
2
2
|
* The bridge's process-wide connection registry and its claims on
|
|
3
3
|
* `approval/request` and `user-questions/request`.
|
|
4
4
|
*
|
|
5
|
-
* The hub is what makes "phone not answering equals refusal" true:
|
|
6
|
-
* is claimed only while at least one paired device is connected, the publish
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* The hub is what makes "phone not answering equals refusal" true: an approval
|
|
6
|
+
* is claimed only while at least one paired device is connected, the publish has
|
|
7
|
+
* to actually reach someone, and every other path (timeout, agent cancellation,
|
|
8
|
+
* the last phone leaving) delegates to the next answerer, which the Host
|
|
9
|
+
* normalizes to `'unavailable'`.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* A user question adds the one case where "reach someone" is the notification
|
|
12
|
+
* rather than the socket: with no paired connection on the wire but a device on
|
|
13
|
+
* the roster that registered for pushes, the question is claimed for that phone
|
|
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.
|
|
18
|
+
*
|
|
19
|
+
* The claim on `user-questions/request` follows the same rules, with three
|
|
12
20
|
* differences that belong to the host's own semantics: delegating is not a
|
|
13
21
|
* refusal, because only a phone that declares `questions.v1` is ever shown the
|
|
14
|
-
* question;
|
|
22
|
+
* question; a question is named on the wire even when the host named none,
|
|
15
23
|
* because a blocking ask carries no call id and the phone still needs a handle
|
|
16
|
-
* to answer with
|
|
24
|
+
* to answer with; and the claim outlives the last paired device by a grace
|
|
25
|
+
* window, because a phone whose app the system suspended has refused nothing.
|
|
17
26
|
* @module dsh-remote-bridge/core/hub
|
|
18
27
|
*/
|
|
19
28
|
import type { ApprovalOutcome } from '@deepseek-ai/dsh-user-approval';
|
|
@@ -46,10 +55,48 @@ export interface ApprovalRequestPayload {
|
|
|
46
55
|
readonly summary: string;
|
|
47
56
|
readonly toolName: string;
|
|
48
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* How long a user question outlives the last paired device, in milliseconds.
|
|
60
|
+
*
|
|
61
|
+
* A push notification carries a session link and nothing else: the phone can
|
|
62
|
+
* draw a question card only while this bridge still holds the claim, and it has
|
|
63
|
+
* to reconnect before it can read one. A phone whose app was suspended is gone
|
|
64
|
+
* for tens of seconds, so releasing the claim the instant its socket drops
|
|
65
|
+
* decides the question for it — the ask went back to the host's own answerer
|
|
66
|
+
* chain, the Mac showed the card, and the tap that arrived afterwards opened a
|
|
67
|
+
* session with nothing in it (measured 2026-10-23). The window is that reconnect
|
|
68
|
+
* budget, not a second deadline: a claim no phone came back for is released on
|
|
69
|
+
* expiry exactly as it was before.
|
|
70
|
+
*/
|
|
71
|
+
export declare const QUESTION_CLAIM_GRACE_MS = 60000;
|
|
72
|
+
/**
|
|
73
|
+
* How long a user question is held for a phone this bridge reached by
|
|
74
|
+
* notification only, in milliseconds (§32.2).
|
|
75
|
+
*
|
|
76
|
+
* Inside this window the question exists only on the phone's side: the alert is
|
|
77
|
+
* out, no socket has it, and the host's own answerer chain has not been started.
|
|
78
|
+
* When it runs out the claim is withdrawn and delegated, so the agent behind a
|
|
79
|
+
* timed ask waits at most this long past its own deadline and the agent behind a
|
|
80
|
+
* blocking ask (no call id, no deadline) waits at most this long in total — an
|
|
81
|
+
* accepted cost, because the alternative is a question that vanished while the
|
|
82
|
+
* phone was asleep. The window is the bridge's own constant and not the host's:
|
|
83
|
+
* a deployment overrides it, the host never sees it.
|
|
84
|
+
*/
|
|
85
|
+
export declare const OFFLINE_QUESTION_CLAIM_TTL_MS = 600000;
|
|
86
|
+
/** What the hub is built with: the bridge's shared options plus the windows it owns. */
|
|
87
|
+
export interface BridgeHubOptions extends BridgeConnectionOptions {
|
|
88
|
+
/**
|
|
89
|
+
* The offline claim window, in milliseconds.
|
|
90
|
+
*
|
|
91
|
+
* Defaults to {@link OFFLINE_QUESTION_CLAIM_TTL_MS}; a deployment knob, and the
|
|
92
|
+
* seam a suite uses to move the window instead of waiting it out.
|
|
93
|
+
*/
|
|
94
|
+
readonly offlineClaimTtlMs?: number;
|
|
95
|
+
}
|
|
49
96
|
/** The bridge's live connections plus the answerer it composes onto the approval chain. */
|
|
50
97
|
export declare class BridgeHub {
|
|
51
98
|
#private;
|
|
52
|
-
constructor(options:
|
|
99
|
+
constructor(options: BridgeHubOptions);
|
|
53
100
|
/** @returns how many paired devices could answer a question right now. */
|
|
54
101
|
get pairedClients(): number;
|
|
55
102
|
/**
|
|
@@ -60,7 +107,8 @@ export declare class BridgeHub {
|
|
|
60
107
|
attach(transport: BridgeTransport, auth?: ConnectionAuth): BridgeConnection;
|
|
61
108
|
/**
|
|
62
109
|
* Forget one connection and abort everything it owns. When it was the last
|
|
63
|
-
* paired device, every pending
|
|
110
|
+
* paired device, every pending approval is withdrawn at once and every pending
|
|
111
|
+
* user question is released when its grace window ends.
|
|
64
112
|
*/
|
|
65
113
|
detach(connection: BridgeConnection): void;
|
|
66
114
|
/**
|
|
@@ -108,11 +156,13 @@ export declare class BridgeHub {
|
|
|
108
156
|
/**
|
|
109
157
|
* The body of this plugin's `user-questions/request` listener.
|
|
110
158
|
*
|
|
111
|
-
* Claimed only while a
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
159
|
+
* Claimed only while a device that is reachable right now can be shown the
|
|
160
|
+
* card: a paired connection that declared `questions.v1`, or — with no phone on
|
|
161
|
+
* the wire — a roster device that registered for notifications, which the alert
|
|
162
|
+
* reaches instead of a frame (§11.3, §32). The payload has no session field of
|
|
163
|
+
* its own, so an ask that names no agent is delegated either. The wire id is the
|
|
164
|
+
* host's own when the ask is timed, and minted here when it is blocking and the
|
|
165
|
+
* host assigned none — either way the phone answers the id it was shown. A claim
|
|
116
166
|
* nobody received is withdrawn at once instead of holding the agent until the
|
|
117
167
|
* host's deadline. For a timed ask the host's own remaining wait travels with
|
|
118
168
|
* the first frame as `expiresAt`, and every later move of that deadline is
|