@linxin666/dsh-remote-bridge 0.4.8 → 0.4.10
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 +75 -18
- package/README.zh.md +74 -18
- package/lib/client.js +783 -260
- package/lib/client.js.map +1 -1
- package/lib/index.js +15849 -2913
- package/lib/types/client/PairEntry.d.ts +2 -2
- package/lib/types/client/PairPanel.d.ts +10 -2
- package/lib/types/client/UiPresentRow.d.ts +13 -0
- package/lib/types/client/icons.d.ts +5 -13
- package/lib/types/client/index.d.ts +4 -0
- package/lib/types/client/locales.d.ts +24 -15
- package/lib/types/client/semantic.d.ts +9 -5
- package/lib/types/client/toolview-slot.d.ts +68 -0
- package/lib/types/client/ui-card.d.ts +160 -0
- package/lib/types/core/commands.d.ts +59 -0
- package/lib/types/core/connection.d.ts +106 -0
- package/lib/types/core/devices.d.ts +102 -2
- package/lib/types/core/extension.d.ts +13 -0
- package/lib/types/core/hub.d.ts +129 -15
- package/lib/types/core/liveactivity.d.ts +324 -0
- package/lib/types/core/protocol.d.ts +328 -5
- package/lib/types/core/push.d.ts +186 -0
- package/lib/types/core/questions.d.ts +61 -9
- package/lib/types/core/session-meta.d.ts +55 -1
- package/lib/types/core/squads.d.ts +130 -0
- package/lib/types/core/turn-end-quiet.d.ts +135 -0
- package/lib/types/core/ui.d.ts +238 -0
- package/lib/types/core/usage-stats.d.ts +160 -0
- package/lib/types/core/usage.d.ts +294 -0
- package/lib/types/host/apns.d.ts +151 -0
- package/lib/types/host/squads-ledger.d.ts +39 -0
- package/lib/types/host/squads.d.ts +77 -0
- package/lib/types/host/ui-tools.d.ts +80 -0
- package/lib/types/host/usage-stats.d.ts +75 -0
- package/lib/types/host/watchers.d.ts +95 -0
- package/lib/types/index.d.ts +47 -3
- package/package.json +15 -14
- package/src/client/PairEntry.tsx +58 -31
- package/src/client/PairPanel.tsx +181 -97
- package/src/client/UiPresentRow.tsx +149 -0
- package/src/client/icons.tsx +17 -60
- package/src/client/index.ts +11 -0
- package/src/client/locales.ts +36 -24
- package/src/client/panel.module.css +239 -186
- package/src/client/semantic.ts +10 -6
- package/src/client/toolview-slot.ts +84 -0
- package/src/client/ui-card.ts +368 -0
- package/src/client/ui-present.module.css +87 -0
- package/src/core/commands.ts +95 -0
- package/src/core/connection.ts +811 -12
- package/src/core/devices.ts +337 -5
- package/src/core/extension.ts +20 -0
- package/src/core/hub.ts +518 -43
- package/src/core/liveactivity.ts +833 -0
- package/src/core/protocol.ts +370 -5
- package/src/core/push.ts +385 -0
- package/src/core/questions.ts +81 -10
- package/src/core/session-meta.ts +73 -1
- package/src/core/squads.ts +345 -0
- package/src/core/turn-end-quiet.ts +388 -0
- package/src/core/ui.ts +398 -0
- package/src/core/usage-stats.ts +424 -0
- package/src/core/usage.ts +937 -0
- package/src/core/wire.ts +8 -0
- package/src/host/apns.ts +320 -0
- package/src/host/squads-ledger.ts +105 -0
- package/src/host/squads.ts +206 -0
- package/src/host/ui-tools.ts +233 -0
- package/src/host/usage-stats.ts +155 -0
- package/src/host/watchers.ts +296 -0
- package/src/index.ts +327 -10
|
@@ -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,95 @@
|
|
|
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 { TurnEndQuietGate } from '../core/turn-end-quiet.ts';
|
|
41
|
+
import { type BridgeGateway, type GatewayPeer } from '../core/wire.ts';
|
|
42
|
+
/** Most standing streams this bridge keeps open at once. */
|
|
43
|
+
export declare const WATCHER_LIMIT = 64;
|
|
44
|
+
/** How long a watcher waits before re-opening a stream that ended on its own. */
|
|
45
|
+
export declare const WATCHER_REOPEN_MS = 1000;
|
|
46
|
+
export interface StandingWatcherOptions {
|
|
47
|
+
/** The host's gateway, the same one the connections speak through. */
|
|
48
|
+
readonly gateway: BridgeGateway;
|
|
49
|
+
/** The in-process owner peer every call of this bridge speaks for. */
|
|
50
|
+
readonly peer: GatewayPeer;
|
|
51
|
+
/**
|
|
52
|
+
* Sessions that currently hold at least one registered live-activity token,
|
|
53
|
+
* read from the roster on every reconcile.
|
|
54
|
+
*/
|
|
55
|
+
readonly sessions: () => readonly string[];
|
|
56
|
+
/** The card path of §29; absent is a bridge with no signing key. */
|
|
57
|
+
readonly liveActivity?: LiveActivityNotifier;
|
|
58
|
+
/** The notification path of §28; absent for the same reason. */
|
|
59
|
+
readonly push?: PushNotifier;
|
|
60
|
+
/**
|
|
61
|
+
* The gate both channels announce a finished turn through, so a card and a
|
|
62
|
+
* notification wait for the same quiet session. Absent is a watcher set built
|
|
63
|
+
* without one — a suite — and then both report at the frame.
|
|
64
|
+
*/
|
|
65
|
+
readonly turnEndQuiet?: TurnEndQuietGate;
|
|
66
|
+
readonly log: (message: string) => void;
|
|
67
|
+
readonly limit?: number;
|
|
68
|
+
readonly reopenMs?: number;
|
|
69
|
+
readonly maxMessages?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The bridge's stand-in for a client that is no longer there.
|
|
73
|
+
*
|
|
74
|
+
* Deliberately inert when neither push path is configured: {@link sync} returns
|
|
75
|
+
* without opening anything, so a bridge without an Apple signing key keeps the
|
|
76
|
+
* exact stream count it had before this module existed.
|
|
77
|
+
*/
|
|
78
|
+
export declare class StandingWatchers {
|
|
79
|
+
#private;
|
|
80
|
+
constructor(options: StandingWatcherOptions);
|
|
81
|
+
/** @returns how many standing streams are open right now. */
|
|
82
|
+
get size(): number;
|
|
83
|
+
/** @returns whether this bridge has any path worth opening a stream for. */
|
|
84
|
+
get enabled(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Reconcile the open streams with the sessions that hold a card right now.
|
|
87
|
+
*
|
|
88
|
+
* Called when the roster changes (a registration arrived, a dead token was
|
|
89
|
+
* retired) and when a stream ends. Idempotent, and safe to call before the
|
|
90
|
+
* roster has been read: no session with a token means nothing to watch.
|
|
91
|
+
*/
|
|
92
|
+
sync(): void;
|
|
93
|
+
/** Close every stream and drop every pending re-arm. Idempotent. */
|
|
94
|
+
dispose(): void;
|
|
95
|
+
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,11 +13,20 @@
|
|
|
13
13
|
* - `approval/request` is claimed in-process while a paired device is connected,
|
|
14
14
|
* and delegated (`next()`) in every other case, which the Host normalizes to
|
|
15
15
|
* the fail-closed `'unavailable'`.
|
|
16
|
+
* - `ui.present` is this bridge's own model tool (protocol §35): one whole
|
|
17
|
+
* self-contained page is announced as `ui.request` to the paired clients that
|
|
18
|
+
* declared `ui.v1`, and the user's first action inside it comes back as that
|
|
19
|
+
* tool call's result. `ui.event` settles it, `ui.list` reads the cards still
|
|
20
|
+
* held. No paired client that declared the channel means the call answers
|
|
21
|
+
* `unavailable` at once instead of holding the agent.
|
|
16
22
|
* - `user-questions/request` is claimed the same way and published as
|
|
17
23
|
* `question.request` to the devices that declared `questions.v1`; their
|
|
18
24
|
* `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
|
-
*
|
|
25
|
+
* continued question through the host's Remote `answer`. With no paired
|
|
26
|
+
* connection on the wire the claim is still made when a roster device registered
|
|
27
|
+
* for notifications, which is reached by the alert and holds the question for one
|
|
28
|
+
* window before it goes back to the host's chain (§11.3, §32). Every other case
|
|
29
|
+
* delegates, and a timed question keeps the Host's own deadline.
|
|
21
30
|
*
|
|
22
31
|
* The browser half lives in `src/client/` and is declared by `dsh.client`: one
|
|
23
32
|
* sidebar-foot panel that reads the same loopback-gated token route over a
|
|
@@ -29,10 +38,45 @@
|
|
|
29
38
|
import type { Context } from '@deepseek-ai/cordis';
|
|
30
39
|
/** Loader row identity of this plugin. */
|
|
31
40
|
export declare const name = "remote-bridge";
|
|
32
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The Host services this plugin cannot run without.
|
|
43
|
+
*
|
|
44
|
+
* `tools` is what protocol §35 added: this bridge contributes one model tool of
|
|
45
|
+
* its own (`ui.present`), so a host that composes no tool registry is a host where
|
|
46
|
+
* the card channel has no caller — the row simply does not mount here.
|
|
47
|
+
*/
|
|
33
48
|
export declare const inject: string[];
|
|
34
49
|
/** Where the paired-device roster lives inside the DSH home. */
|
|
35
50
|
export declare const ROSTER_PATH = "remote-bridge/devices.json";
|
|
51
|
+
/** The environment variable that moves the offline claim window (§32.2). */
|
|
52
|
+
export declare const OFFLINE_CLAIM_TTL_ENV = "DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TTL_MS";
|
|
53
|
+
/**
|
|
54
|
+
* The offline claim window this process runs with.
|
|
55
|
+
*
|
|
56
|
+
* The window is the bridge's own constant and never a host fact, so a deployment
|
|
57
|
+
* moves it here. A value that is missing, unreadable or not positive falls back to
|
|
58
|
+
* the constant instead of closing the window: a zero window would silently switch
|
|
59
|
+
* the channel off, and an operator who wanted that would be turning off push.
|
|
60
|
+
* @param env - the process environment, injectable for a suite.
|
|
61
|
+
* @returns the window in milliseconds.
|
|
62
|
+
*/
|
|
63
|
+
export declare function offlineClaimTtl(env?: NodeJS.ProcessEnv): number;
|
|
64
|
+
/** The environment variable that moves how long a finished turn waits for its session to go quiet (§28). */
|
|
65
|
+
export declare const TURN_END_QUIET_MAX_ENV = "DSH_REMOTE_BRIDGE_TURN_END_QUIET_MAX_MS";
|
|
66
|
+
/**
|
|
67
|
+
* The quiet-wait budget this process runs with.
|
|
68
|
+
*
|
|
69
|
+
* The budget is the bridge's own constant and never a host fact, so a deployment
|
|
70
|
+
* moves it here. A value that is missing, unreadable or not positive falls back to
|
|
71
|
+
* the constant instead of closing the window: a zero budget would announce every
|
|
72
|
+
* turn end at its frame, and an operator who wanted that would be turning push
|
|
73
|
+
* off. The budget only bounds the wait — a session that does fall quiet inside it
|
|
74
|
+
* is announced then, and one that does not is announced at the end with the
|
|
75
|
+
* reason it was still busy.
|
|
76
|
+
* @param env - the process environment, injectable for a suite.
|
|
77
|
+
* @returns the budget in milliseconds.
|
|
78
|
+
*/
|
|
79
|
+
export declare function turnEndQuietMaxWait(env?: NodeJS.ProcessEnv): number;
|
|
36
80
|
/**
|
|
37
81
|
* Mount the bridge.
|
|
38
82
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-remote-bridge",
|
|
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.
|
|
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 draws an interactive card inside the tool row without answering it, and adds no wire surface",
|
|
4
|
+
"version": "0.4.10",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"license": "Apache-2.0",
|
|
38
38
|
"dsh": {
|
|
39
39
|
"engines": {
|
|
40
|
-
"dsh": ">=0.2.1-rc.
|
|
40
|
+
"dsh": ">=0.2.1-rc.3"
|
|
41
41
|
},
|
|
42
42
|
"bundle": {
|
|
43
43
|
"patch": "./cordis.patch.yml"
|
|
@@ -55,22 +55,23 @@
|
|
|
55
55
|
"qrcode.react": "^4.2.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@deepseek-ai/dsh": ">=0.2.1-rc.
|
|
58
|
+
"@deepseek-ai/dsh": ">=0.2.1-rc.3",
|
|
59
59
|
"react": "^18.2.0",
|
|
60
60
|
"react-dom": "^18.2.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@deepseek-ai/cordis": "^4.0.5",
|
|
64
|
-
"@deepseek-ai/dsh-api-gateway": "^0.2.1-rc.
|
|
65
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.1-rc.
|
|
66
|
-
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.1-rc.
|
|
67
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.1-rc.
|
|
68
|
-
"@deepseek-ai/dsh-client-ui-sidebar": "^0.2.1-rc.
|
|
69
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.
|
|
70
|
-
"@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.
|
|
71
|
-
"@deepseek-ai/dsh-session": "^0.2.1-rc.
|
|
72
|
-
"@deepseek-ai/dsh-
|
|
73
|
-
"@deepseek-ai/dsh-
|
|
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-tools": "^0.2.1-rc.3",
|
|
73
|
+
"@deepseek-ai/dsh-typert-protocol": "^0.2.1-rc.3",
|
|
74
|
+
"@deepseek-ai/dsh-user-approval": "^0.2.1-rc.3",
|
|
74
75
|
"@testing-library/dom": "^10.4.1",
|
|
75
76
|
"@testing-library/react": "^16.3.2",
|
|
76
77
|
"@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
|
)
|