@linxin666/dsh-remote-bridge 0.4.7 → 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 +93 -26
- package/README.zh.md +91 -26
- package/icon.svg +3 -0
- package/lib/client.js +274 -253
- package/lib/client.js.map +1 -1
- package/lib/index.js +8891 -2433
- 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/approvals.d.ts +24 -0
- package/lib/types/core/commands.d.ts +59 -0
- package/lib/types/core/connection.d.ts +124 -5
- package/lib/types/core/delta.d.ts +101 -0
- package/lib/types/core/devices.d.ts +98 -2
- package/lib/types/core/dsh-frames.d.ts +155 -4
- package/lib/types/core/envelope.d.ts +34 -0
- package/lib/types/core/extension.d.ts +144 -0
- package/lib/types/core/hub.d.ts +96 -20
- package/lib/types/core/jobs.d.ts +204 -0
- package/lib/types/core/liveactivity.d.ts +324 -0
- package/lib/types/core/protocol.d.ts +491 -2
- package/lib/types/core/push.d.ts +178 -0
- package/lib/types/core/questions.d.ts +109 -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/core/wire.d.ts +1 -1
- package/lib/types/core/ws-frames.d.ts +11 -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/host/websocket.d.ts +8 -1
- package/lib/types/index.d.ts +34 -3
- package/lib/types/mount-once.d.ts +55 -0
- package/locale/en.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +20 -14
- 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/approvals.ts +32 -1
- package/src/core/commands.ts +95 -0
- package/src/core/connection.ts +1483 -31
- package/src/core/delta.ts +204 -0
- package/src/core/devices.ts +221 -3
- package/src/core/dsh-frames.ts +365 -8
- package/src/core/envelope.ts +46 -0
- package/src/core/extension.ts +197 -0
- package/src/core/hub.ts +441 -49
- package/src/core/jobs.ts +372 -0
- package/src/core/liveactivity.ts +833 -0
- package/src/core/protocol.ts +556 -2
- package/src/core/push.ts +354 -0
- package/src/core/questions.ts +264 -17
- 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 +13 -1
- package/src/core/ws-frames.ts +14 -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/host/websocket.ts +37 -3
- package/src/index.ts +310 -9
- package/src/mount-once.ts +142 -0
|
@@ -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";
|
|
@@ -32,6 +32,19 @@ export interface ApprovalPrompt {
|
|
|
32
32
|
/** Settles exactly once, with a decision or `undefined` to delegate. */
|
|
33
33
|
readonly answer: Promise<ApprovalAnswer>;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* One live question as a second delivery publishes it.
|
|
37
|
+
*
|
|
38
|
+
* The same four fields the first broadcast carries, so a card a phone was shown
|
|
39
|
+
* and the same card handed to it again after a reconnect cannot be spelled
|
|
40
|
+
* differently.
|
|
41
|
+
*/
|
|
42
|
+
export interface PendingPromptView {
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly sessionId: string;
|
|
45
|
+
readonly toolName: string;
|
|
46
|
+
readonly summary: string;
|
|
47
|
+
}
|
|
35
48
|
export interface ApprovalRegistryOptions {
|
|
36
49
|
readonly timeoutMs?: number;
|
|
37
50
|
/** Id source, injectable so a test can answer the exact id it was given. */
|
|
@@ -49,6 +62,17 @@ export declare class ApprovalRegistry {
|
|
|
49
62
|
constructor(options?: ApprovalRegistryOptions);
|
|
50
63
|
/** @returns how many questions are currently waiting for a phone. */
|
|
51
64
|
get size(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Every question still waiting for a phone, in claim order.
|
|
67
|
+
*
|
|
68
|
+
* Only a live claim can be named here: {@link #settle} is the single path out
|
|
69
|
+
* of the pending map, and an answer, the bridge's own timeout, the agent's
|
|
70
|
+
* cancellation and every withdrawal all pass through it before this reads the
|
|
71
|
+
* map again. A question this bridge released therefore cannot come back to a
|
|
72
|
+
* client that reconnects.
|
|
73
|
+
* @returns the fields a second delivery republishes, oldest claim first.
|
|
74
|
+
*/
|
|
75
|
+
openPrompts(): readonly PendingPromptView[];
|
|
52
76
|
/**
|
|
53
77
|
* Claim one question.
|
|
54
78
|
* @param input - session identity, tool name, presentation summary, and the agent's own lifetime.
|
|
@@ -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;
|
|
@@ -17,19 +17,53 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import type { ApprovalRegistry } from './approvals.ts';
|
|
19
19
|
import type { DeviceRoster } from './devices.ts';
|
|
20
|
+
import type { RemoteBridgeRegistry } from './extension.ts';
|
|
21
|
+
import { type JobRoster } from './jobs.ts';
|
|
22
|
+
import type { LiveActivityNotifier } from './liveactivity.ts';
|
|
20
23
|
import type { PairingService } from './pairing.ts';
|
|
24
|
+
import type { PushNotifier } from './push.ts';
|
|
21
25
|
import type { QuestionClaims } from './questions.ts';
|
|
26
|
+
import { type SquadTransport } from './squads.ts';
|
|
22
27
|
import { type SessionMeta } from './session-meta.ts';
|
|
23
28
|
import type { SessionPermissions } from './session-permissions.ts';
|
|
29
|
+
import { type UsageService } from './usage.ts';
|
|
24
30
|
import type { BridgeGateway, GatewayPeer } from './wire.ts';
|
|
25
31
|
/** Protocol-level heartbeat period: a frame is sent after this long without one. */
|
|
26
32
|
export declare const IDLE_PING_MS = 20000;
|
|
33
|
+
/**
|
|
34
|
+
* Deadline behind one liveness ping: a peer that sends no frame at all within
|
|
35
|
+
* this long of the ping is torn down.
|
|
36
|
+
*
|
|
37
|
+
* It only ever exists because a ping was sent — a connection the host has not
|
|
38
|
+
* pinged has no deadline — so a quiet client is never closed for being quiet,
|
|
39
|
+
* only for failing to answer. The measured one-way path over the relay is about
|
|
40
|
+
* 410 ms (2026-10-19), so this is more than an order of magnitude of slack.
|
|
41
|
+
*/
|
|
42
|
+
export declare const LIVENESS_TIMEOUT_MS = 10000;
|
|
27
43
|
/** How long `session.snapshot` waits for its follow stream's opening frame. */
|
|
28
44
|
export declare const SNAPSHOT_OPEN_TIMEOUT_MS = 10000;
|
|
29
45
|
/** Largest turn window one snapshot asks DSH for. */
|
|
30
46
|
export declare const SNAPSHOT_MAX_MESSAGES = 200;
|
|
31
47
|
/** Default byte budget of one `session.history` page: 512 KiB. */
|
|
32
48
|
export declare const HISTORY_PAGE_BYTES: number;
|
|
49
|
+
/**
|
|
50
|
+
* Window one `session.history.deep` read asks DSH for: at least 50 user or
|
|
51
|
+
* assistant messages across at least 2 turns, and never more than 500 messages.
|
|
52
|
+
*
|
|
53
|
+
* It is the window the harness's own Web client pages history with, and it is
|
|
54
|
+
* deliberately wider than one answer: a byte budget is the caller's, so the
|
|
55
|
+
* store is asked for a whole span once and the bridge then cuts that span to
|
|
56
|
+
* `maxBytes` by entry. Nothing in the answer depends on where the store cut:
|
|
57
|
+
* the host's `hasMore` is folded into the answer's own `hasMore`, and the
|
|
58
|
+
* cursor is always the oldest entry the answer carries.
|
|
59
|
+
*/
|
|
60
|
+
export declare const DEEP_HISTORY_WINDOW: {
|
|
61
|
+
readonly maxMessages: 500;
|
|
62
|
+
readonly turnWindow: {
|
|
63
|
+
readonly minMessages: 50;
|
|
64
|
+
readonly minTurns: 2;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
33
67
|
/** Highest number of prompt receipts one connection remembers for idempotency. */
|
|
34
68
|
export declare const PROMPT_RECEIPT_LIMIT = 512;
|
|
35
69
|
/** Largest base64 text one prompt attachment may carry: 6 MiB (protocol §10.2). */
|
|
@@ -38,6 +72,14 @@ export declare const PROMPT_ATTACHMENT_MAX_BYTES: number;
|
|
|
38
72
|
export interface BridgeTransport {
|
|
39
73
|
send(text: string): void;
|
|
40
74
|
close(code: number, reason: string): void;
|
|
75
|
+
/**
|
|
76
|
+
* Optional: whether the peer declared `frame.deflate.v1`, reported once the
|
|
77
|
+
* `hello` that declares it has been recorded. The capability is the client's
|
|
78
|
+
* declaration and the wire form is the carrier's, so this is the one fact that
|
|
79
|
+
* has to cross between them. A carrier with no socket to compress — a
|
|
80
|
+
* recording double, for one — omits the member and keeps writing text.
|
|
81
|
+
*/
|
|
82
|
+
frameDeflate?(declared: boolean): void;
|
|
41
83
|
}
|
|
42
84
|
export interface BridgeConnectionOptions {
|
|
43
85
|
readonly gateway: BridgeGateway;
|
|
@@ -46,8 +88,16 @@ export interface BridgeConnectionOptions {
|
|
|
46
88
|
readonly approvals: ApprovalRegistry;
|
|
47
89
|
/** Pending user questions: the claims this bridge holds and the answer path back to the host. */
|
|
48
90
|
readonly questions: QuestionClaims;
|
|
91
|
+
/** The host's background jobs: the read-only projection and the scopes this connection watches. */
|
|
92
|
+
readonly jobs: JobRoster;
|
|
49
93
|
/** Process-local session metadata: live titles and the host's archive set. */
|
|
50
94
|
readonly sessionMeta: SessionMeta;
|
|
95
|
+
/**
|
|
96
|
+
* `usage.v1` 背后两半读数:一条会话的上下文窗口与请求组成估算,以及某条
|
|
97
|
+
* provider 路由背后账户的余额。两者都是宿主侧的事实而不是某个设备的事实,
|
|
98
|
+
* 所以一个宿主一份、所有连接共享(见 `core/usage.ts`)。
|
|
99
|
+
*/
|
|
100
|
+
readonly usage: UsageService;
|
|
51
101
|
/** Host-process permission presets, read and switched through their real service objects. */
|
|
52
102
|
readonly permissions: SessionPermissions;
|
|
53
103
|
/**
|
|
@@ -68,18 +118,75 @@ export interface BridgeConnectionOptions {
|
|
|
68
118
|
*/
|
|
69
119
|
readonly onDeclare?: (connection: BridgeConnection) => void;
|
|
70
120
|
readonly heartbeatMs?: number;
|
|
121
|
+
/**
|
|
122
|
+
* Methods plugins registered on the bridge's extension seam. Absent is the
|
|
123
|
+
* protocol exactly as this package defines it: every name outside
|
|
124
|
+
* `KNOWN_METHODS` answers `unknown-method`.
|
|
125
|
+
*/
|
|
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;
|
|
71
159
|
}
|
|
72
160
|
/** A device the connection proved itself to be, resolved from the upgrade request. */
|
|
73
161
|
export interface ConnectionAuth {
|
|
74
162
|
readonly deviceId: string;
|
|
75
163
|
}
|
|
76
164
|
/**
|
|
77
|
-
*
|
|
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.
|
|
78
182
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* a subscription's own drain loop.
|
|
183
|
+
* Both halves stay optional: a session that never ran has neither, and the
|
|
184
|
+
* catalog default is then the only truthful current value.
|
|
82
185
|
*/
|
|
186
|
+
export declare function modelSelectionOf(value: unknown): {
|
|
187
|
+
readonly next?: ModelSelection;
|
|
188
|
+
readonly lastUsed?: ModelSelection;
|
|
189
|
+
};
|
|
83
190
|
export declare class BridgeConnection {
|
|
84
191
|
#private;
|
|
85
192
|
constructor(options: BridgeConnectionOptions, transport: BridgeTransport, auth?: ConnectionAuth);
|
|
@@ -89,6 +196,11 @@ export declare class BridgeConnection {
|
|
|
89
196
|
get deviceId(): string | undefined;
|
|
90
197
|
/** @returns whether the connection has been torn down. */
|
|
91
198
|
get disposed(): boolean;
|
|
199
|
+
/**
|
|
200
|
+
* @returns this connection's identity for the extension seam. Stable for the
|
|
201
|
+
* life of the socket and never reused by a later one.
|
|
202
|
+
*/
|
|
203
|
+
get id(): string;
|
|
92
204
|
/**
|
|
93
205
|
* @param capability - one capability name this protocol defines.
|
|
94
206
|
* @returns whether this connection announced it in `hello`.
|
|
@@ -114,6 +226,13 @@ export declare class BridgeConnection {
|
|
|
114
226
|
* Tear the connection down: stop the heartbeat, abort every follow stream it
|
|
115
227
|
* owns, and tell the carrier to go away. Idempotent, and safe to call from a
|
|
116
228
|
* socket error handler — a carrier whose socket already closed ignores it.
|
|
229
|
+
* @param close - the close frame to send instead of the bridge-unloading one.
|
|
230
|
+
* Only the liveness deadline passes it, so a client can tell a peer that
|
|
231
|
+
* stopped answering from an ordinary teardown; every other caller leaves it
|
|
232
|
+
* out and keeps the same code and reason as before.
|
|
117
233
|
*/
|
|
118
|
-
dispose(
|
|
234
|
+
dispose(close?: {
|
|
235
|
+
readonly code: number;
|
|
236
|
+
readonly reason: string;
|
|
237
|
+
}): void;
|
|
119
238
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-connection delta windows: what a client that already holds a copy of a
|
|
3
|
+
* whole set is sent instead of the whole set again.
|
|
4
|
+
*
|
|
5
|
+
* The difference is computed here, in the bridge, because the bridge is the
|
|
6
|
+
* only place that holds what the host said last — the host itself is asked for
|
|
7
|
+
* its complete answer every time and never learns that a client is caching one.
|
|
8
|
+
* That is the whole point of this module: the saving is bytes on the wire
|
|
9
|
+
* between the bridge and the phone, not a change to any host API.
|
|
10
|
+
*
|
|
11
|
+
* Three rules live in this file and nowhere else, so the roster and the board
|
|
12
|
+
* cannot disagree about them:
|
|
13
|
+
*
|
|
14
|
+
* - a delta is only diffed against the exact set this window last sent, and
|
|
15
|
+
* only for a token this window itself issued; anything else answers a reset,
|
|
16
|
+
* because a wrong base is a wrong answer;
|
|
17
|
+
* - a change is a change of the serialised row, not of a timestamp — the host's
|
|
18
|
+
* `updatedAt` is not a change signal for every field, and a row whose body is
|
|
19
|
+
* byte-identical has not changed;
|
|
20
|
+
* - a delta that is not clearly smaller than the reset body is not worth
|
|
21
|
+
* sending: past {@link DELTA_CHANGED_RATIO} of the rows, the answer is a reset.
|
|
22
|
+
* @module dsh-remote-bridge/core/delta
|
|
23
|
+
*/
|
|
24
|
+
/** Largest roster one connection's delta window retains. */
|
|
25
|
+
export declare const ROSTER_DELTA_MAX_ROWS = 5000;
|
|
26
|
+
/** Largest board one connection's delta window retains. */
|
|
27
|
+
export declare const BOARD_DELTA_MAX_ROWS = 2000;
|
|
28
|
+
/**
|
|
29
|
+
* Share of the current set that may change before a reset is the cheaper
|
|
30
|
+
* answer. Bytes, not cleverness: past this point the delta carries most of the
|
|
31
|
+
* body already and the extra keys only make it bigger.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DELTA_CHANGED_RATIO = 0.6;
|
|
34
|
+
/** The one row field every set this module diffs is keyed by. */
|
|
35
|
+
export interface DeltaRow {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
}
|
|
38
|
+
/** One window's answer, before a method wraps it in its own wire shape. */
|
|
39
|
+
export type DeltaAnswer<T> = {
|
|
40
|
+
readonly mode: 'reset';
|
|
41
|
+
/** Opaque token to send back as `since`; `""` when nothing was retained. */
|
|
42
|
+
readonly token: string;
|
|
43
|
+
/** The whole set, exactly as the method always published it. */
|
|
44
|
+
readonly rows: readonly T[];
|
|
45
|
+
} | {
|
|
46
|
+
readonly mode: 'delta';
|
|
47
|
+
readonly token: string;
|
|
48
|
+
/** Every row that is new or whose body differs from the last one sent. */
|
|
49
|
+
readonly changed: readonly T[];
|
|
50
|
+
/** Every id this window sent before and the host no longer names. */
|
|
51
|
+
readonly removed: readonly string[];
|
|
52
|
+
};
|
|
53
|
+
/** Cap on the set one window may retain. */
|
|
54
|
+
export interface DeltaLimits {
|
|
55
|
+
readonly maxRows: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* One connection's view of one set: the rows it last sent, and the token that
|
|
59
|
+
* set was announced under.
|
|
60
|
+
*
|
|
61
|
+
* A window is created lazily by whoever needs it and lives exactly as long as
|
|
62
|
+
* the connection that owns it (see {@link RemoteBridgeDeltas}), so two
|
|
63
|
+
* connections never share a base and a dropped connection leaks nothing.
|
|
64
|
+
*/
|
|
65
|
+
export declare class DeltaWindow<T extends DeltaRow> {
|
|
66
|
+
#private;
|
|
67
|
+
constructor(limits: DeltaLimits);
|
|
68
|
+
/**
|
|
69
|
+
* Answer one call over the current full set.
|
|
70
|
+
* @param rows - the complete set, exactly as the host answered it this time.
|
|
71
|
+
* @param since - the opaque token the client sent, if it sent one.
|
|
72
|
+
* @returns a reset carrying every row, or a delta against the last set sent.
|
|
73
|
+
*/
|
|
74
|
+
answer(rows: readonly T[], since: string | undefined): DeltaAnswer<T>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The delta windows one connection owns, by the name its owner keys them with.
|
|
78
|
+
*
|
|
79
|
+
* Held on the connection, so the state is released exactly when the connection
|
|
80
|
+
* is: there is no second registry to expire, and no connection's window can be
|
|
81
|
+
* read by another.
|
|
82
|
+
*/
|
|
83
|
+
export declare class RemoteBridgeDeltas {
|
|
84
|
+
#private;
|
|
85
|
+
/**
|
|
86
|
+
* @param key - the window's name within this connection; one set, one key.
|
|
87
|
+
* @param limits - the cap this window retains.
|
|
88
|
+
* @returns the window, created on first use.
|
|
89
|
+
*/
|
|
90
|
+
window<T extends DeltaRow>(key: string, limits: DeltaLimits): DeltaWindow<T>;
|
|
91
|
+
/**
|
|
92
|
+
* @param key - one window's name.
|
|
93
|
+
*
|
|
94
|
+
* Drops that window and the set it retained, so its token names nothing and
|
|
95
|
+
* the next call answers a reset. Used when a connection stops being served
|
|
96
|
+
* increments at all, which must cost it no memory either.
|
|
97
|
+
*/
|
|
98
|
+
drop(key: string): void;
|
|
99
|
+
/** Drop every window: called when the owning connection is torn down. */
|
|
100
|
+
clear(): void;
|
|
101
|
+
}
|
|
@@ -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
|
}
|