dsh-sensenova-pool 0.0.0-stage → 0.1.1

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/LICENSE ADDED
Binary file
package/README.md CHANGED
@@ -1,3 +1,245 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ <div align="center">
2
+
3
+ # dsh-sensenova-pool
4
+
5
+ **商汤日日新(SenseNova)多 Key 轮换池 · DeepSeek Harness 插件**
6
+
7
+ 在一个地方填入多把商汤 API Key,即可在 DSH 对话窗口里直接使用日日新的各种模型 —— 遇 429 限流自动切换到下一把 Key,全程无感。
8
+
9
+ [![npm](https://img.shields.io/npm/v/dsh-sensenova-pool?color=cb3837&logo=npm)](https://www.npmjs.com/package/dsh-sensenova-pool)
10
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
11
+ [![DSH](https://img.shields.io/badge/DeepSeek%20Harness-plugin-4f46e5)](https://github.com/deepseek-ai/deepseek-harness)
12
+
13
+ 中文 | [English](#english)
14
+
15
+ </div>
16
+
17
+ ---
18
+
19
+ ## 功能
20
+
21
+ ### 🔑 多 Key 轮换池
22
+
23
+ 填入任意多把商汤 Key,请求在多把 Key 之间自动轮转,把每把 Key 的额度摊开使用。
24
+
25
+ ![Key 管理卡片](https://raw.githubusercontent.com/Phoeky/dsh-sensenova-pool/main/docs/shots/01-keys.png)
26
+
27
+ - **一次粘贴多把**:换行、逗号、分号、空格分隔都可以
28
+ - **自动清洗**:识别并去除 `Bearer ` 前缀、首尾引号、重复项、明显无效的短串
29
+ - **只看得到脱敏值**:界面只显示 `sk-example...0001` 这样的掩码,明文 Key 不会出现在任何界面上
30
+ - **单把可测**:每把 Key 都能单独「测试」探活,看到真实的可用状态与延迟
31
+ - **单独删除**:任意一把失效随时移除,不影响其他 Key
32
+
33
+ ### 🛡 429 限流自动切换
34
+
35
+ 这是本插件的核心能力。商汤的 Key 有较低的 RPM 上限(实测现有 Key 约 3 RPM),单靠重试无法解决。本插件的做法:
36
+
37
+ - 遇 429 **立即切换到下一把 Key** 重试,用户看不到任何报错
38
+ - 每把 Key 独立冷却,按指数退避 + 随机抖动错开解冻时间
39
+ - 本地 RPM 预限流主动排队,**从源头避开**限流,而不是挨打后再退避
40
+ - 池子真的耗尽时,回报 `503 + Retry-After`(而不是 429),交由 DSH 自行退避重试
41
+ - 429 计数与冷却状态在卡片上实时可见
42
+
43
+ 截图中的 `3/9 成功,6 次限流` 就是真实发生的记录:这把 Key 触发了 6 次 429,全部被池子内部消化,上层没有收到过一个 429。
44
+
45
+ ### 🧠 一次接入全部模型
46
+
47
+ 装好插件后,模型选择器里自动出现「商汤日日新(Key 轮换池)」分组,包含以下模型:
48
+
49
+ | 模型 | 上下文 | 最大输出 | 图片输入 |
50
+ |---|---|---|---|
51
+ | `deepseek-v4.1-flash` | 1,048,576 | 65,536 | – |
52
+ | `deepseek-v4-flash` | 1,048,576 | 65,536 | – |
53
+ | `deepseek-v4-pro` | 1,048,576 | 65,536 | – |
54
+ | `deepseek-flash` | 1,048,576 | 65,536 | – |
55
+ | `glm-5.2` | 1,048,576 | 131,072 | – |
56
+ | `kimi-k3` | 1,048,576 | 65,536 | – |
57
+ | `sensenova-6.8-flash-lite` | 262,144 | 65,536 | ✓ |
58
+
59
+ 启动时内置一份保守目录(无需网络即可用),拿到有效 Key 后自动通过 `/v1/models` 刷新,**商汤日后上线新模型无需升级插件**。
60
+
61
+ 思考等级同样支持,可选 `none / low / medium / high / xhigh`。
62
+
63
+ ### ⚙️ 零配置
64
+
65
+ Key 存在 DSH 的凭据库里,不写进任何配置文件。填入即生效,无需重启 DSH、无需改 YAML。
66
+
67
+ ---
68
+
69
+ ## 安装
70
+
71
+ ### 方式一:npm(推荐)
72
+
73
+ ```bash
74
+ npm install dsh-sensenova-pool
75
+ ```
76
+
77
+ 或使用 pnpm:
78
+
79
+ ```bash
80
+ pnpm add dsh-sensenova-pool
81
+ ```
82
+
83
+ 安装后,把 `dsh-sensenova-pool` 加入 profile `package.json` 的 `dsh.profile.bundles`:
84
+
85
+ ```json
86
+ {
87
+ "dsh": {
88
+ "profile": {
89
+ "bundles": [
90
+ "dsh-sensenova-pool"
91
+ ]
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ ### 方式二:本地开发
98
+
99
+ ```bash
100
+ git clone https://github.com/Phoeky/dsh-sensenova-pool.git
101
+ cd dsh-sensenova-pool
102
+ npm install
103
+ npm run build
104
+
105
+ # 链接到你的 profile
106
+ pnpm --dir "$DSH_PROFILE_DIR" add "link:$PWD"
107
+ ```
108
+
109
+ 同样需要把 `dsh-sensenova-pool` 加进 `dsh.profile.bundles`。
110
+
111
+ ### 重启 DSH
112
+
113
+ 改完 `package.json` 后**重启 DeepSeek Harness**。确认安装成功:插件页的「已安装」列表里会出现本插件。
114
+
115
+ ![插件页](https://raw.githubusercontent.com/Phoeky/dsh-sensenova-pool/main/docs/shots/02-installed.png)
116
+
117
+ ---
118
+
119
+ ## 使用
120
+
121
+ ### 1. 填入 Key
122
+
123
+ 打开 **插件 → dsh-sensenova-pool**,在弹出的卡片里粘贴一把或多把商汤 Key:
124
+
125
+ ```
126
+ sk-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
127
+ sk-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
128
+ sk-cccccccccccccccccccccccccccccc
129
+ ```
130
+
131
+ 点「**添加 Key**」。支持多种分隔方式,重复和无效项会被自动过滤。
132
+
133
+ ### 2. 选择模型
134
+
135
+ 新建会话,在模型选择器里选「**商汤日日新(Key 轮换池)**」下的任意模型,然后正常对话即可。
136
+
137
+ ### 3. 需要时调整
138
+
139
+ | 按钮 | 作用 |
140
+ |---|---|
141
+ | **测试** | 对单把 Key 发一次极小请求,立刻看到是否可用与延迟 |
142
+ | **删除** | 移除单把 Key |
143
+ | **清空全部** | 移除所有 Key |
144
+ | **刷新模型列表** | 主动从商汤 `/v1/models` 拉取最新模型目录 |
145
+
146
+ ---
147
+
148
+ ## 配置项(可选)
149
+
150
+ 绝大多数情况无需改动。如需微调,在 profile 的 `cordis.patch.yml` 里加入:
151
+
152
+ ```yaml
153
+ - id: llm-sensenova-pool
154
+ name: dsh-sensenova-pool
155
+ config:
156
+ rpmLimit: 2 # 每把 Key 的本地 RPM 预限流上限;0 = 关闭
157
+ maxAttempts: 6 # 单个请求最多尝试几把 Key
158
+ maxConcurrency: 1 # 每把 Key 的并发上限;1 = 串行(推荐)
159
+ acquireTimeoutMs: 180000
160
+ requestTimeoutMs: 60000
161
+ baseUrl: https://token.sensenova.cn/v1
162
+ ```
163
+
164
+ `rpmLimit: 2` 是默认值,基于实测(真实上限约 3 RPM)。**调大它不会提高吞吐,只会更容易被限流** —— 想提高吞吐应该增加 Key,而不是加压。
165
+
166
+ ---
167
+
168
+ ## 常见问题
169
+
170
+ **模型选择器里没有「商汤日日新」分组?**
171
+
172
+ 确认 `dsh.profile.bundles` 里有 `dsh-sensenova-pool`,然后**重启 DSH**。
173
+
174
+ **插件卡片打不开?**
175
+
176
+ 在插件页「已安装」列表里点本插件进入详情页。
177
+
178
+ **一直失败怎么办?**
179
+
180
+ 在卡片上点某把 Key 的「测试」看真实原因。`403 model is not available in the current token plan` 表示该模型不在这个 Key 的套餐里 —— 换模型,而不是换 Key。
181
+
182
+ **Key 会泄漏吗?**
183
+
184
+ 不会。界面只显示掩码;明文只存在 DSH 凭据库(`$DSH_HOME/.credentials.yaml`)中,不会写入任何配置文件,也不会出现在日志里。
185
+
186
+ ---
187
+
188
+ ## 环境要求
189
+
190
+ - DeepSeek Harness `0.2.0-rc.2` 或更高
191
+ - Node.js `^22.19.0 || >=24.0.0`
192
+
193
+ ---
194
+
195
+ ## 致谢
196
+
197
+ 本插件在设计与实现上参考了以下开源项目,特此致谢:
198
+
199
+ - **[corrinehu/dsh-workbuddy-connect](https://github.com/corrinehu/dsh-workbuddy-connect)** —— 将第三方模型接入 DSH 的插件范式。本插件的 provider 注册方式与浏览器卡片结构参考了该项目。
200
+ - **[Phoeky/st-rotator](https://github.com/Phoeky/st-rotator)** —— 商汤 Key 轮换网关。本插件的轮换调度、冷却退避与本地预限流策略参考了该项目。
201
+
202
+ ---
203
+
204
+ ## 许可
205
+
206
+ [MIT](./LICENSE)
207
+
208
+ ---
209
+
210
+ <a id="english"></a>
211
+
212
+ ## English
213
+
214
+ **A multi-key rotation pool for SenseNova (商汤日日新) as a DeepSeek Harness plugin.**
215
+
216
+ Paste one or more SenseNova API keys in one place and use every SenseNova model directly in the DSH chat window — rate-limited keys (HTTP 429) are switched out automatically and transparently.
217
+
218
+ ### Features
219
+
220
+ - **Multi-key pool** — paste any number of keys at once (newline / comma / semicolon separated); prefixes, quotes, duplicates and junk are cleaned automatically
221
+ - **Automatic 429 failover** — on rate limiting the pool immediately retries with the next key; each key cools down independently with exponential backoff and jitter, plus local RPM pre-throttling to avoid 429s in the first place
222
+ - **Never leaks a 429 upward** — when every key is exhausted the plugin reports `503 + Retry-After` so DSH backs off on its own
223
+ - **All models, zero config** — a built-in catalogue works offline and refreshes from `/v1/models` once a valid key is present, so new models need no plugin upgrade
224
+ - **Keys are masked** — only `sk-example...0001` style masks are ever displayed
225
+
226
+ ### Install
227
+
228
+ ```bash
229
+ npm install dsh-sensenova-pool
230
+ ```
231
+
232
+ Add `"dsh-sensenova-pool"` to `dsh.profile.bundles` in your profile `package.json`, then restart DeepSeek Harness.
233
+
234
+ ### Usage
235
+
236
+ Open **Plugins → dsh-sensenova-pool**, paste your keys, click **Add keys**, then pick any model under the "商汤日日新(Key 轮换池)" group in the model picker.
237
+
238
+ ### Acknowledgements
239
+
240
+ - [corrinehu/dsh-workbuddy-connect](https://github.com/corrinehu/dsh-workbuddy-connect) — the plugin pattern for bringing third-party models into DSH
241
+ - [Phoeky/st-rotator](https://github.com/Phoeky/st-rotator) — the SenseNova key-rotation gateway this plugin's rotation strategy derives from
242
+
243
+ ### License
244
+
245
+ [MIT](./LICENSE)
@@ -0,0 +1,6 @@
1
+ # Register the SenseNova key-pool provider without changing the profile's
2
+ # current default model. Keys are entered through the plugin's own settings
3
+ # card / web route; nothing secret is written into this file.
4
+ - insert:
5
+ - id: llm-sensenova-pool
6
+ name: dsh-sensenova-pool
@@ -0,0 +1,76 @@
1
+ /**
2
+ * 商汤日日新(SenseNova)模型目录与上游错误分类。
3
+ *
4
+ * 目录来自 `GET https://token.sensenova.cn/v1/models` 的实测结果(2026-10)。
5
+ * 这里固化一份「保守基线」,用途有二:
6
+ * 1. 插件启动时即可注册模型(不需要网络),实现真正的开箱可用;
7
+ * 2. 拿到有效 key 后,用 `/v1/models` 的结果覆盖它,因此新模型无需改代码。
8
+ */
9
+ export interface SenseNovaModel {
10
+ id: string;
11
+ name: string;
12
+ contextWindow: number;
13
+ maxTokens: number;
14
+ /** 是否支持图片输入。 */
15
+ supportsImages: boolean;
16
+ /** 是否为「只推理」模型(无法关闭思考)。 */
17
+ reasoning: boolean;
18
+ }
19
+ /**
20
+ * 内置基线目录(实测自 token.sensenova.cn)。
21
+ *
22
+ * contextWindow 严格取自 `context_length`,maxTokens 取自 `max_output_length`。
23
+ * 刻意不写 `sensenova-u1-fast` / `sensenova-u1.5-lite`:它们实测返回 404
24
+ * (`output_modalities: ["image"]`,属图像生成模型,不是对话模型),列出来只会
25
+ * 让用户选到必然失败的模型。
26
+ */
27
+ export declare const BUILTIN_MODELS: readonly SenseNovaModel[];
28
+ export declare const DEFAULT_BASE_URL = "https://token.sensenova.cn/v1";
29
+ /**
30
+ * 把 `/v1/models` 的原始响应解析成目录。
31
+ *
32
+ * 宽容解析:字段缺失就回落到基线/默认值,任何一条坏数据都不应该让整个目录失败。
33
+ */
34
+ export declare function parseModelCatalog(payload: unknown): SenseNovaModel[];
35
+ export type UpstreamErrorKind = 'rate_limit' | 'invalid_credential' | 'not_found' | 'server' | 'client';
36
+ export interface ClassifiedError {
37
+ kind: UpstreamErrorKind;
38
+ status: number;
39
+ message: string;
40
+ /** 服务端建议的重试等待毫秒数(来自 Retry-After)。 */
41
+ retryAfterMs?: number;
42
+ }
43
+ /**
44
+ * 解析 Retry-After(秒数或 HTTP-date)。
45
+ *
46
+ * 商汤实测**不返回** Retry-After,所以这只是尽力而为;真正决定冷却时长的是
47
+ * keypool 的指数退避。
48
+ */
49
+ export declare function parseRetryAfter(header: string | null): number | undefined;
50
+ /** 从响应体里尽力提取人类可读的错误消息。 */
51
+ export declare function extractErrorMessage(body: string): string;
52
+ /**
53
+ * 把上游 HTTP 状态分类成轮换决策所需的语义。
54
+ *
55
+ * 关键判定(实测商汤行为):
56
+ * - 429 `ModelAccountTpmRateLimitExceeded` → 限流,**换 key 重试**。
57
+ * - 401/403 `permission_denied_error` (code 7) → 该 key 对该模型无权限。
58
+ * 注意:这**不代表 key 失效**,只代表这个模型不在当前套餐里;因此归类为
59
+ * `client`(不冷却、不换 key 空转),而不是 `invalid_credential`。
60
+ * 实测 `deepseek-v4.1-flash` 对现有 key 返回 403,而 `glm-5.2` 返回 200。
61
+ * - 403 若消息含鉴权字样(invalid api key 等)才算凭据失效。
62
+ * - 404 → 模型不存在,换 key 也没用。
63
+ * - 5xx → 上游抖动,短冷却后重试。
64
+ */
65
+ export declare function classifyError(status: number, body: string, retryAfterHeader?: string | null): ClassifiedError;
66
+ /**
67
+ * 该错误是否值得「换一把 key 再试」。
68
+ *
69
+ * - `rate_limit`:本插件存在的理由 —— 必须换。
70
+ * - `server`:上游抖动,换一把往往就好了。
71
+ * - `invalid_credential`:这一把废了,但**池里其他 key 仍然可用**,所以必须继续
72
+ * 换下一把。若在这里放弃,只要池里混进一把坏 key,整个池子就会连带不可用 ——
73
+ * 那正是「池」要避免的事。
74
+ * - `not_found` / `client`(含 403 套餐不含该模型):换 key 解决不了,立即上报。
75
+ */
76
+ export declare function isRetryableAcrossKeys(kind: UpstreamErrorKind): boolean;
package/lib/catalog.js ADDED
@@ -0,0 +1,151 @@
1
+ /**
2
+ * 商汤日日新(SenseNova)模型目录与上游错误分类。
3
+ *
4
+ * 目录来自 `GET https://token.sensenova.cn/v1/models` 的实测结果(2026-10)。
5
+ * 这里固化一份「保守基线」,用途有二:
6
+ * 1. 插件启动时即可注册模型(不需要网络),实现真正的开箱可用;
7
+ * 2. 拿到有效 key 后,用 `/v1/models` 的结果覆盖它,因此新模型无需改代码。
8
+ */
9
+ /**
10
+ * 内置基线目录(实测自 token.sensenova.cn)。
11
+ *
12
+ * contextWindow 严格取自 `context_length`,maxTokens 取自 `max_output_length`。
13
+ * 刻意不写 `sensenova-u1-fast` / `sensenova-u1.5-lite`:它们实测返回 404
14
+ * (`output_modalities: ["image"]`,属图像生成模型,不是对话模型),列出来只会
15
+ * 让用户选到必然失败的模型。
16
+ */
17
+ export const BUILTIN_MODELS = [
18
+ { id: 'deepseek-v4.1-flash', name: 'DeepSeek V4.1 Flash', contextWindow: 1048576, maxTokens: 65536, supportsImages: false, reasoning: true },
19
+ { id: 'deepseek-v4-flash', name: 'DeepSeek V4 Flash', contextWindow: 1048576, maxTokens: 65536, supportsImages: false, reasoning: true },
20
+ { id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro', contextWindow: 1048576, maxTokens: 65536, supportsImages: false, reasoning: true },
21
+ { id: 'deepseek-flash', name: 'DeepSeek Flash', contextWindow: 1048576, maxTokens: 65536, supportsImages: false, reasoning: true },
22
+ { id: 'glm-5.2', name: 'GLM-5.2', contextWindow: 1048576, maxTokens: 131072, supportsImages: false, reasoning: true },
23
+ { id: 'kimi-k3', name: 'Kimi K3', contextWindow: 1048576, maxTokens: 65536, supportsImages: false, reasoning: true },
24
+ { id: 'sensenova-6.8-flash-lite', name: 'SenseNova 6.8 Flash-Lite', contextWindow: 262144, maxTokens: 65536, supportsImages: true, reasoning: true },
25
+ ];
26
+ export const DEFAULT_BASE_URL = 'https://token.sensenova.cn/v1';
27
+ /**
28
+ * 把 `/v1/models` 的原始响应解析成目录。
29
+ *
30
+ * 宽容解析:字段缺失就回落到基线/默认值,任何一条坏数据都不应该让整个目录失败。
31
+ */
32
+ export function parseModelCatalog(payload) {
33
+ const data = payload?.data;
34
+ if (!Array.isArray(data))
35
+ return [];
36
+ const out = [];
37
+ for (const raw of data) {
38
+ const id = typeof raw?.id === 'string' ? raw.id.trim() : '';
39
+ if (!id)
40
+ continue;
41
+ const modalities = Array.isArray(raw.input_modalities) ? raw.input_modalities : [];
42
+ const features = Array.isArray(raw.supported_features) ? raw.supported_features : [];
43
+ const baseline = BUILTIN_MODELS.find((model) => model.id === id);
44
+ // 只保留文本输出模型:图像生成模型(output_modalities 无 text)无法用于对话。
45
+ const outputs = Array.isArray(raw.output_modalities)
46
+ ? raw.output_modalities
47
+ : undefined;
48
+ if (outputs && outputs.length > 0 && !outputs.includes('text'))
49
+ continue;
50
+ out.push({
51
+ id,
52
+ name: typeof raw.name === 'string' && raw.name.trim() ? raw.name.trim() : id,
53
+ contextWindow: typeof raw.context_length === 'number' && raw.context_length > 0
54
+ ? raw.context_length
55
+ : baseline?.contextWindow ?? 262144,
56
+ maxTokens: typeof raw.max_output_length === 'number' && raw.max_output_length > 0
57
+ ? raw.max_output_length
58
+ : baseline?.maxTokens ?? 32768,
59
+ supportsImages: modalities.includes('image'),
60
+ reasoning: features.includes('reasoning'),
61
+ });
62
+ }
63
+ return out;
64
+ }
65
+ /**
66
+ * 解析 Retry-After(秒数或 HTTP-date)。
67
+ *
68
+ * 商汤实测**不返回** Retry-After,所以这只是尽力而为;真正决定冷却时长的是
69
+ * keypool 的指数退避。
70
+ */
71
+ export function parseRetryAfter(header) {
72
+ if (!header)
73
+ return undefined;
74
+ const trimmed = header.trim();
75
+ if (!trimmed)
76
+ return undefined;
77
+ const seconds = Number(trimmed);
78
+ if (Number.isFinite(seconds) && seconds >= 0)
79
+ return Math.round(seconds * 1000);
80
+ const date = Date.parse(trimmed);
81
+ if (!Number.isNaN(date))
82
+ return Math.max(0, date - Date.now());
83
+ return undefined;
84
+ }
85
+ /** 从响应体里尽力提取人类可读的错误消息。 */
86
+ export function extractErrorMessage(body) {
87
+ if (!body)
88
+ return '';
89
+ try {
90
+ const parsed = JSON.parse(body);
91
+ const message = parsed?.error?.message ?? parsed?.message;
92
+ if (typeof message === 'string')
93
+ return message;
94
+ }
95
+ catch {
96
+ // 非 JSON:退化为截断的原文。
97
+ }
98
+ return body.slice(0, 400);
99
+ }
100
+ /**
101
+ * 把上游 HTTP 状态分类成轮换决策所需的语义。
102
+ *
103
+ * 关键判定(实测商汤行为):
104
+ * - 429 `ModelAccountTpmRateLimitExceeded` → 限流,**换 key 重试**。
105
+ * - 401/403 `permission_denied_error` (code 7) → 该 key 对该模型无权限。
106
+ * 注意:这**不代表 key 失效**,只代表这个模型不在当前套餐里;因此归类为
107
+ * `client`(不冷却、不换 key 空转),而不是 `invalid_credential`。
108
+ * 实测 `deepseek-v4.1-flash` 对现有 key 返回 403,而 `glm-5.2` 返回 200。
109
+ * - 403 若消息含鉴权字样(invalid api key 等)才算凭据失效。
110
+ * - 404 → 模型不存在,换 key 也没用。
111
+ * - 5xx → 上游抖动,短冷却后重试。
112
+ */
113
+ export function classifyError(status, body, retryAfterHeader) {
114
+ const message = extractErrorMessage(body);
115
+ const retryAfterMs = parseRetryAfter(retryAfterHeader ?? null);
116
+ const lower = message.toLowerCase();
117
+ if (status === 429)
118
+ return { kind: 'rate_limit', status, message, retryAfterMs };
119
+ if (status === 401)
120
+ return { kind: 'invalid_credential', status, message };
121
+ if (status === 403) {
122
+ // 只有在消息明确指向凭据问题时才算 key 失效;
123
+ // 「model is not available in the current token plan」是套餐/权限问题。
124
+ const credentialish = lower.includes('invalid api key') ||
125
+ lower.includes('api key') && lower.includes('invalid') ||
126
+ lower.includes('unauthorized') ||
127
+ lower.includes('authentication') ||
128
+ lower.includes('invalid_authentication');
129
+ if (credentialish)
130
+ return { kind: 'invalid_credential', status, message };
131
+ return { kind: 'client', status, message };
132
+ }
133
+ if (status === 404)
134
+ return { kind: 'not_found', status, message };
135
+ if (status >= 500)
136
+ return { kind: 'server', status, message };
137
+ return { kind: 'client', status, message };
138
+ }
139
+ /**
140
+ * 该错误是否值得「换一把 key 再试」。
141
+ *
142
+ * - `rate_limit`:本插件存在的理由 —— 必须换。
143
+ * - `server`:上游抖动,换一把往往就好了。
144
+ * - `invalid_credential`:这一把废了,但**池里其他 key 仍然可用**,所以必须继续
145
+ * 换下一把。若在这里放弃,只要池里混进一把坏 key,整个池子就会连带不可用 ——
146
+ * 那正是「池」要避免的事。
147
+ * - `not_found` / `client`(含 403 套餐不含该模型):换 key 解决不了,立即上报。
148
+ */
149
+ export function isRetryableAcrossKeys(kind) {
150
+ return kind === 'rate_limit' || kind === 'server' || kind === 'invalid_credential';
151
+ }