Repository navigation
Feat: Add a prefix to the name of the FormField associated with the chat. - #16178
Conversation
📝 WalkthroughWalkthroughAdds a ChangesPrefix-namespaced form fields across chat app settings
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx (1)
27-27: ⚡ Quick winUse
useTranslationdirectly here.This updated component still uses the wrapper hook instead of
useTranslation.As per coding guidelines, "Prefer
useTranslationfromreact-i18nextover project-wrapped utilities likeuseTranslatefor 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 winPrefer
useTranslationinTopNFormField.Switch this component from
useTranslatetouseTranslationto align with the frontend i18n guideline.As per coding guidelines, "Prefer
useTranslationfromreact-i18nextover project-wrapped utilities likeuseTranslatefor 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 winNormalize separator handling in
prefixNameto avoid malformed form paths.
prefixNamecurrently assumesprefixalready includes the trailing.. If a caller passeschatinstead ofchat., the resulting key becomeschaticon, 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 winUse
useTranslationinstead ofuseTranslatein these React components.Both updated components still use the wrapper hook; switch to
useTranslationdirectly for i18n consistency in this layer.As per coding guidelines, "Prefer
useTranslationfromreact-i18nextover project-wrapped utilities likeuseTranslatefor 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
📒 Files selected for processing (6)
web/src/components/rerank.tsxweb/src/components/top-n-item.tsxweb/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsxweb/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsxweb/src/pages/next-chats/chat/app-settings/dynamic-variable.tsxweb/src/utils/form.ts
| export default function ChatBasicSetting({ | ||
| prefix = '', | ||
| }: ChatBasicSettingProps) { |
There was a problem hiding this comment.
🧩 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/srcRepository: 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`.
| <TOCEnhanceFormField | ||
| name={prefixName(prefix, 'prompt_config.toc_enhance')} | ||
| ></TOCEnhanceFormField> | ||
| <TavilyFormField></TavilyFormField> | ||
| <MetadataFilter></MetadataFilter> | ||
| <FormField |
There was a problem hiding this comment.
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.
| <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.
What problem does this PR solve?
Fix: Add a prefix to the
nameof theFormFieldassociated with the chat.Type of change