rooms

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRoomID          = errors.New("room id is required")
	ErrInvalidRoomRequest     = errors.New("invalid room request")
	ErrRoomExists             = errors.New("room already exists")
	ErrUnknownRoom            = errors.New("unknown room")
	ErrUnknownThread          = errors.New("unknown thread")
	ErrUnknownAgent           = errors.New("unknown agent")
	ErrInvalidDMID            = errors.New("dm id is required")
	ErrInvalidCursor          = errors.New("invalid cursor")
	ErrInvalidMessage         = errors.New("invalid message request")
	ErrDMTopologyConflict     = errors.New("direct message participant topology is invalid")
	ErrUnknownDM              = errors.New("unknown direct conversation")
	ErrArtifactFilter         = errors.New("artifact filter is required")
	ErrUnknownPairing         = errors.New("unknown pairing")
	ErrPairingClientMissing   = errors.New("pairing client is not configured")
	ErrHumanIngressDisabled   = errors.New("human ingress is disabled")
	ErrDirectMessagesDisabled = errors.New("direct messages are disabled")
	ErrRemotePairing          = errors.New("paired network request failed")
	ErrAgentConflict          = errors.New("agent identity conflict")
	ErrAgentUnauthorized      = errors.New("agent identity requires authentication")
	ErrAgentForbidden         = errors.New("agent identity is forbidden")
	ErrWriteForbidden         = errors.New("room write policy forbids sender")
)

Functions

func AgentEventIdentityMatches added in v0.1.14

func AgentEventIdentityMatches(defaultNetworkID, candidate string, event protocol.Event) bool

AgentEventIdentityMatches resolves every identity authority on an agent event before comparing it with an attachment or restricted claim. Empty authorities inherit defaultNetworkID; explicit authorities must agree.

func AgentIdentityMatches added in v0.1.14

func AgentIdentityMatches(credentialNetwork, credentialID, parentNetwork, parentID string) bool

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) StatusCode

func (e *Error) StatusCode() int

func (*Error) Unwrap

func (e *Error) Unwrap() error

type EventBroker

type EventBroker interface {
	Publish(event protocol.Event)
	Subscribe(ctx context.Context) <-chan protocol.Event
}

type PairingClient

type PairingClient interface {
	FetchNetwork(ctx context.Context, pairing protocol.Pairing) (protocol.Network, error)
	FetchRooms(ctx context.Context, pairing protocol.Pairing) ([]protocol.Room, error)
	FetchAgents(ctx context.Context, pairing protocol.Pairing) ([]protocol.AgentSummary, error)
	RelayMessage(ctx context.Context, pairing protocol.Pairing, request protocol.SendMessageRequest) (protocol.MessageAccepted, error)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(config ServiceConfig) *Service

func (*Service) AcknowledgeAttachmentContext added in v0.1.18

func (s *Service) AcknowledgeAttachmentContext(ctx context.Context, agentID string, eventID string) error

func (*Service) AgentConnected added in v0.1.7

func (s *Service) AgentConnected(ctx context.Context, agent protocol.Actor)

func (*Service) AgentDisconnected added in v0.1.7

func (s *Service) AgentDisconnected(ctx context.Context, agent protocol.Actor, reason string, err error)

func (*Service) AgentWakeDelivered added in v0.1.7

func (s *Service) AgentWakeDelivered(ctx context.Context, agent protocol.Actor, event protocol.Event)

func (*Service) AgentWakeFailed added in v0.1.7

func (s *Service) AgentWakeFailed(
	ctx context.Context,
	agent protocol.Actor,
	event protocol.Event,
	err error,
	details protocol.WakeFailureDetails,
)

func (*Service) ApplyConfigContext added in v0.1.12

func (s *Service) ApplyConfigContext(
	ctx context.Context,
	request protocol.ApplyConfigRequest,
) (protocol.ApplyConfigResult, error)

func (*Service) AuthenticateAgentTokenContext added in v0.1.1

func (s *Service) AuthenticateAgentTokenContext(
	ctx context.Context,
	token string,
) (authn.Claims, bool, error)

func (*Service) Close

func (s *Service) Close() error

func (*Service) CreateRoom

func (s *Service) CreateRoom(request protocol.CreateRoomRequest) (protocol.Room, error)

func (*Service) CreateRoomContext

func (s *Service) CreateRoomContext(ctx context.Context, request protocol.CreateRoomRequest) (protocol.Room, error)

func (*Service) EnsureFollowRoom added in v0.1.20

func (s *Service) EnsureFollowRoom(ctx context.Context, config protocol.Follow, remote protocol.Room) error

func (*Service) GetAgent

func (s *Service) GetAgent(agentID string) (protocol.AgentSummary, error)

func (*Service) GetAgentContext added in v0.1.11

func (s *Service) GetAgentContext(ctx context.Context, agentID string) (protocol.AgentSummary, error)

func (*Service) GetDirectConversation

func (s *Service) GetDirectConversation(dmID string) (protocol.DirectConversation, error)

func (*Service) GetDirectConversationContext added in v0.1.14

func (s *Service) GetDirectConversationContext(ctx context.Context, dmID string) (protocol.DirectConversation, error)

func (*Service) GetFollowCheckpoint added in v0.1.20

func (s *Service) GetFollowCheckpoint(ctx context.Context, key string) (follow.Checkpoint, error)

func (*Service) GetRoom

func (s *Service) GetRoom(roomID string) (protocol.Room, error)

func (*Service) GetRoomContext added in v0.1.11

func (s *Service) GetRoomContext(ctx context.Context, roomID string) (protocol.Room, error)

func (*Service) GetThread

func (s *Service) GetThread(threadID string) (protocol.Thread, error)

func (*Service) GetThreadContext added in v0.1.11

func (s *Service) GetThreadContext(ctx context.Context, threadID string) (protocol.Thread, error)

func (*Service) Health

func (s *Service) Health(ctx context.Context) error

func (*Service) ImportFollowMessage added in v0.1.20

func (s *Service) ImportFollowMessage(ctx context.Context, config protocol.Follow, networkID string, remote protocol.Message) (bool, error)

func (*Service) JoinRoomContext added in v0.1.14

func (s *Service) JoinRoomContext(
	ctx context.Context,
	roomID string,
	request protocol.JoinRoomRequest,
) (protocol.Room, error)

func (*Service) ListAgents

func (s *Service) ListAgents() ([]protocol.AgentSummary, error)

func (*Service) ListAgentsContext

func (s *Service) ListAgentsContext(ctx context.Context, page protocol.PageRequest) (protocol.AgentPage, error)

ListAgentsContext derives the whole roster from rooms this caller may see: readableRoom drops rooms they cannot read, roomVisibleToPairScopedContext drops rooms their pairing is not federated with, and an agent is named here only by surviving-room membership or by canReadPrivateRoster (which a pure [pair] peer credential fails). That is the entire pair-scoped agent filter.

A second, redundant filter used to sit in front of this, behind an `agentRegistry == nil && contextAgents != nil` fast path. Both fields are type assertions on the same config.Store and every store here (MemoryStore, FileStore, SQLStore) satisfies both interfaces, so the branch was unreachable -- `panic("REACHED")` in it left the suite green. Deleted rather than kept-and-unreached; TestPairScopedAgentListingIsFilteredByFederation (federation_access_test.go) now pins the guarantee on the one live path.

func (*Service) ListArtifacts

func (s *Service) ListArtifacts(
	filter protocol.ArtifactFilter,
	before string,
	limit int,
) (protocol.ArtifactPage, error)

func (*Service) ListArtifactsContext

func (s *Service) ListArtifactsContext(
	ctx context.Context,
	filter protocol.ArtifactFilter,
	page protocol.PageRequest,
) (protocol.ArtifactPage, error)

func (*Service) ListDMMessages

func (s *Service) ListDMMessages(dmID string, before string, limit int) (protocol.MessagePage, error)

func (*Service) ListDMMessagesContext

func (s *Service) ListDMMessagesContext(
	ctx context.Context,
	dmID string,
	page protocol.PageRequest,
) (protocol.MessagePage, error)

func (*Service) ListDirectConversations

func (s *Service) ListDirectConversations() (protocol.DirectConversationPage, error)

func (*Service) ListDirectConversationsContext

func (s *Service) ListDirectConversationsContext(ctx context.Context, page protocol.PageRequest) (protocol.DirectConversationPage, error)

func (*Service) ListFollowsContext added in v0.1.20

func (s *Service) ListFollowsContext(context.Context) (protocol.FollowPage, error)

func (*Service) ListPairings

func (s *Service) ListPairings() ([]protocol.Pairing, error)

func (*Service) ListPairingsContext

func (s *Service) ListPairingsContext(ctx context.Context, page protocol.PageRequest) (protocol.PairingPage, error)

func (*Service) ListRoomMessages

func (s *Service) ListRoomMessages(roomID string, before string, limit int) (protocol.MessagePage, error)

func (*Service) ListRoomMessagesContext

func (s *Service) ListRoomMessagesContext(
	ctx context.Context,
	roomID string,
	page protocol.PageRequest,
) (protocol.MessagePage, error)

func (*Service) ListRooms

func (s *Service) ListRooms() ([]protocol.Room, error)

func (*Service) ListRoomsContext

func (s *Service) ListRoomsContext(ctx context.Context, page protocol.PageRequest) (protocol.RoomPage, error)

func (*Service) ListThreadMessages

func (s *Service) ListThreadMessages(threadID string, before string, limit int) (protocol.MessagePage, error)

func (*Service) ListThreadMessagesContext

func (s *Service) ListThreadMessagesContext(
	ctx context.Context,
	threadID string,
	page protocol.PageRequest,
) (protocol.MessagePage, error)

func (*Service) ListThreads

func (s *Service) ListThreads(roomID string) (protocol.ThreadPage, error)

func (*Service) ListThreadsContext

func (s *Service) ListThreadsContext(ctx context.Context, roomID string, page protocol.PageRequest) (protocol.ThreadPage, error)

func (*Service) Network

func (s *Service) Network() protocol.Network

func (*Service) PairingAgents

func (s *Service) PairingAgents(ctx context.Context, pairingID string) ([]protocol.AgentSummary, error)

func (*Service) PairingAgentsContext

func (s *Service) PairingAgentsContext(ctx context.Context, pairingID string, page protocol.PageRequest) (protocol.AgentPage, error)

func (*Service) PairingForPairScopedContext added in v0.1.15

func (s *Service) PairingForPairScopedContext(ctx context.Context) (protocol.Pairing, bool)

PairingForPairScopedContext is pairingForPairScopedContext, exported so internal/transport's federation discovery gate (filterPairScopedRoomDiscovery, federation_discovery.go) can share the exact same resolution strategy instead of re-deriving its own.

P1-1 (final-gate review, confirmed live): before this export existed, that transport-layer gate matched a pair-scoped caller's pairing by claims.Network() alone -- the network-fallback half of this method's own strategy, with no token-id-first lookup at all. `pair invite` never persists a network binding on the inviter side (that is why the 7B.2 default flip was reverted, see PLAN.md 7B.2), so every inviter-issued pairing credential resolved to nothing and GET /v1/rooms came back empty for it, even though this same service's own room-visibility gate (roomVisibleToPairScopedContext, right below) would have allowed its federated rooms via the token-id lookup above. The two gates enforced different pairing identities for the same request. Exporting this one resolution method -- rather than exporting a second predicate transport re-implements independently, the mistake that produced the divergence in the first place -- means there is exactly one strategy for "which pairing does this pair-scoped credential belong to," and every gate that needs it calls this.

func (*Service) PairingNetwork

func (s *Service) PairingNetwork(ctx context.Context, pairingID string) (protocol.Network, error)

func (*Service) PairingRooms

func (s *Service) PairingRooms(ctx context.Context, pairingID string) ([]protocol.Room, error)

func (*Service) PairingRoomsContext

func (s *Service) PairingRoomsContext(ctx context.Context, pairingID string, page protocol.PageRequest) (protocol.RoomPage, error)

func (*Service) ReconcileRoomContext added in v0.1.11

func (s *Service) ReconcileRoomContext(ctx context.Context, request protocol.CreateRoomRequest) (protocol.Room, error)

func (*Service) RegisterAgentContext

func (s *Service) RegisterAgentContext(
	ctx context.Context,
	request protocol.RegisterAgentRequest,
) (store.RegistrationResult, error)

func (*Service) RegisterDurableAttachmentContext added in v0.1.18

func (s *Service) RegisterDurableAttachmentContext(
	ctx context.Context,
	request protocol.RegisterAgentRequest,
) (protocol.AgentRegistration, <-chan protocol.Event, bool, error)

RegisterDurableAttachmentContext closes the registration/subscription gap: the agent is authenticated and registered before its durable baseline is created, while message commit and publication are excluded by deliveryMu.

func (*Service) RemoveAgentContext added in v0.1.10

func (s *Service) RemoveAgentContext(ctx context.Context, agentID string) (protocol.RemoveResult, error)

func (*Service) RemoveRoomContext added in v0.1.10

func (s *Service) RemoveRoomContext(ctx context.Context, roomID string) (protocol.RemoveResult, error)

func (*Service) SendMessage

func (s *Service) SendMessage(request protocol.SendMessageRequest) (protocol.MessageAccepted, error)

func (*Service) SendMessageContext

func (s *Service) SendMessageContext(ctx context.Context, request protocol.SendMessageRequest) (protocol.MessageAccepted, error)

func (*Service) SetFollowCheckpoint added in v0.1.20

func (s *Service) SetFollowCheckpoint(ctx context.Context, key string, value follow.Checkpoint) error

func (*Service) SetFollowCheckpoints added in v0.1.20

func (s *Service) SetFollowCheckpoints(ctx context.Context, values map[string]follow.Checkpoint, deletePrefixes []string) error

func (*Service) StartPairingDelivery added in v0.1.21

func (s *Service) StartPairingDelivery()

StartPairingDelivery resumes the durable outbox after initial configuration has been applied. New messages also start the worker after acceptance.

func (*Service) Subscribe

func (s *Service) Subscribe(ctx context.Context) <-chan protocol.Event

func (*Service) SubscribeFrom

func (s *Service) SubscribeFrom(ctx context.Context, lastEventID string) <-chan protocol.Event

func (*Service) SubscribeFromContext added in v0.1.19

func (s *Service) SubscribeFromContext(ctx context.Context, lastEventID string) (<-chan protocol.Event, error)

func (*Service) UpdateRoomMembers

func (s *Service) UpdateRoomMembers(
	ctx context.Context,
	roomID string,
	request protocol.UpdateRoomMembersRequest,
) (protocol.Room, error)

type ServiceConfig

type ServiceConfig struct {
	// Now stamps domain data only; operational deadlines always use real time.
	Now                       func() (time.Time, error)
	AllowHumanIngress         bool
	DebugEvents               bool
	DisableDirectMessages     bool
	RequirePairNetworkBinding bool
	NetworkID                 string
	NetworkName               string
	Pairings                  []protocol.Pairing
	Version                   string
	Store                     store.RoomStore
	Messages                  store.MessageStore
	Broker                    EventBroker
	PairingClient             PairingClient
	DeliveryRetryMin          time.Duration
	DeliveryRetryMax          time.Duration
	DeliveryPollInterval      time.Duration
	DeliveryTimeout           time.Duration
	// CausalWriter is optional. When set, SendMessageContext stamps a
	// message.accepted causal event (pkg/protocol.CausalEvent) after each
	// durable, non-duplicate message append. When nil, causal stamping is
	// skipped entirely and message send behavior is unchanged.
	CausalWriter *observability.CausalWriter
	// TranscriptWriter is optional. When set, accepted room/DM messages are
	// exported beside causal.jsonl as research data for the memetics programme.
	TranscriptWriter *observability.TranscriptWriter
}

Jump to

Keyboard shortcuts

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