mslxdff 0.1.171 → 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/package.json
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// 模型上下文窗口的四级解析(ADR-0054):/v1/models 富化时唯一真相源。
|
|
2
|
+
// 旧状:顶层 context_length(provider 自报)与 capabilities.context(models.dev)两套并行可能矛盾,
|
|
3
|
+
// 且四层全空时什么都不报;本模块把优先级收死,并保证"双层同源同值"。
|
|
4
|
+
// 纯函数 + env,无 IO 无网络(L1/L2/L4 不依赖目录,冷缓存/目录挂掉照常生效)。
|
|
5
|
+
// L4 方向沿上游 workbuddy2api-hub:"未知报 1M——高估比低估安全"(只作元数据,网关转发不读它)。
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_CONTEXT_FALLBACK = 1_000_000;
|
|
8
|
+
|
|
9
|
+
/** L4 兜底值:`MSLXDFF_MODEL_CONTEXT_FALLBACK` 覆盖;0/负数 = 关闭兜底(回"未知不报"旧口径);非法值按默认 1M。 */
|
|
10
|
+
export function contextFallback() {
|
|
11
|
+
const raw = String(process.env.MSLXDFF_MODEL_CONTEXT_FALLBACK ?? "").trim();
|
|
12
|
+
if (raw === "") return DEFAULT_CONTEXT_FALLBACK;
|
|
13
|
+
const n = Number(raw);
|
|
14
|
+
if (!Number.isFinite(n)) return DEFAULT_CONTEXT_FALLBACK;
|
|
15
|
+
if (n <= 0) return 0;
|
|
16
|
+
const f = Math.floor(n);
|
|
17
|
+
return f > 0 ? f : DEFAULT_CONTEXT_FALLBACK; // (0,1) 被.floor 成 0 会静默变"关兜底",按非法回默认
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function positiveInt(v) {
|
|
21
|
+
if (typeof v !== "number" && typeof v !== "string") return null; // boolean/数组/对象 = 未自报,不猜
|
|
22
|
+
const n = Number(v);
|
|
23
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** L1 条目自报(first-party 最准)。键序覆盖现网全部自报形状;非数字/0/负数 = 未自报,丢弃而非钳制。 */
|
|
27
|
+
export function firstPartyContextOf(entry) {
|
|
28
|
+
if (!entry || typeof entry !== "object") return null;
|
|
29
|
+
for (const v of [entry.context_length, entry.maxInputTokens, entry.max_input_tokens]) {
|
|
30
|
+
const n = positiveInt(v);
|
|
31
|
+
if (n) return n;
|
|
32
|
+
}
|
|
33
|
+
const cw = entry.contextWindow;
|
|
34
|
+
return positiveInt(cw && typeof cw === "object" ? cw.defaultLength : cw);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// L2 内置知识表:给"provider 目录不自报窗口、且值有官方/上游文档出处"的模型补一手。
|
|
38
|
+
// 准入红线(评审过:无据值不得进表——traework 硬编码 131072 正是反面教材,本次已删):
|
|
39
|
+
// - key = **实际传入解析器的条目 id 小写**(现网含裸 id 与 `-free` 后缀形态;填表前必须按此对键,
|
|
40
|
+
// 跨 provider 撞名靠带前缀的 id 天然区分),别照 ADR 初稿的 `prov/raw` canonical 形去猜;
|
|
41
|
+
// - 每条必须带 source 出处注释(文档/上游字段 + 核对日期),给不出出处就让它落 L4 兜底。
|
|
42
|
+
// 首期为空是盘点结论:raccoon/qoder/codearts/workbuddy/globalworkbuddy/qwenwork 系的有据值全部已被 L1 覆盖,
|
|
43
|
+
// 把 L1 复制进表只会制造第二个真相源。等出现"只回 id 的极简目录 provider"之类的真缺口再填。
|
|
44
|
+
export const KNOWN_CONTEXT = Object.freeze({});
|
|
45
|
+
|
|
46
|
+
/** L2 查表(按条目 id 小写);未命中或值非法返回 null。`table` 为测试注入口(缺省用内置表)。 */
|
|
47
|
+
export function knownContextOf(id, table = KNOWN_CONTEXT) {
|
|
48
|
+
const e = table[String(id || "").trim().toLowerCase()];
|
|
49
|
+
return e ? positiveInt(e.context) : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 四级解析:L1 自报 > L2 内置表 > L3 models.dev caps > L4 兜底。
|
|
54
|
+
* 返回正整数;env 关闭兜底且 L1–L3 全空时返回 null(调用方两层都不写)。
|
|
55
|
+
* `knownTable` 仅供测试注入假表锁 L2>L3 顺序,生产调用方不传。
|
|
56
|
+
*/
|
|
57
|
+
export function resolveContextLength({ entry, id, caps, knownTable } = {}) {
|
|
58
|
+
const fp = firstPartyContextOf(entry);
|
|
59
|
+
if (fp) return fp;
|
|
60
|
+
const known = knownContextOf(id, knownTable);
|
|
61
|
+
if (known) return known;
|
|
62
|
+
const c = positiveInt(caps?.context);
|
|
63
|
+
if (c) return c;
|
|
64
|
+
return contextFallback() || null;
|
|
65
|
+
}
|
|
@@ -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
|
}
|
|
@@ -3,7 +3,8 @@ import { AGENT_HOST, EP_MODELS, FUNCTION, DEFAULT_MODEL } from "./constants.js";
|
|
|
3
3
|
import { soloHeaders } from "./headers.js";
|
|
4
4
|
import { joinModelId } from "../model-id.js";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// 窗口自报已删(ADR-0054):此前对所有模型硬编码 context_length=131072,无任何依据;
|
|
7
|
+
// 现交由 /v1/models 富化的四级解析统一裁决——本 provider 不自报,未知落 1M 兜底。
|
|
7
8
|
const CREATED = 1753600000;
|
|
8
9
|
const OWNER = "trae-solo";
|
|
9
10
|
|
|
@@ -19,7 +20,7 @@ export const STATIC_MODEL_IDS = [
|
|
|
19
20
|
];
|
|
20
21
|
|
|
21
22
|
export function staticModels(id = "traework") {
|
|
22
|
-
return STATIC_MODEL_IDS.map((m) => ({ id: joinModelId(id, m), object: "model", created: CREATED, owned_by: OWNER
|
|
23
|
+
return STATIC_MODEL_IDS.map((m) => ({ id: joinModelId(id, m), object: "model", created: CREATED, owned_by: OWNER }));
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export function normalizeModelName(s) {
|
|
@@ -78,7 +79,7 @@ export function createModelsService({
|
|
|
78
79
|
if (cache && now - fetchedAt < CACHE_TTL_MS) return cache;
|
|
79
80
|
try {
|
|
80
81
|
const dyn = await fetchDynamic();
|
|
81
|
-
cache = dyn.map((m) => ({ id: joinModelId(id, m.id), object: "model", created: CREATED, owned_by: OWNER,
|
|
82
|
+
cache = dyn.map((m) => ({ id: joinModelId(id, m.id), object: "model", created: CREATED, owned_by: OWNER, name: m.name }));
|
|
82
83
|
fetchedAt = now;
|
|
83
84
|
return cache;
|
|
84
85
|
} catch {
|