feat: config.json validation
This commit is contained in:
parent
e99b2c7c75
commit
429e54ed34
19 changed files with 450 additions and 128 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -164,7 +164,7 @@ 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,27 @@ import {
|
|||
} from "../index.js";
|
||||
import Ollama from "../llm/llms/Ollama.js";
|
||||
import { GlobalContext } from "../util/GlobalContext.js";
|
||||
import { finalToBrowserConfig } 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";
|
||||
import { ValidationError } from "./validation.js";
|
||||
|
||||
export interface ProfileDescription {
|
||||
title: string;
|
||||
id: string;
|
||||
}
|
||||
import {
|
||||
ProfileDescription,
|
||||
ProfileLifecycleManager,
|
||||
} from "./ProfileLifecycleManager.js";
|
||||
|
||||
export type { ProfileDescription };
|
||||
|
||||
type ConfigUpdateFunction = (payload: {
|
||||
config: ContinueConfig | undefined;
|
||||
error: ValidationError | undefined;
|
||||
}) => 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 +132,7 @@ export class ConfigHandler {
|
|||
async setSelectedProfile(profileId: string) {
|
||||
this.selectedProfileId = profileId;
|
||||
const newConfig = await this.loadConfig();
|
||||
this.notifyConfigListeners(newConfig);
|
||||
this.notifyConfigListeners({ config: newConfig, error: undefined });
|
||||
const selectedProfiles =
|
||||
this.globalContext.get("lastSelectedProfileForWorkspace") ?? {};
|
||||
selectedProfiles[await this.getWorkspaceId()] = profileId;
|
||||
|
|
@ -248,24 +178,44 @@ export class ConfigHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private notifyConfigListeners(newConfig: ContinueConfig) {
|
||||
private notifyConfigListeners({
|
||||
config,
|
||||
error,
|
||||
}: {
|
||||
config: ContinueConfig | undefined;
|
||||
error: ValidationError | undefined;
|
||||
}) {
|
||||
// Notify listeners that config changed
|
||||
for (const listener of this.updateListeners) {
|
||||
listener(newConfig);
|
||||
listener({ config, error });
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
let config: ContinueConfig | undefined;
|
||||
let error: ValidationError | undefined;
|
||||
try {
|
||||
config = await this.currentProfile.reloadConfig();
|
||||
this.inactiveProfiles.forEach((profile) => profile.clearConfig());
|
||||
} catch (caughtError) {
|
||||
console.log(caughtError);
|
||||
if (caughtError instanceof ValidationError) {
|
||||
error = caughtError;
|
||||
} else {
|
||||
throw caughtError;
|
||||
}
|
||||
} finally {
|
||||
this.notifyConfigListeners({ config, error });
|
||||
return { config, error };
|
||||
}
|
||||
}
|
||||
|
||||
getSerializedConfig(): Promise<BrowserSerializedContinueConfig> {
|
||||
|
|
|
|||
100
core/config/ProfileLifecycleManager.ts
Normal file
100
core/config/ProfileLifecycleManager.ts
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import {
|
||||
BrowserSerializedContinueConfig,
|
||||
ContinueConfig,
|
||||
IContextProvider,
|
||||
} from "../index.js";
|
||||
|
||||
import { finalToBrowserConfig } from "./load.js";
|
||||
|
||||
import { IProfileLoader } from "./profile/IProfileLoader.js";
|
||||
import { ValidationError } from "./validation.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<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) => {
|
||||
try {
|
||||
const newConfig = await this.profileLoader.doLoadConfig();
|
||||
|
||||
// Add registered context providers
|
||||
newConfig.contextProviders = (newConfig.contextProviders ?? []).concat(
|
||||
additionalContextProviders,
|
||||
);
|
||||
|
||||
this.savedConfig = newConfig;
|
||||
resolve(newConfig);
|
||||
} catch (error) {
|
||||
if (error instanceof ValidationError) {
|
||||
reject(`Error in config.json: ${error.errors.join(" | ")}`);
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +62,7 @@ import {
|
|||
getPromptFiles,
|
||||
slashCommandFromPromptFile,
|
||||
} from "./promptFile.js";
|
||||
import { validateConfig } from "./validation.js";
|
||||
|
||||
function resolveSerializedConfig(filepath: string): SerializedContinueConfig {
|
||||
let content = fs.readFileSync(filepath, "utf8");
|
||||
|
|
@ -108,6 +109,8 @@ function loadSerializedConfig(
|
|||
}
|
||||
}
|
||||
|
||||
validateConfig(config);
|
||||
|
||||
if (config.allowAnonymousTelemetry === undefined) {
|
||||
config.allowAnonymousTelemetry = true;
|
||||
}
|
||||
|
|
|
|||
112
core/config/validation.ts
Normal file
112
core/config/validation.ts
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
import { SerializedContinueConfig } from "../";
|
||||
|
||||
export type ValidationErrorMessage = string;
|
||||
|
||||
export class ValidationError extends Error {
|
||||
public errors: ValidationErrorMessage[];
|
||||
|
||||
constructor(errors: ValidationErrorMessage[]) {
|
||||
super("Validation failed");
|
||||
this.errors = errors;
|
||||
|
||||
// Maintains proper stack trace for where our error was thrown (only available on V8 engines)
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, ValidationError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 the array is empty, the config is valid.
|
||||
*/
|
||||
export function validateConfig(config: SerializedContinueConfig) {
|
||||
const errors: ValidationErrorMessage[] = [];
|
||||
|
||||
// Validate models
|
||||
if (!Array.isArray(config.models) || config.models.length === 0) {
|
||||
errors.push("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(
|
||||
`Model at index ${index} has an invalid or missing 'title'.`,
|
||||
);
|
||||
}
|
||||
if (typeof model.provider !== "string") {
|
||||
errors.push(`Model at index ${index} has an invalid 'provider'.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Validate slashCommands
|
||||
if (config.slashCommands) {
|
||||
if (!Array.isArray(config.slashCommands)) {
|
||||
errors.push("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(
|
||||
`Slash command at index ${index} has an invalid or missing 'name'.`,
|
||||
);
|
||||
}
|
||||
if (typeof command.description !== "string") {
|
||||
errors.push(
|
||||
`Slash command at index ${index} has an invalid or missing 'description'.`,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Validate contextProviders
|
||||
if (config.contextProviders) {
|
||||
if (!Array.isArray(config.contextProviders)) {
|
||||
errors.push(
|
||||
"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(
|
||||
`Context provider at index ${index} has an invalid or missing 'name'.`,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Validate embeddingsProvider
|
||||
if (
|
||||
config.embeddingsProvider &&
|
||||
typeof config.embeddingsProvider !== "object"
|
||||
) {
|
||||
errors.push(
|
||||
"The 'embeddingsProvider' field should be an object if defined.",
|
||||
);
|
||||
}
|
||||
|
||||
// Validate reranker
|
||||
if (config.reranker && typeof config.reranker !== "object") {
|
||||
errors.push("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(`The '${flag}' field should be a boolean if defined.`);
|
||||
}
|
||||
});
|
||||
|
||||
if (errors.length > 0) {
|
||||
throw new ValidationError(errors);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 { ValidationError } from "../config/validation.js";
|
||||
import type { ContextItemWithId, IndexingProgressUpdate } from "../index.js";
|
||||
|
||||
export type ToWebviewFromIdeOrCoreProtocol = {
|
||||
configUpdate: [undefined, void];
|
||||
configError: [ValidationError, 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 (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,17 +151,25 @@ export class VsCodeExtension {
|
|||
verticalDiffCodeLens.refresh.bind(verticalDiffCodeLens);
|
||||
});
|
||||
|
||||
this.configHandler.onConfigUpdate((newConfig) => {
|
||||
this.sidebar.webviewProtocol?.request("configUpdate", undefined);
|
||||
this.configHandler.onConfigUpdate(({ config: newConfig, error }) => {
|
||||
if (error) {
|
||||
// Show error in status bar
|
||||
setupStatusBar(undefined, undefined, true);
|
||||
this.sidebar.webviewProtocol?.request("configError", error);
|
||||
} 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,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Tab autocomplete
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"tsc:check": "tsc -p ./ --noEmit",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
61
gui/src/pages/config-error/index.tsx
Normal file
61
gui/src/pages/config-error/index.tsx
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import {
|
||||
ArrowLeftIcon,
|
||||
ExclamationCircleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { vscBackground } from "../../components";
|
||||
import { ROUTES } from "../../util/navigation";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootState } from "../../redux/store";
|
||||
|
||||
export default function ConfigErrorPage() {
|
||||
const navigate = useNavigate();
|
||||
const configError = useSelector(
|
||||
(store: RootState) => store.state.configError,
|
||||
);
|
||||
|
||||
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-y 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">
|
||||
{configError && configError.errors.length > 0 ? (
|
||||
<ul className="list-none space-y-4 p-0 m-0">
|
||||
{configError.errors.map((error, index) => (
|
||||
<li
|
||||
key={index}
|
||||
className="text-sm text-red-800 bg-red-100 rounded-md shadow-md flex items-start p-2"
|
||||
>
|
||||
<ExclamationCircleIcon className="w-5 h-5 mr-2" />
|
||||
<p className="m-0">
|
||||
<strong>Error:</strong> {error}
|
||||
</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>
|
||||
);
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import { createSelector } from "reselect";
|
|||
import { v4 } from "uuid";
|
||||
import { RootState } from "../store";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { ValidationError } 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: ValidationError | 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<ValidationError>,
|
||||
) => {
|
||||
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