@cydm/pie 4.8.0 → 4.9.0
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/README.md +51 -27
- package/dist/builtin/extensions/ask-user/index.js +4 -4
- package/dist/builtin/extensions/cron/index.js +906 -158
- package/dist/builtin/extensions/im-forward/README.md +4 -2
- package/dist/builtin/extensions/im-forward/index.js +6822 -3951
- package/dist/builtin/extensions/memory/index.js +76 -28
- package/dist/builtin/extensions/pie-ipc/README.md +2 -2
- package/dist/builtin/extensions/pie-ipc/index.js +282 -58
- package/dist/builtin/extensions/pie-proc/README.md +7 -7
- package/dist/builtin/extensions/pie-proc/index.js +227 -75
- package/dist/builtin/extensions/plan-mode/index.js +5 -5
- package/dist/builtin/extensions/subagent/index.js +8 -8
- package/dist/builtin/extensions/todo/index.js +4 -4
- package/dist/builtin/skills/chrome-devtools-axi/SKILL.md +26 -24
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +199 -121
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/chunk-HAUDUMDO.js +795 -0
- package/dist/builtin/skills/chrome-devtools-axi/{cli-ZE754CTH.js → cli-K7ESY3XD.js} +433 -255
- package/dist/builtin/skills/computer-use-axi/SKILL.md +25 -8
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +293 -64
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-runtime.js +2 -2
- package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +451 -43
- package/dist/chunks/{chunk-3W3SXVPB.js → chunk-4UIUMTHG.js} +993 -371
- package/dist/chunks/chunk-6WKBQZWM.js +19 -0
- package/dist/chunks/{chunk-5KI4Y4LA.js → chunk-BA4Z27XT.js} +4 -3
- package/dist/chunks/{chunk-BLDI2GRF.js → chunk-DBDU3RRN.js} +1364 -446
- package/dist/chunks/{chunk-LAJXWOKS.js → chunk-EEC5PJTC.js} +11 -9
- package/dist/chunks/chunk-IZKHSUNQ.js +30 -0
- package/dist/chunks/{chunk-Y3I2UV5Y.js → chunk-LRHNAG4V.js} +349 -288
- package/dist/chunks/chunk-OU33ROFD.js +717 -0
- package/dist/chunks/{chunk-Z2FKA2ZH.js → chunk-PN6B54VT.js} +104 -22
- package/dist/chunks/{chunk-NHV2CALB.js → chunk-WYXUF4MP.js} +388 -32
- package/dist/chunks/{chunk-4PR34UZF.js → chunk-Z5KL6AO2.js} +159 -145
- package/dist/chunks/{host-image-fallback-N7RHNPYN.js → host-image-fallback-RASJSVZY.js} +1 -1
- package/dist/chunks/{manager-cli-NEZA46M5.js → manager-cli-Y6HM3MHA.js} +5 -5
- package/dist/chunks/{model-registry-3XAHXXTA.js → model-registry-5TLYILYR.js} +2 -2
- package/dist/chunks/{read-file-understanding-FMPXR6EJ.js → read-file-understanding-VPKDBV23.js} +5 -5
- package/dist/chunks/{src-B44QWSGM.js → src-2XI5P62J.js} +2 -2
- package/dist/chunks/{src-EGXFJ3WA.js → src-6QGGDHIW.js} +3 -3
- package/dist/chunks/{src-Q7LU27C2.js → src-CCEENRKC.js} +31 -1
- package/dist/chunks/{src-CLE5ILN4.js → src-DI4MCAGT.js} +20 -4
- package/dist/chunks/{test-stream-OR3EJBNF.js → test-stream-SYVWIPPW.js} +2 -2
- package/dist/cli.js +1890 -1489
- package/models.schema.json +271 -0
- package/package.json +2 -2
- package/dist/builtin/skills/chrome-devtools-axi/chunk-Z2A5LA5A.js +0 -407
- package/dist/chunks/chunk-EGZ5TZRM.js +0 -1444
- package/dist/chunks/{chunk-CGSFBWOM.js → chunk-WBL73KRI.js} +3 -3
- package/dist/chunks/{manager-upgrade-CTU3ISCW.js → manager-upgrade-LSTOHBUV.js} +3 -3
|
@@ -3,19 +3,354 @@ import {
|
|
|
3
3
|
getConfigDir
|
|
4
4
|
} from "./chunk-CBDQJMUI.js";
|
|
5
5
|
import {
|
|
6
|
+
ACTIVE_THINKING_LEVELS,
|
|
7
|
+
ALL_THINKING_LEVELS,
|
|
6
8
|
MODEL_CLASS_FALLBACK_ORDER,
|
|
9
|
+
isDisableWireCompatibleWithApi,
|
|
10
|
+
isThinkingModeCompatibleWithApi,
|
|
11
|
+
isThinkingSelectionLevel,
|
|
7
12
|
modelSupportsToolPurpose,
|
|
8
13
|
requiredCapabilityForToolPurpose,
|
|
9
14
|
sortToolModelCandidatesByCapability
|
|
10
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-4UIUMTHG.js";
|
|
11
16
|
|
|
12
17
|
// src/core/model-registry.ts
|
|
13
18
|
import * as fs from "fs";
|
|
14
19
|
import * as path from "path";
|
|
15
20
|
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
21
|
+
|
|
22
|
+
// src/core/thinking-capability-validation.ts
|
|
23
|
+
var THINKING_MODES = /* @__PURE__ */ new Set(["none", "effort", "adaptive", "budget"]);
|
|
24
|
+
var DISABLE_WIRES = /* @__PURE__ */ new Set(["omit", "none", "disabled"]);
|
|
25
|
+
var EFFORT_WIRES = /* @__PURE__ */ new Set(["none", ...ACTIVE_THINKING_LEVELS]);
|
|
26
|
+
var ADAPTIVE_WIRE_EFFORTS = /* @__PURE__ */ new Set(["low", "medium", "high", "max"]);
|
|
27
|
+
var ACTIVE_LEVEL_SET = new Set(ACTIVE_THINKING_LEVELS);
|
|
28
|
+
var THINKING_KEYS = /* @__PURE__ */ new Set([
|
|
29
|
+
"mode",
|
|
30
|
+
"supportedLevels",
|
|
31
|
+
"defaultLevel",
|
|
32
|
+
"disableWire",
|
|
33
|
+
"effortMap",
|
|
34
|
+
"budgets",
|
|
35
|
+
"minBudgetTokens",
|
|
36
|
+
"maxBudgetTokens",
|
|
37
|
+
"outputAllowance"
|
|
38
|
+
]);
|
|
39
|
+
function isPlainRecord(value) {
|
|
40
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
41
|
+
const proto = Object.getPrototypeOf(value);
|
|
42
|
+
return proto === Object.prototype || proto === null;
|
|
43
|
+
}
|
|
44
|
+
function validateBudgetMap(value, label) {
|
|
45
|
+
if (value === void 0) return;
|
|
46
|
+
if (!isPlainRecord(value)) throw new Error(`${label} must be an object`);
|
|
47
|
+
for (const [level, tokens] of Object.entries(value)) {
|
|
48
|
+
if (!ACTIVE_LEVEL_SET.has(level)) {
|
|
49
|
+
throw new Error(`${label}.${level} is unsupported`);
|
|
50
|
+
}
|
|
51
|
+
if (typeof tokens !== "number" || !Number.isFinite(tokens) || !Number.isInteger(tokens) || tokens < 0) {
|
|
52
|
+
throw new Error(`${label}.${level} must be a non-negative integer`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function validateThinkingCapability(value, label) {
|
|
57
|
+
if (value === void 0) return;
|
|
58
|
+
if (!isPlainRecord(value)) throw new Error(`${label} must be an object`);
|
|
59
|
+
for (const key of Object.keys(value)) {
|
|
60
|
+
if (!THINKING_KEYS.has(key)) throw new Error(`${label} contains unsupported field ${key}`);
|
|
61
|
+
}
|
|
62
|
+
if (typeof value.mode !== "string" || !THINKING_MODES.has(value.mode)) {
|
|
63
|
+
throw new Error(`${label}.mode must be one of none | effort | adaptive | budget`);
|
|
64
|
+
}
|
|
65
|
+
if (value.supportedLevels !== void 0) {
|
|
66
|
+
if (!Array.isArray(value.supportedLevels) || value.supportedLevels.length === 0) {
|
|
67
|
+
throw new Error(`${label}.supportedLevels must be a non-empty array`);
|
|
68
|
+
}
|
|
69
|
+
const seen = /* @__PURE__ */ new Set();
|
|
70
|
+
for (const level of value.supportedLevels) {
|
|
71
|
+
if (!isThinkingSelectionLevel(level)) {
|
|
72
|
+
throw new Error(`${label}.supportedLevels contains unsupported level ${String(level)} (allowed: ${ALL_THINKING_LEVELS.join(", ")})`);
|
|
73
|
+
}
|
|
74
|
+
if (seen.has(level)) {
|
|
75
|
+
throw new Error(`${label}.supportedLevels contains duplicate level ${level}`);
|
|
76
|
+
}
|
|
77
|
+
if (value.mode === "none" && level !== "off") {
|
|
78
|
+
throw new Error(`${label}.supportedLevels can only include "off" when mode is "none"`);
|
|
79
|
+
}
|
|
80
|
+
seen.add(level);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (value.defaultLevel !== void 0) {
|
|
84
|
+
if (!isThinkingSelectionLevel(value.defaultLevel)) {
|
|
85
|
+
throw new Error(`${label}.defaultLevel is invalid`);
|
|
86
|
+
}
|
|
87
|
+
if (value.mode === "none" && value.defaultLevel !== "off") {
|
|
88
|
+
throw new Error(`${label}.defaultLevel must be "off" when mode is "none"`);
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(value.supportedLevels) && !value.supportedLevels.includes(value.defaultLevel)) {
|
|
91
|
+
throw new Error(`${label}.defaultLevel "${value.defaultLevel}" must be included in supportedLevels (${value.supportedLevels.join(", ")})`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (value.disableWire !== void 0 && (typeof value.disableWire !== "string" || !DISABLE_WIRES.has(value.disableWire))) {
|
|
95
|
+
throw new Error(`${label}.disableWire must be one of omit | none | disabled`);
|
|
96
|
+
}
|
|
97
|
+
const effortMapRecord = isPlainRecord(value.effortMap) ? value.effortMap : void 0;
|
|
98
|
+
if (value.effortMap !== void 0) {
|
|
99
|
+
if (!effortMapRecord) throw new Error(`${label}.effortMap must be an object`);
|
|
100
|
+
for (const [level, target] of Object.entries(effortMapRecord)) {
|
|
101
|
+
if (!ACTIVE_LEVEL_SET.has(level)) throw new Error(`${label}.effortMap.${level} is unsupported`);
|
|
102
|
+
if (typeof target !== "string" || !EFFORT_WIRES.has(target)) {
|
|
103
|
+
throw new Error(`${label}.effortMap.${level} has invalid wire effort ${String(target)}`);
|
|
104
|
+
}
|
|
105
|
+
if (value.mode === "adaptive" && target !== "none" && !ADAPTIVE_WIRE_EFFORTS.has(target)) {
|
|
106
|
+
throw new Error(`${label}.effortMap.${level} has unsupported adaptive effort ${target} (allowed: low | medium | high | max | none)`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (value.mode === "adaptive" && Array.isArray(value.supportedLevels)) {
|
|
111
|
+
for (const level of value.supportedLevels) {
|
|
112
|
+
if (level === "off") continue;
|
|
113
|
+
const mapped = effortMapRecord && typeof effortMapRecord[level] === "string" ? effortMapRecord[level] : level;
|
|
114
|
+
if (mapped !== "none" && !ADAPTIVE_WIRE_EFFORTS.has(mapped)) {
|
|
115
|
+
throw new Error(`${label}.supportedLevels level "${level}" is unsupported by adaptive mode without an effortMap entry to low|medium|high|max`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
validateBudgetMap(value.budgets, `${label}.budgets`);
|
|
120
|
+
validateBudgetMap(value.outputAllowance, `${label}.outputAllowance`);
|
|
121
|
+
for (const bound of ["minBudgetTokens", "maxBudgetTokens"]) {
|
|
122
|
+
if (value[bound] !== void 0 && (typeof value[bound] !== "number" || !Number.isInteger(value[bound]) || value[bound] < 0)) {
|
|
123
|
+
throw new Error(`${label}.${bound} must be a non-negative integer`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (typeof value.minBudgetTokens === "number" && typeof value.maxBudgetTokens === "number" && value.maxBudgetTokens < value.minBudgetTokens) {
|
|
127
|
+
throw new Error(`${label}.maxBudgetTokens must be >= minBudgetTokens`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function validateThinkingCapabilityForApi(value, api, label) {
|
|
131
|
+
if (value === void 0) return;
|
|
132
|
+
validateThinkingCapability(value, label);
|
|
133
|
+
if (!api) return;
|
|
134
|
+
const cap = value;
|
|
135
|
+
if (!isThinkingModeCompatibleWithApi(api, cap.mode)) {
|
|
136
|
+
throw new Error(`${label}.mode "${cap.mode}" is incompatible with api "${api}"`);
|
|
137
|
+
}
|
|
138
|
+
if (cap.disableWire !== void 0 && !isDisableWireCompatibleWithApi(api, cap.disableWire)) {
|
|
139
|
+
throw new Error(`${label}.disableWire "${cap.disableWire}" is incompatible with api "${api}"`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function cloneThinkingCapability(value) {
|
|
143
|
+
if (!value) return void 0;
|
|
144
|
+
return {
|
|
145
|
+
mode: value.mode,
|
|
146
|
+
...value.supportedLevels ? { supportedLevels: [...value.supportedLevels] } : {},
|
|
147
|
+
...value.defaultLevel !== void 0 ? { defaultLevel: value.defaultLevel } : {},
|
|
148
|
+
...value.disableWire !== void 0 ? { disableWire: value.disableWire } : {},
|
|
149
|
+
...value.effortMap ? { effortMap: { ...value.effortMap } } : {},
|
|
150
|
+
...value.budgets ? { budgets: { ...value.budgets } } : {},
|
|
151
|
+
...value.minBudgetTokens !== void 0 ? { minBudgetTokens: value.minBudgetTokens } : {},
|
|
152
|
+
...value.maxBudgetTokens !== void 0 ? { maxBudgetTokens: value.maxBudgetTokens } : {},
|
|
153
|
+
...value.outputAllowance ? { outputAllowance: { ...value.outputAllowance } } : {}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function mergeThinkingCapability(base, override, api, label = "thinking") {
|
|
157
|
+
if (!override) return cloneThinkingCapability(base);
|
|
158
|
+
if (!base) {
|
|
159
|
+
const cloned = cloneThinkingCapability(override);
|
|
160
|
+
validateThinkingCapabilityForApi(cloned, api, label);
|
|
161
|
+
return cloned;
|
|
162
|
+
}
|
|
163
|
+
let merged;
|
|
164
|
+
if (override.mode !== base.mode) {
|
|
165
|
+
merged = {
|
|
166
|
+
...cloneThinkingCapability(override),
|
|
167
|
+
...override.outputAllowance === void 0 && base.outputAllowance ? { outputAllowance: { ...base.outputAllowance } } : {}
|
|
168
|
+
};
|
|
169
|
+
} else {
|
|
170
|
+
merged = {
|
|
171
|
+
...cloneThinkingCapability(base),
|
|
172
|
+
...cloneThinkingCapability(override),
|
|
173
|
+
...override.supportedLevels !== void 0 ? { supportedLevels: [...override.supportedLevels] } : base.supportedLevels ? { supportedLevels: [...base.supportedLevels] } : {},
|
|
174
|
+
...base.effortMap || override.effortMap ? { effortMap: { ...base.effortMap, ...override.effortMap } } : {},
|
|
175
|
+
...base.budgets || override.budgets ? { budgets: { ...base.budgets, ...override.budgets } } : {},
|
|
176
|
+
...base.outputAllowance || override.outputAllowance ? { outputAllowance: { ...base.outputAllowance, ...override.outputAllowance } } : {}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
validateThinkingCapabilityForApi(merged, api, label);
|
|
180
|
+
return merged;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/core/voice-config-validation.ts
|
|
184
|
+
var VOICE_CONFIG_KEYS = [
|
|
185
|
+
"apiBaseUrl",
|
|
186
|
+
"apiKey",
|
|
187
|
+
"apiKeyEnv",
|
|
188
|
+
"mode",
|
|
189
|
+
"contextHint",
|
|
190
|
+
"tone",
|
|
191
|
+
"language",
|
|
192
|
+
"targetLanguage",
|
|
193
|
+
"preserveTerms",
|
|
194
|
+
"asrModel",
|
|
195
|
+
"llmModel",
|
|
196
|
+
"timeoutSeconds"
|
|
197
|
+
];
|
|
198
|
+
var VOICE_MODES = /* @__PURE__ */ new Set(["clean", "structure", "compose"]);
|
|
199
|
+
var VOICE_CONTEXT_HINTS = /* @__PURE__ */ new Set(["chat", "email", "support", "note", "task", "code", "social"]);
|
|
200
|
+
var VOICE_TONES = /* @__PURE__ */ new Set(["neutral", "casual", "formal", "polite", "concise"]);
|
|
201
|
+
var ENV_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
202
|
+
var DEC_OCTET = "(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])";
|
|
203
|
+
var IPV4_HOST = `${DEC_OCTET}(?:\\.${DEC_OCTET}){3}`;
|
|
204
|
+
var H16 = "[0-9A-Fa-f]{1,4}";
|
|
205
|
+
var LS32 = `(?:${H16}:${H16}|${IPV4_HOST})`;
|
|
206
|
+
var IPV6_HOST = `(?:(?:${H16}:){6}${LS32}|::(?:${H16}:){5}${LS32}|(?:${H16})?::(?:${H16}:){4}${LS32}|(?:(?:${H16}:){0,1}${H16})?::(?:${H16}:){3}${LS32}|(?:(?:${H16}:){0,2}${H16})?::(?:${H16}:){2}${LS32}|(?:(?:${H16}:){0,3}${H16})?::${H16}:${LS32}|(?:(?:${H16}:){0,4}${H16})?::${LS32}|(?:(?:${H16}:){0,5}${H16})?::${H16}|(?:(?:${H16}:){0,6}${H16})?::)`;
|
|
207
|
+
var DNS_LABEL = "(?![xX][nN]--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?";
|
|
208
|
+
var DNS_FINAL_LABEL = "(?!(?:[0-9]+|0[xX][0-9A-Fa-f]*)(?:[:/]|$))(?![xX][nN]--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?";
|
|
209
|
+
var DNS_HOST = `(?:${DNS_LABEL}\\.)*${DNS_FINAL_LABEL}`;
|
|
210
|
+
var PORT_PART = "(?::(?:[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?";
|
|
211
|
+
var PATH_PART = "(?:/(?:[A-Za-z0-9._~!$&'()*+,;=:@-]|%[0-9A-Fa-f]{2})*)*";
|
|
212
|
+
var VOICE_API_BASE_URL_MAX_LENGTH = 2048;
|
|
213
|
+
var VOICE_API_BASE_URL_PATTERN = `^https?://(?:\\[${IPV6_HOST}\\]|${IPV4_HOST}|${DNS_HOST})${PORT_PART}${PATH_PART}$`;
|
|
214
|
+
var VOICE_API_BASE_URL_RE = new RegExp(VOICE_API_BASE_URL_PATTERN);
|
|
215
|
+
function validateVoiceConfig(value) {
|
|
216
|
+
if (value === void 0) return;
|
|
217
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
218
|
+
throw new Error("models.json voice must be an object");
|
|
219
|
+
}
|
|
220
|
+
const record = value;
|
|
221
|
+
const allowed = new Set(VOICE_CONFIG_KEYS);
|
|
222
|
+
for (const key of Object.keys(record)) {
|
|
223
|
+
if (!allowed.has(key)) throw new Error(`models.json voice has unsupported field: ${key}`);
|
|
224
|
+
}
|
|
225
|
+
if (typeof record.apiBaseUrl !== "string" || record.apiBaseUrl.length > VOICE_API_BASE_URL_MAX_LENGTH || !VOICE_API_BASE_URL_RE.test(record.apiBaseUrl)) {
|
|
226
|
+
throw new Error(`models.json voice.apiBaseUrl must be a canonical http(s):// URL (at most ${VOICE_API_BASE_URL_MAX_LENGTH} chars) without whitespace, userinfo, query, or fragment`);
|
|
227
|
+
}
|
|
228
|
+
let parsedUrl;
|
|
229
|
+
try {
|
|
230
|
+
parsedUrl = new URL(record.apiBaseUrl);
|
|
231
|
+
} catch {
|
|
232
|
+
throw new Error("models.json voice.apiBaseUrl must be a canonical http(s):// URL without whitespace, userinfo, query, or fragment");
|
|
233
|
+
}
|
|
234
|
+
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:" || !parsedUrl.hostname || parsedUrl.username !== "" || parsedUrl.password !== "" || parsedUrl.search !== "" || parsedUrl.hash !== "") {
|
|
235
|
+
throw new Error("models.json voice.apiBaseUrl must be a canonical http(s):// URL without whitespace, userinfo, query, or fragment");
|
|
236
|
+
}
|
|
237
|
+
if (record.apiKey !== void 0 && (typeof record.apiKey !== "string" || !/\S/.test(record.apiKey))) {
|
|
238
|
+
throw new Error("models.json voice.apiKey must be a non-empty string");
|
|
239
|
+
}
|
|
240
|
+
if (record.apiKeyEnv !== void 0 && (typeof record.apiKeyEnv !== "string" || !ENV_NAME_RE.test(record.apiKeyEnv))) {
|
|
241
|
+
throw new Error("models.json voice.apiKeyEnv must be an environment variable name");
|
|
242
|
+
}
|
|
243
|
+
if (record.mode !== void 0 && (typeof record.mode !== "string" || !VOICE_MODES.has(record.mode))) {
|
|
244
|
+
throw new Error("models.json voice.mode must be one of clean, structure, compose");
|
|
245
|
+
}
|
|
246
|
+
if (record.contextHint !== void 0 && (typeof record.contextHint !== "string" || !VOICE_CONTEXT_HINTS.has(record.contextHint))) {
|
|
247
|
+
throw new Error("models.json voice.contextHint is invalid");
|
|
248
|
+
}
|
|
249
|
+
if (record.tone !== void 0 && (typeof record.tone !== "string" || !VOICE_TONES.has(record.tone))) {
|
|
250
|
+
throw new Error("models.json voice.tone is invalid");
|
|
251
|
+
}
|
|
252
|
+
for (const field of ["language", "targetLanguage", "preserveTerms", "asrModel", "llmModel"]) {
|
|
253
|
+
if (record[field] !== void 0 && typeof record[field] !== "string") {
|
|
254
|
+
throw new Error(`models.json voice.${field} must be a string`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (record.timeoutSeconds !== void 0 && (!Number.isInteger(record.timeoutSeconds) || Number(record.timeoutSeconds) < 1 || Number(record.timeoutSeconds) > 3600)) {
|
|
258
|
+
throw new Error("models.json voice.timeoutSeconds must be an integer between 1 and 3600");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/core/game-use-config-validation.ts
|
|
263
|
+
var GAME_USE_TOP_KEYS = /* @__PURE__ */ new Set(["decision", "visualDecision"]);
|
|
264
|
+
var DECISION_ENDPOINT_KEYS = /* @__PURE__ */ new Set([
|
|
265
|
+
"protocol",
|
|
266
|
+
"provider",
|
|
267
|
+
"modelId",
|
|
268
|
+
"baseUrl",
|
|
269
|
+
"model",
|
|
270
|
+
"apiKey",
|
|
271
|
+
"apiKeyEnv",
|
|
272
|
+
"supportsVisual",
|
|
273
|
+
"timeoutMs",
|
|
274
|
+
"cacheTtlMs"
|
|
275
|
+
]);
|
|
276
|
+
var PROTOCOLS = /* @__PURE__ */ new Set(["systemone", "openai-compat", "openai-responses"]);
|
|
277
|
+
var ENV_NAME_RE2 = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
278
|
+
function validateEndpoint(value, label) {
|
|
279
|
+
if (value === void 0) return;
|
|
280
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
281
|
+
throw new Error(`${label} must be an object`);
|
|
282
|
+
}
|
|
283
|
+
const record = value;
|
|
284
|
+
for (const key of Object.keys(record)) {
|
|
285
|
+
if (!DECISION_ENDPOINT_KEYS.has(key)) {
|
|
286
|
+
throw new Error(`${label} has unsupported field: ${key}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (record.protocol !== void 0 && (typeof record.protocol !== "string" || !PROTOCOLS.has(record.protocol))) {
|
|
290
|
+
throw new Error(`${label}.protocol must be one of systemone, openai-compat, openai-responses`);
|
|
291
|
+
}
|
|
292
|
+
if (record.provider !== void 0 && (typeof record.provider !== "string" || !record.provider.trim())) {
|
|
293
|
+
throw new Error(`${label}.provider must be a non-empty string`);
|
|
294
|
+
}
|
|
295
|
+
if (record.modelId !== void 0 && (typeof record.modelId !== "string" || !record.modelId.trim())) {
|
|
296
|
+
throw new Error(`${label}.modelId must be a non-empty string`);
|
|
297
|
+
}
|
|
298
|
+
if (record.provider !== void 0 !== (record.modelId !== void 0)) {
|
|
299
|
+
throw new Error(`${label} must specify both provider and modelId when referencing a profile`);
|
|
300
|
+
}
|
|
301
|
+
if (record.baseUrl !== void 0) {
|
|
302
|
+
if (typeof record.baseUrl !== "string" || !record.baseUrl.trim()) {
|
|
303
|
+
throw new Error(`${label}.baseUrl must be a non-empty http(s):// URL`);
|
|
304
|
+
}
|
|
305
|
+
let parsed;
|
|
306
|
+
try {
|
|
307
|
+
parsed = new URL(record.baseUrl);
|
|
308
|
+
} catch {
|
|
309
|
+
throw new Error(`${label}.baseUrl must be a valid http(s):// URL`);
|
|
310
|
+
}
|
|
311
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:" || !parsed.hostname || parsed.username !== "" || parsed.password !== "" || parsed.hash !== "") {
|
|
312
|
+
throw new Error(`${label}.baseUrl must be a valid http(s):// URL without credentials or fragments`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (record.model !== void 0 && (typeof record.model !== "string" || !record.model.trim())) {
|
|
316
|
+
throw new Error(`${label}.model must be a non-empty string`);
|
|
317
|
+
}
|
|
318
|
+
if (record.apiKey !== void 0 && (typeof record.apiKey !== "string" || !/\S/.test(record.apiKey))) {
|
|
319
|
+
throw new Error(`${label}.apiKey must be a non-empty string`);
|
|
320
|
+
}
|
|
321
|
+
if (record.apiKeyEnv !== void 0 && (typeof record.apiKeyEnv !== "string" || !ENV_NAME_RE2.test(record.apiKeyEnv))) {
|
|
322
|
+
throw new Error(`${label}.apiKeyEnv must be an environment variable name`);
|
|
323
|
+
}
|
|
324
|
+
if (record.supportsVisual !== void 0 && typeof record.supportsVisual !== "boolean") {
|
|
325
|
+
throw new Error(`${label}.supportsVisual must be a boolean`);
|
|
326
|
+
}
|
|
327
|
+
if (record.timeoutMs !== void 0 && (typeof record.timeoutMs !== "number" || !Number.isFinite(record.timeoutMs) || record.timeoutMs < 100 || record.timeoutMs > 12e4)) {
|
|
328
|
+
throw new Error(`${label}.timeoutMs must be a number between 100 and 120000`);
|
|
329
|
+
}
|
|
330
|
+
if (record.cacheTtlMs !== void 0 && (typeof record.cacheTtlMs !== "number" || !Number.isFinite(record.cacheTtlMs) || record.cacheTtlMs < 0 || record.cacheTtlMs > 3e5)) {
|
|
331
|
+
throw new Error(`${label}.cacheTtlMs must be a number between 0 and 300000`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function validateGameUseConfig(value) {
|
|
335
|
+
if (value === void 0) return;
|
|
336
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
337
|
+
throw new Error("models.json gameUse must be an object");
|
|
338
|
+
}
|
|
339
|
+
const record = value;
|
|
340
|
+
for (const key of Object.keys(record)) {
|
|
341
|
+
if (!GAME_USE_TOP_KEYS.has(key)) {
|
|
342
|
+
throw new Error(`models.json gameUse has unsupported field: ${key}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
validateEndpoint(record.decision, "models.json gameUse.decision");
|
|
346
|
+
validateEndpoint(record.visualDecision, "models.json gameUse.visualDecision");
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/core/model-registry.ts
|
|
16
350
|
var MODEL_OVERRIDE_KEYS = [
|
|
17
351
|
"name",
|
|
18
352
|
"reasoning",
|
|
353
|
+
"thinking",
|
|
19
354
|
"input",
|
|
20
355
|
"cost",
|
|
21
356
|
"contextWindow",
|
|
@@ -44,6 +379,7 @@ function validateExtensionProviderConfig(provider, config) {
|
|
|
44
379
|
assertHeadersShape(model.headers, `registerProvider("${provider}") model "${model.id}"`);
|
|
45
380
|
validateTransport(model.transport, `Model "${model.id}"`);
|
|
46
381
|
validateCompat(model.compat, `registerProvider("${provider}") model "${model.id}" compat`);
|
|
382
|
+
validateThinkingCapabilityForApi(model.thinking, config.api, `registerProvider("${provider}") model "${model.id}" thinking`);
|
|
47
383
|
validateCacheCapability(model.cacheCapability, `registerProvider("${provider}") model "${model.id}" cacheCapability`);
|
|
48
384
|
validateWebSearchCapability(model.webSearch, `registerProvider("${provider}") model "${model.id}" webSearch`);
|
|
49
385
|
validateFileCapabilities(model.fileCapabilities, `registerProvider("${provider}") model "${model.id}" fileCapabilities`);
|
|
@@ -229,7 +565,7 @@ function credentialNamespaceKey(modelsPath, create) {
|
|
|
229
565
|
try {
|
|
230
566
|
fs.writeFileSync(keyPath, randomBytes(32), { flag: "wx", mode: 384 });
|
|
231
567
|
} catch (error) {
|
|
232
|
-
if (!
|
|
568
|
+
if (!isPlainRecord2(error) || error.code !== "EEXIST") throw error;
|
|
233
569
|
}
|
|
234
570
|
}
|
|
235
571
|
const key = readSafeRemoteCacheFile(directory, keyPath);
|
|
@@ -419,7 +755,7 @@ function validateRemoteEndpoint(baseUrl, catalogUrl, label) {
|
|
|
419
755
|
if (endpoint.search) throw new Error(`${label} baseUrl must not contain query parameters`);
|
|
420
756
|
if (endpoint.origin !== catalogUrl.origin) throw new Error(`${label} baseUrl must use the authenticated catalog origin`);
|
|
421
757
|
}
|
|
422
|
-
function
|
|
758
|
+
function isPlainRecord2(value) {
|
|
423
759
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
424
760
|
const prototype = Object.getPrototypeOf(value);
|
|
425
761
|
return prototype === Object.prototype || prototype === null;
|
|
@@ -430,7 +766,7 @@ function assertOnlyKeys(value, allowed, label) {
|
|
|
430
766
|
if (unexpected) throw new Error(`${label} contains unsupported field ${unexpected}`);
|
|
431
767
|
}
|
|
432
768
|
function validateRemoteCatalogConfig(value, label) {
|
|
433
|
-
if (!
|
|
769
|
+
if (!isPlainRecord2(value)) throw new Error(`${label} must be an object`);
|
|
434
770
|
assertOnlyKeys(value, ["id", "url", "apiKeyEnv"], label);
|
|
435
771
|
if (typeof value.id !== "string" || !value.id.trim() || value.id !== value.id.trim() || /\s/.test(value.id)) throw new Error(`${label}.id must be a non-empty identifier without whitespace`);
|
|
436
772
|
if (typeof value.url !== "string" || !value.url) throw new Error(`${label}.url must be a URL`);
|
|
@@ -461,33 +797,35 @@ function validatedRemoteCatalogs(value) {
|
|
|
461
797
|
return catalogs;
|
|
462
798
|
}
|
|
463
799
|
function validateModelsDocumentShape(value) {
|
|
464
|
-
if (!
|
|
465
|
-
assertOnlyKeys(value, ["$schema", "profiles", "remoteCatalogs", "defaults", "modelOverrides"], "models.json");
|
|
800
|
+
if (!isPlainRecord2(value)) throw new Error("models.json must be an object");
|
|
801
|
+
assertOnlyKeys(value, ["$schema", "profiles", "remoteCatalogs", "defaults", "modelOverrides", "voice", "gameUse"], "models.json");
|
|
466
802
|
if (value.$schema !== void 0 && (typeof value.$schema !== "string" || !value.$schema)) throw new Error("models.json $schema must be a non-empty string");
|
|
467
803
|
const hasProfiles = Object.prototype.hasOwnProperty.call(value, "profiles");
|
|
468
804
|
const hasRemoteCatalogs = Object.prototype.hasOwnProperty.call(value, "remoteCatalogs");
|
|
469
805
|
if (!hasProfiles && !hasRemoteCatalogs) throw new Error("models.json must define profiles or remoteCatalogs");
|
|
470
806
|
validatedRemoteCatalogs(value.remoteCatalogs);
|
|
471
807
|
if (hasProfiles) {
|
|
472
|
-
if (!
|
|
808
|
+
if (!isPlainRecord2(value.profiles) || Object.keys(value.profiles).length === 0) throw new Error("models.json profiles must be a non-empty object");
|
|
473
809
|
for (const [profileId, profile] of Object.entries(value.profiles)) {
|
|
474
810
|
if (!profileId || profileId !== profileId.trim() || /\s/.test(profileId)) throw new Error(`models.json profile id is invalid: ${profileId}`);
|
|
475
811
|
validateProfileConfig(profileId, profile);
|
|
476
812
|
}
|
|
477
813
|
}
|
|
478
814
|
validateModelOverrides(value.modelOverrides);
|
|
815
|
+
validateVoiceConfig(value.voice);
|
|
816
|
+
validateGameUseConfig(value.gameUse);
|
|
479
817
|
if (value.defaults !== void 0) {
|
|
480
|
-
if (!
|
|
818
|
+
if (!isPlainRecord2(value.defaults)) throw new Error("models.json defaults must be an object");
|
|
481
819
|
assertOnlyKeys(value.defaults, ["provider", "modelId", "modelClasses", "toolModels"], "models.json defaults");
|
|
482
820
|
assertOptionalString(value.defaults.provider, "models.json defaults.provider");
|
|
483
821
|
assertOptionalString(value.defaults.modelId, "models.json defaults.modelId");
|
|
484
822
|
for (const [field, allowed] of [["modelClasses", ["light", "balanced", "strong"]], ["toolModels", ["web_search", "read_file.image", "read_file.video", "read_file.audio", "read_file.document"]]]) {
|
|
485
823
|
const routes = value.defaults[field];
|
|
486
824
|
if (routes === void 0) continue;
|
|
487
|
-
if (!
|
|
825
|
+
if (!isPlainRecord2(routes)) throw new Error(`models.json defaults.${field} must be an object`);
|
|
488
826
|
assertOnlyKeys(routes, allowed, `models.json defaults.${field}`);
|
|
489
827
|
for (const [routeName, route] of Object.entries(routes)) {
|
|
490
|
-
if (!
|
|
828
|
+
if (!isPlainRecord2(route)) throw new Error(`models.json defaults.${field}.${routeName} must be an object`);
|
|
491
829
|
assertOnlyKeys(route, ["provider", "modelId"], `models.json defaults.${field}.${routeName}`);
|
|
492
830
|
assertOptionalString(route.provider, `models.json defaults.${field}.${routeName}.provider`);
|
|
493
831
|
assertOptionalString(route.modelId, `models.json defaults.${field}.${routeName}.modelId`);
|
|
@@ -508,14 +846,14 @@ function assertOptionalBoolean(value, label) {
|
|
|
508
846
|
}
|
|
509
847
|
function validateCacheCapability(value, label) {
|
|
510
848
|
if (value === void 0) return;
|
|
511
|
-
if (!
|
|
849
|
+
if (!isPlainRecord2(value) || !["none", "session_store", "prompt_cache", "usage_only"].includes(String(value.mode)) || typeof value.supported !== "boolean") throw new Error(`${label} is invalid`);
|
|
512
850
|
assertOnlyKeys(value, ["mode", "supported", "supportsUsageMetrics", "description"], label);
|
|
513
851
|
assertOptionalBoolean(value.supportsUsageMetrics, `${label}.supportsUsageMetrics`);
|
|
514
852
|
assertOptionalString(value.description, `${label}.description`);
|
|
515
853
|
}
|
|
516
854
|
function validateWebSearchCapability(value, label) {
|
|
517
855
|
if (value === void 0) return;
|
|
518
|
-
if (!
|
|
856
|
+
if (!isPlainRecord2(value) || !["anthropic_server_tool", "chat_completions_web_search", "openai_responses"].includes(String(value.type))) {
|
|
519
857
|
throw new Error(`${label} is invalid`);
|
|
520
858
|
}
|
|
521
859
|
assertOnlyKeys(value, ["type", "forceToolChoice", "searchEngine", "count", "contentSize"], label);
|
|
@@ -526,11 +864,11 @@ function validateWebSearchCapability(value, label) {
|
|
|
526
864
|
}
|
|
527
865
|
function validateFileCapabilities(value, label) {
|
|
528
866
|
if (value === void 0) return;
|
|
529
|
-
if (!
|
|
867
|
+
if (!isPlainRecord2(value)) throw new Error(`${label} is invalid`);
|
|
530
868
|
for (const [kind, capability] of Object.entries(value)) {
|
|
531
869
|
if (!["image", "video", "audio", "document"].includes(kind)) throw new Error(`${label}.${kind} is unsupported`);
|
|
532
870
|
if (typeof capability === "boolean") continue;
|
|
533
|
-
if (!
|
|
871
|
+
if (!isPlainRecord2(capability)) throw new Error(`${label}.${kind} is invalid`);
|
|
534
872
|
assertOnlyKeys(capability, ["supported", "formats", "maxFileSizeMb", "maxDurationSeconds", "nativeInline"], `${label}.${kind}`);
|
|
535
873
|
assertOptionalBoolean(capability.supported, `${label}.${kind}.supported`);
|
|
536
874
|
assertOptionalBoolean(capability.nativeInline, `${label}.${kind}.nativeInline`);
|
|
@@ -552,7 +890,7 @@ function validateTransport(value, label) {
|
|
|
552
890
|
}
|
|
553
891
|
function validateCompat(value, label) {
|
|
554
892
|
if (value === void 0) return;
|
|
555
|
-
if (!
|
|
893
|
+
if (!isPlainRecord2(value)) throw new Error(`${label} is invalid`);
|
|
556
894
|
assertOnlyKeys(value, [
|
|
557
895
|
"forcedReasoningEffort",
|
|
558
896
|
"store",
|
|
@@ -603,12 +941,13 @@ function validateCompat(value, label) {
|
|
|
603
941
|
validateCacheCapability(value.cacheCapability, `${label}.cacheCapability`);
|
|
604
942
|
}
|
|
605
943
|
function validateRemoteModel(profileId, model) {
|
|
606
|
-
if (!
|
|
944
|
+
if (!isPlainRecord2(model) || typeof model.id !== "string" || !model.id.trim() || model.id !== model.id.trim() || /\s/.test(model.id)) throw new Error(`Remote profile "${profileId}" contains an invalid model id`);
|
|
607
945
|
assertOnlyKeys(model, [
|
|
608
946
|
"id",
|
|
609
947
|
"api",
|
|
610
948
|
"name",
|
|
611
949
|
"reasoning",
|
|
950
|
+
"thinking",
|
|
612
951
|
"input",
|
|
613
952
|
"cost",
|
|
614
953
|
"contextWindow",
|
|
@@ -632,7 +971,7 @@ function validateRemoteModel(profileId, model) {
|
|
|
632
971
|
if (!Array.isArray(model.input) || model.input.length === 0 || model.input.some((item) => !["text", "image", "audio", "video"].includes(item))) {
|
|
633
972
|
throw new Error(`Remote profile "${profileId}" model "${model.id}" has invalid input capabilities`);
|
|
634
973
|
}
|
|
635
|
-
if (!
|
|
974
|
+
if (!isPlainRecord2(model.cost)) throw new Error(`Remote profile "${profileId}" model "${model.id}" has invalid cost values`);
|
|
636
975
|
assertOnlyKeys(model.cost, ["input", "output", "cacheRead", "cacheWrite", "cacheWriteLong"], `Remote profile "${profileId}" model "${model.id}" cost`);
|
|
637
976
|
const invalidRate = (value) => typeof value !== "number" || !Number.isFinite(value) || value < 0;
|
|
638
977
|
if ([model.cost.input, model.cost.output, model.cost.cacheRead, model.cost.cacheWrite].some(invalidRate) || model.cost.cacheWriteLong !== void 0 && invalidRate(model.cost.cacheWriteLong)) {
|
|
@@ -644,13 +983,14 @@ function validateRemoteModel(profileId, model) {
|
|
|
644
983
|
if (new Set(model.input).size !== model.input.length) throw new Error(`Remote profile "${profileId}" model "${model.id}" has duplicate input capabilities`);
|
|
645
984
|
validateTransport(model.transport, `Model "${model.id}"`);
|
|
646
985
|
validateCompat(model.compat, `Remote profile "${profileId}" model "${model.id}" compat`);
|
|
986
|
+
validateThinkingCapability(model.thinking, `Remote profile "${profileId}" model "${model.id}" thinking`);
|
|
647
987
|
validateCacheCapability(model.cacheCapability, `Remote profile "${profileId}" model "${model.id}" cacheCapability`);
|
|
648
988
|
validateWebSearchCapability(model.webSearch, `Remote profile "${profileId}" model "${model.id}" webSearch`);
|
|
649
989
|
validateFileCapabilities(model.fileCapabilities, `Remote profile "${profileId}" model "${model.id}" fileCapabilities`);
|
|
650
990
|
}
|
|
651
991
|
function assertHeadersShape(headers, label) {
|
|
652
992
|
if (headers === void 0) return;
|
|
653
|
-
if (!
|
|
993
|
+
if (!isPlainRecord2(headers)) throw new Error(`${label} headers must be an object`);
|
|
654
994
|
for (const [name, value] of Object.entries(headers)) {
|
|
655
995
|
if (!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(name)) throw new Error(`${label} header name ${name || "(empty)"} is invalid`);
|
|
656
996
|
if (typeof value !== "string") throw new Error(`${label} header ${name} must be a string`);
|
|
@@ -675,7 +1015,7 @@ function sanitizeRemotePayload(decoded, remote, catalogUrl, allowLocallyInjected
|
|
|
675
1015
|
}
|
|
676
1016
|
const profiles = /* @__PURE__ */ Object.create(null);
|
|
677
1017
|
for (const [provider, source] of Object.entries(sourceProfiles)) {
|
|
678
|
-
if (!provider || provider !== provider.trim() || /\s/.test(provider) || !
|
|
1018
|
+
if (!provider || provider !== provider.trim() || /\s/.test(provider) || !isPlainRecord2(source)) throw new Error("catalog contains an invalid profile");
|
|
679
1019
|
assertOnlyKeys(source, [
|
|
680
1020
|
"baseUrl",
|
|
681
1021
|
"endpoints",
|
|
@@ -689,6 +1029,7 @@ function sanitizeRemotePayload(decoded, remote, catalogUrl, allowLocallyInjected
|
|
|
689
1029
|
"transport",
|
|
690
1030
|
"compat",
|
|
691
1031
|
"cacheCapability",
|
|
1032
|
+
"thinking",
|
|
692
1033
|
"webSearch",
|
|
693
1034
|
"fileCapabilities",
|
|
694
1035
|
"models"
|
|
@@ -710,12 +1051,13 @@ function sanitizeRemotePayload(decoded, remote, catalogUrl, allowLocallyInjected
|
|
|
710
1051
|
assertRemoteHeadersSafe(source.headers, `Remote profile "${provider}"`);
|
|
711
1052
|
validateTransport(source.transport, `Remote profile "${provider}"`);
|
|
712
1053
|
validateCompat(source.compat, `Remote profile "${provider}" compat`);
|
|
1054
|
+
validateThinkingCapability(source.thinking, `Remote profile "${provider}" thinking`);
|
|
713
1055
|
validateCacheCapability(source.cacheCapability, `Remote profile "${provider}" cacheCapability`);
|
|
714
1056
|
validateWebSearchCapability(source.webSearch, `Remote profile "${provider}" webSearch`);
|
|
715
1057
|
validateFileCapabilities(source.fileCapabilities, `Remote profile "${provider}" fileCapabilities`);
|
|
716
1058
|
const seen = /* @__PURE__ */ new Set();
|
|
717
1059
|
for (const model of source.models) {
|
|
718
|
-
if (
|
|
1060
|
+
if (isPlainRecord2(model) && Object.prototype.hasOwnProperty.call(model, "apiKeyEnv") && (!allowLocallyInjectedCredential || model.apiKeyEnv !== remote.apiKeyEnv)) {
|
|
719
1061
|
throw new Error(`Remote profile "${provider}" model must not declare credential fields`);
|
|
720
1062
|
}
|
|
721
1063
|
validateRemoteModel(provider, model);
|
|
@@ -735,6 +1077,7 @@ function sanitizeRemotePayload(decoded, remote, catalogUrl, allowLocallyInjected
|
|
|
735
1077
|
...source.attachmentPlatform === void 0 ? {} : { attachmentPlatform: source.attachmentPlatform },
|
|
736
1078
|
...source.compat === void 0 ? {} : { compat: { ...source.compat } },
|
|
737
1079
|
...source.cacheCapability === void 0 ? {} : { cacheCapability: { ...source.cacheCapability } },
|
|
1080
|
+
...source.thinking === void 0 ? {} : { thinking: cloneThinkingCapability(source.thinking) },
|
|
738
1081
|
...source.webSearch === void 0 ? {} : { webSearch: { ...source.webSearch } },
|
|
739
1082
|
...source.fileCapabilities === void 0 ? {} : { fileCapabilities: { ...source.fileCapabilities } },
|
|
740
1083
|
models: source.models.map((model) => ({
|
|
@@ -742,6 +1085,7 @@ function sanitizeRemotePayload(decoded, remote, catalogUrl, allowLocallyInjected
|
|
|
742
1085
|
...model.api === void 0 ? {} : { api: model.api },
|
|
743
1086
|
...model.name === void 0 ? {} : { name: model.name },
|
|
744
1087
|
...model.reasoning === void 0 ? {} : { reasoning: model.reasoning },
|
|
1088
|
+
...model.thinking === void 0 ? {} : { thinking: cloneThinkingCapability(model.thinking) },
|
|
745
1089
|
input: [...model.input],
|
|
746
1090
|
cost: {
|
|
747
1091
|
input: model.cost.input,
|
|
@@ -829,20 +1173,20 @@ function loadResolvedModelsConfig(modelsPath) {
|
|
|
829
1173
|
return { config: { ...raw, profiles }, remoteCatalogs: catalogs.sort((a, b) => a.id.localeCompare(b.id)) };
|
|
830
1174
|
}
|
|
831
1175
|
function deepMergePlainRecords(base, patch) {
|
|
832
|
-
const result =
|
|
833
|
-
if (!
|
|
1176
|
+
const result = isPlainRecord2(base) ? { ...base } : {};
|
|
1177
|
+
if (!isPlainRecord2(patch)) return result;
|
|
834
1178
|
for (const [key, value] of Object.entries(patch)) {
|
|
835
1179
|
const current = result[key];
|
|
836
|
-
result[key] =
|
|
1180
|
+
result[key] = isPlainRecord2(current) && isPlainRecord2(value) ? deepMergePlainRecords(current, value) : value;
|
|
837
1181
|
}
|
|
838
1182
|
return result;
|
|
839
1183
|
}
|
|
840
1184
|
function validateModelOverrides(value) {
|
|
841
1185
|
if (value === void 0) return;
|
|
842
|
-
if (!
|
|
1186
|
+
if (!isPlainRecord2(value)) throw new Error("models.json modelOverrides must be an object");
|
|
843
1187
|
for (const [key, override] of Object.entries(value)) {
|
|
844
1188
|
if (!/^[^\s/]+\/[^\s/]+$/.test(key)) throw new Error(`models.json modelOverrides key must be "provider/modelId": ${key}`);
|
|
845
|
-
if (!
|
|
1189
|
+
if (!isPlainRecord2(override)) throw new Error(`models.json modelOverrides["${key}"] must be an object`);
|
|
846
1190
|
assertOnlyKeys(override, [...MODEL_OVERRIDE_KEYS], `models.json modelOverrides["${key}"]`);
|
|
847
1191
|
if (override.name !== void 0 && (typeof override.name !== "string" || !override.name.trim())) throw new Error(`models.json modelOverrides["${key}"].name must be a non-empty string`);
|
|
848
1192
|
if (override.displayName !== void 0 && (typeof override.displayName !== "string" || !override.displayName.trim())) throw new Error(`models.json modelOverrides["${key}"].displayName must be a non-empty string`);
|
|
@@ -851,19 +1195,20 @@ function validateModelOverrides(value) {
|
|
|
851
1195
|
if (override.contextWindow !== void 0 && (!Number.isInteger(override.contextWindow) || Number(override.contextWindow) < 1)) throw new Error(`models.json modelOverrides["${key}"].contextWindow is invalid`);
|
|
852
1196
|
if (override.maxTokens !== void 0 && (!Number.isInteger(override.maxTokens) || Number(override.maxTokens) < 1)) throw new Error(`models.json modelOverrides["${key}"].maxTokens is invalid`);
|
|
853
1197
|
if (override.cost !== void 0) {
|
|
854
|
-
if (!
|
|
1198
|
+
if (!isPlainRecord2(override.cost)) throw new Error(`models.json modelOverrides["${key}"].cost must be an object`);
|
|
855
1199
|
for (const field of ["input", "output", "cacheRead", "cacheWrite", "cacheWriteLong"]) {
|
|
856
1200
|
if (override.cost[field] !== void 0 && (typeof override.cost[field] !== "number" || !Number.isFinite(override.cost[field]) || override.cost[field] < 0)) throw new Error(`models.json modelOverrides["${key}"].cost.${field} must be a non-negative finite number`);
|
|
857
1201
|
}
|
|
858
1202
|
}
|
|
859
1203
|
if (override.headers !== void 0) {
|
|
860
|
-
if (!
|
|
1204
|
+
if (!isPlainRecord2(override.headers)) throw new Error(`models.json modelOverrides["${key}"].headers must be an object`);
|
|
861
1205
|
for (const [headerName, headerValue] of Object.entries(override.headers)) {
|
|
862
1206
|
if (typeof headerValue !== "string") throw new Error(`models.json modelOverrides["${key}"].headers.${headerName} must be a string`);
|
|
863
1207
|
}
|
|
864
1208
|
}
|
|
865
1209
|
validateTransport(override.transport, `Model override "${key}"`);
|
|
866
1210
|
validateCompat(override.compat, `models.json modelOverrides["${key}"].compat`);
|
|
1211
|
+
validateThinkingCapability(override.thinking, `models.json modelOverrides["${key}"].thinking`);
|
|
867
1212
|
validateCacheCapability(override.cacheCapability, `models.json modelOverrides["${key}"].cacheCapability`);
|
|
868
1213
|
validateWebSearchCapability(override.webSearch, `models.json modelOverrides["${key}"].webSearch`);
|
|
869
1214
|
validateFileCapabilities(override.fileCapabilities, `models.json modelOverrides["${key}"].fileCapabilities`);
|
|
@@ -871,7 +1216,7 @@ function validateModelOverrides(value) {
|
|
|
871
1216
|
}
|
|
872
1217
|
function validateProfileEndpoints(profile, label) {
|
|
873
1218
|
if (profile.endpoints === void 0) return;
|
|
874
|
-
if (!
|
|
1219
|
+
if (!isPlainRecord2(profile.endpoints)) throw new Error(`${label} endpoints must be an object`);
|
|
875
1220
|
for (const [api, value] of Object.entries(profile.endpoints)) {
|
|
876
1221
|
if (!SUPPORTED_REMOTE_APIS.has(api)) throw new Error(`${label} endpoints has unsupported api ${api}`);
|
|
877
1222
|
try {
|
|
@@ -893,7 +1238,7 @@ function resolveProfileRoute(profile, model) {
|
|
|
893
1238
|
return { api, baseUrl: endpoint ?? profile.baseUrl };
|
|
894
1239
|
}
|
|
895
1240
|
function validateProfileConfig(profileId, profileConfig) {
|
|
896
|
-
if (!
|
|
1241
|
+
if (!isPlainRecord2(profileConfig)) throw new Error(`Profile "${profileId}" must be an object.`);
|
|
897
1242
|
assertOnlyKeys(profileConfig, [
|
|
898
1243
|
"baseUrl",
|
|
899
1244
|
"endpoints",
|
|
@@ -907,6 +1252,7 @@ function validateProfileConfig(profileId, profileConfig) {
|
|
|
907
1252
|
"transport",
|
|
908
1253
|
"compat",
|
|
909
1254
|
"cacheCapability",
|
|
1255
|
+
"thinking",
|
|
910
1256
|
"webSearch",
|
|
911
1257
|
"fileCapabilities",
|
|
912
1258
|
"models"
|
|
@@ -943,14 +1289,16 @@ function validateProfileConfig(profileId, profileConfig) {
|
|
|
943
1289
|
validateCacheCapability(profileConfig.cacheCapability, `Profile "${profileId}" cacheCapability`);
|
|
944
1290
|
validateWebSearchCapability(profileConfig.webSearch, `Profile "${profileId}" webSearch`);
|
|
945
1291
|
validateFileCapabilities(profileConfig.fileCapabilities, `Profile "${profileId}" fileCapabilities`);
|
|
1292
|
+
validateThinkingCapability(profileConfig.thinking, `Profile "${profileId}" thinking`);
|
|
946
1293
|
const seenModelIds = /* @__PURE__ */ new Set();
|
|
947
1294
|
for (const [index, modelConfig] of (profileConfig.models || []).entries()) {
|
|
948
|
-
if (!
|
|
1295
|
+
if (!isPlainRecord2(modelConfig)) throw new Error(`Profile "${profileId}" model #${index} must be an object.`);
|
|
949
1296
|
assertOnlyKeys(modelConfig, [
|
|
950
1297
|
"id",
|
|
951
1298
|
"api",
|
|
952
1299
|
"name",
|
|
953
1300
|
"reasoning",
|
|
1301
|
+
"thinking",
|
|
954
1302
|
"input",
|
|
955
1303
|
"cost",
|
|
956
1304
|
"contextWindow",
|
|
@@ -979,7 +1327,8 @@ function validateProfileConfig(profileId, profileConfig) {
|
|
|
979
1327
|
);
|
|
980
1328
|
}
|
|
981
1329
|
validateRemoteModel(profileId, modelConfig);
|
|
982
|
-
resolveProfileRoute(profileConfig, modelConfig);
|
|
1330
|
+
const route = resolveProfileRoute(profileConfig, modelConfig);
|
|
1331
|
+
validateThinkingCapabilityForApi(modelConfig.thinking ?? profileConfig.thinking, route.api, `Profile "${profileId}" model "${modelConfig.id}" thinking`);
|
|
983
1332
|
assertHeadersShape(modelConfig.headers, `Profile "${profileId}" model "${modelConfig.id}"`);
|
|
984
1333
|
assertOptionalEnvName(modelConfig.apiKeyEnv, `Profile "${profileId}" model "${modelConfig.id}" apiKeyEnv`);
|
|
985
1334
|
if (seenModelIds.has(modelConfig.id)) throw new Error(`Profile "${profileId}" contains duplicate model "${modelConfig.id}".`);
|
|
@@ -1096,6 +1445,7 @@ var ModelRegistry = class {
|
|
|
1096
1445
|
...resolveProfileRoute(providerConfig, customModel),
|
|
1097
1446
|
provider,
|
|
1098
1447
|
reasoning: customModel.reasoning ?? baseModel?.reasoning ?? false,
|
|
1448
|
+
thinking: cloneThinkingCapability(customModel.thinking ?? providerConfig.thinking ?? baseModel?.thinking),
|
|
1099
1449
|
input: customModel.input || baseModel?.input || ["text"],
|
|
1100
1450
|
cost: customModel.cost || baseModel?.cost || { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
1101
1451
|
contextWindow: customModel.contextWindow || baseModel?.contextWindow || 128e3,
|
|
@@ -1153,6 +1503,7 @@ var ModelRegistry = class {
|
|
|
1153
1503
|
if (override.name !== void 0) patched.name = override.name;
|
|
1154
1504
|
if (override.displayName !== void 0) patched.displayName = override.displayName;
|
|
1155
1505
|
if (override.reasoning !== void 0) patched.reasoning = override.reasoning;
|
|
1506
|
+
if (override.thinking !== void 0) patched.thinking = mergeThinkingCapability(existing.thinking, override.thinking, existing.api, `models.json modelOverrides["${key}"].thinking`);
|
|
1156
1507
|
if (override.input !== void 0) patched.input = [...override.input];
|
|
1157
1508
|
if (override.contextWindow !== void 0) patched.contextWindow = override.contextWindow;
|
|
1158
1509
|
if (override.maxTokens !== void 0) patched.maxTokens = override.maxTokens;
|
|
@@ -1183,6 +1534,7 @@ var ModelRegistry = class {
|
|
|
1183
1534
|
...resolveProfileRoute(providerConfig, customModel),
|
|
1184
1535
|
provider,
|
|
1185
1536
|
reasoning: customModel.reasoning ?? false,
|
|
1537
|
+
thinking: cloneThinkingCapability(customModel.thinking ?? providerConfig.thinking),
|
|
1186
1538
|
input: customModel.input || ["text"],
|
|
1187
1539
|
cost: customModel.cost || { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
1188
1540
|
contextWindow: customModel.contextWindow || 128e3,
|
|
@@ -1645,13 +1997,17 @@ var ModelRegistry = class {
|
|
|
1645
1997
|
}
|
|
1646
1998
|
for (const customModel of config.models ?? []) {
|
|
1647
1999
|
const baseModel = this.models.get(provider)?.get(customModel.id);
|
|
2000
|
+
const resolvedApi = config.api || baseModel?.api || "openai-completions";
|
|
2001
|
+
const resolvedThinking = cloneThinkingCapability(customModel.thinking ?? baseModel?.thinking);
|
|
2002
|
+
validateThinkingCapabilityForApi(resolvedThinking, resolvedApi, `registerProvider("${provider}") model "${customModel.id}" thinking`);
|
|
1648
2003
|
this.upsert({
|
|
1649
2004
|
id: customModel.id,
|
|
1650
2005
|
name: customModel.name || baseModel?.name || customModel.id,
|
|
1651
|
-
api:
|
|
2006
|
+
api: resolvedApi,
|
|
1652
2007
|
provider,
|
|
1653
2008
|
baseUrl: config.baseUrl || baseModel?.baseUrl || "",
|
|
1654
2009
|
reasoning: customModel.reasoning ?? baseModel?.reasoning ?? false,
|
|
2010
|
+
thinking: resolvedThinking,
|
|
1655
2011
|
input: customModel.input || baseModel?.input || ["text"],
|
|
1656
2012
|
cost: customModel.cost || baseModel?.cost || { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
1657
2013
|
contextWindow: customModel.contextWindow || baseModel?.contextWindow || 128e3,
|