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}`, +};