messaging

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BundleFromAttachment

func BundleFromAttachment(att Attachment) attachmentpkg.Bundle

func ContainsMarkdown

func ContainsMarkdown(text string) bool

func IsSameConversation

func IsSameConversation(session SessionContext, platform, target string) bool

IsSameConversation reports whether platform+target matches the session's current conversation.

Types

type Action

type Action struct {
	Type  string `json:"type"`
	Label string `json:"label,omitempty"`
	Value string `json:"value,omitempty"`
	URL   string `json:"url,omitempty"`
	Row   int    `json:"row,omitempty"`
}

type AssetMeta

type AssetMeta = media.Asset

AssetMeta holds resolved metadata for a media asset.

type AssetResolver

type AssetResolver interface {
	Stat(ctx context.Context, botID, contentHash string) (media.Asset, error)
	Open(ctx context.Context, botID, contentHash string) (io.ReadCloser, media.Asset, error)
	Ingest(ctx context.Context, input media.IngestInput) (media.Asset, error)
	GetByStorageKey(ctx context.Context, botID, storageKey string) (media.Asset, error)
	AccessPath(ctx context.Context, asset media.Asset) string
	IngestContainerFile(ctx context.Context, botID, containerPath string) (media.Asset, error)
}

type Attachment

type Attachment struct {
	Type           AttachmentType `json:"type"`
	URL            string         `json:"url,omitempty"`
	Path           string         `json:"path,omitempty"`
	PlatformKey    string         `json:"platform_key,omitempty"`
	SourcePlatform string         `json:"source_platform,omitempty"`
	ContentHash    string         `json:"content_hash,omitempty"`
	Base64         string         `json:"base64,omitempty"`
	Name           string         `json:"name,omitempty"`
	Size           int64          `json:"size,omitempty"`
	Mime           string         `json:"mime,omitempty"`
	DurationMs     int64          `json:"duration_ms,omitempty"`
	Width          int            `json:"width,omitempty"`
	Height         int            `json:"height,omitempty"`
	ThumbnailURL   string         `json:"thumbnail_url,omitempty"`
	Caption        string         `json:"caption,omitempty"`
	Metadata       map[string]any `json:"metadata,omitempty"`
}

func AssetMetaToAttachment

func AssetMetaToAttachment(asset media.Asset, botID, attType, name string) *Attachment

AssetMetaToAttachment converts an AssetMeta to a Attachment.

func AttachmentFromBundle

func AttachmentFromBundle(bundle attachmentpkg.Bundle) Attachment

type AttachmentPromoter

type AttachmentPromoter interface {
	PromoteAttachments(ctx context.Context, botID string, platform Platform, msg Message) (Message, error)
}

AttachmentPromoter lets the Channel boundary convert container-local attachment references into durable outbound assets.

type AttachmentType

type AttachmentType string
const (
	AttachmentImage AttachmentType = "image"
	AttachmentAudio AttachmentType = "audio"
	AttachmentVideo AttachmentType = "video"
	AttachmentVoice AttachmentType = "voice"
	AttachmentFile  AttachmentType = "file"
	AttachmentGIF   AttachmentType = "gif"
)

func InferAttachmentTypeFromExt

func InferAttachmentTypeFromExt(path string) AttachmentType

InferAttachmentTypeFromExt infers attachment type from file extension.

func InferAttachmentTypeFromMime

func InferAttachmentTypeFromMime(mime string) AttachmentType

InferAttachmentTypeFromMime infers attachment type from MIME type.

type ChannelTypeResolver

type ChannelTypeResolver interface {
	ParseChannelType(raw string) (Platform, error)
}

type Contact

type Contact struct {
	RouteID                string
	Platform               string
	ConversationType       string
	ReplyTarget            string
	ExternalConversationID string
	Metadata               map[string]any
	UpdatedAt              time.Time
}

type ContactReader

type ContactReader interface {
	ListContacts(ctx context.Context, botID string) ([]Contact, error)
}

type Executor

type Executor struct {
	Sender        Sender
	Reactor       Reactor
	Resolver      ChannelTypeResolver
	AssetResolver AssetResolver
	Promoter      AttachmentPromoter
	Logger        *slog.Logger
}

Executor provides send and react operations for channel messaging.

func (*Executor) CanReact

func (e *Executor) CanReact() bool

CanReact returns true if the executor has a reactor and resolver configured.

func (*Executor) CanSend

func (e *Executor) CanSend() bool

CanSend returns true if the executor has a sender and resolver configured.

func (*Executor) React

func (e *Executor) React(ctx context.Context, session SessionContext, args map[string]any) (*ReactResult, error)

React executes a react action. args are the tool call arguments.

func (*Executor) ResolveAttachments

func (e *Executor) ResolveAttachments(ctx context.Context, botID string, bundles []attachmentpkg.Bundle) []Attachment

ResolveAttachments converts raw attachment arguments into Attachment values.

func (*Executor) Send

func (e *Executor) Send(ctx context.Context, session SessionContext, args map[string]any) (*SendResult, error)

Send executes a send-message action. args are the tool call arguments.

func (*Executor) SendDirect

func (e *Executor) SendDirect(ctx context.Context, session SessionContext, target string, args map[string]any) (*SendResult, error)

SendDirect sends a message via the channel adapter without the same-conversation local shortcut. Used by discuss mode where there is no active stream emitter.

