magpie-ima-local-auth 0.0.0-stage → 0.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/AGENTS.md +23 -0
- package/CHANGELOG.md +10 -0
- package/CHECKLIST.md +24 -0
- package/LICENSE +21 -0
- package/NOTICE.md +12 -0
- package/README.en.md +48 -0
- package/README.md +125 -3
- package/docs/evaluation.md +92 -0
- package/docs/internals.md +114 -0
- package/index.mjs +406 -0
- package/package.json +60 -6
- package/registry-entry.json +11 -0
- package/scripts/check.mjs +362 -0
- package/scripts/import-cdp.mjs +113 -0
- package/scripts/import-login.mjs +48 -0
- package/scripts/release.mjs +389 -0
- package/src/api.mjs +212 -0
- package/src/chat.mjs +316 -0
- package/src/context.mjs +65 -0
- package/src/login.mjs +238 -0
- package/src/models.mjs +91 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# AGENTS.md —— 给维护者的入口
|
|
2
|
+
|
|
3
|
+
这个仓库是 `magpie-plugin-scaffold` 的派生插件。动手前先读:
|
|
4
|
+
|
|
5
|
+
1. `README.md` —— 用户看什么、支持哪些模型、怎么登录。
|
|
6
|
+
2. `docs/internals.md` —— 协议证据、IUA 的必要性、被否掉的方案。
|
|
7
|
+
3. `docs/evaluation.md` —— 反代价值评估与实测数字。
|
|
8
|
+
4. `node scripts/check.mjs` —— 合规定稿检查,退出码必须 0。
|
|
9
|
+
5. `node --test` —— 语义锁(bkn / 模型 / SSE / DSH 上下文过滤)。
|
|
10
|
+
|
|
11
|
+
## 会静默出错的四条
|
|
12
|
+
|
|
13
|
+
| 症状 | 判据 | 出处 |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| 模型目录退回 DeepSeek-V4.1-Flash / Hy3 / Hy4 / GLM,问答 200 但没正文 | `x-ima-cookie` 必须带 `IMA-IUA`;`src/api.mjs` 的 `defaultIua()` 永远补 | `docs/internals.md` 第 3 节 |
|
|
16
|
+
| 回复答非所问,像是在回答“技能目录” | DSH 把 AGENTS/技能目录作为 user 消息追加;`isContextMessage()` 必须把它们从问题/历史里滤掉 | `src/chat.mjs`、`docs/internals.md` |
|
|
17
|
+
| 流式客户端报 `Stream ended without finish_reason` | `finish()` 必须先发带 `finish_reason:"stop"` 的帧,再置 `closed`;`frame()` 不能提前 return | `src/chat.mjs` |
|
|
18
|
+
| 登录后模型 0 个 / 401 | 用 `importLocalLogin()` 的种子或 profile;`provider.models` 调用 `ensureFresh` 后续期 | `src/login.mjs`、`src/api.mjs` |
|
|
19
|
+
|
|
20
|
+
## 发版
|
|
21
|
+
|
|
22
|
+
`scripts/release.mjs`(预演 → `--yes`),或按 scaffold 的 `UPDATING.md` 七步走。
|
|
23
|
+
`git push` 只是第 4 步;npm publish、tag + GitHub Release、四条验证一个都不能少。
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# 更新记录
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-10-28
|
|
4
|
+
|
|
5
|
+
- 首个版本:从本机 ima.copilot 客户端导入登录态(Windows DPAPI / 种子文件),
|
|
6
|
+
把账号的免费知识库模型(DeepSeek V3.2 / Tencent HY 2.0,含 Think 档)接进 magpie。
|
|
7
|
+
- 流式 `MESSAGE` 与思考 `THINKING` 转 OpenAI Chat Completions;支持非流式。
|
|
8
|
+
- 多轮 session(30 分钟 TTL、60 轮兜底)、`auth.refresh` 续期、算力余额展示。
|
|
9
|
+
- 不列 Copilot:ima 的 Copilot 是云端 agent,本机 2.6.15 对它的问答返回「当前版本暂不支持」。
|
|
10
|
+
- 不依赖 cookie 粘贴、不开 CDP;`IMA-IUA` 缺失会让 ima 把请求当匿名,插件默认补最小 IUA。
|
package/CHECKLIST.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# CHECKLIST
|
|
2
|
+
|
|
3
|
+
## A · 交付前
|
|
4
|
+
|
|
5
|
+
- [ ] `node scripts/check.mjs` 退出码 0
|
|
6
|
+
- [ ] `node --test` 全绿
|
|
7
|
+
- [ ] `config.models` 有 4 条静态兜底
|
|
8
|
+
- [ ] `authorize()` 立刻返回;导入在 callback 里
|
|
9
|
+
- [ ] `refresh` 只返回合并字段
|
|
10
|
+
- [ ] `usage.windows` 没有假 `used` / 假 `limit`
|
|
11
|
+
- [ ] 模型级错误用 404;登录失效才用 401
|
|
12
|
+
- [ ] `IMA-IUA` 默认补上
|
|
13
|
+
- [ ] DSH 上下文消息过滤
|
|
14
|
+
- [ ] 流末有 `finish_reason:"stop"`
|
|
15
|
+
|
|
16
|
+
## B · 发版前
|
|
17
|
+
|
|
18
|
+
- [ ] CHANGELOG 有当前版本
|
|
19
|
+
- [ ] bump version
|
|
20
|
+
- [ ] `npm pack --dry-run` 看到 README / CHANGELOG / docs
|
|
21
|
+
- [ ] commit + push 默认分支
|
|
22
|
+
- [ ] `npm publish`
|
|
23
|
+
- [ ] tag `v<version>` + GitHub Release
|
|
24
|
+
- [ ] 四条验证:npm version / tarball / magpie plugin list / Release 200
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 YOUR NAME
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# NOTICE
|
|
2
|
+
|
|
3
|
+
This plugin is MIT. The following work informed it:
|
|
4
|
+
|
|
5
|
+
| Source | Licence | Used for |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| [magpie-plugin-scaffold](https://github.com/MYCF711/magpie-plugin-scaffold) | MIT | the nine hooks skeleton, `scripts/check.mjs`, release flow |
|
|
8
|
+
| [magpie-ima-auth](https://github.com/dongsujiang0205-coder/magpie-ima-auth) | MIT | the ima `/cgi-bin/session_logic/init_session`, `/cgi-bin/assistant/qa` and `/cgi-bin/model_manage/get_models` protocol facts |
|
|
9
|
+
| [opencli-plugin-ima](https://github.com/whynpc9/opencli-plugin-ima) | see its repository | cross-checking the `x-ima-cookie` fields and the ima.copilot desktop login behaviour |
|
|
10
|
+
|
|
11
|
+
ima and ima.copilot are products of Tencent. This repository is not affiliated with or
|
|
12
|
+
endorsed by Tencent. The endpoints used here are private and may change without notice.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# ima.copilot (local client) for magpie
|
|
2
|
+
|
|
3
|
+
**Put the free models of the ima.copilot desktop app in front of your agent — no cookie to paste, and no ima cloud agent in the path.**
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
Sign-in the ima.copilot client already signed in on this machine (DPAPI profile / seed file)
|
|
7
|
+
Models DeepSeek / Tencent HY, free Q&A; Copilot credit models are not listed
|
|
8
|
+
Streaming MESSAGE text + THINKING reasoning as SSE
|
|
9
|
+
Usage free Q&A spends no 算力; the card shows the account's balance
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## What it does
|
|
13
|
+
|
|
14
|
+
- Imports the sign-in the ima.copilot client wrote to its profile (Windows DPAPI); no DevTools cookie copying.
|
|
15
|
+
- Reads the account's own model catalogue from `/model_manage/get_models`; a static table covers the signed-out state.
|
|
16
|
+
- Streams `MESSAGE` deltas and sends `THINKING` deltas to `reasoning_content`.
|
|
17
|
+
- Keeps one ima session per magpie conversation (30 min TTL, 60-turn backstop), carrying recent turns into a new session.
|
|
18
|
+
- Uses `robot_type=10000` (plain Q&A) only. Copilot (`robot_type=15`) is ima's own cloud agent; it is neither listed nor called.
|
|
19
|
+
|
|
20
|
+
## Models
|
|
21
|
+
|
|
22
|
+
**DeepSeek / Tencent HY** — the real list follows the account and client version.
|
|
23
|
+
|
|
24
|
+
| Vendor | Model | Thinking | Billing |
|
|
25
|
+
|---|---|---|---|
|
|
26
|
+
| DeepSeek | `deepseek-v3.2` | — | free (knowledge-base Q&A) |
|
|
27
|
+
| DeepSeek | `deepseek-v3.2-think` | ✓ | free |
|
|
28
|
+
| Tencent | `tencent-hy-2.0` | — | free |
|
|
29
|
+
| Tencent | `tencent-hy-2.0-think` | ✓ | free |
|
|
30
|
+
|
|
31
|
+
Copilot credit models are deliberately not listed: they are an agent channel, and the client tested answers
|
|
32
|
+
"当前版本暂不支持" for them.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
Search `magpie-ima-local-auth` under **Plugins → Discover**, then **Sign in → Use ima.copilot on this machine**.
|
|
37
|
+
|
|
38
|
+
The ima.copilot client must have been signed in once on this machine. If magpie can't find the sign-in,
|
|
39
|
+
run `node scripts/import-login.mjs --profile "<ima User Data directory>"` or set `IMA_COPILOT_LOGIN_FILE`.
|
|
40
|
+
|
|
41
|
+
## Limits
|
|
42
|
+
|
|
43
|
+
No tool calls, no image input, no token counts (ima reports none), Windows-only sign-in import. The model
|
|
44
|
+
catalogue's context window is not published by ima; `limit.context` is left 0.
|
|
45
|
+
|
|
46
|
+
## Licence
|
|
47
|
+
|
|
48
|
+
MIT. ima and ima.copilot belong to Tencent; this is a third-party plugin, not an official one.
|
package/README.md
CHANGED
|
@@ -1,3 +1,125 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# ima.copilot(本机客户端)for magpie
|
|
2
|
+
|
|
3
|
+
**把本机已登录的 ima.copilot 免费模型接进 magpie —— 不粘贴 cookie,不走 ima 的云端 agent。**
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
登录 本机 ima.copilot 客户端(profile 里的 DPAPI 凭证 / 种子文件)
|
|
7
|
+
模型 DeepSeek / Tencent HY,免费问答;Copilot 积分模型默认不列
|
|
8
|
+
流式 MESSAGE 正文 + THINKING 思考,SSE 增量
|
|
9
|
+
额度 免费问答不扣算力;卡片显示账号算力余额
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 功能
|
|
15
|
+
|
|
16
|
+
- **一键导入本机登录态** —— 读取 ima.copilot 客户端退出时写进 profile 的加密凭证(Windows DPAPI),不用去浏览器 DevTools 复制 `x-ima-cookie`。
|
|
17
|
+
- **真实模型目录** —— 登录后从 `/model_manage/get_models` 读账号自己的模型表,跟随 ima 账号上下架;未登录时用静态兜底表。
|
|
18
|
+
- **流式与思考** —— 正文按 `MESSAGE` 增量转发;思考模型走 `THINKING` 事件进 `reasoning_content`,不混进正文。
|
|
19
|
+
- **多轮会话** —— 一个 magpie 会话对应一个 ima session(30 分钟 TTL,60 轮兜底轮换);新 session 会自动带上最近几轮上下文。
|
|
20
|
+
- **省心的错误语义** —— 登录失效返回 401 + `X-Magpie-Sign-In: expired`;模型不存在返回 404;限流/业务失败原样给出 ima 的 code 与 message。
|
|
21
|
+
- **不碰云端 agent** —— 只走 `robot_type=10000`(问问 ima 的普通问答)。Copilot 的 `robot_type=15` 是 ima 自己的 agent,本插件不列、不调;这正是 today 式结果被排除的原因。
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 模型
|
|
26
|
+
|
|
27
|
+
**DeepSeek / Tencent HY** —— 登录后跟随 ima 账号目录;不同账号、不同客户端版本的目录可能不同。
|
|
28
|
+
|
|
29
|
+
| 发行商 | 代表模型 | 思考 | 计费 |
|
|
30
|
+
|---|---|---|---|
|
|
31
|
+
| DeepSeek | `deepseek-v3.2` | — | 免费(知识库问答) |
|
|
32
|
+
| DeepSeek | `deepseek-v3.2-think` | ✓ | 免费(知识库问答) |
|
|
33
|
+
| Tencent | `tencent-hy-2.0` | — | 免费(知识库问答) |
|
|
34
|
+
| Tencent | `tencent-hy-2.0-think` | ✓ | 免费(知识库问答) |
|
|
35
|
+
|
|
36
|
+
> 这里只列本机实测到的代表模型。真实目录由 `provider.models` 在登录后整份替换;
|
|
37
|
+
> 装好以后 `magpie plugin list` / 模型选择器里看到的才是账号当前的全部。
|
|
38
|
+
|
|
39
|
+
**Copilot 积分模型默认不列。** 本机 ima 2.6.15 对 Copilot 问答返回「当前版本暂不支持」;
|
|
40
|
+
更重要的是 Copilot 是 ima 的云端 agent,不是模型通道。需要积分模型时请用别的供应商。
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 签到
|
|
45
|
+
|
|
46
|
+
**没有每日签到。** `auth.checkin` 返回 `inactive`。
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 安装
|
|
51
|
+
|
|
52
|
+
在 magpie 的 **插件 → 发现** 搜 `magpie-ima-local-auth`,点**安装**。
|
|
53
|
+
|
|
54
|
+
装完点**登录**,选 **Use ima.copilot on this machine**。插件会读取本机 ima.copilot 的登录态并保存到 magpie 的账号文件。
|
|
55
|
+
|
|
56
|
+
> 前置条件:这台机器上的 ima.copilot 客户端**登录过一次**(之后不要求一直开着)。
|
|
57
|
+
> 登录态来自客户端 profile 的 `tencent.wxlogin` 段;如果客户端还没把凭证写盘,先打开它、登录,再退出一次。
|
|
58
|
+
|
|
59
|
+
如果 magpie 提示找不到登录态,有三种办法:
|
|
60
|
+
|
|
61
|
+
1. 再打开一次 ima.copilot,确认账号页显示已登录,然后回 magpie 重试;
|
|
62
|
+
2. 用种子文件:`node scripts/import-login.mjs --profile "<ima 的 User Data 目录>"`,它会把登录态写到 `~/.cache/magpie/ima-local-auth/login.json`;
|
|
63
|
+
3. 直接把导出的 JSON 路径给环境变量 `IMA_COPILOT_LOGIN_FILE`(适合 macOS / 多 profile);
|
|
64
|
+
4. 如果客户端已经带 `--remote-debugging-port` 启动,用 CDP + native bridge 导入:`node scripts/import-cdp.mjs --port 9222`(同一个 `chrome.imaFrame` 接口,官方前端用的就是它);
|
|
65
|
+
5. 自定义 profile 目录可以用 `IMA_COPILOT_PROFILE_DIRS`(路径分隔符分隔)告诉插件。
|
|
66
|
+
|
|
67
|
+
### 命令行
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# 从 npm(发布后)
|
|
71
|
+
magpie plugin add magpie-ima-local-auth
|
|
72
|
+
|
|
73
|
+
# 从本仓库源码
|
|
74
|
+
magpie plugin add "<本仓库目录>"
|
|
75
|
+
|
|
76
|
+
# 登录
|
|
77
|
+
magpie plugin login ima
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
装完确认:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
magpie plugin list
|
|
84
|
+
# magpie-ima-local-auth on
|
|
85
|
+
# ima (ima, N models) signed in as ...
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## 常见问题
|
|
91
|
+
|
|
92
|
+
**Q:需要 ima.copilot 一直开着吗?**
|
|
93
|
+
不用。登录导入之后,magpie 用 refresh token 续期;客户端只在导入那一下需要存在。
|
|
94
|
+
|
|
95
|
+
**Q:为什么没有 Copilot 的模型?**
|
|
96
|
+
Copilot 是 ima 的云端 agent(`robot_type=15`),不是模型通道。本机版本直接返回「当前版本暂不支持」;插件按“模型供应商”定位,不把 agent 包装成模型。
|
|
97
|
+
|
|
98
|
+
**Q:支持工具调用 / 图片吗?**
|
|
99
|
+
不支持。ima 的问答接口没有 tool 通道,免费模型也不收图;插件在模型条目上如实声明 `toolcall: false` / `attachment: false`。
|
|
100
|
+
|
|
101
|
+
**Q:上下文窗口是多少?**
|
|
102
|
+
ima 的模型目录不下发窗口大小。插件把 `limit.context` 留 0,让 magpie 用它自己的模型库;不写一个猜的数字。
|
|
103
|
+
|
|
104
|
+
**Q:macOS 能用吗?**
|
|
105
|
+
协议与模型目录是同一套;但登录导入的 DPAPI 解密目前只做了 Windows。macOS 请用种子文件 / `IMA_COPILOT_LOGIN_FILE`。
|
|
106
|
+
|
|
107
|
+
**Q:token 存在哪?**
|
|
108
|
+
登录态由 magpie 保存在它自己的账号文件里(`plugin-auth.json`);`~/.cache/magpie/ima-local-auth/login.json` 只是种子文件,权限 600。插件不写 magpie 的市场缓存。
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 参考源
|
|
113
|
+
|
|
114
|
+
| 来源 | 用在哪 |
|
|
115
|
+
|---|---|
|
|
116
|
+
| [magpie-plugin-scaffold](https://github.com/MYCF711/magpie-plugin-scaffold)(MIT) | 九项钩子骨架、`check.mjs`、发版流程 |
|
|
117
|
+
| [magpie-ima-auth](https://github.com/dongsujiang0205-coder/magpie-ima-auth)(MIT) | ima 的 `init_session` / `assistant/qa` / `model_manage` 协议事实 |
|
|
118
|
+
| [opencli-plugin-ima](https://github.com/whynpc9/opencli-plugin-ima) | ima 登录态、WebContents、`x-ima-cookie` 字段的交叉验证 |
|
|
119
|
+
| ima.copilot 本机客户端 | 2026-10-28 在本机实测的模型目录、`MESSAGE` / `THINKING` 事件、IUA 行为 |
|
|
120
|
+
|
|
121
|
+
> 更新记录:[CHANGELOG.md](./CHANGELOG.md)
|
|
122
|
+
|
|
123
|
+
## 许可
|
|
124
|
+
|
|
125
|
+
MIT。ima 与 ima.copilot 归腾讯所有;这是一个第三方插件,不是官方产品。
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# ima.copilot 反代价值评估
|
|
2
|
+
|
|
3
|
+
> 评估对象:`E:\ima.copilot\ima.copilot.exe`(本机 2.6.15.5280 / Chromium 150.0.7871.5469)
|
|
4
|
+
> 评估时间:2026-10-28。所有数字都是本机实测,不是查资料估的。
|
|
5
|
+
|
|
6
|
+
## 结论
|
|
7
|
+
|
|
8
|
+
| 反代对象 | 价值 | 判定 |
|
|
9
|
+
|---|---|---|
|
|
10
|
+
| **免费知识库模型**(DeepSeek V3.2 / Tencent HY 2.0,含 Think 档) | **高** | 4 个模型可用、不扣算力、支持流式与思考、单问 session 能多轮;适合做 magpie 供应商 |
|
|
11
|
+
| **积分模型(Copilot)** | **0(在“不能是云端 agent”约束下)** | 本机 2.6.15 对 Copilot 问答直接返回 `{"Code":1,"Msg":"当前版本暂不支持"}`;即使别的版本支持,它也是 ima 自己的云端 agent(`robot_type=15`),正是 today 式结果的来源 |
|
|
12
|
+
| 知识库文件 / 文档管理 | 低(本次不做) | 是 ima 的知识库业务,不是模型;对 magpie 供应商没有直接价值 |
|
|
13
|
+
| 图片生成 / 播客等 | 低(本次不做) | 与 magpie 的 chat 供应商无关;且需要单独的计费与权限 |
|
|
14
|
+
|
|
15
|
+
**一句话:这个软件的反代价值全部集中在“免费模型”上;积分模型不是模型通道,是云端 agent,不值得为它牺牲模型级体验。**
|
|
16
|
+
|
|
17
|
+
## 实测证据
|
|
18
|
+
|
|
19
|
+
### 免费模型目录(`POST /cgi-bin/model_manage/get_models`,body `{}`)
|
|
20
|
+
|
|
21
|
+
| model_type | model_id | 显示名 | 倍率字段 |
|
|
22
|
+
|---|---|---|---|
|
|
23
|
+
| 3 | official_3 | DeepSeek V3.2 | 空 |
|
|
24
|
+
| 1 | official_1 | DeepSeek V3.2 Think | 空 |
|
|
25
|
+
| 0 | official_0 | Tencent HY 2.0 | 空 |
|
|
26
|
+
| 2 | official_2 | Tencent HY 2.0 Think | 空 |
|
|
27
|
+
|
|
28
|
+
`model_token_copywriting` 为空 = 知识库问答不扣算力。连续多次 `assistant/qa` 后
|
|
29
|
+
`token_manager/get_balance` 仍为 500,说明免费不是“暂时没扣”。
|
|
30
|
+
|
|
31
|
+
### 问答
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
POST /cgi-bin/session_logic/init_session
|
|
35
|
+
{"env_info":{"interact_type":2,"robot_type":10000},"name":"…","msgs_limit":20}
|
|
36
|
+
→ {"code":0,"session_id":"…"}
|
|
37
|
+
|
|
38
|
+
POST /cgi-bin/assistant/qa (SSE)
|
|
39
|
+
{"session_id":"…","robot_type":10000,"question":"…","question_type":2,
|
|
40
|
+
"command_info":{"question_info":{}},"model_info":{"model_type":3,"model_id":"official_3"}}
|
|
41
|
+
→ MESSAGE {"Text":"DSH-IMA-OK"} … COMPLETED {"Code":0}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- 多轮:同一 session 第一问“记住 7391”、第二问“刚才的数字”返回 7391。
|
|
45
|
+
- 长回答:9 个 `MESSAGE` 增量拼出完整 1..20。
|
|
46
|
+
- 思考模型:`THINKING {"Message":"…","Status":1}` 增量;最后一条 `Status:2` 是结束标记。
|
|
47
|
+
- `SUGGEST_QUESTION` 是建议列表,不是答案。
|
|
48
|
+
|
|
49
|
+
### 登录态
|
|
50
|
+
|
|
51
|
+
ima 的 token 有两份:运行中客户端的内存(native bridge),以及客户端正常退出时写进
|
|
52
|
+
profile 的 `tencent.wxlogin.account_secret_encrypted`(DPAPI)。插件读后者,不读内存、
|
|
53
|
+
不开 CDP、不要求粘贴 cookie。读到的 `token` 约 2 小时,`refresh_token` 约一年;
|
|
54
|
+
`/auth_login/refresh` 实测可换新 token(返回相对 7200 秒)。
|
|
55
|
+
|
|
56
|
+
### IUA 的必要性
|
|
57
|
+
|
|
58
|
+
`x-ima-cookie` 里少了 `IMA-IUA`,服务端不报错,但会把请求当匿名:
|
|
59
|
+
模型目录退回默认的 DeepSeek-V4.1-Flash / Hy3 / Hy4 / GLM,`assistant/qa` 返回 200
|
|
60
|
+
却没有正文。补一个最小 IUA
|
|
61
|
+
(`PR=IMA&PP=com.tencent.imawin&PPVN=<版本>&PL=WIN&COVC=<Chromium 版本>&EV=`)
|
|
62
|
+
就按账号目录回答。所以插件永远补 IUA。
|
|
63
|
+
|
|
64
|
+
## 与现有实现的关系
|
|
65
|
+
|
|
66
|
+
| 实现 | 路径 | 问题 |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| `magpie-ima-auth`(npm) | 浏览器 cookie → 云端 `assistant/qa` | 登录要手工复制 `x-ima-cookie`;本质是把 ima 的云端 agent 会话包装成 chat(单问、无工具、system prompt 受限) |
|
|
69
|
+
| `opencli-plugin-ima` | 直接 API + WebContents/UI | 主要面向知识库问答;Windows 直接 API 遇到 600001;需要客户端/UI 自动化 |
|
|
70
|
+
| 本插件 | 本机客户端 profile → DPAPI 登录态 → 伪装请求头 | 不粘贴 cookie、运行时不需要 CDP;只走 `robot_type=10000` 的普通问答;模型目录/流式/思考/续期都按模型供应商做 |
|
|
71
|
+
|
|
72
|
+
## 限制(如实写)
|
|
73
|
+
|
|
74
|
+
- **单问 session**:ima 的 `assistant/qa` 一次只收一个问题,没有 messages 数组;插件用
|
|
75
|
+
session 保持多轮,但 system prompt 只在 session 第一问里发。
|
|
76
|
+
- **没有工具调用**:ima 的问答接口没有 tool 通道;模型条目如实声明 `toolcall: false`。
|
|
77
|
+
- **没有 token 计数**:ima 不返回 usage;插件不按字符数编,返回 0。
|
|
78
|
+
- **没有上下文窗口**:模型目录不下发;`limit.context` 留 0,交给 magpie 的模型库。
|
|
79
|
+
- **私有接口**:随时可能变;ima 客户端升级后 IUA/字段可能需要跟着调。
|
|
80
|
+
- **登录导入平台**:DPAPI 解密目前只做 Windows;macOS 用种子文件 / `IMA_COPILOT_LOGIN_FILE`。
|
|
81
|
+
- **Copilot 不可用**:本机版本直接“暂不支持”,且它是 agent;插件默认不列。
|
|
82
|
+
|
|
83
|
+
## 已完成的验收
|
|
84
|
+
|
|
85
|
+
- `node scripts/check.mjs`:通过 29 · 警告 0 · 失败 0
|
|
86
|
+
- `node --test`:10/10
|
|
87
|
+
- magpie 0.1.1814 安装后 `ima (ima, 4 models) signed in as 001ab…`
|
|
88
|
+
- 网关:`POST /v1/chat/completions`(`ima/deepseek-v3.2`)返回 `GATEWAY-OK`;
|
|
89
|
+
流式返回 role/content/`finish_reason:"stop"`;`ima/deepseek-v3.2-think` 返回
|
|
90
|
+
`reasoning_content`。
|
|
91
|
+
- DSH headless(`dsh --profile headless` + patch,模型 `ima/tencent-hy-2.0`)返回
|
|
92
|
+
`DSH-IMA-OK`。
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# 内部说明:协议、证据与被否掉的方案
|
|
2
|
+
|
|
3
|
+
这份文件只记录「为什么这样做」与「怎么验证」。用户看 README;改代码前先看这里。
|
|
4
|
+
|
|
5
|
+
## 1. 这个插件反代的是什么
|
|
6
|
+
|
|
7
|
+
ima.copilot 客户端里有两套对话:
|
|
8
|
+
|
|
9
|
+
| | 问问 ima / 知识库问答 | Copilot |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| 请求 `robot_type` | **10000(Main)** | 15 |
|
|
12
|
+
| 本插件 | **用这一套** | **不用** |
|
|
13
|
+
| 计费 | 免费 | 算力(×倍率) |
|
|
14
|
+
| 形态 | 单问 session + SSE | ima 自己的云端 agent |
|
|
15
|
+
|
|
16
|
+
`assistant/qa` 不是 OpenAI 兼容接口:它一次只收一个问题,没有 messages 数组;
|
|
17
|
+
所以插件把一个 magpie 会话映射成一个 ima session,把上一条 user 消息作为这一轮的问题,
|
|
18
|
+
把 system/developer 指令只放在新 session 的第一问里。
|
|
19
|
+
|
|
20
|
+
## 2. 登录态从哪来
|
|
21
|
+
|
|
22
|
+
ima 的 token 有两份:
|
|
23
|
+
|
|
24
|
+
1. **运行中的客户端内存**(native bridge,前端用 `chrome.imaFrame.invokeWithCallback`
|
|
25
|
+
`getAccountInfo` 读它)。进程一关就没了,不能当持久来源。
|
|
26
|
+
2. **客户端正常退出时写进 profile 的 `Preferences`**:
|
|
27
|
+
`tencent.wxlogin.account_secret_encrypted` 是一段 DPAPI 加密的 base64,
|
|
28
|
+
解出来是 `{ token, refresh_token, token_valid_time, refresh_token_valid_time }`。
|
|
29
|
+
|
|
30
|
+
插件读第 2 份:Windows 上用 PowerShell 的
|
|
31
|
+
`System.Security.Cryptography.ProtectedData.Unprotect(..., CurrentUser)` 解 DPAPI。
|
|
32
|
+
不读进程内存、不开 CDP、不要求用户粘贴 cookie。
|
|
33
|
+
|
|
34
|
+
> 如果 client 还没写盘,`tencent.wxlogin.account_secret_encrypted` 为空。
|
|
35
|
+
> 这时打开 ima.copilot 登录一次,再退出;或者用 `scripts/import-login.mjs` 从一个
|
|
36
|
+
> 已登录 profile 导出种子文件;如果客户端已经带调试端口启动,也可以用
|
|
37
|
+
> `scripts/import-cdp.mjs --port 9222` 走 CDP + native bridge 导入。
|
|
38
|
+
> 运行时本身不需要 CDP —— 只有导入这一步可以用它。
|
|
39
|
+
|
|
40
|
+
## 3. 请求头
|
|
41
|
+
|
|
42
|
+
实测(2026-10-28,ima 2.6.15.5280 / Chromium 150.0.7871.5469):
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
x-ima-cookie: PLATFORM=H5; CLIENT-TYPE=windows; WEB-VERSION=5.16.12;
|
|
46
|
+
IMA-GUID=...; IMA-UID=...; IMA-TOKEN=...; IMA-REFRESH-TOKEN=...;
|
|
47
|
+
UID-TYPE=2; TOKEN-TYPE=14; IMA-IUA=PR=IMA&PP=com.tencent.imawin&PPVN=...
|
|
48
|
+
from_browser_ima: 1
|
|
49
|
+
extension_version: 5.16.12
|
|
50
|
+
x-ima-bkn: djb2(IMA-TOKEN) & 0x7fffffff
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**`IMA-IUA` 是关键。** 少了它,服务端不会报错,只会把整套请求当成匿名:
|
|
54
|
+
`model_manage/get_models` 返回默认目录(DeepSeek-V4.1-Flash / Hy3 / Hy4 / GLM),
|
|
55
|
+
`assistant/qa` 返回 200 但没有 `MESSAGE` 正文。实测只要 IUA 以
|
|
56
|
+
`PR=IMA&PP=com.tencent.imawin&PPVN=<版本>&PL=WIN&COVC=<Chromium 版本>&EV=` 的形式存在,
|
|
57
|
+
服务端就按账号目录回答,不需要精确的设备指纹字段(`BT/CH/DC` 可省)。
|
|
58
|
+
所以 `src/api.mjs` 的 `defaultIua()` 永远补一个最小 IUA。
|
|
59
|
+
|
|
60
|
+
`IMA-Q36` 的精确值可以从 profile 的 `sync.cache_guid` 得到,但不是必需。
|
|
61
|
+
|
|
62
|
+
## 4. 流式事件(实测)
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
QA_START {"model_type":3,"model_name":"DeepSeek V3.2",...}
|
|
66
|
+
SESSION_START {"MsgSeqID":"..."}
|
|
67
|
+
MESSAGE {"Text":"增量"}
|
|
68
|
+
THINKING {"Message":"思考增量","Status":1}
|
|
69
|
+
SUGGEST_QUESTION [{"Text":"..."}] ← 不是答案,忽略
|
|
70
|
+
COMPLETED {"Code":0,"Msg":""} ← 业务错误在这里
|
|
71
|
+
CLOSE [DONE]
|
|
72
|
+
HEARTBEAT
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`THINKING` 的最后一条是 `{"Message":"","Status":2,"Tips":"..."}`,是结束标记,不能拼进
|
|
76
|
+
`reasoning_content`。正文按 `MESSAGE` 增量拼接;长回答实测 9 个 `MESSAGE` 事件拼出完整
|
|
77
|
+
1..20。`SUGGEST_QUESTION` 的 data 是数组,不能按对象读。
|
|
78
|
+
|
|
79
|
+
## 5. 模型目录
|
|
80
|
+
|
|
81
|
+
`POST /cgi-bin/model_manage/get_models`(body `{}`)返回账号的免费目录,本机实测:
|
|
82
|
+
|
|
83
|
+
| model_type | model_id | 名字 | model_token_copywriting |
|
|
84
|
+
|---|---|---|---|
|
|
85
|
+
| 3 | official_3 | DeepSeek V3.2 | 空 |
|
|
86
|
+
| 1 | official_1 | DeepSeek V3.2 Think | 空 |
|
|
87
|
+
| 0 | official_0 | Tencent HY 2.0 | 空 |
|
|
88
|
+
| 2 | official_2 | Tencent HY 2.0 Think | 空 |
|
|
89
|
+
|
|
90
|
+
`model_token_copywriting` 为空 = 不扣算力,插件标 `free: true`;`×1.0` 之类是积分模型,
|
|
91
|
+
插件标 `rate`。Copilot 的 `scene:1` 在本机只返回「默认模型 ×1.0」,且 `assistant/qa`
|
|
92
|
+
(robot 15)返回 `{"Code":1,"Msg":"当前版本暂不支持"}`;所以默认不列 Copilot。
|
|
93
|
+
|
|
94
|
+
## 6. 被否掉的方案
|
|
95
|
+
|
|
96
|
+
- **云端 cookie 直连**:magpie-ima-auth 走的就是它;它把 ima 的 agent 会话包装成 chat,
|
|
97
|
+
system prompt、工具、单问限制都在。它仍是一个云端 agent 桥,不是模型供应商体验。
|
|
98
|
+
- **插件运行时开 CDP 拿 native bridge**:ima 只有特定启动方式才暴露 CDP,且 companion
|
|
99
|
+
实例是否拿到登录态不稳定;每次使用还要拉起/重启客户端。不用。
|
|
100
|
+
- **扫描客户端进程内存**:能找到字符串常量,但 token 不在可检索的明文里;且需要
|
|
101
|
+
ReadProcessMemory 权限,跨版本极脆。不用。
|
|
102
|
+
- **Copilot 积分模型**:本机版本直接「暂不支持」,且它是 agent 通道(today 式结果)。
|
|
103
|
+
默认不列;代码保留了 `robot_type` 参数,但本版本没有开启。
|
|
104
|
+
|
|
105
|
+
## 7. 已验证
|
|
106
|
+
|
|
107
|
+
2026-10-28,本机 ima 2.6.15.5280:
|
|
108
|
+
|
|
109
|
+
- 从 profile 导入登录态 → `model_manage/get_models` 返回 4 个免费模型
|
|
110
|
+
- `assistant/qa`(robot 10000, model_type=3)返回 `PLUGIN-OK` / `FACTORY-OK` / `IUA-OK`
|
|
111
|
+
- `THINKING` 事件进 `reasoning_content`;`COMPLETED Code 0` 正常结束
|
|
112
|
+
- `token_manager/get_balance` 返回算力余额
|
|
113
|
+
- `auth.refresh` 成功换到新 access token(`token_valid_time` 为相对 7200 秒)
|
|
114
|
+
- 插件 factory 的 loader 流式/非流式都返回 200
|