dsh-sub2api 0.2.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.1
4
+
5
+ - Declare reasoning efforts so the picker actually offers a thinking control.
6
+ The host only accepts an effort a model has declared, and the adapter declared
7
+ none, so the selector was empty. Known families (deepseek-v4/flash/reasoner,
8
+ gpt-5, o3/o4) now expose minimal/low/medium/high, the chosen level is merged
9
+ into the request body as `reasoning_effort`, and `reasoningModels` opts other
10
+ ids in without guessing at upstreams that would reject the field.
11
+
3
12
  ## 0.2.0 — feature complete
4
13
 
5
14
  - **每模型上下文修正**:面板里点容量数字即可手填,存在面板状态文件里,优先于上游声明。
package/README.md CHANGED
@@ -98,6 +98,22 @@ dsh plugin add dsh-sub2api
98
98
 
99
99
  ---
100
100
 
101
+ ## 思考等级
102
+
103
+ 模型的思考档位由适配器**声明**,宿主只认声明过的 id——没声明就完全没有这个控件。插件对下列家族声明四档 `reasoning_effort`(极低 / 低 / 中 / 高):
104
+
105
+ `deepseek-v4*`、`deepseek-flash`、`deepseek-reasoner`、`deepseek-r1`、`gpt-5*`、`o3*`、`o4*`
106
+
107
+ 其它模型默认不给档位,因为无法确认上游认不认这个字段(认不出会忽略、也可能直接 400)。要让某个模型也出现档位,在配置里加:
108
+
109
+ ```yaml
110
+ llm-sub2api:
111
+ reasoningModels: ["glm-5", "kimi-k3"] # 按 id 片段匹配
112
+ defaultReasoningEffort: medium # 可选,留空则用上游默认
113
+ ```
114
+
115
+ 选中的档位会以 `{"reasoning_effort": "<id>"}` 合并进请求体,和采样参数走同一条路径。面板的模型列表里,支持档位的模型会标注「思考 4 档」。
116
+
101
117
  ## 命令与工具
102
118
 
