@linxin666/dsh-remote-bridge 0.4.12 → 0.4.14
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 +53 -11
- package/README.zh.md +53 -11
- package/lib/client.js +112 -90
- package/lib/client.js.map +1 -1
- package/lib/index.js +18800 -334
- package/lib/types/client/PairPanel.d.ts +7 -0
- package/lib/types/client/locales.d.ts +13 -10
- package/lib/types/core/connection.d.ts +50 -0
- package/lib/types/core/devices.d.ts +80 -6
- package/lib/types/core/liveactivity.d.ts +7 -0
- package/lib/types/core/model-efforts.d.ts +83 -0
- package/lib/types/core/protocol.d.ts +24 -0
- package/lib/types/core/push.d.ts +70 -3
- package/lib/types/host/firewall.d.ts +74 -0
- package/lib/types/host/host-bind-capability.d.ts +90 -0
- package/lib/types/host/ingress-gate.d.ts +59 -0
- package/lib/types/host/ingress-sync.d.ts +429 -0
- package/lib/types/host/lan-bind-plan.d.ts +96 -0
- package/lib/types/host/lan-bind.d.ts +106 -0
- package/lib/types/host/lan-forward.d.ts +112 -0
- package/lib/types/host/lan.d.ts +61 -0
- package/lib/types/host/pair-origin.d.ts +34 -19
- package/lib/types/host/relay-bridge-connector.d.ts +234 -0
- package/lib/types/host/relay-connector.d.ts +156 -0
- package/lib/types/host/relay-control.d.ts +195 -0
- package/lib/types/host/relay-registry.d.ts +123 -0
- package/lib/types/host/relay-secondary.d.ts +209 -0
- package/lib/types/host/relay.d.ts +170 -0
- package/lib/types/host/routes.d.ts +29 -1
- package/lib/types/host/tunnel-orphan.d.ts +145 -0
- package/lib/types/host/tunnel-plan.d.ts +41 -0
- package/lib/types/host/tunnel.d.ts +289 -0
- package/lib/types/index.d.ts +488 -1
- package/package.json +4 -2
- package/src/client/PairPanel.tsx +21 -0
- package/src/client/locales.ts +19 -15
- package/src/client/panel.module.css +48 -1
- package/src/core/connection.ts +316 -11
- package/src/core/devices.ts +165 -16
- package/src/core/hub.ts +17 -5
- package/src/core/liveactivity.ts +16 -2
- package/src/core/model-efforts.ts +223 -0
- package/src/core/protocol.ts +27 -0
- package/src/core/push.ts +90 -5
- package/src/host/firewall.ts +230 -0
- package/src/host/host-bind-capability.ts +249 -0
- package/src/host/ingress-gate.ts +203 -0
- package/src/host/ingress-sync.ts +1074 -0
- package/src/host/lan-bind-plan.ts +134 -0
- package/src/host/lan-bind.ts +250 -0
- package/src/host/lan-forward.ts +321 -0
- package/src/host/lan.ts +142 -0
- package/src/host/pair-origin.ts +44 -38
- package/src/host/relay-bridge-connector.ts +849 -0
- package/src/host/relay-connector.ts +324 -0
- package/src/host/relay-control.ts +315 -0
- package/src/host/relay-registry.ts +275 -0
- package/src/host/relay-secondary.ts +478 -0
- package/src/host/relay.ts +294 -0
- package/src/host/routes.ts +57 -3
- package/src/host/tunnel-orphan.ts +325 -0
- package/src/host/tunnel-plan.ts +58 -0
- package/src/host/tunnel.ts +688 -0
- package/src/index.ts +1516 -23
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
|
+
/**
|
|
3
|
+
* Where a reader of the beta build can reach the people running it. The URL is
|
|
4
|
+
* code, not copy: the dictionaries carry the sentence, this constant carries the
|
|
5
|
+
* destination, so a translation cannot retarget the link and a check can assert
|
|
6
|
+
* the real one.
|
|
7
|
+
*/
|
|
8
|
+
export declare const COMMUNITY_INVITE_URL = "https://discord.gg/nBy28kjun";
|
|
2
9
|
/** What the panel is currently showing. */
|
|
3
10
|
export type PairPanelState =
|
|
4
11
|
/** A read is in flight. */
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* the header of an interactive card (§35.11).
|
|
4
4
|
*
|
|
5
5
|
* The panel has one job — put the live one-shot code in front of the operator as
|
|
6
|
-
* a QR symbol — so its copy carries
|
|
7
|
-
*
|
|
8
|
-
* the
|
|
9
|
-
*
|
|
6
|
+
* a QR symbol — so its copy carries what to do with the symbol, how long it
|
|
7
|
+
* lives, which address the phone will actually dial, why the code is single-use,
|
|
8
|
+
* and that the app is still in testing: the reader is told what they are joining
|
|
9
|
+
* and where to ask about it. No key states how the host finds its public
|
|
10
|
+
* address, and no key names the wire protocol: both are implementation facts the
|
|
11
|
+
* reader cannot act on.
|
|
10
12
|
*
|
|
11
13
|
* The card's keys say only what the transcript row can act on: whether the page
|
|
12
14
|
* is still waiting for the operator, that it is over, that this desktop renders
|
|
@@ -15,17 +17,18 @@
|
|
|
15
17
|
*/
|
|
16
18
|
/** Simplified Chinese dictionary (the key-set source of truth). */
|
|
17
19
|
export declare const zh: {
|
|
18
|
-
readonly 'entry.label': "
|
|
19
|
-
readonly title: "
|
|
20
|
-
readonly subtitle: "
|
|
20
|
+
readonly 'entry.label': "配对 iPhone";
|
|
21
|
+
readonly title: "iOS App 配对";
|
|
22
|
+
readonly subtitle: "用 iOS App(内测)扫描二维码,把 iPhone 连到这台电脑上。配对码只在本机显示。";
|
|
21
23
|
readonly 'state.reading': "正在取配对码…";
|
|
22
24
|
readonly 'pair.qrLabel': "配对二维码";
|
|
23
25
|
readonly 'pair.countdown': "剩余 {s} 秒";
|
|
24
26
|
readonly 'pair.expired': "配对码已过期";
|
|
25
27
|
readonly 'pair.refresh': "重新取码";
|
|
26
|
-
readonly 'pair.usedHint': "
|
|
27
|
-
readonly 'origin.located': "
|
|
28
|
-
readonly 'origin.missing': "
|
|
28
|
+
readonly 'pair.usedHint': "配对码一次性有效:iPhone 一开始配对就作废,重新取码也会作废上一张。";
|
|
29
|
+
readonly 'origin.located': "iPhone 将连到 {origin}";
|
|
30
|
+
readonly 'origin.missing': "没有找到公网地址:先在 App 里把连接地址填成你的公网中继,再扫码。本页的 {host} 只有本机能连。";
|
|
31
|
+
readonly 'community.invite': "iOS App 还在内测,欢迎来 Discord 交流";
|
|
29
32
|
readonly 'forbidden.title': "这个页面不是从本机打开的";
|
|
30
33
|
readonly 'forbidden.body': "配对码只能在本机 Web UI 上取。请在本机浏览器打开 http://127.0.0.1:<端口> 后重试。";
|
|
31
34
|
readonly 'failed.title': "取配对码失败";
|
|
@@ -20,6 +20,7 @@ import type { DeviceRoster } from './devices.ts';
|
|
|
20
20
|
import type { RemoteBridgeRegistry } from './extension.ts';
|
|
21
21
|
import { type JobRoster } from './jobs.ts';
|
|
22
22
|
import type { LiveActivityNotifier } from './liveactivity.ts';
|
|
23
|
+
import type { ModelEffortPreferences } from './model-efforts.ts';
|
|
23
24
|
import type { PairingService } from './pairing.ts';
|
|
24
25
|
import type { PushNotifier } from './push.ts';
|
|
25
26
|
import type { QuestionClaims } from './questions.ts';
|
|
@@ -83,6 +84,33 @@ export interface BridgeTransport {
|
|
|
83
84
|
*/
|
|
84
85
|
frameDeflate?(declared: boolean): void;
|
|
85
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* 第二会合点在协议面上的那一半:一条公告与一次收帧。
|
|
89
|
+
*
|
|
90
|
+
* 只有配了第二会合点的宿主才提供这个面,而它存在与否就是 `relay.tier.v1` 这个
|
|
91
|
+
* 能力名与 `relay.grant` 这个方法存在与否——没有它,握手与应答与今天逐字相同。
|
|
92
|
+
* 宿主侧的动作(写名册、去第二会合点申领)全在插件半区,core 里只留这两处接线,
|
|
93
|
+
* 所以一个不认识的宿主不会因为这里多了一层而改变任何一帧。
|
|
94
|
+
*/
|
|
95
|
+
export interface RelayTierFace {
|
|
96
|
+
/**
|
|
97
|
+
* 这次握手要在 `hello.r.relay` 里公告的会合点,或 undefined(此刻没有可公告的)。
|
|
98
|
+
*
|
|
99
|
+
* 公告的含义是「这台宿主此刻确实持有一份中继承认的、按 6 小时周期刷新的租约」,
|
|
100
|
+
* 而不是「它曾经申到过一次」:公告出去的是「拨这个地址」,而一个没有有效租约的
|
|
101
|
+
* 地址背后没有人服务。还没申到、降级被拒、grant 过期、主动释放,四种情况都回
|
|
102
|
+
* undefined,于是一条连接的下一个世代自己退回市场边缘,不需要服务端推送任何东西。
|
|
103
|
+
* @returns `wss://<id><suffix>`,或 undefined。
|
|
104
|
+
*/
|
|
105
|
+
origin(): string | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* 一条新授权已经落进名册行:第二会合点要立刻重新申领一次。
|
|
108
|
+
*
|
|
109
|
+
* 调用发生在名册写完之后,所以插件半区读到的就是这条授权。它是**触发**而不是
|
|
110
|
+
* 等待:`relay.grant` 的应答不等那一次网络往返,申领失败由半区自己的退避收着。
|
|
111
|
+
*/
|
|
112
|
+
grantLanded(): void;
|
|
113
|
+
}
|
|
86
114
|
export interface BridgeConnectionOptions {
|
|
87
115
|
readonly gateway: BridgeGateway;
|
|
88
116
|
readonly pairing: PairingService;
|
|
@@ -107,6 +135,14 @@ export interface BridgeConnectionOptions {
|
|
|
107
135
|
readonly usage: UsageService;
|
|
108
136
|
/** Host-process permission presets, read and switched through their real service objects. */
|
|
109
137
|
readonly permissions: SessionPermissions;
|
|
138
|
+
/**
|
|
139
|
+
* 每个模型自己的思考档偏好表(`core/model-efforts.ts`)。
|
|
140
|
+
*
|
|
141
|
+
* 一个宿主一份、所有连接与所有会话共享:它记的是这个模型在这台机器上被选过
|
|
142
|
+
* 哪一档,与哪条会话无关(契约 §4)。它与宿主自己的 `reasoning.defaultEffort`
|
|
143
|
+
* 是两件事,`session.models` 用另一个键名 `preferredEffort` 公布它。
|
|
144
|
+
*/
|
|
145
|
+
readonly modelEfforts: ModelEffortPreferences;
|
|
110
146
|
/**
|
|
111
147
|
* The in-process owner peer every gateway call speaks for, minted by the
|
|
112
148
|
* bridge itself (`core/owner-peer.ts`). Dispatch refuses unpaired
|
|
@@ -162,6 +198,11 @@ export interface BridgeConnectionOptions {
|
|
|
162
198
|
* read the host's own answer.
|
|
163
199
|
*/
|
|
164
200
|
readonly turnEndQuiet?: TurnEndQuietGate;
|
|
201
|
+
/**
|
|
202
|
+
* 第二会合点(`relay.tier.v1`)。缺省就是没有第二会合点:`hello` 不带
|
|
203
|
+
* `relay` 键、能力表里没有那个名字、`relay.grant` 仍是 `unknown-method`。
|
|
204
|
+
*/
|
|
205
|
+
readonly relay?: RelayTierFace;
|
|
165
206
|
/**
|
|
166
207
|
* Called after a registration changed the device table.
|
|
167
208
|
*
|
|
@@ -172,6 +213,15 @@ export interface BridgeConnectionOptions {
|
|
|
172
213
|
* `push.register` into a failure.
|
|
173
214
|
*/
|
|
174
215
|
readonly onPushRegistered?: () => void;
|
|
216
|
+
/**
|
|
217
|
+
* Called after `pair.finish` admits a device into the roster.
|
|
218
|
+
*
|
|
219
|
+
* A machine that started with no paired devices defers claiming its relay
|
|
220
|
+
* lease until a remote device is actually paired (or a pairing code is
|
|
221
|
+
* requested); guarded at the call site so background relay work never fails
|
|
222
|
+
* the pairing response.
|
|
223
|
+
*/
|
|
224
|
+
readonly onDeviceEnrolled?: () => void;
|
|
175
225
|
}
|
|
176
226
|
/** A device the connection proved itself to be, resolved from the upgrade request. */
|
|
177
227
|
export interface ConnectionAuth {
|
|
@@ -18,13 +18,16 @@ export declare const DEVICE_ID_BYTES = 12;
|
|
|
18
18
|
* On-disk schema version of the roster file.
|
|
19
19
|
*
|
|
20
20
|
* 1 carried the six identity fields only; 2 adds the optional `push` block per
|
|
21
|
-
* row (§28)
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
21
|
+
* row (§28); 3 adds the optional `relayToken` inside that block, the credential the
|
|
22
|
+
* hosted relay signs a delivery for instead of a local Apple key; 4 adds the
|
|
23
|
+
* optional `relay` block beside it, the tier grant the phone handed over and when
|
|
24
|
+
* this bridge received it. Every step is additive, so an older file reads as-is:
|
|
25
|
+
* no row loses a field, every paired phone stays paired, and the file is rewritten
|
|
26
|
+
* as the current version the next time anything is written. The reader therefore
|
|
27
|
+
* accepts any version whose row table validates rather than quarantining a file it
|
|
28
|
+
* merely does not recognise — a downgrade must never un-pair every phone.
|
|
26
29
|
*/
|
|
27
|
-
export declare const ROSTER_VERSION =
|
|
30
|
+
export declare const ROSTER_VERSION = 4;
|
|
28
31
|
/** The APNs environments a device may register for. */
|
|
29
32
|
export type PushEnvironment = 'sandbox' | 'production';
|
|
30
33
|
/** One Live Activity push token, with the session the card belongs to. */
|
|
@@ -58,8 +61,38 @@ export interface PushRegistration {
|
|
|
58
61
|
readonly bundle: string;
|
|
59
62
|
readonly locale?: string;
|
|
60
63
|
readonly liveActivityTokens?: readonly PushLiveActivityToken[];
|
|
64
|
+
/**
|
|
65
|
+
* The bearer the hosted relay accepts for this device's fingerprint.
|
|
66
|
+
*
|
|
67
|
+
* The App obtains it from the account service, scoped to `(userId, fingerprint)`
|
|
68
|
+
* and valid for 90 days, and hands it to this bridge through `push.register`. It
|
|
69
|
+
* is what lets a machine with no Apple signing key still deliver §28's events: the
|
|
70
|
+
* relay signs them with the key that never leaves the service. Absent is a phone
|
|
71
|
+
* whose only route is this machine's own key, which is the pre-relay behaviour.
|
|
72
|
+
*/
|
|
73
|
+
readonly relayToken?: string;
|
|
61
74
|
readonly registeredAt: number;
|
|
62
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* One device's relay tier grant (schema 4).
|
|
78
|
+
*
|
|
79
|
+
* The App obtains it from the account service and hands it over through
|
|
80
|
+
* `relay.grant`. This bridge never mints, parses or reissues it: it keeps the text
|
|
81
|
+
* and presents it in its next claim to the second meeting point, which decides the
|
|
82
|
+
* entitlement out of band and answers the host with a lease or a refusal. Nothing
|
|
83
|
+
* about the account crosses the wire back — the host learns "admitted" or "not",
|
|
84
|
+
* never who the phone is.
|
|
85
|
+
*
|
|
86
|
+
* It is a fact about the phone that gave it, so it lives in that phone's row and
|
|
87
|
+
* disappears with the row when the phone is revoked; it never becomes a second
|
|
88
|
+
* identity of the bridge's own.
|
|
89
|
+
*/
|
|
90
|
+
export interface RelayGrant {
|
|
91
|
+
/** The grant text, exactly as the account service issued it. */
|
|
92
|
+
readonly grant: string;
|
|
93
|
+
/** When this bridge received it, in epoch seconds. */
|
|
94
|
+
readonly receivedAt: number;
|
|
95
|
+
}
|
|
63
96
|
/** One device a notification can be addressed to. */
|
|
64
97
|
export interface PushTargetView {
|
|
65
98
|
readonly deviceId: string;
|
|
@@ -80,6 +113,14 @@ export interface DeviceRecord {
|
|
|
80
113
|
* every phone that predates the channel.
|
|
81
114
|
*/
|
|
82
115
|
readonly push?: PushRegistration;
|
|
116
|
+
/**
|
|
117
|
+
* The device's relay tier grant, absent until it calls `relay.grant`.
|
|
118
|
+
*
|
|
119
|
+
* A row without it is a phone whose host may still claim the second meeting
|
|
120
|
+
* point — a bridged lease needs no grant at the market edge — it just cannot be
|
|
121
|
+
* admitted to a tier that requires one.
|
|
122
|
+
*/
|
|
123
|
+
readonly relay?: RelayGrant;
|
|
83
124
|
}
|
|
84
125
|
/** What one successful enrollment hands back to the caller exactly once. */
|
|
85
126
|
export interface EnrollmentResult {
|
|
@@ -140,6 +181,30 @@ export declare class DeviceRoster {
|
|
|
140
181
|
* @returns false when no such device is paired.
|
|
141
182
|
*/
|
|
142
183
|
registerPush(deviceId: string, registration: PushRegistration): Promise<boolean>;
|
|
184
|
+
/**
|
|
185
|
+
* Record the relay grant one device just handed over (schema 4).
|
|
186
|
+
*
|
|
187
|
+
* A grant the phone resends replaces the one on the row: the account service
|
|
188
|
+
* reissues them periodically, and the newest text is the one the second meeting
|
|
189
|
+
* point will verify against the current plan. Nothing else on the row moves, so a
|
|
190
|
+
* grant that arrives between two reconnects cannot disturb a push registration.
|
|
191
|
+
* @param deviceId - the device that sent `relay.grant`.
|
|
192
|
+
* @param grant - the grant text as the account service issued it.
|
|
193
|
+
* @returns false when no such device is paired.
|
|
194
|
+
*/
|
|
195
|
+
setRelayGrant(deviceId: string, grant: string): Promise<boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* @returns the relay grant this bridge claims with, or undefined when no row
|
|
198
|
+
* holds one.
|
|
199
|
+
*
|
|
200
|
+
* The newest one wins, because one host holds one lease at the second meeting
|
|
201
|
+
* point and the phone that most recently handed a grant over is the one whose
|
|
202
|
+
* subscription is being claimed. A pairing with several phones of mixed tiers is
|
|
203
|
+
* then the accepted asymmetry the design names: the host is admitted while at
|
|
204
|
+
* least one paired phone holds a tier that is, and the free-tier phone simply
|
|
205
|
+
* keeps using the market edge.
|
|
206
|
+
*/
|
|
207
|
+
relayGrant(): RelayGrant | undefined;
|
|
143
208
|
/**
|
|
144
209
|
* Forget one Live Activity token the phone no longer holds.
|
|
145
210
|
*
|
|
@@ -169,4 +234,13 @@ export declare class DeviceRoster {
|
|
|
169
234
|
removePush(deviceToken: string): Promise<boolean>;
|
|
170
235
|
/** @returns every paired device that registered for notifications. */
|
|
171
236
|
pushTargets(): readonly PushTargetView[];
|
|
237
|
+
/**
|
|
238
|
+
* @returns every paired device that holds a relay token.
|
|
239
|
+
*
|
|
240
|
+
* The relay path's own reachability question: a row that registered an APNs
|
|
241
|
+
* token before the relay existed is a phone this machine cannot notify without a
|
|
242
|
+
* local key, so counting {@link pushTargets} there would claim a delivery that
|
|
243
|
+
* has no route at all.
|
|
244
|
+
*/
|
|
245
|
+
relayTargets(): readonly PushTargetView[];
|
|
172
246
|
}
|
|
@@ -187,6 +187,8 @@ export interface LiveActivityAddress {
|
|
|
187
187
|
readonly environment: 'sandbox' | 'production';
|
|
188
188
|
/** The app bundle id; the topic is this bundle plus the Live Activity suffix. */
|
|
189
189
|
readonly bundle: string;
|
|
190
|
+
/** The relay credential this card's device row holds, when the bridge stands on the relay. */
|
|
191
|
+
readonly relayToken?: string;
|
|
190
192
|
}
|
|
191
193
|
/** Whatever actually reaches a card; the APNs client implements this. */
|
|
192
194
|
export interface LiveActivitySender {
|
|
@@ -206,6 +208,11 @@ export interface LiveActivityNotifierOptions {
|
|
|
206
208
|
readonly targets: () => readonly LiveActivityAddress[];
|
|
207
209
|
/** The sender; absent is a bridge with no signing key, and then nothing happens. */
|
|
208
210
|
readonly sender?: LiveActivitySender;
|
|
211
|
+
/**
|
|
212
|
+
* Whether the configured route is reachable right now; the same probe the alert
|
|
213
|
+
* channel beside it reads, so a bridge with neither route sends no card either.
|
|
214
|
+
*/
|
|
215
|
+
readonly available?: () => boolean;
|
|
209
216
|
readonly now?: () => number;
|
|
210
217
|
readonly log?: (message: string) => void;
|
|
211
218
|
/**
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host's per-model reasoning-effort preferences:
|
|
3
|
+
* `$DSH_HOME/remote-bridge/model-efforts.json`.
|
|
4
|
+
*
|
|
5
|
+
* A preference belongs to a MODEL, not to a session or a device: the phone picks
|
|
6
|
+
* a level for one model once, and every session on this host that later selects
|
|
7
|
+
* that model is handed the same level. The table therefore has exactly one scope
|
|
8
|
+
* — the whole host — and nothing expires an entry when a session ends.
|
|
9
|
+
*
|
|
10
|
+
* It is deliberately not the catalog's `reasoning.defaultEffort`: that is what
|
|
11
|
+
* the harness publishes for a model, this is what the user chose here, and the
|
|
12
|
+
* two disagree the moment somebody picks a level the catalog does not call the
|
|
13
|
+
* default. The wire keeps them apart too (`session.models` rows carry this one
|
|
14
|
+
* as `preferredEffort`, beside the catalog's own `reasoning`).
|
|
15
|
+
* @module dsh-remote-bridge/core/model-efforts
|
|
16
|
+
*/
|
|
17
|
+
/** The schema version this build writes; an older file is read as the table it is. */
|
|
18
|
+
export declare const EFFORT_TABLE_VERSION = 1;
|
|
19
|
+
/** One remembered choice: the model it belongs to and the level it was given. */
|
|
20
|
+
export interface EffortPreference {
|
|
21
|
+
readonly provider: string;
|
|
22
|
+
readonly model: string;
|
|
23
|
+
readonly effort: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ModelEffortPreferencesOptions {
|
|
26
|
+
/** Absolute path of the preference file. */
|
|
27
|
+
readonly file: string;
|
|
28
|
+
readonly log?: (message: string) => void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The persisted effort table, shared by every connection of one host.
|
|
32
|
+
*
|
|
33
|
+
* Read once per process and written atomically: a corrupt file is an EMPTY table
|
|
34
|
+
* with one log line, never a failed mount — a phone must still be able to read
|
|
35
|
+
* the catalog and pick a model on a host whose preference file went bad, and the
|
|
36
|
+
* next write replaces the file rather than writing into the damage.
|
|
37
|
+
*/
|
|
38
|
+
export declare class ModelEffortPreferences {
|
|
39
|
+
#private;
|
|
40
|
+
constructor(options: ModelEffortPreferencesOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Read the table once. A missing file is an empty table, and an unreadable or
|
|
43
|
+
* malformed one is reported and then read as empty.
|
|
44
|
+
* @returns when the in-memory table reflects the file.
|
|
45
|
+
*/
|
|
46
|
+
load(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* @param provider - provider id.
|
|
49
|
+
* @param model - model id.
|
|
50
|
+
* @returns the level remembered for that model, or undefined when the table has none.
|
|
51
|
+
*/
|
|
52
|
+
effortOf(provider: string, model: string): string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Remember one level and persist it before answering.
|
|
55
|
+
*
|
|
56
|
+
* The write is what the caller is told succeeded, so the memory copy is set
|
|
57
|
+
* first only for the duration of it: a failed write rejects, and the answer
|
|
58
|
+
* the client sees is the failure rather than a level this host never stored.
|
|
59
|
+
* @param provider - provider id.
|
|
60
|
+
* @param model - model id.
|
|
61
|
+
* @param effort - the level chosen for that model.
|
|
62
|
+
*/
|
|
63
|
+
save(provider: string, model: string, effort: string): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Drop the remembered level for one model, but only the one judged stale.
|
|
66
|
+
*
|
|
67
|
+
* A level a model stopped publishing is worse than none at all: the backfill in
|
|
68
|
+
* `session.setModel` would send it, the harness would refuse, and the model
|
|
69
|
+
* would become unswitchable — and because that backfill is the only writer, the
|
|
70
|
+
* row could never heal itself. Dropping it makes the next switch plain.
|
|
71
|
+
*
|
|
72
|
+
* The `staleEffort` argument is what keeps that cure from being worse than the
|
|
73
|
+
* disease: an awaited catalog read sits between judging a level stale and
|
|
74
|
+
* arriving here, and frames of one connection are dispatched concurrently, so
|
|
75
|
+
* the user may have typed a NEW level in that window. A row that no longer holds
|
|
76
|
+
* the level this caller judged is a newer choice, and it survives.
|
|
77
|
+
* @param provider - provider id.
|
|
78
|
+
* @param model - model id.
|
|
79
|
+
* @param staleEffort - the level this caller found the catalog no longer offers.
|
|
80
|
+
* @param reason - why it is being dropped, for the log line.
|
|
81
|
+
*/
|
|
82
|
+
forget(provider: string, model: string, staleEffort: string, reason: string): Promise<void>;
|
|
83
|
+
}
|
|
@@ -17,6 +17,8 @@ export declare const METHOD_SESSION_PERMISSIONS = "session.permissions";
|
|
|
17
17
|
export declare const METHOD_SESSION_SET_PERMISSION = "session.setPermission";
|
|
18
18
|
export declare const METHOD_SESSION_MODELS = "session.models";
|
|
19
19
|
export declare const METHOD_SESSION_SET_MODEL = "session.setModel";
|
|
20
|
+
/** Remember one model's reasoning level, without switching the session's model. */
|
|
21
|
+
export declare const METHOD_SESSION_SET_EFFORT = "session.setEffort";
|
|
20
22
|
export declare const METHOD_SESSION_CREATE = "session.create";
|
|
21
23
|
export declare const METHOD_SESSION_FORK = "session.fork";
|
|
22
24
|
export declare const METHOD_SESSION_COMMANDS = "session.commands";
|
|
@@ -45,6 +47,14 @@ export declare const METHOD_USAGE_BALANCE = "usage.balance";
|
|
|
45
47
|
export declare const METHOD_USAGE_STATS = "usage.stats";
|
|
46
48
|
export declare const METHOD_UI_EVENT = "ui.event";
|
|
47
49
|
export declare const METHOD_UI_LIST = "ui.list";
|
|
50
|
+
/**
|
|
51
|
+
* 一条配对连接把手机从账号服务换到的中继授权交给宿主。
|
|
52
|
+
*
|
|
53
|
+
* 它是这条通道唯一的写动作:授权落进那台设备自己的名册行,随后宿主拿它去第二
|
|
54
|
+
* 会合点申领租约。宿主不认识账号——它只会看到「准了」或「不准」,绝不会从这一帧
|
|
55
|
+
* 里读出用户是谁。只在配了第二会合点的宿主上是这个方法(见 {@link CAP_RELAY_TIER})。
|
|
56
|
+
*/
|
|
57
|
+
export declare const METHOD_RELAY_GRANT = "relay.grant";
|
|
48
58
|
/** Server-pushed topics of protocol v1. */
|
|
49
59
|
export declare const TOPIC_SESSION_DELTA = "session.delta";
|
|
50
60
|
export declare const TOPIC_APPROVAL_REQUEST = "approval.request";
|
|
@@ -260,6 +270,20 @@ export declare const CAP_UI = "ui.v1";
|
|
|
260
270
|
* `ui.request` 说 `settled` 时结束),而不是按一次它信不过的应答清卡。
|
|
261
271
|
*/
|
|
262
272
|
export declare const CAP_UI_LIST = "ui.list.v1";
|
|
273
|
+
/**
|
|
274
|
+
* 宿主配了第二会合点时,在 `hello` 的 `capabilities` 里公告的能力名。
|
|
275
|
+
*
|
|
276
|
+
* 它是这条通道的全部门槛,而且门槛落在宿主这一侧:一个配了第二会合点的宿主才
|
|
277
|
+
* 公告这个名字、才收 {@link METHOD_RELAY_GRANT},客户端读到它之后才把授权发过来。
|
|
278
|
+
* 不配第二会合点的宿主——也就是缺省配置的每一台——公告表里没有这个名字,
|
|
279
|
+
* `relay.grant` 对它仍是 `unknown-method`,名册里也不会因此多出一个块:缺省
|
|
280
|
+
* 宿主的握手与名册与这条通道出现之前逐字相同。
|
|
281
|
+
*
|
|
282
|
+
* 正因为它是**条件**公告,{@link MINOR} 不随它抬格:minor 描述的是这个协议本身,
|
|
283
|
+
* 而缺省宿主在线路上读不到任何新东西(设计冻结在 21)。客户端因此按名字判断而不是
|
|
284
|
+
* 按 minor 判断:读不到这个名字就什么都不发。
|
|
285
|
+
*/
|
|
286
|
+
export declare const CAP_RELAY_TIER = "relay.tier.v1";
|
|
263
287
|
/**
|
|
264
288
|
* Capability a client declares in `hello`'s `cap` array to be answered with
|
|
265
289
|
* byte-level increments instead of the whole roster or the whole board.
|
package/lib/types/core/push.d.ts
CHANGED
|
@@ -26,6 +26,16 @@
|
|
|
26
26
|
*/
|
|
27
27
|
/** One thing a notification can be about. */
|
|
28
28
|
export type PushEvent = 'turn-end' | 'turn-error' | 'question' | 'approval';
|
|
29
|
+
/**
|
|
30
|
+
* Which way this bridge delivers a notification.
|
|
31
|
+
*
|
|
32
|
+
* `direct` signs for APNs with this machine's own Apple key, `relay` asks the
|
|
33
|
+
* hosted service to sign with the one key no deployment may hold, and `off` is a
|
|
34
|
+
* bridge with neither route — the channel's original shape, byte for byte. The two
|
|
35
|
+
* routes are exclusive rather than a fallback chain: a machine holding a key keeps
|
|
36
|
+
* using it, so a developer's delivery never travels through the service.
|
|
37
|
+
*/
|
|
38
|
+
export type PushRoute = 'direct' | 'relay' | 'off';
|
|
29
39
|
/** Window inside which the same `(sessionId, event)` is one notification. */
|
|
30
40
|
export declare const PUSH_DEDUPE_MS = 30000;
|
|
31
41
|
/** Shortest gap between two notifications about the same session. */
|
|
@@ -36,12 +46,29 @@ export declare const PUSH_GLOBAL_PER_MINUTE = 30;
|
|
|
36
46
|
export declare const PUSH_WORKSPACE_LIMIT = 512;
|
|
37
47
|
/** The only deep-link form this channel emits. */
|
|
38
48
|
export declare const PUSH_DEEP_LINK_PREFIX = "whale://session/";
|
|
49
|
+
/**
|
|
50
|
+
* The one category a delivery may name (§28.4).
|
|
51
|
+
*
|
|
52
|
+
* A banner draws a button only where a category it knows is named, so this is the
|
|
53
|
+
* identifier the client registered statically for the two approval answers. It is
|
|
54
|
+
* the client's name rather than this bridge's: the bridge writes it verbatim and
|
|
55
|
+
* holds no second opinion about what a button says.
|
|
56
|
+
*/
|
|
57
|
+
export declare const PUSH_APPROVAL_CATEGORY = "dev.dsh.Whale.category.approval";
|
|
39
58
|
/** One device a notification can be addressed to. */
|
|
40
59
|
export interface PushAddress {
|
|
41
60
|
readonly deviceToken: string;
|
|
42
61
|
readonly environment: 'sandbox' | 'production';
|
|
43
62
|
readonly bundle: string;
|
|
44
63
|
readonly locale?: string;
|
|
64
|
+
/**
|
|
65
|
+
* The relay credential that same row registered, when it registered one.
|
|
66
|
+
*
|
|
67
|
+
* Present on the address rather than looked up by the sender so the two routes
|
|
68
|
+
* stay one decision: a row carries the token only in relay mode, and the sender
|
|
69
|
+
* that reads it is the only one this bridge built.
|
|
70
|
+
*/
|
|
71
|
+
readonly relayToken?: string;
|
|
45
72
|
}
|
|
46
73
|
/** The request body one APNs delivery carries (protocol §28.4). */
|
|
47
74
|
export interface PushNotification {
|
|
@@ -51,6 +78,13 @@ export interface PushNotification {
|
|
|
51
78
|
readonly body: string;
|
|
52
79
|
};
|
|
53
80
|
readonly sound: 'default';
|
|
81
|
+
/**
|
|
82
|
+
* The client's registered category, named only by an approval.
|
|
83
|
+
*
|
|
84
|
+
* Absent for every other event rather than empty: an absent key is a banner
|
|
85
|
+
* with no buttons, and an empty one would be a second way to say it.
|
|
86
|
+
*/
|
|
87
|
+
readonly category?: string;
|
|
54
88
|
};
|
|
55
89
|
/** Workspace short name; absent when this bridge cannot resolve one. */
|
|
56
90
|
readonly w?: string;
|
|
@@ -61,10 +95,19 @@ export interface PushNotification {
|
|
|
61
95
|
/** What one delivery attempt reported. */
|
|
62
96
|
export interface PushSendResult {
|
|
63
97
|
readonly ok: boolean;
|
|
64
|
-
/** The status APNs answered, when it answered at all. */
|
|
98
|
+
/** The status APNs answered, or the relay did, when it answered at all. */
|
|
65
99
|
readonly status?: number;
|
|
66
100
|
/** The reason APNs named, or this bridge's own note. */
|
|
67
101
|
readonly reason?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Whether the answer said this registration will never work again.
|
|
104
|
+
*
|
|
105
|
+
* APNs says it in a status and a reason this module can read; the relay says it
|
|
106
|
+
* in a count of tokens it just retired, which names no status of its own. The
|
|
107
|
+
* sender that learned it reports the fact here instead of borrowing an APNs
|
|
108
|
+
* status it did not receive.
|
|
109
|
+
*/
|
|
110
|
+
readonly dead?: boolean;
|
|
68
111
|
}
|
|
69
112
|
/** One delivery a sender refused, in the words the bridge needs to read it. */
|
|
70
113
|
export interface PushDeliveryFailure {
|
|
@@ -74,6 +117,8 @@ export interface PushDeliveryFailure {
|
|
|
74
117
|
readonly status?: number;
|
|
75
118
|
/** The reason APNs named, or this bridge's own note. */
|
|
76
119
|
readonly reason?: string;
|
|
120
|
+
/** Whether this failure was final about the registration behind it. */
|
|
121
|
+
readonly dead?: boolean;
|
|
77
122
|
}
|
|
78
123
|
/** What one {@link PushNotifier.notify} ended up doing, once every attempt settled. */
|
|
79
124
|
export interface PushDeliveryReport {
|
|
@@ -113,6 +158,18 @@ export interface PushNotifierOptions {
|
|
|
113
158
|
readonly targets: () => readonly PushAddress[];
|
|
114
159
|
/** The sender; absent is a bridge with no signing key, and then nothing happens. */
|
|
115
160
|
readonly sender?: PushSender;
|
|
161
|
+
/**
|
|
162
|
+
* Whether the configured route can reach a phone right now.
|
|
163
|
+
*
|
|
164
|
+
* Absent means "the sender is reason enough", which is what a machine holding its
|
|
165
|
+
* own Apple key is: the key is configured or it is not. The relay has a second
|
|
166
|
+
* fact in front of the credential — some paired row must still hold a relay
|
|
167
|
+
* token — and reading it per event is what keeps a bridge with neither route
|
|
168
|
+
* exactly as inert as one with no key at all.
|
|
169
|
+
*/
|
|
170
|
+
readonly available?: () => boolean;
|
|
171
|
+
/** Which route this notifier stands on; `direct` by default, as before the relay existed. */
|
|
172
|
+
readonly mode?: PushRoute;
|
|
116
173
|
/** The session's own title (§26's source), read per event. */
|
|
117
174
|
readonly titles?: (sessionId: string) => string | undefined;
|
|
118
175
|
readonly now?: () => number;
|
|
@@ -126,7 +183,9 @@ export interface PushNotifierOptions {
|
|
|
126
183
|
*
|
|
127
184
|
* Pure, and exported so the shape can be asserted without a sender: the keys
|
|
128
185
|
* are the contract, and the absence of any body text is the property that
|
|
129
|
-
* matters most.
|
|
186
|
+
* matters most. One key is conditional — an approval names the category the
|
|
187
|
+
* client registered, because naming it is the only thing that makes a banner
|
|
188
|
+
* draw a button, and every other event omits it so a banner stays buttonless.
|
|
130
189
|
* @param event - what happened.
|
|
131
190
|
* @param sessionId - the session it happened to.
|
|
132
191
|
* @param labels - the name and workspace short name, when the bridge holds them.
|
|
@@ -151,8 +210,16 @@ export declare function pushEventOfTurnEnd(reason: string): PushEvent;
|
|
|
151
210
|
export declare class PushNotifier {
|
|
152
211
|
#private;
|
|
153
212
|
constructor(options: PushNotifierOptions);
|
|
154
|
-
/**
|
|
213
|
+
/**
|
|
214
|
+
* @returns whether this bridge will actually deliver anything.
|
|
215
|
+
*
|
|
216
|
+
* Read by every entrance — a delta path, a claim, a watcher — so a bridge whose
|
|
217
|
+
* route is not armed is indistinguishable from one that never had a channel: no
|
|
218
|
+
* target is read, no clock is consulted and no timer is armed.
|
|
219
|
+
*/
|
|
155
220
|
get enabled(): boolean;
|
|
221
|
+
/** @returns which road a delivery would take: this machine's key or the hosted relay. */
|
|
222
|
+
get mode(): PushRoute;
|
|
156
223
|
/**
|
|
157
224
|
* Remember the workspace each session belongs to, from a roster this bridge
|
|
158
225
|
* just served.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host firewall management for the LAN bind toggle: while LAN access is on,
|
|
3
|
+
* keep one inbound allow rule for the bound port; when it turns off, remove
|
|
4
|
+
* the rule. Windows manages the Windows Defender Firewall rule via netsh;
|
|
5
|
+
* Linux uses the first available manager among firewalld / ufw / iptables.
|
|
6
|
+
* On every other platform (macOS included) the plugin reports the firewall
|
|
7
|
+
* as unmanaged: the port usually needs no rule there, and managing pf or the
|
|
8
|
+
* application firewall is out of scope for a distributable plugin.
|
|
9
|
+
*
|
|
10
|
+
* Ported from the dsh-LAN reference implementation (MIT), adapted to this
|
|
11
|
+
* package's structure and test seams.
|
|
12
|
+
*/
|
|
13
|
+
/** Rule name shared by every backend so re-runs recreate the same rule. */
|
|
14
|
+
export declare const FIREWALL_RULE_NAME = "remote-web-ui (auto)";
|
|
15
|
+
/** One command execution result (test seam replaces the runner). */
|
|
16
|
+
export interface ToolResult {
|
|
17
|
+
ok: boolean;
|
|
18
|
+
out: string;
|
|
19
|
+
err: string;
|
|
20
|
+
/** true when the binary could not be spawned at all (ENOENT et al). */
|
|
21
|
+
missing?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** The command runner seam: spawnSync in production, a stub in tests. */
|
|
24
|
+
export type CommandRunner = (cmd: string, args: readonly string[]) => ToolResult;
|
|
25
|
+
/** Production runner: spawn without a shell, capture text, 20s timeout. */
|
|
26
|
+
export declare const spawnRunner: CommandRunner;
|
|
27
|
+
/** A firewall backend manages one allow rule for a TCP port. */
|
|
28
|
+
export interface FirewallBackend {
|
|
29
|
+
/** Short label surfaced in the settings card (netsh, firewalld, ...). */
|
|
30
|
+
readonly label: string;
|
|
31
|
+
ruleExists(port: number): boolean;
|
|
32
|
+
addRule(port: number): boolean;
|
|
33
|
+
removeRule(port: number): boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Detect the platform firewall manager. Returns undefined when the platform
|
|
37
|
+
* has no supported manager (macOS, unknown Linux without tools): the port
|
|
38
|
+
* then usually needs no rule and the UI reports "unmanaged".
|
|
39
|
+
*/
|
|
40
|
+
export declare function detectFirewallBackend(platform: NodeJS.Platform, run?: CommandRunner): FirewallBackend | undefined;
|
|
41
|
+
/** Cached detection for the running platform (per process). */
|
|
42
|
+
export declare function firewallBackend(): FirewallBackend | undefined;
|
|
43
|
+
/** Firewall state reported to the settings card. */
|
|
44
|
+
export interface FirewallSummary {
|
|
45
|
+
/** true when the rule state matches the LAN toggle (or nothing to manage). */
|
|
46
|
+
ok: boolean;
|
|
47
|
+
/** false when no supported firewall manager exists on this platform. */
|
|
48
|
+
managed: boolean;
|
|
49
|
+
/** Backend label or an explanation for unmanaged platforms. */
|
|
50
|
+
note?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Delete-and-add: recreating the rule is idempotent and locale-proof (netsh
|
|
54
|
+
* output is localized, so parsing the live rule's port is fragile; the Linux
|
|
55
|
+
* backends follow the same recreate pattern).
|
|
56
|
+
*/
|
|
57
|
+
export declare function ensureFirewallRule(port: number): boolean;
|
|
58
|
+
export declare function removeFirewallRule(port: number): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Human-readable firewall state for the status endpoint. A missing backend
|
|
61
|
+
* means the platform has nothing to manage; detection stays at the call site
|
|
62
|
+
* so an explicit undefined cannot silently re-probe the real OS mid-test.
|
|
63
|
+
*/
|
|
64
|
+
export declare function computeFirewallSummary(port: number, lanEnabled: boolean, backend: FirewallBackend | undefined): FirewallSummary;
|
|
65
|
+
/** How long a firewallSummary answer is reused before the backend is probed again. */
|
|
66
|
+
export declare const FIREWALL_SUMMARY_TTL_MS = 30000;
|
|
67
|
+
/** Forget the cached summary (rule mutations call this). */
|
|
68
|
+
export declare function invalidateFirewallSummary(): void;
|
|
69
|
+
/**
|
|
70
|
+
* The settings card polls this every ten seconds; the probes are blocking
|
|
71
|
+
* spawnSync subprocesses on managed platforms, so short-TTL memoization
|
|
72
|
+
* keeps one poll from freezing the host event loop per request.
|
|
73
|
+
*/
|
|
74
|
+
export declare function firewallSummary(port: number, lanEnabled: boolean): FirewallSummary;
|