@codelia/config 0.1.80 → 0.1.82
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/dist/index.cjs +316 -10
- package/dist/index.d.cts +82 -1
- package/dist/index.d.ts +82 -1
- package/dist/index.js +307 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,21 +20,268 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
BUILTIN_PROVIDER_NAMES: () => BUILTIN_PROVIDER_NAMES,
|
|
23
24
|
CONFIG_GROUP_DEFAULT_WRITE_SCOPE: () => CONFIG_GROUP_DEFAULT_WRITE_SCOPE,
|
|
24
25
|
CONFIG_VERSION: () => CONFIG_VERSION,
|
|
25
26
|
ConfigRegistry: () => ConfigRegistry,
|
|
27
|
+
OPENAI_CODEX_IMAGE_MODELS: () => OPENAI_CODEX_IMAGE_MODELS,
|
|
28
|
+
OPENAI_IMAGE_MODELS: () => OPENAI_IMAGE_MODELS,
|
|
29
|
+
SUBAGENT_MAX_CONCURRENT_LIMIT: () => SUBAGENT_MAX_CONCURRENT_LIMIT,
|
|
26
30
|
configRegistry: () => configRegistry,
|
|
27
|
-
parseConfig: () => parseConfig
|
|
31
|
+
parseConfig: () => parseConfig,
|
|
32
|
+
parseImageGenerationConfig: () => parseImageGenerationConfig,
|
|
33
|
+
parseResponsesProviders: () => parseResponsesProviders
|
|
28
34
|
});
|
|
29
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/responses-provider.ts
|
|
38
|
+
var BUILTIN_PROVIDER_NAMES = [
|
|
39
|
+
"openai",
|
|
40
|
+
"anthropic",
|
|
41
|
+
"openrouter",
|
|
42
|
+
"google",
|
|
43
|
+
"moonshot",
|
|
44
|
+
"zai",
|
|
45
|
+
"xai"
|
|
46
|
+
];
|
|
47
|
+
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
48
|
+
function parseResponsesProviders(value, source = "config") {
|
|
49
|
+
const fail = (field) => {
|
|
50
|
+
throw new Error(`${source}: invalid providers.${field}`);
|
|
51
|
+
};
|
|
52
|
+
if (!record(value)) return fail("(expected object)");
|
|
53
|
+
const keys2 = (entry, allowed, field) => {
|
|
54
|
+
if (Object.keys(entry).some((key) => !allowed.includes(key))) fail(field);
|
|
55
|
+
};
|
|
56
|
+
const integer = (entry, key, field, min = 1) => {
|
|
57
|
+
const number = entry[key];
|
|
58
|
+
if (number === void 0) return void 0;
|
|
59
|
+
if (typeof number !== "number" || !Number.isSafeInteger(number) || number < min)
|
|
60
|
+
fail(`${field}.${key}`);
|
|
61
|
+
return number;
|
|
62
|
+
};
|
|
63
|
+
const result = {};
|
|
64
|
+
for (const [name, raw] of Object.entries(value)) {
|
|
65
|
+
if (!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(name) || BUILTIN_PROVIDER_NAMES.some((builtin) => builtin === name) || ["__proto__", "constructor", "prototype"].includes(name))
|
|
66
|
+
fail(name);
|
|
67
|
+
if (!record(raw)) return fail(name);
|
|
68
|
+
keys2(
|
|
69
|
+
raw,
|
|
70
|
+
[
|
|
71
|
+
"type",
|
|
72
|
+
"base_url",
|
|
73
|
+
"api_key_env",
|
|
74
|
+
"timeout_ms",
|
|
75
|
+
"retry",
|
|
76
|
+
"features",
|
|
77
|
+
"models"
|
|
78
|
+
],
|
|
79
|
+
name
|
|
80
|
+
);
|
|
81
|
+
if (raw.type !== "responses" || typeof raw.base_url !== "string")
|
|
82
|
+
return fail(name);
|
|
83
|
+
let url;
|
|
84
|
+
try {
|
|
85
|
+
url = new URL(raw.base_url);
|
|
86
|
+
} catch {
|
|
87
|
+
return fail(`${name}.base_url`);
|
|
88
|
+
}
|
|
89
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash)
|
|
90
|
+
fail(`${name}.base_url`);
|
|
91
|
+
if (raw.api_key_env !== void 0 && (typeof raw.api_key_env !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(raw.api_key_env)))
|
|
92
|
+
fail(`${name}.api_key_env`);
|
|
93
|
+
let retry;
|
|
94
|
+
if (raw.retry === "off") retry = "off";
|
|
95
|
+
else if (raw.retry !== void 0) {
|
|
96
|
+
if (!record(raw.retry)) return fail(`${name}.retry`);
|
|
97
|
+
keys2(raw.retry, ["max_retries", "base_delay_ms"], `${name}.retry`);
|
|
98
|
+
const max = integer(raw.retry, "max_retries", `${name}.retry`, 0);
|
|
99
|
+
if (max === void 0 || max > 10)
|
|
100
|
+
return fail(`${name}.retry.max_retries`);
|
|
101
|
+
retry = {
|
|
102
|
+
max_retries: max,
|
|
103
|
+
base_delay_ms: integer(raw.retry, "base_delay_ms", `${name}.retry`, 0)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
let features;
|
|
107
|
+
if (raw.features !== void 0) {
|
|
108
|
+
if (!record(raw.features)) return fail(`${name}.features`);
|
|
109
|
+
keys2(
|
|
110
|
+
raw.features,
|
|
111
|
+
[
|
|
112
|
+
"encrypted_reasoning",
|
|
113
|
+
"reasoning_summary",
|
|
114
|
+
"prompt_cache_key",
|
|
115
|
+
"session_id_header",
|
|
116
|
+
"text_verbosity"
|
|
117
|
+
],
|
|
118
|
+
`${name}.features`
|
|
119
|
+
);
|
|
120
|
+
for (const [key, option] of Object.entries(raw.features)) {
|
|
121
|
+
if (key === "reasoning_summary") {
|
|
122
|
+
if (!["auto", "concise", "detailed"].includes(String(option)))
|
|
123
|
+
fail(`${name}.features.${key}`);
|
|
124
|
+
} else if (typeof option !== "boolean") fail(`${name}.features.${key}`);
|
|
125
|
+
}
|
|
126
|
+
features = { ...raw.features };
|
|
127
|
+
}
|
|
128
|
+
if (!record(raw.models) || !Object.keys(raw.models).length)
|
|
129
|
+
return fail(`${name}.models`);
|
|
130
|
+
const models = {};
|
|
131
|
+
for (const [id2, model] of Object.entries(raw.models)) {
|
|
132
|
+
const field = `${name}.models.${id2}`;
|
|
133
|
+
if (!id2.trim() || id2 !== id2.trim() || id2.length > 256 || ["__proto__", "constructor", "prototype"].includes(id2) || !record(model))
|
|
134
|
+
return fail(field);
|
|
135
|
+
keys2(
|
|
136
|
+
model,
|
|
137
|
+
[
|
|
138
|
+
"context_window",
|
|
139
|
+
"max_input_tokens",
|
|
140
|
+
"max_output_tokens",
|
|
141
|
+
"supports_tools",
|
|
142
|
+
"supports_reasoning",
|
|
143
|
+
"supports_json_schema",
|
|
144
|
+
"supports_vision",
|
|
145
|
+
"reasoning_levels"
|
|
146
|
+
],
|
|
147
|
+
field
|
|
148
|
+
);
|
|
149
|
+
const context = integer(model, "context_window", field);
|
|
150
|
+
if (context === void 0) return fail(`${field}.context_window`);
|
|
151
|
+
const input = integer(model, "max_input_tokens", field);
|
|
152
|
+
const output = integer(model, "max_output_tokens", field);
|
|
153
|
+
if ((input ?? 0) > context || (output ?? 0) > context) fail(field);
|
|
154
|
+
for (const key of [
|
|
155
|
+
"supports_tools",
|
|
156
|
+
"supports_reasoning",
|
|
157
|
+
"supports_json_schema",
|
|
158
|
+
"supports_vision"
|
|
159
|
+
]) {
|
|
160
|
+
if (model[key] !== void 0 && typeof model[key] !== "boolean")
|
|
161
|
+
fail(`${field}.${key}`);
|
|
162
|
+
}
|
|
163
|
+
if (model.reasoning_levels !== void 0 && (!Array.isArray(model.reasoning_levels) || !model.reasoning_levels.length || model.reasoning_levels.some(
|
|
164
|
+
(level) => !["low", "medium", "high", "xhigh", "max"].includes(level)
|
|
165
|
+
) || model.supports_reasoning !== true))
|
|
166
|
+
fail(`${field}.reasoning_levels`);
|
|
167
|
+
models[id2] = {
|
|
168
|
+
...model,
|
|
169
|
+
context_window: context
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
result[name] = {
|
|
173
|
+
type: "responses",
|
|
174
|
+
base_url: raw.base_url.replace(/\/+$/, ""),
|
|
175
|
+
models,
|
|
176
|
+
...raw.api_key_env ? { api_key_env: raw.api_key_env } : {},
|
|
177
|
+
...raw.timeout_ms !== void 0 ? { timeout_ms: integer(raw, "timeout_ms", name) } : {},
|
|
178
|
+
...retry !== void 0 ? { retry } : {},
|
|
179
|
+
...features ? { features } : {}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/image-generation.ts
|
|
186
|
+
var OPENAI_IMAGE_MODELS = [
|
|
187
|
+
"gpt-image-2.5-sunburst",
|
|
188
|
+
"gpt-image-2.5-flare"
|
|
189
|
+
];
|
|
190
|
+
var OPENAI_CODEX_IMAGE_MODELS = [
|
|
191
|
+
"gpt-image-2",
|
|
192
|
+
...OPENAI_IMAGE_MODELS
|
|
193
|
+
];
|
|
194
|
+
var object = (v) => {
|
|
195
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) invalid();
|
|
196
|
+
return v;
|
|
197
|
+
};
|
|
198
|
+
var invalid = () => {
|
|
199
|
+
throw new Error(
|
|
200
|
+
"Invalid image_generation configuration; check mode, provider, model and allowed options (never put credentials here)."
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
var keys = (v, allowed) => {
|
|
204
|
+
if (Object.keys(v).some((key) => !allowed.includes(key))) invalid();
|
|
205
|
+
};
|
|
206
|
+
var choice = (v, allowed) => {
|
|
207
|
+
if (typeof v !== "string" || !allowed.includes(v)) invalid();
|
|
208
|
+
return v;
|
|
209
|
+
};
|
|
210
|
+
var id = (v) => {
|
|
211
|
+
if (typeof v !== "string" || v.length > 160 || !/^[a-zA-Z0-9][a-zA-Z0-9._:/-]*$/.test(v) || v.includes("://"))
|
|
212
|
+
invalid();
|
|
213
|
+
return v;
|
|
214
|
+
};
|
|
215
|
+
var parseImageGenerationConfig = (value) => {
|
|
216
|
+
const v = object(value);
|
|
217
|
+
const mode = choice(v.mode, ["off", "builtin", "custom"]);
|
|
218
|
+
keys(
|
|
219
|
+
v,
|
|
220
|
+
mode === "off" ? ["mode"] : mode === "builtin" ? ["mode", "provider_options"] : ["mode", "provider", "model", "api_key_env", "provider_options"]
|
|
221
|
+
);
|
|
222
|
+
if (mode === "off") return { mode };
|
|
223
|
+
const options = {};
|
|
224
|
+
if (v.provider_options !== void 0) {
|
|
225
|
+
const p = object(v.provider_options);
|
|
226
|
+
keys(p, ["openai", "openrouter"]);
|
|
227
|
+
if (p.openai !== void 0) {
|
|
228
|
+
const o = object(p.openai);
|
|
229
|
+
keys(o, ["model", "size", "quality"]);
|
|
230
|
+
options.openai = {
|
|
231
|
+
...o.model !== void 0 ? { model: choice(o.model, OPENAI_CODEX_IMAGE_MODELS) } : {},
|
|
232
|
+
...o.size !== void 0 ? {
|
|
233
|
+
size: choice(o.size, [
|
|
234
|
+
"auto",
|
|
235
|
+
"1024x1024",
|
|
236
|
+
"1536x1024",
|
|
237
|
+
"1024x1536"
|
|
238
|
+
])
|
|
239
|
+
} : {},
|
|
240
|
+
...o.quality !== void 0 ? { quality: choice(o.quality, ["auto", "low", "medium", "high"]) } : {}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
if (p.openrouter !== void 0) {
|
|
244
|
+
const o = object(p.openrouter);
|
|
245
|
+
keys(o, ["endpoint", "quality", "resolution", "aspect_ratio"]);
|
|
246
|
+
if (o.aspect_ratio !== void 0 && (typeof o.aspect_ratio !== "string" || !/^(auto|[1-9][0-9]?:[1-9][0-9]?)$/.test(o.aspect_ratio)))
|
|
247
|
+
invalid();
|
|
248
|
+
options.openrouter = {
|
|
249
|
+
...o.endpoint !== void 0 ? { endpoint: id(o.endpoint) } : {},
|
|
250
|
+
...o.quality !== void 0 ? { quality: choice(o.quality, ["auto", "low", "medium", "high"]) } : {},
|
|
251
|
+
...o.resolution !== void 0 ? { resolution: choice(o.resolution, ["512", "1K", "2K", "4K"]) } : {},
|
|
252
|
+
...typeof o.aspect_ratio === "string" ? { aspect_ratio: o.aspect_ratio } : {}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const common = v.provider_options !== void 0 ? { provider_options: options } : {};
|
|
257
|
+
if (mode === "builtin") return { mode, ...common };
|
|
258
|
+
const provider = choice(v.provider, ["openai", "openrouter"]);
|
|
259
|
+
const model = provider === "openai" ? choice(v.model, OPENAI_IMAGE_MODELS) : id(v.model);
|
|
260
|
+
if (provider === "openai" && options.openai?.model !== void 0) invalid();
|
|
261
|
+
if (v.api_key_env !== void 0 && (typeof v.api_key_env !== "string" || !/^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(v.api_key_env)))
|
|
262
|
+
invalid();
|
|
263
|
+
return {
|
|
264
|
+
mode,
|
|
265
|
+
provider,
|
|
266
|
+
model,
|
|
267
|
+
...common,
|
|
268
|
+
...typeof v.api_key_env === "string" ? { api_key_env: v.api_key_env } : {}
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// src/index.ts
|
|
273
|
+
var SUBAGENT_MAX_CONCURRENT_LIMIT = 16;
|
|
30
274
|
var CONFIG_GROUP_DEFAULT_WRITE_SCOPE = {
|
|
31
275
|
model: "global",
|
|
276
|
+
providers: "global",
|
|
277
|
+
subagent: "global",
|
|
32
278
|
experimental: "global",
|
|
33
279
|
permissions: "project",
|
|
34
280
|
mcp: "project",
|
|
35
281
|
skills: "project",
|
|
36
282
|
execution_environment: "project",
|
|
37
283
|
search: "project",
|
|
284
|
+
image_generation: "project",
|
|
38
285
|
tui: "global"
|
|
39
286
|
};
|
|
40
287
|
var CONFIG_VERSION = 1;
|
|
@@ -312,6 +559,44 @@ var parseSearchConfig = (value) => {
|
|
|
312
559
|
}
|
|
313
560
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
314
561
|
};
|
|
562
|
+
var parseModelConfig = (value) => isRecord(value) ? {
|
|
563
|
+
provider: pickString(value.provider),
|
|
564
|
+
name: pickString(value.name),
|
|
565
|
+
reasoning: pickString(value.reasoning),
|
|
566
|
+
verbosity: pickString(value.verbosity),
|
|
567
|
+
fast: pickBoolean(value.fast)
|
|
568
|
+
} : void 0;
|
|
569
|
+
var parseSubagentConfig = (value, source) => {
|
|
570
|
+
if (!isRecord(value)) return void 0;
|
|
571
|
+
const maxConcurrent = value.max_concurrent;
|
|
572
|
+
if (maxConcurrent !== void 0 && (typeof maxConcurrent !== "number" || !Number.isInteger(maxConcurrent) || maxConcurrent < 1 || maxConcurrent > SUBAGENT_MAX_CONCURRENT_LIMIT)) {
|
|
573
|
+
throw new Error(
|
|
574
|
+
`${source}: subagent.max_concurrent must be an integer from 1 to ${SUBAGENT_MAX_CONCURRENT_LIMIT}`
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
const profiles = isRecord(value.profiles) ? Object.fromEntries(
|
|
578
|
+
Object.entries(value.profiles).map(([name, profile]) => {
|
|
579
|
+
const model = isRecord(profile) ? parseModelConfig(profile.model) : void 0;
|
|
580
|
+
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(name) || !model?.name) {
|
|
581
|
+
throw new Error(
|
|
582
|
+
`${source}: subagent profile ${name} requires a valid profile name and model.name`
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
return [
|
|
586
|
+
name,
|
|
587
|
+
{
|
|
588
|
+
description: isRecord(profile) ? pickString(profile.description) : void 0,
|
|
589
|
+
model: { ...model, name: model.name }
|
|
590
|
+
}
|
|
591
|
+
];
|
|
592
|
+
})
|
|
593
|
+
) : void 0;
|
|
594
|
+
return {
|
|
595
|
+
max_concurrent: maxConcurrent,
|
|
596
|
+
default_profile: pickString(value.default_profile),
|
|
597
|
+
profiles
|
|
598
|
+
};
|
|
599
|
+
};
|
|
315
600
|
var parseConfig = (value, sourceLabel) => {
|
|
316
601
|
if (!isRecord(value)) {
|
|
317
602
|
throw new Error(`${sourceLabel}: config must be an object`);
|
|
@@ -320,14 +605,8 @@ var parseConfig = (value, sourceLabel) => {
|
|
|
320
605
|
if (version !== CONFIG_VERSION) {
|
|
321
606
|
throw new Error(`${sourceLabel}: unsupported version ${String(version)}`);
|
|
322
607
|
}
|
|
323
|
-
const
|
|
324
|
-
const
|
|
325
|
-
provider: pickString(modelValue.provider),
|
|
326
|
-
name: pickString(modelValue.name),
|
|
327
|
-
reasoning: pickString(modelValue.reasoning),
|
|
328
|
-
verbosity: pickString(modelValue.verbosity),
|
|
329
|
-
fast: pickBoolean(modelValue.fast)
|
|
330
|
-
} : void 0;
|
|
608
|
+
const model = parseModelConfig(value.model);
|
|
609
|
+
const subagent = parseSubagentConfig(value.subagent, sourceLabel);
|
|
331
610
|
const permissionsValue = value.permissions;
|
|
332
611
|
const permissions = isRecord(permissionsValue) ? {
|
|
333
612
|
allow: parsePermissionRules(permissionsValue.allow),
|
|
@@ -345,6 +624,13 @@ var parseConfig = (value, sourceLabel) => {
|
|
|
345
624
|
...pickString(value.tui.theme) ? { theme: pickString(value.tui.theme) } : {}
|
|
346
625
|
} : void 0;
|
|
347
626
|
const result = { version, model };
|
|
627
|
+
if (value.providers !== void 0)
|
|
628
|
+
result.providers = parseResponsesProviders(value.providers, sourceLabel);
|
|
629
|
+
if (value.image_generation !== void 0)
|
|
630
|
+
result.image_generation = parseImageGenerationConfig(
|
|
631
|
+
value.image_generation
|
|
632
|
+
);
|
|
633
|
+
if (subagent) result.subagent = subagent;
|
|
348
634
|
if (hasPermissions) {
|
|
349
635
|
result.permissions = hasPermissions;
|
|
350
636
|
}
|
|
@@ -376,9 +662,23 @@ var ConfigRegistry = class {
|
|
|
376
662
|
resolve(layers) {
|
|
377
663
|
const merged = { version: CONFIG_VERSION };
|
|
378
664
|
for (const layer of [...this.defaults, ...layers]) {
|
|
665
|
+
if (layer?.providers)
|
|
666
|
+
merged.providers = { ...merged.providers, ...layer.providers };
|
|
379
667
|
if (layer?.model) {
|
|
380
668
|
merged.model = { ...merged.model, ...layer.model };
|
|
381
669
|
}
|
|
670
|
+
if (layer?.subagent) {
|
|
671
|
+
merged.subagent = {
|
|
672
|
+
max_concurrent: layer.subagent.max_concurrent ?? merged.subagent?.max_concurrent,
|
|
673
|
+
default_profile: layer.subagent.default_profile ?? merged.subagent?.default_profile,
|
|
674
|
+
profiles: {
|
|
675
|
+
...merged.subagent?.profiles,
|
|
676
|
+
...layer.subagent.profiles
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
if (layer?.image_generation)
|
|
681
|
+
merged.image_generation = structuredClone(layer.image_generation);
|
|
382
682
|
if (layer?.experimental) {
|
|
383
683
|
const nextExperimental = layer.experimental;
|
|
384
684
|
merged.experimental ??= {};
|
|
@@ -499,9 +799,15 @@ var ConfigRegistry = class {
|
|
|
499
799
|
var configRegistry = new ConfigRegistry();
|
|
500
800
|
// Annotate the CommonJS export names for ESM import in node:
|
|
501
801
|
0 && (module.exports = {
|
|
802
|
+
BUILTIN_PROVIDER_NAMES,
|
|
502
803
|
CONFIG_GROUP_DEFAULT_WRITE_SCOPE,
|
|
503
804
|
CONFIG_VERSION,
|
|
504
805
|
ConfigRegistry,
|
|
806
|
+
OPENAI_CODEX_IMAGE_MODELS,
|
|
807
|
+
OPENAI_IMAGE_MODELS,
|
|
808
|
+
SUBAGENT_MAX_CONCURRENT_LIMIT,
|
|
505
809
|
configRegistry,
|
|
506
|
-
parseConfig
|
|
810
|
+
parseConfig,
|
|
811
|
+
parseImageGenerationConfig,
|
|
812
|
+
parseResponsesProviders
|
|
507
813
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
/** Named HTTP Responses endpoints. This module is pure config validation. */
|
|
2
|
+
type ResponsesModelConfig = {
|
|
3
|
+
context_window: number;
|
|
4
|
+
max_input_tokens?: number;
|
|
5
|
+
max_output_tokens?: number;
|
|
6
|
+
supports_tools?: boolean;
|
|
7
|
+
supports_reasoning?: boolean;
|
|
8
|
+
supports_json_schema?: boolean;
|
|
9
|
+
supports_vision?: boolean;
|
|
10
|
+
reasoning_levels?: Array<"low" | "medium" | "high" | "xhigh" | "max">;
|
|
11
|
+
};
|
|
12
|
+
type ResponsesProviderConfig = {
|
|
13
|
+
type: "responses";
|
|
14
|
+
base_url: string;
|
|
15
|
+
api_key_env?: string;
|
|
16
|
+
timeout_ms?: number;
|
|
17
|
+
retry?: "off" | {
|
|
18
|
+
max_retries: number;
|
|
19
|
+
base_delay_ms?: number;
|
|
20
|
+
};
|
|
21
|
+
features?: {
|
|
22
|
+
encrypted_reasoning?: boolean;
|
|
23
|
+
reasoning_summary?: "auto" | "concise" | "detailed";
|
|
24
|
+
prompt_cache_key?: boolean;
|
|
25
|
+
session_id_header?: boolean;
|
|
26
|
+
text_verbosity?: boolean;
|
|
27
|
+
};
|
|
28
|
+
models: Record<string, ResponsesModelConfig>;
|
|
29
|
+
};
|
|
30
|
+
declare const BUILTIN_PROVIDER_NAMES: readonly ["openai", "anthropic", "openrouter", "google", "moonshot", "zai", "xai"];
|
|
31
|
+
declare function parseResponsesProviders(value: unknown, source?: string): Record<string, ResponsesProviderConfig>;
|
|
32
|
+
|
|
33
|
+
declare const OPENAI_IMAGE_MODELS: readonly ["gpt-image-2.5-sunburst", "gpt-image-2.5-flare"];
|
|
34
|
+
declare const OPENAI_CODEX_IMAGE_MODELS: readonly ["gpt-image-2", "gpt-image-2.5-sunburst", "gpt-image-2.5-flare"];
|
|
35
|
+
type OpenAiImageOptions = {
|
|
36
|
+
model?: string;
|
|
37
|
+
quality?: "auto" | "low" | "medium" | "high";
|
|
38
|
+
size?: "auto" | "1024x1024" | "1536x1024" | "1024x1536";
|
|
39
|
+
};
|
|
40
|
+
type OpenRouterImageOptions = {
|
|
41
|
+
endpoint?: string;
|
|
42
|
+
quality?: "auto" | "low" | "medium" | "high";
|
|
43
|
+
resolution?: "512" | "1K" | "2K" | "4K";
|
|
44
|
+
aspect_ratio?: string;
|
|
45
|
+
};
|
|
46
|
+
type ImageProviderOptions = {
|
|
47
|
+
openai?: OpenAiImageOptions;
|
|
48
|
+
openrouter?: OpenRouterImageOptions;
|
|
49
|
+
};
|
|
50
|
+
type ImageGenerationConfig = {
|
|
51
|
+
mode: "off";
|
|
52
|
+
} | {
|
|
53
|
+
mode: "builtin";
|
|
54
|
+
provider_options?: ImageProviderOptions;
|
|
55
|
+
} | {
|
|
56
|
+
mode: "custom";
|
|
57
|
+
provider: "openai" | "openrouter";
|
|
58
|
+
model: string;
|
|
59
|
+
api_key_env?: string;
|
|
60
|
+
provider_options?: ImageProviderOptions;
|
|
61
|
+
};
|
|
62
|
+
/** Strict and atomic: malformed configuration must never silently enable a route. */
|
|
63
|
+
declare const parseImageGenerationConfig: (value: unknown) => ImageGenerationConfig;
|
|
64
|
+
|
|
1
65
|
type ModelConfig = {
|
|
2
66
|
provider?: string;
|
|
3
67
|
name?: string;
|
|
@@ -5,6 +69,17 @@ type ModelConfig = {
|
|
|
5
69
|
verbosity?: string;
|
|
6
70
|
fast?: boolean;
|
|
7
71
|
};
|
|
72
|
+
declare const SUBAGENT_MAX_CONCURRENT_LIMIT = 16;
|
|
73
|
+
type SubagentConfig = {
|
|
74
|
+
max_concurrent?: number;
|
|
75
|
+
default_profile?: string;
|
|
76
|
+
profiles?: Record<string, {
|
|
77
|
+
description?: string;
|
|
78
|
+
model: ModelConfig & {
|
|
79
|
+
name: string;
|
|
80
|
+
};
|
|
81
|
+
}>;
|
|
82
|
+
};
|
|
8
83
|
type OpenAiExperimentalConfig = {
|
|
9
84
|
websocket_mode?: "off" | "auto" | "on";
|
|
10
85
|
};
|
|
@@ -98,8 +173,11 @@ type TuiConfig = {
|
|
|
98
173
|
theme?: string;
|
|
99
174
|
};
|
|
100
175
|
type CodeliaConfig = {
|
|
176
|
+
providers?: Record<string, ResponsesProviderConfig>;
|
|
177
|
+
image_generation?: ImageGenerationConfig;
|
|
101
178
|
version: number;
|
|
102
179
|
model?: ModelConfig;
|
|
180
|
+
subagent?: SubagentConfig;
|
|
103
181
|
experimental?: ExperimentalConfig;
|
|
104
182
|
permissions?: PermissionsConfig;
|
|
105
183
|
mcp?: McpConfig;
|
|
@@ -114,7 +192,10 @@ declare const CONFIG_GROUP_DEFAULT_WRITE_SCOPE: Record<ConfigWriteGroup, ConfigW
|
|
|
114
192
|
declare const CONFIG_VERSION = 1;
|
|
115
193
|
declare const parseConfig: (value: unknown, sourceLabel: string) => CodeliaConfig;
|
|
116
194
|
type ConfigLayer = {
|
|
195
|
+
providers?: Record<string, ResponsesProviderConfig>;
|
|
196
|
+
image_generation?: ImageGenerationConfig;
|
|
117
197
|
model?: ModelConfig;
|
|
198
|
+
subagent?: SubagentConfig;
|
|
118
199
|
experimental?: ExperimentalConfig;
|
|
119
200
|
permissions?: PermissionsConfig;
|
|
120
201
|
mcp?: McpConfig;
|
|
@@ -130,4 +211,4 @@ declare class ConfigRegistry {
|
|
|
130
211
|
}
|
|
131
212
|
declare const configRegistry: ConfigRegistry;
|
|
132
213
|
|
|
133
|
-
export { CONFIG_GROUP_DEFAULT_WRITE_SCOPE, CONFIG_VERSION, type CodeliaConfig, ConfigRegistry, type ConfigWriteGroup, type ConfigWriteScope, type ExecutionEnvironmentConfig, type ExecutionEnvironmentStartupChecksConfig, type ExecutionEnvironmentStartupChecksMode, type ExperimentalConfig, type McpConfig, type McpServerConfig, type ModelConfig, type OpenAiExperimentalConfig, type PermissionRule, type PermissionsConfig, type SearchConfig, type SearchMode, type SkillsConfig, type TuiConfig, configRegistry, parseConfig };
|
|
214
|
+
export { BUILTIN_PROVIDER_NAMES, CONFIG_GROUP_DEFAULT_WRITE_SCOPE, CONFIG_VERSION, type CodeliaConfig, ConfigRegistry, type ConfigWriteGroup, type ConfigWriteScope, type ExecutionEnvironmentConfig, type ExecutionEnvironmentStartupChecksConfig, type ExecutionEnvironmentStartupChecksMode, type ExperimentalConfig, type ImageGenerationConfig, type ImageProviderOptions, type McpConfig, type McpServerConfig, type ModelConfig, OPENAI_CODEX_IMAGE_MODELS, OPENAI_IMAGE_MODELS, type OpenAiExperimentalConfig, type OpenAiImageOptions, type OpenRouterImageOptions, type PermissionRule, type PermissionsConfig, type ResponsesModelConfig, type ResponsesProviderConfig, SUBAGENT_MAX_CONCURRENT_LIMIT, type SearchConfig, type SearchMode, type SkillsConfig, type SubagentConfig, type TuiConfig, configRegistry, parseConfig, parseImageGenerationConfig, parseResponsesProviders };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
/** Named HTTP Responses endpoints. This module is pure config validation. */
|
|
2
|
+
type ResponsesModelConfig = {
|
|
3
|
+
context_window: number;
|
|
4
|
+
max_input_tokens?: number;
|
|
5
|
+
max_output_tokens?: number;
|
|
6
|
+
supports_tools?: boolean;
|
|
7
|
+
supports_reasoning?: boolean;
|
|
8
|
+
supports_json_schema?: boolean;
|
|
9
|
+
supports_vision?: boolean;
|
|
10
|
+
reasoning_levels?: Array<"low" | "medium" | "high" | "xhigh" | "max">;
|
|
11
|
+
};
|
|
12
|
+
type ResponsesProviderConfig = {
|
|
13
|
+
type: "responses";
|
|
14
|
+
base_url: string;
|
|
15
|
+
api_key_env?: string;
|
|
16
|
+
timeout_ms?: number;
|
|
17
|
+
retry?: "off" | {
|
|
18
|
+
max_retries: number;
|
|
19
|
+
base_delay_ms?: number;
|
|
20
|
+
};
|
|
21
|
+
features?: {
|
|
22
|
+
encrypted_reasoning?: boolean;
|
|
23
|
+
reasoning_summary?: "auto" | "concise" | "detailed";
|
|
24
|
+
prompt_cache_key?: boolean;
|
|
25
|
+
session_id_header?: boolean;
|
|
26
|
+
text_verbosity?: boolean;
|
|
27
|
+
};
|
|
28
|
+
models: Record<string, ResponsesModelConfig>;
|
|
29
|
+
};
|
|
30
|
+
declare const BUILTIN_PROVIDER_NAMES: readonly ["openai", "anthropic", "openrouter", "google", "moonshot", "zai", "xai"];
|
|
31
|
+
declare function parseResponsesProviders(value: unknown, source?: string): Record<string, ResponsesProviderConfig>;
|
|
32
|
+
|
|
33
|
+
declare const OPENAI_IMAGE_MODELS: readonly ["gpt-image-2.5-sunburst", "gpt-image-2.5-flare"];
|
|
34
|
+
declare const OPENAI_CODEX_IMAGE_MODELS: readonly ["gpt-image-2", "gpt-image-2.5-sunburst", "gpt-image-2.5-flare"];
|
|
35
|
+
type OpenAiImageOptions = {
|
|
36
|
+
model?: string;
|
|
37
|
+
quality?: "auto" | "low" | "medium" | "high";
|
|
38
|
+
size?: "auto" | "1024x1024" | "1536x1024" | "1024x1536";
|
|
39
|
+
};
|
|
40
|
+
type OpenRouterImageOptions = {
|
|
41
|
+
endpoint?: string;
|
|
42
|
+
quality?: "auto" | "low" | "medium" | "high";
|
|
43
|
+
resolution?: "512" | "1K" | "2K" | "4K";
|
|
44
|
+
aspect_ratio?: string;
|
|
45
|
+
};
|
|
46
|
+
type ImageProviderOptions = {
|
|
47
|
+
openai?: OpenAiImageOptions;
|
|
48
|
+
openrouter?: OpenRouterImageOptions;
|
|
49
|
+
};
|
|
50
|
+
type ImageGenerationConfig = {
|
|
51
|
+
mode: "off";
|
|
52
|
+
} | {
|
|
53
|
+
mode: "builtin";
|
|
54
|
+
provider_options?: ImageProviderOptions;
|
|
55
|
+
} | {
|
|
56
|
+
mode: "custom";
|
|
57
|
+
provider: "openai" | "openrouter";
|
|
58
|
+
model: string;
|
|
59
|
+
api_key_env?: string;
|
|
60
|
+
provider_options?: ImageProviderOptions;
|
|
61
|
+
};
|
|
62
|
+
/** Strict and atomic: malformed configuration must never silently enable a route. */
|
|
63
|
+
declare const parseImageGenerationConfig: (value: unknown) => ImageGenerationConfig;
|
|
64
|
+
|
|
1
65
|
type ModelConfig = {
|
|
2
66
|
provider?: string;
|
|
3
67
|
name?: string;
|
|
@@ -5,6 +69,17 @@ type ModelConfig = {
|
|
|
5
69
|
verbosity?: string;
|
|
6
70
|
fast?: boolean;
|
|
7
71
|
};
|
|
72
|
+
declare const SUBAGENT_MAX_CONCURRENT_LIMIT = 16;
|
|
73
|
+
type SubagentConfig = {
|
|
74
|
+
max_concurrent?: number;
|
|
75
|
+
default_profile?: string;
|
|
76
|
+
profiles?: Record<string, {
|
|
77
|
+
description?: string;
|
|
78
|
+
model: ModelConfig & {
|
|
79
|
+
name: string;
|
|
80
|
+
};
|
|
81
|
+
}>;
|
|
82
|
+
};
|
|
8
83
|
type OpenAiExperimentalConfig = {
|
|
9
84
|
websocket_mode?: "off" | "auto" | "on";
|
|
10
85
|
};
|
|
@@ -98,8 +173,11 @@ type TuiConfig = {
|
|
|
98
173
|
theme?: string;
|
|
99
174
|
};
|
|
100
175
|
type CodeliaConfig = {
|
|
176
|
+
providers?: Record<string, ResponsesProviderConfig>;
|
|
177
|
+
image_generation?: ImageGenerationConfig;
|
|
101
178
|
version: number;
|
|
102
179
|
model?: ModelConfig;
|
|
180
|
+
subagent?: SubagentConfig;
|
|
103
181
|
experimental?: ExperimentalConfig;
|
|
104
182
|
permissions?: PermissionsConfig;
|
|
105
183
|
mcp?: McpConfig;
|
|
@@ -114,7 +192,10 @@ declare const CONFIG_GROUP_DEFAULT_WRITE_SCOPE: Record<ConfigWriteGroup, ConfigW
|
|
|
114
192
|
declare const CONFIG_VERSION = 1;
|
|
115
193
|
declare const parseConfig: (value: unknown, sourceLabel: string) => CodeliaConfig;
|
|
116
194
|
type ConfigLayer = {
|
|
195
|
+
providers?: Record<string, ResponsesProviderConfig>;
|
|
196
|
+
image_generation?: ImageGenerationConfig;
|
|
117
197
|
model?: ModelConfig;
|
|
198
|
+
subagent?: SubagentConfig;
|
|
118
199
|
experimental?: ExperimentalConfig;
|
|
119
200
|
permissions?: PermissionsConfig;
|
|
120
201
|
mcp?: McpConfig;
|
|
@@ -130,4 +211,4 @@ declare class ConfigRegistry {
|
|
|
130
211
|
}
|
|
131
212
|
declare const configRegistry: ConfigRegistry;
|
|
132
213
|
|
|
133
|
-
export { CONFIG_GROUP_DEFAULT_WRITE_SCOPE, CONFIG_VERSION, type CodeliaConfig, ConfigRegistry, type ConfigWriteGroup, type ConfigWriteScope, type ExecutionEnvironmentConfig, type ExecutionEnvironmentStartupChecksConfig, type ExecutionEnvironmentStartupChecksMode, type ExperimentalConfig, type McpConfig, type McpServerConfig, type ModelConfig, type OpenAiExperimentalConfig, type PermissionRule, type PermissionsConfig, type SearchConfig, type SearchMode, type SkillsConfig, type TuiConfig, configRegistry, parseConfig };
|
|
214
|
+
export { BUILTIN_PROVIDER_NAMES, CONFIG_GROUP_DEFAULT_WRITE_SCOPE, CONFIG_VERSION, type CodeliaConfig, ConfigRegistry, type ConfigWriteGroup, type ConfigWriteScope, type ExecutionEnvironmentConfig, type ExecutionEnvironmentStartupChecksConfig, type ExecutionEnvironmentStartupChecksMode, type ExperimentalConfig, type ImageGenerationConfig, type ImageProviderOptions, type McpConfig, type McpServerConfig, type ModelConfig, OPENAI_CODEX_IMAGE_MODELS, OPENAI_IMAGE_MODELS, type OpenAiExperimentalConfig, type OpenAiImageOptions, type OpenRouterImageOptions, type PermissionRule, type PermissionsConfig, type ResponsesModelConfig, type ResponsesProviderConfig, SUBAGENT_MAX_CONCURRENT_LIMIT, type SearchConfig, type SearchMode, type SkillsConfig, type SubagentConfig, type TuiConfig, configRegistry, parseConfig, parseImageGenerationConfig, parseResponsesProviders };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,251 @@
|
|
|
1
|
+
// src/responses-provider.ts
|
|
2
|
+
var BUILTIN_PROVIDER_NAMES = [
|
|
3
|
+
"openai",
|
|
4
|
+
"anthropic",
|
|
5
|
+
"openrouter",
|
|
6
|
+
"google",
|
|
7
|
+
"moonshot",
|
|
8
|
+
"zai",
|
|
9
|
+
"xai"
|
|
10
|
+
];
|
|
11
|
+
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
12
|
+
function parseResponsesProviders(value, source = "config") {
|
|
13
|
+
const fail = (field) => {
|
|
14
|
+
throw new Error(`${source}: invalid providers.${field}`);
|
|
15
|
+
};
|
|
16
|
+
if (!record(value)) return fail("(expected object)");
|
|
17
|
+
const keys2 = (entry, allowed, field) => {
|
|
18
|
+
if (Object.keys(entry).some((key) => !allowed.includes(key))) fail(field);
|
|
19
|
+
};
|
|
20
|
+
const integer = (entry, key, field, min = 1) => {
|
|
21
|
+
const number = entry[key];
|
|
22
|
+
if (number === void 0) return void 0;
|
|
23
|
+
if (typeof number !== "number" || !Number.isSafeInteger(number) || number < min)
|
|
24
|
+
fail(`${field}.${key}`);
|
|
25
|
+
return number;
|
|
26
|
+
};
|
|
27
|
+
const result = {};
|
|
28
|
+
for (const [name, raw] of Object.entries(value)) {
|
|
29
|
+
if (!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(name) || BUILTIN_PROVIDER_NAMES.some((builtin) => builtin === name) || ["__proto__", "constructor", "prototype"].includes(name))
|
|
30
|
+
fail(name);
|
|
31
|
+
if (!record(raw)) return fail(name);
|
|
32
|
+
keys2(
|
|
33
|
+
raw,
|
|
34
|
+
[
|
|
35
|
+
"type",
|
|
36
|
+
"base_url",
|
|
37
|
+
"api_key_env",
|
|
38
|
+
"timeout_ms",
|
|
39
|
+
"retry",
|
|
40
|
+
"features",
|
|
41
|
+
"models"
|
|
42
|
+
],
|
|
43
|
+
name
|
|
44
|
+
);
|
|
45
|
+
if (raw.type !== "responses" || typeof raw.base_url !== "string")
|
|
46
|
+
return fail(name);
|
|
47
|
+
let url;
|
|
48
|
+
try {
|
|
49
|
+
url = new URL(raw.base_url);
|
|
50
|
+
} catch {
|
|
51
|
+
return fail(`${name}.base_url`);
|
|
52
|
+
}
|
|
53
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash)
|
|
54
|
+
fail(`${name}.base_url`);
|
|
55
|
+
if (raw.api_key_env !== void 0 && (typeof raw.api_key_env !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(raw.api_key_env)))
|
|
56
|
+
fail(`${name}.api_key_env`);
|
|
57
|
+
let retry;
|
|
58
|
+
if (raw.retry === "off") retry = "off";
|
|
59
|
+
else if (raw.retry !== void 0) {
|
|
60
|
+
if (!record(raw.retry)) return fail(`${name}.retry`);
|
|
61
|
+
keys2(raw.retry, ["max_retries", "base_delay_ms"], `${name}.retry`);
|
|
62
|
+
const max = integer(raw.retry, "max_retries", `${name}.retry`, 0);
|
|
63
|
+
if (max === void 0 || max > 10)
|
|
64
|
+
return fail(`${name}.retry.max_retries`);
|
|
65
|
+
retry = {
|
|
66
|
+
max_retries: max,
|
|
67
|
+
base_delay_ms: integer(raw.retry, "base_delay_ms", `${name}.retry`, 0)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
let features;
|
|
71
|
+
if (raw.features !== void 0) {
|
|
72
|
+
if (!record(raw.features)) return fail(`${name}.features`);
|
|
73
|
+
keys2(
|
|
74
|
+
raw.features,
|
|
75
|
+
[
|
|
76
|
+
"encrypted_reasoning",
|
|
77
|
+
"reasoning_summary",
|
|
78
|
+
"prompt_cache_key",
|
|
79
|
+
"session_id_header",
|
|
80
|
+
"text_verbosity"
|
|
81
|
+
],
|
|
82
|
+
`${name}.features`
|
|
83
|
+
);
|
|
84
|
+
for (const [key, option] of Object.entries(raw.features)) {
|
|
85
|
+
if (key === "reasoning_summary") {
|
|
86
|
+
if (!["auto", "concise", "detailed"].includes(String(option)))
|
|
87
|
+
fail(`${name}.features.${key}`);
|
|
88
|
+
} else if (typeof option !== "boolean") fail(`${name}.features.${key}`);
|
|
89
|
+
}
|
|
90
|
+
features = { ...raw.features };
|
|
91
|
+
}
|
|
92
|
+
if (!record(raw.models) || !Object.keys(raw.models).length)
|
|
93
|
+
return fail(`${name}.models`);
|
|
94
|
+
const models = {};
|
|
95
|
+
for (const [id2, model] of Object.entries(raw.models)) {
|
|
96
|
+
const field = `${name}.models.${id2}`;
|
|
97
|
+
if (!id2.trim() || id2 !== id2.trim() || id2.length > 256 || ["__proto__", "constructor", "prototype"].includes(id2) || !record(model))
|
|
98
|
+
return fail(field);
|
|
99
|
+
keys2(
|
|
100
|
+
model,
|
|
101
|
+
[
|
|
102
|
+
"context_window",
|
|
103
|
+
"max_input_tokens",
|
|
104
|
+
"max_output_tokens",
|
|
105
|
+
"supports_tools",
|
|
106
|
+
"supports_reasoning",
|
|
107
|
+
"supports_json_schema",
|
|
108
|
+
"supports_vision",
|
|
109
|
+
"reasoning_levels"
|
|
110
|
+
],
|
|
111
|
+
field
|
|
112
|
+
);
|
|
113
|
+
const context = integer(model, "context_window", field);
|
|
114
|
+
if (context === void 0) return fail(`${field}.context_window`);
|
|
115
|
+
const input = integer(model, "max_input_tokens", field);
|
|
116
|
+
const output = integer(model, "max_output_tokens", field);
|
|
117
|
+
if ((input ?? 0) > context || (output ?? 0) > context) fail(field);
|
|
118
|
+
for (const key of [
|
|
119
|
+
"supports_tools",
|
|
120
|
+
"supports_reasoning",
|
|
121
|
+
"supports_json_schema",
|
|
122
|
+
"supports_vision"
|
|
123
|
+
]) {
|
|
124
|
+
if (model[key] !== void 0 && typeof model[key] !== "boolean")
|
|
125
|
+
fail(`${field}.${key}`);
|
|
126
|
+
}
|
|
127
|
+
if (model.reasoning_levels !== void 0 && (!Array.isArray(model.reasoning_levels) || !model.reasoning_levels.length || model.reasoning_levels.some(
|
|
128
|
+
(level) => !["low", "medium", "high", "xhigh", "max"].includes(level)
|
|
129
|
+
) || model.supports_reasoning !== true))
|
|
130
|
+
fail(`${field}.reasoning_levels`);
|
|
131
|
+
models[id2] = {
|
|
132
|
+
...model,
|
|
133
|
+
context_window: context
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
result[name] = {
|
|
137
|
+
type: "responses",
|
|
138
|
+
base_url: raw.base_url.replace(/\/+$/, ""),
|
|
139
|
+
models,
|
|
140
|
+
...raw.api_key_env ? { api_key_env: raw.api_key_env } : {},
|
|
141
|
+
...raw.timeout_ms !== void 0 ? { timeout_ms: integer(raw, "timeout_ms", name) } : {},
|
|
142
|
+
...retry !== void 0 ? { retry } : {},
|
|
143
|
+
...features ? { features } : {}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/image-generation.ts
|
|
150
|
+
var OPENAI_IMAGE_MODELS = [
|
|
151
|
+
"gpt-image-2.5-sunburst",
|
|
152
|
+
"gpt-image-2.5-flare"
|
|
153
|
+
];
|
|
154
|
+
var OPENAI_CODEX_IMAGE_MODELS = [
|
|
155
|
+
"gpt-image-2",
|
|
156
|
+
...OPENAI_IMAGE_MODELS
|
|
157
|
+
];
|
|
158
|
+
var object = (v) => {
|
|
159
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) invalid();
|
|
160
|
+
return v;
|
|
161
|
+
};
|
|
162
|
+
var invalid = () => {
|
|
163
|
+
throw new Error(
|
|
164
|
+
"Invalid image_generation configuration; check mode, provider, model and allowed options (never put credentials here)."
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
var keys = (v, allowed) => {
|
|
168
|
+
if (Object.keys(v).some((key) => !allowed.includes(key))) invalid();
|
|
169
|
+
};
|
|
170
|
+
var choice = (v, allowed) => {
|
|
171
|
+
if (typeof v !== "string" || !allowed.includes(v)) invalid();
|
|
172
|
+
return v;
|
|
173
|
+
};
|
|
174
|
+
var id = (v) => {
|
|
175
|
+
if (typeof v !== "string" || v.length > 160 || !/^[a-zA-Z0-9][a-zA-Z0-9._:/-]*$/.test(v) || v.includes("://"))
|
|
176
|
+
invalid();
|
|
177
|
+
return v;
|
|
178
|
+
};
|
|
179
|
+
var parseImageGenerationConfig = (value) => {
|
|
180
|
+
const v = object(value);
|
|
181
|
+
const mode = choice(v.mode, ["off", "builtin", "custom"]);
|
|
182
|
+
keys(
|
|
183
|
+
v,
|
|
184
|
+
mode === "off" ? ["mode"] : mode === "builtin" ? ["mode", "provider_options"] : ["mode", "provider", "model", "api_key_env", "provider_options"]
|
|
185
|
+
);
|
|
186
|
+
if (mode === "off") return { mode };
|
|
187
|
+
const options = {};
|
|
188
|
+
if (v.provider_options !== void 0) {
|
|
189
|
+
const p = object(v.provider_options);
|
|
190
|
+
keys(p, ["openai", "openrouter"]);
|
|
191
|
+
if (p.openai !== void 0) {
|
|
192
|
+
const o = object(p.openai);
|
|
193
|
+
keys(o, ["model", "size", "quality"]);
|
|
194
|
+
options.openai = {
|
|
195
|
+
...o.model !== void 0 ? { model: choice(o.model, OPENAI_CODEX_IMAGE_MODELS) } : {},
|
|
196
|
+
...o.size !== void 0 ? {
|
|
197
|
+
size: choice(o.size, [
|
|
198
|
+
"auto",
|
|
199
|
+
"1024x1024",
|
|
200
|
+
"1536x1024",
|
|
201
|
+
"1024x1536"
|
|
202
|
+
])
|
|
203
|
+
} : {},
|
|
204
|
+
...o.quality !== void 0 ? { quality: choice(o.quality, ["auto", "low", "medium", "high"]) } : {}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
if (p.openrouter !== void 0) {
|
|
208
|
+
const o = object(p.openrouter);
|
|
209
|
+
keys(o, ["endpoint", "quality", "resolution", "aspect_ratio"]);
|
|
210
|
+
if (o.aspect_ratio !== void 0 && (typeof o.aspect_ratio !== "string" || !/^(auto|[1-9][0-9]?:[1-9][0-9]?)$/.test(o.aspect_ratio)))
|
|
211
|
+
invalid();
|
|
212
|
+
options.openrouter = {
|
|
213
|
+
...o.endpoint !== void 0 ? { endpoint: id(o.endpoint) } : {},
|
|
214
|
+
...o.quality !== void 0 ? { quality: choice(o.quality, ["auto", "low", "medium", "high"]) } : {},
|
|
215
|
+
...o.resolution !== void 0 ? { resolution: choice(o.resolution, ["512", "1K", "2K", "4K"]) } : {},
|
|
216
|
+
...typeof o.aspect_ratio === "string" ? { aspect_ratio: o.aspect_ratio } : {}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const common = v.provider_options !== void 0 ? { provider_options: options } : {};
|
|
221
|
+
if (mode === "builtin") return { mode, ...common };
|
|
222
|
+
const provider = choice(v.provider, ["openai", "openrouter"]);
|
|
223
|
+
const model = provider === "openai" ? choice(v.model, OPENAI_IMAGE_MODELS) : id(v.model);
|
|
224
|
+
if (provider === "openai" && options.openai?.model !== void 0) invalid();
|
|
225
|
+
if (v.api_key_env !== void 0 && (typeof v.api_key_env !== "string" || !/^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(v.api_key_env)))
|
|
226
|
+
invalid();
|
|
227
|
+
return {
|
|
228
|
+
mode,
|
|
229
|
+
provider,
|
|
230
|
+
model,
|
|
231
|
+
...common,
|
|
232
|
+
...typeof v.api_key_env === "string" ? { api_key_env: v.api_key_env } : {}
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
|
|
1
236
|
// src/index.ts
|
|
237
|
+
var SUBAGENT_MAX_CONCURRENT_LIMIT = 16;
|
|
2
238
|
var CONFIG_GROUP_DEFAULT_WRITE_SCOPE = {
|
|
3
239
|
model: "global",
|
|
240
|
+
providers: "global",
|
|
241
|
+
subagent: "global",
|
|
4
242
|
experimental: "global",
|
|
5
243
|
permissions: "project",
|
|
6
244
|
mcp: "project",
|
|
7
245
|
skills: "project",
|
|
8
246
|
execution_environment: "project",
|
|
9
247
|
search: "project",
|
|
248
|
+
image_generation: "project",
|
|
10
249
|
tui: "global"
|
|
11
250
|
};
|
|
12
251
|
var CONFIG_VERSION = 1;
|
|
@@ -284,6 +523,44 @@ var parseSearchConfig = (value) => {
|
|
|
284
523
|
}
|
|
285
524
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
286
525
|
};
|
|
526
|
+
var parseModelConfig = (value) => isRecord(value) ? {
|
|
527
|
+
provider: pickString(value.provider),
|
|
528
|
+
name: pickString(value.name),
|
|
529
|
+
reasoning: pickString(value.reasoning),
|
|
530
|
+
verbosity: pickString(value.verbosity),
|
|
531
|
+
fast: pickBoolean(value.fast)
|
|
532
|
+
} : void 0;
|
|
533
|
+
var parseSubagentConfig = (value, source) => {
|
|
534
|
+
if (!isRecord(value)) return void 0;
|
|
535
|
+
const maxConcurrent = value.max_concurrent;
|
|
536
|
+
if (maxConcurrent !== void 0 && (typeof maxConcurrent !== "number" || !Number.isInteger(maxConcurrent) || maxConcurrent < 1 || maxConcurrent > SUBAGENT_MAX_CONCURRENT_LIMIT)) {
|
|
537
|
+
throw new Error(
|
|
538
|
+
`${source}: subagent.max_concurrent must be an integer from 1 to ${SUBAGENT_MAX_CONCURRENT_LIMIT}`
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
const profiles = isRecord(value.profiles) ? Object.fromEntries(
|
|
542
|
+
Object.entries(value.profiles).map(([name, profile]) => {
|
|
543
|
+
const model = isRecord(profile) ? parseModelConfig(profile.model) : void 0;
|
|
544
|
+
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(name) || !model?.name) {
|
|
545
|
+
throw new Error(
|
|
546
|
+
`${source}: subagent profile ${name} requires a valid profile name and model.name`
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
return [
|
|
550
|
+
name,
|
|
551
|
+
{
|
|
552
|
+
description: isRecord(profile) ? pickString(profile.description) : void 0,
|
|
553
|
+
model: { ...model, name: model.name }
|
|
554
|
+
}
|
|
555
|
+
];
|
|
556
|
+
})
|
|
557
|
+
) : void 0;
|
|
558
|
+
return {
|
|
559
|
+
max_concurrent: maxConcurrent,
|
|
560
|
+
default_profile: pickString(value.default_profile),
|
|
561
|
+
profiles
|
|
562
|
+
};
|
|
563
|
+
};
|
|
287
564
|
var parseConfig = (value, sourceLabel) => {
|
|
288
565
|
if (!isRecord(value)) {
|
|
289
566
|
throw new Error(`${sourceLabel}: config must be an object`);
|
|
@@ -292,14 +569,8 @@ var parseConfig = (value, sourceLabel) => {
|
|
|
292
569
|
if (version !== CONFIG_VERSION) {
|
|
293
570
|
throw new Error(`${sourceLabel}: unsupported version ${String(version)}`);
|
|
294
571
|
}
|
|
295
|
-
const
|
|
296
|
-
const
|
|
297
|
-
provider: pickString(modelValue.provider),
|
|
298
|
-
name: pickString(modelValue.name),
|
|
299
|
-
reasoning: pickString(modelValue.reasoning),
|
|
300
|
-
verbosity: pickString(modelValue.verbosity),
|
|
301
|
-
fast: pickBoolean(modelValue.fast)
|
|
302
|
-
} : void 0;
|
|
572
|
+
const model = parseModelConfig(value.model);
|
|
573
|
+
const subagent = parseSubagentConfig(value.subagent, sourceLabel);
|
|
303
574
|
const permissionsValue = value.permissions;
|
|
304
575
|
const permissions = isRecord(permissionsValue) ? {
|
|
305
576
|
allow: parsePermissionRules(permissionsValue.allow),
|
|
@@ -317,6 +588,13 @@ var parseConfig = (value, sourceLabel) => {
|
|
|
317
588
|
...pickString(value.tui.theme) ? { theme: pickString(value.tui.theme) } : {}
|
|
318
589
|
} : void 0;
|
|
319
590
|
const result = { version, model };
|
|
591
|
+
if (value.providers !== void 0)
|
|
592
|
+
result.providers = parseResponsesProviders(value.providers, sourceLabel);
|
|
593
|
+
if (value.image_generation !== void 0)
|
|
594
|
+
result.image_generation = parseImageGenerationConfig(
|
|
595
|
+
value.image_generation
|
|
596
|
+
);
|
|
597
|
+
if (subagent) result.subagent = subagent;
|
|
320
598
|
if (hasPermissions) {
|
|
321
599
|
result.permissions = hasPermissions;
|
|
322
600
|
}
|
|
@@ -348,9 +626,23 @@ var ConfigRegistry = class {
|
|
|
348
626
|
resolve(layers) {
|
|
349
627
|
const merged = { version: CONFIG_VERSION };
|
|
350
628
|
for (const layer of [...this.defaults, ...layers]) {
|
|
629
|
+
if (layer?.providers)
|
|
630
|
+
merged.providers = { ...merged.providers, ...layer.providers };
|
|
351
631
|
if (layer?.model) {
|
|
352
632
|
merged.model = { ...merged.model, ...layer.model };
|
|
353
633
|
}
|
|
634
|
+
if (layer?.subagent) {
|
|
635
|
+
merged.subagent = {
|
|
636
|
+
max_concurrent: layer.subagent.max_concurrent ?? merged.subagent?.max_concurrent,
|
|
637
|
+
default_profile: layer.subagent.default_profile ?? merged.subagent?.default_profile,
|
|
638
|
+
profiles: {
|
|
639
|
+
...merged.subagent?.profiles,
|
|
640
|
+
...layer.subagent.profiles
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
if (layer?.image_generation)
|
|
645
|
+
merged.image_generation = structuredClone(layer.image_generation);
|
|
354
646
|
if (layer?.experimental) {
|
|
355
647
|
const nextExperimental = layer.experimental;
|
|
356
648
|
merged.experimental ??= {};
|
|
@@ -470,9 +762,15 @@ var ConfigRegistry = class {
|
|
|
470
762
|
};
|
|
471
763
|
var configRegistry = new ConfigRegistry();
|
|
472
764
|
export {
|
|
765
|
+
BUILTIN_PROVIDER_NAMES,
|
|
473
766
|
CONFIG_GROUP_DEFAULT_WRITE_SCOPE,
|
|
474
767
|
CONFIG_VERSION,
|
|
475
768
|
ConfigRegistry,
|
|
769
|
+
OPENAI_CODEX_IMAGE_MODELS,
|
|
770
|
+
OPENAI_IMAGE_MODELS,
|
|
771
|
+
SUBAGENT_MAX_CONCURRENT_LIMIT,
|
|
476
772
|
configRegistry,
|
|
477
|
-
parseConfig
|
|
773
|
+
parseConfig,
|
|
774
|
+
parseImageGenerationConfig,
|
|
775
|
+
parseResponsesProviders
|
|
478
776
|
};
|