BROKEN - cascading config updates part 1
This commit is contained in:
parent
97960fa517
commit
b8de35cd8a
20 changed files with 227 additions and 540 deletions
|
|
@ -9,7 +9,7 @@ import { defaultConfig } from "./default";
|
|||
|
||||
describe.skip("Test the ConfigHandler and E2E config loading", () => {
|
||||
test("should show only local profile", () => {
|
||||
const profiles = testConfigHandler.listProfiles();
|
||||
const profiles = testConfigHandler.listProfileDescriptions();
|
||||
expect(profiles?.length).toBe(1);
|
||||
expect(profiles?.[0].id).toBe("local");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { ConfigResult, FullSlug } from "@continuedev/config-yaml";
|
||||
import { ConfigResult } from "@continuedev/config-yaml";
|
||||
|
||||
import {
|
||||
ControlPlaneClient,
|
||||
|
|
@ -25,6 +25,7 @@ import ControlPlaneProfileLoader from "./profile/ControlPlaneProfileLoader.js";
|
|||
import LocalProfileLoader from "./profile/LocalProfileLoader.js";
|
||||
import PlatformProfileLoader from "./profile/PlatformProfileLoader.js";
|
||||
import {
|
||||
OrganizationDescription,
|
||||
ProfileDescription,
|
||||
ProfileLifecycleManager,
|
||||
} from "./ProfileLifecycleManager.js";
|
||||
|
|
@ -38,10 +39,21 @@ type ConfigUpdateFunction = (payload: ConfigResult<ContinueConfig>) => void;
|
|||
export class ConfigHandler {
|
||||
private readonly globalContext = new GlobalContext();
|
||||
private additionalContextProviders: IContextProvider[] = [];
|
||||
private profiles: ProfileLifecycleManager[] | null = null; // null until profiles are loaded
|
||||
private selectedProfileId: string | null = null;
|
||||
private localProfileManager: ProfileLifecycleManager;
|
||||
private profiles: ProfileLifecycleManager[] = [];
|
||||
private globalLocalProfileManager: ProfileLifecycleManager;
|
||||
currentProfile: ProfileLifecycleManager | null = null;
|
||||
private currentProfileId: string | null = null;
|
||||
controlPlaneClient: ControlPlaneClient;
|
||||
_selectedOrgId: string | null = null;
|
||||
_organizations: OrganizationDescription[] = [];
|
||||
|
||||
get organizations() {
|
||||
return this._organizations;
|
||||
}
|
||||
|
||||
get selectedOrgId() {
|
||||
return this._selectedOrgId;
|
||||
}
|
||||
|
||||
initializedPromise: Promise<void>;
|
||||
|
||||
|
|
@ -50,7 +62,6 @@ export class ConfigHandler {
|
|||
private ideSettingsPromise: Promise<IdeSettings>,
|
||||
private readonly writeLog: (text: string) => Promise<void>,
|
||||
sessionInfoPromise: Promise<ControlPlaneSessionInfo | undefined>,
|
||||
private readonly didSelectOrganization?: (orgId: string | null) => void,
|
||||
) {
|
||||
this.ide = ide;
|
||||
this.ideSettingsPromise = ideSettingsPromise;
|
||||
|
|
@ -67,7 +78,7 @@ export class ConfigHandler {
|
|||
this.controlPlaneClient,
|
||||
writeLog,
|
||||
);
|
||||
this.localProfileManager = new ProfileLifecycleManager(
|
||||
this.globalLocalProfileManager = new ProfileLifecycleManager(
|
||||
localProfileLoader,
|
||||
this.ide,
|
||||
);
|
||||
|
|
@ -115,13 +126,7 @@ export class ConfigHandler {
|
|||
}
|
||||
|
||||
private async init() {
|
||||
try {
|
||||
await this.fetchControlPlaneProfiles();
|
||||
} catch (e) {
|
||||
// If this fails, make sure at least local profile is loaded
|
||||
console.error("Failed to fetch control plane profiles in init: ", e);
|
||||
await this.loadLocalProfilesOnly();
|
||||
}
|
||||
await this.fetchControlPlaneProfiles();
|
||||
|
||||
try {
|
||||
const configResult = await this.loadConfig();
|
||||
|
|
@ -131,33 +136,12 @@ export class ConfigHandler {
|
|||
}
|
||||
}
|
||||
|
||||
get currentProfile() {
|
||||
if (!this.selectedProfileId) {
|
||||
return null;
|
||||
}
|
||||
// IMPORTANT
|
||||
// We must fall back to null, not the first or local profiles
|
||||
// Because GUI must be the source of truth for selected profile
|
||||
return (
|
||||
this.profiles?.find(
|
||||
(p) => p.profileDescription.id === this.selectedProfileId,
|
||||
) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
get inactiveProfiles() {
|
||||
return (this.profiles ?? []).filter(
|
||||
(p) => p.profileDescription.id !== this.selectedProfileId,
|
||||
);
|
||||
}
|
||||
|
||||
async openConfigProfile(profileId?: string) {
|
||||
let openProfileId = profileId || this.selectedProfileId;
|
||||
let openProfileId = profileId || this.currentProfileId;
|
||||
const profile = this.profiles?.find(
|
||||
(p) => p.profileDescription.id === openProfileId,
|
||||
);
|
||||
if (profile?.profileDescription.profileType === "local") {
|
||||
const ideInfo = await this.ide.getIdeInfo();
|
||||
await this.ide.openFile(profile.profileDescription.uri);
|
||||
} else {
|
||||
const env = await getControlPlaneEnv(this.ide.getIdeSettings());
|
||||
|
|
@ -165,8 +149,94 @@ export class ConfigHandler {
|
|||
}
|
||||
}
|
||||
|
||||
async listOrganizations() {
|
||||
return await this.controlPlaneClient.listOrganizations();
|
||||
private async cascadeConfigRefresh({
|
||||
refetchOrgs,
|
||||
}: {
|
||||
refetchOrgs: boolean;
|
||||
refetchProfiles: boolean;
|
||||
}) {
|
||||
async function getWorkspaceId(): Promise<string> {
|
||||
const orgPart = (await this.getSelectedOrgId()) ?? "personal";
|
||||
const dirs = await this.ide.getWorkspaceDirs();
|
||||
return `${dirs.join("&")}:::${orgPart}`;
|
||||
}
|
||||
|
||||
// private async updateAvailableProfiles(profiles: ProfileLifecycleManager[]) {
|
||||
// this.profiles = profiles;
|
||||
|
||||
// // If the last selected profile is in the list choose that
|
||||
// // Otherwise, choose the first profile
|
||||
// const previouslySelectedProfileId =
|
||||
// await this.getPersistedSelectedProfileId();
|
||||
|
||||
// // Check if the previously selected profile exists in the current profiles
|
||||
// const profileExists = profiles.some(
|
||||
// (profile) =>
|
||||
// profile.profileDescription.id === previouslySelectedProfileId,
|
||||
// );
|
||||
|
||||
// const selectedProfileId = profileExists
|
||||
// ? previouslySelectedProfileId
|
||||
// : (profiles[0]?.profileDescription.id ?? null);
|
||||
|
||||
// // Notify listeners
|
||||
// const profileDescriptions = profiles.map(
|
||||
// (profile) => profile.profileDescription,
|
||||
// );
|
||||
// this.notifyConfigListeners();
|
||||
// this.notifyProfileListeners(profileDescriptions, selectedProfileId);
|
||||
// await this.setSelectedProfile(selectedProfileId);
|
||||
// }
|
||||
|
||||
// if (config) {
|
||||
// this.inactiveProfiles.forEach((profile) => profile.clearConfig());
|
||||
// return (this.profiles ?? []).filter(
|
||||
// (p) => p.profileDescription.id !== this.selectedProfileId,
|
||||
// );
|
||||
// }
|
||||
|
||||
// SET SELECTED PROFILE ID
|
||||
const result = await this.loadConfig();
|
||||
this.notifyConfigListeners(result);
|
||||
const selectedProfiles =
|
||||
this.globalContext.get("lastSelectedProfileForWorkspace") ?? {};
|
||||
selectedProfiles[await getWorkspaceId()] = profileId;
|
||||
this.globalContext.update(
|
||||
"lastSelectedProfileForWorkspace",
|
||||
selectedProfiles,
|
||||
);
|
||||
|
||||
// OTHER CASCADE STUFF
|
||||
// async getPersistedSelectedProfileId(): Promise<string | null> {
|
||||
// const workspaceId = await this.getWorkspaceId();
|
||||
// const lastSelectedIds =
|
||||
// this.globalContext.get("lastSelectedProfileForWorkspace") ?? {};
|
||||
// return lastSelectedIds[workspaceId] ?? null;
|
||||
// }
|
||||
|
||||
// async getSelectedOrgId(): Promise<string | null> {
|
||||
// const selectedOrgs =
|
||||
// this.globalContext.get("lastSelectedOrgIdForWorkspace") ?? {};
|
||||
// const workspaceId = await this.getWorkspaceId();
|
||||
// return selectedOrgs[workspaceId] ?? null;
|
||||
// }
|
||||
|
||||
// async setSelectedOrgId(orgId: string | null) {
|
||||
// const selectedOrgs =
|
||||
// this.globalContext.get("lastSelectedOrgIdForWorkspace") ?? {};
|
||||
// selectedOrgs[await this.getWorkspaceId()] = orgId;
|
||||
// this.globalContext.update("lastSelectedOrgIdForWorkspace", selectedOrgs);
|
||||
// }
|
||||
}
|
||||
|
||||
async setSelectedOrgId(orgId: string | null) {
|
||||
this._selectedOrgId = orgId;
|
||||
await this.cascadeConfigRefresh();
|
||||
}
|
||||
|
||||
async setSelectedProfile(profileId: string | null) {
|
||||
this.currentProfile = profileId;
|
||||
await this.cascadeConfigRefresh();
|
||||
}
|
||||
|
||||
async loadAssistantsForSelectedOrg() {
|
||||
|
|
@ -217,97 +287,20 @@ export class ConfigHandler {
|
|||
}
|
||||
}
|
||||
|
||||
await this.updateAvailableProfiles(profiles);
|
||||
this.profiles = profiles;
|
||||
await this.cascadeConfigRefresh();
|
||||
}
|
||||
|
||||
private async getAllLocalProfiles() {
|
||||
const localAssistantProfiles = await this.getLocalAssistantProfiles();
|
||||
return [this.localProfileManager, ...localAssistantProfiles];
|
||||
}
|
||||
|
||||
private async loadLocalProfilesOnly() {
|
||||
const allLocalProfiles = await this.getAllLocalProfiles();
|
||||
await this.updateAvailableProfiles(allLocalProfiles);
|
||||
}
|
||||
|
||||
private async updateAvailableProfiles(profiles: ProfileLifecycleManager[]) {
|
||||
this.profiles = profiles;
|
||||
|
||||
// If the last selected profile is in the list choose that
|
||||
// Otherwise, choose the first profile
|
||||
const previouslySelectedProfileId =
|
||||
await this.getPersistedSelectedProfileId();
|
||||
|
||||
// Check if the previously selected profile exists in the current profiles
|
||||
const profileExists = profiles.some(
|
||||
(profile) =>
|
||||
profile.profileDescription.id === previouslySelectedProfileId,
|
||||
);
|
||||
|
||||
const selectedProfileId = profileExists
|
||||
? previouslySelectedProfileId
|
||||
: (profiles[0]?.profileDescription.id ?? null);
|
||||
|
||||
// Notify listeners
|
||||
const profileDescriptions = profiles.map(
|
||||
(profile) => profile.profileDescription,
|
||||
);
|
||||
this.notifyProfileListeners(profileDescriptions, selectedProfileId);
|
||||
await this.setSelectedProfile(selectedProfileId);
|
||||
}
|
||||
|
||||
private platformProfilesRefreshInterval: NodeJS.Timeout | undefined;
|
||||
// We use this to keep track of whether we should reload the assistants
|
||||
private lastFullSlugsList: FullSlug[] = [];
|
||||
|
||||
private fullSlugsListsDiffer(a: FullSlug[], b: FullSlug[]): boolean {
|
||||
if (a.length !== b.length) {
|
||||
return true;
|
||||
}
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i].ownerSlug !== b[i].ownerSlug) {
|
||||
return true;
|
||||
}
|
||||
if (a[i].packageSlug !== b[i].packageSlug) {
|
||||
return true;
|
||||
}
|
||||
if (a[i].versionSlug !== b[i].versionSlug) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private async reloadHubAssistants() {
|
||||
const selectedOrgId = await this.getSelectedOrgId();
|
||||
const newFullSlugsList =
|
||||
await this.controlPlaneClient.listAssistantFullSlugs(selectedOrgId);
|
||||
|
||||
if (newFullSlugsList) {
|
||||
const shouldReload = this.fullSlugsListsDiffer(
|
||||
newFullSlugsList,
|
||||
this.lastFullSlugsList,
|
||||
);
|
||||
if (shouldReload) {
|
||||
await this.loadAssistantsForSelectedOrg();
|
||||
}
|
||||
this.lastFullSlugsList = newFullSlugsList;
|
||||
}
|
||||
return [this.globalLocalProfileManager, ...localAssistantProfiles];
|
||||
}
|
||||
|
||||
private async fetchControlPlaneProfiles() {
|
||||
if (await useHub(this.ideSettingsPromise)) {
|
||||
clearInterval(this.platformProfilesRefreshInterval);
|
||||
await this.loadAssistantsForSelectedOrg();
|
||||
|
||||
// Every 5 seconds we ask the platform whether there are any assistant updates in the last 5 seconds
|
||||
// If so, we do the full (more expensive) reload
|
||||
this.platformProfilesRefreshInterval = setInterval(
|
||||
this.reloadHubAssistants.bind(this),
|
||||
PlatformProfileLoader.RELOAD_INTERVAL,
|
||||
);
|
||||
} else {
|
||||
try {
|
||||
try {
|
||||
if (await useHub(this.ideSettingsPromise)) {
|
||||
await this.loadAssistantsForSelectedOrg();
|
||||
} else {
|
||||
const workspaces = await this.controlPlaneClient.listWorkspaces();
|
||||
const profiles = await this.getAllLocalProfiles();
|
||||
workspaces.forEach((workspace) => {
|
||||
|
|
@ -323,60 +316,20 @@ export class ConfigHandler {
|
|||
|
||||
profiles.push(new ProfileLifecycleManager(profileLoader, this.ide));
|
||||
});
|
||||
|
||||
await this.updateAvailableProfiles(profiles);
|
||||
} catch (e: any) {
|
||||
console.error("Failed to load profiles: ", e);
|
||||
await this.loadLocalProfilesOnly();
|
||||
this.profiles = profiles;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to load profiles: ", e);
|
||||
this.profiles = await this.getAllLocalProfiles();
|
||||
} finally {
|
||||
await this.cascadeConfigRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
async getPersistedSelectedProfileId(): Promise<string | null> {
|
||||
const workspaceId = await this.getWorkspaceId();
|
||||
const lastSelectedIds =
|
||||
this.globalContext.get("lastSelectedProfileForWorkspace") ?? {};
|
||||
return lastSelectedIds[workspaceId] ?? null;
|
||||
}
|
||||
|
||||
async getSelectedOrgId(): Promise<string | null> {
|
||||
const selectedOrgs =
|
||||
this.globalContext.get("lastSelectedOrgIdForWorkspace") ?? {};
|
||||
const workspaceId = await this.getWorkspaceId();
|
||||
return selectedOrgs[workspaceId] ?? null;
|
||||
}
|
||||
|
||||
async setSelectedOrgId(orgId: string | null) {
|
||||
const selectedOrgs =
|
||||
this.globalContext.get("lastSelectedOrgIdForWorkspace") ?? {};
|
||||
selectedOrgs[await this.getWorkspaceId()] = orgId;
|
||||
this.globalContext.update("lastSelectedOrgIdForWorkspace", selectedOrgs);
|
||||
this.didSelectOrganization?.(orgId);
|
||||
}
|
||||
|
||||
async setSelectedProfile(profileId: string | null) {
|
||||
this.selectedProfileId = profileId;
|
||||
const result = await this.loadConfig();
|
||||
this.notifyConfigListeners(result);
|
||||
const selectedProfiles =
|
||||
this.globalContext.get("lastSelectedProfileForWorkspace") ?? {};
|
||||
selectedProfiles[await this.getWorkspaceId()] = profileId;
|
||||
this.globalContext.update(
|
||||
"lastSelectedProfileForWorkspace",
|
||||
selectedProfiles,
|
||||
);
|
||||
}
|
||||
|
||||
// A unique ID for the current workspace, built from folder names
|
||||
private async getWorkspaceId(): Promise<string> {
|
||||
const dirs = await this.ide.getWorkspaceDirs();
|
||||
return dirs.join("&");
|
||||
}
|
||||
|
||||
// Automatically refresh config when Continue-related IDE (e.g. VS Code) settings are changed
|
||||
updateIdeSettings(ideSettings: IdeSettings) {
|
||||
this.ideSettingsPromise = Promise.resolve(ideSettings);
|
||||
void this.reloadConfig();
|
||||
void this.cascadeConfigRefresh();
|
||||
}
|
||||
|
||||
async updateControlPlaneSessionInfo(
|
||||
|
|
@ -387,33 +340,7 @@ export class ConfigHandler {
|
|||
this.ideSettingsPromise,
|
||||
);
|
||||
|
||||
this.fetchControlPlaneProfiles().catch(async (e) => {
|
||||
console.error("Failed to fetch control plane profiles: ", e);
|
||||
await this.loadLocalProfilesOnly();
|
||||
await this.reloadConfig();
|
||||
});
|
||||
}
|
||||
|
||||
private profilesListeners: ((
|
||||
profiles: ProfileDescription[],
|
||||
selectedProfileId: string | null,
|
||||
) => void)[] = [];
|
||||
onDidChangeAvailableProfiles(
|
||||
listener: (
|
||||
profiles: ProfileDescription[],
|
||||
selectedProfileId: string | null,
|
||||
) => void,
|
||||
) {
|
||||
this.profilesListeners.push(listener);
|
||||
}
|
||||
|
||||
private notifyProfileListeners(
|
||||
profiles: ProfileDescription[],
|
||||
selectedProfileId: string | null,
|
||||
) {
|
||||
for (const listener of this.profilesListeners) {
|
||||
listener(profiles, selectedProfileId);
|
||||
}
|
||||
await this.fetchControlPlaneProfiles();
|
||||
}
|
||||
|
||||
private notifyConfigListeners(result: ConfigResult<ContinueConfig>) {
|
||||
|
|
@ -442,9 +369,7 @@ export class ConfigHandler {
|
|||
const { config, errors, configLoadInterrupted } =
|
||||
await this.currentProfile.reloadConfig(this.additionalContextProviders);
|
||||
|
||||
if (config) {
|
||||
this.inactiveProfiles.forEach((profile) => profile.clearConfig());
|
||||
}
|
||||
await this.cascadeConfigRefresh();
|
||||
|
||||
this.notifyConfigListeners({ config, errors, configLoadInterrupted });
|
||||
return { config, errors, configLoadInterrupted };
|
||||
|
|
@ -465,8 +390,8 @@ export class ConfigHandler {
|
|||
);
|
||||
}
|
||||
|
||||
listProfiles(): ProfileDescription[] | null {
|
||||
return this.profiles?.map((p) => p.profileDescription) ?? null;
|
||||
listProfileDescriptions(): ProfileDescription[] {
|
||||
return this.profiles?.map((p) => p.profileDescription) ?? [];
|
||||
}
|
||||
|
||||
async loadConfig(): Promise<ConfigResult<ContinueConfig>> {
|
||||
|
|
|
|||
31
core/core.ts
31
core/core.ts
|
|
@ -108,11 +108,6 @@ export class Core {
|
|||
ideSettingsPromise,
|
||||
this.onWrite,
|
||||
sessionInfoPromise,
|
||||
(orgId: string | null) => {
|
||||
void messenger.request("didSelectOrganization", {
|
||||
orgId,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
this.docsService = DocsService.createSingleton(
|
||||
|
|
@ -123,8 +118,6 @@ export class Core {
|
|||
|
||||
const mcpManager = MCPManagerSingleton.getInstance();
|
||||
mcpManager.onConnectionsRefreshed = async () => {
|
||||
// This ensures that it triggers a NEW load after waiting for config promise to finish
|
||||
await this.configHandler.loadConfig();
|
||||
await this.configHandler.reloadConfig();
|
||||
};
|
||||
|
||||
|
|
@ -134,6 +127,9 @@ export class Core {
|
|||
result: serializedResult,
|
||||
profileId:
|
||||
this.configHandler.currentProfile?.profileDescription.id ?? null,
|
||||
selectedOrgId: this.configHandler.selectedOrgId,
|
||||
availableOrgProfiles: this.configHandler.listProfileDescriptions(),
|
||||
availableOrgs: this.configHandler.organizations,
|
||||
});
|
||||
|
||||
// update additional submenu context providers registered via VSCode API
|
||||
|
|
@ -146,14 +142,6 @@ export class Core {
|
|||
}
|
||||
});
|
||||
|
||||
this.configHandler.onDidChangeAvailableProfiles(
|
||||
(profiles, selectedProfileId) =>
|
||||
this.messenger.send("didChangeAvailableProfiles", {
|
||||
profiles,
|
||||
selectedProfileId,
|
||||
}),
|
||||
);
|
||||
|
||||
// Dev Data Logger
|
||||
const dataLogger = DataLogger.getInstance();
|
||||
dataLogger.core = this;
|
||||
|
|
@ -308,13 +296,6 @@ export class Core {
|
|||
this.configHandler.updateIdeSettings(msg.data);
|
||||
});
|
||||
|
||||
on("config/listProfiles", async (msg) => {
|
||||
const profiles = this.configHandler.listProfiles();
|
||||
const selectedProfileId =
|
||||
this.configHandler.currentProfile?.profileDescription.id ?? null;
|
||||
return { profiles, selectedProfileId };
|
||||
});
|
||||
|
||||
on("config/refreshProfiles", async (msg) => {
|
||||
await this.configHandler.loadAssistantsForSelectedOrg();
|
||||
});
|
||||
|
|
@ -344,10 +325,6 @@ export class Core {
|
|||
await this.messenger.request("openUrl", url);
|
||||
});
|
||||
|
||||
on("controlPlane/listOrganizations", async (msg) => {
|
||||
return await this.configHandler.listOrganizations();
|
||||
});
|
||||
|
||||
on("mcp/reloadServer", async (msg) => {
|
||||
mcpManager.refreshConnection(msg.data.id);
|
||||
});
|
||||
|
|
@ -829,7 +806,7 @@ export class Core {
|
|||
//
|
||||
|
||||
on("didChangeSelectedProfile", async (msg) => {
|
||||
await this.configHandler.setSelectedProfile(msg.data.id);
|
||||
await this.configHandler.setSelectedProfileId(msg.data.id);
|
||||
await this.configHandler.reloadConfig();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ import {
|
|||
} from "@continuedev/config-yaml";
|
||||
|
||||
import { AutocompleteInput } from "../autocomplete/util/types";
|
||||
import { ProfileDescription } from "../config/ConfigHandler";
|
||||
import { OrganizationDescription } from "../config/ProfileLifecycleManager";
|
||||
import { SharedConfigSchema } from "../config/sharedConfig";
|
||||
import { GlobalContextModelSelections } from "../util/GlobalContext";
|
||||
|
||||
|
|
@ -32,6 +30,7 @@ import type {
|
|||
SlashCommandDescription,
|
||||
ToolCall,
|
||||
} from "../";
|
||||
import { ControlPlaneSessionInfo } from "../control-plane/client";
|
||||
|
||||
export type OnboardingModes = "Local" | "Best" | "Custom" | "Quickstart";
|
||||
|
||||
|
|
@ -70,10 +69,6 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
];
|
||||
"config/deleteModel": [{ title: string }, void];
|
||||
"config/reload": [undefined, ConfigResult<BrowserSerializedContinueConfig>];
|
||||
"config/listProfiles": [
|
||||
undefined,
|
||||
{ profiles: ProfileDescription[] | null; selectedProfileId: string | null },
|
||||
];
|
||||
"config/refreshProfiles": [undefined, void];
|
||||
"config/openProfile": [{ profileId: string | undefined }, void];
|
||||
"config/updateSharedConfig": [SharedConfigSchema, SharedConfigSchema];
|
||||
|
|
@ -198,5 +193,8 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
];
|
||||
"clipboardCache/add": [{ content: string }, void];
|
||||
"controlPlane/openUrl": [{ path: string; orgSlug: string | undefined }, void];
|
||||
"controlPlane/listOrganizations": [undefined, OrganizationDescription[]];
|
||||
didChangeControlPlaneSessionInfo: [
|
||||
{ sessionInfo: ControlPlaneSessionInfo | undefined },
|
||||
void,
|
||||
];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import { ProfileDescription } from "../config/ConfigHandler.js";
|
||||
|
||||
import { ToCoreFromIdeOrWebviewProtocol } from "./core.js";
|
||||
import { ToWebviewFromIdeOrCoreProtocol } from "./webview.js";
|
||||
|
||||
|
|
@ -10,10 +8,4 @@ export type ToCoreFromWebviewProtocol = ToCoreFromIdeOrWebviewProtocol & {
|
|||
void,
|
||||
];
|
||||
};
|
||||
export type ToWebviewFromCoreProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
||||
didChangeAvailableProfiles: [
|
||||
{ profiles: ProfileDescription[]; selectedProfileId: string | null },
|
||||
void,
|
||||
];
|
||||
didSelectOrganization: [{ orgId: string | null }, void];
|
||||
};
|
||||
export type ToWebviewFromCoreProtocol = ToWebviewFromIdeOrCoreProtocol;
|
||||
|
|
|
|||
|
|
@ -102,9 +102,4 @@ export type ToIdeFromWebviewOrCoreProtocol = {
|
|||
|
||||
export type ToWebviewOrCoreFromIdeProtocol = {
|
||||
didChangeActiveTextEditor: [{ filepath: string }, void];
|
||||
didChangeControlPlaneSessionInfo: [
|
||||
{ sessionInfo: ControlPlaneSessionInfo | undefined },
|
||||
void,
|
||||
];
|
||||
didChangeIdeSettings: [{ settings: IdeSettings }, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"config/ideSettingsUpdate",
|
||||
"config/getSerializedProfileInfo",
|
||||
"config/deleteModel",
|
||||
"config/listProfiles",
|
||||
"config/refreshProfiles",
|
||||
"config/openProfile",
|
||||
"config/updateSharedConfig",
|
||||
|
|
@ -60,7 +59,6 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"didChangeSelectedOrg",
|
||||
"tools/call",
|
||||
"controlPlane/openUrl",
|
||||
"controlPlane/listOrganizations",
|
||||
];
|
||||
|
||||
// Message types to pass through from core to webview
|
||||
|
|
@ -75,10 +73,8 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] =
|
|||
"addContextItem",
|
||||
"refreshSubmenuItems",
|
||||
"isContinueInputFocused",
|
||||
"didChangeAvailableProfiles",
|
||||
"setTTSActive",
|
||||
"getWebviewHistoryLength",
|
||||
"getCurrentSessionId",
|
||||
"didCloseFiles",
|
||||
"didSelectOrganization",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
import { ConfigResult } from "@continuedev/config-yaml";
|
||||
import {
|
||||
OrganizationDescription,
|
||||
ProfileDescription,
|
||||
} from "../config/ProfileLifecycleManager.js";
|
||||
import type {
|
||||
BrowserSerializedContinueConfig,
|
||||
ContextItemWithId,
|
||||
ContextProviderName,
|
||||
IndexingProgressUpdate,
|
||||
IndexingStatus,
|
||||
PackageDocsResult,
|
||||
} from "../index.js";
|
||||
|
||||
export type ToWebviewFromIdeOrCoreProtocol = {
|
||||
|
|
@ -13,6 +16,9 @@ export type ToWebviewFromIdeOrCoreProtocol = {
|
|||
{
|
||||
result: ConfigResult<BrowserSerializedContinueConfig>;
|
||||
profileId: string | null;
|
||||
availableOrgs: OrganizationDescription[];
|
||||
selectedOrgId: string | null;
|
||||
availableOrgProfiles: ProfileDescription[];
|
||||
},
|
||||
void,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -152,17 +152,12 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
|
|||
val connection = ApplicationManager.getApplication().messageBus.connect()
|
||||
connection.subscribe(SettingsListener.TOPIC, object : SettingsListener {
|
||||
override fun settingsUpdated(settings: ContinueExtensionSettings.ContinueState) {
|
||||
continuePluginService.coreMessenger?.request("config/ideSettingsUpdate", settings, null) { _ -> }
|
||||
continuePluginService.sendToWebview(
|
||||
"didChangeIdeSettings", mapOf(
|
||||
"settings" to mapOf(
|
||||
"remoteConfigServerUrl" to settings.remoteConfigServerUrl,
|
||||
"remoteConfigSyncPeriod" to settings.remoteConfigSyncPeriod,
|
||||
"userToken" to settings.userToken,
|
||||
"enableControlServerBeta" to settings.enableContinueTeamsBeta
|
||||
)
|
||||
)
|
||||
)
|
||||
continuePluginService.coreMessenger?.request("config/ideSettingsUpdate", mapOf(
|
||||
"remoteConfigServerUrl" to settings.remoteConfigServerUrl,
|
||||
"remoteConfigSyncPeriod" to settings.remoteConfigSyncPeriod,
|
||||
"userToken" to settings.userToken,
|
||||
"enableControlServerBeta" to settings.enableContinueTeamsBeta
|
||||
), null) { _ -> }
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -236,7 +231,6 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
|
|||
"sessionInfo" to initialSessionInfo
|
||||
)
|
||||
continuePluginService.coreMessenger?.request("didChangeControlPlaneSessionInfo", data, null) { _ -> }
|
||||
continuePluginService.sendToWebview("didChangeControlPlaneSessionInfo", data)
|
||||
}
|
||||
|
||||
connection.subscribe(AuthListener.TOPIC, object : AuthListener {
|
||||
|
|
@ -253,7 +247,6 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
|
|||
data,
|
||||
null
|
||||
) { _ -> }
|
||||
continuePluginService.sendToWebview("didChangeControlPlaneSessionInfo", data)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -65,12 +65,10 @@ class MessageTypes {
|
|||
"addContextItem",
|
||||
"refreshSubmenuItems",
|
||||
"isContinueInputFocused",
|
||||
"didChangeAvailableProfiles",
|
||||
"setTTSActive",
|
||||
"getWebviewHistoryLength",
|
||||
"getCurrentSessionId",
|
||||
"didCloseFiles",
|
||||
"didSelectOrganization"
|
||||
)
|
||||
|
||||
// Note: If updating these values, make a corresponding update in
|
||||
|
|
@ -87,7 +85,6 @@ class MessageTypes {
|
|||
"config/ideSettingsUpdate",
|
||||
"config/getSerializedProfileInfo",
|
||||
"config/deleteModel",
|
||||
"config/listProfiles",
|
||||
"config/refreshProfiles",
|
||||
"config/openProfile",
|
||||
"config/updateSharedConfig",
|
||||
|
|
@ -128,8 +125,6 @@ class MessageTypes {
|
|||
"didChangeSelectedOrg",
|
||||
"tools/call",
|
||||
"controlPlane/openUrl",
|
||||
"controlPlane/listOrganizations"
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ class IdeProtocolClient(
|
|||
.handleUpdatedSessionInfo(null)
|
||||
|
||||
// Tell the webview that session info changed
|
||||
continuePluginService.sendToWebview("didChangeControlPlaneSessionInfo", null, uuid())
|
||||
continuePluginService.coreMessenger?.request("didChangeControlPlaneSessionInfo", null, null) { _ -> }
|
||||
|
||||
respond(null)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,14 +334,6 @@ export class VsCodeExtension {
|
|||
);
|
||||
|
||||
const sessionInfo = await getControlPlaneSessionInfo(true, false);
|
||||
this.webviewProtocolPromise.then(async (webviewProtocol) => {
|
||||
void webviewProtocol.request("didChangeControlPlaneSessionInfo", {
|
||||
sessionInfo,
|
||||
});
|
||||
|
||||
// To make sure continue-proxy models and anything else requiring it get updated access token
|
||||
this.configHandler.reloadConfig();
|
||||
});
|
||||
void this.core.invoke("didChangeControlPlaneSessionInfo", {
|
||||
sessionInfo,
|
||||
});
|
||||
|
|
@ -415,10 +407,7 @@ export class VsCodeExtension {
|
|||
vscode.workspace.onDidChangeConfiguration(async (event) => {
|
||||
if (event.affectsConfiguration(EXTENSION_NAME)) {
|
||||
const settings = await this.ide.getIdeSettings();
|
||||
const webviewProtocol = await this.webviewProtocolPromise;
|
||||
void webviewProtocol.request("didChangeIdeSettings", {
|
||||
settings,
|
||||
});
|
||||
void this.core.invoke("config/ideSettingsUpdate", settings);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import {
|
|||
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useAuth } from "../../../context/Auth";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { cycleProfile, selectProfileThunk } from "../../../redux";
|
||||
import { setSelectedProfile } from "../../../redux";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import {
|
||||
fontSize,
|
||||
|
|
@ -52,7 +52,12 @@ const AssistantSelectOption = ({
|
|||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
function handleOptionClick() {
|
||||
dispatch(selectProfileThunk(profile.id));
|
||||
// optimistic update
|
||||
dispatch(setSelectedProfile(profile.id));
|
||||
// notify core which will handle actual update
|
||||
ideMessenger.post("didChangeSelectedProfile", {
|
||||
id: profile.id,
|
||||
});
|
||||
onClick();
|
||||
}
|
||||
|
||||
|
|
@ -142,6 +147,9 @@ export default function AssistantSelect() {
|
|||
const dispatch = useAppDispatch();
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
const { selectedProfile, selectedOrganization } = useAuth();
|
||||
const availableProfiles = useAppSelector(
|
||||
(store) => store.profiles.availableProfiles,
|
||||
);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const isLumpToolbarExpanded = useAppSelector(
|
||||
(state) => state.ui.isBlockSettingsToolbarExpanded,
|
||||
|
|
@ -176,8 +184,24 @@ export default function AssistantSelect() {
|
|||
const now = Date.now();
|
||||
|
||||
if (now - lastToggleTime >= DEBOUNCE_MS) {
|
||||
dispatch(cycleProfile());
|
||||
lastToggleTime = now;
|
||||
|
||||
const profileIds =
|
||||
availableProfiles?.map((profile) => profile.id) ?? [];
|
||||
// In case of 1 or 0 profiles just does nothing
|
||||
if (profileIds.length < 2) {
|
||||
return;
|
||||
}
|
||||
let nextId = profileIds[0];
|
||||
if (selectedProfile) {
|
||||
const curIndex = profileIds.indexOf(selectedProfile.id);
|
||||
const nextIndex = (curIndex + 1) % profileIds.length;
|
||||
nextId = profileIds[nextIndex];
|
||||
}
|
||||
dispatch(setSelectedProfile(nextId));
|
||||
ideMessenger.post("didChangeSelectedProfile", {
|
||||
id: nextId,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -186,7 +210,7 @@ export default function AssistantSelect() {
|
|||
return () => {
|
||||
window.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, []);
|
||||
}, [availableProfiles, selectedProfile]);
|
||||
|
||||
const tinyFont = useFontSize(-4);
|
||||
const smallFont = useFontSize(-3);
|
||||
|
|
|
|||
|
|
@ -11,11 +11,8 @@ import React, {
|
|||
useState,
|
||||
} from "react";
|
||||
import ConfirmationDialog from "../components/dialogs/ConfirmationDialog";
|
||||
import { useWebviewListener } from "../hooks/useWebviewListener";
|
||||
import { updateOrgsThunk, updateProfilesThunk } from "../redux";
|
||||
import { selectSelectedProfile } from "../redux/";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice";
|
||||
import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice";
|
||||
import { IdeMessengerContext } from "./IdeMessenger";
|
||||
|
||||
|
|
@ -100,23 +97,17 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
);
|
||||
};
|
||||
|
||||
useWebviewListener("didChangeControlPlaneSessionInfo", async (data) => {
|
||||
setSession(data.sessionInfo);
|
||||
// On logout, clear the list of orgs
|
||||
if (!data.sessionInfo) {
|
||||
dispatch(updateOrgsThunk([]));
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
ideMessenger
|
||||
.request("getControlPlaneSessionInfo", {
|
||||
async function init() {
|
||||
const result = await ideMessenger.request("getControlPlaneSessionInfo", {
|
||||
silent: true,
|
||||
useOnboarding: false,
|
||||
})
|
||||
.then(
|
||||
(result) => result.status === "success" && setSession(result.content),
|
||||
);
|
||||
});
|
||||
if (result.status === "success") {
|
||||
setSession(result.content);
|
||||
}
|
||||
}
|
||||
void init();
|
||||
}, []);
|
||||
|
||||
const [controlServerBetaEnabled, setControlServerBetaEnabled] =
|
||||
|
|
@ -127,50 +118,20 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
.getIdeSettings()
|
||||
.then(({ enableControlServerBeta, continueTestEnvironment }) => {
|
||||
setControlServerBetaEnabled(enableControlServerBeta);
|
||||
dispatch(
|
||||
setLastControlServerBetaEnabledStatus(enableControlServerBeta),
|
||||
);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (session) {
|
||||
ideMessenger
|
||||
.request("controlPlane/listOrganizations", undefined)
|
||||
.then((result) => {
|
||||
if (result.status === "success") {
|
||||
dispatch(updateOrgsThunk(result.content));
|
||||
} else {
|
||||
dispatch(updateOrgsThunk([]));
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [session]);
|
||||
|
||||
useWebviewListener(
|
||||
"didChangeIdeSettings",
|
||||
async (msg) => {
|
||||
const { settings } = msg;
|
||||
setControlServerBetaEnabled(settings.enableControlServerBeta);
|
||||
dispatch(
|
||||
setLastControlServerBetaEnabledStatus(settings.enableControlServerBeta),
|
||||
);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
ideMessenger.request("config/listProfiles", undefined).then((result) => {
|
||||
if (result.status === "success") {
|
||||
dispatch(
|
||||
updateProfilesThunk({
|
||||
profiles: result.content.profiles,
|
||||
selectedProfileId: result.content.selectedProfileId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
// useWebviewListener(
|
||||
// setControlServerBetaEnabled(settings.enableControlServerBeta);
|
||||
// "didChangeIdeSettings",
|
||||
// async (msg) => {
|
||||
// const { settings } = msg;
|
||||
// dispatch(
|
||||
// setLastControlServerBetaEnabledStatus(settings.enableControlServerBeta),
|
||||
// );
|
||||
// },
|
||||
// [],
|
||||
// );
|
||||
|
||||
const refreshProfiles = async () => {
|
||||
try {
|
||||
|
|
@ -182,19 +143,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
}
|
||||
};
|
||||
|
||||
useWebviewListener(
|
||||
"didChangeAvailableProfiles",
|
||||
async (data) => {
|
||||
dispatch(
|
||||
updateProfilesThunk({
|
||||
profiles: data.profiles,
|
||||
selectedProfileId: data.selectedProfileId,
|
||||
}),
|
||||
);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider
|
||||
value={{
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import { IdeMessengerContext } from "../context/IdeMessenger";
|
|||
import { ConfigResult } from "@continuedev/config-yaml";
|
||||
import { BrowserSerializedContinueConfig } from "core";
|
||||
import {
|
||||
initializeProfilePreferencesThunk,
|
||||
selectProfileThunk,
|
||||
initializeProfilePreferences,
|
||||
selectSelectedProfileId,
|
||||
setSelectedProfile,
|
||||
} from "../redux";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
import {
|
||||
|
|
@ -34,28 +34,33 @@ function useSetup() {
|
|||
const defaultModel = useAppSelector(selectDefaultModel);
|
||||
const selectedProfileId = useAppSelector(selectSelectedProfileId);
|
||||
|
||||
const hasLoadedConfig = useRef(false);
|
||||
const hasDoneInitialConfigLoad = useRef(false);
|
||||
|
||||
const handleConfigUpdate = useCallback(
|
||||
async (
|
||||
initial: boolean,
|
||||
isInitial: boolean,
|
||||
result: {
|
||||
result: ConfigResult<BrowserSerializedContinueConfig>;
|
||||
profileId: string | null;
|
||||
},
|
||||
) => {
|
||||
const { result: configResult, profileId } = result;
|
||||
if (initial && hasLoadedConfig.current) {
|
||||
if (isInitial && hasDoneInitialConfigLoad.current) {
|
||||
return;
|
||||
}
|
||||
hasLoadedConfig.current = true;
|
||||
hasDoneInitialConfigLoad.current = true;
|
||||
dispatch(setConfigResult(configResult));
|
||||
dispatch(selectProfileThunk(profileId));
|
||||
dispatch(setSelectedProfile(profileId));
|
||||
|
||||
const isNewProfileId = profileId && profileId !== selectedProfileId;
|
||||
|
||||
if (isNewProfileId) {
|
||||
dispatch(initializeProfilePreferencesThunk({ profileId }));
|
||||
dispatch(
|
||||
initializeProfilePreferences({
|
||||
defaultSlashCommands: [],
|
||||
profileId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// Perform any actions needed with the config
|
||||
|
|
@ -64,28 +69,31 @@ function useSetup() {
|
|||
document.body.style.fontSize = `${configResult.config.ui.fontSize}px`;
|
||||
}
|
||||
},
|
||||
[dispatch, hasLoadedConfig],
|
||||
[dispatch, hasDoneInitialConfigLoad],
|
||||
);
|
||||
|
||||
const loadConfig = useCallback(
|
||||
const initialLoadAuthAndConfig = useCallback(
|
||||
async (initial: boolean) => {
|
||||
// const authResult = await ideMessenger.request(
|
||||
// "auth/getState",
|
||||
// undefined
|
||||
// )
|
||||
const result = await ideMessenger.request(
|
||||
"config/getSerializedProfileInfo",
|
||||
undefined,
|
||||
);
|
||||
if (result.status === "error") {
|
||||
return;
|
||||
if (result.status === "success") {
|
||||
await handleConfigUpdate(initial, result.content);
|
||||
}
|
||||
await handleConfigUpdate(initial, result.content);
|
||||
},
|
||||
[ideMessenger, handleConfigUpdate],
|
||||
);
|
||||
|
||||
// Load config from the IDE
|
||||
useEffect(() => {
|
||||
loadConfig(true);
|
||||
initialLoadAuthAndConfig(true);
|
||||
const interval = setInterval(() => {
|
||||
if (hasLoadedConfig.current) {
|
||||
if (hasDoneInitialConfigLoad.current) {
|
||||
// Init to run on initial config load
|
||||
ideMessenger.post("docs/initStatuses", undefined);
|
||||
dispatch(updateFileSymbolsFromHistory());
|
||||
|
|
@ -93,13 +101,13 @@ function useSetup() {
|
|||
|
||||
// This triggers sending pending status to the GUI for relevant docs indexes
|
||||
clearInterval(interval);
|
||||
return;
|
||||
} else {
|
||||
initialLoadAuthAndConfig(true);
|
||||
}
|
||||
loadConfig(true);
|
||||
}, 2_000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [hasLoadedConfig, loadConfig, ideMessenger]);
|
||||
}, [hasDoneInitialConfigLoad, initialLoadAuthAndConfig, ideMessenger]);
|
||||
|
||||
useWebviewListener(
|
||||
"configUpdate",
|
||||
|
|
@ -109,7 +117,7 @@ function useSetup() {
|
|||
}
|
||||
await handleConfigUpdate(false, update);
|
||||
},
|
||||
[loadConfig],
|
||||
[handleConfigUpdate],
|
||||
);
|
||||
|
||||
// Load symbols for chat on any session change
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import {
|
|||
ListboxOptions,
|
||||
} from "../../components/ui/Listbox";
|
||||
import { useAuth } from "../../context/Auth";
|
||||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { selectOrgThunk } from "../../redux";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
|
||||
|
|
@ -25,10 +24,6 @@ export function ScopeSelect() {
|
|||
dispatch(selectOrgThunk(newValue));
|
||||
};
|
||||
|
||||
useWebviewListener("didSelectOrganization", async (data) => {
|
||||
handleChange(data.orgId);
|
||||
});
|
||||
|
||||
const CurScopeEntityFallBackIcon = selectedOrgId
|
||||
? BuildingOfficeIcon
|
||||
: UserCircleIcon;
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
|
||||
import { PackageDocsResult } from "core";
|
||||
|
||||
export type MiscState = {
|
||||
lastControlServerBetaEnabledStatus: boolean;
|
||||
};
|
||||
|
||||
const initialState: MiscState = {
|
||||
lastControlServerBetaEnabledStatus: false,
|
||||
};
|
||||
|
||||
export const miscSlice = createSlice({
|
||||
name: "misc",
|
||||
initialState,
|
||||
reducers: {
|
||||
setLastControlServerBetaEnabledStatus: (
|
||||
state,
|
||||
action: PayloadAction<boolean>,
|
||||
) => {
|
||||
state.lastControlServerBetaEnabledStatus = action.payload;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const { setLastControlServerBetaEnabledStatus } = miscSlice.actions;
|
||||
|
||||
export default miscSlice.reducer;
|
||||
|
|
@ -21,16 +21,8 @@ export const organizationsSlice = createSlice({
|
|||
) => {
|
||||
state.organizations = payload;
|
||||
},
|
||||
setSelectedOrganizationId: (
|
||||
state,
|
||||
{ payload }: PayloadAction<string | null>,
|
||||
) => {
|
||||
state.selectedOrganizationId = payload;
|
||||
},
|
||||
},
|
||||
selectors: {
|
||||
selectOrganizations: (state) => state.organizations,
|
||||
selectSelectedOrganizationId: (state) => state.selectedOrganizationId,
|
||||
selectSelectedOrganization: (state) =>
|
||||
state.organizations.find(
|
||||
(org) => org.id === state.selectedOrganizationId,
|
||||
|
|
@ -38,13 +30,8 @@ export const organizationsSlice = createSlice({
|
|||
},
|
||||
});
|
||||
|
||||
export const { setOrganizations, setSelectedOrganizationId } =
|
||||
organizationsSlice.actions;
|
||||
export const { setOrganizations } = organizationsSlice.actions;
|
||||
|
||||
export const {
|
||||
selectOrganizations,
|
||||
selectSelectedOrganizationId,
|
||||
selectSelectedOrganization,
|
||||
} = organizationsSlice.selectors;
|
||||
export const { selectSelectedOrganization } = organizationsSlice.selectors;
|
||||
|
||||
export const { reducer: organizationsReducer } = organizationsSlice;
|
||||
|
|
|
|||
|
|
@ -1,108 +0,0 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { ProfileDescription } from "core/config/ConfigHandler";
|
||||
import { ThunkApiType } from "../../store";
|
||||
import {
|
||||
initializeProfilePreferences,
|
||||
setAvailableProfiles,
|
||||
setSelectedProfile,
|
||||
} from "./slice";
|
||||
|
||||
export const selectProfileThunk = createAsyncThunk<
|
||||
void,
|
||||
string | null,
|
||||
ThunkApiType
|
||||
>("profiles/select", async (id, { dispatch, extra, getState }) => {
|
||||
const state = getState();
|
||||
|
||||
if (state.profiles.availableProfiles === null) {
|
||||
// Currently in loading state
|
||||
return;
|
||||
}
|
||||
|
||||
const initialId = state.profiles.selectedProfileId;
|
||||
|
||||
let newId = id;
|
||||
|
||||
// If no profiles, force clear
|
||||
if (state.profiles.availableProfiles.length === 0) {
|
||||
newId = null;
|
||||
} else {
|
||||
// If new id doesn't match an existing profile, clear it
|
||||
if (newId) {
|
||||
if (!state.profiles.availableProfiles.find((p) => p.id === newId)) {
|
||||
newId = null;
|
||||
}
|
||||
}
|
||||
if (!newId) {
|
||||
// At this point if null ID and there ARE profiles,
|
||||
// Fallback to a profile, prioritizing the first in the list
|
||||
newId = state.profiles.availableProfiles[0].id;
|
||||
}
|
||||
}
|
||||
|
||||
// Only update if there's a change
|
||||
if ((newId ?? null) !== (initialId ?? null)) {
|
||||
dispatch(setSelectedProfile(newId));
|
||||
|
||||
extra.ideMessenger.post("didChangeSelectedProfile", {
|
||||
id: newId,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const cycleProfile = createAsyncThunk<void, undefined, ThunkApiType>(
|
||||
"profiles/cycle",
|
||||
async (_, { dispatch, getState }) => {
|
||||
const state = getState();
|
||||
|
||||
if (state.profiles.availableProfiles === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const profileIds = state.profiles.availableProfiles.map(
|
||||
(profile) => profile.id,
|
||||
);
|
||||
// In case of no profiles just does nothing
|
||||
if (profileIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
let nextId = profileIds[0];
|
||||
if (state.profiles.selectedProfileId) {
|
||||
const curIndex = profileIds.indexOf(state.profiles.selectedProfileId);
|
||||
const nextIndex = (curIndex + 1) % profileIds.length;
|
||||
nextId = profileIds[nextIndex];
|
||||
}
|
||||
await dispatch(selectProfileThunk(nextId));
|
||||
},
|
||||
);
|
||||
|
||||
export const updateProfilesThunk = createAsyncThunk<
|
||||
void,
|
||||
{ profiles: ProfileDescription[] | null; selectedProfileId: string | null },
|
||||
ThunkApiType
|
||||
>("profiles/update", async (data, { dispatch, extra, getState }) => {
|
||||
const { profiles, selectedProfileId } = data;
|
||||
|
||||
dispatch(setAvailableProfiles(profiles));
|
||||
|
||||
// This will trigger reselection if needed
|
||||
dispatch(selectProfileThunk(selectedProfileId));
|
||||
});
|
||||
|
||||
export const initializeProfilePreferencesThunk = createAsyncThunk<
|
||||
void,
|
||||
{ profileId: string },
|
||||
ThunkApiType
|
||||
>(
|
||||
"profiles/initializeProfilePreferences",
|
||||
async (data, { getState, dispatch }) => {
|
||||
const { profileId } = data;
|
||||
|
||||
dispatch(
|
||||
initializeProfilePreferences({
|
||||
defaultSlashCommands: [],
|
||||
profileId,
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
@ -14,7 +14,6 @@ import { organizationsReducer, profilesReducer } from "./slices";
|
|||
import configReducer from "./slices/configSlice";
|
||||
import editModeStateReducer from "./slices/editModeState";
|
||||
import indexingReducer from "./slices/indexingSlice";
|
||||
import miscReducer from "./slices/miscSlice";
|
||||
import sessionReducer from "./slices/sessionSlice";
|
||||
import tabsReducer from "./slices/tabsSlice";
|
||||
import uiReducer from "./slices/uiSlice";
|
||||
|
|
@ -26,7 +25,6 @@ export interface ChatMessage {
|
|||
|
||||
const rootReducer = combineReducers({
|
||||
session: sessionReducer,
|
||||
misc: miscReducer,
|
||||
ui: uiReducer,
|
||||
editModeState: editModeStateReducer,
|
||||
config: configReducer,
|
||||
|
|
@ -47,10 +45,6 @@ const saveSubsetFilters = [
|
|||
"mode",
|
||||
"codeToEdit",
|
||||
|
||||
// TODO consider removing persisted profiles/orgs
|
||||
"availableProfiles",
|
||||
"organizations",
|
||||
|
||||
// higher risk to persist
|
||||
// codeBlockApplyStates
|
||||
// symbols
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue