@codelia/config 0.1.81 → 0.1.83
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 +267 -3
- package/dist/index.d.cts +70 -2
- package/dist/index.d.ts +70 -2
- package/dist/index.js +259 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,17 +20,260 @@ 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,
|
|
26
29
|
SUBAGENT_MAX_CONCURRENT_LIMIT: () => SUBAGENT_MAX_CONCURRENT_LIMIT,
|
|
27
30
|
configRegistry: () => configRegistry,
|
|
28
|
-
parseConfig: () => parseConfig
|
|
31
|
+
parseConfig: () => parseConfig,
|
|
32
|
+
parseImageGenerationConfig: () => parseImageGenerationConfig,
|
|
33
|
+
parseResponsesProviders: () => parseResponsesProviders
|
|
29
34
|
});
|
|
30
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
|
|
31
273
|
var SUBAGENT_MAX_CONCURRENT_LIMIT = 16;
|
|
32
274
|
var CONFIG_GROUP_DEFAULT_WRITE_SCOPE = {
|
|
33
275
|
model: "global",
|
|
276
|
+
providers: "global",
|
|
34
277
|
subagent: "global",
|
|
35
278
|
experimental: "global",
|
|
36
279
|
permissions: "project",
|
|
@@ -38,6 +281,7 @@ var CONFIG_GROUP_DEFAULT_WRITE_SCOPE = {
|
|
|
38
281
|
skills: "project",
|
|
39
282
|
execution_environment: "project",
|
|
40
283
|
search: "project",
|
|
284
|
+
image_generation: "project",
|
|
41
285
|
tui: "global"
|
|
42
286
|
};
|
|
43
287
|
var CONFIG_VERSION = 1;
|
|
@@ -315,12 +559,17 @@ var parseSearchConfig = (value) => {
|
|
|
315
559
|
}
|
|
316
560
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
317
561
|
};
|
|
562
|
+
var parseModelFastMode = (value) => {
|
|
563
|
+
if (value === void 0 || typeof value === "boolean" || value === "ultrafast")
|
|
564
|
+
return value;
|
|
565
|
+
throw new Error('model.fast must be true, false, or "ultrafast"');
|
|
566
|
+
};
|
|
318
567
|
var parseModelConfig = (value) => isRecord(value) ? {
|
|
319
568
|
provider: pickString(value.provider),
|
|
320
569
|
name: pickString(value.name),
|
|
321
570
|
reasoning: pickString(value.reasoning),
|
|
322
571
|
verbosity: pickString(value.verbosity),
|
|
323
|
-
fast:
|
|
572
|
+
fast: parseModelFastMode(value.fast)
|
|
324
573
|
} : void 0;
|
|
325
574
|
var parseSubagentConfig = (value, source) => {
|
|
326
575
|
if (!isRecord(value)) return void 0;
|
|
@@ -380,6 +629,12 @@ var parseConfig = (value, sourceLabel) => {
|
|
|
380
629
|
...pickString(value.tui.theme) ? { theme: pickString(value.tui.theme) } : {}
|
|
381
630
|
} : void 0;
|
|
382
631
|
const result = { version, model };
|
|
632
|
+
if (value.providers !== void 0)
|
|
633
|
+
result.providers = parseResponsesProviders(value.providers, sourceLabel);
|
|
634
|
+
if (value.image_generation !== void 0)
|
|
635
|
+
result.image_generation = parseImageGenerationConfig(
|
|
636
|
+
value.image_generation
|
|
637
|
+
);
|
|
383
638
|
if (subagent) result.subagent = subagent;
|
|
384
639
|
if (hasPermissions) {
|
|
385
640
|
result.permissions = hasPermissions;
|
|
@@ -412,6 +667,8 @@ var ConfigRegistry = class {
|
|
|
412
667
|
resolve(layers) {
|
|
413
668
|
const merged = { version: CONFIG_VERSION };
|
|
414
669
|
for (const layer of [...this.defaults, ...layers]) {
|
|
670
|
+
if (layer?.providers)
|
|
671
|
+
merged.providers = { ...merged.providers, ...layer.providers };
|
|
415
672
|
if (layer?.model) {
|
|
416
673
|
merged.model = { ...merged.model, ...layer.model };
|
|
417
674
|
}
|
|
@@ -425,6 +682,8 @@ var ConfigRegistry = class {
|
|
|
425
682
|
}
|
|
426
683
|
};
|
|
427
684
|
}
|
|
685
|
+
if (layer?.image_generation)
|
|
686
|
+
merged.image_generation = structuredClone(layer.image_generation);
|
|
428
687
|
if (layer?.experimental) {
|
|
429
688
|
const nextExperimental = layer.experimental;
|
|
430
689
|
merged.experimental ??= {};
|
|
@@ -545,10 +804,15 @@ var ConfigRegistry = class {
|
|
|
545
804
|
var configRegistry = new ConfigRegistry();
|
|
546
805
|
// Annotate the CommonJS export names for ESM import in node:
|
|
547
806
|
0 && (module.exports = {
|
|
807
|
+
BUILTIN_PROVIDER_NAMES,
|
|
548
808
|
CONFIG_GROUP_DEFAULT_WRITE_SCOPE,
|
|
549
809
|
CONFIG_VERSION,
|
|
550
810
|
ConfigRegistry,
|
|
811
|
+
OPENAI_CODEX_IMAGE_MODELS,
|
|
812
|
+
OPENAI_IMAGE_MODELS,
|
|
551
813
|
SUBAGENT_MAX_CONCURRENT_LIMIT,
|
|
552
814
|
configRegistry,
|
|
553
|
-
parseConfig
|
|
815
|
+
parseConfig,
|
|
816
|
+
parseImageGenerationConfig,
|
|
817
|
+
parseResponsesProviders
|
|
554
818
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,73 @@
|
|
|
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;
|
|
4
68
|
reasoning?: string;
|
|
5
69
|
verbosity?: string;
|
|
6
|
-
fast?: boolean;
|
|
70
|
+
fast?: boolean | "ultrafast";
|
|
7
71
|
};
|
|
8
72
|
declare const SUBAGENT_MAX_CONCURRENT_LIMIT = 16;
|
|
9
73
|
type SubagentConfig = {
|
|
@@ -109,6 +173,8 @@ type TuiConfig = {
|
|
|
109
173
|
theme?: string;
|
|
110
174
|
};
|
|
111
175
|
type CodeliaConfig = {
|
|
176
|
+
providers?: Record<string, ResponsesProviderConfig>;
|
|
177
|
+
image_generation?: ImageGenerationConfig;
|
|
112
178
|
version: number;
|
|
113
179
|
model?: ModelConfig;
|
|
114
180
|
subagent?: SubagentConfig;
|
|
@@ -126,6 +192,8 @@ declare const CONFIG_GROUP_DEFAULT_WRITE_SCOPE: Record<ConfigWriteGroup, ConfigW
|
|
|
126
192
|
declare const CONFIG_VERSION = 1;
|
|
127
193
|
declare const parseConfig: (value: unknown, sourceLabel: string) => CodeliaConfig;
|
|
128
194
|
type ConfigLayer = {
|
|
195
|
+
providers?: Record<string, ResponsesProviderConfig>;
|
|
196
|
+
image_generation?: ImageGenerationConfig;
|
|
129
197
|
model?: ModelConfig;
|
|
130
198
|
subagent?: SubagentConfig;
|
|
131
199
|
experimental?: ExperimentalConfig;
|
|
@@ -143,4 +211,4 @@ declare class ConfigRegistry {
|
|
|
143
211
|
}
|
|
144
212
|
declare const configRegistry: ConfigRegistry;
|
|
145
213
|
|
|
146
|
-
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, SUBAGENT_MAX_CONCURRENT_LIMIT, type SearchConfig, type SearchMode, type SkillsConfig, type SubagentConfig, 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,9 +1,73 @@
|
|
|
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;
|
|
4
68
|
reasoning?: string;
|
|
5
69
|
verbosity?: string;
|
|
6
|
-
fast?: boolean;
|
|
70
|
+
fast?: boolean | "ultrafast";
|
|
7
71
|
};
|
|
8
72
|
declare const SUBAGENT_MAX_CONCURRENT_LIMIT = 16;
|
|
9
73
|
type SubagentConfig = {
|
|
@@ -109,6 +173,8 @@ type TuiConfig = {
|
|
|
109
173
|
theme?: string;
|
|
110
174
|
};
|
|
111
175
|
type CodeliaConfig = {
|
|
176
|
+
providers?: Record<string, ResponsesProviderConfig>;
|
|
177
|
+
image_generation?: ImageGenerationConfig;
|
|
112
178
|
version: number;
|
|
113
179
|
model?: ModelConfig;
|
|
114
180
|
subagent?: SubagentConfig;
|
|
@@ -126,6 +192,8 @@ declare const CONFIG_GROUP_DEFAULT_WRITE_SCOPE: Record<ConfigWriteGroup, ConfigW
|
|
|
126
192
|
declare const CONFIG_VERSION = 1;
|
|
127
193
|
declare const parseConfig: (value: unknown, sourceLabel: string) => CodeliaConfig;
|
|
128
194
|
type ConfigLayer = {
|
|
195
|
+
providers?: Record<string, ResponsesProviderConfig>;
|
|
196
|
+
image_generation?: ImageGenerationConfig;
|
|
129
197
|
model?: ModelConfig;
|
|
130
198
|
subagent?: SubagentConfig;
|
|
131
199
|
experimental?: ExperimentalConfig;
|
|
@@ -143,4 +211,4 @@ declare class ConfigRegistry {
|
|
|
143
211
|
}
|
|
144
212
|
declare const configRegistry: ConfigRegistry;
|
|
145
213
|
|
|
146
|
-
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, SUBAGENT_MAX_CONCURRENT_LIMIT, type SearchConfig, type SearchMode, type SkillsConfig, type SubagentConfig, 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,7 +1,243 @@
|
|
|
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
|
|
2
237
|
var SUBAGENT_MAX_CONCURRENT_LIMIT = 16;
|
|
3
238
|
var CONFIG_GROUP_DEFAULT_WRITE_SCOPE = {
|
|
4
239
|
model: "global",
|
|
240
|
+
providers: "global",
|
|
5
241
|
subagent: "global",
|
|
6
242
|
experimental: "global",
|
|
7
243
|
permissions: "project",
|
|
@@ -9,6 +245,7 @@ var CONFIG_GROUP_DEFAULT_WRITE_SCOPE = {
|
|
|
9
245
|
skills: "project",
|
|
10
246
|
execution_environment: "project",
|
|
11
247
|
search: "project",
|
|
248
|
+
image_generation: "project",
|
|
12
249
|
tui: "global"
|
|
13
250
|
};
|
|
14
251
|
var CONFIG_VERSION = 1;
|
|
@@ -286,12 +523,17 @@ var parseSearchConfig = (value) => {
|
|
|
286
523
|
}
|
|
287
524
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
288
525
|
};
|
|
526
|
+
var parseModelFastMode = (value) => {
|
|
527
|
+
if (value === void 0 || typeof value === "boolean" || value === "ultrafast")
|
|
528
|
+
return value;
|
|
529
|
+
throw new Error('model.fast must be true, false, or "ultrafast"');
|
|
530
|
+
};
|
|
289
531
|
var parseModelConfig = (value) => isRecord(value) ? {
|
|
290
532
|
provider: pickString(value.provider),
|
|
291
533
|
name: pickString(value.name),
|
|
292
534
|
reasoning: pickString(value.reasoning),
|
|
293
535
|
verbosity: pickString(value.verbosity),
|
|
294
|
-
fast:
|
|
536
|
+
fast: parseModelFastMode(value.fast)
|
|
295
537
|
} : void 0;
|
|
296
538
|
var parseSubagentConfig = (value, source) => {
|
|
297
539
|
if (!isRecord(value)) return void 0;
|
|
@@ -351,6 +593,12 @@ var parseConfig = (value, sourceLabel) => {
|
|
|
351
593
|
...pickString(value.tui.theme) ? { theme: pickString(value.tui.theme) } : {}
|
|
352
594
|
} : void 0;
|
|
353
595
|
const result = { version, model };
|
|
596
|
+
if (value.providers !== void 0)
|
|
597
|
+
result.providers = parseResponsesProviders(value.providers, sourceLabel);
|
|
598
|
+
if (value.image_generation !== void 0)
|
|
599
|
+
result.image_generation = parseImageGenerationConfig(
|
|
600
|
+
value.image_generation
|
|
601
|
+
);
|
|
354
602
|
if (subagent) result.subagent = subagent;
|
|
355
603
|
if (hasPermissions) {
|
|
356
604
|
result.permissions = hasPermissions;
|
|
@@ -383,6 +631,8 @@ var ConfigRegistry = class {
|
|
|
383
631
|
resolve(layers) {
|
|
384
632
|
const merged = { version: CONFIG_VERSION };
|
|
385
633
|
for (const layer of [...this.defaults, ...layers]) {
|
|
634
|
+
if (layer?.providers)
|
|
635
|
+
merged.providers = { ...merged.providers, ...layer.providers };
|
|
386
636
|
if (layer?.model) {
|
|
387
637
|
merged.model = { ...merged.model, ...layer.model };
|
|
388
638
|
}
|
|
@@ -396,6 +646,8 @@ var ConfigRegistry = class {
|
|
|
396
646
|
}
|
|
397
647
|
};
|
|
398
648
|
}
|
|
649
|
+
if (layer?.image_generation)
|
|
650
|
+
merged.image_generation = structuredClone(layer.image_generation);
|
|
399
651
|
if (layer?.experimental) {
|
|
400
652
|
const nextExperimental = layer.experimental;
|
|
401
653
|
merged.experimental ??= {};
|
|
@@ -515,10 +767,15 @@ var ConfigRegistry = class {
|
|
|
515
767
|
};
|
|
516
768
|
var configRegistry = new ConfigRegistry();
|
|
517
769
|
export {
|
|
770
|
+
BUILTIN_PROVIDER_NAMES,
|
|
518
771
|
CONFIG_GROUP_DEFAULT_WRITE_SCOPE,
|
|
519
772
|
CONFIG_VERSION,
|
|
520
773
|
ConfigRegistry,
|
|
774
|
+
OPENAI_CODEX_IMAGE_MODELS,
|
|
775
|
+
OPENAI_IMAGE_MODELS,
|
|
521
776
|
SUBAGENT_MAX_CONCURRENT_LIMIT,
|
|
522
777
|
configRegistry,
|
|
523
|
-
parseConfig
|
|
778
|
+
parseConfig,
|
|
779
|
+
parseImageGenerationConfig,
|
|
780
|
+
parseResponsesProviders
|
|
524
781
|
};
|