Skip to content

Feat: Add edit model type function - #16029

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
dcc123456:fix/bug-0615
Jun 15, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
dcc123456:fix/bug-0615

Conversation

@dcc123456

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Feat: Add edit model type function

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🧰 typescript Pull requests that update Typescript code labels Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds end-to-end support for editing a custom instance model. A new editInstanceModel REST endpoint (PUT) is wired through the API utility, service layer, and a useEditInstanceModel React Query mutation hook. AddCustomModelDialog gains disabled per-field support and a defaultValues prop. ModelListItem in the used-model settings page is extended with a pencil edit button, truncated type-tag display, and the submit handler calling the new hook.

Changes

Edit Instance Model Feature

Layer / File(s) Summary
API URL, service registration, and request interface
web/src/utils/api.ts, web/src/services/llm-service.ts, web/src/interfaces/request/llm.ts
Adds the editInstanceModel URL-builder for /providers/{provider_name}/instances/{instance_name}/models, registers a PUT method in llmService, and defines IEditInstanceModelRequestBody with model_name and model_type string arrays.
useEditInstanceModel mutation hook
web/src/hooks/use-llm-request.tsx
Adds LLMApiAction.EditInstanceModel enum member and useEditInstanceModel hook that calls the service, shows a success toast, and invalidates instance model, added model, and default model caches.
AddCustomModelDialog edit mode support
web/src/pages/user-setting/setting-model/modal/provider-modal/components/add-custom-model-dialog.tsx
Extends field config with optional disabled, adds defaultValues prop, propagates disabled into switch-group and standard field configs (with onCheckedChange guard), resets form to defaultValues on dialog open, and passes defaultValues to DynamicForm.Root.
ModelListItem edit UI and i18n
web/src/pages/user-setting/setting-model/components/used-model.tsx, web/src/locales/en.ts, web/src/locales/zh.ts
Wires useEditInstanceModel into ModelListItem with memoized edit field definitions (all fields disabled except model_types), truncates displayed type tags to 3+ellipsis, adds a hover-revealed pencil button, mounts AddCustomModelDialog for edit submission, and adds editCustomModelTitle in English and Chinese.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A pencil appears on the model row,
With types trimmed to three (and an ellipsis show),
The PUT finds its path through provider and name,
Default values reset — the form plays the game.
The cache clears its slate, toast says "modified" bright,
A bunny edits models with fluffy delight! ✏️

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete. It duplicates the title instead of explaining the problem, lacks implementation details, and incorrectly marks this new feature as a bug fix. Replace the duplicated title text with a clear problem statement, explain what the edit functionality enables, and correct the type of change to 'New Feature' instead of 'Bug Fix'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main feature added: an edit model type function for custom instance models.
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.

@dcc123456 dcc123456 added the ci Continue Integration label Jun 15, 2026
@dcc123456
dcc123456 marked this pull request as draft June 15, 2026 09:24
@dcc123456
dcc123456 marked this pull request as ready for review June 15, 2026 09:24

@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: 3

🧹 Nitpick comments (1)
web/src/pages/user-setting/setting-model/modal/provider-modal/components/add-custom-model-dialog.tsx (1)

83-85: ⚡ Quick win

Use useTranslation directly in this React component.

This component still uses the project wrapper hook, which diverges from the i18n standard used across React components.

💡 Suggested refactor
-import { useTranslate } from '`@/hooks/common-hooks`';
+import { useTranslation } from 'react-i18next';
@@
-  const { t } = useTranslate('setting');
-  const { t: commonT } = useTranslate('common');
+  const { t } = useTranslation('setting');
+  const { t: commonT } = useTranslation('common');

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/user-setting/setting-model/modal/provider-modal/components/add-custom-model-dialog.tsx`
around lines 83 - 85, Replace the project wrapper `useTranslate` hook calls with
the standard `useTranslation` hook from react-i18next. Change the imports and
update the lines where `const { t } = useTranslate('setting')` and `const { t:
commonT } = useTranslate('common')` are defined to use `useTranslation` with
appropriate namespace parameters instead. This aligns with the i18n standards
being used across React components in the project.

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/hooks/use-llm-request.tsx`:
- Around line 383-385: The invalidateQueries call in the LlmKeys.allModels()
usage does not properly invalidate all cache variants of the models list. The
current query key resolves to a tuple with undefined that misses caches created
with LlmKeys.allModels('<type>') containing specific type parameters. Fix this
by using the root key factory pattern from LlmKeys that will match and
invalidate all allModels cache variants regardless of their type parameter,
ensuring that both unfiltered and filtered model lists get properly invalidated.

In `@web/src/pages/user-setting/setting-model/components/used-model.tsx`:
- Around line 370-379: The Button component with aria-label
'setting.editCustomModelTitle' uses className with `hidden group-hover:flex`
which makes it invisible and non-focusable until hovered. Modify the className
to make the button visible and focusable by default (remove `hidden`), while you
can optionally adjust hover styling to provide visual feedback. This ensures the
button is accessible via keyboard navigation and discoverable on touch devices.
- Around line 337-346: The handleEditSubmit function in used-model.tsx closes
the edit dialog with setEditOpen(false) unconditionally after awaiting
editInstanceModel, which means the dialog closes even when the API mutation
fails. Add proper error handling around the editInstanceModel call: wrap it in a
try-catch block and only call setEditOpen(false) in the success path (either
after the try block or within a conditional that checks for success), so that
failed mutations keep the dialog open and allow the user to see and respond to
any error messages returned by the server.

---

Nitpick comments:
In
`@web/src/pages/user-setting/setting-model/modal/provider-modal/components/add-custom-model-dialog.tsx`:
- Around line 83-85: Replace the project wrapper `useTranslate` hook calls with
the standard `useTranslation` hook from react-i18next. Change the imports and
update the lines where `const { t } = useTranslate('setting')` and `const { t:
commonT } = useTranslate('common')` are defined to use `useTranslation` with
appropriate namespace parameters instead. This aligns with the i18n standards
being used across React components in the project.
🪄 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: 67d67f87-05ef-41a5-9d75-1ee30eb8b847

📥 Commits

Reviewing files that changed from the base of the PR and between f6a2075 and 1927844.

📒 Files selected for processing (8)
  • web/src/hooks/use-llm-request.tsx
  • web/src/interfaces/request/llm.ts
  • web/src/locales/en.ts
  • web/src/locales/zh.ts
  • web/src/pages/user-setting/setting-model/components/used-model.tsx
  • web/src/pages/user-setting/setting-model/modal/provider-modal/components/add-custom-model-dialog.tsx
  • web/src/services/llm-service.ts
  • web/src/utils/api.ts

Comment on lines +383 to +385
queryClient.invalidateQueries({
queryKey: LlmKeys.allModels(),
});

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

Invalidate all allModels cache variants via a root key factory.

queryKey: LlmKeys.allModels() resolves to a tuple including undefined, which can miss caches created with LlmKeys.allModels('<type>'). After edit, filtered model lists can stay stale.

