diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index e1c2a17e4..e2d1b5061 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -49,6 +49,7 @@ export class ConfigHandler { private additionalContextProviders: IContextProvider[] = []; private profiles: ProfileLifecycleManager[]; private selectedProfileId: string; + private selectedOrgId: string | null; constructor( private readonly ide: IDE, @@ -69,6 +70,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 { @@ -77,6 +79,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(); } @@ -119,7 +135,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) => { @@ -164,6 +180,7 @@ export class ConfigHandler { const workspaceId = await this.getWorkspaceId(); const lastSelectedWorkspaceIds = this.globalContext.get("lastSelectedProfileForWorkspace") ?? {}; + const selectedWorkspaceId = lastSelectedWorkspaceIds[workspaceId]; if (selectedWorkspaceId) { this.selectedProfileId = selectedWorkspaceId; @@ -213,7 +230,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( @@ -275,6 +294,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 7c15c8910..7d0e03cc8 100644 --- a/core/control-plane/client.ts +++ b/core/control-plane/client.ts @@ -104,7 +104,7 @@ export class ControlPlaneClient { } } - public async listAssistants(organizationId?: string): Promise< + public async listAssistants(organizationId: string | null): Promise< { configResult: ConfigResult; ownerSlug: string; @@ -132,38 +132,37 @@ export class ControlPlaneClient { } 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 []; - // } + const userId = await this.userId; - // try { - // const resp = await this.request("ide/list-organizations", { - // method: "GET", - // }); - // const { organizations } = (await resp.json()) as any; - // return organizations; - // } catch (e) { - // return []; - // } + 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 listAssistantFullSlugs( + organizationId: string | null, + ): Promise { 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 52e5a58cd..04ded9932 100644 --- a/core/core.ts +++ b/core/core.ts @@ -882,6 +882,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 edf079157..8ee0c5ae8 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", "controlPlane/listOrganizations", 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 873add597..d3f69bc7a 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", "controlPlane/listOrganizations" diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index c688eda3f..09f98e789 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/components/modelSelection/platform/AssistantSelectOptions.tsx b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx index b2604501c..6c95b9f45 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx @@ -1,4 +1,4 @@ -import { PlusIcon } from "@heroicons/react/24/outline"; +import { BuildingOfficeIcon, PlusIcon } from "@heroicons/react/24/outline"; import { useContext } from "react"; import { lightGray } from "../.."; import { useAuth } from "../../../context/Auth"; @@ -10,9 +10,9 @@ import { getFontSize, getMetaKeyLabel, isLocalProfile } from "../../../util"; import AboutAssistantDialog from "../../dialogs/AboutAssistantDialog"; import { Divider, Option, OptionDiv } from "./shared"; import { getProfileDisplayText } from "./utils"; -import AssistantIcon from "./AssistantIcon"; import { useNavigate } from "react-router-dom"; import { ROUTES } from "../../../util/navigation"; +import AssistantIcon from "./AssistantIcon"; interface AssistantSelectOptionsProps { onClose: () => void; @@ -55,13 +55,6 @@ export function AssistantSelectOptions(props: AssistantSelectOptionsProps) { return (
-
navigate(ROUTES.CONFIG)} - > - {selectedOrganization?.name || "Personal"} Assistants -
-
{profiles.map((profile, idx) => (
-
- - {profile.fullSlug.ownerSlug} - - - {getProfileDisplayText(profile)} - {profile.fullSlug.versionSlug && - ` (${profile.fullSlug.versionSlug})`} - -
+ + {getProfileDisplayText(profile)} + {profile.fullSlug.versionSlug && + ` (${profile.fullSlug.versionSlug})`} +
))} @@ -118,12 +103,27 @@ export function AssistantSelectOptions(props: AssistantSelectOptionsProps) { - - {getMetaKeyLabel()} ⇧ ' to toggle - + + {getMetaKeyLabel()} ⇧ ' to toggle + +
navigate(ROUTES.CONFIG)} + > + {selectedOrganization?.iconUrl ? ( + + ) : ( + + )} + + {selectedOrganization?.name || "Personal"} + +
+ ); diff --git a/gui/src/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index 773ad180f..9ee287e8b 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -1,44 +1,44 @@ -// gui/src/pages/config/ScopeSelect.tsx - import { Listbox } from "@headlessui/react"; import { ChevronDownIcon, UserCircleIcon, - CubeIcon, + BuildingOfficeIcon, } from "@heroicons/react/24/outline"; import { useState } from "react"; import { useAuth } from "../../context/Auth"; -import { useDispatch } from "react-redux"; -import { setSelectedOrganizationId } from "../../redux/slices/sessionSlice"; +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 || "personal", + selectedOrganization?.id || USER_PROFILE_VAL, ); - const dispatch = useDispatch(); + const dispatch = useAppDispatch(); const handleChange = (newValue: string) => { setValue(newValue); - dispatch( - setSelectedOrganizationId(newValue === "personal" ? null : newValue), - ); + + const orgId = newValue === USER_PROFILE_VAL ? null : newValue; + dispatch(setOrgId(orgId)); }; const selectedDisplay = - value === "personal" + value === USER_PROFILE_VAL ? { name: "Personal", iconUrl: null } : organizations.find((org) => org.id === value); return (
- +
{selectedDisplay?.iconUrl ? ( ) : ( - + )} {selectedDisplay?.name || "Select Organization"} @@ -49,30 +49,34 @@ export function ScopeSelect() { -
- Organizations -
- {organizations.map((org) => ( - -
- {org.iconUrl ? ( - - ) : ( - - )} - {org.name} + {organizations.length > 0 && ( + <> +
+ Organizations
- - ))} + {organizations.map((org) => ( + +
+ {org.iconUrl ? ( + + ) : ( + + )} + {org.name} +
+
+ ))} -
+
+ + )}
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

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, + }); + }, +);