diff --git a/extensions/void/src/extension.ts b/extensions/void/src/extension.ts index 4cd8ac26..953e89e4 100644 --- a/extensions/void/src/extension.ts +++ b/extensions/void/src/extension.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import { WebviewMessage } from './shared_types'; +import { ChatThread, WebviewMessage } from './shared_types'; import { CtrlKCodeLensProvider } from './CtrlKCodeLensProvider'; import { getDiffedLines } from './getDiffedLines'; import { ApprovalCodeLensProvider, SuggestedEdit } from './ApprovalCodeLensProvider'; @@ -124,6 +124,20 @@ export function activate(context: vscode.ExtensionContext) { webview.postMessage({ type: 'apiConfig', apiConfig } satisfies WebviewMessage) } + else if (m.type === 'getThreadHistory') { + + const threads: ChatThread[] = context.workspaceState.get('threadHistory') ?? [] + webview.postMessage({ type: 'threadHistory', threads } satisfies WebviewMessage) + } + else if (m.type === 'updateThread') { + + const threads: ChatThread[] = context.workspaceState.get('threadHistory') as [] ?? [] + const updatedThreads = threads.find((t: ChatThread) => t.id === m.thread.id) + ? threads.map((t: ChatThread) => t.id === m.thread.id ? m.thread : t) + : [...threads, m.thread] + context.workspaceState.update('threadHistory', updatedThreads) + webview.postMessage({ type: 'threadHistory', threads: updatedThreads } satisfies WebviewMessage) + } else { console.error('unrecognized command', m.type, m) diff --git a/extensions/void/src/shared_types.ts b/extensions/void/src/shared_types.ts index 4d7c0dc9..563f3ec8 100644 --- a/extensions/void/src/shared_types.ts +++ b/extensions/void/src/shared_types.ts @@ -27,13 +27,44 @@ type WebviewMessage = ( // editor -> sidebar | { type: 'apiConfig', apiConfig: ApiConfig } + // sidebar -> editor + | { type: 'getThreadHistory' } + + // editor -> sidebar + | { type: 'threadHistory', threads: ChatThread[] } + + // sidebar -> editor + | { type: 'updateThread', thread: ChatThread } + ) type Command = WebviewMessage['type'] +type ChatThread = { + id: string; + createdAt: string; + messages: ChatMessage[]; +} + +type ChatMessage = + | { + role: "user"; + content: string; // content sent to the llm + displayContent: string; // content displayed to user + selection: Selection | null; // the user's selection + files: vscode.Uri[]; // the files sent in the message + } + | { + role: "assistant"; + content: string; // content received from LLM + displayContent: string; // content displayed to user (this is the same as content for now) + } + export { Selection, File, WebviewMessage, Command, + ChatThread, + ChatMessage, } diff --git a/extensions/void/src/sidebar/getVscodeApi.ts b/extensions/void/src/sidebar/getVscodeApi.ts index 890b31f2..126207c7 100644 --- a/extensions/void/src/sidebar/getVscodeApi.ts +++ b/extensions/void/src/sidebar/getVscodeApi.ts @@ -9,7 +9,10 @@ const awaiting: { [c in Command]: ((res: any) => void)[] } = { "requestFiles": [], "files": [], "apiConfig": [], - "getApiConfig": [] + "getApiConfig": [], + "getThreadHistory": [], + "threadHistory": [], + "updateThread": [], } // use this function to await responses