diff --git a/.gitignore b/.gitignore index b24d52983..763b96238 100644 --- a/.gitignore +++ b/.gitignore @@ -169,4 +169,4 @@ extensions/.continue-debug/ *.vsix .continuerules -.continue/assistants/ \ No newline at end of file +**/.continue/assistants/ \ No newline at end of file diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 8f2c6ad4c..3eadb9708 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -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, private readonly writeLog: (text: string) => Promise, sessionInfoPromise: Promise, + 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 { 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(); diff --git a/core/config/getSystemPromptDotFile.ts b/core/config/getSystemPromptDotFile.ts index fa07b9cfd..550144cd8 100644 --- a/core/config/getSystemPromptDotFile.ts +++ b/core/config/getSystemPromptDotFile.ts @@ -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 { 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 }; - }), - ); -} diff --git a/core/config/loadLocalAssistants.ts b/core/config/loadLocalAssistants.ts new file mode 100644 index 000000000..6eb6670ea --- /dev/null +++ b/core/config/loadLocalAssistants.ts @@ -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 }; + }), + ); +} diff --git a/core/config/profile/LocalProfileLoader.ts b/core/config/profile/LocalProfileLoader.ts index 13a1480c9..94af3a0e2 100644 --- a/core/config/profile/LocalProfileLoader.ts +++ b/core/config/profile/LocalProfileLoader.ts @@ -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 ?? diff --git a/core/config/yaml/convertFromJson.ts b/core/config/yaml/convertFromJson.ts index fdf73606f..ef928e6a6 100644 --- a/core/config/yaml/convertFromJson.ts +++ b/core/config/yaml/convertFromJson.ts @@ -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( diff --git a/core/config/yaml/default.ts b/core/config/yaml/default.ts index c9ca4dc8e..b63b2b848 100644 --- a/core/config/yaml/default.ts +++ b/core/config/yaml/default.ts @@ -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", }; diff --git a/core/config/yaml/models.ts b/core/config/yaml/models.ts index f2270c429..3f98d2d4e 100644 --- a/core/config/yaml/models.ts +++ b/core/config/yaml/models.ts @@ -35,8 +35,10 @@ async function modelConfigToBaseLLM( return undefined; } + const { capabilities, ...rest } = model; + let options: LLMOptions = { - ...model, + ...rest, completionOptions: { ...(model.defaultCompletionOptions ?? {}), model: model.model, @@ -55,6 +57,22 @@ async function modelConfigToBaseLLM( }, }; + // Model capabilities - need to be undefined if not found + // To fallback to our autodetection + if (capabilities?.find((c) => c === "tool_use")) { + options.capabilities = { + ...options.capabilities, + tools: true, + }; + } + + if (capabilities?.find((c) => c === "image_input")) { + options.capabilities = { + ...options.capabilities, + uploadImage: true, + }; + } + if (model.embedOptions?.maxBatchSize) { options.maxEmbeddingBatchSize = model.embedOptions.maxBatchSize; } diff --git a/core/core.ts b/core/core.ts index 037bb48ce..77505a976 100644 --- a/core/core.ts +++ b/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(); + } + } } }); diff --git a/core/indexing/walkDir.ts b/core/indexing/walkDir.ts index 757163d96..a544cff9e 100644 --- a/core/indexing/walkDir.ts +++ b/core/indexing/walkDir.ts @@ -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 { const defaultAndGlobalIgnores = ignore() - .add(defaultIgnoreFileAndDir) + .add(this.options.overrideIgnore ?? defaultIgnoreFileAndDir) .add(getGlobalContinueIgArray()); const rootContext: WalkContext = { diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 1b19a46cb..138c7e9d3 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -68,7 +68,10 @@ export type ToCoreFromIdeOrWebviewProtocol = { "config/deleteModel": [{ title: string }, void]; "config/addContextProvider": [ContextProviderWithParams, void]; "config/reload": [undefined, ConfigResult]; - "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]; diff --git a/core/protocol/coreWebview.ts b/core/protocol/coreWebview.ts index 5e71e5f11..4dcf74ee5 100644 --- a/core/protocol/coreWebview.ts +++ b/core/protocol/coreWebview.ts @@ -15,4 +15,5 @@ export type ToWebviewFromCoreProtocol = ToWebviewFromIdeOrCoreProtocol & { { profiles: ProfileDescription[]; selectedProfileId: string | null }, void, ]; + didSelectOrganization: [{ orgId: string | null }, void]; }; diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 352075d2e..7d0d51fc0 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -85,4 +85,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] = "getCurrentSessionId", "docs/suggestions", "didCloseFiles", + "didSelectOrganization", ]; diff --git a/docs/docs/json-reference.md b/docs/docs/json-reference.md index ba21ccb65..11e92a183 100644 --- a/docs/docs/json-reference.md +++ b/docs/docs/json-reference.md @@ -36,6 +36,7 @@ Each model has specific configuration options tailored to its provider and funct - `engine`: Engine for Azure OpenAI requests. - `capabilities`: Override auto-detected capabilities: - `uploadImage`: Boolean indicating if the model supports image uploads. + - `tools`: Boolean indicating if the model supports tool calls. _(AWS Only)_ diff --git a/docs/docs/yaml-reference.md b/docs/docs/yaml-reference.md index d4e63d1b4..723f08f2d 100644 --- a/docs/docs/yaml-reference.md +++ b/docs/docs/yaml-reference.md @@ -134,6 +134,7 @@ The `models` section defines the language models used in your configuration. Mod - `provider` (**required**): The provider of the model (e.g., `openai`, `ollama`). - `model` (**required**): The specific model name (e.g., `gpt-4`, `starcoder`). - `roles`: An array specifying the roles this model can fulfill, such as `chat`, `autocomplete`, `embed`, `rerank`, `edit`, `apply`, `summarize`. The default value is `[chat, edit, apply, summarize]`. Note that the `summarize` role is not currently used. +- `capabilities`: Array of strings denoting model capabilities, which will overwrite Continue's autodetection based on provider and model. Supported capabilities include `tool_use` and `image_input`. - `embedOptions`: If the model includes role `embed`, these settings apply for embeddings: - `maxChunkSize`: Maximum tokens per document chunk. Minimum is 128 tokens. @@ -187,6 +188,17 @@ models: model: codestral-latest roles: - autocomplete + + - name: My Model - OpenAI-Compatible + provider: openai + apiBase: http://my-endpoint/v1 + model: my-custom-model + capabilities: + - tool_use + - image_input + roles: + - chat + - edit ``` --- diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt index 81a6e1313..945fb218c 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt @@ -72,6 +72,7 @@ class MessageTypes { "getCurrentSessionId", "docs/suggestions", "didCloseFiles", + "didSelectOrganization" ) // Note: If updating these values, make a corresponding update in diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 5f7702aee..dc6465ddd 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -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", diff --git a/gui/package-lock.json b/gui/package-lock.json index abbd7f782..b56229b56 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -7,7 +7,7 @@ "name": "gui", "license": "Apache-2.0", "dependencies": { - "@continuedev/config-yaml": "^1.0.58", + "@continuedev/config-yaml": "^1.0.56", "@headlessui/react": "^1.7.17", "@heroicons/react": "^2.0.18", "@reduxjs/toolkit": "^2.3.0", @@ -555,9 +555,9 @@ } }, "node_modules/@continuedev/config-yaml": { - "version": "1.0.58", - "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.58.tgz", - "integrity": "sha512-SvIeEUwitG0Jt2gBa5J8wS4UJPTi+DttezBtS+MEJ+K6A8WCuP58XEAHVj5fwjz6am3mKelWyGYWawnNHYY72A==", + "version": "1.0.56", + "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.56.tgz", + "integrity": "sha512-2OBhmlSFOgZ+Z/ZQ18R/JR9zo6HIzkQ09PCuHQQ9NanN+g5AEVCdWgEtMyOq5DmQM3HLJCoLMXwqzQ9qSJEfFg==", "dependencies": { "@continuedev/config-types": "^1.0.14", "yaml": "^2.6.1", diff --git a/gui/package.json b/gui/package.json index c932c8075..b54727753 100644 --- a/gui/package.json +++ b/gui/package.json @@ -15,7 +15,7 @@ "test:watch": "vitest" }, "dependencies": { - "@continuedev/config-yaml": "^1.0.58", + "@continuedev/config-yaml": "^1.0.56", "@headlessui/react": "^1.7.17", "@heroicons/react": "^2.0.18", "@reduxjs/toolkit": "^2.3.0", diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index 807065019..d4e6f7925 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -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, }), ); } diff --git a/gui/src/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index c67f68241..2d42483a0 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -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; diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 01c398eb5..8b03d30f3 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -88,9 +88,8 @@ export const uiSlice = createSlice({ state.useTools = !state.useTools; }, addTool: (state, action: PayloadAction) => { - state.toolSettings[action.payload.function.name] = action.payload.readonly - ? "allowedWithoutPermission" - : "allowedWithPermission"; + state.toolSettings[action.payload.function.name] = + "allowedWithPermission"; }, toggleToolSetting: (state, action: PayloadAction) => { const setting = state.toolSettings[action.payload]; diff --git a/packages/config-yaml/package.json b/packages/config-yaml/package.json index ac70b5752..7c7619e97 100644 --- a/packages/config-yaml/package.json +++ b/packages/config-yaml/package.json @@ -1,6 +1,6 @@ { "name": "@continuedev/config-yaml", - "version": "1.0.58", + "version": "1.0.56", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/config-yaml/src/schemas/models.ts b/packages/config-yaml/src/schemas/models.ts index 1fd6247a6..ff3f6bec3 100644 --- a/packages/config-yaml/src/schemas/models.ts +++ b/packages/config-yaml/src/schemas/models.ts @@ -31,6 +31,14 @@ export const modelRolesSchema = z.enum([ ]); export type ModelRole = z.infer; +// TODO consider just using array of strings for model capabilities +// To allow more dynamic string parsing +export const modelCapabilitySchema = z.union([ + z.literal("tool_use"), + z.literal("image_input"), +]); +export type ModelCapability = z.infer; + export const completionOptionsSchema = z.object({ contextLength: z.number().optional(), maxTokens: z.number().optional(), @@ -61,6 +69,7 @@ const baseModelFields = { apiKey: z.string().optional(), apiBase: z.string().optional(), roles: modelRolesSchema.array().optional(), + capabilities: modelCapabilitySchema.array().optional(), defaultCompletionOptions: completionOptionsSchema.optional(), requestOptions: requestOptionsSchema.optional(), embedOptions: embedOptionsSchema.optional(),