Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: model config modal confirm spins forever on null config (#20809)

YuTengjingfcbc16a627c1
diff --git a/src/features/Settings/provider/features/ModelList/ModelConfigModal/Footer.tsx b/src/features/Settings/provider/features/ModelList/ModelConfigModal/Footer.tsx
index 8ccd9d52f2d..92c14ef4541 100644
--- a/src/features/Settings/provider/features/ModelList/ModelConfigModal/Footer.tsx
+++ b/src/features/Settings/provider/features/ModelList/ModelConfigModal/Footer.tsx
@@ -1,19 +1,22 @@
'use client';
-import { Button, ModalFooter, useModalContext } from '@lobehub/ui/base-ui';
+import { Button, ModalFooter, toast, useModalContext } from '@lobehub/ui/base-ui';
import { type FormInstance } from '@lobehub/ui/base-ui/form';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useAiInfraStore } from '@/store/aiInfra';
+import { pickModelConfigFormValues } from './utils';
+
interface ModelConfigFooterProps {
formRef: { current?: FormInstance };
id: string;
+ showDeployName?: boolean;
}
-const ModelConfigFooter = memo<ModelConfigFooterProps>(({ formRef, id }) => {
- const { t } = useTranslation('common');
+const ModelConfigFooter = memo<ModelConfigFooterProps>(({ formRef, id, showDeployName }) => {
+ const { t } = useTranslation(['common', 'error']);
const { close } = useModalContext();
const [loading, setLoading] = useState(false);
const [editingProvider, updateAiModelsConfig] = useAiInfraStore((s) => [
@@ -23,23 +26,28 @@ const ModelConfigFooter = memo<ModelConfigFooterProps>(({ formRef, id }) => {
return (
<ModalFooter>
- <Button onClick={close}>{t('cancel')}</Button>
+ <Button onClick={close}>{t('cancel', { ns: 'common' })}</Button>
<Button
loading={loading}
type="primary"
onClick={async () => {
const form = formRef.current;
if (!editingProvider || !id || !form) return;
- const data = form.getValues();
+ const data = pickModelConfigFormValues(form.getValues(), { showDeployName });
setLoading(true);
- await updateAiModelsConfig(id, editingProvider, data);
- setLoading(false);
-
- close();
+ try {
+ await updateAiModelsConfig(id, editingProvider, data);
+ close();
+ } catch (error) {
+ console.error(error);
+ toast.error(t('saveState.saveFailed', { ns: 'error' }));
+ } finally {
+ setLoading(false);
+ }
}}
>
- {t('ok')}
+ {t('ok', { ns: 'common' })}
</Button>
</ModalFooter>
);
diff --git a/src/features/Settings/provider/features/ModelList/ModelConfigModal/__tests__/utils.test.ts b/src/features/Settings/provider/features/ModelList/ModelConfigModal/__tests__/utils.test.ts
new file mode 100644
index 00000000000..fbe51cafe41
--- /dev/null
+++ b/src/features/Settings/provider/features/ModelList/ModelConfigModal/__tests__/utils.test.ts
@@ -0,0 +1,63 @@
+import { UpdateAiModelSchema } from 'model-bank';
+import { describe, expect, it } from 'vitest';
+
+import { pickModelConfigFormValues } from '../utils';
+
+// Shape of a merged model list item used as the form's initial values: a custom model row
+// whose `config` column is NULL, plus builtin-only settings.
+const formValues = {
+ abilities: { functionCall: true, vision: false },
+ config: null,
+ contextWindowTokens: 128_000,
+ displayName: 'My Model',
+ enabled: true,
+ id: 'my-model',
+ settings: { extendParams: ['enableReasoning'], searchImpl: 'params' },
+ source: 'custom',
+ type: 'chat',
+};
+
+describe('pickModelConfigFormValues', () => {
+ it('produces a payload accepted by UpdateAiModelSchema when config is null', () => {
+ // The raw form values are what base-ui getValues() returns and the server rejects
+ expect(UpdateAiModelSchema.safeParse(formValues).success).toBe(false);
+
+ const payload = pickModelConfigFormValues(formValues);
+
+ expect(UpdateAiModelSchema.safeParse(payload).success).toBe(true);
+ expect(payload.config).toBeUndefined();
+ });
+
+ it('keeps only the fields rendered by the form', () => {
+ expect(pickModelConfigFormValues(formValues)).toEqual({
+ abilities: {
+ functionCall: true,
+ imageOutput: undefined,
+ reasoning: undefined,
+ search: undefined,
+ video: undefined,
+ vision: false,
+ },
+ config: undefined,
+ contextWindowTokens: 128_000,
+ displayName: 'My Model',
+ settings: { extendParams: ['enableReasoning'] },
+ type: 'chat',
+ });
+ });
+
+ it('submits the deployment name only when the field is shown', () => {
+ const values = { ...formValues, config: { chatConfig: {}, deploymentName: 'gpt-4o-prod' } };
+
+ expect(pickModelConfigFormValues(values, { showDeployName: true }).config).toEqual({
+ deploymentName: 'gpt-4o-prod',
+ });
+ expect(pickModelConfigFormValues(values).config).toBeUndefined();
+ });
+
+ it('accepts a null deployment config when the field is shown', () => {
+ const payload = pickModelConfigFormValues(formValues, { showDeployName: true });
+
+ expect(UpdateAiModelSchema.safeParse(payload).success).toBe(true);
+ });
+});
diff --git a/src/features/Settings/provider/features/ModelList/ModelConfigModal/index.tsx b/src/features/Settings/provider/features/ModelList/ModelConfigModal/index.tsx
index 0a4ad1e994b..7cfef0cd80a 100644
--- a/src/features/Settings/provider/features/ModelList/ModelConfigModal/index.tsx
+++ b/src/features/Settings/provider/features/ModelList/ModelConfigModal/index.tsx
@@ -25,7 +25,13 @@ export const createModelConfigModal = (options: ModelConfigModalOptions): ModalI
}}
/>
),
- footer: <ModelConfigFooter formRef={formRef} id={options.id} />,
+ footer: (
+ <ModelConfigFooter
+ formRef={formRef}
+ id={options.id}
+ showDeployName={options.showDeployName}
+ />
+ ),
maskClosable: true,
title: t('llm.customModelCards.modelConfig.modalTitle', { ns: 'setting' }),
width: 'min(90vw, 640px)',
diff --git a/src/features/Settings/provider/features/ModelList/ModelConfigModal/utils.ts b/src/features/Settings/provider/features/ModelList/ModelConfigModal/utils.ts
new file mode 100644
index 00000000000..c95df7c6b59
--- /dev/null
+++ b/src/features/Settings/provider/features/ModelList/ModelConfigModal/utils.ts
@@ -0,0 +1,45 @@
+import type { FormValues } from '@lobehub/ui/base-ui/form';
+import type { UpdateAiModelParams } from 'model-bank';
+
+const EDITABLE_ABILITIES = [
+ 'functionCall',
+ 'vision',
+ 'reasoning',
+ 'search',
+ 'imageOutput',
+ 'video',
+] as const;
+
+/**
+ * Pick only the fields rendered by the model config form.
+ *
+ * base-ui `form.getValues()` returns every initial value, not just the registered fields
+ * like antd `getFieldsValue()` did. The initial values are the merged model list item, so
+ * they carry columns such as `config: null` (rejected by `UpdateAiModelSchema`, leaving the
+ * confirm button spinning forever) and builtin-only settings that must not be persisted.
+ */
+export const pickModelConfigFormValues = (
+ values: FormValues,
+ { showDeployName }: { showDeployName?: boolean } = {},
+): UpdateAiModelParams => {
+ const abilities = (values.abilities ?? {}) as Record<string, unknown>;
+ const settings = (values.settings ?? {}) as Record<string, unknown>;
+ const config = (values.config ?? {}) as Record<string, unknown>;
+
+ return {
+ abilities: Object.fromEntries(
+ EDITABLE_ABILITIES.map((key) => [key, abilities[key] ?? undefined]),
+ ) as UpdateAiModelParams['abilities'],
+ config: showDeployName
+ ? { deploymentName: (config.deploymentName as string | undefined) ?? undefined }
+ : undefined,
+ contextWindowTokens: values.contextWindowTokens as number | null | undefined,
+ displayName: values.displayName as string | null | undefined,
+ settings: {
+ extendParams: (settings.extendParams ?? undefined) as NonNullable<
+ UpdateAiModelParams['settings']
+ >['extendParams'],
+ },
+ type: values.type as UpdateAiModelParams['type'],
+ };
+};
diff --git a/src/store/aiInfra/slices/aiModel/action.ts b/src/store/aiInfra/slices/aiModel/action.ts
index 46246fcd809..471237eeabc 100644
--- a/src/store/aiInfra/slices/aiModel/action.ts
+++ b/src/store/aiInfra/slices/aiModel/action.ts
@@ -7,6 +7,7 @@ import type {
AiProviderModelListItem,
CreateAiModelParams,
ToggleAiModelEnableParams,
+ UpdateAiModelParams,
} from 'model-bank';
import type { SWRResponse } from 'swr';
@@ -349,7 +350,7 @@ export class AiModelActionImpl {
updateAiModelsConfig = async (
id: string,
providerId: string,
- data: Partial<AiProviderModelListItem>,
+ data: UpdateAiModelParams,
): Promise<void> => {
await aiModelService.updateAiModel(id, providerId, data);
await this.#get().refreshAiModelList();