messages

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 24 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 subjects of the question, post and proposal gates: a turn's question, an agent's post and a proposal. Each open message waits on its gate; resolving the gate delivers its answer to the session or applies its decision, and closes the message.

Index

Constants

View Source
const (
	ChatRead = "chat.read"
	ChatTold = "chat.told"
)

The marks on a task's own unit of its chat: ChatRead, the newest message its agents read or were started with; ChatTold, the newest one a notice told an agent of.

View Source
const (
	ChatTyped = "typed"
	// ChatQueued waits for the busy agent's next stop, which the notice blocks.
	ChatQueued  = "queued"
	ChatStarted = "started"
	ChatResumed = "resumed"
)

How a chat message reached the task's agent.

View Source
const KindChat = "message"

KindChat is the event kind of a message the user wrote on a task's chat: its Data is {"text": ...}.

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 to a message that is no longer open.
	ErrClosed = errors.New("the message is closed")
	// ErrNoStartedTurn refuses task_post from a session with no started turn.
	ErrNoStartedTurn = errors.New("this session has no started turn")
)
View Source
var ErrNoChat = errors.New("the chat is not served")

ErrNoChat refuses a chat the service is not wired for.

View Source
var ErrNoTurn = errors.New("this session has no turn")

ErrNoTurn refuses a read from a session with no turn on the unit.

View Source
var ErrNotApplied = errors.New("the approved proposal was not applied")

ErrNotApplied is an approved proposal whose operations the ledger refused: it stays open, on a new gate.

View Source
var ErrNotTheTasks = errors.New("this session has no turn on the task")

ErrNotTheTasks refuses a read of a task's chat to a session with no turn on the task or a unit it holds.

Functions

func GateAnswer added in v0.3.0

func GateAnswer(a Answer) string

GateAnswer is a's text as a question or post gate takes it, which AnswerOf reads back: the option, or yes or no, on its first line, then the note.

func WithDelivery added in v0.3.0

func WithDelivery(ctx context.Context, d *Delivery) context.Context

WithDelivery is ctx carrying d, which Deliver reads the answer's source from and fills with its route.

Types

type Answer

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

func AnswerOf added in v0.3.0

func AnswerOf(m message.Message, text string) Answer

AnswerOf reads a gate's answer to m: a first line naming one of m's options, or yes or no on a confirm, chooses it, and the lines after it are the note; any other text is the answer itself.

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 ChatDeps added in v0.3.0

type ChatDeps struct {
	Sessions Sessions
	Log      TaskLog
	Units    TaskUnits
	// Intent is the profile's chat intent, the turn a message starts when no session of its task is live.
	Intent func() string
}

ChatDeps are what the chat on the tasks needs; a Service with zero ChatDeps serves no chat.

type ChatRefusal added in v0.3.0

type ChatRefusal struct{ Why string }

ChatRefusal is a message the loop stored on the task but could not deliver.

func (ChatRefusal) Error added in v0.3.0

func (r ChatRefusal) Error() string

type ChatRequest added in v0.3.0

type ChatRequest struct {
	Task   task.ID
	Text   string
	Intent string
}

ChatRequest is a message the user wrote on a task's chat; Intent is the intent of the turn it starts when no session of the task is live, the profile's chat intent when "".

type ChatResult added in v0.3.0

type ChatResult struct {
	Seq      int64
	Route    string
	Session  string
	Intent   string
	ResumeOf int64
}

ChatResult is where a chat message went: Route, the session typed into, or the intent and the turn its new turn resumes.

type Delivery added in v0.3.0

type Delivery struct {
	Source turn.Source
	Route  turns.AnswerResult
}

Delivery is what the caller of a gate's resolution learns of the answer it delivered: the Source it gives the answer, and the Route the answer took.

func DeliveryOf added in v0.3.0

func DeliveryOf(ctx context.Context) (*Delivery, bool)

DeliveryOf is the Delivery ctx carries; false when it carries none.

type Gates added in v0.3.0

type Gates interface {
	Open(ctx context.Context, g gate.Gate, p gates.Policy) (gate.Gate, error)
	Supersede(ctx context.Context, id int64, by task.Actor) error
	Where(ctx context.Context, q gates.Query) ([]gate.Gate, error)
}

