fix: live elf progress shows tool calls + results, not just text
This commit is contained in:
@@ -102,16 +102,21 @@ func (t *Tool) Execute(ctx context.Context, args json.RawMessage) (tool.Result,
|
|||||||
done := make(chan elf.Result, 1)
|
done := make(chan elf.Result, 1)
|
||||||
go func() { done <- e.Wait() }()
|
go func() { done <- e.Wait() }()
|
||||||
|
|
||||||
// Forward elf streaming events as 2-line progress summary
|
// Forward elf streaming events as live progress
|
||||||
go func() {
|
go func() {
|
||||||
var buf strings.Builder
|
var textBuf strings.Builder
|
||||||
for evt := range e.Events() {
|
for evt := range e.Events() {
|
||||||
if evt.Type == stream.EventTextDelta && evt.Text != "" {
|
if t.ProgressCh == nil {
|
||||||
buf.WriteString(evt.Text)
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if t.ProgressCh != nil {
|
var progress string
|
||||||
// Extract last 2 non-empty lines, truncate to 70 chars each
|
switch evt.Type {
|
||||||
allLines := strings.Split(buf.String(), "\n")
|
case stream.EventTextDelta:
|
||||||
|
if evt.Text != "" {
|
||||||
|
textBuf.WriteString(evt.Text)
|
||||||
|
// Show last 2 non-empty lines of text
|
||||||
|
allLines := strings.Split(textBuf.String(), "\n")
|
||||||
var recent []string
|
var recent []string
|
||||||
for i := len(allLines) - 1; i >= 0 && len(recent) < 2; i-- {
|
for i := len(allLines) - 1; i >= 0 && len(recent) < 2; i-- {
|
||||||
line := strings.TrimSpace(allLines[i])
|
line := strings.TrimSpace(allLines[i])
|
||||||
@@ -122,10 +127,28 @@ func (t *Tool) Execute(ctx context.Context, args json.RawMessage) (tool.Result,
|
|||||||
recent = append([]string{line}, recent...)
|
recent = append([]string{line}, recent...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
select {
|
progress = strings.Join(recent, "\n")
|
||||||
case t.ProgressCh <- strings.Join(recent, "\n"):
|
}
|
||||||
default:
|
case stream.EventToolCallDone:
|
||||||
}
|
name := evt.ToolCallName
|
||||||
|
if name == "" {
|
||||||
|
name = "tool"
|
||||||
|
}
|
||||||
|
progress = fmt.Sprintf("⚙ [%s] running...", name)
|
||||||
|
case stream.EventToolResult:
|
||||||
|
// Show truncated tool result
|
||||||
|
out := evt.ToolOutput
|
||||||
|
if len(out) > 70 {
|
||||||
|
out = out[:70] + "…"
|
||||||
|
}
|
||||||
|
out = strings.ReplaceAll(out, "\n", " ")
|
||||||
|
progress = fmt.Sprintf(" → %s", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
if progress != "" {
|
||||||
|
select {
|
||||||
|
case t.ProgressCh <- progress:
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user