load multiple local assistants

This commit is contained in:
Nate 2025-03-08 16:09:08 -08:00
parent 6bc7c5560e
commit edcf5b321c
15 changed files with 134 additions and 76 deletions

View file

@ -1,5 +1,3 @@
import * as fs from "node:fs";
import { ConfigResult, FullSlug } from "@continuedev/config-yaml";
import {
@ -17,8 +15,6 @@ import {
} from "../index.js";
import Ollama from "../llm/llms/Ollama.js";
import { GlobalContext } from "../util/GlobalContext.js";
import { getConfigJsonPath, getConfigYamlPath } from "../util/paths.js";
import { localPathToUri } from "../util/pathToUri.js";
import { getAllAssistantFiles } from "./getSystemPromptDotFile.js";
import {
@ -98,7 +94,7 @@ export class ConfigHandler {
this.ideSettingsPromise,
this.controlPlaneClient,
this.writeLog,
assistant.path,
assistant,
);
});
return profiles.map(
@ -162,14 +158,12 @@ export class ConfigHandler {
async openConfigProfile(profileId?: string) {
let openProfileId = profileId || this.selectedProfileId;
if (openProfileId === "local") {
const profile = this.profiles?.find(
(p) => p.profileDescription.id === openProfileId,
);
if (profile?.profileDescription.profileType === "local") {
const ideInfo = await this.ide.getIdeInfo();
const configYamlPath = getConfigYamlPath(ideInfo.ideType);
if (fs.existsSync(configYamlPath)) {
await this.ide.openFile(localPathToUri(configYamlPath));
} else {
await this.ide.openFile(localPathToUri(getConfigJsonPath()));
}
await this.ide.openFile(profile.profileDescription.uri);
} else {
const env = await getControlPlaneEnv(this.ide.getIdeSettings());
await this.ide.openUrl(`${env.APP_URL}${openProfileId}`);
@ -194,25 +188,27 @@ export class ConfigHandler {
const assistants =
await this.controlPlaneClient.listAssistants(selectedOrgId);
const hubProfiles = assistants.map((assistant) => {
const profileLoader = new PlatformProfileLoader(
{
...assistant.configResult,
config: assistant.configResult.config,
},
assistant.ownerSlug,
assistant.packageSlug,
assistant.iconUrl,
assistant.configResult.config?.version ?? "latest",
this.controlPlaneClient,
this.ide,
this.ideSettingsPromise,
this.writeLog,
this.reloadConfig.bind(this),
);
const hubProfiles = await Promise.all(
assistants.map(async (assistant) => {
const profileLoader = await PlatformProfileLoader.create(
{
...assistant.configResult,
config: assistant.configResult.config,
},
assistant.ownerSlug,
assistant.packageSlug,
assistant.iconUrl,
assistant.configResult.config?.version ?? "latest",
this.controlPlaneClient,
this.ide,
this.ideSettingsPromise,
this.writeLog,
this.reloadConfig.bind(this),
);
return new ProfileLifecycleManager(profileLoader, this.ide);
});
return new ProfileLifecycleManager(profileLoader, this.ide);
}),
);
if (selectedOrgId === null) {
// Personal

View file

@ -21,6 +21,7 @@ export interface ProfileDescription {
id: string;
iconUrl: string;
errors: ConfigValidationError[] | undefined;
uri: string;
}
export interface OrganizationDescription {

View file

@ -10,6 +10,7 @@ import {
} from "../../index.js";
import { ProfileDescription } from "../ProfileLifecycleManager.js";
import { PRODUCTION_ENV } from "../../control-plane/env.js";
import doLoadConfig from "./doLoadConfig.js";
import { IProfileLoader } from "./IProfileLoader.js";
@ -40,6 +41,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader {
},
title: workspaceTitle,
errors: undefined,
uri: `${PRODUCTION_ENV.APP_URL}workspaces/${workspaceId}`,
};
setInterval(async () => {

View file

@ -1,34 +1,54 @@
import { ConfigResult } from "@continuedev/config-yaml";
import { ConfigResult, parseConfigYaml } from "@continuedev/config-yaml";
import { ControlPlaneClient } from "../../control-plane/client.js";
import { ContinueConfig, IDE, IdeSettings } from "../../index.js";
import { ProfileDescription } from "../ProfileLifecycleManager.js";
import { getPrimaryConfigFilePath } from "../../util/paths.js";
import { localPathToUri } from "../../util/pathToUri.js";
import doLoadConfig from "./doLoadConfig.js";
import { IProfileLoader } from "./IProfileLoader.js";
export default class LocalProfileLoader implements IProfileLoader {
static ID = "local";
description: ProfileDescription = {
id: LocalProfileLoader.ID,
profileType: "local",
fullSlug: {
ownerSlug: "",
packageSlug: "",
versionSlug: "",
},
iconUrl: "",
title: "Local Config",
errors: undefined,
};
constructor(
private ide: IDE,
private ideSettingsPromise: Promise<IdeSettings>,
private controlPlaneClient: ControlPlaneClient,
private writeLog: (message: string) => Promise<void>,
private overrideConfigYamlByPath?: string | undefined,
) {}
private overrideAssistantFile?:
| { path: string; content: string }
| undefined,
) {
const description: ProfileDescription = {
id: overrideAssistantFile?.path ?? LocalProfileLoader.ID,
profileType: "local",
fullSlug: {
ownerSlug: "",
packageSlug: "",
versionSlug: "",
},
iconUrl: "",
title: overrideAssistantFile?.path ?? "Local Config",
errors: undefined,
uri:
overrideAssistantFile?.path ??
localPathToUri(getPrimaryConfigFilePath()),
};
this.description = description;
if (overrideAssistantFile?.content) {
try {
const parsedAssistant = parseConfigYaml(
overrideAssistantFile?.content ?? "",
);
this.description.title = parsedAssistant.name;
} catch (e) {
console.error("Failed to parse assistant file: ", e);
}
}
}
description: ProfileDescription;
async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
const result = await doLoadConfig(
@ -40,7 +60,7 @@ export default class LocalProfileLoader implements IProfileLoader {
undefined,
undefined,
this.description.id,
this.overrideConfigYamlByPath,
this.overrideAssistantFile?.path,
);
this.description.errors = result.errors;

View file

@ -5,6 +5,7 @@ import { ContinueConfig, IDE, IdeSettings } from "../../index.js";
import { ProfileDescription } from "../ProfileLifecycleManager.js";
import { getControlPlaneEnv } from "../../control-plane/env.js";
import doLoadConfig from "./doLoadConfig.js";
import { IProfileLoader } from "./IProfileLoader.js";
@ -21,21 +22,35 @@ export interface PlatformConfigMetadata {
export default class PlatformProfileLoader implements IProfileLoader {
static RELOAD_INTERVAL = 1000 * 5; // 5 seconds
description: ProfileDescription;
constructor(
private constructor(
private configResult: ConfigResult<AssistantUnrolled>,
private readonly ownerSlug: string,
private readonly packageSlug: string,
private readonly iconUrl: string,
versionSlug: string,
private readonly versionSlug: string,
private readonly controlPlaneClient: ControlPlaneClient,
private readonly ide: IDE,
private ideSettingsPromise: Promise<IdeSettings>,
private writeLog: (message: string) => Promise<void>,
private readonly onReload: () => void,
) {
this.description = {
readonly description: ProfileDescription,
) {}
static async create(
configResult: ConfigResult<AssistantUnrolled>,
ownerSlug: string,
packageSlug: string,
iconUrl: string,
versionSlug: string,
controlPlaneClient: ControlPlaneClient,
ide: IDE,
ideSettingsPromise: Promise<IdeSettings>,
writeLog: (message: string) => Promise<void>,
onReload: () => void,
): Promise<PlatformProfileLoader> {
const controlPlaneEnv = await getControlPlaneEnv(ideSettingsPromise);
const description: ProfileDescription = {
id: `${ownerSlug}/${packageSlug}`,
profileType: "platform",
fullSlug: {
@ -45,8 +60,23 @@ export default class PlatformProfileLoader implements IProfileLoader {
},
title: configResult.config?.name ?? `${ownerSlug}/${packageSlug}`,
errors: configResult.errors,
iconUrl: this.iconUrl,
iconUrl: iconUrl,
uri: `${controlPlaneEnv}${ownerSlug}/${packageSlug}`,
};
return new PlatformProfileLoader(
configResult,
ownerSlug,
packageSlug,
iconUrl,
versionSlug,
controlPlaneClient,
ide,
ideSettingsPromise,
writeLog,
onReload,
description,
);
}
async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
@ -70,7 +100,7 @@ export default class PlatformProfileLoader implements IProfileLoader {
packageSlug: this.packageSlug,
},
this.description.id,
undefined
undefined,
);
return {

View file

@ -19,13 +19,14 @@ import { getControlPlaneEnv } from "../../control-plane/env.js";
import { TeamAnalytics } from "../../control-plane/TeamAnalytics.js";
import ContinueProxy from "../../llm/llms/stubs/ContinueProxy";
import { getConfigJsonPath, getConfigYamlPath } from "../../util/paths";
import { localPathOrUriToPath } from "../../util/pathToUri";
import { Telemetry } from "../../util/posthog";
import { TTS } from "../../util/tts";
import { loadContinueConfigFromJson } from "../load";
import { migrateJsonSharedConfig } from "../migrateSharedConfig";
import { rectifySelectedModelsFromGlobalContext } from "../selectedModels";
import { loadContinueConfigFromYaml } from "../yaml/loadYaml";
import { PlatformConfigMetadata } from "./PlatformProfileLoader";
import { rectifySelectedModelsFromGlobalContext } from "../selectedModels";
export default async function doLoadConfig(
ide: IDE,
@ -36,7 +37,7 @@ export default async function doLoadConfig(
overrideConfigYaml: AssistantUnrolled | undefined,
platformConfigMetadata: PlatformConfigMetadata | undefined,
profileId: string,
overrideConfigYamlByPath: string | undefined
overrideConfigYamlByPath: string | undefined,
): Promise<ConfigResult<ContinueConfig>> {
const workspaceConfigs = await getWorkspaceConfigs(ide);
const ideInfo = await ide.getIdeInfo();
@ -51,7 +52,9 @@ export default async function doLoadConfig(
migrateJsonSharedConfig(configJsonPath, ide);
}
const configYamlPath = overrideConfigYamlByPath || getConfigYamlPath(ideInfo.ideType);
const configYamlPath = localPathOrUriToPath(
overrideConfigYamlByPath || getConfigYamlPath(ideInfo.ideType),
);
let newConfig: ContinueConfig | undefined;
let errors: ConfigValidationError[] | undefined;
@ -69,6 +72,7 @@ export default async function doLoadConfig(
overrideConfigYaml,
platformConfigMetadata,
controlPlaneClient,
configYamlPath,
);
newConfig = result.config;
errors = result.errors;

View file

@ -366,10 +366,14 @@ export async function loadContinueConfigFromYaml(
overrideConfigYaml: AssistantUnrolled | undefined,
platformConfigMetadata: PlatformConfigMetadata | undefined,
controlPlaneClient: ControlPlaneClient,
configYamlPath: string | undefined,
): Promise<ConfigResult<ContinueConfig>> {
const rawYaml =
overrideConfigYaml === undefined
? fs.readFileSync(getConfigYamlPath(ideInfo.ideType), "utf-8")
? fs.readFileSync(
configYamlPath ?? getConfigYamlPath(ideInfo.ideType),
"utf-8",
)
: "";
const configYamlResult = await loadConfigYaml(

View file

@ -18,7 +18,7 @@ const WORKOS_CLIENT_ID_STAGING = "client_01J0FW6XCPMJMQ3CG51RB4HBZQ";
const WORKOS_ENV_ID_PRODUCTION = "continue";
const WORKOS_ENV_ID_STAGING = "continue-staging";
const PRODUCTION_ENV: ControlPlaneEnv = {
export const PRODUCTION_ENV: ControlPlaneEnv = {
DEFAULT_CONTROL_PLANE_PROXY_URL:
"https://control-plane-api-service-i3dqylpbqa-uc.a.run.app/",
CONTROL_PLANE_URL:

View file

@ -103,7 +103,7 @@ export function getConfigJsonPath(ideType: IdeType = "vscode"): string {
return p;
}
export function getConfigYamlPath(ideType: IdeType): string {
export function getConfigYamlPath(ideType?: IdeType): string {
const p = path.join(getContinueGlobalPath(), "config.yaml");
// if (!fs.existsSync(p)) {
// if (ideType === "jetbrains") {
@ -115,6 +115,14 @@ export function getConfigYamlPath(ideType: IdeType): string {
return p;
}
export function getPrimaryConfigFilePath(): string {
const configYamlPath = getConfigYamlPath();
if (fs.existsSync(configYamlPath)) {
return configYamlPath;
}
return getConfigJsonPath();
}
export function getConfigTsPath(): string {
const p = path.join(getContinueGlobalPath(), "config.ts");
if (!fs.existsSync(p)) {

View file

@ -12,7 +12,7 @@ function AddModelButtonSubtext() {
className="cursor-pointer underline"
onClick={() =>
ideMessenger.post("config/openProfile", {
profileId: "local",
profileId: undefined,
})
}
>

View file

@ -19,14 +19,10 @@ import {
setDefaultModel,
} from "../../redux/slices/configSlice";
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
import {
getFontSize,
getMetaKeyLabel,
isMetaEquivalentKeyPressed,
} from "../../util";
import { getFontSize, isMetaEquivalentKeyPressed } from "../../util";
import ConfirmationDialog from "../dialogs/ConfirmationDialog";
import Shortcut from "../gui/Shortcut";
import { Divider } from "./platform/shared";
import Shortcut from '../gui/Shortcut';
interface ModelOptionProps {
option: Option;
@ -166,9 +162,7 @@ function ModelOption({
e.stopPropagation();
e.preventDefault();
ideMessenger.post("config/openProfile", {
profileId: "local",
});
ideMessenger.post("config/openProfile", { profileId: undefined });
}
function handleOptionClick(e: any) {
@ -351,7 +345,7 @@ function ModelSelect() {
<div className="mt-auto">
<Divider className="!my-0" />
{selectedProfile?.id === "local" && (
{selectedProfile?.profileType === "local" && (
<>
<StyledListboxOption
key={options.length}

View file

@ -1,6 +1,5 @@
import { ProfileDescription } from "core/config/ProfileLifecycleManager";
import { isLocalProfile } from "../../../util";
export function getProfileDisplayText(profile: ProfileDescription): string {
return isLocalProfile(profile) ? profile.title : profile.fullSlug.packageSlug;
return profile.title;
}

View file

@ -221,7 +221,7 @@ function AddNewModel() {
disabled={false}
onClick={(e) => {
ideMessenger.post("config/openProfile", {
profileId: "local",
profileId: undefined,
});
}}
>

View file

@ -297,7 +297,7 @@ function ConfigPage() {
</div>
{selectedProfile && (
<SecondaryButton onClick={handleOpenConfig}>
{selectedProfile.id === "local"
{selectedProfile.profileType === "local"
? "Open Config File"
: hubEnabled
? "Open Assistant"

View file

@ -108,5 +108,5 @@ export function updatedObj(old: any, pathToValue: { [key: string]: any }) {
}
export function isLocalProfile(profile: ProfileDescription): boolean {
return profile.id === "local";
return profile.profileType === "local";
}