@linxin666/dsh-client-ui-browser-view 0.0.0-stage → 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/LICENSE +202 -0
- package/README.i18n.yaml +6 -0
- package/README.md +77 -2
- package/README.zh.md +78 -0
- package/cordis.patch.yml +7 -0
- package/lib/client.js +974 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +10555 -0
- package/lib/types/client/guide-icon.d.ts +21 -0
- package/lib/types/client/index.d.ts +51 -0
- package/lib/types/client/live-title.d.ts +39 -0
- package/lib/types/client/locales.d.ts +37 -0
- package/lib/types/client/panel.d.ts +28 -0
- package/lib/types/client/semantic.d.ts +37 -0
- package/lib/types/client/socket.d.ts +114 -0
- package/lib/types/client/tab-title.d.ts +17 -0
- package/lib/types/client/tab-type.d.ts +59 -0
- package/lib/types/core/actions.d.ts +112 -0
- package/lib/types/core/cdp.d.ts +95 -0
- package/lib/types/core/chrome.d.ts +209 -0
- package/lib/types/core/protocol.d.ts +179 -0
- package/lib/types/core/snapshot.d.ts +106 -0
- package/lib/types/core/tabs.d.ts +229 -0
- package/lib/types/host/auth.d.ts +52 -0
- package/lib/types/host/loopback.d.ts +64 -0
- package/lib/types/host/routes.d.ts +73 -0
- package/lib/types/host/service.d.ts +395 -0
- package/lib/types/host/tools.d.ts +64 -0
- package/lib/types/index.d.ts +31 -0
- package/package.json +81 -3
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tab lifecycle over one CDP connection: create, list, select, close, and the
|
|
3
|
+
* per-tab instrumentation the panel and the tools read.
|
|
4
|
+
*
|
|
5
|
+
* Each tab is a flat-mode session. Three domain subscriptions make a tab
|
|
6
|
+
* observable — `Runtime`/`Log` for the console ring, `Network` for the
|
|
7
|
+
* request table, `Page` for navigation state and the screencast — and they are
|
|
8
|
+
* enabled once, when the tab is attached, because a domain that is enabled late
|
|
9
|
+
* silently misses everything that happened before it.
|
|
10
|
+
*
|
|
11
|
+
* Ring buffers are bounded by {@link EVENT_RING_SIZE}: an unbounded console
|
|
12
|
+
* turns a chatty page into an unbounded memory leak in the host process, and
|
|
13
|
+
* the ring's newest entries are the ones anyone reads.
|
|
14
|
+
*
|
|
15
|
+
* Screencast frames must be acknowledged one by one. Chrome stops sending after
|
|
16
|
+
* an unacknowledged frame, so a dropped ack looks exactly like a frozen page.
|
|
17
|
+
*
|
|
18
|
+
* @module @linxin666/dsh-client-ui-browser-view/core/tabs
|
|
19
|
+
*/
|
|
20
|
+
import type { CdpTransport } from './cdp.ts';
|
|
21
|
+
import { type BrowserConsoleEntry, type BrowserNetworkEntry, type BrowserTabView } from './protocol.ts';
|
|
22
|
+
/** One JPEG frame as the panel receives it. */
|
|
23
|
+
export interface ScreencastFrame {
|
|
24
|
+
/** Tab the frame belongs to. */
|
|
25
|
+
tabId: string;
|
|
26
|
+
/** Monotonic per-tab frame counter. */
|
|
27
|
+
seq: number;
|
|
28
|
+
/** Frame width in CSS pixels. */
|
|
29
|
+
width: number;
|
|
30
|
+
/** Frame height in CSS pixels. */
|
|
31
|
+
height: number;
|
|
32
|
+
/** Base64 JPEG without the `data:` prefix. */
|
|
33
|
+
data: string;
|
|
34
|
+
}
|
|
35
|
+
/** Construction options. */
|
|
36
|
+
export interface TabManagerOptions {
|
|
37
|
+
/** The protocol transport every tab shares. */
|
|
38
|
+
transport: CdpTransport;
|
|
39
|
+
/** JPEG quality requested from CDP. @default DEFAULT_JPEG_QUALITY */
|
|
40
|
+
jpegQuality?: number;
|
|
41
|
+
/** Viewport pinned on every new tab. @default DEFAULT_VIEWPORT */
|
|
42
|
+
viewport?: {
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
};
|
|
46
|
+
/** Console and network ring size. @default EVENT_RING_SIZE */
|
|
47
|
+
ringSize?: number;
|
|
48
|
+
/** Clock used for entry timestamps. @default Date.now */
|
|
49
|
+
now?: () => number;
|
|
50
|
+
/** Receives every screencast frame and every explicitly refreshed frame. */
|
|
51
|
+
onFrame?: (frame: ScreencastFrame) => void;
|
|
52
|
+
/** Notifies that a tab's url, title, loading state, or membership changed. */
|
|
53
|
+
onTabsChanged?: () => void;
|
|
54
|
+
}
|
|
55
|
+
/** One tab's host-side record. */
|
|
56
|
+
interface TabRecord {
|
|
57
|
+
id: string;
|
|
58
|
+
sessionId: string;
|
|
59
|
+
url: string;
|
|
60
|
+
title: string;
|
|
61
|
+
loading: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Loader id of the document the observation buffers describe. A new loader
|
|
64
|
+
* id means a new document, which is what makes "the console only shows this
|
|
65
|
+
* page" hold even when the address itself did not change (a reload).
|
|
66
|
+
*/
|
|
67
|
+
loaderId: string | undefined;
|
|
68
|
+
ownerSessionId: string | undefined;
|
|
69
|
+
console: BrowserConsoleEntry[];
|
|
70
|
+
network: BrowserNetworkEntry[];
|
|
71
|
+
/** Pending requests keyed by network request id, so response frames update in place. */
|
|
72
|
+
pendingRequests: Map<string, BrowserNetworkEntry>;
|
|
73
|
+
screencastRunning: boolean;
|
|
74
|
+
frameSeq: number;
|
|
75
|
+
/** Depth-first ref to CSS selector map captured by the last snapshot. */
|
|
76
|
+
refs: Map<number, string>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Append one entry to a bounded ring, dropping the oldest overflow.
|
|
80
|
+
* @param ring - the ring, mutated in place.
|
|
81
|
+
* @param entry - the new entry.
|
|
82
|
+
* @param limit - maximum retained entries.
|
|
83
|
+
*/
|
|
84
|
+
export declare function pushBounded<T>(ring: T[], entry: T, limit: number): void;
|
|
85
|
+
/**
|
|
86
|
+
* One browser's tabs.
|
|
87
|
+
*/
|
|
88
|
+
export declare class TabManager {
|
|
89
|
+
private readonly transport;
|
|
90
|
+
private readonly jpegQuality;
|
|
91
|
+
private readonly viewport;
|
|
92
|
+
private readonly ringSize;
|
|
93
|
+
private readonly now;
|
|
94
|
+
private onFrame;
|
|
95
|
+
private onTabsChanged;
|
|
96
|
+
private readonly tabs;
|
|
97
|
+
private readonly bySession;
|
|
98
|
+
private readonly unsubscribers;
|
|
99
|
+
private active;
|
|
100
|
+
private disposed;
|
|
101
|
+
/**
|
|
102
|
+
* @param options - transport, viewport, ring size, callbacks.
|
|
103
|
+
*/
|
|
104
|
+
constructor(options: TabManagerOptions);
|
|
105
|
+
/** Replace the frame sink (the service rewires it when a panel attaches). */
|
|
106
|
+
setFrameSink(sink: ((frame: ScreencastFrame) => void) | undefined): void;
|
|
107
|
+
/** Replace the tab-change sink. */
|
|
108
|
+
setTabsChangedSink(sink: (() => void) | undefined): void;
|
|
109
|
+
/** Tabs in creation order. */
|
|
110
|
+
list(): BrowserTabView[];
|
|
111
|
+
/** The tab the panel watches, if any. */
|
|
112
|
+
get activeTabId(): string | null;
|
|
113
|
+
/** Whether a tab id is still open. */
|
|
114
|
+
has(tabId: string): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Resolve one tab or fail with a message the model can act on.
|
|
117
|
+
* @param tabId - id from a previous tool call or panel event.
|
|
118
|
+
* @returns the tab record.
|
|
119
|
+
*/
|
|
120
|
+
tab(tabId: string): BrowserTabView;
|
|
121
|
+
/** Internal record access for the layers that need the CDP session. */
|
|
122
|
+
sessionOf(tabId: string): string;
|
|
123
|
+
/**
|
|
124
|
+
* Create one tab and instrument it.
|
|
125
|
+
* @param options - url to open and the session that asked for it.
|
|
126
|
+
* @returns the new tab as the panel sees it.
|
|
127
|
+
*/
|
|
128
|
+
createTab(options?: {
|
|
129
|
+
url?: string;
|
|
130
|
+
sessionId?: string;
|
|
131
|
+
}): Promise<BrowserTabView>;
|
|
132
|
+
/**
|
|
133
|
+
* Pin CSS-pixel viewport metrics so frames, boxes, and clicks share one
|
|
134
|
+
* coordinate space regardless of the window the browser opened with.
|
|
135
|
+
* @param record - the tab to pin.
|
|
136
|
+
*/
|
|
137
|
+
pinViewport(record: TabRecord): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Navigate one tab and wait for the load to settle.
|
|
140
|
+
* @param tabId - target tab.
|
|
141
|
+
* @param url - absolute or `data:` url.
|
|
142
|
+
* @returns the tab after navigation settled.
|
|
143
|
+
*/
|
|
144
|
+
navigate(tabId: string, url: string): Promise<BrowserTabView>;
|
|
145
|
+
/**
|
|
146
|
+
* Mark which dsh session owns a tab, so the panel can show it.
|
|
147
|
+
* @param tabId - target tab.
|
|
148
|
+
* @param sessionId - owning session, or undefined to clear.
|
|
149
|
+
*/
|
|
150
|
+
bindSession(tabId: string, sessionId: string | undefined): void;
|
|
151
|
+
/**
|
|
152
|
+
* Select the tab the panel follows.
|
|
153
|
+
* @param tabId - target tab.
|
|
154
|
+
* @returns the selected tab.
|
|
155
|
+
*/
|
|
156
|
+
selectTab(tabId: string): BrowserTabView;
|
|
157
|
+
/**
|
|
158
|
+
* Close one tab and forget its ring buffers.
|
|
159
|
+
* @param tabId - target tab.
|
|
160
|
+
*/
|
|
161
|
+
closeTab(tabId: string): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Start the JPEG screencast for one tab.
|
|
164
|
+
* @param tabId - target tab.
|
|
165
|
+
*/
|
|
166
|
+
startScreencast(tabId: string): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Stop the screencast for one tab; a tab that is already stopped is fine.
|
|
169
|
+
* @param tabId - target tab.
|
|
170
|
+
*/
|
|
171
|
+
stopScreencast(tabId: string): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Capture one JPEG frame on demand.
|
|
174
|
+
* @param tabId - target tab.
|
|
175
|
+
* @returns base64 JPEG without the `data:` prefix.
|
|
176
|
+
*/
|
|
177
|
+
captureScreenshot(tabId: string): Promise<string>;
|
|
178
|
+
/**
|
|
179
|
+
* Capture a frame and hand it to the panel. An action calls this because a
|
|
180
|
+
* screencast only emits when the compositor sees a change: a click that
|
|
181
|
+
* changes nothing visually would otherwise leave the panel showing the
|
|
182
|
+
* pre-click state forever.
|
|
183
|
+
* @param tabId - target tab.
|
|
184
|
+
* @returns the emitted frame.
|
|
185
|
+
*/
|
|
186
|
+
refreshFrame(tabId: string): Promise<ScreencastFrame>;
|
|
187
|
+
/**
|
|
188
|
+
* Console entries captured so far, oldest first.
|
|
189
|
+
* @param tabId - target tab.
|
|
190
|
+
* @returns a copy; the ring keeps mutating.
|
|
191
|
+
*/
|
|
192
|
+
consoleEntries(tabId: string): BrowserConsoleEntry[];
|
|
193
|
+
/**
|
|
194
|
+
* Network entries captured so far, in request order.
|
|
195
|
+
* @param tabId - target tab.
|
|
196
|
+
* @returns a copy; the table keeps mutating.
|
|
197
|
+
*/
|
|
198
|
+
networkEntries(tabId: string): BrowserNetworkEntry[];
|
|
199
|
+
/**
|
|
200
|
+
* Record the ref-to-selector map produced by one snapshot, replacing the
|
|
201
|
+
* previous one: a ref is only meaningful against the observation it came
|
|
202
|
+
* from, and keeping two generations would let a click hit a stale node.
|
|
203
|
+
* @param tabId - target tab.
|
|
204
|
+
* @param refs - depth-first ref to CSS selector.
|
|
205
|
+
*/
|
|
206
|
+
setSnapshotRefs(tabId: string, refs: Map<number, string>): void;
|
|
207
|
+
/**
|
|
208
|
+
* Resolve a snapshot ref to the selector captured with it.
|
|
209
|
+
* @param tabId - target tab.
|
|
210
|
+
* @param ref - depth-first index from the last snapshot.
|
|
211
|
+
* @returns the CSS selector.
|
|
212
|
+
*/
|
|
213
|
+
selectorForRef(tabId: string, ref: number): string;
|
|
214
|
+
/** Stop every screencast and detach all protocol listeners. */
|
|
215
|
+
dispose(): Promise<void>;
|
|
216
|
+
/** One view for the panel and the tools. */
|
|
217
|
+
private view;
|
|
218
|
+
/** Look up a record or fail with an actionable message. */
|
|
219
|
+
private requireRecord;
|
|
220
|
+
/** Enable the domains every tab needs and attach nothing else. */
|
|
221
|
+
private enableDomains;
|
|
222
|
+
/** Drop every observation that belonged to the previous document. */
|
|
223
|
+
private resetObservation;
|
|
224
|
+
/** Read the current url and title into the record. */
|
|
225
|
+
private refreshDocumentInfo;
|
|
226
|
+
/** Register every protocol event the manager consumes. */
|
|
227
|
+
private subscribe;
|
|
228
|
+
}
|
|
229
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH's own authentication page, and the single launch-token retry a
|
|
3
|
+
* navigation to it gets.
|
|
4
|
+
*
|
|
5
|
+
* A fresh `dsh web` process prints a URL carrying `?token=<launch token>`.
|
|
6
|
+
* A request to the site root with that token answers 303 to the clean address
|
|
7
|
+
* and sets the `dsh-auth-<authority>` cookie; every later request is served
|
|
8
|
+
* from the cookie. A browser profile that never received the token — an
|
|
9
|
+
* ephemeral `--user-data-dir`, which is exactly what this plugin launches —
|
|
10
|
+
* sees the 401 challenge instead, whose body is the sentence matched here.
|
|
11
|
+
*
|
|
12
|
+
* The host's connection service can mint that same token for any URL
|
|
13
|
+
* (`ctx.connection.authenticatedUrl`), which is what makes the retry possible
|
|
14
|
+
* without this package depending on that SDK.
|
|
15
|
+
*
|
|
16
|
+
* If DSH rewords the challenge, {@link AUTH_CHALLENGE_TEXT} simply stops
|
|
17
|
+
* matching: the capability degrades to showing the authentication page exactly
|
|
18
|
+
* as before, and no other site's page is ever mistaken for ours.
|
|
19
|
+
*
|
|
20
|
+
* @module @linxin666/dsh-client-ui-browser-view/host/auth
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Script that reads the document's visible text. `document.body` is absent on
|
|
24
|
+
* a document that has no body yet, and `innerText` needs one.
|
|
25
|
+
*/
|
|
26
|
+
export declare const DOCUMENT_TEXT_EXPRESSION = "document.body ? document.body.innerText : ''";
|
|
27
|
+
/**
|
|
28
|
+
* The host seam that turns one clean URL into the same URL carrying the
|
|
29
|
+
* process launch token. Typed structurally: the connection SDK package is not
|
|
30
|
+
* a dependency of this one.
|
|
31
|
+
*/
|
|
32
|
+
export interface AuthenticatedUrlSource {
|
|
33
|
+
/**
|
|
34
|
+
* @param baseUrl - clean browser URL whose authority and mount are preserved.
|
|
35
|
+
* @returns the same URL carrying the process token.
|
|
36
|
+
*/
|
|
37
|
+
authenticatedUrl(baseUrl: string): string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether a page's visible text is DSH's authentication challenge.
|
|
41
|
+
* @param text - `document.body.innerText` of the page that just loaded.
|
|
42
|
+
* @returns true when the document is the challenge rather than a real page.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isAuthChallengeText(text: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Whether a navigation target is one this DSH process serves on loopback: a
|
|
47
|
+
* `localhost` name, 127/8, or `[::1]`. A remote site can render any text it
|
|
48
|
+
* likes, so only a loopback authority is worth a token retry.
|
|
49
|
+
* @param url - the URL a navigation was asked to open.
|
|
50
|
+
* @returns true for an absolute http(s) URL naming a loopback authority.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isLoopbackTarget(url: string): boolean;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loopback trust fence shared by the host route families: socket address,
|
|
3
|
+
* Host header, and browser same-origin markers. Packages receive this file as
|
|
4
|
+
* a generated copy via scripts/sync-shared.mjs; edit the shared source and
|
|
5
|
+
* re-run the sync instead of editing a copy.
|
|
6
|
+
*
|
|
7
|
+
* Semantics: RFC 5735 IPv4 127/8, ::1, IPv4-mapped ::ffff:127/8 (matching the
|
|
8
|
+
* remote-web-ui gate), localhost hostnames, plus the browser same-origin
|
|
9
|
+
* markers (sec-fetch-site and Origin) for the request-level fence.
|
|
10
|
+
*
|
|
11
|
+
* A reverse proxy in front of the host rewrites the Host header to its own
|
|
12
|
+
* upstream literal (a Cloudflare tunnel, frp and an nginx reverse proxy all
|
|
13
|
+
* dial 127.0.0.1:<port>), and the socket the origin sees is the proxy's, which
|
|
14
|
+
* is loopback by construction. Both halves of the fence then hold for a public
|
|
15
|
+
* request. Forwarding headers are the signal that a hop stands in between: a
|
|
16
|
+
* request that carries CF-Connecting-IP or X-Forwarded-For is answered through
|
|
17
|
+
* a proxy and is never treated as a local one (issue #1906).
|
|
18
|
+
*
|
|
19
|
+
* An operator who runs that proxy or tunnel themselves can opt into the
|
|
20
|
+
* narrower case: isForwardedLoopbackRequest describes a forwarded request that
|
|
21
|
+
* still landed on this machine's loopback upstream, and a route family admits
|
|
22
|
+
* it only behind its own default-off switch (issue #1918).
|
|
23
|
+
* @module dsh-web-shared/host/loopback
|
|
24
|
+
*/
|
|
25
|
+
import type { IncomingMessage } from 'node:http';
|
|
26
|
+
/** IPv4 127/8 predicate (four decimal octets, first == 127). */
|
|
27
|
+
export declare function isIPv4Loopback(v4: string): boolean;
|
|
28
|
+
/** Whether a socket remote address names the loopback range (127/8, ::1, IPv4-mapped). */
|
|
29
|
+
export declare function isLoopbackAddress(address: string | undefined): boolean;
|
|
30
|
+
/** Whether a normalized URL hostname names the loopback authority (localhost, [::1], 127/8). */
|
|
31
|
+
export declare function isLoopbackHostname(hostname: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether a reverse proxy stood between the client and this host: the request
|
|
34
|
+
* carries CF-Connecting-IP or X-Forwarded-For. Either header is stamped by a
|
|
35
|
+
* hop that forwards traffic, so the request did not originate on this machine.
|
|
36
|
+
* @param request - node HTTP request.
|
|
37
|
+
* @returns true when a forwarding header is present.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isProxiedRequest(request: IncomingMessage): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Request-level trust fence: a loopback socket address AND a loopback Host
|
|
42
|
+
* header, plus browser same-origin markers. The socket address is
|
|
43
|
+
* authoritative for a direct connection; a request that carries a forwarding
|
|
44
|
+
* header is refused outright, because a proxy in front of the host makes both
|
|
45
|
+
* the socket address and the Host header describe the proxy rather than the
|
|
46
|
+
* client. X-Forwarded-For is therefore never evidence *for* loopback.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isLoopbackRequest(request: IncomingMessage): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a forwarded request landed on this machine's loopback upstream: a
|
|
51
|
+
* forwarding header (the proxy's own stamp), a loopback socket address (the
|
|
52
|
+
* proxy dials 127.0.0.1:<port>), and a loopback Host header (the proxy rewrote
|
|
53
|
+
* the authority to its upstream literal).
|
|
54
|
+
*
|
|
55
|
+
* This is a fact about the route, not a trust decision. A public request to a
|
|
56
|
+
* tunnel satisfies all three by construction, because the proxy is the client
|
|
57
|
+
* of this process: only a caller that operates the proxy can decide it stands
|
|
58
|
+
* for the browser, which is why every consumer keeps this behind an explicit
|
|
59
|
+
* default-off switch and its own browser markers. isLoopbackRequest is
|
|
60
|
+
* unchanged and still refuses a forwarded request (issue #1906).
|
|
61
|
+
* @param request - node HTTP request.
|
|
62
|
+
* @returns true when a forwarding header, a loopback socket, and a loopback Host all hold.
|
|
63
|
+
*/
|
|
64
|
+
export declare function isForwardedLoopbackRequest(request: IncomingMessage): boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The /api/dsh-browser-view route family: one status route and the panel
|
|
3
|
+
* WebSocket.
|
|
4
|
+
*
|
|
5
|
+
* The socket is push-only once it is open — the host sends frames, state, and
|
|
6
|
+
* action traces, and the panel sends four small commands — so the protocol is a
|
|
7
|
+
* plain JSON text frame in both directions rather than a second sub-protocol.
|
|
8
|
+
*
|
|
9
|
+
* Two gates sit in front of every accepted command.
|
|
10
|
+
*
|
|
11
|
+
* Loopback. Both the route and the upgrade refuse a non-loopback request with
|
|
12
|
+
* 403 and destroy the socket. This surface drives a browser on the host
|
|
13
|
+
* machine, so an LAN-exposed GUI must not serve it.
|
|
14
|
+
*
|
|
15
|
+
* Version. The FIRST frame must declare {@link BROWSER_VIEW_API_VERSION}; a
|
|
16
|
+
* mismatch closes the socket instead of accepting commands whose meaning we
|
|
17
|
+
* cannot know. Later malformed frames only produce an error event, because by
|
|
18
|
+
* then the panel is known-good and a close would cost it its stream.
|
|
19
|
+
*
|
|
20
|
+
* @module @linxin666/dsh-client-ui-browser-view/host/routes
|
|
21
|
+
*/
|
|
22
|
+
import { WebSocket } from 'ws';
|
|
23
|
+
import type { WebRoute, WebUpgradeRoute } from '@deepseek-ai/dsh-host-webserver';
|
|
24
|
+
import type { BrowserViewBackend, BrowserViewSink } from './service.ts';
|
|
25
|
+
/** Status route of the family; the panel's fallback probe when the socket fails. */
|
|
26
|
+
export declare const BROWSER_VIEW_STATE_PATH = "/api/dsh-browser-view/state";
|
|
27
|
+
/** Close code used when the panel speaks a contract version we do not have. */
|
|
28
|
+
export declare const PROTOCOL_MISMATCH_CLOSE_CODE = 1002;
|
|
29
|
+
/**
|
|
30
|
+
* Send one error event to a panel.
|
|
31
|
+
* @param sink - the socket adapter.
|
|
32
|
+
* @param code - stable machine code.
|
|
33
|
+
* @param message - human text, never a stack trace.
|
|
34
|
+
*/
|
|
35
|
+
export declare function sendError(sink: BrowserViewSink, code: string, message: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Decode one panel frame.
|
|
38
|
+
* @param raw - the frame's text.
|
|
39
|
+
* @returns the parsed value, or undefined when it is not JSON.
|
|
40
|
+
*/
|
|
41
|
+
export declare function decodeFrame(raw: string): unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Run one inbound panel frame through the version and shape gates.
|
|
44
|
+
*
|
|
45
|
+
* Exported so tests can exercise the gate without a socket: the socket path and
|
|
46
|
+
* the gate must not drift apart.
|
|
47
|
+
* @param backend - the service that executes accepted commands.
|
|
48
|
+
* @param sink - the socket adapter the frame arrived on.
|
|
49
|
+
* @param raw - the frame's text.
|
|
50
|
+
* @param first - whether this is the socket's first frame.
|
|
51
|
+
* @returns what the caller should do next: keep the socket, or close it.
|
|
52
|
+
*/
|
|
53
|
+
export declare function handleClientFrame(backend: BrowserViewBackend, sink: BrowserViewSink, raw: string, first: boolean): Promise<'accept' | 'close'>;
|
|
54
|
+
/**
|
|
55
|
+
* Adapt one accepted WebSocket to the service's sink contract.
|
|
56
|
+
* @param socket - the upgraded socket.
|
|
57
|
+
* @returns the sink.
|
|
58
|
+
*/
|
|
59
|
+
export declare function socketSink(socket: WebSocket): BrowserViewSink;
|
|
60
|
+
/** Route family dependencies. */
|
|
61
|
+
export interface BrowserViewRoutesDeps {
|
|
62
|
+
/** The browser service (tests pass a stub). */
|
|
63
|
+
backend: BrowserViewBackend;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Build the route family and its upgrade.
|
|
67
|
+
* @param deps - the backend the socket commands reach.
|
|
68
|
+
* @returns exact routes plus the socket upgrade.
|
|
69
|
+
*/
|
|
70
|
+
export declare function makeRoutes(deps: BrowserViewRoutesDeps): {
|
|
71
|
+
routes: WebRoute[];
|
|
72
|
+
upgrade: WebUpgradeRoute;
|
|
73
|
+
};
|