dsh-sensenova-pool 0.2.1 → 1.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/CHANGELOG.md ADDED
@@ -0,0 +1,74 @@
1
+ # 更新日志
2
+
3
+ 本文件记录本插件的所有重要变更,格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),
4
+ 版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
5
+
6
+ ## [1.1.0] - 2026-11-19
7
+
8
+ ### 新增
9
+
10
+ - **端点选择:中国站 / 国际站**。设置卡片顶部新增「上游端点」区,一键在
11
+ `https://token.sensenova.cn/v1`(中国站,默认)与 `https://token.sensenova.ai/v1`(国际站)之间切换,
12
+ 无需重启 DSH。所选端点随 key 一起存进凭据库,重启后仍然记得([#5](https://github.com/Phoeky/dsh-sensenova-pool/issues/5))。
13
+ - **国际站模型目录**:国际站的内置基线覆盖上游 `/v1/models` 列出的全部 5 个模型,
14
+ 包括两个生图模型(`sensenova-u1-fast`、`sensenova-u1.5-lite`)。
15
+ - **按端点的限流额度**:本地 RPM 预限流按站分开计算(默认中国站 2、国际站 3),
16
+ 配置项 `rpmLimit` 新增 `-1` 表示「按端点取默认值」(即现在的默认行为)。
17
+ - 新增配置项 `endpoint`(`cn` / `intl`),只决定**默认**端点;卡片里的选择优先。
18
+ - 设置卡片显示当前实际上游地址,并提示 baseUrl 是否被配置文件固定。
19
+
20
+ ### 变更
21
+
22
+ - 切换端点会连带重置模型目录、RPM 额度与 key 的冷却/失效标记。两个站的 key 互不通用,
23
+ 带着旧站的「已失效/冷却」标记切过去,会让刚切换的几分钟内一把 key 都用不了。
24
+ - **模型目录不再按输出模态过滤**:上游 `/v1/models` 列什么就收什么(此前会静默剔除生图模型)。
25
+ 不想要的模型可在设置页取消勾选,可见性会持久化。
26
+ - 单把 key 探活的默认模型改为取自当前端点的目录(此前写死 `deepseek-v4-flash`,
27
+ 在国际站上必然 404)。
28
+ - `baseUrl` 配置项默认值改为空(表示「用所选端点的官方地址」);仍可显式填写以走自建网关,
29
+ 此时切端点只换目录与额度,不改请求地址。
30
+
31
+ ### 修复
32
+
33
+ - 端点切换后模型选择器不再残留另一个站独有的模型(例如国际站上出现 `deepseek-v4-flash`)。
34
+
35
+ ### 兼容性
36
+
37
+ - 未切换过端点的老用户**行为完全不变**:默认端点仍是中国站,地址与限流额度不变。
38
+ - 凭据记录只新增了一个可选字段 `endpoint`,旧记录照常读取。
39
+
40
+ ## [1.0.0]
41
+
42
+ 商汤日日新多 Key 轮换池的稳定版:遇 429 自动切换 key、本地 RPM 预限流、
43
+ OpenAI 兼容本地接口、模型可见性与窗口自定义。
44
+
45
+ ## [0.2.2]
46
+
47
+ - 思考档位改为**按模型维护实测词表**([#3](https://github.com/Phoeky/dsh-sensenova-pool/issues/3)):
48
+ `glm-5.3` 只认 `low / high / max`,单一映射表无论怎么调都会踩到某一头。
49
+ 模型选择器里只显示该模型真实支持的档位。
50
+
51
+ ## [0.2.1]
52
+
53
+ - 请求体清洗层:把「Agent 合法、商汤网关不认」的写法语义等价地规范化
54
+ (`developer`→`system`、`content: null`→`""`、`arguments` 对象→JSON 字符串、
55
+ `off`→`none`、摘掉 `logprobs` / `metadata` 等),修复 [issue #2](https://github.com/Phoeky/dsh-sensenova-pool/issues/2) 的 400。
56
+ - 新增 `debugRequestOn400`,400 时把实际发出的请求体写进日志。
57
+
58
+ ## [0.2.0]
59
+
60
+ - 支持逐模型自定义上下文窗口与最大输出([#4](https://github.com/Phoeky/dsh-sensenova-pool/issues/4))。
61
+ - 用实测值覆盖上游把 `sensenova-6.8-flash` 报小 4 倍的 `context_length`。
62
+
63
+ ## [0.1.3]
64
+
65
+ - 修复**启动期凭据竞态**:改为等凭据服务真正就绪后再装载,不再出现
66
+ 「重启电脑后 Key 池为空」([#1](https://github.com/Phoeky/dsh-sensenova-pool/issues/1))。
67
+
68
+ ## [0.1.1]
69
+
70
+ - 修复凭据记录写成 `api-key` + `payload` 导致整机 DSH 无法启动的问题(必须用 `grant`)。
71
+
72
+ ## [0.1.0]
73
+
74
+ 首个可用版本:多 Key 轮换池、429 自动切换、设置页管理 key。
package/README.md CHANGED
@@ -47,6 +47,28 @@
47
47
 
48
48
  截图里的 `2/3 成功,1 次限流` 是真实发生的记录:这把 Key 触发过 1 次 429,被池子内部消化掉,上层没有收到过任何 429。
49
49
 
50
+ ### 🌏 可选端点:中国站 / 国际站
51
+
52
+ 商汤有**两个独立的 API 站**,模型、套餐、额度、key 都各自独立:
53
+
54
+ | 端点 | 地址 | 适用 |
55
+ |---|---|---|
56
+ | 中国站(默认) | `https://token.sensenova.cn/v1` | 在商汤国内平台申请的 key |
57
+ | 国际站 | `https://token.sensenova.ai/v1` | 在国际站申请的 key |
58
+
59
+ 在设置卡片最上方点一下就能切换,**无需重启 DSH**;所选端点会随 key 一起存进凭据库,
60
+ 重启后仍然记得。切换会连带做四件事,缺一件状态就会自相矛盾:
61
+
62
+ 1. **上游地址** —— 之后所有请求打到新站;
63
+ 2. **模型目录** —— 换回该站的内置基线,再自动用新 key 刷新(中国站独有 `deepseek-*` / `glm-*`,
64
+ 国际站是 5 个 `sensenova-*` 模型,含 2 个生图模型,全部列出);
65
+ 3. **限流额度** —— 两个站的 RPM 分开算(本地预限流默认中国站 2、国际站 3);
66
+ 4. **key 健康状态** —— 冷却/失效是针对旧站记下的,切过去时一律清掉,不带着旧标记进新站。
67
+
68
+ > ⚠️ 两个站的 key **互不通用**:拿国际站的 key 打中国站会得到 `401 Forbidden`。插件不会
69
+ > 自动猜你在哪个站(猜错会把本来好用的 key 标成失效),所以端点必须自己选对 ——
70
+ > 如果切过去后所有 key 都显示「已失效」,先检查是不是选错了站。
71
+
50
72
  ### 🧠 一次接入全部模型
51
73
 
52
74
  装好插件后,模型选择器里自动出现「商汤日日新(Key 轮换池)」分组,包含以下模型:
@@ -59,11 +81,17 @@
59
81
  | `deepseek-flash` | 1,048,576 | 65,536 | – |
60
82
  | `glm-5.2` | 1,048,576 | 131,072 | – |
61
83
  | `kimi-k3` | 1,048,576 | 65,536 | – |
84
+ | `sensenova-6.8-flash` | 1,048,576 | 65,536 | ✓ |
62
85
  | `sensenova-6.8-flash-lite` | 262,144 | 65,536 | ✓ |
63
86
 
64
87
  启动时内置一份保守目录(无需网络即可用),拿到有效 Key 后自动通过 `/v1/models` 刷新,**商汤日后上线新模型无需升级插件**。
65
88
 
66
- 思考等级同样支持,可选 `none / low / medium / high / xhigh`。
89
+ > ⚠️ 上游 `/v1/models` 的 `context_length` **不一定可信**:它把 `sensenova-6.8-flash` 报成 262,144,
90
+ > 而实测(2026-11-17 直连上游逐级加压)**1,047,536 tokens 仍 200、约 1.05M 才 400** —— 真实窗口就是
91
+ > 1,048,576,被报小了 4 倍。对这类已实测的模型,插件用基线**覆盖**上游值;对照组 `flash-lite` 的
92
+ > 262,144 是真值(257,013 通过、275K 档 400),保持不动。其余模型仍以上游为准,不影响「新模型无需改代码」。
93
+
94
+ 思考等级同样支持,且**档位按模型自动适配**:`glm-5.3` 只认 `low / high / max`,`glm-5.2` 七档全收,缺档时自动就近归位而不是撞 400(见下文「思考档位按模型映射」)。
67
95
 
68
96
  ### ⚙️ 零配置
69
97
 
@@ -73,6 +101,10 @@ Key 存在 DSH 的凭据库里,不写进任何配置文件。填入即生效
73
101
 
74
102
  设置侧栏新增 `dsh-sensenova-pool` 分区,Key 池、对外接口、模型可见性都在这一页。插件页里的卡片同样可以打开。
75
103
 
104
+ 每个模型的**上下文窗口**与**最大输出**都能改:点模型行右侧的「设置」,在展开的面板里填写后点「保存」才生效
105
+ (`取消` 丢弃草稿,`恢复默认` 清掉覆盖)。输入框接受 `1M` / `128K` 这种简写,也接受精确数字。
106
+ 上游对个别模型会报小窗口,基线只覆盖了我们实测过的那些;其余的可以按你自己的实测或套餐情况修正。
107
+
76
108
  ### 🔌 提供对外的 OpenAI 兼容接口
77
109
 
78
110
  插件在 127.0.0.1 上起一个 OpenAI 兼容服务。设置页显示接口地址和 API Key,复制后填进其他 Agent 或客户端即可使用;请求共用同一个 Key 池,遇到限流同样自动换 Key。
@@ -159,11 +191,16 @@ sk-cccccccccccccccccccccccccccccc
159
191
 
160
192
  点「**添加 Key**」。支持多种分隔方式,重复和无效项会被自动过滤。
161
193
 
162
- ### 2. 选择模型
194
+ ### 2. 先确认端点
195
+
196
+ 卡片最上方的「上游端点」区显示当前打的是哪个站 —— 中国站还是国际站。点另一个按钮即可切换,
197
+ 下方会显示切换后的实际上游地址。**key 只在自己申请的那个站有效**,选错站会看到 401。
198
+
199
+ ### 3. 选择模型
163
200
 
164
201
  新建会话,在模型选择器里选「**商汤日日新(Key 轮换池)**」下的任意模型,然后正常对话即可。
165
202
 
166
- ### 3. 需要时调整
203
+ ### 4. 需要时调整
167
204
 
168
205
  | 按钮 | 作用 |
169
206
  |---|---|
@@ -174,7 +211,7 @@ sk-cccccccccccccccccccccccccccccc
174
211
  | **复制**(接口区) | 复制接口地址 / 对外 API Key |
175
212
  | **模型勾选框** | 决定该模型是否出现在模型选择器里 |
176
213
 
177
- ### 4. 接入其他服务
214
+ ### 5. 接入其他服务
178
215
 
179
216
  设置页「本地接口」区给出两样东西:
180
217
 
@@ -207,20 +244,49 @@ print(client.chat.completions.create(
207
244
  - id: llm-sensenova-pool
208
245
  name: dsh-sensenova-pool
209
246
  config:
210
- rpmLimit: 2 # 每把 Key 的本地 RPM 预限流上限;0 = 关闭
247
+ endpoint: cn # cn = 中国站,intl = 国际站;默认 cn。也可在设置卡片里切换
248
+ rpmLimit: 2 # 每把 Key 的本地 RPM 预限流上限;0 = 关闭,-1(默认)= 按端点取值
211
249
  maxAttempts: 6 # 单个请求最多尝试几把 Key
212
250
  maxConcurrency: 1 # 每把 Key 的并发上限;1 = 串行(推荐)
213
251
  acquireTimeoutMs: 180000
214
252
  requestTimeoutMs: 60000
215
- baseUrl: https://token.sensenova.cn/v1
253
+ # baseUrl: https://token.sensenova.cn/v1 # 仅当所有请求要走自建网关时才填;填了就不随端点切换
216
254
  ```
217
255
 
218
- `rpmLimit: 2` 是默认值,基于实测(真实上限约 3 RPM)。**调大它不会提高吞吐,只会更容易被限流** —— 想提高吞吐应该增加 Key,而不是加压。
256
+ `endpoint` 只决定**默认**端点:一旦在设置卡片里切过,以卡片里的选择(存在凭据库)为准,
257
+ 这样「重启后还记得你在哪个站」不需要改配置文件。`rpmLimit` 留默认值时按端点取
258
+ (中国站 2、国际站 3),显式写数字则两个端点都用这个值。
259
+
260
+ `rpmLimit` 的中国站默认值 2 基于实测(真实上限约 3 RPM)。**调大它不会提高吞吐,只会更容易被限流** —— 想提高吞吐应该增加 Key,而不是加压。
261
+
262
+ **两个站的 Key 能混着用吗?** 不能。key 只在发卡的那个站有效,池子只打「当前选中的端点」,
263
+ 所以换站后要换用该站的 key(切站不会删除现有的 key,切回来它们还在)。
219
264
 
220
265
  ---
221
266
 
222
267
  ## 常见问题
223
268
 
269
+ **切到国际站后所有 key 都显示「已失效」?**
270
+
271
+ 基本就是**选错站了**:国际站的 key 打中国站会返回 `401 Forbidden`,反之亦然。切回正确的站即可
272
+ (切站时会清掉冷却/失效标记,所以切回来那些 key 会立刻恢复可用)。如果确认站选对了仍然 401,
273
+ 那才是 key 本身的问题。
274
+
275
+ **国际站里怎么没有 `deepseek-v4-flash` / `glm-5.2`?**
276
+
277
+ 这些模型只在中国站提供。国际站目前有 5 个模型,且**全部列出、不做事先筛选**:
278
+
279
+ | 模型 | 输出 | 对话实测(2026-11-19) |
280
+ |---|---|---|
281
+ | `sensenova-6.8-flash` | 文本 | ✅ 流式 / 非流式 / 图片输入 / 七档思考强度 |
282
+ | `sensenova-6.8-flash-lite` | 文本 | ✅ 同上 |
283
+ | `sensenova-6.7-flash-lite` | 文本 | ⚠️ 本 key 返回 404 `model is not found` |
284
+ | `sensenova-u1-fast` | 图片 | ⚠️ 生图模型,对话接口 404 |
285
+ | `sensenova-u1.5-lite` | 图片 | ⚠️ 生图模型,对话接口 404 |
286
+
287
+ ⚠️ 的那三个仍然展示:404 可能是套餐/灰度差异,隐藏会让有权限的人也选不到。选中后上游
288
+ 会如实报 404 —— 不想要的话在设置页取消勾选即可,可见性会持久化。
289
+
224
290
  **模型选择器里没有「商汤日日新」分组?**
225
291
 
226
292
  确认 `dsh.profile.bundles` 里有 `dsh-sensenova-pool`,然后**重启 DSH**。如果分组在但某个模型不见了,去设置页看看是不是被自己勾掉了。
@@ -279,7 +345,9 @@ records:
279
345
  | `content` 传数字(`123`) | ❌ 400 `invalid arguments` | 必须是字符串或数组 |
280
346
  | `temperature` 等传字符串(`"0.7"`) | ❌ 400 `invalid arguments` | 必须是数字 |
281
347
  | `logprobs` / `top_logprobs` / `metadata` | ❌ 400 | 商汤不支持这些字段 |
282
- | `reasoning_effort` 传 `off` | ❌ 400 `field ReasoningEffort invalid` | 合法值只有 `none`/`minimal`/`low`/`medium`/`high`/`xhigh`/`max`(`off` 要翻成 `none`) |
348
+ | `reasoning_effort` 传 `off` | ❌ 400 `field ReasoningEffort invalid` | DSH 的 `off` 商汤拼作 `none` |
349
+ | `reasoning_effort` 传**该模型不认的档位**(如 `glm-5.3` 收到 `xhigh`) | ❌ 400 `field ReasoningEffort invalid` | 合法词表**按模型**判定,见下方「思考档位按模型映射」 |
350
+ | 给 `kimi-k3` 传任何非 `1` 的 `temperature` | ❌ 400 `field Temperature invalid, only 1 is allowed` | 该模型没有可调随机性;shim 会在转发前把它归一到 `1` |
283
351
 
284
352
  **0.2.1 已修复**:shim 在转发前会把这些写法**语义等价**地规范成商汤接受的形式
285
353
  (`developer`→`system`、`null`/缺失的 content→`""`、`arguments` 对象→JSON 字符串、
@@ -296,6 +364,36 @@ records:
296
364
  > `debugRequestOn400` 打开,插件的 400 日志里会**直接打出实际发出的请求体**,
297
365
  > 一眼就能定位是哪个字段——不用再猜。相关讨论见 [issue #2](https://github.com/Phoeky/dsh-sensenova-pool/issues/2)。
298
366
 
367
+ ### 思考档位按模型映射
368
+
369
+ [issue #3](https://github.com/Phoeky/dsh-sensenova-pool/issues/3) 实测发现:上游的合法
370
+ `reasoning_effort` 集合是**按模型**判定的,不是全局一张表。`glm-5.3` 只认
371
+ `low / high / max`,收到 `xhigh` 就是 400;而 `glm-5.2`、`deepseek-v4-flash`
372
+ 七档全收。单一映射表无论怎么调都会踩到某一头。
373
+
374
+ **0.2.2 起**改为每个模型维护一张实测词表:
375
+
376
+ | 模型 | 实测接受的档位 |
377
+ |---|---|
378
+ | `glm-5.3` | `low` / `high` / `max` |
379
+ | `glm-5.2`、`deepseek-v4-flash`、`sensenova-6.8-flash`、`sensenova-6.8-flash-lite` | 七档全收 |
380
+ | `kimi-k3` | 七档,`max` 未确认 → 不发 |
381
+ | `deepseek-flash` | 七档,`xhigh` 未确认 → 不发 |
382
+ | 其他 / 新上架模型 | 保守表 `low` / `high`(全员交集,永不 400) |
383
+
384
+ 模型选择器里**只显示这张表里真实存在的档位**:`glm-5.3` 的思考档下拉就是
385
+ `Low / High / Max`(+`Default`)—— 不会出现「选了 `Xhigh`、实际发 `max`」这种
386
+ 看着能用、发出去却换了值的档位。
387
+
388
+ shim 侧另有一层兜底:万一别的客户端(或旧配置)发来该模型不认的值,转发前会
389
+ **就近改合法** —— `xhigh` / `max` 这类饱和档由模型最强档承接(不降级,`glm-5.3` 的
390
+ `xhigh → max`),其余档向下取(`medium → low`、`off → low`),宁可省 token 也不
391
+ 悄悄抬高成本。
392
+
393
+ 未实测的模型(新上架、或还没测过的)只显示保守表 `low` / `high` —— 七档里只有这两档
394
+ 是全员交集。写漏顶多降一档,写多会让整条链路每次都 400。新模型上架后,把它的词表
395
+ 补进 `MODEL_REASONING_EFFORTS`(`src/catalog.ts`)即可。
396
+
299
397
  **Key 会泄漏吗?**
300
398
 
301
399
  不会。界面只显示掩码;明文只存在 DSH 凭据库(`$DSH_HOME/.credentials.yaml`)中,不会写入任何配置文件,也不会出现在日志里。
@@ -324,6 +422,12 @@ records:
324
422
  - **[corrinehu/dsh-workbuddy-connect](https://github.com/corrinehu/dsh-workbuddy-connect)** —— 将第三方模型接入 DSH 的插件范式。本插件的 provider 注册方式与浏览器卡片结构参考了该项目。
325
423
  - **[Phoeky/st-rotator](https://github.com/Phoeky/st-rotator)** —— 商汤 Key 轮换网关。本插件的轮换调度、冷却退避与本地预限流策略参考了该项目。
326
424
 
425
+ 特别感谢以下朋友反馈问题、提供实测数据,其中好几处结论直接改变了实现方向:
426
+
427
+ - **@Drhusku** —— [issue #1](https://github.com/Phoeky/dsh-sensenova-pool/issues/1) 启动期凭据竞态、[issue #4](https://github.com/Phoeky/dsh-sensenova-pool/issues/4) 上游把 `sensenova-6.8-flash` 的 1M 窗口谎报成 262144(还附了逐级加压的实测表,让"该不该覆盖上游"这件事有据可依)。
428
+ - **@Sumtenm** —— [issue #3](https://github.com/Phoeky/dsh-sensenova-pool/issues/3) 逐个模型逐个档位实测出 `reasoning_effort` 的词表差异,直接促成了"按模型维护词表"这一版重构。
429
+ - **@Mahiro-FT** —— [issue #2](https://github.com/Phoeky/dsh-sensenova-pool/issues/2) 最先报出 400,并配合确认了复现路径。
430
+
327
431
  ---
328
432
 
329
433
  ## 许可
@@ -352,6 +456,7 @@ Paste one or more SenseNova API keys in one place and use every SenseNova model
352
456
  - **Never leaks a 429 upward** — when every key is exhausted the plugin reports `503 + Retry-After` so DSH backs off on its own
353
457
  - **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
354
458
  - **Keys are masked** — only `sk-example...0001` style masks are ever displayed
459
+ - **Two endpoints** — pick the China site (`token.sensenova.cn`) or the international site (`token.sensenova.ai`) from the settings card; switching also swaps the model list and the rate-limit budget, and the choice survives restarts
355
460
 
356
461
  ### Install
357
462
 
@@ -363,7 +468,7 @@ Add `"dsh-sensenova-pool"` to `dsh.profile.bundles` in your profile `package.jso
363
468
 
364
469
  ### Usage
365
470
 
366
- Open **Settings → dsh-sensenova-pool** (or the plugin card on the Plugins page), paste your keys, click **Add keys**, then pick any model under the "商汤日日新(Key 轮换池)" group in the model picker. The same page shows the local endpoint (base URL, port, API key) and lets you hide models from the picker.
471
+ Open **Settings → dsh-sensenova-pool** (or the plugin card on the Plugins page), pick your endpoint (China site / international site — a key only works on the site that issued it), paste your keys, click **Add keys**, then pick any model under the "商汤日日新(Key 轮换池)" group in the model picker. The same page shows the local endpoint (base URL, port, API key) and lets you hide models from the picker.
367
472
 
368
473
  ### Troubleshooting
369
474
 
@@ -378,6 +483,12 @@ Upgrade and your keys will be picked up again; they were never lost (they live i
378
483
  - [corrinehu/dsh-workbuddy-connect](https://github.com/corrinehu/dsh-workbuddy-connect) — the plugin pattern for bringing third-party models into DSH
379
484
  - [Phoeky/st-rotator](https://github.com/Phoeky/st-rotator) — the SenseNova key-rotation gateway this plugin's rotation strategy derives from
380
485
 
486
+ Thanks to everyone who reported issues and shared measured data — several conclusions came straight from these reports:
487
+
488
+ - **@Drhusku** — [issue #1](https://github.com/Phoeky/dsh-sensenova-pool/issues/1) credential race at startup; [issue #4](https://github.com/Phoeky/dsh-sensenova-pool/issues/4) upstream under-reporting `sensenova-6.8-flash`'s 1M window as 262144, with a full pressure-test table.
489
+ - **@Sumtenm** — [issue #3](https://github.com/Phoeky/dsh-sensenova-pool/issues/3) per-model `reasoning_effort` vocabulary measurements that drove the per-model table rewrite.
490
+ - **@Mahiro-FT** — [issue #2](https://github.com/Phoeky/dsh-sensenova-pool/issues/2) the first 400 report, plus reproduction follow-up.
491
+
381
492
  ### License
382
493
 
383
494
  [MIT](./LICENSE)
package/lib/catalog.d.ts CHANGED
@@ -15,23 +15,202 @@ export interface SenseNovaModel {
15
15
  supportsImages: boolean;
16
16
  /** 是否为「只推理」模型(无法关闭思考)。 */
17
17
  reasoning: boolean;
18
+ /**
19
+ * 基线窗口是否**覆盖**上游 `/v1/models` 的 `context_length`(issue #4)。
20
+ *
21
+ * 只给「实测确认上游报小了」的模型打开;默认 false(以上游为准,保住「新模型
22
+ * 无需改代码」)。打开时必须在 {@link BUILTIN_MODELS} 的注释里写清实测依据与
23
+ * 日期 —— 上游一旦把真实上限调小,这类覆盖就会变成超窗错误(400/413)的来源。
24
+ *
25
+ * 用户在设置页里给某个模型自定义的窗口优先级更高,见 index.ts 的 modelLimits。
26
+ */
27
+ contextWindowOverridesUpstream?: boolean;
18
28
  }
19
29
  /**
20
30
  * 内置基线目录(实测自 token.sensenova.cn)。
21
31
  *
22
32
  * contextWindow 严格取自 `context_length`,maxTokens 取自 `max_output_length`。
23
- * 刻意不写 `sensenova-u1-fast` / `sensenova-u1.5-lite`:它们实测返回 404
24
- * (`output_modalities: ["image"]`,属图像生成模型,不是对话模型),列出来只会
25
- * 让用户选到必然失败的模型。
33
+ * 不含 `sensenova-u1-fast` / `sensenova-u1.5-lite`:**中国站的 /v1/models 本来就不列
34
+ * 这两个生图模型**(基线只镜像上游列出的内容;国际站的目录里它们有,见
35
+ * {@link INTL_BUILTIN_MODELS})。拿到 key 后刷新的目录同样不做任何筛选。
36
+ *
37
+ * 这是**中国站**的目录。国际站的目录不同,见 {@link INTL_BUILTIN_MODELS}。
26
38
  */
27
39
  export declare const BUILTIN_MODELS: readonly SenseNovaModel[];
28
- export declare const DEFAULT_BASE_URL = "https://token.sensenova.cn/v1";
40
+ /** 端点标识:'cn' = 中国站,'intl' = 国际站。 */
41
+ export type EndpointId = 'cn' | 'intl';
42
+ export interface SenseNovaEndpoint {
43
+ id: EndpointId;
44
+ /** 显示名(中英文一致:网页端点本身没有语言)。 */
45
+ label: string;
46
+ /** OpenAI 兼容根地址(含 `/v1`)。 */
47
+ baseUrl: string;
48
+ }
49
+ /**
50
+ * 可选的上游端点。
51
+ *
52
+ * 商汤分两个独立的 API 站点,**key 不通用**(在哪个站注册的 key 只能打哪个站),
53
+ * 所以端点必须是用户自己的选择,不能靠「挨个试」自动判定 —— 拿 A 站的 key 打
54
+ * B 站只会得到 401,而池子会把这把本来好用的 key 标成失效。
55
+ *
56
+ * 默认 'cn' 是刻意的:老用户的 key 与配置都指向中国站,升级后行为必须不变。
57
+ */
58
+ export declare const ENDPOINTS: readonly SenseNovaEndpoint[];
59
+ export declare const DEFAULT_ENDPOINT_ID: EndpointId;
60
+ /** 端点 id 归一;认不出来时回落到默认端点。 */
61
+ export declare function isEndpointId(value: unknown): value is EndpointId;
62
+ /** 按 id 取端点定义;未知 id 回落到默认端点。 */
63
+ export declare function endpointFor(id: unknown): SenseNovaEndpoint;
64
+ /** 默认上游根地址(中国站)。 */
65
+ export declare const DEFAULT_BASE_URL: string;
66
+ /**
67
+ * 国际站(token.sensenova.ai)的内置基线目录 —— 与上游 `/v1/models` 一一对应,
68
+ * **不做任何筛选**:上游列了什么,这里就有什么。
69
+ *
70
+ * 2026-11-19 用真实国际站 key 实测的可用性(供参考,不决定是否展示):
71
+ *
72
+ * - `sensenova-6.8-flash` / `sensenova-6.8-flash-lite` —— 对话、流式、图片输入、
73
+ * 七档 `reasoning_effort` 全部 200。
74
+ * - `sensenova-6.7-flash-lite` —— `/v1/models` 声明 `output_modalities: ["text"]`(是多模态
75
+ * 对话模型),但本 key 对话请求多次返回 404 `model is not found`。仍然列出:
76
+ * 可能是该 key 的套餐/灰度差异,隐藏它会让有权限的用户也选不到。选中后上游会
77
+ * 如实报 404,在设置页取消勾选即可隐藏。
78
+ * - `sensenova-u1-fast` / `sensenova-u1.5-lite` —— 生图模型(`output_modalities: ["image"]`),
79
+ * 对话接口返回 404。同样列出,理由同上。
80
+ *
81
+ * 窗口沿用上游报的 262144:国际站**没有**国内站 issue #4 那种「报小 4 倍」的实测
82
+ * 证据,因此不设 `contextWindowOverridesUpstream`,以拿到 key 后刷新的上游值为准。
83
+ */
84
+ export declare const INTL_BUILTIN_MODELS: readonly SenseNovaModel[];
85
+ /** 该端点的内置基线目录。 */
86
+ export declare function builtinModelsFor(endpointId: unknown): readonly SenseNovaModel[];
87
+ /**
88
+ * 商汤 `reasoning_effort` 的合法拼写,按推理强度从弱到强排列。
89
+ *
90
+ * 上游的 400 原文把七档列得很全(`field ReasoningEffort invalid, should be one
91
+ * of: none, minimal, low, medium, high, xhigh, max`),但**每个模型实际接受的
92
+ * 子集不同**:`glm-5.3` 只认 `low / high / max`,发 `xhigh` 直接 400;而
93
+ * `glm-5.2`、`deepseek-v4-flash` 七档全收(issue #3 的逐模型实测矩阵)。
94
+ *
95
+ * 所以「哪几个值安全」不是全局属性 —— 一张全局映射表无论怎么调都会踩到某一头。
96
+ * 这里改成按模型维护词表,见 {@link MODEL_REASONING_EFFORTS}。
97
+ */
98
+ export declare const REASONING_EFFORTS: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
99
+ export type ReasoningEffort = (typeof REASONING_EFFORTS)[number];
100
+ /**
101
+ * DSH(pi-ai)侧的思考档位名,同样从弱到强。
102
+ *
103
+ * 与 {@link REASONING_EFFORTS} 一一对应,只差一个拼写:DSH 的 `off` 商汤
104
+ * 写作 `none`。
105
+ */
106
+ export declare const THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
107
+ export type ThinkingLevel = (typeof THINKING_LEVELS)[number];
108
+ /**
109
+ * 每个模型**实测**接受的上游 `reasoning_effort` 词表
110
+ * (issue #3,2026-11-14 对 `token.sensenova.cn` 逐个模型逐个档位实测,
111
+ * 撞 429 的格子已重试排除)。
112
+ *
113
+ * 「未确认」的档位**不写进来**:写漏顶多把这一档就近归位到合法档,写多了会让
114
+ * 整条链路每次都 400 —— 用户会直接无法使用该模型。
115
+ *
116
+ * 本表**按模型 id 查**,不依赖 {@link BUILTIN_MODELS}:`/v1/models` 动态目录里
117
+ * 新出现的模型(例如目前还不在基线目录里的 `glm-5.3`)只要这里补一行就生效。
118
+ *
119
+ * 没列在这里的模型(新上架、或本文写作时还未实测的)走
120
+ * {@link DEFAULT_REASONING_EFFORTS};补词表是唯一需要做的维护动作。
121
+ */
122
+ export declare const MODEL_REASONING_EFFORTS: Readonly<Record<string, readonly ReasoningEffort[]>>;
123
+ /**
124
+ * 未实测模型的保守词表:只用**所有**实测模型都接受的拼写。
125
+ *
126
+ * 七档里只有 `low` / `high` 是全员交集(`glm-5.3` 缺
127
+ * `none`/`minimal`/`medium`/`xhigh`,`kimi-k3` 缺 `max`,
128
+ * `deepseek-flash` 缺 `xhigh`),因此用它永远不会撞 400。
129
+ *
130
+ * 代价是新模型的上限被压到 `high`。这是有意的取舍:新模型上线时先把词表补进
131
+ * {@link MODEL_REASONING_EFFORTS},而不是先让用户吃一轮 400。
132
+ */
133
+ export declare const DEFAULT_REASONING_EFFORTS: readonly ReasoningEffort[];
134
+ /** 该模型的上游词表;未实测的模型返回保守默认表。 */
135
+ export declare function reasoningEffortsFor(modelId: string | undefined): readonly ReasoningEffort[];
136
+ /** 该模型是否有实测词表(决定清洗层敢不敢替调用方改档位)。 */
137
+ export declare function hasMeasuredReasoningEfforts(modelId: string | undefined): boolean;
138
+ /**
139
+ * 把一个 DSH 档位翻译成该模型接受的**上游拼写**(就近归位)。
140
+ *
141
+ * 只给 shim 清洗层用:那是「已经收到一个不该出现的档位、必须改成合法值」的场合。
142
+ * 注册给 pi-ai 的 `thinkingLevelMap` **不用**它 —— 声明能力时要如实写 `null`,
143
+ * 而不是替用户挑一个替代档(见 {@link thinkingLevelMapFor})。
144
+ *
145
+ * 规则(issue #3):
146
+ * 1. 词表里有同名档 → 直接用;
147
+ * 2. `xhigh` / `max` 属于「饱和区」:用户明确要了「极高 / 最高」,缺档时由
148
+ * 该模型最强的档承接,**不降级**(`glm-5.3` 的 `xhigh → max`)。`kimi-k3`
149
+ * 的 `max → xhigh` 是它本来就没有更高档,不是我们改主意;
150
+ * 3. 其余档(含 `off`)取词表内不超过它的最强档,没有更弱档就取最弱档 ——
151
+ * 于是无法关闭思考的模型(`glm-5.3`)把 `off` 落成 `low`。
152
+ */
153
+ export declare function thinkingEffortFor(modelId: string | undefined, level: ThinkingLevel): ReasoningEffort;
154
+ /**
155
+ * 该模型注册进 pi-ai 时用的 `thinkingLevelMap`。
156
+ *
157
+ * **只有实测支持的档位给出拼写,其余一律 `null`**。`null` 在 pi-ai / DSH 里的
158
+ * 含义就是「这个模型没有这一档」:`getSupportedThinkingLevels()` 会把它们从模型
159
+ * 选择器里摘掉,于是 `glm-5.3` 的思考档下拉只剩 **Low / High / Max**(+`Default`)。
160
+ *
161
+ * 为什么不像早先那样「把缺档就近归位」(`xhigh → max`):
162
+ * 那样 UI 上仍然有 7 档,用户选 `Xhigh` 实际发的是 `max`、选 `Off` 实际发的是
163
+ * `low` —— 看着能用,发出去的不是他选的东西,等于用 UI 撒谎。声明的能力应当
164
+ * 与实际能力一致;**兜住非法值**的活交给 shim 清洗层({@link coerceReasoningEffort}),
165
+ * 那里是真的收到了一个不该出现的值才动手。
166
+ *
167
+ * 键一定要写全(包括 `null`):pi-ai 对**缺失**键的处理是不对称的 —— 前五档视为
168
+ * 「支持、用 provider 默认」,`xhigh`/`max` 视为「不支持」;显式给 `null` 才确定。
169
+ */
170
+ export declare function thinkingLevelMapFor(modelId: string | undefined): Record<ThinkingLevel, ReasoningEffort | null>;
171
+ /** 清洗层的归一结果。 */
172
+ export interface ReasoningEffortCoercion {
173
+ /** 应发给上游的合法拼写;`undefined` 表示认不出来(调用方应摘掉该字段)。 */
174
+ value?: ReasoningEffort;
175
+ /** 是否改写了调用方传进来的值。 */
176
+ changed: boolean;
177
+ }
178
+ /**
179
+ * 把请求体里的 `reasoning_effort` 规整到该模型接受的词表内(shim 清洗层用)。
180
+ *
181
+ * 和注册层不同,这里**只动已知模型的已知问题**:
182
+ * * 未实测的模型原样放行 —— 我们没有它的词表,猜一个只会把「上游如实报错」
183
+ * 变成「上游收到了被我们悄悄改过的请求」,那正是 issue #2 批评过的做法;
184
+ * * 已知模型则按 {@link thinkingEffortFor} 就近归位,保证不发非法拼写。
185
+ *
186
+ * 认不出来的取值(拼写错误、将来新增的档位)返回 `value: undefined`,由调用方
187
+ * 摘掉字段 —— 不发垃圾值去撞 400。
188
+ */
189
+ export declare function coerceReasoningEffort(modelId: string | undefined, requested: string): ReasoningEffortCoercion;
190
+ /**
191
+ * 某些模型的采样参数只有**唯一合法值**(2026-11-17 实测)。
192
+ *
193
+ * `kimi-k3` 收到 `temperature: 0`(或任何非 1 的值)直接 400:
194
+ * `field Temperature invalid, only 1 is allowed for this model` —— 它根本
195
+ * 不提供「调低随机性」这个能力。既然唯一能发的值就是 1,清洗层直接兜住,
196
+ * 比让整轮对话失败要好;这不是篡改意图(没有别的值可选)。
197
+ */
198
+ export declare const MODEL_FIXED_PARAMS: Readonly<Record<string, {
199
+ temperature?: number;
200
+ }>>;
201
+ /** 该模型必须使用的固定采样参数;没有则返回 `undefined`。 */
202
+ export declare function fixedParamsFor(modelId: string | undefined): {
203
+ temperature?: number;
204
+ } | undefined;
29
205
  /**
30
206
  * 把 `/v1/models` 的原始响应解析成目录。
31
207
  *
32
208
  * 宽容解析:字段缺失就回落到基线/默认值,任何一条坏数据都不应该让整个目录失败。
209
+ *
210
+ * `baselines` 由调用方按**当前端点**给出:两个站的模型集合不同,拿中国站的基线
211
+ * 去解析国际站的响应,会让国际站缺失的模型也套上中国站的窗口/上限。
33
212
  */
34
- export declare function parseModelCatalog(payload: unknown): SenseNovaModel[];
213
+ export declare function parseModelCatalog(payload: unknown, baselines?: readonly SenseNovaModel[]): SenseNovaModel[];
35
214
  export type UpstreamErrorKind = 'rate_limit' | 'invalid_credential' | 'not_found' | 'server' | 'client';
36
215
  export interface ClassifiedError {
37
216
  kind: UpstreamErrorKind;
@@ -54,6 +233,9 @@ export declare function extractErrorMessage(body: string): string;
54
233
  *
55
234
  * 关键判定(实测商汤行为):
56
235
  * - 429 `ModelAccountTpmRateLimitExceeded` → 限流,**换 key 重试**。
236
+ * - 401 `{"code":16,"message":"Forbidden"}` → 该 key 不属于**这个端点**。实测国际站
237
+ * key 打中国站 `token.sensenova.cn` 就是这条;两个站的 key 互不通用,因此用户
238
+ * 选错端点时应当直接看到鉴权失败,而不是被当成「限流」无限重试。
57
239
  * - 401/403 `permission_denied_error` (code 7) → 该 key 对该模型无权限。
58
240
  * 注意:这**不代表 key 失效**,只代表这个模型不在当前套餐里;因此归类为
59
241
  * `client`(不冷却、不换 key 空转),而不是 `invalid_credential`。