dsh-vt-web-chat 2.0.0 → 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/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "dsh-vt-web-chat",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
- "description": "Adds a Web Chat panel that runs DeepSeek's official open-source chat UI inside DeepSeek Harness, with requests proxied through your signed-in account and a configurable local chat-retention policy.",
5
+ "description": "Adds a DeepSeek Chat mode inside DeepSeek Harness: the official open-source chat UI, chat history in the sidebar, and a back-to-Harness switch, with requests proxied through your signed-in account and a configurable local chat-retention policy.",
6
6
  "license": "MIT",
7
7
  "author": "Vontean",
8
8
  "homepage": "https://github.com/Vontean/vt-dsh-plugin/tree/main/plugins/vt-web-chat#readme",
@@ -20,7 +20,9 @@
20
20
  "web-chat",
21
21
  "chat-demo",
22
22
  "deepseek",
23
- "retention"
23
+ "retention",
24
+ "sidebar",
25
+ "chat-mode"
24
26
  ],
25
27
  "engines": {
26
28
  "dsh": ">=0.2.1-rc.5 <0.3.0"
@@ -79,6 +79,156 @@ for (const [file, from, to] of brandPatches) {
79
79
  }
80
80
  }
81
81
 
82
+ // 2c. 宿主桥:DSH 的 Chat 模式侧栏需要「列会话 / 打开会话 / 新建对话」,
83
+ // 上游没有跨文档 API。这里只加一个只读 store + 消息转发的模块,
84
+ // 不改任何既有行为;锚点找不到就显式失败,避免静默少功能。
85
+ const bridgeSource = `/**
86
+ * DSH 嵌入式宿主桥:只做消息收发,不改变本应用的默认行为。
87
+ *
88
+ * 父页面(dsh-vt-web-chat 的侧栏)需要三件事:读取会话列表、打开某个会话、新建对话。
89
+ * 上游没有跨文档 API,这里把 store 已有的动作转成 postMessage,
90
+ * 并且只接受来自 window.parent 的命令。
91
+ */
92
+ import { initChat, newChat, selectSession, useChatStore } from './services/chat/store.js'
93
+
94
+ const HOST_SOURCE = 'vt-webchat-host'
95
+ const SHELL_SOURCE = 'vt-webchat-shell'
96
+
97
+ type HostSession = {
98
+ id: string
99
+ title: string
100
+ createdAt: number
101
+ updatedAt: number
102
+ }
103
+
104
+ const embedded = window.parent !== window
105
+
106
+ if (embedded) {
107
+ // 增量发布:切会话只发 activeId,列表真的变了才带 sessions;
108
+ // 流式回答期间 250ms 合并一次,避免每帧都给父页面重建整张列表。
109
+ let lastSessions = ''
110
+ let lastActive: string | null | undefined
111
+ let lastReady: boolean | undefined
112
+ let lastError: boolean | undefined
113
+ let timer: ReturnType<typeof setTimeout> | undefined
114
+
115
+ const publish = (force = false) => {
116
+ const state = useChatStore.getState()
117
+ const sessions: HostSession[] = state.sessions.map((session) => ({
118
+ id: session.id,
119
+ title: session.title,
120
+ createdAt: session.createdAt,
121
+ updatedAt: session.updatedAt,
122
+ }))
123
+ const sessionsBody = JSON.stringify(sessions)
124
+ const sessionsChanged = force || sessionsBody !== lastSessions
125
+ const activeChanged = force || state.activeId !== lastActive
126
+ const readyChanged = force || state.ready !== lastReady
127
+ const errorChanged = force || state.initError !== lastError
128
+ if (!sessionsChanged && !activeChanged && !readyChanged && !errorChanged) {
129
+ return
130
+ }
131
+
132
+ const message: Record<string, unknown> = { source: HOST_SOURCE, type: 'sync' }
133
+ if (sessionsChanged) {
134
+ message.sessions = sessions
135
+ lastSessions = sessionsBody
136
+ }
137
+ if (activeChanged) {
138
+ message.activeId = state.activeId
139
+ lastActive = state.activeId
140
+ }
141
+ if (readyChanged) {
142
+ message.ready = state.ready
143
+ lastReady = state.ready
144
+ }
145
+ if (errorChanged) {
146
+ message.error = state.initError
147
+ lastError = state.initError
148
+ }
149
+ window.parent.postMessage(message, '*')
150
+ }
151
+
152
+ const schedule = () => {
153
+ if (timer !== undefined) {
154
+ return
155
+ }
156
+ timer = setTimeout(() => {
157
+ timer = undefined
158
+ publish()
159
+ }, 250)
160
+ }
161
+
162
+ useChatStore.subscribe(schedule)
163
+
164
+ window.addEventListener('message', (event) => {
165
+ if (event.source !== window.parent) {
166
+ return
167
+ }
168
+ const data = event.data as { source?: string; type?: string; id?: unknown } | null
169
+ if (data === null || data.source !== SHELL_SOURCE) {
170
+ return
171
+ }
172
+ if (data.type === 'open-session' && typeof data.id === 'string') {
173
+ selectSession(data.id)
174
+ } else if (data.type === 'new-chat') {
175
+ newChat()
176
+ } else if (data.type === 'request-sync') {
177
+ publish(true)
178
+ } else if (data.type === 'retry') {
179
+ void initChat().then(() => publish(true))
180
+ }
181
+ })
182
+
183
+ void initChat().then(() => {
184
+ publish(true)
185
+ window.parent.postMessage({ source: HOST_SOURCE, type: 'ready' }, '*')
186
+ })
187
+ }
188
+ `;
189
+ fs.writeFileSync(path.join(work, 'src/hostBridge.ts'), bridgeSource);
190
+ const mainPath = path.join(work, 'src/main.tsx');
191
+ const mainText = fs.readFileSync(mainPath, 'utf8');
192
+ const importAnchor = "import { App } from './app/App.js'";
193
+ if (!mainText.includes("import './hostBridge.js'")) {
194
+ if (!mainText.includes(importAnchor)) {
195
+ throw new Error('src/main.tsx 的 App 导入锚点变了,请检查上游入口结构');
196
+ }
197
+ fs.writeFileSync(mainPath, mainText.replace(importAnchor, `${importAnchor}\nimport './hostBridge.js'`));
198
+ process.stderr.write('patched src/main.tsx: host bridge\n');
199
+ }
200
+
201
+ // 2d. 宿主接管导航后,面板自己的「收起态按钮岛」不再需要:
202
+ // DSH 侧栏已经有新建对话、历史和返回入口,重复的一层只会互相打架。
203
+ // 只在被嵌入时隐藏,单独打开 /webchat/ 的用法保持不变。
204
+ const collapsePath = path.join(work, 'src/app/App.tsx');
205
+ const collapseText = fs.readFileSync(collapsePath, 'utf8');
206
+ const collapseFrom = 'const siderCollapsed = useSettings((state) => state.siderCollapsed) && !isMobile';
207
+ const collapseTo = [
208
+ 'const prefersCollapsed = useSettings((state) => state.siderCollapsed) && !isMobile',
209
+ ' // 被 DSH 嵌入时导航统一走宿主侧栏,面板自己的侧栏永远不展开。',
210
+ ' const siderCollapsed = window.parent !== window || prefersCollapsed',
211
+ ].join('\n');
212
+ if (!collapseText.includes('const siderCollapsed = window.parent !== window || prefersCollapsed')) {
213
+ if (!collapseText.includes(collapseFrom)) {
214
+ throw new Error('src/app/App.tsx 的侧栏收起锚点变了,请检查上游 App 结构');
215
+ }
216
+ fs.writeFileSync(collapsePath, collapseText.replace(collapseFrom, collapseTo));
217
+ process.stderr.write('patched src/app/App.tsx: force the panel sider collapsed when embedded\n');
218
+ }
219
+
220
+ const appPath = path.join(work, 'src/app/App.tsx');
221
+ const appText = fs.readFileSync(appPath, 'utf8');
222
+ const islandFrom = '{siderCollapsed ? <CollapsedSider /> : null}';
223
+ const islandTo = '{siderCollapsed && window.parent === window ? <CollapsedSider /> : null}';
224
+ if (!appText.includes(islandTo)) {
225
+ if (!appText.includes(islandFrom)) {
226
+ throw new Error('src/app/App.tsx 的收起态按钮岛锚点变了,请检查上游侧栏结构');
227
+ }
228
+ fs.writeFileSync(appPath, appText.replace(islandFrom, islandTo));
229
+ process.stderr.write('patched src/app/App.tsx: hide the collapsed island when embedded\n');
230
+ }
231
+
82
232
  // 3. 安装与构建。
83
233
  run('pnpm', ['install', '--ignore-scripts'], work);
84
234
  run('pnpm', ['build'], work, { CHAT_DEMO_API_ORIGIN: API_PREFIX, NODE_ENV: 'production' });
@@ -2,5 +2,5 @@
2
2
  "repo": "https://github.com/deepseek-ai/chat-demo.git",
3
3
  "ref": "8ad7b56e196b87d8a3215dc09476d6d146ad3f0e",
4
4
  "apiOrigin": "/webchat",
5
- "builtAt": "2026-11-21T09:45:01.158Z"
5
+ "builtAt": "2026-11-22T07:53:16.901Z"
6
6
  }
@@ -1 +1 @@
1
- <!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="theme-color" content="#ffffff"><title>API 使用 demo</title><meta content="0.1.3" name="application-version"><script defer src="static/js/main.7c5f914e.js"></script><link href="static/css/main.27198ffe.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
1
+ <!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="theme-color" content="#ffffff"><title>API 使用 demo</title><meta content="0.1.3" name="application-version"><script defer src="static/js/main.12b22c21.js"></script><link href="static/css/main.27198ffe.css" rel="stylesheet"></head><body><div id="root"></div></body></html>