mslxdff 0.1.170 → 0.1.171

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.
Files changed (107) hide show
  1. package/bin/mslxdff.js +3 -3
  2. package/docs/cli_help_mini.md +143 -0
  3. package/package.json +1 -1
  4. package/src/anthropic/count-tokens.js +39 -0
  5. package/src/anthropic/translate.js +20 -41
  6. package/src/auto.js +254 -254
  7. package/src/bench/cline-bench.js +42 -42
  8. package/src/bench/probe.js +70 -70
  9. package/src/bench/report.js +162 -162
  10. package/src/bench/runner.js +77 -77
  11. package/src/bench/via-probe.js +124 -124
  12. package/src/bench/via-routes.js +87 -87
  13. package/src/bench/workbuddy-bench.js +54 -54
  14. package/src/chat/engine.js +160 -160
  15. package/src/chat/gateway.js +163 -163
  16. package/src/chat/orchestrator.js +234 -234
  17. package/src/chat/prompt.js +70 -70
  18. package/src/chat/repl.js +88 -88
  19. package/src/chat/terminal.js +135 -135
  20. package/src/chat/tools.js +306 -306
  21. package/src/chat-pipeline/index.js +131 -131
  22. package/src/chat-pipeline/policy.js +76 -76
  23. package/src/cli/commands/group.js +249 -249
  24. package/src/cli/commands/model/picks.js +50 -50
  25. package/src/cli/commands/provider/bench-via.js +247 -247
  26. package/src/cli/commands/provider/bench.js +141 -141
  27. package/src/cli/commands/provider/index.js +133 -133
  28. package/src/cli/commands/provider/models.js +145 -145
  29. package/src/cli/commands/provider/qwenwork-login.js +119 -119
  30. package/src/cli/commands/sync.js +310 -310
  31. package/src/cli/status.js +279 -279
  32. package/src/daemon.js +112 -112
  33. package/src/model-capabilities/enrich.js +86 -86
  34. package/src/model-capabilities/index.js +183 -183
  35. package/src/model-capabilities/parse.js +70 -70
  36. package/src/models.js +225 -225
  37. package/src/providers/AGENTS.md +49 -0
  38. package/src/providers/cline/auth.js +228 -228
  39. package/src/providers/cline/chat.js +307 -307
  40. package/src/providers/cline.js +2 -2
  41. package/src/providers/codearts/concurrency.js +34 -0
  42. package/src/providers/codearts/index.js +11 -3
  43. package/src/providers/globalqwenwork/cosy.js +123 -123
  44. package/src/providers/globalqwenwork/crypto.js +218 -218
  45. package/src/providers/globalqwenwork/http.js +20 -20
  46. package/src/providers/globalqwenwork/payload.js +4 -2
  47. package/src/providers/globalqwenwork/rsa.js +54 -54
  48. package/src/providers/globalqwenwork/sse.js +268 -268
  49. package/src/providers/globalqwenwork/stream.js +130 -130
  50. package/src/providers/globalqwenwork/upstream.js +122 -122
  51. package/src/providers/keyring.js +60 -60
  52. package/src/providers/qoder/chat.js +203 -200
  53. package/src/providers/qoder/index.js +249 -249
  54. package/src/providers/qoder/sse.js +145 -145
  55. package/src/providers/qwenwork/account-store.js +133 -133
  56. package/src/providers/qwenwork/constants.js +67 -67
  57. package/src/providers/qwenwork/cosy.js +120 -120
  58. package/src/providers/qwenwork/crypto.js +218 -218
  59. package/src/providers/qwenwork/http.js +20 -20
  60. package/src/providers/qwenwork/index.js +327 -327
  61. package/src/providers/qwenwork/payload.js +144 -142
  62. package/src/providers/qwenwork/rsa.js +54 -54
  63. package/src/providers/qwenwork/sse.js +268 -268
  64. package/src/providers/qwenwork/stream.js +130 -130
  65. package/src/providers/qwenwork/upstream.js +120 -120
  66. package/src/providers/qwenwork.js +1 -1
  67. package/src/providers/raccoon/chat.js +10 -5
  68. package/src/providers/raccoon/const.js +4 -4
  69. package/src/providers/registry.js +79 -79
  70. package/src/providers/workbuddy/chat.js +248 -248
  71. package/src/providers/workbuddy/payload.js +16 -7
  72. package/src/providers/workbuddy/reshape.js +152 -152
  73. package/src/providers/workbuddy.js +2 -2
  74. package/src/providers/zcode/chat.js +7 -0
  75. package/src/reasoning.js +32 -32
  76. package/src/responses/translate.js +4 -0
  77. package/src/routes/AGENTS.md +37 -0
  78. package/src/routes/chat/exhausted-handler.js +5 -0
  79. package/src/routes/chat/gateway.js +46 -46
  80. package/src/routes/chat/relay-pipeline.js +294 -291
  81. package/src/routes/chat/via-route-handler.js +146 -146
  82. package/src/routes/hedge.js +255 -255
  83. package/src/routes/messages-route.js +1 -1
  84. package/src/routes/models-route.js +167 -167
  85. package/src/routes/peers.js +273 -273
  86. package/src/routes/stream-scan.js +47 -21
  87. package/src/routes/stream.js +385 -385
  88. package/src/runtime/bootstrap.js +50 -50
  89. package/src/runtime/provider-gate.js +36 -36
  90. package/src/runtime/providers-setup.js +165 -165
  91. package/src/server.js +69 -69
  92. package/src/state/schemas/allowlist.js +92 -92
  93. package/src/sync-opencode.js +280 -280
  94. package/src/talk-full.js +1 -0
  95. package/src/talk-log.js +3 -2
  96. package/src/thinking-effort.js +67 -0
  97. package/src/transport/index.js +244 -244
  98. package/src/transport/pool.js +56 -56
  99. package/src/transport/retry.js +24 -24
  100. package/src/transport/sse.js +93 -93
  101. package/src/upstream-engine/sdk/convert.js +6 -0
  102. package/src/upstream-probe/display.js +52 -52
  103. package/src/upstream-probe/probe.js +49 -49
  104. package/src/upstream-probe/rotate.js +110 -110
  105. package/src/upstream-probe/start.js +45 -45
  106. package/src/upstream-responses.js +5 -0
  107. package/src/upstream.js +289 -289