type ForwardRef

type ForwardRef struct {
	MessageID          string `json:"message_id,omitempty"`
	FromUserID         string `json:"from_user_id,omitempty"`
	FromConversationID string `json:"from_conversation_id,omitempty"`
	Sender             string `json:"sender,omitempty"`
	Date               int64  `json:"date,omitempty"`
	AttachmentsKnown   bool   `json:"attachments_known,omitempty"`
}

type Message

type Message struct {
	ID          string         `json:"id,omitempty"`
	Format      MessageFormat  `json:"format,omitempty"`
	Text        string         `json:"text,omitempty"`
	Parts       []MessagePart  `json:"parts,omitempty"`
	Attachments []Attachment   `json:"attachments,omitempty"`
	Actions     []Action       `json:"actions,omitempty"`
	Thread      *ThreadRef     `json:"thread,omitempty"`
	Reply       *ReplyRef      `json:"reply,omitempty"`
	Forward     *ForwardRef    `json:"forward,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

func ParseOutboundMessage

func ParseOutboundMessage(arguments map[string]any, fallbackText string) (Message, error)

ParseOutboundMessage parses a message from tool call arguments.

func (Message) IsEmpty

func (m Message) IsEmpty() bool

type MessageFormat

type MessageFormat string
const (
	MessageFormatPlain    MessageFormat = "plain"
	MessageFormatMarkdown MessageFormat = "markdown"
	MessageFormatRich     MessageFormat = "rich"
)

type MessagePart

type MessagePart struct {
	Type              MessagePartType    `json:"type"`
	Text              string             `json:"text,omitempty"`
	URL               string             `json:"url,omitempty"`
	Styles            []MessageTextStyle `json:"styles,omitempty"`
	Language          string             `json:"language,omitempty"`
	ChannelIdentityID string             `json:"channel_identity_id,omitempty"`
	Emoji             string             `json:"emoji,omitempty"`
	Metadata          map[string]any     `json:"metadata,omitempty"`
}

type MessagePartType

type MessagePartType string
const (
	MessagePartText       MessagePartType = "text"
	MessagePartLink       MessagePartType = "link"
	MessagePartCodeBlock  MessagePartType = "code_block"
	MessagePartMention    MessagePartType = "mention"
	MessagePartEmoji      MessagePartType = "emoji"
	MessagePartHeading    MessagePartType = "heading"
	MessagePartBlockquote MessagePartType = "blockquote"
	MessagePartListItem   MessagePartType = "list_item"
)

type MessageTextStyle

type MessageTextStyle string
const (
	MessageStyleBold          MessageTextStyle = "bold"
	MessageStyleItalic        MessageTextStyle = "italic"
	MessageStyleStrikethrough MessageTextStyle = "strikethrough"
	MessageStyleCode          MessageTextStyle = "code"
	MessageStyleUnderline     MessageTextStyle = "underline"
	MessageStyleSpoiler       MessageTextStyle = "spoiler"
)

type Platform

type Platform string

Platform is the delivery platform identifier used by Agent-facing messaging ports. Channel adapters translate it to their own ChannelType.

func (Platform) String

func (p Platform) String() string

type ReactRequest

type ReactRequest struct {
	Target    string `json:"target"`
	MessageID string `json:"message_id"`
	Emoji     string `json:"emoji"`
	Remove    bool   `json:"remove,omitempty"`
}

type ReactResult

type ReactResult struct {
	BotID     string
	Platform  string
	Target    string
	MessageID string
	Emoji     string
	Action    string // "added" or "removed"
	Local     bool
	Remove    bool
}

ReactResult is the success payload returned after reacting.

type Reactor

type Reactor interface {
	React(ctx context.Context, botID string, platform Platform, req ReactRequest) error
}

type ReplyRef

type ReplyRef struct {
	Target           string       `json:"target,omitempty"`
	MessageID        string       `json:"message_id,omitempty"`
	Sender           string       `json:"sender,omitempty"`
	Preview          string       `json:"preview,omitempty"`
	Attachments      []Attachment `json:"attachments,omitempty"`
	AttachmentsKnown bool         `json:"attachments_known,omitempty"`
}

type SendRequest

type SendRequest struct {
	Target            string  `json:"target,omitempty"`
	ChannelIdentityID string  `json:"channel_identity_id,omitempty"`
	Message           Message `json:"message"`
}

type SendResult

type SendResult struct {
	BotID     string
	Platform  string
	Target    string
	MessageID string
	// Local is true when the message targets the current conversation.
	// The caller should emit the resolved attachments as stream events.
	Local            bool
	LocalAttachments []Attachment
	// LocalTextOmitted is true when the local shortcut delivered the
	// attachments but dropped accompanying text/parts; the caller should tell
	// the model to restate that text in its assistant reply.
	LocalTextOmitted bool
}

SendResult is the success payload returned after sending a message.

type Sender

type Sender interface {
	Send(ctx context.Context, botID string, platform Platform, req SendRequest) error
}

type SessionContext

type SessionContext struct {
	BotID              string
	ChatID             string
	CanOmitTarget      bool
	AllowLocalShortcut bool
	CurrentPlatform    string
	ReplyTarget        string
}

SessionContext carries request-scoped identity for tool execution.

type ThreadRef

type ThreadRef struct {
	ID string `json:"id"`
}

Jump to

Keyboard shortcuts

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