mslxdff 0.1.161 → 0.1.162

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 (93) hide show
  1. package/bin/mslxdff.js +4 -4
  2. package/package.json +1 -1
  3. package/src/auto.js +254 -254
  4. package/src/bench/cline-bench.js +42 -42
  5. package/src/bench/probe.js +70 -70
  6. package/src/bench/report.js +162 -162
  7. package/src/bench/runner.js +77 -77
  8. package/src/bench/via-probe.js +124 -124
  9. package/src/bench/via-routes.js +87 -87
  10. package/src/bench/workbuddy-bench.js +54 -54
  11. package/src/chat/engine.js +160 -160
  12. package/src/chat/gateway.js +163 -163
  13. package/src/chat/orchestrator.js +234 -234
  14. package/src/chat/prompt.js +70 -70
  15. package/src/chat/repl.js +88 -88
  16. package/src/chat/terminal.js +135 -135
  17. package/src/chat/tools.js +306 -306
  18. package/src/chat-pipeline/index.js +126 -126
  19. package/src/chat-pipeline/policy.js +76 -76
  20. package/src/cli/commands/group.js +249 -249
  21. package/src/cli/commands/model/picks.js +50 -50
  22. package/src/cli/commands/provider/bench-via.js +247 -247
  23. package/src/cli/commands/provider/bench.js +141 -141
  24. package/src/cli/commands/provider/index.js +126 -126
  25. package/src/cli/commands/provider/models.js +142 -142
  26. package/src/cli/commands/provider/qwenwork-login.js +119 -119
  27. package/src/cli/commands/sync.js +232 -232
  28. package/src/cli/format.js +1 -0
  29. package/src/cli/status.js +279 -279
  30. package/src/daemon.js +101 -101
  31. package/src/model-capabilities/enrich.js +86 -86
  32. package/src/model-capabilities/index.js +183 -183
  33. package/src/model-capabilities/parse.js +70 -70
  34. package/src/model-trace.js +4 -3
  35. package/src/models.js +225 -225
  36. package/src/providers/cline/auth.js +228 -228
  37. package/src/providers/cline/chat.js +307 -307
  38. package/src/providers/cline.js +2 -2
  39. package/src/providers/dispatcher.js +26 -14
  40. package/src/providers/globalqwenwork/cosy.js +123 -123
  41. package/src/providers/globalqwenwork/crypto.js +218 -218
  42. package/src/providers/globalqwenwork/http.js +20 -20
  43. package/src/providers/globalqwenwork/rsa.js +54 -54
  44. package/src/providers/globalqwenwork/sse.js +268 -268
  45. package/src/providers/globalqwenwork/stream.js +130 -130
  46. package/src/providers/globalqwenwork/upstream.js +122 -122
  47. package/src/providers/keyring.js +60 -60
  48. package/src/providers/qoder/chat.js +193 -183
  49. package/src/providers/qoder/index.js +239 -230
  50. package/src/providers/qoder/sse.js +141 -103
  51. package/src/providers/qwenwork/account-store.js +133 -133
  52. package/src/providers/qwenwork/constants.js +67 -67
  53. package/src/providers/qwenwork/cosy.js +120 -120
  54. package/src/providers/qwenwork/crypto.js +218 -218
  55. package/src/providers/qwenwork/http.js +20 -20
  56. package/src/providers/qwenwork/index.js +327 -327
  57. package/src/providers/qwenwork/payload.js +142 -142
  58. package/src/providers/qwenwork/rsa.js +54 -54
  59. package/src/providers/qwenwork/sse.js +268 -268
  60. package/src/providers/qwenwork/stream.js +130 -130
  61. package/src/providers/qwenwork/upstream.js +120 -120
  62. package/src/providers/qwenwork.js +1 -1
  63. package/src/providers/registry.js +74 -74
  64. package/src/providers/workbuddy/chat.js +248 -248
  65. package/src/providers/workbuddy/reshape.js +152 -152
  66. package/src/providers/workbuddy.js +2 -2
  67. package/src/reasoning.js +32 -32
  68. package/src/routes/chat/gateway.js +46 -46
  69. package/src/routes/chat/relay-pipeline.js +276 -276
  70. package/src/routes/chat/via-route-handler.js +146 -146
  71. package/src/routes/hedge.js +255 -255
  72. package/src/routes/models-route.js +167 -167
  73. package/src/routes/peers.js +273 -273
  74. package/src/routes/stream.js +386 -386
  75. package/src/runtime/bootstrap.js +45 -45
  76. package/src/runtime/provider-gate.js +34 -34
  77. package/src/runtime/providers-setup.js +165 -165
  78. package/src/runtime/server-lifecycle.js +5 -6
  79. package/src/server.js +64 -64
  80. package/src/state/schemas/allowlist.js +92 -92
  81. package/src/sync-opencode.js +280 -280
  82. package/src/transport/index.js +244 -244
  83. package/src/transport/pool.js +56 -56
  84. package/src/transport/retry.js +24 -24
  85. package/src/transport/sse.js +93 -93
  86. package/src/upstream-probe/display.js +52 -52
  87. package/src/upstream-probe/probe.js +49 -49
  88. package/src/upstream-probe/rotate.js +110 -110
  89. package/src/upstream-probe/start.js +45 -45
  90. package/src/upstream.js +289 -289
  91. package/docs/cli_help_mini.md +0 -135
  92. package/src/providers/AGENTS.md +0 -46
  93. package/src/routes/AGENTS.md +0 -37
