Documentation
¶
Overview ¶
Package codec provides message serialization and deserialization for the protocol adapter.
Index ¶
- Constants
- func DecodeMessage(data MessageData) (*agenkit.Message, error)
- func DecodeToolResult(data ToolResultData) *agenkit.ToolResult
- func EncodeBytes(env *Envelope) ([]byte, error)
- func ValidateEnvelope(env *Envelope) error
- type Envelope
- func CreateErrorEnvelope(requestID, errorCode, errorMessage string, errorDetails map[string]interface{}) *Envelope
- func CreateRequestEnvelope(method string, agentName string, payload map[string]interface{}) *Envelope
- func CreateResponseEnvelope(requestID string, payload map[string]interface{}) *Envelope
- func CreateStreamChunkEnvelope(requestID string, message MessageData) *Envelope
- func CreateStreamEndEnvelope(requestID string) *Envelope
- func DecodeBytes(data []byte) (*Envelope, error)
- type MessageData
- type ToolResultData
Constants ¶
const ( TypeRequest = "request" TypeResponse = "response" TypeError = "error" TypeHeartbeat = "heartbeat" TypeRegister = "register" TypeUnregister = "unregister" TypeStreamChunk = "stream_chunk" TypeStreamEnd = "stream_end" )
Envelope types
const ProtocolVersion = "1.0"
Variables ¶
This section is empty.
Functions ¶
func DecodeMessage ¶
func DecodeMessage(data MessageData) (*agenkit.Message, error)
DecodeMessage converts serialized message data to a Message.
func DecodeToolResult ¶
func DecodeToolResult(data ToolResultData) *agenkit.ToolResult
DecodeToolResult converts serialized tool result data to a ToolResult.
func EncodeBytes ¶
EncodeBytes encodes an envelope to bytes for transmission.
func ValidateEnvelope ¶
ValidateEnvelope validates a protocol envelope.
Types ¶
type Envelope ¶
type Envelope struct {
Version string `json:"version"`
Type string `json:"type"`
ID string `json:"id"`
Timestamp string `json:"timestamp"`
Payload map[string]interface{} `json:"payload"`
}
Envelope represents a protocol message envelope.
func CreateErrorEnvelope ¶
func CreateErrorEnvelope(requestID, errorCode, errorMessage string, errorDetails map[string]interface{}) *Envelope
CreateErrorEnvelope creates a protocol error envelope.
func CreateRequestEnvelope ¶
func CreateRequestEnvelope(method string, agentName string, payload map[string]interface{}) *Envelope
CreateRequestEnvelope creates a protocol request envelope.
func CreateResponseEnvelope ¶
CreateResponseEnvelope creates a protocol response envelope.
func CreateStreamChunkEnvelope ¶
func CreateStreamChunkEnvelope(requestID string, message MessageData) *Envelope
CreateStreamChunkEnvelope creates a protocol stream chunk envelope.
func CreateStreamEndEnvelope ¶
CreateStreamEndEnvelope creates a protocol stream end envelope.
func DecodeBytes ¶
DecodeBytes decodes bytes to an envelope.
type MessageData ¶
type MessageData struct {
Role string `json:"role"`
Content string `json:"content"`
Metadata map[string]interface{} `json:"metadata"`
Timestamp string `json:"timestamp"`
}
MessageData represents the serialized form of a Message.
func EncodeMessage ¶
func EncodeMessage(msg *agenkit.Message) MessageData
EncodeMessage converts a Message to its serializable form.
type ToolResultData ¶
type ToolResultData struct {
Success bool `json:"success"`
Data interface{} `json:"data,omitempty"`
Error string `json:"error,omitempty"`
Metadata map[string]interface{} `json:"metadata"`
}
ToolResultData represents the serialized form of a ToolResult.
func EncodeToolResult ¶
func EncodeToolResult(result *agenkit.ToolResult) ToolResultData
EncodeToolResult converts a ToolResult to its serializable form.