Merge pull request #18 from dj-oyu/fix/heartbeat-streaming-bubble

fix: streaming preview shares task status bubble for background tasks
This commit is contained in:
dj-oyu 2026-03-03 11:15:38 +09:00 committed by GitHub
commit 2309be8fcb

View file

@ -1063,7 +1063,7 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, agent *AgentInstance, opt
if opts.TaskID != "" { if opts.TaskID != "" {
elapsed := time.Since(task.StartedAt) elapsed := time.Since(task.StartedAt)
completionMsg := fmt.Sprintf("\u2705 Task completed (%.1fs)", elapsed.Seconds()) completionMsg := fmt.Sprintf("\u2705 Task completed (%.1fs)", elapsed.Seconds())
if finalContent != "" && finalContent != defaultResponse { if finalContent != "" && finalContent != defaultResponse && finalContent != "HEARTBEAT_OK" {
// Keep completion + response in one bubble if short enough (4096 = Telegram limit). // Keep completion + response in one bubble if short enough (4096 = Telegram limit).
// If too long, edit the status bubble with the header, then send the // If too long, edit the status bubble with the header, then send the
// full response as a regular message — the channel worker's SplitMessage // full response as a regular message — the channel worker's SplitMessage
@ -2245,12 +2245,21 @@ func (al *AgentLoop) runLLMIteration(
defer close(streamDone) defer close(streamDone)
for up := range streamCh { for up := range streamCh {
display := buildStreamingDisplay(up.accumulated, up.reasoning) display := buildStreamingDisplay(up.accumulated, up.reasoning)
_ = al.bus.PublishOutbound(ctx, bus.OutboundMessage{ outMsg := bus.OutboundMessage{
Channel: opts.Channel, Channel: opts.Channel,
ChatID: opts.ChatID, ChatID: opts.ChatID,
Content: display, Content: display,
IsStatus: true, }
}) // For background tasks, publish streaming preview as
// IsTaskStatus so it shares the same bubble as task
// progress/completion (avoids a second bubble).
if opts.Background && opts.TaskID != "" {
outMsg.IsTaskStatus = true
outMsg.TaskID = opts.TaskID
} else {
outMsg.IsStatus = true
}
_ = al.bus.PublishOutbound(ctx, outMsg)
} }
}() }()
onChunk = func(accumulated, reasoning string) { onChunk = func(accumulated, reasoning string) {