@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
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The squad domain as this Host reaches it: the `dsh-agents` HTTP routes over
|
|
3
|
+
* this machine's own loopback origin, with its ledger as a read-only fallback.
|
|
4
|
+
*
|
|
5
|
+
* The plugin's routes are the preferred source because they are the live one: a
|
|
6
|
+
* definition the user just saved and a run that is still settling are both in the
|
|
7
|
+
* plugin's own process state, while the ledger is the last committed write. So the
|
|
8
|
+
* read is `GET /dsh-agents/api/state` and the two launches are POSTs, all
|
|
9
|
+
* addressed at the origin `webServer` already serves and all carrying the `origin`
|
|
10
|
+
* header the plugin's browser fence reads as its same-origin signal.
|
|
11
|
+
*
|
|
12
|
+
* A loopback call that cannot connect at all — nothing bound, a refused
|
|
13
|
+
* connection, or a deadline — is what makes the fallback necessary: the
|
|
14
|
+
* definitions are then read from the plugin's ledger, read-only, and the two run
|
|
15
|
+
* commands fail closed with `squads-run-unavailable` instead of answering a run
|
|
16
|
+
* that never started. An answer of any status is NOT a fallback: it is the plugin
|
|
17
|
+
* speaking, and its refusal crosses with its own code.
|
|
18
|
+
* @module dsh-remote-bridge/host/squads
|
|
19
|
+
*/
|
|
20
|
+
import { type SquadMemberRunRequest, type SquadRunRequest, type SquadTransport } from '../core/squads.ts';
|
|
21
|
+
/**
|
|
22
|
+
* The three routes this channel drives, restated from the plugin's own
|
|
23
|
+
* `DSH_AGENTS_ROUTE_PATHS`. They are spelled here rather than imported: this
|
|
24
|
+
* package depends on no other plugin, so a frozen path is the only thing that can
|
|
25
|
+
* cross between them.
|
|
26
|
+
*/
|
|
27
|
+
export declare const SQUADS_STATE_PATH = "/dsh-agents/api/state";
|
|
28
|
+
export declare const SQUADS_RUN_MEMBER_PATH = "/dsh-agents/api/run";
|
|
29
|
+
export declare const SQUADS_RUN_SQUAD_PATH = "/dsh-agents/api/squad/run";
|
|
30
|
+
/** Deadline behind one loopback read: the plugin answers a state read from memory. */
|
|
31
|
+
export declare const SQUADS_LOOPBACK_TIMEOUT_MS = 5000;
|
|
32
|
+
/**
|
|
33
|
+
* Deadline behind one launch. A launch composes a session, restores it when it is
|
|
34
|
+
* cold and may queue a first message, so it is allowed far longer than a read; the
|
|
35
|
+
* bound exists to keep one stuck call from holding a connection open, not to time
|
|
36
|
+
* the plugin's work.
|
|
37
|
+
*/
|
|
38
|
+
export declare const SQUADS_RUN_TIMEOUT_MS = 60000;
|
|
39
|
+
/** Construction options; the origin and the ledger directory are resolved per call. */
|
|
40
|
+
export interface LoopbackSquadsOptions {
|
|
41
|
+
/** The origin this host's own web server listens on, or undefined before it binds. */
|
|
42
|
+
readonly origin: () => string | undefined;
|
|
43
|
+
/** The plugin-owned directory `dsh-agents` keeps its ledger in. */
|
|
44
|
+
readonly ledgerDirectory: () => string;
|
|
45
|
+
/** Outbound call seam; the production default is the process's own fetch. */
|
|
46
|
+
readonly fetch?: typeof fetch;
|
|
47
|
+
/** Deadline behind one read; the default is {@link SQUADS_LOOPBACK_TIMEOUT_MS}. */
|
|
48
|
+
readonly timeoutMs?: number;
|
|
49
|
+
/** Deadline behind one launch; the default is {@link SQUADS_RUN_TIMEOUT_MS}. */
|
|
50
|
+
readonly runTimeoutMs?: number;
|
|
51
|
+
readonly log: (message: string) => void;
|
|
52
|
+
}
|
|
53
|
+
/** The squad domain over loopback, with the ledger as its read-only fallback. */
|
|
54
|
+
export declare class LoopbackSquads implements SquadTransport {
|
|
55
|
+
#private;
|
|
56
|
+
constructor(options: LoopbackSquadsOptions);
|
|
57
|
+
/**
|
|
58
|
+
* Read the definitions and runs.
|
|
59
|
+
*
|
|
60
|
+
* A loopback call that connects answers for the domain, its refusals included.
|
|
61
|
+
* A call that cannot connect at all falls back to the ledger, and a ledger that
|
|
62
|
+
* is missing or unreadable refuses the read rather than answering an empty
|
|
63
|
+
* board.
|
|
64
|
+
*/
|
|
65
|
+
state(): Promise<unknown>;
|
|
66
|
+
/**
|
|
67
|
+
* Launch one member session through the plugin's own run route.
|
|
68
|
+
* @param request - the squad, the member and the optional first message.
|
|
69
|
+
*/
|
|
70
|
+
runMember(request: SquadMemberRunRequest): Promise<unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Launch the Lead session of one whole squad through the plugin's own squad run
|
|
73
|
+
* route.
|
|
74
|
+
* @param request - the squad and the optional goal its Lead is given.
|
|
75
|
+
*/
|
|
76
|
+
runSquad(request: SquadRunRequest): Promise<unknown>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 宿主上 `dsh-usage` 插件的两条路由,按 `usage.stats` 需要的那一格读出来。
|
|
3
|
+
*
|
|
4
|
+
* 那个插件把台账挂在**同一个** web 服务上(`/api/dsh-usage/overview` 与
|
|
5
|
+
* `/api/dsh-usage/day`,见它的 `host/routes.ts`),所以这里不去进程里找它的服务
|
|
6
|
+
* ——它不发布任何 cordis 服务——而是对本机回环 origin 发一次真正的 GET。路径在这
|
|
7
|
+
* 里重写一遍而不是 import 过来:本包不依赖任何别的插件,能跨过来的只有冻结的路径
|
|
8
|
+
* 字符串。
|
|
9
|
+
*
|
|
10
|
+
* 端口从哪来:先问宿主自己的 `webServer.getOrigin()`(那是它已经绑定的地址,含
|
|
11
|
+
* 协议与端口,也是 `dsh-agents` 那一格用的同一条路);拿不到时退回
|
|
12
|
+
* `${protocol}//127.0.0.1:${port}` 的监听端口探测。后者只在这台宿主把监听绑在
|
|
13
|
+
* 回环地址上时才连得通,绑到别的网卡上会连不上——那时答案是 `probe-failed`,
|
|
14
|
+
* 而不是一个编出来的读数。
|
|
15
|
+
*
|
|
16
|
+
* 一次读的三种结局:答了、路由不存在、这次没读到。第三种带一句短原因。**404 是
|
|
17
|
+
* 第二种**:那台宿主没挂这个插件,是一件事实;而连接被拒、超时、非 200、读不出
|
|
18
|
+
* JSON 都是第三种。
|
|
19
|
+
* @module dsh-remote-bridge/host/usage-stats
|
|
20
|
+
*/
|
|
21
|
+
import type { UsageStatsOutcome, UsageStatsTransport } from '../core/usage-stats.ts';
|
|
22
|
+
/**
|
|
23
|
+
* 那个插件挂的两条路由;按它的 `USAGE_API_PREFIX` 拼出来。
|
|
24
|
+
*/
|
|
25
|
+
export declare const USAGE_OVERVIEW_PATH = "/api/dsh-usage/overview";
|
|
26
|
+
export declare const USAGE_DAY_PATH = "/api/dsh-usage/day";
|
|
27
|
+
/** 一次回环读的超时。那个插件从内存里答,这个时限只是不让一次卡住拖住连接。 */
|
|
28
|
+
export declare const USAGE_PROBE_TIMEOUT_MS = 5000;
|
|
29
|
+
/** 宿主 web 服务在这条路上要的那两格;结构读取,不导入它的类型。 */
|
|
30
|
+
export interface WebServerAddress {
|
|
31
|
+
/** 已经绑定的 origin,形如 `http://127.0.0.1:3080`;监听之前会抛。 */
|
|
32
|
+
getOrigin?(): string;
|
|
33
|
+
/** 监听器说的协议,随配置而不是随请求。 */
|
|
34
|
+
readonly protocol?: string;
|
|
35
|
+
/** 实际监听的端口(端口写 0 时是系统分配的那个);绑定之前是 undefined。 */
|
|
36
|
+
readonly port?: number;
|
|
37
|
+
}
|
|
38
|
+
/** 构造 {@link LoopbackUsage} 的全部输入。 */
|
|
39
|
+
export interface LoopbackUsageOptions {
|
|
40
|
+
/** 每次读数都重新解析一次:这一行挂载时监听器可能还没有端口。 */
|
|
41
|
+
readonly origin: () => string | undefined;
|
|
42
|
+
/** 出站调用的接缝;生产默认是本进程的 `fetch`。 */
|
|
43
|
+
readonly fetch?: typeof fetch;
|
|
44
|
+
/** 一次读的超时;默认 {@link USAGE_PROBE_TIMEOUT_MS}。 */
|
|
45
|
+
readonly timeoutMs?: number;
|
|
46
|
+
readonly log: (message: string) => void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 本机 web 服务的 origin。
|
|
50
|
+
*
|
|
51
|
+
* 先问宿主给的那个(它知道自己的绑定地址),拿不到就退回 127.0.0.1 上的监听端口。
|
|
52
|
+
* 两条都不成立时回 undefined,调用方据此答 `probe-failed`。
|
|
53
|
+
* @param server - 宿主 web 服务,可能还没挂载。
|
|
54
|
+
* @returns origin,或者 undefined。
|
|
55
|
+
*/
|
|
56
|
+
export declare function hostWebOrigin(server: WebServerAddress | undefined): string | undefined;
|
|
57
|
+
/** 宿主那两条路由,走本机回环。 */
|
|
58
|
+
export declare class LoopbackUsage implements UsageStatsTransport {
|
|
59
|
+
#private;
|
|
60
|
+
/**
|
|
61
|
+
* @param options - origin 解析函数、出站调用与超时。
|
|
62
|
+
*/
|
|
63
|
+
constructor(options: LoopbackUsageOptions);
|
|
64
|
+
/**
|
|
65
|
+
* `GET /api/dsh-usage/overview`。
|
|
66
|
+
* @returns 宿主答的那份聚合,或者为什么没读到。
|
|
67
|
+
*/
|
|
68
|
+
overview(): Promise<UsageStatsOutcome>;
|
|
69
|
+
/**
|
|
70
|
+
* `GET /api/dsh-usage/day?date=<day>`。
|
|
71
|
+
* @param day - 本地日期键 `YYYY-MM-DD`。
|
|
72
|
+
* @returns 那一天的台账,或者为什么没读到。
|
|
73
|
+
*/
|
|
74
|
+
day(day: string): Promise<UsageStatsOutcome>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge's own follow streams: one per session that holds a live card.
|
|
3
|
+
*
|
|
4
|
+
* §28 and §29 both describe things this bridge must report while it is the only
|
|
5
|
+
* party still awake, and everything that reports them used to hang off a
|
|
6
|
+
* client's own stream: a turn end was observed only while this bridge was
|
|
7
|
+
* draining a follow stream for a connected phone. A suspended app has no such
|
|
8
|
+
* stream — its socket is closed and the subscription is aborted with the
|
|
9
|
+
* connection — so the card frozen on its lock screen kept saying "running" long
|
|
10
|
+
* after the turn was over, and no APNs delivery ever failed, because nothing was
|
|
11
|
+
* ever sent.
|
|
12
|
+
*
|
|
13
|
+
* A standing watcher is that missing party: for one session with at least one
|
|
14
|
+
* registered live-activity token this bridge opens its OWN follow stream, under
|
|
15
|
+
* the same in-process owner peer every other gateway call speaks for, and turns
|
|
16
|
+
* the one frame it cares about — `turn/end` — into the two things a card needs:
|
|
17
|
+
* §28's notification and §29's card end, each addressed to that session alone.
|
|
18
|
+
*
|
|
19
|
+
* Five rules keep that from becoming a second, unaccountable scheduler:
|
|
20
|
+
*
|
|
21
|
+
* - a watcher exists exactly while its session holds a card token, reconciled by
|
|
22
|
+
* {@link StandingWatchers.sync} from the roster rather than from any client
|
|
23
|
+
* frame;
|
|
24
|
+
* - at most {@link WATCHER_LIMIT} streams are open at once; past that a session
|
|
25
|
+
* is logged once and left unwatched, so a card on a session that never ends
|
|
26
|
+
* cannot grow the set without bound;
|
|
27
|
+
* - dedupe is inherited, not added: a client that is also following the same
|
|
28
|
+
* session sees the same turn end, and the two reports collapse in the layers
|
|
29
|
+
* that already own that rule — §28.5's `(sessionId, event)` window and §29's
|
|
30
|
+
* identical-content key. No third window is introduced here;
|
|
31
|
+
* - a stream that ends on its own is re-armed after {@link WATCHER_REOPEN_MS},
|
|
32
|
+
* because the next turn is the next thing a card has to show;
|
|
33
|
+
* - nothing a watcher does can reach a client frame: every failure is one log
|
|
34
|
+
* line, and a stream that cannot be opened is dropped rather than retried in a
|
|
35
|
+
* tight loop.
|
|
36
|
+
* @module dsh-remote-bridge/host/watchers
|
|
37
|
+
*/
|
|
38
|
+
import type { LiveActivityNotifier } from '../core/liveactivity.ts';
|
|
39
|
+
import { type PushNotifier } from '../core/push.ts';
|
|
40
|
+
import { type BridgeGateway, type GatewayPeer } from '../core/wire.ts';
|
|
41
|
+
/** Most standing streams this bridge keeps open at once. */
|
|
42
|
+
export declare const WATCHER_LIMIT = 64;
|
|
43
|
+
/** How long a watcher waits before re-opening a stream that ended on its own. */
|
|
44
|
+
export declare const WATCHER_REOPEN_MS = 1000;
|
|
45
|
+
export interface StandingWatcherOptions {
|
|
46
|
+
/** The host's gateway, the same one the connections speak through. */
|
|
47
|
+
readonly gateway: BridgeGateway;
|
|
48
|
+
/** The in-process owner peer every call of this bridge speaks for. */
|
|
49
|
+
readonly peer: GatewayPeer;
|
|
50
|
+
/**
|
|
51
|
+
* Sessions that currently hold at least one registered live-activity token,
|
|
52
|
+
* read from the roster on every reconcile.
|
|
53
|
+
*/
|
|
54
|
+
readonly sessions: () => readonly string[];
|
|
55
|
+
/** The card path of §29; absent is a bridge with no signing key. */
|
|
56
|
+
readonly liveActivity?: LiveActivityNotifier;
|
|
57
|
+
/** The notification path of §28; absent for the same reason. */
|
|
58
|
+
readonly push?: PushNotifier;
|
|
59
|
+
readonly log: (message: string) => void;
|
|
60
|
+
readonly limit?: number;
|
|
61
|
+
readonly reopenMs?: number;
|
|
62
|
+
readonly maxMessages?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The bridge's stand-in for a client that is no longer there.
|
|
66
|
+
*
|
|
67
|
+
* Deliberately inert when neither push path is configured: {@link sync} returns
|
|
68
|
+
* without opening anything, so a bridge without an Apple signing key keeps the
|
|
69
|
+
* exact stream count it had before this module existed.
|
|
70
|
+
*/
|
|
71
|
+
export declare class StandingWatchers {
|
|
72
|
+
#private;
|
|
73
|
+
constructor(options: StandingWatcherOptions);
|
|
74
|
+
/** @returns how many standing streams are open right now. */
|
|
75
|
+
get size(): number;
|
|
76
|
+
/** @returns whether this bridge has any path worth opening a stream for. */
|
|
77
|
+
get enabled(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Reconcile the open streams with the sessions that hold a card right now.
|
|
80
|
+
*
|
|
81
|
+
* Called when the roster changes (a registration arrived, a dead token was
|
|
82
|
+
* retired) and when a stream ends. Idempotent, and safe to call before the
|
|
83
|
+
* roster has been read: no session with a token means nothing to watch.
|
|
84
|
+
*/
|
|
85
|
+
sync(): void;
|
|
86
|
+
/** Close every stream and drop every pending re-arm. Idempotent. */
|
|
87
|
+
dispose(): void;
|
|
88
|
+
}
|
|
@@ -95,7 +95,14 @@ export declare class WebSocketCarrier implements BridgeTransport {
|
|
|
95
95
|
onClose(handler: () => void): void;
|
|
96
96
|
/** Feed raw bytes from the socket into the frame loop. */
|
|
97
97
|
feed(chunk: Buffer): void;
|
|
98
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Record the peer's `frame.deflate.v1` declaration, as `hello` reported it.
|
|
100
|
+
*
|
|
101
|
+
* It defaults to off, so a connection that never declares the capability keeps
|
|
102
|
+
* the text frame this carrier always wrote, byte for byte.
|
|
103
|
+
*/
|
|
104
|
+
frameDeflate(declared: boolean): void;
|
|
105
|
+
/** Send one frame: the text itself, or raw DEFLATE of it as a binary frame. */
|
|
99
106
|
send(text: string): void;
|
|
100
107
|
/** Send a close frame and end the socket. Idempotent. */
|
|
101
108
|
close(code: number, reason: string): void;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -16,8 +16,11 @@
|
|
|
16
16
|
* - `user-questions/request` is claimed the same way and published as
|
|
17
17
|
* `question.request` to the devices that declared `questions.v1`; their
|
|
18
18
|
* `question.answer` settles the host's own ask while it is open, or reaches a
|
|
19
|
-
* continued question through the host's Remote `answer`.
|
|
20
|
-
*
|
|
19
|
+
* continued question through the host's Remote `answer`. With no paired
|
|
20
|
+
* connection on the wire the claim is still made when a roster device registered
|
|
21
|
+
* for notifications, which is reached by the alert and holds the question for one
|
|
22
|
+
* window before it goes back to the host's chain (§11.3, §32). Every other case
|
|
23
|
+
* delegates, and a timed question keeps the Host's own deadline.
|
|
21
24
|
*
|
|
22
25
|
* The browser half lives in `src/client/` and is declared by `dsh.client`: one
|
|
23
26
|
* sidebar-foot panel that reads the same loopback-gated token route over a
|
|
@@ -33,8 +36,36 @@ export declare const name = "remote-bridge";
|
|
|
33
36
|
export declare const inject: string[];
|
|
34
37
|
/** Where the paired-device roster lives inside the DSH home. */
|
|
35
38
|
export declare const ROSTER_PATH = "remote-bridge/devices.json";
|
|
39
|
+
/** The environment variable that moves the offline claim window (§32.2). */
|
|
40
|
+
export declare const OFFLINE_CLAIM_TTL_ENV = "DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TTL_MS";
|
|
41
|
+
/**
|
|
42
|
+
* The offline claim window this process runs with.
|
|
43
|
+
*
|
|
44
|
+
* The window is the bridge's own constant and never a host fact, so a deployment
|
|
45
|
+
* moves it here. A value that is missing, unreadable or not positive falls back to
|
|
46
|
+
* the constant instead of closing the window: a zero window would silently switch
|
|
47
|
+
* the channel off, and an operator who wanted that would be turning off push.
|
|
48
|
+
* @param env - the process environment, injectable for a suite.
|
|
49
|
+
* @returns the window in milliseconds.
|
|
50
|
+
*/
|
|
51
|
+
export declare function offlineClaimTtl(env?: NodeJS.ProcessEnv): number;
|
|
36
52
|
/**
|
|
37
53
|
* Mount the bridge.
|
|
54
|
+
*
|
|
55
|
+
* Guarded by the family's single-instance rule: the aggregate row
|
|
56
|
+
* (`web-ui-remote-bridge`) and a standalone install of this same package can
|
|
57
|
+
* both be live in one profile, and the second mount would otherwise register
|
|
58
|
+
* `/ios/v1` and the token route a second time. Whichever source mounts first
|
|
59
|
+
* owns the package name; the other is queued and replayed when that owner
|
|
60
|
+
* disposes.
|
|
38
61
|
* @param ctx - the plugin's context, carrying the gateway and web server.
|
|
39
62
|
*/
|
|
40
|
-
|
|
63
|
+
declare function applyImpl(ctx: Context): void;
|
|
64
|
+
/**
|
|
65
|
+
* The plugin's mount point: {@link applyImpl} behind the family's
|
|
66
|
+
* single-instance guard. The name is the npm package identity, which every
|
|
67
|
+
* install source of this plugin shares — the aggregate's `web-ui-remote-bridge`
|
|
68
|
+
* row and the standalone `remote-bridge` row alike.
|
|
69
|
+
*/
|
|
70
|
+
export declare const apply: typeof applyImpl;
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host single-instance guard shared by the plugin family. The family bundle
|
|
3
|
+
* (dsh-web-all / dsh-skins) namespaces every child row id (web-ui-*), so
|
|
4
|
+
* the loader accepts a standalone install of the same package side by side;
|
|
5
|
+
* without this guard the second instance would still re-register the same
|
|
6
|
+
* webserver routes, tools, settings namespaces, and system-prompt sections
|
|
7
|
+
* and fail the boot. mountOnce makes a mount of an already-mounted package a
|
|
8
|
+
* no-op for as long as the first instance lives (the browser half is already
|
|
9
|
+
* deduped by package name in the client module host).
|
|
10
|
+
*
|
|
11
|
+
* A no-op is only safe while the holder is ALIVE. The holder can be disposed
|
|
12
|
+
* long after the refused mount ran its course: the Host reloads a profile by
|
|
13
|
+
* creating the new loader entries before the old ones are torn down (a
|
|
14
|
+
* plugin-manager enable/disable/install write, a settings-driven row reload,
|
|
15
|
+
* HMR), so the new aggregate shell entry mounts its family plugin while the
|
|
16
|
+
* previous entry still owns the name. Dropping that refused mount lost the
|
|
17
|
+
* plugin for good - the previous entry then disposed its own mount, releasing
|
|
18
|
+
* the name with nobody left to take it, and the family row stayed listed as
|
|
19
|
+
* active while its host routes 404ed (the task-board panel showed
|
|
20
|
+
* "board.hostError.notMounted", no degraded record appeared, and only a Host
|
|
21
|
+
* restart recovered it).
|
|
22
|
+
*
|
|
23
|
+
* The refused mount is therefore QUEUED, not dropped, and replayed the moment
|
|
24
|
+
* the holder releases the name - if the waiting fiber is still alive then. The
|
|
25
|
+
* single-instance guarantee is unchanged: exactly one mount is live per
|
|
26
|
+
* package name, and the replay re-enters the guard so a later mount still
|
|
27
|
+
* dedupes against it.
|
|
28
|
+
*
|
|
29
|
+
* The registry rides a global symbol so two module instances of the same
|
|
30
|
+
* package (npm copy vs repository link) still share one verdict. That symbol
|
|
31
|
+
* is a CROSS-REPOSITORY contract, not this file's private state: the four
|
|
32
|
+
* satellite packages (dsh-skins / dsh-pet / dsh-presets /
|
|
33
|
+
* dsh-community-plugins) are separate repositories carrying their own copy of
|
|
34
|
+
* this guard, rebuilt on their own schedule, so the value under `MOUNTED`
|
|
35
|
+
* must keep the shape every published copy reads (a `Set` of package names
|
|
36
|
+
* with `has`/`add`/`delete`). The wait queues this guard added therefore live
|
|
37
|
+
* under their own additive key, and the registry reads back a `Set` even when
|
|
38
|
+
* some other build left a different value there. Changing `MOUNTED`'s shape
|
|
39
|
+
* in place broke that contract once: a satellite's legacy copy created a
|
|
40
|
+
* `Set`, the family's new copy read it as a `Map`, and every family row
|
|
41
|
+
* mounted after it failed with "claims.get is not a function".
|
|
42
|
+
*
|
|
43
|
+
* cordis `ctx.effect` runs its callback immediately and treats the callback's
|
|
44
|
+
* return value as the fiber disposer, so the unmarker is returned, not run.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Wrap a cordis plugin apply so the package runs at most once per process.
|
|
48
|
+
* The first mount registers normally and releases the name when its fiber
|
|
49
|
+
* disposes; a mount refused while that name is held waits for the release and
|
|
50
|
+
* then runs, unless its own fiber disposes first.
|
|
51
|
+
* @param packageName - npm package identity shared by every install source.
|
|
52
|
+
* @param fn - the original plugin apply.
|
|
53
|
+
* @returns an apply of the same shape.
|
|
54
|
+
*/
|
|
55
|
+
export declare function mountOnce<T extends (...args: any[]) => unknown>(packageName: string, fn: T): T;
|
package/locale/en.json
ADDED
package/locale/ru.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-remote-bridge",
|
|
3
3
|
"description": "DSH remote bridge: the host half serves protocol v1 over one exact /ios/v1 WebSocket route — session roster, history baseline, prompting, live turn increments with tool activity, interrupt, and in-process agent approval — to a device paired by a one-shot bootstrap token and a P-256 challenge-response, with the token endpoint admitted only from this machine; the browser half adds one sidebar-foot panel that shows that same one-shot token as a QR symbol, and no wire surface",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.9",
|
|
5
|
+
"icon": "./icon.svg",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"engines": {
|
|
7
8
|
"node": "^22.19.0 || >=24.0.0"
|
|
@@ -18,6 +19,9 @@
|
|
|
18
19
|
"default": "./lib/client.js"
|
|
19
20
|
},
|
|
20
21
|
"./src/*": "./src/*",
|
|
22
|
+
"./locale/en.json": "./locale/en.json",
|
|
23
|
+
"./locale/ru.json": "./locale/ru.json",
|
|
24
|
+
"./locale/zh.json": "./locale/zh.json",
|
|
21
25
|
"./package.json": "./package.json"
|
|
22
26
|
},
|
|
23
27
|
"files": [
|
|
@@ -26,12 +30,14 @@
|
|
|
26
30
|
"lib/**/*.d.ts",
|
|
27
31
|
"lib/**/*.d.ts.map",
|
|
28
32
|
"src",
|
|
29
|
-
"cordis.patch.yml"
|
|
33
|
+
"cordis.patch.yml",
|
|
34
|
+
"icon.svg",
|
|
35
|
+
"locale"
|
|
30
36
|
],
|
|
31
37
|
"license": "Apache-2.0",
|
|
32
38
|
"dsh": {
|
|
33
39
|
"engines": {
|
|
34
|
-
"dsh": ">=0.2.1-rc.
|
|
40
|
+
"dsh": ">=0.2.1-rc.3"
|
|
35
41
|
},
|
|
36
42
|
"bundle": {
|
|
37
43
|
"patch": "./cordis.patch.yml"
|
|
@@ -49,22 +55,22 @@
|
|
|
49
55
|
"qrcode.react": "^4.2.0"
|
|
50
56
|
},
|
|
51
57
|
"peerDependencies": {
|
|
52
|
-
"@deepseek-ai/dsh": ">=0.2.1-rc.
|
|
58
|
+
"@deepseek-ai/dsh": ">=0.2.1-rc.3",
|
|
53
59
|
"react": "^18.2.0",
|
|
54
60
|
"react-dom": "^18.2.0"
|
|
55
61
|
},
|
|
56
62
|
"devDependencies": {
|
|
57
63
|
"@deepseek-ai/cordis": "^4.0.5",
|
|
58
|
-
"@deepseek-ai/dsh-api-gateway": "^0.2.1-rc.
|
|
59
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.1-rc.
|
|
60
|
-
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.1-rc.
|
|
61
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.1-rc.
|
|
62
|
-
"@deepseek-ai/dsh-client-ui-sidebar": "^0.2.1-rc.
|
|
63
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.
|
|
64
|
-
"@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.
|
|
65
|
-
"@deepseek-ai/dsh-session": "^0.2.1-rc.
|
|
66
|
-
"@deepseek-ai/dsh-typert-protocol": "^0.2.1-rc.
|
|
67
|
-
"@deepseek-ai/dsh-user-approval": "^0.2.1-rc.
|
|
64
|
+
"@deepseek-ai/dsh-api-gateway": "^0.2.1-rc.3",
|
|
65
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.1-rc.3",
|
|
66
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.1-rc.3",
|
|
67
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.1-rc.3",
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-sidebar": "^0.2.1-rc.3",
|
|
69
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.3",
|
|
70
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.3",
|
|
71
|
+
"@deepseek-ai/dsh-session": "^0.2.1-rc.3",
|
|
72
|
+
"@deepseek-ai/dsh-typert-protocol": "^0.2.1-rc.3",
|
|
73
|
+
"@deepseek-ai/dsh-user-approval": "^0.2.1-rc.3",
|
|
68
74
|
"@testing-library/dom": "^10.4.1",
|
|
69
75
|
"@testing-library/react": "^16.3.2",
|
|
70
76
|
"@types/node": "^22.20.0",
|
package/src/client/PairEntry.tsx
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
* (declared by ui-sidebar — the same seat dsh-remote-web-ui and dsh-update
|
|
6
6
|
* share).
|
|
7
7
|
*
|
|
8
|
-
* This component owns the panel's behavior: one read per open, one
|
|
9
|
-
* while a live code is on screen, the mint-again action,
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* This component owns the panel's presence and behavior: one read per open, one
|
|
9
|
+
* clock tick while a live code is on screen, the mint-again action, the copy
|
|
10
|
+
* action, and the leave leg that keeps the modal mounted until its exit reports
|
|
11
|
+
* completion. The wire call and the clipboard are injected (see the plugin
|
|
12
|
+
* entry), so the rendered tree carries no closure-factory bundle import and both
|
|
13
|
+
* can be driven by a test without patching a module.
|
|
13
14
|
*/
|
|
14
|
-
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
15
|
-
import { createPortal } from 'react-dom'
|
|
15
|
+
import { useCallback, useEffect, useId, useRef, useState } from 'react'
|
|
16
16
|
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
|
17
17
|
import { PairPanel, type PairCopyState, type PairPanelState } from './PairPanel.tsx'
|
|
18
18
|
import type { PairTokenOutcome } from './pair-token.ts'
|
|
@@ -24,6 +24,19 @@ import css from './panel.module.css'
|
|
|
24
24
|
const COPY_FEEDBACK_MS = 1_500
|
|
25
25
|
/** The countdown's tick; one second is the resolution the panel shows. */
|
|
26
26
|
const TICK_MS = 1_000
|
|
27
|
+
/**
|
|
28
|
+
* Upper bound on the leave leg. The card reports its own animation end, and the
|
|
29
|
+
* reduced-motion fade reports a transition end; this only ends the presence of a
|
|
30
|
+
* browser that reports neither, just past var(--ds-transition-duration).
|
|
31
|
+
*/
|
|
32
|
+
const EXIT_TIMEOUT_MS = 260
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The modal's presence. `closing` is a state of its own: the card stays mounted
|
|
36
|
+
* for its reverse exit and unmounts only when that exit reports completion,
|
|
37
|
+
* instead of disappearing on the same tick as the click.
|
|
38
|
+
*/
|
|
39
|
+
type Presence = 'closed' | 'open' | 'closing'
|
|
27
40
|
|
|
28
41
|
export type PairEntryProps = PropsLocale<'remote-bridge'> & {
|
|
29
42
|
/** Whether the sidebar renders wide content (false = 56px rail). */
|
|
@@ -53,15 +66,16 @@ function panelStateOf(outcome: PairTokenOutcome, issuedAt: number): PairPanelSta
|
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
/**
|
|
56
|
-
* Render the pairing seat trigger and,
|
|
69
|
+
* Render the pairing seat trigger and, while it is open or leaving, the panel.
|
|
57
70
|
* @param props - the footer seat's column state, the injected actions and the locale seat.
|
|
58
|
-
* @returns the trigger and the panel
|
|
71
|
+
* @returns the trigger and, when present, the official Modal holding the panel.
|
|
59
72
|
*/
|
|
60
73
|
export function PairEntry({ wide, read, copy, t }: PairEntryProps) {
|
|
61
|
-
const [
|
|
74
|
+
const [presence, setPresence] = useState<Presence>('closed')
|
|
62
75
|
const [state, setState] = useState<PairPanelState>({ kind: 'reading' })
|
|
63
76
|
const [copyState, setCopyState] = useState<PairCopyState>('idle')
|
|
64
77
|
const [now, setNow] = useState<number>(() => Date.now())
|
|
78
|
+
const panelId = useId()
|
|
65
79
|
// Generation counter: closing (or minting again) invalidates a read that is
|
|
66
80
|
// still in flight, so an answer that lands after the panel closed cannot
|
|
67
81
|
// resurrect a code nobody asked for.
|
|
@@ -79,20 +93,38 @@ export function PairEntry({ wide, read, copy, t }: PairEntryProps) {
|
|
|
79
93
|
}, [read])
|
|
80
94
|
|
|
81
95
|
const openPanel = useCallback((): void => {
|
|
82
|
-
|
|
96
|
+
setPresence('open')
|
|
83
97
|
setCopyState('idle')
|
|
84
98
|
mint()
|
|
85
99
|
}, [mint])
|
|
86
100
|
|
|
87
|
-
|
|
101
|
+
// Escape, the mask click, the focus trap and focus restoration belong to the
|
|
102
|
+
// official Modal; this only decides what closing means for the presence, and
|
|
103
|
+
// it invalidates a read that is still in flight.
|
|
104
|
+
const requestClose = useCallback((): void => {
|
|
88
105
|
generation.current += 1
|
|
89
|
-
|
|
106
|
+
setPresence((current) => (current === 'closed' ? 'closed' : 'closing'))
|
|
107
|
+
}, [])
|
|
108
|
+
|
|
109
|
+
const finishClose = useCallback((): void => {
|
|
110
|
+
setPresence((current) => (current === 'closing' ? 'closed' : current))
|
|
90
111
|
}, [])
|
|
91
112
|
|
|
113
|
+
const closing = presence === 'closing'
|
|
114
|
+
const showing = presence !== 'closed'
|
|
115
|
+
|
|
116
|
+
// Safety net for the leave leg: the card normally reports its own animation or
|
|
117
|
+
// transition end, and this bound covers the case where neither arrives.
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!closing) return
|
|
120
|
+
const timer = window.setTimeout(() => { finishClose() }, EXIT_TIMEOUT_MS)
|
|
121
|
+
return () => { window.clearTimeout(timer) }
|
|
122
|
+
}, [closing, finishClose])
|
|
123
|
+
|
|
92
124
|
// One ticker per live code; it clears itself at the deadline, so a panel left
|
|
93
125
|
// open on an expired code stops re-rendering instead of ticking forever.
|
|
94
126
|
useEffect(() => {
|
|
95
|
-
if (
|
|
127
|
+
if (presence !== 'open' || state.kind !== 'ready') return
|
|
96
128
|
const deadline = state.expiresAt
|
|
97
129
|
const timer = window.setInterval(() => {
|
|
98
130
|
const current = Date.now()
|
|
@@ -100,19 +132,10 @@ export function PairEntry({ wide, read, copy, t }: PairEntryProps) {
|
|
|
100
132
|
if (current >= deadline) window.clearInterval(timer)
|
|
101
133
|
}, TICK_MS)
|
|
102
134
|
return () => { window.clearInterval(timer) }
|
|
103
|
-
}, [
|
|
104
|
-
|
|
105
|
-
useEffect(() => {
|
|
106
|
-
if (!open) return
|
|
107
|
-
const onKey = (event: KeyboardEvent): void => {
|
|
108
|
-
if (event.key === 'Escape') closePanel()
|
|
109
|
-
}
|
|
110
|
-
window.addEventListener('keydown', onKey)
|
|
111
|
-
return () => { window.removeEventListener('keydown', onKey) }
|
|
112
|
-
}, [open, closePanel])
|
|
135
|
+
}, [presence, state])
|
|
113
136
|
|
|
114
|
-
const handleCopy = useCallback((
|
|
115
|
-
void copy(
|
|
137
|
+
const handleCopy = useCallback((payload: string): void => {
|
|
138
|
+
void copy(payload).then((ok) => {
|
|
116
139
|
setCopyState(ok ? 'copied' : 'failed')
|
|
117
140
|
window.setTimeout(() => { setCopyState('idle') }, COPY_FEEDBACK_MS)
|
|
118
141
|
})
|
|
@@ -127,24 +150,28 @@ export function PairEntry({ wide, read, copy, t }: PairEntryProps) {
|
|
|
127
150
|
data-dsh-part={PART_ENTRY}
|
|
128
151
|
data-wide={wide ? 'wide' : 'rail'}
|
|
129
152
|
aria-label={t('entry.label')}
|
|
130
|
-
aria-expanded={
|
|
153
|
+
aria-expanded={showing}
|
|
154
|
+
aria-controls={showing ? panelId : undefined}
|
|
131
155
|
title={t('entry.label')}
|
|
132
156
|
onClick={openPanel}
|
|
133
157
|
>
|
|
134
158
|
<QrIcon />
|
|
135
159
|
</button>
|
|
136
|
-
{
|
|
160
|
+
{showing && (
|
|
137
161
|
<PairPanel
|
|
162
|
+
id={panelId}
|
|
138
163
|
t={t}
|
|
139
164
|
state={state}
|
|
140
165
|
now={now}
|
|
141
166
|
host={window.location.host}
|
|
142
167
|
copy={copyState}
|
|
143
|
-
|
|
168
|
+
showing={showing}
|
|
169
|
+
closing={closing}
|
|
170
|
+
onClose={requestClose}
|
|
171
|
+
onExited={finishClose}
|
|
144
172
|
onRefresh={mint}
|
|
145
173
|
onCopy={handleCopy}
|
|
146
|
-
|
|
147
|
-
document.body,
|
|
174
|
+
/>
|
|
148
175
|
)}
|
|
149
176
|
</>
|
|
150
177
|
)
|