From 429e54ed347446747d206a97cb80c91baf5d407e Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Sun, 13 Oct 2024 23:22:20 +0700 Subject: [PATCH 1/8] feat: config.json validation --- .gitignore | 2 +- core/config/ConfigHandler.test.ts | 8 ++ core/config/ConfigHandler.ts | 132 ++++++------------ core/config/ProfileLifecycleManager.ts | 100 +++++++++++++ core/config/load.ts | 3 + core/config/validation.ts | 112 +++++++++++++++ core/indexing/docs/DocsService.ts | 33 +++-- core/package.json | 1 + core/protocol/webview.ts | 2 + extensions/vscode/package.json | 1 + .../vscode/src/autocomplete/statusBar.ts | 36 ++++- .../vscode/src/extension/VsCodeExtension.ts | 26 ++-- gui/package.json | 1 + gui/src/App.tsx | 6 + gui/src/components/Footer.tsx | 28 +++- gui/src/hooks/useSetup.ts | 7 +- gui/src/pages/config-error/index.tsx | 61 ++++++++ gui/src/redux/slices/stateSlice.ts | 12 +- gui/src/util/navigation.ts | 7 + 19 files changed, 450 insertions(+), 128 deletions(-) create mode 100644 core/config/ProfileLifecycleManager.ts create mode 100644 core/config/validation.ts create mode 100644 gui/src/pages/config-error/index.tsx create mode 100644 gui/src/util/navigation.ts diff --git a/.gitignore b/.gitignore index 113c07c43..9e32c699e 100644 --- a/.gitignore +++ b/.gitignore @@ -164,7 +164,7 @@ Icon Icon? .continue - +.continuerc.json .prompts/ .aider* diff --git a/core/config/ConfigHandler.test.ts b/core/config/ConfigHandler.test.ts index ef4e1814d..e817713bb 100644 --- a/core/config/ConfigHandler.test.ts +++ b/core/config/ConfigHandler.test.ts @@ -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"); }); }); diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 99f77270f..9d452d015 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -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; - - 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 { - this.savedConfig = undefined; - this.savedBrowserConfig = undefined; - this.pendingConfigPromise = undefined; - - return await this.profileLoader.doLoadConfig(); - } - - async loadConfig( - additionalContextProviders: IContextProvider[], - ): Promise { - // 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 { - 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 { diff --git a/core/config/ProfileLifecycleManager.ts b/core/config/ProfileLifecycleManager.ts new file mode 100644 index 000000000..cdae5bf87 --- /dev/null +++ b/core/config/ProfileLifecycleManager.ts @@ -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; + + 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 { + this.savedConfig = undefined; + this.savedBrowserConfig = undefined; + this.pendingConfigPromise = undefined; + + return this.profileLoader.doLoadConfig(); + } + + async loadConfig( + additionalContextProviders: IContextProvider[], + ): Promise { + // 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 { + if (!this.savedBrowserConfig) { + const continueConfig = await this.loadConfig(additionalContextProviders); + this.savedBrowserConfig = finalToBrowserConfig(continueConfig); + } + return this.savedBrowserConfig; + } +} diff --git a/core/config/load.ts b/core/config/load.ts index 67982ecad..cd5175506 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -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; } diff --git a/core/config/validation.ts b/core/config/validation.ts new file mode 100644 index 000000000..aae1406ef --- /dev/null +++ b/core/config/validation.ts @@ -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); + } +} diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 9cba2d841..d6c3b684c 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -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, + ); + } } }); } diff --git a/core/package.json b/core/package.json index b04da182b..ecb041d44 100644 --- a/core/package.json +++ b/core/package.json @@ -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" diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index d3b127fdc..3adf2bd8c 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -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]; diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index ffa27b831..279be8980 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -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", diff --git a/extensions/vscode/src/autocomplete/statusBar.ts b/extensions/vscode/src/autocomplete/statusBar.ts index ae541151f..8259e467a 100644 --- a/extensions/vscode/src/autocomplete/statusBar.ts +++ b/extensions/vscode/src/autocomplete/statusBar.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"; diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 674a80d1f..b80bcf62a 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -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 diff --git a/gui/package.json b/gui/package.json index 9eefbd9fd..884d6f1d1 100644 --- a/gui/package.json +++ b/gui/package.json @@ -6,6 +6,7 @@ "license": "Apache-2.0", "scripts": { "dev": "vite", + "tsc:check": "tsc -p ./ --noEmit", "build": "tsc && vite build", "preview": "vite preview" }, diff --git a/gui/src/App.tsx b/gui/src/App.tsx index f5ef97e67..b384936c5 100644 --- a/gui/src/App.tsx +++ b/gui/src/App.tsx @@ -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: , }, + { + path: ROUTES.CONFIG_ERROR, + element: , + }, { path: "/monaco", element: , diff --git a/gui/src/components/Footer.tsx b/gui/src/components/Footer.tsx index 671b000fb..4b6b012a8 100644 --- a/gui/src/components/Footer.tsx +++ b/gui/src/components/Footer.tsx @@ -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() {
+ {configError && ( + + + + )} + ) { } }); + useWebviewListener("configError", async (error) => { + dispatch(setConfigError(error)); + }); + useWebviewListener("submitMessage", async (data) => { streamResponse( data.message, diff --git a/gui/src/pages/config-error/index.tsx b/gui/src/pages/config-error/index.tsx new file mode 100644 index 000000000..50fad2097 --- /dev/null +++ b/gui/src/pages/config-error/index.tsx @@ -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 ( +
+
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, + }} + > + + Chat +
+ +
+
+

Config Errors

+

+ Please resolve the following errors in your config.json file. +

+
+ {configError && configError.errors.length > 0 ? ( +
    + {configError.errors.map((error, index) => ( +
  • + +

    + Error: {error} +

    +
  • + ))} +
+ ) : ( +

+ No configuration errors found. +

+ )} +
+
+
+
+ ); +} diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index b97bb0755..0b2f0548c 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -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, + ) => { + state.configError = error; + }, addPromptCompletionPair: ( state, { payload }: PayloadAction, @@ -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; diff --git a/gui/src/util/navigation.ts b/gui/src/util/navigation.ts new file mode 100644 index 000000000..2416226d8 --- /dev/null +++ b/gui/src/util/navigation.ts @@ -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}`, +}; From cc199c28634d006d38416533b06f26e001cea3fe Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Tue, 15 Oct 2024 22:17:39 +0700 Subject: [PATCH 2/8] fix: reset config errors --- gui/src/hooks/useSetup.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 09bb77010..e0da9dc44 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -109,6 +109,8 @@ function useSetup(dispatch: Dispatch) { useWebviewListener("configUpdate", async () => { await loadConfig(); + dispatch(setConfigError(undefined)); + if (!isJetBrains && !getLocalStorage("disableIndexing")) { debouncedIndexDocs(); } From 170676a46149a4e507f827aa566f4b1d39344e2e Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Tue, 15 Oct 2024 22:23:16 +0700 Subject: [PATCH 3/8] fix: config error handling --- gui/src/hooks/useSetup.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index e0da9dc44..ba0d6c692 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -34,6 +34,7 @@ function useSetup(dispatch: Dispatch) { return; } const { config, profileId } = result.content; + dispatch(setConfigError(undefined)); dispatch(setConfig(config)); dispatch(setSelectedProfileId(profileId)); setConfigLoaded(true); @@ -109,8 +110,6 @@ function useSetup(dispatch: Dispatch) { useWebviewListener("configUpdate", async () => { await loadConfig(); - dispatch(setConfigError(undefined)); - if (!isJetBrains && !getLocalStorage("disableIndexing")) { debouncedIndexDocs(); } From 19a25ff65f7950d410b5c45f860a75de7e883203 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 16 Oct 2024 13:58:04 +0700 Subject: [PATCH 4/8] refactor: return errors instead of throwing --- core/config/ConfigHandler.ts | 32 +++++++------------ core/config/ProfileLifecycleManager.ts | 17 ++++------ core/config/load.ts | 31 ++++++++++++++---- .../profile/ControlPlaneProfileLoader.ts | 6 +++- core/config/profile/IProfileLoader.ts | 6 +++- core/config/profile/LocalProfileLoader.ts | 6 +++- core/config/profile/doLoadConfig.ts | 9 ++++-- core/config/validation.ts | 20 ++---------- core/protocol/webview.ts | 4 +-- .../vscode/src/extension/VsCodeExtension.ts | 6 ++-- gui/src/redux/slices/stateSlice.ts | 6 ++-- 11 files changed, 75 insertions(+), 68 deletions(-) diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 9d452d015..6f3fdd2b5 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -18,18 +18,18 @@ import { } from "./onboarding.js"; import ControlPlaneProfileLoader from "./profile/ControlPlaneProfileLoader.js"; import LocalProfileLoader from "./profile/LocalProfileLoader.js"; -import { ValidationError } from "./validation.js"; import { ProfileDescription, ProfileLifecycleManager, } from "./ProfileLifecycleManager.js"; +import { ValidationErrorMessage } from "./validation.js"; export type { ProfileDescription }; type ConfigUpdateFunction = (payload: { config: ContinueConfig | undefined; - error: ValidationError | undefined; + errors: ValidationErrorMessage[] | undefined; }) => void; // Separately manages saving/reloading each profile @@ -132,7 +132,7 @@ export class ConfigHandler { async setSelectedProfile(profileId: string) { this.selectedProfileId = profileId; const newConfig = await this.loadConfig(); - this.notifyConfigListeners({ config: newConfig, error: undefined }); + this.notifyConfigListeners({ config: newConfig, errors: undefined }); const selectedProfiles = this.globalContext.get("lastSelectedProfileForWorkspace") ?? {}; selectedProfiles[await this.getWorkspaceId()] = profileId; @@ -180,14 +180,14 @@ export class ConfigHandler { private notifyConfigListeners({ config, - error, + errors, }: { config: ContinueConfig | undefined; - error: ValidationError | undefined; + errors: ValidationErrorMessage[] | undefined; }) { // Notify listeners that config changed for (const listener of this.updateListeners) { - listener({ config, error }); + listener({ config, errors }); } } @@ -200,22 +200,14 @@ export class ConfigHandler { async reloadConfig() { // TODO: this isn't right, there are two different senses in which you want to "reload" - let config: ContinueConfig | undefined; - let error: ValidationError | undefined; - try { - config = await this.currentProfile.reloadConfig(); + const { config, errors } = await this.currentProfile.reloadConfig(); + + if (config) { 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 }; } + + this.notifyConfigListeners({ config, errors }); + return { config, errors }; } getSerializedConfig(): Promise { diff --git a/core/config/ProfileLifecycleManager.ts b/core/config/ProfileLifecycleManager.ts index cdae5bf87..29cbcbd61 100644 --- a/core/config/ProfileLifecycleManager.ts +++ b/core/config/ProfileLifecycleManager.ts @@ -1,3 +1,4 @@ +import { config } from "dotenv"; import { BrowserSerializedContinueConfig, ContinueConfig, @@ -7,7 +8,6 @@ import { import { finalToBrowserConfig } from "./load.js"; import { IProfileLoader } from "./profile/IProfileLoader.js"; -import { ValidationError } from "./validation.js"; export interface ProfileDescription { title: string; @@ -43,7 +43,7 @@ export class ProfileLifecycleManager { } // Clear saved config and reload - async reloadConfig(): Promise { + async reloadConfig(): ReturnType { this.savedConfig = undefined; this.savedBrowserConfig = undefined; this.pendingConfigPromise = undefined; @@ -63,9 +63,10 @@ export class ProfileLifecycleManager { // Set pending config promise this.pendingConfigPromise = new Promise(async (resolve, reject) => { - try { - const newConfig = await this.profileLoader.doLoadConfig(); + const { config: newConfig, errors } = + await this.profileLoader.doLoadConfig(); + if (newConfig) { // Add registered context providers newConfig.contextProviders = (newConfig.contextProviders ?? []).concat( additionalContextProviders, @@ -73,12 +74,8 @@ export class ProfileLifecycleManager { this.savedConfig = newConfig; resolve(newConfig); - } catch (error) { - if (error instanceof ValidationError) { - reject(`Error in config.json: ${error.errors.join(" | ")}`); - } else { - reject(error); - } + } else if (errors) { + reject(`Error in config.json: ${errors.join(" | ")}`); } }); diff --git a/core/config/load.ts b/core/config/load.ts index cd5175506..6cf99f72c 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -62,7 +62,7 @@ import { getPromptFiles, slashCommandFromPromptFile, } from "./promptFile.js"; -import { validateConfig } from "./validation.js"; +import { validateConfig, ValidationErrorMessage } from "./validation.js"; function resolveSerializedConfig(filepath: string): SerializedContinueConfig { let content = fs.readFileSync(filepath, "utf8"); @@ -98,7 +98,10 @@ function loadSerializedConfig( ideSettings: IdeSettings, ideType: IdeType, overrideConfigJson: SerializedContinueConfig | undefined, -): SerializedContinueConfig { +): { + config: SerializedContinueConfig | undefined; + errors: ValidationErrorMessage[] | undefined; +} { const configPath = getConfigJsonPath(ideType); let config: SerializedContinueConfig = overrideConfigJson!; if (!config) { @@ -109,7 +112,14 @@ function loadSerializedConfig( } } - validateConfig(config); + const errors = validateConfig(config); + + if (errors) { + return { + errors, + config: undefined, + }; + } if (config.allowAnonymousTelemetry === undefined) { config.allowAnonymousTelemetry = true; @@ -145,7 +155,7 @@ function loadSerializedConfig( ? [...defaultSlashCommandsVscode] : [...defaultSlashCommandsJetBrains]; - return config; + return { config, errors }; } async function serializedToIntermediateConfig( @@ -580,15 +590,22 @@ async function loadFullConfigNode( writeLog: (log: string) => Promise, workOsAccessToken: string | undefined, overrideConfigJson: SerializedContinueConfig | undefined, -): Promise { +): Promise<{ + config: ContinueConfig | undefined; + errors: ValidationErrorMessage[] | undefined; +}> { // Serialized config - let serialized = loadSerializedConfig( + let { config: serialized, errors } = loadSerializedConfig( workspaceConfigs, ideSettings, ideType, overrideConfigJson, ); + if (!serialized) { + return { errors, config: undefined }; + } + // Convert serialized to intermediate config let intermediate = await serializedToIntermediateConfig(serialized, ide); @@ -656,7 +673,7 @@ async function loadFullConfigNode( writeLog, workOsAccessToken, ); - return finalConfig; + return { config: finalConfig, errors }; } export { diff --git a/core/config/profile/ControlPlaneProfileLoader.ts b/core/config/profile/ControlPlaneProfileLoader.ts index 12fe16ec0..03f363f0c 100644 --- a/core/config/profile/ControlPlaneProfileLoader.ts +++ b/core/config/profile/ControlPlaneProfileLoader.ts @@ -8,6 +8,7 @@ import { } from "../../index.js"; import { IProfileLoader } from "./IProfileLoader.js"; import doLoadConfig from "./doLoadConfig.js"; +import { ValidationErrorMessage } from "../validation.js"; export default class ControlPlaneProfileLoader implements IProfileLoader { private static RELOAD_INTERVAL = 1000 * 60 * 15; // every 15 minutes @@ -36,7 +37,10 @@ export default class ControlPlaneProfileLoader implements IProfileLoader { }, ControlPlaneProfileLoader.RELOAD_INTERVAL); } - async doLoadConfig(): Promise { + async doLoadConfig(): Promise<{ + config: ContinueConfig | undefined; + errors: ValidationErrorMessage[] | undefined; + }> { const settings = this.workspaceSettings ?? ((await this.controlPlaneClient.getSettingsForWorkspace( diff --git a/core/config/profile/IProfileLoader.ts b/core/config/profile/IProfileLoader.ts index b803e3f68..3b91f34e9 100644 --- a/core/config/profile/IProfileLoader.ts +++ b/core/config/profile/IProfileLoader.ts @@ -1,11 +1,15 @@ // 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 { ValidationErrorMessage } from "../validation.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; + doLoadConfig(): Promise<{ + config: ContinueConfig | undefined; + errors: ValidationErrorMessage[] | undefined; + }>; setIsActive(isActive: boolean): void; } diff --git a/core/config/profile/LocalProfileLoader.ts b/core/config/profile/LocalProfileLoader.ts index 69cfeb9a5..c51e464dd 100644 --- a/core/config/profile/LocalProfileLoader.ts +++ b/core/config/profile/LocalProfileLoader.ts @@ -1,5 +1,6 @@ import { ControlPlaneClient } from "../../control-plane/client.js"; import { ContinueConfig, IDE, IdeSettings } from "../../index.js"; +import { ValidationErrorMessage } from "../validation.js"; import doLoadConfig from "./doLoadConfig.js"; import { IProfileLoader } from "./IProfileLoader.js"; @@ -15,7 +16,10 @@ export default class LocalProfileLoader implements IProfileLoader { private writeLog: (message: string) => Promise, ) {} - async doLoadConfig(): Promise { + async doLoadConfig(): Promise<{ + config: ContinueConfig | undefined; + errors: ValidationErrorMessage[] | undefined; + }> { return doLoadConfig( this.ide, this.ideSettingsPromise, diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index e19feed85..2bd859859 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -38,7 +38,7 @@ export default async function doLoadConfig( const ideSettings = await ideSettingsPromise; const workOsAccessToken = await controlPlaneClient.getAccessToken(); - let newConfig = await loadFullConfigNode( + let { config: newConfig, errors } = await loadFullConfigNode( ide, workspaceConfigs, ideSettings, @@ -48,6 +48,11 @@ export default async function doLoadConfig( workOsAccessToken, overrideConfigJson, ); + + if (!newConfig) { + return { errors, config: undefined }; + } + newConfig.allowAnonymousTelemetry = newConfig.allowAnonymousTelemetry && (await ide.isTelemetryEnabled()); @@ -89,7 +94,7 @@ export default async function doLoadConfig( controlPlaneProxyInfo, ); - return newConfig; + return { config: newConfig, errors }; } // Pass ControlPlaneProxyInfo to objects that need it diff --git a/core/config/validation.ts b/core/config/validation.ts index aae1406ef..8207d8060 100644 --- a/core/config/validation.ts +++ b/core/config/validation.ts @@ -2,24 +2,10 @@ 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. + * @returns An array of error messages if there are any. Otherwise, the config is valid. */ export function validateConfig(config: SerializedContinueConfig) { const errors: ValidationErrorMessage[] = []; @@ -106,7 +92,5 @@ export function validateConfig(config: SerializedContinueConfig) { } }); - if (errors.length > 0) { - throw new ValidationError(errors); - } + return errors.length > 0 ? errors : undefined; } diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index 3adf2bd8c..8a8f451b8 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -1,9 +1,9 @@ -import { ValidationError } from "../config/validation.js"; +import { ValidationErrorMessage } from "../config/validation.js"; import type { ContextItemWithId, IndexingProgressUpdate } from "../index.js"; export type ToWebviewFromIdeOrCoreProtocol = { configUpdate: [undefined, void]; - configError: [ValidationError, void]; + configError: [ValidationErrorMessage[], void]; getDefaultModelTitle: [undefined, string]; indexProgress: [IndexingProgressUpdate, void]; refreshSubmenuItems: [undefined, void]; diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index b80bcf62a..3c1cf4acd 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -151,11 +151,11 @@ export class VsCodeExtension { verticalDiffCodeLens.refresh.bind(verticalDiffCodeLens); }); - this.configHandler.onConfigUpdate(({ config: newConfig, error }) => { - if (error) { + this.configHandler.onConfigUpdate(({ config: newConfig, errors }) => { + if (errors) { // Show error in status bar setupStatusBar(undefined, undefined, true); - this.sidebar.webviewProtocol?.request("configError", error); + this.sidebar.webviewProtocol?.request("configError", errors); } else if (newConfig) { setupStatusBar(undefined, undefined, false); diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 0b2f0548c..004c37d0b 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -15,7 +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"; +import { ValidationErrorMessage } from "core/config/validation"; export const memoizedContextItemsSelector = createSelector( [(state: RootState) => state.state.history], @@ -45,7 +45,7 @@ type State = { defaultModelTitle: string; mainEditorContent?: JSONContent; selectedProfileId: string; - configError: ValidationError | undefined; + configError: ValidationErrorMessage[] | undefined; }; const initialState: State = { @@ -101,7 +101,7 @@ export const stateSlice = createSlice({ }, setConfigError: ( state, - { payload: error }: PayloadAction, + { payload: error }: PayloadAction, ) => { state.configError = error; }, From 8f076bfc04a12a54fcc228d1c9bda2393cd265ea Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 16 Oct 2024 11:37:32 -0700 Subject: [PATCH 5/8] fix type errs --- docs/static/schemas/config.json | 66 +++++++++++++++++++ .../src/quickEdit/QuickEditQuickPick.ts | 2 +- gui/src/pages/config-error/index.tsx | 10 +-- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index c000f2d7f..58128d128 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -1629,6 +1629,72 @@ } }, "allOf": [ + { + "if": { + "properties": { + "name": { + "enum": ["discord"] + } + } + }, + "then": { + "allOf": [ + { + "properties": { + "params": { + "properties": { + "discordKey": { + "type": "string", + "description": "Your Discord bot token to access the Discord API. Required to fetch messages from servers." + }, + "guildId": { + "type": "string", + "description": "The ID of the guild (server) from which to fetch channels and messages." + }, + "channels": { + "type": "array", + "description": "A list of channel objects to search for messages", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "The unique ID of the channel" + }, + "name": { + "type": "string", + "description": "The name of the channel" + } + }, + "required": ["id"] + } + } + }, + "required": ["discordKey"] + } + } + }, + { + "oneOf": [ + { + "properties": { + "params": { + "required": ["guildId"] + } + } + }, + { + "properties": { + "params": { + "required": ["channels"] + } + } + } + ] + } + ] + } + }, { "if": { "properties": { diff --git a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts index 0c0b276a8..64d262957 100644 --- a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts +++ b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts @@ -384,7 +384,7 @@ export class QuickEdit { const searchResults = this.miniSearch.search( searchQuery, - ) as FileMiniSearchResult[]; + ) as unknown as FileMiniSearchResult[]; if (searchResults.length > 0) { quickPick.items = searchResults diff --git a/gui/src/pages/config-error/index.tsx b/gui/src/pages/config-error/index.tsx index 50fad2097..349c2cfe4 100644 --- a/gui/src/pages/config-error/index.tsx +++ b/gui/src/pages/config-error/index.tsx @@ -2,11 +2,11 @@ import { ArrowLeftIcon, ExclamationCircleIcon, } from "@heroicons/react/24/outline"; +import { useSelector } from "react-redux"; 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"; +import { ROUTES } from "../../util/navigation"; export default function ConfigErrorPage() { const navigate = useNavigate(); @@ -27,16 +27,16 @@ export default function ConfigErrorPage() { Chat
-
+

Config Errors

Please resolve the following errors in your config.json file.

- {configError && configError.errors.length > 0 ? ( + {configError && configError.length > 0 ? (
    - {configError.errors.map((error, index) => ( + {configError.map((error, index) => (
  • Date: Thu, 17 Oct 2024 12:57:45 +0700 Subject: [PATCH 6/8] improv: handle fatal and non-fatal errors fix fix: ui feat: intrusive error fix: errors fix: error handling fix: validation fix: naming fix: errors cleanup feat: fatal / non-fatal ui cleanup feat: fatal errors --- core/config/ConfigHandler.ts | 28 +++---- core/config/ProfileLifecycleManager.ts | 8 +- core/config/load.ts | 35 +++++---- .../profile/ControlPlaneProfileLoader.ts | 7 +- core/config/profile/IProfileLoader.ts | 7 +- core/config/profile/LocalProfileLoader.ts | 7 +- core/config/profile/doLoadConfig.ts | 16 ++-- core/config/validation.ts | 74 ++++++++++++------- core/protocol/webview.ts | 4 +- .../vscode/src/extension/VsCodeExtension.ts | 41 +++++----- gui/src/components/Layout.tsx | 22 +++++- gui/src/hooks/useSetup.ts | 1 - gui/src/pages/config-error/index.tsx | 33 ++++++--- gui/src/redux/hooks.ts | 5 ++ gui/src/redux/slices/stateSlice.ts | 6 +- 15 files changed, 178 insertions(+), 116 deletions(-) create mode 100644 gui/src/redux/hooks.ts diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 6f3fdd2b5..ef5cd3ec2 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -12,6 +12,7 @@ import { } from "../index.js"; import Ollama from "../llm/llms/Ollama.js"; import { GlobalContext } from "../util/GlobalContext.js"; +import { ConfigResult } from "./load.js"; import { LOCAL_ONBOARDING_CHAT_MODEL, ONBOARDING_LOCAL_MODEL_TITLE, @@ -23,14 +24,10 @@ import { ProfileDescription, ProfileLifecycleManager, } from "./ProfileLifecycleManager.js"; -import { ValidationErrorMessage } from "./validation.js"; export type { ProfileDescription }; -type ConfigUpdateFunction = (payload: { - config: ContinueConfig | undefined; - errors: ValidationErrorMessage[] | undefined; -}) => void; +type ConfigUpdateFunction = (payload: ConfigResult) => void; // Separately manages saving/reloading each profile @@ -132,7 +129,11 @@ export class ConfigHandler { async setSelectedProfile(profileId: string) { this.selectedProfileId = profileId; const newConfig = await this.loadConfig(); - this.notifyConfigListeners({ config: newConfig, errors: undefined }); + this.notifyConfigListeners({ + config: newConfig, + errors: undefined, + configLoadInterrupted: false, + }); const selectedProfiles = this.globalContext.get("lastSelectedProfileForWorkspace") ?? {}; selectedProfiles[await this.getWorkspaceId()] = profileId; @@ -178,16 +179,10 @@ export class ConfigHandler { } } - private notifyConfigListeners({ - config, - errors, - }: { - config: ContinueConfig | undefined; - errors: ValidationErrorMessage[] | undefined; - }) { + private notifyConfigListeners(result: ConfigResult) { // Notify listeners that config changed for (const listener of this.updateListeners) { - listener({ config, errors }); + listener(result); } } @@ -200,13 +195,14 @@ export class ConfigHandler { async reloadConfig() { // TODO: this isn't right, there are two different senses in which you want to "reload" - const { config, errors } = await this.currentProfile.reloadConfig(); + const { config, errors, configLoadInterrupted } = + await this.currentProfile.reloadConfig(); if (config) { this.inactiveProfiles.forEach((profile) => profile.clearConfig()); } - this.notifyConfigListeners({ config, errors }); + this.notifyConfigListeners({ config, errors, configLoadInterrupted }); return { config, errors }; } diff --git a/core/config/ProfileLifecycleManager.ts b/core/config/ProfileLifecycleManager.ts index 29cbcbd61..b9788e328 100644 --- a/core/config/ProfileLifecycleManager.ts +++ b/core/config/ProfileLifecycleManager.ts @@ -5,7 +5,7 @@ import { IContextProvider, } from "../index.js"; -import { finalToBrowserConfig } from "./load.js"; +import { ConfigResult, finalToBrowserConfig } from "./load.js"; import { IProfileLoader } from "./profile/IProfileLoader.js"; @@ -43,7 +43,7 @@ export class ProfileLifecycleManager { } // Clear saved config and reload - async reloadConfig(): ReturnType { + async reloadConfig(): Promise> { this.savedConfig = undefined; this.savedBrowserConfig = undefined; this.pendingConfigPromise = undefined; @@ -75,7 +75,9 @@ export class ProfileLifecycleManager { this.savedConfig = newConfig; resolve(newConfig); } else if (errors) { - reject(`Error in config.json: ${errors.join(" | ")}`); + reject( + `Error in config.json: ${errors.map((item) => item.message).join(" | ")}`, + ); } }); diff --git a/core/config/load.ts b/core/config/load.ts index 6cf99f72c..118ac10c7 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -62,7 +62,13 @@ import { getPromptFiles, slashCommandFromPromptFile, } from "./promptFile.js"; -import { validateConfig, ValidationErrorMessage } from "./validation.js"; +import { validateConfig, ConfigValidationError } from "./validation.js"; + +export interface ConfigResult { + config: T | undefined; + errors: ConfigValidationError[] | undefined; + configLoadInterrupted: boolean; +} function resolveSerializedConfig(filepath: string): SerializedContinueConfig { let content = fs.readFileSync(filepath, "utf8"); @@ -98,10 +104,7 @@ function loadSerializedConfig( ideSettings: IdeSettings, ideType: IdeType, overrideConfigJson: SerializedContinueConfig | undefined, -): { - config: SerializedContinueConfig | undefined; - errors: ValidationErrorMessage[] | undefined; -} { +): ConfigResult { const configPath = getConfigJsonPath(ideType); let config: SerializedContinueConfig = overrideConfigJson!; if (!config) { @@ -114,10 +117,11 @@ function loadSerializedConfig( const errors = validateConfig(config); - if (errors) { + if (errors?.some((error) => error.fatal)) { return { errors, config: undefined, + configLoadInterrupted: true, }; } @@ -155,7 +159,7 @@ function loadSerializedConfig( ? [...defaultSlashCommandsVscode] : [...defaultSlashCommandsJetBrains]; - return { config, errors }; + return { config, errors, configLoadInterrupted: false }; } async function serializedToIntermediateConfig( @@ -590,20 +594,21 @@ async function loadFullConfigNode( writeLog: (log: string) => Promise, workOsAccessToken: string | undefined, overrideConfigJson: SerializedContinueConfig | undefined, -): Promise<{ - config: ContinueConfig | undefined; - errors: ValidationErrorMessage[] | undefined; -}> { +): Promise> { // Serialized config - let { config: serialized, errors } = loadSerializedConfig( + let { + config: serialized, + errors, + configLoadInterrupted, + } = loadSerializedConfig( workspaceConfigs, ideSettings, ideType, overrideConfigJson, ); - if (!serialized) { - return { errors, config: undefined }; + if (!serialized || configLoadInterrupted) { + return { errors, config: undefined, configLoadInterrupted: true }; } // Convert serialized to intermediate config @@ -673,7 +678,7 @@ async function loadFullConfigNode( writeLog, workOsAccessToken, ); - return { config: finalConfig, errors }; + return { config: finalConfig, errors, configLoadInterrupted: false }; } export { diff --git a/core/config/profile/ControlPlaneProfileLoader.ts b/core/config/profile/ControlPlaneProfileLoader.ts index 03f363f0c..ec407974a 100644 --- a/core/config/profile/ControlPlaneProfileLoader.ts +++ b/core/config/profile/ControlPlaneProfileLoader.ts @@ -8,7 +8,7 @@ import { } from "../../index.js"; import { IProfileLoader } from "./IProfileLoader.js"; import doLoadConfig from "./doLoadConfig.js"; -import { ValidationErrorMessage } from "../validation.js"; +import { ConfigResult } from "../load.js"; export default class ControlPlaneProfileLoader implements IProfileLoader { private static RELOAD_INTERVAL = 1000 * 60 * 15; // every 15 minutes @@ -37,10 +37,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader { }, ControlPlaneProfileLoader.RELOAD_INTERVAL); } - async doLoadConfig(): Promise<{ - config: ContinueConfig | undefined; - errors: ValidationErrorMessage[] | undefined; - }> { + async doLoadConfig(): Promise> { const settings = this.workspaceSettings ?? ((await this.controlPlaneClient.getSettingsForWorkspace( diff --git a/core/config/profile/IProfileLoader.ts b/core/config/profile/IProfileLoader.ts index 3b91f34e9..2d22a821e 100644 --- a/core/config/profile/IProfileLoader.ts +++ b/core/config/profile/IProfileLoader.ts @@ -1,15 +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 { ValidationErrorMessage } from "../validation.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<{ - config: ContinueConfig | undefined; - errors: ValidationErrorMessage[] | undefined; - }>; + doLoadConfig(): Promise>; setIsActive(isActive: boolean): void; } diff --git a/core/config/profile/LocalProfileLoader.ts b/core/config/profile/LocalProfileLoader.ts index c51e464dd..1b4f06696 100644 --- a/core/config/profile/LocalProfileLoader.ts +++ b/core/config/profile/LocalProfileLoader.ts @@ -1,6 +1,6 @@ import { ControlPlaneClient } from "../../control-plane/client.js"; import { ContinueConfig, IDE, IdeSettings } from "../../index.js"; -import { ValidationErrorMessage } from "../validation.js"; +import { ConfigResult } from "../load.js"; import doLoadConfig from "./doLoadConfig.js"; import { IProfileLoader } from "./IProfileLoader.js"; @@ -16,10 +16,7 @@ export default class LocalProfileLoader implements IProfileLoader { private writeLog: (message: string) => Promise, ) {} - async doLoadConfig(): Promise<{ - config: ContinueConfig | undefined; - errors: ValidationErrorMessage[] | undefined; - }> { + async doLoadConfig(): Promise> { return doLoadConfig( this.ide, this.ideSettingsPromise, diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index 2bd859859..0aaf21e8b 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -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, overrideConfigJson: SerializedContinueConfig | undefined, workspaceId?: string, -) { +): Promise> { 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 { config: newConfig, errors } = await loadFullConfigNode( + let { + config: newConfig, + errors, + configLoadInterrupted, + } = await loadFullConfigNode( ide, workspaceConfigs, ideSettings, @@ -49,8 +53,8 @@ export default async function doLoadConfig( overrideConfigJson, ); - if (!newConfig) { - return { errors, config: undefined }; + if (configLoadInterrupted || !newConfig) { + return { errors, config: newConfig, configLoadInterrupted: true }; } newConfig.allowAnonymousTelemetry = @@ -94,7 +98,7 @@ export default async function doLoadConfig( controlPlaneProxyInfo, ); - return { config: newConfig, errors }; + return { config: newConfig, errors, configLoadInterrupted: false }; } // Pass ControlPlaneProxyInfo to objects that need it diff --git a/core/config/validation.ts b/core/config/validation.ts index 8207d8060..e6c4d4c07 100644 --- a/core/config/validation.ts +++ b/core/config/validation.ts @@ -1,6 +1,9 @@ import { SerializedContinueConfig } from "../"; -export type ValidationErrorMessage = string; +export interface ConfigValidationError { + fatal: boolean; + message: string; +} /** * Validates a SerializedContinueConfig object to ensure all properties are correctly formed. @@ -8,20 +11,27 @@ export type ValidationErrorMessage = string; * @returns An array of error messages if there are any. Otherwise, the config is valid. */ export function validateConfig(config: SerializedContinueConfig) { - const errors: ValidationErrorMessage[] = []; + const errors: ConfigValidationError[] = []; // Validate models if (!Array.isArray(config.models) || config.models.length === 0) { - errors.push("The 'models' field should be a non-empty array."); + 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( - `Model at index ${index} has an invalid or missing 'title'.`, - ); + errors.push({ + fatal: true, + message: `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'.`); + errors.push({ + fatal: true, + message: `Model at index ${index} has an invalid 'provider'.`, + }); } }); } @@ -29,18 +39,23 @@ export function validateConfig(config: SerializedContinueConfig) { // Validate slashCommands if (config.slashCommands) { if (!Array.isArray(config.slashCommands)) { - errors.push("The 'slashCommands' field should be an array if defined."); + 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( - `Slash command at index ${index} has an invalid or missing 'name'.`, - ); + errors.push({ + fatal: true, + message: `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'.`, - ); + errors.push({ + fatal: true, + message: `Slash command at index ${index} has an invalid or missing 'description'.`, + }); } }); } @@ -49,15 +64,17 @@ export function validateConfig(config: SerializedContinueConfig) { // Validate contextProviders if (config.contextProviders) { if (!Array.isArray(config.contextProviders)) { - errors.push( - "The 'contextProviders' field should be an array if defined.", - ); + 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( - `Context provider at index ${index} has an invalid or missing 'name'.`, - ); + errors.push({ + fatal: true, + message: `Context provider at index ${index} has an invalid or missing 'name'.`, + }); } }); } @@ -68,14 +85,18 @@ export function validateConfig(config: SerializedContinueConfig) { config.embeddingsProvider && typeof config.embeddingsProvider !== "object" ) { - errors.push( - "The 'embeddingsProvider' field should be an object if defined.", - ); + 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("The 'reranker' field should be an object if defined."); + errors.push({ + fatal: true, + message: "The 'reranker' field should be an object if defined.", + }); } // Validate other boolean flags @@ -88,7 +109,10 @@ export function validateConfig(config: SerializedContinueConfig) { booleanFlags.forEach((flag) => { if (config[flag] !== undefined && typeof config[flag] !== "boolean") { - errors.push(`The '${flag}' field should be a boolean if defined.`); + errors.push({ + fatal: true, + message: `The '${flag}' field should be a boolean if defined.`, + }); } }); diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index 8a8f451b8..eccb1e97e 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -1,9 +1,9 @@ -import { ValidationErrorMessage } from "../config/validation.js"; +import { ConfigValidationError } from "../config/validation.js"; import type { ContextItemWithId, IndexingProgressUpdate } from "../index.js"; export type ToWebviewFromIdeOrCoreProtocol = { configUpdate: [undefined, void]; - configError: [ValidationErrorMessage[], void]; + configError: [ConfigValidationError[] | undefined, void]; getDefaultModelTitle: [undefined, string]; indexProgress: [IndexingProgressUpdate, void]; refreshSubmenuItems: [undefined, void]; diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 3c1cf4acd..ce0f97979 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -151,26 +151,29 @@ export class VsCodeExtension { verticalDiffCodeLens.refresh.bind(verticalDiffCodeLens); }); - this.configHandler.onConfigUpdate(({ config: newConfig, errors }) => { - if (errors) { - // Show error in status bar - setupStatusBar(undefined, undefined, true); + 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.sidebar.webviewProtocol?.request("configUpdate", undefined); + + this.tabAutocompleteModel.clearLlm(); + + registerAllCodeLensProviders( + context, + this.diffManager, + this.verticalDiffManager.filepathToCodeLens, + newConfig, + ); + } + this.sidebar.webviewProtocol?.request("configError", errors); - } else if (newConfig) { - setupStatusBar(undefined, undefined, false); - - this.sidebar.webviewProtocol?.request("configUpdate", undefined); - - this.tabAutocompleteModel.clearLlm(); - - registerAllCodeLensProviders( - context, - this.diffManager, - this.verticalDiffManager.filepathToCodeLens, - newConfig, - ); - } - }); + }, + ); // Tab autocomplete const config = vscode.workspace.getConfiguration(EXTENSION_NAME); diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 0714d32b4..3e5614c6a 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -1,4 +1,4 @@ -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"; @@ -14,6 +14,8 @@ import { updateApplyState, setShowDialog } from "../redux/slices/uiStateSlice"; import TextDialog from "./dialogs"; import { useOnboardingCard, isNewUserOnboarding } from "./OnboardingCard"; import { LastSessionProvider } from "../context/LastSessionContext"; +import { useConfigError } from "../redux/hooks"; +import { ROUTES } from "../util/navigation"; 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, @@ -176,6 +185,17 @@ const Layout = () => { return ( + {hasFatalErrors && pathname !== ROUTES.CONFIG_ERROR && ( +
    navigate(ROUTES.CONFIG_ERROR)} + > + Error!{" "} + Could not load config.json +
    Learn More
    +
    + )}
    ) { return; } const { config, profileId } = result.content; - dispatch(setConfigError(undefined)); dispatch(setConfig(config)); dispatch(setSelectedProfileId(profileId)); setConfigLoaded(true); diff --git a/gui/src/pages/config-error/index.tsx b/gui/src/pages/config-error/index.tsx index 349c2cfe4..230a45204 100644 --- a/gui/src/pages/config-error/index.tsx +++ b/gui/src/pages/config-error/index.tsx @@ -1,18 +1,20 @@ import { ArrowLeftIcon, ExclamationCircleIcon, + ExclamationTriangleIcon, } from "@heroicons/react/24/outline"; -import { useSelector } from "react-redux"; import { useNavigate } from "react-router-dom"; import { vscBackground } from "../../components"; -import { RootState } from "../../redux/store"; import { ROUTES } from "../../util/navigation"; +import { useConfigError } from "../../redux/hooks"; export default function ConfigErrorPage() { const navigate = useNavigate(); - const configError = useSelector( - (store: RootState) => store.state.configError, - ); + const configError = useConfigError(); + + const sortedErrors = configError + ? [...configError].sort((a, b) => (b.fatal ? 1 : 0) - (a.fatal ? 1 : 0)) + : []; return (
    @@ -34,16 +36,27 @@ export default function ConfigErrorPage() { Please resolve the following errors in your config.json file.

    - {configError && configError.length > 0 ? ( + {sortedErrors.length > 0 ? (
      - {configError.map((error, index) => ( + {sortedErrors.map((error, index) => (
    • - + {error.fatal ? ( + + ) : ( + + )}

      - Error: {error} + + {error.fatal ? "Fatal Error:" : "Warning:"} + {" "} + {error.message}

    • ))} diff --git a/gui/src/redux/hooks.ts b/gui/src/redux/hooks.ts new file mode 100644 index 000000000..fcd45dc63 --- /dev/null +++ b/gui/src/redux/hooks.ts @@ -0,0 +1,5 @@ +import { useSelector } from "react-redux"; +import { RootState } from "./store"; + +export const useConfigError = () => + useSelector((store: RootState) => store.state.configError); diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 004c37d0b..c22d4bb1b 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -15,7 +15,7 @@ import { createSelector } from "reselect"; import { v4 } from "uuid"; import { RootState } from "../store"; import { v4 as uuidv4 } from "uuid"; -import { ValidationErrorMessage } from "core/config/validation"; +import { ConfigValidationError } from "core/config/validation"; export const memoizedContextItemsSelector = createSelector( [(state: RootState) => state.state.history], @@ -45,7 +45,7 @@ type State = { defaultModelTitle: string; mainEditorContent?: JSONContent; selectedProfileId: string; - configError: ValidationErrorMessage[] | undefined; + configError: ConfigValidationError[] | undefined; }; const initialState: State = { @@ -101,7 +101,7 @@ export const stateSlice = createSlice({ }, setConfigError: ( state, - { payload: error }: PayloadAction, + { payload: error }: PayloadAction, ) => { state.configError = error; }, From e0e777bb72c8999145ade4c4c273e129a6a67321 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 17 Oct 2024 14:51:00 +0700 Subject: [PATCH 7/8] improv: copy --- extensions/vscode/src/autocomplete/statusBar.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/src/autocomplete/statusBar.ts b/extensions/vscode/src/autocomplete/statusBar.ts index 8259e467a..5f59b9660 100644 --- a/extensions/vscode/src/autocomplete/statusBar.ts +++ b/extensions/vscode/src/autocomplete/statusBar.ts @@ -46,7 +46,7 @@ const statusBarItemText = ( error?: boolean, ) => { if (error) { - return "$(alert) Continue (error)"; + return "$(alert) Continue (FATAL ERROR)"; } switch (status) { From 271b07f98c5bdc732bb5cd11af63030171bb92cd Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 17 Oct 2024 21:20:33 -0700 Subject: [PATCH 8/8] move error banner to bottom --- gui/src/components/Layout.tsx | 39 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 3e5614c6a..a165ee1a8 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -4,18 +4,18 @@ 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 TextDialog from "./dialogs"; -import { useOnboardingCard, isNewUserOnboarding } from "./OnboardingCard"; -import { LastSessionProvider } from "../context/LastSessionContext"; -import { useConfigError } from "../redux/hooks"; import { ROUTES } from "../util/navigation"; +import TextDialog from "./dialogs"; +import Footer from "./Footer"; +import { isNewUserOnboarding, useOnboardingCard } from "./OnboardingCard"; +import PostHogPageView from "./PosthogPageView"; const LayoutTopDiv = styled(CustomScrollbarDiv)` height: 100%; @@ -185,17 +185,6 @@ const Layout = () => { return ( - {hasFatalErrors && pathname !== ROUTES.CONFIG_ERROR && ( -
      navigate(ROUTES.CONFIG_ERROR)} - > - Error!{" "} - Could not load config.json -
      Learn More
      -
      - )}
      { + {hasFatalErrors && pathname !== ROUTES.CONFIG_ERROR && ( +
      navigate(ROUTES.CONFIG_ERROR)} + > + Error!{" "} + + Could not load config.json + +
      Learn More
      +
      + )} +