feat(im): align agent stream display with web thinking and tool progress
Mirror Web AgentStreamDisplay/RagPipelineProgress in IM text streams: retract live answers into 思考过程, show Web-aligned tool titles with query/summary from structured data, and collapse thinking on finalize instead of dropping it entirely.
This commit is contained in:
@@ -275,27 +275,35 @@ func (c *LongConnClient) StartStream(ctx context.Context, incoming *im.IncomingM
|
||||
return streamID, nil
|
||||
}
|
||||
|
||||
// SendStreamChunk accumulates the content and sends the full text so far.
|
||||
// WeCom stream protocol is replace-based: each frame replaces the previous display.
|
||||
func (c *LongConnClient) SendStreamChunk(ctx context.Context, incoming *im.IncomingMessage, streamID string, content string) error {
|
||||
if content == "" {
|
||||
// UpdateStreamContent replaces the user-visible stream text (WeCom replace protocol).
|
||||
func (c *LongConnClient) UpdateStreamContent(ctx context.Context, incoming *im.IncomingMessage, streamID string, fullContent string) error {
|
||||
if fullContent == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Accumulate
|
||||
c.streamBufsMu.Lock()
|
||||
buf, ok := c.streamBufs[streamID]
|
||||
if !ok {
|
||||
c.streamBufsMu.Unlock()
|
||||
return fmt.Errorf("unknown stream ID: %s", streamID)
|
||||
}
|
||||
buf.WriteString(content)
|
||||
fullContent := buf.String()
|
||||
buf.Reset()
|
||||
buf.WriteString(fullContent)
|
||||
c.streamBufsMu.Unlock()
|
||||
|
||||
return c.sendStreamFrame(incoming, streamID, fullContent, false)
|
||||
}
|
||||
|
||||
// FinalizeStream replaces the display with answer-only content before the stream ends.
|
||||
func (c *LongConnClient) FinalizeStream(ctx context.Context, incoming *im.IncomingMessage, streamID string, finalContent string) error {
|
||||
return c.UpdateStreamContent(ctx, incoming, streamID, finalContent)
|
||||
}
|
||||
|
||||
// SendStreamChunk is deprecated; kept as an alias for UpdateStreamContent.
|
||||
func (c *LongConnClient) SendStreamChunk(ctx context.Context, incoming *im.IncomingMessage, streamID string, content string) error {
|
||||
return c.UpdateStreamContent(ctx, incoming, streamID, content)
|
||||
}
|
||||
|
||||
// EndStream sends the final frame with the full accumulated content and cleans up.
|
||||
// It retries briefly if the connection is temporarily unavailable during a reconnect.
|
||||
func (c *LongConnClient) EndStream(ctx context.Context, incoming *im.IncomingMessage, streamID string) error {
|
||||
|
||||
@@ -60,8 +60,16 @@ func (a *WSAdapter) StartStream(ctx context.Context, incoming *im.IncomingMessag
|
||||
return a.client.StartStream(ctx, incoming)
|
||||
}
|
||||
|
||||
func (a *WSAdapter) UpdateStreamContent(ctx context.Context, incoming *im.IncomingMessage, streamID string, fullContent string) error {
|
||||
return a.client.UpdateStreamContent(ctx, incoming, streamID, fullContent)
|
||||
}
|
||||
|
||||
func (a *WSAdapter) FinalizeStream(ctx context.Context, incoming *im.IncomingMessage, streamID string, finalContent string) error {
|
||||
return a.client.FinalizeStream(ctx, incoming, streamID, finalContent)
|
||||
}
|
||||
|
||||
func (a *WSAdapter) SendStreamChunk(ctx context.Context, incoming *im.IncomingMessage, streamID string, content string) error {
|
||||
return a.client.SendStreamChunk(ctx, incoming, streamID, content)
|
||||
return a.client.UpdateStreamContent(ctx, incoming, streamID, content)
|
||||
}
|
||||
|
||||
func (a *WSAdapter) EndStream(ctx context.Context, incoming *im.IncomingMessage, streamID string) error {
|
||||
|
||||
Reference in New Issue
Block a user