Merge pull request #3949 from continuedev/pe/org-select-caching

feat: fetch actual org assistants + cache org selectoin
This commit is contained in:
Nate Sesti 2025-02-04 16:52:53 -08:00 • committed by GitHub
commit bc4169496b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 150 additions and 91 deletions

View file

@ -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();

View file

@ -104,7 +104,7 @@ export class ControlPlaneClient {
}
}
public async listAssistants(organizationId?: string): Promise<
public async listAssistants(organizationId: string | null): Promise<
{
configResult: ConfigResult<AssistantUnrolled>;
ownerSlug: string;
@ -132,38 +132,37 @@ export class ControlPlaneClient {
}
public async listOrganizations(): Promise<Array<OrganizationDescription>> {
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<FullSlug[] | null> {
public async listAssistantFullSlugs(
organizationId: string | null,
): Promise<FullSlug[] | null> {
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;

View file

@ -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);
});

View file

@ -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];

View file

@ -59,6 +59,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
"addAutocompleteModel",
"profiles/switch",
"didChangeSelectedProfile",
"didChangeSelectedOrg",
"tools/call",
"controlPlane/openUrl",
"controlPlane/listOrganizations",

View file

@ -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.

View file

@ -116,6 +116,7 @@ class MessageTypes {
"addAutocompleteModel",
"profiles/switch",
"didChangeSelectedProfile",
"didChangeSelectedOrg",
"tools/call",
"controlPlane/openUrl",
"controlPlane/listOrganizations"

View file

@ -220,7 +220,7 @@
{
"command": "continue.openConfigPage",
"category": "Continue",
"title": "Open Continue Config",
"title": "Open Settings",
"icon": "$(gear)",
"group": "Continue"
},

View file

@ -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 (
<div className="border-lightgray flex min-w-0 flex-col overflow-x-hidden pt-0">
<div
className="pb-1 pl-3.5 pt-3 font-semibold hover:cursor-pointer hover:underline"
onClick={() => navigate(ROUTES.CONFIG)}
>
{selectedOrganization?.name || "Personal"} Assistants
</div>
<div className={`max-h-[300px]`}>
{profiles.map((profile, idx) => (
<Option
@ -84,22 +77,14 @@ export function AssistantSelectOptions(props: AssistantSelectOptionsProps) {
<div className="mr-2 h-4 w-4 flex-shrink-0">
<AssistantIcon assistant={profile} />
</div>
<div className="flex min-w-0 flex-col gap-0.5">
<span
className="text-lightgray truncate"
style={{ fontSize: getFontSize() - 4 }}
>
{profile.fullSlug.ownerSlug}
</span>
<span
className="flex-1 truncate"
style={{ fontSize: getFontSize() - 2 }}
>
{getProfileDisplayText(profile)}
{profile.fullSlug.versionSlug &&
` (${profile.fullSlug.versionSlug})`}
</span>
</div>
<span
className="flex-1 truncate"
style={{ fontSize: getFontSize() - 2 }}
>
{getProfileDisplayText(profile)}
{profile.fullSlug.versionSlug &&
` (${profile.fullSlug.versionSlug})`}
</span>
</div>
</Option>
))}
@ -118,12 +103,27 @@ export function AssistantSelectOptions(props: AssistantSelectOptionsProps) {
<Divider className="!my-0" />
<span
className="block px-3 py-3"
<div
className="flex items-center justify-between p-2"
style={{ color: lightGray, fontSize: getFontSize() - 4 }}
>
<code>{getMetaKeyLabel()} ⇧ '</code> to toggle
</span>
<span className="block">
<code>{getMetaKeyLabel()} ⇧ '</code> to toggle
</span>
<div
className="flex items-center gap-1"
onClick={() => navigate(ROUTES.CONFIG)}
>
{selectedOrganization?.iconUrl ? (
<img src={selectedOrganization.iconUrl} className="h-4 w-4" />
) : (
<BuildingOfficeIcon className="h-4 w-4" />
)}
<span className="hover:cursor-pointer hover:underline">
{selectedOrganization?.name || "Personal"}
</span>
</div>
</div>
</div>
</div>
);

View file

@ -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<string>(
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 (
<Listbox value={value} onChange={handleChange}>
<div className="relative">
<Listbox.Button className="border-vsc-foreground text-vsc-foreground hover:bg-vsc-background flex w-full cursor-pointer items-center gap-0.5 rounded border bg-transparent p-2 hover:opacity-90">
<Listbox.Button className="border-vsc-foreground text-vsc-foreground hover:bg-vsc-background flex w-full max-w-[400px] cursor-pointer items-center gap-0.5 rounded border bg-transparent p-2 hover:opacity-90">
<div className="flex w-full items-center justify-between">
<div className="flex items-center gap-2">
{selectedDisplay?.iconUrl ? (
<img src={selectedDisplay.iconUrl} alt="" className="h-5 w-5" />
) : (
<UserCircleIcon className="h-5 w-5" />
<BuildingOfficeIcon className="h-5 w-5" />
)}
<span className="truncate">
{selectedDisplay?.name || "Select Organization"}
@ -49,30 +49,34 @@ export function ScopeSelect() {
</Listbox.Button>
<Listbox.Options className="bg-vsc-input-background absolute z-50 mt-1 w-full min-w-[200px] list-none overflow-auto rounded p-0 shadow-lg">
<div className="text-vsc-foreground p-2 font-semibold">
Organizations
</div>
{organizations.map((org) => (
<Listbox.Option
key={org.id}
value={org.id}
className="text-vsc-foreground hover:bg-lightgray/20 cursor-pointer rounded p-2 hover:opacity-90"
>
<div className="flex items-center gap-2">
{org.iconUrl ? (
<img src={org.iconUrl} alt="" className="h-5 w-5" />
) : (
<CubeIcon className="h-5 w-5" />
)}
<span>{org.name}</span>
{organizations.length > 0 && (
<>
<div className="text-vsc-foreground p-2 font-semibold">
Organizations
</div>
</Listbox.Option>
))}
{organizations.map((org) => (
<Listbox.Option
key={org.id}
value={org.id}
className="text-vsc-foreground hover:bg-lightgray/20 cursor-pointer rounded p-2 hover:opacity-90"
>
<div className="flex items-center gap-2">
{org.iconUrl ? (
<img src={org.iconUrl} alt="" className="h-5 w-5" />
) : (
<BuildingOfficeIcon className="h-5 w-5" />
)}
<span>{org.name}</span>
</div>
</Listbox.Option>
))}
<div className="bg-lightgray mx-1 my-1 h-px" />
<div className="bg-lightgray mx-1 my-1 h-px" />
</>
)}
<Listbox.Option
value="personal"
value={USER_PROFILE_VAL}
className="text-vsc-foreground hover:bg-lightgray/20 cursor-pointer rounded p-2 hover:opacity-90"
>
<div className="flex items-center gap-2">

View file

@ -150,14 +150,17 @@ function ConfigPage() {
<div className="flex flex-col gap-4 py-6">
<h2 className="mb-1 mt-0">Configuration</h2>
<SecondaryButton onClick={handleOpenConfig} className="!my-0">
<SecondaryButton
onClick={handleOpenConfig}
className="!my-0 max-w-[400px]"
>
Open configuration file
</SecondaryButton>
</div>
<div className="flex flex-col gap-4 py-6">
<div>
<h2 className="mb-4 mt-0">User settings</h2>
<h2 className="mb-2 mt-0">User settings</h2>
</div>
<div className="flex flex-col gap-4">

View file

@ -0,0 +1,13 @@
import { createAsyncThunk } from "@reduxjs/toolkit";
import { setSelectedOrganizationId } from "../slices/sessionSlice";
import { ThunkApiType } from "../store";
export const setOrgId = createAsyncThunk<void, string | null, ThunkApiType>(
"profile/setOrgId",
async (id, { dispatch, extra }) => {
dispatch(setSelectedOrganizationId(id));
extra.ideMessenger.post("didChangeSelectedOrg", {
id,
});
},
);