From 88b56763a3fe831230d4d172c97ff95a1f3d3ba8 Mon Sep 17 00:00:00 2001 From: mkummer225 <7843299+mkummer225@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:46:37 -0600 Subject: [PATCH 01/53] initial TTS functionality --- core/config/profile/doLoadConfig.ts | 4 ++ core/core.ts | 6 ++ core/index.d.ts | 5 ++ core/util/tts.ts | 108 ++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 core/util/tts.ts diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index 16f72d40e..7537fedd6 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -10,6 +10,7 @@ import { import ContinueProxyEmbeddingsProvider from "../../indexing/embeddings/ContinueProxyEmbeddingsProvider.js"; 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"; export default async function doLoadConfig( @@ -51,6 +52,9 @@ export default async function doLoadConfig( ideInfo.extensionVersion, ); + // TODO: pass config to pre-load non-system TTS models + await TTS.setup(); + if (newConfig.analytics) { await TeamAnalytics.setup( newConfig.analytics as any, // TODO: Need to get rid of index.d.ts once and for all diff --git a/core/core.ts b/core/core.ts index 340008cdb..bba55631f 100644 --- a/core/core.ts +++ b/core/core.ts @@ -26,6 +26,7 @@ import historyManager from "./util/history"; import type { IMessenger, Message } from "./util/messenger"; import { editConfigJson } from "./util/paths"; import { Telemetry } from "./util/posthog"; +import { TTS } from "./util/tts"; import { streamDiffLines } from "./util/verticalEdit"; export class Core { @@ -383,6 +384,11 @@ export class Core { next = await gen.next(); } + const config = await configHandler.loadConfig(); + if(config.experimental?.readResponseTTS && "completion" in next.value) { + TTS.read(next.value?.completion); + } + return { done: true, content: next.value }; } diff --git a/core/index.d.ts b/core/index.d.ts index 3fcb08fa1..a23068516 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -887,6 +887,11 @@ interface ExperimentalConfig { * function and class declarations. */ quickActions?: QuickActionConfig[]; + + /** + * Automatically read LLM chat responses aloud using system TTS models + */ + readResponseTTS?: boolean; } interface AnalyticsConfig { diff --git a/core/util/tts.ts b/core/util/tts.ts new file mode 100644 index 000000000..77e4b1b12 --- /dev/null +++ b/core/util/tts.ts @@ -0,0 +1,108 @@ +import os from "node:os"; +import { exec, ChildProcess } from "child_process"; + +// The amount of time before a process is declared +// a zombie after executing .kill() +const ttsKillTimeout: number = 5000; + +/** + * Removes code blocks from a message. + * + * Return modified message text. + */ +function removeCodeBlocks(msgText: string): string { + const codeBlockRegex = /```[\s\S]*?```/g; + + // Remove code blocks from the message text + const textWithoutCodeBlocks = msgText.replace(codeBlockRegex, ""); + + return textWithoutCodeBlocks.trim(); +} + +/** + * Cleans a message text to safely be used in 'exec' context on host. + * + * Return modified message text. + */ +function sanitizeMessageForTTS(message: string): string { + message = removeCodeBlocks(message); + + // Remove or replace problematic characters + message = message + .replace(/"/g, "") + .replace(/`/g, "") + .replace(/\$/g, "") + .replace(/\\/g, "") + .replace(/[&|;()<>]/g, ""); + + message = message.trim().replace(/\s+/g, " "); + + return message; +} + +export class TTS { + static os: string | undefined = undefined; + static handle: ChildProcess | undefined = undefined; + + static async read(message: string) { + message = sanitizeMessageForTTS(message); + + try { + // Kill any active TTS processes + await TTS.kill(); + } catch (e) { + console.warn("Error killing TTS process: ", e); + return; + } + + switch (TTS.os) { + case "darwin": + TTS.handle = exec(`say "${message}"`); + break; + case "win32": + // Replace single quotes on windows + TTS.handle = exec( + `powershell -Command "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('${message.replace( + /'/g, + "''", + )}')"`, + ); + break; + case "linux": + TTS.handle = exec(`espeak "${message}"`); + break; + default: + console.log( + "Text-to-speech is not supported on this operating system.", + ); + break; + } + } + + static async kill(): Promise { + return new Promise((resolve, reject) => { + // Only kill a TTS process if it's still running + if (TTS.handle && TTS.handle.exitCode === null) { + // Use a timeout in case of zombie processes + let killTimeout: NodeJS.Timeout = setTimeout(() => { + reject(`Unable to kill TTS process: ${TTS.handle?.pid}`); + }, ttsKillTimeout); + + // Resolve our promise once the program has exited + TTS.handle.once("exit", () => { + clearTimeout(killTimeout); + TTS.handle = undefined; + resolve(); + }); + + TTS.handle.kill(); + } else { + resolve(); + } + }); + } + + static async setup() { + TTS.os = os.platform(); + } +} From 058784f84a484f6c13873a55e49924442a9df92f Mon Sep 17 00:00:00 2001 From: mkummer225 <7843299+mkummer225@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:52:57 -0600 Subject: [PATCH 02/53] add GUI stop TTS button functionality & stop TTS on new chat --- core/core.ts | 15 ++++++++++++++- core/protocol/core.ts | 1 + core/protocol/ideWebview.ts | 2 ++ core/protocol/passThrough.ts | 3 +++ core/protocol/webview.ts | 2 ++ core/util/tts.ts | 11 ++++++++++- gui/src/hooks/useSetup.ts | 10 ++++++++++ gui/src/pages/gui.tsx | 11 +++++++++++ gui/src/redux/slices/stateSlice.ts | 10 ++++++++++ 9 files changed, 63 insertions(+), 2 deletions(-) diff --git a/core/core.ts b/core/core.ts index bba55631f..16dbd0f06 100644 --- a/core/core.ts +++ b/core/core.ts @@ -360,6 +360,13 @@ export class Core { abortedMessageIds: Set, msg: Message, ) { + const config = await configHandler.loadConfig(); + + // Stop TTS on new StreamChat + if(config.experimental?.readResponseTTS) { + TTS.kill(); + } + const model = await configHandler.llmFromTitle(msg.data.title); const gen = model.streamChat( msg.data.messages, @@ -384,7 +391,6 @@ export class Core { next = await gen.next(); } - const config = await configHandler.loadConfig(); if(config.experimental?.readResponseTTS && "completion" in next.value) { TTS.read(next.value?.completion); } @@ -463,6 +469,13 @@ export class Core { } }); + // Provide messenger to TTS so it can set GUI active / inactive state + TTS.messenger = this.messenger; + + on("tts/kill", async () => { + TTS.kill(); + }); + async function* runNodeJsSlashCommand( configHandler: ConfigHandler, abortedMessageIds: Set, diff --git a/core/protocol/core.ts b/core/protocol/core.ts index fb3f7c684..1476fe67e 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -129,6 +129,7 @@ export type ToCoreFromIdeOrWebviewProtocol = { undefined, { model: string; promptTokens: number; generatedTokens: number }[], ]; + "tts/kill": [undefined, void]; "index/setPaused": [boolean, void]; "index/forceReIndex": [ undefined | { dir?: string; shouldClearIndexes?: boolean }, diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 2fa70bf73..d8701a035 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -31,6 +31,8 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { setInactive: [undefined, void]; + setTTSActive: [undefined, void]; + setTTSInactive: [undefined, void]; submitMessage: [{ message: any }, void]; // any -> JSONContent from TipTap updateSubmenuItems: [ { provider: string; submenuItems: ContextSubmenuItem[] }, diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 5fe14573a..3cfaa7628 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -30,6 +30,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "autocomplete/cancel", "autocomplete/accept", "command/run", + "tts/kill", "llm/complete", "llm/streamComplete", "llm/streamChat", @@ -57,4 +58,6 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] = "refreshSubmenuItems", "isContinueInputFocused", "didChangeAvailableProfiles", + "setTTSActive", + "setTTSInactive", ]; diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index 061f2819d..5ee751dec 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -13,4 +13,6 @@ export type ToWebviewFromIdeOrCoreProtocol = { }, void, ]; + setTTSInactive: [undefined, void]; + setTTSActive: [undefined, void]; }; diff --git a/core/util/tts.ts b/core/util/tts.ts index 77e4b1b12..62f69f600 100644 --- a/core/util/tts.ts +++ b/core/util/tts.ts @@ -1,5 +1,7 @@ import os from "node:os"; import { exec, ChildProcess } from "child_process"; +import type { IMessenger } from "./messenger"; +import type { FromCoreProtocol, ToCoreProtocol } from "../protocol"; // The amount of time before a process is declared // a zombie after executing .kill() @@ -43,6 +45,7 @@ function sanitizeMessageForTTS(message: string): string { export class TTS { static os: string | undefined = undefined; static handle: ChildProcess | undefined = undefined; + static messenger: IMessenger; static async read(message: string) { message = sanitizeMessageForTTS(message); @@ -75,8 +78,14 @@ export class TTS { console.log( "Text-to-speech is not supported on this operating system.", ); - break; + return; } + + TTS.messenger.request("setTTSActive", undefined); + + TTS.handle?.once("exit", () => { + TTS.messenger.request("setTTSInactive", undefined); + }); } static async kill(): Promise { diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 28cd4019b..e6d05771b 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -7,6 +7,8 @@ import { setVscMachineId } from "../redux/slices/configSlice"; import { addContextItemsAtIndex, setConfig, + setTTSActive, + setTTSInactive, setInactive, setSelectedProfileId, } from "../redux/slices/stateSlice"; @@ -81,6 +83,14 @@ function useSetup(dispatch: Dispatch) { dispatch(setInactive()); }); + useWebviewListener("setTTSActive", async () => { + dispatch(setTTSActive()); + }); + + useWebviewListener("setTTSInactive", async () => { + dispatch(setTTSInactive()); + }); + useWebviewListener("setColors", async (colors) => { Object.keys(colors).forEach((key) => { document.body.style.setProperty(key, colors[key]); diff --git a/gui/src/pages/gui.tsx b/gui/src/pages/gui.tsx index caaff7ea6..faeeccd83 100644 --- a/gui/src/pages/gui.tsx +++ b/gui/src/pages/gui.tsx @@ -195,6 +195,7 @@ function GUI() { const defaultModel = useSelector(defaultModelSelector); + const ttsActive = useSelector((state: RootState) => state.state.ttsActive); const active = useSelector((state: RootState) => state.state.active); const [stepsOpen, setStepsOpen] = useState<(boolean | undefined)[]>([]); @@ -549,6 +550,16 @@ function GUI() { trackVisibility={active} /> + {ttsActive && ( + { + ideMessenger.post("tts/kill", undefined); + }} + > + ■ Stop TTS + + )} {active && ( (values: &mut[T]) { type State = { history: ChatHistory; contextItems: ContextItemWithId[]; + ttsActive: boolean; active: boolean; config: BrowserSerializedContinueConfig; title: string; @@ -110,6 +111,7 @@ type State = { const initialState: State = { history: [], contextItems: [], + ttsActive: false, active: false, config: { slashCommands: [ @@ -168,6 +170,9 @@ export const stateSlice = createSlice({ ? lastHistory.promptLogs.concat(payload) : payload; }, + setTTSActive: (state) => { + state.ttsActive = true; + }, setActive: (state) => { state.active = true; }, @@ -329,6 +334,9 @@ export const stateSlice = createSlice({ } historyItem.contextItems.push(...payload.contextItems); }, + setTTSInactive: (state) => { + state.ttsActive = false; + }, setInactive: (state) => { state.active = false; }, @@ -500,6 +508,7 @@ export const { setContextItemsAtIndex, addContextItems, addContextItemsAtIndex, + setTTSInactive, setInactive, streamUpdate, newSession, @@ -510,6 +519,7 @@ export const { setDefaultModel, setConfig, addPromptCompletionPair, + setTTSActive, setActive, setEditingContextItemAtIndex, initNewActiveMessage, From b5fbb9827890af4d03133baeb63fa3730683099f Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 14 Aug 2024 17:48:30 -0700 Subject: [PATCH 03/53] add(llm)-bedrock-imported-models --- binary/package-lock.json | 1 + core/index.d.ts | 9 +- core/llm/llms/Bedrock.ts | 11 ++- core/llm/llms/BedrockImport.ts | 94 +++++++++++++++++++ core/llm/llms/index.ts | 2 + docs/static/schemas/config.json | 2 + .../src/main/resources/config_schema.json | 2 + extensions/vscode/config_schema.json | 2 + extensions/vscode/continue_rc_schema.json | 2 + extensions/vscode/package-lock.json | 4 +- extensions/vscode/package.json | 2 +- 11 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 core/llm/llms/BedrockImport.ts diff --git a/binary/package-lock.json b/binary/package-lock.json index 9378d2eef..b57800a29 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -79,6 +79,7 @@ "ollama": "^0.4.6", "onnxruntime-node": "1.14.0", "openai": "^4.20.1", + "p-limit": "^6.1.0", "pg": "^8.11.3", "posthog-node": "^3.6.3", "quick-lru": "^7.0.0", diff --git a/core/index.d.ts b/core/index.d.ts index 3fcb08fa1..42bc389ed 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -341,8 +341,14 @@ export interface LLMOptions { apiVersion?: string; apiType?: string; - // GCP Options + // AWS options + profile?: string; + modelArn?: string; + + // AWS and GCP Options region?: string; + + // GCP Options projectId?: string; capabilities?: ModelCapability; @@ -595,6 +601,7 @@ type ModelProvider = | "gemini" | "mistral" | "bedrock" + | "bedrockimport" | "sagemaker" | "deepinfra" | "flowise" diff --git a/core/llm/llms/Bedrock.ts b/core/llm/llms/Bedrock.ts index 226671c52..0cdebc309 100644 --- a/core/llm/llms/Bedrock.ts +++ b/core/llm/llms/Bedrock.ts @@ -14,19 +14,22 @@ import { stripImages } from "../images.js"; import { BaseLLM } from "../index.js"; class Bedrock extends BaseLLM { - private static PROFILE_NAME: string = "bedrock"; static providerName: ModelProvider = "bedrock"; static defaultOptions: Partial = { region: "us-east-1", model: "anthropic.claude-3-sonnet-20240229-v1:0", - contextLength: 200_000, + contextLength: 200_000 }; + profile?: string | undefined; constructor(options: LLMOptions) { super(options); if (!options.apiBase) { this.apiBase = `https://bedrock-runtime.${options.region}.amazonaws.com`; } + if (options.profile) { + this.profile = options.profile; + } } protected async *_streamComplete( @@ -124,11 +127,11 @@ class Bedrock extends BaseLLM { private async _getCredentials() { try { return await fromIni({ - profile: Bedrock.PROFILE_NAME, + profile: this.profile, })(); } catch (e) { console.warn( - `AWS profile with name ${Bedrock.PROFILE_NAME} not found in ~/.aws/credentials, using default profile`, + `AWS profile with name ${this.profile} not found in ~/.aws/credentials, using default profile`, ); return await fromIni()(); } diff --git a/core/llm/llms/BedrockImport.ts b/core/llm/llms/BedrockImport.ts new file mode 100644 index 000000000..504f472f2 --- /dev/null +++ b/core/llm/llms/BedrockImport.ts @@ -0,0 +1,94 @@ +import { + BedrockRuntimeClient, + InvokeModelWithResponseStreamCommand, +} from "@aws-sdk/client-bedrock-runtime"; +import { fromIni } from "@aws-sdk/credential-providers"; +import { + CompletionOptions, + LLMOptions, + ModelProvider, +} from "../../index.js"; +import { BaseLLM } from "../index.js"; + +class BedrockImport extends BaseLLM { + static providerName: ModelProvider = "bedrockimport"; + static defaultOptions: Partial = { + region: "us-east-1" + }; + // the BedRock imported custom model ARN + modelArn?: string | undefined; + profile?: string | undefined; + + constructor(options: LLMOptions) { + super(options); + if (!options.apiBase) { + this.apiBase = `https://bedrock-runtime.${options.region}.amazonaws.com`; + } + if (options.modelArn) { + this.modelArn = options.modelArn; + } + if (options.profile) { + this.profile = options.profile; + } + } + + protected async *_streamComplete( + prompt: string, + options: CompletionOptions, + ): AsyncGenerator { + const credentials = await this._getCredentials(); + const client = new BedrockRuntimeClient({ + region: this.region, + credentials: { + accessKeyId: credentials.accessKeyId, + secretAccessKey: credentials.secretAccessKey, + sessionToken: credentials.sessionToken || "", + }, + }); + + const input = this._generateInvokeModelCommandInput(prompt, options); + const command = new InvokeModelWithResponseStreamCommand(input); + const response = await client.send(command); + + if (response.body) { + for await (const item of response.body) { + const chunk = JSON.parse(new TextDecoder().decode(item.chunk?.bytes)); + if (chunk.outputs[0].text) { + yield chunk.outputs[0].text; + } + } + } + } + + private _generateInvokeModelCommandInput( + prompt: string, + options: CompletionOptions, + ): any { + const payload = { + prompt: prompt + }; + + return { + body: JSON.stringify(payload), + modelId: this.modelArn, + accept: "application/json", + contentType: "application/json" + }; + } + + private async _getCredentials() { + try { + return await + fromIni({ + profile: this.profile + })(); + } catch (e) { + console.warn( + `AWS profile with name ${this.profile} not found in ~/.aws/credentials, using default profile`, + ); + return await fromIni()(); + } + } +} + +export default BedrockImport; diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index cd084207e..7cc6f701f 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -11,6 +11,7 @@ import { BaseLLM } from "../index"; import Anthropic from "./Anthropic"; import Azure from "./Azure"; import Bedrock from "./Bedrock"; +import BedrockImport from "./BedrockImport"; import Cloudflare from "./Cloudflare"; import Cohere from "./Cohere"; import DeepInfra from "./DeepInfra"; @@ -53,6 +54,7 @@ const LLMs = [ LMStudio, Mistral, Bedrock, + BedrockImport, SageMaker, DeepInfra, Flowise, diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 44a908810..4e85e91a4 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -171,6 +171,7 @@ "anthropic", "cohere", "bedrock", + "bedrockimport", "sagemaker", "together", "ollama", @@ -197,6 +198,7 @@ "### Anthropic\nTo get started with Anthropic models, you first need to sign up for the open beta [here](https://claude.ai/login) to obtain an API key.\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/anthropicllm)", "### Cohere\nTo use Cohere, visit the [Cohere dashboard](https://dashboard.cohere.com/api-keys) to create an API key.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/cohere)", "### Bedrock\nTo get started with Bedrock you need to sign up on AWS [here](https://aws.amazon.com/bedrock/claude/)", + "### Bedrock Imported Models\nTo get started with Bedrock you need to sign up on AWS [here](https://aws.amazon.com/bedrock/claude/)", "### Together\nTogether is a hosted service that provides extremely fast streaming of open-source language models. To get started with Together:\n1. Obtain an API key from [here](https://together.ai)\n2. Paste below\n3. Select a model preset\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/togetherllm)", "### Ollama\nTo get started with Ollama, follow these steps:\n1. Download from [ollama.ai](https://ollama.ai/) and open the application\n2. Open a terminal and run `ollama run `. Example model names are `codellama:7b-instruct` or `llama2:7b-text`. You can find the full list [here](https://ollama.ai/library).\n3. Make sure that the model name used in step 2 is the same as the one in config.json (e.g. `model=\"codellama:7b-instruct\"`)\n4. Once the model has finished downloading, you can start asking questions through Continue.\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/ollama)", "### Huggingface TGI\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/huggingfacetgi)", diff --git a/extensions/intellij/src/main/resources/config_schema.json b/extensions/intellij/src/main/resources/config_schema.json index 44a908810..4e85e91a4 100644 --- a/extensions/intellij/src/main/resources/config_schema.json +++ b/extensions/intellij/src/main/resources/config_schema.json @@ -171,6 +171,7 @@ "anthropic", "cohere", "bedrock", + "bedrockimport", "sagemaker", "together", "ollama", @@ -197,6 +198,7 @@ "### Anthropic\nTo get started with Anthropic models, you first need to sign up for the open beta [here](https://claude.ai/login) to obtain an API key.\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/anthropicllm)", "### Cohere\nTo use Cohere, visit the [Cohere dashboard](https://dashboard.cohere.com/api-keys) to create an API key.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/cohere)", "### Bedrock\nTo get started with Bedrock you need to sign up on AWS [here](https://aws.amazon.com/bedrock/claude/)", + "### Bedrock Imported Models\nTo get started with Bedrock you need to sign up on AWS [here](https://aws.amazon.com/bedrock/claude/)", "### Together\nTogether is a hosted service that provides extremely fast streaming of open-source language models. To get started with Together:\n1. Obtain an API key from [here](https://together.ai)\n2. Paste below\n3. Select a model preset\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/togetherllm)", "### Ollama\nTo get started with Ollama, follow these steps:\n1. Download from [ollama.ai](https://ollama.ai/) and open the application\n2. Open a terminal and run `ollama run `. Example model names are `codellama:7b-instruct` or `llama2:7b-text`. You can find the full list [here](https://ollama.ai/library).\n3. Make sure that the model name used in step 2 is the same as the one in config.json (e.g. `model=\"codellama:7b-instruct\"`)\n4. Once the model has finished downloading, you can start asking questions through Continue.\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/ollama)", "### Huggingface TGI\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/huggingfacetgi)", diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 44a908810..4e85e91a4 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -171,6 +171,7 @@ "anthropic", "cohere", "bedrock", + "bedrockimport", "sagemaker", "together", "ollama", @@ -197,6 +198,7 @@ "### Anthropic\nTo get started with Anthropic models, you first need to sign up for the open beta [here](https://claude.ai/login) to obtain an API key.\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/anthropicllm)", "### Cohere\nTo use Cohere, visit the [Cohere dashboard](https://dashboard.cohere.com/api-keys) to create an API key.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/cohere)", "### Bedrock\nTo get started with Bedrock you need to sign up on AWS [here](https://aws.amazon.com/bedrock/claude/)", + "### Bedrock Imported Models\nTo get started with Bedrock you need to sign up on AWS [here](https://aws.amazon.com/bedrock/claude/)", "### Together\nTogether is a hosted service that provides extremely fast streaming of open-source language models. To get started with Together:\n1. Obtain an API key from [here](https://together.ai)\n2. Paste below\n3. Select a model preset\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/togetherllm)", "### Ollama\nTo get started with Ollama, follow these steps:\n1. Download from [ollama.ai](https://ollama.ai/) and open the application\n2. Open a terminal and run `ollama run `. Example model names are `codellama:7b-instruct` or `llama2:7b-text`. You can find the full list [here](https://ollama.ai/library).\n3. Make sure that the model name used in step 2 is the same as the one in config.json (e.g. `model=\"codellama:7b-instruct\"`)\n4. Once the model has finished downloading, you can start asking questions through Continue.\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/ollama)", "### Huggingface TGI\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/huggingfacetgi)", diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index d6c797596..35fc4906f 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -174,6 +174,7 @@ "anthropic", "cohere", "bedrock", + "bedrockimport", "sagemaker", "together", "ollama", @@ -200,6 +201,7 @@ "### Anthropic\nTo get started with Anthropic models, you first need to sign up for the open beta [here](https://claude.ai/login) to obtain an API key.\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/anthropicllm)", "### Cohere\nTo use Cohere, visit the [Cohere dashboard](https://dashboard.cohere.com/api-keys) to create an API key.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/cohere)", "### Bedrock\nTo get started with Bedrock you need to sign up on AWS [here](https://aws.amazon.com/bedrock/claude/)", + "### Bedrock Imported Models\nTo get started with Bedrock you need to sign up on AWS [here](https://aws.amazon.com/bedrock/claude/)", "### Together\nTogether is a hosted service that provides extremely fast streaming of open-source language models. To get started with Together:\n1. Obtain an API key from [here](https://together.ai)\n2. Paste below\n3. Select a model preset\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/togetherllm)", "### Ollama\nTo get started with Ollama, follow these steps:\n1. Download from [ollama.ai](https://ollama.ai/) and open the application\n2. Open a terminal and run `ollama run `. Example model names are `codellama:7b-instruct` or `llama2:7b-text`. You can find the full list [here](https://ollama.ai/library).\n3. Make sure that the model name used in step 2 is the same as the one in config.json (e.g. `model=\"codellama:7b-instruct\"`)\n4. Once the model has finished downloading, you can start asking questions through Continue.\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/ollama)", "### Huggingface TGI\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/huggingfacetgi)", diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 6af742e21..7c2cad527 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.197", + "version": "0.9.199", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.197", + "version": "0.9.199", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 389c6bac5..a87c6ac3c 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -2,7 +2,7 @@ "name": "continue", "icon": "media/icon.png", "author": "Continue Dev, Inc", - "version": "0.9.197", + "version": "0.9.199", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" From 48353e651de2a7a8df9cce77473f25e2b79807b1 Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 14 Aug 2024 17:58:38 -0700 Subject: [PATCH 04/53] update docs --- .../docs/reference/Model Providers/bedrock.md | 11 ++++---- .../Model Providers/bedrockimport.md | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 docs/docs/reference/Model Providers/bedrockimport.md diff --git a/docs/docs/reference/Model Providers/bedrock.md b/docs/docs/reference/Model Providers/bedrock.md index daac562af..d720de66f 100644 --- a/docs/docs/reference/Model Providers/bedrock.md +++ b/docs/docs/reference/Model Providers/bedrock.md @@ -1,4 +1,4 @@ -# AWS Bedrock +# AWS Bedrock To setup Bedrock, add the following to your `config.json` file: @@ -9,18 +9,19 @@ To setup Bedrock, add the following to your `config.json` file: "title": "Bedrock: Claude 3 Sonnet", "provider": "bedrock", "model": "anthropic.claude-3-sonnet-20240229-v1:0", - "region": "us-east-1" + "region": "us-east-1", + "profile": "bedrock", } ] } ``` -Authentication will be through temporary or long-term credentials in -~/.aws/credentials under a profile called "bedrock". +Authentication will be through temporary or long-term credentials in +~/.aws/credentials under a configured profile (e.g. "bedrock"). ```title="~/.aws/credentials [bedrock] aws_access_key_id = abcdefg aws_secret_access_key = hijklmno -aws_session_token = pqrstuvwxyz # Optional: means short term creds. +aws_session_token = pqrstuvwxyz # Optional: means short term creds. ``` diff --git a/docs/docs/reference/Model Providers/bedrockimport.md b/docs/docs/reference/Model Providers/bedrockimport.md new file mode 100644 index 000000000..6a8c50d68 --- /dev/null +++ b/docs/docs/reference/Model Providers/bedrockimport.md @@ -0,0 +1,28 @@ +# AWS Bedrock Custom Imported Models + +To setup Bedrock using custom imported models, add the following to your `config.json` file: + +```json title="~/.continue/config.json" +{ + "models": [ + { + "title": "AWS Bedrock deepseek-coder-6.7b-instruct", + "provider": "bedrockimport", + "model": "deepseek-coder-6.7b-instruct", + "modelArn": "arn:aws:bedrock:us-west-2:XXXXX:imported-model/XXXXXX", + "region": "us-west-2", + "profile": "bedrock" + } + ] +} +``` + +Authentication will be through temporary or long-term credentials in +~/.aws/credentials under a configured profile (e.g. "bedrock"). + +```title="~/.aws/credentials +[bedrock] +aws_access_key_id = abcdefg +aws_secret_access_key = hijklmno +aws_session_token = pqrstuvwxyz # Optional: means short term creds. +``` From c20b0b42204afbcc74c1ba779a06f551db885156 Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Thu, 15 Aug 2024 08:15:18 -0700 Subject: [PATCH 05/53] default to bedrock profile for backwards compatibility --- core/llm/llms/Bedrock.ts | 2 ++ core/llm/llms/BedrockImport.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core/llm/llms/Bedrock.ts b/core/llm/llms/Bedrock.ts index 0cdebc309..415ec0f10 100644 --- a/core/llm/llms/Bedrock.ts +++ b/core/llm/llms/Bedrock.ts @@ -29,6 +29,8 @@ class Bedrock extends BaseLLM { } if (options.profile) { this.profile = options.profile; + } else { + this.profile = "bedrock"; } } diff --git a/core/llm/llms/BedrockImport.ts b/core/llm/llms/BedrockImport.ts index 504f472f2..f53d4b15e 100644 --- a/core/llm/llms/BedrockImport.ts +++ b/core/llm/llms/BedrockImport.ts @@ -29,6 +29,8 @@ class BedrockImport extends BaseLLM { } if (options.profile) { this.profile = options.profile; + } else { + this.profile = "bedrock"; } } From e701ceacfa77a8c75f1878770fbdfb428cdf9524 Mon Sep 17 00:00:00 2001 From: mkummer225 <7843299+mkummer225@users.noreply.github.com> Date: Thu, 15 Aug 2024 18:48:18 -0600 Subject: [PATCH 06/53] cleanup --- core/protocol/ideWebview.ts | 3 +-- core/protocol/passThrough.ts | 1 - core/protocol/webview.ts | 3 +-- core/util/tts.ts | 4 ++-- gui/src/hooks/useSetup.ts | 9 ++------- gui/src/redux/slices/stateSlice.ts | 8 ++------ 6 files changed, 8 insertions(+), 20 deletions(-) diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index d8701a035..5e1e74589 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -31,8 +31,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { setInactive: [undefined, void]; - setTTSActive: [undefined, void]; - setTTSInactive: [undefined, void]; + setTTSActive: [boolean, void]; submitMessage: [{ message: any }, void]; // any -> JSONContent from TipTap updateSubmenuItems: [ { provider: string; submenuItems: ContextSubmenuItem[] }, diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 3cfaa7628..1e2499ca7 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -59,5 +59,4 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] = "isContinueInputFocused", "didChangeAvailableProfiles", "setTTSActive", - "setTTSInactive", ]; diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index 5ee751dec..d3b127fdc 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -13,6 +13,5 @@ export type ToWebviewFromIdeOrCoreProtocol = { }, void, ]; - setTTSInactive: [undefined, void]; - setTTSActive: [undefined, void]; + setTTSActive: [boolean, void]; }; diff --git a/core/util/tts.ts b/core/util/tts.ts index 62f69f600..248c38518 100644 --- a/core/util/tts.ts +++ b/core/util/tts.ts @@ -81,10 +81,10 @@ export class TTS { return; } - TTS.messenger.request("setTTSActive", undefined); + TTS.messenger.request("setTTSActive", true); TTS.handle?.once("exit", () => { - TTS.messenger.request("setTTSInactive", undefined); + TTS.messenger.request("setTTSActive", false); }); } diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index e6d05771b..a3a4dcfc4 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -8,7 +8,6 @@ import { addContextItemsAtIndex, setConfig, setTTSActive, - setTTSInactive, setInactive, setSelectedProfileId, } from "../redux/slices/stateSlice"; @@ -83,12 +82,8 @@ function useSetup(dispatch: Dispatch) { dispatch(setInactive()); }); - useWebviewListener("setTTSActive", async () => { - dispatch(setTTSActive()); - }); - - useWebviewListener("setTTSInactive", async () => { - dispatch(setTTSInactive()); + useWebviewListener("setTTSActive", async (status) => { + dispatch(setTTSActive(status)); }); useWebviewListener("setColors", async (colors) => { diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index de11a237c..7534d9b85 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -170,8 +170,8 @@ export const stateSlice = createSlice({ ? lastHistory.promptLogs.concat(payload) : payload; }, - setTTSActive: (state) => { - state.ttsActive = true; + setTTSActive: (state, { payload }: PayloadAction) => { + state.ttsActive = payload; }, setActive: (state) => { state.active = true; @@ -334,9 +334,6 @@ export const stateSlice = createSlice({ } historyItem.contextItems.push(...payload.contextItems); }, - setTTSInactive: (state) => { - state.ttsActive = false; - }, setInactive: (state) => { state.active = false; }, @@ -508,7 +505,6 @@ export const { setContextItemsAtIndex, addContextItems, addContextItemsAtIndex, - setTTSInactive, setInactive, streamUpdate, newSession, From f6d100df524873e44e9da5da00c4b6e192a83ffe Mon Sep 17 00:00:00 2001 From: hbernie Date: Thu, 15 Aug 2024 14:06:07 -0700 Subject: [PATCH 07/53] Add Kindo provider --- core/index.d.ts | 1 + core/llm/llms/Kindo.ts | 16 ++++++++ core/llm/llms/index.ts | 2 + docs/docs/reference/Model Providers/kindo.md | 42 ++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 core/llm/llms/Kindo.ts create mode 100644 docs/docs/reference/Model Providers/kindo.md diff --git a/core/index.d.ts b/core/index.d.ts index 8ce83c6f7..51ea0ecb7 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -588,6 +588,7 @@ type ModelProvider = | "ollama" | "huggingface-tgi" | "huggingface-inference-api" + | "kindo" | "llama.cpp" | "replicate" | "text-gen-webui" diff --git a/core/llm/llms/Kindo.ts b/core/llm/llms/Kindo.ts new file mode 100644 index 000000000..855e386de --- /dev/null +++ b/core/llm/llms/Kindo.ts @@ -0,0 +1,16 @@ +import { LLMOptions, ModelProvider } from "../.."; +import OpenAI from "./OpenAI"; + +class Kindo extends OpenAI { + static providerName: ModelProvider = "kindo"; + static defaultOptions: Partial = { + apiBase: "https://llm.kindo.ai/v1", + requestOptions: { + headers: { + "kindo-token-transaction-type": "CONTINUE" + } + } + }; +} + +export default Kindo; \ No newline at end of file diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index cd084207e..33c7d0406 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -22,6 +22,7 @@ import Gemini from "./Gemini"; import Groq from "./Groq"; import HuggingFaceInferenceAPI from "./HuggingFaceInferenceAPI"; import HuggingFaceTGI from "./HuggingFaceTGI"; +import Kindo from "./Kindo"; import LMStudio from "./LMStudio"; import LlamaCpp from "./LlamaCpp"; import Llamafile from "./Llamafile"; @@ -48,6 +49,7 @@ const LLMs = [ Together, HuggingFaceTGI, HuggingFaceInferenceAPI, + Kindo, LlamaCpp, OpenAI, LMStudio, diff --git a/docs/docs/reference/Model Providers/kindo.md b/docs/docs/reference/Model Providers/kindo.md new file mode 100644 index 000000000..442e30b10 --- /dev/null +++ b/docs/docs/reference/Model Providers/kindo.md @@ -0,0 +1,42 @@ +# Kindo +Kindo offers centralized control over your organization's AI operations, ensuring data protection and compliance with internal policies while supporting various commercial and open-source models. To get started, sign up [here](https://app.kindo.ai/), create your API key on the [API keys page](https://app.kindo.ai/settings/api), and choose a model from the list of supported models in the [plugins tab](https://app.kindo.ai/plugins). + +## Config Example + +```json title="~/.continue/config.json" +{ + "models": [ + { + "title": "Claude 3.5 Sonnet", + "provider": "kindo", + "model": "claude-3-5-sonnet-20240620", + "apiKey": "" + } + ] +} +``` + +## Tab Autocomplete Config Example + +```json title="~/.continue/config.json" +{ + "tabAutocompleteModel": [ + { + "title": "WhiteRabbitNeo", + "provider": "kindo", + "model": "/models/WhiteRabbitNeo-33B-DeepSeekCoder", + "apiKey": "" + }, + { + "title": "DeepSeek", + "provider": "kindo", + "model": "deepseek-ai/deepseek-coder-33b-instruct", + "apiKey": "" + } + ] +} +``` + +## Security + +To update your organization's model access, adjust the controls in [security settings](https://app.kindo.ai/security-settings). \ No newline at end of file From 872915b643bbe289adf743899f8c046dbca2a9f1 Mon Sep 17 00:00:00 2001 From: hbernie Date: Fri, 16 Aug 2024 15:25:08 -0700 Subject: [PATCH 08/53] Add to model-providers --- docs/docs/setup/model-providers.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/setup/model-providers.md b/docs/docs/setup/model-providers.md index ab774d242..db79d5e33 100644 --- a/docs/docs/setup/model-providers.md +++ b/docs/docs/setup/model-providers.md @@ -63,6 +63,7 @@ You can deploy a model in your [AWS](https://github.com/continuedev/deploy-os-co You can access both open-source and commercial LLMs via: - [OpenRouter](../reference/Model%20Providers/openrouter.md) +- [Kindo](../reference/Model%20Providers/kindo.md) ### Open-source models From fd9fa36e27aa436a39ee2baf6e6a1b839978f73a Mon Sep 17 00:00:00 2001 From: Cheng Zhu Date: Sun, 18 Aug 2024 17:53:39 -0700 Subject: [PATCH 09/53] added @ open files context provider "pinned" option. --- .../continue/IdeProtocolClient.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt index e8aa27b6c..cead14fbf 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt @@ -31,6 +31,7 @@ import com.intellij.openapi.extensions.PluginId import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.fileEditor.TextEditor +import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl import com.intellij.openapi.progress.DumbProgressIndicator import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.project.DumbAware @@ -44,6 +45,8 @@ import com.intellij.openapi.wm.WindowManager import com.intellij.psi.PsiDocumentManager import com.intellij.testFramework.LightVirtualFile import com.intellij.ui.awt.RelativePoint +import com.intellij.ui.content.ContentManagerUtil +import com.intellij.util.concurrency.annotations.RequiresEdt import kotlinx.coroutines.* import java.awt.Toolkit import java.awt.datatransfer.StringSelection @@ -605,8 +608,10 @@ class IdeProtocolClient ( respond(currentFile) } "getPinnedFiles" -> { - val openFiles = visibleFiles() - respond(openFiles) + ApplicationManager.getApplication().invokeLater { + val pinnedFiles = pinnedFiles() + respond(pinnedFiles) + } } "insertAtCursor" -> { val msg = data as Map; @@ -964,6 +969,14 @@ class IdeProtocolClient ( return fileEditorManager.openFiles.toList().map { it.path } } + @RequiresEdt + private fun pinnedFiles(): List { + val fileEditorManager = FileEditorManager.getInstance(project) as? FileEditorManagerImpl ?: return listOf() + val openFiles = fileEditorManager.openFiles.map { it.path }.toList() + val pinnedFiles = fileEditorManager.windows.flatMap { window -> window.files.filter { window.isFilePinned(it) } }.map { it.path }.toSet() + return openFiles.intersect(pinnedFiles).toList() + } + private fun currentFile(): String? { val fileEditorManager = FileEditorManager.getInstance(project) val editor = fileEditorManager.selectedTextEditor From 41e1eb582bec8676fc973c3a2b76259344fbb317 Mon Sep 17 00:00:00 2001 From: Priyash Patil <38959321+priyashpatil@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:51:03 +0530 Subject: [PATCH 10/53] fix(gui): passing style props on StyledTooltip --- gui/src/components/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gui/src/components/index.tsx b/gui/src/components/index.tsx index a186d0e6b..eac6bf022 100644 --- a/gui/src/components/index.tsx +++ b/gui/src/components/index.tsx @@ -192,7 +192,12 @@ const TooltipStyles = { }; export function StyledTooltip(props: any) { - return ; + const combinedStyles = { + ...TooltipStyles, + ...props.style, // Merge any additional styles passed via props + }; + + return ; } export const TextArea = styled.textarea` From acea620043d2c48826266d4f1f73eaf42819f0c6 Mon Sep 17 00:00:00 2001 From: Priyash Patil <38959321+priyashpatil@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:57:44 +0530 Subject: [PATCH 11/53] fix(core): delete indexed docs if re-indexing --- core/indexing/docs/DocsService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index dbf1910dc..efd679290 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -291,8 +291,8 @@ export default class DocsService { status: "indexing", }; - // Clear old index if re-indexing. - if (reIndex) { + // Delete indexed docs if re-indexing + if (reIndex && await this.has(startUrl.toString())) { console.log("Deleting old embeddings"); await this.delete(startUrl); } From e8add8253a0368bdb63172eafcc2da82df698a27 Mon Sep 17 00:00:00 2001 From: anrgct Date: Tue, 20 Aug 2024 22:20:54 +0800 Subject: [PATCH 12/53] Fix passing codebaseContext parameter and InputToolbar flickering --- core/config/load.ts | 4 ++- gui/src/components/mainInput/TipTapEditor.tsx | 28 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/core/config/load.ts b/core/config/load.ts index a9b2ba94f..2bb836d73 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -355,9 +355,11 @@ async function intermediateToFinalConfig( // These context providers are always included, regardless of what, if anything, // the user has configured in config.json + + const codebaseContextParams = ((config.contextProviders || []).filter(isContextProviderWithParams).find(cp => cp.name === "codebase") as ContextProviderWithParams | undefined)?.params || {}; const DEFAULT_CONTEXT_PROVIDERS = [ new FileContextProvider({}), - new CodebaseContextProvider({}), + new CodebaseContextProvider(codebaseContextParams), ]; const DEFAULT_CONTEXT_PROVIDERS_TITLES = DEFAULT_CONTEXT_PROVIDERS.map( diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 8ab8f190e..83752c95f 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -56,6 +56,7 @@ import { getSlashCommandDropdownOptions, } from "./getSuggestion"; import { ComboBoxItem } from "./types"; +import { debounce } from "lodash"; const InputBoxDiv = styled.div` resize: none; @@ -473,6 +474,31 @@ function TipTapEditor(props: TipTapEditorProps) { }, }); + const [shouldHideToolbar, setShouldHideToolbar] = useState(false); + const debouncedShouldHideToolbar = debounce((value) => { + setShouldHideToolbar(value); + }, 200); + + useEffect(() => { + if (editor) { + const handleFocus = () => { + debouncedShouldHideToolbar(false); + } + + const handleBlur = () => { + debouncedShouldHideToolbar(true); + }; + + editor.on('focus', handleFocus); + editor.on('blur', handleBlur); + + return () => { + editor.off('focus', handleFocus); + editor.off('blur', handleBlur); + }; + } + }, [editor]); + const editorFocusedRef = useUpdatingRef(editor?.isFocused, [editor]); useEffect(() => { @@ -831,7 +857,7 @@ function TipTapEditor(props: TipTapEditorProps) { />