@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
package/lib/client.js
ADDED
|
@@ -0,0 +1,974 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@linxin666/dsh-client-ui-browser-view",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
//#region src/client/live-title.ts
|
|
11
|
+
/**
|
|
12
|
+
* Create one store for the plugin's lifetime.
|
|
13
|
+
* @returns the channel.
|
|
14
|
+
*/
|
|
15
|
+
function createLiveTitleStore() {
|
|
16
|
+
const titles = /* @__PURE__ */ new Map();
|
|
17
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
18
|
+
const notify = () => {
|
|
19
|
+
for (const listener of [...listeners]) listener();
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
get(sessionId) {
|
|
23
|
+
return sessionId === void 0 ? void 0 : titles.get(sessionId);
|
|
24
|
+
},
|
|
25
|
+
set(sessionId, title) {
|
|
26
|
+
if (sessionId === void 0) return;
|
|
27
|
+
const current = titles.get(sessionId);
|
|
28
|
+
if (title === void 0 || title.length === 0) {
|
|
29
|
+
if (current === void 0) return;
|
|
30
|
+
titles.delete(sessionId);
|
|
31
|
+
notify();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (current === title) return;
|
|
35
|
+
titles.set(sessionId, title);
|
|
36
|
+
notify();
|
|
37
|
+
},
|
|
38
|
+
subscribe(listener) {
|
|
39
|
+
listeners.add(listener);
|
|
40
|
+
return () => {
|
|
41
|
+
listeners.delete(listener);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/client/locales.ts
|
|
48
|
+
/**
|
|
49
|
+
* Locale dictionaries for the browser-view plugin. `zh` is the key-set source
|
|
50
|
+
* of truth; `en` keeps a full key-for-key mirror (packages/AGENTS.md bilingual
|
|
51
|
+
* rules). Registered through ctx.locale.register(NS, { zh, en }); the components
|
|
52
|
+
* read every string through the injected `t` seat, so no copy is hardcoded in
|
|
53
|
+
* JSX.
|
|
54
|
+
*
|
|
55
|
+
* The page-title keys are gone with the page header: a right-sidebar tab is
|
|
56
|
+
* named by the shell's chip, and the chip's text comes from the tab type and
|
|
57
|
+
* the published page title instead ('panel.title' / 'panel.close' had no
|
|
58
|
+
* reader left once the "back to the conversation" control was removed).
|
|
59
|
+
*
|
|
60
|
+
* 'panel.tabs.empty' went with the always-drawn tab strip: the controlled
|
|
61
|
+
* browser's chips now appear only when it holds more than one page, so there is
|
|
62
|
+
* no empty strip left to caption.
|
|
63
|
+
*/
|
|
64
|
+
/** Simplified Chinese dictionary (key-set source of truth). */
|
|
65
|
+
const zh = {
|
|
66
|
+
"tab.title": "浏览器视图",
|
|
67
|
+
"guide.description": "看 agent 正在操作的网页",
|
|
68
|
+
"panel.tab.untitled": "未命名页面",
|
|
69
|
+
"panel.url.empty": "还没有打开页面",
|
|
70
|
+
"panel.address.label": "页面地址",
|
|
71
|
+
"panel.toolbar.refresh": "刷新画面",
|
|
72
|
+
"panel.frame.alt": "agent 正在操作的页面画面",
|
|
73
|
+
"panel.empty.title": "还没有画面",
|
|
74
|
+
"panel.empty.hint": "让 agent 打开一个页面后,这里会实时显示它正在看的网页。",
|
|
75
|
+
"panel.error.title": "浏览器视图出错",
|
|
76
|
+
"panel.trace.idle": "暂无工具动作",
|
|
77
|
+
"panel.status.connecting": "正在连接",
|
|
78
|
+
"panel.status.loading": "加载中",
|
|
79
|
+
"panel.status.live": "实时"
|
|
80
|
+
};
|
|
81
|
+
/** English dictionary, key-for-key complete against zh. */
|
|
82
|
+
const en = {
|
|
83
|
+
"tab.title": "Browser view",
|
|
84
|
+
"guide.description": "Watch the page the agent is driving",
|
|
85
|
+
"panel.tab.untitled": "Untitled page",
|
|
86
|
+
"panel.url.empty": "No page open yet",
|
|
87
|
+
"panel.address.label": "Page address",
|
|
88
|
+
"panel.toolbar.refresh": "Refresh the frame",
|
|
89
|
+
"panel.frame.alt": "Live view of the page the agent is driving",
|
|
90
|
+
"panel.empty.title": "No frames yet",
|
|
91
|
+
"panel.empty.hint": "Once the agent opens a page, this tab shows the page it is looking at.",
|
|
92
|
+
"panel.error.title": "Browser view error",
|
|
93
|
+
"panel.trace.idle": "No tool actions yet",
|
|
94
|
+
"panel.status.connecting": "Connecting",
|
|
95
|
+
"panel.status.loading": "Loading",
|
|
96
|
+
"panel.status.live": "Live"
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/core/protocol.ts
|
|
100
|
+
/** Mount path of the panel socket, relative to the GUI origin. */
|
|
101
|
+
const BROWSER_VIEW_SOCKET_PATH = "/api/dsh-browser-view/socket";
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/client/semantic.ts
|
|
104
|
+
/**
|
|
105
|
+
* Semantic attributes for the browser-view surface (semantic-attrs-v1).
|
|
106
|
+
*
|
|
107
|
+
* The plugin name lives on the root element of each surface so part values stay
|
|
108
|
+
* bare words; a theme anchors on the pair, never on a part name that repeats
|
|
109
|
+
* the plugin. The right-sidebar chip and the shell's tab strip around it are
|
|
110
|
+
* not ours, so only this plugin's own elements are stamped.
|
|
111
|
+
*
|
|
112
|
+
* The body's part names follow the shipped browser tab's structure - a toolbar
|
|
113
|
+
* with an address display, the frame, and the action trace - so a theme that
|
|
114
|
+
* already anchors on that chrome reaches this tab the same way.
|
|
115
|
+
*/
|
|
116
|
+
/** Root plugin attribute value carried by every top-level browser-view element. */
|
|
117
|
+
const BROWSER_VIEW_PLUGIN = "browser-view";
|
|
118
|
+
/** Part names this plugin emits, in surface order. */
|
|
119
|
+
const BROWSER_VIEW_PARTS = {
|
|
120
|
+
/** The tab body the sidebar mounts in its content area. */
|
|
121
|
+
panel: "panel",
|
|
122
|
+
/** Top chrome row: address display, connection state, refresh. */
|
|
123
|
+
toolbar: "toolbar",
|
|
124
|
+
/** The read-only address display of the streamed page. */
|
|
125
|
+
address: "address",
|
|
126
|
+
/** The controlled browser's tab chips; drawn only when it holds several. */
|
|
127
|
+
tabs: "tabs",
|
|
128
|
+
/** The live frame image. */
|
|
129
|
+
frame: "frame",
|
|
130
|
+
/** Bottom action trace. */
|
|
131
|
+
trace: "trace",
|
|
132
|
+
/** Connection state marker in the toolbar. */
|
|
133
|
+
status: "status",
|
|
134
|
+
/** No-frame placeholder. */
|
|
135
|
+
empty: "empty",
|
|
136
|
+
/** Host-reported failure placeholder. */
|
|
137
|
+
error: "error",
|
|
138
|
+
/** This plugin's share of the right-sidebar chip. */
|
|
139
|
+
tabTitle: "tab-title"
|
|
140
|
+
};
|
|
141
|
+
/** Reconnect ceiling; a host that stays down must not spin the tab. */
|
|
142
|
+
const RECONNECT_MAX_MS = 15e3;
|
|
143
|
+
/** Commands held while the socket is down; the oldest drop first. */
|
|
144
|
+
const PENDING_COMMAND_LIMIT = 16;
|
|
145
|
+
/** The network authority of a shell-owned Host, without credentials or a path. */
|
|
146
|
+
function hostAuthorityOf(base) {
|
|
147
|
+
if (base === void 0 || base === "") return void 0;
|
|
148
|
+
let url;
|
|
149
|
+
try {
|
|
150
|
+
url = new URL(base);
|
|
151
|
+
} catch {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return void 0;
|
|
155
|
+
if (url.username !== "" || url.password !== "" || url.host === "") return void 0;
|
|
156
|
+
return {
|
|
157
|
+
protocol: url.protocol,
|
|
158
|
+
authority: url.host
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Derive the socket URL from a web page or its application shell's Host.
|
|
163
|
+
*
|
|
164
|
+
* A web page keeps its own origin even when a transport hook is present. An
|
|
165
|
+
* application-delivered page such as the desktop shell's dsh-app: cannot carry
|
|
166
|
+
* a WebSocket upgrade on that scheme, so it uses the Host authority the shell
|
|
167
|
+
* publishes instead. The shell rewrites that handshake; the Host fence is unchanged.
|
|
168
|
+
* @param location - origin the panel is rendered on.
|
|
169
|
+
* @param streamBaseUrl - official `__DSH_TRANSPORT__.streamBaseUrl`, when published.
|
|
170
|
+
* @returns the absolute ws/wss URL, or null when no safe Host authority is known.
|
|
171
|
+
*/
|
|
172
|
+
function browserViewSocketUrl(location, streamBaseUrl) {
|
|
173
|
+
const pageProtocol = location.protocol === "https:" ? "wss:" : location.protocol === "http:" ? "ws:" : null;
|
|
174
|
+
if (pageProtocol !== null) return `${pageProtocol}//${location.host}${BROWSER_VIEW_SOCKET_PATH}`;
|
|
175
|
+
const base = hostAuthorityOf(streamBaseUrl);
|
|
176
|
+
if (base === void 0) return null;
|
|
177
|
+
return `${base.protocol === "https:" ? "wss:" : "ws:"}//${base.authority}${BROWSER_VIEW_SOCKET_PATH}`;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Backoff for one reconnect attempt.
|
|
181
|
+
* @param attempt - zero-based attempt index.
|
|
182
|
+
* @returns delay in milliseconds, capped at RECONNECT_MAX_MS.
|
|
183
|
+
*/
|
|
184
|
+
function reconnectDelay(attempt) {
|
|
185
|
+
const exponential = 500 * 2 ** Math.max(0, Math.floor(attempt));
|
|
186
|
+
return Math.min(exponential, RECONNECT_MAX_MS);
|
|
187
|
+
}
|
|
188
|
+
/** Narrow a tab row from the wire. */
|
|
189
|
+
function readTab(value) {
|
|
190
|
+
if (typeof value !== "object" || value === null) return null;
|
|
191
|
+
const candidate = value;
|
|
192
|
+
if (typeof candidate.id !== "string") return null;
|
|
193
|
+
if (typeof candidate.url !== "string") return null;
|
|
194
|
+
if (typeof candidate.title !== "string") return null;
|
|
195
|
+
if (typeof candidate.loading !== "boolean") return null;
|
|
196
|
+
return {
|
|
197
|
+
id: candidate.id,
|
|
198
|
+
url: candidate.url,
|
|
199
|
+
title: candidate.title,
|
|
200
|
+
loading: candidate.loading,
|
|
201
|
+
...typeof candidate.sessionId === "string" ? { sessionId: candidate.sessionId } : {}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** Narrow the panel state from the wire. */
|
|
205
|
+
function readPanelState(value) {
|
|
206
|
+
if (typeof value !== "object" || value === null) return null;
|
|
207
|
+
const candidate = value;
|
|
208
|
+
if (!Array.isArray(candidate.tabs)) return null;
|
|
209
|
+
if (typeof candidate.running !== "boolean") return null;
|
|
210
|
+
if (candidate.activeTabId !== null && typeof candidate.activeTabId !== "string") return null;
|
|
211
|
+
const tabs = [];
|
|
212
|
+
for (const entry of candidate.tabs) {
|
|
213
|
+
const tab = readTab(entry);
|
|
214
|
+
if (tab === null) return null;
|
|
215
|
+
tabs.push(tab);
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
tabs,
|
|
219
|
+
activeTabId: candidate.activeTabId,
|
|
220
|
+
running: candidate.running,
|
|
221
|
+
...typeof candidate.message === "string" ? { message: candidate.message } : {}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Narrow one decoded payload into a protocol event.
|
|
226
|
+
*
|
|
227
|
+
* The protocol is a discriminated union over `kind`, so an unknown kind or a
|
|
228
|
+
* wrong field type is a shape this panel cannot render: it is dropped rather
|
|
229
|
+
* than half-applied, which keeps one malformed push from corrupting the view.
|
|
230
|
+
* @param value - parsed JSON value (or a raw frame string).
|
|
231
|
+
* @returns the event, or null when the payload is not one this version reads.
|
|
232
|
+
*/
|
|
233
|
+
function parseBrowserViewEvent(value) {
|
|
234
|
+
let payload = value;
|
|
235
|
+
if (typeof payload === "string") try {
|
|
236
|
+
payload = JSON.parse(payload);
|
|
237
|
+
} catch {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
if (typeof payload !== "object" || payload === null) return null;
|
|
241
|
+
const candidate = payload;
|
|
242
|
+
if (candidate.v !== 1) return null;
|
|
243
|
+
switch (candidate.kind) {
|
|
244
|
+
case "hello":
|
|
245
|
+
case "state": {
|
|
246
|
+
const state = readPanelState(candidate.state);
|
|
247
|
+
if (state === null) return null;
|
|
248
|
+
return {
|
|
249
|
+
v: 1,
|
|
250
|
+
kind: candidate.kind,
|
|
251
|
+
state
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
case "frame":
|
|
255
|
+
if (typeof candidate.tabId !== "string") return null;
|
|
256
|
+
if (typeof candidate.seq !== "number") return null;
|
|
257
|
+
if (typeof candidate.width !== "number") return null;
|
|
258
|
+
if (typeof candidate.height !== "number") return null;
|
|
259
|
+
if (typeof candidate.data !== "string") return null;
|
|
260
|
+
return {
|
|
261
|
+
v: 1,
|
|
262
|
+
kind: "frame",
|
|
263
|
+
tabId: candidate.tabId,
|
|
264
|
+
seq: candidate.seq,
|
|
265
|
+
width: candidate.width,
|
|
266
|
+
height: candidate.height,
|
|
267
|
+
data: candidate.data
|
|
268
|
+
};
|
|
269
|
+
case "action": {
|
|
270
|
+
const trace = candidate.trace;
|
|
271
|
+
if (typeof trace !== "object" || trace === null) return null;
|
|
272
|
+
const row = trace;
|
|
273
|
+
if (typeof row.tool !== "string" || typeof row.summary !== "string" || typeof row.at !== "number") return null;
|
|
274
|
+
return {
|
|
275
|
+
v: 1,
|
|
276
|
+
kind: "action",
|
|
277
|
+
trace: {
|
|
278
|
+
tool: row.tool,
|
|
279
|
+
summary: row.summary,
|
|
280
|
+
at: row.at
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
case "error":
|
|
285
|
+
if (typeof candidate.code !== "string" || typeof candidate.message !== "string") return null;
|
|
286
|
+
return {
|
|
287
|
+
v: 1,
|
|
288
|
+
kind: "error",
|
|
289
|
+
code: candidate.code,
|
|
290
|
+
message: candidate.message
|
|
291
|
+
};
|
|
292
|
+
default: return null;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Open one connection to the host half and keep it alive.
|
|
297
|
+
*
|
|
298
|
+
* Sequencing: every successful open sends `attach` (the host answers with
|
|
299
|
+
* `hello` plus frames), and the per-tab frame counter is cleared because the
|
|
300
|
+
* host restarts its `seq` for a new connection — keeping the old high-water
|
|
301
|
+
* mark would drop the whole fresh stream.
|
|
302
|
+
* @param handlers - panel callbacks.
|
|
303
|
+
* @param options - transport, origin, session and timer seams.
|
|
304
|
+
* @returns the handle the panel closes on unmount.
|
|
305
|
+
*/
|
|
306
|
+
function connectBrowserViewSocket(handlers, options = {}) {
|
|
307
|
+
const globals = globalThis;
|
|
308
|
+
const WebSocketImpl = options.WebSocketImpl ?? globals.WebSocket;
|
|
309
|
+
const location = options.location ?? globals.location;
|
|
310
|
+
const setTimer = options.setTimer ?? ((handler, ms) => setTimeout(handler, ms));
|
|
311
|
+
const clearTimer = options.clearTimer ?? ((handle) => {
|
|
312
|
+
clearTimeout(handle);
|
|
313
|
+
});
|
|
314
|
+
const publishedBase = globals.__DSH_TRANSPORT__?.streamBaseUrl;
|
|
315
|
+
const url = location === void 0 ? null : browserViewSocketUrl(location, typeof publishedBase === "string" ? publishedBase : void 0);
|
|
316
|
+
let status = "connecting";
|
|
317
|
+
let socket = null;
|
|
318
|
+
let attempt = 0;
|
|
319
|
+
let disposed = false;
|
|
320
|
+
let timer = null;
|
|
321
|
+
const pending = [];
|
|
322
|
+
const lastSeqByTab = /* @__PURE__ */ new Map();
|
|
323
|
+
/** Publish a phase change once. */
|
|
324
|
+
const setStatus = (next) => {
|
|
325
|
+
if (status === next) return;
|
|
326
|
+
status = next;
|
|
327
|
+
handlers.onStatus?.(next);
|
|
328
|
+
};
|
|
329
|
+
/** Send without buffering (open socket only). */
|
|
330
|
+
const sendNow = (command) => {
|
|
331
|
+
if (socket === null) return false;
|
|
332
|
+
try {
|
|
333
|
+
socket.send(JSON.stringify(command));
|
|
334
|
+
return true;
|
|
335
|
+
} catch {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
/** Dispatch one decoded event, dropping frames older than what is on screen. */
|
|
340
|
+
const dispatch = (event) => {
|
|
341
|
+
switch (event.kind) {
|
|
342
|
+
case "hello":
|
|
343
|
+
case "state":
|
|
344
|
+
handlers.onState(event.state);
|
|
345
|
+
return;
|
|
346
|
+
case "frame": {
|
|
347
|
+
const previous = lastSeqByTab.get(event.tabId);
|
|
348
|
+
if (previous !== void 0 && event.seq <= previous) return;
|
|
349
|
+
lastSeqByTab.set(event.tabId, event.seq);
|
|
350
|
+
handlers.onFrame({
|
|
351
|
+
tabId: event.tabId,
|
|
352
|
+
seq: event.seq,
|
|
353
|
+
width: event.width,
|
|
354
|
+
height: event.height,
|
|
355
|
+
data: event.data
|
|
356
|
+
});
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
case "action":
|
|
360
|
+
handlers.onAction(event.trace);
|
|
361
|
+
return;
|
|
362
|
+
case "error":
|
|
363
|
+
handlers.onError(event.code, event.message);
|
|
364
|
+
return;
|
|
365
|
+
default: return;
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
/** Arm the next reconnect; each failure doubles the wait until the ceiling. */
|
|
369
|
+
const scheduleReconnect = () => {
|
|
370
|
+
if (disposed) return;
|
|
371
|
+
if (url === null || WebSocketImpl === void 0) {
|
|
372
|
+
setStatus("closed");
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
setStatus("reconnecting");
|
|
376
|
+
if (timer !== null) clearTimer(timer);
|
|
377
|
+
const delay = reconnectDelay(attempt);
|
|
378
|
+
attempt += 1;
|
|
379
|
+
timer = setTimer(() => {
|
|
380
|
+
timer = null;
|
|
381
|
+
connect();
|
|
382
|
+
}, delay);
|
|
383
|
+
};
|
|
384
|
+
/** Open one transport and wire it to the handlers. */
|
|
385
|
+
const connect = () => {
|
|
386
|
+
if (disposed) return;
|
|
387
|
+
if (url === null || WebSocketImpl === void 0) {
|
|
388
|
+
setStatus("closed");
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
setStatus(attempt === 0 ? "connecting" : "reconnecting");
|
|
392
|
+
let transport;
|
|
393
|
+
try {
|
|
394
|
+
transport = new WebSocketImpl(url);
|
|
395
|
+
} catch {
|
|
396
|
+
socket = null;
|
|
397
|
+
scheduleReconnect();
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
socket = transport;
|
|
401
|
+
transport.onopen = () => {
|
|
402
|
+
if (disposed) return;
|
|
403
|
+
attempt = 0;
|
|
404
|
+
lastSeqByTab.clear();
|
|
405
|
+
setStatus("open");
|
|
406
|
+
while (pending.length > 0) {
|
|
407
|
+
const command = pending.shift();
|
|
408
|
+
if (command !== void 0) sendNow(command);
|
|
409
|
+
}
|
|
410
|
+
sendNow({
|
|
411
|
+
v: 1,
|
|
412
|
+
kind: "attach",
|
|
413
|
+
...options.sessionId === void 0 ? {} : { sessionId: options.sessionId }
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
transport.onmessage = (event) => {
|
|
417
|
+
if (disposed) return;
|
|
418
|
+
const parsed = parseBrowserViewEvent(event.data);
|
|
419
|
+
if (parsed !== null) dispatch(parsed);
|
|
420
|
+
};
|
|
421
|
+
transport.onerror = () => {};
|
|
422
|
+
transport.onclose = () => {
|
|
423
|
+
if (socket === transport) socket = null;
|
|
424
|
+
if (disposed) return;
|
|
425
|
+
scheduleReconnect();
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
connect();
|
|
429
|
+
return {
|
|
430
|
+
send(command) {
|
|
431
|
+
if (sendNow(command)) return;
|
|
432
|
+
pending.push(command);
|
|
433
|
+
if (pending.length > PENDING_COMMAND_LIMIT) pending.shift();
|
|
434
|
+
},
|
|
435
|
+
close() {
|
|
436
|
+
if (disposed) return;
|
|
437
|
+
disposed = true;
|
|
438
|
+
if (timer !== null) {
|
|
439
|
+
clearTimer(timer);
|
|
440
|
+
timer = null;
|
|
441
|
+
}
|
|
442
|
+
const transport = socket;
|
|
443
|
+
socket = null;
|
|
444
|
+
setStatus("closed");
|
|
445
|
+
if (transport !== null) try {
|
|
446
|
+
transport.close();
|
|
447
|
+
} catch {}
|
|
448
|
+
},
|
|
449
|
+
status() {
|
|
450
|
+
return status;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region \0dsh-css:packages/dsh-browser-view/src/client/panel.module.css.mjs
|
|
456
|
+
const css = ".mm_Yva_tabTitle{align-items:center;gap:5px;min-width:0;max-width:100%;display:inline-flex}.mm_Yva_tabTitleMark{flex:none;width:13px;height:13px}.mm_Yva_tabTitleText{white-space:nowrap;text-overflow:ellipsis;min-width:0;overflow:hidden}.mm_Yva_root{min-width:0;height:100%;min-height:0;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-base);flex-direction:column;flex:auto;display:flex;overflow:hidden}.mm_Yva_toolbar{box-sizing:border-box;border-bottom:.5px solid var(--dsw-alias-border-l3);flex:none;align-items:center;gap:4px;height:38px;padding:5px 6px;display:flex}.mm_Yva_tool{width:28px;height:28px;color:var(--dsw-alias-label-secondary);border-radius:var(--dsw-radius-sm);cursor:pointer;background:0 0;border:0;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}@media (hover:hover){.mm_Yva_tool:hover:not(:disabled){color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}}.mm_Yva_tool:disabled{color:var(--dsw-alias-label-quaternary);cursor:default}.mm_Yva_tool:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-bg-base), 0 0 0 4px var(--dsw-alias-brand-primary);outline:none}.mm_Yva_addressBox{flex:auto;min-width:0;position:relative}.mm_Yva_address{box-sizing:border-box;width:100%;height:28px;color:var(--dsw-alias-label-primary);font:var(--dsw-font-xxs-12);text-overflow:ellipsis;white-space:nowrap;background:var(--dsw-alias-bg-layer-1);border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm);padding:0 9px;overflow:hidden}.mm_Yva_address::placeholder{color:var(--dsw-alias-label-tertiary)}.mm_Yva_address:focus{outline:1px solid var(--dsw-alias-state-business-primary);outline-offset:-1px}.mm_Yva_status{color:var(--dsw-alias-label-tertiary);font:var(--dsw-font-xxxs-11);white-space:nowrap;flex:none;align-items:center;gap:4px;line-height:16px;display:inline-flex}.mm_Yva_statusText{text-overflow:ellipsis;max-width:72px;overflow:hidden}.mm_Yva_tabs{border-bottom:.5px solid var(--dsw-alias-border-l3);scrollbar-width:none;flex:none;align-items:center;gap:4px;padding:4px 6px;display:flex;overflow-x:auto}.mm_Yva_tabs::-webkit-scrollbar{display:none}.mm_Yva_tab{max-width:150px;height:24px;color:var(--dsw-alias-label-secondary);font:var(--dsw-font-xxxs-11);white-space:nowrap;text-overflow:ellipsis;border-radius:var(--dsw-radius-sm);cursor:pointer;background:0 0;border:0;flex:none;padding:0 8px;transition:background-color .12s,color .12s;overflow:hidden}@media (hover:hover){.mm_Yva_tab:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}}.mm_Yva_tabActive{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-active)}.mm_Yva_tab:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-bg-base), 0 0 0 4px var(--dsw-alias-brand-primary);outline:none}.mm_Yva_content{background:var(--dsw-alias-bg-base);flex:auto;min-width:0;min-height:0;display:flex;overflow:auto}.mm_Yva_frame{object-fit:contain;max-width:100%;height:auto;margin:auto;display:block}.mm_Yva_empty,.mm_Yva_error{text-align:center;flex-direction:column;align-items:center;gap:6px;margin:auto;padding:20px 16px;display:flex}.mm_Yva_emptyTitle,.mm_Yva_errorTitle{color:var(--dsw-alias-label-secondary);font-size:13px;font-weight:600;line-height:20px}.mm_Yva_emptyHint,.mm_Yva_errorBody{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}.mm_Yva_errorTitle{color:var(--dsw-alias-state-error-primary)}.mm_Yva_errorCode{color:var(--dsw-alias-label-tertiary);font-family:var(--dsw-font-mono,ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);font-size:11px;line-height:16px}.mm_Yva_trace{border-top:.5px solid var(--dsw-alias-border-l3);flex:none;align-items:center;gap:8px;max-height:84px;padding:6px 10px;display:flex;overflow:hidden}.mm_Yva_traceList{flex-direction:column;flex:1;gap:2px;min-width:0;display:flex;overflow:hidden}.mm_Yva_traceIdle{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}.mm_Yva_traceRow{align-items:baseline;gap:6px;min-width:0;font-size:12px;line-height:18px;display:flex}.mm_Yva_traceTool{color:var(--dsw-alias-brand-primary);font-family:var(--dsw-font-mono,ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);flex:none;font-size:11px}.mm_Yva_traceSummary{min-width:0;color:var(--dsw-alias-label-secondary);white-space:nowrap;text-overflow:ellipsis;overflow:hidden}";
|
|
457
|
+
const tagId = "@linxin666/dsh-client-ui-browser-view/packages/dsh-browser-view/src/client/panel.module.css";
|
|
458
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
459
|
+
const tag = document.createElement("style");
|
|
460
|
+
tag.dataset.plugin = "@linxin666/dsh-client-ui-browser-view";
|
|
461
|
+
tag.dataset.pluginCss = tagId;
|
|
462
|
+
tag.textContent = css;
|
|
463
|
+
document.head.appendChild(tag);
|
|
464
|
+
}
|
|
465
|
+
var panel_module_css_default = {
|
|
466
|
+
"address": "mm_Yva_address",
|
|
467
|
+
"addressBox": "mm_Yva_addressBox",
|
|
468
|
+
"content": "mm_Yva_content",
|
|
469
|
+
"empty": "mm_Yva_empty",
|
|
470
|
+
"emptyHint": "mm_Yva_emptyHint",
|
|
471
|
+
"emptyTitle": "mm_Yva_emptyTitle",
|
|
472
|
+
"error": "mm_Yva_error",
|
|
473
|
+
"errorBody": "mm_Yva_errorBody",
|
|
474
|
+
"errorCode": "mm_Yva_errorCode",
|
|
475
|
+
"errorTitle": "mm_Yva_errorTitle",
|
|
476
|
+
"frame": "mm_Yva_frame",
|
|
477
|
+
"root": "mm_Yva_root",
|
|
478
|
+
"status": "mm_Yva_status",
|
|
479
|
+
"statusText": "mm_Yva_statusText",
|
|
480
|
+
"tab": "mm_Yva_tab",
|
|
481
|
+
"tabActive": "mm_Yva_tabActive",
|
|
482
|
+
"tabTitle": "mm_Yva_tabTitle",
|
|
483
|
+
"tabTitleMark": "mm_Yva_tabTitleMark",
|
|
484
|
+
"tabTitleText": "mm_Yva_tabTitleText",
|
|
485
|
+
"tabs": "mm_Yva_tabs",
|
|
486
|
+
"tool": "mm_Yva_tool",
|
|
487
|
+
"toolbar": "mm_Yva_toolbar",
|
|
488
|
+
"trace": "mm_Yva_trace",
|
|
489
|
+
"traceIdle": "mm_Yva_traceIdle",
|
|
490
|
+
"traceList": "mm_Yva_traceList",
|
|
491
|
+
"traceRow": "mm_Yva_traceRow",
|
|
492
|
+
"traceSummary": "mm_Yva_traceSummary",
|
|
493
|
+
"traceTool": "mm_Yva_traceTool"
|
|
494
|
+
};
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region src/client/panel.tsx
|
|
497
|
+
/**
|
|
498
|
+
* The browser view tab's content, mounted by the right sidebar into its
|
|
499
|
+
* content area under the 'browser-view' tab type.
|
|
500
|
+
*
|
|
501
|
+
* The shell owns the column, the chip, the close control and the switch between
|
|
502
|
+
* tabs; this file owns what is drawn inside one tab and scrolls inside it. It
|
|
503
|
+
* therefore has no title bar of its own and no "back" control - a page header
|
|
504
|
+
* in a sidebar tab would repeat the chip right above it - and it fills the
|
|
505
|
+
* height it is given instead of positioning itself against the viewport.
|
|
506
|
+
*
|
|
507
|
+
* The body is laid out like the shipped browser tab's chrome: one 38px toolbar
|
|
508
|
+
* holding the address display, the connection marker and the one control this
|
|
509
|
+
* plugin actually has - refresh the captured frame - then the frame itself,
|
|
510
|
+
* then the action trace. Nothing here claims a capability the host does not
|
|
511
|
+
* expose: there is no forward/back pair, no reload of the page (the host drives
|
|
512
|
+
* navigation, this side only observes it) and no "open in a new window",
|
|
513
|
+
* because the page lives in a Chromium process on the host.
|
|
514
|
+
*
|
|
515
|
+
* The refresh control and the state marker are the product's own atoms -
|
|
516
|
+
* IconRefreshOutlineRegular and StateDot from @deepseek-ai/dsh-client-ui-primitives,
|
|
517
|
+
* the same two the shipped browser tab's toolbar uses - so the chrome is drawn
|
|
518
|
+
* from one source rather than redrawn beside it. The package's Vite config
|
|
519
|
+
* inlines @deepseek-ai packages, which is what lets the jsdom body tests load
|
|
520
|
+
* that entry point (it imports its own stylesheets).
|
|
521
|
+
*
|
|
522
|
+
* Frame rendering: an <img> fed a base64 JPEG data URL, not a <canvas>. The host
|
|
523
|
+
* already decoded and re-encoded the frame (CDP gives it JPEG base64), so there
|
|
524
|
+
* are no pixels for this side to compose - a canvas would add a drawImage hop,
|
|
525
|
+
* a context lifecycle and an invalidation race for zero gain, while the image
|
|
526
|
+
* element decodes off the main thread and lets CSS own the aspect-ratio fit.
|
|
527
|
+
*/
|
|
528
|
+
/** Trace rows kept on screen; older tool calls scroll out of relevance. */
|
|
529
|
+
const TRACE_LIMIT = 5;
|
|
530
|
+
/** State before the host publishes anything. */
|
|
531
|
+
const EMPTY_STATE = {
|
|
532
|
+
tabs: [],
|
|
533
|
+
activeTabId: null,
|
|
534
|
+
running: false
|
|
535
|
+
};
|
|
536
|
+
/** Join truthy class names (CSS Modules maps are typed as plain records). */
|
|
537
|
+
function cx(...names) {
|
|
538
|
+
return names.filter((name) => typeof name === "string" && name.length > 0).join(" ");
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Render the browser view tab body.
|
|
542
|
+
* @param props - composed slot props.
|
|
543
|
+
* @returns the tab content.
|
|
544
|
+
*/
|
|
545
|
+
function BrowserViewPanel({ t, sessionId, liveTitle, socketFactory, location }) {
|
|
546
|
+
const [state, setState] = (0, react.useState)(EMPTY_STATE);
|
|
547
|
+
const [frame, setFrame] = (0, react.useState)(null);
|
|
548
|
+
const [traces, setTraces] = (0, react.useState)([]);
|
|
549
|
+
const [error, setError] = (0, react.useState)(null);
|
|
550
|
+
const [status, setStatus] = (0, react.useState)("connecting");
|
|
551
|
+
const socketRef = (0, react.useRef)(null);
|
|
552
|
+
/** Last active tab seen in a state push; a tab switch invalidates the picture. */
|
|
553
|
+
const lastActiveTabRef = (0, react.useRef)(null);
|
|
554
|
+
const factory = (0, react.useMemo)(() => socketFactory ?? ((handlers) => connectBrowserViewSocket(handlers, {
|
|
555
|
+
location,
|
|
556
|
+
sessionId
|
|
557
|
+
})), [
|
|
558
|
+
socketFactory,
|
|
559
|
+
location,
|
|
560
|
+
sessionId
|
|
561
|
+
]);
|
|
562
|
+
(0, react.useEffect)(() => {
|
|
563
|
+
const instance = factory({
|
|
564
|
+
onStatus: (next) => {
|
|
565
|
+
setStatus(next);
|
|
566
|
+
},
|
|
567
|
+
onState: (next) => {
|
|
568
|
+
if (lastActiveTabRef.current !== next.activeTabId) {
|
|
569
|
+
lastActiveTabRef.current = next.activeTabId;
|
|
570
|
+
setFrame(null);
|
|
571
|
+
}
|
|
572
|
+
setState(next);
|
|
573
|
+
},
|
|
574
|
+
onFrame: (next) => {
|
|
575
|
+
setError(null);
|
|
576
|
+
setFrame(next);
|
|
577
|
+
},
|
|
578
|
+
onAction: (trace) => {
|
|
579
|
+
setTraces((current) => [trace, ...current].slice(0, TRACE_LIMIT));
|
|
580
|
+
},
|
|
581
|
+
onError: (code, message) => {
|
|
582
|
+
setError({
|
|
583
|
+
code,
|
|
584
|
+
message
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
socketRef.current = instance;
|
|
589
|
+
return () => {
|
|
590
|
+
socketRef.current = null;
|
|
591
|
+
instance.close();
|
|
592
|
+
};
|
|
593
|
+
}, [factory]);
|
|
594
|
+
const activeTab = state.tabs.find((tab) => tab.id === state.activeTabId) ?? null;
|
|
595
|
+
const loading = activeTab?.loading === true || status !== "open";
|
|
596
|
+
const hostError = state.message !== void 0 && state.message.length > 0 ? {
|
|
597
|
+
code: "",
|
|
598
|
+
message: state.message
|
|
599
|
+
} : null;
|
|
600
|
+
const effectiveError = error ?? hostError;
|
|
601
|
+
const visibleFrame = effectiveError === null ? frame : null;
|
|
602
|
+
const dataUrl = visibleFrame === null ? null : `data:image/jpeg;base64,${visibleFrame.data}`;
|
|
603
|
+
const statusLabel = status !== "open" ? t("panel.status.connecting") : loading ? t("panel.status.loading") : t("panel.status.live");
|
|
604
|
+
const dotState = status !== "open" ? "idle" : loading ? "ongoing" : "done";
|
|
605
|
+
const pageTitle = activeTab === null || activeTab.title.length === 0 ? void 0 : activeTab.title;
|
|
606
|
+
const url = activeTab?.url ?? "";
|
|
607
|
+
(0, react.useEffect)(() => {
|
|
608
|
+
liveTitle?.set(sessionId, pageTitle);
|
|
609
|
+
return () => {
|
|
610
|
+
liveTitle?.set(sessionId, void 0);
|
|
611
|
+
};
|
|
612
|
+
}, [
|
|
613
|
+
liveTitle,
|
|
614
|
+
sessionId,
|
|
615
|
+
pageTitle
|
|
616
|
+
]);
|
|
617
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
618
|
+
className: panel_module_css_default.root,
|
|
619
|
+
"data-dsh-plugin": BROWSER_VIEW_PLUGIN,
|
|
620
|
+
"data-dsh-part": BROWSER_VIEW_PARTS.panel,
|
|
621
|
+
children: [
|
|
622
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
623
|
+
className: panel_module_css_default.toolbar,
|
|
624
|
+
"data-dsh-part": BROWSER_VIEW_PARTS.toolbar,
|
|
625
|
+
children: [
|
|
626
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
627
|
+
className: panel_module_css_default.addressBox,
|
|
628
|
+
"data-dsh-part": BROWSER_VIEW_PARTS.address,
|
|
629
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
630
|
+
className: panel_module_css_default.address,
|
|
631
|
+
type: "text",
|
|
632
|
+
readOnly: true,
|
|
633
|
+
value: url,
|
|
634
|
+
title: url.length > 0 ? url : void 0,
|
|
635
|
+
placeholder: t("panel.url.empty"),
|
|
636
|
+
"aria-label": t("panel.address.label"),
|
|
637
|
+
spellCheck: false,
|
|
638
|
+
onFocus: (event) => {
|
|
639
|
+
event.currentTarget.select();
|
|
640
|
+
},
|
|
641
|
+
onClick: (event) => {
|
|
642
|
+
event.currentTarget.select();
|
|
643
|
+
}
|
|
644
|
+
})
|
|
645
|
+
}),
|
|
646
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
647
|
+
className: panel_module_css_default.status,
|
|
648
|
+
"data-dsh-part": BROWSER_VIEW_PARTS.status,
|
|
649
|
+
"aria-live": "polite",
|
|
650
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, {
|
|
651
|
+
state: dotState,
|
|
652
|
+
size: 10
|
|
653
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
654
|
+
className: panel_module_css_default.statusText,
|
|
655
|
+
children: statusLabel
|
|
656
|
+
})]
|
|
657
|
+
}),
|
|
658
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
659
|
+
type: "button",
|
|
660
|
+
className: panel_module_css_default.tool,
|
|
661
|
+
title: t("panel.toolbar.refresh"),
|
|
662
|
+
"aria-label": t("panel.toolbar.refresh"),
|
|
663
|
+
disabled: activeTab === null,
|
|
664
|
+
onClick: () => {
|
|
665
|
+
socketRef.current?.send({
|
|
666
|
+
v: 1,
|
|
667
|
+
kind: "request-frame"
|
|
668
|
+
});
|
|
669
|
+
},
|
|
670
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconRefreshOutlineRegular, {})
|
|
671
|
+
})
|
|
672
|
+
]
|
|
673
|
+
}),
|
|
674
|
+
state.tabs.length > 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
675
|
+
className: panel_module_css_default.tabs,
|
|
676
|
+
role: "tablist",
|
|
677
|
+
"data-dsh-part": BROWSER_VIEW_PARTS.tabs,
|
|
678
|
+
children: state.tabs.map((tab) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
679
|
+
type: "button",
|
|
680
|
+
role: "tab",
|
|
681
|
+
"aria-selected": tab.id === state.activeTabId,
|
|
682
|
+
className: cx(panel_module_css_default.tab, tab.id === state.activeTabId && panel_module_css_default.tabActive),
|
|
683
|
+
title: tab.url,
|
|
684
|
+
onClick: () => {
|
|
685
|
+
socketRef.current?.send({
|
|
686
|
+
v: 1,
|
|
687
|
+
kind: "select-tab",
|
|
688
|
+
tabId: tab.id
|
|
689
|
+
});
|
|
690
|
+
},
|
|
691
|
+
children: tab.title.length > 0 ? tab.title : t("panel.tab.untitled")
|
|
692
|
+
}, tab.id))
|
|
693
|
+
}),
|
|
694
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
695
|
+
className: panel_module_css_default.content,
|
|
696
|
+
children: effectiveError !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
697
|
+
className: panel_module_css_default.error,
|
|
698
|
+
"data-dsh-part": BROWSER_VIEW_PARTS.error,
|
|
699
|
+
role: "alert",
|
|
700
|
+
children: [
|
|
701
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
702
|
+
className: panel_module_css_default.errorTitle,
|
|
703
|
+
children: t("panel.error.title")
|
|
704
|
+
}),
|
|
705
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
706
|
+
className: panel_module_css_default.errorBody,
|
|
707
|
+
children: effectiveError.message
|
|
708
|
+
}),
|
|
709
|
+
effectiveError.code.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
710
|
+
className: panel_module_css_default.errorCode,
|
|
711
|
+
children: effectiveError.code
|
|
712
|
+
})
|
|
713
|
+
]
|
|
714
|
+
}) : dataUrl === null || visibleFrame === null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
715
|
+
className: panel_module_css_default.empty,
|
|
716
|
+
"data-dsh-part": BROWSER_VIEW_PARTS.empty,
|
|
717
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
718
|
+
className: panel_module_css_default.emptyTitle,
|
|
719
|
+
children: t("panel.empty.title")
|
|
720
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
721
|
+
className: panel_module_css_default.emptyHint,
|
|
722
|
+
children: t("panel.empty.hint")
|
|
723
|
+
})]
|
|
724
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
725
|
+
className: panel_module_css_default.frame,
|
|
726
|
+
"data-dsh-part": BROWSER_VIEW_PARTS.frame,
|
|
727
|
+
src: dataUrl,
|
|
728
|
+
alt: t("panel.frame.alt"),
|
|
729
|
+
width: visibleFrame.width,
|
|
730
|
+
height: visibleFrame.height,
|
|
731
|
+
draggable: false
|
|
732
|
+
})
|
|
733
|
+
}),
|
|
734
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("footer", {
|
|
735
|
+
className: panel_module_css_default.trace,
|
|
736
|
+
"data-dsh-part": BROWSER_VIEW_PARTS.trace,
|
|
737
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
738
|
+
className: panel_module_css_default.traceList,
|
|
739
|
+
children: traces.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
740
|
+
className: panel_module_css_default.traceIdle,
|
|
741
|
+
children: t("panel.trace.idle")
|
|
742
|
+
}) : traces.map((trace, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
743
|
+
className: panel_module_css_default.traceRow,
|
|
744
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
745
|
+
className: panel_module_css_default.traceTool,
|
|
746
|
+
children: trace.tool
|
|
747
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
748
|
+
className: panel_module_css_default.traceSummary,
|
|
749
|
+
children: trace.summary
|
|
750
|
+
})]
|
|
751
|
+
}, `${trace.at}-${index}`))
|
|
752
|
+
})
|
|
753
|
+
})
|
|
754
|
+
]
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
//#endregion
|
|
758
|
+
//#region src/client/guide-icon.tsx
|
|
759
|
+
/**
|
|
760
|
+
* Render the guide glyph.
|
|
761
|
+
* @param props - square edge in px (the guide passes 22 or 26) and a layout class.
|
|
762
|
+
* @returns the window-and-cursor mark.
|
|
763
|
+
*/
|
|
764
|
+
function BrowserViewGuideGlyph({ size = 16, className }) {
|
|
765
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
766
|
+
width: size,
|
|
767
|
+
height: size,
|
|
768
|
+
viewBox: "0 0 16 16",
|
|
769
|
+
className,
|
|
770
|
+
"aria-hidden": "true",
|
|
771
|
+
focusable: "false",
|
|
772
|
+
children: [
|
|
773
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
774
|
+
x: "1.75",
|
|
775
|
+
y: "2.25",
|
|
776
|
+
width: "12.5",
|
|
777
|
+
height: "11.5",
|
|
778
|
+
rx: "1.75",
|
|
779
|
+
fill: "none",
|
|
780
|
+
stroke: "currentColor",
|
|
781
|
+
strokeWidth: "1.2"
|
|
782
|
+
}),
|
|
783
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
784
|
+
d: "M1.75 5.75h12.5",
|
|
785
|
+
fill: "none",
|
|
786
|
+
stroke: "currentColor",
|
|
787
|
+
strokeWidth: "1.2"
|
|
788
|
+
}),
|
|
789
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
790
|
+
cx: "3.9",
|
|
791
|
+
cy: "4",
|
|
792
|
+
r: "0.7",
|
|
793
|
+
fill: "currentColor"
|
|
794
|
+
}),
|
|
795
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
796
|
+
d: "M7.4 8.15l3.85 1.7-1.6.65-.7 1.65z",
|
|
797
|
+
fill: "currentColor"
|
|
798
|
+
})
|
|
799
|
+
]
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
//#endregion
|
|
803
|
+
//#region src/client/tab-type.ts
|
|
804
|
+
/** What this plugin's tabs are, and what openTabIn/openTab name. */
|
|
805
|
+
const BROWSER_VIEW_TAB_KIND = "browser-view";
|
|
806
|
+
/** This implementation's identity in the tab system; also the keyed slot dispatch key. */
|
|
807
|
+
const BROWSER_VIEW_TAB_ID = "@linxin666/dsh-client-ui-browser-view";
|
|
808
|
+
/** Identity of this type's capsule on the guide page, stable within the provider. */
|
|
809
|
+
const BROWSER_VIEW_GUIDE_ENTRY_ID = "open";
|
|
810
|
+
/**
|
|
811
|
+
* Build stage one of the registration.
|
|
812
|
+
* @param t - translate function of this plugin's dictionary.
|
|
813
|
+
* @returns the static tab type the registry keeps.
|
|
814
|
+
*/
|
|
815
|
+
function browserViewTabDefinition(t) {
|
|
816
|
+
return {
|
|
817
|
+
id: BROWSER_VIEW_TAB_ID,
|
|
818
|
+
kind: BROWSER_VIEW_TAB_KIND,
|
|
819
|
+
keepMounted: true,
|
|
820
|
+
priority: "extension",
|
|
821
|
+
title: () => t("tab.title"),
|
|
822
|
+
guide: [{
|
|
823
|
+
id: BROWSER_VIEW_GUIDE_ENTRY_ID,
|
|
824
|
+
order: 40,
|
|
825
|
+
title: () => t("tab.title"),
|
|
826
|
+
description: () => t("guide.description"),
|
|
827
|
+
icon: BrowserViewGuideGlyph
|
|
828
|
+
}]
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
//#endregion
|
|
832
|
+
//#region src/client/tab-title.tsx
|
|
833
|
+
/**
|
|
834
|
+
* The browser view's chip text.
|
|
835
|
+
*
|
|
836
|
+
* The shell owns the right-sidebar chip: its box, its close and hidden
|
|
837
|
+
* controls, the active highlight and the switch between tabs. This component
|
|
838
|
+
* draws only what sits inside it - the browser mark and the name - which is why
|
|
839
|
+
* it carries no state of its own.
|
|
840
|
+
*
|
|
841
|
+
* The name prefers the page the body is streaming, read from the published
|
|
842
|
+
* channel (live-title.ts), and falls back to this plugin's own name before the
|
|
843
|
+
* first state push: a chip that says "Checkout" is more useful than one that
|
|
844
|
+
* says "Browser view", but an empty chip is worse than either.
|
|
845
|
+
*/
|
|
846
|
+
/**
|
|
847
|
+
* Decorative browser-window mark; inline so the chip carries no icon dependency.
|
|
848
|
+
* @returns the glyph.
|
|
849
|
+
*/
|
|
850
|
+
function BrowserViewMark() {
|
|
851
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
852
|
+
className: panel_module_css_default.tabTitleMark,
|
|
853
|
+
viewBox: "0 0 16 16",
|
|
854
|
+
"aria-hidden": "true",
|
|
855
|
+
focusable: "false",
|
|
856
|
+
children: [
|
|
857
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
858
|
+
x: "1.75",
|
|
859
|
+
y: "2.25",
|
|
860
|
+
width: "12.5",
|
|
861
|
+
height: "11.5",
|
|
862
|
+
rx: "1.75",
|
|
863
|
+
fill: "none",
|
|
864
|
+
stroke: "currentColor",
|
|
865
|
+
strokeWidth: "1.5"
|
|
866
|
+
}),
|
|
867
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
868
|
+
d: "M1.75 5.75h12.5",
|
|
869
|
+
fill: "none",
|
|
870
|
+
stroke: "currentColor",
|
|
871
|
+
strokeWidth: "1.5"
|
|
872
|
+
}),
|
|
873
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
874
|
+
d: "M7.4 8.15l3.85 1.7-1.6.65-.7 1.65z",
|
|
875
|
+
fill: "currentColor"
|
|
876
|
+
})
|
|
877
|
+
]
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Render the chip contents.
|
|
882
|
+
* @param props - composed slot props.
|
|
883
|
+
* @returns the mark and the tab's name.
|
|
884
|
+
*/
|
|
885
|
+
function BrowserViewTabTitle({ t, sessionId, liveTitle }) {
|
|
886
|
+
const pageTitle = (0, react.useSyncExternalStore)((0, react.useCallback)((listener) => liveTitle?.subscribe(listener) ?? (() => {}), [liveTitle]), (0, react.useCallback)(() => liveTitle?.get(sessionId), [liveTitle, sessionId]), () => void 0);
|
|
887
|
+
const label = pageTitle !== void 0 && pageTitle.length > 0 ? pageTitle : t("tab.title");
|
|
888
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
889
|
+
className: panel_module_css_default.tabTitle,
|
|
890
|
+
"data-dsh-plugin": BROWSER_VIEW_PLUGIN,
|
|
891
|
+
"data-dsh-part": BROWSER_VIEW_PARTS.tabTitle,
|
|
892
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BrowserViewMark, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
893
|
+
className: panel_module_css_default.tabTitleText,
|
|
894
|
+
children: label
|
|
895
|
+
})]
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
//#endregion
|
|
899
|
+
//#region src/client/index.ts
|
|
900
|
+
/** Dictionary namespace owned by this plugin. */
|
|
901
|
+
const NS = "browser-view";
|
|
902
|
+
/** Services required by this plugin. */
|
|
903
|
+
const inject = [
|
|
904
|
+
"slots",
|
|
905
|
+
"locale",
|
|
906
|
+
"sidebarRightTabs"
|
|
907
|
+
];
|
|
908
|
+
/**
|
|
909
|
+
* Register the browser-view tab type and its surfaces.
|
|
910
|
+
* @param ctx - client root context.
|
|
911
|
+
*/
|
|
912
|
+
function apply(ctx) {
|
|
913
|
+
ctx.effect(() => {
|
|
914
|
+
try {
|
|
915
|
+
return ctx.locale.register(NS, {
|
|
916
|
+
zh,
|
|
917
|
+
en
|
|
918
|
+
});
|
|
919
|
+
} catch {
|
|
920
|
+
return () => {};
|
|
921
|
+
}
|
|
922
|
+
}, "browser-view: dictionaries");
|
|
923
|
+
let translate;
|
|
924
|
+
try {
|
|
925
|
+
translate = ctx.locale.bind(NS);
|
|
926
|
+
} catch {}
|
|
927
|
+
const copy = (key) => translate?.(key) ?? zh[key];
|
|
928
|
+
ctx.effect(() => {
|
|
929
|
+
try {
|
|
930
|
+
return ctx.sidebarRightTabs.register(browserViewTabDefinition(copy));
|
|
931
|
+
} catch {
|
|
932
|
+
return () => {};
|
|
933
|
+
}
|
|
934
|
+
}, "browser-view: tab type");
|
|
935
|
+
const liveTitle = createLiveTitleStore();
|
|
936
|
+
ctx.slots.inject("sidebar.right.pane.tab", () => {
|
|
937
|
+
try {
|
|
938
|
+
return ctx.slots.register({
|
|
939
|
+
name: "sidebar.right.pane.tab",
|
|
940
|
+
key: BROWSER_VIEW_TAB_ID,
|
|
941
|
+
locale: NS,
|
|
942
|
+
inject: (sessionId) => ({
|
|
943
|
+
sessionId,
|
|
944
|
+
liveTitle
|
|
945
|
+
})
|
|
946
|
+
}, BrowserViewPanel);
|
|
947
|
+
} catch {
|
|
948
|
+
return () => {};
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
ctx.slots.inject("sidebar.right.pane.tab.title", () => {
|
|
952
|
+
try {
|
|
953
|
+
return ctx.slots.register({
|
|
954
|
+
name: "sidebar.right.pane.tab.title",
|
|
955
|
+
key: BROWSER_VIEW_TAB_ID,
|
|
956
|
+
locale: NS,
|
|
957
|
+
inject: (sessionId) => ({
|
|
958
|
+
sessionId,
|
|
959
|
+
liveTitle
|
|
960
|
+
})
|
|
961
|
+
}, BrowserViewTabTitle);
|
|
962
|
+
} catch {
|
|
963
|
+
return () => {};
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
//#endregion
|
|
968
|
+
exports.apply = apply;
|
|
969
|
+
exports.inject = inject;
|
|
970
|
+
return module.exports;
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
//# sourceMappingURL=client.js.map
|