Documentation
¶
Overview ¶
Package assistant keeps the voice assistant's talk (docs/voice-assistant.md): one pinned conversation of the person's per machine data folder, the agent chats the assistant has under its control and the one in focus. The voice and the screen both write here through the runtime's routes; every change grows Rev, and a subscriber is told so the other tab or the voice re-reads.
The whole talk is one small JSON file (<data>/assistant/talk.json), written whole and atomically: a crash leaves the old talk or the new one, never half of one.
Index ¶
- Constants
- func IsBadInput(err error) bool
- type Error
- type Followed
- type Line
- type NewLine
- type Service
- func (s *Service) Append(in []NewLine) ([]Line, int64, error)
- func (s *Service) Clear() (int64, error)
- func (s *Service) Follow(conv, title string) (int64, error)
- func (s *Service) Get(before string) Talk
- func (s *Service) SetFocus(conv string) (int64, error)
- func (s *Service) Subscribe() (<-chan int64, func())
- func (s *Service) Unfollow(conv string) (int64, error)
- type Talk
Constants ¶
const ( MaxLines = 2000 PageLines = 300 // what GET returns without ?before MaxText = 4000 MaxDetail = 20000 MaxTitle = 200 MaxConvLen = 200 MaxChats = 100 MaxBatch = 50 )
Limits. Lines past MaxLines are dropped oldest first; a talk is a feed, not an archive. The text limits keep one bad caller (or a runaway agent reply written as a line) from making the file and every GET huge.
const ( RoleUser = "user" RoleAssistant = "assistant" RoleEvent = "event" )
Roles of a line.
Variables ¶
This section is empty.
Functions ¶
func IsBadInput ¶
IsBadInput says whether err is the caller's fault.
Types ¶
type Error ¶
type Error struct{ Msg string }
Error is a refusal of bad input; the routes answer it with 400.
type Followed ¶
type Followed struct {
Conv string `json:"conv"`
Title string `json:"title"`
Since int64 `json:"since"`
}
Followed is a chat under the assistant's control.
type Line ¶
type Line struct {
ID string `json:"id"`
At int64 `json:"at"`
Role string `json:"role"`
Text string `json:"text"`
Kind string `json:"kind,omitempty"`
// Chat is the chat an event is about; Detail is its long part (the prompt sent to an agent), folded in the feed.
Chat string `json:"chat,omitempty"`
Detail string `json:"detail,omitempty"`
}
Line is one thing in the feed: what was said, or what the assistant did (role "event").
type NewLine ¶
type NewLine struct {
Role string `json:"role"`
Text string `json:"text"`
Kind string `json:"kind,omitempty"`
Chat string `json:"chat,omitempty"`
Detail string `json:"detail,omitempty"`
}
NewLine is a line before it has an id and a time.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the talk of one data folder.
func New ¶
New opens the talk kept in dir (made on the first write). A talk file that cannot be read starts an empty talk: the voice must work, and the lines are a convenience, not the person's data.
func (*Service) Follow ¶
Follow takes a chat under the assistant's control (idempotent; a new title renames it).
func (*Service) Get ¶
Get is the talk: the last PageLines lines, or the PageLines before the line `before` (none when it is not there any more: nothing older is kept).
func (*Service) SetFocus ¶
SetFocus makes conv the chat in focus; a chat not under control is taken under control by it. "" clears it.