1- import { useCallback , useState , useMemo } from "react"
1+ import { useCallback , useState , useMemo , useEffect } from "react"
22import { useEvent } from "react-use"
33import { Trans } from "react-i18next"
44import { Checkbox } from "vscrui"
@@ -9,6 +9,7 @@ import type { ProviderSettings } from "@roo-code/types"
99import { useAppTranslation } from "@src/i18n/TranslationContext"
1010import { ExtensionMessage } from "@roo/ExtensionMessage"
1111import { useRouterModels } from "@src/components/ui/hooks/useRouterModels"
12+ import { vscode } from "@src/utils/vscode"
1213
1314import { inputEventTransform } from "../transforms"
1415
@@ -49,6 +50,21 @@ export const LMStudio = ({ apiConfiguration, setApiConfigurationField }: LMStudi
4950
5051 useEvent ( "message" , onMessage )
5152
53+ // Refresh models on mount
54+ useEffect ( ( ) => {
55+ // Request fresh models without flushing first
56+ // This ensures cached models remain visible while new ones load
57+ vscode . postMessage ( { type : "requestRouterModels" } )
58+
59+ // Optionally flush cache after a delay to ensure fresh data on next load
60+ // This won't affect the current session since models are already being fetched
61+ const timer = setTimeout ( ( ) => {
62+ vscode . postMessage ( { type : "flushRouterModels" , text : "lmstudio" } )
63+ } , 1000 )
64+
65+ return ( ) => clearTimeout ( timer )
66+ } , [ ] )
67+
5268 // Check if the selected model exists in the fetched models
5369 const modelNotAvailable = useMemo ( ( ) => {
5470 const selectedModel = apiConfiguration ?. lmStudioModelId
0 commit comments