@linxin666/dsh-remote-bridge 0.4.9 → 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 +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,13 @@
|
|
|
1
|
+
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
|
+
export type UiPresentRowProps = PropsLocale<'remote-bridge'> & {
|
|
3
|
+
/** The stage the Tool slot published (`preparing`, `start` or `result`). */
|
|
4
|
+
readonly phase?: unknown;
|
|
5
|
+
/** The call material of that stage: the argument view, argument text, meta. */
|
|
6
|
+
readonly block?: unknown;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Render one card, or the neutral line of a call that carries no page.
|
|
10
|
+
* @param props - the stage, the call material and the locale seat.
|
|
11
|
+
* @returns the card body placed inside the official tool row.
|
|
12
|
+
*/
|
|
13
|
+
export declare function UiPresentRow({ phase, block, t }: UiPresentRowProps): import("react").JSX.Element;
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
* the events are untouched — and it does not touch `dsh-remote-web-ui`'s pairing
|
|
12
12
|
* service, its roster, or its browser cookie path.
|
|
13
13
|
*
|
|
14
|
+
* The half also draws the transcript side of §35.11: one keyed `tool.call.toolview`
|
|
15
|
+
* entry renders a `ui.present` call's whole page in a controlled frame, while the
|
|
16
|
+
* phone stays the only place an action can be answered.
|
|
17
|
+
*
|
|
14
18
|
* Export discipline (packages/AGENTS.md): the /client surface carries only what
|
|
15
19
|
* cordis loading needs plus types.
|
|
16
20
|
*/
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `remote-bridge` namespace dictionaries: the protocol v1 pairing panel copy
|
|
2
|
+
* `remote-bridge` namespace dictionaries: the protocol v1 pairing panel copy and
|
|
3
|
+
* the header of an interactive card (§35.11).
|
|
3
4
|
*
|
|
4
5
|
* The panel has one job — put the live one-shot code in front of the operator as
|
|
5
|
-
* a QR symbol — so
|
|
6
|
+
* a QR symbol — so its copy carries exactly four things: what to do with the
|
|
6
7
|
* symbol, how long it lives, which address the phone will actually dial, and why
|
|
7
8
|
* the code is single-use. No key states how the host finds its public address:
|
|
8
9
|
* that is an implementation fact the reader cannot act on.
|
|
10
|
+
*
|
|
11
|
+
* The card's keys say only what the transcript row can act on: whether the page
|
|
12
|
+
* is still waiting for the operator, that it is over, that this desktop renders
|
|
13
|
+
* without answering, and that a page carrying nothing or too much draws a
|
|
14
|
+
* sentence instead of a frame.
|
|
9
15
|
*/
|
|
10
16
|
/** Simplified Chinese dictionary (the key-set source of truth). */
|
|
11
17
|
export declare const zh: {
|
|
@@ -31,6 +37,13 @@ export declare const zh: {
|
|
|
31
37
|
readonly 'action.copied': "已复制";
|
|
32
38
|
readonly 'action.copyFailed': "复制失败";
|
|
33
39
|
readonly 'action.retry': "重试";
|
|
40
|
+
readonly 'card.waiting': "等你操作";
|
|
41
|
+
readonly 'card.settled': "已结算";
|
|
42
|
+
readonly 'card.answerOnPhone': "在手机上作答";
|
|
43
|
+
readonly 'card.interacted': "已收到页面上的操作,但桌面端不作答:在手机上作答";
|
|
44
|
+
readonly 'card.frameLabel': "整页卡片";
|
|
45
|
+
readonly 'card.empty': "这次调用没有可渲染的页面";
|
|
46
|
+
readonly 'card.oversize': "页面超出大小上限,未渲染";
|
|
34
47
|
};
|
|
35
48
|
/** English dictionary, key-for-key with the zh source. */
|
|
36
49
|
export declare const en: Record<RemoteBridgeKey, string>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one seam through which this package registers its keyed Tool view.
|
|
3
|
+
*
|
|
4
|
+
* `tool.call.toolview` is declared by `@deepseek-ai/dsh-client-ui-tool`
|
|
5
|
+
* (`lib/types/client/contract/slots.d.ts`). That package is not installed in this
|
|
6
|
+
* workspace, so its types cannot be imported — a type-only import would itself be
|
|
7
|
+
* a new dependency, and a local `declare module` extension of the SDK's `SlotMap`
|
|
8
|
+
* would duplicate a contract another package owns and collide with the real
|
|
9
|
+
* declaration wherever both are loaded. This module therefore narrows
|
|
10
|
+
* `ctx.slots` to the two members the registration needs and states the slot's own
|
|
11
|
+
* shape locally:
|
|
12
|
+
*
|
|
13
|
+
* - the slot is keyed and session-scoped, and its key is the wire Tool name
|
|
14
|
+
* (`ui.present`), which is what makes one registration draw the card's body
|
|
15
|
+
* without shadowing the official `tool-call` renderer;
|
|
16
|
+
* - the owner publishes the call identity plus a stage union, mirrored here from
|
|
17
|
+
* the upstream `ToolCallPhaseProps`: `preparing`, `start` and `result`. The
|
|
18
|
+
* row reads the arguments at every stage but `result`, which is the only arm
|
|
19
|
+
* that carries the result node.
|
|
20
|
+
*
|
|
21
|
+
* Upstream changing that shape is a change to this file: the phase names, the
|
|
22
|
+
* keyed dispatch and the `locale` seat are the three facts the mirror carries.
|
|
23
|
+
*
|
|
24
|
+
* Technical debt, recorded rather than hidden: when this package next takes a
|
|
25
|
+
* dependency pass, adding `@deepseek-ai/dsh-client-ui-tool` as a devDependency
|
|
26
|
+
* lets this seam be replaced by `PropsRuntime<'tool.call.toolview'>` and by the
|
|
27
|
+
* typed `ctx.slots.register` overload directly.
|
|
28
|
+
* @module dsh-remote-bridge/client/toolview-slot
|
|
29
|
+
*/
|
|
30
|
+
import type { ComponentType } from 'react';
|
|
31
|
+
import { type UiPresentRowProps } from './UiPresentRow.tsx';
|
|
32
|
+
/** The keyed Tool view slot the official row dispatches into. */
|
|
33
|
+
export declare const TOOLVIEW_SLOT = "tool.call.toolview";
|
|
34
|
+
/** The wire Tool name this package renders: the keyed cell it claims. */
|
|
35
|
+
export declare const PRESENT_TOOL = "ui.present";
|
|
36
|
+
/** The registration options this seam needs. */
|
|
37
|
+
export interface ToolviewRegistration {
|
|
38
|
+
/** Exact SlotMap key. */
|
|
39
|
+
readonly name: 'tool.call.toolview';
|
|
40
|
+
/** Keyed cell: the wire Tool name the owner dispatches by. */
|
|
41
|
+
readonly key: string;
|
|
42
|
+
/** Dictionary namespace the render machinery synthesizes `t` from. */
|
|
43
|
+
readonly locale: string;
|
|
44
|
+
}
|
|
45
|
+
/** The narrowed face of `ctx.slots` this package uses. */
|
|
46
|
+
export interface ToolviewSlotPort {
|
|
47
|
+
/** Run `seats` once the slot is declared; drop them if the declarer leaves. */
|
|
48
|
+
inject(name: string, seats: () => (() => void) | Iterable<() => void>): void;
|
|
49
|
+
/** Contribute one view to one keyed cell; the answer is its disposer. */
|
|
50
|
+
register(options: ToolviewRegistration, view: ComponentType<UiPresentRowProps>): () => void;
|
|
51
|
+
}
|
|
52
|
+
/** The host this seam needs: the client Context, structurally. */
|
|
53
|
+
export interface ToolviewSlotHost {
|
|
54
|
+
readonly slots: unknown;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Contribute the `ui.present` card into the Tool row.
|
|
58
|
+
*
|
|
59
|
+
* The contribution is declaration-aware: `inject` waits for the official slot
|
|
60
|
+
* declaration, so a GUI composed without a Tool layer has no keyed cell and thus
|
|
61
|
+
* no card — that is the capability being absent, not an error to report. A
|
|
62
|
+
* registration refused by the registry (an occupied cell at the same priority)
|
|
63
|
+
* is swallowed the same way it is for this package's other seat, so one occupied
|
|
64
|
+
* slot never takes the sidebar entry down with it.
|
|
65
|
+
* @param host - the client Context.
|
|
66
|
+
* @param locale - the dictionary namespace this package registered.
|
|
67
|
+
*/
|
|
68
|
+
export declare function registerPresentToolview(host: ToolviewSlotHost, locale: string): void;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transcript reading of one `ui.present` call (protocol §35.10, §35.11):
|
|
3
|
+
* what the desktop row draws, decided without touching the DOM.
|
|
4
|
+
*
|
|
5
|
+
* A card has two sources and neither may be dropped. While the call is still
|
|
6
|
+
* running the arguments are the only material on the wire, so the page comes out
|
|
7
|
+
* of `args` and the header says the operator has not acted yet. Once the result
|
|
8
|
+
* lands, the presentation payload `meta.ui` is the card's own record — its
|
|
9
|
+
* `state`, its `title` and the very document that crossed — and the arguments
|
|
10
|
+
* are only the fallback for a result that carries no payload.
|
|
11
|
+
*
|
|
12
|
+
* The argument view is read by shape rather than by import: a toolview receives a
|
|
13
|
+
* lazy `PartialArguments` when the call arrived as argument text and a plain
|
|
14
|
+
* payload when the call was dispatched as an object, and §35.10 fixes neither. A
|
|
15
|
+
* field reader therefore answers from all three shapes it can meet (lazy view,
|
|
16
|
+
* JSON text, parsed object) so a page is never lost to a shape this row did not
|
|
17
|
+
* anticipate.
|
|
18
|
+
*
|
|
19
|
+
* Two rules live here rather than in the renderer. A document above 256 KiB is
|
|
20
|
+
* never handed to a frame (§35.2 caps it on this side too), and a frame message is
|
|
21
|
+
* read by shape alone: the sandboxed document has an opaque origin, so identity
|
|
22
|
+
* comes from the frame element the row owns, never from what the message claims.
|
|
23
|
+
* Nothing read here is forwarded anywhere — the desktop renders and does not
|
|
24
|
+
* answer (§35.11).
|
|
25
|
+
* @module dsh-remote-bridge/client/ui-card
|
|
26
|
+
*/
|
|
27
|
+
import { type UiState } from '../core/ui.ts';
|
|
28
|
+
/**
|
|
29
|
+
* The Tool slot's stage literals, as the composing contract publishes them
|
|
30
|
+
* (`ToolCallPhaseProps`). `result` is the settled arm; every other stage still
|
|
31
|
+
* has the call's arguments only.
|
|
32
|
+
*/
|
|
33
|
+
export type PresentPhase = 'preparing' | 'start' | 'result';
|
|
34
|
+
/** One card as a row draws it, whichever source it came from. */
|
|
35
|
+
export interface PresentCard {
|
|
36
|
+
/** The whole self-contained document, `<!doctype html>` first. */
|
|
37
|
+
readonly html: string;
|
|
38
|
+
/** Whether the card still holds the call (`open`) or is only a notice. */
|
|
39
|
+
readonly state: UiState;
|
|
40
|
+
/** One header line; absent when the presenter named none. */
|
|
41
|
+
readonly title?: string;
|
|
42
|
+
/** The presenter's suggested first height in points; the measurement wins. */
|
|
43
|
+
readonly height?: number;
|
|
44
|
+
/** `"<sessionId>/<callId>"`, when the payload carries the card identity. */
|
|
45
|
+
readonly key?: string;
|
|
46
|
+
}
|
|
47
|
+
/** What one row read produced. */
|
|
48
|
+
export type PresentRead = {
|
|
49
|
+
readonly kind: 'card';
|
|
50
|
+
readonly card: PresentCard;
|
|
51
|
+
}
|
|
52
|
+
/** A page over {@link UI_HTML_MAX_BYTES}: refused visibly, never rendered. */
|
|
53
|
+
| {
|
|
54
|
+
readonly kind: 'oversize';
|
|
55
|
+
}
|
|
56
|
+
/** No page in either source: the row keeps a neutral line instead of a card. */
|
|
57
|
+
| {
|
|
58
|
+
readonly kind: 'empty';
|
|
59
|
+
};
|
|
60
|
+
/** One theme token as it is handed to a card's document. */
|
|
61
|
+
export type ThemeToken = readonly [name: string, value: string];
|
|
62
|
+
/**
|
|
63
|
+
* The theme tokens a card inherits from the GUI's own root element.
|
|
64
|
+
*
|
|
65
|
+
* Four roles and no more: the page needs a text colour it can trust, a quieter
|
|
66
|
+
* one, a surface and a border. A token the running theme does not define is
|
|
67
|
+
* simply not injected — the page then falls back to its own CSS, which is why an
|
|
68
|
+
* unreadable theme is a degraded look rather than a broken card.
|
|
69
|
+
*/
|
|
70
|
+
export declare const CARD_THEME_TOKENS: readonly ["--dsw-alias-label-primary", "--dsw-alias-label-secondary", "--dsw-alias-bg-layer-1", "--dsw-alias-border-l2"];
|
|
71
|
+
/** The one sandbox value a card frame is allowed (§35.7, §35.11). */
|
|
72
|
+
export declare const FRAME_SANDBOX = "allow-scripts";
|
|
73
|
+
/**
|
|
74
|
+
* The permissions a card frame is explicitly denied.
|
|
75
|
+
*
|
|
76
|
+
* §35.7 refuses camera, microphone, location and clipboard reads on both ends.
|
|
77
|
+
* A sandboxed document already has an opaque origin, and this policy states the
|
|
78
|
+
* denial where the browser enforces it rather than leaving it to the default.
|
|
79
|
+
*/
|
|
80
|
+
export declare const FRAME_PERMISSIONS: string;
|
|
81
|
+
/** The message type the injected reporter uses to publish the content height. */
|
|
82
|
+
export declare const FRAME_HEIGHT_CHANNEL = "dsh-ui-card-height";
|
|
83
|
+
/** The first height of a card whose presenter suggested none. */
|
|
84
|
+
export declare const CARD_DEFAULT_HEIGHT = 320;
|
|
85
|
+
/** The smallest and largest heights a measured card may take, in CSS pixels. */
|
|
86
|
+
export declare const CARD_MIN_HEIGHT = 96;
|
|
87
|
+
export declare const CARD_MAX_HEIGHT = 720;
|
|
88
|
+
/**
|
|
89
|
+
* Read the presentation payload a settled call carries (§35.10).
|
|
90
|
+
*
|
|
91
|
+
* The payload is the card's own record, so it is read only when it is one: a
|
|
92
|
+
* `html` that is not a string is no card at all, which keeps a malformed payload
|
|
93
|
+
* from becoming an empty frame. `state` outside the frozen pair reads as
|
|
94
|
+
* `settled` — a result-phase payload is a finished card by definition, and the
|
|
95
|
+
* `open` arm exists for a presenter that answers before its first event.
|
|
96
|
+
* @param meta - the result's `meta` value, carried verbatim.
|
|
97
|
+
* @returns the card, or undefined when this result carries no presentation.
|
|
98
|
+
*/
|
|
99
|
+
export declare function readPresentation(meta: unknown): PresentCard | undefined;
|
|
100
|
+
/** @returns whether one document is within {@link UI_HTML_MAX_BYTES}. */
|
|
101
|
+
export declare function cardHtmlFits(html: string): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Decide what the row draws at one stage of the call.
|
|
104
|
+
*
|
|
105
|
+
* The settled stage prefers `meta.ui`, because that payload is the presentation
|
|
106
|
+
* the host published and carries its ending. A result without the payload falls
|
|
107
|
+
* back to the arguments — and then the card is still over, so it reads
|
|
108
|
+
* `settled`: the stage decides that, not a field that is absent.
|
|
109
|
+
* @param phase - the stage the Tool slot published.
|
|
110
|
+
* @param block - the call material of that stage.
|
|
111
|
+
* @returns a card, a refusal, or the neutral line.
|
|
112
|
+
*/
|
|
113
|
+
export declare function presentReadOf(phase: unknown, block: unknown): PresentRead;
|
|
114
|
+
/**
|
|
115
|
+
* Read the theme tokens off a computed style, skipping the ones it does not carry.
|
|
116
|
+
* @param style - the GUI root element's computed style.
|
|
117
|
+
* @returns the tokens, in {@link CARD_THEME_TOKENS} order.
|
|
118
|
+
*/
|
|
119
|
+
export declare function cardThemeTokens(style: {
|
|
120
|
+
getPropertyValue(name: string): string;
|
|
121
|
+
}): readonly ThemeToken[];
|
|
122
|
+
/**
|
|
123
|
+
* Build the document handed to a card's frame.
|
|
124
|
+
*
|
|
125
|
+
* The agent's page stays byte for byte what crossed; this only adds the theme
|
|
126
|
+
* variables its CSS may use and the height reporter. Insertion happens ahead of
|
|
127
|
+
* the closing tags rather than at the start of the string, because a snippet
|
|
128
|
+
* placed before `<!doctype html>` would put the document into quirks mode.
|
|
129
|
+
* @param html - the card document as the presenter wrote it.
|
|
130
|
+
* @param tokens - the theme tokens to hand the page.
|
|
131
|
+
* @param channel - the message type the reporter publishes on.
|
|
132
|
+
* @returns the frame document; the original page when it takes no injection.
|
|
133
|
+
*/
|
|
134
|
+
export declare function frameDocument(html: string, tokens: readonly ThemeToken[], channel?: string): string;
|
|
135
|
+
/** One message a card's frame sent the parent. */
|
|
136
|
+
export type FrameEvent = {
|
|
137
|
+
readonly kind: 'height';
|
|
138
|
+
readonly height: number;
|
|
139
|
+
}
|
|
140
|
+
/** Anything else the page posted: an action this desktop never answers. */
|
|
141
|
+
| {
|
|
142
|
+
readonly kind: 'interaction';
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Read one message a card's frame posted.
|
|
146
|
+
*
|
|
147
|
+
* Only the shape is read. The frame's origin is opaque, so the parent identifies
|
|
148
|
+
* the sender by the frame element it owns; what is left to decide here is what
|
|
149
|
+
* the payload means, and a page's own `{type, payload}` action means nothing
|
|
150
|
+
* beyond "the operator tried to act here".
|
|
151
|
+
* @param data - the message payload.
|
|
152
|
+
* @returns the event, or undefined when the message is not one this row reads.
|
|
153
|
+
*/
|
|
154
|
+
export declare function frameEventOf(data: unknown): FrameEvent | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Hold a measured height inside the range a card may occupy.
|
|
157
|
+
* @param height - the content height the frame reported, in CSS pixels.
|
|
158
|
+
* @returns the height the card takes.
|
|
159
|
+
*/
|
|
160
|
+
export declare function clampCardHeight(height: number): number;
|
|
@@ -23,6 +23,8 @@ import type { LiveActivityNotifier } from './liveactivity.ts';
|
|
|
23
23
|
import type { PairingService } from './pairing.ts';
|
|
24
24
|
import type { PushNotifier } from './push.ts';
|
|
25
25
|
import type { QuestionClaims } from './questions.ts';
|
|
26
|
+
import type { TurnEndQuietGate } from './turn-end-quiet.ts';
|
|
27
|
+
import type { UiCards } from './ui.ts';
|
|
26
28
|
import { type SquadTransport } from './squads.ts';
|
|
27
29
|
import { type SessionMeta } from './session-meta.ts';
|
|
28
30
|
import type { SessionPermissions } from './session-permissions.ts';
|
|
@@ -88,6 +90,11 @@ export interface BridgeConnectionOptions {
|
|
|
88
90
|
readonly approvals: ApprovalRegistry;
|
|
89
91
|
/** Pending user questions: the claims this bridge holds and the answer path back to the host. */
|
|
90
92
|
readonly questions: QuestionClaims;
|
|
93
|
+
/**
|
|
94
|
+
* 整页卡(§35):`ui.present` 持有的每一张卡,`ui.event` 结算它们,`ui.list`
|
|
95
|
+
* 把它们念回去。与提问表平级、各自认领各自结算——两条通道互不改形状(§35.8)。
|
|
96
|
+
*/
|
|
97
|
+
readonly ui: UiCards;
|
|
91
98
|
/** The host's background jobs: the read-only projection and the scopes this connection watches. */
|
|
92
99
|
readonly jobs: JobRoster;
|
|
93
100
|
/** Process-local session metadata: live titles and the host's archive set. */
|
|
@@ -146,6 +153,15 @@ export interface BridgeConnectionOptions {
|
|
|
146
153
|
* (§28.3, §29).
|
|
147
154
|
*/
|
|
148
155
|
readonly liveActivity?: LiveActivityNotifier;
|
|
156
|
+
/**
|
|
157
|
+
* The gate a finished turn is announced through (§28, §29).
|
|
158
|
+
*
|
|
159
|
+
* Absent is a bridge assembled without one — a suite, or an embedder — and then
|
|
160
|
+
* both channels report at the frame, exactly as they did before the gate
|
|
161
|
+
* existed. The mount always hands one, because it is the only assembly that can
|
|
162
|
+
* read the host's own answer.
|
|
163
|
+
*/
|
|
164
|
+
readonly turnEndQuiet?: TurnEndQuietGate;
|
|
149
165
|
/**
|
|
150
166
|
* Called after a registration changed the device table.
|
|
151
167
|
*
|
|
@@ -161,6 +177,28 @@ export interface BridgeConnectionOptions {
|
|
|
161
177
|
export interface ConnectionAuth {
|
|
162
178
|
readonly deviceId: string;
|
|
163
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Whether one follow increment proves its session is working again.
|
|
182
|
+
*
|
|
183
|
+
* Deliberately narrow, and never "anything that is not a turn end": a parent's
|
|
184
|
+
* stream also carries a settled child's message (`source.kind` `subagent-settled`
|
|
185
|
+
* or `agent-message`, which the frames read as an agent actor), the usage count the
|
|
186
|
+
* host publishes as an assistant message finishes, and the catalog changes of the
|
|
187
|
+
* threads that session spawned. Reading any of those as a new turn would drop the
|
|
188
|
+
* turn end a waiting phone has not been told about yet — the one whose session is
|
|
189
|
+
* still busy with a running child, which is the case §28's gate exists for.
|
|
190
|
+
*
|
|
191
|
+
* One shared rule on purpose: this connection's own drain and the standing watchers
|
|
192
|
+
* both read it, so the two paths cannot disagree about what a new turn looks like.
|
|
193
|
+
* @param delta - one increment of a follow stream.
|
|
194
|
+
* @returns whether assistant work is streaming, or this session's own user wrote.
|
|
195
|
+
*/
|
|
196
|
+
export declare function isTurnStartDelta(delta: {
|
|
197
|
+
readonly kind: string;
|
|
198
|
+
readonly actor?: {
|
|
199
|
+
readonly kind?: string;
|
|
200
|
+
};
|
|
201
|
+
}): boolean;
|
|
164
202
|
/**
|
|
165
203
|
* One model selection, in the field names the protocol publishes.
|
|
166
204
|
*
|
|
@@ -99,6 +99,10 @@ export interface DeviceRosterOptions {
|
|
|
99
99
|
* Revocation is a file edit: protocol v1 has no revoke method, so an operator
|
|
100
100
|
* removes the row (or deletes the file) and restarts. The in-memory copy is
|
|
101
101
|
* loaded once per process.
|
|
102
|
+
*
|
|
103
|
+
* One phone is one row. Pairing again replaces the credential on the row the
|
|
104
|
+
* phone already has instead of adding a second one, and a table that still
|
|
105
|
+
* carries duplicates is compacted when it is read.
|
|
102
106
|
*/
|
|
103
107
|
export declare class DeviceRoster {
|
|
104
108
|
#private;
|
|
@@ -118,6 +118,19 @@ export declare class RemoteBridgeRegistry {
|
|
|
118
118
|
* @returns whether any plugin registered it, whatever capability it requires.
|
|
119
119
|
*/
|
|
120
120
|
has(method: string): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* The capabilities the registered tables require a client to declare.
|
|
123
|
+
*
|
|
124
|
+
* A table registered without a capability contributes none: nothing gates its
|
|
125
|
+
* methods, so there is nothing for a client to announce. A name stays listed
|
|
126
|
+
* while any registered method still requires it, so withdrawing one table
|
|
127
|
+
* withdraws its capability only when it was the last one holding it. Sorted,
|
|
128
|
+
* because this answer travels on the wire: one set must read the same way
|
|
129
|
+
* whatever order the plugins happened to mount in.
|
|
130
|
+
* @returns the distinct non-blank capabilities, ascending; empty when no
|
|
131
|
+
* extension is registered.
|
|
132
|
+
*/
|
|
133
|
+
capabilities(): readonly string[];
|
|
121
134
|
/**
|
|
122
135
|
* @param method - the method name a client asked for.
|
|
123
136
|
* @param declares - whether the calling connection declared a capability.
|
package/lib/types/core/hub.d.ts
CHANGED
|
@@ -23,12 +23,21 @@
|
|
|
23
23
|
* because a blocking ask carries no call id and the phone still needs a handle
|
|
24
24
|
* to answer with; and the claim outlives the last paired device by a grace
|
|
25
25
|
* window, because a phone whose app the system suspended has refused nothing.
|
|
26
|
+
*
|
|
27
|
+
* A presented page (`ui.present`, protocol §35) is the second claim that takes a
|
|
28
|
+
* grace window, and it takes the same one: the tool call it blocks is the agent's
|
|
29
|
+
* own wait, the card is the only place its answer can come from, and a phone that
|
|
30
|
+
* was suspended has refused nothing either. It differs in one direction only —
|
|
31
|
+
* there is no "next answerer" to hand a card back to, so a window that runs out
|
|
32
|
+
* ends the tool call as a refusal (§35.5: the host side reads it as a timeout)
|
|
33
|
+
* rather than starting another answerer.
|
|
26
34
|
* @module dsh-remote-bridge/core/hub
|
|
27
35
|
*/
|
|
28
36
|
import type { ApprovalOutcome } from '@deepseek-ai/dsh-user-approval';
|
|
29
37
|
import type { BridgeConnectionOptions, BridgeTransport, ConnectionAuth } from './connection.ts';
|
|
30
38
|
import { BridgeConnection } from './connection.ts';
|
|
31
39
|
import type { QuestionAnswer, UserQuestionRequestLike } from './questions.ts';
|
|
40
|
+
import type { JsonValue, UiCardView, UiRefusalReason } from './ui.ts';
|
|
32
41
|
/**
|
|
33
42
|
* The fields of an approval question this bridge reads. Structural on purpose:
|
|
34
43
|
* the event's own type is not exported from the package root, and only these
|
|
@@ -93,6 +102,26 @@ export interface BridgeHubOptions extends BridgeConnectionOptions {
|
|
|
93
102
|
*/
|
|
94
103
|
readonly offlineClaimTtlMs?: number;
|
|
95
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* What one `ui.present` call ended as, with the count of connections that took
|
|
107
|
+
* the first frame.
|
|
108
|
+
*
|
|
109
|
+
* The count is here rather than in the card registry because it is a fact about
|
|
110
|
+
* delivery: the registry owns the claim, the hub owns the fan-out, and a client
|
|
111
|
+
* count read back out of the claim would be a second answer to the same question.
|
|
112
|
+
* It rides the tool result so the desktop can say how many screens the page
|
|
113
|
+
* reached (§35.10).
|
|
114
|
+
*/
|
|
115
|
+
export type UiPresentReply = {
|
|
116
|
+
readonly ok: true;
|
|
117
|
+
readonly delivered: number;
|
|
118
|
+
readonly type: string;
|
|
119
|
+
readonly payload?: JsonValue;
|
|
120
|
+
} | {
|
|
121
|
+
readonly ok: false;
|
|
122
|
+
readonly delivered: number;
|
|
123
|
+
readonly reason: UiRefusalReason;
|
|
124
|
+
};
|
|
96
125
|
/** The bridge's live connections plus the answerer it composes onto the approval chain. */
|
|
97
126
|
export declare class BridgeHub {
|
|
98
127
|
#private;
|
|
@@ -141,6 +170,22 @@ export declare class BridgeHub {
|
|
|
141
170
|
* @param connection - the connection that just declared its capabilities.
|
|
142
171
|
*/
|
|
143
172
|
replayApprovals(connection: BridgeConnection): void;
|
|
173
|
+
/**
|
|
174
|
+
* Hand one freshly declared connection the cards this bridge still holds (§35.5).
|
|
175
|
+
*
|
|
176
|
+
* Without this, a presentation raised while the phone was reconnecting stays on
|
|
177
|
+
* the host with no page anywhere on the phone: the first `ui.request` was
|
|
178
|
+
* addressed to the clients that had already announced the channel. The replay
|
|
179
|
+
* emits a frame and nothing else — it claims no card and moves no deadline, so
|
|
180
|
+
* re-handing a page never lengthens how long the agent waits for it.
|
|
181
|
+
*
|
|
182
|
+
* A phone that can take a card is on the wire, so the window that held those
|
|
183
|
+
* cards for nobody is over: it is cancelled here rather than at attach, because
|
|
184
|
+
* only a connection that DECLARED the channel can actually receive one (§11.5's
|
|
185
|
+
* own judgement, which §35.5 reuses).
|
|
186
|
+
* @param connection - the connection that just declared its capabilities.
|
|
187
|
+
*/
|
|
188
|
+
replayUi(connection: BridgeConnection): void;
|
|
144
189
|
/**
|
|
145
190
|
* Publish one event to every paired device that announced a capability.
|
|
146
191
|
* @returns how many connections actually took the frame.
|
|
@@ -172,6 +217,25 @@ export declare class BridgeHub {
|
|
|
172
217
|
* @returns the phone's answer, the host's own deadline outcome, or whatever the next answerer says.
|
|
173
218
|
*/
|
|
174
219
|
question(request: UserQuestionRequestLike, next: () => Promise<QuestionAnswer>): Promise<QuestionAnswer>;
|
|
220
|
+
/**
|
|
221
|
+
* Present one page to the clients that declared `ui.v1` and wait for the user's
|
|
222
|
+
* first action (§35).
|
|
223
|
+
*
|
|
224
|
+
* The body of the `ui.present` tool call. Claimed only while a paired
|
|
225
|
+
* connection that declared the channel is on the wire: with none, a page would
|
|
226
|
+
* reach nobody, so the call answers `unavailable` at once instead of holding the
|
|
227
|
+
* agent on a wait no screen can end (§35.6 — the same judgement as §11.3's claim
|
|
228
|
+
* exclusivity). A frame no connection took is not held either, for the same
|
|
229
|
+
* reason.
|
|
230
|
+
*
|
|
231
|
+
* The card is announced `open` here and announced `settled` from the claim's own
|
|
232
|
+
* notice, so both frames come out of one payload builder and the page a phone was
|
|
233
|
+
* originally handed cannot drift from the one it reads back out of `ui.list`.
|
|
234
|
+
* @param card - the page, under the host's own `ToolCallId`.
|
|
235
|
+
* @param signal - the tool call's cancellation lifetime.
|
|
236
|
+
* @returns the user's action, or the refusal that ended the wait.
|
|
237
|
+
*/
|
|
238
|
+
present(card: UiCardView, signal?: AbortSignal): Promise<UiPresentReply>;
|
|
175
239
|
/** Close every connection and withdraw every question. Idempotent. */
|
|
176
240
|
dispose(): void;
|
|
177
241
|
}
|
|
@@ -43,11 +43,14 @@ export declare const METHOD_PUSH_REGISTER = "push.register";
|
|
|
43
43
|
export declare const METHOD_USAGE_SESSION = "usage.session";
|
|
44
44
|
export declare const METHOD_USAGE_BALANCE = "usage.balance";
|
|
45
45
|
export declare const METHOD_USAGE_STATS = "usage.stats";
|
|
46
|
+
export declare const METHOD_UI_EVENT = "ui.event";
|
|
47
|
+
export declare const METHOD_UI_LIST = "ui.list";
|
|
46
48
|
/** Server-pushed topics of protocol v1. */
|
|
47
49
|
export declare const TOPIC_SESSION_DELTA = "session.delta";
|
|
48
50
|
export declare const TOPIC_APPROVAL_REQUEST = "approval.request";
|
|
49
51
|
export declare const TOPIC_QUESTION_REQUEST = "question.request";
|
|
50
52
|
export declare const TOPIC_JOBS_CHANGED = "jobs.changed";
|
|
53
|
+
export declare const TOPIC_UI_REQUEST = "ui.request";
|
|
51
54
|
/**
|
|
52
55
|
* Capability a client declares in `hello`'s `cap` array to ask for a trimmed
|
|
53
56
|
* `session.snapshot` baseline. A client that does not declare it — including
|
|
@@ -233,6 +236,30 @@ export declare const CAP_USAGE = "usage.v1";
|
|
|
233
236
|
* 它看到的能力表里多一项、别的什么都没有变。
|
|
234
237
|
*/
|
|
235
238
|
export declare const CAP_USAGE_STATS = "usage.stats.v1";
|
|
239
|
+
/**
|
|
240
|
+
* 客户端在 `hello` 的 `cap` 数组里宣告它要渲染整页卡并回答它(协议 §35)。
|
|
241
|
+
*
|
|
242
|
+
* 宣告它是 `ui.request` 与 `ui.event` 进入这个客户端协议的唯一前提:不宣告的
|
|
243
|
+
* 客户端——包括这个通道出现之前写下的每一个客户端——收不到任何一帧整页卡,它的
|
|
244
|
+
* `ui.event` 回 `unknown-method`,其余逐字节不变。它是**公告不是协商**(§13.1、
|
|
245
|
+
* §24.1 同一判据):宿主公告同名项、客户端声明,双向缺一即当作这个能力不存在,
|
|
246
|
+
* 且不得把「宿主没这个能力」渲染成「这张卡不存在」或任何错误态。
|
|
247
|
+
*
|
|
248
|
+
* 宿主半区只有真实现了 `ui.present` 这一半的桥才把自己列进
|
|
249
|
+
* {@link SERVED_CAPABILITIES},所以一个客户端读到这个名字,就能断定 `ui.request`
|
|
250
|
+
* 会出现、`ui.event` 会被接受。
|
|
251
|
+
*/
|
|
252
|
+
export declare const CAP_UI = "ui.v1";
|
|
253
|
+
/**
|
|
254
|
+
* 客户端在 `hello` 的 `cap` 数组里宣告它要按 §24.3 的四条件对账自己手上的整页卡
|
|
255
|
+
* (协议 §35.4)。
|
|
256
|
+
*
|
|
257
|
+
* 与 {@link CAP_QUESTION_LIST} 同一形状:`ui.list` 本身是只读的、对每条配对连接
|
|
258
|
+
* 都开放,这个名字买到的是「这条连接会不会被答」之外的另一种确定性——一条老桥
|
|
259
|
+
* 回 `unknown-method`,于是没有这个名字的客户端就保留它原有的退休规则(卡片只在
|
|
260
|
+
* `ui.request` 说 `settled` 时结束),而不是按一次它信不过的应答清卡。
|
|
261
|
+
*/
|
|
262
|
+
export declare const CAP_UI_LIST = "ui.list.v1";
|
|
236
263
|
/**
|
|
237
264
|
* Capability a client declares in `hello`'s `cap` array to be answered with
|
|
238
265
|
* byte-level increments instead of the whole roster or the whole board.
|
|
@@ -411,6 +438,23 @@ export declare const CODE_QUESTION_UNKNOWN = "question-unknown";
|
|
|
411
438
|
* not a complete one — it is a bridge that cannot answer this question today.
|
|
412
439
|
*/
|
|
413
440
|
export declare const CODE_QUESTION_LIST_UNAVAILABLE = "question-list-unavailable";
|
|
441
|
+
/**
|
|
442
|
+
* 本桥不认领这个 `callId`:它从没呈现过这张卡,或者这张卡已被别处结算(宽限窗口
|
|
443
|
+
* 到期、回合被取消、桥卸载)。客户端码表保持开放:除本码之外的未知码不得被读成
|
|
444
|
+
* 「卡已消失」(§11.3 同一句)。
|
|
445
|
+
*/
|
|
446
|
+
export declare const CODE_UI_UNKNOWN = "ui-unknown";
|
|
447
|
+
/**
|
|
448
|
+
* 这张卡已经被用户自己的第一条动作结算过(§35.3)。它与 {@link CODE_UI_UNKNOWN}
|
|
449
|
+
* 是两个答案:重复的一次点击是「已经做完了」,不是「这张卡不存在」。
|
|
450
|
+
*/
|
|
451
|
+
export declare const CODE_UI_SETTLED = "ui-settled";
|
|
452
|
+
/**
|
|
453
|
+
* 本桥读不出自己持有的卡,所以它说不了哪些还活着。答案故意不是一张空表:客户端
|
|
454
|
+
* 只会按 COMPLETE 的列表退休卡片,一次失败的读不是一张完整的空表,而是这台桥今天
|
|
455
|
+
* 答不了这一问(与 {@link CODE_QUESTION_LIST_UNAVAILABLE} 同一句)。
|
|
456
|
+
*/
|
|
457
|
+
export declare const CODE_UI_LIST_UNAVAILABLE = "ui-list-unavailable";
|
|
414
458
|
/**
|
|
415
459
|
* The named session is a delegated child whose durable parent is not a session
|
|
416
460
|
* this connection may read. The bridge follows an addressable child and refuses
|
|
@@ -457,6 +501,13 @@ export declare const PROTO = 1;
|
|
|
457
501
|
/**
|
|
458
502
|
* Minor version this package speaks.
|
|
459
503
|
*
|
|
504
|
+
* 21 当可交互回复(协议 §35)落地:新增 {@link CAP_UI} 与 {@link CAP_UI_LIST}
|
|
505
|
+
* 两个能力名、{@link TOPIC_UI_REQUEST} 一个主题、{@link METHOD_UI_EVENT} 与
|
|
506
|
+
* {@link METHOD_UI_LIST} 两个方法,宿主半区还多一个模型工具 `ui.present`。客户端
|
|
507
|
+
* 因此从线路上读到两项新能力名、一种新主题与两种新应答体,所以 minor 抬一格;
|
|
508
|
+
* `proto` 仍为 1,没有任何既有帧、既有方法或既有键改形状。工具结果是**新增**的:
|
|
509
|
+
* 老会话、老 prompt、老回合都不受影响,工具名进入宿主工具表之后只有新回合才可能
|
|
510
|
+
* 被调用。
|
|
460
511
|
* 20 when the usage stats channel shipped: behind {@link CAP_USAGE_STATS} a
|
|
461
512
|
* client may call {@link METHOD_USAGE_STATS} and read the host's own usage
|
|
462
513
|
* ledger — today, this month and one row per local day — and behind the same
|
|
@@ -561,13 +612,26 @@ export declare const PROTO = 1;
|
|
|
561
612
|
* declares the capability that plugin requires. No addition changed the major
|
|
562
613
|
* version, a frozen field, or an existing method or topic name.
|
|
563
614
|
*/
|
|
564
|
-
export declare const MINOR =
|
|
565
|
-
/**
|
|
566
|
-
* The capabilities this bridge itself serves,
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
615
|
+
export declare const MINOR = 21;
|
|
616
|
+
/**
|
|
617
|
+
* The capabilities this bridge itself serves, and the opening half of what
|
|
618
|
+
* `hello` advertises.
|
|
619
|
+
*
|
|
620
|
+
* A capability a mounted plugin adds is not listed here — the bridge is not its
|
|
621
|
+
* author and names none of them — but `hello` advertises it all the same: the
|
|
622
|
+
* answer is this list plus every capability the extension registry currently
|
|
623
|
+
* requires a client to declare (`RemoteBridgeRegistry.capabilities`), computed
|
|
624
|
+
* on each greeting so a plugin mounted after this bridge was built is visible
|
|
625
|
+
* to the next phone. A name both halves carry is listed once, and this list
|
|
626
|
+
* keeps its order at the front, so a bridge with no extension mounted answers
|
|
627
|
+
* byte for byte the list it always did. Extension names never move
|
|
628
|
+
* {@link MINOR}: that number describes this protocol, and a plugin's own names
|
|
629
|
+
* are the plugin's.
|
|
630
|
+
*
|
|
631
|
+
* A capability whose whole switch is a declaration — no method, no answer, no
|
|
632
|
+
* field behind it, such as {@link CAP_APPROVALS} — stays out of this list for
|
|
633
|
+
* the reason it always did: advertising it would claim a handshake change
|
|
634
|
+
* without one.
|
|
571
635
|
*/
|
|
572
636
|
export declare const SERVED_CAPABILITIES: readonly string[];
|
|
573
637
|
/** `server` field of the hello response. */
|
package/lib/types/core/push.d.ts
CHANGED
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
* screen, which is the last place session content should be;
|
|
17
17
|
* - the same `(sessionId, event)` inside {@link PUSH_DEDUPE_MS} is one
|
|
18
18
|
* notification, because two phones following one session both see the same
|
|
19
|
-
* turn end and the user has one lock screen
|
|
19
|
+
* turn end and the user has one lock screen, and one APNs token is one
|
|
20
|
+
* delivery, because a token belongs to the app install rather than to one
|
|
21
|
+
* pairing, so the rows that share it are still that one phone;
|
|
20
22
|
* - a failed delivery is logged and dropped. Nothing here is awaited by the
|
|
21
23
|
* delta path, so a broken APNs connection cannot delay, reorder or suppress a
|
|
22
24
|
* frame that a connected phone is waiting for.
|
|
@@ -101,7 +103,13 @@ export interface PushLabels {
|
|
|
101
103
|
readonly workspace?: string;
|
|
102
104
|
}
|
|
103
105
|
export interface PushNotifierOptions {
|
|
104
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* The devices that asked to be notified, read per event.
|
|
108
|
+
*
|
|
109
|
+
* The list may carry several rows holding the same `deviceToken`: a phone that
|
|
110
|
+
* pairs again owns more than one roster row, and a token outlives any one
|
|
111
|
+
* pairing. Converging them is this module's job, not the caller's.
|
|
112
|
+
*/
|
|
105
113
|
readonly targets: () => readonly PushAddress[];
|
|
106
114
|
/** The sender; absent is a bridge with no signing key, and then nothing happens. */
|
|
107
115
|
readonly sender?: PushSender;
|