@@ -1,183 +1,183 @@
1
- // 模型能力目录服务(opencode 官方同源 models.dev):fetch + 磁盘缓存 + TTL + staleness 降级
2
- // 源:https://models.opencode.ai/api.json(opencode core models-dev.ts:160 同款;备选 https://models.dev/api.json)
3
- // 形状:{ [providerId]: { models: { [modelId]: raw } } };mslxdff 裸 id 归 opencode,`prov/id` 前缀路由到对应 provider
4
- import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
- import { homedir } from "node:os";
6
- import { dirname, join } from "node:path";
7
- import { normalizeProviderModels, normalizeWorkbuddyCaps } from "./parse.js";
8
- import { compatFetch } from "../compat.js";
9
-
10
- export const DEFAULT_SOURCE_URL = "https://models.opencode.ai/api.json";
11
-
12
- export function sourceUrl() {
13
- const raw = process.env.MSLXDFF_MODELS_DEV_URL;
14
- return raw && String(raw).trim() ? String(raw).trim() : DEFAULT_SOURCE_URL;
15
- }
16
-
17
- export function ttlMs() {
18
- const n = Number(process.env.MSLXDFF_MODELS_DEV_TTL_MS);
19
- return Number.isInteger(n) && n >= 0 ? n : 86_400_000; // 默认 24h
20
- }
21
-
22
- export function createCapabilitiesService({
23
- fetchImpl = compatFetch,
24
- cacheFile = "",
25
- ttlMs: ttl = ttlMs(),
26
- url = sourceUrl(),
27
- now = Date.now,
28
- } = {}) {
29
- let raw = null; // 原始目录(全 provider)
30
- let capsIndex = new Map(); // providerId -> { modelId -> caps }
31
- let npmIndex = new Map(); // opencode 裸 modelId -> provider.npm(responses 判定用;null = 继承默认)
32
- let loadedAt = 0;
33
- let inflight = null;
34
-
35
- function buildIndex(data) {
36
- const idx = new Map();
37
- const npm = new Map();
38
- for (const [pid, p] of Object.entries(data || {})) {
39
- if (!p || typeof p !== "object") continue;
40
- const caps = normalizeProviderModels(p.models || {});
41
- idx.set(pid, caps);
42
- if (String(pid).toLowerCase() === "opencode") {
43
- for (const [mid, c] of Object.entries(caps)) npm.set(mid, c.npm ?? null);
44
- }
45
- }
46
- npmIndex = npm;
47
- return idx;
48
- }
49
-
50
- function readCache() {
51
- if (!cacheFile) return null;
52
- try { return JSON.parse(readFileSync(cacheFile, "utf8")); } catch { return null; }
53
- }
54
-
55
- function writeCache(data) {
56
- if (!cacheFile || !data) return;
57
- try {
58
- mkdirSync(dirname(cacheFile), { recursive: true });
59
- writeFileSync(cacheFile, JSON.stringify(data));
60
- } catch { /* 缓存失败不致命 */ }
61
- }
62
-
63
- async function fetchFresh() {
64
- const res = await fetchImpl(url, { headers: { Accept: "application/json" } });
65
- if (!res?.ok) throw new Error(`models.dev fetch ${res?.status || "network"}`);
66
- return res.json();
67
- }
68
-
69
- // ready:缓存新鲜直接用;否则拉新;失败回退旧缓存(含磁盘),完全无数据才抛
70
- async function ready() {
71
- const t = now();
72
- if (raw && t - loadedAt < ttl) return;
73
- if (inflight) return inflight;
74
- inflight = (async () => {
75
- try {
76
- const data = await fetchFresh();
77
- raw = data;
78
- capsIndex = buildIndex(data);
79
- loadedAt = t;
80
- writeCache(data);
81
- } catch (e) {
82
- if (raw) return; // 内存还有旧的,继续用
83
- const disk = readCache();
84
- if (disk) {
85
- raw = disk;
86
- capsIndex = buildIndex(disk);
87
- loadedAt = t; // 视作刚加载,避免每请求都重试打上游
88
- return;
89
- }
90
- throw e;
91
- } finally {
92
- inflight = null;
93
- }
94
- })();
95
- return inflight;
96
- }
97
-
98
- function capsFor(pid) {
99
- return capsIndex.get(pid) || null;
100
- }
101
-
102
- function get(providerId, modelId) {
103
- const pid = String(providerId || "opencode").toLowerCase();
104
- const mid = String(modelId || "");
105
- const map = capsFor(pid);
106
- if (!map) return null;
107
- return map[mid] || null;
108
- }
109
-
110
- function list(providerId) {
111
- const pid = String(providerId || "opencode").toLowerCase();
112
- const map = capsFor(pid);
113
- if (!map) return [];
114
- return Object.entries(map).map(([id, capabilities]) => ({ id, capabilities }));
115
- }
116
-
117
- function providers() {
118
- return [...capsIndex.keys()].sort();
119
- }
120
- // readyWarm:仅用内存/磁盘缓存热身,绝不网络请求。/models 富化用它避免冷启动阻塞;
121
- // 冷缓存时后台拉新(不 await),下次请求即富化。
122
- async function readyWarm() {
123
- const t = now();
124
- if (raw && t - loadedAt < ttl) return true;
125
- const disk = readCache();
126
- if (disk) {
127
- raw = disk;
128
- capsIndex = buildIndex(disk);
129
- loadedAt = t;
130
- return true;
131
- }
132
- ready().catch(() => {}); // 后台拉新,失败静默(/models 原样降级)
133
- return false;
134
- }
135
- return { ready, readyWarm, get, list, providers, npmIndex: () => new Map(npmIndex) };
136
- }
137
-
138
- // 模块级单例:HTTP handler 懒加载,测试 _reset 后注入
139
- let _global = null;
140
- export function globalCapabilities() {
141
- if (!_global) _global = createCapabilitiesService({ cacheFile: defaultCacheFile() });
142
- return _global;
143
- }
144
- export function _resetGlobalCapabilities() { _global = null; }
145
- // 缓存落盘位置:MSLXDFF_MODELS_DEV_CACHE 覆盖 > ~/.config/mslxdff/models-dev.json(与 state 同目录)
146
- function defaultCacheFile() {
147
- const override = process.env.MSLXDFF_MODELS_DEV_CACHE;
148
- if (override && String(override).trim()) return String(override).trim();
149
- return join(homedir(), ".config", "mslxdff", "models-dev.json");
150
- }
151
-
152
- // workbuddy 动态源:从聚合模型服务(models.get(),带 10min 上游缓存)拉 workbuddy/ 前缀条目
153
- // → 统一 caps 形状 map({ rawId -> caps })。上游原生字段 first-party 最准,不走 models.dev。
154
- export function workbuddyCapsFromModels(getModels, normalizeFn) {
155
- const normalize = normalizeFn || ((m) => normalizeWorkbuddyCaps(m.id, m));
156
- return async () => {
157
- const agg = await getModels();
158
- const all = Array.isArray(agg?.data) ? agg.data : [];
159
- const map = {};
160
- for (const entry of all) {
161
- const id = String(entry?.id || "");
162
- if (!id.toLowerCase().startsWith("workbuddy/")) continue;
163
- const raw = id.slice("workbuddy/".length);
164
- if (!raw) continue;
165
- map[raw] = normalize(entry);
166
- }
167
- return map;
168
- };
169
- }
170
-
171
- // workbuddy provider 单例(直连上游 listModels 自带 10min 缓存):HTTP handler 与
172
- // -setto opencode 能力注入共享同一个实例,避免双份连接池/缓存。
173
- let _wbProv = null;
174
- export function _resetWorkbuddyProv() { _wbProv = null; }
175
- export async function workbuddyAllModels() {
176
- if (!_wbProv) {
177
- const { createWorkbuddyProvider } = await import("../providers/workbuddy.js");
178
- const { defaultStateFile } = await import("../state.js");
179
- _wbProv = createWorkbuddyProvider({ file: defaultStateFile() });
180
- }
181
- const list = await _wbProv.listModels();
182
- return { object: "list", data: Array.isArray(list) ? list : [] };
183
- }
1
+ // 模型能力目录服务(opencode 官方同源 models.dev):fetch + 磁盘缓存 + TTL + staleness 降级
2
+ // 源:https://models.opencode.ai/api.json(opencode core models-dev.ts:160 同款;备选 https://models.dev/api.json)
3
+ // 形状:{ [providerId]: { models: { [modelId]: raw } } };mslxdff 裸 id 归 opencode,`prov/id` 前缀路由到对应 provider
4
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
+ import { homedir } from "node:os";
6
+ import { dirname, join } from "node:path";
7
+ import { normalizeProviderModels, normalizeWorkbuddyCaps } from "./parse.js";
8
+ import { compatFetch } from "../compat.js";
9
+
10
+ export const DEFAULT_SOURCE_URL = "https://models.opencode.ai/api.json";
11
+
12
+ export function sourceUrl() {
13
+ const raw = process.env.MSLXDFF_MODELS_DEV_URL;
14
+ return raw && String(raw).trim() ? String(raw).trim() : DEFAULT_SOURCE_URL;
15
+ }
16
+
17
+ export function ttlMs() {
18
+ const n = Number(process.env.MSLXDFF_MODELS_DEV_TTL_MS);
19
+ return Number.isInteger(n) && n >= 0 ? n : 86_400_000; // 默认 24h
20
+ }
21
+
22
+ export function createCapabilitiesService({
23
+ fetchImpl = compatFetch,
24
+ cacheFile = "",
25
+ ttlMs: ttl = ttlMs(),
26
+ url = sourceUrl(),
27
+ now = Date.now,
28
+ } = {}) {
29
+ let raw = null; // 原始目录(全 provider)
30
+ let capsIndex = new Map(); // providerId -> { modelId -> caps }
31
+ let npmIndex = new Map(); // opencode 裸 modelId -> provider.npm(responses 判定用;null = 继承默认)
32
+ let loadedAt = 0;
33
+ let inflight = null;
34
+
35
+ function buildIndex(data) {
36
+ const idx = new Map();
37
+ const npm = new Map();
38
+ for (const [pid, p] of Object.entries(data || {})) {
39
+ if (!p || typeof p !== "object") continue;
40
+ const caps = normalizeProviderModels(p.models || {});
41
+ idx.set(pid, caps);
42
+ if (String(pid).toLowerCase() === "opencode") {
43
+ for (const [mid, c] of Object.entries(caps)) npm.set(mid, c.npm ?? null);
44
+ }
45
+ }
46
+ npmIndex = npm;
47
+ return idx;
48
+ }
49
+
50
+ function readCache() {
51
+ if (!cacheFile) return null;
52
+ try { return JSON.parse(readFileSync(cacheFile, "utf8")); } catch { return null; }
53
+ }
54
+
55
+ function writeCache(data) {
56
+ if (!cacheFile || !data) return;
57
+ try {
58
+ mkdirSync(dirname(cacheFile), { recursive: true });
59
+ writeFileSync(cacheFile, JSON.stringify(data));
60
+ } catch { /* 缓存失败不致命 */ }
61
+ }
62
+
63
+ async function fetchFresh() {
64
+ const res = await fetchImpl(url, { headers: { Accept: "application/json" } });
65
+ if (!res?.ok) throw new Error(`models.dev fetch ${res?.status || "network"}`);
66
+ return res.json();
67
+ }
68
+
69
+ // ready:缓存新鲜直接用;否则拉新;失败回退旧缓存(含磁盘),完全无数据才抛
70
+ async function ready() {
71
+ const t = now();
72
+ if (raw && t - loadedAt < ttl) return;
73
+ if (inflight) return inflight;
74
+ inflight = (async () => {
75
+ try {
76
+ const data = await fetchFresh();
77
+ raw = data;
78
+ capsIndex = buildIndex(data);
79
+ loadedAt = t;
80
+ writeCache(data);
81
+ } catch (e) {
82
+ if (raw) return; // 内存还有旧的,继续用
83
+ const disk = readCache();
84
+ if (disk) {
85
+ raw = disk;
86
+ capsIndex = buildIndex(disk);
87
+ loadedAt = t; // 视作刚加载,避免每请求都重试打上游
88
+ return;
89
+ }
90
+ throw e;
91
+ } finally {
92
+ inflight = null;
93
+ }
94
+ })();
95
+ return inflight;
96
+ }
97
+
98
+ function capsFor(pid) {
99
+ return capsIndex.get(pid) || null;
100
+ }
101
+
102
+ function get(providerId, modelId) {
103
+ const pid = String(providerId || "opencode").toLowerCase();
104
+ const mid = String(modelId || "");
105
+ const map = capsFor(pid);
106
+ if (!map) return null;
107
+ return map[mid] || null;
108
+ }
109
+
110
+ function list(providerId) {
111
+ const pid = String(providerId || "opencode").toLowerCase();
112
+ const map = capsFor(pid);
113
+ if (!map) return [];
114
+ return Object.entries(map).map(([id, capabilities]) => ({ id, capabilities }));
115
+ }
116
+
117
+ function providers() {
118
+ return [...capsIndex.keys()].sort();
119
+ }
120
+ // readyWarm:仅用内存/磁盘缓存热身,绝不网络请求。/models 富化用它避免冷启动阻塞;
121
+ // 冷缓存时后台拉新(不 await),下次请求即富化。
122
+ async function readyWarm() {
123
+ const t = now();
124
+ if (raw && t - loadedAt < ttl) return true;
125
+ const disk = readCache();
126
+ if (disk) {
127
+ raw = disk;
128
+ capsIndex = buildIndex(disk);
129
+ loadedAt = t;
130
+ return true;
131
+ }
132
+ ready().catch(() => {}); // 后台拉新,失败静默(/models 原样降级)
133
+ return false;
134
+ }
135
+ return { ready, readyWarm, get, list, providers, npmIndex: () => new Map(npmIndex) };
136
+ }
137
+
138
+ // 模块级单例:HTTP handler 懒加载,测试 _reset 后注入
139
+ let _global = null;
140
+ export function globalCapabilities() {
141
+ if (!_global) _global = createCapabilitiesService({ cacheFile: defaultCacheFile() });
142
+ return _global;
143
+ }
144
+ export function _resetGlobalCapabilities() { _global = null; }
145
+ // 缓存落盘位置:MSLXDFF_MODELS_DEV_CACHE 覆盖 > ~/.config/mslxdff/models-dev.json(与 state 同目录)
146
+ function defaultCacheFile() {
147
+ const override = process.env.MSLXDFF_MODELS_DEV_CACHE;
148
+ if (override && String(override).trim()) return String(override).trim();
149
+ return join(homedir(), ".config", "mslxdff", "models-dev.json");
150
+ }
151
+
152
+ // workbuddy 动态源:从聚合模型服务(models.get(),带 10min 上游缓存)拉 workbuddy/ 前缀条目
153
+ // → 统一 caps 形状 map({ rawId -> caps })。上游原生字段 first-party 最准,不走 models.dev。
154
+ export function workbuddyCapsFromModels(getModels, normalizeFn) {
155
+ const normalize = normalizeFn || ((m) => normalizeWorkbuddyCaps(m.id, m));
156
+ return async () => {
157
+ const agg = await getModels();
158
+ const all = Array.isArray(agg?.data) ? agg.data : [];
159
+ const map = {};
160
+ for (const entry of all) {
161
+ const id = String(entry?.id || "");
162
+ if (!id.toLowerCase().startsWith("workbuddy/")) continue;
163
+ const raw = id.slice("workbuddy/".length);
164
+ if (!raw) continue;
165
+ map[raw] = normalize(entry);
166
+ }
167
+ return map;
168
+ };
169
+ }
170
+
171
+ // workbuddy provider 单例(直连上游 listModels 自带 10min 缓存):HTTP handler 与
172
+ // -setto opencode 能力注入共享同一个实例,避免双份连接池/缓存。
173
+ let _wbProv = null;
174
+ export function _resetWorkbuddyProv() { _wbProv = null; }
175
+ export async function workbuddyAllModels() {
176
+ if (!_wbProv) {
177
+ const { createWorkbuddyProvider } = await import("../providers/workbuddy.js");
178
+ const { defaultStateFile } = await import("../state.js");
179
+ _wbProv = createWorkbuddyProvider({ file: defaultStateFile() });
180
+ }
181
+ const list = await _wbProv.listModels();
182
+ return { object: "list", data: Array.isArray(list) ? list : [] };
183
+ }
@@ -1,70 +1,70 @@
1
- // models.dev 能力目录 → mslxdff 能力形状的纯函数解析层(无 IO,测试接缝 S1)
2
- // 源数据形态(实测 models.opencode.ai/api.json 2026-09-11):
3
- // reasoning_options: [{type:"effort",values:["low","medium","high","max"]} | {type:"toggle"} | {type:"budget_tokens",min}]
4
- // modalities.input 含 "image" 即可读图;limit.context/output;cost.input/output 为 $/M tokens
5
- export function normalizeModelCaps(_id, m) {
6
- const opts = Array.isArray(m?.reasoning_options) ? m.reasoning_options : [];
7
- const effort = opts.find((o) => o?.type === "effort");
8
- const toggle = opts.some((o) => o?.type === "toggle");
9
- const budget = opts.find((o) => o?.type === "budget_tokens");
10
- const input = Array.isArray(m?.modalities?.input) ? m.modalities.input : [];
11
- return {
12
- reasoning: Boolean(m?.reasoning),
13
- effortType: effort ? "effort" : toggle ? "toggle" : budget ? "budget_tokens" : null,
14
- effortValues: effort && Array.isArray(effort.values) ? effort.values.map(String) : null,
15
- imageInput: input.includes("image"),
16
- toolCall: Boolean(m?.tool_call),
17
- context: Number(m?.limit?.context) || null,
18
- maxOutput: Number(m?.limit?.output) || null,
19
- costIn: Number(m?.cost?.input) || null,
20
- costOut: Number(m?.cost?.output) || null,
21
- // opencode Model 形状补充字段(-setto opencode 条目注入用)
22
- attachment: Boolean(m?.attachment),
23
- temperature: Boolean(m?.temperature),
24
- releaseDate: typeof m?.release_date === "string" && m.release_date ? m.release_date : null,
25
- inputModalities: input.length ? input : ["text"],
26
- outputModalities: Array.isArray(m?.modalities?.output) && m.modalities.output.length ? m.modalities.output : ["text"],
27
- // 模型级 SDK 覆盖(models.dev provider.npm):@ai-sdk/openai → responses 端点;null = 继承 provider 默认
28
- npm: typeof m?.provider?.npm === "string" && m.provider.npm ? m.provider.npm : null,
29
- };
30
- }
31
-
32
- // provider.models 对象({ [modelId]: rawModel })→ { [modelId]: caps }
33
- export function normalizeProviderModels(modelsObj) {
34
- const out = {};
35
- if (!modelsObj || typeof modelsObj !== "object") return out;
36
- for (const [id, m] of Object.entries(modelsObj)) {
37
- if (!m || typeof m !== "object") continue;
38
- out[id] = normalizeModelCaps(id, m);
39
- }
40
- return out;
41
- }
42
-
43
- // workbuddy 上游原生字段(/v3/config 产品文档,first-party 最准)→ 统一 caps 形状
44
- // 实测字段(2026-09-11,29 模型全覆盖):maxInputTokens/maxOutputTokens/supportsImages/
45
- // supportsReasoning/reasoning{effort,summary}/supportsToolCall/disabledMultimodal/credits/tags/name/vendor
46
- // reasoning 是"当前档位"非档位列表 → effortType=effort 但 effortValues=null、defaultEffort 记默认档
47
- export function normalizeWorkbuddyCaps(_id, m) {
48
- const imageOk = Boolean(m?.supportsImages) && !m?.disabledMultimodal;
49
- const reasoning = Boolean(m?.supportsReasoning);
50
- const effort = reasoning && m?.reasoning && typeof m.reasoning === "object" ? String(m.reasoning.effort || "").trim() : "";
51
- return {
52
- reasoning,
53
- effortType: reasoning ? "effort" : null,
54
- // 上游只给当前档位不给档位列表;实测 hy3 reasoning_effort low/high 均生效(思考块 99 vs 210),
55
- // 网关层按 OpenAI 兼容标准给通用三档(上游不识别时忽略,无害)
56
- effortValues: reasoning ? ["low", "medium", "high"] : null,
57
- defaultEffort: effort || null,
58
- imageInput: imageOk,
59
- toolCall: Boolean(m?.supportsToolCall),
60
- context: Number(m?.maxInputTokens) || null,
61
- maxOutput: Number(m?.maxOutputTokens) || null,
62
- costIn: null,
63
- costOut: null,
64
- attachment: false,
65
- temperature: m?.temperature != null,
66
- releaseDate: null,
67
- inputModalities: imageOk ? ["text", "image"] : ["text"],
68
- outputModalities: ["text"],
69
- };
70
- }
1
+ // models.dev 能力目录 → mslxdff 能力形状的纯函数解析层(无 IO,测试接缝 S1)
2
+ // 源数据形态(实测 models.opencode.ai/api.json 2026-09-11):
3
+ // reasoning_options: [{type:"effort",values:["low","medium","high","max"]} | {type:"toggle"} | {type:"budget_tokens",min}]
4
+ // modalities.input 含 "image" 即可读图;limit.context/output;cost.input/output 为 $/M tokens
5
+ export function normalizeModelCaps(_id, m) {
6
+ const opts = Array.isArray(m?.reasoning_options) ? m.reasoning_options : [];
7
+ const effort = opts.find((o) => o?.type === "effort");
8
+ const toggle = opts.some((o) => o?.type === "toggle");
9
+ const budget = opts.find((o) => o?.type === "budget_tokens");
10
+ const input = Array.isArray(m?.modalities?.input) ? m.modalities.input : [];
11
+ return {
12
+ reasoning: Boolean(m?.reasoning),
13
+ effortType: effort ? "effort" : toggle ? "toggle" : budget ? "budget_tokens" : null,
14
+ effortValues: effort && Array.isArray(effort.values) ? effort.values.map(String) : null,
15
+ imageInput: input.includes("image"),
16
+ toolCall: Boolean(m?.tool_call),
17
+ context: Number(m?.limit?.context) || null,
18
+ maxOutput: Number(m?.limit?.output) || null,
19
+ costIn: Number(m?.cost?.input) || null,
20
+ costOut: Number(m?.cost?.output) || null,
21
+ // opencode Model 形状补充字段(-setto opencode 条目注入用)
22
+ attachment: Boolean(m?.attachment),
23
+ temperature: Boolean(m?.temperature),
24
+ releaseDate: typeof m?.release_date === "string" && m.release_date ? m.release_date : null,
25
+ inputModalities: input.length ? input : ["text"],
26
+ outputModalities: Array.isArray(m?.modalities?.output) && m.modalities.output.length ? m.modalities.output : ["text"],
27
+ // 模型级 SDK 覆盖(models.dev provider.npm):@ai-sdk/openai → responses 端点;null = 继承 provider 默认
28
+ npm: typeof m?.provider?.npm === "string" && m.provider.npm ? m.provider.npm : null,
29
+ };
30
+ }
31
+
32
+ // provider.models 对象({ [modelId]: rawModel })→ { [modelId]: caps }
33
+ export function normalizeProviderModels(modelsObj) {
34
+ const out = {};
35
+ if (!modelsObj || typeof modelsObj !== "object") return out;
36
+ for (const [id, m] of Object.entries(modelsObj)) {
37
+ if (!m || typeof m !== "object") continue;
38
+ out[id] = normalizeModelCaps(id, m);
39
+ }
40
+ return out;
41
+ }
42
+
43
+ // workbuddy 上游原生字段(/v3/config 产品文档,first-party 最准)→ 统一 caps 形状
44
+ // 实测字段(2026-09-11,29 模型全覆盖):maxInputTokens/maxOutputTokens/supportsImages/
45
+ // supportsReasoning/reasoning{effort,summary}/supportsToolCall/disabledMultimodal/credits/tags/name/vendor
46
+ // reasoning 是"当前档位"非档位列表 → effortType=effort 但 effortValues=null、defaultEffort 记默认档
47
+ export function normalizeWorkbuddyCaps(_id, m) {
48
+ const imageOk = Boolean(m?.supportsImages) && !m?.disabledMultimodal;
49
+ const reasoning = Boolean(m?.supportsReasoning);
50
+ const effort = reasoning && m?.reasoning && typeof m.reasoning === "object" ? String(m.reasoning.effort || "").trim() : "";
51
+ return {
52
+ reasoning,
53
+ effortType: reasoning ? "effort" : null,
54
+ // 上游只给当前档位不给档位列表;实测 hy3 reasoning_effort low/high 均生效(思考块 99 vs 210),
55
+ // 网关层按 OpenAI 兼容标准给通用三档(上游不识别时忽略,无害)
56
+ effortValues: reasoning ? ["low", "medium", "high"] : null,
57
+ defaultEffort: effort || null,
58
+ imageInput: imageOk,
59
+ toolCall: Boolean(m?.supportsToolCall),
60
+ context: Number(m?.maxInputTokens) || null,
61
+ maxOutput: Number(m?.maxOutputTokens) || null,
62
+ costIn: null,
63
+ costOut: null,
64
+ attachment: false,
65
+ temperature: m?.temperature != null,
66
+ releaseDate: null,
67
+ inputModalities: imageOk ? ["text", "image"] : ["text"],
68
+ outputModalities: ["text"],
69
+ };
70
+ }