envelope

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 3 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Envelope

type Envelope struct {
	ID           string            `json:"id"`
	Source       string            `json:"source"`
	Destination  string            `json:"destination"`
	Protocol     protocol.Protocol `json:"protocol"`
	MessageType  MessageType       `json:"message_type"`
	ContentType  string            `json:"content_type"`
	Payload      []byte            `json:"payload"`
	Metadata     map[string]string `json:"metadata,omitempty"`
	Timestamp    time.Time         `json:"timestamp"`
	TTL          int               `json:"ttl,omitempty"`
	TraceID      string            `json:"trace_id,omitempty"`
	SessionID    string            `json:"session_id,omitempty"`
	Signature    string            `json:"signature,omitempty"`
	Nonce        string            `json:"nonce,omitempty"`
	Encrypted    bool              `json:"encrypted,omitempty"`
	SenderX25519 string            `json:"sender_x25519,omitempty"`
}

Envelope is the universal message wrapper that bridges different AI agent protocols. Every message flowing through PeerClaw is wrapped in an Envelope regardless of the originating protocol.

func New

func New(source, destination string, proto protocol.Protocol, payload []byte) *Envelope

New creates a new Envelope with a generated ID and timestamp.

func (*Envelope) WithMessageType

func (e *Envelope) WithMessageType(mt MessageType) *Envelope

WithMessageType sets the message type and returns the envelope for chaining.

func (*Envelope) WithMetadata

func (e *Envelope) WithMetadata(key, value string) *Envelope

WithMetadata adds a metadata key-value pair and returns the envelope for chaining.

func (*Envelope) WithSessionID added in v0.2.0

func (e *Envelope) WithSessionID(sessionID string) *Envelope

WithSessionID sets the session ID for multi-turn conversations and returns the envelope for chaining.

func (*Envelope) WithTTL

func (e *Envelope) WithTTL(ttl int) *Envelope

WithTTL sets the time-to-live and returns the envelope for chaining.

type MessageType

type MessageType string

MessageType categorizes the purpose of a message.

const (
	MessageTypeRequest  MessageType = "request"
	MessageTypeResponse MessageType = "response"
	MessageTypeEvent    MessageType = "event"
	MessageTypeError    MessageType = "error"
)

Jump to

Keyboard shortcuts

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