From 6e81720186d4215d6a650835f72ed1c6cc20e28f Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 3 Feb 2025 21:01:58 -0800 Subject: [PATCH 1/4] feat: cache org selection results --- core/config/ConfigHandler.ts | 31 ++++- core/control-plane/client.ts | 63 ++++++++- core/core.ts | 6 + core/protocol/coreWebview.ts | 1 + core/protocol/passThrough.ts | 1 + core/util/GlobalContext.ts | 4 + .../constants/MessageTypes.kt | 1 + .../platform/AssistantSelectOptions.tsx | 129 ++++++++++++++++++ gui/src/context/Auth.tsx | 44 ++++-- gui/src/pages/config/ScopeSelect.tsx | 93 +++++++++++++ gui/src/redux/thunks/setOrgId.ts | 13 ++ 11 files changed, 375 insertions(+), 11 deletions(-) create mode 100644 gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx create mode 100644 gui/src/pages/config/ScopeSelect.tsx create mode 100644 gui/src/redux/thunks/setOrgId.ts diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index edcf62071..904dcb2db 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -48,6 +48,7 @@ export class ConfigHandler { private additionalContextProviders: IContextProvider[] = []; private profiles: ProfileLifecycleManager[]; private selectedProfileId: string; + private selectedOrgId: string | null; constructor( private readonly ide: IDE, @@ -68,6 +69,7 @@ export class ConfigHandler { ); this.profiles = [new ProfileLifecycleManager(localProfileLoader, this.ide)]; this.selectedProfileId = localProfileLoader.description.id; + this.selectedOrgId = null; // Always load local profile immediately in case control plane doesn't load try { @@ -76,6 +78,20 @@ export class ConfigHandler { console.error("Failed to load config: ", e); } + void this.init(); + } + + private async init() { + const workspaceId = await this.getWorkspaceId(); + const lastSelectedOrgIds = + this.globalContext.get("lastSelectedOrgIdForWorkspace") ?? {}; + const selectedOrgId = lastSelectedOrgIds[workspaceId]; + + // We want to set the org ID before fetching control plane profiles + if (selectedOrgId) { + this.selectedOrgId = selectedOrgId; + } + // Load control plane profiles void this.fetchControlPlaneProfiles(); } @@ -118,7 +134,7 @@ export class ConfigHandler { private async loadPlatformProfiles() { // Get the profiles and create their lifecycle managers this.controlPlaneClient - .listAssistants() + .listAssistants(this.selectedOrgId) .then(async (assistants) => { const hubProfiles = await Promise.all( assistants.map(async (assistant) => { @@ -162,6 +178,7 @@ export class ConfigHandler { const workspaceId = await this.getWorkspaceId(); const lastSelectedWorkspaceIds = this.globalContext.get("lastSelectedProfileForWorkspace") ?? {}; + const selectedWorkspaceId = lastSelectedWorkspaceIds[workspaceId]; if (selectedWorkspaceId) { this.selectedProfileId = selectedWorkspaceId; @@ -211,7 +228,9 @@ export class ConfigHandler { // If so, we do the full (more expensive) reload this.platformProfilesRefreshInterval = setInterval(async () => { const newFullSlugsList = - await this.controlPlaneClient.listAssistantFullSlugs(); + await this.controlPlaneClient.listAssistantFullSlugs( + this.selectedOrgId, + ); if (newFullSlugsList) { const shouldReload = this.fullSlugsListsDiffer( @@ -273,6 +292,14 @@ export class ConfigHandler { } } + async setSelectedOrgId(orgId: string | null) { + this.selectedOrgId = orgId; + const selectedOrgs = + this.globalContext.get("lastSelectedOrgIdForWorkspace") ?? {}; + selectedOrgs[await this.getWorkspaceId()] = orgId; + this.globalContext.update("lastSelectedOrgIdForWorkspace", selectedOrgs); + } + async setSelectedProfile(profileId: string) { this.selectedProfileId = profileId; const result = await this.loadConfig(); diff --git a/core/control-plane/client.ts b/core/control-plane/client.ts index 6200bc8de..1bf4fe558 100644 --- a/core/control-plane/client.ts +++ b/core/control-plane/client.ts @@ -107,7 +107,13 @@ export class ControlPlaneClient { } } +<<<<<<< Updated upstream public async listAssistants(): Promise< +||||||| Stash base + public async listAssistants(organizationId?: string): Promise< +======= + public async listAssistants(organizationId: string | null): Promise< +>>>>>>> Stashed changes { configResult: ConfigResult; ownerSlug: string; @@ -130,14 +136,69 @@ export class ControlPlaneClient { } } +<<<<<<< Updated upstream public async listAssistantFullSlugs(): Promise { +||||||| Stash base + public async listOrganizations(): Promise> { + return [ + { + id: "1", + iconUrl: + "https://cdn.prod.website-files.com/663e06c56841363663ffbbcf/663e1b9fb023f0b622ad3608_log-text.svg", + name: "Continue", + }, + ]; + // const userId = await this.userId; + // if (!userId) { + // return []; + // } + + // try { + // const resp = await this.request("ide/list-organizations", { + // method: "GET", + // }); + // const { organizations } = (await resp.json()) as any; + // return organizations; + // } catch (e) { + // return []; + // } + } + + public async listAssistantFullSlugs(): Promise { +======= + public async listOrganizations(): Promise> { + const userId = await this.userId; + + if (!userId) { + return []; + } + + try { + const resp = await this.request("ide/list-organizations", { + method: "GET", + }); + const { organizations } = (await resp.json()) as any; + return organizations; + } catch (e) { + return []; + } + } + + public async listAssistantFullSlugs( + organizationId: string | null, + ): Promise { +>>>>>>> Stashed changes const userId = await this.userId; if (!userId) { return null; } + const url = organizationId + ? `ide/list-assistant-full-slugs?organizationId=${organizationId}` + : "ide/list-assistant-full-slugs"; + try { - const resp = await this.request("ide/list-assistant-full-slugs", { + const resp = await this.request(url, { method: "GET", }); const { fullSlugs } = (await resp.json()) as any; diff --git a/core/core.ts b/core/core.ts index 4db77443c..4b76084b8 100644 --- a/core/core.ts +++ b/core/core.ts @@ -877,6 +877,12 @@ export class Core { void this.configHandler.setSelectedProfile(msg.data.id); void this.configHandler.reloadConfig(); }); + + on("didChangeSelectedOrg", (msg) => { + void this.configHandler.setSelectedOrgId(msg.data.id); + void this.configHandler.reloadConfig(); + }); + on("didChangeControlPlaneSessionInfo", async (msg) => { this.configHandler.updateControlPlaneSessionInfo(msg.data.sessionInfo); }); diff --git a/core/protocol/coreWebview.ts b/core/protocol/coreWebview.ts index 1622b4be5..e8ef70ab9 100644 --- a/core/protocol/coreWebview.ts +++ b/core/protocol/coreWebview.ts @@ -5,6 +5,7 @@ import { ToWebviewFromIdeOrCoreProtocol } from "./webview.js"; export type ToCoreFromWebviewProtocol = ToCoreFromIdeOrWebviewProtocol & { didChangeSelectedProfile: [{ id: string }, void]; + didChangeSelectedOrg: [{ id: string | null }, void]; }; export type ToWebviewFromCoreProtocol = ToWebviewFromIdeOrCoreProtocol & { didChangeAvailableProfiles: [{ profiles: ProfileDescription[] }, void]; diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 0ce81bfe8..e157eac67 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -59,6 +59,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "addAutocompleteModel", "profiles/switch", "didChangeSelectedProfile", + "didChangeSelectedOrg", "tools/call", "controlPlane/openUrl", ]; diff --git a/core/util/GlobalContext.ts b/core/util/GlobalContext.ts index 90b403d41..aa1b66fcf 100644 --- a/core/util/GlobalContext.ts +++ b/core/util/GlobalContext.ts @@ -12,6 +12,10 @@ export type GlobalContextType = { indexingPaused: boolean; selectedTabAutocompleteModel: string; lastSelectedProfileForWorkspace: { [workspaceIdentifier: string]: string }; + lastSelectedOrgIdForWorkspace: { + [workspaceIdentifier: string]: string | null; + }; + /** * This is needed to handle the case where a JetBrains user has created * docs embeddings using one provider, and then updates to a new provider. 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 2388ce8ab..6a4647c43 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 @@ -116,6 +116,7 @@ class MessageTypes { "addAutocompleteModel", "profiles/switch", "didChangeSelectedProfile", + "didChangeSelectedOrg", "tools/call", "controlPlane/openUrl" ) diff --git a/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx new file mode 100644 index 000000000..d02bc6788 --- /dev/null +++ b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx @@ -0,0 +1,129 @@ +import { BuildingOfficeIcon, PlusIcon } from "@heroicons/react/24/outline"; +import { useContext } from "react"; +import { lightGray } from "../.."; +import { useAuth } from "../../../context/Auth"; +import { IdeMessengerContext } from "../../../context/IdeMessenger"; +import { useAppDispatch } from "../../../redux/hooks"; +import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; +import { setProfileId } from "../../../redux/thunks/setProfileId"; +import { getFontSize, getMetaKeyLabel } from "../../../util"; +import AboutAssistantDialog from "../../dialogs/AboutAssistantDialog"; +import { Divider, Option, OptionDiv } from "./shared"; +import { getProfileDisplayText } from "./utils"; +import { useNavigate } from "react-router-dom"; +import { ROUTES } from "../../../util/navigation"; + +interface AssistantSelectOptionsProps { + onClose: () => void; +} + +export function AssistantSelectOptions(props: AssistantSelectOptionsProps) { + const ideMessenger = useContext(IdeMessengerContext); + const { profiles, selectedProfile, selectedOrganization } = useAuth(); + const dispatch = useAppDispatch(); + const navigate = useNavigate(); + + function onNewAssistant() { + ideMessenger.post("controlPlane/openUrl", { + path: "platform/new", + }); + } + + function handleOptionLink(e: React.MouseEvent, profileId: string) { + e.stopPropagation(); + e.preventDefault(); + ideMessenger.post("config/openProfile", { profileId }); + } + + function handleConfigure(e: React.MouseEvent, option: any) { + e.stopPropagation(); + e.preventDefault(); + + if (option.id === "local") { + ideMessenger.post("config/openProfile", { profileId: option.id }); + } else { + props.onClose(); + dispatch(setDialogMessage()); + dispatch(setShowDialog(true)); + } + } + + function handleClickError(profileId: string) { + ideMessenger.post("config/openProfile", { profileId }); + } + + return ( +
+
+ {profiles.map((profile, idx) => ( + + ))} +
+ +
+ +
+ + New Assistant +
+
+ + + +
+ + {getMetaKeyLabel()} ⇧ ' to toggle + +
navigate(ROUTES.CONFIG)} + > + {selectedOrganization?.iconUrl ? ( + + ) : ( + + )} + + {selectedOrganization?.name || "Personal"} + +
+
+
+
+ ); +} diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index c81aa1bc1..5154c67ae 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -1,4 +1,7 @@ -import { ProfileDescription } from "core/config/ProfileLifecycleManager"; +import { + OrganizationDescription, + ProfileDescription, +} from "core/config/ProfileLifecycleManager"; import { ControlPlaneSessionInfo } from "core/control-plane/client"; import React, { createContext, @@ -28,6 +31,8 @@ interface AuthContextType { selectedProfile: ProfileDescription | undefined; profiles: ProfileDescription[]; controlServerBetaEnabled: boolean; + organizations: OrganizationDescription[]; + selectedOrganization: OrganizationDescription | undefined; } const AuthContext = createContext(undefined); @@ -39,6 +44,20 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ undefined, ); + const [organizations, setOrganizations] = useState( + [], + ); + + const ideMessenger = useContext(IdeMessengerContext); + + const selectedOrganizationId = useAppSelector( + (store) => store.session.selectedOrganizationId, + ); + + const selectedOrganization = useMemo(() => { + return organizations.find((p) => p.id === selectedOrganizationId); + }, [organizations, selectedOrganizationId]); + const profiles = useAppSelector(selectAvailableProfiles); const selectedProfileId = useAppSelector( @@ -48,13 +67,8 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ return profiles.find((p) => p.id === selectedProfileId); }, [profiles, selectedProfileId]); - const ideMessenger = useContext(IdeMessengerContext); const dispatch = useDispatch(); - const lastControlServerBetaEnabledStatus = useAppSelector( - (state) => state.misc.lastControlServerBetaEnabledStatus, - ); - const login: AuthContextType["login"] = (useOnboarding: boolean) => { return new Promise((resolve) => { ideMessenger @@ -142,11 +156,23 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ enableControlServerBeta || continueTestEnvironment !== "none"; setControlServerBetaEnabled(enabled); dispatch(setLastControlServerBetaEnabledStatus(enabled)); - - const shouldShowPopup = !lastControlServerBetaEnabledStatus && enabled; }); }, []); + useEffect(() => { + if (session) { + ideMessenger + .request("controlPlane/listOrganizations", undefined) + .then((result) => { + if (result.status === "success") { + setOrganizations(result.content); + } + }); + } else { + setOrganizations([]); + } + }, [session]); + useWebviewListener( "didChangeIdeSettings", async (msg) => { @@ -185,6 +211,8 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ login, selectedProfile, profiles, + selectedOrganization, + organizations, controlServerBetaEnabled, }} > diff --git a/gui/src/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx new file mode 100644 index 000000000..d1b4d99f8 --- /dev/null +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -0,0 +1,93 @@ +// gui/src/pages/config/ScopeSelect.tsx + +import { Listbox } from "@headlessui/react"; +import { + ChevronDownIcon, + UserCircleIcon, + BuildingOfficeIcon, +} from "@heroicons/react/24/outline"; +import { useState } from "react"; +import { useAuth } from "../../context/Auth"; +import { setOrgId } from "../../redux/thunks/setOrgId"; +import { useAppDispatch } from "../../redux/hooks"; + +const USER_PROFILE_VAL = "personal"; + +export function ScopeSelect() { + const { organizations, selectedOrganization } = useAuth(); + const [value, setValue] = useState( + selectedOrganization?.id || USER_PROFILE_VAL, + ); + const dispatch = useAppDispatch(); + + const handleChange = (newValue: string) => { + setValue(newValue); + + const orgId = newValue === USER_PROFILE_VAL ? null : newValue; + dispatch(setOrgId(orgId)); + }; + const selectedDisplay = + value === USER_PROFILE_VAL + ? { name: "Personal", iconUrl: null } + : organizations.find((org) => org.id === value); + + return ( + +
+ +
+
+ {selectedDisplay?.iconUrl ? ( + + ) : ( + + )} + + {selectedDisplay?.name || "Select Organization"} + +
+
+
+ + + {organizations.length > 0 && ( + <> +
+ Organizations +
+ {organizations.map((org) => ( + +
+ {org.iconUrl ? ( + + ) : ( + + )} + {org.name} +
+
+ ))} + +
+ + )} + + +
+ + Personal +
+
+ +
+ + ); +} diff --git a/gui/src/redux/thunks/setOrgId.ts b/gui/src/redux/thunks/setOrgId.ts new file mode 100644 index 000000000..9db496365 --- /dev/null +++ b/gui/src/redux/thunks/setOrgId.ts @@ -0,0 +1,13 @@ +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { setSelectedOrganizationId } from "../slices/sessionSlice"; +import { ThunkApiType } from "../store"; + +export const setOrgId = createAsyncThunk( + "profile/setOrgId", + async (id, { dispatch, extra }) => { + dispatch(setSelectedOrganizationId(id)); + extra.ideMessenger.post("didChangeSelectedOrg", { + id, + }); + }, +); From 13d566831db9e66ae270ff70e2b5c63304df6458 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 3 Feb 2025 21:04:19 -0800 Subject: [PATCH 2/4] feat: cache org selection results --- core/control-plane/client.ts | 45 ++++-------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/core/control-plane/client.ts b/core/control-plane/client.ts index 1bf4fe558..7c45718ee 100644 --- a/core/control-plane/client.ts +++ b/core/control-plane/client.ts @@ -1,8 +1,4 @@ import { ConfigJson } from "@continuedev/config-types"; -import fetch, { RequestInit, Response } from "node-fetch"; - -import { IdeSettings, ModelDescription } from "../index.js"; - import { AssistantUnrolled, ConfigResult, @@ -10,6 +6,10 @@ import { FullSlug, SecretResult, } from "@continuedev/config-yaml"; +import fetch, { RequestInit, Response } from "node-fetch"; + +import { IdeSettings, ModelDescription } from "../index.js"; + import { getControlPlaneEnv } from "./env.js"; export interface ControlPlaneSessionInfo { @@ -107,13 +107,7 @@ export class ControlPlaneClient { } } -<<<<<<< Updated upstream - public async listAssistants(): Promise< -||||||| Stash base - public async listAssistants(organizationId?: string): Promise< -======= public async listAssistants(organizationId: string | null): Promise< ->>>>>>> Stashed changes { configResult: ConfigResult; ownerSlug: string; @@ -136,36 +130,6 @@ export class ControlPlaneClient { } } -<<<<<<< Updated upstream - public async listAssistantFullSlugs(): Promise { -||||||| Stash base - public async listOrganizations(): Promise> { - return [ - { - id: "1", - iconUrl: - "https://cdn.prod.website-files.com/663e06c56841363663ffbbcf/663e1b9fb023f0b622ad3608_log-text.svg", - name: "Continue", - }, - ]; - // const userId = await this.userId; - // if (!userId) { - // return []; - // } - - // try { - // const resp = await this.request("ide/list-organizations", { - // method: "GET", - // }); - // const { organizations } = (await resp.json()) as any; - // return organizations; - // } catch (e) { - // return []; - // } - } - - public async listAssistantFullSlugs(): Promise { -======= public async listOrganizations(): Promise> { const userId = await this.userId; @@ -187,7 +151,6 @@ export class ControlPlaneClient { public async listAssistantFullSlugs( organizationId: string | null, ): Promise { ->>>>>>> Stashed changes const userId = await this.userId; if (!userId) { return null; From 505795eb4d6644415b6a7af4c254dc279e522785 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 3 Feb 2025 21:05:12 -0800 Subject: [PATCH 3/4] Update ScopeSelect.tsx --- gui/src/pages/config/ScopeSelect.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/gui/src/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index d1b4d99f8..99bdba606 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -1,5 +1,3 @@ -// gui/src/pages/config/ScopeSelect.tsx - import { Listbox } from "@headlessui/react"; import { ChevronDownIcon, From 9ebae75e740a1cd80101e3a6ac4a1f3615d53252 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 4 Feb 2025 09:43:13 -0800 Subject: [PATCH 4/4] update settings UI --- extensions/vscode/package.json | 2 +- gui/src/pages/config/ScopeSelect.tsx | 2 +- gui/src/pages/config/index.tsx | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 6ad3051a7..45d02f90d 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -220,7 +220,7 @@ { "command": "continue.openConfigPage", "category": "Continue", - "title": "Open Continue Config", + "title": "Open Settings", "icon": "$(gear)", "group": "Continue" }, diff --git a/gui/src/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index 99bdba606..9ee287e8b 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -32,7 +32,7 @@ export function ScopeSelect() { return (
- +
{selectedDisplay?.iconUrl ? ( diff --git a/gui/src/pages/config/index.tsx b/gui/src/pages/config/index.tsx index 5f9cf3d09..3f9cc611b 100644 --- a/gui/src/pages/config/index.tsx +++ b/gui/src/pages/config/index.tsx @@ -150,14 +150,17 @@ function ConfigPage() {

Configuration

- + Open configuration file
-

User settings

+

User settings