Gates are the gates the messages are the subjects of, as gates.Service opens and supersedes them.

type Intents

type Intents interface {
	Answerable() []string
	Rules(intent string) (dintent.RecordRules, error)
}

Intents names the intents whose questions an answer addresses, and the missing gate of each.

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
	TaskID  string // the task its gate is on; "" is its unit's task, or a capture task with no unit
	Text    string
	Options []record.Option
	Origin  message.Origin // Kind core or workflow; Workflow names the rule (dedupe key with Unit)
}

type ReadRequest added in v0.3.0

type ReadRequest struct {
	Session string
	// Unit is the unit whose turns the session holds; zero is the unit of its newest turn.
	Unit unit.Unit
	// Message is the message to read; 0 reads every answer the agent has not read.
	Message int64
	// Gate, in place of Message, reads the answers that resolved it.
	Gate int64
}

ReadRequest is task_read's answers: the answers to the messages of the session's turns.

type Service

type Service struct {
	Store   message.Store
	Books   Books
	Turns   Turns
	Ledger  Ledger // nil: no proposal messages
	Tasks   Tasks
	Gates   Gates
	Intents Intents
	Clock   port.Clock
	Log     func(format string, args ...any)
	// OnAnswer runs when a core or workflow proposal's gate is resolved, before it closes; nil only closes it.
	OnAnswer func(ctx context.Context, m message.Message, a Answer) error
	// ProposalText words a ledger proposal's message, as the profile's proposal gate does; nil leaves it
	// without text.
	ProposalText func(p coreitems.Proposal) string
	// ChatDeps serve the chat on the tasks; zero serves none.
	ChatDeps ChatDeps
	// contains filtered or unexported fields
}

func (*Service) Chat added in v0.3.0

func (s *Service) Chat(ctx context.Context, r ChatRequest) (ChatResult, error)

Chat keeps the message on the task's own unit, then delivers it: a live session of any of the task's units is typed the notice that a message waits, which the agent reads with the task's read tool, or, while its agent is busy, is told at its next stop; with none, a turn of the chat intent starts on the task's own unit with every message its agents have not read as its guidance, oldest first, resuming the last run there that had a session.

func (*Service) Chats added in v0.3.0

func (s *Service) Chats() turns.Chats

Chats are the chats no notice told an agent of, which a session's stop tells of.

func (*Service) Conversation added in v0.3.0

func (s *Service) Conversation(ctx context.Context, m message.Message) (message.Conversation, error)

Conversation is m and the answers the user gave to it.

func (*Service) Decide added in v0.3.0

func (s *Service) Decide(ctx context.Context, g gate.Gate) error

Decide is a resolved proposal gate's consequence: an item proposal is accepted when the gate is approved and rejected otherwise, a workflow's or core rule's goes to OnAnswer, and its message closes. A ledger proposal is decided under the lock ReconcileProposals holds, even when the reconcile already closed its message as its gate decided; one whose operations the ledger refuses stays open on a new gate, and Decide returns ErrNotApplied.

func (*Service) Deliver added in v0.3.0

func (s *Service) Deliver(ctx context.Context, g gate.Gate) error

Deliver is a resolved question or post gate's consequence: the answer goes to the session that asked, a dismissal dismisses the question, and the message closes. A missing gate's answer resumes its turn with it, an answer with no text resumes it as it was, and a dismissal dismisses it.

func (*Service) GateOf added in v0.3.0

func (s *Service) GateOf(ctx context.Context, m message.Message) (gate.Gate, bool, error)

GateOf is m's open gate; false when it has none.

func (*Service) OpenMissing added in v0.3.0

func (s *Service) OpenMissing(ctx context.Context, g gate.Gate) (gate.Gate, error)

OpenMissing opens g, the missing gate of a turn that failed or ended without its record, unless one with its subject is open on its unit already; it returns the open one. A gate on a task that closed moves off it, as a message's does, and a run whose own task closed asks nothing more: it returns no gate.

func (*Service) Post

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

Post is task_post: an open agent_post message, with its gate, 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, with its gate, one per unit and rule while it is open; with TaskID its gate is on that task.

func (*Service) Question added in v0.3.0

func (s *Service) Question(ctx context.Context, u unit.Unit) (message.Message, bool, error)

Question is the question message of the unit's turn while that turn asks: the open one, after reconciling it with the unit's book, or the one already answered, which a newer answer given with no gate open replaces or adds to.

func (*Service) Read added in v0.3.0

Read returns the answers the user gave to the messages of the session's turns, oldest first, and marks them read: with a message, that message and every answer to it; without, every answer not read yet. An answer still waiting for the session to stop is not read: its notice is on the way.

func (*Service) ReadTask added in v0.3.0

func (s *Service) ReadTask(ctx context.Context, r ReadRequest) (TaskRead, error)

ReadTask is the task's read tool: Read's answers, with the task of the session's turns, its brief, its open gates and the chat messages not read yet, which it marks read. A session whose turns are on no task reads the answers alone.

func (*Service) Reanswer added in v0.3.0

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

Reanswer answers question message id again, given its gate closed answered while its turn still asks: the newer answer replaces a queued one or adds to it, and rewords the message.

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, each with its open gate; others closed, their gates superseded. A missing gate whose turn no longer waits on the user is superseded too. With no units it reconciles every book.

func (*Service) ReconcileProposals

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

ReconcileProposals makes one open proposal message, with its gate, per open items.Proposal; one whose proposal is no longer open closes.

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 and TopicTasks note, so a gate leaves a task that closed, and the proposals on each TopicItems note, on its own goroutine, until ctx ends: the subscriber only queues them.

type Sessions added in v0.3.0

type Sessions interface {
	LiveOn(ctx context.Context, units ...unit.Unit) (turn.Session, bool, error)
	Busy(ctx context.Context, sess turn.Session) (bool, error)
	TellChat(ctx context.Context, sess turn.Session, task unit.Unit) (bool, error)
	LastRun(ctx context.Context, u unit.Unit) (turn.Turn, bool, error)
	Launch(ctx context.Context, l turns.Launch) error
}

Sessions reach a task's agent, as turns.Service does: the live session of its units, typed a notice that the user wrote unless its agent is busy, else a new turn that resumes the last run of the task's own unit.

type TaskLog added in v0.3.0

type TaskLog interface {
	RecordEvents(ctx context.Context, evs ...port.Event) error
	Of(ctx context.Context, id task.ID, f timeline.Filter) ([]timeline.Event, error)
	Marks(ctx context.Context, u unit.Unit) (map[string]string, error)
	SetMarks(ctx context.Context, u unit.Unit, marks map[string]string) error
	// Brief is the task's brief record's data, false when it keeps none.
	Brief(ctx context.Context, e task.Task) (string, bool, error)
}

TaskLog is a task's side of its chat: the messages in the event log, the marks of how far its agents read them, and its brief.

type TaskRead added in v0.3.0

type TaskRead struct {
	Task    task.Task
	Brief   string
	Gates   []gate.Gate
	Chat    []timeline.Event
	Answers []message.Conversation
}

TaskRead is what an agent reads of the task its session works on: the task, its brief, its open gates, the chat messages since its agents last read, oldest first, and the answers to the session's gates.

type TaskUnits added in v0.3.0

type TaskUnits interface {
	TasksOf(ctx context.Context, u unit.Unit) ([]task.Task, error)
}

TaskUnits are the tasks a unit is on.

type Tasks added in v0.3.0

type Tasks interface {
	Close(ctx context.Context, id task.ID, to task.Category) error
	Task(ctx context.Context, id task.ID) (task.Task, error)
	Retitle(ctx context.Context, id task.ID, title string) error
}

Tasks names the capture task a message on no unit gets after its text, and closes the message task a message of an earlier version holds, as tasks.Service does.

type Turns

type Turns interface {
	Answer(ctx context.Context, r turns.AnswerRequest) (turns.AnswerResult, error)
	Continue(ctx context.Context, u unit.Unit) error
	Dismiss(ctx context.Context, u unit.Unit) error
	MarkRead(ctx context.Context, u unit.Unit, ids []int64) error
}

Turns answers, continues and dismisses a unit's question and notes the answers an agent read, 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