Files
synapbus/internal/messaging/types.go
T
Algis DumbrisandClaude Opus 4.6 e51adc376e feat: message reactions and workflow states (010-reactions-workflows)
Add typed reactions (approve/reject/in_progress/done/published) with
toggle semantics. Workflow state derived from highest-priority reaction.
New reactions package with model, SQLite store, and service layer.

REST API: POST/GET/DELETE /api/messages/{id}/reactions for toggle/query,
PUT /api/channels/{name}/settings for workflow config, GET by-state
endpoint for listing messages by workflow state.

MCP: react/unreact/get_reactions/list_by_state actions via bridge.

Web UI: WorkflowBadge (colored state pills) and ReactionPills (toggle
pills with agent names) components integrated into channel view.

Channel settings: auto_approve, stalemate_remind_after,
stalemate_escalate_after columns. CLI: channels update command.

Migration 013_reactions.sql adds message_reactions table and channel
workflow columns. 29+ new test cases across model and store.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 09:30:06 +02:00

104 lines
3.8 KiB
Go

// Package messaging provides core messaging types and services for SynapBus.
package messaging
import (
"encoding/json"
"time"
)
// Message status constants.
const (
StatusPending = "pending"
StatusProcessing = "processing"
StatusDone = "done"
StatusFailed = "failed"
)
// AttachmentInfo is a lightweight attachment summary included in message responses.
// It avoids importing the attachments package into the messaging package.
type AttachmentInfo struct {
Hash string `json:"hash"`
OriginalFilename string `json:"original_filename"`
Size int64 `json:"size"`
MIMEType string `json:"mime_type"`
IsImage bool `json:"is_image"`
}
// Message represents a single message in the system.
type Message struct {
ID int64 `json:"id"`
ConversationID int64 `json:"conversation_id"`
FromAgent string `json:"from_agent"`
ToAgent string `json:"to_agent,omitempty"`
ChannelID *int64 `json:"channel_id,omitempty"`
ReplyTo *int64 `json:"reply_to,omitempty"`
Body string `json:"body"`
Priority int `json:"priority"`
Status string `json:"status"`
Metadata json.RawMessage `json:"metadata"`
ClaimedBy string `json:"claimed_by,omitempty"`
ClaimedAt *time.Time `json:"claimed_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ReplyCount int `json:"reply_count"`
Attachments []AttachmentInfo `json:"attachments,omitempty"`
WorkflowState string `json:"workflow_state,omitempty"`
Reactions []ReactionInfo `json:"reactions,omitempty"`
}
// ReactionInfo is a lightweight reaction summary included in message responses.
type ReactionInfo struct {
AgentName string `json:"agent_name"`
Reaction string `json:"reaction"`
Metadata json.RawMessage `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
// Conversation groups related messages into a thread.
type Conversation struct {
ID int64 `json:"id"`
Subject string `json:"subject"`
CreatedBy string `json:"created_by"`
ChannelID *int64 `json:"channel_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// DeadLetter represents an undeliverable message captured when an agent is deleted.
type DeadLetter struct {
ID int64 `json:"id"`
OwnerID int64 `json:"owner_id"`
OriginalMessageID int64 `json:"original_message_id"`
ToAgent string `json:"to_agent"`
FromAgent string `json:"from_agent"`
Body string `json:"body"`
Subject string `json:"subject"`
Priority int `json:"priority"`
Metadata json.RawMessage `json:"metadata,omitempty"`
Acknowledged bool `json:"acknowledged"`
CreatedAt time.Time `json:"created_at"`
}
// PaginatedMessages holds a page of messages with total count.
type PaginatedMessages struct {
Messages []*Message `json:"messages"`
Total int `json:"total"`
Offset int `json:"offset"`
Limit int `json:"limit"`
}
// InboxState tracks per-agent, per-conversation read position.
type InboxState struct {
AgentName string `json:"agent_name"`
ConversationID int64 `json:"conversation_id"`
LastReadMessageID int64 `json:"last_read_message_id"`
UpdatedAt time.Time `json:"updated_at"`
}
// DMUnreadCount holds the unread DM count for a specific peer agent.
type DMUnreadCount struct {
Agent string `json:"agent"`
UnreadCount int `json:"unread_count"`
LastMessageID int64 `json:"last_message_id"`
}