dsh-chat-history-sync 0.9.2 → 0.10.8
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.en.md +36 -0
- package/README.md +38 -2
- package/client/client.js +153 -70
- package/lib/browser/login-save.mjs +105 -0
- package/lib/engine/install.cjs +1343 -0
- package/lib/engine/sync-all.cjs +1 -0
- package/lib/index.js +64 -15
- package/package.json +8 -3
package/README.en.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Chat History Sync
|
|
2
|
+
|
|
3
|
+
Free. Pull a DeepSeek account's chat history from the web and mobile app into DeepSeek Harness as native sessions, organized by month and ready to continue.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
DeepSeek keeps chats in the web app and mobile app, but DSH cannot see them or continue them. This plugin imports the same account's chats into DSH, stores them by month, and lets you open and continue each one.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- One account, both clients: web and mobile-app history come from the same DeepSeek account; multiple accounts supported
|
|
12
|
+
- Months only: DSH workspaces are monthly, not split by category
|
|
13
|
+
- Report and catalog: every sync writes a report; a category catalog adds a 50–100 character summary per chat
|
|
14
|
+
- Append-only: same-title chats with different content are kept; backups before install; DSH-created sessions are never touched
|
|
15
|
+
- Local tokens: encrypted with Windows DPAPI, never shown in the UI, never uploaded
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
Requirements: Windows 10/11, DSH 0.2.x.
|
|
20
|
+
|
|
21
|
+
```powershell
|
|
22
|
+
dsh plugin add dsh-chat-history-sync
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then open **Settings → Chat History Sync → Log in → Sync now**.
|
|
26
|
+
|
|
27
|
+
## Data
|
|
28
|
+
|
|
29
|
+
- Chat data stays in the local DSH workspace
|
|
30
|
+
- Sync only talks to `chat.deepseek.com`
|
|
31
|
+
- Tokens stay on this machine, encrypted with DPAPI
|
|
32
|
+
- No telemetry, no model calls; summaries are generated locally and free
|
|
33
|
+
|
|
34
|
+
## Scope
|
|
35
|
+
|
|
36
|
+
Windows only. Not an official DeepSeek plugin.
|
package/README.md
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 聊天历史同步
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**免费。把 DeepSeek 账号的网页端和手机 App 聊天记录同步进 DSH,整理成按月份归档、可以继续对话的原生会话。**
|
|
4
|
+
|
|
5
|
+
## 它解决什么问题
|
|
6
|
+
|
|
7
|
+
DeepSeek 的聊天记录散在网页和手机 App 里,DSH 里看不到,也不能接着聊。这个插件把同一个账号的聊天记录拉进 DSH,按月份放好,打开就能继续。
|
|
8
|
+
|
|
9
|
+
## 主要功能
|
|
10
|
+
|
|
11
|
+
- **一个账号,两端记录**:网页端和手机 App 的聊天都从同一个 DeepSeek 账号读取;支持多个账号
|
|
12
|
+
- **只留月份**:DSH 工作区只建月份,不再按分类拆工作区
|
|
13
|
+
- **报告和目录**:每次同步生成报告;按主题生成分类目录,每条带 50–100 字摘要
|
|
14
|
+
- **只增不减**:同名但内容不同的会话保留;安装前备份;不改 DSH 自建会话
|
|
15
|
+
- **免费,不调用模型**:摘要由本地规则生成,零模型费用、零隐私外发;同步本身也不调用模型
|
|
16
|
+
- **本机 token**:token 用 Windows DPAPI 加密,界面不显示,不上传
|
|
17
|
+
|
|
18
|
+
## 安装
|
|
19
|
+
|
|
20
|
+
要求:Windows 10/11,DSH 0.2.x。
|
|
21
|
+
|
|
22
|
+
```powershell
|
|
23
|
+
dsh plugin add dsh-chat-history-sync
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
安装后打开:
|
|
27
|
+
|
|
28
|
+
**设置 → 聊天历史同步 → 登录新账号 → 立即同步**
|
|
29
|
+
|
|
30
|
+
## 数据说明
|
|
31
|
+
|
|
32
|
+
- 聊天记录只存在本机 DSH 工作区
|
|
33
|
+
- 同步时只访问 `chat.deepseek.com`,不发送到其它服务
|
|
34
|
+
- token 只存本机,DPAPI 加密
|
|
35
|
+
- 无遥测、无统计上报
|
|
36
|
+
|
|
37
|
+
## 范围
|
|
38
|
+
|
|
39
|
+
**仅 Windows。** 不是 DeepSeek 官方插件,和 DeepSeek 官方无隶属关系。
|
|
4
40
|
|
|
5
41
|
## 功能
|
|
6
42
|
|
package/client/client.js
CHANGED
|
@@ -32,7 +32,13 @@ window.__ModuleLoader__.load({
|
|
|
32
32
|
const key = 'r' + i;
|
|
33
33
|
if (/^##\s+/.test(line)) return h('div', { key, className: 'msx-report-h' }, line.replace(/^##\s+/, ''));
|
|
34
34
|
if (/^\s*-\s+摘要:/.test(line)) return h('div', { key, className: 'msx-report-sum' }, line.replace(/^\s*-\s+/, ''));
|
|
35
|
-
if (/^-\s+/.test(line))
|
|
35
|
+
if (/^-\s+/.test(line)) {
|
|
36
|
+
const link = line.match(/\[([^\]]+)\]\(([^)]+)\)/);
|
|
37
|
+
return h('div', { key, className: 'msx-report-item' },
|
|
38
|
+
'• ' + line.replace(/^-\s+/, '').replace(/\[([^\]]+)\]\([^)]*\)/g, '$1'),
|
|
39
|
+
link ? h('button', { className: 'msx-linkbtn', 'aria-label': '复制会话位置路径', title: link[2], onClick: () => { try { navigator.clipboard.writeText(link[2]); } catch (e) {} } }, '复制路径') : null,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
36
42
|
return h('div', { key, className: 'msx-report-line' }, line.replace(/\[([^\]]+)\]\([^)]*\)/g, '$1'));
|
|
37
43
|
});
|
|
38
44
|
|
|
@@ -80,6 +86,73 @@ window.__ModuleLoader__.load({
|
|
|
80
86
|
}
|
|
81
87
|
`;
|
|
82
88
|
|
|
89
|
+
function FooterEntry({ wide }) {
|
|
90
|
+
const [busy, setBusy] = React.useState(false);
|
|
91
|
+
const [hover, setHover] = React.useState(false);
|
|
92
|
+
const [meta, setMeta] = React.useState({ running: false, pending: false, empty: true });
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
let alive = true;
|
|
95
|
+
const tick = async () => {
|
|
96
|
+
if (document.visibilityState === 'hidden') return;
|
|
97
|
+
try {
|
|
98
|
+
const res = await clientCtx.remote.settings.describe();
|
|
99
|
+
const doc = res && res.ok ? res.value : null;
|
|
100
|
+
const list = (doc && doc.namespaces) || [];
|
|
101
|
+
const ns = list.find((n) => n.ns === NS) || list.find((n) => String(n.ns).endsWith(':' + NS) || String(n.ns).endsWith('/' + NS));
|
|
102
|
+
if (alive && ns) {
|
|
103
|
+
let accounts = [];
|
|
104
|
+
try { accounts = JSON.parse((ns.value && ns.value.accounts) || '[]'); } catch (e) { accounts = []; }
|
|
105
|
+
setMeta({ running: ns.value && ns.value.status === 'running', pending: !!(ns.value && ns.value.installPending), empty: !accounts.length });
|
|
106
|
+
}
|
|
107
|
+
} catch (e) {}
|
|
108
|
+
};
|
|
109
|
+
tick();
|
|
110
|
+
const id = setInterval(tick, 5000);
|
|
111
|
+
return () => { alive = false; clearInterval(id); };
|
|
112
|
+
}, []);
|
|
113
|
+
const running = busy || meta.running;
|
|
114
|
+
const run = async () => {
|
|
115
|
+
if (running || meta.empty) return;
|
|
116
|
+
setBusy(true);
|
|
117
|
+
try {
|
|
118
|
+
const res = await clientCtx.remote.settings.describe();
|
|
119
|
+
const doc = res && res.ok ? res.value : null;
|
|
120
|
+
const list = (doc && doc.namespaces) || [];
|
|
121
|
+
const ns = list.find((n) => n.ns === NS) || list.find((n) => String(n.ns).endsWith(':' + NS) || String(n.ns).endsWith('/' + NS));
|
|
122
|
+
if (!ns) return;
|
|
123
|
+
await clientCtx.remote.settings.mutate(ns.ns, [{ op: 'set', path: ['runNow'], value: true }], ns.revision || 0);
|
|
124
|
+
} catch (e) {} finally {
|
|
125
|
+
setTimeout(() => setBusy(false), 5000);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return h('button', {
|
|
129
|
+
type: 'button',
|
|
130
|
+
className: 'msx-footer-action',
|
|
131
|
+
title: meta.empty ? '请先在设置中登录账号' : (running ? '正在同步,可在设置页查看进度' : '立即同步聊天历史'),
|
|
132
|
+
'aria-label': meta.empty ? '未登录,请先在设置中登录账号' : (running ? '正在同步聊天历史' : '立即同步聊天历史'),
|
|
133
|
+
disabled: running || meta.empty,
|
|
134
|
+
onClick: run,
|
|
135
|
+
onMouseEnter: () => setHover(true),
|
|
136
|
+
onMouseLeave: () => setHover(false),
|
|
137
|
+
style: { display: 'flex', alignItems: 'center', justifyContent: wide ? 'flex-start' : 'center', gap: 8, width: '100%', padding: '8px 10px', border: 'none', borderRadius: 9, background: hover && !running ? 'var(--dsw-alias-bg-layer-2)' : 'transparent', color: 'var(--dsw-alias-label-secondary)', font: 'inherit', fontSize: 13, cursor: 'pointer' },
|
|
138
|
+
}, h('span', { 'aria-hidden': 'true', style: { fontSize: 16, lineHeight: 1, position: 'relative' } }, running ? '…' : '↻', meta.pending && !running ? h('i', { style: { position: 'absolute', right: -3, top: -2, width: 6, height: 6, borderRadius: '50%', background: 'var(--dsw-alias-state-warning)' } }) : null), wide ? h('span', null, meta.empty ? '未登录' : (running ? '正在同步' : (meta.pending ? '待安装' : '同步聊天历史'))) : null);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
class SlotBoundary extends React.Component {
|
|
142
|
+
constructor(props) {
|
|
143
|
+
super(props);
|
|
144
|
+
this.state = { err: null };
|
|
145
|
+
}
|
|
146
|
+
static getDerivedStateFromError(err) { return { err }; }
|
|
147
|
+
render() {
|
|
148
|
+
if (this.state.err) return h('div', { style: { padding: '12px 16px', color: 'var(--dsw-alias-state-error)', fontSize: 13 } }, '界面加载失败,请关闭设置后重开。');
|
|
149
|
+
return this.props.children;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function CardSafe() { return h(SlotBoundary, null, h(Card)); }
|
|
154
|
+
function FooterSafe(props) { return h(SlotBoundary, null, h(FooterEntry, props)); }
|
|
155
|
+
|
|
83
156
|
function Card() {
|
|
84
157
|
const [value, setValue] = React.useState(null);
|
|
85
158
|
const [revision, setRevision] = React.useState(0);
|
|
@@ -90,6 +163,7 @@ window.__ModuleLoader__.load({
|
|
|
90
163
|
const [reportOpen, setReportOpen] = React.useState(false);
|
|
91
164
|
const [reportFull, setReportFull] = React.useState(false);
|
|
92
165
|
const [confirmDel, setConfirmDel] = React.useState(-1);
|
|
166
|
+
const [advOpen, setAdvOpen] = React.useState(false);
|
|
93
167
|
const lastRev = React.useRef(0);
|
|
94
168
|
const nsRef = React.useRef(NS);
|
|
95
169
|
|
|
@@ -100,7 +174,7 @@ window.__ModuleLoader__.load({
|
|
|
100
174
|
const list = (doc && doc.namespaces) || [];
|
|
101
175
|
const exact = list.find((n) => n.ns === NS);
|
|
102
176
|
if (exact) { nsRef.current = exact.ns; return exact; }
|
|
103
|
-
// 宿主 0.2.x 的命名空间是 Loader 入口 id(如 include:dsh-
|
|
177
|
+
// 宿主 0.2.x 的命名空间是 Loader 入口 id(如 include:dsh-chat-history-sync)
|
|
104
178
|
const bySuffix = list.find((n) => String(n.ns).endsWith(':' + NS) || String(n.ns).endsWith('/' + NS));
|
|
105
179
|
if (bySuffix) nsRef.current = bySuffix.ns;
|
|
106
180
|
return bySuffix || null;
|
|
@@ -176,7 +250,8 @@ window.__ModuleLoader__.load({
|
|
|
176
250
|
} else if (v.status === 'done') {
|
|
177
251
|
setStartedAt(0);
|
|
178
252
|
try { window.localStorage.removeItem(START_KEY); } catch (e) {}
|
|
179
|
-
|
|
253
|
+
const doneText = String(v.statusText || '');
|
|
254
|
+
setMsg(doneText && !/^同步完成/.test(doneText) ? doneText : '');
|
|
180
255
|
} else if (v.status === 'error') {
|
|
181
256
|
setStartedAt(0);
|
|
182
257
|
try { window.localStorage.removeItem(START_KEY); } catch (e) {}
|
|
@@ -200,8 +275,10 @@ window.__ModuleLoader__.load({
|
|
|
200
275
|
setBusy(true);
|
|
201
276
|
try {
|
|
202
277
|
const r = await clientCtx.remote.settings.mutate(nsRef.current, [{ op: 'set', path: [field], value: v }], revision);
|
|
203
|
-
if (r && r.ok) {
|
|
204
|
-
|
|
278
|
+
if (r && r.ok) {
|
|
279
|
+
setRevision(r.value.revision); lastRev.current = r.value.revision; setValue(r.value.value || {}); setMsg('已保存');
|
|
280
|
+
setTimeout(() => setMsg((cur) => (cur === '已保存' ? '' : cur)), 1800);
|
|
281
|
+
} else { setMsg('保存被拒绝'); void load(); }
|
|
205
282
|
} catch (e) { setMsg('保存失败:' + (e && e.message)); }
|
|
206
283
|
setBusy(false);
|
|
207
284
|
};
|
|
@@ -260,19 +337,17 @@ window.__ModuleLoader__.load({
|
|
|
260
337
|
try { attachStats = JSON.parse((value && value.attachmentStats) || 'null'); } catch (e) { attachStats = null; }
|
|
261
338
|
const attachText = attachStats ? '预计 ' + attachStats.count + ' 个附件 · ' + (attachStats.bytes / 1048576).toFixed(1) + ' MB' : '';
|
|
262
339
|
const setAccounts = (next) => { void write('accounts', JSON.stringify(next)); };
|
|
340
|
+
const hasAccounts = accounts.some((a) => a && a.enabled !== false);
|
|
341
|
+
const hasAnyAccounts = accounts.length > 0;
|
|
263
342
|
const patchRow = (i, patch) => { const n = accounts.slice(); n[i] = { ...n[i], ...patch }; setAccounts(n); };
|
|
264
343
|
const loginStatus = value && value.loginStatus;
|
|
265
|
-
const statusLine = msg || (running ? '正在同步…' : '尚未同步');
|
|
344
|
+
const statusLine = msg || (running ? '正在同步…' : (value && value.status === 'error' ? String(value.statusText || '同步失败') : (value && value.lastSyncAt ? '已同步' : '尚未同步')));
|
|
266
345
|
const pendingText = /检测到新会话/.test(String((value && value.statusText) || ''));
|
|
267
346
|
const needInstall = installPending || pendingText;
|
|
268
347
|
const shownStatus = (!running && pendingText) ? '同步完成 · 待确认安装' : statusLine;
|
|
269
348
|
const failed = !!(value && (value.status === 'error' || /失败|失效/.test(String(shownStatus || ''))));
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
if (!s) return '';
|
|
273
|
-
if (s.includes('*')) return s;
|
|
274
|
-
const d = s.replace(/\D/g, '');
|
|
275
|
-
return d.length >= 11 ? d.slice(0, 3) + '****' + d.slice(-4) : '';
|
|
349
|
+
const fmtTime = (ts) => {
|
|
350
|
+
try { return new Date(ts).toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); } catch (e) { return ''; }
|
|
276
351
|
};
|
|
277
352
|
|
|
278
353
|
return h('div', { className: 'msx', style: { display: 'grid', gap: 18, maxWidth: 640, padding: '2px 0 8px' } },
|
|
@@ -280,7 +355,7 @@ window.__ModuleLoader__.load({
|
|
|
280
355
|
|
|
281
356
|
h('div', null,
|
|
282
357
|
h('h2', { style: { margin: 0, fontSize: 18, fontWeight: 600, color: 'var(--dsw-alias-label-primary)' } }, '聊天历史同步'),
|
|
283
|
-
h('div', { className: 'msx-muted', style: { marginTop: 6 } }, '
|
|
358
|
+
h('div', { className: 'msx-muted', style: { marginTop: 6 } }, 'DeepSeek 聊天记录 → DSH,按月份归档。'),
|
|
284
359
|
),
|
|
285
360
|
|
|
286
361
|
// 同步状态 + 立即同步
|
|
@@ -291,17 +366,17 @@ window.__ModuleLoader__.load({
|
|
|
291
366
|
h('div', { className: 'msx-sub', role: 'status', 'aria-live': 'polite', style: failed ? { color: 'var(--dsw-alias-state-error)' } : null }, shownStatus),
|
|
292
367
|
),
|
|
293
368
|
h('div', { style: { display: 'flex', gap: 8 } },
|
|
294
|
-
running ? h('button', { className: 'msx-btn', disabled: busy, onClick: () => void write('cancelSync', true) }, '取消') : null,
|
|
295
|
-
h('button', { className: 'msx-btn msx-btn-primary', disabled: busy || running, onClick: trigger }, running ? '同步中…' : '立即同步'),
|
|
369
|
+
running ? h('button', { className: 'msx-btn', disabled: busy, 'aria-label': '取消当前同步', onClick: () => void write('cancelSync', true) }, '取消') : null,
|
|
370
|
+
h('button', { className: 'msx-btn msx-btn-primary', disabled: busy || running || !hasAccounts, 'aria-label': !hasAccounts ? (hasAnyAccounts ? '请先启用账号' : '请先登录账号') : (running ? '同步进行中' : '立即同步聊天历史'), onClick: trigger }, !hasAccounts ? (hasAnyAccounts ? '先启用' : '先登录') : (running ? '同步中…' : '立即同步')),
|
|
296
371
|
),
|
|
297
372
|
),
|
|
373
|
+
h('div', { className: 'msx-sub', style: { padding: '0 16px 12px' } }, running ? '后台同步中,可离开此页。' : (!hasAccounts ? (hasAnyAccounts ? '先启用账号,再同步。' : '先登录账号,再同步。') : '同步时可离开此页。')),
|
|
298
374
|
running ? h('div', { className: 'msx-kbar', role: 'progressbar', 'aria-busy': 'true', 'aria-valuetext': '同步进行中' }, h('i', null)) : null,
|
|
299
375
|
(value && value.lastSyncAt) ? h('div', { className: 'msx-sub', style: { paddingTop: 6 } },
|
|
300
|
-
'上次同步 ' +
|
|
376
|
+
'上次同步 ' + fmtTime(value.lastSyncAt),
|
|
301
377
|
) : null,
|
|
302
378
|
(value && value.reportText) ? h('div', { className: 'msx-row', style: { borderTop: '1px solid var(--dsw-alias-border-l1)', paddingTop: 10, paddingBottom: 10 } },
|
|
303
|
-
h('button', { className: 'msx-linkbtn', onClick: () => setReportOpen(!reportOpen) }, reportOpen ? '
|
|
304
|
-
h('span', { className: 'msx-muted' }, '最近一次同步结果'),
|
|
379
|
+
h('button', { className: 'msx-linkbtn', 'aria-expanded': reportOpen, onClick: () => setReportOpen(!reportOpen) }, reportOpen ? '收起报告' : '查看报告'),
|
|
305
380
|
) : null,
|
|
306
381
|
(reportOpen && value && value.reportText) ? h('div', { className: 'msx-report' },
|
|
307
382
|
renderReportText(reportFull ? value.reportText : (String(value.reportText).slice(0, 1200) + (String(value.reportText).length > 1200 ? '\n…' : ''))),
|
|
@@ -313,11 +388,11 @@ window.__ModuleLoader__.load({
|
|
|
313
388
|
needInstall ? h('div', { className: 'msx-card', style: { marginTop: 10 } },
|
|
314
389
|
h('div', { style: { minWidth: 0 } },
|
|
315
390
|
h('div', { className: 'msx-label' }, '检测到新会话'),
|
|
316
|
-
h('div', { className: 'msx-sub' }, '是否现在安装到工作区?DSH
|
|
391
|
+
h('div', { className: 'msx-sub' }, '是否现在安装到工作区?DSH 会重启一次;请先完成当前回复。'),
|
|
317
392
|
),
|
|
318
393
|
h('div', { style: { display: 'flex', gap: 8, marginTop: 10 } },
|
|
319
|
-
h('button', { className: 'msx-btn msx-btn-primary', disabled: busy, onClick: () => void write('installNow', true) }, '立即安装'),
|
|
320
|
-
h('button', { className: 'msx-btn', disabled: busy, onClick: () => void write('installPending', false) }, '稍后'),
|
|
394
|
+
h('button', { className: 'msx-btn msx-btn-primary', disabled: busy, 'aria-label': '立即安装到工作区并重启 DSH', onClick: () => void write('installNow', true) }, '立即安装'),
|
|
395
|
+
h('button', { className: 'msx-btn', disabled: busy, 'aria-label': '稍后安装', onClick: () => void write('installPending', false) }, '稍后'),
|
|
321
396
|
),
|
|
322
397
|
) : null,
|
|
323
398
|
|
|
@@ -328,14 +403,13 @@ window.__ModuleLoader__.load({
|
|
|
328
403
|
h('h3', { className: 'msx-h3', style: { margin: 0 } }, '同步账号'),
|
|
329
404
|
h('span', { className: 'msx-muted' }, accounts.length + ' 个'),
|
|
330
405
|
),
|
|
331
|
-
h('button', { className: 'msx-linkbtn', onClick: () => setAccOpen(!accOpen) }, accOpen ? '收起' : '展开'),
|
|
406
|
+
h('button', { className: 'msx-linkbtn', 'aria-expanded': accOpen, onClick: () => setAccOpen(!accOpen) }, accOpen ? '收起' : '展开'),
|
|
332
407
|
),
|
|
333
408
|
accOpen ? h('div', { className: 'msx-card', style: { marginTop: 8 } },
|
|
334
409
|
accounts.length === 0
|
|
335
|
-
? h('div',
|
|
336
|
-
h('div', { className: 'msx-muted' }, '
|
|
337
|
-
h('div', { className: 'msx-
|
|
338
|
-
h('div', { className: 'msx-sub', style: { marginTop: 8 } }, '开始使用:1)登录新账号 2)点「立即同步」 3)有新会话时点「立即安装」'),
|
|
410
|
+
? h('div', { style: { padding: '14px 16px' } },
|
|
411
|
+
h('div', { className: 'msx-muted' }, '还没有账号。登录后自动同步该账号的聊天历史。'),
|
|
412
|
+
h('div', { className: 'msx-sub', style: { marginTop: 6 } }, 'DSH 自建会话不会被改动。'),
|
|
339
413
|
)
|
|
340
414
|
: accounts.map((a, i) => h('div', { key: i, className: 'msx-row', style: { gap: 10 } },
|
|
341
415
|
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, minWidth: 0, flex: '1 1 auto' } },
|
|
@@ -343,13 +417,11 @@ window.__ModuleLoader__.load({
|
|
|
343
417
|
? h('img', { src: a.avatarUrl, className: 'msx-avatar-img', alt: '', referrerPolicy: 'no-referrer' })
|
|
344
418
|
: h('div', { className: 'msx-avatar' }, String(a.nickname || a.name || a.prefix || '?').slice(0, 1)),
|
|
345
419
|
h('div', { style: { minWidth: 0 } },
|
|
346
|
-
h('div', { className: 'msx-fieldlabel' }, '显示名'),
|
|
347
420
|
h(EditableField, {
|
|
348
421
|
value: a.nickname || '', placeholder: a.name || '显示名', label: '显示名', disabled: busy, width: 130, bold: true,
|
|
349
422
|
onCommit: (v) => patchRow(i, { nickname: v }),
|
|
350
423
|
}),
|
|
351
|
-
h('div', { className: 'msx-sub' },
|
|
352
|
-
(health[a.name] || health[a.prefix]) ? h('div', { className: 'msx-sub', style: { color: /失败|error|失效/.test(String(health[a.name] || health[a.prefix])) ? 'var(--dsw-alias-state-error)' : 'var(--dsw-alias-label-secondary)' } }, String(health[a.name] || health[a.prefix]).slice(0, 80)) : null,
|
|
424
|
+
(health[a.name] || health[a.prefix]) && /失败|error|失效/.test(String(health[a.name] || health[a.prefix])) ? h('div', { className: 'msx-sub', style: { color: 'var(--dsw-alias-state-error)' } }, String(health[a.name] || health[a.prefix]).slice(0, 80)) : null,
|
|
353
425
|
),
|
|
354
426
|
),
|
|
355
427
|
h('label', { style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: 13, color: 'var(--dsw-alias-label-secondary)', flex: '0 0 auto' } },
|
|
@@ -360,16 +432,16 @@ window.__ModuleLoader__.load({
|
|
|
360
432
|
}),
|
|
361
433
|
),
|
|
362
434
|
h('label', { style: { display: 'flex', gap: 5, alignItems: 'center', fontSize: 13, color: 'var(--dsw-alias-label-secondary)', whiteSpace: 'nowrap' } },
|
|
363
|
-
h('input', { type: 'checkbox', checked: a.enabled !== false, disabled: busy, onChange: (e) => patchRow(i, { enabled: e.target.checked }) }),
|
|
435
|
+
h('input', { type: 'checkbox', checked: a.enabled !== false, disabled: busy, 'aria-label': '启用账号 ' + (a.nickname || a.name || a.prefix), onChange: (e) => patchRow(i, { enabled: e.target.checked }) }),
|
|
364
436
|
'启用',
|
|
365
437
|
),
|
|
366
|
-
h('button', { className: 'msx-btn msx-btn-danger', disabled: busy, onClick: () => setConfirmDel(confirmDel === i ? -1 : i) }, confirmDel === i ? '取消' : '删除'),
|
|
367
|
-
confirmDel === i ? h('button', { className: 'msx-btn msx-btn-danger', disabled: busy, onClick: () => { setConfirmDel(-1); setAccounts(accounts.filter((_, j) => j !== i)); } }, '确认删除') : null,
|
|
438
|
+
h('button', { className: 'msx-btn msx-btn-danger', disabled: busy, 'aria-label': confirmDel === i ? '取消删除' : '删除账号', onClick: () => setConfirmDel(confirmDel === i ? -1 : i) }, confirmDel === i ? '取消' : '删除'),
|
|
439
|
+
confirmDel === i ? h('button', { className: 'msx-btn msx-btn-danger', autoFocus: true, disabled: busy, 'aria-label': '确认删除账号', onClick: () => { setConfirmDel(-1); setAccounts(accounts.filter((_, j) => j !== i)); } }, '确认删除') : null,
|
|
368
440
|
)),
|
|
369
441
|
) : null,
|
|
370
|
-
h('button', { className: 'msx-dashed', disabled: busy, onClick: login }, '+ 登录新账号'),
|
|
371
|
-
(value && Number(value.duplicateCount) > 0) ? h('
|
|
372
|
-
'
|
|
442
|
+
h('button', { className: 'msx-dashed', disabled: busy, 'aria-label': '登录新的 DeepSeek 账号', onClick: login }, '+ 登录新账号'),
|
|
443
|
+
(value && Number(value.duplicateCount) > 0) ? h('button', { className: 'msx-linkbtn', style: { marginTop: 6, textAlign: 'left' }, onClick: () => setReportOpen(true) },
|
|
444
|
+
'同名不同内容 ' + Number(value.duplicateCount) + ' 组 · 在报告中查看',
|
|
373
445
|
) : null,
|
|
374
446
|
(value && value.loginStatus && /请在弹出的浏览器|正在打开登录页/.test(String(value.loginStatus)))
|
|
375
447
|
? h('button', { className: 'msx-btn', style: { marginTop: 8 }, disabled: busy, onClick: () => void write('loginCancel', Date.now()) }, '取消登录')
|
|
@@ -383,8 +455,8 @@ window.__ModuleLoader__.load({
|
|
|
383
455
|
h('div', { className: 'msx-card' },
|
|
384
456
|
h('div', { className: 'msx-row' },
|
|
385
457
|
h('div', null,
|
|
386
|
-
h('div', { className: 'msx-label' }, '
|
|
387
|
-
h('div', { className: 'msx-sub' }, '
|
|
458
|
+
h('div', { className: 'msx-label' }, '附件'),
|
|
459
|
+
h('div', { className: 'msx-sub' }, '原件 + 图片'),
|
|
388
460
|
attachText ? h('div', { className: 'msx-sub' }, attachText) : null,
|
|
389
461
|
),
|
|
390
462
|
h('select', { className: 'msx-select', 'aria-label': '附件策略', value: mode, disabled: busy, onChange: (e) => void write('attachmentMode', e.target.value) },
|
|
@@ -393,59 +465,64 @@ window.__ModuleLoader__.load({
|
|
|
393
465
|
h('option', { value: 'none' }, '都不下载'),
|
|
394
466
|
),
|
|
395
467
|
),
|
|
396
|
-
h('div', { className: 'msx-row' },
|
|
397
|
-
h('div', { style: { minWidth: 0 } },
|
|
398
|
-
h('div', { className: 'msx-label' }, '报告会话 ID'),
|
|
399
|
-
h('div', { className: 'msx-sub' }, '写入指定会话;留空则自动创建'),
|
|
400
|
-
),
|
|
401
|
-
h('input', {
|
|
402
|
-
className: 'msx-input', value: (value && value.reportTargetSessionId) || '', placeholder: 'session-…', disabled: busy,
|
|
403
|
-
onChange: (e) => void write('reportTargetSessionId', e.target.value), style: { flex: '0 0 200px' },
|
|
404
|
-
}),
|
|
405
|
-
),
|
|
406
468
|
h('div', { className: 'msx-row' },
|
|
407
469
|
h('div', null,
|
|
408
470
|
h('div', { className: 'msx-label' }, '自动巡检'),
|
|
409
|
-
h('div', { className: 'msx-sub' }, '
|
|
471
|
+
h('div', { className: 'msx-sub' }, '有变化才生成报告'),
|
|
410
472
|
),
|
|
411
473
|
h('label', { style: { display: 'flex', alignItems: 'center' } },
|
|
412
|
-
h('input', { type: 'checkbox', checked: auto, disabled: busy, onChange: (e) => void write('autoSync', e.target.checked) }),
|
|
474
|
+
h('input', { type: 'checkbox', checked: auto, disabled: busy, 'aria-label': '自动巡检', onChange: (e) => void write('autoSync', e.target.checked) }),
|
|
413
475
|
),
|
|
414
476
|
),
|
|
415
477
|
h('div', { className: 'msx-row' },
|
|
416
478
|
h('div', null,
|
|
417
|
-
h('div', { className: 'msx-label' }, '
|
|
418
|
-
h('div', { className: 'msx-sub' }, '
|
|
479
|
+
h('div', { className: 'msx-label' }, '自动安装'),
|
|
480
|
+
h('div', { className: 'msx-sub' }, '新会话自动安装(会重启)'),
|
|
419
481
|
),
|
|
420
482
|
h('label', { style: { display: 'flex', alignItems: 'center' } },
|
|
421
|
-
h('input', { type: 'checkbox', checked: autoInstall, disabled: busy, onChange: (e) => void write('autoInstall', e.target.checked) }),
|
|
483
|
+
h('input', { type: 'checkbox', checked: autoInstall, disabled: busy, 'aria-label': '同步后自动安装', onChange: (e) => void write('autoInstall', e.target.checked) }),
|
|
422
484
|
),
|
|
423
485
|
),
|
|
424
486
|
h('div', { className: 'msx-row' },
|
|
425
|
-
h('
|
|
426
|
-
|
|
427
|
-
|
|
487
|
+
h('button', { className: 'msx-linkbtn', 'aria-expanded': advOpen, onClick: () => setAdvOpen(!advOpen) }, advOpen ? '收起高级设置 ▴' : '高级设置 ▾'),
|
|
488
|
+
),
|
|
489
|
+
advOpen ? h('div', null,
|
|
490
|
+
h('div', { className: 'msx-row' },
|
|
491
|
+
h('div', null,
|
|
492
|
+
h('div', { className: 'msx-label' }, '报告会话'),
|
|
493
|
+
h('div', { className: 'msx-sub' }, '留空自动管理'),
|
|
494
|
+
),
|
|
495
|
+
h(EditableField, {
|
|
496
|
+
value: (value && value.reportTargetSessionId) || '', placeholder: '自动管理', label: '报告会话 ID', disabled: busy, width: 180,
|
|
497
|
+
onCommit: (v) => void write('reportTargetSessionId', v),
|
|
498
|
+
}),
|
|
428
499
|
),
|
|
429
|
-
h('
|
|
430
|
-
h('
|
|
500
|
+
h('div', { className: 'msx-row' },
|
|
501
|
+
h('div', null,
|
|
502
|
+
h('div', { className: 'msx-label' }, '系统通知'),
|
|
503
|
+
h('div', { className: 'msx-sub' }, '仅失败/待确认'),
|
|
504
|
+
),
|
|
505
|
+
h('label', { style: { display: 'flex', alignItems: 'center' } },
|
|
506
|
+
h('input', { type: 'checkbox', checked: notifyOn, disabled: busy, 'aria-label': '系统通知', onChange: (e) => void write('notifyEnabled', e.target.checked) }),
|
|
507
|
+
),
|
|
431
508
|
),
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
509
|
+
h('div', { className: 'msx-row' },
|
|
510
|
+
h('div', null,
|
|
511
|
+
h('div', { className: 'msx-label' }, '每日汇总'),
|
|
512
|
+
h('div', { className: 'msx-sub' }, '9:00 后一条摘要'),
|
|
513
|
+
),
|
|
514
|
+
h('label', { style: { display: 'flex', alignItems: 'center' } },
|
|
515
|
+
h('input', { type: 'checkbox', checked: digestOn, disabled: busy, 'aria-label': '每日汇总', onChange: (e) => void write('digestEnabled', e.target.checked) }),
|
|
516
|
+
),
|
|
437
517
|
),
|
|
438
|
-
h('
|
|
439
|
-
h('
|
|
518
|
+
h('div', { className: 'msx-row' },
|
|
519
|
+
h('button', { className: 'msx-linkbtn', disabled: busy, 'aria-label': '导出脱敏诊断信息', onClick: () => void write('exportDiagnostics', true) }, '导出诊断'),
|
|
440
520
|
),
|
|
441
|
-
),
|
|
521
|
+
) : null,
|
|
442
522
|
),
|
|
443
523
|
),
|
|
444
524
|
|
|
445
|
-
h('div', {
|
|
446
|
-
h('button', { className: 'msx-linkbtn', disabled: busy, onClick: () => void write('exportDiagnostics', true) }, '导出诊断(不含 token)'),
|
|
447
|
-
),
|
|
448
|
-
h('div', { className: 'msx-muted' }, '同步有新增时会先出「检测到新会话」确认卡;点「立即安装」才重启。成功且无新增不弹系统通知;自动巡检只更新报告,不打扰。'),
|
|
525
|
+
h('div', { className: 'msx-muted' }, '免费 · 本地摘要 · 无遥测'),
|
|
449
526
|
);
|
|
450
527
|
}
|
|
451
528
|
|
|
@@ -458,7 +535,13 @@ window.__ModuleLoader__.load({
|
|
|
458
535
|
id: 'chat-history-sync',
|
|
459
536
|
order: 16,
|
|
460
537
|
label: '聊天历史同步',
|
|
461
|
-
},
|
|
538
|
+
}, CardSafe));
|
|
539
|
+
ctx.slots.inject('sidebar.footer.action', () => ctx.slots.register({
|
|
540
|
+
name: 'sidebar.footer.action',
|
|
541
|
+
id: 'chat-history-sync',
|
|
542
|
+
order: 27,
|
|
543
|
+
label: () => '同步聊天历史',
|
|
544
|
+
}, FooterSafe));
|
|
462
545
|
},
|
|
463
546
|
};
|
|
464
547
|
},
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// 登录新账号:连接本次启动的临时 Edge(CDP 端口由宿主传入),
|
|
2
|
+
// 清掉任何残留登录状态 → 打开登录页 → 等用户登录并校验 userId → 写结果 JSON。
|
|
3
|
+
// 结果只写文件(不打印 token);结束后自动关闭这个临时浏览器。
|
|
4
|
+
// 用法:node login-save.mjs <result.json> <known-tokens.json> [port]
|
|
5
|
+
import puppeteer from 'puppeteer-core';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import crypto from 'node:crypto';
|
|
8
|
+
|
|
9
|
+
const outPath = process.argv[2];
|
|
10
|
+
const knownPath = process.argv[3];
|
|
11
|
+
const port = String(process.argv[4] || '9222');
|
|
12
|
+
const write = (o) => { try { fs.writeFileSync(outPath, JSON.stringify({ ...o, at: Date.now() })); } catch (e) {} };
|
|
13
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
14
|
+
|
|
15
|
+
if (!outPath) { console.error('usage: login-save.mjs <result.json> <known-tokens.json> [port]'); process.exit(2); }
|
|
16
|
+
let known = [];
|
|
17
|
+
try { known = JSON.parse(fs.readFileSync(knownPath, 'utf8')); } catch (e) { known = []; }
|
|
18
|
+
const knownSet = new Set((known || []).filter(Boolean));
|
|
19
|
+
|
|
20
|
+
const parseToken = (raw) => {
|
|
21
|
+
if (!raw) return '';
|
|
22
|
+
try {
|
|
23
|
+
const p = JSON.parse(raw);
|
|
24
|
+
if (p && typeof p === 'object') return typeof p.value === 'string' ? p.value : '';
|
|
25
|
+
} catch (e) { /* 不是 JSON,按原始字符串处理 */ }
|
|
26
|
+
return typeof raw === 'string' ? raw.replace(/^"|"$/g, '') : '';
|
|
27
|
+
};
|
|
28
|
+
const validToken = (t) => !!t && t.length >= 30 && !/[{}\s"]/.test(t);
|
|
29
|
+
|
|
30
|
+
let browser = null;
|
|
31
|
+
let failed = [], consoleErrors = [], pageState = {};
|
|
32
|
+
const finish = async (obj, code) => {
|
|
33
|
+
write(obj);
|
|
34
|
+
try { if (browser) await browser.close(); } catch (e) {}
|
|
35
|
+
process.exit(code);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
for (let i = 0; i < 20 && !browser; i += 1) {
|
|
40
|
+
try { browser = await puppeteer.connect({ browserURL: 'http://127.0.0.1:' + port, defaultViewport: null }); }
|
|
41
|
+
catch (e) { await sleep(1000); }
|
|
42
|
+
}
|
|
43
|
+
if (!browser) throw new Error('无法连接浏览器(CDP ' + port + ' 未就绪)');
|
|
44
|
+
|
|
45
|
+
const pages = (await browser.pages()).filter((p) => !p.isClosed());
|
|
46
|
+
const page = pages.find((p) => p.url() === 'about:blank') || pages[0] || (await browser.newPage());
|
|
47
|
+
failed = [];
|
|
48
|
+
consoleErrors = [];
|
|
49
|
+
page.on('requestfailed', (r) => {
|
|
50
|
+
try { failed.push({ url: r.url().slice(0, 240), err: r.failure() && r.failure().errorText }); } catch (e) {}
|
|
51
|
+
});
|
|
52
|
+
page.on('console', (m) => {
|
|
53
|
+
try { if (m.type() === 'error') consoleErrors.push(m.text().slice(0, 240)); } catch (e) {}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// 新临时配置本来就是干净状态;不要再清 cookie(会破坏 Cloudflare/Turnstile 的挑战态)
|
|
57
|
+
await page.goto('https://chat.deepseek.com/sign_in', { waitUntil: 'domcontentloaded', timeout: 60000 }).catch(() => {});
|
|
58
|
+
await sleep(2500);
|
|
59
|
+
pageState = await page.evaluate(() => ({
|
|
60
|
+
url: location.href,
|
|
61
|
+
title: document.title,
|
|
62
|
+
hasPhone: !!document.querySelector('input[type="tel"], input[placeholder*="手机"], input[placeholder*="验证码"]'),
|
|
63
|
+
body: (document.body && document.body.innerText || '').slice(0, 300),
|
|
64
|
+
})).catch(() => ({}));
|
|
65
|
+
write({ ok: false, status: 'waiting', page: pageState, failed: failed.slice(-10), console: consoleErrors.slice(-10) });
|
|
66
|
+
|
|
67
|
+
for (let i = 0; i < 300; i += 1) {
|
|
68
|
+
if (page.isClosed()) await finish({ ok: false, status: 'cancelled', error: '浏览器页面已关闭,未保存', failed: failed.slice(-10), console: consoleErrors.slice(-10) }, 1);
|
|
69
|
+
const raw = await page.evaluate(() => {
|
|
70
|
+
try { return localStorage.getItem('userToken') || ''; } catch (e) { return ''; }
|
|
71
|
+
}).catch(() => '');
|
|
72
|
+
const tok = parseToken(raw);
|
|
73
|
+
if (validToken(tok) && !knownSet.has(crypto.createHash('sha256').update(tok).digest('hex'))) {
|
|
74
|
+
const info = await page.evaluate(async (token) => {
|
|
75
|
+
const h = {
|
|
76
|
+
accept: '*/*', authorization: 'Bearer ' + token,
|
|
77
|
+
'x-client-bundle-id': 'com.deepseek.chat', 'x-client-locale': 'zh_CN',
|
|
78
|
+
'x-client-platform': 'web', 'x-client-timezone-offset': String(-new Date().getTimezoneOffset() * 60),
|
|
79
|
+
'x-client-version': '2.7.1',
|
|
80
|
+
};
|
|
81
|
+
try {
|
|
82
|
+
const r = await fetch('/api/v0/users/current', { headers: h, credentials: 'include' });
|
|
83
|
+
const me = await r.json();
|
|
84
|
+
const b = (me.data && (me.data.biz_data || me.data)) || {};
|
|
85
|
+
let ui = {};
|
|
86
|
+
try { ui = JSON.parse(localStorage.getItem('userInfo') || '{}') || {}; } catch (e) { ui = {}; }
|
|
87
|
+
return {
|
|
88
|
+
userId: b.id || b.user_id || '',
|
|
89
|
+
phone: b.mobile_number || '',
|
|
90
|
+
email: b.email || '',
|
|
91
|
+
nickname: ui.name || ui.nickname || ui.user_name || ui.userName || ui.nickName || '',
|
|
92
|
+
avatarUrl: ui.avatar || ui.avatar_url || ui.avatarUrl || ui.head_url || ui.headUrl || '',
|
|
93
|
+
};
|
|
94
|
+
} catch (e) { return { userId: '', phone: '', email: '', nickname: '', avatarUrl: '' }; }
|
|
95
|
+
}, tok).catch(() => ({ userId: '', phone: '', email: '', nickname: '', avatarUrl: '' }));
|
|
96
|
+
if (info.userId) {
|
|
97
|
+
await finish({ ok: true, token: tok, userId: info.userId, phone: info.phone || '', email: info.email || '', nickname: info.nickname || '', avatarUrl: info.avatarUrl || '' }, 0);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
await sleep(2000);
|
|
101
|
+
}
|
|
102
|
+
await finish({ ok: false, status: 'timeout', error: '登录超时(10 分钟),未保存', failed: failed.slice(-10), console: consoleErrors.slice(-10), page: pageState }, 1);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
await finish({ ok: false, status: 'error', error: String((e && e.message) || e).slice(0, 200), failed: failed.slice(-10), console: consoleErrors.slice(-10) }, 1);
|
|
105
|
+
}
|