codec

package
v0.0.0-...-140e820 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package codec provides message serialization and deserialization for the protocol adapter.

Index

Constants

View Source
const (
	TypeRequest     = "request"
	TypeResponse    = "response"
	TypeError       = "error"
	TypeHeartbeat   = "heartbeat"
	TypeRegister    = "register"
	TypeUnregister  = "unregister"
	TypeStreamChunk = "stream_chunk"
	TypeStreamEnd   = "stream_end"
)

Envelope types

View Source
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

func EncodeBytes(env *Envelope) ([]byte, error)

EncodeBytes encodes an envelope to bytes for transmission.

func ValidateEnvelope

func ValidateEnvelope(env *Envelope) error

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

func CreateResponseEnvelope(requestID string, payload map[string]interface{}) *Envelope

CreateResponseEnvelope creates a protocol response envelope.

func CreateStreamChunkEnvelope

func CreateStreamChunkEnvelope(requestID string, message MessageData) *Envelope

CreateStreamChunkEnvelope creates a protocol stream chunk envelope.

func CreateStreamEndEnvelope

func CreateStreamEndEnvelope(requestID string) *Envelope

CreateStreamEndEnvelope creates a protocol stream end envelope.

func DecodeBytes

func DecodeBytes(data []byte) (*Envelope, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL