Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -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"
Comment on lines +3 to +6
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement formatting is inconsistent with the rest of the codebase. The project uses spaces around braces in imports (e.g., import { getModels } rather than import {getModels}). For example, see the consistent pattern in files like src/auth.ts, src/routes/chat-completions/handler.ts, and many others. This inconsistency will likely be flagged by the linter.

Copilot uses AI. Check for mistakes.

export const sleep = (ms: number) =>
new Promise((resolve) => {
Expand All @@ -14,8 +14,7 @@ export const isNullish = (value: unknown): value is null | undefined =>
value === null || value === undefined

export async function cacheModels(): Promise<void> {
const models = await getModels()
state.models = models
state.models = await getModels()
}

export const cacheVSCodeVersion = async () => {
Expand Down
14 changes: 10 additions & 4 deletions src/routes/messages/non-stream-translation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import consola from "consola"

import {
type ChatCompletionResponse,
type ChatCompletionsPayload,
Expand Down Expand Up @@ -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,
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern does not match the actual Anthropic Claude model naming format. Anthropic models use the format claude-{version}-{variant}-{date} (e.g., claude-3-5-sonnet-20241022), but this regex expects claude-{variant}-{version}-{date} format.

The pattern /(claude-(?:haiku|sonnet|opus)-\d+)-(\d+)(?:[.-]\d+)?/g would match something like claude-sonnet-4-20250115 but not claude-3-5-sonnet-20241022. This means the regex will not transform most Claude model names as intended, causing them to pass through unchanged when they should be transformed.

Consider updating the regex to match the actual Anthropic model format, or verify what specific model names from Claude Code need to be transformed.

Suggested change
/(claude-(?:haiku|sonnet|opus)-\d+)-(\d+)(?:[.-]\d+)?/g,
/(claude-\d+(?:-\d+)?-(?:haiku|sonnet|opus))-(\d{8})(?:[.-]\d+)?/g,

Copilot uses AI. Check for mistakes.
"$1.$2",
)
consola.log("Use Model:", model, newModel)
return newModel
Comment on lines +54 to +59
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new model name translation logic lacks test coverage. Given that this PR aims to fix a 400 error with Claude model names, tests should be added to verify that the regex correctly transforms various Claude model name formats (e.g., claude-sonnet-4-20250115 to claude-sonnet-4.20250115). Tests should also verify that models not matching the pattern are passed through unchanged. Consider adding tests in tests/anthropic-request.test.ts that specifically test the translateModelName function with various input formats.

Copilot uses AI. Check for mistakes.
}
consola.log("Use Model:", model)
Comment on lines +58 to +61
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These log statements will be emitted on every request, which could create excessive noise in production logs. Consider using a debug-level log (e.g., consola.debug) instead of consola.log, or removing these logs entirely once the feature is stable. Production logs should typically be reserved for errors, warnings, and important informational messages rather than routine processing details.

Suggested change
consola.log("Use Model:", model, newModel)
return newModel
}
consola.log("Use Model:", model)
consola.debug("Use Model:", model, newModel)
return newModel
}
consola.debug("Use Model:", model)

Copilot uses AI. Check for mistakes.
return model
}

Expand Down