From 344f54b84d436e9d35071f8c598b005765c662d8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 26 Feb 2026 20:00:11 +0100 Subject: [PATCH] refactor(config): dedupe model api definitions --- src/commands/onboard-auth.test.ts | 3 ++- src/config/types.models.ts | 21 ++++++++++++--------- src/config/zod-schema.core.ts | 12 ++---------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/commands/onboard-auth.test.ts b/src/commands/onboard-auth.test.ts index 5b671cbed5d..65c886b2926 100644 --- a/src/commands/onboard-auth.test.ts +++ b/src/commands/onboard-auth.test.ts @@ -8,6 +8,7 @@ import { resolveAgentModelFallbackValues, resolveAgentModelPrimaryValue, } from "../config/model-input.js"; +import type { ModelApi } from "../config/types.models.js"; import { applyAuthProfileConfig, applyLitellmProviderConfig, @@ -45,7 +46,7 @@ import { function createLegacyProviderConfig(params: { providerId: string; - api: "anthropic-messages" | "openai-completions" | "openai-responses"; + api: ModelApi; modelId?: string; modelName?: string; baseUrl?: string; diff --git a/src/config/types.models.ts b/src/config/types.models.ts index b367553982f..252e635e856 100644 --- a/src/config/types.models.ts +++ b/src/config/types.models.ts @@ -1,14 +1,17 @@ import type { SecretInput } from "./types.secrets.js"; -export type ModelApi = - | "openai-completions" - | "openai-responses" - | "openai-codex-responses" - | "anthropic-messages" - | "google-generative-ai" - | "github-copilot" - | "bedrock-converse-stream" - | "ollama"; +export const MODEL_APIS = [ + "openai-completions", + "openai-responses", + "openai-codex-responses", + "anthropic-messages", + "google-generative-ai", + "github-copilot", + "bedrock-converse-stream", + "ollama", +] as const; + +export type ModelApi = (typeof MODEL_APIS)[number]; export type ModelCompatConfig = { supportsStore?: boolean; diff --git a/src/config/zod-schema.core.ts b/src/config/zod-schema.core.ts index 70396b3109e..201efe4aa96 100644 --- a/src/config/zod-schema.core.ts +++ b/src/config/zod-schema.core.ts @@ -2,6 +2,7 @@ import path from "node:path"; import { z } from "zod"; import { isSafeExecutableValue } from "../infra/exec-safety.js"; import { isValidFileSecretRefId } from "../secrets/ref-contract.js"; +import { MODEL_APIS } from "./types.models.js"; import { createAllowDenyChannelRulesSchema } from "./zod-schema.allowdeny.js"; import { sensitive } from "./zod-schema.sensitive.js"; @@ -179,16 +180,7 @@ export const SecretsConfigSchema = z .strict() .optional(); -export const ModelApiSchema = z.union([ - z.literal("openai-completions"), - z.literal("openai-responses"), - z.literal("openai-codex-responses"), - z.literal("anthropic-messages"), - z.literal("google-generative-ai"), - z.literal("github-copilot"), - z.literal("bedrock-converse-stream"), - z.literal("ollama"), -]); +export const ModelApiSchema = z.enum(MODEL_APIS); export const ModelCompatSchema = z .object({