refactor: dedupe extension lowercase readers

This commit is contained in:
Peter Steinberger
2026-04-07 11:28:02 +01:00
parent fbf7859f6d
commit b39c7eece6
16 changed files with 64 additions and 37 deletions

View File

@@ -3,6 +3,7 @@ import type {
ProviderRuntimeModel,
} from "openclaw/plugin-sdk/core";
import { normalizeModelCompat } from "openclaw/plugin-sdk/provider-model-shared";
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
export const PROVIDER_ID = "github-copilot";
const CODEX_GPT_54_MODEL_ID = "gpt-5.4";
@@ -14,7 +15,7 @@ const DEFAULT_MAX_TOKENS = 8192;
export function resolveCopilotTransportApi(
modelId: string,
): "anthropic-messages" | "openai-responses" {
return modelId.trim().toLowerCase().includes("claude")
return (normalizeOptionalLowercaseString(modelId) ?? "").includes("claude")
? "anthropic-messages"
: "openai-responses";
}
@@ -28,14 +29,15 @@ export function resolveCopilotForwardCompatModel(
}
// If the model is already in the registry, let the normal path handle it.
const existing = ctx.modelRegistry.find(PROVIDER_ID, trimmedModelId.toLowerCase());
const lowerModelId = normalizeOptionalLowercaseString(trimmedModelId) ?? "";
const existing = ctx.modelRegistry.find(PROVIDER_ID, lowerModelId);
if (existing) {
return undefined;
}
// For gpt-5.4 specifically, clone from the gpt-5.2-codex template
// to preserve any special settings the registry has for codex models.
if (trimmedModelId.toLowerCase() === CODEX_GPT_54_MODEL_ID) {
if (lowerModelId === CODEX_GPT_54_MODEL_ID) {
for (const templateId of CODEX_TEMPLATE_MODEL_IDS) {
const template = ctx.modelRegistry.find(
PROVIDER_ID,
@@ -58,7 +60,6 @@ export function resolveCopilotForwardCompatModel(
// model isn't available on the user's plan. This lets new models be used
// by simply adding them to agents.defaults.models in openclaw.json — no
// code change required.
const lowerModelId = trimmedModelId.toLowerCase();
const reasoning = /^o[13](\b|$)/.test(lowerModelId);
return normalizeModelCompat({
id: trimmedModelId,