edit message bug fixes

This commit is contained in:
Mathew Pareles 2025-03-02 00:04:41 -08:00
parent 027c0ee6bd
commit a6c9b5f089
3 changed files with 46 additions and 4 deletions

View file

@ -176,6 +176,9 @@ export interface IChatThreadService {
getCurrentThreadState: () => ThreadType['state']
setCurrentThreadState: (newState: Partial<ThreadType['state']>) => void
closeStagingSelectionsInCurrentThread(): void;
closeStagingSelectionsInMessage(messageIdx: number): void;
// call to edit a message
editUserMessageAndStreamResponse({ userMessage, chatMode, messageIdx }: { userMessage: string, chatMode: ChatMode, messageIdx: number }): Promise<void>;
@ -657,6 +660,35 @@ class ChatThreadService extends Disposable implements IChatThreadService {
}
closeStagingSelectionsInCurrentThread = () => {
const currThread = this.getCurrentThreadState()
// close all stagingSelections
const closedStagingSelections = currThread.stagingSelections.map(s => ({ ...s, state: { ...s.state, isOpened: false } }))
const newThread = currThread
newThread.stagingSelections = closedStagingSelections
this.setCurrentThreadState(newThread)
}
closeStagingSelectionsInMessage = (messageIdx: number) => {
const currMessage = this.getCurrentMessageState(messageIdx)
// close all stagingSelections
const closedStagingSelections = currMessage.stagingSelections.map(s => ({ ...s, state: { ...s.state, isOpened: false } }))
const newMessage = currMessage
newMessage.stagingSelections = closedStagingSelections
this.setCurrentMessageState(messageIdx, newMessage)
}
getCurrentThreadState = () => {
const currentThread = this.getCurrentThread()
return currentThread.state

View file

@ -418,7 +418,7 @@ export const SelectedFiles = (
{allSelections.map((selection, i) => {
const isThisSelectionOpened = (!!selection.selectionStr && selection.state.isOpened) //!!(selection.selectionStr && selectionIsOpened[i])
const isThisSelectionOpened = (!!selection.selectionStr && selection.state.isOpened && type === 'staging')
const isThisSelectionAFile = selection.selectionStr === null
const isThisSelectionProspective = i > selections.length - 1
@ -501,7 +501,7 @@ export const SelectedFiles = (
{isThisSelectionOpened ?
<div
className={`
w-full px-1 rounded-sm border-vscode-editor-border
w-full rounded-sm border-vscode-editor-border
${isThisSelectionOpened ? 'ring-1 ring-[#007FD4]' : ''}
`}
onClick={(e) => {
@ -923,9 +923,10 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
const thread = chatThreadsService.getCurrentThread()
chatThreadsService.cancelStreaming(thread.id)
// reset state
// update state
setIsBeingEdited(false)
chatThreadsService.setFocusedMessageIdx(undefined)
chatThreadsService.closeStagingSelectionsInMessage(messageIdx)
// stream the edit
const userMessage = textAreaRefState.value;
@ -1064,7 +1065,13 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
: role === 'user' ? 'p-2 flex flex-col gap-1 bg-void-bg-1 text-void-fg-1 overflow-x-auto'
: role === 'assistant' ? 'px-2 overflow-x-auto' : ''
}
${role === 'user' && mode === 'display' ? 'cursor-pointer' : ''}
`}
onClick={() => {
if (role === 'user' && mode === 'display') {
onOpenEdit()
}
}}
>
{chatbubbleContents}
{isLoading && <IconLoading className='opacity-50 text-sm px-2' />}
@ -1155,6 +1162,9 @@ export const SidebarChat = () => {
if (isDisabled) return
if (isStreaming) return
// update state
chatThreadsService.closeStagingSelectionsInCurrentThread() // close all selections
// send message to LLM
const userMessage = textAreaRef.current?.value ?? ''
await chatThreadsService.addUserMessageAndStreamResponse({ userMessage, chatMode: 'agent' })

View file

@ -57,7 +57,7 @@ export const defaultModelsOfProvider = {
],
anthropic: [ // https://docs.anthropic.com/en/docs/about-claude/models
'claude-3-7-sonnet-latest',
// 'claude-3-5-sonnet-latest',
'claude-3-5-sonnet-latest',
'claude-3-5-haiku-latest',
'claude-3-opus-latest',
],