Skip to content

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

Fix: Document Generator – Header Text/Footer Text/Watermark Text configurations cannot be saved. (#20187)

balibabu8968f94bd92f
diff --git a/web/src/components/__tests__/switch-fom-field.test.tsx b/web/src/components/__tests__/switch-fom-field.test.tsx
index 90ee0f8f28..62eff8f404 100644
--- a/web/src/components/__tests__/switch-fom-field.test.tsx
+++ b/web/src/components/__tests__/switch-fom-field.test.tsx
@@ -3,7 +3,7 @@ import { TooltipProvider } from '@/components/ui/tooltip';
import { fireEvent, render, screen } from '@testing-library/react';
import { useEffect } from 'react';
import { useForm } from 'react-hook-form';
-import { SwitchFormField } from '../switch-fom-field';
+import { SwitchFormField } from '../switch-form-field';
function Harness() {
const form = useForm({ defaultValues: { flag: false } });
diff --git a/web/src/components/embed-dialog/index.tsx b/web/src/components/embed-dialog/index.tsx
index 76fe54f7c7..ef8329d2a5 100644
--- a/web/src/components/embed-dialog/index.tsx
+++ b/web/src/components/embed-dialog/index.tsx
@@ -55,7 +55,7 @@ import {
} from 'react-syntax-highlighter/dist/esm/styles/prism';
import { z } from 'zod';
import { RAGFlowFormItem } from '../ragflow-form';
-import { SwitchFormField } from '../switch-fom-field';
+import { SwitchFormField } from '../switch-form-field';
import { useIsDarkTheme } from '../theme-provider';
import { Input } from '../ui/input';
diff --git a/web/src/components/switch-fom-field.tsx b/web/src/components/switch-form-field.tsx
similarity index 100%
rename from web/src/components/switch-fom-field.tsx
rename to web/src/components/switch-form-field.tsx
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index a636024aa7..0a25e00bb4 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -2957,6 +2957,13 @@ Best for: Documents with flowing, contextually connected content — such as boo
addPageNumbers: 'Add Page Numbers',
addTimestamp: 'Add Timestamp',
watermarkText: 'Watermark Text',
+ headerText: 'Header Text',
+ footerText: 'Footer Text',
+ includeDownloadInfoInContent: 'Append download info to content',
+ contentPlaceholder: 'Enter markdown content...',
+ filenamePlaceholder: 'document.ext (auto-generated if empty)',
+ contentRequired: 'Content is required',
+ fontSizeMin: 'Font size must be at least 12',
channel: 'Channel',
channelTip: `Perform text search or news search on the component's input`,
text: 'Text',
diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts
index 085bb85df0..22495952ee 100644
--- a/web/src/locales/zh.ts
+++ b/web/src/locales/zh.ts
@@ -2546,6 +2546,13 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 R
addPageNumbers: '添加页码',
addTimestamp: '添加时间戳',
watermarkText: '水印文本',
+ headerText: '页眉文本',
+ footerText: '页脚文本',
+ includeDownloadInfoInContent: '在内容末尾附加下载信息',
+ contentPlaceholder: '输入 Markdown 内容...',
+ filenamePlaceholder: 'document.ext(留空则自动生成)',
+ contentRequired: '内容不能为空',
+ fontSizeMin: '字号不能小于 12',
channel: '频道',
channelTip: '针对该组件的输入进行文本搜索或新闻搜索',
text: '文本',
diff --git a/web/src/pages/agent/constant/doc-generator.ts b/web/src/pages/agent/constant/doc-generator.ts
new file mode 100644
index 0000000000..2842bed8da
--- /dev/null
+++ b/web/src/pages/agent/constant/doc-generator.ts
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+export enum DocGeneratorOutputFormat {
+ Pdf = 'pdf',
+ Docx = 'docx',
+ Txt = 'txt',
+ Markdown = 'markdown',
+ Html = 'html',
+}
+
+export const DocGeneratorFormatOptions = [
+ { label: 'PDF', value: DocGeneratorOutputFormat.Pdf },
+ { label: 'DOCX', value: DocGeneratorOutputFormat.Docx },
+ { label: 'TXT', value: DocGeneratorOutputFormat.Txt },
+ { label: 'Markdown', value: DocGeneratorOutputFormat.Markdown },
+ { label: 'HTML', value: DocGeneratorOutputFormat.Html },
+];
+
+export const DocGeneratorFormatFeatures: Record<
+ DocGeneratorOutputFormat,
+ { decorations: boolean; timestamp: boolean }
+> = {
+ [DocGeneratorOutputFormat.Pdf]: { decorations: true, timestamp: true },
+ [DocGeneratorOutputFormat.Docx]: { decorations: true, timestamp: true },
+ [DocGeneratorOutputFormat.Txt]: { decorations: false, timestamp: true },
+ [DocGeneratorOutputFormat.Markdown]: { decorations: false, timestamp: true },
+ [DocGeneratorOutputFormat.Html]: { decorations: false, timestamp: true },
+};
diff --git a/web/src/pages/agent/constant/index.tsx b/web/src/pages/agent/constant/index.tsx
index ca101cd64f..97827bcf52 100644
--- a/web/src/pages/agent/constant/index.tsx
+++ b/web/src/pages/agent/constant/index.tsx
@@ -25,6 +25,8 @@ export {
export * from './pipeline';
+import { DocGeneratorOutputFormat } from './doc-generator';
+
import { ModelVariableType } from '@/constants/knowledge';
import { t } from 'i18next';
import {
@@ -1119,7 +1121,7 @@ export enum AgentVariableType {
}
export const initialDocGeneratorValues = {
- output_format: 'pdf',
+ output_format: DocGeneratorOutputFormat.Pdf,
content: '',
filename: '',
header_text: '',
diff --git a/web/src/pages/agent/form/begin-form/index.tsx b/web/src/pages/agent/form/begin-form/index.tsx
index 4e66605c3e..750b002f30 100644
--- a/web/src/pages/agent/form/begin-form/index.tsx
+++ b/web/src/pages/agent/form/begin-form/index.tsx
@@ -1,7 +1,7 @@
import { Collapse } from '@/components/collapse';
import { LayoutRecognizeFormField } from '@/components/layout-recognize-form-field';
import { RAGFlowFormItem } from '@/components/ragflow-form';
-import { SwitchFormField } from '@/components/switch-fom-field';
+import { SwitchFormField } from '@/components/switch-form-field';
import { Button } from '@/components/ui/button';
import { Form, FormField } from '@/components/ui/form';
import { SelectWithSearch } from '@/components/originui/select-with-search';
@@ -30,7 +30,10 @@ function BeginForm({ node }: INextOperatorForm) {
const ModeOptions = useMemo(
() => [
- { value: AgentDialogueMode.Conversational, label: t('flow.conversational') },
+ {
+ value: AgentDialogueMode.Conversational,
+ label: t('flow.conversational'),
+ },
{ value: AgentDialogueMode.Task, label: t('flow.task') },
{ value: AgentDialogueMode.Webhook, label: t('flow.webhook.name') },
],
diff --git a/web/src/pages/agent/form/doc-generator-form/index.tsx b/web/src/pages/agent/form/doc-generator-form/index.tsx
index 341a3b4428..08bc30040f 100644
--- a/web/src/pages/agent/form/doc-generator-form/index.tsx
+++ b/web/src/pages/agent/form/doc-generator-form/index.tsx
@@ -1,20 +1,20 @@
+import { RAGFlowFormItem } from '@/components/ragflow-form';
import { FormContainer } from '@/components/form-container';
-import {
- Form,
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from '@/components/ui/form';
-import { Input } from '@/components/ui/input';
+import { Form } from '@/components/ui/form';
+import { Input, NumberInput } from '@/components/ui/input';
import { SelectWithSearch } from '@/components/originui/select-with-search';
-import { Switch } from '@/components/ui/switch';
+import { SwitchFormField } from '@/components/switch-form-field';
import { zodResolver } from '@hookform/resolvers/zod';
-import { memo, useEffect, useMemo } from 'react';
+import i18n from '@/locales/config';
+import { memo, useMemo } from 'react';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { z } from 'zod';
+import {
+ DocGeneratorFormatFeatures,
+ DocGeneratorFormatOptions,
+ DocGeneratorOutputFormat,
+} from '../../constant/doc-generator';
import { INextOperatorForm } from '../../interface';
import { FormWrapper } from '../components/form-wrapper';
import { Output, transferOutputs } from '../components/output';
@@ -22,55 +22,44 @@ import { PromptEditor } from '../components/prompt-editor';
import { useValues } from './use-values';
import { useWatchFormChange } from './use-watch-form-change';
+const FormSchema = z.object({
+ output_format: z.nativeEnum(DocGeneratorOutputFormat),
+ content: z.string().min(1, i18n.t('flow.contentRequired')),
+ filename: z.string().optional(),
+ header_text: z.string().optional(),
+ footer_text: z.string().optional(),
+ watermark_text: z.string().optional(),
+ add_page_numbers: z.boolean(),
+ add_timestamp: z.boolean(),
+ include_download_info_in_content: z.boolean(),
+ font_size: z.coerce.number().min(12, i18n.t('flow.fontSizeMin')),
+ outputs: z.object({
+ doc_id: z.object({ type: z.string() }),
+ filename: z.object({ type: z.string() }),
+ mime_type: z.object({ type: z.string() }),
+ size: z.object({ type: z.string() }),
+ download: z.object({ type: z.string() }),
+ }),
+});
+
function DocGeneratorForm({ node }: INextOperatorForm) {
const { t } = useTranslation();
const values = useValues(node);
- const FormSchema = z.object({
- output_format: z.string().default('pdf'),
- content: z.string().min(1, 'Content is required'),
- filename: z.string().optional(),
- header: z.string().optional(),
- footer: z.string().optional(),
- watermark: z.string().optional(),
- add_page_numbers: z.boolean(),
- add_timestamp: z.boolean(),
- include_download_info_in_content: z.boolean(),
- font_size: z.coerce.number().min(12, 'Font size must be at least 12'),
- outputs: z.object({
- doc_id: z.object({ type: z.string() }),
- filename: z.object({ type: z.string() }),
- mime_type: z.object({ type: z.string() }),
- size: z.object({ type: z.string() }),
- download: z.object({ type: z.string() }),
- }),
- });
-
const form = useForm<z.infer<typeof FormSchema>>({
defaultValues: values,
resolver: zodResolver(FormSchema),
});
const outputFormat = form.watch('output_format');
- const formOutputs = form.watch('outputs');
- const supportsDocumentDecorations =
- outputFormat === 'pdf' || outputFormat === 'docx';
-
- const supportsTimestamp =
- outputFormat === 'pdf' ||
- outputFormat === 'docx' ||
- outputFormat === 'txt' ||
- outputFormat === 'markdown' ||
- outputFormat === 'html';
+ const formatFeatures = DocGeneratorFormatFeatures[outputFormat];
+ const supportsDocumentDecorations = formatFeatures.decorations;
+ const supportsTimestamp = formatFeatures.timestamp;
const outputList = useMemo(() => {
- return transferOutputs(formOutputs ?? values.outputs);
- }, [formOutputs, values.outputs]);
-
- useEffect(() => {
- form.setValue('outputs', values.outputs);
- }, [form, values.outputs]);
+ return transferOutputs(values.outputs);
+ }, [values.outputs]);
useWatchFormChange(node?.id, form);
@@ -78,203 +67,71 @@ function DocGeneratorForm({ node }: INextOperatorForm) {
<Form {...form}>
<FormWrapper>
<FormContainer>
- <FormField
- control={form.control}
- name="output_format"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Output Format</FormLabel>
- <FormControl>
- <SelectWithSearch
- {...field}
- options={[
- { label: 'PDF', value: 'pdf' },
- { label: 'DOCX', value: 'docx' },
- { label: 'TXT', value: 'txt' },
- { label: 'Markdown', value: 'markdown' },
- { label: 'HTML', value: 'html' },
- ]}
- ></SelectWithSearch>
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="content"
- render={({ field }) => (
- <FormItem>
- <FormLabel>{t('flow.content')}</FormLabel>
- <FormControl>
- <PromptEditor
- {...field}
- showToolbar={true}
- placeholder="Enter markdown content..."
- ></PromptEditor>
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
+ <RAGFlowFormItem label={t('flow.outputFormat')} name="output_format">
+ <SelectWithSearch
+ options={DocGeneratorFormatOptions}
+ ></SelectWithSearch>
+ </RAGFlowFormItem>
+
+ <RAGFlowFormItem label={t('flow.content')} name="content">
+ <PromptEditor
+ showToolbar={true}
+ placeholder={t('flow.contentPlaceholder')}
+ ></PromptEditor>
+ </RAGFlowFormItem>
+
+ <SwitchFormField
+ vertical={false}
+ label={t('flow.includeDownloadInfoInContent')}
name="include_download_info_in_content"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between gap-4">
- <div className="space-y-1">
- <FormLabel>
- {t(
- 'flow.includeDownloadInfoInContent',
- 'Append download info to content',
- )}
- </FormLabel>
- </div>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
/>
- <FormField
- control={form.control}
- name="filename"
- render={({ field }) => (
- <FormItem>
- <FormLabel>{t('flow.filename')}</FormLabel>
- <FormControl>
- <Input
- {...field}
- placeholder="document.ext (auto-generated if empty)"
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
+ <RAGFlowFormItem label={t('flow.filename')} name="filename">
+ <Input placeholder={t('flow.filenamePlaceholder')}></Input>
+ </RAGFlowFormItem>
{supportsDocumentDecorations && (
<>
- <FormField
- control={form.control}
- name="font_size"
- render={({ field }) => (
- <FormItem>
- <FormLabel>{t('flow.fontSize')}</FormLabel>
- <FormControl>
- <Input
- {...field}
- type="number"
- min={12}
- onChange={(e) => field.onChange(e.target.value)}
- onBlur={(e) => {
- field.onBlur();
- const value = Number(e.target.value);
- field.onChange(
- Number.isFinite(value) && value >= 12 ? value : 12,
- );
- }}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="header"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Header Text</FormLabel>
- <FormControl>
- <Input {...field} placeholder="Header text" />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="footer"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Footer Text</FormLabel>
- <FormControl>
- <Input {...field} placeholder="Footer text" />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- {outputFormat === 'pdf' && (
- <FormField
- control={form.control}
- name="watermark"
- render={({ field }) => (
- <FormItem>
- <FormLabel>{t('flow.watermarkText')}</FormLabel>
- <FormControl>
- <Input {...field} placeholder="Watermark text" />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
+ <RAGFlowFormItem label={t('flow.fontSize')} name="font_size">
+ {(field) => <NumberInput min={12} {...field}></NumberInput>}
+ </RAGFlowFormItem>
+
+ <RAGFlowFormItem label={t('flow.headerText')} name="header_text">
+ <Input placeholder={t('flow.headerText')}></Input>
+ </RAGFlowFormItem>
+
+ <RAGFlowFormItem label={t('flow.footerText')} name="footer_text">
+ <Input placeholder={t('flow.footerText')}></Input>
+ </RAGFlowFormItem>
+
+ {outputFormat === DocGeneratorOutputFormat.Pdf && (
+ <RAGFlowFormItem
+ label={t('flow.watermarkText')}
+ name="watermark_text"
+ >
+ <Input placeholder={t('flow.watermarkText')}></Input>
+ </RAGFlowFormItem>
)}
- <FormField
- control={form.control}
+ <SwitchFormField
+ vertical={false}
+ label={t('flow.addPageNumbers')}
name="add_page_numbers"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between">
- <FormLabel>{t('flow.addPageNumbers')}</FormLabel>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
/>
</>
)}
{supportsTimestamp && (
- <FormField
- control={form.control}
+ <SwitchFormField
+ vertical={false}
+ label={t('flow.addTimestamp')}
name="add_timestamp"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between">
- <FormLabel>{t('flow.addTimestamp')}</FormLabel>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
/>
)}
-
- <FormField
- control={form.control}
- name="outputs"
- render={() => <div></div>}
- />
</FormContainer>
</FormWrapper>
<div className="p-5">
- <Output list={outputList}></Output>
+ <Output list={outputList} isFormRequired></Output>
</div>
</Form>
);
diff --git a/web/src/pages/agent/form/doc-generator-form/use-values.ts b/web/src/pages/agent/form/doc-generator-form/use-values.ts
index 93ee15c2fb..d0e7100391 100644
--- a/web/src/pages/agent/form/doc-generator-form/use-values.ts
+++ b/web/src/pages/agent/form/doc-generator-form/use-values.ts
@@ -1,26 +1,22 @@
import { type Node } from '@xyflow/react';
import { useMemo } from 'react';
+import { DocGeneratorOutputFormat } from '../../constant/doc-generator';
import { initialDocGeneratorValues } from '../../constant';
export const useValues = (node?: Node) => {
const values = useMemo(() => {
- const supportedOutputFormats = ['pdf', 'docx', 'txt', 'markdown', 'html'];
const nextValues = {
...initialDocGeneratorValues,
...(node?.data.form ?? {}),
};
return {
- output_format: supportedOutputFormats.includes(nextValues.output_format)
+ ...nextValues,
+ output_format: (
+ Object.values(DocGeneratorOutputFormat) as string[]
+ ).includes(nextValues.output_format)
? nextValues.output_format
: initialDocGeneratorValues.output_format,
- content: nextValues.content,
- filename: nextValues.filename,
- header_text: nextValues.header_text,
- footer_text: nextValues.footer_text,
- watermark_text: nextValues.watermark_text,
- add_page_numbers: nextValues.add_page_numbers,
- add_timestamp: nextValues.add_timestamp,
include_download_info_in_content:
nextValues.include_download_info_in_content ?? false,
font_size: Math.max(12, Number(nextValues.font_size) || 12),
diff --git a/web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx b/web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx
index e8baeea6f9..8992e255f4 100644
--- a/web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx
+++ b/web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx
@@ -6,7 +6,7 @@ import { MetadataFilter } from '@/components/metadata-filter';
import { RerankCandidatesCountFormField } from '@/components/rerank-candidates-count-item';
import { RerankFormFields } from '@/components/rerank';
import { SimilaritySliderFormField } from '@/components/similarity-slider';
-import { SwitchFormField } from '@/components/switch-fom-field';
+import { SwitchFormField } from '@/components/switch-form-field';
import { TopNFormField } from '@/components/top-n-item';
import {
FormControl,
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 0f6a63e5cd..7d49ccbc56 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
@@ -16,7 +16,7 @@
import { SelectWithSearch } from '@/components/originui/select-with-search';
import { RAGFlowFormItem } from '@/components/ragflow-form';
-import { SwitchFormField } from '@/components/switch-fom-field';
+import { SwitchFormField } from '@/components/switch-form-field';
import { Input } from '@/components/ui/input';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Textarea } from '@/components/ui/textarea';
diff --git a/web/src/pages/user-setting/compilation-templates/edit-next/components/tree-template-fields.tsx b/web/src/pages/user-setting/compilation-templates/edit-next/components/tree-template-fields.tsx
index 0fb04ebe83..b99eab78b8 100644
--- a/web/src/pages/user-setting/compilation-templates/edit-next/components/tree-template-fields.tsx
+++ b/web/src/pages/user-setting/compilation-templates/edit-next/components/tree-template-fields.tsx
@@ -17,7 +17,7 @@
import { Collapse } from '@/components/collapse';
import { RAGFlowFormItem } from '@/components/ragflow-form';
import { SliderInputFormField } from '@/components/slider-input-form-field';
-import { SwitchFormField } from '@/components/switch-fom-field';
+import { SwitchFormField } from '@/components/switch-form-field';
import { Textarea } from '@/components/ui/textarea';
import { useTranslation } from 'react-i18next';