1- import { useCallback , useState } from "react"
1+ import { useCallback , useState , useMemo } from "react"
22import { useEvent } from "react-use"
33import { Trans } from "react-i18next"
44import { Checkbox } from "vscrui"
@@ -8,6 +8,7 @@ import type { ProviderSettings } from "@roo-code/types"
88
99import { useAppTranslation } from "@src/i18n/TranslationContext"
1010import { ExtensionMessage } from "@roo/ExtensionMessage"
11+ import { useRouterModels } from "@src/components/ui/hooks/useRouterModels"
1112
1213import { inputEventTransform } from "../transforms"
1314
@@ -20,6 +21,7 @@ export const LMStudio = ({ apiConfiguration, setApiConfigurationField }: LMStudi
2021 const { t } = useAppTranslation ( )
2122
2223 const [ lmStudioModels , setLmStudioModels ] = useState < string [ ] > ( [ ] )
24+ const routerModels = useRouterModels ( )
2325
2426 const handleInputChange = useCallback (
2527 < K extends keyof ProviderSettings , E > (
@@ -47,6 +49,48 @@ export const LMStudio = ({ apiConfiguration, setApiConfigurationField }: LMStudi
4749
4850 useEvent ( "message" , onMessage )
4951
52+ // Check if the selected model exists in the fetched models
53+ const modelNotAvailable = useMemo ( ( ) => {
54+ const selectedModel = apiConfiguration ?. lmStudioModelId
55+ if ( ! selectedModel ) return false
56+
57+ // Check if model exists in local LM Studio models
58+ if ( lmStudioModels . length > 0 && lmStudioModels . includes ( selectedModel ) ) {
59+ return false // Model is available locally
60+ }
61+
62+ // If we have router models data for LM Studio
63+ if ( routerModels . data ?. lmstudio ) {
64+ const availableModels = Object . keys ( routerModels . data . lmstudio )
65+ // Show warning if model is not in the list (regardless of how many models there are)
66+ return ! availableModels . includes ( selectedModel )
67+ }
68+
69+ // If neither source has loaded yet, don't show warning
70+ return false
71+ } , [ apiConfiguration ?. lmStudioModelId , routerModels . data , lmStudioModels ] )
72+
73+ // Check if the draft model exists
74+ const draftModelNotAvailable = useMemo ( ( ) => {
75+ const draftModel = apiConfiguration ?. lmStudioDraftModelId
76+ if ( ! draftModel ) return false
77+
78+ // Check if model exists in local LM Studio models
79+ if ( lmStudioModels . length > 0 && lmStudioModels . includes ( draftModel ) ) {
80+ return false // Model is available locally
81+ }
82+
83+ // If we have router models data for LM Studio
84+ if ( routerModels . data ?. lmstudio ) {
85+ const availableModels = Object . keys ( routerModels . data . lmstudio )
86+ // Show warning if model is not in the list (regardless of how many models there are)
87+ return ! availableModels . includes ( draftModel )
88+ }
89+
90+ // If neither source has loaded yet, don't show warning
91+ return false
92+ } , [ apiConfiguration ?. lmStudioDraftModelId , routerModels . data , lmStudioModels ] )
93+
5094 return (
5195 < >
5296 < VSCodeTextField
@@ -64,6 +108,16 @@ export const LMStudio = ({ apiConfiguration, setApiConfigurationField }: LMStudi
64108 className = "w-full" >
65109 < label className = "block font-medium mb-1" > { t ( "settings:providers.lmStudio.modelId" ) } </ label >
66110 </ VSCodeTextField >
111+ { modelNotAvailable && (
112+ < div className = "flex flex-col gap-2 text-vscode-errorForeground text-sm" >
113+ < div className = "flex flex-row items-center gap-1" >
114+ < div className = "codicon codicon-close" />
115+ < div >
116+ { t ( "settings:validation.modelAvailability" , { modelId : apiConfiguration ?. lmStudioModelId } ) }
117+ </ div >
118+ </ div >
119+ </ div >
120+ ) }
67121 { lmStudioModels . length > 0 && (
68122 < VSCodeRadioGroup
69123 value = {
@@ -101,6 +155,18 @@ export const LMStudio = ({ apiConfiguration, setApiConfigurationField }: LMStudi
101155 < div className = "text-sm text-vscode-descriptionForeground" >
102156 { t ( "settings:providers.lmStudio.draftModelDesc" ) }
103157 </ div >
158+ { draftModelNotAvailable && (
159+ < div className = "flex flex-col gap-2 text-vscode-errorForeground text-sm mt-2" >
160+ < div className = "flex flex-row items-center gap-1" >
161+ < div className = "codicon codicon-close" />
162+ < div >
163+ { t ( "settings:validation.modelAvailability" , {
164+ modelId : apiConfiguration ?. lmStudioDraftModelId ,
165+ } ) }
166+ </ div >
167+ </ div >
168+ </ div >
169+ ) }
104170 </ div >
105171 { lmStudioModels . length > 0 && (
106172 < >
0 commit comments