mslxdff 0.1.155 → 0.1.158

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 (151) hide show
  1. package/bin/mslxdff.js +4 -4
  2. package/docs/ARCHITECTURE.md +426 -0
  3. package/docs/FEATURE_TREE.md +164 -0
  4. package/docs/MOBILE.md +82 -0
  5. package/docs/adr/0001-reasoning-content-injection.md +14 -0
  6. package/docs/adr/0002-models-free-filter.md +12 -0
  7. package/docs/adr/0003-zero-state-no-auth.md +10 -0
  8. package/docs/adr/0004-bearer-token.md +18 -0
  9. package/docs/adr/0005-peer-mesh.md +53 -0
  10. package/docs/adr/0006-broadband-member.md +103 -0
  11. package/docs/adr/0007-multi-provider-prefix.md +25 -0
  12. package/docs/adr/0008-share-keys-to-peers.md +52 -0
  13. package/docs/adr/0009-chat-repl.md +37 -0
  14. package/docs/adr/0010-allowlist.md +36 -0
  15. package/docs/adr/0011-broadband-stream.md +30 -0
  16. package/docs/adr/0012-responses-endpoint-codex-sync.md +48 -0
  17. package/docs/adr/0013-node16-compat.md +41 -0
  18. package/docs/adr/0014-deepseek-provider.md +52 -0
  19. package/docs/adr/0015-upstream-probe-routing.md +50 -0
  20. package/docs/adr/0016-model-capabilities.md +27 -0
  21. package/docs/adr/0017-ai-sdk-upstream-engine.md +59 -0
  22. package/docs/adr/0018-zen-client-identity.md +52 -0
  23. package/docs/adr/0019-share-keys-always-lend.md +59 -0
  24. package/docs/adr/0020-zen-free-lane-agent-shape.md +52 -0
  25. package/docs/adr/0021-usage-report-jsonl.md +47 -0
  26. package/docs/adr/0022-models-capability-merge.md +61 -0
  27. package/docs/adr/0023-key-provider-default-direct.md +58 -0
  28. package/docs/adr/0024-node18-baseline.md +63 -0
  29. package/docs/adr/0025-workbuddy-authdir-follows-state.md +71 -0
  30. package/docs/adr/0026-cline-provider-id-unify.md +67 -0
  31. package/docs/adr/0027-codearts-provider.md +48 -0
  32. package/docs/adr/0028-traework-provider.md +34 -0
  33. package/docs/adr/0029-qoder-native-provider.md +60 -0
  34. package/docs/adr/0030-models-list-scoped-by-picks.md +53 -0
  35. package/docs/adr/0031-qoder-true-streaming.md +50 -0
  36. package/docs/adr/0032-generic-responses-channel.md +72 -0
  37. package/docs/adr/0033-cline-allowlist-auto-sync.md +75 -0
  38. package/docs/adr/0034-request-level-human-readable-observability.md +60 -0
  39. package/docs/adr/0035-sdk-channel-headers-timeout.md +49 -0
  40. package/docs/adr/0036-qoder-per-request-sticky-account.md +82 -0
  41. package/docs/adr/0037-qwenwork-independent-provider.md +82 -0
  42. package/docs/adr/0038-zcode-provider.md +140 -0
  43. package/docs/agents/domain.md +51 -0
  44. package/docs/agents/issue-tracker.md +30 -0
  45. package/docs/agents/triage-labels.md +15 -0
  46. package/docs/cli_help.md +1391 -0
  47. package/docs/cli_help_mini.md +133 -0
  48. package/docs/plans/bench-via-latency-2026-09-01.md +215 -0
  49. package/docs/plugins.md +187 -0
  50. package/package.json +1 -1
  51. package/src/auto.js +254 -254
  52. package/src/bench/cline-bench.js +42 -42
  53. package/src/bench/probe.js +70 -70
  54. package/src/bench/report.js +162 -162
  55. package/src/bench/runner.js +77 -77
  56. package/src/bench/via-probe.js +124 -124
  57. package/src/bench/via-routes.js +87 -87
  58. package/src/bench/workbuddy-bench.js +54 -54
  59. package/src/chat/engine.js +160 -160
  60. package/src/chat/gateway.js +163 -163
  61. package/src/chat/orchestrator.js +234 -234
  62. package/src/chat/prompt.js +70 -70
  63. package/src/chat/repl.js +88 -88
  64. package/src/chat/terminal.js +135 -135
  65. package/src/chat/tools.js +306 -306
  66. package/src/chat-pipeline/index.js +123 -123
  67. package/src/chat-pipeline/policy.js +76 -76
  68. package/src/chat-pipeline/serial-trial.js +210 -210
  69. package/src/cli/commands/group.js +249 -249
  70. package/src/cli/commands/model/list-providers.js +4 -3
  71. package/src/cli/commands/model/list-render.js +7 -9
  72. package/src/cli/commands/model/list-sort.js +52 -0
  73. package/src/cli/commands/model/list-tty.js +76 -0
  74. package/src/cli/commands/model/list.js +5 -62
  75. package/src/cli/commands/model/picks.js +50 -50
  76. package/src/cli/commands/provider/bench-via.js +247 -247
  77. package/src/cli/commands/provider/bench.js +141 -141
  78. package/src/cli/commands/provider/index.js +124 -116
  79. package/src/cli/commands/provider/models.js +139 -128
  80. package/src/cli/commands/provider/qwenwork-login.js +119 -0
  81. package/src/cli/commands/provider/zcode-login.js +77 -0
  82. package/src/cli/commands/provider/zcode-quota.js +55 -0
  83. package/src/cli/commands/sync.js +232 -232
  84. package/src/cli/provider-row.js +2 -2
  85. package/src/cli/status.js +279 -279
  86. package/src/daemon.js +96 -96
  87. package/src/model-capabilities/enrich.js +86 -86
  88. package/src/model-capabilities/index.js +183 -183
  89. package/src/model-capabilities/parse.js +70 -70
  90. package/src/model-trace.js +1 -0
  91. package/src/models.js +225 -225
  92. package/src/providers/classify.js +1 -1
  93. package/src/providers/cline/auth.js +228 -228
  94. package/src/providers/cline/chat.js +307 -307
  95. package/src/providers/cline.js +2 -2
  96. package/src/providers/keyring.js +60 -56
  97. package/src/providers/qoder/chat.js +183 -100
  98. package/src/providers/qoder/index.js +230 -184
  99. package/src/providers/qoder/sse.js +103 -46
  100. package/src/providers/qoder/sticky.js +1 -0
  101. package/src/providers/qoder/stream.js +32 -9
  102. package/src/providers/qwenwork/account-store.js +133 -0
  103. package/src/providers/qwenwork/constants.js +67 -0
  104. package/src/providers/qwenwork/cosy.js +120 -0
  105. package/src/providers/qwenwork/crypto.js +218 -0
  106. package/src/providers/qwenwork/http.js +20 -0
  107. package/src/providers/qwenwork/index.js +327 -0
  108. package/src/providers/qwenwork/payload.js +142 -0
  109. package/src/providers/qwenwork/rsa.js +54 -0
  110. package/src/providers/qwenwork/sse.js +268 -0
  111. package/src/providers/qwenwork/stream.js +130 -0
  112. package/src/providers/qwenwork/upstream.js +120 -0
  113. package/src/providers/qwenwork.js +1 -0
  114. package/src/providers/registry.js +66 -56
  115. package/src/providers/share-keys.js +2 -2
  116. package/src/providers/workbuddy/chat.js +248 -248
  117. package/src/providers/workbuddy/reshape.js +152 -152
  118. package/src/providers/workbuddy.js +2 -2
  119. package/src/providers/zcode/account-store.js +129 -0
  120. package/src/providers/zcode/auth.js +28 -0
  121. package/src/providers/zcode/chat.js +171 -0
  122. package/src/providers/zcode/const.js +54 -0
  123. package/src/providers/zcode/headers.js +55 -0
  124. package/src/providers/zcode/index.js +124 -0
  125. package/src/providers/zcode/models.js +65 -0
  126. package/src/providers/zcode/oauth.js +120 -0
  127. package/src/providers/zcode/quota.js +176 -0
  128. package/src/providers/zcode/sse.js +179 -0
  129. package/src/reasoning.js +32 -32
  130. package/src/routes/chat/gateway.js +46 -46
  131. package/src/routes/chat/relay-pipeline.js +250 -246
  132. package/src/routes/chat/via-route-handler.js +144 -144
  133. package/src/routes/hedge.js +255 -255
  134. package/src/routes/models-route.js +167 -167
  135. package/src/routes/peers.js +273 -273
  136. package/src/routes/stream.js +438 -399
  137. package/src/runtime/bootstrap.js +45 -45
  138. package/src/runtime/provider-gate.js +33 -30
  139. package/src/runtime/providers-setup.js +165 -165
  140. package/src/server.js +64 -64
  141. package/src/state/schemas/allowlist.js +92 -92
  142. package/src/sync-opencode.js +280 -280
  143. package/src/transport/index.js +244 -244
  144. package/src/transport/pool.js +56 -56
  145. package/src/transport/retry.js +24 -24
  146. package/src/transport/sse.js +93 -93
  147. package/src/upstream-probe/display.js +52 -52
  148. package/src/upstream-probe/probe.js +49 -49
  149. package/src/upstream-probe/rotate.js +110 -110
  150. package/src/upstream-probe/start.js +45 -45
  151. 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 上游原生字段(/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
+ }
@@ -1,5 +1,6 @@
1
1
  // Per-model request trace formatting. Never include prompt, response body, headers or credentials.
2
2
  // Note: 同步 appendFileSync(异步 append 会在并发下打乱同一请求的阶段行序)— 见 .agents/notes/implemented/feature/2026-09-25-model-trace-log.md
3
+ // Note: 事件面用黑名单(默认全可见,只排除噪声/敏感面)+ 决定类事件只渲染登记过的标量字段——起因是 empty-turn-retry 曾被阶段白名单静默吞掉,"关键决定不许再被漏登记" — 见 .agents/notes/implemented/feature/2026-09-27-qoder-per-request-sticky-account.md
3
4
  import { appendFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
4
5
  import { join } from "node:path";
5
6
  import { logDir } from "./logs.js";