mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
isRunning: tool | message
This commit is contained in:
parent
4a06d79170
commit
f2caa9876c
4 changed files with 13 additions and 11 deletions
|
|
@ -108,7 +108,7 @@ export type ThreadsState = {
|
||||||
export type ThreadStreamState = {
|
export type ThreadStreamState = {
|
||||||
[threadId: string]: undefined | {
|
[threadId: string]: undefined | {
|
||||||
// state related
|
// state related
|
||||||
isRunning?: undefined | true; // whether or not actually running the agent loop (can be running and not streaming, like if it's calling a tool and awaiting user response)
|
isRunning?: undefined | 'message' | 'tool'; // whether or not actually running the agent loop (can be running and not streaming, like if it's calling a tool and awaiting user response)
|
||||||
error?: { message: string, fullError: Error | null, };
|
error?: { message: string, fullError: Error | null, };
|
||||||
|
|
||||||
// streaming related
|
// streaming related
|
||||||
|
|
@ -722,6 +722,7 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. call the tool
|
// 3. call the tool
|
||||||
|
this._setStreamState(threadId, { isRunning: 'tool' }, 'merge')
|
||||||
try {
|
try {
|
||||||
toolResult = await this._toolsService.callTool[toolName](toolParams as any) // ts is bad...
|
toolResult = await this._toolsService.callTool[toolName](toolParams as any) // ts is bad...
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -748,8 +749,8 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
const { chatMode } = this._settingsService.state.globalSettings // should not change as we loop even if user changes it, so it goes here
|
const { chatMode } = this._settingsService.state.globalSettings // should not change as we loop even if user changes it, so it goes here
|
||||||
const tools = this._tools(chatMode)
|
const tools = this._tools(chatMode)
|
||||||
|
|
||||||
// clear any previous error + set running
|
// clear any previous error
|
||||||
this._setStreamState(threadId, { isRunning: true, error: undefined }, 'set')
|
this._setStreamState(threadId, { error: undefined }, 'set')
|
||||||
|
|
||||||
let nMessagesSent = 0
|
let nMessagesSent = 0
|
||||||
let shouldSendAnotherMessage = true
|
let shouldSendAnotherMessage = true
|
||||||
|
|
@ -757,11 +758,13 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
|
|
||||||
// before enter loop, call tool
|
// before enter loop, call tool
|
||||||
if (callThisToolFirst) {
|
if (callThisToolFirst) {
|
||||||
|
this._setStreamState(threadId, { isRunning: 'tool' }, 'merge')
|
||||||
await handleToolCall(callThisToolFirst, { preapproved: true, toolParams: callThisToolFirst.params })
|
await handleToolCall(callThisToolFirst, { preapproved: true, toolParams: callThisToolFirst.params })
|
||||||
}
|
}
|
||||||
|
|
||||||
// tool use loop
|
// tool use loop
|
||||||
while (shouldSendAnotherMessage) {
|
while (shouldSendAnotherMessage) {
|
||||||
|
this._setStreamState(threadId, { isRunning: 'message' }, 'merge')
|
||||||
|
|
||||||
// false by default each iteration
|
// false by default each iteration
|
||||||
shouldSendAnotherMessage = false
|
shouldSendAnotherMessage = false
|
||||||
|
|
|
||||||
|
|
@ -1912,8 +1912,7 @@ export const SidebarChat = () => {
|
||||||
|
|
||||||
// stream state
|
// stream state
|
||||||
const currThreadStreamState = useChatThreadsStreamState(chatThreadsState.currentThreadId)
|
const currThreadStreamState = useChatThreadsStreamState(chatThreadsState.currentThreadId)
|
||||||
const isRunning = !!currThreadStreamState?.isRunning
|
const isRunning = currThreadStreamState?.isRunning
|
||||||
const isStreaming = !!currThreadStreamState?.streamingToken // might be running but not streaming
|
|
||||||
const latestError = currThreadStreamState?.error
|
const latestError = currThreadStreamState?.error
|
||||||
const messageSoFar = currThreadStreamState?.messageSoFar
|
const messageSoFar = currThreadStreamState?.messageSoFar
|
||||||
const reasoningSoFar = currThreadStreamState?.reasoningSoFar
|
const reasoningSoFar = currThreadStreamState?.reasoningSoFar
|
||||||
|
|
@ -1978,7 +1977,7 @@ export const SidebarChat = () => {
|
||||||
|
|
||||||
const previousMessagesHTML = useMemo(() => {
|
const previousMessagesHTML = useMemo(() => {
|
||||||
return previousMessages.map((message, i) => {
|
return previousMessages.map((message, i) => {
|
||||||
const isLast = i === numMessages - 1 && !isStreaming // last if there is no streaming assistant message currently
|
const isLast = i === numMessages - 1 && isRunning !== 'tool'
|
||||||
return <ChatBubble key={getChatBubbleId(currentThread.id, i)}
|
return <ChatBubble key={getChatBubbleId(currentThread.id, i)}
|
||||||
chatMessage={message}
|
chatMessage={message}
|
||||||
messageIdx={i}
|
messageIdx={i}
|
||||||
|
|
@ -1987,10 +1986,10 @@ export const SidebarChat = () => {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}, [previousMessages, isStreaming, currentThread, numMessages])
|
}, [previousMessages, isRunning, currentThread, numMessages])
|
||||||
|
|
||||||
const streamingChatIdx = previousMessagesHTML.length
|
const streamingChatIdx = previousMessagesHTML.length
|
||||||
const currStreamingMessageHTML = !!(reasoningSoFar || messageSoFar || isRunning || isStreaming) ?
|
const currStreamingMessageHTML = !!(reasoningSoFar || messageSoFar || isRunning) ?
|
||||||
<ChatBubble key={getChatBubbleId(currentThread.id, streamingChatIdx)}
|
<ChatBubble key={getChatBubbleId(currentThread.id, streamingChatIdx)}
|
||||||
chatMessage={{
|
chatMessage={{
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
|
|
@ -2062,7 +2061,7 @@ export const SidebarChat = () => {
|
||||||
divRef={chatAreaRef}
|
divRef={chatAreaRef}
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
onAbort={onAbort}
|
onAbort={onAbort}
|
||||||
isStreaming={isRunning}
|
isStreaming={!!isRunning}
|
||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
showSelections={true}
|
showSelections={true}
|
||||||
showProspectiveSelections={previousMessagesHTML.length === 0}
|
showProspectiveSelections={previousMessagesHTML.length === 0}
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ export const SidebarThreadSelector = () => {
|
||||||
`}
|
`}
|
||||||
onClick={() => chatThreadsService.switchToThread(pastThread.id)}
|
onClick={() => chatThreadsService.switchToThread(pastThread.id)}
|
||||||
onDoubleClick={() => sidebarStateService.setState({ isHistoryOpen: false })}
|
onDoubleClick={() => sidebarStateService.setState({ isHistoryOpen: false })}
|
||||||
title={new Date(pastThread.createdAt).toLocaleString()}
|
title={new Date(pastThread.lastModified).toLocaleString()}
|
||||||
>
|
>
|
||||||
<div className='truncate'>{`${firstMsg}`}</div>
|
<div className='truncate'>{`${firstMsg}`}</div>
|
||||||
<div>{`\u00A0(${numMessages})`}</div>
|
<div>{`\u00A0(${numMessages})`}</div>
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export const editToolDesc_toolDescription = `\
|
||||||
A high level description of the change you'd like to make in the file. This description will be handed to a dumber, faster model that will quickly apply the change.\
|
A high level description of the change you'd like to make in the file. This description will be handed to a dumber, faster model that will quickly apply the change.\
|
||||||
The model does not have ANY context except the file content and this description, so make sure to include all necessary information to make the change here.\
|
The model does not have ANY context except the file content and this description, so make sure to include all necessary information to make the change here.\
|
||||||
Typically the best description you can give is a code block of the form:\n${tripleTick[0]}\n// ... existing code ...\n{{change 1}}\n// ... existing code ...\n{{change2}}\n// ... existing code ...\n{{change 3}}\n...\n${tripleTick[1]}. \
|
Typically the best description you can give is a code block of the form:\n${tripleTick[0]}\n// ... existing code ...\n{{change 1}}\n// ... existing code ...\n{{change2}}\n// ... existing code ...\n{{change 3}}\n...\n${tripleTick[1]}. \
|
||||||
Do NOT output the whole file here if possible, and try to write as LITTLE code as needed to describe the change.`
|
Wrap your output in triple ticks. Do NOT output the whole file here if possible, and try to write as LITTLE code as needed to describe the change.`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue