wip, at least prettier likes it
This commit is contained in:
parent
022747ba04
commit
52c3e8d727
1 changed files with 155 additions and 149 deletions
|
|
@ -159,8 +159,6 @@ export const useStreamResponse = ({
|
||||||
// Use fullStream to get all events including tool calls, results, and text
|
// Use fullStream to get all events including tool calls, results, and text
|
||||||
for await (const event of result.fullStream) {
|
for await (const event of result.fullStream) {
|
||||||
console.log(JSON.stringify(event))
|
console.log(JSON.stringify(event))
|
||||||
try {
|
|
||||||
if (event.type === 'reasoning') {
|
|
||||||
setConversations((prev) => {
|
setConversations((prev) => {
|
||||||
const updated = [...prev]
|
const updated = [...prev]
|
||||||
const conv = updated.find((c) => c.id === conversationId)
|
const conv = updated.find((c) => c.id === conversationId)
|
||||||
|
|
@ -169,7 +167,8 @@ export const useStreamResponse = ({
|
||||||
return updated
|
return updated
|
||||||
}
|
}
|
||||||
const lastMessage = conv.messages?.at(-1)
|
const lastMessage = conv.messages?.at(-1)
|
||||||
|
try {
|
||||||
|
if (event.type === 'reasoning') {
|
||||||
if (lastMessage?.role === 'assistant' && lastMessage.type === 'reasoning') {
|
if (lastMessage?.role === 'assistant' && lastMessage.type === 'reasoning') {
|
||||||
// We have an existing reasoning block!
|
// We have an existing reasoning block!
|
||||||
lastMessage.content = lastMessage.content + event.textDelta.trim()
|
lastMessage.content = lastMessage.content + event.textDelta.trim()
|
||||||
|
|
@ -191,9 +190,14 @@ export const useStreamResponse = ({
|
||||||
debugMessages('Current messages:', JSON.stringify(conv.messages))
|
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
|
// End reasoning phase immediately when we see a tool call for linear flow
|
||||||
if (currentReasoningStartTime && !currentReasoningEndTime) {
|
if (currentReasoningStartTime && !currentReasoningEndTime) {
|
||||||
currentReasoningEndTime = Date.now()
|
currentReasoningEndTime = Date.now()
|
||||||
|
|
@ -347,6 +351,8 @@ export const useStreamResponse = ({
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error in full stream processing:', e)
|
console.error('Error in full stream processing:', e)
|
||||||
}
|
}
|
||||||
|
return updated
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
debugMessages('Stream processing completed. Final message count:', assistantMessageCreated ? 'created' : 'none')
|
debugMessages('Stream processing completed. Final message count:', assistantMessageCreated ? 'created' : 'none')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue