Skip to content

Feat: Add a prefix to the name of the FormField associated with the chat. - #16178

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
cike8899:fix-search-required
Jun 22, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
cike8899:fix-search-required

Conversation

@cike8899

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Fix: Add a prefix to the name of the FormField associated with the chat.

Type of change

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 18, 2026
@cike8899 cike8899 added the ci Continue Integration label Jun 18, 2026
@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a prefixName(prefix, name) utility to form.ts and refactors RerankFormFields, TopNFormField, DynamicVariableForm, ChatBasicSetting, and ChatPromptEngine to accept optional prefix/name props. All react-hook-form field bindings in these components are updated to use prefixName-generated paths, enabling namespaced form field registration.

Changes

Prefix-namespaced form fields across chat app settings

Layer / File(s) Summary
prefixName utility
web/src/utils/form.ts
Exports prefixName(prefix, name) which concatenates prefix and name, documented with JSDoc examples.
Shared form component parameterization
web/src/components/rerank.tsx, web/src/components/top-n-item.tsx, web/src/pages/next-chats/chat/app-settings/dynamic-variable.tsx
RerankFormField/RerankFormFields gain DefaultRerankId/DefaultTopK constants and prefix-aware props; rerankFormSchema uses computed keys. TopNFormField adds an optional name prop forwarded to SliderInputFormField. DynamicVariableForm replaces a hard-coded name constant with an optional name prop defaulting to 'prompt_config.parameters'.
Chat settings pages wired to prefix props
web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx, web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx
ChatBasicSetting and ChatPromptEngine each gain an optional prefix prop; all react-hook-form field names, useEffect reads/writes, toggle handlers, and child component props are updated to use prefixName(prefix, ...).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A rabbit hops through form fields wide,
With prefix prop as trusted guide,
Each field name grown from one small root—
prefixName sprouts like a carrot shoot!
No hard-coded string left behind,
Reusable forms for every mind 🐇✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is incomplete; it lacks the required background context explaining why this prefix feature is needed and the implementation rationale. Add background context explaining the business/technical reason for adding prefix support and how this enables the desired functionality or flexibility.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: adding prefix support to form field names in chat-related components.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cike8899
cike8899 marked this pull request as draft June 18, 2026 05:46
@cike8899
cike8899 marked this pull request as ready for review June 18, 2026 05:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx (1)

27-27: ⚡ Quick win

Use useTranslation directly here.

This updated component still uses the wrapper hook instead of useTranslation.

As per coding guidelines, "Prefer useTranslation from react-i18next over project-wrapped utilities like useTranslate for i18n in React components".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx` at line
27, Replace the useTranslate wrapper hook with the useTranslation hook directly
from react-i18next. In the line where useTranslate is called with the 'chat'
namespace, remove the useTranslate function call and import useTranslation from
react-i18next instead, passing the namespace as an optional parameter to
useTranslation if needed.

Source: Coding guidelines

web/src/components/top-n-item.tsx (1)

19-19: ⚡ Quick win

Prefer useTranslation in TopNFormField.

Switch this component from useTranslate to useTranslation to align with the frontend i18n guideline.

As per coding guidelines, "Prefer useTranslation from react-i18next over project-wrapped utilities like useTranslate for i18n in React components".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/components/top-n-item.tsx` at line 19, The TopNFormField component is
currently using the project-wrapped useTranslate utility instead of the standard
useTranslation hook from react-i18next. Replace the useTranslate import and hook
call with useTranslation from react-i18next, removing the namespace parameter
'chat' and instead accessing translations through the returned t function with
namespace-prefixed keys, or adjust the component to align with the established
i18n pattern used elsewhere in the frontend codebase.

Source: Coding guidelines

web/src/utils/form.ts (1)

77-79: ⚡ Quick win

Normalize separator handling in prefixName to avoid malformed form paths.

prefixName currently assumes prefix already includes the trailing .. If a caller passes chat instead of chat., the resulting key becomes chaticon, which silently binds the wrong field.

