Merge pull request #4609 from continuedev/nate/assistant-switcher-improvements
local assistant instead of config
This commit is contained in:
commit
d634f69d97
17 changed files with 142 additions and 81 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -169,4 +169,4 @@ extensions/.continue-debug/
|
|||
*.vsix
|
||||
|
||||
.continuerules
|
||||
.continue/assistants/
|
||||
**/.continue/assistants/
|
||||
|
|
@ -16,7 +16,7 @@ import {
|
|||
import Ollama from "../llm/llms/Ollama.js";
|
||||
import { GlobalContext } from "../util/GlobalContext.js";
|
||||
|
||||
import { getAllAssistantFiles } from "./getSystemPromptDotFile.js";
|
||||
import { getAllAssistantFiles } from "./loadLocalAssistants.js";
|
||||
import {
|
||||
LOCAL_ONBOARDING_CHAT_MODEL,
|
||||
LOCAL_ONBOARDING_PROVIDER_TITLE,
|
||||
|
|
@ -50,6 +50,7 @@ export class ConfigHandler {
|
|||
private ideSettingsPromise: Promise<IdeSettings>,
|
||||
private readonly writeLog: (text: string) => Promise<void>,
|
||||
sessionInfoPromise: Promise<ControlPlaneSessionInfo | undefined>,
|
||||
private readonly didSelectOrganization?: (orgId: string | null) => void,
|
||||
) {
|
||||
this.ide = ide;
|
||||
this.ideSettingsPromise = ideSettingsPromise;
|
||||
|
|
@ -114,12 +115,6 @@ export class ConfigHandler {
|
|||
}
|
||||
|
||||
private async init() {
|
||||
try {
|
||||
await this.loadLocalProfilesOnly();
|
||||
} catch (e) {
|
||||
console.error("Failed to load local assistants: ", e);
|
||||
}
|
||||
|
||||
try {
|
||||
await this.fetchControlPlaneProfiles();
|
||||
} catch (e) {
|
||||
|
|
@ -346,7 +341,8 @@ export class ConfigHandler {
|
|||
async getSelectedOrgId(): Promise<string | null> {
|
||||
const selectedOrgs =
|
||||
this.globalContext.get("lastSelectedOrgIdForWorkspace") ?? {};
|
||||
return selectedOrgs[await this.getWorkspaceId()] ?? null;
|
||||
const workspaceId = await this.getWorkspaceId();
|
||||
return selectedOrgs[workspaceId] ?? null;
|
||||
}
|
||||
|
||||
async setSelectedOrgId(orgId: string | null) {
|
||||
|
|
@ -354,9 +350,13 @@ export class ConfigHandler {
|
|||
this.globalContext.get("lastSelectedOrgIdForWorkspace") ?? {};
|
||||
selectedOrgs[await this.getWorkspaceId()] = orgId;
|
||||
this.globalContext.update("lastSelectedOrgIdForWorkspace", selectedOrgs);
|
||||
this.didSelectOrganization?.(orgId);
|
||||
}
|
||||
|
||||
async setSelectedProfile(profileId: string | null) {
|
||||
console.log(
|
||||
`Changing selected profile from ${this.selectedProfileId} to ${profileId}`,
|
||||
);
|
||||
this.selectedProfileId = profileId;
|
||||
const result = await this.loadConfig();
|
||||
this.notifyConfigListeners(result);
|
||||
|
|
@ -388,6 +388,17 @@ export class ConfigHandler {
|
|||
Promise.resolve(sessionInfo),
|
||||
this.ideSettingsPromise,
|
||||
);
|
||||
|
||||
// After login, default to the first org as the selected org
|
||||
try {
|
||||
const orgs = await this.controlPlaneClient.listOrganizations();
|
||||
if (orgs.length) {
|
||||
await this.setSelectedOrgId(orgs[0].id);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to fetch control plane profiles: ", e);
|
||||
}
|
||||
|
||||
this.fetchControlPlaneProfiles().catch(async (e) => {
|
||||
console.error("Failed to fetch control plane profiles: ", e);
|
||||
await this.loadLocalProfilesOnly();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
import { IDE } from "..";
|
||||
import { walkDir } from "../indexing/walkDir";
|
||||
import { getGlobalAssistantsPath } from "../util/paths";
|
||||
import { localPathToUri } from "../util/pathToUri";
|
||||
import { joinPathsToUri } from "../util/uri";
|
||||
export const SYSTEM_PROMPT_DOT_FILE = ".continuerules";
|
||||
|
||||
|
|
@ -27,56 +24,3 @@ export async function getSystemPromptDotFile(ide: IDE): Promise<string | null> {
|
|||
|
||||
return prompts.join("\n\n");
|
||||
}
|
||||
|
||||
export const ASSISTANTS_FOLDER = ".continue/assistants";
|
||||
|
||||
export async function getAssistantFilesFromDir(
|
||||
ide: IDE,
|
||||
dir: string,
|
||||
): Promise<{ path: string; content: string }[]> {
|
||||
try {
|
||||
const exists = await ide.fileExists(dir);
|
||||
|
||||
if (!exists) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const uris = await walkDir(dir, ide);
|
||||
const assistantFilePaths = uris.filter(
|
||||
(p) => p.endsWith(".yaml") || p.endsWith(".yml"),
|
||||
);
|
||||
const results = assistantFilePaths.map(async (uri) => {
|
||||
const content = await ide.readFile(uri); // make a try catch
|
||||
return { path: uri, content };
|
||||
});
|
||||
return Promise.all(results);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllAssistantFiles(
|
||||
ide: IDE,
|
||||
): Promise<{ path: string; content: string }[]> {
|
||||
const workspaceDirs = await ide.getWorkspaceDirs();
|
||||
let assistantFiles: { path: string; content: string }[] = [];
|
||||
|
||||
let dirsToCheck = [ASSISTANTS_FOLDER];
|
||||
const fullDirs = workspaceDirs
|
||||
.map((dir) => dirsToCheck.map((d) => joinPathsToUri(dir, d)))
|
||||
.flat();
|
||||
|
||||
fullDirs.push(localPathToUri(getGlobalAssistantsPath()));
|
||||
|
||||
assistantFiles = (
|
||||
await Promise.all(fullDirs.map((dir) => getAssistantFilesFromDir(ide, dir)))
|
||||
).flat();
|
||||
|
||||
return await Promise.all(
|
||||
assistantFiles.map(async (file) => {
|
||||
const content = await ide.readFile(file.path);
|
||||
return { path: file.path, content };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
76
core/config/loadLocalAssistants.ts
Normal file
76
core/config/loadLocalAssistants.ts
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import ignore from "ignore";
|
||||
import { IDE } from "..";
|
||||
import {
|
||||
DEFAULT_IGNORE_DIRS,
|
||||
DEFAULT_IGNORE_FILETYPES,
|
||||
} from "../indexing/ignore";
|
||||
import { walkDir } from "../indexing/walkDir";
|
||||
import { getGlobalAssistantsPath } from "../util/paths";
|
||||
import { localPathToUri } from "../util/pathToUri";
|
||||
import { joinPathsToUri } from "../util/uri";
|
||||
|
||||
export const ASSISTANTS_FOLDER = ".continue/assistants";
|
||||
|
||||
export function isLocalAssistantFile(uri: string): boolean {
|
||||
if (!uri.endsWith(".yaml") && !uri.endsWith(".yml")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const normalizedUri = uri.replace(/\\/g, "/");
|
||||
return normalizedUri.includes(`/${ASSISTANTS_FOLDER}/`);
|
||||
}
|
||||
|
||||
export async function getAssistantFilesFromDir(
|
||||
ide: IDE,
|
||||
dir: string,
|
||||
): Promise<{ path: string; content: string }[]> {
|
||||
try {
|
||||
const exists = await ide.fileExists(dir);
|
||||
|
||||
if (!exists) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const overrideIgnore = ignore()
|
||||
.add(DEFAULT_IGNORE_FILETYPES.filter((t) => t !== "config.yaml"))
|
||||
.add(DEFAULT_IGNORE_DIRS);
|
||||
|
||||
const uris = await walkDir(dir, ide, { overrideIgnore });
|
||||
const assistantFilePaths = uris.filter(
|
||||
(p) => p.endsWith(".yaml") || p.endsWith(".yml"),
|
||||
);
|
||||
const results = assistantFilePaths.map(async (uri) => {
|
||||
const content = await ide.readFile(uri); // make a try catch
|
||||
return { path: uri, content };
|
||||
});
|
||||
return Promise.all(results);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllAssistantFiles(
|
||||
ide: IDE,
|
||||
): Promise<{ path: string; content: string }[]> {
|
||||
const workspaceDirs = await ide.getWorkspaceDirs();
|
||||
let assistantFiles: { path: string; content: string }[] = [];
|
||||
|
||||
let dirsToCheck = [ASSISTANTS_FOLDER];
|
||||
const fullDirs = workspaceDirs
|
||||
.map((dir) => dirsToCheck.map((d) => joinPathsToUri(dir, d)))
|
||||
.flat();
|
||||
|
||||
fullDirs.push(localPathToUri(getGlobalAssistantsPath()));
|
||||
|
||||
assistantFiles = (
|
||||
await Promise.all(fullDirs.map((dir) => getAssistantFilesFromDir(ide, dir)))
|
||||
).flat();
|
||||
|
||||
return await Promise.all(
|
||||
assistantFiles.map(async (file) => {
|
||||
const content = await ide.readFile(file.path);
|
||||
return { path: file.path, content };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import { ProfileDescription } from "../ProfileLifecycleManager.js";
|
|||
|
||||
import { getPrimaryConfigFilePath } from "../../util/paths.js";
|
||||
import { localPathToUri } from "../../util/pathToUri.js";
|
||||
import { getUriPathBasename } from "../../util/uri.js";
|
||||
import doLoadConfig from "./doLoadConfig.js";
|
||||
import { IProfileLoader } from "./IProfileLoader.js";
|
||||
|
||||
|
|
@ -30,7 +31,9 @@ export default class LocalProfileLoader implements IProfileLoader {
|
|||
versionSlug: "",
|
||||
},
|
||||
iconUrl: "",
|
||||
title: overrideAssistantFile?.path ?? "Local Config",
|
||||
title: overrideAssistantFile?.path
|
||||
? getUriPathBasename(overrideAssistantFile.path)
|
||||
: "Local Assistant",
|
||||
errors: undefined,
|
||||
uri:
|
||||
overrideAssistantFile?.path ??
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { ModelConfig, AssistantUnrolled } from "@continuedev/config-yaml";
|
||||
import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml";
|
||||
|
||||
import { SerializedContinueConfig } from "../..";
|
||||
|
||||
|
|
@ -6,7 +6,7 @@ export function convertConfigJsonToConfigYaml(
|
|||
configJson: SerializedContinueConfig,
|
||||
): AssistantUnrolled {
|
||||
return {
|
||||
name: "Local Config",
|
||||
name: "Local Assistant",
|
||||
version: "1.0.0",
|
||||
models: [
|
||||
...configJson.models.map(
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ import { AssistantUnrolled } from "@continuedev/config-yaml";
|
|||
export const defaultConfigYaml: AssistantUnrolled = {
|
||||
models: [],
|
||||
context: [],
|
||||
name: "Local Config",
|
||||
name: "Local Assistant",
|
||||
version: "1.0.0",
|
||||
};
|
||||
|
||||
export const defaultConfigYamlJetBrains: AssistantUnrolled = {
|
||||
models: [],
|
||||
context: [],
|
||||
name: "Local Config",
|
||||
name: "Local Assistant",
|
||||
version: "1.0.0",
|
||||
};
|
||||
|
|
|
|||
20
core/core.ts
20
core/core.ts
|
|
@ -44,6 +44,7 @@ import {
|
|||
type IndexingProgressUpdate,
|
||||
} from ".";
|
||||
|
||||
import { isLocalAssistantFile } from "./config/loadLocalAssistants";
|
||||
import { shouldIgnore } from "./indexing/shouldIgnore";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
||||
import type { IMessenger, Message } from "./protocol/messenger";
|
||||
|
|
@ -106,6 +107,11 @@ export class Core {
|
|||
ideSettingsPromise,
|
||||
this.onWrite,
|
||||
sessionInfoPromise,
|
||||
(orgId: string | null) => {
|
||||
void messenger.request("didSelectOrganization", {
|
||||
orgId,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
this.docsService = DocsService.createSingleton(
|
||||
|
|
@ -294,8 +300,11 @@ export class Core {
|
|||
this.configHandler.updateIdeSettings(msg.data);
|
||||
});
|
||||
|
||||
on("config/listProfiles", (msg) => {
|
||||
return this.configHandler.listProfiles();
|
||||
on("config/listProfiles", async (msg) => {
|
||||
const profiles = this.configHandler.listProfiles();
|
||||
const selectedProfileId =
|
||||
this.configHandler.currentProfile?.profileDescription.id ?? null;
|
||||
return { profiles, selectedProfileId };
|
||||
});
|
||||
|
||||
on("config/refreshProfiles", async (msg) => {
|
||||
|
|
@ -926,6 +935,13 @@ export class Core {
|
|||
on("files/created", async ({ data }) => {
|
||||
if (data?.uris?.length) {
|
||||
void refreshIfNotIgnored(data.uris);
|
||||
|
||||
// If it's a local assistant being created, we want to reload all assistants so it shows up in the list
|
||||
for (const uri of data.uris) {
|
||||
if (isLocalAssistantFile(uri)) {
|
||||
await this.configHandler.loadAssistantsForSelectedOrg();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
export interface WalkerOptions {
|
||||
onlyDirs?: boolean;
|
||||
returnRelativeUrisPaths?: boolean;
|
||||
overrideIgnore?: Ignore;
|
||||
}
|
||||
|
||||
type Entry = [string, FileType];
|
||||
|
|
@ -46,7 +47,7 @@ class DFSWalker {
|
|||
// walk is a depth-first search implementation
|
||||
public async *walk(): AsyncGenerator<string> {
|
||||
const defaultAndGlobalIgnores = ignore()
|
||||
.add(defaultIgnoreFileAndDir)
|
||||
.add(this.options.overrideIgnore ?? defaultIgnoreFileAndDir)
|
||||
.add(getGlobalContinueIgArray());
|
||||
|
||||
const rootContext: WalkContext = {
|
||||
|
|
|
|||
|
|
@ -68,7 +68,10 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
"config/deleteModel": [{ title: string }, void];
|
||||
"config/addContextProvider": [ContextProviderWithParams, void];
|
||||
"config/reload": [undefined, ConfigResult<BrowserSerializedContinueConfig>];
|
||||
"config/listProfiles": [undefined, ProfileDescription[] | null];
|
||||
"config/listProfiles": [
|
||||
undefined,
|
||||
{ profiles: ProfileDescription[] | null; selectedProfileId: string | null },
|
||||
];
|
||||
"config/refreshProfiles": [undefined, void];
|
||||
"config/openProfile": [{ profileId: string | undefined }, void];
|
||||
"config/updateSharedConfig": [SharedConfigSchema, SharedConfigSchema];
|
||||
|
|
|
|||
|
|
@ -15,4 +15,5 @@ export type ToWebviewFromCoreProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
|||
{ profiles: ProfileDescription[]; selectedProfileId: string | null },
|
||||
void,
|
||||
];
|
||||
didSelectOrganization: [{ orgId: string | null }, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -85,4 +85,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] =
|
|||
"getCurrentSessionId",
|
||||
"docs/suggestions",
|
||||
"didCloseFiles",
|
||||
"didSelectOrganization",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ class MessageTypes {
|
|||
"getCurrentSessionId",
|
||||
"docs/suggestions",
|
||||
"didCloseFiles",
|
||||
"didSelectOrganization"
|
||||
)
|
||||
|
||||
// Note: If updating these values, make a corresponding update in
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "1.1.7",
|
||||
"version": "1.1.8",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "1.1.7",
|
||||
"version": "1.1.8",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
|
|
|
|||
|
|
@ -168,8 +168,8 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
if (result.status === "success") {
|
||||
dispatch(
|
||||
updateProfilesThunk({
|
||||
profiles: result.content,
|
||||
selectedProfileId: null,
|
||||
profiles: result.content.profiles,
|
||||
selectedProfileId: result.content.selectedProfileId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
UserCircleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useAuth } from "../../context/Auth";
|
||||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectOrgThunk } from "../../redux/thunks/profileAndOrg";
|
||||
|
||||
|
|
@ -19,6 +20,10 @@ export function ScopeSelect() {
|
|||
dispatch(selectOrgThunk(newValue));
|
||||
};
|
||||
|
||||
useWebviewListener("didSelectOrganization", async (data) => {
|
||||
handleChange(data.orgId);
|
||||
});
|
||||
|
||||
const CurScopeEntityFallBackIcon = selectedOrgId
|
||||
? BuildingOfficeIcon
|
||||
: UserCircleIcon;
|
||||
|
|
|
|||
|
|
@ -88,9 +88,8 @@ export const uiSlice = createSlice({
|
|||
state.useTools = !state.useTools;
|
||||
},
|
||||
addTool: (state, action: PayloadAction<Tool>) => {
|
||||
state.toolSettings[action.payload.function.name] = action.payload.readonly
|
||||
? "allowedWithoutPermission"
|
||||
: "allowedWithPermission";
|
||||
state.toolSettings[action.payload.function.name] =
|
||||
"allowedWithPermission";
|
||||
},
|
||||
toggleToolSetting: (state, action: PayloadAction<string>) => {
|
||||
const setting = state.toolSettings[action.payload];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue