-
Notifications
You must be signed in to change notification settings - Fork 182
fix(settings): pre-populate model field from active routing config when editing existing provider #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(settings): pre-populate model field from active routing config when editing existing provider #193
Changes from all commits
0ee9e43
4e07754
8fd761c
880ab4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,7 +134,7 @@ const PROVIDERS = [ | |
| description: "Fast inference for popular OSS models", | ||
| placeholder: "...", | ||
| envVar: "FIREWORKS_API_KEY", | ||
| defaultModel: "fireworks/accounts/fireworks/models/llama-v3p3-70b-instruct", | ||
| defaultModel: "fireworks/accounts/fireworks/models/minimax-m2p5", | ||
| }, | ||
| { | ||
| id: "deepseek", | ||
|
|
@@ -262,6 +262,38 @@ export function Settings() { | |
| enabled: activeSection === "providers", | ||
| }); | ||
|
|
||
| // Fetch agents list and default agent config so we can pre-populate the | ||
| // model field with the currently active routing model when editing an | ||
| // already-configured provider (instead of always showing the hardcoded | ||
| // defaultModel). | ||
| const { data: agentsData } = useQuery({ | ||
| queryKey: ["agents"], | ||
| queryFn: api.agents, | ||
| staleTime: 10_000, | ||
| enabled: activeSection === "providers", | ||
| }); | ||
| const defaultAgentId = | ||
| agentsData?.agents?.find((agent) => agent.id === "main")?.id ?? agentsData?.agents?.[0]?.id; | ||
| const { data: defaultAgentConfig } = useQuery({ | ||
| queryKey: ["agent-config", defaultAgentId], | ||
| queryFn: () => api.agentConfig(defaultAgentId!), | ||
| staleTime: 10_000, | ||
| enabled: activeSection === "providers" && !!defaultAgentId, | ||
| }); | ||
|
|
||
| // If the routing config loads *after* the edit dialog is already open (race | ||
| // condition: user clicks edit before the agent-config query resolves), update | ||
| // the model field to show the active routing model instead of defaultModel. | ||
| useEffect(() => { | ||
| if (!editingProvider) return; | ||
| const currentChannel = defaultAgentConfig?.routing?.channel; | ||
| if (!currentChannel?.startsWith(`${editingProvider}/`)) return; | ||
| setModelInput(currentChannel); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [defaultAgentConfig]); | ||
| // Note: intentionally omitting editingProvider and modelInput from deps — we | ||
| // only want this to fire when the config data arrives, not on every keystroke. | ||
|
Comment on lines
+284
to
+295
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against overwriting user edits when the routing config arrives late. If a user starts typing before 💡 Safer update to avoid clobbering user inputuseEffect(() => {
if (!editingProvider) return;
const currentChannel = defaultAgentConfig?.routing?.channel;
if (!currentChannel?.startsWith(`${editingProvider}/`)) return;
- setModelInput(currentChannel);
+ const providerDefault =
+ PROVIDERS.find((p) => p.id === editingProvider)?.defaultModel ?? "";
+ setModelInput((prev) =>
+ prev === providerDefault || !prev ? currentChannel : prev
+ );
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [defaultAgentConfig]);🤖 Prompt for AI Agents |
||
|
|
||
| // Fetch global settings (only when on api-keys, server, or worker-logs tabs) | ||
| const { data: globalSettings, isLoading: globalSettingsLoading } = useQuery({ | ||
| queryKey: ["global-settings"], | ||
|
|
@@ -591,7 +623,16 @@ export function Settings() { | |
| onEdit={() => { | ||
| setEditingProvider(provider.id); | ||
| setKeyInput(""); | ||
| setModelInput(provider.defaultModel ?? ""); | ||
| // When the provider is already configured, pre-populate | ||
| // the model field with the current routing model so the | ||
| // user sees (and can adjust) what's actually active, | ||
| // rather than the hardcoded defaultModel placeholder. | ||
| const currentChannel = defaultAgentConfig?.routing?.channel; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One edge case: if the user clicks “Update” before |
||
| const currentModel = | ||
| isConfigured(provider.id) && currentChannel?.startsWith(`${provider.id}/`) | ||
| ? currentChannel | ||
| : null; | ||
| setModelInput(currentModel ?? provider.defaultModel ?? ""); | ||
| setTestedSignature(null); | ||
| setTestResult(null); | ||
| setMessage(null); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
["agent-config"]is never invalidated after provider mutations — pre-populated model will be stale.After
updateMutationsucceeds (or the ChatGPT OAuth flow completes), the backend updates the routing config, but neitherupdateMutation.onSuccessnormonitorOpenAiBrowserOAuthinvalidates the["agent-config", ...]cache. WithstaleTime: 10_000, the old routing model stays cached for up to 10 seconds. If the user saves a provider, then immediately clicks "Update" again, the dialog pre-populates the old channel — the opposite of what this PR intends.🐛 Proposed fix — add agent-config invalidation in both mutation handlers
In
updateMutation.onSuccess(around line 296):setTimeout(() => { queryClient.invalidateQueries({ queryKey: ["agents"] }); + queryClient.invalidateQueries({ queryKey: ["agent-config"] }); queryClient.invalidateQueries({ queryKey: ["overview"] }); }, 3000);In
monitorOpenAiBrowserOAuthsuccess branch (around line 391):setTimeout(() => { queryClient.invalidateQueries({queryKey: ["agents"]}); + queryClient.invalidateQueries({queryKey: ["agent-config"]}); queryClient.invalidateQueries({queryKey: ["overview"]}); }, 3000);Using the prefix key
["agent-config"](no agent ID) invalidates all variants, so it works even beforedefaultAgentIdis known.🤖 Prompt for AI Agents