Skip to content

Commit 5973132

Browse files
committed
backfill; remove old object-based map; rename to old name
1 parent 47ac679 commit 5973132

File tree

4 files changed

+21
-41
lines changed

4 files changed

+21
-41
lines changed

src/services/ghost/GhostModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ApiHandler, buildApiHandler } from "../../api"
33
import { ProviderSettingsManager } from "../../core/config/ProviderSettingsManager"
44
import { OpenRouterHandler } from "../../api/providers"
55
import { ApiStreamChunk } from "../../api/transform/stream"
6-
import { AUTOCOMPLETE_PROVIDER_MAP, AUTOCOMPLETE_PROVIDER_MODELS, checkKilocodeBalance } from "./utils/kilocode-utils"
6+
import { AUTOCOMPLETE_PROVIDER_MODELS, checkKilocodeBalance } from "./utils/kilocode-utils"
77

88
export class GhostModel {
99
private apiHandler: ApiHandler | null = null
@@ -26,7 +26,7 @@ export class GhostModel {
2626
this.cleanup()
2727

2828
// Check providers in order, but skip unusable ones (e.g., kilocode with zero balance)
29-
for (const [provider, model] of AUTOCOMPLETE_PROVIDER_MAP) {
29+
for (const [provider, model] of AUTOCOMPLETE_PROVIDER_MODELS) {
3030
const selectedProfile = profiles.find((x) => x?.apiProvider === provider)
3131
if (!selectedProfile) continue
3232
const profile = await providerSettingsManager.getProfile({ id: selectedProfile.id })

src/services/ghost/__tests__/GhostModel.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("GhostModel", () => {
1515

1616
describe("reload", () => {
1717
it("sorts profiles by supportedProviders index order", async () => {
18-
const supportedProviders = Object.keys(AUTOCOMPLETE_PROVIDER_MODELS)
18+
const supportedProviders = [...AUTOCOMPLETE_PROVIDER_MODELS.keys()]
1919
const profiles = [
2020
{ id: "3", name: "profile3", apiProvider: supportedProviders[2] },
2121
{ id: "1", name: "profile1", apiProvider: supportedProviders[0] },
@@ -37,7 +37,7 @@ describe("GhostModel", () => {
3737
})
3838

3939
it("filters out profiles without apiProvider", async () => {
40-
const supportedProviders = Object.keys(AUTOCOMPLETE_PROVIDER_MODELS)
40+
const supportedProviders = [...AUTOCOMPLETE_PROVIDER_MODELS.keys()]
4141
const profiles = [
4242
{ id: "1", name: "profile1", apiProvider: undefined },
4343
{ id: "2", name: "profile2", apiProvider: supportedProviders[0] },
@@ -58,7 +58,7 @@ describe("GhostModel", () => {
5858
})
5959

6060
it("filters out profiles with unsupported apiProvider", async () => {
61-
const supportedProviders = Object.keys(AUTOCOMPLETE_PROVIDER_MODELS)
61+
const supportedProviders = [...AUTOCOMPLETE_PROVIDER_MODELS.keys()]
6262
const profiles = [
6363
{ id: "1", name: "profile1", apiProvider: "unsupported" },
6464
{ id: "2", name: "profile2", apiProvider: supportedProviders[0] },
@@ -90,7 +90,7 @@ describe("GhostModel", () => {
9090
})
9191

9292
it("returns true when profile found", async () => {
93-
const supportedProviders = Object.keys(AUTOCOMPLETE_PROVIDER_MODELS)
93+
const supportedProviders = [...AUTOCOMPLETE_PROVIDER_MODELS.keys()]
9494
const profiles = [{ id: "1", name: "profile1", apiProvider: supportedProviders[0] }] as any
9595

9696
vi.mocked(mockProviderSettingsManager.listConfig).mockResolvedValue(profiles)
@@ -303,7 +303,7 @@ describe("GhostModel", () => {
303303
})
304304

305305
it("returns provider name from API handler when provider is loaded", async () => {
306-
const supportedProviders = Object.keys(AUTOCOMPLETE_PROVIDER_MODELS)
306+
const supportedProviders = [...AUTOCOMPLETE_PROVIDER_MODELS.keys()]
307307
const profiles = [{ id: "1", name: "profile1", apiProvider: supportedProviders[0] }] as any
308308

309309
vi.mocked(mockProviderSettingsManager.listConfig).mockResolvedValue(profiles)

src/services/ghost/new-auto-complete/NewAutocompleteModel.ts

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,50 +34,33 @@ export class NewAutocompleteModel {
3434

3535
public async reload(providerSettingsManager: ProviderSettingsManager): Promise<boolean> {
3636
const profiles = await providerSettingsManager.listConfig()
37-
const supportedProviders = Object.keys(AUTOCOMPLETE_PROVIDER_MODELS) as Array<
38-
keyof typeof AUTOCOMPLETE_PROVIDER_MODELS
39-
>
4037

4138
this.cleanup()
4239

4340
// Check providers in order, but skip unusable ones (e.g., kilocode with zero balance)
44-
for (const provider of supportedProviders) {
41+
for (const [provider, model] of AUTOCOMPLETE_PROVIDER_MODELS) {
4542
const selectedProfile = profiles.find((x) => x?.apiProvider === provider)
4643
if (!selectedProfile) continue
44+
const profile = await providerSettingsManager.getProfile({ id: selectedProfile.id })
4745

4846
if (provider === "kilocode") {
4947
// For all other providers, assume they are usable
50-
const profile = await providerSettingsManager.getProfile({ id: selectedProfile.id })
5148
if (!profile.kilocodeToken) continue
5249
if (!(await checkKilocodeBalance(profile.kilocodeToken, profile.kilocodeOrganizationId))) continue
5350
}
5451

55-
this.loadProfile(providerSettingsManager, selectedProfile, provider)
52+
this.apiHandler = buildApiHandler({ ...profile, [modelIdKeysByProvider[provider]]: model })
53+
54+
if (this.apiHandler instanceof OpenRouterHandler) {
55+
await this.apiHandler.fetchModel()
56+
}
5657
this.loaded = true
5758
return true
5859
}
5960

6061
this.loaded = true // we loaded, and found nothing, but we do not wish to reload
6162
return false
6263
}
63-
public async loadProfile(
64-
providerSettingsManager: ProviderSettingsManager,
65-
selectedProfile: ProviderSettingsEntry,
66-
provider: keyof typeof AUTOCOMPLETE_PROVIDER_MODELS,
67-
): Promise<void> {
68-
this.profile = await providerSettingsManager.getProfile({
69-
id: selectedProfile.id,
70-
})
71-
72-
this.apiHandler = buildApiHandler({
73-
...this.profile,
74-
[modelIdKeysByProvider[provider]]: AUTOCOMPLETE_PROVIDER_MODELS[provider],
75-
})
76-
77-
if (this.apiHandler instanceof OpenRouterHandler) {
78-
await this.apiHandler.fetchModel()
79-
}
80-
}
8164

8265
/**
8366
* Creates an ILLM-compatible instance from provider settings for autocomplete.
@@ -147,7 +130,11 @@ export class NewAutocompleteModel {
147130
}
148131

149132
const provider = this.profile.apiProvider as AutocompleteProviderKey
150-
const model = AUTOCOMPLETE_PROVIDER_MODELS[provider]
133+
const model = AUTOCOMPLETE_PROVIDER_MODELS.get(provider)
134+
if (!model) {
135+
console.warn(`[NewAutocompleteModel] Unsupported provider: ${provider}`)
136+
return null
137+
}
151138

152139
switch (provider) {
153140
case "mistral":

src/services/ghost/utils/kilocode-utils.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,10 @@ export async function checkKilocodeBalance(kilocodeToken: string, kilocodeOrgani
3636
}
3737
}
3838

39-
export const AUTOCOMPLETE_PROVIDER_MODELS = {
40-
mistral: "codestral-latest",
41-
kilocode: "mistralai/codestral-2508",
42-
openrouter: "mistralai/codestral-2508",
43-
bedrock: "mistral.codestral-2508-v1:0",
44-
} as const
45-
export type AutocompleteProviderKey = keyof typeof AUTOCOMPLETE_PROVIDER_MODELS
46-
export const AUTOCOMPLETE_PROVIDER_MAP = new Map([
39+
export const AUTOCOMPLETE_PROVIDER_MODELS = new Map([
4740
["mistral", "codestral-latest"],
4841
["kilocode", "mistralai/codestral-2508"],
4942
["openrouter", "mistralai/codestral-2508"],
5043
["bedrock", "mistral.codestral-2508-v1:0"],
5144
] as const)
52-
export type AutocompleteProviderKey2 = typeof AUTOCOMPLETE_PROVIDER_MAP extends Map<infer K, any> ? K : never
45+
export type AutocompleteProviderKey = typeof AUTOCOMPLETE_PROVIDER_MODELS extends Map<infer K, any> ? K : never

0 commit comments

Comments
 (0)