103
119
  ```
package/lib/adapter.js CHANGED
@@ -136,6 +136,16 @@ export class Sub2ApiAdapter extends LlmAdapter {
136
136
  if (known?.contextWindow !== undefined) resolved.context = { contextWindow: known.contextWindow };
137
137
  if (known?.maxTokens !== undefined) resolved.defaultMaxTokens = known.maxTokens;
138
138
  if (known?.vision === true) resolved.inputModalities = ["text", "image"];
139
+
140
+ // Declaring the levels is the only way the picker offers a thinking control:
141
+ // the host rejects any effort a model has not declared.
142
+ const reasoning = this.deps.catalog.reasoningFor(model);
143
+ if (reasoning !== undefined) {
144
+ resolved.reasoning = {
145
+ efforts: reasoning.efforts.map((effort) => ({ id: effort.id, name: effort.name })),
146
+ ...(reasoning.defaultEffort === undefined ? {} : { defaultEffort: reasoning.defaultEffort }),
147
+ };
148
+ }
139
149
  return resolved;
140
150
  }
141
151
 
@@ -151,12 +161,21 @@ export class Sub2ApiAdapter extends LlmAdapter {
151
161
  }
152
162
 
153
163
  const model = route.models.find((entry) => entry.id === options.model);
164
+
165
+ // The transport forwards `sampling.body` verbatim, so the chosen level's
166
+ // fields have to land there; the host only validates the id.
167
+ const sampling = mergeSampling(route.sampling, model?.sampling, options);
168
+ const effort = selectedEffort(model, options.reasoningEffort);
169
+ if (effort !== undefined) {
170
+ sampling.body = { ...(sampling.body ?? {}), ...effort.body };
171
+ }
172
+
154
173
  /** @type {any} */
155
174
  const call = {
156
175
  options,
157
176
  route,
158
177
  model,
159
- sampling: mergeSampling(route.sampling, model?.sampling, options),
178
+ sampling,
160
179
  headers: safeAttributionHeaders(),
161
180
  };
162
181
 
@@ -186,6 +205,19 @@ export function mergeSampling(routeSampling, modelSampling, options) {
186
205
  return merged;
187
206
  }
188
207
 
208
+ /**
209
+ * The level a request selected, matched by id against the model's declared
210
+ * levels. An unknown id yields undefined rather than guessing.
211
+ * @param {any} model
212
+ * @param {unknown} id
213
+ */
214
+ export function selectedEffort(model, id) {
215
+ if (id === undefined || id === null) return undefined;
216
+ const levels = model?.reasoningLevels;
217
+ if (!Array.isArray(levels)) return undefined;
218
+ return levels.find((level) => String(level.id) === String(id));
219
+ }
220
+
189
221
  /** Read an optional host service without letting an absent one abort the call. */
190
222
  function optionalService(ctx, name) {
191
223
  try {
package/lib/client.js CHANGED
@@ -659,6 +659,10 @@ window.__ModuleLoader__.load({
659
659
  color: current.contextSource === "default" ? C.warn : C.muted, fontSize: 11.5,
660
660
  },
661
661
  }, contextBadge(current) ?? "设置"),
662
+ Array.isArray(current.reasoningEfforts)
663
+ ? h("span", { style: { ...T.hint, whiteSpace: "nowrap" } },
664
+ "思考 " + current.reasoningEfforts.length + " 档")
665
+ : null,
662
666
  shown.some((m) => m.id === model.id && m.vision) ? h("span", { style: T.hint }, "图片") : null,
663
667
  );
664
668
  }
package/lib/config.js CHANGED
@@ -70,6 +70,8 @@ export function resolveConfig(config) {
70
70
  visibleModels: toStringArray(field(config, "visibleModels", [])),
71
71
  contextWindow: toPositiveInt(field(config, "contextWindow", undefined)),
72
72
  defaultContextWindow: toPositiveInt(field(config, "defaultContextWindow", undefined)),
73
+ reasoningModels: toStringArray(field(config, "reasoningModels", [])),
74
+ defaultReasoningEffort: String(field(config, "defaultReasoningEffort", "")).trim() || undefined,
73
75
  autoProvision: field(config, "autoProvision", true) !== false,
74
76
  announceToAgent: field(config, "announceToAgent", true) !== false,
75
77
  };
package/lib/constants.js CHANGED
@@ -66,6 +66,34 @@ export const KNOWN_CONTEXT = [
66
66
  { match: "deepseek-flash", contextWindow: 1048576 },
67
67
  ];
68
68
 
69
+ /**
70
+ * The four selectable reasoning efforts of an OpenAI-compatible endpoint, from
71
+ * least to greatest. `body` is merged into the request when one is selected.
72
+ */
73
+ export const STANDARD_EFFORTS = [
74
+ { id: "minimal", name: "极低", body: { reasoning_effort: "minimal" } },
75
+ { id: "low", name: "低", body: { reasoning_effort: "low" } },
76
+ { id: "medium", name: "中", body: { reasoning_effort: "medium" } },
77
+ { id: "high", name: "高", body: { reasoning_effort: "high" } },
78
+ ];
79
+
80
+ /**
81
+ * Model id fragments whose upstream accepts `reasoning_effort`.
82
+ *
83
+ * Only families with a documented or observed mapping belong here: an endpoint
84
+ * that does not know the field either ignores it (the selector then lies) or
85
+ * rejects the request. Anything else can be opted in through `reasoningModels`.
86
+ */
87
+ export const REASONING_HINTS = [
88
+ "deepseek-v4",
89
+ "deepseek-flash",
90
+ "deepseek-reasoner",
91
+ "deepseek-r1",
92
+ "gpt-5",
93
+ "o3",
94
+ "o4",
95
+ ];
96
+
69
97
  /** Model id fragments that mark an image-capable model when the endpoint says nothing. */
70
98
  export const VISION_HINTS = [
71
99
  "gpt-4o",
package/lib/index.js CHANGED
@@ -90,6 +90,8 @@ export function apply(ctx, rawConfig = {}) {
90
90
  contextOverride: (id) => panel.contextOverride(id),
91
91
  contextWindow: () => cfg().contextWindow,
92
92
  defaultContextWindow: () => cfg().defaultContextWindow,
93
+ reasoningModels: () => cfg().reasoningModels,
94
+ defaultReasoningEffort: () => cfg().defaultReasoningEffort,
93
95
  apiKey: () => session.apiKey(),
94
96
  logger,
95
97
  });
package/lib/schema.js CHANGED
@@ -32,6 +32,8 @@ export const Config = z.object({
32
32
  visibleModels: z.array(z.string()).description("只在这些模型 id 中显示;留空显示全部").volatile(),
33
33
  contextWindow: count("强制覆盖所有模型的上下文窗口;留空则逐模型解析"),
34
34
  defaultContextWindow: count("上游没有声明上下文窗口时使用的兜底值(默认 128000)"),
35
+ reasoningModels: z.array(z.string()).description("额外声明支持思考等级的模型 id 片段").volatile(),
36
+ defaultReasoningEffort: text("", "默认思考等级(minimal/low/medium/high);留空由上游决定"),
35
37
  showSidebarQuota: z.boolean().default(false).description("在侧边栏显示余额卡片").volatile(),
36
38
  autoProvision: z.boolean().default(true).description("登录后自动创建并保存密钥").volatile(),
37
39
  announceToAgent: z.boolean().default(true).description("向 agent 注入插件说明").volatile(),
@@ -10,7 +10,14 @@
10
10
 
11
11
  import { mkdir, readFile, writeFile } from "node:fs/promises";
12
12
  import { dirname } from "node:path";
13
- import { CATALOG_TTL_MS, DEFAULT_CONTEXT_WINDOW, KNOWN_CONTEXT, VISION_HINTS } from "../constants.js";
13
+ import {
14
+ CATALOG_TTL_MS,
15
+ DEFAULT_CONTEXT_WINDOW,
16
+ KNOWN_CONTEXT,
17
+ REASONING_HINTS,
18
+ STANDARD_EFFORTS,
19
+ VISION_HINTS,
20
+ } from "../constants.js";
14
21
  import { Sub2ApiError } from "../util.js";
15
22
 
16
23
  /**
@@ -149,6 +156,30 @@ export class ModelCatalog {
149
156
  return this.deps.selection?.() ?? [];
150
157
  }
151
158
 
159
+ /**
160
+ * Reasoning levels this model accepts, when the upstream is known to
161
+ * understand `reasoning_effort`. Declaring none is what makes the selector
162
+ * offer no thinking control at all.
163
+ * @param {string} id
164
+ * @returns {{efforts: Array<{id: string, name: string, body: Record<string, unknown>}>, defaultEffort?: string} | undefined}
165
+ */
166
+ reasoningFor(id) {
167
+ const lower = String(id).toLowerCase();
168
+ const forced = (this.deps.reasoningModels?.() ?? []).some(
169
+ (entry) => entry === id || lower.includes(String(entry).toLowerCase()),
170
+ );
171
+ const known = REASONING_HINTS.some((hint) => lower.includes(hint));
172
+ if (!forced && !known) return undefined;
173
+
174
+ const efforts = STANDARD_EFFORTS.map((effort) => ({
175
+ id: effort.id,
176
+ name: effort.name,
177
+ body: { ...effort.body },
178
+ }));
179
+ const preferred = this.deps.defaultReasoningEffort?.();
180
+ return preferred === undefined ? { efforts } : { efforts, defaultEffort: preferred };
181
+ }
182
+
152
183
  /**
153
184
  * Where a model's capacity came from, in precedence order.
154
185
  * @param {ModelRecord} model
@@ -201,6 +232,11 @@ export class ModelCatalog {
201
232
  if (model.contextWindow !== undefined) entry.contextWindow = model.contextWindow;
202
233
  if (model.maxTokens !== undefined) entry.maxTokens = model.maxTokens;
203
234
  if (model.vision === true) entry.vision = true;
235
+ const reasoning = this.reasoningFor(model.id);
236
+ if (reasoning !== undefined) {
237
+ entry.reasoningLevels = reasoning.efforts;
238
+ if (reasoning.defaultEffort !== undefined) entry.defaultReasoning = reasoning.defaultEffort;
239
+ }
204
240
  return entry;
205
241
  });
206
242
  }
@@ -235,6 +271,7 @@ export class ModelCatalog {
235
271
  contextWindow: model.contextWindow ?? null,
236
272
  contextSource: model.contextSource ?? null,
237
273
  maxTokens: model.maxTokens ?? null,
274
+ reasoningEfforts: this.reasoningFor(model.id)?.efforts.map((e) => e.name) ?? null,
238
275
  vision: model.vision === true,
239
276
  ownedBy: model.ownedBy ?? null,
240
277
  })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sub2api",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Sub2API provider for DeepSeek Harness: zero-friction signup, auto-provisioned API key, upstream model sync, balance and recharge",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-only",