wip, at least prettier likes it

This commit is contained in:
Glen Maddern 2025-06-25 17:13:45 +10:00
commit 52c3e8d727

View file

@ -159,8 +159,6 @@ export const useStreamResponse = ({
// Use fullStream to get all events including tool calls, results, and text
for await (const event of result.fullStream) {
console.log(JSON.stringify(event))
try {
if (event.type === 'reasoning') {
setConversations((prev) => {
const updated = [...prev]
const conv = updated.find((c) => c.id === conversationId)
@ -169,7 +167,8 @@ export const useStreamResponse = ({
return updated
}
const lastMessage = conv.messages?.at(-1)
try {
if (event.type === 'reasoning') {
if (lastMessage?.role === 'assistant' && lastMessage.type === 'reasoning') {
// We have an existing reasoning block!
lastMessage.content = lastMessage.content + event.textDelta.trim()
@ -191,9 +190,14 @@ export const useStreamResponse = ({
debugMessages('Current messages:', JSON.stringify(conv.messages))
}
}
return updated
})
} else if (event.type === 'tool-call') {
}
// We're not thinking, so maybe close the last message?
if (lastMessage?.role === 'assistant' && lastMessage.type === 'reasoning') {
lastMessage.reasoningEndTime = Date.now()
}
if (event.type === 'tool-call') {
// End reasoning phase immediately when we see a tool call for linear flow
if (currentReasoningStartTime && !currentReasoningEndTime) {
currentReasoningEndTime = Date.now()
@ -347,6 +351,8 @@ export const useStreamResponse = ({
} catch (e) {
console.error('Error in full stream processing:', e)
}
return updated
})
}
debugMessages('Stream processing completed. Final message count:', assistantMessageCreated ? 'created' : 'none')