From 0855376e022d2b4591a45edd4a3dbe6e18269788 Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Wed, 4 Dec 2024 21:36:33 -0800 Subject: [PATCH] update message display --- .../react/src/markdown/MarkdownRender.tsx | 2 +- .../react/src/sidebar-tsx/ErrorDisplay.tsx | 3 +- .../react/src/sidebar-tsx/SidebarChat.tsx | 57 ++++++------------- .../src/sidebar-tsx/SidebarThreadSelector.tsx | 17 ++++-- .../contrib/void/browser/registerThreads.ts | 39 +++---------- 5 files changed, 39 insertions(+), 79 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/react/src/markdown/MarkdownRender.tsx b/src/vs/workbench/contrib/void/browser/react/src/markdown/MarkdownRender.tsx index ce41e17c..e17beb37 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/markdown/MarkdownRender.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/markdown/MarkdownRender.tsx @@ -212,7 +212,7 @@ const RenderToken = ({ token, nested = false }: { token: Token | string, nested? } export const MarkdownRender = ({ string, nested = false }: { string: string, nested?: boolean }) => { - const tokens = marked.lexer(string ?? '(empty)'); // https://marked.js.org/using_pro#renderer + const tokens = marked.lexer(string); // https://marked.js.org/using_pro#renderer return ( <> {tokens.map((token, index) => ( diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/ErrorDisplay.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/ErrorDisplay.tsx index c137d56f..af205dd3 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/ErrorDisplay.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/ErrorDisplay.tsx @@ -68,7 +68,6 @@ export const ErrorDisplay = ({ error, onDismiss = null, showDismiss = true, - className = '' }: { error: Error | object | string, onDismiss: (() => void) | null, @@ -81,7 +80,7 @@ export const ErrorDisplay = ({ const hasDetails = details.cause || Object.keys(details.additional).length > 0; return ( -
+
{/* Header */}
diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index 9bb7a9e1..31909bba 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -8,7 +8,7 @@ import React, { FormEvent, Fragment, useCallback, useEffect, useRef, useState } import { useConfigState, useService, useThreadsState } from '../util/services.js'; import { generateDiffInstructions } from '../../../prompt/systemPrompts.js'; import { userInstructionsStr } from '../../../prompt/stringifyFiles.js'; -import { CodeSelection, CodeStagingSelection } from '../../../registerThreads.js'; +import { ChatMessage, CodeSelection, CodeStagingSelection } from '../../../registerThreads.js'; import { BlockCode } from '../markdown/BlockCode.js'; import { MarkdownRender } from '../markdown/MarkdownRender.js'; @@ -20,8 +20,6 @@ import { ErrorDisplay } from './ErrorDisplay.js'; import { LLMMessageServiceParams } from '../../../../../../../platform/void/common/llmMessageTypes.js'; import { getCmdKey } from '../../../getCmdKey.js' -import { VSCodeDropdown } from '@vscode/webview-ui-toolkit/react'; - // read files from VSCode const VSReadFile = async (modelService: IModelService, uri: URI): Promise => { const model = modelService.getModel(uri) @@ -30,27 +28,6 @@ const VSReadFile = async (modelService: IModelService, uri: URI): Promise { // 'unixify' path pathStr = pathStr.replace(/[/\\]+/g, '/') // replace any / or \ or \\ with / @@ -174,7 +151,7 @@ export const SidebarChat = () => { const [instructions, setInstructions] = useState('') // the user's instructions // state of chat - const [messageStream, setMessageStream] = useState('') + const [messageStream, setMessageStream] = useState(null) const [isLoading, setIsLoading] = useState(false) const latestRequestIdRef = useRef(null) @@ -204,8 +181,8 @@ export const SidebarChat = () => { threadsStateService.addMessageToCurrentThread(systemPromptElt) const userContent = userInstructionsStr(instructions, selections) - const newHistoryElt: ChatMessage = { role: 'user', content: userContent, displayContent: instructions, selections } - threadsStateService.addMessageToCurrentThread(newHistoryElt) + const userHistoryElt: ChatMessage = { role: 'user', content: userContent, displayContent: instructions, selections } + threadsStateService.addMessageToCurrentThread(userHistoryElt) const currentThread = threadsStateService.getCurrentThread(threadsStateService.state) // the the instant state right now, don't wait for the React state @@ -214,24 +191,24 @@ export const SidebarChat = () => { const object: LLMMessageServiceParams = { logging: { loggingName: 'Chat' }, - messages: [...(currentThread?.messages ?? []).map(m => ({ role: m.role, content: m.content })),], + messages: [...(currentThread?.messages ?? []).map(m => ({ role: m.role, content: m.content || '(null)' })),], onText: ({ newText, fullText }) => setMessageStream(fullText), onFinalMessage: ({ fullText: content }) => { console.log('chat: running final message') // add assistant's message to chat history, and clear selection - const newHistoryElt: ChatMessage = { role: 'assistant', content, displayContent: content } - threadsStateService.addMessageToCurrentThread(newHistoryElt) - setMessageStream('') + const assistantHistoryElt: ChatMessage = { role: 'assistant', content, displayContent: content || null } + threadsStateService.addMessageToCurrentThread(assistantHistoryElt) + setMessageStream(null) setIsLoading(false) }, onError: ({ error }) => { console.log('chat: running error', error) // add assistant's message to chat history, and clear selection - let content = messageStream; // just use the current content - const newHistoryElt: ChatMessage = { role: 'assistant', content, displayContent: content, } - threadsStateService.addMessageToCurrentThread(newHistoryElt) + let content = messageStream ?? ''; // just use the current content + const assistantHistoryElt: ChatMessage = { role: 'assistant', content, displayContent: content || null, } + threadsStateService.addMessageToCurrentThread(assistantHistoryElt) setMessageStream('') setIsLoading(false) @@ -259,9 +236,9 @@ export const SidebarChat = () => { sendLLMMessageService.abort(latestRequestIdRef.current) // if messageStream was not empty, add it to the history - const llmContent = messageStream || '(empty)' - const newHistoryElt: ChatMessage = { role: 'assistant', content: llmContent, displayContent: messageStream, } - threadsStateService.addMessageToCurrentThread(newHistoryElt) + const llmContent = messageStream ?? '' + const assistantHistoryElt: ChatMessage = { role: 'assistant', content: llmContent, displayContent: messageStream || null, } + threadsStateService.addMessageToCurrentThread(assistantHistoryElt) setMessageStream('') setIsLoading(false) @@ -280,7 +257,7 @@ export const SidebarChat = () => { )} {/* message stream */} - +
{/* chatbar */}
@@ -331,7 +308,7 @@ export const SidebarChat = () => { \n \n ))}\n \n \n
\n );\n};\n\nexport default Sidebar;\n```\n\nSELECTION\n``` \n-
    \n- {items.map((item, index) => (\n-\t
  • \n-\t onItemSelect?.(item.label)}\n-\t >\n-\t\t{item.label}\n-\t \n-\t
  • \n- ))}\n-
\n-\n-
\n+
\n+
    \n+ {items.map((item, index) => (\n+\t
  • \n+\t onItemSelect?.(item.label)}\n+\t >\n+\t\t{item.label}\n+\t
\n+\t\n+ ))}\n+\n+
\n+ Extra Action\n+
\n+
\n```\n" -// }, -// { -// "role": "user", -// "content": "test", -// "displayContent": "test", -// "selections": null -// }, -// { -// "role": "assistant", -// "content": { -// "requestId": "49d4c9e6-5e53-4768-a77e-5c297223fa9c", -// "fullText": "I apologize, but I don't have enough context to provide a meaningful response based on just the word \"test\". If you have a specific question or topic you'd like me to assist with, please provide more details or context so I can better understand how to help you. I'm here to engage in conversation and provide information to the best of my abilities." -// }, -// "displayContent": { -// "requestId": "49d4c9e6-5e53-4768-a77e-5c297223fa9c", -// "fullText": "I apologize, but I don't have enough context to provide a meaningful response based on just the word \"test\". If you have a specific question or topic you'd like me to assist with, please provide more details or context so I can better understand how to help you. I'm here to engage in conversation and provide information to the best of my abilities." -// } -// } -// ]