messages

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package messages keeps the Inbox messages: questions of turns, agent posts and proposals that ask a decision.

Index

Constants

View Source
const (
	OptionAccept = "accept"
	OptionReject = "reject"
)

The options of a ledger proposal's message.

View Source
const PostsPerTurn = 3

PostsPerTurn is how many agent posts of one turn may be open at once.

Variables

View Source
var (
	ErrNoMessage = errors.New("no such message")
	// ErrClosed is an answer or a dismiss of a message that is no longer open.
	ErrClosed = errors.New("the message is closed")
	// ErrNoStartedTurn refuses inbox_post from a session with no started turn.
	ErrNoStartedTurn = errors.New("this session has no started turn")
)

Functions

This section is empty.

Types

type Answer

type Answer struct {
	Text, OptionID string
	Yes, No        bool
	Source         turn.Source
}

type Books

type Books interface {
	Books(ctx context.Context, units ...unit.Unit) (map[unit.Unit]turn.Book, error)
	BookOf(ctx context.Context, k turns.Key) (turn.Book, bool, error)
}

Books reads the turn books, as turns.Store does.

type Capped

type Capped struct{ Max int }

Capped refuses a post over PostsPerTurn.

func (Capped) Error

func (c Capped) Error() string

type Entries

type Entries interface {
	Open(ctx context.Context, r coregtd.OpenRequest) (gtd.Entry, error)
	Close(ctx context.Context, id gtd.ID, to gtd.State) error
	Entry(ctx context.Context, id gtd.ID) (gtd.Entry, error)
	Retitle(ctx context.Context, id gtd.ID, title string) error
}

Entries opens and closes the Inbox entry of each message, as gtd.Service does.

type Intents

type Intents interface{ Answerable() []string }

Intents names the intents whose questions an answer addresses.

type Ledger

type Ledger interface {
	Proposals(ctx context.Context, state coreitems.ProposalState) ([]coreitems.Proposal, error)
	Decide(ctx context.Context, id int64, accept bool) (coreitems.Result, error)
}

Ledger is the items ledger's proposals.

type PostRequest

type PostRequest struct {
	Session, Text, Recommend string
	Options                  []record.Option
	Confirm                  bool
}

type ProposeRequest

type ProposeRequest struct {
	Unit    unit.Unit
	EntryID string // attach to an existing entry; "" opens a new Inbox entry
	Text    string
	Options []record.Option // answering an option calls OnAnswer
	Origin  message.Origin  // Kind core or workflow; Workflow names the rule (dedupe key with Unit)
}

type Service

type Service struct {
	Store   message.Store
	Books   Books
	Turns   Turns
	Ledger  Ledger // nil: no proposal messages
	Entries Entries
	Intents Intents
	Clock   port.Clock
	Log     func(format string, args ...any)
	// OnAnswer runs when a core or workflow proposal is answered, before it closes; nil only closes it.
	OnAnswer func(ctx context.Context, m message.Message, a Answer) error
	// contains filtered or unexported fields
}

func (*Service) Answer

func (s *Service) Answer(ctx context.Context, id int64, a Answer) (turns.AnswerResult, error)

Answer answers an open message: a question through turns.Service.Answer unchanged, an agent post into the session that posted it, a proposal by deciding it.

func (*Service) Dismiss

func (s *Service) Dismiss(ctx context.Context, id int64) error

Dismiss closes a message without an answer: a question's turn is dismissed as turns.Service.Dismiss does, a ledger proposal is rejected.

func (*Service) Post

func (s *Service) Post(ctx context.Context, p PostRequest) (message.Message, error)

Post is inbox_post: an open agent_post message on the unit of the session's started turn.

func (*Service) Propose

func (s *Service) Propose(ctx context.Context, p ProposeRequest) (message.Message, error)

Propose opens a proposal message of a workflow or core rule, one per unit and rule while it is open; with EntryID it attaches to that entry instead of opening one.

func (*Service) Reconcile

func (s *Service) Reconcile(ctx context.Context, units ...unit.Unit) error

Reconcile makes the open question messages match the books: one per turn whose newest record is asked or that stopped waiting on the user; others closed. With no units it reconciles every book.

func (*Service) ReconcileProposals

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

ReconcileProposals makes one open proposal message per open items.Proposal; closed when it is decided.

func (*Service) Run

func (s *Service) Run(ctx context.Context, changes port.Changes)

Run reconciles every book and proposal, then the units of each TopicTurns note and the proposals on each TopicItems note, on its own goroutine, until ctx ends: the subscriber only queues them.

type Turns

type Turns interface {
	Answer(ctx context.Context, r turns.AnswerRequest) (turns.AnswerResult, error)
	Dismiss(ctx context.Context, u unit.Unit) error
}

Turns answers and dismisses a unit's question, as turns.Service does.

Directories

Path Synopsis
Package messagestest holds an in-memory message store and the contract every message store meets.
Package messagestest holds an in-memory message store and the contract every message store meets.

Jump to

Keyboard shortcuts

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