dsh-vt-web-chat 0.0.0-stage → 1.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vontean
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,50 @@
1
- # Temporary Holding Version
1
+ # dsh-vt-web-chat · 网页对话
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 在 DSH 桌面版的「新会话」正下方加一行「网页对话」入口,点开后在主内容区整页显示
4
+ `chat.deepseek.com`,用官网自己的对话历史,并记住上次停留的对话。
5
+
6
+ ## 它改了什么
7
+
8
+ - 侧栏「新会话」下面多一行「网页对话」,点击后在主内容区打开整页网页对话;
9
+ - 载体是桌面壳的 guest 租约桥(Electron `<webview>`)。官网返回
10
+ `frame-ancestors 'none'`,普通 iframe 无法承载,租约是主进程唯一放行的建法;
11
+ - 离开面板会释放 guest,回来时按本机记录的上次对话地址恢复;
12
+ - 纯 Web 环境(没有桌面桥)显示说明卡,并可「在浏览器打开」;
13
+ - 入口文案与面板文案随宿主语言切换(zh / en)。
14
+
15
+ ## 已知限制
16
+
17
+ - **登录不共享**:内嵌页是独立 cookie 分区,无法使用 DSH 的账号凭证。可以直接在页面里
18
+ 登录,但分区是进程级的,**重启 DSH 后需要重新登录**。
19
+ - 离开面板会销毁页面内存(未发送的草稿会丢),只恢复上次对话地址。
20
+ - 桌面壳统一拒绝下载、权限请求与原生弹窗;依赖这些能力的站点功能不可用。
21
+ - 不修改「新会话」按钮:该按钮由内置侧栏直接绘制,没有插件插槽。
22
+
23
+ ## 安装
24
+
25
+ 1. **插件市场(推荐)**:在「插件 → 发现 → 添加索引源」里填入
26
+ `https://vontean.github.io/vt-dsh-plugin/index.json`,找到「网页对话」点安装。
27
+ 2. **npm**:`dsh plugin --profile <profile> add dsh-vt-web-chat@1.0.1`。
28
+ 3. **Release tarball**:从 GitHub Release 下载 `.tgz`,再执行
29
+ `dsh plugin --profile <profile> add <该 .tgz 的本地路径或 URL>`。
30
+
31
+ 安装或升级后需要重启 DSH;只刷新页面不生效。
32
+
33
+ ## 支持的 DSH 版本
34
+
35
+ `engines.dsh` = `>=0.2.1-rc.5 <0.3.0`。超出范围时,加载器会在插件装载前拒绝,
36
+ 不会出现「装上了但只加载一半」的状态。
37
+
38
+ ## 安全边界
39
+
40
+ - 插件代码在用户进程内运行,**没有沙箱**;只安装你信任的来源。
41
+ - 插件只增加一个界面入口:不注册 Host 服务、工具、提示词段落或路由。内嵌页面属于
42
+ 用户侧展示状态,不会进入模型请求。
43
+ - 内嵌页面的网络访问由页面自身完成,与 DSH 的模型请求链路相互独立。
44
+
45
+ ## 开发
46
+
47
+ - `index.js`:Host 半侧,空实现;客户端 bundle 通过这个 Loader 入口被发现。
48
+ - `client.js`:全部功能在客户端。模块 id、`PLUGIN_ID`、`VERSION`、日志前缀与存储 key
49
+ 都从同一处常量派生,改包名时只需改 `PLUGIN_ID`。
50
+ - 本目录没有额外的设计 / 开发文档;行为说明见本文件与 `client.js` 头部注释。
package/client.js ADDED
@@ -0,0 +1,808 @@
1
+ /**
2
+ * dsh-vt-web-chat — client half.
3
+ *
4
+ * One sidebar entry (the same `sidebar.panellist` + `main` mechanism the Plugins
5
+ * and Scheduled tasks rows use) and one full main-area page hosting
6
+ * `chat.deepseek.com`.
7
+ *
8
+ * Why a webview and not an iframe: the site answers with
9
+ * `content-security-policy: frame-ancestors 'none'`, so no page may frame it.
10
+ * The desktop shell exposes `globalThis.dshDesktop.browser` — the same guest
11
+ * lease bridge its built-in sidebar browser uses. The main process rejects every
12
+ * webview that does not carry an approved lease, so the only legal sequence is
13
+ * acquire → create an element named by the lease with its partition → load.
14
+ *
15
+ * Failure containment is a hard rule here. DSH has no error boundary around a
16
+ * slot entry, and an escaping error in the `main` slot unmounts the whole
17
+ * application UI. Every guest call is attached-checked and wrapped, and a
18
+ * rendering boundary keeps a crash inside this panel. A dead guest becomes a
19
+ * retry card, never a blank window.
20
+ *
21
+ * Leaving the panel releases the guest, so the page remembers the last
22
+ * conversation URL and reopens there instead of starting a new chat each time.
23
+ */
24
+ /** Package identity: one source for the module id and every log/storage prefix. */
25
+ const PLUGIN_ID = 'dsh-vt-web-chat';
26
+ /** Must equal `version` in package.json; printed once in the mount trace below. */
27
+ const VERSION = '1.0.1';
28
+
29
+ // Mount trace: one line naming the loaded build (DevTools → verbose level).
30
+ console.debug(`[${PLUGIN_ID}] v${VERSION}`);
31
+
32
+ window.__ModuleLoader__.load({
33
+ id: PLUGIN_ID,
34
+ factory(require) {
35
+ 'use strict';
36
+
37
+ const reactModule = require('react');
38
+ const React =
39
+ reactModule !== null && typeof reactModule.createElement === 'function'
40
+ ? reactModule
41
+ : reactModule.default;
42
+
43
+ /** Locale namespace owned by this plugin. */
44
+ const NS = 'vtWebChat';
45
+ /** `main` cell key and `sidebar.panellist` id — the two must match. */
46
+ const PANEL_ID = 'vt-web-chat';
47
+ const CHAT_URL = 'https://chat.deepseek.com/';
48
+ /**
49
+ * Storage identity for the guest partition. The main process keeps one
50
+ * partition per identity for the lifetime of the process, so leaving and
51
+ * re-entering the panel keeps the page and its login.
52
+ */
53
+ const PARTITION_KEY = 'panel:vt-web-chat';
54
+ /** Last visited conversation, remembered across panel switches and reloads. */
55
+ const STORAGE_KEY = `${PLUGIN_ID}:last-url`;
56
+ /** Paths that are not a conversation: a brand-new chat, or an auth page. */
57
+ const AUTH_PATHS = new Set(['/sign_in', '/login', '/signup', '/auth']);
58
+ /** A guest that never reaches `dom-ready` is reported instead of hanging. */
59
+ const WATCHDOG_MS = 15000;
60
+
61
+ const DICT = {
62
+ zh: {
63
+ entry: '网页对话',
64
+ title: 'DeepSeek 网页对话',
65
+ loading: '正在加载网页对话…',
66
+ failed: '网页对话没有打开',
67
+ timeout: '网页对话没有启动',
68
+ crashed: '内嵌页面已退出',
69
+ retry: '重试',
70
+ unsupportedTitle: '需要桌面版 App',
71
+ unsupportedBody: '网页对话依赖桌面端的内嵌浏览器。当前环境请在浏览器新标签中打开。',
72
+ openExternal: '在浏览器打开',
73
+ signInHint: '登录状态只在本次运行中保留;重启 DSH 后需要重新登录。',
74
+ signInAction: '在系统浏览器登录',
75
+ },
76
+ en: {
77
+ entry: 'Web Chat',
78
+ title: 'DeepSeek Web Chat',
79
+ loading: 'Loading Web Chat…',
80
+ failed: 'Web Chat did not open',
81
+ timeout: 'Web Chat did not start',
82
+ crashed: 'The embedded page exited',
83
+ retry: 'Retry',
84
+ unsupportedTitle: 'Desktop app required',
85
+ unsupportedBody:
86
+ 'Web Chat uses the desktop embedded browser. Open it in a browser tab instead.',
87
+ openExternal: 'Open in browser',
88
+ signInHint:
89
+ 'Your sign-in lasts only for this app run; restarting DSH requires signing in again.',
90
+ signInAction: 'Sign in with your browser',
91
+ },
92
+ };
93
+
94
+ /** Set by `apply`; components fall back to it when slot injection is absent. */
95
+ let translate = (key) => key;
96
+ let localeService = undefined;
97
+
98
+ /**
99
+ * Re-render when the active locale changes, so panel copy follows the host.
100
+ * @param locale - Client locale service, if available.
101
+ * @returns the current revision; the value itself is not read.
102
+ */
103
+ function useLocaleRevision(locale) {
104
+ const [revision, setRevision] = React.useState(0);
105
+ React.useEffect(() => {
106
+ if (locale === undefined || locale === null || typeof locale.subscribe !== 'function') {
107
+ return undefined;
108
+ }
109
+ return locale.subscribe(() => setRevision((value) => value + 1));
110
+ }, [locale]);
111
+ return revision;
112
+ }
113
+
114
+ /**
115
+ * Parse a chat.deepseek.com page URL.
116
+ * @param value - candidate URL.
117
+ * @returns the parsed URL for the site origin, or undefined.
118
+ */
119
+ function parseChatUrl(value) {
120
+ if (typeof value !== 'string' || value.length === 0 || value.length > 4096) return undefined;
121
+ try {
122
+ const url = new URL(value);
123
+ if (url.protocol !== 'https:' || url.hostname !== 'chat.deepseek.com') return undefined;
124
+ if (url.username !== '' || url.password !== '') return undefined;
125
+ return url;
126
+ } catch {
127
+ return undefined;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Whether a URL is deep enough to be a conversation page.
133
+ * @param url - parsed chat URL, possibly undefined.
134
+ * @returns true for a conversation, false for the new-chat root or an auth page.
135
+ */
136
+ function isConversation(url) {
137
+ if (url === undefined) return false;
138
+ const path = url.pathname.replace(/\/+$/u, '') || '/';
139
+ return !AUTH_PATHS.has(path) && path !== '/';
140
+ }
141
+
142
+ /**
143
+ * Whether the guest currently shows a sign-in page.
144
+ * @param raw - current page URL reported by the guest.
145
+ * @returns true for the known auth paths.
146
+ */
147
+ function isAuthUrl(raw) {
148
+ const url = parseChatUrl(raw);
149
+ if (url === undefined) return false;
150
+ const path = url.pathname.replace(/\/+$/u, '') || '/';
151
+ return AUTH_PATHS.has(path);
152
+ }
153
+
154
+ /**
155
+ * Read the conversation remembered from the last visit.
156
+ * @returns the URL to open; the site root when nothing usable is remembered.
157
+ */
158
+ function rememberedTarget() {
159
+ try {
160
+ const saved = parseChatUrl(window.localStorage.getItem(STORAGE_KEY));
161
+ return isConversation(saved) ? saved.toString() : CHAT_URL;
162
+ } catch {
163
+ return CHAT_URL;
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Remember where the guest currently is.
169
+ *
170
+ * A brand-new chat clears the memory so the next visit starts clean. An auth
171
+ * page never overwrites it, so a login detour does not lose the conversation.
172
+ * @param raw - current page URL reported by the guest.
173
+ */
174
+ function rememberTarget(raw) {
175
+ const url = parseChatUrl(raw);
176
+ if (url === undefined) return;
177
+ try {
178
+ if (isConversation(url)) window.localStorage.setItem(STORAGE_KEY, url.toString());
179
+ else if ((url.pathname.replace(/\/+$/u, '') || '/') === '/') {
180
+ window.localStorage.removeItem(STORAGE_KEY);
181
+ }
182
+ } catch {
183
+ /* storage unavailable: the panel still works, it just forgets */
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Open a chat URL in the system browser. The desktop shell routes
189
+ * `window.open` for http(s) to the OS browser and denies every other window.
190
+ * @param url - http(s) target.
191
+ */
192
+ function openExternally(url) {
193
+ try {
194
+ window.open(url, '_blank', 'noopener');
195
+ } catch {
196
+ /* a blocked popup leaves the panel usable */
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Whether the guest element is still in the document. Electron's webview
202
+ * methods throw once it is detached, so this gates every guest call.
203
+ * @param element - webview element.
204
+ * @returns true while the element can still host a guest.
205
+ */
206
+ function attached(element) {
207
+ try {
208
+ return element.isConnected === true;
209
+ } catch {
210
+ return false;
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Guest URL, or undefined when the element cannot report one.
216
+ * @param element - webview element.
217
+ * @returns the URL string, or undefined.
218
+ */
219
+ function readUrl(element) {
220
+ if (!attached(element)) return undefined;
221
+ try {
222
+ const url = element.getURL();
223
+ return typeof url === 'string' && url.length > 0 ? url : undefined;
224
+ } catch {
225
+ return undefined;
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Navigate the guest without ever throwing.
231
+ * @param element - webview element.
232
+ * @param url - target URL.
233
+ * @returns false when the guest is gone, so the caller can report it.
234
+ */
235
+ function navigate(element, url) {
236
+ if (!attached(element)) return false;
237
+ try {
238
+ const pending = element.loadURL(url);
239
+ if (pending !== undefined && pending !== null && typeof pending.catch === 'function') {
240
+ pending.catch(() => {});
241
+ }
242
+ return true;
243
+ } catch {
244
+ return false;
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Sidebar glyph: a speech bubble drawn on currentColor so the sidebar's
250
+ * active state owns the ink. Sized for its 16/18px seat.
251
+ * @param props - size supplied by the panel list.
252
+ * @returns the glyph element.
253
+ */
254
+ function Glyph({ size = 16 }) {
255
+ return React.createElement(
256
+ 'svg',
257
+ {
258
+ width: size,
259
+ height: size,
260
+ viewBox: '0 0 24 24',
261
+ fill: 'none',
262
+ 'aria-hidden': 'true',
263
+ focusable: 'false',
264
+ },
265
+ React.createElement('path', {
266
+ d: 'M20.25 11.5c0 4.28-3.7 7.75-8.25 7.75-.53 0-1.05-.05-1.55-.14l-4.1 1.9c-.6.28-1.26-.22-1.18-.87l.5-3.93C4.4 14.9 3.75 13.27 3.75 11.5c0-4.28 3.7-7.75 8.25-7.75s8.25 3.47 8.25 7.75Z',
267
+ stroke: 'currentColor',
268
+ strokeWidth: 1.3,
269
+ strokeLinejoin: 'round',
270
+ }),
271
+ React.createElement('path', {
272
+ d: 'M8.5 11.5h.01M12 11.5h.01M15.5 11.5h.01',
273
+ stroke: 'currentColor',
274
+ strokeWidth: 1.6,
275
+ strokeLinecap: 'round',
276
+ }),
277
+ );
278
+ }
279
+
280
+ const styles = {
281
+ root: {
282
+ display: 'flex',
283
+ flexDirection: 'column',
284
+ height: '100%',
285
+ minHeight: '0',
286
+ background: 'var(--dsw-alias-bg-base)',
287
+ color: 'var(--dsw-alias-label-primary)',
288
+ },
289
+ host: {
290
+ position: 'relative',
291
+ flex: '1',
292
+ minHeight: '0',
293
+ display: 'flex',
294
+ },
295
+ guest: {
296
+ width: '100%',
297
+ height: '100%',
298
+ border: '0',
299
+ background: 'transparent',
300
+ display: 'flex',
301
+ },
302
+ overlay: {
303
+ position: 'absolute',
304
+ inset: '0',
305
+ zIndex: '1',
306
+ display: 'flex',
307
+ flexDirection: 'column',
308
+ alignItems: 'center',
309
+ justifyContent: 'center',
310
+ gap: '10px',
311
+ padding: '24px',
312
+ textAlign: 'center',
313
+ color: 'var(--dsw-alias-label-tertiary)',
314
+ fontSize: '12px',
315
+ lineHeight: '18px',
316
+ background: 'var(--dsw-alias-bg-base)',
317
+ },
318
+ overlayTitle: {
319
+ color: 'var(--dsw-alias-label-primary)',
320
+ fontSize: '13px',
321
+ lineHeight: '20px',
322
+ },
323
+ actions: {
324
+ display: 'flex',
325
+ alignItems: 'center',
326
+ gap: '8px',
327
+ },
328
+ button: {
329
+ color: 'var(--dsw-alias-label-primary)',
330
+ background: 'var(--dsw-alias-bg-layer-1)',
331
+ border: '.5px solid var(--dsw-alias-border-l2)',
332
+ borderRadius: 'var(--dsw-radius-sm)',
333
+ padding: '4px 12px',
334
+ cursor: 'pointer',
335
+ fontSize: '12px',
336
+ lineHeight: '18px',
337
+ },
338
+ linkButton: {
339
+ border: '0',
340
+ padding: '0',
341
+ background: 'transparent',
342
+ color: 'var(--dsw-alias-brand-primary)',
343
+ cursor: 'pointer',
344
+ fontSize: '12px',
345
+ lineHeight: '18px',
346
+ },
347
+ signInBar: {
348
+ display: 'flex',
349
+ alignItems: 'center',
350
+ gap: '8px',
351
+ flex: 'none',
352
+ padding: '6px 12px',
353
+ borderBottom: '.5px solid var(--dsw-alias-border-l1)',
354
+ background: 'var(--dsw-alias-bg-layer-1)',
355
+ color: 'var(--dsw-alias-label-secondary)',
356
+ fontSize: '12px',
357
+ lineHeight: '18px',
358
+ },
359
+ signInText: {
360
+ flex: '1',
361
+ minWidth: '0',
362
+ },
363
+ };
364
+
365
+ /**
366
+ * Keeps a rendering failure inside this panel. DSH has no boundary of its
367
+ * own around slot entries: an escaping error unmounts the root slot, which
368
+ * is the whole application UI.
369
+ */
370
+ class PanelBoundary extends React.Component {
371
+ constructor(props) {
372
+ super(props);
373
+ this.state = { failure: undefined };
374
+ }
375
+
376
+ static getDerivedStateFromError(error) {
377
+ return { failure: String((error && error.message) || error) };
378
+ }
379
+
380
+ componentDidCatch(error) {
381
+ try {
382
+ console.error(`${PLUGIN_ID}: panel render failed`, error);
383
+ } catch {
384
+ /* console unavailable */
385
+ }
386
+ }
387
+
388
+ render() {
389
+ if (this.state.failure !== undefined) {
390
+ const t = this.props.t;
391
+ return React.createElement(
392
+ 'div',
393
+ { style: styles.root },
394
+ React.createElement(
395
+ 'div',
396
+ { style: styles.overlay },
397
+ React.createElement('div', { style: styles.overlayTitle }, t('failed')),
398
+ React.createElement('div', null, this.state.failure),
399
+ React.createElement(
400
+ 'div',
401
+ { style: styles.actions },
402
+ React.createElement(
403
+ 'button',
404
+ {
405
+ type: 'button',
406
+ style: styles.button,
407
+ onClick: () => openExternally(CHAT_URL),
408
+ },
409
+ t('openExternal'),
410
+ ),
411
+ ),
412
+ ),
413
+ );
414
+ }
415
+ return this.props.children ?? null;
416
+ }
417
+ }
418
+
419
+ /**
420
+ * The global Web Chat panel: a guest webview filling the main column.
421
+ *
422
+ * The guest is created only after the lease resolves, and it is mounted with
423
+ * `name`/`partition`/`src` already set, because the main process inspects
424
+ * exactly that bootstrap src when it approves the attachment. The first load
425
+ * goes to the remembered conversation; navigation events keep that memory
426
+ * current. A dead guest (crash, destroy, failed start) turns into a retry
427
+ * card inside the panel; cleanup releases the lease and never calls into a
428
+ * detached element.
429
+ * @param props - slot props; `t` and `locale` arrive through registration.
430
+ * @returns the panel element tree.
431
+ */
432
+ function ChatPanel(props) {
433
+ const t = props.t ?? translate;
434
+ const locale = props.locale ?? localeService;
435
+ useLocaleRevision(locale);
436
+
437
+ const hostRef = React.useRef(null);
438
+ const lastUrlRef = React.useRef(undefined);
439
+ const [phase, setPhase] = React.useState('loading');
440
+ const [failure, setFailure] = React.useState(undefined);
441
+ const [authPage, setAuthPage] = React.useState(false);
442
+ const [attempt, setAttempt] = React.useState(0);
443
+
444
+ const retry = React.useCallback(() => {
445
+ try {
446
+ setPhase('loading');
447
+ setFailure(undefined);
448
+ setAuthPage(false);
449
+ setAttempt((value) => value + 1);
450
+ } catch {
451
+ /* the panel is gone */
452
+ }
453
+ }, []);
454
+
455
+ React.useEffect(() => {
456
+ const host = hostRef.current;
457
+ const bridge = globalThis.dshDesktop?.browser;
458
+ if (host === null) return undefined;
459
+ if (bridge === undefined) {
460
+ try {
461
+ setPhase('unsupported');
462
+ } catch {
463
+ /* the panel is gone */
464
+ }
465
+ return undefined;
466
+ }
467
+
468
+ let disposed = false;
469
+ let unsubscribeOpen;
470
+ let lease;
471
+ let watchdog;
472
+ let started = false;
473
+ const element = document.createElement('webview');
474
+ const initialTarget = rememberedTarget();
475
+ let restoring = initialTarget !== CHAT_URL;
476
+
477
+ Object.assign(element.style, styles.guest);
478
+ element.setAttribute('allowpopups', '');
479
+
480
+ /** Report a guest failure inside the panel; never throw. */
481
+ const fail = (error) => {
482
+ if (disposed) return;
483
+ try {
484
+ setPhase('failed');
485
+ setFailure(String((error && error.message) || error));
486
+ } catch {
487
+ /* the panel is gone */
488
+ }
489
+ };
490
+
491
+ /** Remember a URL reported by the guest and refresh the sign-in notice. */
492
+ const remember = (raw) => {
493
+ const url = parseChatUrl(raw);
494
+ if (url === undefined) return;
495
+ lastUrlRef.current = url.toString();
496
+ rememberTarget(url.toString());
497
+ try {
498
+ setAuthPage(isAuthUrl(url.toString()));
499
+ } catch {
500
+ /* the panel is gone */
501
+ }
502
+ };
503
+
504
+ const clearWatchdog = () => {
505
+ if (watchdog !== undefined) {
506
+ clearTimeout(watchdog);
507
+ watchdog = undefined;
508
+ }
509
+ };
510
+
511
+ const onDomReady = () => {
512
+ started = true;
513
+ clearWatchdog();
514
+ if (!navigate(element, initialTarget)) {
515
+ fail(new Error(t('crashed')));
516
+ return;
517
+ }
518
+ remember(initialTarget);
519
+ };
520
+
521
+ const onStopLoading = () => {
522
+ if (disposed) return;
523
+ const raw = readUrl(element);
524
+ if (raw !== undefined) remember(raw);
525
+ restoring = false;
526
+ try {
527
+ setPhase('ready');
528
+ setFailure(undefined);
529
+ } catch {
530
+ /* the panel is gone */
531
+ }
532
+ };
533
+
534
+ const onNavigate = () => {
535
+ if (disposed) return;
536
+ remember(readUrl(element));
537
+ };
538
+
539
+ const onNavigateInPage = (event) => {
540
+ if (disposed || event?.isMainFrame !== true) return;
541
+ onNavigate();
542
+ };
543
+
544
+ const onFailLoad = (event) => {
545
+ if (disposed || event?.isMainFrame !== true) return;
546
+ // -3 is ERR_ABORTED: a superseded navigation, not a failure.
547
+ if (event.errorCode === -3) return;
548
+ if (restoring) {
549
+ // The remembered conversation is gone or unreachable; start clean.
550
+ restoring = false;
551
+ if (!navigate(element, CHAT_URL)) fail(new Error(t('crashed')));
552
+ else remember(CHAT_URL);
553
+ return;
554
+ }
555
+ fail(event.errorDescription ?? event.errorCode);
556
+ };
557
+
558
+ /** The guest process exited or the guest was torn down underneath us. */
559
+ const onGuestGone = () => {
560
+ if (disposed) return;
561
+ fail(new Error(t('crashed')));
562
+ };
563
+
564
+ const listeners = [
565
+ ['dom-ready', onDomReady],
566
+ ['did-stop-loading', onStopLoading],
567
+ ['did-navigate', onNavigate],
568
+ ['did-navigate-in-page', onNavigateInPage],
569
+ ['did-fail-load', onFailLoad],
570
+ ['render-process-gone', onGuestGone],
571
+ ['destroyed', onGuestGone],
572
+ ];
573
+
574
+ try {
575
+ for (const [type, handler] of listeners) {
576
+ element.addEventListener(type, handler, type === 'dom-ready' ? { once: true } : undefined);
577
+ }
578
+ } catch (error) {
579
+ fail(error);
580
+ }
581
+
582
+ const start = async () => {
583
+ try {
584
+ const reservation = await bridge.acquire(PARTITION_KEY);
585
+ if (disposed) {
586
+ try {
587
+ Promise.resolve(bridge.release(reservation.lease)).catch(() => {});
588
+ } catch {
589
+ /* lease already gone */
590
+ }
591
+ return;
592
+ }
593
+ lease = reservation.lease;
594
+ element.setAttribute('name', reservation.lease);
595
+ element.setAttribute('partition', reservation.partition);
596
+ element.setAttribute('src', `about:blank#${reservation.lease}`);
597
+ try {
598
+ unsubscribeOpen = bridge.onOpenRequested(reservation.lease, (url) => {
599
+ if (!disposed && typeof url === 'string') navigate(element, url);
600
+ });
601
+ } catch {
602
+ /* popup bridge unavailable: the guest still works */
603
+ }
604
+ host.append(element);
605
+ watchdog = setTimeout(() => {
606
+ watchdog = undefined;
607
+ if (disposed || started) return;
608
+ fail(new Error(t('timeout')));
609
+ }, WATCHDOG_MS);
610
+ } catch (error) {
611
+ fail(error);
612
+ }
613
+ };
614
+ void start();
615
+
616
+ return () => {
617
+ disposed = true;
618
+ // Read before removal: React cleans up after taking the DOM away, and
619
+ // Electron's getURL() throws on a detached webview.
620
+ const current = readUrl(element);
621
+ if (current !== undefined) {
622
+ lastUrlRef.current = current;
623
+ rememberTarget(current);
624
+ }
625
+ clearWatchdog();
626
+ try {
627
+ if (typeof unsubscribeOpen === 'function') unsubscribeOpen();
628
+ } catch {
629
+ /* already detached */
630
+ }
631
+ for (const [type, handler] of listeners) {
632
+ try {
633
+ element.removeEventListener(type, handler);
634
+ } catch {
635
+ /* already detached */
636
+ }
637
+ }
638
+ try {
639
+ element.remove();
640
+ } catch {
641
+ /* already detached */
642
+ }
643
+ const released = lease;
644
+ lease = undefined;
645
+ if (released !== undefined) {
646
+ try {
647
+ Promise.resolve(bridge.release(released)).catch(() => {});
648
+ } catch {
649
+ /* lease already gone */
650
+ }
651
+ }
652
+ };
653
+ // The effect is re-run only by an explicit retry.
654
+ // eslint-disable-next-line react-hooks/exhaustive-deps
655
+ }, [attempt]);
656
+
657
+ if (phase === 'unsupported') {
658
+ return React.createElement(
659
+ 'div',
660
+ { style: styles.root, role: 'region', 'aria-label': t('title') },
661
+ React.createElement(
662
+ 'div',
663
+ { style: styles.overlay },
664
+ React.createElement('div', { style: styles.overlayTitle }, t('unsupportedTitle')),
665
+ React.createElement('div', null, t('unsupportedBody')),
666
+ React.createElement(
667
+ 'div',
668
+ { style: styles.actions },
669
+ React.createElement(
670
+ 'button',
671
+ { type: 'button', style: styles.button, onClick: () => openExternally(CHAT_URL) },
672
+ t('openExternal'),
673
+ ),
674
+ ),
675
+ ),
676
+ );
677
+ }
678
+
679
+ return React.createElement(
680
+ 'div',
681
+ { style: styles.root, role: 'region', 'aria-label': t('title') },
682
+ phase === 'ready' && authPage
683
+ ? React.createElement(
684
+ 'div',
685
+ { style: styles.signInBar },
686
+ React.createElement('span', { style: styles.signInText }, t('signInHint')),
687
+ React.createElement(
688
+ 'button',
689
+ {
690
+ type: 'button',
691
+ style: styles.linkButton,
692
+ onClick: () => openExternally('https://chat.deepseek.com/sign_in'),
693
+ },
694
+ t('signInAction'),
695
+ ),
696
+ )
697
+ : null,
698
+ React.createElement(
699
+ 'div',
700
+ { style: styles.host, ref: hostRef },
701
+ phase === 'failed' ? null : phase === 'ready' ? null : React.createElement(
702
+ 'div',
703
+ { style: styles.overlay },
704
+ React.createElement('div', null, t('loading')),
705
+ ),
706
+ phase === 'failed'
707
+ ? React.createElement(
708
+ 'div',
709
+ { style: styles.overlay },
710
+ React.createElement('div', { style: styles.overlayTitle }, t('failed')),
711
+ failure === undefined ? null : React.createElement('div', null, failure),
712
+ React.createElement(
713
+ 'div',
714
+ { style: styles.actions },
715
+ React.createElement(
716
+ 'button',
717
+ { type: 'button', style: styles.button, onClick: retry },
718
+ t('retry'),
719
+ ),
720
+ React.createElement(
721
+ 'button',
722
+ {
723
+ type: 'button',
724
+ style: styles.linkButton,
725
+ onClick: () => openExternally(CHAT_URL),
726
+ },
727
+ t('openExternal'),
728
+ ),
729
+ ),
730
+ )
731
+ : null,
732
+ ),
733
+ );
734
+ }
735
+
736
+ /** The registered panel: the boundary owns every rendering failure below it. */
737
+ function ChatPanelShell(props) {
738
+ return React.createElement(
739
+ PanelBoundary,
740
+ { t: props.t ?? translate },
741
+ React.createElement(ChatPanel, props),
742
+ );
743
+ }
744
+
745
+ /** Client services this plugin reads; the loader waits for the slot registry. */
746
+ const inject = ['slots', 'locale'];
747
+
748
+ /**
749
+ * Register the sidebar entry and its main panel.
750
+ * @param ctx - client plugin context.
751
+ */
752
+ function apply(ctx) {
753
+ try {
754
+ // Copy is owned by the locale service so it follows host language changes.
755
+ ctx.effect(() => {
756
+ const offZh = ctx.locale.register(NS, 'zh', DICT.zh);
757
+ const offEn = ctx.locale.register(NS, 'en', DICT.en);
758
+ return () => {
759
+ offZh();
760
+ offEn();
761
+ };
762
+ }, 'vt-web-chat: locale dictionaries');
763
+
764
+ const bound = ctx.locale.bind(NS);
765
+ const fallback = (key) => DICT.en[key] ?? key;
766
+ const t = (key) => {
767
+ const raw = bound(key);
768
+ return raw === key || raw === undefined || raw === null ? fallback(key) : raw;
769
+ };
770
+ translate = t;
771
+ localeService = ctx.locale;
772
+
773
+ // The same id addresses the panellist row and the main panel it selects.
774
+ ctx.slots.inject('main', () =>
775
+ ctx.slots.register(
776
+ {
777
+ name: 'main',
778
+ key: PANEL_ID,
779
+ inject: () => ({ t, locale: ctx.locale }),
780
+ },
781
+ ChatPanelShell,
782
+ ),
783
+ );
784
+
785
+ // order -10 puts the row directly under "New Session", before Plugins (0).
786
+ ctx.slots.inject('sidebar.panellist', () =>
787
+ ctx.slots.register(
788
+ {
789
+ name: 'sidebar.panellist',
790
+ id: PANEL_ID,
791
+ order: -10,
792
+ label: () => t('entry'),
793
+ },
794
+ Glyph,
795
+ ),
796
+ );
797
+ } catch (error) {
798
+ try {
799
+ console.error(`${PLUGIN_ID}: registration failed`, error);
800
+ } catch {
801
+ /* console unavailable */
802
+ }
803
+ }
804
+ }
805
+
806
+ return { apply, inject };
807
+ },
808
+ });
@@ -0,0 +1,5 @@
1
+ # dsh-vt-web-chat bundle patch: one insert mounts the plugin row.
2
+ # insert.name must be the package name; insert.id must be unique in the loader tree.
3
+ - insert:
4
+ - id: dsh-vt-web-chat
5
+ name: dsh-vt-web-chat
package/icon.svg ADDED
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
2
+ <path d="M20.25 11.5c0 4.28-3.7 7.75-8.25 7.75-.53 0-1.05-.05-1.55-.14l-4.1 1.9c-.6.28-1.26-.22-1.18-.87l.5-3.93C4.4 14.9 3.75 13.27 3.75 11.5c0-4.28 3.7-7.75 8.25-7.75s8.25 3.47 8.25 7.75Z" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round"/>
3
+ <path d="M8.5 11.5h.01M12 11.5h.01M15.5 11.5h.01" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/>
4
+ </svg>
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Host half of dsh-vt-web-chat.
3
+ *
4
+ * The feature is browser-surface only: the sidebar entry, the main-area panel
5
+ * and the embedded guest all live in `client.js`. This half exists because the
6
+ * package is mounted as an ordinary Loader entry, and a Client bundle is
7
+ * discovered through that entry.
8
+ *
9
+ * It deliberately registers no Host service, tool, prompt section or route:
10
+ * the embedded page is user-side presentation state and must never reach the
11
+ * model request.
12
+ */
13
+ export function apply() {}
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Web Chat",
4
+ "description": "Adds a \"Web Chat\" entry under New Session that opens chat.deepseek.com as a full main-area panel in the desktop embedded browser, remembering the last conversation."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "网页对话",
4
+ "description": "在「新会话」下方新增「网页对话」入口,点击后在主内容区打开 chat.deepseek.com 官网对话(桌面端内嵌浏览器),并记住上次的对话。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "dsh-vt-web-chat",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "type": "module",
5
+ "description": "Adds a Web Chat entry under New Session that opens chat.deepseek.com as a full main-area panel in the desktop embedded browser and remembers the last conversation.",
6
+ "license": "MIT",
7
+ "author": "Vontean",
8
+ "homepage": "https://github.com/Vontean/vt-dsh-plugin/tree/main/plugins/vt-web-chat#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Vontean/vt-dsh-plugin.git",
12
+ "directory": "plugins/vt-web-chat"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/Vontean/vt-dsh-plugin/issues"
16
+ },
17
+ "keywords": [
18
+ "dsh-plugin",
19
+ "deepseek-harness",
20
+ "web-chat",
21
+ "chat",
22
+ "sidebar",
23
+ "embedded-browser"
24
+ ],
25
+ "engines": {
26
+ "dsh": ">=0.2.1-rc.5 <0.3.0"
27
+ },
28
+ "exports": {
29
+ ".": "./index.js",
30
+ "./client": "./client.js",
31
+ "./locale/*.json": "./locale/*.json",
32
+ "./icon": "./icon.svg"
33
+ },
34
+ "files": [
35
+ "index.js",
36
+ "client.js",
37
+ "cordis.patch.yml",
38
+ "locale/*.json",
39
+ "icon.svg",
40
+ "README.md"
41
+ ],
42
+ "dsh": {
43
+ "bundle": {
44
+ "patch": "./cordis.patch.yml"
45
+ },
46
+ "client": {
47
+ "platform": "web",
48
+ "immediately": true,
49
+ "inject": [
50
+ "@deepseek-ai/dsh-client-ui-sidebar",
51
+ "@deepseek-ai/dsh-client-locale"
52
+ ]
53
+ }
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ }
58
+ }