streaming: handle tool streaming via empty-content start signal
This commit is contained in:
parent
4b24b33377
commit
208db7ba68
|
|
@ -147,17 +147,15 @@ func (sess *Session) startEventLog() {
|
|||
sess.AppendLog(FormatEvent(ev))
|
||||
|
||||
case "tool":
|
||||
// Tool events can stream (multiple chunks with same name) or
|
||||
// arrive as a single final result. Write header on first chunk,
|
||||
// then append content. Duplicate final result is suppressed.
|
||||
// Tool events: empty content = header-only (stream start),
|
||||
// non-empty while streaming = chunk, non-empty without streaming = full result.
|
||||
if streamingRole == "tool" {
|
||||
// Continuation of streaming tool output.
|
||||
if ev.Content != "" {
|
||||
sess.AppendLog([]byte(ev.Content))
|
||||
} else {
|
||||
// Empty content = final result marker; streaming is done.
|
||||
if ev.Content == "" {
|
||||
// End of stream.
|
||||
sess.AppendLog([]byte("\n"))
|
||||
streamingRole = ""
|
||||
} else {
|
||||
sess.AppendLog([]byte(ev.Content))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -165,12 +163,14 @@ func (sess *Session) startEventLog() {
|
|||
sess.AppendLog([]byte("\n"))
|
||||
streamingRole = ""
|
||||
}
|
||||
// First tool event — write header and start streaming.
|
||||
if ev.Content == "" {
|
||||
// Stream start: write header, enter streaming mode.
|
||||
sess.AppendLog([]byte("[tool:" + ev.Name + "]\n"))
|
||||
if ev.Content != "" {
|
||||
sess.AppendLog([]byte(ev.Content))
|
||||
}
|
||||
streamingRole = "tool"
|
||||
} else {
|
||||
// Non-streamed tool result (fast tool, no streaming happened).
|
||||
sess.AppendLog(FormatEvent(ev))
|
||||
}
|
||||
|
||||
case "call":
|
||||
if streamingRole != "" {
|
||||
|
|
|
|||
Reference in New Issue