From f5cdd0160ed8aef8d601331ef6e2f9ae3cc92855 Mon Sep 17 00:00:00 2001 From: balibabu Date: Wed, 5 Aug 2026 10:57:25 +0800 Subject: [PATCH] Fix: Switching back and forth between the wiki template's custom options caused the Instructions to disappear. (#17805) --- .../agents/compilation-template-card.tsx | 2 +- .../components/blueprint-section.tsx | 5 +- .../components/template-configuration.tsx | 13 ++--- .../hooks/use-blueprint-selection.ts | 47 +++++++++++++------ .../compilation-templates/edit-next/index.tsx | 1 + 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/web/src/pages/agents/compilation-template-card.tsx b/web/src/pages/agents/compilation-template-card.tsx index 4a8688f1c4..7231dc9f64 100644 --- a/web/src/pages/agents/compilation-template-card.tsx +++ b/web/src/pages/agents/compilation-template-card.tsx @@ -33,7 +33,7 @@ export function CompilationTemplateCard({ return ( - + ; selectedTemplateIndex: number; + builtins: ICompilationTemplateBuiltin[]; }; export function BlueprintSection({ form, selectedTemplateIndex, + builtins, }: BlueprintSectionProps) { const { t } = useTranslation(); const { data: presets } = useFetchWikiPresets(); @@ -28,7 +31,7 @@ export function BlueprintSection({ instructionPath, pageExample, handlePageExampleChange, - } = useBlueprintSelection({ form, selectedTemplateIndex, presets }); + } = useBlueprintSelection({ form, selectedTemplateIndex, presets, builtins }); if (presets.length === 0) { return null; diff --git a/web/src/pages/user-setting/compilation-templates/edit-next/components/template-configuration.tsx b/web/src/pages/user-setting/compilation-templates/edit-next/components/template-configuration.tsx index 46cbfec27b..b34a69996f 100644 --- a/web/src/pages/user-setting/compilation-templates/edit-next/components/template-configuration.tsx +++ b/web/src/pages/user-setting/compilation-templates/edit-next/components/template-configuration.tsx @@ -1,7 +1,6 @@ import { ModelTreeSelectFormField } from '@/components/model-tree-select'; import { SelectWithSearch } from '@/components/originui/select-with-search'; import { RAGFlowFormItem } from '@/components/ragflow-form'; -import { Checkbox } from '@/components/ui/checkbox'; import { SwitchFormField } from '@/components/switch-fom-field'; import { Input } from '@/components/ui/input'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; @@ -195,17 +194,11 @@ export function TemplateConfiguration({ {kind === CompilationTemplateKind.Artifacts && ( - - {(field) => ( - field.onChange(v)} - /> - )} - + vertical={false} + /> )} {kind === CompilationTemplateKind.Tree ? ( diff --git a/web/src/pages/user-setting/compilation-templates/edit-next/hooks/use-blueprint-selection.ts b/web/src/pages/user-setting/compilation-templates/edit-next/hooks/use-blueprint-selection.ts index 36273f2241..0d75a380a5 100644 --- a/web/src/pages/user-setting/compilation-templates/edit-next/hooks/use-blueprint-selection.ts +++ b/web/src/pages/user-setting/compilation-templates/edit-next/hooks/use-blueprint-selection.ts @@ -1,10 +1,15 @@ import { SelectWithSearchFlagOptionType } from '@/components/originui/select-with-search'; -import { IWikiPreset } from '@/interfaces/database/compilation-template'; +import { + ICompilationTemplateBuiltin, + IWikiPreset, +} from '@/interfaces/database/compilation-template'; +import { capitalize, lowerCase } from 'lodash'; import { useCallback, useMemo, useState } from 'react'; import { UseFormReturn, useWatch } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { FormSchemaType } from '../schema'; +import { splitExampleToBlueprintFields } from '../utils'; export const CustomBlueprintValue = '__custom__'; @@ -12,6 +17,7 @@ type UseBlueprintSelectionParams = { form: UseFormReturn; selectedTemplateIndex: number; presets: IWikiPreset[]; + builtins: ICompilationTemplateBuiltin[]; }; const isSameBlueprintContent = ( @@ -26,10 +32,12 @@ export function useBlueprintSelection({ form, selectedTemplateIndex, presets, + builtins, }: UseBlueprintSelectionParams) { const { t } = useTranslation(); const [explicitValue, setExplicitValue] = useState(); + const kindPath = `templates.${selectedTemplateIndex}.kind` as const; const instructionPath = `templates.${selectedTemplateIndex}.config.instruction` as const; const pageExamplePath = @@ -37,6 +45,10 @@ export function useBlueprintSelection({ const useBlueprintPath = `templates.${selectedTemplateIndex}.config.use_blueprint` as const; + const kind = useWatch({ + control: form.control, + name: kindPath, + }); const instruction = useWatch({ control: form.control, name: instructionPath, @@ -63,7 +75,7 @@ export function useBlueprintSelection({ const options = useMemo( () => [ ...presets.map((preset) => ({ - label: preset.id, + label: capitalize(lowerCase(preset.id)), value: preset.id, })), { label: t('setting.custom'), value: CustomBlueprintValue }, @@ -77,19 +89,23 @@ export function useBlueprintSelection({ setExplicitValue(value); if (value === CustomBlueprintValue) { - const defaultConfig = - form.formState.defaultValues?.templates?.[selectedTemplateIndex] - ?.config; - form.setValue( - instructionPath, - String(defaultConfig?.instruction ?? ''), - { shouldValidate: false }, - ); - form.setValue( - pageExamplePath, - String(defaultConfig?.page_example ?? ''), - { shouldValidate: false }, + const builtinTemplate = builtins.find( + (template) => template.kind === kind, ); + const example = + typeof builtinTemplate?.config?.example === 'string' + ? builtinTemplate.config.example + : ''; + const { + instruction: defaultInstruction, + page_example: defaultPageExample, + } = splitExampleToBlueprintFields(example); + form.setValue(instructionPath, defaultInstruction, { + shouldValidate: false, + }); + form.setValue(pageExamplePath, defaultPageExample, { + shouldValidate: false, + }); } else { const preset = presets.find((item) => item.id === value); if (!preset) return; @@ -104,11 +120,12 @@ export function useBlueprintSelection({ form.setValue(useBlueprintPath, true, { shouldValidate: false }); }, [ + builtins, form, instructionPath, + kind, pageExamplePath, presets, - selectedTemplateIndex, selectedValue, useBlueprintPath, ], diff --git a/web/src/pages/user-setting/compilation-templates/edit-next/index.tsx b/web/src/pages/user-setting/compilation-templates/edit-next/index.tsx index 3bd7f1573c..09ea1269b4 100644 --- a/web/src/pages/user-setting/compilation-templates/edit-next/index.tsx +++ b/web/src/pages/user-setting/compilation-templates/edit-next/index.tsx @@ -66,6 +66,7 @@ export default function EditNextCompilationTemplate() { )}