dsh-vt-web-chat 1.2.1 → 2.0.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 +66 -33
- package/client.js +355 -798
- 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 +15 -6
- package/scripts/dev-server.mjs +54 -0
- package/scripts/sync-upstream.mjs +106 -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.7c5f914e.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,389 @@
|
|
|
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
|
-
* 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.
|
|
8
|
+
* 为什么不再用桌面壳的 webview 租约:本插件的页面由自己托管,
|
|
9
|
+
* 不受站点 `frame-ancestors` 限制,Web 端与桌面端可以用同一条路径。
|
|
23
10
|
*/
|
|
24
11
|
window.__ModuleLoader__.load({
|
|
25
|
-
// 模块 id 必须与包名一致;装载器把多个 client.js 拼进同一个脚本,所以顶层只能有
|
|
26
|
-
// 这一个 load() 调用,其余常量一律放进 factory 的作用域,避免重名 SyntaxError。
|
|
27
12
|
id: 'dsh-vt-web-chat',
|
|
28
13
|
factory(require) {
|
|
29
|
-
|
|
14
|
+
const React = require('react');
|
|
15
|
+
const h = React.createElement;
|
|
30
16
|
|
|
31
|
-
/** Package identity: one source for the module id and every log/storage prefix. */
|
|
32
17
|
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. */
|
|
18
|
+
const VERSION = '2.0.0';
|
|
19
|
+
const NS = PLUGIN_ID;
|
|
20
|
+
/** 侧栏行与主面板共用的 id。 */
|
|
48
21
|
const PANEL_ID = 'vt-web-chat';
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* re-entering the panel keeps the page and its login.
|
|
54
|
-
*/
|
|
55
|
-
const PARTITION_KEY = 'panel:vt-web-chat';
|
|
56
|
-
/** Last visited conversation, remembered across panel switches and reloads. */
|
|
57
|
-
const STORAGE_KEY = `${PLUGIN_ID}:last-url`;
|
|
58
|
-
/**
|
|
59
|
-
* Record the site keeps its own UI preferences in. It is written by the
|
|
60
|
-
* site's storage kit, so a hand-written value must keep the same envelope
|
|
61
|
-
* (`{ value, __version }`) or the site discards it.
|
|
62
|
-
*/
|
|
63
|
-
const SITE_PREFS_KEY = '__appKit_@deepseek/chat_lastSessionValue';
|
|
64
|
-
/**
|
|
65
|
-
* The site's own "environment warning dismissed" flag. The warning is shown
|
|
66
|
-
* because the embedded browser reports Electron; closing it writes this
|
|
67
|
-
* flag, so writing it here is the same dismissal without a click.
|
|
68
|
-
*/
|
|
69
|
-
const UNSAFE_WARN_KEY = 'closeUnsafeEnvWarn';
|
|
70
|
-
/** Guest-side reload counter, so a failed write cannot reload forever. */
|
|
71
|
-
const PREF_GUARD_KEY = `${PLUGIN_ID}:pref-reloads`;
|
|
72
|
-
/** Reloads one guest session may perform while it settles its preferences. */
|
|
73
|
-
const PREF_RELOAD_LIMIT = 2;
|
|
74
|
-
/** Paths that are not a conversation: a brand-new chat, or an auth page. */
|
|
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;
|
|
22
|
+
/** 与宿主路由一致的接口前缀。 */
|
|
23
|
+
const ROUTE_PREFIX = '/webchat';
|
|
24
|
+
/** 保留天数档位;0 表示永不清理。 */
|
|
25
|
+
const RETENTION_CHOICES = [30, 60, 90, 0];
|
|
78
26
|
|
|
79
27
|
const DICT = {
|
|
80
28
|
zh: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
29
|
+
'meta.title': '网页对话',
|
|
30
|
+
'meta.description': '用官方 DeepSeek 网页界面聊天,请求走 DeepSeek API 与你的 DSH 账号。',
|
|
31
|
+
'entry': '网页对话',
|
|
32
|
+
'panel.title': '网页对话',
|
|
33
|
+
'panel.hint': '滚动、复制、上传都在面板内完成;对话保存在本机,不会写入 DSH 会话。',
|
|
34
|
+
'settings.nav': '网页对话',
|
|
35
|
+
'settings.title': '会话保留',
|
|
36
|
+
'settings.description': '超过所选天数没有继续聊的会话,会在下次打开面板时自动删除。',
|
|
37
|
+
'settings.days30': '30 天',
|
|
38
|
+
'settings.days60': '60 天',
|
|
39
|
+
'settings.days90': '90 天',
|
|
40
|
+
'settings.never': '永不',
|
|
41
|
+
'settings.saving': '保存中…',
|
|
42
|
+
'settings.saved': '已保存',
|
|
43
|
+
'settings.failed': '保存失败,请重试',
|
|
44
|
+
'settings.loadFailed': '读取设置失败,暂按 30 天处理',
|
|
45
|
+
'settings.currentDays': '当前:闲置超过 {n} 天的会话会被删除。',
|
|
46
|
+
'settings.currentNever': '当前:永不自动删除。',
|
|
47
|
+
'settings.crashed': '设置区块加载失败,请重新打开设置页。',
|
|
93
48
|
},
|
|
94
49
|
en: {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
50
|
+
'meta.title': 'Web Chat',
|
|
51
|
+
'meta.description': 'Chat on the official DeepSeek web UI, billed through the DeepSeek API with your DSH account.',
|
|
52
|
+
'entry': 'Web Chat',
|
|
53
|
+
'panel.title': 'Web Chat',
|
|
54
|
+
'panel.hint': 'Scrolling, copying and uploads stay inside the panel; chats are stored locally and never written to a DSH session.',
|
|
55
|
+
'settings.nav': 'Web Chat',
|
|
56
|
+
'settings.title': 'Chat retention',
|
|
57
|
+
'settings.description': 'Chats untouched for longer than the chosen period are deleted the next time the panel opens.',
|
|
58
|
+
'settings.days30': '30 days',
|
|
59
|
+
'settings.days60': '60 days',
|
|
60
|
+
'settings.days90': '90 days',
|
|
61
|
+
'settings.never': 'Never',
|
|
62
|
+
'settings.saving': 'Saving…',
|
|
63
|
+
'settings.saved': 'Saved',
|
|
64
|
+
'settings.failed': 'Save failed, please retry',
|
|
65
|
+
'settings.loadFailed': 'Could not read settings; assuming 30 days',
|
|
66
|
+
'settings.currentDays': 'Current: chats idle for more than {n} days are deleted.',
|
|
67
|
+
'settings.currentNever': 'Current: never delete automatically.',
|
|
68
|
+
'settings.crashed': 'This section failed to render; reopen Settings to try again.',
|
|
109
69
|
},
|
|
110
70
|
};
|
|
111
71
|
|
|
112
|
-
/** Set by `apply`; components fall back to it when slot injection is absent. */
|
|
113
|
-
let translate = (key) => key;
|
|
114
|
-
let localeService = undefined;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Re-render when the active locale changes, so panel copy follows the host.
|
|
118
|
-
* @param locale - Client locale service, if available.
|
|
119
|
-
* @returns the current revision; the value itself is not read.
|
|
120
|
-
*/
|
|
121
|
-
function useLocaleRevision(locale) {
|
|
122
|
-
const [revision, setRevision] = React.useState(0);
|
|
123
|
-
React.useEffect(() => {
|
|
124
|
-
if (locale === undefined || locale === null || typeof locale.subscribe !== 'function') {
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
return locale.subscribe(() => setRevision((value) => value + 1));
|
|
128
|
-
}, [locale]);
|
|
129
|
-
return revision;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Parse a chat.deepseek.com page URL.
|
|
134
|
-
* @param value - candidate URL.
|
|
135
|
-
* @returns the parsed URL for the site origin, or undefined.
|
|
136
|
-
*/
|
|
137
|
-
function parseChatUrl(value) {
|
|
138
|
-
if (typeof value !== 'string' || value.length === 0 || value.length > 4096) return undefined;
|
|
139
|
-
try {
|
|
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;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Whether a URL is deep enough to be a conversation page.
|
|
151
|
-
* @param url - parsed chat URL, possibly undefined.
|
|
152
|
-
* @returns true for a conversation, false for the new-chat root or an auth page.
|
|
153
|
-
*/
|
|
154
|
-
function isConversation(url) {
|
|
155
|
-
if (url === undefined) return false;
|
|
156
|
-
const path = url.pathname.replace(/\/+$/u, '') || '/';
|
|
157
|
-
return !AUTH_PATHS.has(path) && path !== '/';
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Whether the guest currently shows a sign-in page.
|
|
162
|
-
* @param raw - current page URL reported by the guest.
|
|
163
|
-
* @returns true for the known auth paths.
|
|
164
|
-
*/
|
|
165
|
-
function isAuthUrl(raw) {
|
|
166
|
-
const url = parseChatUrl(raw);
|
|
167
|
-
if (url === undefined) return false;
|
|
168
|
-
const path = url.pathname.replace(/\/+$/u, '') || '/';
|
|
169
|
-
return AUTH_PATHS.has(path);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
72
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
73
|
+
* 面板地址。桌面壳的静态页面通过 `__DSH_TRANSPORT__` 拿到 Host 的 HTTP origin,
|
|
74
|
+
* 浏览器页面直接用当前 origin;两者都没有时退回根路径。
|
|
75
|
+
*
|
|
76
|
+
* 带上 `lang`:面板是独立文档,拿不到宿主的 i18n;首次进入时由注入脚本
|
|
77
|
+
* 把它写进前端自己的 locale 存储,之后用户在前端里改过就以前端为准。
|
|
78
|
+
* @param locale - 宿主当前语言。
|
|
79
|
+
* @returns 面板 URL。
|
|
175
80
|
*/
|
|
176
|
-
function
|
|
81
|
+
function panelUrl(locale) {
|
|
177
82
|
try {
|
|
178
|
-
const
|
|
179
|
-
|
|
83
|
+
const transport = window.__DSH_TRANSPORT__;
|
|
84
|
+
const base =
|
|
85
|
+
typeof transport?.streamBaseUrl === 'string' && transport.streamBaseUrl.length > 0
|
|
86
|
+
? transport.streamBaseUrl.replace(/\/+$/u, '')
|
|
87
|
+
: window.location.protocol === 'file:'
|
|
88
|
+
? ''
|
|
89
|
+
: window.location.origin;
|
|
90
|
+
return `${base}${ROUTE_PREFIX}/?lang=${encodeURIComponent(locale)}`;
|
|
180
91
|
} catch {
|
|
181
|
-
return
|
|
92
|
+
return `${ROUTE_PREFIX}/?lang=${encodeURIComponent(locale)}`;
|
|
182
93
|
}
|
|
183
94
|
}
|
|
184
95
|
|
|
185
96
|
/**
|
|
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.
|
|
97
|
+
* 把宿主语言收敛成前端认识的两个值。
|
|
98
|
+
* @param ctx - Client 插件上下文。
|
|
99
|
+
* @returns `'zh-CN'` 或 `'en-US'`(上游 Locale 的合法值)。
|
|
191
100
|
*/
|
|
192
|
-
function
|
|
193
|
-
const url = parseChatUrl(raw);
|
|
194
|
-
if (url === undefined) return;
|
|
101
|
+
function hostLocale(ctx) {
|
|
195
102
|
try {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
103
|
+
const active = ctx.locale.getSnapshot?.()?.active;
|
|
104
|
+
if (typeof active === 'string' && active.length > 0) {
|
|
105
|
+
return active.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
|
|
199
106
|
}
|
|
200
107
|
} catch {
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Script that settles the site's own preferences before the panel is used.
|
|
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`.
|
|
215
|
-
*/
|
|
216
|
-
function guestPreferencesScript() {
|
|
217
|
-
return `(() => {
|
|
218
|
-
try {
|
|
219
|
-
const reloads = Number(sessionStorage.getItem('${PREF_GUARD_KEY}') || '0');
|
|
220
|
-
if (reloads >= ${PREF_RELOAD_LIMIT}) return 'settled';
|
|
221
|
-
const read = (key) => {
|
|
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;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
const write = (key, value) => {
|
|
232
|
-
const record = read(key) || {};
|
|
233
|
-
record.value = value;
|
|
234
|
-
if (typeof record.__version !== 'string') record.__version = '0';
|
|
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;
|
|
108
|
+
// 快照不可用:退回文档语言。
|
|
253
109
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
sessionStorage.setItem('${PREF_GUARD_KEY}', String(reloads + 1));
|
|
257
|
-
location.reload();
|
|
258
|
-
return 'reloading';
|
|
259
|
-
} catch (error) {
|
|
260
|
-
return 'unavailable';
|
|
261
|
-
}
|
|
262
|
-
})()`;
|
|
110
|
+
const lang = typeof document?.documentElement?.lang === 'string' ? document.documentElement.lang : '';
|
|
111
|
+
return lang.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
|
|
263
112
|
}
|
|
264
113
|
|
|
265
114
|
/**
|
|
266
|
-
*
|
|
115
|
+
* 量出 DSH 顶部占位(侧栏收起后的悬浮岛)的高度。
|
|
267
116
|
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
* @param element - webview element hosting the site.
|
|
117
|
+
* DSH 在主面板左上角盖了一个 `shell.leading` 座位;框架会给出
|
|
118
|
+
* `--dsh-frame-leading-clearance`,但 iframe 拿不到宿主的 CSS 变量,
|
|
119
|
+
* 所以这里直接量座位元素的实际底边,再把数字发给面板。
|
|
120
|
+
* @returns 需要让出的顶部高度,没有座位时为 0。
|
|
273
121
|
*/
|
|
274
|
-
function
|
|
275
|
-
if (!attached(element)) return;
|
|
122
|
+
function measureSeatInset(host) {
|
|
276
123
|
try {
|
|
277
|
-
const
|
|
278
|
-
if (
|
|
279
|
-
|
|
124
|
+
const seat = document.querySelector('[class*="leadingSeat"]');
|
|
125
|
+
if (seat !== null) {
|
|
126
|
+
const rect = seat.getBoundingClientRect();
|
|
127
|
+
if (rect.width > 0 || rect.height > 0) return Math.ceil(rect.bottom + 8);
|
|
280
128
|
}
|
|
129
|
+
// 兜底:座位元素找不到(例如上游改了类名),但框架声明了 leading clearance,
|
|
130
|
+
// 说明座位仍然挂在主面板上方,用一个保守高度让开。
|
|
131
|
+
const probe = host ?? document.querySelector('[class*="mainPanel"]') ?? document.body;
|
|
132
|
+
const clearance = getComputedStyle(probe).getPropertyValue('--dsh-frame-leading-clearance');
|
|
133
|
+
if (Number.parseFloat(clearance) > 0) return 48;
|
|
281
134
|
} catch {
|
|
282
|
-
|
|
135
|
+
// 量不到就让开 0:宁可重叠,也不要凭空留一条空白。
|
|
283
136
|
}
|
|
137
|
+
return 0;
|
|
284
138
|
}
|
|
285
139
|
|
|
286
140
|
/**
|
|
287
|
-
*
|
|
288
|
-
* `
|
|
289
|
-
* @param url - http(s) target.
|
|
141
|
+
* 读设置。
|
|
142
|
+
* @returns `{ retentionDays }`;失败时抛出。
|
|
290
143
|
*/
|
|
291
|
-
function
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
/* a blocked popup leaves the panel usable */
|
|
296
|
-
}
|
|
144
|
+
async function fetchSettings() {
|
|
145
|
+
const response = await fetch(`${ROUTE_PREFIX}/api/settings`, { headers: { accept: 'application/json' } });
|
|
146
|
+
if (!response.ok) throw new Error(`settings ${response.status}`);
|
|
147
|
+
return response.json();
|
|
297
148
|
}
|
|
298
149
|
|
|
299
150
|
/**
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* @
|
|
303
|
-
* @returns true while the element can still host a guest.
|
|
151
|
+
* 写设置。
|
|
152
|
+
* @param retentionDays - 保留天数,0 表示永不。
|
|
153
|
+
* @returns 落盘后的设置。
|
|
304
154
|
*/
|
|
305
|
-
function
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
155
|
+
async function saveSettings(retentionDays) {
|
|
156
|
+
const response = await fetch(`${ROUTE_PREFIX}/api/settings`, {
|
|
157
|
+
method: 'POST',
|
|
158
|
+
headers: { 'content-type': 'application/json' },
|
|
159
|
+
body: JSON.stringify({ retentionDays }),
|
|
160
|
+
});
|
|
161
|
+
if (!response.ok) throw new Error(`settings ${response.status}`);
|
|
162
|
+
return response.json();
|
|
311
163
|
}
|
|
312
164
|
|
|
313
|
-
/**
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
*/
|
|
318
|
-
function readUrl(element) {
|
|
319
|
-
if (!attached(element)) return undefined;
|
|
320
|
-
try {
|
|
321
|
-
const url = element.getURL();
|
|
322
|
-
return typeof url === 'string' && url.length > 0 ? url : undefined;
|
|
323
|
-
} catch {
|
|
324
|
-
return undefined;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
165
|
+
/** 面板本体:一个占满主内容区的同源 iframe。 */
|
|
166
|
+
function Panel(props) {
|
|
167
|
+
const frameRef = React.useRef(null);
|
|
168
|
+
const inset = props.inset ?? 0;
|
|
327
169
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
try {
|
|
337
|
-
const pending = element.loadURL(url);
|
|
338
|
-
if (pending !== undefined && pending !== null && typeof pending.catch === 'function') {
|
|
339
|
-
pending.catch(() => {});
|
|
170
|
+
// 座位高度用 postMessage 传进去:面板是独立文档,读不到宿主的布局状态。
|
|
171
|
+
const pushSeat = React.useCallback(() => {
|
|
172
|
+
const win = frameRef.current === null ? null : frameRef.current.contentWindow;
|
|
173
|
+
if (win === null) return;
|
|
174
|
+
try {
|
|
175
|
+
win.postMessage({ type: 'vt-webchat:seat', inset }, '*');
|
|
176
|
+
} catch {
|
|
177
|
+
// 面板还没准备好:等 onLoad 再发一次。
|
|
340
178
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
179
|
+
}, [inset]);
|
|
180
|
+
|
|
181
|
+
React.useEffect(pushSeat, [pushSeat]);
|
|
182
|
+
|
|
183
|
+
return h(
|
|
184
|
+
'div',
|
|
185
|
+
{
|
|
186
|
+
// 容器留在宿主文档里,用来读取继承下来的框架变量(座位是否挂载)。
|
|
187
|
+
ref: props.hostRef,
|
|
188
|
+
style: {
|
|
189
|
+
height: '100%',
|
|
190
|
+
minHeight: 320,
|
|
191
|
+
display: 'flex',
|
|
192
|
+
background: 'var(--dsw-alias-bg-layer-1, #fff)',
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
h('iframe', {
|
|
196
|
+
ref: frameRef,
|
|
197
|
+
onLoad: pushSeat,
|
|
198
|
+
src: panelUrl(props.locale ?? 'zh-CN'),
|
|
199
|
+
title: 'DeepSeek',
|
|
200
|
+
allow: 'clipboard-write; microphone',
|
|
201
|
+
style: { width: '100%', height: '100%', border: 'none', display: 'block', background: 'transparent' },
|
|
202
|
+
}),
|
|
203
|
+
);
|
|
345
204
|
}
|
|
346
205
|
|
|
347
|
-
/**
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
* @returns the glyph element.
|
|
352
|
-
*/
|
|
353
|
-
function Glyph({ size = 16 }) {
|
|
354
|
-
return React.createElement(
|
|
206
|
+
/** 侧栏图标:与 icon.svg 同形,用 currentColor 跟随侧栏配色。 */
|
|
207
|
+
function Glyph(props) {
|
|
208
|
+
const size = typeof props?.size === 'number' ? props.size : 16;
|
|
209
|
+
return h(
|
|
355
210
|
'svg',
|
|
356
211
|
{
|
|
212
|
+
viewBox: '0 0 24 24',
|
|
357
213
|
width: size,
|
|
358
214
|
height: size,
|
|
359
|
-
viewBox: '0 0 24 24',
|
|
360
215
|
fill: 'none',
|
|
361
|
-
|
|
362
|
-
|
|
216
|
+
stroke: 'currentColor',
|
|
217
|
+
'aria-hidden': true,
|
|
218
|
+
style: { display: 'block' },
|
|
363
219
|
},
|
|
364
|
-
|
|
220
|
+
h('path', {
|
|
365
221
|
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
222
|
strokeWidth: 1.3,
|
|
368
223
|
strokeLinejoin: 'round',
|
|
369
224
|
}),
|
|
370
|
-
|
|
225
|
+
h('path', {
|
|
371
226
|
d: 'M8.5 11.5h.01M12 11.5h.01M15.5 11.5h.01',
|
|
372
|
-
stroke: 'currentColor',
|
|
373
227
|
strokeWidth: 1.6,
|
|
374
228
|
strokeLinecap: 'round',
|
|
375
229
|
}),
|
|
376
230
|
);
|
|
377
231
|
}
|
|
378
232
|
|
|
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
233
|
/**
|
|
465
|
-
*
|
|
466
|
-
* own around slot entries: an escaping error unmounts the root slot, which
|
|
467
|
-
* is the whole application UI.
|
|
468
|
-
*/
|
|
469
|
-
class PanelBoundary extends React.Component {
|
|
470
|
-
constructor(props) {
|
|
471
|
-
super(props);
|
|
472
|
-
this.state = { failure: undefined };
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
static getDerivedStateFromError(error) {
|
|
476
|
-
return { failure: String((error && error.message) || error) };
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
componentDidCatch(error) {
|
|
480
|
-
try {
|
|
481
|
-
console.error(`${PLUGIN_ID}: panel render failed`, error);
|
|
482
|
-
} catch {
|
|
483
|
-
/* console unavailable */
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
render() {
|
|
488
|
-
if (this.state.failure !== undefined) {
|
|
489
|
-
const t = this.props.t;
|
|
490
|
-
return React.createElement(
|
|
491
|
-
'div',
|
|
492
|
-
{ style: styles.root },
|
|
493
|
-
React.createElement(
|
|
494
|
-
'div',
|
|
495
|
-
{ style: styles.overlay },
|
|
496
|
-
React.createElement('div', { style: styles.overlayTitle }, t('failed')),
|
|
497
|
-
React.createElement('div', null, this.state.failure),
|
|
498
|
-
React.createElement(
|
|
499
|
-
'div',
|
|
500
|
-
{ style: styles.actions },
|
|
501
|
-
React.createElement(
|
|
502
|
-
'button',
|
|
503
|
-
{
|
|
504
|
-
type: 'button',
|
|
505
|
-
style: styles.button,
|
|
506
|
-
onClick: () => openExternally(CHAT_URL),
|
|
507
|
-
},
|
|
508
|
-
t('openExternal'),
|
|
509
|
-
),
|
|
510
|
-
),
|
|
511
|
-
),
|
|
512
|
-
);
|
|
513
|
-
}
|
|
514
|
-
return this.props.children ?? null;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
* The global Web Chat panel: a guest webview filling the main column.
|
|
234
|
+
* 设置区块:四个保留档位,点一下即保存。
|
|
520
235
|
*
|
|
521
|
-
*
|
|
522
|
-
* `
|
|
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.
|
|
236
|
+
* 文案一律走字符串字典:语言服务对函数值不保证透传,
|
|
237
|
+
* 之前的 `t(key)(...)` 在宿主里拿到空串后整块区域会被 React 卸载。
|
|
530
238
|
*/
|
|
531
|
-
function
|
|
532
|
-
const t =
|
|
533
|
-
const locale = props.locale ?? localeService;
|
|
534
|
-
useLocaleRevision(locale);
|
|
535
|
-
|
|
536
|
-
const hostRef = React.useRef(null);
|
|
537
|
-
const lastUrlRef = React.useRef(undefined);
|
|
538
|
-
const [phase, setPhase] = React.useState('loading');
|
|
539
|
-
const [failure, setFailure] = React.useState(undefined);
|
|
540
|
-
const [authPage, setAuthPage] = React.useState(false);
|
|
541
|
-
const [attempt, setAttempt] = React.useState(0);
|
|
542
|
-
|
|
543
|
-
const retry = React.useCallback(() => {
|
|
239
|
+
function RetentionSettings(props) {
|
|
240
|
+
const t = (key) => {
|
|
544
241
|
try {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
242
|
+
if (typeof props?.t === 'function') {
|
|
243
|
+
const value = props.t(key);
|
|
244
|
+
if (typeof value === 'string' && value.length > 0 && value !== key) return value;
|
|
245
|
+
}
|
|
549
246
|
} catch {
|
|
550
|
-
|
|
247
|
+
// 语言服务不可用:退回内置字典,不让设置区跟着崩。
|
|
551
248
|
}
|
|
552
|
-
|
|
249
|
+
return DICT.en[key] ?? key;
|
|
250
|
+
};
|
|
251
|
+
const [days, setDays] = React.useState(30);
|
|
252
|
+
const [state, setState] = React.useState('idle');
|
|
553
253
|
|
|
554
254
|
React.useEffect(() => {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
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
|
-
};
|
|
606
|
-
|
|
607
|
-
const clearWatchdog = () => {
|
|
608
|
-
if (watchdog !== undefined) {
|
|
609
|
-
clearTimeout(watchdog);
|
|
610
|
-
watchdog = undefined;
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
|
|
614
|
-
const onDomReady = () => {
|
|
615
|
-
started = true;
|
|
616
|
-
clearWatchdog();
|
|
617
|
-
if (!navigate(element, initialTarget)) {
|
|
618
|
-
fail(new Error(t('crashed')));
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
remember(initialTarget);
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
const onStopLoading = () => {
|
|
625
|
-
if (disposed) return;
|
|
626
|
-
const raw = readUrl(element);
|
|
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
|
-
};
|
|
638
|
-
|
|
639
|
-
const onNavigate = () => {
|
|
640
|
-
if (disposed) return;
|
|
641
|
-
remember(readUrl(element));
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
const onNavigateInPage = (event) => {
|
|
645
|
-
if (disposed || event?.isMainFrame !== true) return;
|
|
646
|
-
onNavigate();
|
|
647
|
-
// Signing in can be an in-page route change, which skips did-stop-loading.
|
|
648
|
-
applyGuestPreferences(element);
|
|
649
|
-
};
|
|
650
|
-
|
|
651
|
-
const onFailLoad = (event) => {
|
|
652
|
-
if (disposed || event?.isMainFrame !== true) return;
|
|
653
|
-
// -3 is ERR_ABORTED: a superseded navigation, not a failure.
|
|
654
|
-
if (event.errorCode === -3) return;
|
|
655
|
-
if (restoring) {
|
|
656
|
-
// The remembered conversation is gone or unreachable; start clean.
|
|
657
|
-
restoring = false;
|
|
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);
|
|
663
|
-
};
|
|
664
|
-
|
|
665
|
-
/** The guest process exited or the guest was torn down underneath us. */
|
|
666
|
-
const onGuestGone = () => {
|
|
667
|
-
if (disposed) return;
|
|
668
|
-
fail(new Error(t('crashed')));
|
|
669
|
-
};
|
|
670
|
-
|
|
671
|
-
const listeners = [
|
|
672
|
-
['dom-ready', onDomReady],
|
|
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
|
-
];
|
|
680
|
-
|
|
681
|
-
try {
|
|
682
|
-
for (const [type, handler] of listeners) {
|
|
683
|
-
element.addEventListener(type, handler, type === 'dom-ready' ? { once: true } : undefined);
|
|
684
|
-
}
|
|
685
|
-
} catch (error) {
|
|
686
|
-
fail(error);
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
const start = async () => {
|
|
690
|
-
try {
|
|
691
|
-
const reservation = await bridge.acquire(PARTITION_KEY);
|
|
692
|
-
if (disposed) {
|
|
693
|
-
try {
|
|
694
|
-
Promise.resolve(bridge.release(reservation.lease)).catch(() => {});
|
|
695
|
-
} catch {
|
|
696
|
-
/* lease already gone */
|
|
697
|
-
}
|
|
698
|
-
return;
|
|
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
|
-
|
|
255
|
+
let alive = true;
|
|
256
|
+
fetchSettings()
|
|
257
|
+
.then((value) => {
|
|
258
|
+
if (!alive) return;
|
|
259
|
+
if (typeof value?.retentionDays === 'number') setDays(value.retentionDays);
|
|
260
|
+
})
|
|
261
|
+
.catch(() => {
|
|
262
|
+
if (alive) setState('load-failed');
|
|
263
|
+
});
|
|
723
264
|
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
|
-
}
|
|
265
|
+
alive = false;
|
|
759
266
|
};
|
|
760
|
-
|
|
761
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
762
|
-
}, [attempt]);
|
|
267
|
+
}, []);
|
|
763
268
|
|
|
764
|
-
|
|
765
|
-
|
|
269
|
+
const choose = (value) => {
|
|
270
|
+
if (state === 'saving') return;
|
|
271
|
+
const previous = days;
|
|
272
|
+
setDays(value);
|
|
273
|
+
setState('saving');
|
|
274
|
+
saveSettings(value)
|
|
275
|
+
.then((saved) => {
|
|
276
|
+
setDays(Number(saved?.retentionDays ?? value));
|
|
277
|
+
setState('saved');
|
|
278
|
+
})
|
|
279
|
+
.catch(() => {
|
|
280
|
+
setDays(previous);
|
|
281
|
+
setState('failed');
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const status =
|
|
286
|
+
state === 'saving'
|
|
287
|
+
? t('settings.saving')
|
|
288
|
+
: state === 'saved'
|
|
289
|
+
? t('settings.saved')
|
|
290
|
+
: state === 'failed'
|
|
291
|
+
? t('settings.failed')
|
|
292
|
+
: state === 'load-failed'
|
|
293
|
+
? t('settings.loadFailed')
|
|
294
|
+
: '';
|
|
295
|
+
|
|
296
|
+
return h(
|
|
297
|
+
'section',
|
|
298
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 10, padding: '4px 0 8px' } },
|
|
299
|
+
h(
|
|
766
300
|
'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
|
-
),
|
|
301
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
302
|
+
h('h3', { style: { margin: 0, fontSize: 14, fontWeight: 600, color: 'var(--dsw-alias-label-primary, #0f1115)' } }, t('settings.title')),
|
|
303
|
+
h(
|
|
304
|
+
'p',
|
|
305
|
+
{ style: { margin: 0, fontSize: 13, lineHeight: 1.6, color: 'var(--dsw-alias-label-secondary, #61656e)' } },
|
|
306
|
+
t('settings.description'),
|
|
782
307
|
),
|
|
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(
|
|
308
|
+
),
|
|
309
|
+
h(
|
|
806
310
|
'div',
|
|
807
|
-
{ style:
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
311
|
+
{ style: { display: 'flex', flexWrap: 'wrap', gap: 8 } },
|
|
312
|
+
RETENTION_CHOICES.map((value) =>
|
|
313
|
+
h(
|
|
314
|
+
'button',
|
|
315
|
+
{
|
|
316
|
+
key: value,
|
|
317
|
+
type: 'button',
|
|
318
|
+
onClick: () => choose(value),
|
|
319
|
+
'aria-pressed': days === value,
|
|
320
|
+
style: {
|
|
321
|
+
minWidth: 64,
|
|
322
|
+
padding: '6px 14px',
|
|
323
|
+
borderRadius: 999,
|
|
324
|
+
font: 'inherit',
|
|
325
|
+
fontSize: 13,
|
|
326
|
+
cursor: state === 'saving' ? 'progress' : 'pointer',
|
|
327
|
+
border:
|
|
328
|
+
days === value
|
|
329
|
+
? '1px solid var(--dsw-alias-brand-primary, #0f1115)'
|
|
330
|
+
: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,0.12))',
|
|
331
|
+
// 选中态用宿主自己的配对:品牌色做底、反色做字。
|
|
332
|
+
// 暗色下 brand-primary 是近白,反色是深灰;亮色下正好相反。
|
|
333
|
+
background:
|
|
334
|
+
days === value ? 'var(--dsw-alias-brand-primary, #0f1115)' : 'transparent',
|
|
335
|
+
color:
|
|
336
|
+
days === value
|
|
337
|
+
? 'var(--dsw-alias-label-primary-inverted, #fff)'
|
|
338
|
+
: 'var(--dsw-alias-label-primary, #0f1115)',
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
value === 0 ? t('settings.never') : t(`settings.days${value}`),
|
|
342
|
+
),
|
|
812
343
|
),
|
|
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,
|
|
344
|
+
),
|
|
345
|
+
h(
|
|
346
|
+
'p',
|
|
347
|
+
{ style: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-label-tertiary, #8b8f98)' } },
|
|
348
|
+
status.length > 0
|
|
349
|
+
? status
|
|
350
|
+
: days === 0
|
|
351
|
+
? t('settings.currentNever')
|
|
352
|
+
: t('settings.currentDays').replace('{n}', String(days)),
|
|
839
353
|
),
|
|
840
354
|
);
|
|
841
355
|
}
|
|
842
356
|
|
|
843
|
-
/**
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
{
|
|
848
|
-
|
|
849
|
-
);
|
|
850
|
-
}
|
|
357
|
+
/** 设置区块的最小错误边界:DSH 没有为设置区提供边界,一个渲染错误会整页空白。 */
|
|
358
|
+
class SettingsBoundary extends React.Component {
|
|
359
|
+
constructor(props) {
|
|
360
|
+
super(props);
|
|
361
|
+
this.state = { failed: false };
|
|
362
|
+
}
|
|
851
363
|
|
|
852
|
-
|
|
853
|
-
|
|
364
|
+
static getDerivedStateFromError() {
|
|
365
|
+
return { failed: true };
|
|
366
|
+
}
|
|
854
367
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
368
|
+
componentDidCatch(error) {
|
|
369
|
+
console.error(`${PLUGIN_ID}: settings section failed`, error);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
render() {
|
|
373
|
+
if (this.state.failed) {
|
|
374
|
+
return h(
|
|
375
|
+
'p',
|
|
376
|
+
{ style: { margin: 0, fontSize: 13, color: 'var(--dsw-alias-label-secondary, #61656e)' } },
|
|
377
|
+
this.props.fallback,
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
return this.props.children;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return {
|
|
385
|
+
inject: ['slots', 'locale'],
|
|
386
|
+
apply(ctx) {
|
|
862
387
|
ctx.effect(() => {
|
|
863
388
|
const offZh = ctx.locale.register(NS, 'zh', DICT.zh);
|
|
864
389
|
const offEn = ctx.locale.register(NS, 'en', DICT.en);
|
|
@@ -866,50 +391,82 @@ window.__ModuleLoader__.load({
|
|
|
866
391
|
offZh();
|
|
867
392
|
offEn();
|
|
868
393
|
};
|
|
869
|
-
},
|
|
394
|
+
}, `${PLUGIN_ID}: locale`);
|
|
870
395
|
|
|
871
396
|
const bound = ctx.locale.bind(NS);
|
|
872
|
-
const
|
|
873
|
-
const t = (key) => {
|
|
397
|
+
const t = (key, ...rest) => {
|
|
874
398
|
const raw = bound(key);
|
|
875
|
-
|
|
399
|
+
const value = raw === key || raw === undefined || raw === null ? DICT.en[key] : raw;
|
|
400
|
+
return typeof value === 'function' ? value(...rest) : value;
|
|
876
401
|
};
|
|
877
|
-
translate = t;
|
|
878
|
-
localeService = ctx.locale;
|
|
879
402
|
|
|
880
|
-
//
|
|
403
|
+
// 宿主语言变化时重挂 iframe,让面板文案与新语言一致;
|
|
404
|
+
// 同时盯着顶部的悬浮岛,把需要让出的高度实时传进面板。
|
|
405
|
+
function PanelShell() {
|
|
406
|
+
const [locale, setLocale] = React.useState(() => hostLocale(ctx));
|
|
407
|
+
const hostRef = React.useRef(null);
|
|
408
|
+
const [inset, setInset] = React.useState(() => measureSeatInset(null));
|
|
409
|
+
|
|
410
|
+
React.useEffect(() => ctx.locale.subscribe(() => setLocale(hostLocale(ctx))), []);
|
|
411
|
+
|
|
412
|
+
React.useEffect(() => {
|
|
413
|
+
let timer;
|
|
414
|
+
const schedule = () => {
|
|
415
|
+
if (timer !== undefined) return;
|
|
416
|
+
timer = setTimeout(() => {
|
|
417
|
+
timer = undefined;
|
|
418
|
+
setInset(measureSeatInset(hostRef.current));
|
|
419
|
+
}, 120);
|
|
420
|
+
};
|
|
421
|
+
// 侧栏开合会换掉框架的子节点,座位随之出现或消失。
|
|
422
|
+
const observer = new MutationObserver(schedule);
|
|
423
|
+
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] });
|
|
424
|
+
const resizer = new ResizeObserver(schedule);
|
|
425
|
+
resizer.observe(document.documentElement);
|
|
426
|
+
window.addEventListener('resize', schedule);
|
|
427
|
+
const onMessage = (event) => {
|
|
428
|
+
if (event.data?.type === 'vt-webchat:hello') setInset(measureSeatInset(hostRef.current));
|
|
429
|
+
};
|
|
430
|
+
window.addEventListener('message', onMessage);
|
|
431
|
+
return () => {
|
|
432
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
433
|
+
observer.disconnect();
|
|
434
|
+
resizer.disconnect();
|
|
435
|
+
window.removeEventListener('resize', schedule);
|
|
436
|
+
window.removeEventListener('message', onMessage);
|
|
437
|
+
};
|
|
438
|
+
}, []);
|
|
439
|
+
|
|
440
|
+
return h(Panel, { locale, inset, hostRef });
|
|
441
|
+
}
|
|
442
|
+
|
|
881
443
|
ctx.slots.inject('main', () =>
|
|
444
|
+
ctx.slots.register({ name: 'main', key: PANEL_ID }, PanelShell),
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
// order -10 让入口贴着「新会话」;与 1.x 的位置保持一致,升级后用户不会找不到。
|
|
448
|
+
ctx.slots.inject('sidebar.panellist', () =>
|
|
882
449
|
ctx.slots.register(
|
|
883
|
-
{
|
|
884
|
-
|
|
885
|
-
key: PANEL_ID,
|
|
886
|
-
inject: () => ({ t, locale: ctx.locale }),
|
|
887
|
-
},
|
|
888
|
-
ChatPanelShell,
|
|
450
|
+
{ name: 'sidebar.panellist', id: PANEL_ID, order: -10, label: () => t('entry') },
|
|
451
|
+
Glyph,
|
|
889
452
|
),
|
|
890
453
|
);
|
|
891
454
|
|
|
892
|
-
|
|
893
|
-
ctx.slots.inject('sidebar.panellist', () =>
|
|
455
|
+
ctx.slots.inject('settings.section', () =>
|
|
894
456
|
ctx.slots.register(
|
|
895
457
|
{
|
|
896
|
-
name: '
|
|
897
|
-
id:
|
|
898
|
-
order:
|
|
899
|
-
label: () => t('
|
|
458
|
+
name: 'settings.section',
|
|
459
|
+
id: 'web-chat-settings',
|
|
460
|
+
order: 26,
|
|
461
|
+
label: () => t('settings.nav'),
|
|
462
|
+
inject: () => ({ t }),
|
|
900
463
|
},
|
|
901
|
-
|
|
464
|
+
(props) => h(SettingsBoundary, { fallback: t('settings.crashed') }, h(RetentionSettings, props)),
|
|
902
465
|
),
|
|
903
466
|
);
|
|
904
|
-
} catch (error) {
|
|
905
|
-
try {
|
|
906
|
-
console.error(`${PLUGIN_ID}: registration failed`, error);
|
|
907
|
-
} catch {
|
|
908
|
-
/* console unavailable */
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
467
|
|
|
913
|
-
|
|
468
|
+
console.info(`[${PLUGIN_ID}] ${VERSION} ready`);
|
|
469
|
+
},
|
|
470
|
+
};
|
|
914
471
|
},
|
|
915
472
|
});
|