fix(stage-ui): fix LM studio validation problem and add CORS note (#1175)

This commit is contained in:
Rin
2026-03-08 18:41:43 +08:00
committed by GitHub
parent 7b11d1e0bd
commit 88ac92f3a1
2 changed files with 7 additions and 4 deletions
@@ -6,7 +6,8 @@ import { defineProvider } from '../registry'
const lmStudioConfigSchema = z.object({
apiKey: z
.string('API Key'),
.string('API Key')
.optional(),
baseUrl: z
.string('Base URL')
.optional()
@@ -48,17 +49,18 @@ export const providerLmStudio = defineProvider<LMStudioConfig>({
},
validationRequiredWhen(config) {
return !!config.apiKey?.trim()
return !!config.baseUrl?.trim()
},
validators: {
...createOpenAICompatibleValidators({
checks: ['connectivity', 'model_list'],
skipApiKeyCheck: true,
schedule: {
mode: 'interval',
intervalMs: 15_000,
},
connectivityFailureReason: ({ errorMessage }) =>
`Failed to reach LM Studio server, error: ${errorMessage} occurred.\n\nMake sure LM Studio is running and the local server is started. You can start the local server in LM Studio by going to the 'Local Server' tab and clicking 'Start Server'.`,
`Failed to reach LM Studio server, error: ${errorMessage} occurred.\n\nMake sure LM Studio is running and the local server is started. You can start the local server in LM Studio by going to the 'Local Server' tab and clicking 'Start Server'.\n\nIf the LM Studio instance is already running, this is likely a CORS (Cross-Origin Resource Sharing) issue. You need to enable CORS in LM Studio: go to 'Local Server' tab and check 'Enable CORS' option in the Server Settings.`,
modelListFailureReason: ({ errorMessage }) =>
`Failed to reach LM Studio server, error: ${errorMessage} occurred.\n\nMake sure LM Studio is running and the local server is started. You can start the local server in LM Studio by going to the 'Local Server' tab and clicking 'Start Server'.`,
}),
@@ -19,6 +19,7 @@ interface OpenAICompatibleValidationOptions<TConfig extends { apiKey?: string, b
mode: 'once' | 'interval'
intervalMs?: number
}
skipApiKeyCheck?: boolean
connectivityFailureReason?: (input: { config: TConfig, error: unknown, errorMessage: string }) => string
modelListFailureReason?: (input: { config: TConfig, error: unknown, errorMessage: string }) => string
}
@@ -211,7 +212,7 @@ export function createOpenAICompatibleValidators<TConfig extends { apiKey?: stri
const apiKey = typeof config.apiKey === 'string' ? config.apiKey.trim() : ''
const baseUrl = (config.baseUrl as string | URL | undefined) instanceof URL ? config.baseUrl?.toString() : (typeof config.baseUrl === 'string' ? config.baseUrl.trim() : '')
if (!apiKey)
if (!options?.skipApiKeyCheck && !apiKey)
errors.push({ error: new Error('API key is required.') })
if (!baseUrl)
errors.push({ error: new Error('Base URL is required.') })