gui updates 1

This commit is contained in:
Dallin Romney 2025-04-06 14:59:57 -07:00
parent 20e5b12c02
commit ddcd2bc819
17 changed files with 147 additions and 110 deletions

View file

@ -26,19 +26,16 @@ import LocalProfileLoader from "./profile/LocalProfileLoader.js";
import PlatformProfileLoader from "./profile/PlatformProfileLoader.js";
import {
OrganizationDescription,
OrgWithProfiles,
ProfileDescription,
ProfileLifecycleManager,
SerializedOrgWithProfiles,
} from "./ProfileLifecycleManager.js";
export type { ProfileDescription };
type ConfigUpdateFunction = (payload: ConfigResult<ContinueConfig>) => void;
type OrgWithProfiles = OrganizationDescription & {
profiles: ProfileLifecycleManager[];
currentProfile: ProfileLifecycleManager | null;
};
export class ConfigHandler {
controlPlaneClient: ControlPlaneClient;
private readonly globalContext = new GlobalContext();
@ -134,6 +131,7 @@ export class ConfigHandler {
[workspaceId]: selectedOrg.id,
});
this.organizations = orgs;
this.currentOrg = selectedOrg;
this.currentProfile = selectedOrg.currentProfile;
await this.reloadConfig();
@ -150,13 +148,25 @@ export class ConfigHandler {
);
return [personalHubOrg, ...hubOrgs];
} else {
return [await this.getTeamsOrg(orgDescs[0])];
// Should only ever be one teams org. Will be removed soon anyways
return await Promise.all(orgDescs.map((org) => this.getTeamsOrg(org)));
}
} else {
return [await this.getLocalOrg()];
}
}
getSerializedOrgs(): SerializedOrgWithProfiles[] {
return this.organizations.map((org) => ({
iconUrl: org.iconUrl,
id: org.id,
name: org.name,
slug: org.slug,
profiles: org.profiles.map((profile) => profile.profileDescription),
selectedProfileId: org.currentProfile?.profileDescription.id || null,
}));
}
private async getHubProfiles(orgScopeId: string | null) {
const assistants = await this.controlPlaneClient.listAssistants(orgScopeId);

View file

@ -32,6 +32,16 @@ export interface OrganizationDescription {
slug: string | undefined; // TODO: This doesn't need to be undefined, just doing while transitioning the backend
}
export type OrgWithProfiles = OrganizationDescription & {
profiles: ProfileLifecycleManager[];
currentProfile: ProfileLifecycleManager | null;
};
export type SerializedOrgWithProfiles = OrganizationDescription & {
profiles: ProfileDescription[];
selectedProfileId: string | null;
};
export class ProfileLifecycleManager {
private savedConfigResult: ConfigResult<ContinueConfig> | undefined;
private savedBrowserConfigResult?: ConfigResult<BrowserSerializedContinueConfig>;

View file

@ -126,10 +126,9 @@ export class Core {
this.messenger.send("configUpdate", {
result: serializedResult,
profileId:
this.configHandler.currentProfile?.profileDescription.id ?? null,
selectedOrgId: this.configHandler.selectedOrgId,
availableOrgProfiles: this.configHandler.listProfileDescriptions(),
availableOrgs: this.configHandler.organizations,
this.configHandler.currentProfile?.profileDescription.id || null,
organizations: this.configHandler.getSerializedOrgs(),
selectedOrgId: this.configHandler.currentOrg.id,
});
// update additional submenu context providers registered via VSCode API
@ -297,7 +296,7 @@ export class Core {
});
on("config/refreshProfiles", async (msg) => {
await this.configHandler.refreshAssistantsForSelectedOrg();
await this.configHandler.refreshAll();
});
on("config/updateSharedConfig", async (msg) => {
@ -457,6 +456,8 @@ export class Core {
result: await this.configHandler.getSerializedConfig(),
profileId:
this.configHandler.currentProfile?.profileDescription.id ?? null,
organizations: this.configHandler.getSerializedOrgs(),
selectedOrgId: this.configHandler.currentOrg.id,
};
});
@ -752,11 +753,15 @@ export class Core {
void refreshIfNotIgnored(data.uris);
// If it's a local assistant being created, we want to reload all assistants so it shows up in the list
let localAssistantCreated = false;
for (const uri of data.uris) {
if (isLocalAssistantFile(uri)) {
await this.configHandler.refreshAssistantsForSelectedOrg();
localAssistantCreated = true;
}
}
if (localAssistantCreated) {
await this.configHandler.refreshAll();
}
}
});

