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
- Variables
- func GateAnswer(a Answer) string
- func WithDelivery(ctx context.Context, d *Delivery) context.Context
- type Answer
- type Books
- type Capped
- type ChatDeps
- type ChatRefusal
- type ChatRequest
- type ChatResult
- type Delivery
- type Gates
- type Intents
- type Ledger
- type PostRequest
- type ProposeRequest
- type ReadRequest
- type Service
- func (s *Service) Chat(ctx context.Context, r ChatRequest) (ChatResult, error)
- func (s *Service) Chats() turns.Chats
- func (s *Service) Conversation(ctx context.Context, m message.Message) (message.Conversation, error)
- func (s *Service) Decide(ctx context.Context, g gate.Gate) error
- func (s *Service) Deliver(ctx context.Context, g gate.Gate) error
- func (s *Service) GateOf(ctx context.Context, m message.Message) (gate.Gate, bool, error)
- func (s *Service) OpenMissing(ctx context.Context, g gate.Gate) (gate.Gate, error)
- func (s *Service) Post(ctx context.Context, p PostRequest) (message.Message, error)
- func (s *Service) Propose(ctx context.Context, p ProposeRequest) (message.Message, error)
- func (s *Service) Question(ctx context.Context, u unit.Unit) (message.Message, bool, error)
- func (s *Service) Read(ctx context.Context, r ReadRequest) ([]message.Conversation, error)
- func (s *Service) ReadTask(ctx context.Context, r ReadRequest) (TaskRead, error)
- func (s *Service) Reanswer(ctx context.Context, id int64, a Answer) (turns.AnswerResult, error)
- func (s *Service) Reconcile(ctx context.Context, units ...unit.Unit) error
- func (s *Service) ReconcileProposals(ctx context.Context) error
- func (s *Service) Run(ctx context.Context, changes port.Changes)
- type Sessions
- type TaskLog
- type TaskRead
- type TaskUnits
- type Tasks
- type Turns
Constants ¶
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.
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.
const KindChat = "message"
KindChat is the event kind of a message the user wrote on a task's chat: its Data is {"text": ...}.
const PostsPerTurn = 3
PostsPerTurn is how many agent posts of one turn may be open at once.
Variables ¶
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") )
var ErrNoChat = errors.New("the chat is not served")
ErrNoChat refuses a chat the service is not wired for.
var ErrNoTurn = errors.New("this session has no turn")
ErrNoTurn refuses a read from a session with no turn on the unit.
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.
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
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.
Types ¶
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 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
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
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.
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 ProposeRequest ¶
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
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
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
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) OpenMissing ¶ added in v0.3.0
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 ¶
Post is task_post: an open agent_post message, with its gate, on the unit of the session's started turn.
func (*Service) Propose ¶
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
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
func (s *Service) Read(ctx context.Context, r ReadRequest) ([]message.Conversation, error)
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
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
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 ¶
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 ¶
ReconcileProposals makes one open proposal message, with its gate, per open items.Proposal; one whose proposal is no longer open closes.
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 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. |