♻️ Proposed fix
 export function prefixName(prefix: string, name: string): string {
-  return `${prefix}${name}`;
+  if (!prefix) return name;
+  if (prefix.endsWith('.')) return `${prefix}${name}`;
+  return `${prefix}.${name}`;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/utils/form.ts` around lines 77 - 79, The prefixName function
currently assumes the prefix already includes a trailing dot separator, which
causes malformed form paths when callers pass a prefix without a dot (e.g.,
`chat` instead of `chat.`). Fix this by modifying the prefixName function to
normalize the separator handling: ensure the prefix ends with a dot if it
doesn't already, and ensure the name doesn't start with a dot to avoid double
dots, then concatenate them properly to guarantee correct form field paths
regardless of how the caller formats the input.
web/src/components/rerank.tsx (1)

30-33: ⚡ Quick win

Use useTranslation instead of useTranslate in these React components.

Both updated components still use the wrapper hook; switch to useTranslation directly for i18n consistency in this layer.

As per coding guidelines, "Prefer useTranslation from react-i18next over project-wrapped utilities like useTranslate for i18n in React components".

Also applies to: 65-68

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/components/rerank.tsx` around lines 30 - 33, Replace the
`useTranslate` hook with `useTranslation` from the `react-i18next` library in
the RerankFormField function and the other component mentioned at line 65-68.
Instead of calling useTranslate with a namespace parameter like
useTranslate('knowledgeDetails'), call useTranslation with the namespace and
destructure the t function from the returned object. This ensures consistency
with i18n implementation guidelines by using the native react-i18next hook
directly rather than the project-wrapped utility.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx`:
- Around line 24-26: The `ChatBasicSetting` component has a hardcoded
`llmId="llm_id"` prop that bypasses the namespace prefix mechanism, causing
`llm_id` to write to the root level instead of under the `llm_setting.*`
namespace like other fields. Fix this by either dynamically setting `llmId` to
use the `prefix` parameter (e.g., `llmId={`${prefix}.llm_id`}`) or removing the
prop entirely to let the `LlmSettingFieldItems` component's `getFieldWithPrefix`
utility handle the namespacing automatically, consistent with how it's done in
`search-setting.tsx`.

In `@web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx`:
- Around line 130-135: The TavilyFormField and MetadataFilter components in the
form section are not receiving the prefix prop like TOCEnhanceFormField does,
causing them to read/write form values at the root level instead of within the
namespaced prefix structure. Pass the prefix prop to both TavilyFormField and
MetadataFilter components, using the prefixName pattern with the appropriate
field names to ensure they operate within the same namespaced context as the
other form fields in this section.

---

Nitpick comments:
In `@web/src/components/rerank.tsx`:
- Around line 30-33: Replace the `useTranslate` hook with `useTranslation` from
the `react-i18next` library in the RerankFormField function and the other
component mentioned at line 65-68. Instead of calling useTranslate with a
namespace parameter like useTranslate('knowledgeDetails'), call useTranslation
with the namespace and destructure the t function from the returned object. This
ensures consistency with i18n implementation guidelines by using the native
react-i18next hook directly rather than the project-wrapped utility.

In `@web/src/components/top-n-item.tsx`:
- Line 19: The TopNFormField component is currently using the project-wrapped
useTranslate utility instead of the standard useTranslation hook from
react-i18next. Replace the useTranslate import and hook call with useTranslation
from react-i18next, removing the namespace parameter 'chat' and instead
accessing translations through the returned t function with namespace-prefixed
keys, or adjust the component to align with the established i18n pattern used
elsewhere in the frontend codebase.

In `@web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx`:
- Line 27: Replace the useTranslate wrapper hook with the useTranslation hook
directly from react-i18next. In the line where useTranslate is called with the
'chat' namespace, remove the useTranslate function call and import
useTranslation from react-i18next instead, passing the namespace as an optional
parameter to useTranslation if needed.

In `@web/src/utils/form.ts`:
- Around line 77-79: The prefixName function currently assumes the prefix
already includes a trailing dot separator, which causes malformed form paths
when callers pass a prefix without a dot (e.g., `chat` instead of `chat.`). Fix
this by modifying the prefixName function to normalize the separator handling:
ensure the prefix ends with a dot if it doesn't already, and ensure the name
doesn't start with a dot to avoid double dots, then concatenate them properly to
guarantee correct form field paths regardless of how the caller formats the
input.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: abc8aad6-b586-4f33-b085-5fcdfb101b45

📥 Commits

Reviewing files that changed from the base of the PR and between a902152 and c3175a0.

📒 Files selected for processing (6)
  • web/src/components/rerank.tsx
  • web/src/components/top-n-item.tsx
  • web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx
  • web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx
  • web/src/pages/next-chats/chat/app-settings/dynamic-variable.tsx
  • web/src/utils/form.ts

Comment on lines +24 to +26
export default function ChatBasicSetting({
prefix = '',
}: ChatBasicSettingProps) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Locate llm-setting-items implementation:"
fd -i "llm-setting-items" web/src/components

echo
echo "Inspect LlmSettingFieldItems props and internal field-name construction:"
rg -n -C3 "export (function|const) LlmSettingFieldItems|interface .*LlmSettingFieldItems|type .*LlmSettingFieldItems|prefix|llmId|FormField|RAGFlowFormItem|name=" web/src/components/llm-setting-items

echo
echo "Inspect all usages for prefixed vs fixed-name patterns:"
rg -n -C2 "LlmSettingFieldItems" web/src

Repository: infiniflow/ragflow

Length of output: 21411


The llmId prop in chat-basic-settings.tsx line 43 should also be namespaced.

LlmSettingFieldItems does use the prefix parameter correctly for all field bindings through its getFieldWithPrefix utility (lines 97–102 in next.tsx). However, the hardcoded llmId="llm_id" prop overrides this mechanism and writes to the root llm_id key, while all other settings fields (temperature, top_p, penalties, max_tokens) write under llm_setting.*.

This creates a data integrity issue with mixed namespaces. Change line 43 to llmId={${prefix}.llm_id} or omit the prop entirely to let getFieldWithPrefix apply automatically, matching the pattern used in search-setting.tsx line 520.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx` around
lines 24 - 26, The `ChatBasicSetting` component has a hardcoded `llmId="llm_id"`
prop that bypasses the namespace prefix mechanism, causing `llm_id` to write to
the root level instead of under the `llm_setting.*` namespace like other fields.
Fix this by either dynamically setting `llmId` to use the `prefix` parameter
(e.g., `llmId={`${prefix}.llm_id`}`) or removing the prop entirely to let the
`LlmSettingFieldItems` component's `getFieldWithPrefix` utility handle the
namespacing automatically, consistent with how it's done in
`search-setting.tsx`.

Comment on lines +130 to 135
<TOCEnhanceFormField
name={prefixName(prefix, 'prompt_config.toc_enhance')}
></TOCEnhanceFormField>
<TavilyFormField></TavilyFormField>
<MetadataFilter></MetadataFilter>
<FormField

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Prefix propagation is incomplete for TavilyFormField and MetadataFilter.

This refactor namespaces most form fields, but these two children are still mounted with root defaults. In non-empty prefix mode, they read/write different keys than the rest of the section.

🐛 Proposed fix
-        <TavilyFormField></TavilyFormField>
-        <MetadataFilter></MetadataFilter>
+        <TavilyFormField
+          name={prefixName(prefix, 'prompt_config.tavily_api_key')}
+        ></TavilyFormField>
+        <MetadataFilter prefix={prefix}></MetadataFilter>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<TOCEnhanceFormField
name={prefixName(prefix, 'prompt_config.toc_enhance')}
></TOCEnhanceFormField>
<TavilyFormField></TavilyFormField>
<MetadataFilter></MetadataFilter>
<FormField
<TOCEnhanceFormField
name={prefixName(prefix, 'prompt_config.toc_enhance')}
></TOCEnhanceFormField>
<TavilyFormField
name={prefixName(prefix, 'prompt_config.tavily_api_key')}
></TavilyFormField>
<MetadataFilter prefix={prefix}></MetadataFilter>
<FormField
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx` around
lines 130 - 135, The TavilyFormField and MetadataFilter components in the form
section are not receiving the prefix prop like TOCEnhanceFormField does, causing
them to read/write form values at the root level instead of within the
namespaced prefix structure. Pass the prefix prop to both TavilyFormField and
MetadataFilter components, using the prefixName pattern with the appropriate
field names to ensure they operate within the same namespaced context as the
other form fields in this section.

@wangq8
wangq8 merged commit c849c76 into infiniflow:main Jun 22, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 24, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants