mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
edits work
This commit is contained in:
parent
48defe849d
commit
893308c38e
2 changed files with 30 additions and 34 deletions
|
|
@ -36,7 +36,6 @@ export type StagingSelectionItem = CodeSelection | FileSelection
|
||||||
export type StagingInfo = {
|
export type StagingInfo = {
|
||||||
isBeingEdited: boolean;
|
isBeingEdited: boolean;
|
||||||
selections: StagingSelectionItem[] | null; // staging selections in edit mode
|
selections: StagingSelectionItem[] | null; // staging selections in edit mode
|
||||||
text: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -97,7 +96,6 @@ const newThreadObject = () => {
|
||||||
staging: {
|
staging: {
|
||||||
isBeingEdited: true,
|
isBeingEdited: true,
|
||||||
selections: [],
|
selections: [],
|
||||||
text: '',
|
|
||||||
}
|
}
|
||||||
} satisfies ChatThreads[string]
|
} satisfies ChatThreads[string]
|
||||||
}
|
}
|
||||||
|
|
@ -165,8 +163,6 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
// for now just write the version, anticipating bigger changes in the future where we'll want to access this
|
// for now just write the version, anticipating bigger changes in the future where we'll want to access this
|
||||||
this._storageService.store(THREAD_VERSION_KEY, THREAD_VERSION, StorageScope.APPLICATION, StorageTarget.USER)
|
this._storageService.store(THREAD_VERSION_KEY, THREAD_VERSION, StorageScope.APPLICATION, StorageTarget.USER)
|
||||||
|
|
||||||
|
|
||||||
setInterval(() => { console.log(this.getFocusedMessageIdx()) }, 1000)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -265,15 +261,12 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
...this.getCurrentThread().messages.map(m => ({ role: m.role, content: m.content || '(null)' })),
|
...this.getCurrentThread().messages.map(m => ({ role: m.role, content: m.content || '(null)' })),
|
||||||
],
|
],
|
||||||
onText: ({ newText, fullText }) => {
|
onText: ({ newText, fullText }) => {
|
||||||
console.log('onText', fullText)
|
|
||||||
this._setStreamState(threadId, { messageSoFar: fullText })
|
this._setStreamState(threadId, { messageSoFar: fullText })
|
||||||
},
|
},
|
||||||
onFinalMessage: ({ fullText: content }) => {
|
onFinalMessage: ({ fullText: content }) => {
|
||||||
console.log('finalMessage', JSON.stringify(content))
|
|
||||||
this.finishStreaming(threadId, content)
|
this.finishStreaming(threadId, content)
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
console.log('onError', content)
|
|
||||||
this.finishStreaming(threadId, this.streamState[threadId]?.messageSoFar ?? '', error)
|
this.finishStreaming(threadId, this.streamState[threadId]?.messageSoFar ?? '', error)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -322,8 +315,6 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
}
|
}
|
||||||
|
|
||||||
switchToThread(threadId: string) {
|
switchToThread(threadId: string) {
|
||||||
// console.log('threadId', threadId)
|
|
||||||
// console.log('messages', this.state.allThreads[threadId].messages)
|
|
||||||
this._setState({ currentThreadId: threadId }, true)
|
this._setState({ currentThreadId: threadId }, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -413,11 +404,8 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
// set thread.stagingSelections
|
// set thread.stagingSelections
|
||||||
private setDefaultStaging(staging: StagingInfo): void {
|
private setDefaultStaging(staging: StagingInfo): void {
|
||||||
|
|
||||||
console.log('Default1')
|
|
||||||
const thread = this.getCurrentThread()
|
const thread = this.getCurrentThread()
|
||||||
|
|
||||||
console.log('Default2')
|
|
||||||
|
|
||||||
this._setState({
|
this._setState({
|
||||||
allThreads: {
|
allThreads: {
|
||||||
...this.state.allThreads,
|
...this.state.allThreads,
|
||||||
|
|
|
||||||
|
|
@ -539,13 +539,13 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
|
||||||
|
|
||||||
const role = chatMessage.role
|
const role = chatMessage.role
|
||||||
|
|
||||||
|
|
||||||
const accessor = useAccessor()
|
const accessor = useAccessor()
|
||||||
const chatThreadsService = accessor.get('IChatThreadService')
|
const chatThreadsService = accessor.get('IChatThreadService')
|
||||||
|
|
||||||
// edit mode state
|
// edit mode state
|
||||||
const [staging, setStaging] = chatThreadsService._useFocusedStagingState(messageIdx)
|
const [staging, setStaging] = chatThreadsService._useFocusedStagingState(messageIdx)
|
||||||
const mode: ChatBubbleMode = staging.isBeingEdited ? 'edit' : 'display'
|
const mode: ChatBubbleMode = staging.isBeingEdited ? 'edit' : 'display'
|
||||||
|
const [isFocused, setIsFocused] = useState(false)
|
||||||
const [isHovered, setIsHovered] = useState(false)
|
const [isHovered, setIsHovered] = useState(false)
|
||||||
const [isDisabled, setIsDisabled] = useState(false)
|
const [isDisabled, setIsDisabled] = useState(false)
|
||||||
const [textAreaRefState, setTextAreaRef] = useState<HTMLTextAreaElement | null>(null)
|
const [textAreaRefState, setTextAreaRef] = useState<HTMLTextAreaElement | null>(null)
|
||||||
|
|
@ -560,7 +560,6 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
|
||||||
setStaging({
|
setStaging({
|
||||||
...staging,
|
...staging,
|
||||||
selections: chatMessage.selections || [],
|
selections: chatMessage.selections || [],
|
||||||
text: chatMessage.displayContent || '',
|
|
||||||
})
|
})
|
||||||
if (textAreaFnsRef.current)
|
if (textAreaFnsRef.current)
|
||||||
textAreaFnsRef.current.setValue(chatMessage.displayContent || '')
|
textAreaFnsRef.current.setValue(chatMessage.displayContent || '')
|
||||||
|
|
@ -575,6 +574,18 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
|
||||||
|
|
||||||
const EditSymbol = mode === 'display' ? Pencil : X
|
const EditSymbol = mode === 'display' ? Pencil : X
|
||||||
|
|
||||||
|
const onOpenEdit = () => {
|
||||||
|
setStaging({ ...staging, isBeingEdited: true })
|
||||||
|
chatThreadsService.setFocusedMessageIdx(messageIdx)
|
||||||
|
_justEnabledEdit.current = true
|
||||||
|
}
|
||||||
|
const onCloseEdit = () => {
|
||||||
|
setIsFocused(false)
|
||||||
|
setIsHovered(false)
|
||||||
|
setStaging({ ...staging, isBeingEdited: false })
|
||||||
|
chatThreadsService.setFocusedMessageIdx(undefined)
|
||||||
|
|
||||||
|
}
|
||||||
// set chat bubble contents
|
// set chat bubble contents
|
||||||
let chatbubbleContents: React.ReactNode
|
let chatbubbleContents: React.ReactNode
|
||||||
if (role === 'user') {
|
if (role === 'user') {
|
||||||
|
|
@ -612,7 +623,7 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
|
||||||
|
|
||||||
const onKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
const onKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
setStaging({ ...staging, isBeingEdited: false })
|
onCloseEdit()
|
||||||
}
|
}
|
||||||
if (e.key === 'Enter' && !e.shiftKey) {
|
if (e.key === 'Enter' && !e.shiftKey) {
|
||||||
onSubmit()
|
onSubmit()
|
||||||
|
|
@ -640,7 +651,13 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
|
||||||
className='min-h-[81px] max-h-[500px] p-1'
|
className='min-h-[81px] max-h-[500px] p-1'
|
||||||
placeholder="Edit your message..."
|
placeholder="Edit your message..."
|
||||||
onChangeText={(text) => setIsDisabled(!text)}
|
onChangeText={(text) => setIsDisabled(!text)}
|
||||||
onFocus={() => { console.log('CHAT FOCUS'); chatThreadsService.setFocusedMessageIdx(messageIdx) }}
|
onFocus={() => {
|
||||||
|
setIsFocused(true)
|
||||||
|
chatThreadsService.setFocusedMessageIdx(messageIdx);
|
||||||
|
}}
|
||||||
|
onBlur={() => {
|
||||||
|
setIsFocused(false)
|
||||||
|
}}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
fnsRef={textAreaFnsRef}
|
fnsRef={textAreaFnsRef}
|
||||||
multiline={true}
|
multiline={true}
|
||||||
|
|
@ -669,8 +686,11 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
|
||||||
// style chatbubble according to role
|
// style chatbubble according to role
|
||||||
className={`
|
className={`
|
||||||
text-left rounded-lg
|
text-left rounded-lg
|
||||||
overflow-x-auto max-w-full
|
max-w-full
|
||||||
${role === 'user' ? 'p-2 bg-void-bg-1 text-void-fg-1' : 'px-2'}
|
${mode === 'edit' ? ''
|
||||||
|
: role === 'user' ? 'p-2 bg-void-bg-1 text-void-fg-1 overflow-x-auto'
|
||||||
|
: role === 'assistant' ? 'px-2 overflow-x-auto' : ''
|
||||||
|
}
|
||||||
`}
|
`}
|
||||||
>
|
>
|
||||||
{chatbubbleContents}
|
{chatbubbleContents}
|
||||||
|
|
@ -687,16 +707,13 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
|
||||||
p-[2px]
|
p-[2px]
|
||||||
bg-void-bg-1 border border-void-border-1 rounded-md
|
bg-void-bg-1 border border-void-border-1 rounded-md
|
||||||
transition-opacity duration-200 ease-in-out
|
transition-opacity duration-200 ease-in-out
|
||||||
${isHovered ? 'opacity-100' : 'opacity-0'}
|
${isHovered || (isFocused && mode === 'edit') ? 'opacity-100' : 'opacity-0'}
|
||||||
`}
|
`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (mode === 'display') {
|
if (mode === 'display') {
|
||||||
setStaging({ ...staging, isBeingEdited: true })
|
onOpenEdit()
|
||||||
chatThreadsService.setFocusedMessageIdx(messageIdx)
|
|
||||||
_justEnabledEdit.current = true
|
|
||||||
} else if (mode === 'edit') {
|
} else if (mode === 'edit') {
|
||||||
setStaging({ ...staging, isBeingEdited: false })
|
onCloseEdit()
|
||||||
chatThreadsService.setFocusedMessageIdx(undefined)
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>}
|
/>}
|
||||||
|
|
@ -757,25 +774,16 @@ export const SidebarChat = () => {
|
||||||
|
|
||||||
const onSubmit = useCallback(async () => {
|
const onSubmit = useCallback(async () => {
|
||||||
|
|
||||||
console.log('onSubmit')
|
|
||||||
|
|
||||||
if (isDisabled) return
|
if (isDisabled) return
|
||||||
if (isStreaming) return
|
if (isStreaming) return
|
||||||
|
|
||||||
// send message to LLM
|
// send message to LLM
|
||||||
const userMessage = textAreaRef.current?.value ?? ''
|
const userMessage = textAreaRef.current?.value ?? ''
|
||||||
console.log('userMessage', userMessage)
|
|
||||||
console.log('streaming...',)
|
|
||||||
await chatThreadsService.addUserMessageAndStreamResponse(userMessage)
|
await chatThreadsService.addUserMessageAndStreamResponse(userMessage)
|
||||||
console.log('done streaming',)
|
|
||||||
|
|
||||||
setStaging({ ...staging, selections: [], text: '' }) // clear staging
|
setStaging({ ...staging, selections: [], }) // clear staging
|
||||||
console.log('set staging',)
|
|
||||||
textAreaFnsRef.current?.setValue('')
|
textAreaFnsRef.current?.setValue('')
|
||||||
console.log('set value',)
|
|
||||||
textAreaRef.current?.focus() // focus input after submit
|
textAreaRef.current?.focus() // focus input after submit
|
||||||
console.log('textAreaRef', textAreaRef.current)
|
|
||||||
console.log('focus',)
|
|
||||||
|
|
||||||
}, [chatThreadsService, isDisabled, isStreaming, textAreaRef, textAreaFnsRef, staging, setStaging])
|
}, [chatThreadsService, isDisabled, isStreaming, textAreaRef, textAreaFnsRef, staging, setStaging])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue