dsh-vt-web-chat 1.2.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -33
- package/client.js +1272 -739
- package/docs/research/01-chat-demo-embedding.md +322 -0
- package/index.js +36 -8
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +16 -5
- package/scripts/dev-server.mjs +54 -0
- package/scripts/sync-upstream.mjs +256 -0
- package/src/auth.js +65 -0
- package/src/maintenance.js +240 -0
- package/src/proxy.js +139 -0
- package/src/route.js +307 -0
- package/src/settings.js +74 -0
- package/webview/UPSTREAM.json +6 -0
- package/webview/dist/LICENSE +21 -0
- package/webview/dist/index.html +1 -0
- package/webview/dist/static/css/async/4959.1382f613.css +1 -0
- package/webview/dist/static/css/main.27198ffe.css +1 -0
- package/webview/dist/static/js/async/1031.575fa503.js +1 -0
- package/webview/dist/static/js/async/1085.769e13d5.js +1 -0
- package/webview/dist/static/js/async/1086.4d3be1fa.js +1 -0
- package/webview/dist/static/js/async/1097.4f798919.js +117 -0
- package/webview/dist/static/js/async/1299.0ef86619.js +1 -0
- package/webview/dist/static/js/async/1393.6ef1efab.js +1 -0
- package/webview/dist/static/js/async/1401.88487cba.js +1 -0
- package/webview/dist/static/js/async/1505.8913966f.js +1 -0
- package/webview/dist/static/js/async/160.81018107.js +55 -0
- package/webview/dist/static/js/async/1679.153f9f03.js +1 -0
- package/webview/dist/static/js/async/1690.fe25bdfe.js +1 -0
- package/webview/dist/static/js/async/2110.a1d33f2f.js +215 -0
- package/webview/dist/static/js/async/2152.97b0a90c.js +1 -0
- package/webview/dist/static/js/async/2168.9925ab2d.js +1 -0
- package/webview/dist/static/js/async/2312.4fd0ef8e.js +1 -0
- package/webview/dist/static/js/async/2348.41564e59.js +148 -0
- package/webview/dist/static/js/async/2356.631a6aca.js +1 -0
- package/webview/dist/static/js/async/2415.00900482.js +1 -0
- package/webview/dist/static/js/async/2461.15199935.js +1 -0
- package/webview/dist/static/js/async/2541.f8eac009.js +1 -0
- package/webview/dist/static/js/async/2607.abb8bc11.js +1 -0
- package/webview/dist/static/js/async/265.b43cee3f.js +1 -0
- package/webview/dist/static/js/async/2696.60d5ecf0.js +1 -0
- package/webview/dist/static/js/async/3014.c8e9b88f.js +1 -0
- package/webview/dist/static/js/async/3111.e2cca965.js +1 -0
- package/webview/dist/static/js/async/3251.0b9c608e.js +1 -0
- package/webview/dist/static/js/async/3339.ed293391.js +1 -0
- package/webview/dist/static/js/async/3376.3aa54d1a.js +93 -0
- package/webview/dist/static/js/async/3465.845187e8.js +1 -0
- package/webview/dist/static/js/async/3477.94bd21ab.js +5 -0
- package/webview/dist/static/js/async/3594.edfe4411.js +1 -0
- package/webview/dist/static/js/async/3806.28abb895.js +1 -0
- package/webview/dist/static/js/async/3909.4b4bd806.js +1 -0
- package/webview/dist/static/js/async/4138.104dbc81.js +1 -0
- package/webview/dist/static/js/async/426.6fedaabe.js +1 -0
- package/webview/dist/static/js/async/4387.151c5858.js +1 -0
- package/webview/dist/static/js/async/4468.d0c907eb.js +1 -0
- package/webview/dist/static/js/async/4471.b0874c8d.js +158 -0
- package/webview/dist/static/js/async/4568.cf5e547d.js +1 -0
- package/webview/dist/static/js/async/4580.f1bc120a.js +131 -0
- package/webview/dist/static/js/async/4695.8f4b8910.js +1 -0
- package/webview/dist/static/js/async/4959.deb41780.js +1 -0
- package/webview/dist/static/js/async/509.f3e093b4.js +59 -0
- package/webview/dist/static/js/async/5172.e1e3bd11.js +43 -0
- package/webview/dist/static/js/async/535.e10ba324.js +1 -0
- package/webview/dist/static/js/async/5546.89da376c.js +24 -0
- package/webview/dist/static/js/async/5597.3018e134.js +36 -0
- package/webview/dist/static/js/async/5636.61075f0b.js +174 -0
- package/webview/dist/static/js/async/5638.7cfdcd7e.js +1 -0
- package/webview/dist/static/js/async/5706.d34ac064.js +1 -0
- package/webview/dist/static/js/async/5856.d75c4e3b.js +1 -0
- package/webview/dist/static/js/async/6061.7cfcc3e9.js +1 -0
- package/webview/dist/static/js/async/6152.d3a64904.js +1 -0
- package/webview/dist/static/js/async/6297.6e694780.js +1 -0
- package/webview/dist/static/js/async/6325.cafe9e55.js +1 -0
- package/webview/dist/static/js/async/6332.682f48c9.js +1 -0
- package/webview/dist/static/js/async/6349.e9992b47.js +56 -0
- package/webview/dist/static/js/async/6389.1bb952e3.js +1 -0
- package/webview/dist/static/js/async/6443.95da1923.js +1 -0
- package/webview/dist/static/js/async/6526.56ce7dc4.js +1 -0
- package/webview/dist/static/js/async/6600.6e0dfb69.js +1 -0
- package/webview/dist/static/js/async/6689.d0bd8935.js +262 -0
- package/webview/dist/static/js/async/6751.54c80aba.js +1 -0
- package/webview/dist/static/js/async/680.5aa7dcb4.js +1 -0
- package/webview/dist/static/js/async/6948.9cd716f4.js +1 -0
- package/webview/dist/static/js/async/7262.f680270f.js +88 -0
- package/webview/dist/static/js/async/7515.20c14480.js +1 -0
- package/webview/dist/static/js/async/7536.34769b35.js +1 -0
- package/webview/dist/static/js/async/7630.ed725458.js +1 -0
- package/webview/dist/static/js/async/7853.0a4b794a.js +1 -0
- package/webview/dist/static/js/async/8180.4d4299ef.js +1 -0
- package/webview/dist/static/js/async/828.56686119.js +1 -0
- package/webview/dist/static/js/async/8379.1b75211c.js +1 -0
- package/webview/dist/static/js/async/8389.4f120664.js +1 -0
- package/webview/dist/static/js/async/8538.d5f92d14.js +24 -0
- package/webview/dist/static/js/async/8560.1bdf90ec.js +1 -0
- package/webview/dist/static/js/async/8794.759831e8.js +60 -0
- package/webview/dist/static/js/async/8821.2b444259.js +29 -0
- package/webview/dist/static/js/async/925.548cc1b9.js +1 -0
- package/webview/dist/static/js/async/9252.3c22a9cd.js +1 -0
- package/webview/dist/static/js/async/9261.1e796956.js +1 -0
- package/webview/dist/static/js/async/9324.b3518ebf.js +1 -0
- package/webview/dist/static/js/async/9354.4425ac3c.js +1 -0
- package/webview/dist/static/js/async/9501.a7851380.js +4 -0
- package/webview/dist/static/js/async/9560.d604e606.js +166 -0
- package/webview/dist/static/js/async/9640.5f6a6734.js +1 -0
- package/webview/dist/static/js/async/9765.ecc8b5dc.js +1 -0
- package/webview/dist/static/js/async/9821.b1897048.js +63 -0
- package/webview/dist/static/js/main.12b22c21.js +3 -0
- package/webview/dist/static/media/KaTeX_AMS-Regular.1608a09b.woff +0 -0
- package/webview/dist/static/media/KaTeX_AMS-Regular.4aafdb68.ttf +0 -0
- package/webview/dist/static/media/KaTeX_AMS-Regular.a79f1c31.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Caligraphic-Bold.b6770918.woff +0 -0
- package/webview/dist/static/media/KaTeX_Caligraphic-Bold.cce5b8ec.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Caligraphic-Bold.ec17d132.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Caligraphic-Regular.07ef19e7.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Caligraphic-Regular.55fac258.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Caligraphic-Regular.dad44a7f.woff +0 -0
- package/webview/dist/static/media/KaTeX_Fraktur-Bold.9f256b85.woff +0 -0
- package/webview/dist/static/media/KaTeX_Fraktur-Bold.b18f59e1.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Fraktur-Bold.d42a5579.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Fraktur-Regular.7c187121.woff +0 -0
- package/webview/dist/static/media/KaTeX_Fraktur-Regular.d3c882a6.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Fraktur-Regular.ed38e79f.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Main-Bold.b74a1a8b.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Main-Bold.c3fb5ac2.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Main-Bold.d181c465.woff +0 -0
- package/webview/dist/static/media/KaTeX_Main-BoldItalic.6f2bb1df.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Main-BoldItalic.70d8b0a5.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Main-BoldItalic.e3f82f9d.woff +0 -0
- package/webview/dist/static/media/KaTeX_Main-Italic.47373d1e.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Main-Italic.8916142b.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Main-Italic.9024d815.woff +0 -0
- package/webview/dist/static/media/KaTeX_Main-Regular.0462f03b.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Main-Regular.7f51fe03.woff +0 -0
- package/webview/dist/static/media/KaTeX_Main-Regular.b7f8fe9b.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Math-BoldItalic.572d331f.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Math-BoldItalic.a879cf83.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Math-BoldItalic.f1035d8d.woff +0 -0
- package/webview/dist/static/media/KaTeX_Math-Italic.5295ba48.woff +0 -0
- package/webview/dist/static/media/KaTeX_Math-Italic.939bc644.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Math-Italic.f28c23ac.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_SansSerif-Bold.8c5b5494.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_SansSerif-Bold.94e1e8dc.ttf +0 -0
- package/webview/dist/static/media/KaTeX_SansSerif-Bold.bf59d231.woff +0 -0
- package/webview/dist/static/media/KaTeX_SansSerif-Italic.3b1e59b3.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_SansSerif-Italic.7c9bc82b.woff +0 -0
- package/webview/dist/static/media/KaTeX_SansSerif-Italic.b4c20c84.ttf +0 -0
- package/webview/dist/static/media/KaTeX_SansSerif-Regular.74048478.woff +0 -0
- package/webview/dist/static/media/KaTeX_SansSerif-Regular.ba21ed5f.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_SansSerif-Regular.d4d7ba48.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Script-Regular.03e9641d.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Script-Regular.07505710.woff +0 -0
- package/webview/dist/static/media/KaTeX_Script-Regular.fe9cbbe1.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Size1-Regular.e1e279cb.woff +0 -0
- package/webview/dist/static/media/KaTeX_Size1-Regular.eae34984.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Size1-Regular.fabc004a.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Size2-Regular.57727022.woff +0 -0
- package/webview/dist/static/media/KaTeX_Size2-Regular.5916a24f.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Size2-Regular.d6b476ec.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Size3-Regular.9acaf01c.woff +0 -0
- package/webview/dist/static/media/KaTeX_Size3-Regular.a144ef58.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Size3-Regular.b4230e7e.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Size4-Regular.10d95fd3.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Size4-Regular.7a996c9d.woff +0 -0
- package/webview/dist/static/media/KaTeX_Size4-Regular.fbccdabe.ttf +0 -0
- package/webview/dist/static/media/KaTeX_Typewriter-Regular.6258592b.woff +0 -0
- package/webview/dist/static/media/KaTeX_Typewriter-Regular.a8709e36.woff2 +0 -0
- package/webview/dist/static/media/KaTeX_Typewriter-Regular.d97aaf4a.ttf +0 -0
package/client.js
CHANGED
|
@@ -1,864 +1,1057 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-vt-web-chat
|
|
2
|
+
* Browser half of dsh-vt-web-chat.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 面板里就是官方开源 chat-demo 的界面本身:插件把自己的 `/webchat/` 路由托管给同源
|
|
5
|
+
* `iframe`,请求由 Host 用 DSH 的 DeepSeek 凭据代发。这里负责三件事:
|
|
6
|
+
* 侧栏入口、整页面板、设置页里的会话保留策略。
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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.
|
|
8
|
+
* 2.1 起多了一层「Chat 模式」:选中网页对话面板时,侧栏的品牌名、会话浏览区和底部动作
|
|
9
|
+
* 换成 Chat 自己的内容(历史、返回 Harness),离开面板时恢复宿主侧栏。接管只发生在
|
|
10
|
+
* 子座位(brand.name / workspaces / footer.action)上,宿主骨架与「新会话」按钮都保留。
|
|
14
11
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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.
|
|
12
|
+
* 为什么用模式切换而不是把面板做成独立窗口:历史与新建对话都在同一个 iframe 里,
|
|
13
|
+
* 侧栏只是它的导航面;两者由同一份状态驱动,用户不会看到两套互相不同步的列表。
|
|
23
14
|
*/
|
|
24
15
|
window.__ModuleLoader__.load({
|
|
25
|
-
// 模块 id 必须与包名一致;装载器把多个 client.js 拼进同一个脚本,所以顶层只能有
|
|
26
|
-
// 这一个 load() 调用,其余常量一律放进 factory 的作用域,避免重名 SyntaxError。
|
|
27
16
|
id: 'dsh-vt-web-chat',
|
|
28
17
|
factory(require) {
|
|
29
|
-
|
|
18
|
+
const React = require('react');
|
|
19
|
+
const h = React.createElement;
|
|
30
20
|
|
|
31
|
-
/** Package identity: one source for the module id and every log/storage prefix. */
|
|
32
21
|
const PLUGIN_ID = 'dsh-vt-web-chat';
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
// Mount trace: one line naming the loaded build (DevTools → verbose level).
|
|
37
|
-
console.debug(`[${PLUGIN_ID}] v${VERSION}`);
|
|
38
|
-
|
|
39
|
-
const reactModule = require('react');
|
|
40
|
-
const React =
|
|
41
|
-
reactModule !== null && typeof reactModule.createElement === 'function'
|
|
42
|
-
? reactModule
|
|
43
|
-
: reactModule.default;
|
|
44
|
-
|
|
45
|
-
/** Locale namespace owned by this plugin. */
|
|
46
|
-
const NS = 'vtWebChat';
|
|
47
|
-
/** `main` cell key and `sidebar.panellist` id — the two must match. */
|
|
22
|
+
const VERSION = '2.1.0';
|
|
23
|
+
const NS = PLUGIN_ID;
|
|
24
|
+
/** 侧栏行与主面板共用的 id。 */
|
|
48
25
|
const PANEL_ID = 'vt-web-chat';
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
/**
|
|
57
|
-
const
|
|
26
|
+
/** 与宿主路由一致的接口前缀。 */
|
|
27
|
+
const ROUTE_PREFIX = '/webchat';
|
|
28
|
+
/** 保留天数档位;0 表示永不清理。 */
|
|
29
|
+
const RETENTION_CHOICES = [30, 60, 90, 0];
|
|
30
|
+
/** 面板与宿主之间的消息来源标记。 */
|
|
31
|
+
const HOST_SOURCE = 'vt-webchat-host';
|
|
32
|
+
const SHELL_SOURCE = 'vt-webchat-shell';
|
|
33
|
+
/** 离开 Chat 模式时给侧栏留出的淡出时间,需与 CSS 里的退场动画一致。 */
|
|
34
|
+
const LEAVE_MS = 150;
|
|
35
|
+
/** 返回 Harness 时选中的主面板 key。 */
|
|
36
|
+
const CONVERSATION_PANEL = 'conversation';
|
|
58
37
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
38
|
+
* 官方字标在 24px 高度下「deepseek」部分的像素宽度。
|
|
39
|
+
* 字标 SVG 的 viewBox 从 x=26 开始,HARNESS 徽标从 x=129.348 开始,
|
|
40
|
+
* 所以裁到 129.348 - 26 = 103.348px 时只剩下文字本身,徽标由我们自己画。
|
|
62
41
|
*/
|
|
63
|
-
const
|
|
42
|
+
const WORDMARK_WIDTH = 103.35;
|
|
43
|
+
|
|
64
44
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* flag, so writing it here is the same dismissal without a click.
|
|
45
|
+
* 官方品牌字标与鲸鱼标。取不到时品牌名退回纯文字、品牌标不接管,
|
|
46
|
+
* 不能因为一个可选依赖让整个侧栏起不来。
|
|
68
47
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const AUTH_PATHS = new Set(['/sign_in', '/login', '/signup', '/auth']);
|
|
76
|
-
/** A guest that never reaches `dom-ready` is reported instead of hanging. */
|
|
77
|
-
const WATCHDOG_MS = 15000;
|
|
48
|
+
let primitives = null;
|
|
49
|
+
try {
|
|
50
|
+
primitives = require('@deepseek-ai/dsh-client-ui-primitives');
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.warn(`[${PLUGIN_ID}] shared UI primitives unavailable`, error);
|
|
53
|
+
}
|
|
78
54
|
|
|
79
55
|
const DICT = {
|
|
80
56
|
zh: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
57
|
+
'meta.title': '网页对话',
|
|
58
|
+
'meta.description': '用官方 DeepSeek 网页界面聊天,请求走 DeepSeek API 与你的 DSH 账号。',
|
|
59
|
+
'entry': '网页对话',
|
|
60
|
+
'panel.title': '网页对话',
|
|
61
|
+
'panel.hint': '滚动、复制、上传都在面板内完成;对话保存在本机,不会写入 DSH 会话。',
|
|
62
|
+
'back': '返回 Harness',
|
|
63
|
+
'back.hint': '退出 Chat 模式,回到 DSH 会话',
|
|
64
|
+
'history.label': '对话历史',
|
|
65
|
+
'history.today': '今天',
|
|
66
|
+
'history.yesterday': '昨天',
|
|
67
|
+
'history.week': '7 天内',
|
|
68
|
+
'history.month': '30 天内',
|
|
69
|
+
'history.empty': '还没有对话',
|
|
70
|
+
'history.emptyHint': '点上方「新会话」开始第一个对话。',
|
|
71
|
+
'history.error': '会话列表读取失败',
|
|
72
|
+
'history.retry': '重试',
|
|
73
|
+
'history.untitled': '新对话',
|
|
74
|
+
'settings.nav': '网页对话',
|
|
75
|
+
'settings.title': '会话保留',
|
|
76
|
+
'settings.description': '超过所选天数没有继续聊的会话,会在下次打开面板时自动删除。',
|
|
77
|
+
'settings.days30': '30 天',
|
|
78
|
+
'settings.days60': '60 天',
|
|
79
|
+
'settings.days90': '90 天',
|
|
80
|
+
'settings.never': '永不',
|
|
81
|
+
'settings.saving': '保存中…',
|
|
82
|
+
'settings.saved': '已保存',
|
|
83
|
+
'settings.failed': '保存失败,请重试',
|
|
84
|
+
'settings.loadFailed': '读取设置失败,暂按 30 天处理',
|
|
85
|
+
'settings.currentDays': '当前:闲置超过 {n} 天的会话会被删除。',
|
|
86
|
+
'settings.currentNever': '当前:永不自动删除。',
|
|
87
|
+
'settings.crashed': '设置区块加载失败,请重新打开设置页。',
|
|
93
88
|
},
|
|
94
89
|
en: {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
90
|
+
'meta.title': 'Web Chat',
|
|
91
|
+
'meta.description': 'Chat on the official DeepSeek web UI, billed through the DeepSeek API with your DSH account.',
|
|
92
|
+
'entry': 'Web Chat',
|
|
93
|
+
'panel.title': 'Web Chat',
|
|
94
|
+
'panel.hint': 'Scrolling, copying and uploads stay inside the panel; chats are stored locally and never written to a DSH session.',
|
|
95
|
+
'back': 'Back to Harness',
|
|
96
|
+
'back.hint': 'Leave Chat mode and return to your DSH session',
|
|
97
|
+
'history.label': 'Chat history',
|
|
98
|
+
'history.today': 'Today',
|
|
99
|
+
'history.yesterday': 'Yesterday',
|
|
100
|
+
'history.week': 'Previous 7 days',
|
|
101
|
+
'history.month': 'Previous 30 days',
|
|
102
|
+
'history.empty': 'No chats yet',
|
|
103
|
+
'history.emptyHint': 'Start one with New Session above.',
|
|
104
|
+
'history.error': 'Could not read the chat list',
|
|
105
|
+
'history.retry': 'Retry',
|
|
106
|
+
'history.untitled': 'New chat',
|
|
107
|
+
'settings.nav': 'Web Chat',
|
|
108
|
+
'settings.title': 'Chat retention',
|
|
109
|
+
'settings.description': 'Chats untouched for longer than the chosen period are deleted the next time the panel opens.',
|
|
110
|
+
'settings.days30': '30 days',
|
|
111
|
+
'settings.days60': '60 days',
|
|
112
|
+
'settings.days90': '90 days',
|
|
113
|
+
'settings.never': 'Never',
|
|
114
|
+
'settings.saving': 'Saving…',
|
|
115
|
+
'settings.saved': 'Saved',
|
|
116
|
+
'settings.failed': 'Save failed, please retry',
|
|
117
|
+
'settings.loadFailed': 'Could not read settings; assuming 30 days',
|
|
118
|
+
'settings.currentDays': 'Current: chats idle for more than {n} days are deleted.',
|
|
119
|
+
'settings.currentNever': 'Current: never delete automatically.',
|
|
120
|
+
'settings.crashed': 'This section failed to render; reopen Settings to try again.',
|
|
109
121
|
},
|
|
110
122
|
};
|
|
111
123
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
124
|
+
// ---------------------------------------------------------------------
|
|
125
|
+
// 小状态仓库:React 用 useSyncExternalStore 订阅,侧栏与面板共用同一份快照。
|
|
126
|
+
// ---------------------------------------------------------------------
|
|
115
127
|
|
|
116
128
|
/**
|
|
117
|
-
*
|
|
118
|
-
* @param
|
|
119
|
-
* @returns
|
|
129
|
+
* 建一个只放对象快照的订阅仓库。
|
|
130
|
+
* @param initial - 初始快照。
|
|
131
|
+
* @returns `{ get, set, subscribe }`。
|
|
120
132
|
*/
|
|
121
|
-
function
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
function createStore(initial) {
|
|
134
|
+
let value = initial;
|
|
135
|
+
const listeners = new Set();
|
|
136
|
+
return {
|
|
137
|
+
get: () => value,
|
|
138
|
+
set: (next) => {
|
|
139
|
+
if (Object.is(next, value)) return;
|
|
140
|
+
value = next;
|
|
141
|
+
for (const listener of Array.from(listeners)) {
|
|
142
|
+
try {
|
|
143
|
+
listener();
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error(`[${PLUGIN_ID}] store listener failed`, error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
subscribe: (listener) => {
|
|
150
|
+
listeners.add(listener);
|
|
151
|
+
return () => {
|
|
152
|
+
listeners.delete(listener);
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
};
|
|
130
156
|
}
|
|
131
157
|
|
|
132
158
|
/**
|
|
133
|
-
*
|
|
134
|
-
* @param
|
|
135
|
-
* @returns
|
|
159
|
+
* 订阅仓库;宿主 React 一定带 useSyncExternalStore,缺失时退回 useState。
|
|
160
|
+
* @param store - createStore 的返回值。
|
|
161
|
+
* @returns 当前快照。
|
|
136
162
|
*/
|
|
137
|
-
function
|
|
138
|
-
if (typeof
|
|
139
|
-
|
|
140
|
-
const url = new URL(value);
|
|
141
|
-
if (url.protocol !== 'https:' || url.hostname !== 'chat.deepseek.com') return undefined;
|
|
142
|
-
if (url.username !== '' || url.password !== '') return undefined;
|
|
143
|
-
return url;
|
|
144
|
-
} catch {
|
|
145
|
-
return undefined;
|
|
163
|
+
function useStore(store) {
|
|
164
|
+
if (typeof React.useSyncExternalStore === 'function') {
|
|
165
|
+
return React.useSyncExternalStore(store.subscribe, store.get, store.get);
|
|
146
166
|
}
|
|
167
|
+
const [value, setValue] = React.useState(store.get);
|
|
168
|
+
React.useEffect(() => store.subscribe(() => setValue(store.get())), [store]);
|
|
169
|
+
return value;
|
|
147
170
|
}
|
|
148
171
|
|
|
149
|
-
/**
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
function
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
|
|
172
|
+
/** Chat 模式:active 接管侧栏,leaving 播放退场。 */
|
|
173
|
+
const surface = createStore({ active: false, leaving: false });
|
|
174
|
+
let leaveTimer = null;
|
|
175
|
+
|
|
176
|
+
/** 进入 Chat 模式;如果正在退场则取消退场。 */
|
|
177
|
+
function enterSurface() {
|
|
178
|
+
if (leaveTimer !== null) {
|
|
179
|
+
clearTimeout(leaveTimer);
|
|
180
|
+
leaveTimer = null;
|
|
181
|
+
}
|
|
182
|
+
const current = surface.get();
|
|
183
|
+
if (current.active && !current.leaving) return;
|
|
184
|
+
surface.set({ active: true, leaving: false });
|
|
158
185
|
}
|
|
159
186
|
|
|
160
|
-
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
187
|
+
/** 离开 Chat 模式:先淡出,再让宿主侧栏回来。 */
|
|
188
|
+
function leaveSurface() {
|
|
189
|
+
const current = surface.get();
|
|
190
|
+
if (!current.active || current.leaving) return;
|
|
191
|
+
surface.set({ active: true, leaving: true });
|
|
192
|
+
leaveTimer = setTimeout(() => {
|
|
193
|
+
leaveTimer = null;
|
|
194
|
+
surface.set({ active: false, leaving: false });
|
|
195
|
+
}, LEAVE_MS);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** 立即恢复 Harness 侧栏,不走淡出。用于「返回 Harness」这种要求跟手的路径。 */
|
|
199
|
+
function exitSurfaceNow() {
|
|
200
|
+
if (leaveTimer !== null) {
|
|
201
|
+
clearTimeout(leaveTimer);
|
|
202
|
+
leaveTimer = null;
|
|
203
|
+
}
|
|
204
|
+
if (!surface.get().active) return;
|
|
205
|
+
surface.set({ active: false, leaving: false });
|
|
170
206
|
}
|
|
171
207
|
|
|
172
208
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
209
|
+
* 返回 Harness 后,指针通常还停在原来的坐标上;新出现的额度环/DS Bot 返回
|
|
210
|
+
* 与返回行位置、hover 底色完全一样,轻微移动就会点亮,看起来像状态没释放。
|
|
211
|
+
* 这里短暂压掉这两行的 hover 底色,直到指针离开底栏或超时,再恢复正常。
|
|
175
212
|
*/
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
213
|
+
let returnHoverTimer = null;
|
|
214
|
+
let returnHoverCleanup = null;
|
|
215
|
+
let returnHoverToken = 0;
|
|
216
|
+
|
|
217
|
+
function clearReturnedHover() {
|
|
218
|
+
returnHoverToken += 1;
|
|
219
|
+
document.documentElement.removeAttribute('data-vtwc-returning');
|
|
220
|
+
if (returnHoverTimer !== null) {
|
|
221
|
+
clearTimeout(returnHoverTimer);
|
|
222
|
+
returnHoverTimer = null;
|
|
223
|
+
}
|
|
224
|
+
if (returnHoverCleanup !== null) {
|
|
225
|
+
returnHoverCleanup();
|
|
226
|
+
returnHoverCleanup = null;
|
|
182
227
|
}
|
|
183
228
|
}
|
|
184
229
|
|
|
230
|
+
function suppressReturnedHover() {
|
|
231
|
+
clearReturnedHover();
|
|
232
|
+
const token = returnHoverToken;
|
|
233
|
+
document.documentElement.setAttribute('data-vtwc-returning', 'true');
|
|
234
|
+
const finish = () => clearReturnedHover();
|
|
235
|
+
returnHoverTimer = setTimeout(finish, 1200);
|
|
236
|
+
// 底栏要等侧栏提交后才存在;下一帧再挂 pointerleave。
|
|
237
|
+
window.requestAnimationFrame(() => {
|
|
238
|
+
if (token !== returnHoverToken) return;
|
|
239
|
+
const footer = document.querySelector('[class*="footerActions"]');
|
|
240
|
+
if (footer === null) return;
|
|
241
|
+
footer.addEventListener('pointerleave', finish, { once: true });
|
|
242
|
+
footer.addEventListener('pointerdown', finish, { once: true });
|
|
243
|
+
returnHoverCleanup = () => {
|
|
244
|
+
footer.removeEventListener('pointerleave', finish);
|
|
245
|
+
footer.removeEventListener('pointerdown', finish);
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** 面板同步过来的会话历史。 */
|
|
251
|
+
const chatData = createStore({ ready: false, sessions: [], activeId: null, error: false });
|
|
252
|
+
|
|
253
|
+
// ---------------------------------------------------------------------
|
|
254
|
+
// 面板桥:父页面只认 iframe 的 contentWindow,子页面只认 window.parent。
|
|
255
|
+
// ---------------------------------------------------------------------
|
|
256
|
+
|
|
257
|
+
const panelLink = {
|
|
258
|
+
target: null,
|
|
259
|
+
ready: false,
|
|
260
|
+
queue: [],
|
|
261
|
+
/** 记下当前面板窗口;换窗口时清掉旧的 ready 与待发命令。 */
|
|
262
|
+
attach(target) {
|
|
263
|
+
if (this.target === target) return;
|
|
264
|
+
this.target = target ?? null;
|
|
265
|
+
this.ready = false;
|
|
266
|
+
this.queue = [];
|
|
267
|
+
},
|
|
268
|
+
detach(target) {
|
|
269
|
+
if (target !== undefined && this.target !== target) return;
|
|
270
|
+
this.target = null;
|
|
271
|
+
this.ready = false;
|
|
272
|
+
this.queue = [];
|
|
273
|
+
},
|
|
274
|
+
/** 发给面板;还没挂上时先排队,就绪后重放。 */
|
|
275
|
+
post(message) {
|
|
276
|
+
if (this.target === null) {
|
|
277
|
+
if (this.queue.length < 24) this.queue.push(message);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
this.target.postMessage({ source: SHELL_SOURCE, ...message }, '*');
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.warn(`[${PLUGIN_ID}] panel frame unavailable`, error);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
markReady() {
|
|
287
|
+
if (this.ready) return;
|
|
288
|
+
this.ready = true;
|
|
289
|
+
const pending = this.queue;
|
|
290
|
+
this.queue = [];
|
|
291
|
+
for (const message of pending) this.post(message);
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/** 侧栏里点一条历史:交给面板切换会话。模块级引用,供 memo 行复用。 */
|
|
296
|
+
function openChat(id) {
|
|
297
|
+
panelLink.post({ type: 'open-session', id });
|
|
298
|
+
}
|
|
299
|
+
|
|
185
300
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* page never overwrites it, so a login detour does not lose the conversation.
|
|
190
|
-
* @param raw - current page URL reported by the guest.
|
|
301
|
+
* 把面板发来的同步消息收敛成可渲染的会话摘要。
|
|
302
|
+
* @param data - 面板消息。
|
|
303
|
+
* @returns 新快照;字段不合法时返回 null,保留旧列表。
|
|
191
304
|
*/
|
|
192
|
-
function
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
305
|
+
function readSync(data) {
|
|
306
|
+
const current = chatData.get();
|
|
307
|
+
let sessions = current.sessions;
|
|
308
|
+
if (Array.isArray(data.sessions)) {
|
|
309
|
+
sessions = [];
|
|
310
|
+
for (const item of data.sessions) {
|
|
311
|
+
if (item === null || typeof item !== 'object' || typeof item.id !== 'string') continue;
|
|
312
|
+
sessions.push({
|
|
313
|
+
id: item.id,
|
|
314
|
+
title: typeof item.title === 'string' ? item.title : '',
|
|
315
|
+
createdAt: Number(item.createdAt) || 0,
|
|
316
|
+
updatedAt: Number(item.updatedAt) || 0,
|
|
317
|
+
});
|
|
199
318
|
}
|
|
200
|
-
} catch {
|
|
201
|
-
/* storage unavailable: the panel still works, it just forgets */
|
|
202
319
|
}
|
|
320
|
+
// 增量消息可能只带 activeId:其余字段沿用上一份快照。
|
|
321
|
+
const activeId =
|
|
322
|
+
typeof data.activeId === 'string'
|
|
323
|
+
? data.activeId
|
|
324
|
+
: data.activeId === null
|
|
325
|
+
? null
|
|
326
|
+
: current.activeId;
|
|
327
|
+
const ready = typeof data.ready === 'boolean' ? data.ready : current.ready;
|
|
328
|
+
const error = typeof data.error === 'boolean' ? data.error : current.error;
|
|
329
|
+
if (
|
|
330
|
+
sessions === current.sessions &&
|
|
331
|
+
activeId === current.activeId &&
|
|
332
|
+
ready === current.ready &&
|
|
333
|
+
error === current.error
|
|
334
|
+
) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
return { ready, sessions, activeId, error };
|
|
203
338
|
}
|
|
204
339
|
|
|
205
340
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* Two records carry the state, and the site reads both once at boot: the
|
|
209
|
-
* environment-warning dismissal and the sidebar state. Writing them without
|
|
210
|
-
* a reload has no effect, so the script writes only what differs and
|
|
211
|
-
* reloads once. A guest sessionStorage counter caps the reloads, so a site
|
|
212
|
-
* that refuses the write cannot loop. Without a sign-in token there is no
|
|
213
|
-
* sidebar yet, so only the warning is handled on the auth page.
|
|
214
|
-
* @returns the script text, safe to hand to `executeJavaScript`.
|
|
341
|
+
* 处理面板发来的消息。
|
|
342
|
+
* @param data - postMessage 的 data。
|
|
215
343
|
*/
|
|
216
|
-
function
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
try {
|
|
223
|
-
const raw = localStorage.getItem(key);
|
|
224
|
-
if (raw === null) return null;
|
|
225
|
-
const parsed = JSON.parse(raw);
|
|
226
|
-
return parsed !== null && typeof parsed === 'object' ? parsed : null;
|
|
227
|
-
} catch (error) {
|
|
228
|
-
return null;
|
|
344
|
+
function handleHostMessage(data) {
|
|
345
|
+
if (data === null || typeof data !== 'object' || data.source !== HOST_SOURCE) return;
|
|
346
|
+
if (data.type === 'ready') {
|
|
347
|
+
panelLink.markReady();
|
|
348
|
+
panelLink.post({ type: 'request-sync' });
|
|
349
|
+
return;
|
|
229
350
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
localStorage.setItem(key, JSON.stringify(record));
|
|
236
|
-
};
|
|
237
|
-
let reload = false;
|
|
238
|
-
const warning = read('${UNSAFE_WARN_KEY}');
|
|
239
|
-
if (warning === null || warning.value !== true) {
|
|
240
|
-
write('${UNSAFE_WARN_KEY}', true);
|
|
241
|
-
reload = true;
|
|
242
|
-
}
|
|
243
|
-
const token = read('userToken');
|
|
244
|
-
if (token !== null && token.value !== null && token.value !== undefined) {
|
|
245
|
-
const prefs = read('${SITE_PREFS_KEY}');
|
|
246
|
-
const value = prefs !== null && prefs.value !== null && typeof prefs.value === 'object' ? prefs.value : {};
|
|
247
|
-
if (value.siderCollapsed !== true) {
|
|
248
|
-
const next = prefs === null ? {} : prefs;
|
|
249
|
-
next.value = Object.assign({}, value, { siderCollapsed: true });
|
|
250
|
-
if (typeof next.__version !== 'string') next.__version = '0';
|
|
251
|
-
localStorage.setItem('${SITE_PREFS_KEY}', JSON.stringify(next));
|
|
252
|
-
reload = true;
|
|
351
|
+
if (data.type === 'sync') {
|
|
352
|
+
const next = readSync(data);
|
|
353
|
+
if (next === null) return;
|
|
354
|
+
chatData.set(next);
|
|
355
|
+
if (next.ready) panelLink.markReady();
|
|
253
356
|
}
|
|
254
357
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
358
|
+
|
|
359
|
+
const DAY_MS = 86_400_000;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* 当天零点的时间戳。
|
|
363
|
+
* @param value - 毫秒时间戳。
|
|
364
|
+
* @returns 当天 00:00 的时间戳。
|
|
365
|
+
*/
|
|
366
|
+
function startOfDay(value) {
|
|
367
|
+
const date = new Date(value);
|
|
368
|
+
date.setHours(0, 0, 0, 0);
|
|
369
|
+
return date.getTime();
|
|
263
370
|
}
|
|
264
371
|
|
|
265
372
|
/**
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* site redesign cannot break them into wrong clicks. Every failure stays
|
|
270
|
-
* inside this panel: a guest that refuses the script keeps its own layout
|
|
271
|
-
* and its own warning.
|
|
272
|
-
* @param element - webview element hosting the site.
|
|
373
|
+
* 会话历史按月分组的键。
|
|
374
|
+
* @param value - 毫秒时间戳。
|
|
375
|
+
* @returns `YYYY-MM`;时间无效时为空串。
|
|
273
376
|
*/
|
|
274
|
-
function
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (pending !== undefined && pending !== null && typeof pending.catch === 'function') {
|
|
279
|
-
pending.catch(() => {});
|
|
280
|
-
}
|
|
281
|
-
} catch {
|
|
282
|
-
/* scripting disabled for this guest: keep the site's own behaviour */
|
|
283
|
-
}
|
|
377
|
+
function monthKey(value) {
|
|
378
|
+
const date = new Date(value);
|
|
379
|
+
if (Number.isNaN(date.getTime())) return '';
|
|
380
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
|
|
284
381
|
}
|
|
285
382
|
|
|
286
383
|
/**
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
* @param
|
|
384
|
+
* 按 chat-demo 的同一规则分组:今天 / 昨天 / 7 天内 / 30 天内 / 月份。
|
|
385
|
+
* @param sessions - 会话摘要,已按更新时间倒序。
|
|
386
|
+
* @param now - 当前时间。
|
|
387
|
+
* @param t - 翻译函数。
|
|
388
|
+
* @returns 分组数组。
|
|
290
389
|
*/
|
|
291
|
-
function
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
390
|
+
function groupSessions(sessions, now, t) {
|
|
391
|
+
const groups = [];
|
|
392
|
+
for (const session of sessions) {
|
|
393
|
+
const diff = Math.floor((now - startOfDay(session.updatedAt)) / DAY_MS);
|
|
394
|
+
let key = null;
|
|
395
|
+
let label = '';
|
|
396
|
+
if (diff <= 0) {
|
|
397
|
+
key = 'today';
|
|
398
|
+
label = t('history.today');
|
|
399
|
+
} else if (diff <= 1) {
|
|
400
|
+
key = 'yesterday';
|
|
401
|
+
label = t('history.yesterday');
|
|
402
|
+
} else if (diff < 7) {
|
|
403
|
+
key = 'week';
|
|
404
|
+
label = t('history.week');
|
|
405
|
+
} else if (diff < 30) {
|
|
406
|
+
key = 'month';
|
|
407
|
+
label = t('history.month');
|
|
408
|
+
} else {
|
|
409
|
+
key = `m:${monthKey(session.updatedAt)}`;
|
|
410
|
+
label = monthKey(session.updatedAt);
|
|
411
|
+
}
|
|
412
|
+
const last = groups.at(-1);
|
|
413
|
+
if (last !== undefined && last.key === key) last.sessions.push(session);
|
|
414
|
+
else groups.push({ key, label, sessions: [session] });
|
|
296
415
|
}
|
|
416
|
+
return groups;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** 每分钟刷新一次「今天/昨天」边界;窗口重新可见时也刷新。 */
|
|
420
|
+
function useClock() {
|
|
421
|
+
const [now, setNow] = React.useState(() => Date.now());
|
|
422
|
+
React.useEffect(() => {
|
|
423
|
+
const tick = () => setNow(Date.now());
|
|
424
|
+
const timer = setInterval(tick, 60_000);
|
|
425
|
+
const onVisible = () => {
|
|
426
|
+
if (document.visibilityState === 'visible') tick();
|
|
427
|
+
};
|
|
428
|
+
document.addEventListener('visibilitychange', onVisible);
|
|
429
|
+
window.addEventListener('focus', tick);
|
|
430
|
+
return () => {
|
|
431
|
+
clearInterval(timer);
|
|
432
|
+
document.removeEventListener('visibilitychange', onVisible);
|
|
433
|
+
window.removeEventListener('focus', tick);
|
|
434
|
+
};
|
|
435
|
+
}, []);
|
|
436
|
+
return now;
|
|
297
437
|
}
|
|
298
438
|
|
|
299
439
|
/**
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
440
|
+
* 面板地址。桌面壳的静态页面通过 `__DSH_TRANSPORT__` 拿到 Host 的 HTTP origin,
|
|
441
|
+
* 浏览器页面直接用当前 origin;两者都没有时退回根路径。
|
|
442
|
+
*
|
|
443
|
+
* 带上 `lang`:面板是独立文档,拿不到宿主的 i18n;首次进入时由注入脚本
|
|
444
|
+
* 把它写进前端自己的 locale 存储,之后用户在前端里改过就以前端为准。
|
|
445
|
+
* @param locale - 宿主当前语言。
|
|
446
|
+
* @returns 面板 URL。
|
|
304
447
|
*/
|
|
305
|
-
function
|
|
448
|
+
function panelUrl(locale) {
|
|
306
449
|
try {
|
|
307
|
-
|
|
450
|
+
const transport = window.__DSH_TRANSPORT__;
|
|
451
|
+
const base =
|
|
452
|
+
typeof transport?.streamBaseUrl === 'string' && transport.streamBaseUrl.length > 0
|
|
453
|
+
? transport.streamBaseUrl.replace(/\/+$/u, '')
|
|
454
|
+
: window.location.protocol === 'file:'
|
|
455
|
+
? ''
|
|
456
|
+
: window.location.origin;
|
|
457
|
+
return `${base}${ROUTE_PREFIX}/?lang=${encodeURIComponent(locale)}`;
|
|
308
458
|
} catch {
|
|
309
|
-
return
|
|
459
|
+
return `${ROUTE_PREFIX}/?lang=${encodeURIComponent(locale)}`;
|
|
310
460
|
}
|
|
311
461
|
}
|
|
312
462
|
|
|
313
463
|
/**
|
|
314
|
-
*
|
|
315
|
-
* @param
|
|
316
|
-
* @returns
|
|
464
|
+
* 把宿主语言收敛成前端认识的两个值。
|
|
465
|
+
* @param ctx - Client 插件上下文。
|
|
466
|
+
* @returns `'zh-CN'` 或 `'en-US'`(上游 Locale 的合法值)。
|
|
317
467
|
*/
|
|
318
|
-
function
|
|
319
|
-
if (!attached(element)) return undefined;
|
|
468
|
+
function hostLocale(ctx) {
|
|
320
469
|
try {
|
|
321
|
-
const
|
|
322
|
-
|
|
470
|
+
const active = ctx.locale.getSnapshot?.()?.active;
|
|
471
|
+
if (typeof active === 'string' && active.length > 0) {
|
|
472
|
+
return active.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
|
|
473
|
+
}
|
|
323
474
|
} catch {
|
|
324
|
-
|
|
475
|
+
// 快照不可用:退回文档语言。
|
|
325
476
|
}
|
|
477
|
+
const lang = typeof document?.documentElement?.lang === 'string' ? document.documentElement.lang : '';
|
|
478
|
+
return lang.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
|
|
326
479
|
}
|
|
327
480
|
|
|
328
481
|
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
482
|
+
* 量出 DSH 顶部占位(侧栏收起后的悬浮岛)的高度。
|
|
483
|
+
*
|
|
484
|
+
* DSH 在主面板左上角盖了一个 `shell.leading` 座位;框架会给出
|
|
485
|
+
* `--dsh-frame-leading-clearance`,但 iframe 拿不到宿主的 CSS 变量,
|
|
486
|
+
* 所以这里直接量座位元素的实际底边,再把数字发给面板。
|
|
487
|
+
* @returns 需要让出的顶部高度,没有座位时为 0。
|
|
333
488
|
*/
|
|
334
|
-
function
|
|
335
|
-
if (!attached(element)) return false;
|
|
489
|
+
function measureSeatInset(host) {
|
|
336
490
|
try {
|
|
337
|
-
const
|
|
338
|
-
if (
|
|
339
|
-
|
|
491
|
+
const seat = document.querySelector('[class*="leadingSeat"]');
|
|
492
|
+
if (seat !== null) {
|
|
493
|
+
const rect = seat.getBoundingClientRect();
|
|
494
|
+
if (rect.width > 0 || rect.height > 0) return Math.ceil(rect.bottom + 8);
|
|
340
495
|
}
|
|
341
|
-
|
|
496
|
+
// 兜底:座位元素找不到(例如上游改了类名),但框架声明了 leading clearance,
|
|
497
|
+
// 说明座位仍然挂在主面板上方,用一个保守高度让开。
|
|
498
|
+
const probe = host ?? document.querySelector('[class*="mainPanel"]') ?? document.body;
|
|
499
|
+
const clearance = getComputedStyle(probe).getPropertyValue('--dsh-frame-leading-clearance');
|
|
500
|
+
if (Number.parseFloat(clearance) > 0) return 48;
|
|
342
501
|
} catch {
|
|
343
|
-
|
|
502
|
+
// 量不到就让开 0:宁可重叠,也不要凭空留一条空白。
|
|
344
503
|
}
|
|
504
|
+
return 0;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* 读设置。
|
|
509
|
+
* @returns `{ retentionDays }`;失败时抛出。
|
|
510
|
+
*/
|
|
511
|
+
async function fetchSettings() {
|
|
512
|
+
const response = await fetch(`${ROUTE_PREFIX}/api/settings`, { headers: { accept: 'application/json' } });
|
|
513
|
+
if (!response.ok) throw new Error(`settings ${response.status}`);
|
|
514
|
+
return response.json();
|
|
345
515
|
}
|
|
346
516
|
|
|
347
517
|
/**
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
* @
|
|
351
|
-
* @returns the glyph element.
|
|
518
|
+
* 写设置。
|
|
519
|
+
* @param retentionDays - 保留天数,0 表示永不。
|
|
520
|
+
* @returns 落盘后的设置。
|
|
352
521
|
*/
|
|
353
|
-
function
|
|
354
|
-
|
|
522
|
+
async function saveSettings(retentionDays) {
|
|
523
|
+
const response = await fetch(`${ROUTE_PREFIX}/api/settings`, {
|
|
524
|
+
method: 'POST',
|
|
525
|
+
headers: { 'content-type': 'application/json' },
|
|
526
|
+
body: JSON.stringify({ retentionDays }),
|
|
527
|
+
});
|
|
528
|
+
if (!response.ok) throw new Error(`settings ${response.status}`);
|
|
529
|
+
return response.json();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/** 侧栏图标:与 icon.svg 同形,用 currentColor 跟随侧栏配色。 */
|
|
533
|
+
function Glyph(props) {
|
|
534
|
+
const size = typeof props?.size === 'number' ? props.size : 16;
|
|
535
|
+
return h(
|
|
355
536
|
'svg',
|
|
356
537
|
{
|
|
538
|
+
viewBox: '0 0 24 24',
|
|
357
539
|
width: size,
|
|
358
540
|
height: size,
|
|
359
|
-
viewBox: '0 0 24 24',
|
|
360
541
|
fill: 'none',
|
|
361
|
-
|
|
362
|
-
|
|
542
|
+
stroke: 'currentColor',
|
|
543
|
+
'aria-hidden': true,
|
|
544
|
+
'data-vtwc-glyph': 'true',
|
|
545
|
+
style: { display: 'block' },
|
|
363
546
|
},
|
|
364
|
-
|
|
547
|
+
h('path', {
|
|
365
548
|
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',
|
|
366
|
-
stroke: 'currentColor',
|
|
367
549
|
strokeWidth: 1.3,
|
|
368
550
|
strokeLinejoin: 'round',
|
|
369
551
|
}),
|
|
370
|
-
|
|
552
|
+
h('path', {
|
|
371
553
|
d: 'M8.5 11.5h.01M12 11.5h.01M15.5 11.5h.01',
|
|
372
|
-
stroke: 'currentColor',
|
|
373
554
|
strokeWidth: 1.6,
|
|
374
555
|
strokeLinecap: 'round',
|
|
375
556
|
}),
|
|
376
557
|
);
|
|
377
558
|
}
|
|
378
559
|
|
|
379
|
-
const styles = {
|
|
380
|
-
root: {
|
|
381
|
-
display: 'flex',
|
|
382
|
-
flexDirection: 'column',
|
|
383
|
-
height: '100%',
|
|
384
|
-
minHeight: '0',
|
|
385
|
-
background: 'var(--dsw-alias-bg-base)',
|
|
386
|
-
color: 'var(--dsw-alias-label-primary)',
|
|
387
|
-
},
|
|
388
|
-
host: {
|
|
389
|
-
position: 'relative',
|
|
390
|
-
flex: '1',
|
|
391
|
-
minHeight: '0',
|
|
392
|
-
display: 'flex',
|
|
393
|
-
},
|
|
394
|
-
guest: {
|
|
395
|
-
width: '100%',
|
|
396
|
-
height: '100%',
|
|
397
|
-
border: '0',
|
|
398
|
-
background: 'transparent',
|
|
399
|
-
display: 'flex',
|
|
400
|
-
},
|
|
401
|
-
overlay: {
|
|
402
|
-
position: 'absolute',
|
|
403
|
-
inset: '0',
|
|
404
|
-
zIndex: '1',
|
|
405
|
-
display: 'flex',
|
|
406
|
-
flexDirection: 'column',
|
|
407
|
-
alignItems: 'center',
|
|
408
|
-
justifyContent: 'center',
|
|
409
|
-
gap: '10px',
|
|
410
|
-
padding: '24px',
|
|
411
|
-
textAlign: 'center',
|
|
412
|
-
color: 'var(--dsw-alias-label-tertiary)',
|
|
413
|
-
fontSize: '12px',
|
|
414
|
-
lineHeight: '18px',
|
|
415
|
-
background: 'var(--dsw-alias-bg-base)',
|
|
416
|
-
},
|
|
417
|
-
overlayTitle: {
|
|
418
|
-
color: 'var(--dsw-alias-label-primary)',
|
|
419
|
-
fontSize: '13px',
|
|
420
|
-
lineHeight: '20px',
|
|
421
|
-
},
|
|
422
|
-
actions: {
|
|
423
|
-
display: 'flex',
|
|
424
|
-
alignItems: 'center',
|
|
425
|
-
gap: '8px',
|
|
426
|
-
},
|
|
427
|
-
button: {
|
|
428
|
-
color: 'var(--dsw-alias-label-primary)',
|
|
429
|
-
background: 'var(--dsw-alias-bg-layer-1)',
|
|
430
|
-
border: '.5px solid var(--dsw-alias-border-l2)',
|
|
431
|
-
borderRadius: 'var(--dsw-radius-sm)',
|
|
432
|
-
padding: '4px 12px',
|
|
433
|
-
cursor: 'pointer',
|
|
434
|
-
fontSize: '12px',
|
|
435
|
-
lineHeight: '18px',
|
|
436
|
-
},
|
|
437
|
-
linkButton: {
|
|
438
|
-
border: '0',
|
|
439
|
-
padding: '0',
|
|
440
|
-
background: 'transparent',
|
|
441
|
-
color: 'var(--dsw-alias-brand-primary)',
|
|
442
|
-
cursor: 'pointer',
|
|
443
|
-
fontSize: '12px',
|
|
444
|
-
lineHeight: '18px',
|
|
445
|
-
},
|
|
446
|
-
signInBar: {
|
|
447
|
-
display: 'flex',
|
|
448
|
-
alignItems: 'center',
|
|
449
|
-
gap: '8px',
|
|
450
|
-
flex: 'none',
|
|
451
|
-
padding: '6px 12px',
|
|
452
|
-
borderBottom: '.5px solid var(--dsw-alias-border-l1)',
|
|
453
|
-
background: 'var(--dsw-alias-bg-layer-1)',
|
|
454
|
-
color: 'var(--dsw-alias-label-secondary)',
|
|
455
|
-
fontSize: '12px',
|
|
456
|
-
lineHeight: '18px',
|
|
457
|
-
},
|
|
458
|
-
signInText: {
|
|
459
|
-
flex: '1',
|
|
460
|
-
minWidth: '0',
|
|
461
|
-
},
|
|
462
|
-
};
|
|
463
|
-
|
|
464
560
|
/**
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
561
|
+
* 返回箭头:DSH 官方 onboarding-back.svg 的路径与描边。
|
|
562
|
+
* 路径按 16px 图标网格缩放(不是铺满 24px 占位槽);
|
|
563
|
+
* non-scaling-stroke 让 1.18823 的描边粗细不随缩放变细。
|
|
468
564
|
*/
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
565
|
+
function BackIcon() {
|
|
566
|
+
return h(
|
|
567
|
+
'svg',
|
|
568
|
+
{
|
|
569
|
+
viewBox: '0 0 20.2792 16.825',
|
|
570
|
+
width: 16,
|
|
571
|
+
height: 16,
|
|
572
|
+
preserveAspectRatio: 'xMidYMid meet',
|
|
573
|
+
fill: 'none',
|
|
574
|
+
'aria-hidden': true,
|
|
575
|
+
style: { display: 'block' },
|
|
576
|
+
},
|
|
577
|
+
h('path', {
|
|
578
|
+
d: 'M1.01986 8.58958H20.2792M8.54303 0.407656L0.825554 8.58958L8.54303 16.4077',
|
|
579
|
+
stroke: 'currentColor',
|
|
580
|
+
strokeWidth: 1.18823,
|
|
581
|
+
vectorEffect: 'non-scaling-stroke',
|
|
582
|
+
}),
|
|
583
|
+
);
|
|
584
|
+
}
|
|
474
585
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
586
|
+
/**
|
|
587
|
+
* 面板本体:一个占满主内容区的同源 iframe。
|
|
588
|
+
* @param props - locale、inset、hostRef、frameRef。
|
|
589
|
+
* @returns 面板容器。
|
|
590
|
+
*/
|
|
591
|
+
function Panel(props) {
|
|
592
|
+
const frameRef = props.frameRef;
|
|
593
|
+
const inset = props.inset ?? 0;
|
|
478
594
|
|
|
479
|
-
|
|
595
|
+
// 座位高度用 postMessage 传进去:面板是独立文档,读不到宿主的布局状态。
|
|
596
|
+
const pushSeat = React.useCallback(() => {
|
|
597
|
+
const win = frameRef.current === null ? null : frameRef.current.contentWindow;
|
|
598
|
+
if (win === null) return;
|
|
480
599
|
try {
|
|
481
|
-
|
|
600
|
+
win.postMessage({ type: 'vt-webchat:seat', inset }, '*');
|
|
482
601
|
} catch {
|
|
483
|
-
|
|
602
|
+
// 面板还没准备好:等 onLoad 再发一次。
|
|
484
603
|
}
|
|
485
|
-
}
|
|
604
|
+
}, [frameRef, inset]);
|
|
486
605
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
606
|
+
React.useEffect(pushSeat, [pushSeat]);
|
|
607
|
+
|
|
608
|
+
const onLoad = () => {
|
|
609
|
+
panelLink.attach(frameRef.current === null ? null : frameRef.current.contentWindow);
|
|
610
|
+
panelLink.post({ type: 'request-sync' });
|
|
611
|
+
pushSeat();
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
return h(
|
|
615
|
+
'div',
|
|
616
|
+
{
|
|
617
|
+
// 容器留在宿主文档里,用来读取继承下来的框架变量(座位是否挂载)。
|
|
618
|
+
ref: props.hostRef,
|
|
619
|
+
style: {
|
|
620
|
+
height: '100%',
|
|
621
|
+
minHeight: 320,
|
|
622
|
+
display: 'flex',
|
|
623
|
+
background: 'var(--dsw-alias-bg-layer-1, #fff)',
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
h('iframe', {
|
|
627
|
+
ref: frameRef,
|
|
628
|
+
onLoad,
|
|
629
|
+
src: panelUrl(props.locale ?? 'zh-CN'),
|
|
630
|
+
title: 'DeepSeek',
|
|
631
|
+
allow: 'clipboard-write; microphone',
|
|
632
|
+
style: { width: '100%', height: '100%', border: 'none', display: 'block', background: 'transparent' },
|
|
633
|
+
}),
|
|
634
|
+
);
|
|
516
635
|
}
|
|
517
636
|
|
|
518
637
|
/**
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
* `name`/`partition`/`src` already set, because the main process inspects
|
|
523
|
-
* exactly that bootstrap src when it approves the attachment. The first load
|
|
524
|
-
* goes to the remembered conversation; navigation events keep that memory
|
|
525
|
-
* current. A dead guest (crash, destroy, failed start) turns into a retry
|
|
526
|
-
* card inside the panel; cleanup releases the lease and never calls into a
|
|
527
|
-
* detached element.
|
|
528
|
-
* @param props - slot props; `t` and `locale` arrive through registration.
|
|
529
|
-
* @returns the panel element tree.
|
|
638
|
+
* 主面板外壳:挂载即进入 Chat 模式,卸载即退出;
|
|
639
|
+
* 同时负责把 iframe 的窗口登记给侧栏桥,并转发面板消息。
|
|
640
|
+
* @returns 面板。
|
|
530
641
|
*/
|
|
531
|
-
function
|
|
532
|
-
const
|
|
533
|
-
const
|
|
534
|
-
useLocaleRevision(locale);
|
|
535
|
-
|
|
642
|
+
function PanelShell(props) {
|
|
643
|
+
const ctx = props.ctx;
|
|
644
|
+
const frameRef = React.useRef(null);
|
|
536
645
|
const hostRef = React.useRef(null);
|
|
537
|
-
const
|
|
538
|
-
const [
|
|
539
|
-
const [failure, setFailure] = React.useState(undefined);
|
|
540
|
-
const [authPage, setAuthPage] = React.useState(false);
|
|
541
|
-
const [attempt, setAttempt] = React.useState(0);
|
|
646
|
+
const [locale, setLocale] = React.useState(() => hostLocale(ctx));
|
|
647
|
+
const [inset, setInset] = React.useState(() => measureSeatInset(null));
|
|
542
648
|
|
|
543
|
-
|
|
544
|
-
try {
|
|
545
|
-
setPhase('loading');
|
|
546
|
-
setFailure(undefined);
|
|
547
|
-
setAuthPage(false);
|
|
548
|
-
setAttempt((value) => value + 1);
|
|
549
|
-
} catch {
|
|
550
|
-
/* the panel is gone */
|
|
551
|
-
}
|
|
552
|
-
}, []);
|
|
649
|
+
React.useEffect(() => ctx.locale.subscribe(() => setLocale(hostLocale(ctx))), [ctx]);
|
|
553
650
|
|
|
651
|
+
// 主面板只在被选中时挂载:挂载/卸载就是 Chat 模式的开关。
|
|
554
652
|
React.useEffect(() => {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
// 一旦壳升版,这里会拿到形状不对的对象,表现为「打不开、重试」而看不出原因。
|
|
559
|
-
const carrier = globalThis.dshDesktop;
|
|
560
|
-
const bridge = carrier?.protocolVersion === 1 ? carrier.browser : undefined;
|
|
561
|
-
if (host === null) return undefined;
|
|
562
|
-
if (bridge === undefined) {
|
|
563
|
-
try {
|
|
564
|
-
setPhase('unsupported');
|
|
565
|
-
} catch {
|
|
566
|
-
/* the panel is gone */
|
|
567
|
-
}
|
|
568
|
-
return undefined;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
let disposed = false;
|
|
572
|
-
let unsubscribeOpen;
|
|
573
|
-
let lease;
|
|
574
|
-
let watchdog;
|
|
575
|
-
let started = false;
|
|
576
|
-
const element = document.createElement('webview');
|
|
577
|
-
const initialTarget = rememberedTarget();
|
|
578
|
-
let restoring = initialTarget !== CHAT_URL;
|
|
579
|
-
|
|
580
|
-
Object.assign(element.style, styles.guest);
|
|
581
|
-
element.setAttribute('allowpopups', '');
|
|
582
|
-
|
|
583
|
-
/** Report a guest failure inside the panel; never throw. */
|
|
584
|
-
const fail = (error) => {
|
|
585
|
-
if (disposed) return;
|
|
586
|
-
try {
|
|
587
|
-
setPhase('failed');
|
|
588
|
-
setFailure(String((error && error.message) || error));
|
|
589
|
-
} catch {
|
|
590
|
-
/* the panel is gone */
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
/** Remember a URL reported by the guest and refresh the sign-in notice. */
|
|
595
|
-
const remember = (raw) => {
|
|
596
|
-
const url = parseChatUrl(raw);
|
|
597
|
-
if (url === undefined) return;
|
|
598
|
-
lastUrlRef.current = url.toString();
|
|
599
|
-
rememberTarget(url.toString());
|
|
600
|
-
try {
|
|
601
|
-
setAuthPage(isAuthUrl(url.toString()));
|
|
602
|
-
} catch {
|
|
603
|
-
/* the panel is gone */
|
|
604
|
-
}
|
|
605
|
-
};
|
|
653
|
+
enterSurface();
|
|
654
|
+
return () => leaveSurface();
|
|
655
|
+
}, []);
|
|
606
656
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
};
|
|
657
|
+
React.useEffect(() => {
|
|
658
|
+
const frame = frameRef.current;
|
|
659
|
+
const win = frame === null ? null : frame.contentWindow;
|
|
660
|
+
panelLink.attach(win);
|
|
613
661
|
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
fail(new Error(t('crashed')));
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
remember(initialTarget);
|
|
662
|
+
const onMessage = (event) => {
|
|
663
|
+
const current = frameRef.current;
|
|
664
|
+
if (current === null || event.source !== current.contentWindow) return;
|
|
665
|
+
handleHostMessage(event.data);
|
|
622
666
|
};
|
|
667
|
+
window.addEventListener('message', onMessage);
|
|
623
668
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
if (raw !== undefined) remember(raw);
|
|
628
|
-
restoring = false;
|
|
629
|
-
// Only a site document can carry the preferences; about:blank cannot.
|
|
630
|
-
if (parseChatUrl(raw) !== undefined) applyGuestPreferences(element);
|
|
631
|
-
try {
|
|
632
|
-
setPhase('ready');
|
|
633
|
-
setFailure(undefined);
|
|
634
|
-
} catch {
|
|
635
|
-
/* the panel is gone */
|
|
636
|
-
}
|
|
637
|
-
};
|
|
669
|
+
// 面板脚本可能在监听装好之前就完成了首帧:几次请求同步兜住这个窗口。
|
|
670
|
+
const request = () => panelLink.post({ type: 'request-sync' });
|
|
671
|
+
const timers = [0, 300, 1200, 3000].map((delay) => setTimeout(request, delay));
|
|
638
672
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
673
|
+
return () => {
|
|
674
|
+
for (const timer of timers) clearTimeout(timer);
|
|
675
|
+
window.removeEventListener('message', onMessage);
|
|
676
|
+
panelLink.detach(win);
|
|
642
677
|
};
|
|
678
|
+
}, []);
|
|
643
679
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
680
|
+
React.useEffect(() => {
|
|
681
|
+
let timer;
|
|
682
|
+
const schedule = () => {
|
|
683
|
+
if (timer !== undefined) return;
|
|
684
|
+
timer = setTimeout(() => {
|
|
685
|
+
timer = undefined;
|
|
686
|
+
setInset(measureSeatInset(hostRef.current));
|
|
687
|
+
}, 120);
|
|
649
688
|
};
|
|
650
|
-
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
if (!navigate(element, CHAT_URL)) fail(new Error(t('crashed')));
|
|
659
|
-
else remember(CHAT_URL);
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
fail(event.errorDescription ?? event.errorCode);
|
|
689
|
+
// 侧栏开合会换掉框架的子节点,座位随之出现或消失。
|
|
690
|
+
const observer = new MutationObserver(schedule);
|
|
691
|
+
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] });
|
|
692
|
+
const resizer = new ResizeObserver(schedule);
|
|
693
|
+
resizer.observe(document.documentElement);
|
|
694
|
+
window.addEventListener('resize', schedule);
|
|
695
|
+
const onMessage = (event) => {
|
|
696
|
+
if (event.data?.type === 'vt-webchat:hello') setInset(measureSeatInset(hostRef.current));
|
|
663
697
|
};
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
698
|
+
window.addEventListener('message', onMessage);
|
|
699
|
+
return () => {
|
|
700
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
701
|
+
observer.disconnect();
|
|
702
|
+
resizer.disconnect();
|
|
703
|
+
window.removeEventListener('resize', schedule);
|
|
704
|
+
window.removeEventListener('message', onMessage);
|
|
669
705
|
};
|
|
706
|
+
}, []);
|
|
670
707
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
['did-stop-loading', onStopLoading],
|
|
674
|
-
['did-navigate', onNavigate],
|
|
675
|
-
['did-navigate-in-page', onNavigateInPage],
|
|
676
|
-
['did-fail-load', onFailLoad],
|
|
677
|
-
['render-process-gone', onGuestGone],
|
|
678
|
-
['destroyed', onGuestGone],
|
|
679
|
-
];
|
|
708
|
+
return h(Panel, { locale, inset, hostRef, frameRef });
|
|
709
|
+
}
|
|
680
710
|
|
|
711
|
+
/**
|
|
712
|
+
* 设置区块:四个保留档位,点一下即保存。
|
|
713
|
+
*
|
|
714
|
+
* 文案一律走字符串字典:语言服务对函数值不保证透传,
|
|
715
|
+
* 之前的 `t(key)(...)` 在宿主里拿到空串后整块区域会被 React 卸载。
|
|
716
|
+
*/
|
|
717
|
+
function RetentionSettings(props) {
|
|
718
|
+
const t = (key) => {
|
|
681
719
|
try {
|
|
682
|
-
|
|
683
|
-
|
|
720
|
+
if (typeof props?.t === 'function') {
|
|
721
|
+
const value = props.t(key);
|
|
722
|
+
if (typeof value === 'string' && value.length > 0 && value !== key) return value;
|
|
684
723
|
}
|
|
685
|
-
} catch
|
|
686
|
-
|
|
724
|
+
} catch {
|
|
725
|
+
// 语言服务不可用:退回内置字典,不让设置区跟着崩。
|
|
687
726
|
}
|
|
727
|
+
return DICT.en[key] ?? key;
|
|
728
|
+
};
|
|
729
|
+
const [days, setDays] = React.useState(30);
|
|
730
|
+
const [state, setState] = React.useState('idle');
|
|
688
731
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
}
|
|
700
|
-
lease = reservation.lease;
|
|
701
|
-
element.setAttribute('name', reservation.lease);
|
|
702
|
-
element.setAttribute('partition', reservation.partition);
|
|
703
|
-
element.setAttribute('src', `about:blank#${reservation.lease}`);
|
|
704
|
-
try {
|
|
705
|
-
unsubscribeOpen = bridge.onOpenRequested(reservation.lease, (url) => {
|
|
706
|
-
if (!disposed && typeof url === 'string') navigate(element, url);
|
|
707
|
-
});
|
|
708
|
-
} catch {
|
|
709
|
-
/* popup bridge unavailable: the guest still works */
|
|
710
|
-
}
|
|
711
|
-
host.append(element);
|
|
712
|
-
watchdog = setTimeout(() => {
|
|
713
|
-
watchdog = undefined;
|
|
714
|
-
if (disposed || started) return;
|
|
715
|
-
fail(new Error(t('timeout')));
|
|
716
|
-
}, WATCHDOG_MS);
|
|
717
|
-
} catch (error) {
|
|
718
|
-
fail(error);
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
void start();
|
|
722
|
-
|
|
732
|
+
React.useEffect(() => {
|
|
733
|
+
let alive = true;
|
|
734
|
+
fetchSettings()
|
|
735
|
+
.then((value) => {
|
|
736
|
+
if (!alive) return;
|
|
737
|
+
if (typeof value?.retentionDays === 'number') setDays(value.retentionDays);
|
|
738
|
+
})
|
|
739
|
+
.catch(() => {
|
|
740
|
+
if (alive) setState('load-failed');
|
|
741
|
+
});
|
|
723
742
|
return () => {
|
|
724
|
-
|
|
725
|
-
// Read before removal: React cleans up after taking the DOM away, and
|
|
726
|
-
// Electron's getURL() throws on a detached webview.
|
|
727
|
-
const current = readUrl(element);
|
|
728
|
-
if (current !== undefined) {
|
|
729
|
-
lastUrlRef.current = current;
|
|
730
|
-
rememberTarget(current);
|
|
731
|
-
}
|
|
732
|
-
clearWatchdog();
|
|
733
|
-
try {
|
|
734
|
-
if (typeof unsubscribeOpen === 'function') unsubscribeOpen();
|
|
735
|
-
} catch {
|
|
736
|
-
/* already detached */
|
|
737
|
-
}
|
|
738
|
-
for (const [type, handler] of listeners) {
|
|
739
|
-
try {
|
|
740
|
-
element.removeEventListener(type, handler);
|
|
741
|
-
} catch {
|
|
742
|
-
/* already detached */
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
try {
|
|
746
|
-
element.remove();
|
|
747
|
-
} catch {
|
|
748
|
-
/* already detached */
|
|
749
|
-
}
|
|
750
|
-
const released = lease;
|
|
751
|
-
lease = undefined;
|
|
752
|
-
if (released !== undefined) {
|
|
753
|
-
try {
|
|
754
|
-
Promise.resolve(bridge.release(released)).catch(() => {});
|
|
755
|
-
} catch {
|
|
756
|
-
/* lease already gone */
|
|
757
|
-
}
|
|
758
|
-
}
|
|
743
|
+
alive = false;
|
|
759
744
|
};
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
745
|
+
}, []);
|
|
746
|
+
|
|
747
|
+
const choose = (value) => {
|
|
748
|
+
if (state === 'saving') return;
|
|
749
|
+
const previous = days;
|
|
750
|
+
setDays(value);
|
|
751
|
+
setState('saving');
|
|
752
|
+
saveSettings(value)
|
|
753
|
+
.then((saved) => {
|
|
754
|
+
setDays(Number(saved?.retentionDays ?? value));
|
|
755
|
+
setState('saved');
|
|
756
|
+
})
|
|
757
|
+
.catch(() => {
|
|
758
|
+
setDays(previous);
|
|
759
|
+
setState('failed');
|
|
760
|
+
});
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
const status =
|
|
764
|
+
state === 'saving'
|
|
765
|
+
? t('settings.saving')
|
|
766
|
+
: state === 'saved'
|
|
767
|
+
? t('settings.saved')
|
|
768
|
+
: state === 'failed'
|
|
769
|
+
? t('settings.failed')
|
|
770
|
+
: state === 'load-failed'
|
|
771
|
+
? t('settings.loadFailed')
|
|
772
|
+
: '';
|
|
763
773
|
|
|
764
|
-
|
|
765
|
-
|
|
774
|
+
return h(
|
|
775
|
+
'section',
|
|
776
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 10, padding: '4px 0 8px' } },
|
|
777
|
+
h(
|
|
766
778
|
'div',
|
|
767
|
-
{ style:
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
React.createElement(
|
|
774
|
-
'div',
|
|
775
|
-
{ style: styles.actions },
|
|
776
|
-
React.createElement(
|
|
777
|
-
'button',
|
|
778
|
-
{ type: 'button', style: styles.button, onClick: () => openExternally(CHAT_URL) },
|
|
779
|
-
t('openExternal'),
|
|
780
|
-
),
|
|
781
|
-
),
|
|
779
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
780
|
+
h('h3', { style: { margin: 0, fontSize: 14, fontWeight: 600, color: 'var(--dsw-alias-label-primary, #0f1115)' } }, t('settings.title')),
|
|
781
|
+
h(
|
|
782
|
+
'p',
|
|
783
|
+
{ style: { margin: 0, fontSize: 13, lineHeight: 1.6, color: 'var(--dsw-alias-label-secondary, #61656e)' } },
|
|
784
|
+
t('settings.description'),
|
|
782
785
|
),
|
|
783
|
-
)
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
return React.createElement(
|
|
787
|
-
'div',
|
|
788
|
-
{ style: styles.root, role: 'region', 'aria-label': t('title') },
|
|
789
|
-
phase === 'ready' && authPage
|
|
790
|
-
? React.createElement(
|
|
791
|
-
'div',
|
|
792
|
-
{ style: styles.signInBar },
|
|
793
|
-
React.createElement('span', { style: styles.signInText }, t('signInHint')),
|
|
794
|
-
React.createElement(
|
|
795
|
-
'button',
|
|
796
|
-
{
|
|
797
|
-
type: 'button',
|
|
798
|
-
style: styles.linkButton,
|
|
799
|
-
onClick: () => openExternally('https://chat.deepseek.com/sign_in'),
|
|
800
|
-
},
|
|
801
|
-
t('signInAction'),
|
|
802
|
-
),
|
|
803
|
-
)
|
|
804
|
-
: null,
|
|
805
|
-
React.createElement(
|
|
786
|
+
),
|
|
787
|
+
h(
|
|
806
788
|
'div',
|
|
807
|
-
{ style:
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
789
|
+
{ style: { display: 'flex', flexWrap: 'wrap', gap: 8 } },
|
|
790
|
+
RETENTION_CHOICES.map((value) =>
|
|
791
|
+
h(
|
|
792
|
+
'button',
|
|
793
|
+
{
|
|
794
|
+
key: value,
|
|
795
|
+
type: 'button',
|
|
796
|
+
onClick: () => choose(value),
|
|
797
|
+
'aria-pressed': days === value,
|
|
798
|
+
style: {
|
|
799
|
+
minWidth: 64,
|
|
800
|
+
padding: '6px 14px',
|
|
801
|
+
borderRadius: 999,
|
|
802
|
+
font: 'inherit',
|
|
803
|
+
fontSize: 13,
|
|
804
|
+
cursor: state === 'saving' ? 'progress' : 'pointer',
|
|
805
|
+
border:
|
|
806
|
+
days === value
|
|
807
|
+
? '1px solid var(--dsw-alias-brand-primary, #0f1115)'
|
|
808
|
+
: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,0.12))',
|
|
809
|
+
// 选中态用宿主自己的配对:品牌色做底、反色做字。
|
|
810
|
+
// 暗色下 brand-primary 是近白,反色是深灰;亮色下正好相反。
|
|
811
|
+
background:
|
|
812
|
+
days === value ? 'var(--dsw-alias-brand-primary, #0f1115)' : 'transparent',
|
|
813
|
+
color:
|
|
814
|
+
days === value
|
|
815
|
+
? 'var(--dsw-alias-label-primary-inverted, #fff)'
|
|
816
|
+
: 'var(--dsw-alias-label-primary, #0f1115)',
|
|
817
|
+
},
|
|
818
|
+
},
|
|
819
|
+
value === 0 ? t('settings.never') : t(`settings.days${value}`),
|
|
820
|
+
),
|
|
812
821
|
),
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
React.createElement(
|
|
823
|
-
'button',
|
|
824
|
-
{ type: 'button', style: styles.button, onClick: retry },
|
|
825
|
-
t('retry'),
|
|
826
|
-
),
|
|
827
|
-
React.createElement(
|
|
828
|
-
'button',
|
|
829
|
-
{
|
|
830
|
-
type: 'button',
|
|
831
|
-
style: styles.linkButton,
|
|
832
|
-
onClick: () => openExternally(CHAT_URL),
|
|
833
|
-
},
|
|
834
|
-
t('openExternal'),
|
|
835
|
-
),
|
|
836
|
-
),
|
|
837
|
-
)
|
|
838
|
-
: null,
|
|
822
|
+
),
|
|
823
|
+
h(
|
|
824
|
+
'p',
|
|
825
|
+
{ style: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-label-tertiary, #8b8f98)' } },
|
|
826
|
+
status.length > 0
|
|
827
|
+
? status
|
|
828
|
+
: days === 0
|
|
829
|
+
? t('settings.currentNever')
|
|
830
|
+
: t('settings.currentDays').replace('{n}', String(days)),
|
|
839
831
|
),
|
|
840
832
|
);
|
|
841
833
|
}
|
|
842
834
|
|
|
843
|
-
/**
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
{
|
|
848
|
-
|
|
849
|
-
|
|
835
|
+
/** 设置区块的最小错误边界:DSH 没有为设置区提供边界,一个渲染错误会整页空白。 */
|
|
836
|
+
class SettingsBoundary extends React.Component {
|
|
837
|
+
constructor(props) {
|
|
838
|
+
super(props);
|
|
839
|
+
this.state = { failed: false };
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
static getDerivedStateFromError() {
|
|
843
|
+
return { failed: true };
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
componentDidCatch(error) {
|
|
847
|
+
console.error(`${PLUGIN_ID}: settings section failed`, error);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
render() {
|
|
851
|
+
if (this.state.failed) {
|
|
852
|
+
return h(
|
|
853
|
+
'p',
|
|
854
|
+
{ style: { margin: 0, fontSize: 13, color: 'var(--dsw-alias-label-secondary, #61656e)' } },
|
|
855
|
+
this.props.fallback,
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
return this.props.children;
|
|
859
|
+
}
|
|
850
860
|
}
|
|
851
861
|
|
|
852
|
-
/**
|
|
853
|
-
const
|
|
862
|
+
/** Chat 模式的样式。用宿主 token,深浅色和字体大小自动跟随。 */
|
|
863
|
+
const CHAT_CSS = `
|
|
864
|
+
/* Chat 模式下,全局面板行让位给 Chat 自己的动线。
|
|
865
|
+
座位 API 只能追加,不能删掉别的插件已经注册的行,所以这里按稳定的业务标识
|
|
866
|
+
精确隐藏:全局面板行、DS Bot 的返回按钮、额度条。离开 Chat 模式后属性移除,
|
|
867
|
+
这些行原样恢复;账号/设置行保持可用。 */
|
|
868
|
+
html[data-vtwc-surface='chat'] [class*="panelList"] { display: none; }
|
|
869
|
+
html[data-vtwc-surface='chat'] .bt-return { display: none !important; }
|
|
870
|
+
html[data-vtwc-surface='chat'] [data-plugin='dsh-vt-quote-bar'] { display: none !important; }
|
|
871
|
+
/* 返回后短暂压掉底栏两行的 hover 底色,避免看起来像返回按钮的状态滞留。 */
|
|
872
|
+
html[data-vtwc-returning='true'] .vtq-collapsed:hover { background-color: transparent !important; }
|
|
873
|
+
html[data-vtwc-returning='true'] .bt-return:hover { background-color: var(--bt-return-fill, transparent) !important; }
|
|
874
|
+
.vtwc-brand {
|
|
875
|
+
display: inline-flex;
|
|
876
|
+
align-items: center;
|
|
877
|
+
min-width: 0;
|
|
878
|
+
height: 24px;
|
|
879
|
+
cursor: default;
|
|
880
|
+
animation: vtwc-brand-in 200ms cubic-bezier(.2, .8, .2, 1);
|
|
881
|
+
}
|
|
882
|
+
.vtwc-brand[data-vtwc-leaving='true'] { animation: vtwc-brand-out 150ms ease forwards; }
|
|
883
|
+
.vtwc-brand-wordmark { display: inline-flex; flex: none; width: 103.35px; height: 24px; overflow: hidden; }
|
|
884
|
+
.vtwc-brand-wordmark > svg { display: block; flex: none; }
|
|
885
|
+
.vtwc-brand-fallback {
|
|
886
|
+
font-size: 18px;
|
|
887
|
+
font-weight: 600;
|
|
888
|
+
line-height: 24px;
|
|
889
|
+
letter-spacing: .04em;
|
|
890
|
+
color: var(--dsw-alias-label-primary);
|
|
891
|
+
}
|
|
892
|
+
.vtwc-brand-badge {
|
|
893
|
+
display: inline-flex;
|
|
894
|
+
align-items: center;
|
|
895
|
+
justify-content: center;
|
|
896
|
+
flex: none;
|
|
897
|
+
width: 52px;
|
|
898
|
+
height: 14px;
|
|
899
|
+
border-radius: 2px;
|
|
900
|
+
background: var(--dsw-alias-label-primary);
|
|
901
|
+
color: var(--dsw-specific-sidebar-fill);
|
|
902
|
+
font-family: var(--ds-font-family-code);
|
|
903
|
+
font-size: 10px;
|
|
904
|
+
font-weight: 500;
|
|
905
|
+
line-height: 14px;
|
|
906
|
+
letter-spacing: .08em;
|
|
907
|
+
}
|
|
908
|
+
.vtwc-region {
|
|
909
|
+
display: flex;
|
|
910
|
+
flex-direction: column;
|
|
911
|
+
min-height: 0;
|
|
912
|
+
height: 100%;
|
|
913
|
+
padding-top: 6px;
|
|
914
|
+
animation: vtwc-in 200ms cubic-bezier(.2, .8, .2, 1);
|
|
915
|
+
}
|
|
916
|
+
.vtwc-region[data-vtwc-leaving='true'] { animation: vtwc-out 150ms ease forwards; }
|
|
917
|
+
.vtwc-list {
|
|
918
|
+
flex: 1;
|
|
919
|
+
min-height: 0;
|
|
920
|
+
margin: 0 -2px;
|
|
921
|
+
padding: 0 2px 8px;
|
|
922
|
+
overflow-y: auto;
|
|
923
|
+
overscroll-behavior: contain;
|
|
924
|
+
scrollbar-color: var(--dsh-scrollbar-thumb) transparent;
|
|
925
|
+
}
|
|
926
|
+
.vtwc-group { margin-top: 16px; }
|
|
927
|
+
.vtwc-group:first-child { margin-top: 0; }
|
|
928
|
+
.vtwc-group-label {
|
|
929
|
+
position: sticky;
|
|
930
|
+
top: 0;
|
|
931
|
+
z-index: 1;
|
|
932
|
+
padding: 2px 10px;
|
|
933
|
+
background: var(--dsw-specific-sidebar-fill);
|
|
934
|
+
color: var(--dsw-alias-label-tertiary);
|
|
935
|
+
font-size: 12px;
|
|
936
|
+
font-weight: 500;
|
|
937
|
+
line-height: 18px;
|
|
938
|
+
user-select: none;
|
|
939
|
+
}
|
|
940
|
+
.vtwc-row {
|
|
941
|
+
box-sizing: border-box;
|
|
942
|
+
display: flex;
|
|
943
|
+
align-items: center;
|
|
944
|
+
width: 100%;
|
|
945
|
+
height: 40px;
|
|
946
|
+
padding: 9px 6px 9px 10px;
|
|
947
|
+
border: 0;
|
|
948
|
+
border-radius: 12px;
|
|
949
|
+
background: transparent;
|
|
950
|
+
color: var(--dsw-alias-label-primary);
|
|
951
|
+
font: inherit;
|
|
952
|
+
font-size: 14px;
|
|
953
|
+
line-height: 22px;
|
|
954
|
+
text-align: left;
|
|
955
|
+
cursor: pointer;
|
|
956
|
+
}
|
|
957
|
+
.vtwc-row:hover { background: var(--dsw-specific-sidebar-nav-item-hover); }
|
|
958
|
+
.vtwc-row-active,
|
|
959
|
+
.vtwc-row-active:hover {
|
|
960
|
+
background: var(--dsw-specific-sidebar-nav-item-active-accent);
|
|
961
|
+
color: var(--dsw-alias-brand-primary-invert);
|
|
962
|
+
}
|
|
963
|
+
.vtwc-row:focus-visible { outline: 2px solid var(--dsw-alias-label-primary); outline-offset: -2px; }
|
|
964
|
+
.vtwc-row-title { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; line-height: 18px; }
|
|
965
|
+
.vtwc-skeleton { display: flex; flex-direction: column; gap: 14px; padding: 14px 10px 0; }
|
|
966
|
+
.vtwc-skeleton-row {
|
|
967
|
+
height: 12px;
|
|
968
|
+
border-radius: 6px;
|
|
969
|
+
background: var(--dsw-alias-interactive-bg-hover);
|
|
970
|
+
animation: vtwc-pulse 1.4s ease-in-out infinite;
|
|
971
|
+
}
|
|
972
|
+
.vtwc-empty {
|
|
973
|
+
display: flex;
|
|
974
|
+
flex-direction: column;
|
|
975
|
+
align-items: center;
|
|
976
|
+
gap: 6px;
|
|
977
|
+
padding: 32px 16px;
|
|
978
|
+
text-align: center;
|
|
979
|
+
color: var(--dsw-alias-label-tertiary);
|
|
980
|
+
font-size: 12px;
|
|
981
|
+
line-height: 20px;
|
|
982
|
+
}
|
|
983
|
+
.vtwc-empty-title { color: var(--dsw-alias-label-secondary); font-size: 13px; font-weight: 500; }
|
|
984
|
+
.vtwc-retry {
|
|
985
|
+
margin-top: 4px;
|
|
986
|
+
padding: 4px 12px;
|
|
987
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
988
|
+
border-radius: 999px;
|
|
989
|
+
background: transparent;
|
|
990
|
+
color: var(--dsw-alias-label-primary);
|
|
991
|
+
font: inherit;
|
|
992
|
+
font-size: 12px;
|
|
993
|
+
cursor: pointer;
|
|
994
|
+
}
|
|
995
|
+
.vtwc-retry:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
996
|
+
/* 与侧栏账号行同一套排版:44px 行高、6px 内边距、24px 图标槽、8px 间距、
|
|
997
|
+
14px 字号、label-primary 文本色;只去掉账号行的圆形底。 */
|
|
998
|
+
.vtwc-back {
|
|
999
|
+
box-sizing: border-box;
|
|
1000
|
+
display: flex;
|
|
1001
|
+
align-items: center;
|
|
1002
|
+
gap: 8px;
|
|
1003
|
+
width: calc(100% - 4px);
|
|
1004
|
+
height: 44px;
|
|
1005
|
+
margin: 0 2px 2px;
|
|
1006
|
+
padding: 6px;
|
|
1007
|
+
border: 0;
|
|
1008
|
+
border-radius: var(--dsw-radius-md);
|
|
1009
|
+
background: transparent;
|
|
1010
|
+
color: var(--dsw-alias-label-primary);
|
|
1011
|
+
font: inherit;
|
|
1012
|
+
font-size: 14px;
|
|
1013
|
+
line-height: 22px;
|
|
1014
|
+
text-align: left;
|
|
1015
|
+
cursor: pointer;
|
|
1016
|
+
animation: vtwc-in 200ms cubic-bezier(.2, .8, .2, 1);
|
|
1017
|
+
}
|
|
1018
|
+
.vtwc-back[data-vtwc-leaving='true'] { animation: vtwc-out 150ms ease forwards; }
|
|
1019
|
+
.vtwc-back:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
1020
|
+
.vtwc-back:focus-visible { outline: 2px solid var(--dsw-alias-label-primary); outline-offset: -2px; }
|
|
1021
|
+
.vtwc-back-rail { width: 36px; height: 36px; margin: 0; padding: 0; justify-content: center; gap: 0; }
|
|
1022
|
+
.vtwc-back-icon { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 24px; height: 24px; }
|
|
1023
|
+
.vtwc-back-label { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
|
1024
|
+
.vtwc-rail {
|
|
1025
|
+
display: inline-flex;
|
|
1026
|
+
align-items: center;
|
|
1027
|
+
justify-content: center;
|
|
1028
|
+
width: 36px;
|
|
1029
|
+
height: 36px;
|
|
1030
|
+
margin-top: 2px;
|
|
1031
|
+
padding: 0;
|
|
1032
|
+
border: 0;
|
|
1033
|
+
border-radius: 8px;
|
|
1034
|
+
background: transparent;
|
|
1035
|
+
color: var(--dsw-alias-label-secondary);
|
|
1036
|
+
cursor: pointer;
|
|
1037
|
+
}
|
|
1038
|
+
.vtwc-rail:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
|
|
1039
|
+
@keyframes vtwc-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
|
|
1040
|
+
@keyframes vtwc-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(4px); } }
|
|
1041
|
+
@keyframes vtwc-brand-in { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: none; } }
|
|
1042
|
+
@keyframes vtwc-brand-out { to { opacity: 0; } }
|
|
1043
|
+
@keyframes vtwc-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
|
|
1044
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1045
|
+
.vtwc-region,
|
|
1046
|
+
.vtwc-brand,
|
|
1047
|
+
.vtwc-back,
|
|
1048
|
+
.vtwc-skeleton-row { animation: none !important; }
|
|
1049
|
+
}
|
|
1050
|
+
`;
|
|
854
1051
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
*/
|
|
859
|
-
function apply(ctx) {
|
|
860
|
-
try {
|
|
861
|
-
// Copy is owned by the locale service so it follows host language changes.
|
|
1052
|
+
return {
|
|
1053
|
+
inject: ['slots', 'locale', 'layout'],
|
|
1054
|
+
apply(ctx) {
|
|
862
1055
|
ctx.effect(() => {
|
|
863
1056
|
const offZh = ctx.locale.register(NS, 'zh', DICT.zh);
|
|
864
1057
|
const offEn = ctx.locale.register(NS, 'en', DICT.en);
|
|
@@ -866,50 +1059,390 @@ window.__ModuleLoader__.load({
|
|
|
866
1059
|
offZh();
|
|
867
1060
|
offEn();
|
|
868
1061
|
};
|
|
869
|
-
},
|
|
1062
|
+
}, `${PLUGIN_ID}: locale`);
|
|
1063
|
+
|
|
1064
|
+
ctx.effect(() => {
|
|
1065
|
+
const style = document.createElement('style');
|
|
1066
|
+
style.dataset.plugin = PLUGIN_ID;
|
|
1067
|
+
style.dataset.pluginCss = `${PLUGIN_ID}/chat-mode`;
|
|
1068
|
+
style.textContent = CHAT_CSS;
|
|
1069
|
+
document.head.appendChild(style);
|
|
1070
|
+
return () => style.remove();
|
|
1071
|
+
}, `${PLUGIN_ID}: chat mode styles`);
|
|
1072
|
+
|
|
1073
|
+
ctx.effect(() => {
|
|
1074
|
+
const root = document.documentElement;
|
|
1075
|
+
const sync = () => {
|
|
1076
|
+
if (surface.get().active) root.setAttribute('data-vtwc-surface', 'chat');
|
|
1077
|
+
else root.removeAttribute('data-vtwc-surface');
|
|
1078
|
+
};
|
|
1079
|
+
const off = surface.subscribe(sync);
|
|
1080
|
+
sync();
|
|
1081
|
+
return () => {
|
|
1082
|
+
off();
|
|
1083
|
+
root.removeAttribute('data-vtwc-surface');
|
|
1084
|
+
};
|
|
1085
|
+
}, `${PLUGIN_ID}: chat surface`);
|
|
1086
|
+
|
|
1087
|
+
// 一次捕获监听处理两件事:
|
|
1088
|
+
// 1) 点「网页对话」入口时,先切侧栏,不等主面板挂载完成;
|
|
1089
|
+
// 2) 收起侧栏后,宿主 frame 左上角的浮动「新建会话」在 Chat 模式下改走新建对话。
|
|
1090
|
+
ctx.effect(() => {
|
|
1091
|
+
const onClick = (event) => {
|
|
1092
|
+
const target = event.target;
|
|
1093
|
+
if (target === null || typeof target.closest !== 'function') return;
|
|
1094
|
+
|
|
1095
|
+
if (surface.get().active) {
|
|
1096
|
+
if (target.closest('[data-shell-leading]') === null) return;
|
|
1097
|
+
const button = target.closest('button');
|
|
1098
|
+
if (button === null || button.hasAttribute('data-sidebar-opener')) return;
|
|
1099
|
+
event.preventDefault();
|
|
1100
|
+
event.stopPropagation();
|
|
1101
|
+
panelLink.post({ type: 'new-chat' });
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// 入口行:按钮里带本插件图标的才算,避免误伤其它面板行。
|
|
1106
|
+
const button = target.closest('button');
|
|
1107
|
+
if (button === null || button.querySelector('[data-vtwc-glyph]') === null) return;
|
|
1108
|
+
enterSurface();
|
|
1109
|
+
};
|
|
1110
|
+
document.addEventListener('click', onClick, true);
|
|
1111
|
+
return () => document.removeEventListener('click', onClick, true);
|
|
1112
|
+
}, `${PLUGIN_ID}: mode entry and leading new session`);
|
|
1113
|
+
|
|
1114
|
+
ctx.effect(
|
|
1115
|
+
() => () => clearReturnedHover(),
|
|
1116
|
+
`${PLUGIN_ID}: returned-hover cleanup`,
|
|
1117
|
+
);
|
|
870
1118
|
|
|
871
1119
|
const bound = ctx.locale.bind(NS);
|
|
872
|
-
const
|
|
873
|
-
const t = (key) => {
|
|
1120
|
+
const t = (key, ...rest) => {
|
|
874
1121
|
const raw = bound(key);
|
|
875
|
-
|
|
1122
|
+
const value = raw === key || raw === undefined || raw === null ? DICT.en[key] : raw;
|
|
1123
|
+
return typeof value === 'function' ? value(...rest) : value;
|
|
876
1124
|
};
|
|
877
|
-
translate = t;
|
|
878
|
-
localeService = ctx.locale;
|
|
879
1125
|
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
1126
|
+
/**
|
|
1127
|
+
* 抢在现有注册之前接管一个 single 座位。
|
|
1128
|
+
* priority 越小越优先;每次都取当前最低值再减一,避免与另一个插件撞车抛错。
|
|
1129
|
+
* @param name - 座位名。
|
|
1130
|
+
* @returns 可用的 priority。
|
|
1131
|
+
*/
|
|
1132
|
+
const freePriority = (name) => {
|
|
1133
|
+
try {
|
|
1134
|
+
const entries = ctx.slots.entries(name) ?? [];
|
|
1135
|
+
const values = entries.map((entry) => {
|
|
1136
|
+
const value = entry?.options?.priority;
|
|
1137
|
+
return typeof value === 'number' ? value : 0;
|
|
1138
|
+
});
|
|
1139
|
+
return (values.length > 0 ? Math.min(...values) : 0) - 1;
|
|
1140
|
+
} catch {
|
|
1141
|
+
return -50;
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* 在 Chat 模式期间向一个座位注册;离开后注销,让宿主内容回来。
|
|
1147
|
+
* @param name - 座位名。
|
|
1148
|
+
* @param options - 注册选项(每次激活时求值,方便带 locale 文案)。
|
|
1149
|
+
* @param Component - 组件。
|
|
1150
|
+
* @param label - effect 标签。
|
|
1151
|
+
*/
|
|
1152
|
+
const keepActive = (name, options, Component, label) => {
|
|
1153
|
+
ctx.effect(
|
|
1154
|
+
() =>
|
|
1155
|
+
ctx.slots.inject(name, () => {
|
|
1156
|
+
let dispose = null;
|
|
1157
|
+
const sync = () => {
|
|
1158
|
+
const active = surface.get().active;
|
|
1159
|
+
if (active && dispose === null) {
|
|
1160
|
+
try {
|
|
1161
|
+
dispose = ctx.slots.register({ name, ...options() }, Component);
|
|
1162
|
+
} catch (error) {
|
|
1163
|
+
console.error(`[${PLUGIN_ID}] ${label}`, error);
|
|
1164
|
+
dispose = null;
|
|
1165
|
+
}
|
|
1166
|
+
} else if (!active && dispose !== null) {
|
|
1167
|
+
dispose();
|
|
1168
|
+
dispose = null;
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
const off = surface.subscribe(sync);
|
|
1172
|
+
sync();
|
|
1173
|
+
return () => {
|
|
1174
|
+
off();
|
|
1175
|
+
if (dispose !== null) {
|
|
1176
|
+
dispose();
|
|
1177
|
+
dispose = null;
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
}),
|
|
1181
|
+
label,
|
|
1182
|
+
);
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1185
|
+
// -- 品牌名:Chat 模式把 HARNESS 徽标换成 chat,字标沿用官方那份 ----------
|
|
1186
|
+
|
|
1187
|
+
function ChatBrandName() {
|
|
1188
|
+
const state = useStore(surface);
|
|
1189
|
+
const stop = (event) => {
|
|
1190
|
+
event.preventDefault();
|
|
1191
|
+
event.stopPropagation();
|
|
1192
|
+
};
|
|
1193
|
+
const wordmark =
|
|
1194
|
+
primitives !== null && primitives.BrandWordmark != null
|
|
1195
|
+
? h(primitives.BrandWordmark, { includeMark: false })
|
|
1196
|
+
: h('span', { className: 'vtwc-brand-fallback' }, 'deepseek');
|
|
1197
|
+
return h(
|
|
1198
|
+
'span',
|
|
883
1199
|
{
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
1200
|
+
className: 'vtwc-brand',
|
|
1201
|
+
'data-vtwc-leaving': state.leaving ? 'true' : 'false',
|
|
1202
|
+
// 品牌行本身就是宿主的「新建会话」按钮;Chat 模式下点它不应该建 DSH 会话。
|
|
1203
|
+
onClickCapture: stop,
|
|
887
1204
|
},
|
|
888
|
-
|
|
889
|
-
|
|
1205
|
+
h('span', { className: 'vtwc-brand-wordmark' }, wordmark),
|
|
1206
|
+
h('span', { className: 'vtwc-brand-badge', 'aria-hidden': true }, 'CHAT'),
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
// -- 品牌标:只拦 logo 行的点击,收起态里同一个座位还嵌在展开按钮里 --------
|
|
1211
|
+
|
|
1212
|
+
function ChatBrandMark(props) {
|
|
1213
|
+
const size = typeof props?.size === 'number' ? props.size : 24;
|
|
1214
|
+
const stop = (event) => {
|
|
1215
|
+
const current = event.currentTarget;
|
|
1216
|
+
// 收起态的这个座位在「展开侧栏」按钮内部,点了必须让它正常工作。
|
|
1217
|
+
if (current !== null && typeof current.closest === 'function' && current.closest('[class*="toggle"]') !== null) {
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
event.preventDefault();
|
|
1221
|
+
event.stopPropagation();
|
|
1222
|
+
};
|
|
1223
|
+
return h(
|
|
1224
|
+
'span',
|
|
1225
|
+
{ style: { display: 'inline-flex' }, onClickCapture: stop },
|
|
1226
|
+
h(primitives.FishLogo, { size }),
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
// -- 历史:按 chat-demo 的分组与行高渲染,点击让 iframe 切换会话 ----------
|
|
1231
|
+
|
|
1232
|
+
/** 单条历史行:memo 化,切换选中时只重渲染跨过选中态的两行。 */
|
|
1233
|
+
const ChatRow = React.memo(function ChatRow(props) {
|
|
1234
|
+
return h(
|
|
1235
|
+
'button',
|
|
1236
|
+
{
|
|
1237
|
+
type: 'button',
|
|
1238
|
+
className: `vtwc-row${props.active ? ' vtwc-row-active' : ''}`,
|
|
1239
|
+
title: props.title || props.untitled,
|
|
1240
|
+
onClick: () => openChat(props.id),
|
|
1241
|
+
},
|
|
1242
|
+
h('span', { className: 'vtwc-row-title' }, props.title || props.untitled),
|
|
1243
|
+
);
|
|
1244
|
+
});
|
|
1245
|
+
|
|
1246
|
+
function ChatHistory(props) {
|
|
1247
|
+
const state = useStore(surface);
|
|
1248
|
+
const data = useStore(chatData);
|
|
1249
|
+
const now = useClock();
|
|
1250
|
+
const wide = props?.wide !== false;
|
|
1251
|
+
const untitled = t('history.untitled');
|
|
1252
|
+
const groups = React.useMemo(
|
|
1253
|
+
() => groupSessions(data.sessions, now, t),
|
|
1254
|
+
[data.sessions, now],
|
|
1255
|
+
);
|
|
1256
|
+
|
|
1257
|
+
if (!wide) {
|
|
1258
|
+
return h(
|
|
1259
|
+
'button',
|
|
1260
|
+
{
|
|
1261
|
+
type: 'button',
|
|
1262
|
+
className: 'vtwc-rail',
|
|
1263
|
+
title: t('entry'),
|
|
1264
|
+
'aria-label': t('entry'),
|
|
1265
|
+
onClick: () => {
|
|
1266
|
+
if (typeof props?.expandSidebar === 'function') props.expandSidebar();
|
|
1267
|
+
},
|
|
1268
|
+
},
|
|
1269
|
+
h(Glyph, { size: 18 }),
|
|
1270
|
+
);
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
let content;
|
|
1274
|
+
if (data.error) {
|
|
1275
|
+
content = h(
|
|
1276
|
+
'div',
|
|
1277
|
+
{ className: 'vtwc-empty' },
|
|
1278
|
+
h('span', { className: 'vtwc-empty-title' }, t('history.error')),
|
|
1279
|
+
h(
|
|
1280
|
+
'button',
|
|
1281
|
+
{ type: 'button', className: 'vtwc-retry', onClick: () => panelLink.post({ type: 'retry' }) },
|
|
1282
|
+
t('history.retry'),
|
|
1283
|
+
),
|
|
1284
|
+
);
|
|
1285
|
+
} else if (!data.ready && data.sessions.length === 0) {
|
|
1286
|
+
content = h(
|
|
1287
|
+
'div',
|
|
1288
|
+
{ className: 'vtwc-skeleton', 'aria-hidden': true },
|
|
1289
|
+
h('div', { className: 'vtwc-skeleton-row', style: { width: '72%' } }),
|
|
1290
|
+
h('div', { className: 'vtwc-skeleton-row', style: { width: '88%' } }),
|
|
1291
|
+
h('div', { className: 'vtwc-skeleton-row', style: { width: '60%' } }),
|
|
1292
|
+
);
|
|
1293
|
+
} else if (data.sessions.length === 0) {
|
|
1294
|
+
content = h(
|
|
1295
|
+
'div',
|
|
1296
|
+
{ className: 'vtwc-empty' },
|
|
1297
|
+
h('span', { className: 'vtwc-empty-title' }, t('history.empty')),
|
|
1298
|
+
h('span', null, t('history.emptyHint')),
|
|
1299
|
+
);
|
|
1300
|
+
} else {
|
|
1301
|
+
content = groups.map((group) =>
|
|
1302
|
+
h(
|
|
1303
|
+
'section',
|
|
1304
|
+
{ key: group.key, className: 'vtwc-group' },
|
|
1305
|
+
h('div', { className: 'vtwc-group-label' }, group.label),
|
|
1306
|
+
group.sessions.map((session) =>
|
|
1307
|
+
h(ChatRow, {
|
|
1308
|
+
key: session.id,
|
|
1309
|
+
id: session.id,
|
|
1310
|
+
title: session.title,
|
|
1311
|
+
active: session.id === data.activeId,
|
|
1312
|
+
untitled,
|
|
1313
|
+
}),
|
|
1314
|
+
),
|
|
1315
|
+
),
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
return h(
|
|
1320
|
+
'div',
|
|
1321
|
+
{ className: 'vtwc-region', 'data-vtwc-leaving': state.leaving ? 'true' : 'false' },
|
|
1322
|
+
h('nav', { className: 'vtwc-list', 'aria-label': t('history.label') }, content),
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
// -- 底部:返回 Harness -------------------------------------------------
|
|
1327
|
+
|
|
1328
|
+
function BackToHarness(props) {
|
|
1329
|
+
const state = useStore(surface);
|
|
1330
|
+
const wide = props?.wide !== false;
|
|
1331
|
+
const back = () => {
|
|
1332
|
+
// 先恢复侧栏并让它完成一帧绘制,再挂载会话面板:
|
|
1333
|
+
// 会话面板的挂载较重,放在同一帧会把侧栏恢复一起拖慢。
|
|
1334
|
+
// 同时短暂屏蔽底部动作区,避免指针没动却点亮刚出现的额度环。
|
|
1335
|
+
suppressReturnedHover();
|
|
1336
|
+
exitSurfaceNow();
|
|
1337
|
+
window.requestAnimationFrame(() => {
|
|
1338
|
+
window.requestAnimationFrame(() => {
|
|
1339
|
+
if (surface.get().active) return;
|
|
1340
|
+
try {
|
|
1341
|
+
ctx.layout.selectPanel(CONVERSATION_PANEL);
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
console.error(`[${PLUGIN_ID}] could not return to the conversation`, error);
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
});
|
|
1347
|
+
};
|
|
1348
|
+
return h(
|
|
1349
|
+
'button',
|
|
1350
|
+
{
|
|
1351
|
+
type: 'button',
|
|
1352
|
+
className: `vtwc-back${wide ? '' : ' vtwc-back-rail'}`,
|
|
1353
|
+
'data-vtwc-back': 'true',
|
|
1354
|
+
'data-vtwc-leaving': state.leaving ? 'true' : 'false',
|
|
1355
|
+
'aria-label': t('back'),
|
|
1356
|
+
title: t('back.hint'),
|
|
1357
|
+
onClick: back,
|
|
1358
|
+
},
|
|
1359
|
+
h('span', { className: 'vtwc-back-icon' }, h(BackIcon)),
|
|
1360
|
+
wide ? h('span', { className: 'vtwc-back-label' }, t('back')) : null,
|
|
1361
|
+
);
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
// -- 「新会话」:保留宿主的按钮与样式,Chat 模式下把点击改成新建对话 ------
|
|
1365
|
+
|
|
1366
|
+
function NewSessionLayer(props) {
|
|
1367
|
+
const intercept = React.useCallback((event) => {
|
|
1368
|
+
if (!surface.get().active) return;
|
|
1369
|
+
event.preventDefault();
|
|
1370
|
+
event.stopPropagation();
|
|
1371
|
+
panelLink.post({ type: 'new-chat' });
|
|
1372
|
+
}, []);
|
|
1373
|
+
return h('span', { style: { display: 'contents' }, onClickCapture: intercept }, props?.children ?? null);
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
// -- 注册:品牌、浏览区、底部动作在模式期间接管;入口在模式外显示 ----------
|
|
1377
|
+
|
|
1378
|
+
keepActive(
|
|
1379
|
+
'sidebar.brand.name',
|
|
1380
|
+
() => ({ priority: freePriority('sidebar.brand.name'), locale: NS }),
|
|
1381
|
+
ChatBrandName,
|
|
1382
|
+
`${PLUGIN_ID}: chat brand`,
|
|
1383
|
+
);
|
|
1384
|
+
|
|
1385
|
+
if (primitives !== null && primitives.FishLogo != null) {
|
|
1386
|
+
keepActive(
|
|
1387
|
+
'sidebar.brand.mark',
|
|
1388
|
+
() => ({ priority: freePriority('sidebar.brand.mark'), locale: NS }),
|
|
1389
|
+
ChatBrandMark,
|
|
1390
|
+
`${PLUGIN_ID}: chat brand mark`,
|
|
1391
|
+
);
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
keepActive(
|
|
1395
|
+
'sidebar.workspaces',
|
|
1396
|
+
() => ({ priority: freePriority('sidebar.workspaces'), locale: NS }),
|
|
1397
|
+
ChatHistory,
|
|
1398
|
+
`${PLUGIN_ID}: chat history`,
|
|
1399
|
+
);
|
|
1400
|
+
|
|
1401
|
+
keepActive(
|
|
1402
|
+
'sidebar.footer.action',
|
|
1403
|
+
() => ({ id: 'vt-web-chat-back', order: -10, locale: NS }),
|
|
1404
|
+
BackToHarness,
|
|
1405
|
+
`${PLUGIN_ID}: back to harness`,
|
|
890
1406
|
);
|
|
891
1407
|
|
|
892
|
-
//
|
|
1408
|
+
// 入口行始终注册:Chat 模式下由上面的 panelList 样式整体隐藏,
|
|
1409
|
+
// 这样退出时不必重新注册,宿主的面板列表也不会因为注销而抖动。
|
|
893
1410
|
ctx.slots.inject('sidebar.panellist', () =>
|
|
1411
|
+
ctx.slots.register(
|
|
1412
|
+
{ name: 'sidebar.panellist', id: PANEL_ID, order: -10, label: () => t('entry') },
|
|
1413
|
+
Glyph,
|
|
1414
|
+
),
|
|
1415
|
+
);
|
|
1416
|
+
|
|
1417
|
+
// HOC 只负责拦截点击;按钮本身、图标、尺寸全部保持宿主原样。
|
|
1418
|
+
ctx.effect(
|
|
1419
|
+
() =>
|
|
1420
|
+
ctx.slots.inject('sidebar.session.action', () =>
|
|
1421
|
+
ctx.slots.register(
|
|
1422
|
+
{ name: 'sidebar.session.action', id: 'vt-web-chat-new-session', order: 10, priority: -10 },
|
|
1423
|
+
NewSessionLayer,
|
|
1424
|
+
),
|
|
1425
|
+
),
|
|
1426
|
+
`${PLUGIN_ID}: new session click`,
|
|
1427
|
+
);
|
|
1428
|
+
|
|
1429
|
+
ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL_ID }, (props) => h(PanelShell, { ...props, ctx })));
|
|
1430
|
+
|
|
1431
|
+
ctx.slots.inject('settings.section', () =>
|
|
894
1432
|
ctx.slots.register(
|
|
895
1433
|
{
|
|
896
|
-
name: '
|
|
897
|
-
id:
|
|
898
|
-
order:
|
|
899
|
-
label: () => t('
|
|
1434
|
+
name: 'settings.section',
|
|
1435
|
+
id: 'web-chat-settings',
|
|
1436
|
+
order: 26,
|
|
1437
|
+
label: () => t('settings.nav'),
|
|
1438
|
+
inject: () => ({ t }),
|
|
900
1439
|
},
|
|
901
|
-
|
|
1440
|
+
(props) => h(SettingsBoundary, { fallback: t('settings.crashed') }, h(RetentionSettings, props)),
|
|
902
1441
|
),
|
|
903
1442
|
);
|
|
904
|
-
} catch (error) {
|
|
905
|
-
try {
|
|
906
|
-
console.error(`${PLUGIN_ID}: registration failed`, error);
|
|
907
|
-
} catch {
|
|
908
|
-
/* console unavailable */
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
1443
|
|
|
913
|
-
|
|
1444
|
+
console.info(`[${PLUGIN_ID}] ${VERSION} ready`);
|
|
1445
|
+
},
|
|
1446
|
+
};
|
|
914
1447
|
},
|
|
915
1448
|
});
|