Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

feat(web): save model instances per card instead of a batch button (#21708)

chanxcad315557f30
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 2b635fe247..79b41db58d 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -2467,6 +2467,7 @@ Example: Virtual Hosted Style`,
batchAddModels: 'Add all models',
batchRemoveModels: 'Remove all models',
batchVerifyModels: 'Verify all models',
+ moreActions: 'More actions',
editCustomModelTitle: 'Edit model',
modelMaxTokens: 'Max context length',
modelFeatures: 'Model features',
diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts
index 52c99d3d32..eb25c8065e 100644
--- a/web/src/locales/zh.ts
+++ b/web/src/locales/zh.ts
@@ -2039,6 +2039,7 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 R
batchAddModels: '添加全部模型',
batchRemoveModels: '移除全部模型',
batchVerifyModels: '验证全部模型',
+ moreActions: '更多操作',
editCustomModelTitle: '编辑模型',
modelMaxTokens: '最大上下文长度',
modelTypes: {
diff --git a/web/src/pages/user-setting/setting-model/index.tsx b/web/src/pages/user-setting/setting-model/index.tsx
index 03fbc9e7a0..73cf9e3bb8 100644
--- a/web/src/pages/user-setting/setting-model/index.tsx
+++ b/web/src/pages/user-setting/setting-model/index.tsx
@@ -15,20 +15,15 @@
*/
import Spotlight from '@/components/spotlight';
-import message from '@/components/ui/message';
import { useTranslate } from '@/hooks/common-hooks';
import {
- LlmKeys,
- useAddProviderInstance,
useFetchAddedProviders,
useFetchProviderInstances,
- useUpdateProviderInstance,
} from '@/hooks/use-llm-request';
import { IProviderInstance } from '@/interfaces/database/llm';
-import { useQueryClient } from '@tanstack/react-query';
import { Plus } from 'lucide-react';
import { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react';
-import { ProviderInstanceCardRef } from './instance-card/interface';
+import { InstanceSavePayload } from './instance-card/interface';
import { ProviderInstanceCard } from './instance-card/provider-instance-card';
import { ProviderHeaderBar } from './layout/provider-header-bar';
import { Sidebar, SidebarSelection } from './layout/sidebar';
@@ -41,17 +36,15 @@ import SystemSetting from './layout/system-setting';
* - Left: `Sidebar` (Default-models entry, search, provider list).
* - Right:
* * 'default' selection -> `SystemSetting`.
- * * provider selection -> a sticky `ProviderHeaderBar` at the top
- * (with a batch Save button), a vertical stack of
- * `ProviderInstanceCard` in the middle, and a sticky "+ Instance"
- * button at the bottom. Each click of that button adds a new
- * draft card; multiple drafts can coexist.
+ * * provider selection -> a sticky `ProviderHeaderBar` at the top,
+ * a vertical stack of `ProviderInstanceCard` in the middle, and a
+ * sticky "+ Instance" button at the bottom. Each click of that
+ * button adds a new draft card; multiple drafts can coexist.
*
- * Save flow: the top Save button validates every visible card through
- * the imperative ref API; if all are valid it collects each card's
- * payload (skipping non-dirty saved cards) and dispatches one API call
- * per dirty card - `addProviderInstance` for drafts and
- * `updateProviderInstance` for saved cards.
+ * Save flow: each instance card owns its Save button and persists only
+ * its own instance (drafts via `addProviderInstance`, saved cards via
+ * `updateProviderInstance`). The page just reacts to a draft being
+ * persisted by dropping its card and expanding the persisted one.
*
* Special-case providers (handled inside `ProviderInstanceCard`):
* - `Bedrock`: rendered inline via `BedrockInstanceCard`.
@@ -62,15 +55,13 @@ const SettingModelV2: FC = () => {
const { t: tSetting } = useTranslate('setting');
const [selection, setSelection] = useState<SidebarSelection>('default');
// Stack of draft-instance identifiers, rendered as `ProviderInstanceCard`
- // entries below the persisted instances. Each draft can be cancelled
- // independently; saving is driven by the top Save button.
+ // entries below the persisted instances. Each draft is saved or
+ // cancelled from its own card.
const [draftIds, setDraftIds] = useState<string[]>([]);
- const [saving, setSaving] = useState(false);
-
- // Tracks the instance name that was just persisted by the top Save
- // button. The corresponding saved card mounts expanded so the user
- // can immediately see (and edit) what was just saved. Reset on every
+ // Tracks the instance name that was just persisted from a draft card.
+ // The corresponding saved card mounts expanded so the user can
+ // immediately see (and edit) what was just saved. Reset on every
// selection change so it does not bleed across providers.
const [newlySavedInstanceName, setNewlySavedInstanceName] = useState<
string | null
@@ -82,23 +73,6 @@ const SettingModelV2: FC = () => {
// for the current selection. Reset on every selection change.
const cancelledRef = useRef(false);
- // Imperative refs to every visible card, keyed by the card's React key
- // (instance name for saved cards, draft id for drafts). Used by the
- // top Save button to validate + collect payloads in a single batch.
- const cardRefs = useRef<Map<string, ProviderInstanceCardRef | null>>(
- new Map(),
- );
- const setCardRef = useCallback(
- (id: string) => (ref: ProviderInstanceCardRef | null) => {
- if (ref) {
- cardRefs.current.set(id, ref);
- } else {
- cardRefs.current.delete(id);
- }
- },
- [],
- );
-
const { data: addedProviders } = useFetchAddedProviders();
const providerQueryName = useMemo(() => {
if (selection === 'default') return '';
@@ -108,7 +82,6 @@ const SettingModelV2: FC = () => {
}, [selection, addedProviders]);
const { data: instances, loading: instancesLoading } =
useFetchProviderInstances(providerQueryName);
- const queryClient = useQueryClient();
// Append a new draft id to the visible list.
const addDraft = useCallback(() => {
@@ -123,12 +96,10 @@ const SettingModelV2: FC = () => {
}, []);
// When the selection changes, clear the cancelled flag, drop any
- // in-flight drafts, and reset the ref registry so stale refs from
- // the previous provider don't leak into the next save batch.
+ // in-flight drafts, and reset the just-saved marker.
useEffect(() => {
cancelledRef.current = false;
setDraftIds([]);
- cardRefs.current.clear();
setNewlySavedInstanceName(null);
}, [selection]);
@@ -152,126 +123,6 @@ const SettingModelV2: FC = () => {
}
}, [selection, instances, instancesLoading, draftIds, addDraft]);
- const { addProviderInstance } = useAddProviderInstance();
- const { updateProviderInstance } = useUpdateProviderInstance();
-
- // Batch save handler, wired to the top Save button.
- //
- // Flow:
- // 1. Collect every card ref.
- // 2. Ask each for its save payload. Drafts always return one
- // (provided the name is non-empty); saved cards return `null`
- // when not dirty so we skip the redundant API call.
- // 3. If any card is invalid (or a draft has no name), abort the
- // whole batch - errors are surfaced in the form UI by `trigger()`.
- // 4. Dispatch one API call per dirty card, in order. Drafts go through
- // `addProviderInstance`; saved cards go through
- // `updateProviderInstance`.
- // 5. On success: clear drafts (they're persisted now), mark each
- // saved card's baseline so the next save short-circuits, and
- // invalidate the instance query so the new/updated cards appear.
- const handleSaveAll = useCallback(async () => {
- // Keep each card's registry key alongside its ref: for drafts the
- // key is the draft id, so a successfully-saved draft can be removed
- // from `draftIds` individually even when a later card in the batch
- // fails (the early return must not strand already-persisted drafts).
- const refs = Array.from(cardRefs.current.entries()).flatMap(([key, ref]) =>
- ref ? [{ key, ref }] : [],
- );
- if (refs.length === 0) return;
-
- const dirty = refs
- .map(({ key, ref }) => ({ key, ref, payload: ref.getSavePayload() }))
- .filter((e) => e.payload !== null);
- if (dirty.length === 0) return;
-
- // Reject duplicate instance names before any API call: a draft may
- // not reuse the name of a persisted instance, nor of another draft
- // in the same batch. Without this the backend would either error or
- // silently create a second instance sharing the name.
- const takenNames = new Set(instances.map((i) => i.instance_name));
- for (const { payload } of dirty) {
- if (!payload) continue;
- const name = payload.instanceName.trim();
- if (payload.isDraft && takenNames.has(name)) {
- message.error(tSetting('instanceNameExists'));
- return;
- }
- takenNames.add(name);
- }
-
- const validations = await Promise.all(
- dirty.map(async (e) => ({ ...e, valid: await e.ref.validate() })),
- );
- if (validations.some((v) => !v.valid)) {
- return;
- }
-
- setSaving(true);
- // Pin the auto-show guard so a draft isn't re-spawned while the
- // providerInstances refetch is in flight (during that window both
- // `instances` and `draftIds` are empty and would otherwise re-trigger
- // `addDraft()`).
- cancelledRef.current = true;
- try {
- // 3. Dispatch one API call per dirty card. Sequential so a
- // backend error stops the batch and the user can retry the
- // remaining cards after fixing the issue. Each successfully
- // persisted draft is removed immediately so it never lingers
- // beside its now-saved card when a later card in the batch
- // fails.
- for (const { key, ref, payload } of validations) {
- if (!payload) continue;
- if (payload.apiKind === 'add') {
- const ret = await addProviderInstance(payload.payload as any);
- if (ret?.code !== 0) {
- // Stop on the first failure so the user can see the error.
- // Drafts already persisted above were removed individually.
- return;
- }
- if (payload.isDraft) {
- // This draft is now persisted - drop its card right away.
- setDraftIds((prev) => prev.filter((id) => id !== key));
- // Remember the just-saved name so the persisted card mounts
- // expanded once it surfaces via the invalidated instances
- // query.
- setNewlySavedInstanceName(payload.instanceName);
- }
- } else {
- const ret = await updateProviderInstance(payload.payload as any);
- if (ret?.code !== 0) {
- return;
- }
- // Saved card: update its dirty baseline so the next save
- // short-circuits.
- ref.markSaved();
- }
- }
- // 4. Refresh the persisted instance list (covers updates; adds are
- // already invalidated by the add mutation) so saved cards show.
- queryClient.invalidateQueries({
- queryKey: LlmKeys.providerInstances(providerQueryName),
- });
- } finally {
- setSaving(false);
- }
- }, [
- addProviderInstance,
- updateProviderInstance,
- queryClient,
- providerQueryName,
- instances,
- tSetting,
- ]);
-
- // Whether the Save button should be enabled. We avoid an O(n) ref
- // scan on every render by treating "has any draft OR any saved
- // instance" as a conservative proxy - if there is nothing on screen
- // there is nothing to save, and if there is something the user can
- // always attempt a save (dirty saved cards short-circuit inside
- // `getSavePayload`). The button is disabled while a save is in flight.
- const canSave = !saving && (draftIds.length > 0 || instances.length > 0);
-
// User clicked Cancel on a specific draft - remove it from the list
// and stop the auto-show effect from re-opening it for the current
// empty-instance selection.
@@ -283,6 +134,20 @@ const SettingModelV2: FC = () => {
[removeDraft],
);
+ // A draft card persisted its instance. Drop the draft card and pin the
+ // auto-show guard so a new draft isn't re-spawned while the instances
+ // refetch is in flight (during that window both `instances` and
+ // `draftIds` are empty and would otherwise re-trigger `addDraft()`).
+ // The saved name makes the persisted card mount expanded.
+ const handleDraftSaved = useCallback(
+ (draftId: string) => (payload: InstanceSavePayload) => {
+ cancelledRef.current = true;
+ removeDraft(draftId);
+ setNewlySavedInstanceName(payload.instanceName);
+ },
+ [removeDraft],
+ );
+
const draftInstance: IProviderInstance = useMemo(
() => ({ instance_name: '' }) as IProviderInstance,
[],
@@ -301,13 +166,9 @@ const SettingModelV2: FC = () => {
</div>
) : (
<>
- {/* Sticky top: provider name + doc-link arrow + batch Save */}
- <ProviderHeaderBar
- providerName={selection as string}
- onSave={handleSaveAll}
- saving={saving}
- canSave={canSave}
- />
+ {/* Sticky top: provider name + doc-link arrow. Saving lives
+ in each instance card's header. */}
+ <ProviderHeaderBar providerName={selection as string} />
{/* Scrollable middle: instance cards + optional draft cards */}
<div className="flex-1 overflow-auto scrollbar-auto p-4 flex flex-col gap-4">
@@ -319,7 +180,6 @@ const SettingModelV2: FC = () => {
{instances.map((instance, index) => (
<ProviderInstanceCard
key={instance.instance_name}
- ref={setCardRef(instance.instance_name)}
providerName={selection as string}
instance={instance}
defaultOpen={
@@ -331,11 +191,11 @@ const SettingModelV2: FC = () => {
{draftIds.map((id) => (
<ProviderInstanceCard
key={id}
- ref={setCardRef(id)}
providerName={selection as string}
instance={draftInstance}
isDraft
onDelete={() => handleDraftCancel(id)}
+ onSaved={handleDraftSaved(id)}
/>
))}
<div className="z-10 border-border-button py-4">
diff --git a/web/src/pages/user-setting/setting-model/instance-card/bedrock-instance-card.test.tsx b/web/src/pages/user-setting/setting-model/instance-card/bedrock-instance-card.test.tsx
index 336828d4f0..83f3e80e55 100644
--- a/web/src/pages/user-setting/setting-model/instance-card/bedrock-instance-card.test.tsx
+++ b/web/src/pages/user-setting/setting-model/instance-card/bedrock-instance-card.test.tsx
@@ -92,7 +92,11 @@ jest.mock('@/hooks/logic-hooks/use-build-options', () => ({
jest.mock('@/hooks/use-llm-request', () => {
return {
+ useAddProviderInstance: () => ({ addProviderInstance: jest.fn() }),
+ useUpdateProviderInstance: () => ({ updateProviderInstance: jest.fn() }),
useDeleteProviderInstance: () => ({ deleteProviderInstance: jest.fn() }),
+ useFetchAddedProviders: () => ({ data: [] }),
+ useFetchProviderInstances: () => ({ data: [], loading: false }),
useFetchProviderInstance: (...args: unknown[]) =>
mockFetchProviderInstance(...args),
useVerifyProviderConnection: () => ({
diff --git a/web/src/pages/user-setting/setting-model/instance-card/bedrock-instance-card.tsx b/web/src/pages/user-setting/setting-model/instance-card/bedrock-instance-card.tsx
index dedbd1bb97..7a541ce56a 100644
--- a/web/src/pages/user-setting/setting-model/instance-card/bedrock-instance-card.tsx
+++ b/web/src/pages/user-setting/setting-model/instance-card/bedrock-instance-card.tsx
@@ -53,9 +53,10 @@ import { useForm, useWatch } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { z } from 'zod';
import { BedrockRegionList } from '../constants';
-import { VerifyResult } from '../hooks';
+import { useFetchInstanceNameSet, VerifyResult } from '../hooks';
import { splitProviderPayload } from '../payload-utils';
import {
+ InstanceSavePayload,
ProviderInstanceCardProps,
ProviderInstanceCardRef,
} from './interface';
@@ -63,12 +64,14 @@ import {
applySavedCredentialEdits,
SAVED_CREDENTIAL_MASK,
unwrapApiKey,
+ useInstanceSave,
} from './hooks';
import {
SavedProviderConfigFieldSet,
hasUnsavedProviderCredential,
pickSavedProviderConfigOverrides,
} from './saved-provider-config';
+import { InstanceSaveButton } from './components/instance-save-button';
import { SavedCredentialInput } from './saved-credential-input';
import { ModelsSection } from './models-section';
import VerifyButton from './verify-button';
@@ -96,6 +99,8 @@ interface BedrockInstanceCardProps {
instance: IProviderInstance;
isDraft?: boolean;
onDelete?: () => void;
+ /** Called after the card's Save button persists this instance. */
+ onSaved?: (payload: InstanceSavePayload) => void;
defaultOpen?: boolean;
}
@@ -104,14 +109,20 @@ interface BedrockInstanceCardProps {
* (auth_mode segmented, credentials, region, and manual model settings)
* directly instead of going through the generic DynamicForm path. API key
* drafts discover models and persist them with the instance.
- * The parent page's top Save button drives persistence through the imperative
- * ref API.
+ * The header Save button persists only this instance.
*/
export const BedrockInstanceCard = forwardRef<
ProviderInstanceCardRef,
BedrockInstanceCardProps
>(function BedrockInstanceCard(
- { providerName, instance, isDraft = false, onDelete, defaultOpen = false },
+ {
+ providerName,
+ instance,
+ isDraft = false,
+ onDelete,
+ onSaved,
+ defaultOpen = false,
+ },
ref,
) {
const { t } = useTranslation();
@@ -609,30 +620,48 @@ export const BedrockInstanceCard = forwardRef<
}
}, [isDraft]);
+ // Form validation shared by the header Save button and the
+ // imperative API.
+ const validate = useCallback(async () => {
+ if (isDraft && !draftNameRef.current.trim()) return false;
+ if (!isDraft && !modelsLoadedRef.current) {
+ message.error(tSetting('selectModelBeforeSave'));
+ return false;
+ }
+ if (
+ isDraft &&
+ authMode === 'bedrock_api_key' &&
+ modelInfoRef.current.length === 0
+ ) {
+ message.error(tSetting('selectModelBeforeSave'));
+ return false;
+ }
+ const isValid = await form.trigger();
+ return !!isValid;
+ }, [isDraft, authMode, form, tSetting]);
+
+ // The card header owns the Save button: each instance is persisted
+ // independently, straight from its own card.
+ const { instanceNameSet } = useFetchInstanceNameSet(
+ isDraft ? providerName : '',
+ );
+ const { save: handleSave, saving } = useInstanceSave({
+ isDraft,
+ getSavePayload,
+ validate,
+ markSaved,
+ existingNames: instanceNameSet,
+ onSaved,
+ });
+
useImperativeHandle(
ref,
() => ({
- validate: async () => {
- if (isDraft && !draftNameRef.current.trim()) return false;
- if (!isDraft && !modelsLoadedRef.current) {
- message.error(tSetting('selectModelBeforeSave'));
- return false;
- }
- if (
- isDraft &&
- authMode === 'bedrock_api_key' &&
- modelInfoRef.current.length === 0
- ) {
- message.error(tSetting('selectModelBeforeSave'));
- return false;
- }
- const isValid = await form.trigger();
- return !!isValid;
- },
+ validate,
getSavePayload,
markSaved,
}),
- [isDraft, authMode, form, getSavePayload, markSaved, tSetting],
+ [validate, getSavePayload, markSaved],
);
// ──────────────── Field group rendered in both modes ────────────────
@@ -868,7 +897,7 @@ export const BedrockInstanceCard = forwardRef<
<span className="text-destructive mr-0.5">*</span>
{tSetting('instanceName')}
</label>
- <div className="flex items-center">
+ <div className="flex items-center gap-2">
<Input
id="instance-name-input"
value={draftName}
@@ -881,13 +910,14 @@ export const BedrockInstanceCard = forwardRef<
<Button
variant="delete"
size="icon-sm"
- className="ml-2 shrink-0"
+ className="shrink-0"
aria-label={tSetting('deleteInstance')}
data-testid="draft-delete"
>
<Trash2 className="size-4" />
</Button>
</ConfirmDeleteDialog>
+ <InstanceSaveButton onSave={handleSave} saving={saving} />
</div>
</div>
@@ -912,9 +942,9 @@ export const BedrockInstanceCard = forwardRef<
) : (
<Collapsible open={open} onOpenChange={setOpen}>
<CollapsibleTrigger asChild>
- <div className="flex items-center gap-1 w-full mb-5">
+ <div className="flex items-center gap-2 w-full mb-5">
<div
- className="group flex items-center flex-1 gap-2 px-2 mx-2 py-1 cursor-pointer bg-bg-input rounded-md"
+ className="group flex items-center flex-1 min-w-0 gap-2 px-2 mx-2 py-1 cursor-pointer bg-bg-input rounded-md"
data-testid="instance-name-row"
>
<Button
@@ -949,6 +979,7 @@ export const BedrockInstanceCard = forwardRef<
<Trash2 className="size-4" />
</Button>
</ConfirmDeleteDialog>
+ <InstanceSaveButton onSave={handleSave} saving={saving} />
</div>
</CollapsibleTrigger>
<CollapsibleContent
diff --git a/web/src/pages/user-setting/setting-model/instance-card/components/draft-mode-card.tsx b/web/src/pages/user-setting/setting-model/instance-card/components/draft-mode-card.tsx
index b46a0a8c67..15fff90f7c 100644
--- a/web/src/pages/user-setting/setting-model/instance-card/components/draft-mode-card.tsx
+++ b/web/src/pages/user-setting/setting-model/instance-card/components/draft-mode-card.tsx
@@ -26,12 +26,10 @@ import { InstanceNameSection } from './instance-name-section';
/**
* The draft (unsaved) variant of the provider instance card.
*
- * Renders the instance name input section at the top (without a Save
- * button - the parent drives save through the imperative ref API),
- * followed by the form fields, verify button, and per-instance models
- * section. All fields are editable from the start; there is no
- * fieldset lock - the user can fill in everything and submit via the
- * top-of-page Save button.
+ * Renders the instance name input section at the top (paired with the
+ * delete and Save buttons for this draft), followed by the form fields,
+ * verify button, and per-instance models section. All fields are
+ * editable from the start; there is no fieldset lock.
*/
export function DraftModeCard({
formFields,
@@ -39,6 +37,8 @@ export function DraftModeCard({
formRef,
handleVerify,
handleDelete,
+ handleSave,
+ saving,
handleInstanceModelsEdited,
providerName,
instanceName,
@@ -64,6 +64,8 @@ export function DraftModeCard({
draftName={draftName}
setDraftName={setDraftName}
handleDelete={handleDelete}
+ handleSave={handleSave}
+ saving={saving}
/>
<DynamicForm.Root
diff --git a/web/src/pages/user-setting/setting-model/instance-card/components/instance-name-section.tsx b/web/src/pages/user-setting/setting-model/instance-card/components/instance-name-section.tsx
index b61f6c8cbd..3372e05eae 100644
--- a/web/src/pages/user-setting/setting-model/instance-card/components/instance-name-section.tsx
+++ b/web/src/pages/user-setting/setting-model/instance-card/components/instance-name-section.tsx
@@ -19,24 +19,29 @@ import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { useTranslate } from '@/hooks/common-hooks';
import { Trash2 } from 'lucide-react';
+import { InstanceSaveButton } from './instance-save-button';
export interface InstanceNameSectionProps {
draftName: string;
setDraftName: (name: string) => void;
handleDelete: () => Promise<void>;
+ /** Persist the draft with the typed-in name. */
+ handleSave: () => void;
+ /** True while the save request is in flight. */
+ saving: boolean;
}
/**
* The instance-name input section shown at the top of a draft (unsaved)
- * card. The input carries the destructive red border and is paired with
- * a delete icon. There is no inline Save button - the parent page's
- * top Save button drives persistence through the imperative ref API.
- * The helper text below explains the workflow.
+ * card. The input is paired with a delete icon and the card's Save
+ * button, which persists only this draft.
*/
export function InstanceNameSection({
draftName,
setDraftName,
handleDelete,
+ handleSave,
+ saving,
}: InstanceNameSectionProps) {
const { t: tSetting } = useTranslate('setting');
@@ -49,14 +54,12 @@ export function InstanceNameSection({
<span className="text-state-error mr-0.5">*</span>
{tSetting('instanceName')}
</label>
- <div className="flex items-center">
+ <div className="flex items-center gap-2">
<Input
id="instance-name-input"
value={draftName}
onChange={(e) => setDraftName(e.target.value)}
placeholder={tSetting('instanceNamePlaceholder')}
- // The input itself carries the red border. Persists while the
- // name is unsaved.
className="flex-1"
data-testid="instance-name-input"
/>
@@ -64,13 +67,14 @@ export function InstanceNameSection({
<Button
variant="delete"
size="icon-sm"
- className="ml-2 shrink-0"
+ className="shrink-0"
aria-label={tSetting('deleteInstance')}
data-testid="draft-delete"
>
<Trash2 className="size-4" />
</Button>
</ConfirmDeleteDialog>
+ <InstanceSaveButton onSave={handleSave} saving={saving} />
</div>
</div>
);
diff --git a/web/src/pages/user-setting/setting-model/instance-card/components/instance-save-button.tsx b/web/src/pages/user-setting/setting-model/instance-card/components/instance-save-button.tsx
new file mode 100644
index 0000000000..6ed6a2f73c
--- /dev/null
+++ b/web/src/pages/user-setting/setting-model/instance-card/components/instance-save-button.tsx
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Button } from '@/components/ui/button';
+import { useTranslate } from '@/hooks/common-hooks';
+import { ListCheck, Loader2 } from 'lucide-react';
+import { MouseEvent, useCallback } from 'react';
+
+interface InstanceSaveButtonProps {
+ /** Persist the instance this button belongs to. */
+ onSave: () => void;
+ /** True while the save request is in flight. */
+ saving: boolean;
+}
+
+/**
+ * Header Save button of an instance card. Persists only its own
+ * instance; the click must not bubble into the surrounding collapsible
+ * trigger, which would toggle the card open/closed.
+ */
+export function InstanceSaveButton({
+ onSave,
+ saving,
+}: InstanceSaveButtonProps) {
+ const { t } = useTranslate('setting');
+
+ const handleClick = useCallback(
+ (e: MouseEvent<HTMLButtonElement>) => {
+ e.stopPropagation();
+ onSave();
+ },
+ [onSave],
+ );
+
+ return (
+ <Button
+ size="sm"
+ onClick={handleClick}
+ disabled={saving}
+ data-testid="instance-save"
+ className="gap-1.5"
+ >
+ {saving ? (
+ <Loader2 className="size-4 animate-spin" />
+ ) : (
+ <ListCheck className="size-4" />
+ )}
+ {t('save')}
+ </Button>
+ );
+}
diff --git a/web/src/pages/user-setting/setting-model/instance-card/components/saved-mode-card.tsx b/web/src/pages/user-setting/setting-model/instance-card/components/saved-mode-card.tsx
index 11a595f42b..677f935867 100644
--- a/web/src/pages/user-setting/setting-model/instance-card/components/saved-mode-card.tsx
+++ b/web/src/pages/user-setting/setting-model/instance-card/components/saved-mode-card.tsx
@@ -37,18 +37,18 @@ import { useTranslation } from 'react-i18next';
import { DRAFT_INSTANCE_SENTINEL, SavedModeCardProps } from '../interface';
import { ModelsSection } from '../models-section';
import VerifyButton from '../verify-button';
+import { InstanceSaveButton } from './instance-save-button';
import { cn } from '@/lib/utils';
/**
* The saved (non-draft) variant of the provider instance card.
*
* Renders a Collapsible whose trigger shows a chevron toggle + the
- * instance name (double-click to rename) + delete button, and whose
- * content holds the form fields, the verify button, and (when
+ * instance name (double-click to rename) + delete and Save buttons, and
+ * whose content holds the form fields, the verify button, and (when
* expanded) the per-instance models section.
*
- * Auto-save has been removed; the parent's top Save button drives all
- * persistence through the imperative ref API.
+ * The header Save button persists only this instance.
*/
export function SavedModeCard({
formFields,
@@ -56,6 +56,8 @@ export function SavedModeCard({
formRef,
handleVerify,
handleDelete,
+ handleSave,
+ saving,
handleInstanceModelsEdited,
providerName,
instanceName,
@@ -137,10 +139,10 @@ export function SavedModeCard({
>
<CollapsibleTrigger asChild>
<div
- className={cn('flex items-center gap-1 w-full ', open ? 'mb-5' : '')}
+ className={cn('flex items-center gap-2 w-full ', open ? 'mb-5' : '')}
>
<div
- className="group w-[calc(100%-40px)] flex items-center flex-1 gap-2 cursor-pointer rounded-md"
+ className="group flex items-center flex-1 min-w-0 gap-2 cursor-pointer rounded-md"
data-testid="instance-name-row"
>
<Button
@@ -186,17 +188,20 @@ export function SavedModeCard({
</div>
)}
</div>
- <ConfirmDeleteDialog onOk={handleDelete}>
- <Button
- variant="delete"
- size="icon-sm"
- aria-label={tSetting('deleteInstance')}
- data-testid="instance-delete"
- onClick={(e: React.MouseEvent) => e.stopPropagation()}
- >
- <Trash2 className="size-4" />
- </Button>
- </ConfirmDeleteDialog>
+ <div className="flex items-center gap-2 shrink-0">
+ <ConfirmDeleteDialog onOk={handleDelete}>
+ <Button
+ variant="delete"
+ size="icon-sm"
+ aria-label={tSetting('deleteInstance')}
+ data-testid="instance-delete"
+ onClick={(e: React.MouseEvent) => e.stopPropagation()}
+ >
+ <Trash2 className="size-4" />
+ </Button>
+ </ConfirmDeleteDialog>
+ <InstanceSaveButton onSave={handleSave} saving={saving} />
+ </div>
</div>
</CollapsibleTrigger>
<CollapsibleContent forceMount className="data-[state=closed]:hidden">
diff --git a/web/src/pages/user-setting/setting-model/instance-card/hooks.tsx b/web/src/pages/user-setting/setting-model/instance-card/hooks.tsx
index c04a1433da..b8a2015967 100644
--- a/web/src/pages/user-setting/setting-model/instance-card/hooks.tsx
+++ b/web/src/pages/user-setting/setting-model/instance-card/hooks.tsx
@@ -15,16 +15,26 @@
*/
import { DynamicFormRef, FormFieldType } from '@/components/dynamic-form';
+import message from '@/components/ui/message';
import {
+ useAddProviderInstance,
useDeleteProviderInstance,
useFetchAvailableProviders,
useFetchProviderInstance,
+ useUpdateProviderInstance,
useVerifyProviderConnection,
} from '@/hooks/use-llm-request';
import { useTranslate } from '@/hooks/common-hooks';
import { IProviderInstance } from '@/interfaces/database/llm';
import { IModelInfo } from '@/interfaces/request/llm';
-import { RefObject, useCallback, useEffect, useMemo, useRef } from 'react';
+import {
+ RefObject,
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from 'react';
import { getProviderConfig } from '../provider-schema/field-config';
import { useProviderFields } from '../provider-schema/hooks';
import { SelectOption } from '../provider-schema/types';
@@ -582,6 +592,82 @@ export function useDeleteInstance(
}, [isDraft, providerName, instanceName, deleteProviderInstance, onDelete]);
}
+// ---------------------------------------------------------------------------
+// useInstanceSave - per-card save (button lives in the card header)
+// ---------------------------------------------------------------------------
+
+interface UseInstanceSaveArgs {
+ isDraft: boolean;
+ /** Builds the API body, or `null` when there is nothing to persist. */
+ getSavePayload: () => InstanceSavePayload | null;
+ /** Runs form validation; returns false when the card must not be saved. */
+ validate: () => Promise<boolean>;
+ /** Re-baselines dirty tracking after a successful update. */
+ markSaved: () => void;
+ /** Instance names already persisted for this provider (draft dup check). */
+ existingNames?: Set<string>;
+ /** Called after the save request succeeds. */
+ onSaved?: (payload: InstanceSavePayload) => void;
+}
+
+/**
+ * Drives a single instance card's save button. Drafts go through
+ * `addProviderInstance`, saved instances through `updateProviderInstance`;
+ * both mutations invalidate the instance / model queries themselves.
+ */
+export function useInstanceSave({
+ isDraft,
+ getSavePayload,
+ validate,
+ markSaved,
+ existingNames,
+ onSaved,
+}: UseInstanceSaveArgs) {
+ const { addProviderInstance } = useAddProviderInstance();
+ const { updateProviderInstance } = useUpdateProviderInstance();
+ const { t: tSetting } = useTranslate('setting');
+ const [saving, setSaving] = useState(false);
+
+ const save = useCallback(async () => {
+ if (saving) return;
+ const payload = getSavePayload();
+ if (!payload) return;
+ if (isDraft && existingNames?.has(payload.instanceName)) {
+ message.error(tSetting('instanceNameExists'));
+ return;
+ }
+ if (!(await validate())) return;
+
+ setSaving(true);
+ try {
+ const ret =
+ payload.apiKind === 'add'
+ ? await addProviderInstance(payload.payload as any)
+ : await updateProviderInstance(payload.payload as any);
+ if (ret?.code !== 0) return;
+ if (payload.apiKind === 'update') {
+ markSaved();
+ }
+ onSaved?.(payload);
+ } finally {
+ setSaving(false);
+ }
+ }, [
+ saving,
+ getSavePayload,
+ isDraft,
+ existingNames,
+ validate,
+ addProviderInstance,
+ updateProviderInstance,
+ markSaved,
+ onSaved,
+ tSetting,
+ ]);
+
+ return { save, saving };
+}
+
// ---------------------------------------------------------------------------
// useInstanceSaveState - payload builder + dirty tracking (no auto-save)
// ---------------------------------------------------------------------------
diff --git a/web/src/pages/user-setting/setting-model/instance-card/interface.ts b/web/src/pages/user-setting/setting-model/instance-card/interface.ts
index 429947d9bd..a49c840e76 100644
--- a/web/src/pages/user-setting/setting-model/instance-card/interface.ts
+++ b/web/src/pages/user-setting/setting-model/instance-card/interface.ts
@@ -33,12 +33,12 @@ export type VerifyTransform = (values: Record<string, any>) => {
};
/**
- * Imperative save API exposed by each instance card (generic, Bedrock,
- * SoMark) so the parent page can drive a single batch save from the
- * top-of-page Save button.
+ * Imperative API exposed by each instance card (generic, Bedrock,
+ * SoMark) for tests and embedders that need to validate a card or
+ * inspect its save payload without clicking the header Save button.
*
- * The card owns its form state and dirty tracking; the parent only needs
- * to validate, collect payloads, and dispatch the API calls.
+ * The card owns its form state, dirty tracking, and save request; the
+ * header Save button persists only its own instance.
*/
export interface ProviderInstanceCardRef {
/**
@@ -75,7 +75,7 @@ export interface InstanceSavePayload {
/** True for a new (unsaved) instance, false for an existing one. */
isDraft: boolean;
/**
- * Which save endpoint the parent should dispatch to:
+ * Which save endpoint the card dispatches to:
* - `'add'`: call `addProviderInstance` for drafts.
* - `'update'`: call `updateProviderInstance` for saved cards.
*/
@@ -94,8 +94,7 @@ export interface ProviderInstanceCardProps {
/**
* True when this card represents a freshly-added (unsaved) instance.
* Renders the instance-name input section and treats all fields as
- * editable. Saving is driven by the parent through the imperative
- * ref API (see {@link ProviderInstanceCardRef}).
+ * editable. The card's own Save button persists it.
*/
isDraft?: boolean;
/**
@@ -104,6 +103,8 @@ export interface ProviderInstanceCardProps {
* the component calls useDeleteProviderInstance internally.
*/
onDelete?: () => void;
+ /** Called after the card's Save button persists this instance. */
+ onSaved?: (payload: InstanceSavePayload) => void;
/**
* When true, this card starts expanded and its instance details
* are fetched on mount. Default `false` so additional cards stay
@@ -151,6 +152,10 @@ export interface SavedModeCardProps {
formRef: RefObject<DynamicFormRef>;
handleVerify: (params: any) => Promise<{ isValid: boolean; logs: string }>;
handleDelete: () => Promise<void>;
+ /** Persist this card's instance (header Save button). */
+ handleSave: () => Promise<void>;
+ /** True while the save request is in flight. */
+ saving: boolean;
handleInstanceModelsEdited: () => void;
providerName: string;
/** Persisted instance name (from the backend). */
@@ -181,6 +186,10 @@ export interface DraftModeCardProps {
formRef: RefObject<DynamicFormRef>;
handleVerify: (params: any) => Promise<{ isValid: boolean; logs: string }>;
handleDelete: () => Promise<void>;
+ /** Persist this card's instance (header Save button). */
+ handleSave: () => Promise<void>;
+ /** True while the save request is in flight. */
+ saving: boolean;
handleInstanceModelsEdited: () => void;
providerName: string;
instanceName: string;
diff --git a/web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx b/web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx
index fe030a0a42..7a21783366 100644
--- a/web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx
+++ b/web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx
@@ -16,11 +16,27 @@
import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog';
import { Button } from '@/components/ui/button';
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from '@/components/ui/dropdown-menu';
import { SearchInput } from '@/components/ui/input';
import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks';
import { useFetchInstanceModels } from '@/hooks/use-llm-request';
import { IProviderModelItem } from '@/interfaces/request/llm';
-import { Loader2, Plus, Search, ShieldCheck } from 'lucide-react';
+import {
+ ListMinus,
+ ListPlus,
+ Loader2,
+ LogIn,
+ LogOut,
+ MoreHorizontal,
+ Plus,
+ Search,
+ ShieldCheck,
+} from 'lucide-react';
import {
useCallback,
useEffect,
@@ -288,6 +304,9 @@ export function ModelsSection(props: ModelsSectionProps) {
// Add-custom-model dialog open state (local UI state).
const [dialogOpen, setDialogOpen] = useState(false);
+ const handleAddCustomClick = useCallback(() => {
+ setDialogOpen(true);
+ }, []);
// Mirror dialog open state up to the host so it can pause its
// blur-driven auto-save while the dialog is open (focus shifts into a
@@ -312,75 +331,52 @@ export function ModelsSection(props: ModelsSectionProps) {
{t('setting.models')}
</div>
{!hideActions && (
- <div className="flex items-center gap-4">
- <div className="flex items-center gap-2">
- <Button
- variant="outline"
- size="sm"
- onClick={handleListModels}
- disabled={manualListLoading}
- data-testid="models-list-button"
- >
- {manualListLoading && (
- <Loader2 className="size-3 animate-spin" />
- )}
- {t('setting.listModels')}
- </Button>
- <Button
- variant="outline"
- size="icon-sm"
- onClick={() => setDialogOpen(true)}
- data-testid="models-add-custom"
- aria-label={t('setting.addCustomModel')}
- >
- <Plus className="size-4" />
- </Button>
- </div>
- <div className="flex items-center gap-2">
- <Button
- variant="outline"
- size="sm"
- onClick={handleBatchVerifyClick}
- disabled={batchVerifying || filteredModels.length === 0}
- data-testid="models-batch-verify"
- className="ml-auto"
- >
- {batchVerifying ? (
- <Loader2 className="size-3 animate-spin" />
- ) : (
- <ShieldCheck className="size-3" />
- )}
- {tSetting('batchVerifyModels')}
- </Button>
- {!hideActions && (
- // When the toggle is in "remove all" mode the click opens a
- // confirmation dialog instead of mutating directly; the button
- // acts as the dialog trigger, so the handler moves to `onOk`.
- <ConfirmDeleteDialog
- hidden={!allFilteredAdded}
- onOk={handleBatchToggleModels}
- title={t('common.removeModalTitle')}
- okButtonText={t('common.remove')}
+ <div className="flex items-center gap-2">
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={handleListModels}
+ disabled={manualListLoading}
+ data-testid="models-list-button"
+ >
+ {manualListLoading && <Loader2 className="size-3 animate-spin" />}
+ {t('setting.listModels')}
+ </Button>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ variant="outline"
+ size="icon-sm"
+ aria-label={tSetting('moreActions')}
+ data-testid="models-more-actions"
>
- <Button
- variant="outline"
- size="sm"
- onClick={
- allFilteredAdded ? undefined : handleBatchToggleModels
- }
- disabled={batchLoading || filteredModels.length === 0}
- data-testid="models-batch-toggle"
- >
- {batchLoading && (
- <Loader2 className="size-3 animate-spin" />
- )}
- {allFilteredAdded
- ? tSetting('batchRemoveModels')
- : tSetting('batchAddModels')}
- </Button>
- </ConfirmDeleteDialog>
- )}
- </div>
+ <MoreHorizontal className="size-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="w-48">
+ <DropdownMenuItem
+ justifyBetween={false}
+ onClick={handleAddCustomClick}
+ data-testid="models-add-custom"
+ >
+ <Plus className="size-4" />
+ {tSetting('addCustomModel')}
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ justifyBetween={false}
+ onClick={handleBatchVerifyClick}
+ disabled={batchVerifying || filteredModels.length === 0}
+ data-testid="models-batch-verify"
+ >
+ {batchVerifying ? (
+ <Loader2 className="size-4 animate-spin" />
+ ) : (
+ <ShieldCheck className="size-4" />
+ )}
+ {tSetting('batchVerifyModels')}
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
</div>
)}
</div>
@@ -394,6 +390,47 @@ export function ModelsSection(props: ModelsSectionProps) {
placeholder={t('setting.search')}
rootClassName="flex-1"
/>
+ {!hideActions && (
+ // When every filtered model is already added the toggle
+ // switches to "remove all" mode: the click opens a
+ // confirmation dialog instead of mutating directly, so the
+ // button acts as the dialog trigger and the handler moves
+ // to `onOk`.
+ <ConfirmDeleteDialog
+ hidden={!allFilteredAdded}
+ onOk={handleBatchToggleModels}
+ title={t('common.removeModalTitle')}
+ okButtonText={t('common.remove')}
+ >
+ <Button
+ variant="outline"
+ size="icon-sm"
+ onClick={
+ allFilteredAdded ? undefined : handleBatchToggleModels
+ }
+ disabled={batchLoading || filteredModels.length === 0}
+ aria-label={
+ allFilteredAdded
+ ? tSetting('batchRemoveModels')
+ : tSetting('batchAddModels')
+ }
+ title={
+ allFilteredAdded
+ ? tSetting('batchRemoveModels')
+ : tSetting('batchAddModels')
+ }
+ data-testid="models-batch-toggle"
+ >
+ {batchLoading ? (
+ <Loader2 className="size-4 animate-spin" />
+ ) : allFilteredAdded ? (
+ <ListMinus className="size-4" />
+ ) : (
+ <ListPlus className="size-4" />
+ )}
+ </Button>
+ </ConfirmDeleteDialog>
+ )}
</div>
<div className="flex flex-wrap gap-1.5">
<TagFilterButton
diff --git a/web/src/pages/user-setting/setting-model/instance-card/provider-instance-card.tsx b/web/src/pages/user-setting/setting-model/instance-card/provider-instance-card.tsx
index 480a210c75..c0924b1304 100644
--- a/web/src/pages/user-setting/setting-model/instance-card/provider-instance-card.tsx
+++ b/web/src/pages/user-setting/setting-model/instance-card/provider-instance-card.tsx
@@ -21,6 +21,7 @@ import { useTranslation } from 'react-i18next';
import { LIST_MODEL_PROVIDERS } from '../provider-schema/constants';
import {
forwardRef,
+ useCallback,
useEffect,
useImperativeHandle,
useMemo,
@@ -37,6 +38,7 @@ import {
useDeleteInstance,
useFormFields,
useFormResetOnDetailsLoad,
+ useInstanceSave,
useInstanceSaveState,
useLazyInstanceDetails,
useProviderBaseUrlOptions,
@@ -56,22 +58,28 @@ import {
* Two visual modes driven by `isDraft`:
* 1. **Draft** (`isDraft`): the instance name lives in a dedicated
* input section at the top of the body, and the form fields are
- * always editable (no fieldset lock). The parent drives save
- * through the imperative ref API.
+ * always editable (no fieldset lock). Its header Save button
+ * persists the new instance.
* 2. **Saved** (`!isDraft`): the form-field section collapses into a
* single collapsible row showing the name as plain text with a
* hover-only key/lock icon. The form fields live inside the
* collapsible content and can be collapsed/expanded.
*
- * Auto-save has been removed; the parent page's top Save button
- * collects payloads from all cards via the ref and dispatches the API
- * calls in a single batch.
+ * Saving is per card: the header Save button validates and persists
+ * only the instance it belongs to.
*/
const GenericProviderInstanceCard = forwardRef<
ProviderInstanceCardRef,
ProviderInstanceCardProps
>(function GenericProviderInstanceCard(
- { providerName, instance, isDraft = false, onDelete, defaultOpen = false },
+ {
+ providerName,
+ instance,
+ isDraft = false,
+ onDelete,
+ onSaved,
+ defaultOpen = false,
+ },
ref,
) {
// Drafts always start open (the user just added them and needs to
@@ -83,7 +91,7 @@ const GenericProviderInstanceCard = forwardRef<
const [draftName, setDraftName] = useState('');
// For saved cards: the instance name as shown in the UI. Initialized
// from the persisted name and updated when the user double-clicks the
- // name to rename it. Persisted via the top Save button.
+ // name to rename it. Persisted via the card's Save button.
const [editedInstanceName, setEditedInstanceName] = useState(
instance.instance_name,
);
@@ -188,45 +196,51 @@ const GenericProviderInstanceCard = forwardRef<
submitTransform: providerConfig.submitTransform,
});
- // Expose the imperative save API to the parent so the top-of-page
- // Save button can validate, collect payloads, and dispatch calls
- // in a single batch without each card wiring its own auto-save.
+ // Form validation shared by the header Save button and the
+ // imperative ref API.
+ const validate = useCallback(async () => {
+ // Drafts need a non-empty instance name (the DynamicForm does
+ // not include the instance_name field, so `trigger()` won't
+ // catch it). For both drafts and saved cards, run the form's
+ // own validation so errors surface in the UI.
+ if (isDraft && !draftName.trim()) return false;
+ if (!isDraft && instanceDetails && !modelsLoadedRef.current) {
+ message.error(t('setting.selectModelBeforeSave'));
+ return false;
+ }
+ // List-model providers (list picker) require at least one selected model.
+ if (
+ LIST_MODEL_PROVIDERS.has(providerName) &&
+ modelInfoRef.current.length === 0
+ ) {
+ message.error(t('setting.selectModelBeforeVerify'));
+ return false;
+ }
+ const isValid = await formRef.current?.trigger();
+ return !!isValid;
+ }, [isDraft, draftName, instanceDetails, providerName, t]);
+
+ // The card header owns the Save button: each instance is persisted
+ // independently, straight from its own card.
+ const { save: handleSave, saving } = useInstanceSave({
+ isDraft,
+ getSavePayload,
+ validate,
+ markSaved,
+ existingNames: instanceNameSet,
+ onSaved,
+ });
+
+ // Expose the imperative save API for tests and embedders that drive
+ // the card from outside.
useImperativeHandle(
ref,
() => ({
- validate: async () => {
- // Drafts need a non-empty instance name (the DynamicForm does
- // not include the instance_name field, so `trigger()` won't
- // catch it). For both drafts and saved cards, run the form's
- // own validation so errors surface in the UI.
- if (isDraft && !draftName.trim()) return false;
- if (!isDraft && instanceDetails && !modelsLoadedRef.current) {
- message.error(t('setting.selectModelBeforeSave'));
- return false;
- }
- // List-model providers (list picker) require at least one selected model.
- if (
- LIST_MODEL_PROVIDERS.has(providerName) &&
- modelInfoRef.current.length === 0
- ) {
- message.error(t('setting.selectModelBeforeVerify'));
- return false;
- }
- const isValid = await formRef.current?.trigger();
- return !!isValid;
- },
+ validate,
getSavePayload,
markSaved,
}),
- [
- isDraft,
- draftName,
- getSavePayload,
- markSaved,
- providerName,
- t,
- instanceDetails,
- ],
+ [validate, getSavePayload, markSaved],
);
return (
@@ -241,6 +255,8 @@ const GenericProviderInstanceCard = forwardRef<
formRef={formRef}
handleVerify={handleVerify}
handleDelete={handleDelete}
+ handleSave={handleSave}
+ saving={saving}
handleInstanceModelsEdited={markModelsEdited}
providerName={providerName}
instanceName={instance.instance_name}
@@ -257,6 +273,8 @@ const GenericProviderInstanceCard = forwardRef<
formRef={formRef}
handleVerify={handleVerify}
handleDelete={handleDelete}
+ handleSave={handleSave}
+ saving={saving}
handleInstanceModelsEdited={markModelsEdited}
providerName={providerName}
instanceName={instance.instance_name}
@@ -286,16 +304,15 @@ const GenericProviderInstanceCard = forwardRef<
* Two visual modes driven by `isDraft`:
* 1. **Draft** (`isDraft`): the instance name lives in a dedicated
* input section at the top of the body, and the form fields are
- * always editable (no fieldset lock). The parent drives save
- * through the imperative ref API.
+ * always editable (no fieldset lock). Its header Save button
+ * persists the new instance.
* 2. **Saved** (`!isDraft`): the form-field section collapses into a
* single collapsible row showing the name as plain text with a
* hover-only key/lock icon. The form fields live inside the
* collapsible content and can be collapsed/expanded.
*
- * Auto-save has been removed; the parent page's top Save button
- * collects payloads from all cards via the ref and dispatches the API
- * calls in a single batch.
+ * Saving is per card: the header Save button validates and persists
+ * only the instance it belongs to.
*/
export const ProviderInstanceCard = forwardRef<
ProviderInstanceCardRef,
diff --git a/web/src/pages/user-setting/setting-model/layout/provider-header-bar.tsx b/web/src/pages/user-setting/setting-model/layout/provider-header-bar.tsx
index e545be2d9a..6a3df8ef81 100644
--- a/web/src/pages/user-setting/setting-model/layout/provider-header-bar.tsx
+++ b/web/src/pages/user-setting/setting-model/layout/provider-header-bar.tsx
@@ -15,37 +15,22 @@
*/
import { LlmIcon } from '@/components/svg-icon';
-import { Button } from '@/components/ui/button';
import { APIMapUrl } from '@/constants/llm';
import { useTranslate } from '@/hooks/common-hooks';
-import { ArrowUpRight, Loader2, Save } from 'lucide-react';
+import { ArrowUpRight } from 'lucide-react';
import { getProviderConfig } from '../provider-schema/field-config';
interface ProviderHeaderBarProps {
providerName: string;
- /** Called when the user clicks the batch Save button. */
- onSave?: () => void;
- /** True while the batch save is in flight - disables the button. */
- saving?: boolean;
- /**
- * True when there is at least one dirty card on the page. When false
- * the Save button is disabled (nothing to persist).
- */
- canSave?: boolean;
}
/**
* Sticky top bar for the right pane that displays the selected provider's
- * icon, name, an API-link arrow, an optional integration-doc link, and a
- * batch Save button. Stays visible while the user scrolls the instance
- * list below.
+ * icon, name, an API-link arrow, and an optional integration-doc link.
+ * Stays visible while the user scrolls the instance list below. Saving
+ * lives in each instance card's header, beside its delete button.
*/
-export function ProviderHeaderBar({
- providerName,
- onSave,
- saving = false,
- canSave = false,
-}: ProviderHeaderBarProps) {
+export function ProviderHeaderBar({ providerName }: ProviderHeaderBarProps) {
const { t: tSetting } = useTranslate('setting');
const apiLink = APIMapUrl[providerName as keyof typeof APIMapUrl];
const providerConfig = getProviderConfig(providerName);
@@ -92,22 +77,6 @@ export function ProviderHeaderBar({
<span>{docLinkText}</span>
</a>
)}
- <div className="flex-1" />
- <Button
- type="button"
- size="sm"
- onClick={onSave}
- disabled={saving || !canSave}
- data-testid="provider-save-all"
- className="gap-1.5"
- >
- {saving ? (
- <Loader2 className="size-4 animate-spin" />
- ) : (
- <Save className="size-4" />
- )}
- {tSetting('save')}
- </Button>
</div>
);
}