View file

@ -30,6 +30,7 @@ import type {
SlashCommandDescription,
ToolCall,
} from "../";
import { SerializedOrgWithProfiles } from "../config/ProfileLifecycleManager";
import { ControlPlaneSessionInfo } from "../control-plane/client";
export type OnboardingModes = "Local" | "Best" | "Custom" | "Quickstart";
@ -65,6 +66,8 @@ export type ToCoreFromIdeOrWebviewProtocol = {
{
result: ConfigResult<BrowserSerializedContinueConfig>;
profileId: string | null;
organizations: SerializedOrgWithProfiles[];
selectedOrgId: string;
},
];
"config/deleteModel": [{ title: string }, void];

View file

@ -1,8 +1,5 @@
import { ConfigResult } from "@continuedev/config-yaml";
import {
OrganizationDescription,
ProfileDescription,
} from "../config/ProfileLifecycleManager.js";
import { SerializedOrgWithProfiles } from "../config/ProfileLifecycleManager.js";
import type {
BrowserSerializedContinueConfig,
ContextItemWithId,
@ -16,9 +13,8 @@ export type ToWebviewFromIdeOrCoreProtocol = {
{
result: ConfigResult<BrowserSerializedContinueConfig>;
profileId: string | null;
availableOrgs: OrganizationDescription[];
organizations: SerializedOrgWithProfiles[];
selectedOrgId: string | null;
availableOrgProfiles: ProfileDescription[];
},
void,
];

View file

@ -1,14 +1,12 @@
import { parseConfigYaml } from "@continuedev/config-yaml";
import { IndexingStatus } from "core";
import { useMemo } from "react";
import { useDispatch } from "react-redux";
import { useAuth } from "../../../../../context/Auth";
import { useAppSelector } from "../../../../../redux/hooks";
import { ExploreBlocksButton } from "../ExploreBlocksButton";
import DocsIndexingStatus from "./DocsIndexingStatus";
function DocsIndexingStatuses() {
const dispatch = useDispatch();
const config = useAppSelector((store) => store.config.config);
const indexingStatuses = useAppSelector(
(store) => store.indexing.indexing.statuses,

View file

@ -9,7 +9,7 @@ import {
import { useContext, useEffect, useMemo, useRef } from "react";
import { useAuth } from "../../../context/Auth";
import { IdeMessengerContext } from "../../../context/IdeMessenger";
import { setSelectedProfile } from "../../../redux";
import { selectCurrentOrg, setSelectedProfile } from "../../../redux";
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
import {
fontSize,
@ -154,9 +154,7 @@ export default function AssistantSelect() {
const dispatch = useAppDispatch();
const buttonRef = useRef<HTMLButtonElement>(null);
const { selectedProfile, selectedOrganization } = useAuth();
const availableProfiles = useAppSelector(
(store) => store.profiles.availableProfiles,
);
const currentOrg = useAppSelector(selectCurrentOrg);
const ideMessenger = useContext(IdeMessengerContext);
const { isToolbarExpanded } = useLump();
@ -178,7 +176,7 @@ export default function AssistantSelect() {
useEffect(() => {
let lastToggleTime = 0;
const DEBOUNCE_MS = 500;
const DEBOUNCE_MS = 800;
const handleKeyDown = (event: KeyboardEvent) => {
if (
@ -192,7 +190,7 @@ export default function AssistantSelect() {
lastToggleTime = now;
const profileIds =
availableProfiles?.map((profile) => profile.id) ?? [];
currentOrg?.profiles.map((profile) => profile.id) ?? [];
// In case of 1 or 0 profiles just does nothing
if (profileIds.length < 2) {
return;
@ -203,6 +201,7 @@ export default function AssistantSelect() {
const nextIndex = (curIndex + 1) % profileIds.length;
nextId = profileIds[nextIndex];
}
// Optimistic update
dispatch(setSelectedProfile(nextId));
ideMessenger.post("didChangeSelectedProfile", {
id: nextId,
@ -215,7 +214,7 @@ export default function AssistantSelect() {
return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, [availableProfiles, selectedProfile]);
}, [currentOrg, selectedProfile]);
const tinyFont = useFontSize(-4);
const smallFont = useFontSize(-3);

View file

@ -11,7 +11,7 @@ import React, {
useState,
} from "react";
import ConfirmationDialog from "../components/dialogs/ConfirmationDialog";
import { selectSelectedProfile } from "../redux/";
import { selectCurrentOrg, selectSelectedProfile } from "../redux/";
import { useAppDispatch, useAppSelector } from "../redux/hooks";
import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice";
import { IdeMessengerContext } from "./IdeMessenger";
@ -42,9 +42,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
);
// Orgs
const orgs = useAppSelector((store) => store.organizations.organizations);
const orgs = useAppSelector((store) => store.profiles.organizations);
const selectedOrgId = useAppSelector(
(store) => store.organizations.selectedOrganizationId,
(store) => store.profiles.selectedOrganizationId,
);
const selectedOrganization = useMemo(() => {
if (!selectedOrgId) {
@ -54,7 +54,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
}, [orgs, selectedOrgId]);
// Profiles
const profiles = useAppSelector((store) => store.profiles.availableProfiles);
const currentOrg = useAppSelector(selectCurrentOrg);
const selectedProfile = useAppSelector(selectSelectedProfile);
const login: AuthContextType["login"] = (useOnboarding: boolean) => {
@ -150,7 +150,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
logout,
login,
selectedProfile,
profiles,
profiles: currentOrg?.profiles ?? [],
refreshProfiles,
selectedOrganization,
organizations: orgs,

View file

@ -2,11 +2,11 @@ import { useCallback, useContext, useEffect, useRef } from "react";
import { VSC_THEME_COLOR_VARS } from "../components";
import { IdeMessengerContext } from "../context/IdeMessenger";
import { ConfigResult } from "@continuedev/config-yaml";
import { BrowserSerializedContinueConfig } from "core";
import { FromCoreProtocol } from "core/protocol";
import {
initializeProfilePreferences,
selectSelectedProfileId,
setOrganizations,
setSelectedOrgId,
setSelectedProfile,
} from "../redux";
import { useAppDispatch, useAppSelector } from "../redux/hooks";
@ -36,25 +36,28 @@ function useSetup() {
const ideMessenger = useContext(IdeMessengerContext);
const history = useAppSelector((store) => store.session.history);
const defaultModel = useAppSelector(selectDefaultModel);
const selectedProfileId = useAppSelector(selectSelectedProfileId);
const selectedProfileId = useAppSelector(
(store) => store.profiles.selectedProfileId,
);
const hasDoneInitialConfigLoad = useRef(false);
const handleConfigUpdate = useCallback(
async (
isInitial: boolean,
result: {
result: ConfigResult<BrowserSerializedContinueConfig>;
profileId: string | null;
},
) => {
const { result: configResult, profileId } = result;
async (isInitial: boolean, result: FromCoreProtocol["configUpdate"][0]) => {
const {
result: configResult,
profileId,
organizations,
selectedOrgId,
} = result;
if (isInitial && hasDoneInitialConfigLoad.current) {
return;
}
hasDoneInitialConfigLoad.current = true;
dispatch(setConfigResult(configResult));
dispatch(setOrganizations(organizations));
dispatch(setSelectedOrgId(selectedOrgId));
dispatch(setSelectedProfile(profileId));
dispatch(setConfigResult(configResult));
const isNewProfileId = profileId && profileId !== selectedProfileId;

View file

@ -8,13 +8,13 @@ import {
Transition,
} from "../../components/ui";
import { useAuth } from "../../context/Auth";
import { selectSelectedOrganization } from "../../redux";
import { selectCurrentOrg } from "../../redux";
import { useAppSelector } from "../../redux/hooks";
import { ScopeSelect } from "./ScopeSelect";
export function AccountButton() {
const { session, logout, login, organizations } = useAuth();
const selectedOrg = useAppSelector(selectSelectedOrganization);
const selectedOrg = useAppSelector(selectCurrentOrg);
if (!session) {
return (

View file

@ -12,14 +12,14 @@ import {
} from "../../components/ui/Listbox";
import { useAuth } from "../../context/Auth";
import { IdeMessengerContext } from "../../context/IdeMessenger";
import { setSelectedOrgId } from "../../redux";
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
import { setSelectedOrgId } from "../../redux/slices/profiles/slice";
export function ScopeSelect() {
const { organizations, selectedOrganization } = useAuth();
const ideMessenger = useContext(IdeMessengerContext);
const selectedOrgId = useAppSelector(
(state) => state.organizations.selectedOrganizationId,
(state) => state.profiles.selectedOrganizationId,
);
const dispatch = useAppDispatch();

View file

@ -17,7 +17,7 @@ import { getFontSize } from "../../util";
export function UserSettingsForm() {
/////// User settings section //////
const dispatch = useAppDispatch();
const { selectedProfile, controlServerBetaEnabled } = useAuth();
const { controlServerBetaEnabled } = useAuth();
const ideMessenger = useContext(IdeMessengerContext);
const config = useAppSelector((state) => state.config.config);

View file

@ -1,2 +0,0 @@
export * from "./slice";
export * from "./thunks";

View file

@ -1,40 +0,0 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { OrganizationDescription } from "core/config/ProfileLifecycleManager";
export interface OrganizationsState {
organizations: OrganizationDescription[];
selectedOrganizationId: string | null;
}
const initialState: OrganizationsState = {
organizations: [],
selectedOrganizationId: null,
};
export const organizationsSlice = createSlice({
name: "organizations",
initialState,
reducers: {
setOrganizations: (
state,
{ payload }: PayloadAction<OrganizationDescription[]>,
) => {
state.organizations = payload;
},
setSelectedOrgId: (state, { payload }: PayloadAction<string | null>) => {
state.selectedOrganizationId = payload;
},
},
selectors: {
selectSelectedOrganization: (state) =>
state.organizations.find(
(org) => org.id === state.selectedOrganizationId,
) ?? null,
},
});
export const { setOrganizations } = organizationsSlice.actions;
export const { selectSelectedOrganization } = organizationsSlice.selectors;
export const { reducer: organizationsReducer } = organizationsSlice;

View file

@ -1,2 +1 @@
export * from "./slice";
export * from "./thunks";

View file

@ -1,6 +1,6 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { SlashCommandDescription } from "core";
import { ProfileDescription } from "core/config/ConfigHandler";
import { SerializedOrgWithProfiles } from "core/config/ProfileLifecycleManager";
const DEFAULT_SLASH_COMMANDS_BOOKMARKS_COUNT = 5;
@ -13,15 +13,40 @@ export interface PreferencesState {
}
export interface ProfilesState {
availableProfiles: ProfileDescription[] | null;
organizations: SerializedOrgWithProfiles[];
selectedProfileId: string | null;
selectedOrganizationId: string | null;
preferencesByProfileId: Record<string, PreferencesState>;
}
const initialState: ProfilesState = {
availableProfiles: null,
selectedProfileId: null,
preferencesByProfileId: {},
selectedProfileId: null,
selectedOrganizationId: null,
organizations: [
{
id: "personal",
profiles: [
{
title: "Local Assistant",
id: "local",
errors: [],
profileType: "local",
uri: "",
iconUrl: "",
fullSlug: {
ownerSlug: "",
packageSlug: "",
versionSlug: "",
},
},
],
slug: "",
selectedProfileId: "local",
name: "Personal",
iconUrl: "",
},
],
};
export const profilesSlice = createSlice({
@ -30,12 +55,27 @@ export const profilesSlice = createSlice({
reducers: {
setSelectedProfile: (state, { payload }: PayloadAction<string | null>) => {
state.selectedProfileId = payload;
const currentOrg = state.organizations.find(
(o) => o.id === state.selectedOrganizationId,
);
if (currentOrg) {
currentOrg.selectedProfileId = payload;
}
},
setAvailableProfiles: (
setOrganizations: (
state,
{ payload }: PayloadAction<ProfileDescription[] | null>,
{ payload }: PayloadAction<SerializedOrgWithProfiles[]>,
) => {
state.availableProfiles = payload;
state.organizations = payload;
},
setSelectedOrgId: (state, { payload }: PayloadAction<string | null>) => {
state.selectedOrganizationId = payload;
const org = state.organizations.find((o) => o.id === payload);
if (org) {
state.selectedProfileId = org.selectedProfileId;
} else {
state.selectedProfileId = null;
}
},
initializeProfilePreferences: (
state,
@ -102,15 +142,27 @@ export const profilesSlice = createSlice({
},
selectors: {
selectSelectedProfile: (state) => {
return (
state.availableProfiles?.find(
const selectedOrg = state.organizations.find(
(org) => org.id === state.selectedOrganizationId,
);
if (selectedOrg) {
const profile = selectedOrg.profiles.find(
(profile) => profile.id === state.selectedProfileId,
);
return profile ?? null;
} else {
return null;
}
},
selectCurrentOrg: (state) => {
return (
state.organizations.find(
(org) => org.id === state.selectedOrganizationId,
) ?? null
);
},
selectSelectedProfileId: (state) => state.selectedProfileId,
selectBookmarkedSlashCommands: (state) => {
if (!state.selectedProfileId) return [];
const preferences = state.preferencesByProfileId[state.selectedProfileId];
@ -122,18 +174,19 @@ export const profilesSlice = createSlice({
});
export const {
setAvailableProfiles,
setSelectedProfile,
bookmarkSlashCommand,
unbookmarkSlashCommand,
initializeProfilePreferences,
setOrganizations,
setSelectedOrgId,
} = profilesSlice.actions;
export const {
selectSelectedProfile,
selectSelectedProfileId,
selectBookmarkedSlashCommands,
selectPreferencesByProfileId,
selectCurrentOrg,
} = profilesSlice.selectors;
export const { reducer: profilesReducer } = profilesSlice;

View file

@ -10,7 +10,7 @@ import { createFilter } from "redux-persist-transform-filter";
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
import storage from "redux-persist/lib/storage";
import { IdeMessenger, IIdeMessenger } from "../context/IdeMessenger";
import { organizationsReducer, profilesReducer } from "./slices";
import { profilesReducer } from "./slices";
import configReducer from "./slices/configSlice";
import editModeStateReducer from "./slices/editModeState";
import indexingReducer from "./slices/indexingSlice";
@ -31,7 +31,6 @@ const rootReducer = combineReducers({
indexing: indexingReducer,
tabs: tabsReducer,
profiles: profilesReducer,
organizations: organizationsReducer,
});
const saveSubsetFilters = [
@ -56,8 +55,12 @@ const saveSubsetFilters = [
createFilter("ui", ["toolSettings", "toolGroupSettings"]),
createFilter("indexing", []),
createFilter("tabs", ["tabs"]),
createFilter("organizations", ["selectedOrganizationId"]),
createFilter("profiles", ["preferencesByProfileId", "selectedProfileId"]),
createFilter("profiles", [
"preferencesByProfileId",
"selectedProfileId",
"selectedOrganizationId",
"organizations",
]),
];
const migrations: MigrationManifest = {