Skip to content

Commit f3464f2

Browse files
authored
fix beta model access (#47)
1 parent 9b9de3d commit f3464f2

File tree

9 files changed

+72
-18
lines changed

9 files changed

+72
-18
lines changed

src/core/webview/webviewMessageHandler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,6 +3661,7 @@ ${comment.suggestion}
36613661
})
36623662
}
36633663
break
3664+
36643665
case "fetchBetaModelsRequest": // New handler for beta models
36653666
try {
36663667
const { apiConfiguration } = await provider.getState()
@@ -3681,11 +3682,22 @@ ${comment.suggestion}
36813682
}
36823683

36833684
const url = "https://api.matterai.so/axoncode/betamodels"
3684-
const response = await axios.get<{ enabled: boolean }>(url, { headers })
3685+
const response = await axios.get(url, { headers, timeout: 10000 })
3686+
3687+
// Handle different response formats
3688+
let enabled = false
3689+
if (response.data === true) {
3690+
// API returns boolean true when beta models are enabled
3691+
enabled = true
3692+
} else if (response.data && typeof response.data === "object") {
3693+
// Try different possible field names
3694+
enabled =
3695+
response.data.enabled ?? response.data.betaModelsEnabled ?? response.data.isEnabled ?? false
3696+
}
36853697

