@linxin666/dsh-remote-bridge 0.4.12 → 0.4.13
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 +45 -8
- package/README.zh.md +45 -8
- package/lib/client.js +1 -1
- package/lib/client.js.map +1 -1
- package/lib/index.js +18031 -373
- package/lib/types/core/connection.d.ts +9 -0
- package/lib/types/core/devices.d.ts +27 -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 +2 -0
- package/lib/types/core/push.d.ts +51 -2
- 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 +215 -0
- package/lib/types/host/relay-connector.d.ts +152 -0
- package/lib/types/host/relay-control.d.ts +124 -0
- package/lib/types/host/relay-registry.d.ts +114 -0
- package/lib/types/host/relay.d.ts +170 -0
- package/lib/types/host/routes.d.ts +24 -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 +426 -1
- package/package.json +4 -2
- package/src/client/panel.module.css +16 -1
- package/src/core/connection.ts +206 -11
- package/src/core/devices.ts +31 -6
- 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 +3 -0
- package/src/core/push.ts +70 -4
- 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 +783 -0
- package/src/host/relay-connector.ts +317 -0
- package/src/host/relay-control.ts +224 -0
- package/src/host/relay-registry.ts +263 -0
- package/src/host/relay.ts +294 -0
- package/src/host/routes.ts +47 -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 +1280 -22
|
@@ -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';
|
|
@@ -107,6 +108,14 @@ export interface BridgeConnectionOptions {
|
|
|
107
108
|
readonly usage: UsageService;
|
|
108
109
|
/** Host-process permission presets, read and switched through their real service objects. */
|
|
109
110
|
readonly permissions: SessionPermissions;
|
|
111
|
+
/**
|
|
112
|
+
* 每个模型自己的思考档偏好表(`core/model-efforts.ts`)。
|
|
113
|
+
*
|
|
114
|
+
* 一个宿主一份、所有连接与所有会话共享:它记的是这个模型在这台机器上被选过
|
|
115
|
+
* 哪一档,与哪条会话无关(契约 §4)。它与宿主自己的 `reasoning.defaultEffort`
|
|
116
|
+
* 是两件事,`session.models` 用另一个键名 `preferredEffort` 公布它。
|
|
117
|
+
*/
|
|
118
|
+
readonly modelEfforts: ModelEffortPreferences;
|
|
110
119
|
/**
|
|
111
120
|
* The in-process owner peer every gateway call speaks for, minted by the
|
|
112
121
|
* bridge itself (`core/owner-peer.ts`). Dispatch refuses unpaired
|
|
@@ -18,13 +18,15 @@ 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. Every step is
|
|
23
|
+
* additive, so an older file reads as-is: no row loses a field, every paired phone
|
|
24
|
+
* stays paired, and the file is rewritten as the current version the next time
|
|
25
|
+
* anything is written. The reader therefore accepts any version whose row table
|
|
26
|
+
* validates rather than quarantining a file it merely does not recognise — a
|
|
27
|
+
* downgrade must never un-pair every phone.
|
|
26
28
|
*/
|
|
27
|
-
export declare const ROSTER_VERSION =
|
|
29
|
+
export declare const ROSTER_VERSION = 3;
|
|
28
30
|
/** The APNs environments a device may register for. */
|
|
29
31
|
export type PushEnvironment = 'sandbox' | 'production';
|
|
30
32
|
/** One Live Activity push token, with the session the card belongs to. */
|
|
@@ -58,6 +60,16 @@ export interface PushRegistration {
|
|
|
58
60
|
readonly bundle: string;
|
|
59
61
|
readonly locale?: string;
|
|
60
62
|
readonly liveActivityTokens?: readonly PushLiveActivityToken[];
|
|
63
|
+
/**
|
|
64
|
+
* The bearer the hosted relay accepts for this device's fingerprint.
|
|
65
|
+
*
|
|
66
|
+
* The App obtains it from the account service, scoped to `(userId, fingerprint)`
|
|
67
|
+
* and valid for 90 days, and hands it to this bridge through `push.register`. It
|
|
68
|
+
* is what lets a machine with no Apple signing key still deliver §28's events: the
|
|
69
|
+
* relay signs them with the key that never leaves the service. Absent is a phone
|
|
70
|
+
* whose only route is this machine's own key, which is the pre-relay behaviour.
|
|
71
|
+
*/
|
|
72
|
+
readonly relayToken?: string;
|
|
61
73
|
readonly registeredAt: number;
|
|
62
74
|
}
|
|
63
75
|
/** One device a notification can be addressed to. */
|
|
@@ -169,4 +181,13 @@ export declare class DeviceRoster {
|
|
|
169
181
|
removePush(deviceToken: string): Promise<boolean>;
|
|
170
182
|
/** @returns every paired device that registered for notifications. */
|
|
171
183
|
pushTargets(): readonly PushTargetView[];
|
|
184
|
+
/**
|
|
185
|
+
* @returns every paired device that holds a relay token.
|
|
186
|
+
*
|
|
187
|
+
* The relay path's own reachability question: a row that registered an APNs
|
|
188
|
+
* token before the relay existed is a phone this machine cannot notify without a
|
|
189
|
+
* local key, so counting {@link pushTargets} there would claim a delivery that
|
|
190
|
+
* has no route at all.
|
|
191
|
+
*/
|
|
192
|
+
relayTargets(): readonly PushTargetView[];
|
|
172
193
|
}
|
|
@@ -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";
|
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. */
|
|
@@ -42,6 +52,14 @@ export interface PushAddress {
|
|
|
42
52
|
readonly environment: 'sandbox' | 'production';
|
|
43
53
|
readonly bundle: string;
|
|
44
54
|
readonly locale?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The relay credential that same row registered, when it registered one.
|
|
57
|
+
*
|
|
58
|
+
* Present on the address rather than looked up by the sender so the two routes
|
|
59
|
+
* stay one decision: a row carries the token only in relay mode, and the sender
|
|
60
|
+
* that reads it is the only one this bridge built.
|
|
61
|
+
*/
|
|
62
|
+
readonly relayToken?: string;
|
|
45
63
|
}
|
|
46
64
|
/** The request body one APNs delivery carries (protocol §28.4). */
|
|
47
65
|
export interface PushNotification {
|
|
@@ -61,10 +79,19 @@ export interface PushNotification {
|
|
|
61
79
|
/** What one delivery attempt reported. */
|
|
62
80
|
export interface PushSendResult {
|
|
63
81
|
readonly ok: boolean;
|
|
64
|
-
/** The status APNs answered, when it answered at all. */
|
|
82
|
+
/** The status APNs answered, or the relay did, when it answered at all. */
|
|
65
83
|
readonly status?: number;
|
|
66
84
|
/** The reason APNs named, or this bridge's own note. */
|
|
67
85
|
readonly reason?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Whether the answer said this registration will never work again.
|
|
88
|
+
*
|
|
89
|
+
* APNs says it in a status and a reason this module can read; the relay says it
|
|
90
|
+
* in a count of tokens it just retired, which names no status of its own. The
|
|
91
|
+
* sender that learned it reports the fact here instead of borrowing an APNs
|
|
92
|
+
* status it did not receive.
|
|
93
|
+
*/
|
|
94
|
+
readonly dead?: boolean;
|
|
68
95
|
}
|
|
69
96
|
/** One delivery a sender refused, in the words the bridge needs to read it. */
|
|
70
97
|
export interface PushDeliveryFailure {
|
|
@@ -74,6 +101,8 @@ export interface PushDeliveryFailure {
|
|
|
74
101
|
readonly status?: number;
|
|
75
102
|
/** The reason APNs named, or this bridge's own note. */
|
|
76
103
|
readonly reason?: string;
|
|
104
|
+
/** Whether this failure was final about the registration behind it. */
|
|
105
|
+
readonly dead?: boolean;
|
|
77
106
|
}
|
|
78
107
|
/** What one {@link PushNotifier.notify} ended up doing, once every attempt settled. */
|
|
79
108
|
export interface PushDeliveryReport {
|
|
@@ -113,6 +142,18 @@ export interface PushNotifierOptions {
|
|
|
113
142
|
readonly targets: () => readonly PushAddress[];
|
|
114
143
|
/** The sender; absent is a bridge with no signing key, and then nothing happens. */
|
|
115
144
|
readonly sender?: PushSender;
|
|
145
|
+
/**
|
|
146
|
+
* Whether the configured route can reach a phone right now.
|
|
147
|
+
*
|
|
148
|
+
* Absent means "the sender is reason enough", which is what a machine holding its
|
|
149
|
+
* own Apple key is: the key is configured or it is not. The relay has a second
|
|
150
|
+
* fact in front of the credential — some paired row must still hold a relay
|
|
151
|
+
* token — and reading it per event is what keeps a bridge with neither route
|
|
152
|
+
* exactly as inert as one with no key at all.
|
|
153
|
+
*/
|
|
154
|
+
readonly available?: () => boolean;
|
|
155
|
+
/** Which route this notifier stands on; `direct` by default, as before the relay existed. */
|
|
156
|
+
readonly mode?: PushRoute;
|
|
116
157
|
/** The session's own title (§26's source), read per event. */
|
|
117
158
|
readonly titles?: (sessionId: string) => string | undefined;
|
|
118
159
|
readonly now?: () => number;
|
|
@@ -151,8 +192,16 @@ export declare function pushEventOfTurnEnd(reason: string): PushEvent;
|
|
|
151
192
|
export declare class PushNotifier {
|
|
152
193
|
#private;
|
|
153
194
|
constructor(options: PushNotifierOptions);
|
|
154
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* @returns whether this bridge will actually deliver anything.
|
|
197
|
+
*
|
|
198
|
+
* Read by every entrance — a delta path, a claim, a watcher — so a bridge whose
|
|
199
|
+
* route is not armed is indistinguishable from one that never had a channel: no
|
|
200
|
+
* target is read, no clock is consulted and no timer is armed.
|
|
201
|
+
*/
|
|
155
202
|
get enabled(): boolean;
|
|
203
|
+
/** @returns which road a delivery would take: this machine's key or the hosted relay. */
|
|
204
|
+
get mode(): PushRoute;
|
|
156
205
|
/**
|
|
157
206
|
* Remember the workspace each session belongs to, from a roster this bridge
|
|
158
207
|
* 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;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the installed webserver accepts as a bind address, plus the address
|
|
3
|
+
* classes the LAN-bind decision needs (issue #1893).
|
|
4
|
+
*
|
|
5
|
+
* The managed LAN-bind block used to pin `host: '0.0.0.0'`. Since
|
|
6
|
+
* `@deepseek-ai/dsh-host-webserver@0.2.1-rc.2` the webserver `Config` schema
|
|
7
|
+
* rejects the unspecified (wildcard) address, so such a block is refused at
|
|
8
|
+
* config validation and every later `dsh web` start fails. This module is the
|
|
9
|
+
* one place that asks the installed package instead of assuming, and the block
|
|
10
|
+
* planner reads its answer.
|
|
11
|
+
*
|
|
12
|
+
* The value import below is a devDependency of this package and must stay
|
|
13
|
+
* external in the published bundle: the host process resolves it from the
|
|
14
|
+
* profile tree, which is exactly the module it is about to compose. A host this
|
|
15
|
+
* module cannot interrogate is never assumed permissive - every failure path
|
|
16
|
+
* answers "no wildcard", because an unreadable package must not make the block
|
|
17
|
+
* pin a literal that refuses to boot.
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-remote-bridge/host/host-bind-capability
|
|
20
|
+
*/
|
|
21
|
+
/** A schemastery-style schema: call the factory, throw on refusal. */
|
|
22
|
+
export type ConfigSchemaFactory = (value: unknown) => unknown;
|
|
23
|
+
/**
|
|
24
|
+
* The schema factory of whatever module shape was loaded. The package exposes
|
|
25
|
+
* `WebServer` both as a named export and as the default, and the default may
|
|
26
|
+
* itself be a namespace, so the lookup walks those two links. Anything without
|
|
27
|
+
* a callable `Config` is treated as an unusable shape.
|
|
28
|
+
* @param moduleNamespace - the loaded module object (or any nested holder).
|
|
29
|
+
* @returns the schema factory, or undefined when the shape is unusable.
|
|
30
|
+
*/
|
|
31
|
+
export declare function configSchemaOf(moduleNamespace: unknown): ConfigSchemaFactory | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Validate the wildcard bind against one schema factory.
|
|
34
|
+
* @param configOf - the schema factory to interrogate (undefined = unusable shape).
|
|
35
|
+
* @returns true only when the schema accepts the wildcard bind.
|
|
36
|
+
*/
|
|
37
|
+
export declare function probeWildcardBindSupport(configOf: ConfigSchemaFactory | undefined): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the host this plugin runs on accepts the wildcard bind. Grounded in
|
|
40
|
+
* the installed package's own schema, so it cannot drift away from the host
|
|
41
|
+
* whatever the version is called; false when the package cannot be read.
|
|
42
|
+
* @param configOf - schema factory override (test seam); by default the
|
|
43
|
+
* installed package's own `WebServer.Config`.
|
|
44
|
+
* @returns true only when the wildcard bind validates.
|
|
45
|
+
*/
|
|
46
|
+
export declare function wildcardBindSupported(configOf?: ConfigSchemaFactory): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Validate one bind literal against one schema factory, the way the host
|
|
49
|
+
* validates a profile's webserver row.
|
|
50
|
+
* @param configOf - the schema factory to interrogate (undefined = unusable shape).
|
|
51
|
+
* @param host - the bind literal to validate.
|
|
52
|
+
* @returns true only when the schema accepts that literal on a fixed port.
|
|
53
|
+
*/
|
|
54
|
+
export declare function probeBindAccepted(configOf: ConfigSchemaFactory | undefined, host: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Whether the running host accepts one bind literal. This is the rule the
|
|
57
|
+
* managed block must follow instead of "is it a wildcard": the block REPLACES
|
|
58
|
+
* the webserver row's config wholesale, so nothing else validates the CLI
|
|
59
|
+
* `--host` that reaches it, and a literal the schema refuses bricks the next
|
|
60
|
+
* start with a block that cannot be fixed from the settings card (issue #1893).
|
|
61
|
+
* @param host - the bind literal to validate (an absent or empty value is never accepted).
|
|
62
|
+
* @param configOf - schema factory override (test seam); by default the
|
|
63
|
+
* installed package's own `WebServer.Config`.
|
|
64
|
+
* @returns true only when the schema accepts the literal; false on every
|
|
65
|
+
* unreadable shape, and never throws.
|
|
66
|
+
*/
|
|
67
|
+
export declare function bindAccepted(host: string | undefined, configOf?: ConfigSchemaFactory): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Whether a bind value asks for every interface at once.
|
|
70
|
+
* @param host - the bind value (absent while a recompose pass has not settled).
|
|
71
|
+
* @returns true for the wildcard classes.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isWildcardLiteral(host: string | undefined): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Whether a bind value names this machine only, so no other device can dial
|
|
76
|
+
* it: the loopback literals of the host package (127/8, ::1 and their mapped
|
|
77
|
+
* forms), the `localhost` token the schema refuses as a literal, and an absent
|
|
78
|
+
* bind. A hostname is treated by the host package's own verdict, not guessed.
|
|
79
|
+
* @param host - the bind value (absent while a recompose pass has not settled).
|
|
80
|
+
* @returns true when nothing off this machine can reach the listener.
|
|
81
|
+
*/
|
|
82
|
+
export declare function isLoopbackBind(host: string | undefined): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* The URL authority a concrete bind literal is expressed by. The host package
|
|
85
|
+
* owns the canonical form (mapped loopback collapses to dotted quad, IPv6 gets
|
|
86
|
+
* bracketed, a non-loopback zone id has no URL form).
|
|
87
|
+
* @param host - a concrete bind literal.
|
|
88
|
+
* @returns the URL host, or undefined when the literal has no URL form.
|
|
89
|
+
*/
|
|
90
|
+
export declare function bindUrlHostOf(host: string): string | undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The inbound ingress gate: one loopback-only HTTP listener that forwards
|
|
3
|
+
* exactly one upgrade path to the host's own protocol port.
|
|
4
|
+
*
|
|
5
|
+
* It exists so a tunnel or the relay bridge can be pointed at a listener whose
|
|
6
|
+
* whole surface is `WS_PATH`. Everything else is refused at this hop instead
|
|
7
|
+
* of being forwarded and judged further in: a request the gate does not serve
|
|
8
|
+
* never opens an upstream connection, so the host's routes, plugins and
|
|
9
|
+
* control plane are not reachable through it even by a misconfigured tunnel.
|
|
10
|
+
*
|
|
11
|
+
* The gate holds no state between two connections: it writes no log line,
|
|
12
|
+
* touches no file, and keeps no token. The only thing it owns is one socket
|
|
13
|
+
* per side, closed together.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-remote-bridge/host/ingress-gate
|
|
16
|
+
*/
|
|
17
|
+
/** The body every refused request and upgrade is answered with. */
|
|
18
|
+
export declare const INGRESS_NOT_FOUND_BODY = "{\"error\":\"not-found\"}";
|
|
19
|
+
/**
|
|
20
|
+
* The one address the gate ever binds. It is a loopback listener by
|
|
21
|
+
* construction: nothing outside this machine may reach it directly, which is
|
|
22
|
+
* what keeps the forwarding decision the only way in.
|
|
23
|
+
*/
|
|
24
|
+
export declare const INGRESS_BIND_HOST = "127.0.0.1";
|
|
25
|
+
/**
|
|
26
|
+
* Whether one inbound URL is the single path this gate forwards.
|
|
27
|
+
*
|
|
28
|
+
* The comparison is on the path, not the whole URL: the pairing link carries
|
|
29
|
+
* its one-shot ticket in the query (`WS_PATH?token=...`), so a strict
|
|
30
|
+
* whole-URL match would refuse the one client the host is waiting for. A path
|
|
31
|
+
* that merely starts the same way, another path, and an empty URL are refused.
|
|
32
|
+
* @param url - the request URL as node reports it.
|
|
33
|
+
* @returns true when the path is exactly `WS_PATH`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isIngressPath(url: string): boolean;
|
|
36
|
+
/** What the gate needs to know to dial the host's own listener. */
|
|
37
|
+
export interface IngressGateOptions {
|
|
38
|
+
/** The host the upstream protocol listener answers on. */
|
|
39
|
+
upstreamHost: string;
|
|
40
|
+
/** The port the upstream protocol listener bound. */
|
|
41
|
+
upstreamPort: number;
|
|
42
|
+
}
|
|
43
|
+
/** The port the gate took. */
|
|
44
|
+
export interface IngressGateStarted {
|
|
45
|
+
port: number;
|
|
46
|
+
}
|
|
47
|
+
/** One ingress gate: bind, report the port, close. */
|
|
48
|
+
export interface IngressGate {
|
|
49
|
+
/** Bind the loopback listener and report the port it took. */
|
|
50
|
+
start(): Promise<IngressGateStarted>;
|
|
51
|
+
/** Close the listener and every socket it still holds (idempotent). */
|
|
52
|
+
stop(): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Build one gate.
|
|
56
|
+
* @param options - the upstream listener the gate forwards to.
|
|
57
|
+
* @returns the gate itself; nothing is bound until `start()` runs.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createIngressGate(options: IngressGateOptions): IngressGate;
|