feat: add scope selector

This commit is contained in:
Patrick Erichsen 2025-01-31 13:19:59 -08:00
parent 8580a4cd64
commit b78fdc4147
15 changed files with 294 additions and 126 deletions

View file

@ -23,6 +23,12 @@ export interface ProfileDescription {
errors: ConfigValidationError[] | undefined;
}
export interface OrganizationDescription {
id: string;
iconUrl: string;
name: string;
}
export class ProfileLifecycleManager {
private savedConfigResult: ConfigResult<ContinueConfig> | undefined;
private savedBrowserConfigResult?: ConfigResult<BrowserSerializedContinueConfig>;

View file

@ -1,4 +1,5 @@
import { ConfigJson } from "@continuedev/config-types";
import { ConfigResult } from "@continuedev/config-yaml";
import { ControlPlaneClient } from "../../control-plane/client.js";
import {
@ -7,9 +8,8 @@ import {
IdeSettings,
SerializedContinueConfig,
} from "../../index.js";
import { ConfigResult } from "@continuedev/config-yaml";
import { ProfileDescription } from "../ProfileLifecycleManager.js";
import doLoadConfig from "./doLoadConfig.js";
import { IProfileLoader } from "./IProfileLoader.js";
@ -32,6 +32,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader {
this.description = {
id: workspaceId,
profileType: "control-plane",
iconUrl: "",
fullSlug: {
ownerSlug: "",
packageSlug: "",

View file

@ -1,8 +1,9 @@
import { ConfigResult } from "@continuedev/config-yaml";
import { ControlPlaneClient } from "../../control-plane/client.js";
import { ContinueConfig, IDE, IdeSettings } from "../../index.js";
import { ProfileDescription } from "../ProfileLifecycleManager.js";
import doLoadConfig from "./doLoadConfig.js";
import { IProfileLoader } from "./IProfileLoader.js";
@ -16,6 +17,7 @@ export default class LocalProfileLoader implements IProfileLoader {
packageSlug: "",
versionSlug: "",
},
iconUrl: "",
title: "Local Config",
errors: undefined,
};

View file

@ -1,8 +1,4 @@
import { ConfigJson } from "@continuedev/config-types";
import fetch, { RequestInit, Response } from "node-fetch";
import { IdeSettings, ModelDescription } from "../index.js";
import {
AssistantUnrolled,
ConfigResult,
@ -10,6 +6,11 @@ import {
FullSlug,
SecretResult,
} from "@continuedev/config-yaml";
import fetch, { RequestInit, Response } from "node-fetch";
import { OrganizationDescription } from "../config/ProfileLifecycleManager.js";
import { IdeSettings, ModelDescription } from "../index.js";
import { getControlPlaneEnv } from "./env.js";
export interface ControlPlaneSessionInfo {
@ -32,10 +33,6 @@ export const TRIAL_PROXY_URL =
"https://proxy-server-blue-l6vsfbzhba-uw.a.run.app";
export class ControlPlaneClient {
private static ACCESS_TOKEN_VALID_FOR_MS = 1000 * 60 * 5; // 5 minutes
private lastAccessTokenRefresh = 0;
constructor(
private readonly sessionInfoPromise: Promise<
ControlPlaneSessionInfo | undefined
@ -107,7 +104,7 @@ export class ControlPlaneClient {
}
}
public async listAssistants(): Promise<
public async listAssistants(organizationId?: string): Promise<
{
configResult: ConfigResult<AssistantUnrolled>;
ownerSlug: string;
@ -121,7 +118,11 @@ export class ControlPlaneClient {
}
try {
const resp = await this.request("ide/list-assistants", {
const url = organizationId
? `ide/list-assistants?organizationId=${organizationId}`
: "ide/list-assistants";
const resp = await this.request(url, {
method: "GET",
});
return (await resp.json()) as any;
@ -130,6 +131,31 @@ export class ControlPlaneClient {
}
}
public async listOrganizations(): Promise<Array<OrganizationDescription>> {
return [
{
id: "1",
iconUrl:
"https://cdn.prod.website-files.com/663e06c56841363663ffbbcf/663e1b9fb023f0b622ad3608_log-text.svg",
name: "Continue",
},
];
// const userId = await this.userId;
// if (!userId) {
// return [];
// }
// try {
// const resp = await this.request("ide/list-organizations", {
// method: "GET",
// });
// const { organizations } = (await resp.json()) as any;
// return organizations;
// } catch (e) {
// return [];
// }
}
public async listAssistantFullSlugs(): Promise<FullSlug[] | null> {
const userId = await this.userId;
if (!userId) {

View file

@ -307,6 +307,10 @@ export class Core {
await this.messenger.request("openUrl", `${env.APP_URL}${msg.data.path}`);
});
on("controlPlane/listOrganizations", async (msg) => {
return await this.controlPlaneClient.listOrganizations();
});
// Context providers
on("context/addDocs", async (msg) => {
void this.docsService.indexAndAdd(msg.data);

View file

@ -1,4 +1,10 @@
import { ConfigResult } 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 type {
BrowserSerializedContinueConfig,
ChatMessage,
@ -21,9 +27,6 @@ import type {
SiteIndexingConfig,
ToolCall,
} from "../";
import { AutocompleteInput } from "../autocomplete/util/types";
import { ProfileDescription } from "../config/ConfigHandler";
import { SharedConfigSchema } from "../config/sharedConfig";
export type OnboardingModes =
| "Local"
@ -195,4 +198,5 @@ export type ToCoreFromIdeOrWebviewProtocol = {
];
"clipboardCache/add": [{ content: string }, void];
"controlPlane/openUrl": [{ path: string }, void];
"controlPlane/listOrganizations": [undefined, OrganizationDescription[]];
};

View file

@ -61,6 +61,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
"didChangeSelectedProfile",
"tools/call",
"controlPlane/openUrl",
"controlPlane/listOrganizations",
];
// Message types to pass through from core to webview

View file

@ -117,7 +117,9 @@ class MessageTypes {
"profiles/switch",
"didChangeSelectedProfile",
"tools/call",
"controlPlane/openUrl"
"controlPlane/openUrl",
"controlPlane/listOrganizations"
)
}
}

View file

@ -1,12 +1,12 @@
{
"name": "continue",
"version": "0.9.256",
"version": "0.9.258",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "continue",
"version": "0.9.256",
"version": "0.9.258",
"license": "Apache-2.0",
"dependencies": {
"@continuedev/fetch": "^1.0.3",

View file

@ -1,10 +1,6 @@
import { Popover } from "@headlessui/react";
import {
ChevronDownIcon,
ComputerDesktopIcon,
SparklesIcon,
} from "@heroicons/react/24/outline";
import { cloneElement, useEffect, useRef } from "react";
import { ChevronDownIcon } from "@heroicons/react/24/outline";
import { useEffect, useRef } from "react";
import { useAuth } from "../../../context/Auth";
import { useAppDispatch } from "../../../redux/hooks";
import { cycleProfile } from "../../../redux/thunks/cycleProfile";

View file

@ -1,4 +1,7 @@
import { ProfileDescription } from "core/config/ProfileLifecycleManager";
import {
OrganizationDescription,
ProfileDescription,
} from "core/config/ProfileLifecycleManager";
import { ControlPlaneSessionInfo } from "core/control-plane/client";
import React, {
createContext,
@ -28,6 +31,8 @@ interface AuthContextType {
selectedProfile: ProfileDescription | undefined;
profiles: ProfileDescription[];
controlServerBetaEnabled: boolean;
organizations: OrganizationDescription[];
selectedOrganization: OrganizationDescription | undefined;
}
const AuthContext = createContext<AuthContextType | undefined>(undefined);
@ -39,6 +44,18 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
undefined,
);
const [organizations, setOrganizations] = useState<OrganizationDescription[]>(
[],
);
const selectedOrganizationId = useAppSelector(
(store) => store.session.selectedOrganizationId,
);
const selectedOrganization = useMemo(() => {
return organizations.find((p) => p.id === selectedOrganizationId);
}, [organizations, selectedOrganizationId]);
const profiles = useAppSelector(selectAvailableProfiles);
const selectedProfileId = useAppSelector(
@ -51,10 +68,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
const ideMessenger = useContext(IdeMessengerContext);
const dispatch = useDispatch();
const lastControlServerBetaEnabledStatus = useAppSelector(
(state) => state.misc.lastControlServerBetaEnabledStatus,
);
const login: AuthContextType["login"] = (useOnboarding: boolean) => {
return new Promise((resolve) => {
ideMessenger
@ -142,11 +155,23 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
enableControlServerBeta || continueTestEnvironment !== "none";
setControlServerBetaEnabled(enabled);
dispatch(setLastControlServerBetaEnabledStatus(enabled));
const shouldShowPopup = !lastControlServerBetaEnabledStatus && enabled;
});
}, []);
useEffect(() => {
if (session) {
ideMessenger
.request("controlPlane/listOrganizations", undefined)
.then((result) => {
if (result.status === "success") {
setOrganizations(result.content);
}
});
} else {
setOrganizations([]);
}
}, [session]);
useWebviewListener(
"didChangeIdeSettings",
async (msg) => {
@ -185,6 +210,8 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
login,
selectedProfile,
profiles,
selectedOrganization,
organizations,
controlServerBetaEnabled,
}}
>

View file

@ -1,3 +1,5 @@
// gui/src/pages/config/ScopeSelect.tsx
import { Listbox } from "@headlessui/react";
import {
ChevronDownIcon,
@ -5,46 +7,73 @@ import {
CubeIcon,
} from "@heroicons/react/24/outline";
import { useState } from "react";
import { useAuth } from "../../context/Auth";
import { useDispatch } from "react-redux";
import { setSelectedOrganizationId } from "../../redux/slices/sessionSlice";
export function ScopeSelect() {
const [value, setValue] = useState("");
const [showAbove, setShowAbove] = useState(false);
const { organizations, selectedOrganization } = useAuth();
const [value, setValue] = useState<string>(
selectedOrganization?.id || "personal",
);
const dispatch = useDispatch();
const handleChange = (newValue: string) => {
setValue(newValue);
dispatch(
setSelectedOrganizationId(newValue === "personal" ? null : newValue),
);
};
const selectedDisplay =
value === "personal"
? { name: "Personal", iconUrl: null }
: organizations.find((org) => org.id === value);
return (
<Listbox value={value} onChange={setValue}>
<Listbox value={value} onChange={handleChange}>
<div className="relative">
<Listbox.Button className="border-vsc-foreground text-vsc-foreground hover:bg-vsc-background flex w-full cursor-pointer items-center gap-0.5 rounded border bg-transparent p-2 hover:opacity-90">
<div className="flex w-full items-center justify-between">
<div className="flex items-center gap-2">
<CubeIcon className="h-5 w-5" />
<span className="truncate">Continue</span>
{selectedDisplay?.iconUrl ? (
<img src={selectedDisplay.iconUrl} alt="" className="h-5 w-5" />
) : (
<UserCircleIcon className="h-5 w-5" />
)}
<span className="truncate">
{selectedDisplay?.name || "Select Organization"}
</span>
</div>
<ChevronDownIcon className="h-4 w-4" aria-hidden="true" />
</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-1 shadow-lg ${showAbove ? "bottom-full mb-1" : ""}`}
>
<div className="text-vsc-foreground p-2 text-[13px] font-medium">
<Listbox.Options className="bg-vsc-input-background absolute z-50 mt-1 w-full min-w-[200px] list-none overflow-auto rounded p-0 shadow-lg">
<div className="text-vsc-foreground p-2 font-semibold">
Organizations
</div>
<Listbox.Option
value="continue"
className="text-vsc-foreground hover:bg-lightgray/20 cursor-pointer rounded p-1.5 hover:opacity-90"
>
<div className="flex items-center gap-2">
<CubeIcon className="h-5 w-5" />
<span>Continue</span>
</div>
</Listbox.Option>
{organizations.map((org) => (
<Listbox.Option
key={org.id}
value={org.id}
className="text-vsc-foreground hover:bg-lightgray/20 cursor-pointer rounded p-2 hover:opacity-90"
>
<div className="flex items-center gap-2">
{org.iconUrl ? (
<img src={org.iconUrl} alt="" className="h-5 w-5" />
) : (
<CubeIcon className="h-5 w-5" />
)}
<span>{org.name}</span>
</div>
</Listbox.Option>
))}
<div className="bg-lightgray mx-1 my-1 h-px" />
<Listbox.Option
value="personal"
className="text-vsc-foreground hover:bg-lightgray/20 cursor-pointer rounded p-1.5 hover:opacity-90"
className="text-vsc-foreground hover:bg-lightgray/20 cursor-pointer rounded p-2 hover:opacity-90"
>
<div className="flex items-center gap-2">
<UserCircleIcon className="h-5 w-5" />

View file

@ -8,10 +8,16 @@ import { useAppDispatch, useAppSelector } from "../../redux/hooks";
import { updateConfig } from "../../redux/slices/configSlice";
import ToggleSwitch from "../../components/gui/Switch";
import { useAuth } from "../../context/Auth";
import { Input, SecondaryButton, Select } from "../../components";
import { Input, SecondaryButton } from "../../components";
import { getFontSize } from "../../util";
import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
import { ScopeSelect } from "./ScopeSelect";
import {
SharedConfigSchema,
modifyContinueConfigWithSharedConfig,
} from "core/config/sharedConfig";
import NumberInput from "../../components/gui/NumberInput";
import { Select } from "../../components/gui/Select";
function ConfigPage() {
useNavigationListener();
@ -19,7 +25,7 @@ function ConfigPage() {
const navigate = useNavigate();
const ideMessenger = useContext(IdeMessengerContext);
const { selectedProfile } = useAuth();
const { selectedProfile, selectedOrganization } = useAuth();
const config = useAppSelector((state) => state.config.config);
function handleUpdate(sharedConfig: Partial<SharedConfigSchema>) {
@ -99,7 +105,7 @@ function ConfigPage() {
if (!selectedProfile) {
return (
<div className="overflow-y-scroll">
<PageHeader onClick={() => navigate("/")} title="Chat" />
<PageHeader onTitleClick={() => navigate("/")} title="Chat" />
<div className="px-4">
<div>
<h2>Continue Config</h2>
@ -112,16 +118,20 @@ function ConfigPage() {
return (
<div className="overflow-y-scroll">
<PageHeader onClick={() => navigate("/")} title="Chat" />
<PageHeader onTitleClick={() => navigate("/")} title="Chat" />
<div className="divide-x-0 divide-y-2 divide-solid divide-zinc-700 px-4">
<div className="flex flex-col gap-4 py-6">
<div>
<h2 className="mb-1 mt-0">Account</h2>
<span className="text-lightgray">
You are currently signed in to{" "}
<span className="font-semibold">ORG_NAME</span>
</span>
{selectedOrganization?.name && (
<span className="text-lightgray">
You are currently signed in to{" "}
<span className="font-semibold">
{selectedOrganization?.name}
</span>
</span>
)}
</div>
<ScopeSelect />
@ -277,87 +287,103 @@ function ConfigPage() {
/>
</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 items-end gap-1"
className="flex flex-col gap-1"
onSubmit={(e) => {
e.preventDefault();
handleSubmitPromptPath();
}}
>
<label className="flex flex-row items-center justify-between gap-3">
<div className="flex items-center justify-between">
<span>Workspace prompts path</span>
<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 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
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>
</label>
</div>
</form>
<form
className="flex flex-col items-end gap-1"
className="flex flex-col gap-1"
onSubmit={(e) => {
e.preventDefault();
handleDisableAutocompleteSubmit();
}}
>
<label className="flex flex-row items-center justify-between gap-3">
<div className="flex items-center justify-between">
<span>Disable autocomplete in files</span>
<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 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
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>
</label>
<span className="text-vsc-foreground-muted text-xs">
</div>
<span className="text-vsc-foreground-muted self-end text-xs">
Comma-separated list of path matchers
</span>
</form>

View file

@ -30,6 +30,7 @@ import { v4 as uuidv4 } from "uuid";
import { RootState } from "../store";
import { streamResponseThunk } from "../thunks/streamResponse";
import { findCurrentToolCall } from "../util";
import { OrganizationDescription } from "core/config/ProfileLifecycleManager";
// We need this to handle reorderings (e.g. a mid-array deletion) of the messages array.
// The proper fix is adding a UUID to all chat messages, but this is the temp workaround.
@ -46,6 +47,8 @@ type SessionState = {
id: string;
selectedProfileId: string;
availableProfiles: ProfileDescription[];
selectedOrganizationId: string | null;
availableOrganizations: OrganizationDescription[];
streamAborter: AbortController;
codeToEdit: CodeToEdit[];
curCheckpointIndex: number;
@ -96,8 +99,11 @@ const initialState: SessionState = {
packageSlug: "",
versionSlug: "",
},
iconUrl: "",
},
],
selectedOrganizationId: "",
availableOrganizations: [],
curCheckpointIndex: 0,
streamAborter: new AbortController(),
codeToEdit: [],
@ -368,9 +374,13 @@ export const sessionSlice = createSlice({
startAt: Date.now(),
active: true,
text: messageContent.replace("<think>", "").trim(),
}
} else if (lastItem.reasoning?.active && messageContent.includes("</think>")) {
const [reasoningEnd, answerStart] = messageContent.split("</think>");
};
} else if (
lastItem.reasoning?.active &&
messageContent.includes("</think>")
) {
const [reasoningEnd, answerStart] =
messageContent.split("</think>");
lastItem.reasoning.text += reasoningEnd.trimEnd();
lastItem.reasoning.active = false;
lastItem.reasoning.endAt = Date.now();
@ -552,6 +562,29 @@ export const sessionSlice = createSlice({
: payload[0]?.id,
};
},
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,
};
},
updateCurCheckpoint: (
state,
{ payload }: PayloadAction<{ filepath: string; content: string }>,
@ -669,6 +702,9 @@ export const sessionSlice = createSlice({
selectAvailableProfiles: (state) => {
return state.availableProfiles;
},
selectAvailableOrganizations: (state) => {
return state.availableOrganizations;
},
},
extraReducers: (builder) => {
addPassthroughCases(builder, [streamResponseThunk]);
@ -720,6 +756,7 @@ export const {
clearLastEmptyResponse,
setMainEditorContentTrigger,
setSelectedProfileId,
setSelectedOrganizationId,
deleteMessage,
setIsGatheringContext,
updateCurCheckpoint,
@ -733,6 +770,7 @@ export const {
setCalling,
cancelToolCall,
setAvailableProfiles,
setAvailableOrganizations,
acceptToolCall,
setToolGenerated,
setToolCallOutput,
@ -749,6 +787,7 @@ export const {
selectIsSingleRangeEditOrInsertion,
selectHasCodeToEdit,
selectAvailableProfiles,
selectAvailableOrganizations,
} = sessionSlice.selectors;
export default sessionSlice.reducer;

View file

@ -31,7 +31,12 @@ const rootReducer = combineReducers({
});
const saveSubsetFilters = [
createFilter("session", ["history", "sessionId"]),
createFilter("session", [
"history",
"sessionId",
"selectedOrganizationId",
"selectedProfileId",
]),
// Don't persist any of the edit state for now
createFilter("editModeState", []),
createFilter("config", ["defaultModelTitle"]),