mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-29 03:44:06 +08:00
refactor(gateway): pin DEFAULT_AUTOCOMPLETE_MODEL by explicit id
Looking up by provider+model id instead of relying on array index makes the default robust to reordering of the AUTOCOMPLETE_MODELS list, and fails loudly at module load if the referenced entry is ever removed. Adds a test asserting the default resolves to a real entry.
This commit is contained in:
@@ -83,7 +83,20 @@ const models: AutocompleteModelDef[] = [
|
||||
|
||||
export const AUTOCOMPLETE_MODELS: readonly AutocompleteModelDef[] = models
|
||||
|
||||
export const DEFAULT_AUTOCOMPLETE_MODEL: AutocompleteModelDef = models[0]!
|
||||
export const DEFAULT_AUTOCOMPLETE_PROVIDER_ID: AutocompleteProviderID = "kilo"
|
||||
export const DEFAULT_AUTOCOMPLETE_MODEL_ID = "mistralai/codestral-2508"
|
||||
|
||||
export const DEFAULT_AUTOCOMPLETE_MODEL: AutocompleteModelDef = (() => {
|
||||
const found = models.find(
|
||||
(m) => m.providerID === DEFAULT_AUTOCOMPLETE_PROVIDER_ID && m.modelID === DEFAULT_AUTOCOMPLETE_MODEL_ID,
|
||||
)
|
||||
if (!found) {
|
||||
throw new Error(
|
||||
`DEFAULT_AUTOCOMPLETE_MODEL not found: provider=${DEFAULT_AUTOCOMPLETE_PROVIDER_ID} model=${DEFAULT_AUTOCOMPLETE_MODEL_ID}`,
|
||||
)
|
||||
}
|
||||
return found
|
||||
})()
|
||||
|
||||
const aliases: Record<string, string> = {
|
||||
"inception/mercury-edit": "inception/mercury-edit-2",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import {
|
||||
AUTOCOMPLETE_MODELS,
|
||||
DEFAULT_AUTOCOMPLETE_MODEL,
|
||||
DEFAULT_AUTOCOMPLETE_MODEL_ID,
|
||||
DEFAULT_AUTOCOMPLETE_PROVIDER_ID,
|
||||
} from "../src/autocomplete"
|
||||
|
||||
describe("DEFAULT_AUTOCOMPLETE_MODEL", () => {
|
||||
test("resolves to an entry that exists in AUTOCOMPLETE_MODELS", () => {
|
||||
const match = AUTOCOMPLETE_MODELS.find(
|
||||
(m) => m.providerID === DEFAULT_AUTOCOMPLETE_PROVIDER_ID && m.modelID === DEFAULT_AUTOCOMPLETE_MODEL_ID,
|
||||
)
|
||||
expect(match).toBeDefined()
|
||||
expect(DEFAULT_AUTOCOMPLETE_MODEL).toBe(match!)
|
||||
})
|
||||
|
||||
test("points at the expected provider and model", () => {
|
||||
expect(DEFAULT_AUTOCOMPLETE_PROVIDER_ID).toBe("kilo")
|
||||
expect(DEFAULT_AUTOCOMPLETE_MODEL_ID).toBe("mistralai/codestral-2508")
|
||||
expect(DEFAULT_AUTOCOMPLETE_MODEL.providerID).toBe("kilo")
|
||||
expect(DEFAULT_AUTOCOMPLETE_MODEL.modelID).toBe("mistralai/codestral-2508")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user