mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 13:00:33 +00:00
perf(coding-agent): cache ModelsConfig validator (#1772)
This commit is contained in:
parent
6f4bd814b8
commit
993d916e56
1 changed files with 4 additions and 2 deletions
|
|
@ -28,6 +28,7 @@ import type { AuthStorage } from "./auth-storage.js";
|
||||||
import { clearConfigValueCache, resolveConfigValue, resolveHeaders } from "./resolve-config-value.js";
|
import { clearConfigValueCache, resolveConfigValue, resolveHeaders } from "./resolve-config-value.js";
|
||||||
|
|
||||||
const Ajv = (AjvModule as any).default || AjvModule;
|
const Ajv = (AjvModule as any).default || AjvModule;
|
||||||
|
const ajv = new Ajv();
|
||||||
|
|
||||||
// Schema for OpenRouter routing preferences
|
// Schema for OpenRouter routing preferences
|
||||||
const OpenRouterRoutingSchema = Type.Object({
|
const OpenRouterRoutingSchema = Type.Object({
|
||||||
|
|
@ -120,6 +121,8 @@ const ModelsConfigSchema = Type.Object({
|
||||||
providers: Type.Record(Type.String(), ProviderConfigSchema),
|
providers: Type.Record(Type.String(), ProviderConfigSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ajv.addSchema(ModelsConfigSchema, "ModelsConfig");
|
||||||
|
|
||||||
type ModelsConfig = Static<typeof ModelsConfigSchema>;
|
type ModelsConfig = Static<typeof ModelsConfigSchema>;
|
||||||
|
|
||||||
/** Provider override config (baseUrl, headers, apiKey) without custom models */
|
/** Provider override config (baseUrl, headers, apiKey) without custom models */
|
||||||
|
|
@ -350,8 +353,7 @@ export class ModelRegistry {
|
||||||
const config: ModelsConfig = JSON.parse(content);
|
const config: ModelsConfig = JSON.parse(content);
|
||||||
|
|
||||||
// Validate schema
|
// Validate schema
|
||||||
const ajv = new Ajv();
|
const validate = ajv.getSchema("ModelsConfig")!;
|
||||||
const validate = ajv.compile(ModelsConfigSchema);
|
|
||||||
if (!validate(config)) {
|
if (!validate(config)) {
|
||||||
const errors =
|
const errors =
|
||||||
validate.errors?.map((e: any) => ` - ${e.instancePath || "root"}: ${e.message}`).join("\n") ||
|
validate.errors?.map((e: any) => ` - ${e.instancePath || "root"}: ${e.message}`).join("\n") ||
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue