mslxdff 0.1.107 → 0.1.110
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/package.json +1 -1
- package/src/chat-pipeline/index.js +2 -1
- package/src/chat-pipeline/serial-trial.js +3 -3
- package/src/cli/commands/sync.js +5 -0
- package/src/cli/commands/use-group.js +3 -3
- package/src/cli/help.js +2 -2
- package/src/model-capabilities/enrich.js +72 -0
- package/src/model-capabilities/index.js +130 -0
- package/src/model-capabilities/parse.js +39 -0
- package/src/providers/cline/auth.js +30 -3
- package/src/providers/cline/chat.js +6 -1
- package/src/providers/cline/models.js +30 -4
- package/src/routes/index.js +7 -1
- package/src/routes/models-route.js +26 -0
- package/src/state/schemas/use-group.js +1 -12
- package/src/sync-opencode.js +38 -12
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import { planRoute } from "./planner.js";
|
|
|
4
4
|
import { createEngine } from "./engine.js";
|
|
5
5
|
import { runHook } from "../plugins.js";
|
|
6
6
|
import { isFreeModel } from "../models.js";
|
|
7
|
+
import { shouldUseGroupForModel } from "../state/schemas/use-group.js";
|
|
7
8
|
import { clientIp, summarizePrompt } from "../routes/helpers.js";
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -85,7 +86,7 @@ export function createChatPipeline({ upstream, auto, logs, peers, groups, bus, t
|
|
|
85
86
|
|
|
86
87
|
const plan = planRoute(policy, {
|
|
87
88
|
candidates: order,
|
|
88
|
-
viaRoute: Boolean(!useAuto && requested.includes("/") && canForwardPeers) ? { via: true } : null,
|
|
89
|
+
viaRoute: Boolean(!useAuto && requested.includes("/") && canForwardPeers && shouldUseGroupForModel(requested)) ? { via: true } : null,
|
|
89
90
|
});
|
|
90
91
|
await engine.run(plan, {
|
|
91
92
|
reqId, startedAt, req, res, body: req?.body, policy,
|
|
@@ -35,7 +35,7 @@ export async function runSerialTrial(ctx, deps = {}) {
|
|
|
35
35
|
const workbuddyUid = ctx.workbuddyUid ?? ctx.policy?.workbuddyUid ?? null;
|
|
36
36
|
|
|
37
37
|
let viaRouteLastErr = null;
|
|
38
|
-
if (!useAuto && requested && requested.includes("/") && canForwardPeers && !lockModel && peers) {
|
|
38
|
+
if (!useAuto && requested && requested.includes("/") && canForwardPeers && !lockModel && peers && shouldUseGroupForModel(requested)) {
|
|
39
39
|
try {
|
|
40
40
|
const vr = await viaRoute({ model: requested, body, peers, handlerCtx, evt, logCall, logError, mark, perf0, stages, startedAt, plugins, res, requested, useAuto, lockModel, auto });
|
|
41
41
|
if (vr.handled) return { done: true };
|
|
@@ -131,7 +131,7 @@ export async function runSerialTrial(ctx, deps = {}) {
|
|
|
131
131
|
}
|
|
132
132
|
if (canForwardPeers) {
|
|
133
133
|
if (!shouldUseGroupForModel(model)) {
|
|
134
|
-
evt("group-skip", { reqId, model, reason: "useGroup=off
|
|
134
|
+
evt("group-skip", { reqId, model, reason: "useGroup=off (peer)" });
|
|
135
135
|
} else {
|
|
136
136
|
const pr = await peerRelay({ model, body, lastErr, requested, useAuto, lockModel, auto, peers, handlerCtx, evt, logCall, mark, perf0, stages, startedAt, plugins, res });
|
|
137
137
|
if (pr.handled) return { done: true };
|
|
@@ -139,7 +139,7 @@ export async function runSerialTrial(ctx, deps = {}) {
|
|
|
139
139
|
}
|
|
140
140
|
if (groups) {
|
|
141
141
|
if (!shouldUseGroupForModel(model)) {
|
|
142
|
-
evt("group-skip", { reqId, model, reason: "useGroup=off
|
|
142
|
+
evt("group-skip", { reqId, model, reason: "useGroup=off (broadband)" });
|
|
143
143
|
} else {
|
|
144
144
|
const br = await broadbandRelay({ model, body, hops, lastErr, requested, useAuto, lockModel, auto, groups, token, bus, logs, handlerCtx, evt, mark, perf0, stages, res, startedAt, plugins });
|
|
145
145
|
if (br.handled) return { done: true };
|
package/src/cli/commands/sync.js
CHANGED
|
@@ -88,6 +88,8 @@ export async function handleSetto(args) {
|
|
|
88
88
|
if (r.action === "inserted") inserted++; else updated++;
|
|
89
89
|
prunedTotal += r.pruned || 0;
|
|
90
90
|
console.log(` ${r.action} "${r.id}" -> ${r.internal} @ ${file}`);
|
|
91
|
+
if (r.capsSummaryText) console.log(` ${r.capsSummaryText}`);
|
|
92
|
+
if (r.upgraded) console.log(` 能力补齐 ${r.upgraded} 个旧条目`);
|
|
91
93
|
}
|
|
92
94
|
console.log(`synced to opencode: ${inserted} inserted, ${updated} updated, total ${list.length} @ ${file}`);
|
|
93
95
|
if (prunedTotal) console.log(` pruned ${prunedTotal} 个失效模型(未在 picks,不再于 opencode 显示)`);
|
|
@@ -158,6 +160,9 @@ export async function handleSetto(args) {
|
|
|
158
160
|
const file = opencodeConfigPath();
|
|
159
161
|
const r = await syncToOpencode({ id, token, port, file, keep: pruneKeep(), ensureAll: pruneKeep() });
|
|
160
162
|
console.log(`synced to opencode: ${r.action} "${r.id}" @ ${file}`);
|
|
163
|
+
if (r.capsSummaryText) console.log(` 能力: ${r.capsSummaryText}`);
|
|
164
|
+
else console.log(` 能力: 未收录该模型的能力目录,条目仅含名称(不影响使用)`);
|
|
165
|
+
if (r.upgraded) console.log(` 能力补齐 ${r.upgraded} 个旧条目(此前仅含名称,已注入推理档位/读图/上下文)`);
|
|
161
166
|
if (r.backfilled) console.log(` backfilled ${r.backfilled} 个 picks 模型(此前 pick 了但未同步过,现已补齐)`);
|
|
162
167
|
if (r.pruned) console.log(` pruned ${r.pruned} 个失效模型(未在 picks,不再于 opencode 显示)`);
|
|
163
168
|
console.log(` url: http://127.0.0.1:${port}/v1`);
|
|
@@ -33,7 +33,7 @@ export async function handleUseGroup(args) {
|
|
|
33
33
|
console.log(` stored: ${stored ? "on" : "off"} (state.json useGroup)`);
|
|
34
34
|
if (envVal !== null) console.log(` env MSLXDFF_USE_GROUP=${envVal ? "on" : "off"} (overrides stored)`);
|
|
35
35
|
console.log(` default: on`);
|
|
36
|
-
console.log(` usage: mslxdff -use-group on|off (
|
|
36
|
+
console.log(` usage: mslxdff -use-group on|off (本机失败时是否走组员网络,默认 on)`);
|
|
37
37
|
console.log(` env: MSLXDFF_USE_GROUP=0|1 (优先级高于 state)`);
|
|
38
38
|
process.exit(0);
|
|
39
39
|
}
|
|
@@ -50,7 +50,7 @@ export async function handleUseGroup(args) {
|
|
|
50
50
|
|
|
51
51
|
saveUseGroup(parsed);
|
|
52
52
|
console.log(`use-group set to ${parsed ? "on" : "off"} (stored in state.json)`);
|
|
53
|
-
console.log(`
|
|
54
|
-
if (!parsed) console.log(`
|
|
53
|
+
console.log(` ${parsed ? "允许" : "不再允许"}走组员网络(via-route/hedge/peer/broadband,全部供应商)`);
|
|
54
|
+
if (!parsed) console.log(` 提示:所有请求将仅在本机重试,不再走组员中继`);
|
|
55
55
|
process.exit(0);
|
|
56
56
|
}
|
package/src/cli/help.js
CHANGED
|
@@ -43,7 +43,7 @@ Usage:
|
|
|
43
43
|
mslxdff -autostart status 查看自启状态
|
|
44
44
|
mslxdff -chat ["prompt"] chat REPL(mimo-v2.5-free 优先/big-pickle 兜底,自然语言转命令,模糊匹配由模型完成,历史持久化,超长自动压缩,仅拦 -uninstall,daemon 重启不影响)
|
|
45
45
|
mslxdff -resetban [ip] clear join-failure bans (all, or one ip)
|
|
46
|
-
mslxdff -use-group [on|off]
|
|
46
|
+
mslxdff -use-group [on|off] 本机失败时是否走组员网络(默认 on;off 则所有供应商仅本机,MSLXDFF_USE_GROUP 环境变量可覆盖)
|
|
47
47
|
mslxdff -help show this help
|
|
48
48
|
|
|
49
49
|
Environment:
|
|
@@ -63,7 +63,7 @@ Environment:
|
|
|
63
63
|
MSLXDFF_BAN_THRESHOLD failed joins before an ip is banned (default 5)
|
|
64
64
|
MSLXDFF_BAN_WINDOW_MS ban duration after too many failures (default 48h)
|
|
65
65
|
MSLXDFF_HEDGE_DELAY_MS hedge peer race when local stream first chunk slow (default 1000, 0/off to disable)
|
|
66
|
-
MSLXDFF_USE_GROUP
|
|
66
|
+
MSLXDFF_USE_GROUP 组员中继总开关(默认 on;0/off/false 关闭后所有供应商仅本机,不走 via-route/hedge/peer/broadband)
|
|
67
67
|
MSLXDFF_AUTO_UPDATE auto-update: hourly by default, 0/off/false to disable, 1/true or ms
|
|
68
68
|
MSLXDFF_AUTO_UPDATE_MS same as above, explicit ms (overrides AUTO_UPDATE)
|
|
69
69
|
`);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// -setto opencode 条目能力注入(ADR-0016 联动):把 models.dev 能力写进 opencode.json
|
|
2
|
+
// 的 per-model 条目(opencode Model 形状,实测 debug config 原样保留并生效),
|
|
3
|
+
// 并产出一行人话摘要供 CLI 展示。查不到能力(未收录 provider/模型)时原样返回不硬造。
|
|
4
|
+
import { globalCapabilities } from "./index.js";
|
|
5
|
+
|
|
6
|
+
// "bai/glm-5.3-flash" → { provider: "bai", raw: "glm-5.3-flash" };裸 id 归 opencode
|
|
7
|
+
function splitProvider(modelId) {
|
|
8
|
+
const s = String(modelId || "").trim();
|
|
9
|
+
const i = s.indexOf("/");
|
|
10
|
+
if (i > 0) return { provider: s.slice(0, i).toLowerCase(), raw: s.slice(i + 1) };
|
|
11
|
+
return { provider: "opencode", raw: s };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// caps → opencode Model 形状增量(只含能力字段,name 等原有键不动)
|
|
15
|
+
function capsToEntryFields(caps) {
|
|
16
|
+
if (!caps) return null;
|
|
17
|
+
const fields = {
|
|
18
|
+
reasoning: Boolean(caps.reasoning),
|
|
19
|
+
tool_call: Boolean(caps.toolCall),
|
|
20
|
+
attachment: Boolean(caps.attachment),
|
|
21
|
+
temperature: Boolean(caps.temperature),
|
|
22
|
+
modalities: { input: caps.inputModalities || ["text"], output: caps.outputModalities || ["text"] },
|
|
23
|
+
limit: { context: Number(caps.context) || 0, output: Number(caps.maxOutput) || 0 },
|
|
24
|
+
};
|
|
25
|
+
if (caps.releaseDate) fields.release_date = caps.releaseDate;
|
|
26
|
+
if (caps.costIn != null || caps.costOut != null) {
|
|
27
|
+
fields.cost = { input: Number(caps.costIn) || 0, output: Number(caps.costOut) || 0 };
|
|
28
|
+
}
|
|
29
|
+
return fields;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// entry: 现有条目(含 name 等);modelId: 内部 canonical id;capsSvc: 可注入(默认全局单例)
|
|
33
|
+
// 返回 { entry: 增强后条目, caps: caps|null };服务异常静默降级(同步命令不能因目录拉取失败而挂)
|
|
34
|
+
export async function enrichOpencodeEntry(entry, modelId, capsSvc) {
|
|
35
|
+
const base = entry && typeof entry === "object" && !Array.isArray(entry) ? entry : {};
|
|
36
|
+
const svc = capsSvc === undefined ? globalCapabilities() : capsSvc;
|
|
37
|
+
if (!svc) return { entry: base, caps: null };
|
|
38
|
+
const { provider, raw } = splitProvider(modelId);
|
|
39
|
+
let caps = null;
|
|
40
|
+
try {
|
|
41
|
+
await svc.ready();
|
|
42
|
+
caps = svc.get(provider, raw) || null;
|
|
43
|
+
// 降级匹配:mslxdff 自建目录的 -free/-search-free/-expert-free 后缀在 models.dev 无后缀
|
|
44
|
+
if (!caps && /-free$/.test(raw)) caps = svc.get(provider, raw.replace(/-free$/, "")) || null;
|
|
45
|
+
} catch {
|
|
46
|
+
caps = null; // 目录不可用:降级为无能力条目(staleness 兜底在服务内已做)
|
|
47
|
+
}
|
|
48
|
+
const fields = capsToEntryFields(caps);
|
|
49
|
+
if (!fields) return { entry: base, caps: null };
|
|
50
|
+
return { entry: { ...base, ...fields }, caps };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// caps → 一行人话摘要(无有效信息返回 "",调用方按空跳过不噪音)
|
|
54
|
+
export function capsSummary(caps) {
|
|
55
|
+
if (!caps) return "";
|
|
56
|
+
const parts = [];
|
|
57
|
+
if (caps.effortType === "effort" && Array.isArray(caps.effortValues) && caps.effortValues.length) {
|
|
58
|
+
parts.push(`推理档 ${caps.effortValues.join("/")}`);
|
|
59
|
+
} else if (caps.effortType === "toggle") {
|
|
60
|
+
parts.push("推理 开关型");
|
|
61
|
+
} else if (caps.effortType === "budget_tokens") {
|
|
62
|
+
parts.push("推理 budget_tokens");
|
|
63
|
+
} else if (caps.reasoning) {
|
|
64
|
+
parts.push("推理模型");
|
|
65
|
+
}
|
|
66
|
+
if (caps.imageInput) parts.push("📷读图");
|
|
67
|
+
if (caps.context) parts.push(`上下文 ${caps.context >= 1000 ? `${Math.round(caps.context / 1000)}k` : caps.context}`);
|
|
68
|
+
if (caps.costIn != null || caps.costOut != null) {
|
|
69
|
+
parts.push(`$${caps.costIn ?? 0}/${caps.costOut ?? 0} 每M`);
|
|
70
|
+
}
|
|
71
|
+
return parts.join(" · ");
|
|
72
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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 } 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 loadedAt = 0;
|
|
32
|
+
let inflight = null;
|
|
33
|
+
|
|
34
|
+
function buildIndex(data) {
|
|
35
|
+
const idx = new Map();
|
|
36
|
+
for (const [pid, p] of Object.entries(data || {})) {
|
|
37
|
+
if (!p || typeof p !== "object") continue;
|
|
38
|
+
idx.set(pid, normalizeProviderModels(p.models || {}));
|
|
39
|
+
}
|
|
40
|
+
return idx;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function readCache() {
|
|
44
|
+
if (!cacheFile) return null;
|
|
45
|
+
try { return JSON.parse(readFileSync(cacheFile, "utf8")); } catch { return null; }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function writeCache(data) {
|
|
49
|
+
if (!cacheFile || !data) return;
|
|
50
|
+
try {
|
|
51
|
+
mkdirSync(dirname(cacheFile), { recursive: true });
|
|
52
|
+
writeFileSync(cacheFile, JSON.stringify(data));
|
|
53
|
+
} catch { /* 缓存失败不致命 */ }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function fetchFresh() {
|
|
57
|
+
const res = await fetchImpl(url, { headers: { Accept: "application/json" } });
|
|
58
|
+
if (!res?.ok) throw new Error(`models.dev fetch ${res?.status || "network"}`);
|
|
59
|
+
return res.json();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ready:缓存新鲜直接用;否则拉新;失败回退旧缓存(含磁盘),完全无数据才抛
|
|
63
|
+
async function ready() {
|
|
64
|
+
const t = now();
|
|
65
|
+
if (raw && t - loadedAt < ttl) return;
|
|
66
|
+
if (inflight) return inflight;
|
|
67
|
+
inflight = (async () => {
|
|
68
|
+
try {
|
|
69
|
+
const data = await fetchFresh();
|
|
70
|
+
raw = data;
|
|
71
|
+
capsIndex = buildIndex(data);
|
|
72
|
+
loadedAt = t;
|
|
73
|
+
writeCache(data);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (raw) return; // 内存还有旧的,继续用
|
|
76
|
+
const disk = readCache();
|
|
77
|
+
if (disk) {
|
|
78
|
+
raw = disk;
|
|
79
|
+
capsIndex = buildIndex(disk);
|
|
80
|
+
loadedAt = t; // 视作刚加载,避免每请求都重试打上游
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
throw e;
|
|
84
|
+
} finally {
|
|
85
|
+
inflight = null;
|
|
86
|
+
}
|
|
87
|
+
})();
|
|
88
|
+
return inflight;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function capsFor(pid) {
|
|
92
|
+
return capsIndex.get(pid) || null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function get(providerId, modelId) {
|
|
96
|
+
const pid = String(providerId || "opencode").toLowerCase();
|
|
97
|
+
const mid = String(modelId || "");
|
|
98
|
+
const map = capsFor(pid);
|
|
99
|
+
if (!map) return null;
|
|
100
|
+
return map[mid] || null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function list(providerId) {
|
|
104
|
+
const pid = String(providerId || "opencode").toLowerCase();
|
|
105
|
+
const map = capsFor(pid);
|
|
106
|
+
if (!map) return [];
|
|
107
|
+
return Object.entries(map).map(([id, capabilities]) => ({ id, capabilities }));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function providers() {
|
|
111
|
+
return [...capsIndex.keys()].sort();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return { ready, get, list, providers };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 模块级单例(与 globalDedup 同模式):HTTP handler 懒加载,测试 _reset 后注入
|
|
118
|
+
let _global = null;
|
|
119
|
+
export function globalCapabilities() {
|
|
120
|
+
if (!_global) _global = createCapabilitiesService({ cacheFile: defaultCacheFile() });
|
|
121
|
+
return _global;
|
|
122
|
+
}
|
|
123
|
+
export function _resetGlobalCapabilities() { _global = null; }
|
|
124
|
+
|
|
125
|
+
// 缓存落盘位置:MSLXDFF_MODELS_DEV_CACHE 覆盖 > ~/.config/mslxdff/models-dev.json(与 state 同目录)
|
|
126
|
+
function defaultCacheFile() {
|
|
127
|
+
const override = process.env.MSLXDFF_MODELS_DEV_CACHE;
|
|
128
|
+
if (override && String(override).trim()) return String(override).trim();
|
|
129
|
+
return join(homedir(), ".config", "mslxdff", "models-dev.json");
|
|
130
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// provider.models 对象({ [modelId]: rawModel })→ { [modelId]: caps }
|
|
31
|
+
export function normalizeProviderModels(modelsObj) {
|
|
32
|
+
const out = {};
|
|
33
|
+
if (!modelsObj || typeof modelsObj !== "object") return out;
|
|
34
|
+
for (const [id, m] of Object.entries(modelsObj)) {
|
|
35
|
+
if (!m || typeof m !== "object") continue;
|
|
36
|
+
out[id] = normalizeModelCaps(id, m);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
@@ -19,6 +19,22 @@ export function parseCooldown(body, status) {
|
|
|
19
19
|
return 60 * 1000;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* 真死 vs 假死:对标官方 getValidClineCredentials 契约——只有 invalid_grant
|
|
24
|
+
*(refresh token 被拒)才判死,需重新授权;网络抖动/5xx/超时是瞬时失败,
|
|
25
|
+
* 手里 token 仍有效时继续用,且绝不清掉已存凭证。
|
|
26
|
+
*/
|
|
27
|
+
export function isInvalidGrant(bodyText, status) {
|
|
28
|
+
const t = String(bodyText || "").toLowerCase();
|
|
29
|
+
if (/invalid_grant|invalid_token/.test(t)) return true;
|
|
30
|
+
// 路由拼错/版本提示类 401("...latest version...re-authenticate your Cline account")
|
|
31
|
+
// 只是打错了地址,不是 token 死,绝不能判死,否则好号会被永久冷冻。
|
|
32
|
+
if (/latest version|re-authenticate/.test(t)) return false;
|
|
33
|
+
if ((status === 400 || status === 403) && /invalid|expired|revoked/.test(t)) return true;
|
|
34
|
+
if (status === 401 && /invalid_grant|invalid token|token[^.]{0,30}(expired|revoked|invalid)/.test(t)) return true;
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
22
38
|
/**
|
|
23
39
|
* 一次性 refresh:bench/诊断用,不落盘、不建池。
|
|
24
40
|
* 返回 accessToken 或 null。
|
|
@@ -90,6 +106,7 @@ export function createAuthPool({
|
|
|
90
106
|
for (let k = 0; k < list.length; k++) {
|
|
91
107
|
const acc = list[accountIndex % list.length];
|
|
92
108
|
accountIndex = (accountIndex + 1) % list.length;
|
|
109
|
+
if (acc.dead) continue;
|
|
93
110
|
if (!acc.cooldownUntil || acc.cooldownUntil <= clock()) {
|
|
94
111
|
currentAccount = acc;
|
|
95
112
|
return acc;
|
|
@@ -100,9 +117,13 @@ export function createAuthPool({
|
|
|
100
117
|
|
|
101
118
|
async function refreshOne(account) {
|
|
102
119
|
const now = clock();
|
|
120
|
+
if (account.dead) throw new Error("invalid_grant");
|
|
103
121
|
if (account.cooldownUntil > now) throw new Error("account_cooldown");
|
|
104
122
|
if (account.accessToken && now < account.expiry) return account.accessToken;
|
|
105
|
-
|
|
123
|
+
// base 可能已含 /api/v1(state 里 clinebot baseUrl 就是 …/api/v1),直接拼会 double 成
|
|
124
|
+
// …/api/v1/api/v1/auth/refresh → 上游回 401 Unauthorized(版本/重认证提示),绝不能当 token 死。
|
|
125
|
+
const baseNoV1 = resolvedBase.replace(/\/api\/v1\/?$/, "");
|
|
126
|
+
const url = joinUrl(baseNoV1, "/api/v1/auth/refresh");
|
|
106
127
|
const opts = {
|
|
107
128
|
method: "POST",
|
|
108
129
|
headers: { "Content-Type": "application/json" },
|
|
@@ -111,7 +132,12 @@ export function createAuthPool({
|
|
|
111
132
|
if (dispatcher) opts.dispatcher = dispatcher;
|
|
112
133
|
let res;
|
|
113
134
|
try { res = await fetchImpl(url, opts); } catch { account.cooldownUntil = now + 60 * 1000; throw new Error("refresh_failed"); }
|
|
114
|
-
if (!res.ok) {
|
|
135
|
+
if (!res.ok) {
|
|
136
|
+
let t = "";
|
|
137
|
+
try { t = await res.text(); } catch {}
|
|
138
|
+
if (isInvalidGrant(t, res.status)) { account.dead = true; throw new Error("invalid_grant"); }
|
|
139
|
+
account.cooldownUntil = now + 60 * 1000; throw new Error("refresh_failed");
|
|
140
|
+
}
|
|
115
141
|
let data;
|
|
116
142
|
try { data = await res.json(); } catch { account.cooldownUntil = now + 60 * 1000; throw new Error("refresh_no_token"); }
|
|
117
143
|
const accessToken = data?.data?.accessToken || data?.accessToken || data?.access_token;
|
|
@@ -138,11 +164,12 @@ export function createAuthPool({
|
|
|
138
164
|
if (pool.length === 0) throw new Error("缺少 CLINE_REFRESH_TOKEN(请用 cline_oauth.py 获取)");
|
|
139
165
|
for (let attempt = 0; attempt < pool.length; attempt++) {
|
|
140
166
|
const acc = pool[attempt % pool.length];
|
|
167
|
+
if (acc.dead) continue;
|
|
141
168
|
if (acc.cooldownUntil && acc.cooldownUntil > clock()) continue;
|
|
142
169
|
currentAccount = acc;
|
|
143
170
|
try { return await refreshOne(acc); } catch (e) { if (e.message === "account_cooldown") continue; continue; }
|
|
144
171
|
}
|
|
145
|
-
const acc = pool
|
|
172
|
+
const acc = pool.find((a) => !a.dead) || null;
|
|
146
173
|
if (!acc) throw new Error("无可用 Cline 账号");
|
|
147
174
|
currentAccount = acc;
|
|
148
175
|
acc.cooldownUntil = 0;
|
|
@@ -155,9 +155,14 @@ export function createChatService({
|
|
|
155
155
|
const sessionId = genSessionId();
|
|
156
156
|
const isStream = body?.stream === true;
|
|
157
157
|
const upstreamModel = stripProviderPrefix(model);
|
|
158
|
+
// token 口径双写:对标官方 withMaxCompletionTokensForReasoningModels——
|
|
159
|
+
// cline 上游默认 reasoning_effort high,推理模型认 max_completion_tokens,
|
|
160
|
+
// 只发 max_tokens 会被部分通道拒;双写兼容最稳。
|
|
161
|
+
const tokLimit = body?.max_tokens || body?.max_completion_tokens || 4096;
|
|
158
162
|
const upstreamBody = {
|
|
159
163
|
model: upstreamModel,
|
|
160
|
-
max_tokens:
|
|
164
|
+
max_tokens: tokLimit,
|
|
165
|
+
max_completion_tokens: tokLimit,
|
|
161
166
|
session_id: sessionId,
|
|
162
167
|
reasoning_effort: body?.reasoning_effort || body?.reasoningEffort || "high",
|
|
163
168
|
messages: body?.messages || [],
|
|
@@ -16,10 +16,34 @@ export function createModelsService({ id, baseUrl, modelsPath, fetchImpl, dispat
|
|
|
16
16
|
let cache = null;
|
|
17
17
|
let fetchedAt = 0;
|
|
18
18
|
|
|
19
|
+
// 离线兜底:对标官方 FALLBACK(free 数组实证含 z-ai/glm-5.3-flash)。
|
|
20
|
+
// 上游挂了/401 时也不返回空数组,保证 -provider clinebot models 与 picks 仍有免费可用。
|
|
21
|
+
const FALLBACK_FREE = [
|
|
22
|
+
{ id: "deepseek/deepseek-v4-flash", name: "deepseek-v4-flash" },
|
|
23
|
+
{ id: "z-ai/glm-5.3-flash", name: "glm-5.3-flash" },
|
|
24
|
+
{ id: "poolside/laguna-s-2.1:free", name: "laguna-s-2.1:free" },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
function fallbackList() {
|
|
28
|
+
const out = FALLBACK_FREE.map((m) => ({ ...m, id: joinModelId(id, m.id) }));
|
|
29
|
+
cache = out; fetchedAt = Date.now();
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 端点归一化:官方取 {bareHost}/api/v1/ai/cline/recommended-models。
|
|
34
|
+
// baseUrl 可能是裸 host(https://api.cline.bot)也可能是带 /api/v1 的,
|
|
35
|
+
// 统一收敛到 …/api/v1/ai/cline/recommended-models;用户自定义 path 原样尊重。
|
|
36
|
+
function resolveModelsUrl() {
|
|
37
|
+
const custom = modelsPath && modelsPath !== "/models" && modelsPath !== "/ai/cline/recommended-models";
|
|
38
|
+
if (custom) return joinUrl(resolvedBase, resolvedPath);
|
|
39
|
+
const bare = resolvedBase.replace(/\/api\/v1\/?$/, "");
|
|
40
|
+
return joinUrl(bare, "/api/v1/ai/cline/recommended-models");
|
|
41
|
+
}
|
|
42
|
+
|
|
19
43
|
async function listModels() {
|
|
20
44
|
const now = Date.now();
|
|
21
45
|
if (cache && now - fetchedAt < CACHE_TTL) return cache;
|
|
22
|
-
const url =
|
|
46
|
+
const url = resolveModelsUrl();
|
|
23
47
|
const controller = new AbortController();
|
|
24
48
|
const timer = setTimeout(() => controller.abort(new Error(`${id} models timed out`)), 15_000);
|
|
25
49
|
try {
|
|
@@ -29,20 +53,22 @@ export function createModelsService({ id, baseUrl, modelsPath, fetchImpl, dispat
|
|
|
29
53
|
const opts = { headers, signal: controller.signal };
|
|
30
54
|
if (dispatcher) opts.dispatcher = dispatcher;
|
|
31
55
|
const res = await fetchImpl(url, opts);
|
|
32
|
-
if (!res.ok) return
|
|
56
|
+
if (!res.ok) return fallbackList();
|
|
33
57
|
const json = await res.json().catch(() => ({}));
|
|
34
58
|
if (isClineBotHost(resolvedBase) && Array.isArray(json.free)) {
|
|
35
59
|
const out = json.free.filter((m) => m && typeof m.id === "string").map((m) => ({ ...m, id: joinModelId(id, m.id) }));
|
|
60
|
+
if (!out.length) return fallbackList();
|
|
36
61
|
cache = out; fetchedAt = now; return out;
|
|
37
62
|
}
|
|
38
63
|
const raw = Array.isArray(json.data) ? json.data : Array.isArray(json.models) ? json.models : Array.isArray(json) ? json : [];
|
|
39
64
|
const out = raw.filter((m) => m && typeof m.id === "string").map((m) => ({ ...m, id: joinModelId(id, m.id) }));
|
|
65
|
+
if (!out.length) return fallbackList();
|
|
40
66
|
cache = out; fetchedAt = now; return out;
|
|
41
|
-
} catch { return
|
|
67
|
+
} catch { return fallbackList(); } finally { clearTimeout(timer); }
|
|
42
68
|
}
|
|
43
69
|
|
|
44
70
|
async function preheat() {
|
|
45
|
-
const url =
|
|
71
|
+
const url = resolveModelsUrl();
|
|
46
72
|
const t0 = performance.now();
|
|
47
73
|
try {
|
|
48
74
|
const headers = { Accept: "application/json" };
|
package/src/routes/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { json, notFound, authorized } from "./helpers.js";
|
|
|
4
4
|
import { chatHandler } from "./chat.js";
|
|
5
5
|
import { joinHandler, leaveHandler } from "./groups.js";
|
|
6
6
|
import { heartbeatHandler, pollHandler, resultHandler, forwardHandler, streamHandler } from "./groups-relay.js";
|
|
7
|
-
import { modelsHandler, modelsStatusHandler, providerModelsHandler } from "./models-route.js";
|
|
7
|
+
import { modelsHandler, modelsStatusHandler, providerModelsHandler, capabilitiesHandler } from "./models-route.js";
|
|
8
8
|
import { relayHandler } from "./relay.js";
|
|
9
9
|
import { responsesHandler } from "./responses-route.js";
|
|
10
10
|
|
|
@@ -110,6 +110,12 @@ const ROUTES = [
|
|
|
110
110
|
requiresAuth: true,
|
|
111
111
|
handler: modelsStatusHandler,
|
|
112
112
|
},
|
|
113
|
+
{
|
|
114
|
+
method: "GET",
|
|
115
|
+
path: "/v1/models/capabilities",
|
|
116
|
+
requiresAuth: true,
|
|
117
|
+
handler: capabilitiesHandler,
|
|
118
|
+
},
|
|
113
119
|
];
|
|
114
120
|
|
|
115
121
|
// re-export for facade & tests
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { json, errMsg } from "./helpers.js";
|
|
2
2
|
import { runHook } from "../plugins.js";
|
|
3
3
|
import { isModelAllowed } from "../state.js";
|
|
4
|
+
import { globalCapabilities } from "../model-capabilities/index.js";
|
|
4
5
|
|
|
5
6
|
// Codex 自定义 provider 拉目录要顶层 `models` 数组(codex-rs endpoint/models.rs 解 ModelsResponse{models}),
|
|
6
7
|
// 给它 OpenAI 标准 {object,data} 会报 missing field `models`。学 OmniRoute:仅 codex 调用者追加空数组
|
|
@@ -83,3 +84,28 @@ export async function providerModelsHandler({ req, res, models }) {
|
|
|
83
84
|
json(res, 502, { error: errMsg(err) });
|
|
84
85
|
}
|
|
85
86
|
}
|
|
87
|
+
|
|
88
|
+
// GET /v1/models/capabilities[?provider=opencode][&id=big-pickle]
|
|
89
|
+
// 模型能力元数据(reasoning 档位/图片输入/tool_call/上下文/价格),源 = opencode 官方 models.dev 目录
|
|
90
|
+
// jsonFn 注入仅为测试接缝(S3);生产路径用 helpers.json
|
|
91
|
+
export async function capabilitiesHandler({ req, res, capabilities, jsonFn = json }) {
|
|
92
|
+
// 仅未注入(生产)时用全局单例;显式 null 视作服务不可用(测试可复现 502 空状态)
|
|
93
|
+
const svc = capabilities === undefined ? globalCapabilities() : capabilities;
|
|
94
|
+
if (!svc) return jsonFn(res, 502, { error: "capabilities service unavailable" });
|
|
95
|
+
const q = String(req?.url || "").split("?")[1] || "";
|
|
96
|
+
const params = new URLSearchParams(q);
|
|
97
|
+
const provider = (params.get("provider") || "opencode").toLowerCase();
|
|
98
|
+
const id = params.get("id") || "";
|
|
99
|
+
try {
|
|
100
|
+
await svc.ready();
|
|
101
|
+
} catch (err) {
|
|
102
|
+
return jsonFn(res, 502, { error: `capabilities source unavailable: ${errMsg(err)}` });
|
|
103
|
+
}
|
|
104
|
+
if (id) {
|
|
105
|
+
const caps = svc.get(provider, id);
|
|
106
|
+
if (!caps) return jsonFn(res, 404, { error: `model '${id}' not found in capabilities catalog (provider=${provider})` });
|
|
107
|
+
return jsonFn(res, 200, { object: "model.capabilities", id, provider, capabilities: caps });
|
|
108
|
+
}
|
|
109
|
+
const data = svc.list(provider);
|
|
110
|
+
return jsonFn(res, 200, { object: "list", provider, data });
|
|
111
|
+
}
|
|
@@ -35,19 +35,8 @@ export function getEffectiveUseGroup({ file = defaultStateFile() } = {}) {
|
|
|
35
35
|
return loadUseGroup({ file });
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
//
|
|
38
|
+
// 全局开关:off 则所有供应商都不走组员网络(via-route/hedge/peer/broadband 全禁),仅本机直连
|
|
39
39
|
export function shouldUseGroupForModel(model, { file = defaultStateFile() } = {}) {
|
|
40
|
-
const m = String(model || "").trim();
|
|
41
|
-
if (!m) return getEffectiveUseGroup({ file });
|
|
42
|
-
// 带前缀:判断是否为 opencode
|
|
43
|
-
if (m.includes("/")) {
|
|
44
|
-
const head = m.split("/")[0].trim().toLowerCase();
|
|
45
|
-
if (head === "opencode" || head === "oc") {
|
|
46
|
-
return getEffectiveUseGroup({ file });
|
|
47
|
-
}
|
|
48
|
-
return true; // 其他供应商不受此开关限制
|
|
49
|
-
}
|
|
50
|
-
// 裸 id 视为 opencode
|
|
51
40
|
return getEffectiveUseGroup({ file });
|
|
52
41
|
}
|
|
53
42
|
|
package/src/sync-opencode.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync, mkdirSync, existsSync, renameSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import os from "node:os";
|
|
4
|
+
import { enrichOpencodeEntry, capsSummary as capsSummaryText } from "./model-capabilities/enrich.js";
|
|
4
5
|
|
|
5
6
|
export function opencodeConfigPath() {
|
|
6
7
|
const env = process.env.OPENCODE_CONFIG || process.env.OPENCODE_CONFIG_PATH;
|
|
@@ -79,21 +80,35 @@ export function pruneOpencodeModels(models, keep, currentKey) {
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
// 补齐:把 ensureAll(picks 口径)里缺失的键写入 models(slash → dash + alias 注册)。
|
|
82
|
-
//
|
|
83
|
+
// 已存在但为旧格式(缺 limit 能力字段)的条目也自动补注能力(upgraded 计数)。
|
|
84
|
+
// 返回 { nextModels, backfilled, upgraded };ensureAll 非数组或为空时原样返回。
|
|
83
85
|
// 注意:需在剪枝之前调用——先补 picks 缺失,再剪 picks 外旧键,结果集恰为 picks ∪ currentKey。
|
|
84
|
-
|
|
86
|
+
// capsSvc 透传给能力注入(undefined=全局单例;补齐的条目同样带能力)。
|
|
87
|
+
export async function ensureAllOpencodeModels(models, ensureAll, capsSvc) {
|
|
85
88
|
if (!Array.isArray(ensureAll) || !ensureAll.length || !models || typeof models !== "object") {
|
|
86
|
-
return { nextModels: models, backfilled: 0 };
|
|
89
|
+
return { nextModels: models, backfilled: 0, upgraded: 0 };
|
|
87
90
|
}
|
|
88
91
|
const existing = new Set(Object.keys(models).map(normalizeOpencodeKey));
|
|
89
92
|
let backfilled = 0;
|
|
93
|
+
let upgraded = 0;
|
|
90
94
|
let aliasDirty = false;
|
|
91
95
|
for (const raw of ensureAll) {
|
|
92
96
|
const internal = toInternalId(String(raw || "").trim());
|
|
93
97
|
if (!internal || internal === "auto") continue;
|
|
94
98
|
const storageKey = internal.includes("/") ? internal.replace(/\//g, "-") : internal;
|
|
95
|
-
if (!storageKey
|
|
96
|
-
|
|
99
|
+
if (!storageKey) continue;
|
|
100
|
+
if (existing.has(storageKey)) {
|
|
101
|
+
// 已存在:旧格式条目(仅 name、无能力字段)自动升级注入;已带 limit 的新格式不动
|
|
102
|
+
const cur = models[storageKey];
|
|
103
|
+
if (cur && typeof cur === "object" && !Array.isArray(cur) && cur.limit === undefined) {
|
|
104
|
+
const en = await enrichOpencodeEntry(cur, internal, capsSvc);
|
|
105
|
+
models[storageKey] = en.entry;
|
|
106
|
+
if (en.caps) upgraded++;
|
|
107
|
+
}
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const enriched = await enrichOpencodeEntry({ name: storageKey }, internal, capsSvc);
|
|
111
|
+
models[storageKey] = enriched.entry;
|
|
97
112
|
existing.add(storageKey);
|
|
98
113
|
backfilled++;
|
|
99
114
|
if (internal.includes("/") && storageKey !== internal) {
|
|
@@ -111,10 +126,10 @@ export async function ensureAllOpencodeModels(models, ensureAll) {
|
|
|
111
126
|
persistModelAliases();
|
|
112
127
|
} catch {}
|
|
113
128
|
}
|
|
114
|
-
return { nextModels: models, backfilled };
|
|
129
|
+
return { nextModels: models, backfilled, upgraded };
|
|
115
130
|
}
|
|
116
131
|
|
|
117
|
-
export async function syncToOpencode({ id, token, port, file, keep, ensureAll } = {}) {
|
|
132
|
+
export async function syncToOpencode({ id, token, port, file, keep, ensureAll, capabilities } = {}) {
|
|
118
133
|
const targetFile = file || opencodeConfigPath();
|
|
119
134
|
const normalizedRaw = String(id || "").trim();
|
|
120
135
|
if (!normalizedRaw) throw new Error("model id required");
|
|
@@ -156,6 +171,8 @@ export async function syncToOpencode({ id, token, port, file, keep, ensureAll }
|
|
|
156
171
|
let effectiveId = storageKey;
|
|
157
172
|
let pruned = 0;
|
|
158
173
|
let backfilled = 0;
|
|
174
|
+
let upgraded = 0;
|
|
175
|
+
let currentCaps = null;
|
|
159
176
|
if (oldProvider) {
|
|
160
177
|
const oldModels = oldProvider.models && typeof oldProvider.models === "object" && !Array.isArray(oldProvider.models)
|
|
161
178
|
? oldProvider.models
|
|
@@ -187,16 +204,21 @@ export async function syncToOpencode({ id, token, port, file, keep, ensureAll }
|
|
|
187
204
|
if (nextModels[legacyAlias]) delete nextModels[legacyAlias];
|
|
188
205
|
if (legacyInternal !== legacyAlias && nextModels[legacyInternal]) delete nextModels[legacyInternal];
|
|
189
206
|
}
|
|
190
|
-
|
|
207
|
+
const enriched = await enrichOpencodeEntry({ ...merged, name: storageKey }, internal, capabilities);
|
|
208
|
+
nextModels[storageKey] = enriched.entry;
|
|
209
|
+
currentCaps = enriched.caps;
|
|
191
210
|
effectiveId = storageKey;
|
|
192
211
|
action = "updated";
|
|
193
212
|
} else {
|
|
194
|
-
|
|
213
|
+
const enriched = await enrichOpencodeEntry({ name: storageKey }, internal, capabilities);
|
|
214
|
+
nextModels[storageKey] = enriched.entry;
|
|
215
|
+
currentCaps = enriched.caps;
|
|
195
216
|
effectiveId = storageKey;
|
|
196
217
|
action = "inserted";
|
|
197
218
|
}
|
|
198
|
-
const ensured = await ensureAllOpencodeModels(nextModels, ensureAll);
|
|
219
|
+
const ensured = await ensureAllOpencodeModels(nextModels, ensureAll, capabilities);
|
|
199
220
|
backfilled = ensured.backfilled;
|
|
221
|
+
upgraded = ensured.upgraded || 0;
|
|
200
222
|
pruned = pruneOpencodeModels(nextModels, keep, storageKey);
|
|
201
223
|
const nextProvider = {
|
|
202
224
|
...oldProvider,
|
|
@@ -216,8 +238,12 @@ export async function syncToOpencode({ id, token, port, file, keep, ensureAll }
|
|
|
216
238
|
if (!data.provider.mslxdff.models[storageKey]) {
|
|
217
239
|
data.provider.mslxdff.models = { [storageKey]: { name: storageKey } };
|
|
218
240
|
}
|
|
219
|
-
const
|
|
241
|
+
const enrichedNew = await enrichOpencodeEntry(data.provider.mslxdff.models[storageKey], internal, capabilities);
|
|
242
|
+
data.provider.mslxdff.models[storageKey] = enrichedNew.entry;
|
|
243
|
+
currentCaps = enrichedNew.caps;
|
|
244
|
+
const ensured = await ensureAllOpencodeModels(data.provider.mslxdff.models, ensureAll, capabilities);
|
|
220
245
|
backfilled = ensured.backfilled;
|
|
246
|
+
upgraded = ensured.upgraded || 0;
|
|
221
247
|
action = "inserted";
|
|
222
248
|
}
|
|
223
249
|
|
|
@@ -249,5 +275,5 @@ export async function syncToOpencode({ id, token, port, file, keep, ensureAll }
|
|
|
249
275
|
}
|
|
250
276
|
} catch {}
|
|
251
277
|
|
|
252
|
-
return { action, file: targetFile, id: effectiveId, alias: storageKey, internal, corrupted, storageKey, pruned, backfilled };
|
|
278
|
+
return { action, file: targetFile, id: effectiveId, alias: storageKey, internal, corrupted, storageKey, pruned, backfilled, upgraded, caps: currentCaps, capsSummaryText: capsSummaryText(currentCaps) };
|
|
253
279
|
}
|