isRunning: tool | message

This commit is contained in:
Andrew Pareles 2025-03-17 04:33:00 -07:00
parent 4a06d79170
commit f2caa9876c
4 changed files with 13 additions and 11 deletions

View file

@ -108,7 +108,7 @@ export type ThreadsState = {
export type ThreadStreamState = {
[threadId: string]: undefined | {
// 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, };
// streaming related
@ -722,6 +722,7 @@ class ChatThreadService extends Disposable implements IChatThreadService {
}
// 3. call the tool
this._setStreamState(threadId, { isRunning: 'tool' }, 'merge')
try {
toolResult = await this._toolsService.callTool[toolName](toolParams as any) // ts is bad...
} 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 tools = this._tools(chatMode)
// clear any previous error + set running
this._setStreamState(threadId, { isRunning: true, error: undefined }, 'set')
// clear any previous error
this._setStreamState(threadId, { error: undefined }, 'set')
let nMessagesSent = 0
let shouldSendAnotherMessage = true
@ -757,11 +758,13 @@ class ChatThreadService extends Disposable implements IChatThreadService {
// before enter loop, call tool
if (callThisToolFirst) {
this._setStreamState(threadId, { isRunning: 'tool' }, 'merge')
await handleToolCall(callThisToolFirst, { preapproved: true, toolParams: callThisToolFirst.params })
}
// tool use loop
while (shouldSendAnotherMessage) {
this._setStreamState(threadId, { isRunning: 'message' }, 'merge')
// false by default each iteration
shouldSendAnotherMessage = false

View file

@ -1912,8 +1912,7 @@ export const SidebarChat = () => {
// stream state
const currThreadStreamState = useChatThreadsStreamState(chatThreadsState.currentThreadId)
const isRunning = !!currThreadStreamState?.isRunning
const isStreaming = !!currThreadStreamState?.streamingToken // might be running but not streaming
const isRunning = currThreadStreamState?.isRunning
const latestError = currThreadStreamState?.error
const messageSoFar = currThreadStreamState?.messageSoFar
const reasoningSoFar = currThreadStreamState?.reasoningSoFar
@ -1978,7 +1977,7 @@ export const SidebarChat = () => {
const previousMessagesHTML = useMemo(() => {
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)}
chatMessage={message}
messageIdx={i}
@ -1987,10 +1986,10 @@ export const SidebarChat = () => {
/>
}
)
}, [previousMessages, isStreaming, currentThread, numMessages])
}, [previousMessages, isRunning, currentThread, numMessages])
const streamingChatIdx = previousMessagesHTML.length
const currStreamingMessageHTML = !!(reasoningSoFar || messageSoFar || isRunning || isStreaming) ?
const currStreamingMessageHTML = !!(reasoningSoFar || messageSoFar || isRunning) ?
<ChatBubble key={getChatBubbleId(currentThread.id, streamingChatIdx)}
chatMessage={{
role: 'assistant',
@ -2062,7 +2061,7 @@ export const SidebarChat = () => {
divRef={chatAreaRef}
onSubmit={onSubmit}
onAbort={onAbort}
isStreaming={isRunning}
isStreaming={!!isRunning}
isDisabled={isDisabled}
showSelections={true}
showProspectiveSelections={previousMessagesHTML.length === 0}

View file

@ -106,7 +106,7 @@ export const SidebarThreadSelector = () => {
`}
onClick={() => chatThreadsService.switchToThread(pastThread.id)}
onDoubleClick={() => sidebarStateService.setState({ isHistoryOpen: false })}
title={new Date(pastThread.createdAt).toLocaleString()}
title={new Date(pastThread.lastModified).toLocaleString()}
>
<div className='truncate'>{`${firstMsg}`}</div>
<div>{`\u00A0(${numMessages})`}</div>

View file

@ -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.\
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]}. \
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.`