💡 Suggested fix
 export const LlmKeys = {
+  allModelsRoot: () => [LLMApiAction.AllModels] as const,
   availableProviders: () => [LLMApiAction.AvailableProviders] as const,
   addedProviders: () => [LLMApiAction.AddedProviders] as const,
   allModels: (modelType?: string) =>
     [LLMApiAction.AllModels, modelType] as const,
@@
         queryClient.invalidateQueries({
-          queryKey: LlmKeys.allModels(),
+          queryKey: LlmKeys.allModelsRoot(),
         });

As per coding guidelines, “Never write raw queryKey arrays inline in useQuery or invalidateQueries. Always use a query key factory object named {Domain}Keys...” and “carefully compare query keys ... character-for-character” for invalidation correctness.

🤖 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/hooks/use-llm-request.tsx` around lines 383 - 385, The
invalidateQueries call in the LlmKeys.allModels() usage does not properly
invalidate all cache variants of the models list. The current query key resolves
to a tuple with undefined that misses caches created with
LlmKeys.allModels('<type>') containing specific type parameters. Fix this by
using the root key factory pattern from LlmKeys that will match and invalidate
all allModels cache variants regardless of their type parameter, ensuring that
both unfiltered and filtered model lists get properly invalidated.

Source: Coding guidelines

Comment on lines +337 to +346
const handleEditSubmit = useCallback(
async (item: IProviderModelItem) => {
await editInstanceModel({
provider_name: providerName,
instance_name: instanceName,
model_name: [model.name],
model_type: item.model_types ?? [],
});
setEditOpen(false);
},

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

Only close the edit dialog after a successful mutation.

setEditOpen(false) runs even when the API response is non-success, which hides server-side errors and forces the user to reopen the dialog.

💡 Suggested fix
   const handleEditSubmit = useCallback(
     async (item: IProviderModelItem) => {
-      await editInstanceModel({
+      const result = await editInstanceModel({
         provider_name: providerName,
         instance_name: instanceName,
         model_name: [model.name],
         model_type: item.model_types ?? [],
       });
-      setEditOpen(false);
+      if (result?.code === 0) {
+        setEditOpen(false);
+      }
     },
     [editInstanceModel, providerName, instanceName, model.name],
   );
📝 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
const handleEditSubmit = useCallback(
async (item: IProviderModelItem) => {
await editInstanceModel({
provider_name: providerName,
instance_name: instanceName,
model_name: [model.name],
model_type: item.model_types ?? [],
});
setEditOpen(false);
},
const handleEditSubmit = useCallback(
async (item: IProviderModelItem) => {
const result = await editInstanceModel({
provider_name: providerName,
instance_name: instanceName,
model_name: [model.name],
model_type: item.model_types ?? [],
});
if (result?.code === 0) {
setEditOpen(false);
}
},
🤖 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/components/used-model.tsx` around
lines 337 - 346, The handleEditSubmit function in used-model.tsx closes the edit
dialog with setEditOpen(false) unconditionally after awaiting editInstanceModel,
which means the dialog closes even when the API mutation fails. Add proper error
handling around the editInstanceModel call: wrap it in a try-catch block and
only call setEditOpen(false) in the success path (either after the try block or
within a conditional that checks for success), so that failed mutations keep the
dialog open and allow the user to see and respond to any error messages returned
by the server.

Comment on lines +370 to +379
<Button
size="icon"
variant="ghost"
className={cn('h-6 w-6 hidden', 'group-hover:flex')}
onClick={(e: any) => {
e.stopPropagation();
setEditOpen(true);
}}
aria-label={t('setting.editCustomModelTitle')}
>

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

Make the edit button keyboard/touch accessible (not hover-only).

Using hidden group-hover:flex makes the button non-focusable unless hovered, which blocks keyboard users and hurts discoverability on touch devices.

💡 Suggested fix
         <Button
           size="icon"
           variant="ghost"
-          className={cn('h-6 w-6 hidden', 'group-hover:flex')}
+          className={cn(
+            'h-6 w-6 opacity-0 pointer-events-none transition-opacity',
+            'group-hover:opacity-100 group-hover:pointer-events-auto',
+            'focus-visible:opacity-100 focus-visible:pointer-events-auto',
+          )}
           onClick={(e: any) => {
             e.stopPropagation();
             setEditOpen(true);
           }}
📝 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
<Button
size="icon"
variant="ghost"
className={cn('h-6 w-6 hidden', 'group-hover:flex')}
onClick={(e: any) => {
e.stopPropagation();
setEditOpen(true);
}}
aria-label={t('setting.editCustomModelTitle')}
>
<Button
size="icon"
variant="ghost"
className={cn(
'h-6 w-6 opacity-0 pointer-events-none transition-opacity',
'group-hover:opacity-100 group-hover:pointer-events-auto',
'focus-visible:opacity-100 focus-visible:pointer-events-auto',
)}
onClick={(e: any) => {
e.stopPropagation();
setEditOpen(true);
}}
aria-label={t('setting.editCustomModelTitle')}
>
🤖 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/components/used-model.tsx` around
lines 370 - 379, The Button component with aria-label
'setting.editCustomModelTitle' uses className with `hidden group-hover:flex`
which makes it invisible and non-focusable until hovered. Modify the className
to make the button visible and focusable by default (remove `hidden`), while you
can optionally adjust hover styling to provide visual feedback. This ensures the
button is accessible via keyboard navigation and discoverable on touch devices.

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (400dfd5) to head (1927844).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16029   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit 7d94b08 into infiniflow:main Jun 15, 2026
1 of 2 checks passed
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. 🧰 typescript Pull requests that update Typescript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants