Repository navigation
refactor(setting-model): migrate SoMark to generic provider card withmodel-level extra fields - #17582
Conversation
… model-level extra fields Remove the standalone SoMarkInstanceCard (722 lines) and route SoMark through the generic GenericProviderInstanceCard path. SoMark-specific fields (4 element-format selects + 7 feature-config toggles) are now edited in the model edit dialog (AddCustomModelDialog) and stored per-model in model_info[].extra.
📝 WalkthroughWalkthroughSoMark is routed through generic instance cards and provider configuration. Its model dialog gains provider-specific fields and format translations, while model ChangesSoMark model configuration
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant ModelDialog
participant ModelHooks
participant InstanceModelAPI
User->>ModelDialog: edit provider model fields
ModelDialog->>ModelHooks: submit features and extra
ModelHooks->>InstanceModelAPI: add or patch instance model
InstanceModelAPI-->>ModelHooks: return persisted model extra
ModelHooks-->>ModelDialog: populate future edit defaults
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
wangq8
left a comment
There was a problem hiding this comment.
Nice refactoring — removing 722 lines of SoMark-specific card code and routing through the generic path is the right direction. The new select/switch/section field types in AddCustomModelDialog make this pattern reusable for future providers too. A few points to address:
1. 🔴 Commented-out startRename() in saved-mode-card.tsx
onDoubleClick={(e) => {
e.stopPropagation();
// startRename();
}}The title still says editInstanceName, but double-clicking now does nothing useful (just stopPropagation). If rename is being intentionally disabled:
- Remove the
onDoubleClickhandler and thetitleattribute entirely - If the function/state for rename is no longer used, clean up the related code too
If this is accidental, restore startRename().
2. 🟡 Dialog width change affects all providers
max-w-md → max-w-2xl widens the add/edit model dialog for every provider, not just SoMark. For simple providers with only name/max_tokens/model_types/features, the dialog is now unnecessarily wide. Consider making the width conditional on whether providerFeatureKeys is provided (or compute a max-w class via className prop).
3. 🟡 SoMark model_types no longer defaults to [ocr]
The legacy SoMarkInstanceCard hardcoded model_type: [ocr] in buildPayload. Now users must manually select "OCR" from the model_types multi-select, with no default. This is a silent behavior change:
// In useCustomModelFields — consider adding a SoMark-specific default:
if (isSoMark && field.name === model_types) {
mapped.defaultValue = [ocr];
}Or alternatively, accept defaultValues override from the caller.
4. 🟢 Minor: Spelling in comment
/** Whitelist of provider-specific feature keys ... */
// ^^Convention in the codebase has been "allowlist" — not a blocker, just consistency.
5. 🟢 Edit dialog features reconstruction looks correct
The editDefaultValues logic that rebuilds the features array from extra booleans (matching is_tools + providerFeatureKeys) and the handleEditSubmit optimistic cache patch that properly separates is_tools from item.extra — both look correct. The draft edit path (updateDraftModel instead of PATCH) is also handled well.
6. 🟢 Data shape backward compatibility
Existing SoMark instances store somark_* fields as booleans in model_info[0].extra. The new approach stores them the same way (via item.extra in handleSubmit), so no migration is needed. buildModelInfo and useModelsDerived correctly propagate extra through the echo path. ✅
Summary: Good refactor, just the 3 flagged items to address. The rename regression (#1) is the most impactful — it effectively breaks the inline rename UX for ALL saved instance cards.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts (1)
81-87: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract a shared
extramerge helper; make computedis_toolswin defensively.The pattern
{ is_tools: hasToolFeature(features), ...(x.extra ?? {}) }is repeated across five call sites. It currently relies on two invariants holding everywhere (freshly-submittedextranever carriesis_tools; backend always co-derives the flat and nestedis_tools) to avoid the spread silently overriding the freshly computed flag. Centralizing this into one helper — alongside the existinghasToolFeature/normalizeModelTypespure helpers — removes the duplication and future-proofs the order so a later change to either invariant can't silently reintroduce a staleis_tools.♻️ Proposed helper and usage
+/** Merge a model's features/extra into the `extra` payload sent to the + * backend, with the freshly computed `is_tools` always taking precedence + * over any (unexpected) `is_tools` key in the persisted `extra` blob. */ +export const buildExtraPayload = ( + features: string[] | null | undefined, + extra: Record<string, any> | undefined, +): Record<string, any> => ({ + ...(extra ?? {}), + is_tools: hasToolFeature(features), +});Then replace each occurrence, e.g.:
- extra: { is_tools: hasToolFeature(m.features), ...(m.extra ?? {}) }, + extra: buildExtraPayload(m.features, m.extra),Also applies to: 649-656, 689-696, 860-868, 873-880
🤖 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/user-setting/setting-model/instance-card/models-section/hooks.ts` around lines 81 - 87, Extract a shared pure helper alongside hasToolFeature and normalizeModelTypes to merge model extra data while always preserving the freshly computed is_tools value. Update buildModelInfo and the four other repeated merge sites to use this helper, ensuring extra cannot override the computed flag.web/src/pages/user-setting/setting-model/hooks.tsx (1)
146-150: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the unused
useSubmitBedrockcompatibility hook.
useSubmitBedrockand its Bedrock adding modal helpers are only referenced inhooks.tsx, so keeping them labeled as backward-compat references retains dead code. Drop the legacy hook, modal state bindings, and compatibility comment.🤖 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/user-setting/setting-model/hooks.tsx` around lines 146 - 150, Remove the unused useSubmitBedrock hook and its Bedrock adding-modal helper/state bindings from hooks.tsx, including the surrounding backward-compatibility comment. Leave unrelated retained modal hooks and current inline BedrockInstanceCard behavior unchanged.Source: Coding guidelines
web/src/pages/user-setting/setting-model/instance-card/use-custom-model-fields.tsx (1)
72-159: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUnused
somark.sectionFeatureConfiglocale key — missing section header for the feature toggles.
SOMARK_EXTRA_FIELDSadds a'section'field forsomark.sectionElementFormatsbefore the format selects, but there's no equivalent section field forsomark.sectionFeatureConfigbefore thefeaturesswitch-group (which currently only shows the generic "Model features" label). ThesectionFeatureConfigkey is already defined inen.ts/zh.tsand appears intended for exactly this grouping.💡 Suggested fix
export const MODEL_FIELD_SCHEMA: AddCustomModelDialogFields[] = [ { name: 'name', ... }, { name: 'model_types', ... }, { name: 'max_tokens', ... }, + { + name: 'featureConfig', + label: 'somark.sectionFeatureConfig', + type: 'section', + }, { name: 'features', label: 'modelFeatures', ... }, ];Note: adding this unconditionally to
MODEL_FIELD_SCHEMAwould show the section header for all providers; consider instead overridingfield.labeltot('somark.sectionFeatureConfig')whenisSoMark && field.name === 'features', or appending a dedicated section field only in theisSoMarkbranch.🤖 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/user-setting/setting-model/instance-card/use-custom-model-fields.tsx` around lines 72 - 159, Update the SoMark-specific schema construction around SOMARK_EXTRA_FIELDS and the features field so the SoMark provider displays a section header using somark.sectionFeatureConfig before the feature toggles. Apply this only when isSoMark, such as by overriding the features field label or inserting a conditional section field; preserve the generic Model features label for other providers.
🤖 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/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx`:
- Around line 341-368: Update the dialog layout around DynamicForm.Root and
DialogFooter so the footer is not an absolutely positioned descendant of the
max-h-[70vh] overflow-y-auto wrapper. Move DialogFooter outside the scroll
container or make it a non-absolute sticky footer, preserving visible and
clickable Save/Cancel controls without relying on the mb-12 workaround for long
forms.
In
`@web/src/pages/user-setting/setting-model/instance-card/components/saved-mode-card.tsx`:
- Around line 166-170: Remove the obsolete rename flow from the component
containing the onDoubleClick handler: delete the local rename state,
startRename-related handlers, rename input branch, and commented-out startRename
call. Remove or update the stale editInstanceName title so the card reflects its
remaining behavior without dead or misleading rename code.
---
Nitpick comments:
In `@web/src/pages/user-setting/setting-model/hooks.tsx`:
- Around line 146-150: Remove the unused useSubmitBedrock hook and its Bedrock
adding-modal helper/state bindings from hooks.tsx, including the surrounding
backward-compatibility comment. Leave unrelated retained modal hooks and current
inline BedrockInstanceCard behavior unchanged.
In
`@web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts`:
- Around line 81-87: Extract a shared pure helper alongside hasToolFeature and
normalizeModelTypes to merge model extra data while always preserving the
freshly computed is_tools value. Update buildModelInfo and the four other
repeated merge sites to use this helper, ensuring extra cannot override the
computed flag.
In
`@web/src/pages/user-setting/setting-model/instance-card/use-custom-model-fields.tsx`:
- Around line 72-159: Update the SoMark-specific schema construction around
SOMARK_EXTRA_FIELDS and the features field so the SoMark provider displays a
section header using somark.sectionFeatureConfig before the feature toggles.
Apply this only when isSoMark, such as by overriding the features field label or
inserting a conditional section field; preserve the generic Model features label
for other providers.
🪄 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 Plus
Run ID: 1af034ad-01ff-4455-816a-a8d93657b6e1
📒 Files selected for processing (16)
web/src/interfaces/database/llm.tsweb/src/interfaces/request/llm.tsweb/src/locales/en.tsweb/src/locales/zh.tsweb/src/pages/user-setting/setting-model/hooks.tsxweb/src/pages/user-setting/setting-model/index.tsxweb/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsxweb/src/pages/user-setting/setting-model/instance-card/components/saved-mode-card.tsxweb/src/pages/user-setting/setting-model/instance-card/interface.tsweb/src/pages/user-setting/setting-model/instance-card/models-section/hooks.tsweb/src/pages/user-setting/setting-model/instance-card/models-section/index.tsxweb/src/pages/user-setting/setting-model/instance-card/provider-instance-card.tsxweb/src/pages/user-setting/setting-model/instance-card/somark-instance-card.tsxweb/src/pages/user-setting/setting-model/instance-card/use-custom-model-fields.tsxweb/src/pages/user-setting/setting-model/provider-schema/constants.tsweb/src/pages/user-setting/setting-model/provider-schema/field-config/provider-config-map.ts
💤 Files with no reviewable changes (2)
- web/src/pages/user-setting/setting-model/instance-card/provider-instance-card.tsx
- web/src/pages/user-setting/setting-model/instance-card/somark-instance-card.tsx
| <DialogContent className="max-w-2xl" onClick={(e) => e.stopPropagation()}> | ||
| <DialogHeader> | ||
| <DialogTitle>{title}</DialogTitle> | ||
| </DialogHeader> | ||
|
|
||
| <DynamicForm.Root | ||
| ref={formRef} | ||
| fields={dynamicFields} | ||
| onSubmit={handleSubmit} | ||
| defaultValues={defaultValues} | ||
| > | ||
| <DialogFooter className="mb-0 pb-0"> | ||
| <Button | ||
| type="button" | ||
| variant="outline" | ||
| onClick={() => onOpenChange(false)} | ||
| disabled={loading} | ||
| > | ||
| {cancelText ?? t('cancel')} | ||
| </Button> | ||
| <Button type="submit" disabled={loading}> | ||
| {loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />} | ||
| {submitText ?? commonT('confirm')} | ||
| </Button> | ||
| </DialogFooter> | ||
| </DynamicForm.Root> | ||
| <div className=" max-h-[70vh] overflow-y-auto mb-12"> | ||
| <DynamicForm.Root | ||
| ref={formRef} | ||
| fields={dynamicFields} | ||
| onSubmit={handleSubmit} | ||
| defaultValues={defaultValues} | ||
| className="pr-2 pb-2" | ||
| > | ||
| <DialogFooter className="absolute bottom-5 right-5 left-0 mb-0 pb-0"> | ||
| <Button | ||
| type="button" | ||
| variant="outline" | ||
| onClick={() => onOpenChange(false)} | ||
| disabled={loading} | ||
| > | ||
| {cancelText ?? t('cancel')} | ||
| </Button> | ||
| <Button type="submit" disabled={loading}> | ||
| {loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />} | ||
| {submitText ?? commonT('confirm')} | ||
| </Button> | ||
| </DialogFooter> | ||
| </DynamicForm.Root> | ||
| </div> |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Inspect DialogContent's positioning and DynamicForm.Root's rendering structure
# to confirm the containing-block/overflow assumptions behind the absolute-positioned footer.
rg -n "DialogContent" -A 25 web/src/components/ui/dialog.tsx
fd -i "dynamic-form" web/src/components
rg -n "Root" -A 40 web/src/components/dynamic-form -g "*.tsx" | head -100Repository: infiniflow/ragflow
Length of output: 2594
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== candidate files =="
fd -i 'add-custom-model-dialog\.tsx|dynamic.*form.*\.ts|dynamic.*form.*\.tsx|constants.*form.*\.ts|constants.*form.*\.tsx|schema.*so|so.*schema.*\.ts' web/src
echo
echo "== target file outline/size =="
wc -l web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx
ast-grep outline web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx --view compact | sed -n '1,200p'
echo
echo "== relevant target lines 300-390 =="
sed -n '300,390p' web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx
echo
echo "== DynamicForm definitions =="
rg -n "DynamicForm|const DynamicForm|export .*DynamicForm|Root as|Root =" web/src -g '*.ts' -g '*.tsx' | head -200
rg -n "function.*Root|const Root|export .*default|export default" web/src/pages/user-setting/setting-model/instance-card -g '*.ts' -g '*.tsx' | head -200
echo
echo "== dynamic form usages and form field count candidates =="
rg -n "dynamicFields|defaultValues|fields=" web/src/pages/user-setting/setting-model/instance-card -g '*.ts' -g '*.tsx' -C 4Repository: infiniflow/ragflow
Length of output: 853
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== target related references =="
rg -n "DynamicForm|dynamicFields|defaultValues|fields=" web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx -C 5
echo
echo "== dynamic-form structure =="
wc -l web/src/components/dynamic-form.tsx
ast-grep outline web/src/components/dynamic-form.tsx --view signatures | sed -n '1,240p'
echo
echo "== dynamic-form implementation slices =="
rg -n "const DynamicForm|DynamicForm\.Root|export .*Root|children|Content.*className|className.*overflow" web/src/components/dynamic-form.tsx -C 8
echo
echo "== relevant target lines 300-372 =="
sed -n '300,372p' web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx
echo
echo "== relevant target lines 1-120 for schema/fields setup =="
sed -n '1,140p' web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx
echo
echo "== relevant target lines 340-368 diff context =="
git diff -- web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx | sed -n '1,220p'Repository: infiniflow/ragflow
Length of output: 12630
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== CSS position/flex context =="
fd -i 'tailwind\.css|app\.css|globals\.css|index\.css' web/src web -e css -x sh -c 'echo "--- $1"; sed -n "1,240p" "$1"' sh {}
echo
echo "== static CSS clipping analysis from source =="
python3 - <<'PY'
from pathlib import Path
import re
files = [
Path("web/src/components/ui/dialog.tsx"),
Path("web/src/components/dynamic-form.tsx"),
Path("web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx"),
]
for p in files:
print(f"--- {p}")
txt = p.read_text(encoding="utf-8", errors="replace")
for i, line in enumerate(txt.splitlines(), 1):
if any(tok in line for tok in ["DialogContent", "DialogFooter", "DynamicForm.Root", "overflow-y-auto", "className=", "bottom-5", "right-5", "left-0", "mb-12"]):
print(f"{i}: {line.strip()}")
PY
echo
echo "== read-only DOM/CSS semantics probe for overflow clipping (does not run repo code) =="
python3 - <<'PY'
# Demonstrates why position:absolute elements can be clipped by overflow ancestors
# even when their offsets are resolved relative to a non-overflow ancestor's box.
# CSS spec: an absolutely-positioned element can be clipped by any ancestor
# with non-visible overflow, independent of its containing block.
print("absolute-positioned descendants are clipped by overflow ancestors before formatting")
PYRepository: infiniflow/ragflow
Length of output: 24434
Avoid clipping the absolute footer inside the scrollable form wrapper.
DialogFooter is an absolutely positioned descendant of the max-h-[70vh] overflow-y-auto wrapper (after DynamicForm.Root outputs the form fields). CSS still clips absolutely positioned descendants for ancestors with non-visible overflow before computing visibility/pointer events, and the mb-12 workaround can still overlap the field area when SoMark’s form exceeds the height. Move the footer outside the scroll container or render it as a non-absolutely positioned sticky/fixed element so Save/Cancel remain visible and clickable for the long form.
🤖 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/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx`
around lines 341 - 368, Update the dialog layout around DynamicForm.Root and
DialogFooter so the footer is not an absolutely positioned descendant of the
max-h-[70vh] overflow-y-auto wrapper. Move DialogFooter outside the scroll
container or make it a non-absolute sticky footer, preserving visible and
clickable Save/Cancel controls without relying on the mb-12 workaround for long
forms.
| onDoubleClick={(e) => { | ||
| e.stopPropagation(); | ||
| startRename(); | ||
| // startRename(); | ||
| }} | ||
| title={tSetting('editInstanceName')} |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Remove the now-dead rename implementation instead of commenting out its entry point.
With startRename() disabled, the local rename state, handlers, input branch, and “edit instance name” title are unreachable or misleading. Delete the obsolete rename path and update the stale comments/title so this component has one clear behavior.
As per coding guidelines: “Treat legacy code as liability rather than a compatibility target; prefer deletion over shims, deprecated branches, wrapper APIs, dual-track migrations, dead tests, commented-out code, stale documentation...”
🤖 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/user-setting/setting-model/instance-card/components/saved-mode-card.tsx`
around lines 166 - 170, Remove the obsolete rename flow from the component
containing the onDoubleClick handler: delete the local rename state,
startRename-related handlers, rename input branch, and commented-out startRename
call. Remove or update the stale editInstanceName title so the card reflects its
remaining behavior without dead or misleading rename code.
Source: Coding guidelines
Summary
refactor(setting-model): migrate SoMark to generic provider card withmodel-level extra fields
Remove the standalone SoMarkInstanceCard (722 lines) and route SoMark
through the generic GenericProviderInstanceCard path. SoMark-specific
fields (4 element-format selects + 7 feature-config toggles) are now
edited in the model edit dialog (AddCustomModelDialog) and stored
per-model in model_info[].extra.