- Implemented a state management system for handling different streaming chunk types, including stream start, group start, text, thinking, tool calls, metadata, errors, and stream end. - Introduced a new Send method in the context to facilitate message sending to the client. - Enhanced the output package with message sending capabilities, including support for message groups and flushing. - Improved error handling and message ID generation for better streaming reliability and user feedback.
26 lines
922 B
Go
26 lines
922 B
Go
package cui
|
|
|
|
import "github.com/yaoapp/yao/agent/output/message"
|
|
|
|
// Adapter implements the message.Adapter interface for CUI clients.
|
|
// It performs no conversion and outputs messages as-is, as CUI clients
|
|
// are designed to directly consume the universal DSL.
|
|
type Adapter struct{}
|
|
|
|
// NewAdapter creates a new CUI adapter.
|
|
func NewAdapter() *Adapter {
|
|
return &Adapter{}
|
|
}
|
|
|
|
// Adapt converts a universal Message to one or more client-specific chunks.
|
|
// For CUI, it simply returns the original message as a single chunk.
|
|
func (a *Adapter) Adapt(msg *message.Message) ([]interface{}, error) {
|
|
// CUI clients consume the universal DSL directly, so no conversion is needed.
|
|
return []interface{}{msg}, nil
|
|
}
|
|
|
|
// SupportsType checks if the adapter explicitly supports a given message type.
|
|
// CUI adapter supports all types as it renders them directly.
|
|
func (a *Adapter) SupportsType(msgType string) bool {
|
|
return true
|
|
}
|