Merge pull request #3525 from continuedev/nate/config-result
Use ConfigResult everywhere
This commit is contained in:
commit
62e9f35890
26 changed files with 199 additions and 120 deletions
|
|
@ -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,
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 () => {
|
||||
|
|
|
|||
|
|
@ -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<ContinueConfig> {
|
||||
return (
|
||||
await this.currentProfile.loadConfig(this.additionalContextProviders)
|
||||
).config!; // <-- TODO
|
||||
async loadConfig(): Promise<ConfigResult<ContinueConfig>> {
|
||||
return await this.currentProfile.loadConfig(
|
||||
this.additionalContextProviders,
|
||||
);
|
||||
}
|
||||
|
||||
async llmFromTitle(title?: string): Promise<ILLM> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ export interface ProfileDescription {
|
|||
}
|
||||
|
||||
export class ProfileLifecycleManager {
|
||||
private savedConfig: ConfigResult<ContinueConfig> | undefined;
|
||||
private savedBrowserConfig?: BrowserSerializedContinueConfig;
|
||||
private savedConfigResult: ConfigResult<ContinueConfig> | undefined;
|
||||
private savedBrowserConfigResult?: ConfigResult<BrowserSerializedContinueConfig>;
|
||||
private pendingConfigPromise?: Promise<ConfigResult<ContinueConfig>>;
|
||||
|
||||
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<ConfigResult<ContinueConfig>> {
|
||||
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<ConfigResult<ContinueConfig>> {
|
||||
// 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<ConfigResult<BrowserSerializedContinueConfig>> {
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -132,7 +133,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}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
52
core/core.ts
52
core/core.ts
|
|
@ -65,7 +65,7 @@ export class Core {
|
|||
private abortedMessageIds: Set<string> = new Set();
|
||||
|
||||
private async config() {
|
||||
return this.configHandler.loadConfig();
|
||||
return (await this.configHandler.loadConfig()).config;
|
||||
}
|
||||
|
||||
invoke<T extends keyof ToCoreProtocol>(
|
||||
|
|
@ -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<string>,
|
||||
msg: Message<ToCoreProtocol["llm/streamChat"][0]>,
|
||||
) {
|
||||
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,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -75,7 +75,11 @@ export class CodebaseIndexer {
|
|||
}
|
||||
|
||||
protected async getIndexesToBuild(): Promise<CodebaseIndex[]> {
|
||||
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",
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<ContinueConfig>) {
|
||||
if (newConfig) {
|
||||
const oldConfig = this.config;
|
||||
this.config = newConfig; // IMPORTANT - need to set up top, other methods below use this without passing it in
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import type {
|
|||
SiteIndexingConfig,
|
||||
ToolCall,
|
||||
} from "../";
|
||||
import { ConfigResult } from "../config/load";
|
||||
|
||||
export type ProtocolGeneratorType<T> = AsyncGenerator<{
|
||||
done?: boolean;
|
||||
|
|
@ -63,10 +64,13 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
"config/ideSettingsUpdate": [IdeSettings, void];
|
||||
"config/getSerializedProfileInfo": [
|
||||
undefined,
|
||||
{ config: BrowserSerializedContinueConfig; profileId: string },
|
||||
{
|
||||
result: ConfigResult<BrowserSerializedContinueConfig>;
|
||||
profileId: string;
|
||||
},
|
||||
];
|
||||
"config/deleteModel": [{ title: string }, void];
|
||||
"config/reload": [undefined, BrowserSerializedContinueConfig];
|
||||
"config/reload": [undefined, ConfigResult<BrowserSerializedContinueConfig>];
|
||||
"config/listProfiles": [undefined, ProfileDescription[]];
|
||||
"config/openProfile": [{ profileId: string | undefined }, void];
|
||||
"context/getContextItems": [
|
||||
|
|
|
|||
|
|
@ -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<BrowserSerializedContinueConfig>;
|
||||
profileId: string;
|
||||
},
|
||||
void,
|
||||
];
|
||||
configError: [ConfigValidationError[] | undefined, void];
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
@ -52,6 +55,7 @@ async function callToolFromUri(
|
|||
args: any,
|
||||
extras: ToolExtras,
|
||||
): Promise<ContextItem[]> {
|
||||
// @ts-ignore
|
||||
const canParse = URL.canParse(uri);
|
||||
if (!canParse) {
|
||||
throw new Error(`Invalid URI: ${uri}`);
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ function registerQuickActionsProvider(
|
|||
export function registerAllCodeLensProviders(
|
||||
context: vscode.ExtensionContext,
|
||||
editorToVerticalDiffCodeLens: Map<string, VerticalDiffCodeLens[]>,
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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<string | undefined> {
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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<BrowserSerializedContinueConfig>;
|
||||
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],
|
||||
|
|
|
|||
|
|
@ -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<BrowserSerializedContinueConfig>,
|
||||
{
|
||||
payload: result,
|
||||
}: PayloadAction<ConfigResult<BrowserSerializedContinueConfig>>,
|
||||
) => {
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue