@linxin666/dsh-remote-bridge 0.4.9 → 0.4.11
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 +28 -4
- package/README.zh.md +27 -4
- package/lib/client.js +511 -9
- package/lib/client.js.map +1 -1
- package/lib/index.js +8671 -148
- package/lib/types/client/UiPresentRow.d.ts +13 -0
- package/lib/types/client/index.d.ts +4 -0
- package/lib/types/client/locales.d.ts +15 -2
- package/lib/types/client/toolview-slot.d.ts +68 -0
- package/lib/types/client/ui-card.d.ts +160 -0
- package/lib/types/core/connection.d.ts +38 -0
- package/lib/types/core/devices.d.ts +4 -0
- package/lib/types/core/extension.d.ts +13 -0
- package/lib/types/core/hub.d.ts +64 -0
- package/lib/types/core/protocol.d.ts +71 -7
- package/lib/types/core/push.d.ts +10 -2
- package/lib/types/core/turn-end-quiet.d.ts +135 -0
- package/lib/types/core/ui.d.ts +238 -0
- package/lib/types/host/ui-tools.d.ts +80 -0
- package/lib/types/host/watchers.d.ts +7 -0
- package/lib/types/index.d.ts +29 -1
- package/package.json +3 -2
- package/src/client/UiPresentRow.tsx +149 -0
- package/src/client/index.ts +11 -0
- package/src/client/locales.ts +22 -2
- 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/connection.ts +169 -6
- package/src/core/devices.ts +116 -2
- package/src/core/extension.ts +20 -0
- package/src/core/hub.ts +156 -1
- package/src/core/protocol.ts +78 -6
- package/src/core/push.ts +34 -3
- package/src/core/turn-end-quiet.ts +388 -0
- package/src/core/ui.ts +398 -0
- package/src/host/ui-tools.ts +233 -0
- package/src/host/watchers.ts +27 -3
- package/src/index.ts +70 -2
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When a finished turn may be announced: after the session it belongs to falls
|
|
3
|
+
* quiet, not when the frame arrives.
|
|
4
|
+
*
|
|
5
|
+
* A `turn/end` increment is a fact about one turn and nothing more. The work the
|
|
6
|
+
* user started with it may still be going: the child sessions it delegated to and
|
|
7
|
+
* the background jobs the host still holds under those sessions outlive the turn
|
|
8
|
+
* that started them. A phone told "turn finished" at the frame wakes on a session
|
|
9
|
+
* the roster still badges as running, reads a card that says ended while the work
|
|
10
|
+
* goes on, and is told again by a second turn end it never asked for. §28's
|
|
11
|
+
* notification and §29's card answer the same question — "is this session working
|
|
12
|
+
* right now" — and that question has one answer, the one the client already
|
|
13
|
+
* computes in `SessionRun`: the host's own `agentRunning` for the session, any
|
|
14
|
+
* descendant session still running, and any job the host attributes to either.
|
|
15
|
+
*
|
|
16
|
+
* So a turn end is registered here instead of sent, and sent once the host says
|
|
17
|
+
* the session is quiet. Three rules hold that together:
|
|
18
|
+
*
|
|
19
|
+
* - the answer comes from the host and nowhere else: one `session/list` read for
|
|
20
|
+
* the running flag and the parent chain, and the host's job registry for the
|
|
21
|
+
* jobs it attributes to a session. This module invents no timer-based guess and
|
|
22
|
+
* reads no client state, because a guess that says "quiet" is a lock screen
|
|
23
|
+
* saying the work finished when it did not;
|
|
24
|
+
* - nothing on the frame path waits: a registration stores five fields and arms a
|
|
25
|
+
* timer, so a follow stream still publishes its increment at the speed it did
|
|
26
|
+
* before;
|
|
27
|
+
* - the wait is bounded. At {@link TURN_END_QUIET_MAX_MS} the announcement goes
|
|
28
|
+
* out anyway and the line it logs names what was still going, because a
|
|
29
|
+
* notification that never arrives is the failure this channel exists to prevent.
|
|
30
|
+
* @module dsh-remote-bridge/core/turn-end-quiet
|
|
31
|
+
*/
|
|
32
|
+
import type { JobRoster } from './jobs.ts';
|
|
33
|
+
import type { LiveActivityNotifier } from './liveactivity.ts';
|
|
34
|
+
import { type PushNotifier } from './push.ts';
|
|
35
|
+
import { type BridgeGateway, type GatewayPeer } from './wire.ts';
|
|
36
|
+
/** Longest a registered turn end waits for its session to fall quiet, in milliseconds. */
|
|
37
|
+
export declare const TURN_END_QUIET_MAX_MS = 600000;
|
|
38
|
+
/**
|
|
39
|
+
* How long a held turn end waits before asking the host again, in milliseconds.
|
|
40
|
+
*
|
|
41
|
+
* A turn end usually finds its session already quiet — the host clears the flag
|
|
42
|
+
* as the turn finishes — so the first question is the one that matters, and five
|
|
43
|
+
* seconds is short enough that the notification a user waits for is not visibly
|
|
44
|
+
* late. The interval is also what bounds how many questions one held turn end can
|
|
45
|
+
* cost: at most one every five seconds, never more than one in flight.
|
|
46
|
+
*/
|
|
47
|
+
export declare const TURN_END_QUIET_INTERVAL_MS = 5000;
|
|
48
|
+
/** The host's answer about the work one session still holds. */
|
|
49
|
+
export interface QuietAnswer {
|
|
50
|
+
/** Whether nothing under this session is still going. */
|
|
51
|
+
readonly quiet: boolean;
|
|
52
|
+
/** What was still going when it was not, in one token for the log line. */
|
|
53
|
+
readonly busy?: string;
|
|
54
|
+
}
|
|
55
|
+
/** Whether one session is quiet right now, as the host answers it. */
|
|
56
|
+
export type QuietProbe = (sessionId: string) => Promise<QuietAnswer>;
|
|
57
|
+
export interface TurnEndQuietOptions {
|
|
58
|
+
/** The notification path of §28; absent is a bridge that sends no notification. */
|
|
59
|
+
readonly push?: PushNotifier;
|
|
60
|
+
/** The card path of §29; absent for the same reason. */
|
|
61
|
+
readonly liveActivity?: LiveActivityNotifier;
|
|
62
|
+
/**
|
|
63
|
+
* The host's own answer, asked off the frame path.
|
|
64
|
+
*
|
|
65
|
+
* Absent is a bridge assembled without one, which cannot tell a quiet session
|
|
66
|
+
* from a busy one and therefore reports at the frame rather than holding
|
|
67
|
+
* anything back.
|
|
68
|
+
*/
|
|
69
|
+
readonly probe?: QuietProbe;
|
|
70
|
+
readonly now?: () => number;
|
|
71
|
+
readonly log?: (message: string) => void;
|
|
72
|
+
/** The wait budget; the default is {@link TURN_END_QUIET_MAX_MS}, and a deployment moves it. */
|
|
73
|
+
readonly maxWaitMs?: number;
|
|
74
|
+
/** The re-check interval; the default is {@link TURN_END_QUIET_INTERVAL_MS}. */
|
|
75
|
+
readonly intervalMs?: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The bridge's outbound turn-end path: registration now, announcement when quiet.
|
|
79
|
+
*
|
|
80
|
+
* Deliberately inert when neither channel can send: {@link enabled} is false, no
|
|
81
|
+
* entry is stored and no timer is armed, so a bridge without an Apple signing key
|
|
82
|
+
* behaves — byte for byte, frame for frame — exactly as it did before this module
|
|
83
|
+
* existed, and no host call is ever made on its behalf.
|
|
84
|
+
*/
|
|
85
|
+
export declare class TurnEndQuietGate {
|
|
86
|
+
#private;
|
|
87
|
+
constructor(options: TurnEndQuietOptions);
|
|
88
|
+
/** @returns whether either channel can send, which is the only case a turn end is held at all. */
|
|
89
|
+
get enabled(): boolean;
|
|
90
|
+
/** @returns how many turn ends are held right now. */
|
|
91
|
+
get held(): number;
|
|
92
|
+
/**
|
|
93
|
+
* Hold one finished turn until its session is quiet, then announce it.
|
|
94
|
+
*
|
|
95
|
+
* Returns at once and never awaits a host read: the caller is a follow stream
|
|
96
|
+
* that has already published its increment.
|
|
97
|
+
* @param sessionId - the session the turn belonged to.
|
|
98
|
+
* @param reason - the host's own reason for ending it.
|
|
99
|
+
*/
|
|
100
|
+
noteTurnEnd(sessionId: string, reason: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Drop a held turn end because another turn is on.
|
|
103
|
+
*
|
|
104
|
+
* A caller reports this from the evidence it actually has — an increment for the
|
|
105
|
+
* session that is not a turn end — so a turn the bridge cannot see costs the user
|
|
106
|
+
* nothing: the held end is still announced, and the turn that is really running
|
|
107
|
+
* ends with its own report.
|
|
108
|
+
* @param sessionId - the session that started working again.
|
|
109
|
+
*/
|
|
110
|
+
noteTurnStarted(sessionId: string): void;
|
|
111
|
+
/** Drop every held turn end and every timer. Idempotent. */
|
|
112
|
+
dispose(): void;
|
|
113
|
+
}
|
|
114
|
+
/** What {@link sessionQuietProbe} reads the host through. */
|
|
115
|
+
export interface SessionQuietProbeOptions {
|
|
116
|
+
/** The host's gateway, the same one every connection speaks through. */
|
|
117
|
+
readonly gateway: BridgeGateway;
|
|
118
|
+
/** The in-process owner peer every call of this bridge speaks for. */
|
|
119
|
+
readonly peer: GatewayPeer;
|
|
120
|
+
/** The host's job registry, read for the jobs it attributes to a session. */
|
|
121
|
+
readonly jobs: JobRoster;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The host's answer to "is this session quiet", built from its own two facts.
|
|
125
|
+
*
|
|
126
|
+
* The session list is where the running flag and the parent chain come from, and
|
|
127
|
+
* the job registry is where a job's owner and status come from; neither is
|
|
128
|
+
* captured once, because both move while a held turn end waits. A read that cannot
|
|
129
|
+
* be made is thrown rather than answered as quiet: "the host did not answer" and
|
|
130
|
+
* "nothing is running" are different facts, and the caller retries the one and
|
|
131
|
+
* announces the other.
|
|
132
|
+
* @param options - the faces the answer is read through.
|
|
133
|
+
* @returns the probe the gate asks.
|
|
134
|
+
*/
|
|
135
|
+
export declare function sessionQuietProbe(options: SessionQuietProbeOptions): QuietProbe;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge's claims on `ui.request` (§35): which self-contained pages a phone
|
|
3
|
+
* or the desktop may show, and the one path a user's action travels back into the
|
|
4
|
+
* tool call that presented it.
|
|
5
|
+
*
|
|
6
|
+
* A card belongs to exactly one tool call and ends at the user's FIRST action:
|
|
7
|
+
* the first `ui.event` settles it and becomes that call's result, so a card that
|
|
8
|
+
* should keep taking actions is a second presentation rather than a second event
|
|
9
|
+
* (§35.3, §35.8). Every claim is one record keyed by the call id published on the
|
|
10
|
+
* wire, so an event that arrives late still lands, and one naming a call id this
|
|
11
|
+
* bridge never claimed is refused instead of being handed to a tool that is not
|
|
12
|
+
* waiting for it.
|
|
13
|
+
*
|
|
14
|
+
* The bridge invents no deadline: the tool schema declares no `timeout`, so a
|
|
15
|
+
* card carries no `expiresAt` and stays open until the user acts, the agent's own
|
|
16
|
+
* turn is cancelled, or the last paired device has been gone long enough for the
|
|
17
|
+
* hub's grace window (§35.5). It also fabricates no event: a card nobody answered
|
|
18
|
+
* is released as a refusal, never as a decision the operator did not make.
|
|
19
|
+
*
|
|
20
|
+
* Both caps are enforced on this side rather than the client's (§35.2, §35.3): a
|
|
21
|
+
* client that refused an oversized page would leave the agent waiting for a card
|
|
22
|
+
* that never comes, so the call is refused as `invalid-args` before any frame is
|
|
23
|
+
* written.
|
|
24
|
+
* @module dsh-remote-bridge/core/ui
|
|
25
|
+
*/
|
|
26
|
+
/** Upper bound of one card's document, in UTF-8 bytes (§35.2). */
|
|
27
|
+
export declare const UI_HTML_MAX_BYTES = 262144;
|
|
28
|
+
/** Upper bound of one `ui.event` payload, in UTF-8 bytes (§35.3). */
|
|
29
|
+
export declare const UI_PAYLOAD_MAX_BYTES = 8192;
|
|
30
|
+
/**
|
|
31
|
+
* How many settled call ids this bridge remembers, so a repeated tap is answered
|
|
32
|
+
* `ui-settled` instead of `ui-unknown` (§35.3).
|
|
33
|
+
*
|
|
34
|
+
* The promise is already settled and the card is already gone by then; the only
|
|
35
|
+
* reason to remember the id is that a client which tapped twice must be able to
|
|
36
|
+
* tell "already done" from "never mine". A phone holds no more live cards than it
|
|
37
|
+
* rendered, so the bound costs one short string per presentation and never grows
|
|
38
|
+
* with the process's uptime.
|
|
39
|
+
*/
|
|
40
|
+
export declare const UI_SETTLED_MEMORY = 256;
|
|
41
|
+
/** Whether a card still holds the tool call, or is only a notice now. */
|
|
42
|
+
export type UiState = 'open' | 'settled';
|
|
43
|
+
/** One lossless JSON value, as the wire carries it inside an event payload. */
|
|
44
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
45
|
+
[key: string]: JsonValue;
|
|
46
|
+
};
|
|
47
|
+
/** The action a user took inside one card, in the presenter's own closed set. */
|
|
48
|
+
export interface UiEvent {
|
|
49
|
+
readonly type: string;
|
|
50
|
+
readonly payload?: JsonValue;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The `ui.request` payload for one claim, and the `payload` of every `ui.list`
|
|
54
|
+
* entry.
|
|
55
|
+
*
|
|
56
|
+
* One function for both so the card a client was handed and the card it reads back
|
|
57
|
+
* out of a list cannot drift apart: an absent `title` or `height` is an absent key
|
|
58
|
+
* rather than an empty or null one, exactly as §35.2 froze it. `expiresAt` is never
|
|
59
|
+
* written: a presentation whose tool schema declares no `timeout` has no deadline
|
|
60
|
+
* to publish, and a published one would be a promise this bridge does not keep.
|
|
61
|
+
* @param state - whether the card still holds the tool call.
|
|
62
|
+
* @param card - the claim being published.
|
|
63
|
+
* @returns the frozen payload body.
|
|
64
|
+
*/
|
|
65
|
+
export declare function uiPayload(state: UiState, card: UiCardView): UiRequestPayload;
|
|
66
|
+
/**
|
|
67
|
+
* The identity a client knows one card by (`"<sessionId>/<callId>"`, §35.4).
|
|
68
|
+
*
|
|
69
|
+
* The same pair a `ui.list` row carries, so the card a tool presented and the row
|
|
70
|
+
* a client reconciles it against are compared as one name instead of two fields
|
|
71
|
+
* that could be recombined differently on each side.
|
|
72
|
+
* @param sessionId - the session whose agent presented the card.
|
|
73
|
+
* @param callId - the tool call id it is held under.
|
|
74
|
+
* @returns the card key.
|
|
75
|
+
*/
|
|
76
|
+
export declare function uiKey(sessionId: string, callId: string): string;
|
|
77
|
+
/** @returns whether one card document is within {@link UI_HTML_MAX_BYTES}. */
|
|
78
|
+
export declare function uiHtmlFits(html: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Read one `ui.event` body out of a decoded frame.
|
|
81
|
+
*
|
|
82
|
+
* The event's `type` is the presenter's own closed set: this bridge carries it and
|
|
83
|
+
* never interprets the value, so the only shape it enforces is the one the frame
|
|
84
|
+
* declares (§35.3). An absent and an explicit `null` payload are different
|
|
85
|
+
* things — the payload key is kept exactly when the client sent one.
|
|
86
|
+
* @param raw - the `event` field as it crossed the wire.
|
|
87
|
+
* @returns the event, or undefined when the frame is not one.
|
|
88
|
+
*/
|
|
89
|
+
export declare function uiEventOf(raw: unknown): UiEvent | undefined;
|
|
90
|
+
/** @returns whether one event's payload is within {@link UI_PAYLOAD_MAX_BYTES}. */
|
|
91
|
+
export declare function uiEventFits(event: UiEvent): boolean;
|
|
92
|
+
/** One card this bridge still holds, as `ui.list` publishes it (§35.4). */
|
|
93
|
+
export interface ListedCard {
|
|
94
|
+
/** {@link uiKey}: the identity the client holds it under. */
|
|
95
|
+
readonly key: string;
|
|
96
|
+
readonly sessionId: string;
|
|
97
|
+
/** `open` or `settled`; a settled card is not held and never listed. */
|
|
98
|
+
readonly state: UiState;
|
|
99
|
+
/** The `ui.request` payload, byte for byte the shape §35.2 froze. */
|
|
100
|
+
readonly payload: UiRequestPayload;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The body of one `ui.list` answer.
|
|
104
|
+
*
|
|
105
|
+
* `complete` is what a client is allowed to act on: only a COMPLETE list may
|
|
106
|
+
* retire a card it does not carry (§35.5, §24.3), so a bridge that could answer
|
|
107
|
+
* only part of the set must say `false` rather than let the difference read as
|
|
108
|
+
* "the card is over".
|
|
109
|
+
*/
|
|
110
|
+
export interface UiListPayload {
|
|
111
|
+
readonly cards: readonly ListedCard[];
|
|
112
|
+
readonly complete: boolean;
|
|
113
|
+
}
|
|
114
|
+
/** `ui.request`'s payload, as §35.2 froze it. */
|
|
115
|
+
export interface UiRequestPayload {
|
|
116
|
+
readonly sessionId: string;
|
|
117
|
+
readonly callId: string;
|
|
118
|
+
readonly state: UiState;
|
|
119
|
+
/** One header line; absent when the presenter named none. */
|
|
120
|
+
readonly title?: string;
|
|
121
|
+
/** A whole self-contained document, `<!doctype html>` first, within {@link UI_HTML_MAX_BYTES}. */
|
|
122
|
+
readonly html: string;
|
|
123
|
+
/** The presenter's suggested initial height in points; the client still measures. */
|
|
124
|
+
readonly height?: number;
|
|
125
|
+
/**
|
|
126
|
+
* Epoch milliseconds of this bridge's own deadline for the card; absent, always,
|
|
127
|
+
* for a presentation whose tool schema declares no `timeout` (§35.2).
|
|
128
|
+
*/
|
|
129
|
+
readonly expiresAt?: number;
|
|
130
|
+
}
|
|
131
|
+
/** The identity and content of one claim, as the hub publishes it. */
|
|
132
|
+
export interface UiCardView {
|
|
133
|
+
readonly sessionId: string;
|
|
134
|
+
readonly callId: string;
|
|
135
|
+
readonly html: string;
|
|
136
|
+
readonly title?: string;
|
|
137
|
+
readonly height?: number;
|
|
138
|
+
}
|
|
139
|
+
/** Why one presentation ended without a user action, in the wire's own vocabulary. */
|
|
140
|
+
export type UiRefusalReason = 'unavailable' | 'invalid-args' | 'timeout' | 'cancelled';
|
|
141
|
+
/** What one presentation ended as: the user's action, or the refusal to wait for one. */
|
|
142
|
+
export type UiPresentOutcome = {
|
|
143
|
+
readonly ok: true;
|
|
144
|
+
readonly type: string;
|
|
145
|
+
readonly payload?: JsonValue;
|
|
146
|
+
} | {
|
|
147
|
+
readonly ok: false;
|
|
148
|
+
readonly reason: UiRefusalReason;
|
|
149
|
+
};
|
|
150
|
+
/** What one `ui.event` produced: acknowledgement, or the refusal to accept it. */
|
|
151
|
+
export type UiEventReply = {
|
|
152
|
+
readonly ok: true;
|
|
153
|
+
} | {
|
|
154
|
+
readonly ok: false;
|
|
155
|
+
readonly code: string;
|
|
156
|
+
readonly msg: string;
|
|
157
|
+
};
|
|
158
|
+
export interface OpenCardInput {
|
|
159
|
+
readonly sessionId: string;
|
|
160
|
+
/** The id published on the wire, which is the host's own `ToolCallId`. */
|
|
161
|
+
readonly callId: string;
|
|
162
|
+
readonly html: string;
|
|
163
|
+
readonly title?: string;
|
|
164
|
+
readonly height?: number;
|
|
165
|
+
/** The agent's own cancellation lifetime for this call. */
|
|
166
|
+
readonly signal?: AbortSignal;
|
|
167
|
+
/**
|
|
168
|
+
* Called when the card leaves this bridge — the user's event, the grace window,
|
|
169
|
+
* a cancelled turn, the bridge unloading. The client still holds a card for it
|
|
170
|
+
* and has to be told, or it keeps showing a page whose actions go nowhere.
|
|
171
|
+
*/
|
|
172
|
+
readonly onSettled?: (card: UiCardView) => void;
|
|
173
|
+
}
|
|
174
|
+
/** The presentation one `ui_present` call is waiting on, as the hub publishes it. */
|
|
175
|
+
export interface ClaimedCard extends UiCardView {
|
|
176
|
+
/** The user's action, or the refusal that ended the card. Never rejects. */
|
|
177
|
+
readonly outcome: Promise<UiPresentOutcome>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Pending cards of one bridge process.
|
|
181
|
+
*
|
|
182
|
+
* One record per call id published on the wire and one settle for every path
|
|
183
|
+
* (the user's event, the agent's cancellation, the grace window, bridge unload),
|
|
184
|
+
* so a card can never be settled twice and a released claim leaves no abort
|
|
185
|
+
* listener behind.
|
|
186
|
+
*/
|
|
187
|
+
export declare class UiCards {
|
|
188
|
+
#private;
|
|
189
|
+
/** @returns how many cards this bridge currently holds. */
|
|
190
|
+
get size(): number;
|
|
191
|
+
/**
|
|
192
|
+
* @param callId - one wire call id.
|
|
193
|
+
* @returns `open` while it holds a tool call, `settled` once a user's event
|
|
194
|
+
* settled it, and undefined when this bridge never claimed it — which is how a
|
|
195
|
+
* listener tells `ui-settled` from `ui-unknown` (§35.3).
|
|
196
|
+
*/
|
|
197
|
+
stateOf(callId: string): UiState | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Claim one card.
|
|
200
|
+
* @param input - session identity, wire call id, the page, and the host's lifetime.
|
|
201
|
+
* @returns the claim the hub publishes, or undefined when there is nothing to publish.
|
|
202
|
+
*/
|
|
203
|
+
open(input: OpenCardInput): ClaimedCard | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Settle one card from the client's first event (§35.3).
|
|
206
|
+
*
|
|
207
|
+
* The event is the tool call's result and its only result: the card leaves the
|
|
208
|
+
* held table in the same step, so a second event finds it settled rather than
|
|
209
|
+
* settling the call twice.
|
|
210
|
+
* @param sessionId - the session the client believes owns the card.
|
|
211
|
+
* @param callId - the wire call id the client was shown.
|
|
212
|
+
* @param event - the user's action, carried verbatim.
|
|
213
|
+
*/
|
|
214
|
+
settle(sessionId: string, callId: string, event: UiEvent): UiEventReply;
|
|
215
|
+
/**
|
|
216
|
+
* Every card this bridge still holds, as `ui.list` publishes it (§35.4).
|
|
217
|
+
*
|
|
218
|
+
* The claim registry IS the answer: a card leaves it the moment the user settles
|
|
219
|
+
* it, the grace window releases it, or the bridge unloads, so a card missing from
|
|
220
|
+
* this list is one no action can reach any more. Only `open` is ever listed —
|
|
221
|
+
* `settled` is the one-way notice, never a held row.
|
|
222
|
+
* @returns one entry per held card, in claim order.
|
|
223
|
+
*/
|
|
224
|
+
listed(): readonly ListedCard[];
|
|
225
|
+
/**
|
|
226
|
+
* Withdraw the named cards, ending each tool call with a refusal.
|
|
227
|
+
* @param callIds - the cards to release.
|
|
228
|
+
* @param reason - why; carried into the tool result as it stands.
|
|
229
|
+
* @returns how many were still open and therefore released.
|
|
230
|
+
*/
|
|
231
|
+
withdraw(callIds: readonly string[], reason?: UiRefusalReason): number;
|
|
232
|
+
/**
|
|
233
|
+
* Withdraw every claim.
|
|
234
|
+
* @param reason - why; carried into every released tool call.
|
|
235
|
+
* @returns how many cards were still open.
|
|
236
|
+
*/
|
|
237
|
+
withdrawAll(reason?: UiRefusalReason): number;
|
|
238
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `ui_present` model tool: the agent hands one self-contained page to the
|
|
3
|
+
* clients paired with this host, and the user's first action comes back as that
|
|
4
|
+
* same tool call's result (protocol §35).
|
|
5
|
+
*
|
|
6
|
+
* The tool owns its own vocabulary and nothing else. The page is the argument,
|
|
7
|
+
* the cards are the hub's claims, and the result is one sentence plus the
|
|
8
|
+
* presentation payload the desktop renders from (`meta.ui`, §35.10) — the phone
|
|
9
|
+
* still reads `ui.request` and `ui.list`, so this payload is never its second
|
|
10
|
+
* source of truth.
|
|
11
|
+
*
|
|
12
|
+
* Both caps are enforced here, on the originating side (§35.2): an oversized page
|
|
13
|
+
* is refused `invalid-args` before a frame is written and without a
|
|
14
|
+
* presentation payload, because a refusal on the client would leave the agent
|
|
15
|
+
* waiting for a card that never comes.
|
|
16
|
+
* @module dsh-remote-bridge/host/ui-tools
|
|
17
|
+
*/
|
|
18
|
+
import { type ToolDefinition } from '@deepseek-ai/dsh-tools';
|
|
19
|
+
import type { UiPresentReply } from '../core/hub.ts';
|
|
20
|
+
import type { JsonValue, UiCardView, UiState } from '../core/ui.ts';
|
|
21
|
+
/**
|
|
22
|
+
* The one thing this tool needs from the hub.
|
|
23
|
+
*
|
|
24
|
+
* Structural on purpose, and the seam a suite drives: the tool decides nothing
|
|
25
|
+
* about delivery, deadlines or the grace window, so a test can hand it any host
|
|
26
|
+
* that presents a page.
|
|
27
|
+
*/
|
|
28
|
+
export interface UiToolHost {
|
|
29
|
+
/** Present one page and wait for the user's first action (§35.2). */
|
|
30
|
+
present(card: UiCardView, signal?: AbortSignal): Promise<UiPresentReply>;
|
|
31
|
+
}
|
|
32
|
+
/** The card as the desktop renders it from a tool result (§35.10). */
|
|
33
|
+
export interface UiPresentationMeta {
|
|
34
|
+
/** {@link uiKey}: the same `"<sessionId>/<callId>"` a `ui.list` row carries. */
|
|
35
|
+
readonly key: string;
|
|
36
|
+
readonly title?: string;
|
|
37
|
+
/** The whole page, byte for byte the document that crossed as `html`. */
|
|
38
|
+
readonly html: string;
|
|
39
|
+
readonly height?: number;
|
|
40
|
+
readonly state: UiState;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* What the model is told before it writes a single page.
|
|
44
|
+
*
|
|
45
|
+
* Every clause here is one of §35.2's or §35.7's rules restated where the model
|
|
46
|
+
* can act on it: the page is a whole document, it cannot navigate, its external
|
|
47
|
+
* subresources are `https:`, its only way back is the named message channel, and
|
|
48
|
+
* the two caps are the host's. The blocking lifetime is stated last, because it is
|
|
49
|
+
* what a model most often assumes wrong: one action ends this call.
|
|
50
|
+
*/
|
|
51
|
+
export declare const UI_PRESENT_DESCRIPTION: string;
|
|
52
|
+
/**
|
|
53
|
+
* The canonical result body, as the output schema declares it.
|
|
54
|
+
*
|
|
55
|
+
* Three shapes and no more: the action that settled the card, the release of a
|
|
56
|
+
* card that did reach a screen, and a refusal that never got that far. Only the
|
|
57
|
+
* first two carry the card identity, which is what decides whether a presentation
|
|
58
|
+
* payload rides the result (§35.10).
|
|
59
|
+
*/
|
|
60
|
+
export type UiPresentValue = {
|
|
61
|
+
readonly ok: true;
|
|
62
|
+
readonly key: string;
|
|
63
|
+
readonly delivered: number;
|
|
64
|
+
readonly type: string;
|
|
65
|
+
readonly payload?: JsonValue;
|
|
66
|
+
} | {
|
|
67
|
+
readonly ok: false;
|
|
68
|
+
readonly reason: 'timeout' | 'cancelled';
|
|
69
|
+
readonly key: string;
|
|
70
|
+
readonly delivered: number;
|
|
71
|
+
} | {
|
|
72
|
+
readonly ok: false;
|
|
73
|
+
readonly reason: 'unavailable' | 'invalid-args';
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Build the one card tool.
|
|
77
|
+
* @param host - the hub, as this tool needs it.
|
|
78
|
+
* @returns a registry-ready definition for `ctx.tools.register`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function createUiPresentTool(host: UiToolHost): ToolDefinition;
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
*/
|
|
38
38
|
import type { LiveActivityNotifier } from '../core/liveactivity.ts';
|
|
39
39
|
import { type PushNotifier } from '../core/push.ts';
|
|
40
|
+
import type { TurnEndQuietGate } from '../core/turn-end-quiet.ts';
|
|
40
41
|
import { type BridgeGateway, type GatewayPeer } from '../core/wire.ts';
|
|
41
42
|
/** Most standing streams this bridge keeps open at once. */
|
|
42
43
|
export declare const WATCHER_LIMIT = 64;
|
|
@@ -56,6 +57,12 @@ export interface StandingWatcherOptions {
|
|
|
56
57
|
readonly liveActivity?: LiveActivityNotifier;
|
|
57
58
|
/** The notification path of §28; absent for the same reason. */
|
|
58
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;
|
|
59
66
|
readonly log: (message: string) => void;
|
|
60
67
|
readonly limit?: number;
|
|
61
68
|
readonly reopenMs?: number;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,6 +13,12 @@
|
|
|
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
|
|
@@ -32,7 +38,13 @@
|
|
|
32
38
|
import type { Context } from '@deepseek-ai/cordis';
|
|
33
39
|
/** Loader row identity of this plugin. */
|
|
34
40
|
export declare const name = "remote-bridge";
|
|
35
|
-
/**
|
|
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
|
+
*/
|
|
36
48
|
export declare const inject: string[];
|
|
37
49
|
/** Where the paired-device roster lives inside the DSH home. */
|
|
38
50
|
export declare const ROSTER_PATH = "remote-bridge/devices.json";
|
|
@@ -49,6 +61,22 @@ export declare const OFFLINE_CLAIM_TTL_ENV = "DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TT
|
|
|
49
61
|
* @returns the window in milliseconds.
|
|
50
62
|
*/
|
|
51
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;
|
|
52
80
|
/**
|
|
53
81
|
* Mount the bridge.
|
|
54
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.11",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.3",
|
|
70
70
|
"@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.3",
|
|
71
71
|
"@deepseek-ai/dsh-session": "^0.2.1-rc.3",
|
|
72
|
+
"@deepseek-ai/dsh-tools": "^0.2.1-rc.3",
|
|
72
73
|
"@deepseek-ai/dsh-typert-protocol": "^0.2.1-rc.3",
|
|
73
74
|
"@deepseek-ai/dsh-user-approval": "^0.2.1-rc.3",
|
|
74
75
|
"@testing-library/dom": "^10.4.1",
|