From 88ac92f3a165ac5953643df515aaf6e9acf39f2f Mon Sep 17 00:00:00 2001 From: Rin Date: Sun, 8 Mar 2026 18:41:43 +0800 Subject: [PATCH] fix(stage-ui): fix LM studio validation problem and add CORS note (#1175) --- .../src/libs/providers/providers/lm-studio/index.ts | 8 +++++--- .../src/libs/providers/validators/openai-compatible.ts | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/stage-ui/src/libs/providers/providers/lm-studio/index.ts b/packages/stage-ui/src/libs/providers/providers/lm-studio/index.ts index dee928105..776d0ccd4 100644 --- a/packages/stage-ui/src/libs/providers/providers/lm-studio/index.ts +++ b/packages/stage-ui/src/libs/providers/providers/lm-studio/index.ts @@ -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({ }, 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'.`, }), diff --git a/packages/stage-ui/src/libs/providers/validators/openai-compatible.ts b/packages/stage-ui/src/libs/providers/validators/openai-compatible.ts index b635e01a3..8079f3ba0 100644 --- a/packages/stage-ui/src/libs/providers/validators/openai-compatible.ts +++ b/packages/stage-ui/src/libs/providers/validators/openai-compatible.ts @@ -19,6 +19,7 @@ interface OpenAICompatibleValidationOptions string modelListFailureReason?: (input: { config: TConfig, error: unknown, errorMessage: string }) => string } @@ -211,7 +212,7 @@ export function createOpenAICompatibleValidators