move select profile and org logic to thunks
This commit is contained in:
parent
c829825e32
commit
aa98e1975c
29 changed files with 761 additions and 877 deletions
|
|
@ -14,7 +14,7 @@ describe.skip("Test the ConfigHandler and E2E config loading", () => {
|
|||
expect(profiles[0].id).toBe("local");
|
||||
|
||||
const currentProfile = testConfigHandler.currentProfile;
|
||||
expect(currentProfile.profileDescription.id).toBe("local");
|
||||
expect(currentProfile?.profileDescription.id).toBe("local");
|
||||
});
|
||||
|
||||
test("should load the default config successfully", async () => {
|
||||
|
|
|
|||
|
|
@ -48,8 +48,9 @@ export class ConfigHandler {
|
|||
private readonly globalContext = new GlobalContext();
|
||||
private additionalContextProviders: IContextProvider[] = [];
|
||||
private profiles: ProfileLifecycleManager[];
|
||||
private selectedProfileId: string;
|
||||
private selectedProfileId: string | null;
|
||||
private selectedOrgId: string | null;
|
||||
private localProfileManager: ProfileLifecycleManager;
|
||||
|
||||
constructor(
|
||||
private readonly ide: IDE,
|
||||
|
|
@ -68,21 +69,25 @@ export class ConfigHandler {
|
|||
controlPlaneClient,
|
||||
writeLog,
|
||||
);
|
||||
this.profiles = [new ProfileLifecycleManager(localProfileLoader, this.ide)];
|
||||
this.localProfileManager = new ProfileLifecycleManager(
|
||||
localProfileLoader,
|
||||
this.ide,
|
||||
);
|
||||
this.profiles = [this.localProfileManager];
|
||||
this.selectedProfileId = localProfileLoader.description.id;
|
||||
this.selectedOrgId = null;
|
||||
|
||||
// Always load local profile immediately in case control plane doesn't load
|
||||
try {
|
||||
void this.loadConfig();
|
||||
} catch (e) {
|
||||
console.error("Failed to load config: ", e);
|
||||
}
|
||||
|
||||
void this.init();
|
||||
}
|
||||
|
||||
private async init() {
|
||||
// Always load local profile immediately in case control plane doesn't load
|
||||
try {
|
||||
await this.loadConfig();
|
||||
} catch (e) {
|
||||
console.error("Failed to load config: ", e);
|
||||
}
|
||||
|
||||
const workspaceId = await this.getWorkspaceId();
|
||||
const lastSelectedOrgIds =
|
||||
this.globalContext.get("lastSelectedOrgIdForWorkspace") ?? {};
|
||||
|
|
@ -97,16 +102,17 @@ export class ConfigHandler {
|
|||
void this.fetchControlPlaneProfiles();
|
||||
}
|
||||
|
||||
// This will be the local profile
|
||||
private get fallbackProfile() {
|
||||
return this.profiles[0];
|
||||
}
|
||||
|
||||
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,
|
||||
) ?? this.fallbackProfile
|
||||
) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -165,12 +171,10 @@ export class ConfigHandler {
|
|||
}),
|
||||
);
|
||||
|
||||
this.profiles = [
|
||||
...this.profiles.filter(
|
||||
(profile) => profile.profileDescription.id === "local",
|
||||
),
|
||||
...hubProfiles,
|
||||
];
|
||||
this.profiles =
|
||||
this.selectedOrgId === null
|
||||
? [this.localProfileManager, ...hubProfiles]
|
||||
: hubProfiles;
|
||||
|
||||
this.notifyProfileListeners(
|
||||
this.profiles.map((profile) => profile.profileDescription),
|
||||
|
|
@ -178,19 +182,19 @@ export class ConfigHandler {
|
|||
|
||||
// Check the last selected workspace, and reload if it isn't local
|
||||
const workspaceId = await this.getWorkspaceId();
|
||||
const lastSelectedWorkspaceIds =
|
||||
const lastSelectedIds =
|
||||
this.globalContext.get("lastSelectedProfileForWorkspace") ?? {};
|
||||
|
||||
const selectedWorkspaceId = lastSelectedWorkspaceIds[workspaceId];
|
||||
if (selectedWorkspaceId) {
|
||||
this.selectedProfileId = selectedWorkspaceId;
|
||||
const selectedProfileId = lastSelectedIds[workspaceId];
|
||||
if (selectedProfileId) {
|
||||
this.selectedProfileId = selectedProfileId;
|
||||
await this.loadConfig();
|
||||
} else {
|
||||
// Otherwise we stick with local profile, and record choice
|
||||
lastSelectedWorkspaceIds[workspaceId] = this.selectedProfileId;
|
||||
lastSelectedIds[workspaceId] = this.selectedProfileId;
|
||||
this.globalContext.update(
|
||||
"lastSelectedProfileForWorkspace",
|
||||
lastSelectedWorkspaceIds,
|
||||
lastSelectedIds,
|
||||
);
|
||||
}
|
||||
})
|
||||
|
|
@ -249,9 +253,7 @@ export class ConfigHandler {
|
|||
this.controlPlaneClient
|
||||
.listWorkspaces()
|
||||
.then(async (workspaces) => {
|
||||
this.profiles = this.profiles.filter(
|
||||
(profile) => profile.profileDescription.id === "local",
|
||||
);
|
||||
this.profiles = [this.localProfileManager];
|
||||
workspaces.forEach((workspace) => {
|
||||
const profileLoader = new ControlPlaneProfileLoader(
|
||||
workspace.id,
|
||||
|
|
@ -273,18 +275,18 @@ export class ConfigHandler {
|
|||
|
||||
// Check the last selected workspace, and reload if it isn't local
|
||||
const workspaceId = await this.getWorkspaceId();
|
||||
const lastSelectedWorkspaceIds =
|
||||
const lastSelectedIds =
|
||||
this.globalContext.get("lastSelectedProfileForWorkspace") ?? {};
|
||||
const selectedWorkspaceId = lastSelectedWorkspaceIds[workspaceId];
|
||||
if (selectedWorkspaceId) {
|
||||
this.selectedProfileId = selectedWorkspaceId;
|
||||
const selectedProfileId = lastSelectedIds[workspaceId];
|
||||
if (selectedProfileId) {
|
||||
this.selectedProfileId = selectedProfileId;
|
||||
await this.loadConfig();
|
||||
} else {
|
||||
// Otherwise we stick with local profile, and record choice
|
||||
lastSelectedWorkspaceIds[workspaceId] = this.selectedProfileId;
|
||||
lastSelectedIds[workspaceId] = this.selectedProfileId;
|
||||
this.globalContext.update(
|
||||
"lastSelectedProfileForWorkspace",
|
||||
lastSelectedWorkspaceIds,
|
||||
lastSelectedIds,
|
||||
);
|
||||
}
|
||||
})
|
||||
|
|
@ -302,7 +304,7 @@ export class ConfigHandler {
|
|||
this.globalContext.update("lastSelectedOrgIdForWorkspace", selectedOrgs);
|
||||
}
|
||||
|
||||
async setSelectedProfile(profileId: string) {
|
||||
async setSelectedProfile(profileId: string | null) {
|
||||
this.selectedProfileId = profileId;
|
||||
const result = await this.loadConfig();
|
||||
this.notifyConfigListeners(result);
|
||||
|
|
@ -365,8 +367,15 @@ export class ConfigHandler {
|
|||
this.updateListeners.push(listener);
|
||||
}
|
||||
|
||||
// TODO: this isn't right, there are two different senses in which you want to "reload"
|
||||
async reloadConfig() {
|
||||
// TODO: this isn't right, there are two different senses in which you want to "reload"
|
||||
if (!this.currentProfile) {
|
||||
return {
|
||||
config: undefined,
|
||||
errors: [],
|
||||
configLoadInterrupted: true,
|
||||
};
|
||||
}
|
||||
|
||||
const { config, errors, configLoadInterrupted } =
|
||||
await this.currentProfile.reloadConfig(this.additionalContextProviders);
|
||||
|
|
@ -376,13 +385,20 @@ export class ConfigHandler {
|
|||
}
|
||||
|
||||
this.notifyConfigListeners({ config, errors, configLoadInterrupted });
|
||||
return { config, errors };
|
||||
return { config, errors, configLoadInterrupted };
|
||||
}
|
||||
|
||||
getSerializedConfig(): Promise<
|
||||
async getSerializedConfig(): Promise<
|
||||
ConfigResult<BrowserSerializedContinueConfig>
|
||||
> {
|
||||
return this.currentProfile.getSerializedConfig(
|
||||
if (!this.currentProfile) {
|
||||
return {
|
||||
config: undefined,
|
||||
errors: [],
|
||||
configLoadInterrupted: true,
|
||||
};
|
||||
}
|
||||
return await this.currentProfile.getSerializedConfig(
|
||||
this.additionalContextProviders,
|
||||
);
|
||||
}
|
||||
|
|
@ -392,6 +408,13 @@ export class ConfigHandler {
|
|||
}
|
||||
|
||||
async loadConfig(): Promise<ConfigResult<ContinueConfig>> {
|
||||
if (!this.currentProfile) {
|
||||
return {
|
||||
config: undefined,
|
||||
errors: [],
|
||||
configLoadInterrupted: true,
|
||||
};
|
||||
}
|
||||
return await this.currentProfile.loadConfig(
|
||||
this.additionalContextProviders,
|
||||
);
|
||||
|
|
|
|||
25
core/core.ts
25
core/core.ts
|
|
@ -73,10 +73,6 @@ export class Core {
|
|||
|
||||
private abortedMessageIds: Set<string> = new Set();
|
||||
|
||||
private async config() {
|
||||
return (await this.configHandler.loadConfig()).config;
|
||||
}
|
||||
|
||||
invoke<T extends keyof ToCoreProtocol>(
|
||||
messageType: T,
|
||||
data: ToCoreProtocol[T][0],
|
||||
|
|
@ -136,7 +132,8 @@ export class Core {
|
|||
const serializedResult = await this.configHandler.getSerializedConfig();
|
||||
this.messenger.send("configUpdate", {
|
||||
result: serializedResult,
|
||||
profileId: this.configHandler.currentProfile.profileDescription.id,
|
||||
profileId:
|
||||
this.configHandler.currentProfile?.profileDescription.id ?? null,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -281,10 +278,8 @@ export class Core {
|
|||
});
|
||||
|
||||
on("config/newPromptFile", async (msg) => {
|
||||
await createNewPromptFileV2(
|
||||
this.ide,
|
||||
(await this.config())?.experimental?.promptPath,
|
||||
);
|
||||
const { config } = await this.configHandler.loadConfig();
|
||||
await createNewPromptFileV2(this.ide, config?.experimental?.promptPath);
|
||||
await this.configHandler.reloadConfig();
|
||||
});
|
||||
|
||||
|
|
@ -341,7 +336,7 @@ export class Core {
|
|||
});
|
||||
|
||||
on("context/loadSubmenuItems", async (msg) => {
|
||||
const config = await this.config();
|
||||
const { config } = await this.configHandler.loadConfig();
|
||||
if (!config) {
|
||||
return [];
|
||||
}
|
||||
|
|
@ -358,13 +353,14 @@ export class Core {
|
|||
});
|
||||
|
||||
on("context/getContextItems", async (msg) => {
|
||||
const { name, query, fullInput, selectedCode, selectedModelTitle } =
|
||||
msg.data;
|
||||
const config = await this.config();
|
||||
const { config } = await this.configHandler.loadConfig();
|
||||
if (!config) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const { name, query, fullInput, selectedCode, selectedModelTitle } =
|
||||
msg.data;
|
||||
|
||||
const llm = await this.configHandler.llmFromTitle(selectedModelTitle);
|
||||
const provider =
|
||||
config.contextProviders?.find(
|
||||
|
|
@ -454,7 +450,8 @@ export class Core {
|
|||
on("config/getSerializedProfileInfo", async (msg) => {
|
||||
return {
|
||||
result: await this.configHandler.getSerializedConfig(),
|
||||
profileId: this.configHandler.currentProfile.profileDescription.id,
|
||||
profileId:
|
||||
this.configHandler.currentProfile?.profileDescription.id ?? null,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
undefined,
|
||||
{
|
||||
result: ConfigResult<BrowserSerializedContinueConfig>;
|
||||
profileId: string;
|
||||
profileId: string | null;
|
||||
},
|
||||
];
|
||||
"config/deleteModel": [{ title: string }, void];
|
||||
|
|
@ -184,8 +184,6 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
"docs/getDetails": [{ startUrl: string }, DocsIndexingDetails];
|
||||
addAutocompleteModel: [{ model: ModelDescription }, void];
|
||||
|
||||
"profiles/switch": [{ id: string }, undefined];
|
||||
|
||||
"auth/getAuthUrl": [{ useOnboarding: boolean }, { url: string }];
|
||||
"tools/call": [
|
||||
{ toolCall: ToolCall; selectedModelTitle: string },
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { ToCoreFromIdeOrWebviewProtocol } from "./core.js";
|
|||
import { ToWebviewFromIdeOrCoreProtocol } from "./webview.js";
|
||||
|
||||
export type ToCoreFromWebviewProtocol = ToCoreFromIdeOrWebviewProtocol & {
|
||||
didChangeSelectedProfile: [{ id: string }, void];
|
||||
didChangeSelectedProfile: [{ id: string | null }, void];
|
||||
didChangeSelectedOrg: [{ id: string | null }, void];
|
||||
};
|
||||
export type ToWebviewFromCoreProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
//
|
||||
"completeOnboarding",
|
||||
"addAutocompleteModel",
|
||||
"profiles/switch",
|
||||
"didChangeSelectedProfile",
|
||||
"didChangeSelectedOrg",
|
||||
"tools/call",
|
||||
|
|
@ -82,7 +81,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] =
|
|||
"setTTSActive",
|
||||
"getWebviewHistoryLength",
|
||||
"getCurrentSessionId",
|
||||
"signInToControlPlane",
|
||||
"openDialogMessage",
|
||||
"docs/suggestions",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export type ToWebviewFromIdeOrCoreProtocol = {
|
|||
configUpdate: [
|
||||
{
|
||||
result: ConfigResult<BrowserSerializedContinueConfig>;
|
||||
profileId: string;
|
||||
profileId: string | null;
|
||||
},
|
||||
void,
|
||||
];
|
||||
|
|
@ -37,8 +37,6 @@ export type ToWebviewFromIdeOrCoreProtocol = {
|
|||
setTTSActive: [boolean, void];
|
||||
getWebviewHistoryLength: [undefined, number];
|
||||
getCurrentSessionId: [undefined, string];
|
||||
signInToControlPlane: [undefined, void];
|
||||
openDialogMessage: ["account", void];
|
||||
"docs/suggestions": [PackageDocsResult[], void];
|
||||
"jetbrains/setColors": [Record<string, string>, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ import { SiteIndexingConfig } from "..";
|
|||
export type GlobalContextType = {
|
||||
indexingPaused: boolean;
|
||||
selectedTabAutocompleteModel: string;
|
||||
lastSelectedProfileForWorkspace: { [workspaceIdentifier: string]: string };
|
||||
lastSelectedProfileForWorkspace: {
|
||||
[workspaceIdentifier: string]: string | null;
|
||||
};
|
||||
lastSelectedOrgIdForWorkspace: {
|
||||
[workspaceIdentifier: string]: string | null;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -134,11 +134,4 @@ class OpenMorePageAction : AnAction() {
|
|||
val params = mapOf("path" to "/more", "toggle" to true)
|
||||
continuePluginService.sendToWebview("navigateTo", params)
|
||||
}
|
||||
}
|
||||
|
||||
class OpenAccountDialogAction : AnAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val continuePluginService = getContinuePluginService(e.project) ?: return
|
||||
continuePluginService.sendToWebview("openDialogMessage", "account")
|
||||
}
|
||||
}
|
||||
|
|
@ -70,8 +70,6 @@ class MessageTypes {
|
|||
"setTTSActive",
|
||||
"getWebviewHistoryLength",
|
||||
"getCurrentSessionId",
|
||||
"signInToControlPlane",
|
||||
"openDialogMessage",
|
||||
"docs/suggestions",
|
||||
)
|
||||
|
||||
|
|
@ -126,7 +124,6 @@ class MessageTypes {
|
|||
//
|
||||
"completeOnboarding",
|
||||
"addAutocompleteModel",
|
||||
"profiles/switch",
|
||||
"didChangeSelectedProfile",
|
||||
"didChangeSelectedOrg",
|
||||
"tools/call",
|
||||
|
|
|
|||
|
|
@ -140,14 +140,6 @@
|
|||
<override-text place="GoToAction" text="Continue Config"/>
|
||||
</action>
|
||||
|
||||
<action id="continue.openAccountDialog"
|
||||
class="com.github.continuedev.continueintellijextension.actions.OpenAccountDialogAction"
|
||||
icon="AllIcons.CodeWithMe.CwmAccess"
|
||||
text="Account"
|
||||
description="Account">
|
||||
<override-text place="GoToAction" text="Account"/>
|
||||
</action>
|
||||
|
||||
<action id="continue.openMorePage"
|
||||
class="com.github.continuedev.continueintellijextension.actions.OpenMorePageAction"
|
||||
icon="AllIcons.Actions.MoreHorizontal"
|
||||
|
|
@ -160,7 +152,6 @@
|
|||
<reference ref="continue.newContinueSession"/>
|
||||
<reference ref="continue.viewHistory"/>
|
||||
<reference ref="continue.openConfigPage"/>
|
||||
<reference ref="continue.openAccountDialog"/>
|
||||
<reference ref="continue.openMorePage"/>
|
||||
</group>
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@
|
|||
"continue.enableContinueForTeams": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"markdownDescription": "Enable Continue for teams beta features. To sign in, click the person icon in the bottom right of the sidebar."
|
||||
"markdownDescription": "Enable Continue for teams beta features. To sign in, click the gear icon to go to the settings page, and click Sign In."
|
||||
},
|
||||
"continue.enableContinueHub": {
|
||||
"type": "boolean",
|
||||
|
|
@ -328,20 +328,6 @@
|
|||
"category": "Continue",
|
||||
"title": "Focus Continue Chat",
|
||||
"group": "Continue"
|
||||
},
|
||||
{
|
||||
"command": "continue.signInToControlPlane",
|
||||
"title": "Sign In",
|
||||
"category": "Continue",
|
||||
"group": "Continue",
|
||||
"icon": "$(account)"
|
||||
},
|
||||
{
|
||||
"command": "continue.openAccountDialog",
|
||||
"title": "Account",
|
||||
"category": "Continue",
|
||||
"group": "Continue",
|
||||
"icon": "$(account)"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
|
|
@ -531,16 +517,6 @@
|
|||
"group": "navigation@4",
|
||||
"when": "view == continue.continueGUIView"
|
||||
},
|
||||
{
|
||||
"command": "continue.signInToControlPlane",
|
||||
"group": "navigation@5",
|
||||
"when": "(view == continue.continueGUIView) && (config.continue.enableContinueForTeams || config.continue.enableContinueHub) && !continue.isSignedInToControlPlane"
|
||||
},
|
||||
{
|
||||
"command": "continue.openAccountDialog",
|
||||
"group": "navigation@5",
|
||||
"when": "(view == continue.continueGUIView) && (config.continue.enableContinueForTeams || config.continue.enableContinueHub) && continue.isSignedInToControlPlane"
|
||||
},
|
||||
{
|
||||
"command": "continue.openMorePage",
|
||||
"group": "navigation@6",
|
||||
|
|
|
|||
|
|
@ -916,7 +916,8 @@ const getCommandsMap: (
|
|||
},
|
||||
{
|
||||
label: "$(screen-full) Open full screen chat",
|
||||
description: getMetaKeyLabel() + " + K, " + getMetaKeyLabel() + " + M",
|
||||
description:
|
||||
getMetaKeyLabel() + " + K, " + getMetaKeyLabel() + " + M",
|
||||
},
|
||||
{
|
||||
label: quickPickStatusText(targetStatus),
|
||||
|
|
@ -998,12 +999,6 @@ const getCommandsMap: (
|
|||
sidebar.webviewProtocol?.request("navigateTo", { path, toggle });
|
||||
focusGUI();
|
||||
},
|
||||
"continue.signInToControlPlane": () => {
|
||||
sidebar.webviewProtocol?.request("signInToControlPlane", undefined);
|
||||
},
|
||||
"continue.openAccountDialog": () => {
|
||||
sidebar.webviewProtocol?.request("openDialogMessage", "account");
|
||||
},
|
||||
"continue.startLocalOllama": () => {
|
||||
startLocalOllama(ide);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -168,12 +168,6 @@ export class VsCodeExtension {
|
|||
} else if (newConfig) {
|
||||
setupStatusBar(undefined, undefined, false);
|
||||
|
||||
const result = await this.configHandler.getSerializedConfig();
|
||||
this.sidebar.webviewProtocol?.request("configUpdate", {
|
||||
result,
|
||||
profileId: this.configHandler.currentProfile.profileDescription.id,
|
||||
});
|
||||
|
||||
this.tabAutocompleteModel.clearLlm();
|
||||
|
||||
registerAllCodeLensProviders(
|
||||
|
|
@ -182,8 +176,6 @@ export class VsCodeExtension {
|
|||
newConfig,
|
||||
);
|
||||
}
|
||||
|
||||
this.sidebar.webviewProtocol?.request("configError", errors);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,148 +0,0 @@
|
|||
import { Listbox, Transition } from "@headlessui/react";
|
||||
import { ChevronUpDownIcon } from "@heroicons/react/24/outline";
|
||||
import { Fragment, useContext } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
Button,
|
||||
SecondaryButton,
|
||||
vscInputBackground,
|
||||
vscListActiveBackground,
|
||||
vscListActiveForeground,
|
||||
} from ".";
|
||||
import { useAuth } from "../context/Auth";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { setSelectedProfileId } from "../redux/slices/sessionSlice";
|
||||
import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice";
|
||||
import { getFontSize } from "../util";
|
||||
|
||||
const StyledListboxOption = styled(Listbox.Option)<{ selected: boolean }>`
|
||||
background-color: ${({ selected }) =>
|
||||
selected ? vscListActiveBackground : vscInputBackground};
|
||||
cursor: pointer;
|
||||
padding: 4px 6px;
|
||||
font-size: ${getFontSize() - 1}px;
|
||||
|
||||
&:hover {
|
||||
background-color: ${vscListActiveBackground};
|
||||
color: ${vscListActiveForeground};
|
||||
}
|
||||
`;
|
||||
|
||||
export default function AccountDialog() {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const {
|
||||
session,
|
||||
logout,
|
||||
login,
|
||||
profiles,
|
||||
selectedProfile,
|
||||
controlServerBetaEnabled,
|
||||
} = useAuth();
|
||||
|
||||
// These shouldn't usually show but just to be safe
|
||||
if (!session?.account?.id) {
|
||||
return (
|
||||
<div className="p-4 pt-0">
|
||||
<h1 className="mb-0.5 text-center text-2xl">Account</h1>
|
||||
<span className="text-lightgray mb-4 block text-center">
|
||||
Signed out
|
||||
</span>
|
||||
<Button className="w-full" onClick={() => login(false)}>
|
||||
Sign in
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const changeProfileId = (id: string) => {
|
||||
ideMessenger.post("didChangeSelectedProfile", { id });
|
||||
dispatch(setSelectedProfileId(id));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-5 p-4 pt-0">
|
||||
<div className="flex flex-col items-center text-center">
|
||||
<h1 className="mb-1 text-2xl">Account</h1>
|
||||
<span className="text-lightgray text-sm">
|
||||
{session.account.label === "" ? (
|
||||
"Signed in"
|
||||
) : (
|
||||
<>
|
||||
Signed in as <span className="italic">{session.account.id}</span>
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{controlServerBetaEnabled && (
|
||||
<div className="mb-10 mt-4 w-full">
|
||||
<span className="mb-1 block text-sm">Current workspace</span>
|
||||
|
||||
<Listbox value={"local"} onChange={changeProfileId}>
|
||||
{({ open }) => (
|
||||
<div className="relative w-full">
|
||||
<Listbox.Button className="border-vsc-input-border bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground relative m-0 flex w-full cursor-pointer items-center justify-between rounded-md border border-solid px-3 py-2 text-left">
|
||||
<span className="lines lines-1">
|
||||
{selectedProfile?.title}
|
||||
</span>
|
||||
<div className="pointer-events-none flex items-center">
|
||||
<ChevronUpDownIcon className="h-5 w-5" aria-hidden="true" />
|
||||
</div>
|
||||
</Listbox.Button>
|
||||
|
||||
<Transition
|
||||
as={Fragment}
|
||||
show={open}
|
||||
enter="transition ease-out duration-100"
|
||||
enterFrom="transform opacity-0 scale-95"
|
||||
enterTo="transform opacity-100 scale-100"
|
||||
leave="transition ease-in duration-75"
|
||||
leaveFrom="transform opacity-100 scale-100"
|
||||
leaveTo="transform opacity-0 scale-95"
|
||||
>
|
||||
<Listbox.Options className="bg-vsc-background max-h-80vh absolute mt-0.5 w-full overflow-y-scroll rounded-sm p-0">
|
||||
{profiles.map((option, idx) => (
|
||||
<StyledListboxOption
|
||||
key={idx}
|
||||
selected={selectedProfile?.id === option.id}
|
||||
value={option.id}
|
||||
className="w-full"
|
||||
>
|
||||
<span className="lines lines-1 relative flex h-5 items-center justify-between gap-3 pr-2 text-xs">
|
||||
{option.title}
|
||||
</span>
|
||||
</StyledListboxOption>
|
||||
))}
|
||||
{profiles.length === 0 && (
|
||||
<div className="px-4 py-2">
|
||||
<i>No workspaces found</i>
|
||||
</div>
|
||||
)}
|
||||
</Listbox.Options>
|
||||
</Transition>
|
||||
</div>
|
||||
)}
|
||||
</Listbox>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex w-full justify-end gap-2">
|
||||
<SecondaryButton className="w-auto" onClick={logout}>
|
||||
Sign out
|
||||
</SecondaryButton>
|
||||
<Button
|
||||
className="w-auto"
|
||||
onClick={() => {
|
||||
dispatch(setDialogMessage(undefined));
|
||||
dispatch(setShowDialog(false));
|
||||
}}
|
||||
>
|
||||
Done
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -13,13 +13,12 @@ import {
|
|||
setMode,
|
||||
updateApplyState,
|
||||
} from "../redux/slices/sessionSlice";
|
||||
import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice";
|
||||
import { setShowDialog } from "../redux/slices/uiSlice";
|
||||
import { exitEditMode } from "../redux/thunks";
|
||||
import { loadLastSession, saveCurrentSession } from "../redux/thunks/session";
|
||||
import { getFontSize, isMetaEquivalentKeyPressed } from "../util";
|
||||
import { incrementFreeTrialCount } from "../util/freeTrial";
|
||||
import { ROUTES } from "../util/navigation";
|
||||
import AccountDialog from "./AccountDialog";
|
||||
import TextDialog from "./dialogs";
|
||||
import Footer from "./Footer";
|
||||
import { isNewUserOnboarding, useOnboardingCard } from "./OnboardingCard";
|
||||
|
|
@ -97,17 +96,6 @@ const Layout = () => {
|
|||
location.pathname === ROUTES.HOME,
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"openDialogMessage",
|
||||
async (message) => {
|
||||
if (message === "account") {
|
||||
dispatch(setShowDialog(true));
|
||||
dispatch(setDialogMessage(<AccountDialog />));
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"addModel",
|
||||
async () => {
|
||||
|
|
|
|||
|
|
@ -5,18 +5,21 @@ import { lightGray } from "../..";
|
|||
import { useAuth } from "../../../context/Auth";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { useAppDispatch } from "../../../redux/hooks";
|
||||
import { setProfileId } from "../../../redux/thunks/setProfileId";
|
||||
import { setProfileId } from "../../../redux/thunks/profileAndOrg";
|
||||
import { getFontSize, getMetaKeyLabel, isLocalProfile } from "../../../util";
|
||||
import { ROUTES } from "../../../util/navigation";
|
||||
import AssistantIcon from "./AssistantIcon";
|
||||
import { Divider, Option, OptionDiv } from "./shared";
|
||||
import { getProfileDisplayText } from "./utils";
|
||||
import { ProfileDescription } from "core/config/ConfigHandler";
|
||||
|
||||
interface AssistantSelectOptionsProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function AssistantSelectOptions(props: AssistantSelectOptionsProps) {
|
||||
export function AssistantSelectOptions({
|
||||
onClose,
|
||||
}: AssistantSelectOptionsProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { profiles, selectedProfile, selectedOrganization } = useAuth();
|
||||
const dispatch = useAppDispatch();
|
||||
|
|
@ -27,60 +30,56 @@ export function AssistantSelectOptions(props: AssistantSelectOptionsProps) {
|
|||
path: "new",
|
||||
orgSlug: selectedOrganization?.slug,
|
||||
});
|
||||
onClose();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
ideMessenger.post("config/openProfile", { profileId: option.id });
|
||||
function handleConfigure(profile: ProfileDescription) {
|
||||
ideMessenger.post("config/openProfile", { profileId: profile.id });
|
||||
onClose();
|
||||
}
|
||||
|
||||
function handleClickError(profileId: string) {
|
||||
ideMessenger.post("config/openProfile", { profileId });
|
||||
onClose();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="border-lightgray flex min-w-0 flex-col overflow-x-hidden pt-0">
|
||||
<div className={`max-h-[300px]`}>
|
||||
{profiles.map((profile, idx) => (
|
||||
<Option
|
||||
key={idx}
|
||||
idx={idx}
|
||||
disabled={!!profile.errors?.length}
|
||||
showConfigure={profile.id === "local"}
|
||||
selected={profile.id === selectedProfile?.id}
|
||||
onLink={
|
||||
!isLocalProfile(profile)
|
||||
? (e) => handleOptionLink(e, profile.id)
|
||||
: undefined
|
||||
}
|
||||
onConfigure={(e) => handleConfigure(e, profile)}
|
||||
errors={profile.errors}
|
||||
onClickError={() => handleClickError(profile.id)}
|
||||
onClick={() => dispatch(setProfileId(profile.id))}
|
||||
>
|
||||
<div className="flex min-w-0 items-center">
|
||||
<div className="mr-2 h-4 w-4 flex-shrink-0">
|
||||
<AssistantIcon assistant={profile} />
|
||||
{profiles.map((profile, idx) => {
|
||||
return (
|
||||
<Option
|
||||
key={idx}
|
||||
idx={idx}
|
||||
disabled={!!profile.errors?.length}
|
||||
showConfigure={profile.id === "local"}
|
||||
selected={profile.id === selectedProfile?.id}
|
||||
onOpenConfig={() => {
|
||||
handleConfigure(profile);
|
||||
}}
|
||||
errors={profile.errors}
|
||||
onClickError={() => handleClickError(profile.id)}
|
||||
onClick={() => {
|
||||
dispatch(setProfileId(profile.id));
|
||||
onClose();
|
||||
}}
|
||||
>
|
||||
<div className="flex min-w-0 items-center">
|
||||
<div className="mr-2 h-4 w-4 flex-shrink-0">
|
||||
<AssistantIcon assistant={profile} />
|
||||
</div>
|
||||
<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>
|
||||
))}
|
||||
</Option>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="mt-auto w-full">
|
||||
|
|
|
|||
|
|
@ -54,8 +54,7 @@ interface ModelOptionProps {
|
|||
disabled: boolean;
|
||||
selected: boolean;
|
||||
showConfigure: boolean;
|
||||
onLink?: (e: any) => void;
|
||||
onConfigure: (e: any) => void;
|
||||
onOpenConfig: () => void;
|
||||
onClick: () => void;
|
||||
errors?: ConfigValidationError[];
|
||||
onClickError?: (e: any) => void;
|
||||
|
|
@ -85,16 +84,15 @@ const StyledExclamationTriangleIcon = styled(IconBase).attrs({
|
|||
})``;
|
||||
|
||||
export function Option({
|
||||
onConfigure,
|
||||
children,
|
||||
idx,
|
||||
disabled,
|
||||
onClick,
|
||||
showConfigure,
|
||||
onLink,
|
||||
selected,
|
||||
errors,
|
||||
onClickError,
|
||||
onOpenConfig,
|
||||
}: ModelOptionProps) {
|
||||
const [hovered, setHovered] = useState(false);
|
||||
|
||||
|
|
@ -119,16 +117,27 @@ export function Option({
|
|||
<div className="flex w-full items-center justify-between">
|
||||
{children}
|
||||
<div className="ml-2 flex items-center">
|
||||
{!errors?.length && showConfigure && (
|
||||
<StyledCog6ToothIcon $hovered={hovered} onClick={onConfigure} />
|
||||
)}
|
||||
{!errors?.length && onLink && (
|
||||
<StyledArrowTopRightOnSquareIcon
|
||||
$hovered={hovered}
|
||||
onClick={onLink}
|
||||
/>
|
||||
)}
|
||||
{errors?.length ? (
|
||||
{!errors?.length ? (
|
||||
showConfigure ? (
|
||||
<StyledCog6ToothIcon
|
||||
$hovered={hovered}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
onOpenConfig();
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<StyledArrowTopRightOnSquareIcon
|
||||
$hovered={hovered}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
onOpenConfig();
|
||||
}}
|
||||
/>
|
||||
)
|
||||
) : (
|
||||
<>
|
||||
<StyledExclamationTriangleIcon
|
||||
data-tooltip-id={`${idx}-errors-tooltip`}
|
||||
|
|
@ -141,7 +150,7 @@ export function Option({
|
|||
{JSON.stringify(errors, null, 2)}
|
||||
</ToolTip>
|
||||
</>
|
||||
) : null}
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -10,28 +10,26 @@ import React, {
|
|||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import AccountDialog from "../components/AccountDialog";
|
||||
import ConfirmationDialog from "../components/dialogs/ConfirmationDialog";
|
||||
import { useWebviewListener } from "../hooks/useWebviewListener";
|
||||
import { useAppSelector } from "../redux/hooks";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice";
|
||||
import {
|
||||
selectAvailableProfiles,
|
||||
setAvailableProfiles,
|
||||
} from "../redux/slices/sessionSlice";
|
||||
import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice";
|
||||
import { IdeMessengerContext } from "./IdeMessenger";
|
||||
import {
|
||||
updateOrgsThunk,
|
||||
updateProfilesThunk,
|
||||
} from "../redux/thunks/profileAndOrg";
|
||||
|
||||
interface AuthContextType {
|
||||
session: ControlPlaneSessionInfo | undefined;
|
||||
logout: () => void;
|
||||
login: (useOnboarding: boolean) => Promise<boolean>;
|
||||
selectedProfile: ProfileDescription | undefined;
|
||||
selectedProfile: ProfileDescription | null;
|
||||
profiles: ProfileDescription[];
|
||||
controlServerBetaEnabled: boolean;
|
||||
organizations: OrganizationDescription[];
|
||||
selectedOrganization: OrganizationDescription | undefined;
|
||||
selectedOrganization: OrganizationDescription | null;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||
|
|
@ -39,35 +37,38 @@ const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
|||
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
children,
|
||||
}) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
// Session
|
||||
const [session, setSession] = useState<ControlPlaneSessionInfo | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
const [organizations, setOrganizations] = useState<OrganizationDescription[]>(
|
||||
[],
|
||||
);
|
||||
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const selectedOrganizationId = useAppSelector(
|
||||
// Orgs
|
||||
const orgs = useAppSelector((store) => store.session.organizations);
|
||||
const selectedOrgId = useAppSelector(
|
||||
(store) => store.session.selectedOrganizationId,
|
||||
);
|
||||
|
||||
const selectedOrganization = useMemo(() => {
|
||||
return organizations.find((p) => p.id === selectedOrganizationId);
|
||||
}, [organizations, selectedOrganizationId]);
|
||||
|
||||
const profiles = useAppSelector(selectAvailableProfiles);
|
||||
if (!selectedOrgId) {
|
||||
return null;
|
||||
}
|
||||
return orgs.find((p) => p.id === selectedOrgId) ?? null;
|
||||
}, [orgs, selectedOrgId]);
|
||||
|
||||
// Profiles
|
||||
const profiles = useAppSelector((store) => store.session.availableProfiles);
|
||||
const selectedProfileId = useAppSelector(
|
||||
(store) => store.session.selectedProfileId,
|
||||
);
|
||||
const selectedProfile = useMemo(() => {
|
||||
return profiles.find((p) => p.id === selectedProfileId);
|
||||
if (!selectedProfileId) {
|
||||
return null;
|
||||
}
|
||||
return profiles.find((p) => p.id === selectedProfileId) ?? null;
|
||||
}, [profiles, selectedProfileId]);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const login: AuthContextType["login"] = (useOnboarding: boolean) => {
|
||||
return new Promise((resolve) => {
|
||||
ideMessenger
|
||||
|
|
@ -100,8 +101,8 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
ideMessenger.post("logoutOfControlPlane", undefined);
|
||||
}}
|
||||
onCancel={() => {
|
||||
dispatch(setDialogMessage(<AccountDialog />));
|
||||
dispatch(setShowDialog(true));
|
||||
dispatch(setDialogMessage(undefined));
|
||||
dispatch(setShowDialog(false));
|
||||
}}
|
||||
/>,
|
||||
),
|
||||
|
|
@ -112,10 +113,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
setSession(data.sessionInfo);
|
||||
});
|
||||
|
||||
useWebviewListener("signInToControlPlane", async () => {
|
||||
login(false);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
ideMessenger
|
||||
.request("getControlPlaneSessionInfo", {
|
||||
|
|
@ -147,11 +144,13 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
.request("controlPlane/listOrganizations", undefined)
|
||||
.then((result) => {
|
||||
if (result.status === "success") {
|
||||
setOrganizations(result.content);
|
||||
updateOrgsThunk(result.content);
|
||||
} else {
|
||||
updateOrgsThunk([]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setOrganizations([]);
|
||||
updateOrgsThunk([]);
|
||||
}
|
||||
}, [session]);
|
||||
|
||||
|
|
@ -168,19 +167,17 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
);
|
||||
|
||||
useEffect(() => {
|
||||
ideMessenger
|
||||
.request("config/listProfiles", undefined)
|
||||
.then(
|
||||
(result) =>
|
||||
result.status === "success" &&
|
||||
dispatch(setAvailableProfiles(result.content)),
|
||||
);
|
||||
ideMessenger.request("config/listProfiles", undefined).then((result) => {
|
||||
if (result.status === "success") {
|
||||
dispatch(updateProfilesThunk(result.content));
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
useWebviewListener(
|
||||
"didChangeAvailableProfiles",
|
||||
async (data) => {
|
||||
dispatch(setAvailableProfiles(data.profiles));
|
||||
dispatch(updateProfilesThunk(data.profiles));
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
|
@ -194,7 +191,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
selectedProfile,
|
||||
profiles,
|
||||
selectedOrganization,
|
||||
organizations,
|
||||
organizations: orgs,
|
||||
controlServerBetaEnabled,
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import { updateDocsSuggestions } from "../redux/slices/miscSlice";
|
|||
import {
|
||||
addContextItemsAtIndex,
|
||||
setInactive,
|
||||
setSelectedProfileId,
|
||||
} from "../redux/slices/sessionSlice";
|
||||
import { setTTSActive } from "../redux/slices/uiSlice";
|
||||
import { refreshSessionMetadata } from "../redux/thunks/session";
|
||||
|
|
@ -20,6 +19,7 @@ import { updateFileSymbolsFromHistory } from "../redux/thunks/updateFileSymbols"
|
|||
import { isJetBrains } from "../util";
|
||||
import { setLocalStorage } from "../util/localStorage";
|
||||
import { useWebviewListener } from "./useWebviewListener";
|
||||
import { selectProfileThunk } from "../redux/thunks/profileAndOrg";
|
||||
|
||||
function useSetup() {
|
||||
const dispatch = useAppDispatch();
|
||||
|
|
@ -36,7 +36,7 @@ function useSetup() {
|
|||
initial: boolean,
|
||||
result: {
|
||||
result: ConfigResult<BrowserSerializedContinueConfig>;
|
||||
profileId: string;
|
||||
profileId: string | null;
|
||||
},
|
||||
) => {
|
||||
const { result: configResult, profileId } = result;
|
||||
|
|
@ -44,17 +44,8 @@ function useSetup() {
|
|||
return;
|
||||
}
|
||||
hasLoadedConfig.current = true;
|
||||
// window.postMessage(
|
||||
// {
|
||||
// messageType: "refreshSubmenuItems",
|
||||
// data: {
|
||||
// providers: "all",
|
||||
// },
|
||||
// },
|
||||
// "*",
|
||||
// );
|
||||
dispatch(setConfigResult(configResult));
|
||||
dispatch(setSelectedProfileId(profileId));
|
||||
dispatch(selectProfileThunk(profileId));
|
||||
|
||||
// Perform any actions needed with the config
|
||||
if (configResult.config?.ui?.fontSize) {
|
||||
|
|
|
|||
|
|
@ -4,37 +4,32 @@ import {
|
|||
ChevronDownIcon,
|
||||
UserCircleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useState } from "react";
|
||||
import { useAuth } from "../../context/Auth";
|
||||
import { useAppDispatch } from "../../redux/hooks";
|
||||
import { setOrgId } from "../../redux/thunks/setOrgId";
|
||||
|
||||
const USER_PROFILE_VAL = "personal";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectOrgThunk } from "../../redux/thunks/profileAndOrg";
|
||||
|
||||
export function ScopeSelect() {
|
||||
const { organizations, selectedOrganization } = useAuth();
|
||||
const [value, setValue] = useState<string>(
|
||||
selectedOrganization?.id || USER_PROFILE_VAL,
|
||||
const selectedOrgId = useAppSelector(
|
||||
(state) => state.session.selectedOrganizationId,
|
||||
);
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const handleChange = (newValue: string) => {
|
||||
setValue(newValue);
|
||||
|
||||
const orgId = newValue === USER_PROFILE_VAL ? null : newValue;
|
||||
dispatch(setOrgId(orgId));
|
||||
const handleChange = (newValue: string | null) => {
|
||||
dispatch(selectOrgThunk(newValue));
|
||||
};
|
||||
|
||||
const CurScopeEntityFallBackIcon =
|
||||
value === "personal" ? UserCircleIcon : BuildingOfficeIcon;
|
||||
const CurScopeEntityFallBackIcon = selectedOrgId
|
||||
? BuildingOfficeIcon
|
||||
: UserCircleIcon;
|
||||
|
||||
const selectedDisplay =
|
||||
value === USER_PROFILE_VAL
|
||||
? { name: "Personal", iconUrl: null }
|
||||
: organizations.find((org) => org.id === value);
|
||||
const selectedDisplay = selectedOrganization ?? {
|
||||
name: "Personal",
|
||||
iconUrl: null,
|
||||
};
|
||||
|
||||
return (
|
||||
<Listbox value={value} onChange={handleChange}>
|
||||
<Listbox value={selectedOrgId} onChange={handleChange}>
|
||||
<div className="relative">
|
||||
<Listbox.Button className="border-vsc-input-border text-vsc-foreground hover:bg-vsc-background bg-vsc-input-background flex w-full max-w-[400px] cursor-pointer items-center gap-0.5 rounded border border-solid p-2 hover:opacity-90">
|
||||
<div className="flex w-full items-center justify-between">
|
||||
|
|
@ -52,7 +47,7 @@ export function ScopeSelect() {
|
|||
</div>
|
||||
</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">
|
||||
<Listbox.Options className="bg-vsc-input-background absolute z-50 mt-1 w-full max-w-[400px] list-none overflow-auto rounded p-0 shadow-lg">
|
||||
{organizations.length > 0 && (
|
||||
<>
|
||||
<div className="text-vsc-foreground p-2 font-semibold">
|
||||
|
|
@ -80,7 +75,7 @@ export function ScopeSelect() {
|
|||
)}
|
||||
|
||||
<Listbox.Option
|
||||
value={USER_PROFILE_VAL}
|
||||
value={null}
|
||||
className="text-vsc-foreground hover:bg-lightgray/20 cursor-pointer rounded p-2 hover:opacity-90"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
|
|
|
|||
322
gui/src/pages/config/UserSettings.tsx
Normal file
322
gui/src/pages/config/UserSettings.tsx
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
import { useContext, useEffect, useState } from "react";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
|
||||
import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
|
||||
import {
|
||||
SharedConfigSchema,
|
||||
modifyContinueConfigWithSharedConfig,
|
||||
} from "core/config/sharedConfig";
|
||||
import { Input } from "../../components";
|
||||
import NumberInput from "../../components/gui/NumberInput";
|
||||
import { Select } from "../../components/gui/Select";
|
||||
import ToggleSwitch from "../../components/gui/Switch";
|
||||
import { updateConfig } from "../../redux/slices/configSlice";
|
||||
import { getFontSize } from "../../util";
|
||||
|
||||
function UserSettingsUI() {
|
||||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const config = useAppSelector((state) => state.config.config);
|
||||
|
||||
function handleUpdate(sharedConfig: Partial<SharedConfigSchema>) {
|
||||
dispatch(
|
||||
updateConfig(modifyContinueConfigWithSharedConfig(config, sharedConfig)),
|
||||
);
|
||||
ideMessenger.post("config/updateSharedConfig", sharedConfig);
|
||||
}
|
||||
|
||||
// TODO defaults are in multiple places, should be consolidated and probably not explicit here
|
||||
const codeWrap = config.ui?.codeWrap ?? false;
|
||||
const showChatScrollbar = config.ui?.showChatScrollbar ?? false;
|
||||
const displayRawMarkdown = config.ui?.displayRawMarkdown ?? false;
|
||||
const disableSessionTitles = config.disableSessionTitles ?? false;
|
||||
const readResponseTTS = config.experimental?.readResponseTTS ?? false;
|
||||
|
||||
const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true;
|
||||
const disableIndexing = config.disableIndexing ?? false;
|
||||
|
||||
const useAutocompleteCache = config.tabAutocompleteOptions?.useCache ?? false;
|
||||
const useChromiumForDocsCrawling =
|
||||
config.experimental?.useChromiumForDocsCrawling ?? false;
|
||||
const codeBlockToolbarPosition = config.ui?.codeBlockToolbarPosition ?? "top";
|
||||
const useAutocompleteMultilineCompletions =
|
||||
config.tabAutocompleteOptions?.multilineCompletions ?? "auto";
|
||||
const fontSize = getFontSize();
|
||||
|
||||
// Disable autocomplete
|
||||
const disableAutocompleteInFiles = (
|
||||
config.tabAutocompleteOptions?.disableInFiles ?? []
|
||||
).join(", ");
|
||||
const [formDisableAutocomplete, setFormDisableAutocomplete] = useState(
|
||||
disableAutocompleteInFiles,
|
||||
);
|
||||
const cancelChangeDisableAutocomplete = () => {
|
||||
setFormDisableAutocomplete(disableAutocompleteInFiles);
|
||||
};
|
||||
const handleDisableAutocompleteSubmit = () => {
|
||||
handleUpdate({
|
||||
disableAutocompleteInFiles: formDisableAutocomplete
|
||||
.split(",")
|
||||
.map((val) => val.trim())
|
||||
.filter((val) => !!val),
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Necessary so that reformatted/trimmed values don't cause dirty state
|
||||
setFormDisableAutocomplete(disableAutocompleteInFiles);
|
||||
}, [disableAutocompleteInFiles]);
|
||||
|
||||
// Workspace prompts
|
||||
const promptPath = config.experimental?.promptPath || "";
|
||||
const [formPromptPath, setFormPromptPath] = useState(promptPath);
|
||||
const cancelChangePromptPath = () => {
|
||||
setFormPromptPath(promptPath);
|
||||
};
|
||||
const handleSubmitPromptPath = () => {
|
||||
handleUpdate({
|
||||
promptPath: formPromptPath || "",
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Necessary so that reformatted/trimmed values don't cause dirty state
|
||||
setFormPromptPath(promptPath);
|
||||
}, [promptPath]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 py-6">
|
||||
<div>
|
||||
<h2 className="mb-2 mt-0">User settings</h2>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-4">
|
||||
<ToggleSwitch
|
||||
isToggled={codeWrap}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
codeWrap: !codeWrap,
|
||||
})
|
||||
}
|
||||
text="Wrap Codeblocks"
|
||||
/>
|
||||
<ToggleSwitch
|
||||
isToggled={displayRawMarkdown}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
displayRawMarkdown: !displayRawMarkdown,
|
||||
})
|
||||
}
|
||||
text="Display Raw Markdown"
|
||||
/>
|
||||
<ToggleSwitch
|
||||
isToggled={allowAnonymousTelemetry}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
allowAnonymousTelemetry: !allowAnonymousTelemetry,
|
||||
})
|
||||
}
|
||||
text="Allow Anonymous Telemetry"
|
||||
/>
|
||||
<ToggleSwitch
|
||||
isToggled={disableIndexing}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
disableIndexing: !disableIndexing,
|
||||
})
|
||||
}
|
||||
text="Disable Indexing"
|
||||
/>
|
||||
|
||||
<ToggleSwitch
|
||||
isToggled={disableSessionTitles}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
disableSessionTitles: !disableSessionTitles,
|
||||
})
|
||||
}
|
||||
text="Disable Session Titles"
|
||||
/>
|
||||
<ToggleSwitch
|
||||
isToggled={readResponseTTS}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
readResponseTTS: !readResponseTTS,
|
||||
})
|
||||
}
|
||||
text="Response Text to Speech"
|
||||
/>
|
||||
|
||||
<ToggleSwitch
|
||||
isToggled={showChatScrollbar}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
showChatScrollbar: !showChatScrollbar,
|
||||
})
|
||||
}
|
||||
text="Show Chat Scrollbar"
|
||||
/>
|
||||
|
||||
<ToggleSwitch
|
||||
isToggled={useAutocompleteCache}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
useAutocompleteCache: !useAutocompleteCache,
|
||||
})
|
||||
}
|
||||
text="Use Autocomplete Cache"
|
||||
/>
|
||||
|
||||
<ToggleSwitch
|
||||
isToggled={useChromiumForDocsCrawling}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
useChromiumForDocsCrawling: !useChromiumForDocsCrawling,
|
||||
})
|
||||
}
|
||||
text="Use Chromium for Docs Crawling"
|
||||
/>
|
||||
|
||||
<label className="flex items-center justify-between gap-3">
|
||||
<span className="text-right">Codeblock Actions Position</span>
|
||||
<Select
|
||||
value={codeBlockToolbarPosition}
|
||||
onChange={(e) =>
|
||||
handleUpdate({
|
||||
codeBlockToolbarPosition: e.target.value as "top" | "bottom",
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="top">Top</option>
|
||||
<option value="bottom">Bottom</option>
|
||||
</Select>
|
||||
</label>
|
||||
|
||||
<label className="flex items-center justify-between gap-3">
|
||||
<span className="text-right">Multiline Autocompletions</span>
|
||||
<Select
|
||||
value={useAutocompleteMultilineCompletions}
|
||||
onChange={(e) =>
|
||||
handleUpdate({
|
||||
useAutocompleteMultilineCompletions: e.target.value as
|
||||
| "auto"
|
||||
| "always"
|
||||
| "never",
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="auto">Auto</option>
|
||||
<option value="always">Always</option>
|
||||
<option value="never">Never</option>
|
||||
</Select>
|
||||
</label>
|
||||
|
||||
<label className="flex items-center justify-between gap-3">
|
||||
<span className="text-right">Font Size</span>
|
||||
<NumberInput
|
||||
value={fontSize}
|
||||
onChange={(val) =>
|
||||
handleUpdate({
|
||||
fontSize: val,
|
||||
})
|
||||
}
|
||||
min={7}
|
||||
max={50}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<form
|
||||
className="flex flex-col gap-1"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
handleSubmitPromptPath();
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span>Workspace prompts path</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
value={formPromptPath}
|
||||
className="max-w-[100px]"
|
||||
onChange={(e) => {
|
||||
setFormPromptPath(e.target.value);
|
||||
}}
|
||||
/>
|
||||
<div className="flex h-full flex-col">
|
||||
{formPromptPath !== promptPath ? (
|
||||
<>
|
||||
<div
|
||||
onClick={handleSubmitPromptPath}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" />
|
||||
</div>
|
||||
<div
|
||||
onClick={cancelChangePromptPath}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div>
|
||||
<CheckIcon className="text-vsc-foreground-muted h-4 w-4" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<form
|
||||
className="flex flex-col gap-1"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
handleDisableAutocompleteSubmit();
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span>Disable autocomplete in files</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
value={formDisableAutocomplete}
|
||||
className="max-w-[100px]"
|
||||
onChange={(e) => {
|
||||
setFormDisableAutocomplete(e.target.value);
|
||||
}}
|
||||
/>
|
||||
<div className="flex h-full flex-col">
|
||||
{formDisableAutocomplete !== disableAutocompleteInFiles ? (
|
||||
<>
|
||||
<div
|
||||
onClick={handleDisableAutocompleteSubmit}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" />
|
||||
</div>
|
||||
<div
|
||||
onClick={cancelChangeDisableAutocomplete}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div>
|
||||
<CheckIcon className="text-vsc-foreground-muted h-4 w-4" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span className="text-vsc-foreground-muted self-end text-xs">
|
||||
Comma-separated list of path matchers
|
||||
</span>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserSettingsUI;
|
||||
|
|
@ -1,23 +1,16 @@
|
|||
import { useContext, useEffect, useState } from "react";
|
||||
import { Fragment, useContext, useEffect, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import PageHeader from "../../components/PageHeader";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useNavigationListener } from "../../hooks/useNavigationListener";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
|
||||
import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
|
||||
import {
|
||||
SharedConfigSchema,
|
||||
modifyContinueConfigWithSharedConfig,
|
||||
} from "core/config/sharedConfig";
|
||||
import { Input, SecondaryButton } from "../../components";
|
||||
import NumberInput from "../../components/gui/NumberInput";
|
||||
import { Select } from "../../components/gui/Select";
|
||||
import ToggleSwitch from "../../components/gui/Switch";
|
||||
import { useAppDispatch } from "../../redux/hooks";
|
||||
import { SecondaryButton } from "../../components";
|
||||
import { useAuth } from "../../context/Auth";
|
||||
import { updateConfig } from "../../redux/slices/configSlice";
|
||||
import { getFontSize } from "../../util";
|
||||
import { ScopeSelect } from "./ScopeSelect";
|
||||
import UserSettingsUI from "./UserSettings";
|
||||
import { Listbox, Transition } from "@headlessui/react";
|
||||
import { ChevronUpDownIcon } from "@heroicons/react/24/outline";
|
||||
import { selectProfileThunk } from "../../redux/thunks/profileAndOrg";
|
||||
|
||||
function ConfigPage() {
|
||||
useNavigationListener();
|
||||
|
|
@ -25,82 +18,27 @@ function ConfigPage() {
|
|||
const navigate = useNavigate();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const { selectedProfile, selectedOrganization, session } = useAuth();
|
||||
const config = useAppSelector((state) => state.config.config);
|
||||
const {
|
||||
session,
|
||||
logout,
|
||||
login,
|
||||
profiles,
|
||||
selectedProfile,
|
||||
controlServerBetaEnabled,
|
||||
} = useAuth();
|
||||
// const profiles = [];
|
||||
|
||||
function handleUpdate(sharedConfig: Partial<SharedConfigSchema>) {
|
||||
dispatch(
|
||||
updateConfig(modifyContinueConfigWithSharedConfig(config, sharedConfig)),
|
||||
);
|
||||
ideMessenger.post("config/updateSharedConfig", sharedConfig);
|
||||
}
|
||||
|
||||
const codeWrap = config.ui?.codeWrap ?? false;
|
||||
const showChatScrollbar = config.ui?.showChatScrollbar ?? false;
|
||||
const displayRawMarkdown = config.ui?.displayRawMarkdown ?? false;
|
||||
const disableSessionTitles = config.disableSessionTitles ?? false;
|
||||
const readResponseTTS = config.experimental?.readResponseTTS ?? false;
|
||||
|
||||
const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true;
|
||||
const disableIndexing = config.disableIndexing ?? false;
|
||||
|
||||
const useAutocompleteCache = config.tabAutocompleteOptions?.useCache ?? false;
|
||||
const useChromiumForDocsCrawling =
|
||||
config.experimental?.useChromiumForDocsCrawling ?? false;
|
||||
const codeBlockToolbarPosition = config.ui?.codeBlockToolbarPosition ?? "top";
|
||||
const useAutocompleteMultilineCompletions =
|
||||
config.tabAutocompleteOptions?.multilineCompletions ?? "auto";
|
||||
const fontSize = getFontSize();
|
||||
const changeProfileId = (id: string) => {
|
||||
dispatch(selectProfileThunk(id));
|
||||
};
|
||||
|
||||
const [hubEnabled, setHubEnabled] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
ideMessenger.ide.getIdeSettings().then(({ continueTestEnvironment }) => {
|
||||
setHubEnabled(continueTestEnvironment === "production");
|
||||
});
|
||||
}, [ideMessenger]);
|
||||
|
||||
// Disable autocomplete
|
||||
const disableAutocompleteInFiles = (
|
||||
config.tabAutocompleteOptions?.disableInFiles ?? []
|
||||
).join(", ");
|
||||
const [formDisableAutocomplete, setFormDisableAutocomplete] = useState(
|
||||
disableAutocompleteInFiles,
|
||||
);
|
||||
const cancelChangeDisableAutocomplete = () => {
|
||||
setFormDisableAutocomplete(disableAutocompleteInFiles);
|
||||
};
|
||||
const handleDisableAutocompleteSubmit = () => {
|
||||
handleUpdate({
|
||||
disableAutocompleteInFiles: formDisableAutocomplete
|
||||
.split(",")
|
||||
.map((val) => val.trim())
|
||||
.filter((val) => !!val),
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Necessary so that reformatted/trimmed values don't cause dirty state
|
||||
setFormDisableAutocomplete(disableAutocompleteInFiles);
|
||||
}, [disableAutocompleteInFiles]);
|
||||
|
||||
// Workspace prompts
|
||||
const promptPath = config.experimental?.promptPath || "";
|
||||
const [formPromptPath, setFormPromptPath] = useState(promptPath);
|
||||
const cancelChangePromptPath = () => {
|
||||
setFormPromptPath(promptPath);
|
||||
};
|
||||
const handleSubmitPromptPath = () => {
|
||||
handleUpdate({
|
||||
promptPath: formPromptPath || "",
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Necessary so that reformatted/trimmed values don't cause dirty state
|
||||
setFormPromptPath(promptPath);
|
||||
}, [promptPath]);
|
||||
|
||||
function handleOpenConfig() {
|
||||
if (!selectedProfile) {
|
||||
return;
|
||||
|
|
@ -110,298 +48,126 @@ function ConfigPage() {
|
|||
});
|
||||
}
|
||||
|
||||
if (!selectedProfile) {
|
||||
return (
|
||||
<div className="overflow-y-scroll">
|
||||
<PageHeader onTitleClick={() => navigate("/")} title="Chat" />
|
||||
<div className="px-4">
|
||||
<div>
|
||||
<h2>Continue Config</h2>
|
||||
</div>
|
||||
<p className="italic">No config profile selected</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
// NOTE Hub takes priority over Continue for Teams
|
||||
// Since teams will be moving to hub, not vice versa
|
||||
|
||||
return (
|
||||
<div className="overflow-y-scroll">
|
||||
<PageHeader onTitleClick={() => navigate("/")} title="Chat" />
|
||||
|
||||
<div className="divide-x-0 divide-y-2 divide-solid divide-zinc-700 px-4">
|
||||
{hubEnabled && !!session && (
|
||||
<div className="flex flex-col gap-4 py-6">
|
||||
<div>
|
||||
<h2 className="mb-1 mt-0">Account</h2>
|
||||
{selectedOrganization?.name && (
|
||||
<span className="text-lightgray">
|
||||
You are currently signed in to{" "}
|
||||
<span className="font-semibold">
|
||||
{selectedOrganization?.name}
|
||||
<div className="flex flex-col">
|
||||
<div className="flex max-w-[400px] flex-col gap-4 py-4">
|
||||
<h2 className="mb-1 mt-0">Account</h2>
|
||||
{!session ? (
|
||||
<div className="flex flex-col gap-2">
|
||||
<span>You are not signed in.</span>
|
||||
<SecondaryButton onClick={() => login(false)}>
|
||||
Sign in
|
||||
</SecondaryButton>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-4">
|
||||
{hubEnabled ? (
|
||||
// Hub: show org selector
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<span className="text-lightgray">{`Organization`}</span>
|
||||
<ScopeSelect />
|
||||
</div>
|
||||
) : (
|
||||
// Continue for teams: show org text
|
||||
<div>You are using Continue for Teams</div>
|
||||
)}
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
<span className="text-lightgray">
|
||||
{session.account.label === ""
|
||||
? "Signed in"
|
||||
: `Signed in as ${session.account.label}`}
|
||||
</span>
|
||||
</span>
|
||||
<span
|
||||
onClick={logout}
|
||||
className="text-lightgray cursor-pointer underline"
|
||||
>{`Sign out`}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col">
|
||||
<div className="flex max-w-[400px] flex-col gap-4 py-6">
|
||||
<h2 className="mb-1 mt-0">Configuration</h2>
|
||||
<Listbox value={selectedProfile?.id} onChange={changeProfileId}>
|
||||
{({ open }) => (
|
||||
<div className="relative w-full">
|
||||
<Listbox.Button className="border-vsc-input-border bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground relative m-0 flex w-full cursor-pointer items-center justify-between rounded-md border border-solid px-3 py-2 text-left">
|
||||
<span className="lines lines-1">
|
||||
{selectedProfile?.title}
|
||||
</span>
|
||||
<div className="pointer-events-none flex items-center">
|
||||
<ChevronUpDownIcon
|
||||
className="h-5 w-5"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
</Listbox.Button>
|
||||
|
||||
<Transition
|
||||
as={Fragment}
|
||||
show={open}
|
||||
enter="transition ease-out duration-100"
|
||||
enterFrom="transform opacity-0 scale-95"
|
||||
enterTo="transform opacity-100 scale-100"
|
||||
leave="transition ease-in duration-75"
|
||||
leaveFrom="transform opacity-100 scale-100"
|
||||
leaveTo="transform opacity-0 scale-95"
|
||||
>
|
||||
<Listbox.Options className="bg-vsc-background max-h-80vh absolute mt-0.5 w-full overflow-y-scroll rounded-sm p-0">
|
||||
{profiles.map((option, idx) => (
|
||||
<Listbox.Option
|
||||
key={idx}
|
||||
value={option.id}
|
||||
className={`text-vsc-foreground hover:text-vsc-list-active-foreground flex cursor-pointer flex-row items-center gap-3 px-3 py-2 ${selectedProfile?.id === option.id ? "bg-vsc-list-active-background" : "bg-vsc-input-background"}`}
|
||||
>
|
||||
<span className="lines lines-1 relative flex h-5 items-center justify-between gap-3 pr-2 text-xs">
|
||||
{option.title}
|
||||
</span>
|
||||
</Listbox.Option>
|
||||
))}
|
||||
{profiles.length === 0 && (
|
||||
<Listbox.Option
|
||||
key={"no-profiles"}
|
||||
value={undefined}
|
||||
className={`text-vsc-foreground hover:text-vsc-list-active-foreground flex cursor-pointer flex-row items-center gap-3 px-3 py-2 ${selectedProfile?.id === undefined ? "bg-vsc-list-active-background" : "bg-vsc-input-background"}`}
|
||||
>
|
||||
<span className="lines lines-1 relative flex h-5 items-center justify-between gap-3 pr-2 text-xs italic">
|
||||
No profiles found
|
||||
</span>
|
||||
</Listbox.Option>
|
||||
)}
|
||||
</Listbox.Options>
|
||||
</Transition>
|
||||
</div>
|
||||
)}
|
||||
</Listbox>
|
||||
{selectedProfile && (
|
||||
<SecondaryButton onClick={handleOpenConfig}>
|
||||
{selectedProfile.id === "local"
|
||||
? "Open Config File"
|
||||
: hubEnabled
|
||||
? "Open Assistant"
|
||||
: "Open Workspace"}
|
||||
</SecondaryButton>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{!controlServerBetaEnabled || hubEnabled ? (
|
||||
<div className="flex flex-col">
|
||||
<div className="flex max-w-[400px] flex-col">
|
||||
<UserSettingsUI />
|
||||
</div>
|
||||
|
||||
<ScopeSelect />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col gap-4 py-6">
|
||||
<h2 className="mb-1 mt-0">Configuration</h2>
|
||||
|
||||
<SecondaryButton
|
||||
onClick={handleOpenConfig}
|
||||
className="!my-0 max-w-[400px]"
|
||||
>
|
||||
Open config file
|
||||
</SecondaryButton>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-4 py-6">
|
||||
<div>
|
||||
<h2 className="mb-2 mt-0">User settings</h2>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-4">
|
||||
<ToggleSwitch
|
||||
isToggled={codeWrap}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
codeWrap: !codeWrap,
|
||||
})
|
||||
}
|
||||
text="Wrap Codeblocks"
|
||||
/>
|
||||
<ToggleSwitch
|
||||
isToggled={displayRawMarkdown}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
displayRawMarkdown: !displayRawMarkdown,
|
||||
})
|
||||
}
|
||||
text="Display Raw Markdown"
|
||||
/>
|
||||
<ToggleSwitch
|
||||
isToggled={allowAnonymousTelemetry}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
allowAnonymousTelemetry: !allowAnonymousTelemetry,
|
||||
})
|
||||
}
|
||||
text="Allow Anonymous Telemetry"
|
||||
/>
|
||||
<ToggleSwitch
|
||||
isToggled={disableIndexing}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
disableIndexing: !disableIndexing,
|
||||
})
|
||||
}
|
||||
text="Disable Indexing"
|
||||
/>
|
||||
|
||||
<ToggleSwitch
|
||||
isToggled={disableSessionTitles}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
disableSessionTitles: !disableSessionTitles,
|
||||
})
|
||||
}
|
||||
text="Disable Session Titles"
|
||||
/>
|
||||
<ToggleSwitch
|
||||
isToggled={readResponseTTS}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
readResponseTTS: !readResponseTTS,
|
||||
})
|
||||
}
|
||||
text="Response Text to Speech"
|
||||
/>
|
||||
|
||||
<ToggleSwitch
|
||||
isToggled={showChatScrollbar}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
showChatScrollbar: !showChatScrollbar,
|
||||
})
|
||||
}
|
||||
text="Show Chat Scrollbar"
|
||||
/>
|
||||
|
||||
<ToggleSwitch
|
||||
isToggled={useAutocompleteCache}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
useAutocompleteCache: !useAutocompleteCache,
|
||||
})
|
||||
}
|
||||
text="Use Autocomplete Cache"
|
||||
/>
|
||||
|
||||
<ToggleSwitch
|
||||
isToggled={useChromiumForDocsCrawling}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
useChromiumForDocsCrawling: !useChromiumForDocsCrawling,
|
||||
})
|
||||
}
|
||||
text="Use Chromium for Docs Crawling"
|
||||
/>
|
||||
|
||||
<label className="flex items-center justify-between gap-3">
|
||||
<span className="text-right">Codeblock Actions Position</span>
|
||||
<Select
|
||||
value={codeBlockToolbarPosition}
|
||||
onChange={(e) =>
|
||||
handleUpdate({
|
||||
codeBlockToolbarPosition: e.target.value as
|
||||
| "top"
|
||||
| "bottom",
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="top">Top</option>
|
||||
<option value="bottom">Bottom</option>
|
||||
</Select>
|
||||
</label>
|
||||
|
||||
<label className="flex items-center justify-between gap-3">
|
||||
<span className="text-right">Multiline Autocompletions</span>
|
||||
<Select
|
||||
value={useAutocompleteMultilineCompletions}
|
||||
onChange={(e) =>
|
||||
handleUpdate({
|
||||
useAutocompleteMultilineCompletions: e.target.value as
|
||||
| "auto"
|
||||
| "always"
|
||||
| "never",
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="auto">Auto</option>
|
||||
<option value="always">Always</option>
|
||||
<option value="never">Never</option>
|
||||
</Select>
|
||||
</label>
|
||||
|
||||
<label className="flex items-center justify-between gap-3">
|
||||
<span className="text-right">Font Size</span>
|
||||
<NumberInput
|
||||
value={fontSize}
|
||||
onChange={(val) =>
|
||||
handleUpdate({
|
||||
fontSize: val,
|
||||
})
|
||||
}
|
||||
min={7}
|
||||
max={50}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="flex items-center justify-between gap-3">
|
||||
<span className="text-right">Font Size</span>
|
||||
<NumberInput
|
||||
value={fontSize}
|
||||
onChange={(val) =>
|
||||
handleUpdate({
|
||||
fontSize: val,
|
||||
})
|
||||
}
|
||||
min={7}
|
||||
max={50}
|
||||
/>
|
||||
</label>
|
||||
<form
|
||||
className="flex flex-col gap-1"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
handleSubmitPromptPath();
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span>Workspace prompts path</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
value={formPromptPath}
|
||||
className="max-w-[100px]"
|
||||
onChange={(e) => {
|
||||
setFormPromptPath(e.target.value);
|
||||
}}
|
||||
/>
|
||||
<div className="flex h-full flex-col">
|
||||
{formPromptPath !== promptPath ? (
|
||||
<>
|
||||
<div
|
||||
onClick={handleSubmitPromptPath}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" />
|
||||
</div>
|
||||
<div
|
||||
onClick={cancelChangePromptPath}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div>
|
||||
<CheckIcon className="text-lightgray h-4 w-4" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<form
|
||||
className="flex flex-col gap-1"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
handleDisableAutocompleteSubmit();
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span>Disable autocomplete in files</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
value={formDisableAutocomplete}
|
||||
className="max-w-[100px]"
|
||||
onChange={(e) => {
|
||||
setFormDisableAutocomplete(e.target.value);
|
||||
}}
|
||||
/>
|
||||
<div className="flex h-full flex-col">
|
||||
{formDisableAutocomplete !== disableAutocompleteInFiles ? (
|
||||
<>
|
||||
<div
|
||||
onClick={handleDisableAutocompleteSubmit}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" />
|
||||
</div>
|
||||
<div
|
||||
onClick={cancelChangeDisableAutocomplete}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div>
|
||||
<CheckIcon className="text-lightgray h-4 w-4" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span className="text-lightgray self-end text-xs">
|
||||
Comma-separated list of path matchers
|
||||
</span>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ type SessionState = {
|
|||
isStreaming: boolean;
|
||||
title: string;
|
||||
id: string;
|
||||
selectedProfileId: string;
|
||||
availableProfiles: ProfileDescription[];
|
||||
selectedProfileId: string | null;
|
||||
organizations: OrganizationDescription[];
|
||||
selectedOrganizationId: string | null;
|
||||
availableOrganizations: OrganizationDescription[];
|
||||
streamAborter: AbortController;
|
||||
codeToEdit: CodeToEdit[];
|
||||
curCheckpointIndex: number;
|
||||
|
|
@ -103,8 +103,8 @@ const initialState: SessionState = {
|
|||
iconUrl: "",
|
||||
},
|
||||
],
|
||||
organizations: [],
|
||||
selectedOrganizationId: "",
|
||||
availableOrganizations: [],
|
||||
curCheckpointIndex: 0,
|
||||
streamAborter: new AbortController(),
|
||||
codeToEdit: [],
|
||||
|
|
@ -545,49 +545,34 @@ export const sessionSlice = createSlice({
|
|||
|
||||
state.history[state.history.length - 1].contextItems = contextItems;
|
||||
},
|
||||
setSelectedProfileId: (state, { payload }: PayloadAction<string>) => {
|
||||
return {
|
||||
...state,
|
||||
selectedProfileId: payload,
|
||||
};
|
||||
// Important: these reducers don't handle selected profile/organization fallback logic
|
||||
// That is done in thunks
|
||||
setSelectedProfileId: (
|
||||
state,
|
||||
{ payload }: PayloadAction<string | null>,
|
||||
) => {
|
||||
state.selectedProfileId = payload;
|
||||
},
|
||||
setAvailableProfiles: (
|
||||
state,
|
||||
{ payload }: PayloadAction<ProfileDescription[]>,
|
||||
) => {
|
||||
return {
|
||||
...state,
|
||||
availableProfiles: payload,
|
||||
selectedProfileId: payload.find(
|
||||
(profile) => profile.id === state.selectedProfileId,
|
||||
)
|
||||
? state.selectedProfileId
|
||||
: payload[0]?.id,
|
||||
};
|
||||
state.availableProfiles = payload;
|
||||
},
|
||||
setOrganizations: (
|
||||
state,
|
||||
{ payload }: PayloadAction<OrganizationDescription[]>,
|
||||
) => {
|
||||
state.organizations = payload;
|
||||
},
|
||||
setSelectedOrganizationId: (
|
||||
state,
|
||||
{ payload }: PayloadAction<string | null>,
|
||||
) => {
|
||||
return {
|
||||
...state,
|
||||
selectedOrganizationId: payload,
|
||||
};
|
||||
},
|
||||
setAvailableOrganizations: (
|
||||
state,
|
||||
{ payload }: PayloadAction<OrganizationDescription[]>,
|
||||
) => {
|
||||
return {
|
||||
...state,
|
||||
availableOrganizations: payload,
|
||||
selectedOrganizationId: payload.find(
|
||||
(org) => org.id === state.selectedOrganizationId,
|
||||
)
|
||||
? state.selectedOrganizationId
|
||||
: payload[0]?.id,
|
||||
};
|
||||
state.selectedOrganizationId = payload;
|
||||
},
|
||||
///////////////
|
||||
|
||||
updateCurCheckpoint: (
|
||||
state,
|
||||
{ payload }: PayloadAction<{ filepath: string; content: string }>,
|
||||
|
|
@ -713,12 +698,6 @@ export const sessionSlice = createSlice({
|
|||
selectHasCodeToEdit: (state) => {
|
||||
return state.codeToEdit.length > 0;
|
||||
},
|
||||
selectAvailableProfiles: (state) => {
|
||||
return state.availableProfiles;
|
||||
},
|
||||
selectAvailableOrganizations: (state) => {
|
||||
return state.availableOrganizations;
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
addPassthroughCases(builder, [streamResponseThunk]);
|
||||
|
|
@ -769,8 +748,6 @@ export const {
|
|||
updateHistoryItemAtIndex,
|
||||
clearLastEmptyResponse,
|
||||
setMainEditorContentTrigger,
|
||||
setSelectedProfileId,
|
||||
setSelectedOrganizationId,
|
||||
deleteMessage,
|
||||
setIsGatheringContext,
|
||||
updateCurCheckpoint,
|
||||
|
|
@ -783,8 +760,6 @@ export const {
|
|||
removeCodeToEdit,
|
||||
setCalling,
|
||||
cancelToolCall,
|
||||
setAvailableProfiles,
|
||||
setAvailableOrganizations,
|
||||
acceptToolCall,
|
||||
setToolGenerated,
|
||||
setToolCallOutput,
|
||||
|
|
@ -794,6 +769,11 @@ export const {
|
|||
updateSessionMetadata,
|
||||
deleteSessionMetadata,
|
||||
setNewestCodeblocksForInput,
|
||||
|
||||
setAvailableProfiles,
|
||||
setSelectedProfileId,
|
||||
setOrganizations,
|
||||
setSelectedOrganizationId,
|
||||
} = sessionSlice.actions;
|
||||
|
||||
export const {
|
||||
|
|
@ -801,8 +781,6 @@ export const {
|
|||
selectIsInEditMode,
|
||||
selectIsSingleRangeEditOrInsertion,
|
||||
selectHasCodeToEdit,
|
||||
selectAvailableProfiles,
|
||||
selectAvailableOrganizations,
|
||||
} = sessionSlice.selectors;
|
||||
|
||||
export default sessionSlice.reducer;
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { ThunkApiType } from "../store";
|
||||
import { setProfileId } from "./setProfileId";
|
||||
|
||||
export const cycleProfile = createAsyncThunk<void, undefined, ThunkApiType>(
|
||||
"profile/cycle",
|
||||
async (_, { dispatch, getState, extra }) => {
|
||||
const state = getState();
|
||||
const profileIds = state.session.availableProfiles.map(
|
||||
(profile) => profile.id,
|
||||
);
|
||||
const curIndex = profileIds.indexOf(state.session.selectedProfileId);
|
||||
const nextIndex = (curIndex + 1) % profileIds.length;
|
||||
const nextId = profileIds[nextIndex];
|
||||
dispatch(setProfileId(nextId));
|
||||
|
||||
extra.ideMessenger.post("didChangeSelectedProfile", {
|
||||
id: nextId,
|
||||
});
|
||||
},
|
||||
);
|
||||
74
gui/src/redux/thunks/profileAndOrg.ts
Normal file
74
gui/src/redux/thunks/profileAndOrg.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import {
|
||||
setSelectedOrganizationId,
|
||||
setSelectedProfileId,
|
||||
} from "../slices/sessionSlice";
|
||||
import { ThunkApiType } from "../store";
|
||||
import { ControlPlaneSessionInfo } from "core/control-plane/client";
|
||||
import { ProfileDescription } from "core/config/ConfigHandler";
|
||||
import { OrganizationDescription } from "core/config/ProfileLifecycleManager";
|
||||
|
||||
export const cycleProfile = createAsyncThunk<void, undefined, ThunkApiType>(
|
||||
"profiles/cycle",
|
||||
async (_, { dispatch, getState, extra }) => {
|
||||
const state = getState();
|
||||
const profileIds = state.session.availableProfiles.map(
|
||||
(profile) => profile.id,
|
||||
);
|
||||
// In case of no profiles just does nothing
|
||||
if (profileIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
let nextId = profileIds[0];
|
||||
if (state.session.selectedProfileId) {
|
||||
const curIndex = profileIds.indexOf(state.session.selectedProfileId);
|
||||
const nextIndex = (curIndex + 1) % profileIds.length;
|
||||
nextId = profileIds[nextIndex];
|
||||
}
|
||||
await dispatch(selectProfileThunk(nextId));
|
||||
},
|
||||
);
|
||||
|
||||
export const selectProfileThunk = createAsyncThunk<
|
||||
void,
|
||||
string | null,
|
||||
ThunkApiType
|
||||
>("profiles/select", async (id, { dispatch, extra }) => {
|
||||
dispatch(setSelectedProfileId(id));
|
||||
extra.ideMessenger.post("didChangeSelectedProfile", {
|
||||
id,
|
||||
});
|
||||
});
|
||||
|
||||
export const updateProfilesThunk = createAsyncThunk<
|
||||
void,
|
||||
ProfileDescription[],
|
||||
ThunkApiType
|
||||
>("profiles/update", async (profiles, { dispatch, extra }) => {
|
||||
// dispatch(setSelectedOrganizationId(id));
|
||||
// extra.ideMessenger.post("didChangeSelectedOrg", {
|
||||
// id,
|
||||
// });
|
||||
});
|
||||
|
||||
export const selectOrgThunk = createAsyncThunk<
|
||||
void,
|
||||
string | null,
|
||||
ThunkApiType
|
||||
>("session/selectOrg", async (id, { dispatch, extra }) => {
|
||||
dispatch(setSelectedOrganizationId(id));
|
||||
extra.ideMessenger.post("didChangeSelectedOrg", {
|
||||
id,
|
||||
});
|
||||
});
|
||||
|
||||
export const updateOrgsThunk = createAsyncThunk<
|
||||
void,
|
||||
OrganizationDescription[],
|
||||
ThunkApiType
|
||||
>("session/updateOrgs", async (session, { dispatch, extra }) => {
|
||||
// dispatch(setSelectedOrganizationId(id));
|
||||
// extra.ideMessenger.post("didChangeSelectedOrg", {
|
||||
// id,
|
||||
// });
|
||||
});
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
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,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { setSelectedProfileId } from "../slices/sessionSlice";
|
||||
import { ThunkApiType } from "../store";
|
||||
|
||||
export const setProfileId = createAsyncThunk<void, string, ThunkApiType>(
|
||||
"profile/setId",
|
||||
async (id, { dispatch, extra }) => {
|
||||
dispatch(setSelectedProfileId(id));
|
||||
extra.ideMessenger.post("didChangeSelectedProfile", {
|
||||
id,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
|
@ -30,6 +30,7 @@ const AdvancedPage = () => {
|
|||
<p className="text-xl">
|
||||
Counter: <span className="font-bold">{counter}</span>
|
||||
</p>
|
||||
|
||||
<button
|
||||
className="mt-2 rounded bg-green-500 px-4 py-2 text-white"
|
||||
onClick={() => setCounter(counter + 1)}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue