mslxdff 0.1.170 → 0.1.172
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/bin/mslxdff.js +3 -3
- package/docs/cli_help_mini.md +143 -0
- package/package.json +1 -1
- package/src/anthropic/count-tokens.js +39 -0
- package/src/anthropic/translate.js +20 -41
- package/src/auto.js +254 -254
- package/src/bench/cline-bench.js +42 -42
- package/src/bench/probe.js +70 -70
- package/src/bench/report.js +162 -162
- package/src/bench/runner.js +77 -77
- package/src/bench/via-probe.js +124 -124
- package/src/bench/via-routes.js +87 -87
- package/src/bench/workbuddy-bench.js +54 -54
- package/src/chat/engine.js +160 -160
- package/src/chat/gateway.js +163 -163
- package/src/chat/orchestrator.js +234 -234
- package/src/chat/prompt.js +70 -70
- package/src/chat/repl.js +88 -88
- package/src/chat/terminal.js +135 -135
- package/src/chat/tools.js +306 -306
- package/src/chat-pipeline/index.js +131 -131
- package/src/chat-pipeline/policy.js +76 -76
- package/src/cli/commands/group.js +249 -249
- package/src/cli/commands/model/picks.js +50 -50
- package/src/cli/commands/provider/bench-via.js +247 -247
- package/src/cli/commands/provider/bench.js +141 -141
- package/src/cli/commands/provider/index.js +133 -133
- package/src/cli/commands/provider/models.js +145 -145
- package/src/cli/commands/provider/qwenwork-login.js +119 -119
- package/src/cli/commands/sync.js +310 -310
- package/src/cli/status.js +279 -279
- package/src/daemon.js +112 -112
- package/src/model-capabilities/context-lookup.js +65 -0
- package/src/model-capabilities/enrich.js +86 -86
- package/src/model-capabilities/index.js +183 -183
- package/src/model-capabilities/merge.js +50 -35
- package/src/model-capabilities/parse.js +70 -70
- package/src/models.js +225 -225
- package/src/providers/AGENTS.md +49 -0
- package/src/providers/cline/auth.js +228 -228
- package/src/providers/cline/chat.js +307 -307
- package/src/providers/cline.js +2 -2
- package/src/providers/codearts/concurrency.js +34 -0
- package/src/providers/codearts/index.js +11 -3
- package/src/providers/globalqwenwork/cosy.js +123 -123
- package/src/providers/globalqwenwork/crypto.js +218 -218
- package/src/providers/globalqwenwork/http.js +20 -20
- package/src/providers/globalqwenwork/payload.js +4 -2
- package/src/providers/globalqwenwork/rsa.js +54 -54
- package/src/providers/globalqwenwork/sse.js +268 -268
- package/src/providers/globalqwenwork/stream.js +130 -130
- package/src/providers/globalqwenwork/upstream.js +122 -122
- package/src/providers/keyring.js +60 -60
- package/src/providers/qoder/chat.js +203 -200
- package/src/providers/qoder/index.js +249 -249
- package/src/providers/qoder/sse.js +145 -145
- package/src/providers/qwenwork/account-store.js +133 -133
- package/src/providers/qwenwork/constants.js +67 -67
- package/src/providers/qwenwork/cosy.js +120 -120
- package/src/providers/qwenwork/crypto.js +218 -218
- package/src/providers/qwenwork/http.js +20 -20
- package/src/providers/qwenwork/index.js +327 -327
- package/src/providers/qwenwork/payload.js +144 -142
- package/src/providers/qwenwork/rsa.js +54 -54
- package/src/providers/qwenwork/sse.js +268 -268
- package/src/providers/qwenwork/stream.js +130 -130
- package/src/providers/qwenwork/upstream.js +120 -120
- package/src/providers/qwenwork.js +1 -1
- package/src/providers/raccoon/chat.js +10 -5
- package/src/providers/raccoon/const.js +4 -4
- package/src/providers/registry.js +79 -79
- package/src/providers/traework/models.js +4 -3
- package/src/providers/workbuddy/chat.js +248 -248
- package/src/providers/workbuddy/payload.js +16 -7
- package/src/providers/workbuddy/reshape.js +152 -152
- package/src/providers/workbuddy.js +2 -2
- package/src/providers/zcode/chat.js +7 -0
- package/src/reasoning.js +32 -32
- package/src/responses/translate.js +4 -0
- package/src/routes/AGENTS.md +37 -0
- package/src/routes/chat/exhausted-handler.js +5 -0
- package/src/routes/chat/gateway.js +46 -46
- package/src/routes/chat/relay-pipeline.js +294 -291
- package/src/routes/chat/via-route-handler.js +146 -146
- package/src/routes/hedge.js +255 -255
- package/src/routes/messages-route.js +1 -1
- package/src/routes/models-route.js +167 -167
- package/src/routes/peers.js +273 -273
- package/src/routes/stream-scan.js +47 -21
- package/src/routes/stream.js +385 -385
- package/src/runtime/bootstrap.js +50 -50
- package/src/runtime/provider-gate.js +36 -36
- package/src/runtime/providers-setup.js +165 -165
- package/src/server.js +69 -69
- package/src/state/schemas/allowlist.js +92 -92
- package/src/sync-opencode.js +280 -280
- package/src/talk-full.js +1 -0
- package/src/talk-log.js +3 -2
- package/src/thinking-effort.js +67 -0
- package/src/transport/index.js +244 -244
- package/src/transport/pool.js +56 -56
- package/src/transport/retry.js +24 -24
- package/src/transport/sse.js +93 -93
- package/src/upstream-engine/sdk/convert.js +6 -0
- package/src/upstream-probe/display.js +52 -52
- package/src/upstream-probe/probe.js +49 -49
- package/src/upstream-probe/rotate.js +110 -110
- package/src/upstream-probe/start.js +45 -45
- package/src/upstream-responses.js +5 -0
- 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,8 +1,10 @@
|
|
|
1
|
-
// /v1/models 能力富化(ADR-0022):把 models.dev 目录(+ workbuddy 原生字段兜底)
|
|
2
|
-
//
|
|
1
|
+
// /v1/models 能力富化(ADR-0022 + ADR-0054):把 models.dev 目录(+ workbuddy 原生字段兜底)
|
|
2
|
+
// 的能力合并进每条 data 条目的 `capabilities` 子对象;上下文窗口由 context-lookup 四级解析
|
|
3
|
+
// 统一裁决并双层同源写入(顶层 context_length 与 capabilities.context 恒同值)。
|
|
3
4
|
// 逃生门:GET /v1/models?raw=1 保持 ADR-0016 的原始透传形状;codex 调用者恒原始 + 空 models:[]。
|
|
4
|
-
// 全程 best-effort
|
|
5
|
+
// 全程 best-effort:富化失败不阻塞 /models,context 一致化不依赖目录(冷缓存照常生效)。
|
|
5
6
|
import { globalCapabilities } from "./index.js";
|
|
7
|
+
import { resolveContextLength } from "./context-lookup.js";
|
|
6
8
|
|
|
7
9
|
// "cline/deepseek/deepseek-v4-flash" → { provider: "cline", raw: "deepseek/deepseek-v4-flash" };裸 id 归 opencode
|
|
8
10
|
export function splitModelId(id) {
|
|
@@ -82,46 +84,59 @@ function lookupCapsDeep(svc, provider, raw) {
|
|
|
82
84
|
* wbSource 显式 null 禁用 workbuddy 兜底(测试用)。
|
|
83
85
|
*/
|
|
84
86
|
export async function mergeModelsList(data, { capsSvc, wbSource } = {}) {
|
|
85
|
-
const svc = capsSvc === undefined ? globalCapabilities() : capsSvc;
|
|
86
87
|
const entries = Array.isArray(data?.data) ? data.data : [];
|
|
87
|
-
if (!
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
if (!entries.length) return data;
|
|
89
|
+
const svc = capsSvc === undefined ? globalCapabilities() : capsSvc;
|
|
90
|
+
// 目录冷缓存/抛错不阻塞:context 一致化(L1/L2/L4)不依赖目录,照常生效(ADR-0054)
|
|
91
|
+
let catalogReady = false;
|
|
92
|
+
if (svc) {
|
|
93
|
+
try {
|
|
94
|
+
catalogReady = svc.readyWarm ? await svc.readyWarm() : await svc.ready();
|
|
95
|
+
} catch {
|
|
96
|
+
catalogReady = false;
|
|
97
|
+
}
|
|
94
98
|
}
|
|
95
|
-
//
|
|
99
|
+
// L3 目录直查(仅就绪时);workbuddy 未命中第二遍走上游原生字段
|
|
96
100
|
const resolved = new Map(); // index -> caps
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
101
|
+
if (catalogReady) {
|
|
102
|
+
const needWb = []; // [index, raw]
|
|
103
|
+
entries.forEach((entry, i) => {
|
|
104
|
+
const id = String(entry?.id || "");
|
|
105
|
+
if (!id) return;
|
|
106
|
+
const { provider, raw } = splitModelId(id);
|
|
107
|
+
const caps = lookupCapsDeep(svc, provider, raw);
|
|
108
|
+
if (caps) resolved.set(i, caps);
|
|
109
|
+
else if (provider === "workbuddy" && wbSource !== null) needWb.push([i, raw]);
|
|
110
|
+
});
|
|
111
|
+
if (needWb.length) {
|
|
112
|
+
try {
|
|
113
|
+
const { workbuddyCapsFromModels, workbuddyAllModels } = await import("./index.js");
|
|
114
|
+
const wbMap = await workbuddyCapsFromModels(wbSource || workbuddyAllModels)();
|
|
115
|
+
for (const [i, raw] of needWb) {
|
|
116
|
+
const caps = wbMap?.[raw] || null;
|
|
117
|
+
if (caps) resolved.set(i, caps);
|
|
118
|
+
}
|
|
119
|
+
} catch {
|
|
120
|
+
// workbuddy 源不可用:这些条目保持无能力,不拖垮整个列表
|
|
113
121
|
}
|
|
114
|
-
} catch {
|
|
115
|
-
// workbuddy 源不可用:这些条目保持无能力,不拖垮整个列表
|
|
116
122
|
}
|
|
117
123
|
}
|
|
118
|
-
|
|
124
|
+
// 产物:capabilities(caps 语义字段 + 解析出的 context)+ 顶层 context_length 同源同值(ADR-0054 决定 2:
|
|
125
|
+
// 两层要么同写要么同不写,绝不给客户端两种答案);caps 未命中只补 { context },不硬造能力声明(能力不知道就沉默)
|
|
119
126
|
const next = entries.map((entry, i) => {
|
|
120
|
-
|
|
121
|
-
|
|
127
|
+
if (!entry || typeof entry !== "object") return entry; // 异形条目原样透传,不凭空造成员
|
|
128
|
+
const caps = resolved.get(i) || null;
|
|
129
|
+
const ctx = resolveContextLength({ entry, id: String(entry?.id || ""), caps });
|
|
130
|
+
if (!caps && !ctx) return entry; // env 关兜底 + 全未命中:回旧口径
|
|
122
131
|
const { raw } = splitModelId(String(entry?.id || ""));
|
|
123
|
-
const
|
|
124
|
-
|
|
132
|
+
const capsPart = caps ? capsPayloadFor(caps, raw) : null;
|
|
133
|
+
const capabilities = capsPart
|
|
134
|
+
? (ctx ? { ...capsPart, context: ctx } : capsPart)
|
|
135
|
+
: (ctx ? { context: ctx } : null);
|
|
136
|
+
if (!capabilities) return entry;
|
|
137
|
+
const out = ctx ? { ...entry, context_length: ctx } : { ...entry };
|
|
138
|
+
out.capabilities = capabilities;
|
|
139
|
+
return out;
|
|
125
140
|
});
|
|
126
141
|
return { ...data, data: next };
|
|
127
142
|
}
|
|
@@ -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
|
+
}
|