36863698
provider.postMessageToWebview({
36873699
type: "betaModelsResponse",
3688-
payload: { success: true, enabled: response.data.enabled },
3700+
payload: { success: true, enabled },
36893701
})
36903702
} catch (error: any) {
36913703
const errorMessage =

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "%extension.displayName%",
44
"description": "%extension.description%",
55
"publisher": "matterai",
6-
"version": "5.3.2",
6+
"version": "5.3.3",
77
"icon": "assets/icons/matterai-ic.png",
88
"galleryBanner": {
99
"color": "#FFFFFF",

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ export type ExtensionState = Pick<
381381
| "reasoningBlockCollapsed"
382382
| "codeReviewSettings"
383383
> & {
384+
betaModelsEnabled?: boolean // kilocode_change: Beta models availability
384385
version: string
385386
clineMessages: ClineMessage[]
386387
currentTaskItem?: HistoryItem

webview-ui/src/App.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,29 @@ const App = () => {
251251
// Tell the extension that we are ready to receive messages.
252252
useEffect(() => vscode.postMessage({ type: "webviewDidLaunch" }), [])
253253

254-
// kilocode_change start: Fetch beta models availability on mount
254+
// kilocode_change start: Fetch beta models availability on mount and when API config changes
255255
useEffect(() => {
256256
if (didHydrateState && apiConfiguration?.kilocodeToken) {
257257
vscode.postMessage({ type: "fetchBetaModelsRequest" })
258258
}
259259
}, [didHydrateState, apiConfiguration?.kilocodeToken])
260260

261+
// Additional effect to refresh beta models when switching between API configurations
262+
useEffect(() => {
263+
if (didHydrateState && apiConfiguration?.kilocodeToken) {
264+
// Add a small delay to ensure the API configuration is fully updated
265+
const timeoutId = setTimeout(() => {
266+
vscode.postMessage({ type: "fetchBetaModelsRequest" })
267+
}, 500)
268+
return () => clearTimeout(timeoutId)
269+
}
270+
}, [
271+
didHydrateState,
272+
apiConfiguration?.kilocodeToken,
273+
apiConfiguration?.apiProvider,
274+
apiConfiguration?.kilocodeOrganizationId,
275+
])
276+
261277
// Initialize source map support for better error reporting
262278
useEffect(() => {
263279
// Initialize source maps for better error reporting in production

webview-ui/src/components/kilocode/hooks/useProviderModels.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export const useProviderModels = (apiConfiguration?: ProviderSettings) => {
309309
chutesApiKey: apiConfiguration?.chutesApiKey,
310310
geminiApiKey: apiConfiguration?.geminiApiKey,
311311
googleGeminiBaseUrl: apiConfiguration?.googleGeminiBaseUrl,
312+
betaModelsEnabled, // kilocode_change: Beta models availability
312313
// kilocode_change end
313314
})
314315

@@ -324,12 +325,12 @@ export const useProviderModels = (apiConfiguration?: ProviderSettings) => {
324325

325326
// kilocode_change start: Filter out axon-code-2-pro if beta models are not enabled
326327
const filteredModels = useMemo(() => {
327-
if (betaModelsEnabled) {
328-
return models
328+
if (!betaModelsEnabled) {
329+
// Filter out axon-code-2-pro when beta models are not enabled
330+
const { "axon-code-2-pro": _, ...rest } = models as ModelRecord
331+
return rest
329332
}
330-
// Filter out axon-code-2-pro when beta models are not enabled
331-
const { "axon-code-2-pro": _, ...rest } = models as ModelRecord
332-
return rest
333+
return models
333334
}, [models, betaModelsEnabled])
334335
// kilocode_change end
335336

webview-ui/src/components/kilocode/settings/providers/KiloCode.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { KiloCodeWrapperProperties } from "../../../../../../src/shared/kilocode
88
import { ModelPicker } from "../../../settings/ModelPicker"
99
import { OrganizationSelector } from "../../common/OrganizationSelector"
1010
import { getKiloCodeBackendSignInUrl } from "../../helpers"
11+
import { useExtensionState } from "@/context/ExtensionStateContext"
12+
import { useMemo } from "react"
13+
import type { ModelRecord } from "@roo/api"
1114

1215
type KiloCodeProps = {
1316
apiConfiguration: ProviderSettings
@@ -35,6 +38,18 @@ export const KiloCode = ({
3538
kilocodeDefaultModel,
3639
}: KiloCodeProps) => {
3740
const { t } = useAppTranslation()
41+
const { betaModelsEnabled } = useExtensionState()
42+
43+
// Filter out axon-code-2-pro if beta models are not enabled
44+
const filteredModels = useMemo(() => {
45+
const models = routerModels?.["kilocode-openrouter"] ?? {}
46+
if (!betaModelsEnabled) {
47+
// Filter out axon-code-2-pro when beta models are not enabled
48+
const { "axon-code-2-pro": _, ...rest } = models as ModelRecord
49+
return rest
50+
}
51+
return models
52+
}, [routerModels, betaModelsEnabled])
3853

3954
// const handleInputChange = useCallback(
4055
// <K extends keyof ProviderSettings, E>(
@@ -111,7 +126,7 @@ export const KiloCode = ({
111126
apiConfiguration={apiConfiguration}
112127
setApiConfigurationField={setApiConfigurationField}
113128
defaultModelId={kilocodeDefaultModel}
114-
models={routerModels?.["kilocode-openrouter"] ?? {}}
129+
models={filteredModels}
115130
modelIdKey="kilocodeModel"
116131
serviceName="Axon Code"
117132
serviceUrl={getAppUrl()}

webview-ui/src/components/ui/hooks/useRouterModels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type RouterModelsQueryKey = {
4646
geminiApiKey?: string
4747
googleGeminiBaseUrl?: string
4848
chutesApiKey?: string
49+
betaModelsEnabled?: boolean // kilocode_change: Beta models availability
4950
// Requesty, Unbound, etc should perhaps also be here, but they already have their own hacks for reloading
5051
}
5152

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
335335
openRouterImageApiKey: "",
336336
kiloCodeImageApiKey: "",
337337
openRouterImageGenerationSelectedModel: "",
338+
betaModelsEnabled: false, // kilocode_change: Default to false
338339
})
339340

340341
const [didHydrateState, setDidHydrateState] = useState(false)
@@ -408,13 +409,20 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
408409
break
409410
}
410411
case "betaModelsResponse": {
411-
if (message.payload && "enabled" in message.payload) {
412-
const betaPayload = message.payload as { enabled?: boolean }
413-
setState((prevState) => ({
414-
...prevState,
415-
betaModelsEnabled: betaPayload.enabled,
416-
}))
417-
}
412+
const payload = message.payload as { enabled?: boolean; success?: boolean }
413+
const enabled = payload?.enabled ?? payload?.success ?? false
414+
415+
setState((prevState) => ({
416+
...prevState,
417+
betaModelsEnabled: !!enabled,
418+
}))
419+
420+
// Flush router models cache to force refresh when beta models status changes
421+
vscode.postMessage({ type: "flushRouterModels", text: "kilocode-openrouter" })
422+
// Add a small delay to ensure cache flush completes before requesting new models
423+
setTimeout(() => {
424+
vscode.postMessage({ type: "requestRouterModels" })
425+
}, 100)
418426
break
419427
}
420428
case "action": {

webview-ui/src/utils/prettyModelName.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const AXON_MODEL_CREDITS: Record<string, string> = {
33
"axon-mini": "(0.5x)",
44
"axon-code": "(0.8x)",
55
"axon-code-2": "(1x)",
6-
"axon-code-2-pro": "(2x)",
6+
"axon-code-2-pro": "(1.5x)",
77
}
88

99
export const prettyModelName = (modelId: string): string => {

0 commit comments

Comments
 (0)