Add full ChatStream support to the pico channel, enabling real-time token streaming to connected WebSocket clients. Changes: - Add streamer tracking in turnState (acquire/release per conversation turn) - Integrate ChatStream in pipeline_llm (use when streamer is available) - Wire streamer lifecycle through agent loop - Add Streaming field to PicoSettings config - Skip bus publish when response was already streamed - Add streaming test scaffold When a channel supports streaming and has it enabled in config, the agent loop calls ChatStream() instead of Chat(), allowing tokens to flow in real-time through the WebSocket as the LLM generates them. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
// PicoClaw - Ultra-lightweight personal AI agent
|
|
|
|
package adapters
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/agent/interfaces"
|
|
"github.com/sipeed/picoclaw/pkg/bus"
|
|
)
|
|
|
|
// messageBusAdapter wraps *bus.MessageBus to implement interfaces.MessageBus.
|
|
type messageBusAdapter struct {
|
|
inner *bus.MessageBus
|
|
}
|
|
|
|
// NewMessageBus creates an adapter for *bus.MessageBus.
|
|
func NewMessageBus(inner *bus.MessageBus) interfaces.MessageBus {
|
|
return &messageBusAdapter{inner: inner}
|
|
}
|
|
|
|
func (a *messageBusAdapter) PublishInbound(ctx context.Context, msg bus.InboundMessage) error {
|
|
return a.inner.PublishInbound(ctx, msg)
|
|
}
|
|
|
|
func (a *messageBusAdapter) PublishOutbound(ctx context.Context, msg bus.OutboundMessage) error {
|
|
return a.inner.PublishOutbound(ctx, msg)
|
|
}
|
|
|
|
func (a *messageBusAdapter) PublishOutboundMedia(ctx context.Context, msg bus.OutboundMediaMessage) error {
|
|
return a.inner.PublishOutboundMedia(ctx, msg)
|
|
}
|
|
|
|
func (a *messageBusAdapter) InboundChan() <-chan bus.InboundMessage {
|
|
return a.inner.InboundChan()
|
|
}
|
|
|
|
func (a *messageBusAdapter) GetStreamer(ctx context.Context, channel, chatID string) (bus.Streamer, bool) {
|
|
return a.inner.GetStreamer(ctx, channel, chatID)
|
|
}
|