@@ -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 上游原生字段(/console/enterprises/personal/models,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 上游原生字段(/console/enterprises/personal/models,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
+ }
@@ -78,7 +78,7 @@ const DECISION_FIELDS = [
78
78
  "winPeer", "winTarget", "peer", "peers", "peerLabel", "routeBest", "at",
79
79
  "latencyMs", "ttfMs", "hedged", "hops", "hasShare", "elapsedMs", "threshold",
80
80
  "stallHits", "maxGapMs", "interrupted", "providers", "via",
81
- "retry", "step", "max", "delayMs", "upstream", "account", "pick", "cooled", "nudged", "retries", "waitedMs", "raiseFrom", "raiseTo",
81
+ "retry", "step", "max", "delayMs", "upstream", "account", "pick", "cooled", "queued", "nudged", "retries", "waitedMs", "raiseFrom", "raiseTo",
82
82
  "heldOpen", "terminalForm", "requestWaitedMs", "budgetMs", "budgetOut",
83
83
  ];
84
84
 
@@ -92,7 +92,7 @@ function decisionKv(data = {}) {
92
92
  return out.join(" ");
93
93
  }
94
94
 
95
- // provider 回显头 → 日志字段(谁上的 / 打哪个站 / 为什么选它 / 是否被冷却):
95
+ // provider 回显头 → 日志字段(谁上的 / 打哪个站 / 为什么选它 / 是否被冷却 / 是否被判排队):
96
96
  // 单一来源,防各处重复写法漂移;取不到时返回空对象(其它供应商零变化)。
97
97
  export function upstreamEcho(res) {
98
98
  const h = res?.headers;
@@ -103,6 +103,7 @@ export function upstreamEcho(res) {
103
103
  account: pick("x-mslxdff-workbuddy-uid") || pick("x-mslxdff-qoder-region"),
104
104
  pick: pick("x-mslxdff-qoder-account"),
105
105
  cooled: pick("x-mslxdff-qoder-cooldown"),
106
+ queued: pick("x-mslxdff-qoder-queued"),
106
107
  };
107
108
  }
108
109
 
@@ -115,7 +116,7 @@ export function formatModelTrace({ type, reqId, model, data = {}, request = null
115
116
  else if (type === "alias") detail = `rawModel=${data.rawModel || "-"} requested=${data.requested || model || "-"}`;
116
117
  else if (type === "exhausted-local" || type === "exhausted-all") detail = `last=${data.lastModel || model || "-"} status=${data.lastStatus ?? "-"} order=${(data.order || []).join(" | ")}`;
117
118
  else if (type === "upstream-try") detail = `target=${data.model || model || "-"} attempt=${data.attempt ?? "-"} payload=${kv(data.payload || {})}`;
118
- else if (type === "upstream-done" || type === "upstream-error") detail = `upstream status=${data.status ?? "-"} timing=${data.timing?.totalMs ?? "-"}ms${data.upstream ? ` via=${data.upstream}` : ""}${data.account ? ` account=${data.account}` : ""}${data.pick ? ` pick=${data.pick}` : ""}${data.cooled ? ` cooled=${data.cooled}` : ""} ${safeText(data.message || data.error || "")}`;
119
+ else if (type === "upstream-done" || type === "upstream-error") detail = `upstream status=${data.status ?? "-"} timing=${data.timing?.totalMs ?? "-"}ms${data.upstream ? ` via=${data.upstream}` : ""}${data.account ? ` account=${data.account}` : ""}${data.pick ? ` pick=${data.pick}` : ""}${data.cooled ? ` cooled=${data.cooled}` : ""}${data.queued ? ` queued=1` : ""} ${safeText(data.message || data.error || "")}`;
119
120
  else if (type === "empty-turn-retry") detail = `空转重试:retry ${data.retry ?? "-"}/${data.max ?? "-"}${data.step != null ? ` step=${data.step}` : ""} delay=${data.delayMs ?? "-"}ms${data.waitedMs ? ` waited=${data.waitedMs}ms` : ""}${data.requestWaitedMs != null ? ` 请求级累计=${data.requestWaitedMs}ms/预算${data.budgetMs ?? "-"}ms` : ""}${data.raiseTo ? ` max_tokens ${data.raiseFrom}→${data.raiseTo}` : ""}${data.upstream ? ` after=${data.upstream}` : ""}${data.account ? ` account=${data.account}` : ""}${data.pick ? ` pick=${data.pick}` : ""}${data.nudged ? ` nudged=1` : ""} reason=empty turn${data.reason ? ` :: ${safeText(data.reason, 120)}` : ""}`;
120
121
  else if (type === "empty-turn-recovered") detail = `空转重试成功:第 ${data.retries ?? "-"}/${data.max ?? "-"} 次重拉拿到真实输出,本轮共白等 ${data.waitedMs ?? "-"}ms${data.upstream ? ` via=${data.upstream}` : ""}${data.account ? ` account=${data.account}` : ""}${data.pick ? ` pick=${data.pick}` : ""}`;
121
122
  else if (type === "empty-turn-exhausted") detail = `空转重试已用尽:重试 ${data.retries ?? 0}/${data.max ?? "-"} 次仍零输出(累计等待 ${data.waitedMs ?? 0}ms${data.budgetOut ? `,请求级等待预算 ${data.budgetMs ?? "-"}ms 用尽` : ""}),交回换候选${data.heldOpen ? "(响应仍开着,换过去的正文还能送达)" : "(响应已封口,重拉只为省额度)"}${data.upstream ? ` after=${data.upstream}` : ""}${data.account ? ` account=${data.account}` : ""}${data.pick ? ` pick=${data.pick}` : ""}${data.reason ? ` :: ${safeText(data.reason, 120)}` : ""}`;