@cydm/pie 4.8.0 → 4.10.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 +6875 -3972
- 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 +285 -61
- package/dist/builtin/extensions/pie-proc/README.md +7 -7
- package/dist/builtin/extensions/pie-proc/index.js +493 -107
- 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 +367 -65
- 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-Y3I2UV5Y.js → chunk-5QMS6RQC.js} +353 -287
- package/dist/chunks/chunk-6WKBQZWM.js +19 -0
- package/dist/chunks/{chunk-LAJXWOKS.js → chunk-7LICWWUE.js} +11 -9
- package/dist/chunks/{chunk-5KI4Y4LA.js → chunk-BQWHLYYZ.js} +4 -3
- package/dist/chunks/{chunk-4PR34UZF.js → chunk-BTUMBUDU.js} +159 -145
- package/dist/chunks/{chunk-NHV2CALB.js → chunk-FC5AN5QP.js} +409 -32
- package/dist/chunks/{chunk-3W3SXVPB.js → chunk-G2K4GY6N.js} +993 -371
- package/dist/chunks/{chunk-BLDI2GRF.js → chunk-HK3FHIAH.js} +1364 -446
- package/dist/chunks/chunk-IZKHSUNQ.js +30 -0
- package/dist/chunks/{chunk-CGSFBWOM.js → chunk-KWK7KTSZ.js} +4 -3
- package/dist/chunks/chunk-OU33ROFD.js +717 -0
- package/dist/chunks/{chunk-Z2FKA2ZH.js → chunk-XMTRKMBG.js} +104 -22
- package/dist/chunks/{host-image-fallback-N7RHNPYN.js → host-image-fallback-3TEMOQM5.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-QKJ3YVDS.js} +2 -2
- package/dist/chunks/{read-file-understanding-FMPXR6EJ.js → read-file-understanding-N2ZZQLTZ.js} +5 -5
- package/dist/chunks/{src-EGXFJ3WA.js → src-3PSR2AAX.js} +3 -3
- package/dist/chunks/{src-B44QWSGM.js → src-D5GN4Q5O.js} +2 -2
- package/dist/chunks/{src-CLE5ILN4.js → src-F5N6O2HR.js} +20 -4
- package/dist/chunks/{src-Q7LU27C2.js → src-TIDKYA5F.js} +31 -1
- package/dist/chunks/{test-stream-OR3EJBNF.js → test-stream-JAJHK44G.js} +2 -2
- package/dist/cli.js +4123 -2389
- 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/{manager-upgrade-CTU3ISCW.js → manager-upgrade-LSTOHBUV.js} +3 -3
|
@@ -3,19 +3,375 @@ 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
|
+
getModelThinkingCapabilities,
|
|
10
|
+
isDisableWireCompatibleWithApi,
|
|
11
|
+
isThinkingModeCompatibleWithApi,
|
|
12
|
+
isThinkingSelectionLevel,
|
|
7
13
|
modelSupportsToolPurpose,
|
|
8
14
|
requiredCapabilityForToolPurpose,
|
|
9
15
|
sortToolModelCandidatesByCapability
|
|
10
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-G2K4GY6N.js";
|
|
11
17
|
|
|
12
18
|
// src/core/model-registry.ts
|
|
13
19
|
import * as fs from "fs";
|
|
14
20
|
import * as path from "path";
|
|
15
21
|
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
22
|
+
|
|
23
|
+
// src/core/thinking-capability-validation.ts
|
|
24
|
+
var THINKING_MODES = /* @__PURE__ */ new Set(["none", "effort", "adaptive", "budget"]);
|
|
25
|
+
var DISABLE_WIRES = /* @__PURE__ */ new Set(["omit", "none", "disabled"]);
|
|
26
|
+
var EFFORT_WIRES = /* @__PURE__ */ new Set(["none", ...ACTIVE_THINKING_LEVELS]);
|
|
27
|
+
var ADAPTIVE_WIRE_EFFORTS = /* @__PURE__ */ new Set(["low", "medium", "high", "max"]);
|
|
28
|
+
var ACTIVE_LEVEL_SET = new Set(ACTIVE_THINKING_LEVELS);
|
|
29
|
+
var THINKING_KEYS = /* @__PURE__ */ new Set([
|
|
30
|
+
"mode",
|
|
31
|
+
"supportedLevels",
|
|
32
|
+
"defaultLevel",
|
|
33
|
+
"disableWire",
|
|
34
|
+
"effortMap",
|
|
35
|
+
"budgets",
|
|
36
|
+
"minBudgetTokens",
|
|
37
|
+
"maxBudgetTokens",
|
|
38
|
+
"outputAllowance"
|
|
39
|
+
]);
|
|
40
|
+
function isPlainRecord(value) {
|
|
41
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
42
|
+
const proto = Object.getPrototypeOf(value);
|
|
43
|
+
return proto === Object.prototype || proto === null;
|
|
44
|
+
}
|
|
45
|
+
function validateBudgetMap(value, label) {
|
|
46
|
+
if (value === void 0) return;
|
|
47
|
+
if (!isPlainRecord(value)) throw new Error(`${label} must be an object`);
|
|
48
|
+
for (const [level, tokens] of Object.entries(value)) {
|
|
49
|
+
if (!ACTIVE_LEVEL_SET.has(level)) {
|
|
50
|
+
throw new Error(`${label}.${level} is unsupported`);
|
|
51
|
+
}
|
|
52
|
+
if (typeof tokens !== "number" || !Number.isFinite(tokens) || !Number.isInteger(tokens) || tokens < 0) {
|
|
53
|
+
throw new Error(`${label}.${level} must be a non-negative integer`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function validateThinkingCapability(value, label) {
|
|
58
|
+
if (value === void 0) return;
|
|
59
|
+
if (!isPlainRecord(value)) throw new Error(`${label} must be an object`);
|
|
60
|
+
for (const key of Object.keys(value)) {
|
|
61
|
+
if (!THINKING_KEYS.has(key)) throw new Error(`${label} contains unsupported field ${key}`);
|
|
62
|
+
}
|
|
63
|
+
if (typeof value.mode !== "string" || !THINKING_MODES.has(value.mode)) {
|
|
64
|
+
throw new Error(`${label}.mode must be one of none | effort | adaptive | budget`);
|
|
65
|
+
}
|
|
66
|
+
if (value.supportedLevels !== void 0) {
|
|
67
|
+
if (!Array.isArray(value.supportedLevels) || value.supportedLevels.length === 0) {
|
|
68
|
+
throw new Error(`${label}.supportedLevels must be a non-empty array`);
|
|
69
|
+
}
|
|
70
|
+
const seen = /* @__PURE__ */ new Set();
|
|
71
|
+
for (const level of value.supportedLevels) {
|
|
72
|
+
if (!isThinkingSelectionLevel(level)) {
|
|
73
|
+
throw new Error(`${label}.supportedLevels contains unsupported level ${String(level)} (allowed: ${ALL_THINKING_LEVELS.join(", ")})`);
|
|
74
|
+
}
|
|
75
|
+
if (seen.has(level)) {
|
|
76
|
+
throw new Error(`${label}.supportedLevels contains duplicate level ${level}`);
|
|
77
|
+
}
|
|
78
|
+
if (value.mode === "none" && level !== "off") {
|
|
79
|
+
throw new Error(`${label}.supportedLevels can only include "off" when mode is "none"`);
|
|
80
|
+
}
|
|
81
|
+
seen.add(level);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (value.defaultLevel !== void 0) {
|
|
85
|
+
if (!isThinkingSelectionLevel(value.defaultLevel)) {
|
|
86
|
+
throw new Error(`${label}.defaultLevel is invalid`);
|
|
87
|
+
}
|
|
88
|
+
if (value.mode === "none" && value.defaultLevel !== "off") {
|
|
89
|
+
throw new Error(`${label}.defaultLevel must be "off" when mode is "none"`);
|
|
90
|
+
}
|
|
91
|
+
if (Array.isArray(value.supportedLevels) && !value.supportedLevels.includes(value.defaultLevel)) {
|
|
92
|
+
throw new Error(`${label}.defaultLevel "${value.defaultLevel}" must be included in supportedLevels (${value.supportedLevels.join(", ")})`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (value.disableWire !== void 0 && (typeof value.disableWire !== "string" || !DISABLE_WIRES.has(value.disableWire))) {
|
|
96
|
+
throw new Error(`${label}.disableWire must be one of omit | none | disabled`);
|
|
97
|
+
}
|
|
98
|
+
const effortMapRecord = isPlainRecord(value.effortMap) ? value.effortMap : void 0;
|
|
99
|
+
if (value.effortMap !== void 0) {
|
|
100
|
+
if (!effortMapRecord) throw new Error(`${label}.effortMap must be an object`);
|
|
101
|
+
for (const [level, target] of Object.entries(effortMapRecord)) {
|
|
102
|
+
if (!ACTIVE_LEVEL_SET.has(level)) throw new Error(`${label}.effortMap.${level} is unsupported`);
|
|
103
|
+
if (typeof target !== "string" || !EFFORT_WIRES.has(target)) {
|
|
104
|
+
throw new Error(`${label}.effortMap.${level} has invalid wire effort ${String(target)}`);
|
|
105
|
+
}
|
|
106
|
+
if (value.mode === "adaptive" && target !== "none" && !ADAPTIVE_WIRE_EFFORTS.has(target)) {
|
|
107
|
+
throw new Error(`${label}.effortMap.${level} has unsupported adaptive effort ${target} (allowed: low | medium | high | max | none)`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (value.mode === "adaptive" && Array.isArray(value.supportedLevels)) {
|
|
112
|
+
for (const level of value.supportedLevels) {
|
|
113
|
+
if (level === "off") continue;
|
|
114
|
+
const mapped = effortMapRecord && typeof effortMapRecord[level] === "string" ? effortMapRecord[level] : level;
|
|
115
|
+
if (mapped !== "none" && !ADAPTIVE_WIRE_EFFORTS.has(mapped)) {
|
|
116
|
+
throw new Error(`${label}.supportedLevels level "${level}" is unsupported by adaptive mode without an effortMap entry to low|medium|high|max`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
validateBudgetMap(value.budgets, `${label}.budgets`);
|
|
121
|
+
validateBudgetMap(value.outputAllowance, `${label}.outputAllowance`);
|
|
122
|
+
for (const bound of ["minBudgetTokens", "maxBudgetTokens"]) {
|
|
123
|
+
if (value[bound] !== void 0 && (typeof value[bound] !== "number" || !Number.isInteger(value[bound]) || value[bound] < 0)) {
|
|
124
|
+
throw new Error(`${label}.${bound} must be a non-negative integer`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (typeof value.minBudgetTokens === "number" && typeof value.maxBudgetTokens === "number" && value.maxBudgetTokens < value.minBudgetTokens) {
|
|
128
|
+
throw new Error(`${label}.maxBudgetTokens must be >= minBudgetTokens`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function validateThinkingCapabilityForApi(value, api, label) {
|
|
132
|
+
if (value === void 0) return;
|
|
133
|
+
validateThinkingCapability(value, label);
|
|
134
|
+
if (!api) return;
|
|
135
|
+
const cap = value;
|
|
136
|
+
if (!isThinkingModeCompatibleWithApi(api, cap.mode)) {
|
|
137
|
+
throw new Error(`${label}.mode "${cap.mode}" is incompatible with api "${api}"`);
|
|
138
|
+
}
|
|
139
|
+
if (cap.disableWire !== void 0 && !isDisableWireCompatibleWithApi(api, cap.disableWire)) {
|
|
140
|
+
throw new Error(`${label}.disableWire "${cap.disableWire}" is incompatible with api "${api}"`);
|
|
141
|
+
}
|
|
142
|
+
if (cap.defaultLevel !== void 0 && !Array.isArray(cap.supportedLevels) && cap.mode !== "none") {
|
|
143
|
+
const effective = getModelThinkingCapabilities({
|
|
144
|
+
id: "__validate__",
|
|
145
|
+
name: "__validate__",
|
|
146
|
+
api,
|
|
147
|
+
provider: "__validate__",
|
|
148
|
+
baseUrl: "",
|
|
149
|
+
reasoning: false,
|
|
150
|
+
thinking: cap,
|
|
151
|
+
input: ["text"],
|
|
152
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
153
|
+
contextWindow: 128e3,
|
|
154
|
+
maxTokens: 8192
|
|
155
|
+
});
|
|
156
|
+
if (effective.supportedLevels.length > 0 && !effective.supportedLevels.includes(cap.defaultLevel)) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`${label}.defaultLevel "${cap.defaultLevel}" is not supported by api "${api}" mode "${cap.mode}" (supported: ${effective.supportedLevels.join(", ")})`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function cloneThinkingCapability(value) {
|
|
164
|
+
if (!value) return void 0;
|
|
165
|
+
return {
|
|
166
|
+
mode: value.mode,
|
|
167
|
+
...value.supportedLevels ? { supportedLevels: [...value.supportedLevels] } : {},
|
|
168
|
+
...value.defaultLevel !== void 0 ? { defaultLevel: value.defaultLevel } : {},
|
|
169
|
+
...value.disableWire !== void 0 ? { disableWire: value.disableWire } : {},
|
|
170
|
+
...value.effortMap ? { effortMap: { ...value.effortMap } } : {},
|
|
171
|
+
...value.budgets ? { budgets: { ...value.budgets } } : {},
|
|
172
|
+
...value.minBudgetTokens !== void 0 ? { minBudgetTokens: value.minBudgetTokens } : {},
|
|
173
|
+
...value.maxBudgetTokens !== void 0 ? { maxBudgetTokens: value.maxBudgetTokens } : {},
|
|
174
|
+
...value.outputAllowance ? { outputAllowance: { ...value.outputAllowance } } : {}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function mergeThinkingCapability(base, override, api, label = "thinking") {
|
|
178
|
+
if (!override) return cloneThinkingCapability(base);
|
|
179
|
+
if (!base) {
|
|
180
|
+
const cloned = cloneThinkingCapability(override);
|
|
181
|
+
validateThinkingCapabilityForApi(cloned, api, label);
|
|
182
|
+
return cloned;
|
|
183
|
+
}
|
|
184
|
+
let merged;
|
|
185
|
+
if (override.mode !== base.mode) {
|
|
186
|
+
merged = {
|
|
187
|
+
...cloneThinkingCapability(override),
|
|
188
|
+
...override.outputAllowance === void 0 && base.outputAllowance ? { outputAllowance: { ...base.outputAllowance } } : {}
|
|
189
|
+
};
|
|
190
|
+
} else {
|
|
191
|
+
merged = {
|
|
192
|
+
...cloneThinkingCapability(base),
|
|
193
|
+
...cloneThinkingCapability(override),
|
|
194
|
+
...override.supportedLevels !== void 0 ? { supportedLevels: [...override.supportedLevels] } : base.supportedLevels ? { supportedLevels: [...base.supportedLevels] } : {},
|
|
195
|
+
...base.effortMap || override.effortMap ? { effortMap: { ...base.effortMap, ...override.effortMap } } : {},
|
|
196
|
+
...base.budgets || override.budgets ? { budgets: { ...base.budgets, ...override.budgets } } : {},
|
|
197
|
+
...base.outputAllowance || override.outputAllowance ? { outputAllowance: { ...base.outputAllowance, ...override.outputAllowance } } : {}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
validateThinkingCapabilityForApi(merged, api, label);
|
|
201
|
+
return merged;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/core/voice-config-validation.ts
|
|
205
|
+
var VOICE_CONFIG_KEYS = [
|
|
206
|
+
"apiBaseUrl",
|
|
207
|
+
"apiKey",
|
|
208
|
+
"apiKeyEnv",
|
|
209
|
+
"mode",
|
|
210
|
+
"contextHint",
|
|
211
|
+
"tone",
|
|
212
|
+
"language",
|
|
213
|
+
"targetLanguage",
|
|
214
|
+
"preserveTerms",
|
|
215
|
+
"asrModel",
|
|
216
|
+
"llmModel",
|
|
217
|
+
"timeoutSeconds"
|
|
218
|
+
];
|
|
219
|
+
var VOICE_MODES = /* @__PURE__ */ new Set(["clean", "structure", "compose"]);
|
|
220
|
+
var VOICE_CONTEXT_HINTS = /* @__PURE__ */ new Set(["chat", "email", "support", "note", "task", "code", "social"]);
|
|
221
|
+
var VOICE_TONES = /* @__PURE__ */ new Set(["neutral", "casual", "formal", "polite", "concise"]);
|
|
222
|
+
var ENV_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
223
|
+
var DEC_OCTET = "(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])";
|
|
224
|
+
var IPV4_HOST = `${DEC_OCTET}(?:\\.${DEC_OCTET}){3}`;
|
|
225
|
+
var H16 = "[0-9A-Fa-f]{1,4}";
|
|
226
|
+
var LS32 = `(?:${H16}:${H16}|${IPV4_HOST})`;
|
|
227
|
+
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})?::)`;
|
|
228
|
+
var DNS_LABEL = "(?![xX][nN]--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?";
|
|
229
|
+
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])?";
|
|
230
|
+
var DNS_HOST = `(?:${DNS_LABEL}\\.)*${DNS_FINAL_LABEL}`;
|
|
231
|
+
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]))?";
|
|
232
|
+
var PATH_PART = "(?:/(?:[A-Za-z0-9._~!$&'()*+,;=:@-]|%[0-9A-Fa-f]{2})*)*";
|
|
233
|
+
var VOICE_API_BASE_URL_MAX_LENGTH = 2048;
|
|
234
|
+
var VOICE_API_BASE_URL_PATTERN = `^https?://(?:\\[${IPV6_HOST}\\]|${IPV4_HOST}|${DNS_HOST})${PORT_PART}${PATH_PART}$`;
|
|
235
|
+
var VOICE_API_BASE_URL_RE = new RegExp(VOICE_API_BASE_URL_PATTERN);
|
|
236
|
+
function validateVoiceConfig(value) {
|
|
237
|
+
if (value === void 0) return;
|
|
238
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
239
|
+
throw new Error("models.json voice must be an object");
|
|
240
|
+
}
|
|
241
|
+
const record = value;
|
|
242
|
+
const allowed = new Set(VOICE_CONFIG_KEYS);
|
|
243
|
+
for (const key of Object.keys(record)) {
|
|
244
|
+
if (!allowed.has(key)) throw new Error(`models.json voice has unsupported field: ${key}`);
|
|
245
|
+
}
|
|
246
|
+
if (typeof record.apiBaseUrl !== "string" || record.apiBaseUrl.length > VOICE_API_BASE_URL_MAX_LENGTH || !VOICE_API_BASE_URL_RE.test(record.apiBaseUrl)) {
|
|
247
|
+
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`);
|
|
248
|
+
}
|
|
249
|
+
let parsedUrl;
|
|
250
|
+
try {
|
|
251
|
+
parsedUrl = new URL(record.apiBaseUrl);
|
|
252
|
+
} catch {
|
|
253
|
+
throw new Error("models.json voice.apiBaseUrl must be a canonical http(s):// URL without whitespace, userinfo, query, or fragment");
|
|
254
|
+
}
|
|
255
|
+
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:" || !parsedUrl.hostname || parsedUrl.username !== "" || parsedUrl.password !== "" || parsedUrl.search !== "" || parsedUrl.hash !== "") {
|
|
256
|
+
throw new Error("models.json voice.apiBaseUrl must be a canonical http(s):// URL without whitespace, userinfo, query, or fragment");
|
|
257
|
+
}
|
|
258
|
+
if (record.apiKey !== void 0 && (typeof record.apiKey !== "string" || !/\S/.test(record.apiKey))) {
|
|
259
|
+
throw new Error("models.json voice.apiKey must be a non-empty string");
|
|
260
|
+
}
|
|
261
|
+
if (record.apiKeyEnv !== void 0 && (typeof record.apiKeyEnv !== "string" || !ENV_NAME_RE.test(record.apiKeyEnv))) {
|
|
262
|
+
throw new Error("models.json voice.apiKeyEnv must be an environment variable name");
|
|
263
|
+
}
|
|
264
|
+
if (record.mode !== void 0 && (typeof record.mode !== "string" || !VOICE_MODES.has(record.mode))) {
|
|
265
|
+
throw new Error("models.json voice.mode must be one of clean, structure, compose");
|
|
266
|
+
}
|
|
267
|
+
if (record.contextHint !== void 0 && (typeof record.contextHint !== "string" || !VOICE_CONTEXT_HINTS.has(record.contextHint))) {
|
|
268
|
+
throw new Error("models.json voice.contextHint is invalid");
|
|
269
|
+
}
|
|
270
|
+
if (record.tone !== void 0 && (typeof record.tone !== "string" || !VOICE_TONES.has(record.tone))) {
|
|
271
|
+
throw new Error("models.json voice.tone is invalid");
|
|
272
|
+
}
|
|
273
|
+
for (const field of ["language", "targetLanguage", "preserveTerms", "asrModel", "llmModel"]) {
|
|
274
|
+
if (record[field] !== void 0 && typeof record[field] !== "string") {
|
|
275
|
+
throw new Error(`models.json voice.${field} must be a string`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (record.timeoutSeconds !== void 0 && (!Number.isInteger(record.timeoutSeconds) || Number(record.timeoutSeconds) < 1 || Number(record.timeoutSeconds) > 3600)) {
|
|
279
|
+
throw new Error("models.json voice.timeoutSeconds must be an integer between 1 and 3600");
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/core/game-use-config-validation.ts
|
|
284
|
+
var GAME_USE_TOP_KEYS = /* @__PURE__ */ new Set(["decision", "visualDecision"]);
|
|
285
|
+
var DECISION_ENDPOINT_KEYS = /* @__PURE__ */ new Set([
|
|
286
|
+
"protocol",
|
|
287
|
+
"provider",
|
|
288
|
+
"modelId",
|
|
289
|
+
"baseUrl",
|
|
290
|
+
"model",
|
|
291
|
+
"apiKey",
|
|
292
|
+
"apiKeyEnv",
|
|
293
|
+
"supportsVisual",
|
|
294
|
+
"timeoutMs",
|
|
295
|
+
"cacheTtlMs"
|
|
296
|
+
]);
|
|
297
|
+
var PROTOCOLS = /* @__PURE__ */ new Set(["systemone", "openai-compat", "openai-responses"]);
|
|
298
|
+
var ENV_NAME_RE2 = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
299
|
+
function validateEndpoint(value, label) {
|
|
300
|
+
if (value === void 0) return;
|
|
301
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
302
|
+
throw new Error(`${label} must be an object`);
|
|
303
|
+
}
|
|
304
|
+
const record = value;
|
|
305
|
+
for (const key of Object.keys(record)) {
|
|
306
|
+
if (!DECISION_ENDPOINT_KEYS.has(key)) {
|
|
307
|
+
throw new Error(`${label} has unsupported field: ${key}`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (record.protocol !== void 0 && (typeof record.protocol !== "string" || !PROTOCOLS.has(record.protocol))) {
|
|
311
|
+
throw new Error(`${label}.protocol must be one of systemone, openai-compat, openai-responses`);
|
|
312
|
+
}
|
|
313
|
+
if (record.provider !== void 0 && (typeof record.provider !== "string" || !record.provider.trim())) {
|
|
314
|
+
throw new Error(`${label}.provider must be a non-empty string`);
|
|
315
|
+
}
|
|
316
|
+
if (record.modelId !== void 0 && (typeof record.modelId !== "string" || !record.modelId.trim())) {
|
|
317
|
+
throw new Error(`${label}.modelId must be a non-empty string`);
|
|
318
|
+
}
|
|
319
|
+
if (record.provider !== void 0 !== (record.modelId !== void 0)) {
|
|
320
|
+
throw new Error(`${label} must specify both provider and modelId when referencing a profile`);
|
|
321
|
+
}
|
|
322
|
+
if (record.baseUrl !== void 0) {
|
|
323
|
+
if (typeof record.baseUrl !== "string" || !record.baseUrl.trim()) {
|
|
324
|
+
throw new Error(`${label}.baseUrl must be a non-empty http(s):// URL`);
|
|
325
|
+
}
|
|
326
|
+
let parsed;
|
|
327
|
+
try {
|
|
328
|
+
parsed = new URL(record.baseUrl);
|
|
329
|
+
} catch {
|
|
330
|
+
throw new Error(`${label}.baseUrl must be a valid http(s):// URL`);
|
|
331
|
+
}
|
|
332
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:" || !parsed.hostname || parsed.username !== "" || parsed.password !== "" || parsed.hash !== "") {
|
|
333
|
+
throw new Error(`${label}.baseUrl must be a valid http(s):// URL without credentials or fragments`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (record.model !== void 0 && (typeof record.model !== "string" || !record.model.trim())) {
|
|
337
|
+
throw new Error(`${label}.model must be a non-empty string`);
|
|
338
|
+
}
|
|
339
|
+
if (record.apiKey !== void 0 && (typeof record.apiKey !== "string" || !/\S/.test(record.apiKey))) {
|
|
340
|
+
throw new Error(`${label}.apiKey must be a non-empty string`);
|
|
341
|
+
}
|
|
342
|
+
if (record.apiKeyEnv !== void 0 && (typeof record.apiKeyEnv !== "string" || !ENV_NAME_RE2.test(record.apiKeyEnv))) {
|
|
343
|
+
throw new Error(`${label}.apiKeyEnv must be an environment variable name`);
|
|
344
|
+
}
|
|
345
|
+
if (record.supportsVisual !== void 0 && typeof record.supportsVisual !== "boolean") {
|
|
346
|
+
throw new Error(`${label}.supportsVisual must be a boolean`);
|
|
347
|
+
}
|
|
348
|
+
if (record.timeoutMs !== void 0 && (typeof record.timeoutMs !== "number" || !Number.isFinite(record.timeoutMs) || record.timeoutMs < 100 || record.timeoutMs > 12e4)) {
|
|
349
|
+
throw new Error(`${label}.timeoutMs must be a number between 100 and 120000`);
|
|
350
|
+
}
|
|
351
|
+
if (record.cacheTtlMs !== void 0 && (typeof record.cacheTtlMs !== "number" || !Number.isFinite(record.cacheTtlMs) || record.cacheTtlMs < 0 || record.cacheTtlMs > 3e5)) {
|
|
352
|
+
throw new Error(`${label}.cacheTtlMs must be a number between 0 and 300000`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function validateGameUseConfig(value) {
|
|
356
|
+
if (value === void 0) return;
|
|
357
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
358
|
+
throw new Error("models.json gameUse must be an object");
|
|
359
|
+
}
|
|
360
|
+
const record = value;
|
|
361
|
+
for (const key of Object.keys(record)) {
|
|
362
|
+
if (!GAME_USE_TOP_KEYS.has(key)) {
|
|
363
|
+
throw new Error(`models.json gameUse has unsupported field: ${key}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
validateEndpoint(record.decision, "models.json gameUse.decision");
|
|
367
|
+
validateEndpoint(record.visualDecision, "models.json gameUse.visualDecision");
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/core/model-registry.ts
|
|
16
371
|
var MODEL_OVERRIDE_KEYS = [
|
|
17
372
|
"name",
|
|
18
373
|
"reasoning",
|
|
374
|
+
"thinking",
|
|
19
375
|
"input",
|
|
20
376
|
"cost",
|
|
21
377
|
"contextWindow",
|
|
@@ -44,6 +400,7 @@ function validateExtensionProviderConfig(provider, config) {
|
|
|
44
400
|
assertHeadersShape(model.headers, `registerProvider("${provider}") model "${model.id}"`);
|
|
45
401
|
validateTransport(model.transport, `Model "${model.id}"`);
|
|
46
402
|
validateCompat(model.compat, `registerProvider("${provider}") model "${model.id}" compat`);
|
|
403
|
+
validateThinkingCapabilityForApi(model.thinking, config.api, `registerProvider("${provider}") model "${model.id}" thinking`);
|
|
47
404
|
validateCacheCapability(model.cacheCapability, `registerProvider("${provider}") model "${model.id}" cacheCapability`);
|
|
48
405
|
validateWebSearchCapability(model.webSearch, `registerProvider("${provider}") model "${model.id}" webSearch`);
|
|
49
406
|
validateFileCapabilities(model.fileCapabilities, `registerProvider("${provider}") model "${model.id}" fileCapabilities`);
|
|
@@ -229,7 +586,7 @@ function credentialNamespaceKey(modelsPath, create) {
|
|
|
229
586
|
try {
|
|
230
587
|
fs.writeFileSync(keyPath, randomBytes(32), { flag: "wx", mode: 384 });
|
|
231
588
|
} catch (error) {
|
|
232
|
-
if (!
|
|
589
|
+
if (!isPlainRecord2(error) || error.code !== "EEXIST") throw error;
|
|
233
590
|
}
|
|
234
591
|
}
|
|
235
592
|
const key = readSafeRemoteCacheFile(directory, keyPath);
|
|
@@ -419,7 +776,7 @@ function validateRemoteEndpoint(baseUrl, catalogUrl, label) {
|
|
|
419
776
|
if (endpoint.search) throw new Error(`${label} baseUrl must not contain query parameters`);
|
|
420
777
|
if (endpoint.origin !== catalogUrl.origin) throw new Error(`${label} baseUrl must use the authenticated catalog origin`);
|
|
421
778
|
}
|
|
422
|
-
function
|
|
779
|
+
function isPlainRecord2(value) {
|
|
423
780
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
424
781
|
const prototype = Object.getPrototypeOf(value);
|
|
425
782
|
return prototype === Object.prototype || prototype === null;
|
|
@@ -430,7 +787,7 @@ function assertOnlyKeys(value, allowed, label) {
|
|
|
430
787
|
if (unexpected) throw new Error(`${label} contains unsupported field ${unexpected}`);
|
|
431
788
|
}
|
|
432
789
|
function validateRemoteCatalogConfig(value, label) {
|
|
433
|
-
if (!
|
|
790
|
+
if (!isPlainRecord2(value)) throw new Error(`${label} must be an object`);
|
|
434
791
|
assertOnlyKeys(value, ["id", "url", "apiKeyEnv"], label);
|
|
435
792
|
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
793
|
if (typeof value.url !== "string" || !value.url) throw new Error(`${label}.url must be a URL`);
|
|
@@ -461,33 +818,35 @@ function validatedRemoteCatalogs(value) {
|
|
|
461
818
|
return catalogs;
|
|
462
819
|
}
|
|
463
820
|
function validateModelsDocumentShape(value) {
|
|
464
|
-
if (!
|
|
465
|
-
assertOnlyKeys(value, ["$schema", "profiles", "remoteCatalogs", "defaults", "modelOverrides"], "models.json");
|
|
821
|
+
if (!isPlainRecord2(value)) throw new Error("models.json must be an object");
|
|
822
|
+
assertOnlyKeys(value, ["$schema", "profiles", "remoteCatalogs", "defaults", "modelOverrides", "voice", "gameUse"], "models.json");
|
|
466
823
|
if (value.$schema !== void 0 && (typeof value.$schema !== "string" || !value.$schema)) throw new Error("models.json $schema must be a non-empty string");
|
|
467
824
|
const hasProfiles = Object.prototype.hasOwnProperty.call(value, "profiles");
|
|
468
825
|
const hasRemoteCatalogs = Object.prototype.hasOwnProperty.call(value, "remoteCatalogs");
|
|
469
826
|
if (!hasProfiles && !hasRemoteCatalogs) throw new Error("models.json must define profiles or remoteCatalogs");
|
|
470
827
|
validatedRemoteCatalogs(value.remoteCatalogs);
|
|
471
828
|
if (hasProfiles) {
|
|
472
|
-
if (!
|
|
829
|
+
if (!isPlainRecord2(value.profiles) || Object.keys(value.profiles).length === 0) throw new Error("models.json profiles must be a non-empty object");
|
|
473
830
|
for (const [profileId, profile] of Object.entries(value.profiles)) {
|
|
474
831
|
if (!profileId || profileId !== profileId.trim() || /\s/.test(profileId)) throw new Error(`models.json profile id is invalid: ${profileId}`);
|
|
475
832
|
validateProfileConfig(profileId, profile);
|
|
476
833
|
}
|
|
477
834
|
}
|
|
478
835
|
validateModelOverrides(value.modelOverrides);
|
|
836
|
+
validateVoiceConfig(value.voice);
|
|
837
|
+
validateGameUseConfig(value.gameUse);
|
|
479
838
|
if (value.defaults !== void 0) {
|
|
480
|
-
if (!
|
|
839
|
+
if (!isPlainRecord2(value.defaults)) throw new Error("models.json defaults must be an object");
|
|
481
840
|
assertOnlyKeys(value.defaults, ["provider", "modelId", "modelClasses", "toolModels"], "models.json defaults");
|
|
482
841
|
assertOptionalString(value.defaults.provider, "models.json defaults.provider");
|
|
483
842
|
assertOptionalString(value.defaults.modelId, "models.json defaults.modelId");
|
|
484
843
|
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
844
|
const routes = value.defaults[field];
|
|
486
845
|
if (routes === void 0) continue;
|
|
487
|
-
if (!
|
|
846
|
+
if (!isPlainRecord2(routes)) throw new Error(`models.json defaults.${field} must be an object`);
|
|
488
847
|
assertOnlyKeys(routes, allowed, `models.json defaults.${field}`);
|
|
489
848
|
for (const [routeName, route] of Object.entries(routes)) {
|
|
490
|
-
if (!
|
|
849
|
+
if (!isPlainRecord2(route)) throw new Error(`models.json defaults.${field}.${routeName} must be an object`);
|
|
491
850
|
assertOnlyKeys(route, ["provider", "modelId"], `models.json defaults.${field}.${routeName}`);
|
|
492
851
|
assertOptionalString(route.provider, `models.json defaults.${field}.${routeName}.provider`);
|
|
493
852
|
assertOptionalString(route.modelId, `models.json defaults.${field}.${routeName}.modelId`);
|
|
@@ -508,14 +867,14 @@ function assertOptionalBoolean(value, label) {
|
|
|
508
867
|
}
|
|
509
868
|
function validateCacheCapability(value, label) {
|
|
510
869
|
if (value === void 0) return;
|
|
511
|
-
if (!
|
|
870
|
+
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
871
|
assertOnlyKeys(value, ["mode", "supported", "supportsUsageMetrics", "description"], label);
|
|
513
872
|
assertOptionalBoolean(value.supportsUsageMetrics, `${label}.supportsUsageMetrics`);
|
|
514
873
|
assertOptionalString(value.description, `${label}.description`);
|
|
515
874
|
}
|
|
516
875
|
function validateWebSearchCapability(value, label) {
|
|
517
876
|
if (value === void 0) return;
|
|
518
|
-
if (!
|
|
877
|
+
if (!isPlainRecord2(value) || !["anthropic_server_tool", "chat_completions_web_search", "openai_responses"].includes(String(value.type))) {
|
|
519
878
|
throw new Error(`${label} is invalid`);
|
|
520
879
|
}
|
|
521
880
|
assertOnlyKeys(value, ["type", "forceToolChoice", "searchEngine", "count", "contentSize"], label);
|
|
@@ -526,11 +885,11 @@ function validateWebSearchCapability(value, label) {
|
|
|
526
885
|
}
|
|
527
886
|
function validateFileCapabilities(value, label) {
|
|
528
887
|
if (value === void 0) return;
|
|
529
|
-
if (!
|
|
888
|
+
if (!isPlainRecord2(value)) throw new Error(`${label} is invalid`);
|
|
530
889
|
for (const [kind, capability] of Object.entries(value)) {
|
|
531
890
|
if (!["image", "video", "audio", "document"].includes(kind)) throw new Error(`${label}.${kind} is unsupported`);
|
|
532
891
|
if (typeof capability === "boolean") continue;
|
|
533
|
-
if (!
|
|
892
|
+
if (!isPlainRecord2(capability)) throw new Error(`${label}.${kind} is invalid`);
|
|
534
893
|
assertOnlyKeys(capability, ["supported", "formats", "maxFileSizeMb", "maxDurationSeconds", "nativeInline"], `${label}.${kind}`);
|
|
535
894
|
assertOptionalBoolean(capability.supported, `${label}.${kind}.supported`);
|
|
536
895
|
assertOptionalBoolean(capability.nativeInline, `${label}.${kind}.nativeInline`);
|
|
@@ -552,7 +911,7 @@ function validateTransport(value, label) {
|
|
|
552
911
|
}
|
|
553
912
|
function validateCompat(value, label) {
|
|
554
913
|
if (value === void 0) return;
|
|
555
|
-
if (!
|
|
914
|
+
if (!isPlainRecord2(value)) throw new Error(`${label} is invalid`);
|
|
556
915
|
assertOnlyKeys(value, [
|
|
557
916
|
"forcedReasoningEffort",
|
|
558
917
|
"store",
|
|
@@ -603,12 +962,13 @@ function validateCompat(value, label) {
|
|
|
603
962
|
validateCacheCapability(value.cacheCapability, `${label}.cacheCapability`);
|
|
604
963
|
}
|
|
605
964
|
function validateRemoteModel(profileId, model) {
|
|
606
|
-
if (!
|
|
965
|
+
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
966
|
assertOnlyKeys(model, [
|
|
608
967
|
"id",
|
|
609
968
|
"api",
|
|
610
969
|
"name",
|
|
611
970
|
"reasoning",
|
|
971
|
+
"thinking",
|
|
612
972
|
"input",
|
|
613
973
|
"cost",
|
|
614
974
|
"contextWindow",
|
|
@@ -632,7 +992,7 @@ function validateRemoteModel(profileId, model) {
|
|
|
632
992
|
if (!Array.isArray(model.input) || model.input.length === 0 || model.input.some((item) => !["text", "image", "audio", "video"].includes(item))) {
|
|
633
993
|
throw new Error(`Remote profile "${profileId}" model "${model.id}" has invalid input capabilities`);
|
|
634
994
|
}
|
|
635
|
-
if (!
|
|
995
|
+
if (!isPlainRecord2(model.cost)) throw new Error(`Remote profile "${profileId}" model "${model.id}" has invalid cost values`);
|
|
636
996
|
assertOnlyKeys(model.cost, ["input", "output", "cacheRead", "cacheWrite", "cacheWriteLong"], `Remote profile "${profileId}" model "${model.id}" cost`);
|
|
637
997
|
const invalidRate = (value) => typeof value !== "number" || !Number.isFinite(value) || value < 0;
|
|
638
998
|
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 +1004,14 @@ function validateRemoteModel(profileId, model) {
|
|
|
644
1004
|
if (new Set(model.input).size !== model.input.length) throw new Error(`Remote profile "${profileId}" model "${model.id}" has duplicate input capabilities`);
|
|
645
1005
|
validateTransport(model.transport, `Model "${model.id}"`);
|
|
646
1006
|
validateCompat(model.compat, `Remote profile "${profileId}" model "${model.id}" compat`);
|
|
1007
|
+
validateThinkingCapability(model.thinking, `Remote profile "${profileId}" model "${model.id}" thinking`);
|
|
647
1008
|
validateCacheCapability(model.cacheCapability, `Remote profile "${profileId}" model "${model.id}" cacheCapability`);
|
|
648
1009
|
validateWebSearchCapability(model.webSearch, `Remote profile "${profileId}" model "${model.id}" webSearch`);
|
|
649
1010
|
validateFileCapabilities(model.fileCapabilities, `Remote profile "${profileId}" model "${model.id}" fileCapabilities`);
|
|
650
1011
|
}
|
|
651
1012
|
function assertHeadersShape(headers, label) {
|
|
652
1013
|
if (headers === void 0) return;
|
|
653
|
-
if (!
|
|
1014
|
+
if (!isPlainRecord2(headers)) throw new Error(`${label} headers must be an object`);
|
|
654
1015
|
for (const [name, value] of Object.entries(headers)) {
|
|
655
1016
|
if (!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(name)) throw new Error(`${label} header name ${name || "(empty)"} is invalid`);
|
|
656
1017
|
if (typeof value !== "string") throw new Error(`${label} header ${name} must be a string`);
|
|
@@ -675,7 +1036,7 @@ function sanitizeRemotePayload(decoded, remote, catalogUrl, allowLocallyInjected
|
|
|
675
1036
|
}
|
|
676
1037
|
const profiles = /* @__PURE__ */ Object.create(null);
|
|
677
1038
|
for (const [provider, source] of Object.entries(sourceProfiles)) {
|
|
678
|
-
if (!provider || provider !== provider.trim() || /\s/.test(provider) || !
|
|
1039
|
+
if (!provider || provider !== provider.trim() || /\s/.test(provider) || !isPlainRecord2(source)) throw new Error("catalog contains an invalid profile");
|
|
679
1040
|
assertOnlyKeys(source, [
|
|
680
1041
|
"baseUrl",
|
|
681
1042
|
"endpoints",
|
|
@@ -689,6 +1050,7 @@ function sanitizeRemotePayload(decoded, remote, catalogUrl, allowLocallyInjected
|
|
|
689
1050
|
"transport",
|
|
690
1051
|
"compat",
|
|
691
1052
|
"cacheCapability",
|
|
1053
|
+
"thinking",
|
|
692
1054
|
"webSearch",
|
|
693
1055
|
"fileCapabilities",
|
|
694
1056
|
"models"
|
|
@@ -710,12 +1072,13 @@ function sanitizeRemotePayload(decoded, remote, catalogUrl, allowLocallyInjected
|
|
|
710
1072
|
assertRemoteHeadersSafe(source.headers, `Remote profile "${provider}"`);
|
|
711
1073
|
validateTransport(source.transport, `Remote profile "${provider}"`);
|
|
712
1074
|
validateCompat(source.compat, `Remote profile "${provider}" compat`);
|
|
1075
|
+
validateThinkingCapability(source.thinking, `Remote profile "${provider}" thinking`);
|
|
713
1076
|
validateCacheCapability(source.cacheCapability, `Remote profile "${provider}" cacheCapability`);
|
|
714
1077
|
validateWebSearchCapability(source.webSearch, `Remote profile "${provider}" webSearch`);
|
|
715
1078
|
validateFileCapabilities(source.fileCapabilities, `Remote profile "${provider}" fileCapabilities`);
|
|
716
1079
|
const seen = /* @__PURE__ */ new Set();
|
|
717
1080
|
for (const model of source.models) {
|
|
718
|
-
if (
|
|
1081
|
+
if (isPlainRecord2(model) && Object.prototype.hasOwnProperty.call(model, "apiKeyEnv") && (!allowLocallyInjectedCredential || model.apiKeyEnv !== remote.apiKeyEnv)) {
|
|
719
1082
|
throw new Error(`Remote profile "${provider}" model must not declare credential fields`);
|
|
720
1083
|
}
|
|
721
1084
|
validateRemoteModel(provider, model);
|
|
@@ -735,6 +1098,7 @@ function sanitizeRemotePayload(decoded, remote, catalogUrl, allowLocallyInjected
|
|
|
735
1098
|
...source.attachmentPlatform === void 0 ? {} : { attachmentPlatform: source.attachmentPlatform },
|
|
736
1099
|
...source.compat === void 0 ? {} : { compat: { ...source.compat } },
|
|
737
1100
|
...source.cacheCapability === void 0 ? {} : { cacheCapability: { ...source.cacheCapability } },
|
|
1101
|
+
...source.thinking === void 0 ? {} : { thinking: cloneThinkingCapability(source.thinking) },
|
|
738
1102
|
...source.webSearch === void 0 ? {} : { webSearch: { ...source.webSearch } },
|
|
739
1103
|
...source.fileCapabilities === void 0 ? {} : { fileCapabilities: { ...source.fileCapabilities } },
|
|
740
1104
|
models: source.models.map((model) => ({
|
|
@@ -742,6 +1106,7 @@ function sanitizeRemotePayload(decoded, remote, catalogUrl, allowLocallyInjected
|
|
|
742
1106
|
...model.api === void 0 ? {} : { api: model.api },
|
|
743
1107
|
...model.name === void 0 ? {} : { name: model.name },
|
|
744
1108
|
...model.reasoning === void 0 ? {} : { reasoning: model.reasoning },
|
|
1109
|
+
...model.thinking === void 0 ? {} : { thinking: cloneThinkingCapability(model.thinking) },
|
|
745
1110
|
input: [...model.input],
|
|
746
1111
|
cost: {
|
|
747
1112
|
input: model.cost.input,
|
|
@@ -829,20 +1194,20 @@ function loadResolvedModelsConfig(modelsPath) {
|
|
|
829
1194
|
return { config: { ...raw, profiles }, remoteCatalogs: catalogs.sort((a, b) => a.id.localeCompare(b.id)) };
|
|
830
1195
|
}
|
|
831
1196
|
function deepMergePlainRecords(base, patch) {
|
|
832
|
-
const result =
|
|
833
|
-
if (!
|
|
1197
|
+
const result = isPlainRecord2(base) ? { ...base } : {};
|
|
1198
|
+
if (!isPlainRecord2(patch)) return result;
|
|
834
1199
|
for (const [key, value] of Object.entries(patch)) {
|
|
835
1200
|
const current = result[key];
|
|
836
|
-
result[key] =
|
|
1201
|
+
result[key] = isPlainRecord2(current) && isPlainRecord2(value) ? deepMergePlainRecords(current, value) : value;
|
|
837
1202
|
}
|
|
838
1203
|
return result;
|
|
839
1204
|
}
|
|
840
1205
|
function validateModelOverrides(value) {
|
|
841
1206
|
if (value === void 0) return;
|
|
842
|
-
if (!
|
|
1207
|
+
if (!isPlainRecord2(value)) throw new Error("models.json modelOverrides must be an object");
|
|
843
1208
|
for (const [key, override] of Object.entries(value)) {
|
|
844
1209
|
if (!/^[^\s/]+\/[^\s/]+$/.test(key)) throw new Error(`models.json modelOverrides key must be "provider/modelId": ${key}`);
|
|
845
|
-
if (!
|
|
1210
|
+
if (!isPlainRecord2(override)) throw new Error(`models.json modelOverrides["${key}"] must be an object`);
|
|
846
1211
|
assertOnlyKeys(override, [...MODEL_OVERRIDE_KEYS], `models.json modelOverrides["${key}"]`);
|
|
847
1212
|
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
1213
|
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 +1216,20 @@ function validateModelOverrides(value) {
|
|
|
851
1216
|
if (override.contextWindow !== void 0 && (!Number.isInteger(override.contextWindow) || Number(override.contextWindow) < 1)) throw new Error(`models.json modelOverrides["${key}"].contextWindow is invalid`);
|
|
852
1217
|
if (override.maxTokens !== void 0 && (!Number.isInteger(override.maxTokens) || Number(override.maxTokens) < 1)) throw new Error(`models.json modelOverrides["${key}"].maxTokens is invalid`);
|
|
853
1218
|
if (override.cost !== void 0) {
|
|
854
|
-
if (!
|
|
1219
|
+
if (!isPlainRecord2(override.cost)) throw new Error(`models.json modelOverrides["${key}"].cost must be an object`);
|
|
855
1220
|
for (const field of ["input", "output", "cacheRead", "cacheWrite", "cacheWriteLong"]) {
|
|
856
1221
|
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
1222
|
}
|
|
858
1223
|
}
|
|
859
1224
|
if (override.headers !== void 0) {
|
|
860
|
-
if (!
|
|
1225
|
+
if (!isPlainRecord2(override.headers)) throw new Error(`models.json modelOverrides["${key}"].headers must be an object`);
|
|
861
1226
|
for (const [headerName, headerValue] of Object.entries(override.headers)) {
|
|
862
1227
|
if (typeof headerValue !== "string") throw new Error(`models.json modelOverrides["${key}"].headers.${headerName} must be a string`);
|
|
863
1228
|
}
|
|
864
1229
|
}
|
|
865
1230
|
validateTransport(override.transport, `Model override "${key}"`);
|
|
866
1231
|
validateCompat(override.compat, `models.json modelOverrides["${key}"].compat`);
|
|
1232
|
+
validateThinkingCapability(override.thinking, `models.json modelOverrides["${key}"].thinking`);
|
|
867
1233
|
validateCacheCapability(override.cacheCapability, `models.json modelOverrides["${key}"].cacheCapability`);
|
|
868
1234
|
validateWebSearchCapability(override.webSearch, `models.json modelOverrides["${key}"].webSearch`);
|
|
869
1235
|
validateFileCapabilities(override.fileCapabilities, `models.json modelOverrides["${key}"].fileCapabilities`);
|
|
@@ -871,7 +1237,7 @@ function validateModelOverrides(value) {
|
|
|
871
1237
|
}
|
|
872
1238
|
function validateProfileEndpoints(profile, label) {
|
|
873
1239
|
if (profile.endpoints === void 0) return;
|
|
874
|
-
if (!
|
|
1240
|
+
if (!isPlainRecord2(profile.endpoints)) throw new Error(`${label} endpoints must be an object`);
|
|
875
1241
|
for (const [api, value] of Object.entries(profile.endpoints)) {
|
|
876
1242
|
if (!SUPPORTED_REMOTE_APIS.has(api)) throw new Error(`${label} endpoints has unsupported api ${api}`);
|
|
877
1243
|
try {
|
|
@@ -893,7 +1259,7 @@ function resolveProfileRoute(profile, model) {
|
|
|
893
1259
|
return { api, baseUrl: endpoint ?? profile.baseUrl };
|
|
894
1260
|
}
|
|
895
1261
|
function validateProfileConfig(profileId, profileConfig) {
|
|
896
|
-
if (!
|
|
1262
|
+
if (!isPlainRecord2(profileConfig)) throw new Error(`Profile "${profileId}" must be an object.`);
|
|
897
1263
|
assertOnlyKeys(profileConfig, [
|
|
898
1264
|
"baseUrl",
|
|
899
1265
|
"endpoints",
|
|
@@ -907,6 +1273,7 @@ function validateProfileConfig(profileId, profileConfig) {
|
|
|
907
1273
|
"transport",
|
|
908
1274
|
"compat",
|
|
909
1275
|
"cacheCapability",
|
|
1276
|
+
"thinking",
|
|
910
1277
|
"webSearch",
|
|
911
1278
|
"fileCapabilities",
|
|
912
1279
|
"models"
|
|
@@ -943,14 +1310,16 @@ function validateProfileConfig(profileId, profileConfig) {
|
|
|
943
1310
|
validateCacheCapability(profileConfig.cacheCapability, `Profile "${profileId}" cacheCapability`);
|
|
944
1311
|
validateWebSearchCapability(profileConfig.webSearch, `Profile "${profileId}" webSearch`);
|
|
945
1312
|
validateFileCapabilities(profileConfig.fileCapabilities, `Profile "${profileId}" fileCapabilities`);
|
|
1313
|
+
validateThinkingCapability(profileConfig.thinking, `Profile "${profileId}" thinking`);
|
|
946
1314
|
const seenModelIds = /* @__PURE__ */ new Set();
|
|
947
1315
|
for (const [index, modelConfig] of (profileConfig.models || []).entries()) {
|
|
948
|
-
if (!
|
|
1316
|
+
if (!isPlainRecord2(modelConfig)) throw new Error(`Profile "${profileId}" model #${index} must be an object.`);
|
|
949
1317
|
assertOnlyKeys(modelConfig, [
|
|
950
1318
|
"id",
|
|
951
1319
|
"api",
|
|
952
1320
|
"name",
|
|
953
1321
|
"reasoning",
|
|
1322
|
+
"thinking",
|
|
954
1323
|
"input",
|
|
955
1324
|
"cost",
|
|
956
1325
|
"contextWindow",
|
|
@@ -979,7 +1348,8 @@ function validateProfileConfig(profileId, profileConfig) {
|
|
|
979
1348
|
);
|
|
980
1349
|
}
|
|
981
1350
|
validateRemoteModel(profileId, modelConfig);
|
|
982
|
-
resolveProfileRoute(profileConfig, modelConfig);
|
|
1351
|
+
const route = resolveProfileRoute(profileConfig, modelConfig);
|
|
1352
|
+
validateThinkingCapabilityForApi(modelConfig.thinking ?? profileConfig.thinking, route.api, `Profile "${profileId}" model "${modelConfig.id}" thinking`);
|
|
983
1353
|
assertHeadersShape(modelConfig.headers, `Profile "${profileId}" model "${modelConfig.id}"`);
|
|
984
1354
|
assertOptionalEnvName(modelConfig.apiKeyEnv, `Profile "${profileId}" model "${modelConfig.id}" apiKeyEnv`);
|
|
985
1355
|
if (seenModelIds.has(modelConfig.id)) throw new Error(`Profile "${profileId}" contains duplicate model "${modelConfig.id}".`);
|
|
@@ -1096,6 +1466,7 @@ var ModelRegistry = class {
|
|
|
1096
1466
|
...resolveProfileRoute(providerConfig, customModel),
|
|
1097
1467
|
provider,
|
|
1098
1468
|
reasoning: customModel.reasoning ?? baseModel?.reasoning ?? false,
|
|
1469
|
+
thinking: cloneThinkingCapability(customModel.thinking ?? providerConfig.thinking ?? baseModel?.thinking),
|
|
1099
1470
|
input: customModel.input || baseModel?.input || ["text"],
|
|
1100
1471
|
cost: customModel.cost || baseModel?.cost || { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
1101
1472
|
contextWindow: customModel.contextWindow || baseModel?.contextWindow || 128e3,
|
|
@@ -1153,6 +1524,7 @@ var ModelRegistry = class {
|
|
|
1153
1524
|
if (override.name !== void 0) patched.name = override.name;
|
|
1154
1525
|
if (override.displayName !== void 0) patched.displayName = override.displayName;
|
|
1155
1526
|
if (override.reasoning !== void 0) patched.reasoning = override.reasoning;
|
|
1527
|
+
if (override.thinking !== void 0) patched.thinking = mergeThinkingCapability(existing.thinking, override.thinking, existing.api, `models.json modelOverrides["${key}"].thinking`);
|
|
1156
1528
|
if (override.input !== void 0) patched.input = [...override.input];
|
|
1157
1529
|
if (override.contextWindow !== void 0) patched.contextWindow = override.contextWindow;
|
|
1158
1530
|
if (override.maxTokens !== void 0) patched.maxTokens = override.maxTokens;
|
|
@@ -1183,6 +1555,7 @@ var ModelRegistry = class {
|
|
|
1183
1555
|
...resolveProfileRoute(providerConfig, customModel),
|
|
1184
1556
|
provider,
|
|
1185
1557
|
reasoning: customModel.reasoning ?? false,
|
|
1558
|
+
thinking: cloneThinkingCapability(customModel.thinking ?? providerConfig.thinking),
|
|
1186
1559
|
input: customModel.input || ["text"],
|
|
1187
1560
|
cost: customModel.cost || { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
1188
1561
|
contextWindow: customModel.contextWindow || 128e3,
|
|
@@ -1645,13 +2018,17 @@ var ModelRegistry = class {
|
|
|
1645
2018
|
}
|
|
1646
2019
|
for (const customModel of config.models ?? []) {
|
|
1647
2020
|
const baseModel = this.models.get(provider)?.get(customModel.id);
|
|
2021
|
+
const resolvedApi = config.api || baseModel?.api || "openai-completions";
|
|
2022
|
+
const resolvedThinking = cloneThinkingCapability(customModel.thinking ?? baseModel?.thinking);
|
|
2023
|
+
validateThinkingCapabilityForApi(resolvedThinking, resolvedApi, `registerProvider("${provider}") model "${customModel.id}" thinking`);
|
|
1648
2024
|
this.upsert({
|
|
1649
2025
|
id: customModel.id,
|
|
1650
2026
|
name: customModel.name || baseModel?.name || customModel.id,
|
|
1651
|
-
api:
|
|
2027
|
+
api: resolvedApi,
|
|
1652
2028
|
provider,
|
|
1653
2029
|
baseUrl: config.baseUrl || baseModel?.baseUrl || "",
|
|
1654
2030
|
reasoning: customModel.reasoning ?? baseModel?.reasoning ?? false,
|
|
2031
|
+
thinking: resolvedThinking,
|
|
1655
2032
|
input: customModel.input || baseModel?.input || ["text"],
|
|
1656
2033
|
cost: customModel.cost || baseModel?.cost || { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
1657
2034
|
contextWindow: customModel.contextWindow || baseModel?.contextWindow || 128e3,
|