From 9edd5e3e241862d8189cf17332f7c3a2933125c4 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 24 Dec 2024 14:03:23 -0500 Subject: [PATCH 1/4] Use ConfigResult everywhere --- binary/test/binary.test.ts | 24 ++++----- core/autocomplete/CompletionProvider.ts | 6 +-- core/config/ConfigHandler.test.ts | 4 +- core/config/ConfigHandler.ts | 32 +++++------- core/config/ProfileLifecycleManager.ts | 37 ++++++------- core/context/mcp/index.ts | 2 +- .../providers/_context-providers.test.ts | 9 ++-- core/core.ts | 52 +++++++++++++------ core/indexing/CodebaseIndexer.ts | 10 ++-- core/indexing/LanceDbIndex.test.ts | 7 ++- core/indexing/docs/DocsCrawler.skip.ts | 3 +- core/indexing/docs/DocsService.skip.ts | 4 +- core/indexing/docs/DocsService.ts | 11 ++-- core/protocol/core.ts | 8 ++- core/protocol/webview.ts | 6 ++- extensions/vscode/src/commands.ts | 7 ++- .../vscode/src/extension/VsCodeExtension.ts | 6 +-- .../vscode/src/extension/VsCodeMessenger.ts | 7 ++- .../codeLens/registerAllCodeLensProviders.ts | 12 +++-- .../src/quickEdit/QuickEditQuickPick.ts | 16 ++++-- .../vscode/src/util/loadAutocompleteModel.ts | 6 ++- gui/src/hooks/useSetup.ts | 19 ++++--- gui/src/redux/slices/configSlice.ts | 16 ++++-- 23 files changed, 189 insertions(+), 115 deletions(-) diff --git a/binary/test/binary.test.ts b/binary/test/binary.test.ts index f84b23a2d..bd8504986 100644 --- a/binary/test/binary.test.ts +++ b/binary/test/binary.test.ts @@ -1,8 +1,8 @@ import { SerializedContinueConfig } from "core"; // import Mock from "core/llm/llms/Mock.js"; import { FromIdeProtocol, ToIdeProtocol } from "core/protocol/index.js"; -import FileSystemIde from "core/util/filesystem"; import { IMessenger } from "core/protocol/messenger"; +import FileSystemIde from "core/util/filesystem"; import fs from "fs"; import { ChildProcessWithoutNullStreams, @@ -186,10 +186,11 @@ describe("Test Suite", () => { }); it("should return valid config object", async () => { - const { config } = await messenger.request( + const { result } = await messenger.request( "config/getSerializedProfileInfo", undefined, ); + const { config } = result; expect(config).toHaveProperty("models"); expect(config).toHaveProperty("embeddingsProvider"); expect(config).toHaveProperty("contextProviders"); @@ -229,18 +230,17 @@ describe("Test Suite", () => { await messenger.request("config/addModel", { model, }); - const { config } = await messenger.request( - "config/getSerializedProfileInfo", - undefined, - ); - expect(config.models.some((m) => m.title === model.title)).toBe(true); + const { + result: { config }, + } = await messenger.request("config/getSerializedProfileInfo", undefined); + + expect(config!.models.some((m) => m.title === model.title)).toBe(true); await messenger.request("config/deleteModel", { title: model.title }); - const { config: configAfterDelete } = await messenger.request( - "config/getSerializedProfileInfo", - undefined, - ); - expect(configAfterDelete.models.some((m) => m.title === model.title)).toBe( + const { + result: { config: configAfterDelete }, + } = await messenger.request("config/getSerializedProfileInfo", undefined); + expect(configAfterDelete!.models.some((m) => m.title === model.title)).toBe( false, ); }); diff --git a/core/autocomplete/CompletionProvider.ts b/core/autocomplete/CompletionProvider.ts index 479b9061c..77aadbdf5 100644 --- a/core/autocomplete/CompletionProvider.ts +++ b/core/autocomplete/CompletionProvider.ts @@ -3,11 +3,9 @@ import { TRIAL_FIM_MODEL } from "../config/onboarding.js"; import { IDE, ILLM } from "../index.js"; import OpenAI from "../llm/llms/OpenAI.js"; import { DEFAULT_AUTOCOMPLETE_OPTS } from "../util/parameters.js"; -import { PosthogFeatureFlag, Telemetry } from "../util/posthog.js"; import { shouldCompleteMultiline } from "./classification/shouldCompleteMultiline.js"; import { ContextRetrievalService } from "./context/ContextRetrievalService.js"; -// @prettier-ignore import { BracketMatchingService } from "./filtering/BracketMatchingService.js"; import { CompletionStreamer } from "./generation/CompletionStreamer.js"; @@ -123,10 +121,10 @@ export class CompletionProvider { } private async _getAutocompleteOptions() { - const config = await this.configHandler.loadConfig(); + const { config } = await this.configHandler.loadConfig(); const options = { ...DEFAULT_AUTOCOMPLETE_OPTS, - ...config.tabAutocompleteOptions, + ...config?.tabAutocompleteOptions, }; return options; } diff --git a/core/config/ConfigHandler.test.ts b/core/config/ConfigHandler.test.ts index e7d90f492..5a25e71fc 100644 --- a/core/config/ConfigHandler.test.ts +++ b/core/config/ConfigHandler.test.ts @@ -18,8 +18,8 @@ describe.skip("Test the ConfigHandler and E2E config loading", () => { }); test("should load the default config successfully", async () => { - const config = await testConfigHandler.loadConfig(); - expect(config.models.length).toBe(defaultConfig.models.length); + const result = await testConfigHandler.loadConfig(); + expect(result.config!.models.length).toBe(defaultConfig.models.length); }); test.skip("should add a system message from config.ts", async () => { diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 0106a96c5..9ef3cc8d2 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -60,13 +60,13 @@ export class ConfigHandler { // Always load local profile immediately in case control plane doesn't load try { - this.loadConfig(); + void this.loadConfig(); } catch (e) { console.error("Failed to load config: ", e); } // Load control plane profiles - this.fetchControlPlaneProfiles(); + void this.fetchControlPlaneProfiles(); } // This will be the local profile @@ -146,12 +146,8 @@ export class ConfigHandler { async setSelectedProfile(profileId: string) { this.selectedProfileId = profileId; - const newConfig = await this.loadConfig(); - this.notifyConfigListeners({ - config: newConfig, - errors: undefined, - configLoadInterrupted: false, - }); + const result = await this.loadConfig(); + this.notifyConfigListeners(result); const selectedProfiles = this.globalContext.get("lastSelectedProfileForWorkspace") ?? {}; selectedProfiles[await this.getWorkspaceId()] = profileId; @@ -170,7 +166,7 @@ export class ConfigHandler { // Automatically refresh config when Continue-related IDE (e.g. VS Code) settings are changed updateIdeSettings(ideSettings: IdeSettings) { this.ideSettingsPromise = Promise.resolve(ideSettings); - this.reloadConfig(); + void this.reloadConfig(); } updateControlPlaneSessionInfo( @@ -236,15 +232,15 @@ export class ConfigHandler { return this.profiles.map((p) => p.profileDescription); } - async loadConfig(): Promise { - return ( - await this.currentProfile.loadConfig(this.additionalContextProviders) - ).config!; // <-- TODO + async loadConfig(): Promise> { + return await this.currentProfile.loadConfig( + this.additionalContextProviders, + ); } async llmFromTitle(title?: string): Promise { - const config = await this.loadConfig(); - const model = config.models.find((m) => m.title === title); + const { config } = await this.loadConfig(); + const model = config?.models.find((m) => m.title === title); if (!model) { if (title === ONBOARDING_LOCAL_MODEL_TITLE) { // Special case, make calls to Ollama before we have it in the config @@ -252,8 +248,8 @@ export class ConfigHandler { model: LOCAL_ONBOARDING_CHAT_MODEL, }); return ollama; - } else if (config.models.length > 0) { - return config.models[0]; + } else if (config?.models?.length) { + return config?.models[0]; } throw new Error("No model found"); @@ -264,6 +260,6 @@ export class ConfigHandler { registerCustomContextProvider(contextProvider: IContextProvider) { this.additionalContextProviders.push(contextProvider); - this.reloadConfig(); + void this.reloadConfig(); } } diff --git a/core/config/ProfileLifecycleManager.ts b/core/config/ProfileLifecycleManager.ts index 7b595c0e6..c5ae16f91 100644 --- a/core/config/ProfileLifecycleManager.ts +++ b/core/config/ProfileLifecycleManager.ts @@ -13,8 +13,8 @@ export interface ProfileDescription { } export class ProfileLifecycleManager { - private savedConfig: ConfigResult | undefined; - private savedBrowserConfig?: BrowserSerializedContinueConfig; + private savedConfigResult: ConfigResult | undefined; + private savedBrowserConfigResult?: ConfigResult; private pendingConfigPromise?: Promise>; constructor(private readonly profileLoader: IProfileLoader) {} @@ -35,15 +35,15 @@ export class ProfileLifecycleManager { } clearConfig() { - this.savedConfig = undefined; - this.savedBrowserConfig = undefined; + this.savedConfigResult = undefined; + this.savedBrowserConfigResult = undefined; this.pendingConfigPromise = undefined; } // Clear saved config and reload async reloadConfig(): Promise> { - this.savedConfig = undefined; - this.savedBrowserConfig = undefined; + this.savedConfigResult = undefined; + this.savedBrowserConfigResult = undefined; this.pendingConfigPromise = undefined; return this.loadConfig([], true); @@ -55,8 +55,8 @@ export class ProfileLifecycleManager { ): Promise> { // If we already have a config, return it if (!forceReload) { - if (this.savedConfig) { - return this.savedConfig; + if (this.savedConfigResult) { + return this.savedConfigResult; } else if (this.pendingConfigPromise) { return this.pendingConfigPromise; } @@ -72,7 +72,7 @@ export class ProfileLifecycleManager { result.config.contextProviders ?? [] ).concat(additionalContextProviders); - this.savedConfig = result; + this.savedConfigResult = result; resolve(result); } else if (result.errors) { reject( @@ -82,15 +82,17 @@ export class ProfileLifecycleManager { }); // Wait for the config promise to resolve - this.savedConfig = await this.pendingConfigPromise; + this.savedConfigResult = await this.pendingConfigPromise; this.pendingConfigPromise = undefined; - return this.savedConfig; + return this.savedConfigResult; } async getSerializedConfig( additionalContextProviders: IContextProvider[], ): Promise> { - if (!this.savedBrowserConfig) { + if (this.savedBrowserConfigResult) { + return this.savedBrowserConfigResult; + } else { const result = await this.loadConfig(additionalContextProviders); if (!result.config) { return { @@ -98,12 +100,11 @@ export class ProfileLifecycleManager { config: undefined, }; } - this.savedBrowserConfig = finalToBrowserConfig(result.config); + const serializedConfig = finalToBrowserConfig(result.config); + return { + ...result, + config: serializedConfig, + }; } - return { - config: this.savedBrowserConfig, - errors: [], - configLoadInterrupted: false, - }; } } diff --git a/core/context/mcp/index.ts b/core/context/mcp/index.ts index 9a14e49cd..bcf11492f 100644 --- a/core/context/mcp/index.ts +++ b/core/context/mcp/index.ts @@ -132,7 +132,7 @@ class MCPConnection { if (!error.message.startsWith("StdioClientTransport already started")) { return { fatal: false, - message: `Failed to connect to MCP ${mcpId}: ${error.message}`, + message: `Failed to connect to MCP: ${error.message}`, }; } } diff --git a/core/context/providers/_context-providers.test.ts b/core/context/providers/_context-providers.test.ts index 7e0fdbd73..24cac2c44 100644 --- a/core/context/providers/_context-providers.test.ts +++ b/core/context/providers/_context-providers.test.ts @@ -1,15 +1,15 @@ import fetch from "node-fetch"; +import { contextProviderClassFromName } from "."; import { ContextProviderExtras, ContextProviderWithParams, IContextProvider, } from "../.."; import { ConfigHandler } from "../../config/ConfigHandler"; -import { contextProviderClassFromName } from "."; import { ControlPlaneClient } from "../../control-plane/client"; -import FileSystemIde from "../../util/filesystem"; import { TEST_DIR } from "../../test/testDir"; +import FileSystemIde from "../../util/filesystem"; const CONTEXT_PROVIDERS_TO_TEST: ContextProviderWithParams[] = [ { name: "diff", params: {} }, @@ -33,7 +33,10 @@ async function getContextProviderExtras( async (text) => {}, new ControlPlaneClient(Promise.resolve(undefined)), ); - const config = await configHandler.loadConfig(); + const { config } = await configHandler.loadConfig(); + if (!config) { + throw new Error("Config not found"); + } return { fullInput, diff --git a/core/core.ts b/core/core.ts index aa9c1eb5b..14389910c 100644 --- a/core/core.ts +++ b/core/core.ts @@ -65,7 +65,7 @@ export class Core { private abortedMessageIds: Set = new Set(); private async config() { - return this.configHandler.loadConfig(); + return (await this.configHandler.loadConfig()).config; } invoke( @@ -120,11 +120,9 @@ export class Core { ); this.configHandler.onConfigUpdate(async (result) => { - const serialized = await ( - await this.configHandler.getSerializedConfig() - ).config!; + const serializedResult = await this.configHandler.getSerializedConfig(); this.messenger.send("configUpdate", { - config: serialized, + result: serializedResult, profileId: this.configHandler.currentProfile.profileId, }); }); @@ -178,12 +176,12 @@ export class Core { }); const getLlm = async () => { - const config = await this.configHandler.loadConfig(); + const { config } = await this.configHandler.loadConfig(); const selected = this.globalContext.get("selectedTabAutocompleteModel"); return ( - config.tabAutocompleteModels?.find( + config?.tabAutocompleteModels?.find( (model) => model.title === selected, - ) ?? config.tabAutocompleteModels?.[0] + ) ?? config?.tabAutocompleteModels?.[0] ); }; this.completionProvider = new CompletionProvider( @@ -261,7 +259,7 @@ export class Core { on("config/newPromptFile", async (msg) => { await createNewPromptFileV2( this.ide, - (await this.config()).experimental?.promptPath, + (await this.config())?.experimental?.promptPath, ); await this.configHandler.reloadConfig(); }); @@ -272,7 +270,7 @@ export class Core { on("config/reload", async (msg) => { void this.configHandler.reloadConfig(); - return (await this.configHandler.getSerializedConfig()).config!; // <-- TODO + return await this.configHandler.getSerializedConfig(); }); on("config/ideSettingsUpdate", (msg) => { @@ -297,6 +295,10 @@ export class Core { on("context/loadSubmenuItems", async (msg) => { const config = await this.config(); + if (!config) { + return []; + } + const items = await config.contextProviders ?.find((provider) => provider.description.title === msg.data.title) ?.loadSubmenuItems({ @@ -312,6 +314,10 @@ export class Core { const { name, query, fullInput, selectedCode, selectedModelTitle } = msg.data; const config = await this.config(); + if (!config) { + return []; + } + const llm = await this.configHandler.llmFromTitle(selectedModelTitle); const provider = config.contextProviders?.find( (provider) => provider.description.title === name, @@ -366,7 +372,7 @@ export class Core { on("config/getSerializedProfileInfo", async (msg) => { return { - config: (await this.configHandler.getSerializedConfig()).config!, // <-- TODO + result: await this.configHandler.getSerializedConfig(), profileId: this.configHandler.currentProfile.profileId, }; }); @@ -376,7 +382,11 @@ export class Core { abortedMessageIds: Set, msg: Message, ) { - const config = await configHandler.loadConfig(); + const { config } = await configHandler.loadConfig(); + if (!config) { + throw new Error("Config not loaded"); + } + // Stop TTS on new StreamChat if (config.experimental?.readResponseTTS) { void TTS.kill(); @@ -480,7 +490,11 @@ export class Core { return completion; }); on("llm/listModels", async (msg) => { - const config = await this.configHandler.loadConfig(); + const { config } = await this.configHandler.loadConfig(); + if (!config) { + return []; + } + const model = config.models.find((model) => model.title === msg.data.title) ?? config.models.find((model) => model.title?.startsWith(msg.data.title)); @@ -533,7 +547,11 @@ export class Core { selectedCode, } = msg.data; - const config = await configHandler.loadConfig(); + const { config } = await configHandler.loadConfig(); + if (!config) { + throw new Error("Config not loaded"); + } + const llm = await configHandler.llmFromTitle(modelTitle); const slashCommand = config.slashCommands?.find( (sc) => sc.name === slashCommandName, @@ -846,7 +864,11 @@ export class Core { }); on("tools/call", async ({ data: { toolCall, selectedModelTitle } }) => { - const config = await this.configHandler.loadConfig(); + const { config } = await this.configHandler.loadConfig(); + if (!config) { + throw new Error("Config not loaded"); + } + const tool = config.tools.find( (t) => t.function.name === toolCall.function.name, ); diff --git a/core/indexing/CodebaseIndexer.ts b/core/indexing/CodebaseIndexer.ts index e309549eb..677cc4305 100644 --- a/core/indexing/CodebaseIndexer.ts +++ b/core/indexing/CodebaseIndexer.ts @@ -75,7 +75,11 @@ export class CodebaseIndexer { } protected async getIndexesToBuild(): Promise { - const config = await this.configHandler.loadConfig(); + const { config } = await this.configHandler.loadConfig(); + if (!config) { + return []; + } + const indexes = [ new ChunkCodebaseIndex( this.ide.readFile.bind(this.ide), @@ -198,8 +202,8 @@ export class CodebaseIndexer { return; } - const config = await this.configHandler.loadConfig(); - if (config.disableIndexing) { + const { config } = await this.configHandler.loadConfig(); + if (config?.disableIndexing) { yield { progress, desc: "Indexing is disabled in config.json", diff --git a/core/indexing/LanceDbIndex.test.ts b/core/indexing/LanceDbIndex.test.ts index 6cf36f78d..08c8f9982 100644 --- a/core/indexing/LanceDbIndex.test.ts +++ b/core/indexing/LanceDbIndex.test.ts @@ -2,13 +2,13 @@ import { jest } from "@jest/globals"; import lance from "vectordb"; import { testConfigHandler, testIde } from "../test/fixtures"; +import { getLanceDbPath } from "../util/paths"; import { mockPathAndCacheKey, mockTag, testContinueServerClient, updateIndexAndAwaitGenerator, } from "./test/indexing"; -import { getLanceDbPath } from "../util/paths"; import { LanceDbIndex } from "./LanceDbIndex"; import { DatabaseConnection, SqliteDb } from "./refreshIndex"; @@ -26,7 +26,10 @@ describe.skip("ChunkCodebaseIndex", () => { } beforeAll(async () => { - const mockConfig = await testConfigHandler.loadConfig(); + const { config: mockConfig } = await testConfigHandler.loadConfig(); + if (!mockConfig) { + throw new Error("Failed to load config"); + } index = new LanceDbIndex( mockConfig.embeddingsProvider, diff --git a/core/indexing/docs/DocsCrawler.skip.ts b/core/indexing/docs/DocsCrawler.skip.ts index 97226c296..93d1749c9 100644 --- a/core/indexing/docs/DocsCrawler.skip.ts +++ b/core/indexing/docs/DocsCrawler.skip.ts @@ -28,7 +28,8 @@ describe.skip("DocsCrawler", () => { let docsCrawler: DocsCrawler; beforeAll(async () => { - config = await testConfigHandler.loadConfig(); + const result = await testConfigHandler.loadConfig(); + config = result.config!; mockIde = new FileSystemIde(process.cwd()); chromiumInstaller = new ChromiumInstaller(mockIde, config); docsCrawler = new DocsCrawler(mockIde, config); diff --git a/core/indexing/docs/DocsService.skip.ts b/core/indexing/docs/DocsService.skip.ts index 22c307f35..8b4b6a8bf 100644 --- a/core/indexing/docs/DocsService.skip.ts +++ b/core/indexing/docs/DocsService.skip.ts @@ -74,7 +74,7 @@ describe.skip("DocsService Integration Tests", () => { expect(await docsService.hasMetadata(mockSiteConfig.startUrl)).toBe(true); // config.json check - expect(latestConfig.docs).toContainEqual(mockSiteConfig); + expect(latestConfig.config!.docs).toContainEqual(mockSiteConfig); // Lance DB check let retrievedChunks = await docsService.retrieveChunksFromQuery( @@ -92,7 +92,7 @@ describe.skip("DocsService Integration Tests", () => { // config.json check latestConfig = await getReloadedConfig(); - expect(latestConfig.docs).not.toContainEqual( + expect(latestConfig.config!.docs).not.toContainEqual( expect.objectContaining(mockSiteConfig), ); diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index f35f83466..ddebd47a8 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -16,9 +16,9 @@ import { addContextProvider } from "../../config/util"; import DocsContextProvider from "../../context/providers/DocsContextProvider"; import TransformersJsEmbeddingsProvider from "../../llm/llms/TransformersJsEmbeddingsProvider"; import { FromCoreProtocol, ToCoreProtocol } from "../../protocol"; +import { IMessenger } from "../../protocol/messenger"; import { fetchFavicon, getFaviconBase64 } from "../../util/fetchFavicon"; import { GlobalContext } from "../../util/GlobalContext"; -import { IMessenger } from "../../protocol/messenger"; import { editConfigJson, getDocsSqlitePath, @@ -26,6 +26,7 @@ import { } from "../../util/paths"; import { Telemetry } from "../../util/posthog"; +import { ConfigResult } from "../../config/load"; import { Article, chunkArticle, pageToArticle } from "./article"; import DocsCrawler from "./DocsCrawler"; import { runLanceMigrations, runSqliteMigrations } from "./migrations"; @@ -123,8 +124,8 @@ export default class DocsService { // Initialization - load config and attach config listener private async init(configHandler: ConfigHandler) { - const config = await configHandler.loadConfig(); - await this.handleConfigUpdate({ config }); + const result = await configHandler.loadConfig(); + await this.handleConfigUpdate(result); configHandler.onConfigUpdate(this.handleConfigUpdate.bind(this)); } @@ -247,9 +248,7 @@ export default class DocsService { private async handleConfigUpdate({ config: newConfig, - }: { - config: ContinueConfig | undefined; - }) { + }: ConfigResult) { if (newConfig) { const oldConfig = this.config; this.config = newConfig; // IMPORTANT - need to set up top, other methods below use this without passing it in diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 9a7d85510..e05ce1bc4 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -20,6 +20,7 @@ import type { SiteIndexingConfig, ToolCall, } from "../"; +import { ConfigResult } from "../config/load"; export type ProtocolGeneratorType = AsyncGenerator<{ done?: boolean; @@ -63,10 +64,13 @@ export type ToCoreFromIdeOrWebviewProtocol = { "config/ideSettingsUpdate": [IdeSettings, void]; "config/getSerializedProfileInfo": [ undefined, - { config: BrowserSerializedContinueConfig; profileId: string }, + { + result: ConfigResult; + profileId: string; + }, ]; "config/deleteModel": [{ title: string }, void]; - "config/reload": [undefined, BrowserSerializedContinueConfig]; + "config/reload": [undefined, ConfigResult]; "config/listProfiles": [undefined, ProfileDescription[]]; "config/openProfile": [{ profileId: string | undefined }, void]; "context/getContextItems": [ diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index 65ecde912..11512fa2c 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -1,3 +1,4 @@ +import { ConfigResult } from "../config/load.js"; import { ConfigValidationError } from "../config/validation.js"; import type { @@ -10,7 +11,10 @@ import type { export type ToWebviewFromIdeOrCoreProtocol = { configUpdate: [ - { config: BrowserSerializedContinueConfig; profileId: string }, + { + result: ConfigResult; + profileId: string; + }, void, ]; configError: [ConfigValidationError[] | undefined, void]; diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 690063628..b83d3d380 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -335,7 +335,10 @@ const getCommandsMap: ( onlyOneInsertion?: boolean, range?: vscode.Range, ) { - const config = await configHandler.loadConfig(); + const { config } = await configHandler.loadConfig(); + if (!config) { + throw new Error("Config not loaded"); + } const defaultModelTitle = await sidebar.webviewProtocol.request( "getDefaultModelTitle", @@ -867,7 +870,7 @@ const getCommandsMap: ( const config = vscode.workspace.getConfiguration(EXTENSION_NAME); const quickPick = vscode.window.createQuickPick(); const autocompleteModels = - (await configHandler.loadConfig())?.tabAutocompleteModels ?? []; + (await configHandler.loadConfig()).config?.tabAutocompleteModels ?? []; let selected = new GlobalContext().get("selectedTabAutocompleteModel"); if ( diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index ac3f7fbf7..4ff02a736 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -149,7 +149,7 @@ export class VsCodeExtension { this.configHandler.reloadConfig.bind(this.configHandler), ); - this.configHandler.loadConfig().then((config) => { + this.configHandler.loadConfig().then(({ config }) => { const { verticalDiffCodeLens } = registerAllCodeLensProviders( context, this.verticalDiffManager.fileUriToCodeLens, @@ -168,9 +168,9 @@ export class VsCodeExtension { } else if (newConfig) { setupStatusBar(undefined, undefined, false); - const serialized = await this.configHandler.getSerializedConfig(); + const result = await this.configHandler.getSerializedConfig(); this.sidebar.webviewProtocol?.request("configUpdate", { - config: serialized.config!, // <-- TODO + result, profileId: this.configHandler.currentProfile.profileId, }); diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 2b88fbca6..52238cc1e 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -171,7 +171,12 @@ export class VsCodeMessenger { // Get LLM from config const configHandler = await configHandlerPromise; - const config = await configHandler.loadConfig(); + const { config } = await configHandler.loadConfig(); + + if (!config) { + vscode.window.showErrorMessage("Config not loaded"); + return; + } let llm = getModelByRole(config, "applyCodeBlock"); diff --git a/extensions/vscode/src/lang-server/codeLens/registerAllCodeLensProviders.ts b/extensions/vscode/src/lang-server/codeLens/registerAllCodeLensProviders.ts index ec168de53..9138fba8b 100644 --- a/extensions/vscode/src/lang-server/codeLens/registerAllCodeLensProviders.ts +++ b/extensions/vscode/src/lang-server/codeLens/registerAllCodeLensProviders.ts @@ -74,7 +74,7 @@ function registerQuickActionsProvider( export function registerAllCodeLensProviders( context: vscode.ExtensionContext, editorToVerticalDiffCodeLens: Map, - config: ContinueConfig, + config: ContinueConfig | undefined, ) { if (verticalPerLineCodeLensProvider) { verticalPerLineCodeLensProvider.dispose(); @@ -110,11 +110,13 @@ export function registerAllCodeLensProviders( new providers.SuggestionsCodeLensProvider(), ); - registerQuickActionsProvider(config, context); + if (config) { + registerQuickActionsProvider(config, context); - subscribeToVSCodeQuickActionsSettings(() => - registerQuickActionsProvider(config, context), - ); + subscribeToVSCodeQuickActionsSettings(() => + registerQuickActionsProvider(config, context), + ); + } context.subscriptions.push(verticalPerLineCodeLensProvider); context.subscriptions.push(suggestionsCodeLensDisposable); diff --git a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts index aefc7408f..09cf8e2cd 100644 --- a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts +++ b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts @@ -242,6 +242,10 @@ export class QuickEdit { path: string | undefined, ) => { const modelTitle = await this.getCurModelTitle(); + if (!modelTitle) { + throw new Error("No model selected"); + } + await this._streamEditWithInputAndContext(prompt, modelTitle); this.openAcceptRejectMenu(prompt, path); }; @@ -258,12 +262,15 @@ export class QuickEdit { /** * Gets the model title the user has chosen, or their default model */ - private async getCurModelTitle() { + private async getCurModelTitle(): Promise { if (this._curModelTitle) { return this._curModelTitle; } - const config = await this.configHandler.loadConfig(); + const { config } = await this.configHandler.loadConfig(); + if (!config) { + return undefined; + } return ( getModelByRole(config, "inlineEdit")?.title ?? @@ -517,7 +524,10 @@ export class QuickEdit { editor: vscode.TextEditor; params: QuickEditShowParams | undefined; }) { - const config = await this.configHandler.loadConfig(); + const { config } = await this.configHandler.loadConfig(); + if (!config) { + throw new Error("Config not loaded"); + } let prompt: string | undefined; switch (selectedLabel) { diff --git a/extensions/vscode/src/util/loadAutocompleteModel.ts b/extensions/vscode/src/util/loadAutocompleteModel.ts index b4aa9289b..fda69f023 100644 --- a/extensions/vscode/src/util/loadAutocompleteModel.ts +++ b/extensions/vscode/src/util/loadAutocompleteModel.ts @@ -34,7 +34,11 @@ export class TabAutocompleteModel { async get() { if (!this._llm) { - const config = await this.configHandler.loadConfig(); + const { config } = await this.configHandler.loadConfig(); + if (!config) { + return undefined; + } + if (config.tabAutocompleteModels?.length) { const selected = this.globalContext.get("selectedTabAutocompleteModel"); if (selected) { diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 5534fbc3b..65d72557c 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -3,8 +3,9 @@ import { VSC_THEME_COLOR_VARS } from "../components"; import { IdeMessengerContext } from "../context/IdeMessenger"; import { BrowserSerializedContinueConfig } from "core"; +import { ConfigResult } from "core/config/load"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; -import { setConfig, setConfigError } from "../redux/slices/configSlice"; +import { setConfigError, setConfigResult } from "../redux/slices/configSlice"; import { updateIndexingStatus } from "../redux/slices/indexingSlice"; import { updateDocsSuggestions } from "../redux/slices/miscSlice"; import { @@ -33,20 +34,23 @@ function useSetup() { const handleConfigUpdate = useCallback( async ( initial: boolean, - result: { config: BrowserSerializedContinueConfig; profileId: string }, + result: { + result: ConfigResult; + profileId: string; + }, ) => { - const { config, profileId } = result; + const { result: configResult, profileId } = result; if (initial && hasLoadedConfig.current) { return; } hasLoadedConfig.current = true; - dispatch(setConfig(config)); + dispatch(setConfigResult(configResult)); dispatch(setSelectedProfileId(profileId)); // Perform any actions needed with the config - if (config.ui?.fontSize) { - setLocalStorage("fontSize", config.ui.fontSize); - document.body.style.fontSize = `${config.ui.fontSize}px`; + if (configResult.config?.ui?.fontSize) { + setLocalStorage("fontSize", configResult.config.ui.fontSize); + document.body.style.fontSize = `${configResult.config.ui.fontSize}px`; } }, [dispatch, hasLoadedConfig], @@ -61,6 +65,7 @@ function useSetup() { if (result.status === "error") { return; } + console.log("Config loaded", result.content); await handleConfigUpdate(initial, result.content); }, [ideMessenger, handleConfigUpdate], diff --git a/gui/src/redux/slices/configSlice.ts b/gui/src/redux/slices/configSlice.ts index 95c7e3e8a..35e530e47 100644 --- a/gui/src/redux/slices/configSlice.ts +++ b/gui/src/redux/slices/configSlice.ts @@ -1,5 +1,6 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { BrowserSerializedContinueConfig } from "core"; +import { ConfigResult } from "core/config/load"; import { ConfigValidationError } from "core/config/validation"; import { DEFAULT_MAX_TOKENS } from "core/llm/constants"; @@ -33,10 +34,19 @@ export const configSlice = createSlice({ name: "config", initialState, reducers: { - setConfig: ( + setConfigResult: ( state, - { payload: config }: PayloadAction, + { + payload: result, + }: PayloadAction>, ) => { + const { config, errors } = result; + state.configError = errors; + + if (!config) { + return; + } + const defaultModelTitle = config.models.find((model) => model.title === state.defaultModelTitle) ?.title || @@ -83,7 +93,7 @@ export const configSlice = createSlice({ }, }); -export const { setDefaultModel, setConfig, setConfigError } = +export const { setDefaultModel, setConfigResult, setConfigError } = configSlice.actions; export const { From 38a7c3a9a20ef9a723d226c3acb56ddb83cc85fe Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 24 Dec 2024 14:42:59 -0500 Subject: [PATCH 2/4] fix mcp decoding for tools --- core/context/mcp/index.ts | 3 ++- core/tools/callTool.ts | 5 ++++- extensions/vscode/package-lock.json | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/context/mcp/index.ts b/core/context/mcp/index.ts index bcf11492f..e214b1e02 100644 --- a/core/context/mcp/index.ts +++ b/core/context/mcp/index.ts @@ -7,6 +7,7 @@ import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js"; import { ContinueConfig, MCPOptions, SlashCommand, Tool } from "../.."; import { constructMcpSlashCommand } from "../../commands/slash/mcp"; import { ConfigValidationError } from "../../config/validation"; +import { encodeMCPToolUri } from "../../tools/callTool"; import MCPContextProvider from "../providers/MCPContextProvider"; export class MCPManagerSingleton { @@ -172,7 +173,7 @@ class MCPConnection { readonly: false, type: "function", wouldLikeTo: `use the ${tool.name} tool`, - uri: `mcp://${tool.name}`, + uri: encodeMCPToolUri(mcpId, tool.name), })); config.tools = [...config.tools, ...continueTools]; diff --git a/core/tools/callTool.ts b/core/tools/callTool.ts index 3de329a0b..2bca7c2d1 100644 --- a/core/tools/callTool.ts +++ b/core/tools/callTool.ts @@ -44,7 +44,10 @@ export function decodeMCPToolUri(uri: string): [string, string] | null { if (url.protocol !== "mcp:") { return null; } - return [decodeURIComponent(url.hostname), decodeURIComponent(url.pathname)]; + return [ + decodeURIComponent(url.hostname), + decodeURIComponent(url.pathname).slice(1), // to remove leading '/' + ]; } async function callToolFromUri( diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index ca4edfc38..8f5cad8a0 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.246", + "version": "0.9.247", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.246", + "version": "0.9.247", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", From 2b5ed9e59b0b2ff5bdc3e83b7ee2cd1ced21985e Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 24 Dec 2024 14:45:02 -0500 Subject: [PATCH 3/4] bump package.json --- extensions/vscode/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 4cb023717..6a416096c 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -2,7 +2,7 @@ "name": "continue", "icon": "media/icon.png", "author": "Continue Dev, Inc", - "version": "0.9.247", + "version": "0.9.248", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" From 955117019366c6d286526478497d62cca6c11d5f Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 24 Dec 2024 17:17:09 -0500 Subject: [PATCH 4/4] fix tsc err --- core/tools/callTool.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/core/tools/callTool.ts b/core/tools/callTool.ts index 2bca7c2d1..706fa57d9 100644 --- a/core/tools/callTool.ts +++ b/core/tools/callTool.ts @@ -55,6 +55,7 @@ async function callToolFromUri( args: any, extras: ToolExtras, ): Promise { + // @ts-ignore const canParse = URL.canParse(uri); if (!canParse) { throw new Error(`Invalid URI: ${uri}`);