Repository navigation
Feat: Add edit model type function - #16029
Conversation
📝 WalkthroughWalkthroughAdds end-to-end support for editing a custom instance model. A new ChangesEdit Instance Model Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ 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: 3
🧹 Nitpick comments (1)
web/src/pages/user-setting/setting-model/modal/provider-modal/components/add-custom-model-dialog.tsx (1)
83-85: ⚡ Quick winUse
useTranslationdirectly 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
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/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
📒 Files selected for processing (8)
web/src/hooks/use-llm-request.tsxweb/src/interfaces/request/llm.tsweb/src/locales/en.tsweb/src/locales/zh.tsweb/src/pages/user-setting/setting-model/components/used-model.tsxweb/src/pages/user-setting/setting-model/modal/provider-modal/components/add-custom-model-dialog.tsxweb/src/services/llm-service.tsweb/src/utils/api.ts
| queryClient.invalidateQueries({ | ||
| queryKey: LlmKeys.allModels(), | ||
| }); |
There was a problem hiding this comment.
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
| 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); | ||
| }, |
There was a problem hiding this comment.
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.
| 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.
| <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')} | ||
| > |
There was a problem hiding this comment.
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.
| <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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Feat: Add edit model type function
Type of change