From a80bb413fee990348bcb550ee0f6b0469c4e95f5 Mon Sep 17 00:00:00 2001 From: mrhan <1309443685@qq.com> Date: Mon, 5 Jan 2026 19:27:20 +0800 Subject: [PATCH] fix: #156 --- src/lib/utils.ts | 9 ++++----- src/routes/messages/non-stream-translation.ts | 14 ++++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index cc80be66..641da9a9 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,9 +1,9 @@ import consola from "consola" -import { getModels } from "~/services/copilot/get-models" -import { getVSCodeVersion } from "~/services/get-vscode-version" +import {getModels} from "~/services/copilot/get-models" +import {getVSCodeVersion} from "~/services/get-vscode-version" -import { state } from "./state" +import {state} from "./state" export const sleep = (ms: number) => new Promise((resolve) => { @@ -14,8 +14,7 @@ export const isNullish = (value: unknown): value is null | undefined => value === null || value === undefined export async function cacheModels(): Promise { - const models = await getModels() - state.models = models + state.models = await getModels() } export const cacheVSCodeVersion = async () => { diff --git a/src/routes/messages/non-stream-translation.ts b/src/routes/messages/non-stream-translation.ts index dc41e638..69502242 100644 --- a/src/routes/messages/non-stream-translation.ts +++ b/src/routes/messages/non-stream-translation.ts @@ -1,3 +1,5 @@ +import consola from "consola" + import { type ChatCompletionResponse, type ChatCompletionsPayload, @@ -48,11 +50,15 @@ export function translateToOpenAI( function translateModelName(model: string): string { // Subagent requests use a specific model number which Copilot doesn't support - if (model.startsWith("claude-sonnet-4-")) { - return model.replace(/^claude-sonnet-4-.*/, "claude-sonnet-4") - } else if (model.startsWith("claude-opus-")) { - return model.replace(/^claude-opus-4-.*/, "claude-opus-4") + if (model.startsWith("claude")) { + const newModel = model.replaceAll( + /(claude-(?:haiku|sonnet|opus)-\d+)-(\d+)(?:[.-]\d+)?/g, + "$1.$2", + ) + consola.log("Use Model:", model, newModel) + return newModel } + consola.log("Use Model:", model) return model }