Merge pull request #2534 from continuedev/tomasz/validate-config-backup
Validate config.json
This commit is contained in:
commit
1067ef4155
25 changed files with 545 additions and 148 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -153,6 +153,8 @@ continue_server.dist
|
|||
Icon
|
||||
Icon?
|
||||
|
||||
.continue
|
||||
.continuerc.json
|
||||
.prompts/
|
||||
.aider*
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ describe.skip("Test the ConfigHandler and E2E config loading", () => {
|
|||
fs.writeFileSync(getConfigTsPath(), configTs);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
const config = await testConfigHandler.reloadConfig();
|
||||
/**
|
||||
* @ts-ignore is applied because this test is skipped
|
||||
*/
|
||||
// @ts-ignore
|
||||
expect(config.systemMessage).toBe("SYSTEM");
|
||||
});
|
||||
|
||||
|
|
@ -37,6 +41,10 @@ describe.skip("Test the ConfigHandler and E2E config loading", () => {
|
|||
JSON.stringify({ systemMessage: "SYSTEM2" }),
|
||||
);
|
||||
const config = await testConfigHandler.reloadConfig();
|
||||
/**
|
||||
* @ts-ignore is applied because this test is skipped
|
||||
*/
|
||||
// @ts-ignore
|
||||
expect(config.systemMessage).toBe("SYSTEM2");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,97 +12,24 @@ import {
|
|||
} from "../index.js";
|
||||
import Ollama from "../llm/llms/Ollama.js";
|
||||
import { GlobalContext } from "../util/GlobalContext.js";
|
||||
import { finalToBrowserConfig } from "./load.js";
|
||||
import { ConfigResult } from "./load.js";
|
||||
import {
|
||||
LOCAL_ONBOARDING_CHAT_MODEL,
|
||||
ONBOARDING_LOCAL_MODEL_TITLE,
|
||||
} from "./onboarding.js";
|
||||
import ControlPlaneProfileLoader from "./profile/ControlPlaneProfileLoader.js";
|
||||
import { IProfileLoader } from "./profile/IProfileLoader.js";
|
||||
import LocalProfileLoader from "./profile/LocalProfileLoader.js";
|
||||
|
||||
export interface ProfileDescription {
|
||||
title: string;
|
||||
id: string;
|
||||
}
|
||||
import {
|
||||
ProfileDescription,
|
||||
ProfileLifecycleManager,
|
||||
} from "./ProfileLifecycleManager.js";
|
||||
|
||||
export type { ProfileDescription };
|
||||
|
||||
type ConfigUpdateFunction = (payload: ConfigResult<ContinueConfig>) => void;
|
||||
|
||||
// Separately manages saving/reloading each profile
|
||||
class ProfileLifecycleManager {
|
||||
private savedConfig: ContinueConfig | undefined;
|
||||
private savedBrowserConfig?: BrowserSerializedContinueConfig;
|
||||
private pendingConfigPromise?: Promise<ContinueConfig>;
|
||||
|
||||
constructor(private readonly profileLoader: IProfileLoader) {}
|
||||
|
||||
get profileId() {
|
||||
return this.profileLoader.profileId;
|
||||
}
|
||||
|
||||
get profileTitle() {
|
||||
return this.profileLoader.profileTitle;
|
||||
}
|
||||
|
||||
get profileDescription(): ProfileDescription {
|
||||
return {
|
||||
title: this.profileTitle,
|
||||
id: this.profileId,
|
||||
};
|
||||
}
|
||||
|
||||
clearConfig() {
|
||||
this.savedConfig = undefined;
|
||||
this.savedBrowserConfig = undefined;
|
||||
this.pendingConfigPromise = undefined;
|
||||
}
|
||||
|
||||
// Clear saved config and reload
|
||||
async reloadConfig(): Promise<ContinueConfig> {
|
||||
this.savedConfig = undefined;
|
||||
this.savedBrowserConfig = undefined;
|
||||
this.pendingConfigPromise = undefined;
|
||||
|
||||
return await this.profileLoader.doLoadConfig();
|
||||
}
|
||||
|
||||
async loadConfig(
|
||||
additionalContextProviders: IContextProvider[],
|
||||
): Promise<ContinueConfig> {
|
||||
// If we already have a config, return it
|
||||
if (this.savedConfig) {
|
||||
return this.savedConfig;
|
||||
} else if (this.pendingConfigPromise) {
|
||||
return this.pendingConfigPromise;
|
||||
}
|
||||
|
||||
// Set pending config promise
|
||||
this.pendingConfigPromise = new Promise(async (resolve, reject) => {
|
||||
const newConfig = await this.profileLoader.doLoadConfig();
|
||||
|
||||
// Add registered context providers
|
||||
newConfig.contextProviders = (newConfig.contextProviders ?? []).concat(
|
||||
additionalContextProviders,
|
||||
);
|
||||
|
||||
this.savedConfig = newConfig;
|
||||
resolve(newConfig);
|
||||
});
|
||||
|
||||
// Wait for the config promise to resolve
|
||||
this.savedConfig = await this.pendingConfigPromise;
|
||||
this.pendingConfigPromise = undefined;
|
||||
return this.savedConfig;
|
||||
}
|
||||
|
||||
async getSerializedConfig(
|
||||
additionalContextProviders: IContextProvider[],
|
||||
): Promise<BrowserSerializedContinueConfig> {
|
||||
if (!this.savedBrowserConfig) {
|
||||
const continueConfig = await this.loadConfig(additionalContextProviders);
|
||||
this.savedBrowserConfig = finalToBrowserConfig(continueConfig);
|
||||
}
|
||||
return this.savedBrowserConfig;
|
||||
}
|
||||
}
|
||||
|
||||
export class ConfigHandler {
|
||||
private readonly globalContext = new GlobalContext();
|
||||
|
|
@ -202,7 +129,11 @@ export class ConfigHandler {
|
|||
async setSelectedProfile(profileId: string) {
|
||||
this.selectedProfileId = profileId;
|
||||
const newConfig = await this.loadConfig();
|
||||
this.notifyConfigListeners(newConfig);
|
||||
this.notifyConfigListeners({
|
||||
config: newConfig,
|
||||
errors: undefined,
|
||||
configLoadInterrupted: false,
|
||||
});
|
||||
const selectedProfiles =
|
||||
this.globalContext.get("lastSelectedProfileForWorkspace") ?? {};
|
||||
selectedProfiles[await this.getWorkspaceId()] = profileId;
|
||||
|
|
@ -248,24 +179,31 @@ export class ConfigHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private notifyConfigListeners(newConfig: ContinueConfig) {
|
||||
private notifyConfigListeners(result: ConfigResult<ContinueConfig>) {
|
||||
// Notify listeners that config changed
|
||||
for (const listener of this.updateListeners) {
|
||||
listener(newConfig);
|
||||
listener(result);
|
||||
}
|
||||
}
|
||||
|
||||
private updateListeners: ((newConfig: ContinueConfig) => void)[] = [];
|
||||
onConfigUpdate(listener: (newConfig: ContinueConfig) => void) {
|
||||
private updateListeners: ConfigUpdateFunction[] = [];
|
||||
|
||||
onConfigUpdate(listener: ConfigUpdateFunction) {
|
||||
this.updateListeners.push(listener);
|
||||
}
|
||||
|
||||
async reloadConfig() {
|
||||
// TODO: this isn't right, there are two different senses in which you want to "reload"
|
||||
const newConfig = await this.currentProfile.reloadConfig();
|
||||
this.inactiveProfiles.forEach((profile) => profile.clearConfig());
|
||||
this.notifyConfigListeners(newConfig);
|
||||
return newConfig;
|
||||
|
||||
const { config, errors, configLoadInterrupted } =
|
||||
await this.currentProfile.reloadConfig();
|
||||
|
||||
if (config) {
|
||||
this.inactiveProfiles.forEach((profile) => profile.clearConfig());
|
||||
}
|
||||
|
||||
this.notifyConfigListeners({ config, errors, configLoadInterrupted });
|
||||
return { config, errors };
|
||||
}
|
||||
|
||||
getSerializedConfig(): Promise<BrowserSerializedContinueConfig> {
|
||||
|
|
|
|||
99
core/config/ProfileLifecycleManager.ts
Normal file
99
core/config/ProfileLifecycleManager.ts
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
import { config } from "dotenv";
|
||||
import {
|
||||
BrowserSerializedContinueConfig,
|
||||
ContinueConfig,
|
||||
IContextProvider,
|
||||
} from "../index.js";
|
||||
|
||||
import { ConfigResult, finalToBrowserConfig } from "./load.js";
|
||||
|
||||
import { IProfileLoader } from "./profile/IProfileLoader.js";
|
||||
|
||||
export interface ProfileDescription {
|
||||
title: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export class ProfileLifecycleManager {
|
||||
private savedConfig: ContinueConfig | undefined;
|
||||
private savedBrowserConfig?: BrowserSerializedContinueConfig;
|
||||
private pendingConfigPromise?: Promise<ContinueConfig>;
|
||||
|
||||
constructor(private readonly profileLoader: IProfileLoader) {}
|
||||
|
||||
get profileId() {
|
||||
return this.profileLoader.profileId;
|
||||
}
|
||||
|
||||
get profileTitle() {
|
||||
return this.profileLoader.profileTitle;
|
||||
}
|
||||
|
||||
get profileDescription(): ProfileDescription {
|
||||
return {
|
||||
title: this.profileTitle,
|
||||
id: this.profileId,
|
||||
};
|
||||
}
|
||||
|
||||
clearConfig() {
|
||||
this.savedConfig = undefined;
|
||||
this.savedBrowserConfig = undefined;
|
||||
this.pendingConfigPromise = undefined;
|
||||
}
|
||||
|
||||
// Clear saved config and reload
|
||||
async reloadConfig(): Promise<ConfigResult<ContinueConfig>> {
|
||||
this.savedConfig = undefined;
|
||||
this.savedBrowserConfig = undefined;
|
||||
this.pendingConfigPromise = undefined;
|
||||
|
||||
return this.profileLoader.doLoadConfig();
|
||||
}
|
||||
|
||||
async loadConfig(
|
||||
additionalContextProviders: IContextProvider[],
|
||||
): Promise<ContinueConfig> {
|
||||
// If we already have a config, return it
|
||||
if (this.savedConfig) {
|
||||
return this.savedConfig;
|
||||
} else if (this.pendingConfigPromise) {
|
||||
return this.pendingConfigPromise;
|
||||
}
|
||||
|
||||
// Set pending config promise
|
||||
this.pendingConfigPromise = new Promise(async (resolve, reject) => {
|
||||
const { config: newConfig, errors } =
|
||||
await this.profileLoader.doLoadConfig();
|
||||
|
||||
if (newConfig) {
|
||||
// Add registered context providers
|
||||
newConfig.contextProviders = (newConfig.contextProviders ?? []).concat(
|
||||
additionalContextProviders,
|
||||
);
|
||||
|
||||
this.savedConfig = newConfig;
|
||||
resolve(newConfig);
|
||||
} else if (errors) {
|
||||
reject(
|
||||
`Error in config.json: ${errors.map((item) => item.message).join(" | ")}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for the config promise to resolve
|
||||
this.savedConfig = await this.pendingConfigPromise;
|
||||
this.pendingConfigPromise = undefined;
|
||||
return this.savedConfig;
|
||||
}
|
||||
|
||||
async getSerializedConfig(
|
||||
additionalContextProviders: IContextProvider[],
|
||||
): Promise<BrowserSerializedContinueConfig> {
|
||||
if (!this.savedBrowserConfig) {
|
||||
const continueConfig = await this.loadConfig(additionalContextProviders);
|
||||
this.savedBrowserConfig = finalToBrowserConfig(continueConfig);
|
||||
}
|
||||
return this.savedBrowserConfig;
|
||||
}
|
||||
}
|
||||
|
|
@ -64,9 +64,16 @@ import {
|
|||
DEFAULT_PROMPTS_FOLDER,
|
||||
getPromptFiles,
|
||||
slashCommandFromPromptFile,
|
||||
} from "./promptFile";
|
||||
} from "./promptFile.js";
|
||||
import { validateConfig, ConfigValidationError } from "./validation.js";
|
||||
|
||||
import { GlobalContext } from "../util/GlobalContext";
|
||||
import { Readable } from "stream";
|
||||
|
||||
export interface ConfigResult<T> {
|
||||
config: T | undefined;
|
||||
errors: ConfigValidationError[] | undefined;
|
||||
configLoadInterrupted: boolean;
|
||||
}
|
||||
|
||||
function resolveSerializedConfig(filepath: string): SerializedContinueConfig {
|
||||
let content = fs.readFileSync(filepath, "utf8");
|
||||
|
|
@ -102,7 +109,7 @@ function loadSerializedConfig(
|
|||
ideSettings: IdeSettings,
|
||||
ideType: IdeType,
|
||||
overrideConfigJson: SerializedContinueConfig | undefined,
|
||||
): SerializedContinueConfig {
|
||||
): ConfigResult<SerializedContinueConfig> {
|
||||
const configPath = getConfigJsonPath(ideType);
|
||||
let config: SerializedContinueConfig = overrideConfigJson!;
|
||||
if (!config) {
|
||||
|
|
@ -113,6 +120,16 @@ function loadSerializedConfig(
|
|||
}
|
||||
}
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
if (errors?.some((error) => error.fatal)) {
|
||||
return {
|
||||
errors,
|
||||
config: undefined,
|
||||
configLoadInterrupted: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (config.allowAnonymousTelemetry === undefined) {
|
||||
config.allowAnonymousTelemetry = true;
|
||||
}
|
||||
|
|
@ -147,7 +164,7 @@ function loadSerializedConfig(
|
|||
? [...defaultSlashCommandsVscode]
|
||||
: [...defaultSlashCommandsJetBrains];
|
||||
|
||||
return config;
|
||||
return { config, errors, configLoadInterrupted: false };
|
||||
}
|
||||
|
||||
async function serializedToIntermediateConfig(
|
||||
|
|
@ -686,15 +703,23 @@ async function loadFullConfigNode(
|
|||
writeLog: (log: string) => Promise<void>,
|
||||
workOsAccessToken: string | undefined,
|
||||
overrideConfigJson: SerializedContinueConfig | undefined,
|
||||
): Promise<ContinueConfig> {
|
||||
): Promise<ConfigResult<ContinueConfig>> {
|
||||
// Serialized config
|
||||
let serialized = loadSerializedConfig(
|
||||
let {
|
||||
config: serialized,
|
||||
errors,
|
||||
configLoadInterrupted,
|
||||
} = loadSerializedConfig(
|
||||
workspaceConfigs,
|
||||
ideSettings,
|
||||
ideType,
|
||||
overrideConfigJson,
|
||||
);
|
||||
|
||||
if (!serialized || configLoadInterrupted) {
|
||||
return { errors, config: undefined, configLoadInterrupted: true };
|
||||
}
|
||||
|
||||
// Convert serialized to intermediate config
|
||||
let intermediate = await serializedToIntermediateConfig(serialized, ide);
|
||||
|
||||
|
|
@ -762,7 +787,7 @@ async function loadFullConfigNode(
|
|||
writeLog,
|
||||
workOsAccessToken,
|
||||
);
|
||||
return finalConfig;
|
||||
return { config: finalConfig, errors, configLoadInterrupted: false };
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {
|
|||
} from "../../index.js";
|
||||
import { IProfileLoader } from "./IProfileLoader.js";
|
||||
import doLoadConfig from "./doLoadConfig.js";
|
||||
import { ConfigResult } from "../load.js";
|
||||
|
||||
export default class ControlPlaneProfileLoader implements IProfileLoader {
|
||||
private static RELOAD_INTERVAL = 1000 * 60 * 15; // every 15 minutes
|
||||
|
|
@ -36,7 +37,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader {
|
|||
}, ControlPlaneProfileLoader.RELOAD_INTERVAL);
|
||||
}
|
||||
|
||||
async doLoadConfig(): Promise<ContinueConfig> {
|
||||
async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
|
||||
const settings =
|
||||
this.workspaceSettings ??
|
||||
((await this.controlPlaneClient.getSettingsForWorkspace(
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
// ProfileHandlers manage the loading of a config, allowing us to abstract over different ways of getting to a ContinueConfig
|
||||
|
||||
import { ContinueConfig } from "../../index.js";
|
||||
import { ConfigResult } from "../load.js";
|
||||
|
||||
// After we have the ContinueConfig, the ConfigHandler takes care of everything else (loading models, lifecycle, etc.)
|
||||
export interface IProfileLoader {
|
||||
profileTitle: string;
|
||||
profileId: string;
|
||||
doLoadConfig(): Promise<ContinueConfig>;
|
||||
doLoadConfig(): Promise<ConfigResult<ContinueConfig>>;
|
||||
setIsActive(isActive: boolean): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { ControlPlaneClient } from "../../control-plane/client.js";
|
||||
import { ContinueConfig, IDE, IdeSettings } from "../../index.js";
|
||||
import { ConfigResult } from "../load.js";
|
||||
import doLoadConfig from "./doLoadConfig.js";
|
||||
import { IProfileLoader } from "./IProfileLoader.js";
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ export default class LocalProfileLoader implements IProfileLoader {
|
|||
private writeLog: (message: string) => Promise<void>,
|
||||
) {}
|
||||
|
||||
async doLoadConfig(): Promise<ContinueConfig> {
|
||||
async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
|
||||
return doLoadConfig(
|
||||
this.ide,
|
||||
this.ideSettingsPromise,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import ContinueProxyEmbeddingsProvider from "../../indexing/embeddings/ContinueP
|
|||
import ContinueProxy from "../../llm/llms/stubs/ContinueProxy.js";
|
||||
import { Telemetry } from "../../util/posthog.js";
|
||||
import { TTS } from "../../util/tts.js";
|
||||
import { loadFullConfigNode } from "../load.js";
|
||||
import { ConfigResult, loadFullConfigNode } from "../load.js";
|
||||
|
||||
export default async function doLoadConfig(
|
||||
ide: IDE,
|
||||
|
|
@ -25,7 +25,7 @@ export default async function doLoadConfig(
|
|||
writeLog: (message: string) => Promise<void>,
|
||||
overrideConfigJson: SerializedContinueConfig | undefined,
|
||||
workspaceId?: string,
|
||||
) {
|
||||
): Promise<ConfigResult<ContinueConfig>> {
|
||||
let workspaceConfigs: ContinueRcJson[] = [];
|
||||
try {
|
||||
workspaceConfigs = await ide.getWorkspaceConfigs();
|
||||
|
|
@ -38,7 +38,11 @@ export default async function doLoadConfig(
|
|||
const ideSettings = await ideSettingsPromise;
|
||||
const workOsAccessToken = await controlPlaneClient.getAccessToken();
|
||||
|
||||
let newConfig = await loadFullConfigNode(
|
||||
let {
|
||||
config: newConfig,
|
||||
errors,
|
||||
configLoadInterrupted,
|
||||
} = await loadFullConfigNode(
|
||||
ide,
|
||||
workspaceConfigs,
|
||||
ideSettings,
|
||||
|
|
@ -48,6 +52,11 @@ export default async function doLoadConfig(
|
|||
workOsAccessToken,
|
||||
overrideConfigJson,
|
||||
);
|
||||
|
||||
if (configLoadInterrupted || !newConfig) {
|
||||
return { errors, config: newConfig, configLoadInterrupted: true };
|
||||
}
|
||||
|
||||
newConfig.allowAnonymousTelemetry =
|
||||
newConfig.allowAnonymousTelemetry && (await ide.isTelemetryEnabled());
|
||||
|
||||
|
|
@ -89,7 +98,7 @@ export default async function doLoadConfig(
|
|||
controlPlaneProxyInfo,
|
||||
);
|
||||
|
||||
return newConfig;
|
||||
return { config: newConfig, errors, configLoadInterrupted: false };
|
||||
}
|
||||
|
||||
// Pass ControlPlaneProxyInfo to objects that need it
|
||||
|
|
|
|||
120
core/config/validation.ts
Normal file
120
core/config/validation.ts
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
import { SerializedContinueConfig } from "../";
|
||||
|
||||
export interface ConfigValidationError {
|
||||
fatal: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a SerializedContinueConfig object to ensure all properties are correctly formed.
|
||||
* @param config The configuration object to validate.
|
||||
* @returns An array of error messages if there are any. Otherwise, the config is valid.
|
||||
*/
|
||||
export function validateConfig(config: SerializedContinueConfig) {
|
||||
const errors: ConfigValidationError[] = [];
|
||||
|
||||
// Validate models
|
||||
if (!Array.isArray(config.models) || config.models.length === 0) {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: "The 'models' field should be a non-empty array.",
|
||||
});
|
||||
} else {
|
||||
config.models.forEach((model, index) => {
|
||||
if (typeof model.title !== "string" || model.title.trim() === "") {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: `Model at index ${index} has an invalid or missing 'title'.`,
|
||||
});
|
||||
}
|
||||
if (typeof model.provider !== "string") {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: `Model at index ${index} has an invalid 'provider'.`,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Validate slashCommands
|
||||
if (config.slashCommands) {
|
||||
if (!Array.isArray(config.slashCommands)) {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: "The 'slashCommands' field should be an array if defined.",
|
||||
});
|
||||
} else {
|
||||
config.slashCommands.forEach((command, index) => {
|
||||
if (typeof command.name !== "string" || command.name.trim() === "") {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: `Slash command at index ${index} has an invalid or missing 'name'.`,
|
||||
});
|
||||
}
|
||||
if (typeof command.description !== "string") {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: `Slash command at index ${index} has an invalid or missing 'description'.`,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Validate contextProviders
|
||||
if (config.contextProviders) {
|
||||
if (!Array.isArray(config.contextProviders)) {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: "The 'contextProviders' field should be an array if defined.",
|
||||
});
|
||||
} else {
|
||||
config.contextProviders.forEach((provider, index) => {
|
||||
if (typeof provider.name !== "string" || provider.name.trim() === "") {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: `Context provider at index ${index} has an invalid or missing 'name'.`,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Validate embeddingsProvider
|
||||
if (
|
||||
config.embeddingsProvider &&
|
||||
typeof config.embeddingsProvider !== "object"
|
||||
) {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: "The 'embeddingsProvider' field should be an object if defined.",
|
||||
});
|
||||
}
|
||||
|
||||
// Validate reranker
|
||||
if (config.reranker && typeof config.reranker !== "object") {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: "The 'reranker' field should be an object if defined.",
|
||||
});
|
||||
}
|
||||
|
||||
// Validate other boolean flags
|
||||
const booleanFlags: Array<
|
||||
keyof Pick<
|
||||
SerializedContinueConfig,
|
||||
"allowAnonymousTelemetry" | "disableIndexing" | "disableSessionTitles"
|
||||
>
|
||||
> = ["allowAnonymousTelemetry", "disableIndexing", "disableSessionTitles"];
|
||||
|
||||
booleanFlags.forEach((flag) => {
|
||||
if (config[flag] !== undefined && typeof config[flag] !== "boolean") {
|
||||
errors.push({
|
||||
fatal: true,
|
||||
message: `The '${flag}' field should be a boolean if defined.`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return errors.length > 0 ? errors : undefined;
|
||||
}
|
||||
|
|
@ -420,25 +420,28 @@ export default class DocsService {
|
|||
|
||||
this.globalContext.update("curEmbeddingsProviderId", embeddingsProvider.id);
|
||||
|
||||
configHandler.onConfigUpdate(async (newConfig) => {
|
||||
const oldConfig = this.config;
|
||||
configHandler.onConfigUpdate(async ({ config: newConfig }) => {
|
||||
if (newConfig) {
|
||||
const oldConfig = this.config;
|
||||
|
||||
// Need to update class property for config at the beginning of this callback
|
||||
// to ensure downstream methods have access to the latest config.
|
||||
this.config = newConfig;
|
||||
// Need to update class property for config at the beginning of this callback
|
||||
// to ensure downstream methods have access to the latest config.
|
||||
this.config = newConfig;
|
||||
|
||||
if (oldConfig.docs !== newConfig.docs) {
|
||||
await this.syncConfigAndSqlite();
|
||||
}
|
||||
if (oldConfig.docs !== newConfig.docs) {
|
||||
await this.syncConfigAndSqlite();
|
||||
}
|
||||
|
||||
const shouldReindex = await this.shouldReindexDocsOnNewEmbeddingsProvider(
|
||||
newConfig.embeddingsProvider.id,
|
||||
);
|
||||
const shouldReindex =
|
||||
await this.shouldReindexDocsOnNewEmbeddingsProvider(
|
||||
newConfig.embeddingsProvider.id,
|
||||
);
|
||||
|
||||
if (shouldReindex) {
|
||||
await this.reindexDocsOnNewEmbeddingsProvider(
|
||||
newConfig.embeddingsProvider,
|
||||
);
|
||||
if (shouldReindex) {
|
||||
await this.reindexDocsOnNewEmbeddingsProvider(
|
||||
newConfig.embeddingsProvider,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
"description": "The Continue Core contains functionality that can be shared across web, VS Code, or Node.js",
|
||||
"scripts": {
|
||||
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --runInBand",
|
||||
"tsc:check": "tsc -p ./ --noEmit",
|
||||
"build:npm": "tsc -p ./tsconfig.npm.json",
|
||||
"lint": "eslint . --ext ts",
|
||||
"lint:fix": "eslint . --ext ts --fix"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import { ConfigValidationError } from "../config/validation.js";
|
||||
import type { ContextItemWithId, IndexingProgressUpdate } from "../index.js";
|
||||
|
||||
export type ToWebviewFromIdeOrCoreProtocol = {
|
||||
configUpdate: [undefined, void];
|
||||
configError: [ConfigValidationError[] | undefined, void];
|
||||
getDefaultModelTitle: [undefined, string];
|
||||
indexProgress: [IndexingProgressUpdate, void];
|
||||
refreshSubmenuItems: [undefined, void];
|
||||
|
|
|
|||
|
|
@ -520,6 +520,7 @@
|
|||
"esbuild": "npm run esbuild-base -- --sourcemap",
|
||||
"esbuild-watch": "npm run esbuild-base -- --sourcemap --watch",
|
||||
"tsc": "tsc -p ./",
|
||||
"tsc:check": "tsc -p ./ --noEmit",
|
||||
"tsc-watch": "tsc -watch -p ./",
|
||||
"rebuild": "electron-rebuild -v 19.1.8 node-pty",
|
||||
"lint": "eslint src --ext ts",
|
||||
|
|
|
|||
|
|
@ -40,9 +40,20 @@ export const getStatusBarStatusFromQuickPickItemLabel = (
|
|||
}
|
||||
};
|
||||
|
||||
const statusBarItemText = (status: StatusBarStatus | undefined) => {
|
||||
const statusBarItemText = (
|
||||
status: StatusBarStatus | undefined,
|
||||
loading?: boolean,
|
||||
error?: boolean,
|
||||
) => {
|
||||
if (error) {
|
||||
return "$(alert) Continue (FATAL ERROR)";
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case undefined:
|
||||
if (loading) {
|
||||
return "$(loading~spin) Continue";
|
||||
}
|
||||
case StatusBarStatus.Disabled:
|
||||
return "$(circle-slash) Continue";
|
||||
case StatusBarStatus.Enabled:
|
||||
|
|
@ -67,6 +78,7 @@ const statusBarItemTooltip = (status: StatusBarStatus | undefined) => {
|
|||
let statusBarStatus: StatusBarStatus | undefined = undefined;
|
||||
let statusBarItem: vscode.StatusBarItem | undefined = undefined;
|
||||
let statusBarFalseTimeout: NodeJS.Timeout | undefined = undefined;
|
||||
let statusBarError: boolean = false;
|
||||
|
||||
export function stopStatusBarLoading() {
|
||||
statusBarFalseTimeout = setTimeout(() => {
|
||||
|
|
@ -74,9 +86,15 @@ export function stopStatusBarLoading() {
|
|||
}, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: We should clean up how status bar is handled.
|
||||
* Ideally, there should be a single 'status' value without
|
||||
* 'loading' and 'error' booleans.
|
||||
*/
|
||||
export function setupStatusBar(
|
||||
status: StatusBarStatus | undefined,
|
||||
loading?: boolean,
|
||||
error?: boolean,
|
||||
) {
|
||||
if (loading !== false) {
|
||||
clearTimeout(statusBarFalseTimeout);
|
||||
|
|
@ -90,9 +108,19 @@ export function setupStatusBar(
|
|||
);
|
||||
}
|
||||
|
||||
statusBarItem.text = loading
|
||||
? "$(loading~spin) Continue"
|
||||
: statusBarItemText(status);
|
||||
if (error !== undefined) {
|
||||
statusBarError = error;
|
||||
|
||||
if (status === undefined) {
|
||||
status = statusBarStatus;
|
||||
}
|
||||
|
||||
if (loading === undefined) {
|
||||
loading = loading;
|
||||
}
|
||||
}
|
||||
|
||||
statusBarItem.text = statusBarItemText(status, loading, statusBarError);
|
||||
statusBarItem.tooltip = statusBarItemTooltip(status ?? statusBarStatus);
|
||||
statusBarItem.command = "continue.openTabAutocompleteConfigMenu";
|
||||
|
||||
|
|
|
|||
|
|
@ -151,18 +151,29 @@ export class VsCodeExtension {
|
|||
verticalDiffCodeLens.refresh.bind(verticalDiffCodeLens);
|
||||
});
|
||||
|
||||
this.configHandler.onConfigUpdate((newConfig) => {
|
||||
this.sidebar.webviewProtocol?.request("configUpdate", undefined);
|
||||
this.configHandler.onConfigUpdate(
|
||||
({ config: newConfig, errors, configLoadInterrupted }) => {
|
||||
if (configLoadInterrupted) {
|
||||
// Show error in status bar
|
||||
setupStatusBar(undefined, undefined, true);
|
||||
} else if (newConfig) {
|
||||
setupStatusBar(undefined, undefined, false);
|
||||
|
||||
this.tabAutocompleteModel.clearLlm();
|
||||
this.sidebar.webviewProtocol?.request("configUpdate", undefined);
|
||||
|
||||
registerAllCodeLensProviders(
|
||||
context,
|
||||
this.diffManager,
|
||||
this.verticalDiffManager.filepathToCodeLens,
|
||||
newConfig,
|
||||
);
|
||||
});
|
||||
this.tabAutocompleteModel.clearLlm();
|
||||
|
||||
registerAllCodeLensProviders(
|
||||
context,
|
||||
this.diffManager,
|
||||
this.verticalDiffManager.filepathToCodeLens,
|
||||
newConfig,
|
||||
);
|
||||
}
|
||||
|
||||
this.sidebar.webviewProtocol?.request("configError", errors);
|
||||
},
|
||||
);
|
||||
|
||||
// Tab autocomplete
|
||||
const config = vscode.workspace.getConfiguration(EXTENSION_NAME);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"tsc:check": "tsc -p ./ --noEmit",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview",
|
||||
"test": "vitest run",
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import MonacoPage from "./pages/monaco";
|
|||
import MorePage from "./pages/More";
|
||||
import SettingsPage from "./pages/settings";
|
||||
import Stats from "./pages/stats";
|
||||
import { ROUTES } from "./util/navigation";
|
||||
import ConfigErrorPage from "./pages/config-error";
|
||||
|
||||
const router = createMemoryRouter([
|
||||
{
|
||||
|
|
@ -54,6 +56,10 @@ const router = createMemoryRouter([
|
|||
path: "/more",
|
||||
element: <MorePage />,
|
||||
},
|
||||
{
|
||||
path: ROUTES.CONFIG_ERROR,
|
||||
element: <ConfigErrorPage />,
|
||||
},
|
||||
{
|
||||
path: "/monaco",
|
||||
element: <MonacoPage />,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import {
|
||||
Cog6ToothIcon,
|
||||
EllipsisHorizontalCircleIcon,
|
||||
ExclamationTriangleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useContext } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useLocation, useNavigate, useResolvedPath } from "react-router-dom";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
import { RootState } from "../redux/store";
|
||||
|
|
@ -12,21 +13,26 @@ import { FREE_TRIAL_LIMIT_REQUESTS } from "../util/freeTrial";
|
|||
import ButtonWithTooltip from "./ButtonWithTooltip";
|
||||
import FreeTrialProgressBar from "./loaders/FreeTrialProgressBar";
|
||||
import ProfileSwitcher from "./ProfileSwitcher";
|
||||
import { ROUTES } from "../util/navigation";
|
||||
|
||||
function Footer() {
|
||||
const navigate = useNavigate();
|
||||
const { pathname } = useLocation();
|
||||
const defaultModel = useSelector(defaultModelSelector);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const selectedProfileId = useSelector(
|
||||
(store: RootState) => store.state.selectedProfileId,
|
||||
);
|
||||
const configError = useSelector(
|
||||
(store: RootState) => store.state.configError,
|
||||
);
|
||||
|
||||
function onClickMore() {
|
||||
if (location.pathname === "/more") {
|
||||
navigate("/");
|
||||
} else {
|
||||
navigate("/more");
|
||||
}
|
||||
navigate(pathname === ROUTES.MORE ? "/" : ROUTES.MORE);
|
||||
}
|
||||
|
||||
function onClickError() {
|
||||
navigate(pathname === ROUTES.CONFIG_ERROR ? "/" : ROUTES.CONFIG_ERROR);
|
||||
}
|
||||
|
||||
function onClickSettings() {
|
||||
|
|
@ -53,6 +59,16 @@ function Footer() {
|
|||
</div>
|
||||
|
||||
<div className="flex gap-1">
|
||||
{configError && (
|
||||
<ButtonWithTooltip
|
||||
tooltipPlacement="top-end"
|
||||
text="Config error"
|
||||
onClick={onClickError}
|
||||
>
|
||||
<ExclamationTriangleIcon className="w-4 h-4" />
|
||||
</ButtonWithTooltip>
|
||||
)}
|
||||
|
||||
<ButtonWithTooltip
|
||||
tooltipPlacement="top-end"
|
||||
text="More"
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
import { useContext, useEffect } from "react";
|
||||
import { useContext, useEffect, useMemo } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { CustomScrollbarDiv, defaultBorderRadius, vscInputBackground } from ".";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { LastSessionProvider } from "../context/LastSessionContext";
|
||||
import { useWebviewListener } from "../hooks/useWebviewListener";
|
||||
import { useConfigError } from "../redux/hooks";
|
||||
import { setShowDialog, updateApplyState } from "../redux/slices/uiStateSlice";
|
||||
import { RootState } from "../redux/store";
|
||||
import { getFontSize, isMetaEquivalentKeyPressed } from "../util";
|
||||
import { getLocalStorage, setLocalStorage } from "../util/localStorage";
|
||||
import PostHogPageView from "./PosthogPageView";
|
||||
import Footer from "./Footer";
|
||||
import { updateApplyState, setShowDialog } from "../redux/slices/uiStateSlice";
|
||||
import { ROUTES } from "../util/navigation";
|
||||
import TextDialog from "./dialogs";
|
||||
import { useOnboardingCard, isNewUserOnboarding } from "./OnboardingCard";
|
||||
import { LastSessionProvider } from "../context/LastSessionContext";
|
||||
import Footer from "./Footer";
|
||||
import { isNewUserOnboarding, useOnboardingCard } from "./OnboardingCard";
|
||||
import PostHogPageView from "./PosthogPageView";
|
||||
|
||||
const LayoutTopDiv = styled(CustomScrollbarDiv)`
|
||||
height: 100%;
|
||||
|
|
@ -61,6 +63,13 @@ const Layout = () => {
|
|||
const dispatch = useDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const onboardingCard = useOnboardingCard();
|
||||
const { pathname } = useLocation();
|
||||
|
||||
const configError = useConfigError();
|
||||
|
||||
const hasFatalErrors = useMemo(() => {
|
||||
return configError?.some((error) => error.fatal);
|
||||
}, [configError]);
|
||||
|
||||
const dialogMessage = useSelector(
|
||||
(state: RootState) => state.uiState.dialogMessage,
|
||||
|
|
@ -200,6 +209,20 @@ const Layout = () => {
|
|||
<PostHogPageView />
|
||||
<Outlet />
|
||||
|
||||
{hasFatalErrors && pathname !== ROUTES.CONFIG_ERROR && (
|
||||
<div
|
||||
className="z-50 cursor-pointer bg-red-600 p-4 text-center text-white"
|
||||
role="alert"
|
||||
onClick={() => navigate(ROUTES.CONFIG_ERROR)}
|
||||
>
|
||||
<strong className="font-bold">Error!</strong>{" "}
|
||||
<span className="block sm:inline">
|
||||
Could not load config.json
|
||||
</span>
|
||||
<div className="mt-2 underline">Learn More</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ModelDropdownPortalDiv id="model-select-top-div"></ModelDropdownPortalDiv>
|
||||
<ProfileDropdownPortalDiv id="profile-select-top-div"></ProfileDropdownPortalDiv>
|
||||
<Footer />
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ import { setVscMachineId } from "../redux/slices/configSlice";
|
|||
import {
|
||||
addContextItemsAtIndex,
|
||||
setConfig,
|
||||
setConfigError,
|
||||
setInactive,
|
||||
setSelectedProfileId,
|
||||
setTTSActive
|
||||
setTTSActive,
|
||||
} from "../redux/slices/stateSlice";
|
||||
import { RootState } from "../redux/store";
|
||||
|
||||
|
|
@ -113,6 +114,10 @@ function useSetup(dispatch: Dispatch<any>) {
|
|||
}
|
||||
});
|
||||
|
||||
useWebviewListener("configError", async (error) => {
|
||||
dispatch(setConfigError(error));
|
||||
});
|
||||
|
||||
useWebviewListener("submitMessage", async (data) => {
|
||||
streamResponse(
|
||||
data.message,
|
||||
|
|
|
|||
74
gui/src/pages/config-error/index.tsx
Normal file
74
gui/src/pages/config-error/index.tsx
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import {
|
||||
ArrowLeftIcon,
|
||||
ExclamationCircleIcon,
|
||||
ExclamationTriangleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { vscBackground } from "../../components";
|
||||
import { ROUTES } from "../../util/navigation";
|
||||
import { useConfigError } from "../../redux/hooks";
|
||||
|
||||
export default function ConfigErrorPage() {
|
||||
const navigate = useNavigate();
|
||||
const configError = useConfigError();
|
||||
|
||||
const sortedErrors = configError
|
||||
? [...configError].sort((a, b) => (b.fatal ? 1 : 0) - (a.fatal ? 1 : 0))
|
||||
: [];
|
||||
|
||||
return (
|
||||
<div className="overflow-y-scroll">
|
||||
<div
|
||||
onClick={() => navigate(ROUTES.HOME)}
|
||||
className="items-center flex m-0 p-0 sticky top-0 cursor-pointer border-0 border-b border-solid border-b-zinc-700 bg-inherit"
|
||||
style={{
|
||||
backgroundColor: vscBackground,
|
||||
}}
|
||||
>
|
||||
<ArrowLeftIcon className="inline-block ml-3 cursor-pointer w-3 h-3" />
|
||||
<span className="text-sm font-bold m-2 inline-block">Chat</span>
|
||||
</div>
|
||||
|
||||
<div className="px-4 divide-y-2 divide-zinc-700 divide-solid divide-x-0 gap-2">
|
||||
<div className="py-5">
|
||||
<h3 className="text-xl mb-2 mt-0">Config Errors</h3>
|
||||
<p className="mb-4 text-md">
|
||||
Please resolve the following errors in your config.json file.
|
||||
</p>
|
||||
<div className="flex flex-col gap-5">
|
||||
{sortedErrors.length > 0 ? (
|
||||
<ul className="list-none space-y-4 p-0 m-0">
|
||||
{sortedErrors.map((error, index) => (
|
||||
<li
|
||||
key={index}
|
||||
className={`text-sm p-2 rounded-md shadow-md flex items-start ${
|
||||
error.fatal
|
||||
? "text-red-800 bg-red-100"
|
||||
: "text-yellow-800 bg-yellow-100"
|
||||
}`}
|
||||
>
|
||||
{error.fatal ? (
|
||||
<ExclamationCircleIcon className="w-5 h-5 mr-2" />
|
||||
) : (
|
||||
<ExclamationTriangleIcon className="w-5 h-5 mr-2" />
|
||||
)}
|
||||
<p className="m-0">
|
||||
<strong>
|
||||
{error.fatal ? "Fatal Error:" : "Warning:"}
|
||||
</strong>{" "}
|
||||
{error.message}
|
||||
</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p className="text-sm text-green-700 bg-green-100 p-4 rounded-md">
|
||||
No configuration errors found.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
5
gui/src/redux/hooks.ts
Normal file
5
gui/src/redux/hooks.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { useSelector } from "react-redux";
|
||||
import { RootState } from "./store";
|
||||
|
||||
export const useConfigError = () =>
|
||||
useSelector((store: RootState) => store.state.configError);
|
||||
|
|
@ -15,6 +15,7 @@ import { createSelector } from "reselect";
|
|||
import { v4 } from "uuid";
|
||||
import { RootState } from "../store";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { ConfigValidationError } from "core/config/validation";
|
||||
|
||||
export const memoizedContextItemsSelector = createSelector(
|
||||
[(state: RootState) => state.state.history],
|
||||
|
|
@ -44,6 +45,7 @@ type State = {
|
|||
defaultModelTitle: string;
|
||||
mainEditorContent?: JSONContent;
|
||||
selectedProfileId: string;
|
||||
configError: ConfigValidationError[] | undefined;
|
||||
};
|
||||
|
||||
const initialState: State = {
|
||||
|
|
@ -52,6 +54,7 @@ const initialState: State = {
|
|||
ttsActive: false,
|
||||
active: false,
|
||||
isGatheringContext: false,
|
||||
configError: undefined,
|
||||
config: {
|
||||
slashCommands: [
|
||||
{
|
||||
|
|
@ -96,6 +99,12 @@ export const stateSlice = createSlice({
|
|||
state.config = config;
|
||||
state.defaultModelTitle = defaultModelTitle;
|
||||
},
|
||||
setConfigError: (
|
||||
state,
|
||||
{ payload: error }: PayloadAction<ConfigValidationError[] | undefined>,
|
||||
) => {
|
||||
state.configError = error;
|
||||
},
|
||||
addPromptCompletionPair: (
|
||||
state,
|
||||
{ payload }: PayloadAction<PromptLog[]>,
|
||||
|
|
@ -449,6 +458,7 @@ export const {
|
|||
setEditingAtIds,
|
||||
setDefaultModel,
|
||||
setConfig,
|
||||
setConfigError,
|
||||
addPromptCompletionPair,
|
||||
setTTSActive,
|
||||
setActive,
|
||||
|
|
@ -459,7 +469,7 @@ export const {
|
|||
consumeMainEditorContent,
|
||||
setSelectedProfileId,
|
||||
deleteMessage,
|
||||
setIsGatheringContext
|
||||
setIsGatheringContext,
|
||||
} = stateSlice.actions;
|
||||
|
||||
export default stateSlice.reducer;
|
||||
|
|
|
|||
7
gui/src/util/navigation.ts
Normal file
7
gui/src/util/navigation.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// TODO: Move all the routes here
|
||||
export const ROUTES = {
|
||||
HOME: "/",
|
||||
CONFIG_ERROR: "/config-error",
|
||||
MORE: "/more",
|
||||
// EXAMPLE_ROUTE_WITH_PARAMS: (params: ParamsType) => `/route/${params}`,
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue