dsh-deepseek-account-import 0.1.1 → 0.1.2
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 +53 -0
- package/bin/cli.mjs +57 -3
- package/docs/agent-quickstart.md +58 -0
- package/lib/auth.mjs +100 -47
- package/lib/cdp.mjs +107 -0
- package/lib/index.mjs +4 -0
- package/lib/launch.mjs +135 -0
- package/lib/skill.mjs +58 -0
- package/package.json +1 -1
- package/skill/SKILL.md +15 -1
package/README.md
CHANGED
|
@@ -84,6 +84,57 @@ node test/convert.test.mjs # 转换:分支裁剪、新旧格式、思维链
|
|
|
84
84
|
node test/migrate.test.mjs # 编排:幂等、force、min-turns、limit
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
+
## 浏览器与登录态
|
|
88
|
+
|
|
89
|
+
登录态获取是**自动逐级尝试**的,不需要用户选:
|
|
90
|
+
|
|
91
|
+
1. `~/.dsh/dsh-deepseek-import/auth.json`(上一次保存的凭证)
|
|
92
|
+
2. **自动发现**本机所有 Chromium 系浏览器的 localStorage(不写死厂商路径)
|
|
93
|
+
3. **CDP**:浏览器如果正用 `--remote-debugging-port=9222` 启动着,直接连上去读
|
|
94
|
+
4. `--token-file <path>` 指定的文件(裸 token 或 `{"token":"..."}`)
|
|
95
|
+
5. Playwright 弹窗登录(最后手段,需要装 playwright)
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
ds-migrate browsers # 列出自动发现了哪些浏览器 profile、哪个有登录态
|
|
99
|
+
ds-migrate token --cdp 9222 # 从调试端口取
|
|
100
|
+
ds-migrate token --file ./tok # 从文件取
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 浏览器兼容性
|
|
104
|
+
|
|
105
|
+
| 浏览器 | 自动读取 localStorage | CDP 注入 | Playwright 弹窗 |
|
|
106
|
+
|---|---|---|---|
|
|
107
|
+
| Chrome / Edge / Chromium | ✅ 自动发现 | ✅ 最可靠 | ✅(channel) |
|
|
108
|
+
| 360 安全/极速、QQ、搜狗、夸克、UC、2345 等 Chromium 内核 | ⚠️ 能发现 profile,但见下方说明 | ⚠️ 需「极速模式」+ 手动加启动参数 | ❌ 不是官方 channel |
|
|
109
|
+
| IE 内核 / 兼容模式 | ❌ 不适用 | ❌ | ❌ |
|
|
110
|
+
|
|
111
|
+
**为什么「读 localStorage」只算 ⚠️**:Chrome 的 `.ldb` 是 Snappy 压缩块,`userToken` 若已被压实,明文扫描读不到。
|
|
112
|
+
实测 Windows Chrome 上就踩过这个坑——能读到别的站点同名 key(比如 qwen.ai 的 `userToken`),却读不到 deepseek 的。
|
|
113
|
+
所以**可靠顺序是 CDP > 弹窗登录 > 读 LevelDB**,后者只在 WAL 还没压实时有效。
|
|
114
|
+
|
|
115
|
+
**国产浏览器怎么用 CDP**:它们都是 Chromium 内核,但要用「极速模式」而不是「兼容模式」,并且手动带上调试参数启动,例如
|
|
116
|
+
|
|
117
|
+
```bat
|
|
118
|
+
"C:\Program Files (x86)\360\360se6\Application\360se.exe" --remote-debugging-port=9222
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
起来后在那个窗口里登录 `chat.deepseek.com`,再执行 `ds-migrate token --cdp 9222`。
|
|
122
|
+
|
|
123
|
+
### 这个 skill 怎么分发
|
|
124
|
+
|
|
125
|
+
`skill/SKILL.md` 由插件在运行时通过 `ctx.skills.register()` 注册([lib/skill.mjs](lib/skill.mjs)),
|
|
126
|
+
所以 **`npm i` 装上插件就自动拥有该技能**,用户不需要手工往 `~/.dsh/skills` 拷文件。
|
|
127
|
+
宿主没有 `skills` 服务时(headless/精简 profile)会自动跳过,命令与工具照常可用。
|
|
128
|
+
|
|
129
|
+
## 一句话调用
|
|
130
|
+
|
|
131
|
+
用户只需要说:
|
|
132
|
+
|
|
133
|
+
> **把我 DeepSeek 里的对话都迁到 dsh**
|
|
134
|
+
|
|
135
|
+
Agent 侧就三步:`deepseek_migrate({action:"status"})` → `login`(自动拉起浏览器,扫码一次)→ `run`。
|
|
136
|
+
给集成方看的完整说明(含可直接粘进系统提示的片段)在 [docs/agent-quickstart.md](docs/agent-quickstart.md)。
|
|
137
|
+
|
|
87
138
|
## 安全与隐私
|
|
88
139
|
|
|
89
140
|
- 数据全部留在本机,没有任何服务器:[PRIVACY.md](PRIVACY.md)
|
|
@@ -105,6 +156,8 @@ node test/convert.test.mjs # 分支裁剪 / 新旧格式 / 思维链 / 图
|
|
|
105
156
|
node test/migrate.test.mjs # 幂等 / force / min-turns / limit
|
|
106
157
|
node test/api.test.mjs # 附件下载 URL(ty=p / ty=r / HTML 丢弃)
|
|
107
158
|
node test/import-compat.test.mjs # 喂给真 dsh-chat-import 解析器(未装则 SKIP)
|
|
159
|
+
node test/cdp.test.mjs # CDP 目标挑选与 token 解析
|
|
160
|
+
node test/skill.test.mjs # 运行时 skill 注册形状
|
|
108
161
|
```
|
|
109
162
|
|
|
110
163
|
## License
|
package/bin/cli.mjs
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
import { mkdir, readdir, stat, writeFile } from 'node:fs/promises'
|
|
11
11
|
import { join, resolve } from 'node:path'
|
|
12
12
|
import { DeepSeekApi } from '../lib/api.mjs'
|
|
13
|
-
import { loginInteractively, resolveStoredToken, resolveToken } from '../lib/auth.mjs'
|
|
13
|
+
import { browserRoots, findLevelDbDirs, loginInteractively, readTokenFromLevelDb, resolveStoredToken, resolveToken, writeAuthFile } from '../lib/auth.mjs'
|
|
14
|
+
import { readTokenFromFile, readTokenViaCdp } from '../lib/cdp.mjs'
|
|
14
15
|
import { migrateAccount } from '../lib/migrate.mjs'
|
|
15
16
|
import { OUT_DIR, STATE_PATH, loadState, saveState } from '../lib/state.mjs'
|
|
16
17
|
|
|
@@ -27,8 +28,15 @@ function flag(name, fallback) {
|
|
|
27
28
|
|
|
28
29
|
const log = (message) => process.stdout.write(`${message}\n`)
|
|
29
30
|
|
|
31
|
+
const cdpPort = flag('cdp', undefined)
|
|
32
|
+
const tokenFile = flag('token-file', undefined)
|
|
33
|
+
|
|
30
34
|
async function buildApi() {
|
|
31
|
-
const resolved = await resolveToken({
|
|
35
|
+
const resolved = await resolveToken({
|
|
36
|
+
log,
|
|
37
|
+
cdpPort: Number(cdpPort) || undefined,
|
|
38
|
+
tokenFile: typeof tokenFile === 'string' ? tokenFile : undefined,
|
|
39
|
+
})
|
|
32
40
|
return { api: new DeepSeekApi({ token: resolved.token, log }), resolved }
|
|
33
41
|
}
|
|
34
42
|
|
|
@@ -49,7 +57,18 @@ async function main() {
|
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
if (command === 'login') {
|
|
52
|
-
|
|
60
|
+
// 默认走「自动拉起浏览器 + CDP」,失败再退回 Playwright
|
|
61
|
+
if (cdpPort !== undefined || argv.includes('--cdp')) {
|
|
62
|
+
const { loginViaLaunchedBrowser } = await import('../lib/launch.mjs')
|
|
63
|
+
const port = Number(cdpPort) || 9222
|
|
64
|
+
const hit = await loginViaLaunchedBrowser({ port, log })
|
|
65
|
+
if (!hit) return 1
|
|
66
|
+
await writeAuthFile({ token: hit.token, savedAt: Date.now(), source: hit.source })
|
|
67
|
+
log(`登录成功(${hit.source})`)
|
|
68
|
+
return 0
|
|
69
|
+
}
|
|
70
|
+
const resolved = await resolveToken({ log, cdpPort: Number(cdpPort) || undefined, tokenFile: typeof tokenFile === 'string' ? tokenFile : undefined })
|
|
71
|
+
log(`登录态已就绪(来源:${resolved.source})`)
|
|
53
72
|
return 0
|
|
54
73
|
}
|
|
55
74
|
|
|
@@ -80,6 +99,41 @@ async function main() {
|
|
|
80
99
|
return 0
|
|
81
100
|
}
|
|
82
101
|
|
|
102
|
+
if (command === 'browsers') {
|
|
103
|
+
const roots = await browserRoots()
|
|
104
|
+
const dirs = await findLevelDbDirs()
|
|
105
|
+
log(`发现 ${roots.length} 个浏览器数据根、${dirs.length} 个 profile:`)
|
|
106
|
+
for (const entry of dirs) {
|
|
107
|
+
const token = await readTokenFromLevelDb(entry.dir)
|
|
108
|
+
log(` ${token ? '有登录态' : ' — '} ${entry.browser} / ${entry.profile} ${entry.dir}`)
|
|
109
|
+
}
|
|
110
|
+
if (!dirs.length) log(' 没找到任何 profile(浏览器可能装在非标准位置)')
|
|
111
|
+
log('\n如果这里没有你的浏览器(例如国产 Chromium 内核浏览器),改用 CDP:')
|
|
112
|
+
log(' 用 --remote-debugging-port=9222 启动浏览器后跑 ds-migrate token --cdp 9222')
|
|
113
|
+
return 0
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (command === 'token') {
|
|
117
|
+
const manual = typeof tokenFile === 'string' ? await readTokenFromFile(tokenFile) : ''
|
|
118
|
+
if (manual) {
|
|
119
|
+
await writeAuthFile({ token: manual, savedAt: Date.now(), source: 'token-file' })
|
|
120
|
+
log('已从文件导入 token')
|
|
121
|
+
return 0
|
|
122
|
+
}
|
|
123
|
+
const port = Number(cdpPort) || 9222
|
|
124
|
+
const viaCdp = await readTokenViaCdp({ port })
|
|
125
|
+
if (viaCdp) {
|
|
126
|
+
await writeAuthFile({ token: viaCdp.token, savedAt: Date.now(), source: viaCdp.source })
|
|
127
|
+
log(`已从 CDP 端口 ${port} 读取并保存登录态(${viaCdp.source})`)
|
|
128
|
+
return 0
|
|
129
|
+
}
|
|
130
|
+
log(`两种方式都没拿到 token。用法:
|
|
131
|
+
ds-migrate token --file /path/to/token.txt 从文件读(裸 token 或 {"token":"..."})
|
|
132
|
+
ds-migrate token --cdp 9222 从浏览器调试端口读
|
|
133
|
+
先用 --remote-debugging-port=9222 启动浏览器,并在里面登录 chat.deepseek.com。`)
|
|
134
|
+
return 1
|
|
135
|
+
}
|
|
136
|
+
|
|
83
137
|
if (command === 'list') {
|
|
84
138
|
const { api } = await buildApi()
|
|
85
139
|
const sessions = await api.listSessions({ onPage: ({ total }) => log(` 已取 ${total} 条…`) })
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# 一句话迁移 · Agent 调用说明
|
|
2
|
+
|
|
3
|
+
这份文档给**别的 agent / 集成方**看:怎么用最少的话把「DeepSeek 全账号对话搬到 dsh」跑起来。
|
|
4
|
+
|
|
5
|
+
## 1. 用户只需要说一句话
|
|
6
|
+
|
|
7
|
+
任选其一(触发词都在插件的 skill 描述里覆盖了):
|
|
8
|
+
|
|
9
|
+
- **把我 DeepSeek 里的对话都迁到 dsh**
|
|
10
|
+
- 把以前在 DeepSeek 的聊天搬到 dsh
|
|
11
|
+
- DeepSeek 那边限额了,帮我整体迁到 dsh
|
|
12
|
+
- import my DeepSeek history into DSH
|
|
13
|
+
|
|
14
|
+
## 2. Agent 内部就三步
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
// ① 看状态(只读,无副作用)
|
|
18
|
+
deepseek_migrate({ action: "status" })
|
|
19
|
+
|
|
20
|
+
// ② 没登录态时触发登录:会自动拉起一个 Chromium 内核浏览器,
|
|
21
|
+
// 用户在窗口里扫码/手机号登录一次,检测到 token 后自动继续
|
|
22
|
+
deepseek_migrate({ action: "login" })
|
|
23
|
+
|
|
24
|
+
// ③ 预览 + 执行(run 内含拉取、转换、导入)
|
|
25
|
+
deepseek_migrate({ action: "preview" })
|
|
26
|
+
deepseek_migrate({ action: "run" })
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
可选参数:`minTurns`(跳过太短的会话)、`since`(只迁这段时间之后的)、`limit`(分批)、
|
|
30
|
+
`force`(重做已迁移的)、`downloadFiles: false`(不要图片)。
|
|
31
|
+
|
|
32
|
+
## 3. 可以直接粘进系统提示的片段
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
用户要把 DeepSeek 账号里的历史对话整体迁移到 DSH 时,调用 deepseek_migrate 工具:
|
|
36
|
+
先 action:"status" 看登录态,没有就 action:"login"(会弹出浏览器让用户扫码,这是唯一需要人工的一步),
|
|
37
|
+
然后用 action:"run" 执行;超过 300 条时用 limit 分批。
|
|
38
|
+
不要自己写脚本抓 DeepSeek 接口,也不要索取用户的 token 或 cookie。
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 4. CLI 等价写法
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
ds-migrate status # 或 whoami
|
|
45
|
+
ds-migrate login # 自动拉起浏览器 + CDP,失败退回 Playwright
|
|
46
|
+
ds-migrate preview
|
|
47
|
+
ds-migrate run --limit 100
|
|
48
|
+
ds-migrate browsers # 看看自动发现了哪些浏览器 profile
|
|
49
|
+
ds-migrate token --cdp 9222 # 浏览器已带调试端口启动时直接取
|
|
50
|
+
ds-migrate token --file ./tok # 手动提供 token
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 5. 边界(别对外承诺过头)
|
|
54
|
+
|
|
55
|
+
- 首次登录**必须**有人扫一次码,物理上无法省。
|
|
56
|
+
- 手机(dsh-go)可以用,走「遥控电脑」模式;**手机本机模式不能迁移**(跑不了浏览器)。
|
|
57
|
+
- 图片是**原图 base64**,不是缩略图;单文件 >20MB 或单次总量 >200MB 会降级成文本占位。
|
|
58
|
+
- 数据只在本机处理,不经过任何服务器;但调用的是 DeepSeek 未公开接口,属灰色地带。
|
package/lib/auth.mjs
CHANGED
|
@@ -52,66 +52,85 @@ export async function writeAuthFile(payload, path = AUTH_PATH) {
|
|
|
52
52
|
await writeFile(path, JSON.stringify(payload, null, 2), 'utf8')
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
{ name: 'Chrome', root: join(home, '.config', 'google-chrome') },
|
|
60
|
-
{ name: 'Chromium', root: join(home, '.config', 'chromium') },
|
|
61
|
-
{ name: 'Edge', root: join(home, '.config', 'microsoft-edge') },
|
|
62
|
-
]
|
|
63
|
-
}
|
|
55
|
+
/** 浏览器目录名的启发式清单:覆盖 Chrome/Edge/Chromium 与常见国产 Chromium 内核浏览器。 */
|
|
56
|
+
const BROWSER_DIR_HINT = /(chrome|chromium|edge|brave|vivaldi|opera|yandex|360|qq|tencent|sogou|quark|uc|liebao|2345|maxthon|browser)/i
|
|
57
|
+
/** 厂商目录(Windows 上浏览器普遍是 <厂商>/<产品>/User Data 两层)。 */
|
|
58
|
+
const VENDOR_DIR_HINT = /(google|microsoft|tencent|360|sogou|quark|uc|liebao|2345|maxthon|mozilla|brave|vivaldi|opera|yandex|alibaba)/i
|
|
64
59
|
|
|
65
|
-
|
|
60
|
+
/** 各平台上可能藏浏览器用户数据的基目录。 */
|
|
61
|
+
async function browserBases() {
|
|
66
62
|
const home = homedir()
|
|
63
|
+
const bases = []
|
|
67
64
|
const os = platform()
|
|
68
|
-
if (os === 'linux') return [...(await linuxBrowserRoots()), ...(await windowsBrowserRoots())]
|
|
69
65
|
if (os === 'win32') {
|
|
70
66
|
const local = process.env.LOCALAPPDATA || join(home, 'AppData', 'Local')
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
const roaming = process.env.APPDATA || join(home, 'AppData', 'Roaming')
|
|
68
|
+
bases.push(local, roaming)
|
|
69
|
+
} else if (os === 'darwin') {
|
|
70
|
+
bases.push(join(home, 'Library', 'Application Support'))
|
|
71
|
+
} else {
|
|
72
|
+
bases.push(join(home, '.config'))
|
|
73
|
+
// WSL:把 Windows 侧用户目录也加进来(浏览器多半跑在 Windows 上)
|
|
74
|
+
let users = []
|
|
75
|
+
try { users = await readdir('/mnt/c/Users', { withFileTypes: true }) } catch { users = [] }
|
|
76
|
+
for (const user of users) {
|
|
77
|
+
// 9p/网络盘上 dirent 类型可能不可靠,这里只按名字过滤
|
|
78
|
+
if (['All Users', 'Default', 'Default User', 'Public', 'desktop.ini'].includes(user.name)) continue
|
|
79
|
+
bases.push(join('/mnt/c/Users', user.name, 'AppData', 'Local'))
|
|
80
|
+
bases.push(join('/mnt/c/Users', user.name, 'AppData', 'Roaming'))
|
|
81
|
+
}
|
|
81
82
|
}
|
|
82
|
-
return
|
|
83
|
-
{ name: 'Chrome', root: join(home, '.config', 'google-chrome') },
|
|
84
|
-
{ name: 'Chromium', root: join(home, '.config', 'chromium') },
|
|
85
|
-
{ name: 'Edge', root: join(home, '.config', 'microsoft-edge') },
|
|
86
|
-
]
|
|
83
|
+
return bases
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
86
|
+
/**
|
|
87
|
+
* 自动发现浏览器用户数据根(不写死厂商路径)。
|
|
88
|
+
* 规则:在某基目录下找名字像浏览器的子目录,再看它自己或它的 User Data 子目录里有没有
|
|
89
|
+
* `Local Storage/leveldb`。这样 Chrome、Edge、360、QQ、搜狗、夸克……都能被认出来。
|
|
90
|
+
*/
|
|
91
|
+
export async function browserRoots() {
|
|
92
|
+
const roots = []
|
|
93
|
+
const seen = new Set()
|
|
94
|
+
const push = (name, root) => {
|
|
95
|
+
if (seen.has(root)) return
|
|
96
|
+
seen.add(root)
|
|
97
|
+
roots.push({ name, root })
|
|
98
|
+
}
|
|
99
|
+
for (const base of await browserBases()) {
|
|
100
|
+
let entries = []
|
|
101
|
+
try { entries = await readdir(base, { withFileTypes: true }) } catch { continue }
|
|
102
|
+
const probe = async (name, dir) => {
|
|
103
|
+
// 根目录本身是 profile(含 Local Storage/leveldb),或者根目录下还有 Default / Profile N
|
|
104
|
+
for (const candidate of [join(dir, 'User Data'), dir]) {
|
|
105
|
+
if (await exists(join(candidate, 'Local Storage', 'leveldb'))) { push(name, candidate); return true }
|
|
106
|
+
if (await exists(join(candidate, 'Default', 'Local Storage', 'leveldb'))) { push(name, candidate); return true }
|
|
107
|
+
}
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
// 第一层可能是产品名(Chrome)也可能是厂商名(Google / Tencent / 360)
|
|
112
|
+
if (!BROWSER_DIR_HINT.test(entry.name) && !VENDOR_DIR_HINT.test(entry.name)) continue
|
|
113
|
+
const dir = join(base, entry.name)
|
|
114
|
+
if (await probe(entry.name, dir)) continue
|
|
115
|
+
// 再看一层:<厂商>/<产品>/User Data(Chrome、Edge、QQ浏览器等都是这个形状)
|
|
116
|
+
if (!VENDOR_DIR_HINT.test(entry.name)) continue
|
|
117
|
+
let children = []
|
|
118
|
+
try { children = await readdir(dir, { withFileTypes: true }) } catch { continue }
|
|
119
|
+
for (const child of children) {
|
|
120
|
+
if (!BROWSER_DIR_HINT.test(child.name)) continue
|
|
121
|
+
await probe(child.name, join(dir, child.name))
|
|
122
|
+
}
|
|
105
123
|
}
|
|
106
124
|
}
|
|
107
|
-
return
|
|
125
|
+
return roots
|
|
108
126
|
}
|
|
109
127
|
|
|
110
|
-
/** 列出所有 profile 的 localStorage LevelDB 目录(Default / Profile N
|
|
128
|
+
/** 列出所有 profile 的 localStorage LevelDB 目录(Default / Profile N / 根目录自身)。 */
|
|
111
129
|
export async function findLevelDbDirs() {
|
|
112
130
|
const found = []
|
|
113
131
|
for (const { name, root } of await browserRoots()) {
|
|
114
|
-
|
|
132
|
+
const direct = join(root, 'Local Storage', 'leveldb')
|
|
133
|
+
if (await exists(direct)) found.push({ browser: name, profile: '(root)', dir: direct })
|
|
115
134
|
let entries = []
|
|
116
135
|
try { entries = await readdir(root, { withFileTypes: true }) } catch { continue }
|
|
117
136
|
for (const entry of entries) {
|
|
@@ -295,10 +314,44 @@ export async function loginInteractively({ log = () => {}, timeoutMs = 5 * 60 *
|
|
|
295
314
|
}
|
|
296
315
|
}
|
|
297
316
|
|
|
298
|
-
/**
|
|
299
|
-
export async function resolveToken({ log = () => {}, interactive = true } = {}) {
|
|
317
|
+
/** 把全部备略串起来:凭证文件 → 浏览器存储 → CDP 调试端口 → token 文件 → 弹窗登录。 */
|
|
318
|
+
export async function resolveToken({ log = () => {}, interactive = true, cdpPort, tokenFile } = {}) {
|
|
300
319
|
const stored = await resolveStoredToken({ log })
|
|
301
320
|
if (stored) return stored
|
|
321
|
+
|
|
322
|
+
// 浏览器已经用 --remote-debugging-port 起着的场景(含国产 Chromium 内核浏览器)
|
|
323
|
+
const { readTokenViaCdp, readTokenFromFile } = await import('./cdp.mjs')
|
|
324
|
+
const viaCdp = await readTokenViaCdp({ port: cdpPort || 9222 })
|
|
325
|
+
if (viaCdp) {
|
|
326
|
+
await writeAuthFile({ token: viaCdp.token, savedAt: Date.now(), source: viaCdp.source })
|
|
327
|
+
log(`从 CDP 调试端口读到登录态(${viaCdp.source})`)
|
|
328
|
+
return viaCdp
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (tokenFile) {
|
|
332
|
+
const manual = await readTokenFromFile(tokenFile)
|
|
333
|
+
if (manual) {
|
|
334
|
+
await writeAuthFile({ token: manual, savedAt: Date.now(), source: 'token-file' })
|
|
335
|
+
return { token: manual, source: 'token-file' }
|
|
336
|
+
}
|
|
337
|
+
log(`指定的 token 文件读不出内容:${tokenFile}`)
|
|
338
|
+
}
|
|
339
|
+
|
|
302
340
|
if (!interactive) throw new Error('没有本地凭证,且禁用了交互式登录')
|
|
341
|
+
|
|
342
|
+
// 自动拉起一个带调试端口的 Chromium 内核浏览器(Chrome/Edge/360/QQ…),用户只需登录一次。
|
|
343
|
+
try {
|
|
344
|
+
const { loginViaLaunchedBrowser } = await import('./launch.mjs')
|
|
345
|
+
const port = Number(cdpPort) || 9222
|
|
346
|
+
const launched = await loginViaLaunchedBrowser({ port, log })
|
|
347
|
+
if (launched) {
|
|
348
|
+
await writeAuthFile({ token: launched.token, savedAt: Date.now(), source: launched.source })
|
|
349
|
+
return launched
|
|
350
|
+
}
|
|
351
|
+
} catch (error) {
|
|
352
|
+
log('自动拉起浏览器失败:' + String((error && error.message) || error))
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
log('退回 Playwright 弹窗登录…')
|
|
303
356
|
return loginInteractively({ log })
|
|
304
357
|
}
|
package/lib/cdp.mjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// lib/cdp.mjs — 通过 Chrome DevTools Protocol 读 localStorage.userToken。
|
|
2
|
+
//
|
|
3
|
+
// 不依赖 Playwright:Node 22 自带 fetch 与 WebSocket。只要目标浏览器用
|
|
4
|
+
// --remote-debugging-port 启动(Chrome / Edge / Chromium,以及 360、QQ、
|
|
5
|
+
// 搜狗等 Chromium 内核的国产浏览器在「极速模式」下的调试端口),就能连上。
|
|
6
|
+
// 这比读 LevelDB 可靠:不受 Snappy 压缩影响,也不关心 profile 存在哪。
|
|
7
|
+
|
|
8
|
+
const DEFAULT_PORT = 9222
|
|
9
|
+
|
|
10
|
+
/** 从 /json 列表里挑出 chat.deepseek.com 的页面目标(纯函数,便于测试)。 */
|
|
11
|
+
export function pickDeepseekTarget(targets) {
|
|
12
|
+
if (!Array.isArray(targets)) return null
|
|
13
|
+
return (
|
|
14
|
+
targets.find((t) => t && t.type === 'page' && /chat\.deepseek\.com/i.test(String(t.url || ''))) ||
|
|
15
|
+
targets.find((t) => t && t.type === 'page' && /deepseek\.com/i.test(String(t.url || ''))) ||
|
|
16
|
+
null
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** 从 Runtime.evaluate 的响应文本里挖 token(纯函数,便于测试)。 */
|
|
21
|
+
export function extractTokenFromCdpResponse(text) {
|
|
22
|
+
let message
|
|
23
|
+
try {
|
|
24
|
+
message = JSON.parse(String(text))
|
|
25
|
+
} catch {
|
|
26
|
+
return ''
|
|
27
|
+
}
|
|
28
|
+
const value = message && message.result && message.result.result && message.result.result.value
|
|
29
|
+
if (typeof value !== 'string' || !value) return ''
|
|
30
|
+
// 页面返回的可能是 localStorage 的原始 JSON:{"value":"<token>"}
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(value)
|
|
33
|
+
if (parsed && typeof parsed.value === 'string' && parsed.value) return parsed.value
|
|
34
|
+
} catch { /* 不是 JSON,按裸 token 处理 */ }
|
|
35
|
+
return value.trim()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function fetchJson(url, timeoutMs) {
|
|
39
|
+
const controller = new AbortController()
|
|
40
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs)
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetch(url, { signal: controller.signal })
|
|
43
|
+
if (!response.ok) return null
|
|
44
|
+
return await response.json()
|
|
45
|
+
} catch {
|
|
46
|
+
return null
|
|
47
|
+
} finally {
|
|
48
|
+
clearTimeout(timer)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 连上调试端口,读 chat.deepseek.com 页面的 userToken。
|
|
54
|
+
* 返回 { token, source } 或 ''。
|
|
55
|
+
*/
|
|
56
|
+
export async function readTokenViaCdp({ port = DEFAULT_PORT, host = '127.0.0.1', timeoutMs = 5000 } = {}) {
|
|
57
|
+
const base = `http://${host}:${port}`
|
|
58
|
+
const version = await fetchJson(`${base}/json/version`, timeoutMs)
|
|
59
|
+
if (!version) return ''
|
|
60
|
+
const targets = await fetchJson(`${base}/json`, timeoutMs)
|
|
61
|
+
const target = pickDeepseekTarget(targets)
|
|
62
|
+
if (!target || !target.webSocketDebuggerUrl) return ''
|
|
63
|
+
const socket = new WebSocket(target.webSocketDebuggerUrl)
|
|
64
|
+
try {
|
|
65
|
+
await new Promise((resolve, reject) => {
|
|
66
|
+
socket.addEventListener('open', resolve, { once: true })
|
|
67
|
+
socket.addEventListener('error', () => reject(new Error('CDP WebSocket 连接失败')), { once: true })
|
|
68
|
+
})
|
|
69
|
+
const payload = JSON.stringify({
|
|
70
|
+
id: 1,
|
|
71
|
+
method: 'Runtime.evaluate',
|
|
72
|
+
params: { expression: "localStorage.getItem('userToken')", returnByValue: true },
|
|
73
|
+
})
|
|
74
|
+
socket.send(payload)
|
|
75
|
+
const reply = await new Promise((resolve, reject) => {
|
|
76
|
+
const timer = setTimeout(() => reject(new Error('CDP 响应超时')), timeoutMs)
|
|
77
|
+
socket.addEventListener('message', (event) => {
|
|
78
|
+
clearTimeout(timer)
|
|
79
|
+
resolve(typeof event.data === 'string' ? event.data : String(event.data))
|
|
80
|
+
}, { once: true })
|
|
81
|
+
})
|
|
82
|
+
const token = extractTokenFromCdpResponse(reply)
|
|
83
|
+
return token ? { token, source: `cdp:${version.Browser || 'chromium'}` } : ''
|
|
84
|
+
} catch {
|
|
85
|
+
return ''
|
|
86
|
+
} finally {
|
|
87
|
+
try { socket.close() } catch { /* 忽略 */ }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** 写一份可直接被脚本读走的凭证(用户自己把 token 存文件时用)。 */
|
|
92
|
+
export async function readTokenFromFile(path) {
|
|
93
|
+
const { readFile } = await import('node:fs/promises')
|
|
94
|
+
try {
|
|
95
|
+
const raw = (await readFile(path, 'utf8')).trim()
|
|
96
|
+
if (!raw) return ''
|
|
97
|
+
// 支持三种:裸 token、{"token":"..."}、{"value":"..."}
|
|
98
|
+
try {
|
|
99
|
+
const parsed = JSON.parse(raw)
|
|
100
|
+
if (parsed && typeof parsed.token === 'string') return parsed.token
|
|
101
|
+
if (parsed && typeof parsed.value === 'string') return parsed.value
|
|
102
|
+
} catch { /* 裸 token */ }
|
|
103
|
+
return raw
|
|
104
|
+
} catch {
|
|
105
|
+
return ''
|
|
106
|
+
}
|
|
107
|
+
}
|
package/lib/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { DeepSeekApi } from './api.mjs'
|
|
|
11
11
|
import { loginInteractively, resolveStoredToken, resolveToken } from './auth.mjs'
|
|
12
12
|
import { filterSessions, migrateAccount } from './migrate.mjs'
|
|
13
13
|
import { OUT_DIR, loadState, saveState } from './state.mjs'
|
|
14
|
+
import { registerSkill } from './skill.mjs'
|
|
14
15
|
|
|
15
16
|
export const name = 'dsh-deepseek-account-import'
|
|
16
17
|
export const inject = ['tools']
|
|
@@ -146,6 +147,9 @@ export function apply(ctx) {
|
|
|
146
147
|
ctx.tools.register(definition)
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
// 装上插件即获得 deepseek-to-dsh 技能(自然语言触发,不用手工拷 SKILL.md)
|
|
151
|
+
registerSkill(ctx)
|
|
152
|
+
|
|
149
153
|
ctx.inject(['commands'], (cmdCtx) => {
|
|
150
154
|
cmdCtx.commands.register({
|
|
151
155
|
name: 'ds-migrate',
|
package/lib/launch.mjs
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// lib/launch.mjs — 自动拉起一个带调试端口的 Chromium 内核浏览器,让用户登录一次。
|
|
2
|
+
// 这是「一句话迁移」里唯一必须由人参与的环节:扫码 / 输手机号。其余全自动。
|
|
3
|
+
|
|
4
|
+
import { spawn } from 'node:child_process'
|
|
5
|
+
import { access, mkdir } from 'node:fs/promises'
|
|
6
|
+
import { constants } from 'node:fs'
|
|
7
|
+
import { homedir, platform } from 'node:os'
|
|
8
|
+
import { join } from 'node:path'
|
|
9
|
+
import { readTokenViaCdp } from './cdp.mjs'
|
|
10
|
+
import { HOME_DIR } from './state.mjs'
|
|
11
|
+
|
|
12
|
+
const DEEPSEEK_URL = 'https://chat.deepseek.com/'
|
|
13
|
+
|
|
14
|
+
async function exists(path) {
|
|
15
|
+
try { await access(path, constants.F_OK); return true } catch { return false }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const isWsl = async () => platform() === 'linux' && (await exists('/mnt/c/Windows'))
|
|
19
|
+
|
|
20
|
+
/** 候选浏览器可执行文件(先环境变量,再各平台常见位置,最后 WSL 下的 Windows 浏览器)。 */
|
|
21
|
+
export async function candidateBrowsers() {
|
|
22
|
+
const list = []
|
|
23
|
+
const push = (name, command) => { if (command && !list.some((x) => x.command === command)) list.push({ name, command }) }
|
|
24
|
+
if (process.env.DSH_BROWSER_PATH) push('$DSH_BROWSER_PATH', process.env.DSH_BROWSER_PATH)
|
|
25
|
+
if (process.env.CHROME_PATH) push('$CHROME_PATH', process.env.CHROME_PATH)
|
|
26
|
+
|
|
27
|
+
const os = platform()
|
|
28
|
+
if (os === 'win32') {
|
|
29
|
+
const roots = [process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)'], process.env.LOCALAPPDATA].filter(Boolean)
|
|
30
|
+
for (const root of roots) {
|
|
31
|
+
push('Chrome', join(root, 'Google', 'Chrome', 'Application', 'chrome.exe'))
|
|
32
|
+
push('Edge', join(root, 'Microsoft', 'Edge', 'Application', 'msedge.exe'))
|
|
33
|
+
push('360 极速', join(root, '360', '360Chrome', 'Chrome', 'Application', '360chrome.exe'))
|
|
34
|
+
push('QQ 浏览器', join(root, 'Tencent', 'QQBrowser', 'QQBrowser.exe'))
|
|
35
|
+
}
|
|
36
|
+
} else if (os === 'darwin') {
|
|
37
|
+
push('Chrome', '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')
|
|
38
|
+
push('Edge', '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge')
|
|
39
|
+
push('Chromium', '/Applications/Chromium.app/Contents/MacOS/Chromium')
|
|
40
|
+
} else {
|
|
41
|
+
for (const command of ['google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser', 'microsoft-edge']) {
|
|
42
|
+
push(command, command)
|
|
43
|
+
}
|
|
44
|
+
if (await isWsl()) {
|
|
45
|
+
const users = ['/mnt/c/Program Files', '/mnt/c/Program Files (x86)']
|
|
46
|
+
for (const root of users) {
|
|
47
|
+
push('Chrome (Windows)', `${root}/Google/Chrome/Application/chrome.exe`)
|
|
48
|
+
push('Edge (Windows)', `${root}/Microsoft/Edge/Application/msedge.exe`)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return list
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 构造启动参数(纯函数,便于测试)。 */
|
|
56
|
+
export function buildLaunchArgs({ port, profileDir, url = DEEPSEEK_URL } = {}) {
|
|
57
|
+
return [
|
|
58
|
+
`--remote-debugging-port=${Number(port) || 9222}`,
|
|
59
|
+
`--user-data-dir=${profileDir}`,
|
|
60
|
+
'--no-first-run',
|
|
61
|
+
'--no-default-browser-check',
|
|
62
|
+
'--disable-features=Translate',
|
|
63
|
+
url,
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** WSL 下把 Linux 路径换成 Windows 路径(浏览器的 --user-data-dir 只认 Windows 路径)。 */
|
|
68
|
+
export async function toLaunchProfileDir(profileDir, { windowsTarget }) {
|
|
69
|
+
if (!windowsTarget) return profileDir
|
|
70
|
+
const { execFile } = await import('node:child_process')
|
|
71
|
+
return await new Promise((resolve) => {
|
|
72
|
+
execFile('wslpath', ['-w', profileDir], (error, stdout) => {
|
|
73
|
+
resolve(error ? profileDir : String(stdout).trim())
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 拉起浏览器(不等待登录)。返回 { name, command, child }。 */
|
|
79
|
+
export async function launchBrowser({ port = 9222, log = () => {} } = {}) {
|
|
80
|
+
const candidates = await candidateBrowsers()
|
|
81
|
+
const profileDir = join(HOME_DIR, 'cdp-profile')
|
|
82
|
+
await mkdir(profileDir, { recursive: true })
|
|
83
|
+
for (const candidate of candidates) {
|
|
84
|
+
const windowsTarget = /^\/mnt\/c\//.test(candidate.command) || /\.exe$/i.test(candidate.command)
|
|
85
|
+
const launchProfile = await toLaunchProfileDir(profileDir, { windowsTarget })
|
|
86
|
+
const args = buildLaunchArgs({ port, profileDir: launchProfile })
|
|
87
|
+
try {
|
|
88
|
+
const child = spawn(candidate.command, args, { detached: true, stdio: 'ignore' })
|
|
89
|
+
child.unref()
|
|
90
|
+
// 给进程一点启动时间,再确认调试端口是否真的起来了
|
|
91
|
+
await new Promise((resolve) => setTimeout(resolve, 1500))
|
|
92
|
+
const probe = await readTokenViaCdp({ port, timeoutMs: 2500 })
|
|
93
|
+
if (probe) return { ...candidate, child, alreadyLoggedIn: true }
|
|
94
|
+
const version = await fetch(`http://127.0.0.1:${port}/json/version`).then((r) => (r.ok ? r.json() : null)).catch(() => null)
|
|
95
|
+
if (version) {
|
|
96
|
+
log(`已启动 ${candidate.name},请在弹出的窗口里登录 DeepSeek`)
|
|
97
|
+
return { ...candidate, child, version }
|
|
98
|
+
}
|
|
99
|
+
} catch { /* 换下一个候选 */ }
|
|
100
|
+
log(`未能启动 ${candidate.name},尝试下一个…`)
|
|
101
|
+
}
|
|
102
|
+
return null
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 拉起浏览器并等待用户登录,最多 timeoutMs。
|
|
107
|
+
* 返回 { token, source } 或 null。
|
|
108
|
+
*/
|
|
109
|
+
export async function loginViaLaunchedBrowser({ port = 9222, timeoutMs = 5 * 60 * 1000, log = () => {} } = {}) {
|
|
110
|
+
const launched = await launchBrowser({ port, log })
|
|
111
|
+
if (!launched) {
|
|
112
|
+
log('没有可用的 Chromium 内核浏览器,无法自动拉起。请手动启动浏览器并带上 --remote-debugging-port=' + port)
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
if (launched.alreadyLoggedIn) {
|
|
116
|
+
const hit = await readTokenViaCdp({ port })
|
|
117
|
+
return hit || null
|
|
118
|
+
}
|
|
119
|
+
const deadline = Date.now() + timeoutMs
|
|
120
|
+
let lastNotice = 0
|
|
121
|
+
while (Date.now() < deadline) {
|
|
122
|
+
const hit = await readTokenViaCdp({ port })
|
|
123
|
+
if (hit) {
|
|
124
|
+
log('检测到登录完成')
|
|
125
|
+
return hit
|
|
126
|
+
}
|
|
127
|
+
if (Date.now() - lastNotice > 20000) {
|
|
128
|
+
lastNotice = Date.now()
|
|
129
|
+
log(`等待登录中…(剩 ${Math.round((deadline - Date.now()) / 1000)}s)`)
|
|
130
|
+
}
|
|
131
|
+
await new Promise((resolve) => setTimeout(resolve, 2000))
|
|
132
|
+
}
|
|
133
|
+
log('等待登录超时')
|
|
134
|
+
return null
|
|
135
|
+
}
|
package/lib/skill.mjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// lib/skill.mjs — 把 skill/SKILL.md 注册成宿主运行时 skill。
|
|
2
|
+
// 装上插件就自动拥有这个技能(自然语言触发),不需要用户手工往 ~/.dsh/skills 里拷文件。
|
|
3
|
+
|
|
4
|
+
import { readFileSync } from 'node:fs'
|
|
5
|
+
import { dirname } from 'node:path'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
|
|
8
|
+
export const SKILL_NAME = 'deepseek-to-dsh'
|
|
9
|
+
|
|
10
|
+
const SKILL_FILE = new URL('../skill/SKILL.md', import.meta.url)
|
|
11
|
+
|
|
12
|
+
/** 去掉 YAML frontmatter(运行时注册时元信息走参数,不留在正文里)。 */
|
|
13
|
+
export function stripFrontmatter(markdown) {
|
|
14
|
+
const text = String(markdown || '')
|
|
15
|
+
if (!text.startsWith('---')) return text
|
|
16
|
+
const end = text.indexOf('\n---', 3)
|
|
17
|
+
if (end < 0) return text
|
|
18
|
+
const after = text.indexOf('\n', end + 1)
|
|
19
|
+
return after < 0 ? '' : text.slice(after + 1)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function buildSkill(content) {
|
|
23
|
+
const body = stripFrontmatter(content).trim()
|
|
24
|
+
if (!body) return null
|
|
25
|
+
return {
|
|
26
|
+
name: SKILL_NAME,
|
|
27
|
+
description:
|
|
28
|
+
'把用户整个 DeepSeek 账号的对话(含思维链、联网搜索证据、图片、附件)批量迁移进 DeepSeek Harness。' +
|
|
29
|
+
'当用户说“把 DeepSeek 的对话迁到 dsh / 搬到 dsh / 导入 dsh / 把以前的聊天搬过来 / 换到 dsh 接着聊”时使用。',
|
|
30
|
+
whenToUse:
|
|
31
|
+
'用户想把 DeepSeek 网页/APP 里的历史对话搬到 dsh,或提到迁移、搬家、导入历史会话时。' +
|
|
32
|
+
'Also when the user asks to migrate DeepSeek chat history into DSH.',
|
|
33
|
+
source: 'runtime',
|
|
34
|
+
content: body,
|
|
35
|
+
resourceBase: { kind: 'directory', path: dirname(fileURLToPath(SKILL_FILE)) },
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** skills 是可选宿主服务:缺席时静默跳过,命令与工具照常可用。 */
|
|
40
|
+
export function registerSkill(ctx, { readFile } = {}) {
|
|
41
|
+
if (!ctx || typeof ctx.inject !== 'function') return
|
|
42
|
+
ctx.inject(['skills'], (skillsCtx) => {
|
|
43
|
+
let content
|
|
44
|
+
try {
|
|
45
|
+
const read = readFile || ((p) => readFileSync(p, 'utf8'))
|
|
46
|
+
content = read(fileURLToPath(SKILL_FILE))
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.warn('[dsh-deepseek-account-import] SKILL.md 读取失败,跳过 skill 注册:' + String((error && error.message) || error))
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
const skill = buildSkill(content)
|
|
52
|
+
if (!skill) {
|
|
53
|
+
console.warn('[dsh-deepseek-account-import] SKILL.md 内容为空,跳过 skill 注册')
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
skillsCtx.skills.register(skill)
|
|
57
|
+
})
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-deepseek-account-import",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Migrate a whole DeepSeek account (every conversation, with thinking, web-search evidence, images and attachments) into DeepSeek Harness sessions via dsh-chat-import interchange v1.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.mjs",
|
package/skill/SKILL.md
CHANGED
|
@@ -5,7 +5,8 @@ description: 把用户 DeepSeek 账号里的全部对话(含思维链、图片
|
|
|
5
5
|
|
|
6
6
|
# DeepSeek → dsh 一句话迁移
|
|
7
7
|
|
|
8
|
-
用户只需要说一句“**把我 DeepSeek
|
|
8
|
+
用户只需要说一句“**把我 DeepSeek 里的对话都迁过来**”。
|
|
9
|
+
(集成方视角的最简调用说明见 `docs/agent-quickstart.md`。)你的任务是把它跑完,而不是解释原理。
|
|
9
10
|
|
|
10
11
|
## 前置检查(先做,别跳)
|
|
11
12
|
|
|
@@ -17,6 +18,19 @@ description: 把用户 DeepSeek 账号里的全部对话(含思维链、图片
|
|
|
17
18
|
装完提示用户重启 dsh(或等 profile 热重载),再从第 1 步重来。
|
|
18
19
|
3. 如果返回 `登录态:无`,说明是第一次:执行 `deepseek_migrate({ action: "login" })`,**告诉用户会弹出一个浏览器窗口**,让他在里面登录 DeepSeek(手机号或微信扫码都行),登录完成后自动继续。
|
|
19
20
|
|
|
21
|
+
## 登录态拿不到时
|
|
22
|
+
|
|
23
|
+
按顺序试,别让用户去翻源码:
|
|
24
|
+
|
|
25
|
+
1. `ds-migrate browsers` —— 看能不能自动认出他的浏览器 profile,以及里面有没有登录态
|
|
26
|
+
2. 如果认得出来但读不到 token(`.ldb` 被 Snappy 压缩),让他用 CDP:
|
|
27
|
+
用 **极速模式** 启动浏览器并带 `--remote-debugging-port=9222`,登录 `chat.deepseek.com`,
|
|
28
|
+
然后 `ds-migrate token --cdp 9222`
|
|
29
|
+
3. 都不行就最后一招:让他在浏览器控制台执行 `copy(JSON.parse(localStorage.userToken).value)`,
|
|
30
|
+
存成文件后 `ds-migrate token --file <路径>`
|
|
31
|
+
|
|
32
|
+
**国产浏览器(360/QQ/搜狗/夸克/UC)**:Chromium 内核,同样走上面第 2 条;但必须极速模式,且调试参数要手动加。
|
|
33
|
+
|
|
20
34
|
## 执行
|
|
21
35
|
|
|
22
36
|
1. `deepseek_migrate({ action: "preview" })` —— 把“账号里共 N 条、本次处理 M 条”复述给用户,等他一句“确认”再往下。这是唯一需要用户二次确认的地方。
|