reload assistants when a new local one is created
This commit is contained in:
parent
eba181c92d
commit
762881f981
6 changed files with 88 additions and 69 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,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,4 @@
|
|||
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 SYSTEM_PROMPT_DOT_FILE = ".continuerules";
|
||||
|
||||
|
|
@ -32,60 +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 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 };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
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 };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -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";
|
||||
|
|
@ -926,6 +927,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
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",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue