From bd6cfb047fd94a63239a73d1912e006fc5dc5596 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 26 Feb 2025 16:00:19 -0800 Subject: [PATCH] refresh profiles button on 401 --- core/config/ConfigHandler.ts | 14 ++++--- core/core.ts | 4 ++ core/protocol/core.ts | 1 + core/protocol/passThrough.ts | 1 + docs/docs/yaml-reference.md | 36 +++++++++--------- .../constants/MessageTypes.kt | 1 + gui/src/context/Auth.tsx | 10 +++++ gui/src/pages/gui/StreamError.tsx | 37 ++++++++++++++----- 8 files changed, 72 insertions(+), 32 deletions(-) diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index b9a0f0896..84d578620 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -353,11 +353,7 @@ export class ConfigHandler { Promise.resolve(sessionInfo), this.ideSettingsPromise, ); - this.fetchControlPlaneProfiles().catch(async (e) => { - console.error("Failed to fetch control plane profiles: ", e); - await this.updateAvailableProfiles([this.localProfileManager]); - await this.reloadConfig(); - }); + await this.refreshProfiles(); } private profilesListeners: (( @@ -435,6 +431,14 @@ export class ConfigHandler { return this.profiles?.map((p) => p.profileDescription) ?? null; } + async refreshProfiles() { + this.fetchControlPlaneProfiles().catch(async (e) => { + console.error("Failed to fetch control plane profiles: ", e); + await this.updateAvailableProfiles([this.localProfileManager]); + await this.reloadConfig(); + }); + } + async loadConfig(): Promise> { if (!this.currentProfile) { return { diff --git a/core/core.ts b/core/core.ts index 00d141117..57e0117be 100644 --- a/core/core.ts +++ b/core/core.ts @@ -306,6 +306,10 @@ export class Core { return this.configHandler.listProfiles(); }); + on("config/refreshProfiles", async (msg) => { + await this.configHandler.refreshProfiles(); + }); + on("config/addContextProvider", async (msg) => { addContextProvider(msg.data, this.configHandler); }); diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 0a3913590..ac991622a 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -69,6 +69,7 @@ export type ToCoreFromIdeOrWebviewProtocol = { "config/addContextProvider": [ContextProviderWithParams, void]; "config/reload": [undefined, ConfigResult]; "config/listProfiles": [undefined, ProfileDescription[] | null]; + "config/refreshProfiles": [undefined, void]; "config/openProfile": [{ profileId: string | undefined }, void]; "config/updateSharedConfig": [SharedConfigSchema, SharedConfigSchema]; "config/updateSelectedModel": [ diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index d3a7259f2..ef71c66a1 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -22,6 +22,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "config/getSerializedProfileInfo", "config/deleteModel", "config/listProfiles", + "config/refreshProfiles", "config/openProfile", "config/updateSharedConfig", "config/updateSelectedModel", diff --git a/docs/docs/yaml-reference.md b/docs/docs/yaml-reference.md index 126199f05..dd461cd97 100644 --- a/docs/docs/yaml-reference.md +++ b/docs/docs/yaml-reference.md @@ -435,26 +435,26 @@ model_defaults: &model_defaults apiBase: https://api.example.com/llm models: -- name: mistral - <<: *model_defaults - model: mistral-7b-instruct - roles: - - chat - - edit + - name: mistral + <<: *model_defaults + model: mistral-7b-instruct + roles: + - chat + - edit -- name: qwen2.5-coder-7b-instruct - <<: *model_defaults - model: qwen2.5-coder-7b-instruct - roles: - - chat - - edit + - name: qwen2.5-coder-7b-instruct + <<: *model_defaults + model: qwen2.5-coder-7b-instruct + roles: + - chat + - edit -- name: qwen2.5-coder-7b - <<: *model_defaults - model: qwen2.5-coder-7b - useLegacyCompletionsEndpoint: false - roles: - - autocomplete + - name: qwen2.5-coder-7b + <<: *model_defaults + model: qwen2.5-coder-7b + useLegacyCompletionsEndpoint: false + roles: + - autocomplete ``` ### Fully deprecated settings diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt index bfbe614cc..e71401b15 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt @@ -89,6 +89,7 @@ class MessageTypes { "config/getSerializedProfileInfo", "config/deleteModel", "config/listProfiles", + "config/refreshProfiles", "config/openProfile", "config/updateSharedConfig", "config/updateSelectedModel", diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index 967db1321..d5ec8fa42 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -27,6 +27,7 @@ interface AuthContextType { login: (useOnboarding: boolean) => Promise; selectedProfile: ProfileDescription | null; profiles: ProfileDescription[] | null; + refreshProfiles: () => void; controlServerBetaEnabled: boolean; organizations: OrganizationDescription[]; selectedOrganization: OrganizationDescription | null; @@ -175,6 +176,14 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ }); }, []); + const refreshProfiles = () => { + try { + ideMessenger.post("config/refreshProfiles", undefined); + } catch (e) { + console.error("Failed to refresh profiles", e); + } + }; + useWebviewListener( "didChangeAvailableProfiles", async (data) => { @@ -196,6 +205,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ login, selectedProfile, profiles, + refreshProfiles, selectedOrganization, organizations: orgs, controlServerBetaEnabled, diff --git a/gui/src/pages/gui/StreamError.tsx b/gui/src/pages/gui/StreamError.tsx index 2a8465c30..38da7df22 100644 --- a/gui/src/pages/gui/StreamError.tsx +++ b/gui/src/pages/gui/StreamError.tsx @@ -1,14 +1,17 @@ -import { Cog8ToothIcon, ListBulletIcon } from "@heroicons/react/24/outline"; -import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { useContext } from "react"; -import { GithubIcon } from "../../components/svg/GithubIcon"; -import { DiscordIcon } from "../../components/svg/DiscordIcon"; -import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { Cog8ToothIcon } from "@heroicons/react/24/outline"; import { DISCORD_LINK, GITHUB_LINK } from "core/util/constants"; -import { selectDefaultModel } from "../../redux/slices/configSlice"; -import { providers } from "../AddNewModel/configs/providers"; +import { useContext } from "react"; import { Button, SecondaryButton } from "../../components"; +import { DiscordIcon } from "../../components/svg/DiscordIcon"; +import { GithubIcon } from "../../components/svg/GithubIcon"; +import { useAuth } from "../../context/Auth"; +import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { useAppDispatch, useAppSelector } from "../../redux/hooks"; +import { selectUseHub } from "../../redux/selectors"; +import { selectDefaultModel } from "../../redux/slices/configSlice"; import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; +import { isLocalProfile } from "../../util"; +import { providers } from "../AddNewModel/configs/providers"; interface StreamErrorProps { error: unknown; @@ -17,6 +20,11 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const selectedModel = useAppSelector(selectDefaultModel); + const hubEnabled = useAppSelector(selectUseHub); + const selectedProfile = useAppSelector( + (store) => store.session.selectedProfile, + ); + const { session, refreshProfiles } = useAuth(); // Collect model information to display useful error info let modelTitle = "Chat model"; @@ -139,7 +147,18 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => { if (statusCode === 401) { errorContent = (
- {`Likely cause: your API key is invalid.`} + {hubEnabled && + session && + selectedProfile && + !isLocalProfile(selectedProfile) && ( +
+ {`If your hub secret values may have changed, refresh your profiles`} + + Refresh profile secrets + +
+ )} + {`It's possible that your API key is invalid.`}
{checkKeysButton} {configButton}