assistant

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 10 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 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

View Source
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.

View Source
const (
	RoleUser      = "user"
	RoleAssistant = "assistant"
	RoleEvent     = "event"
)

Roles of a line.

Variables

This section is empty.

Functions

func IsBadInput

func IsBadInput(err error) bool

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.

func (*Error) Error

func (e *Error) Error() string

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

func New(dir string) *Service

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) Append

func (s *Service) Append(in []NewLine) ([]Line, int64, error)

Append adds lines at the end, giving each an id and the time.

func (*Service) Clear

func (s *Service) Clear() (int64, error)

Clear drops the history; the chats and the focus stay.

func (*Service) Follow

func (s *Service) Follow(conv, title string) (int64, error)

Follow takes a chat under the assistant's control (idempotent; a new title renames it).

func (*Service) Get

func (s *Service) Get(before string) Talk

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

func (s *Service) SetFocus(conv string) (int64, error)

SetFocus makes conv the chat in focus; a chat not under control is taken under control by it. "" clears it.

func (*Service) Subscribe

func (s *Service) Subscribe() (<-chan int64, func())

Subscribe returns a channel of revs, one per change (a slow reader gets the newest only), and the stop.

func (*Service) Unfollow

func (s *Service) Unfollow(conv string) (int64, error)

Unfollow lets a chat go; the focus is cleared when it was the chat.

type Talk

type Talk struct {
	Rev   int64      `json:"rev"`
	Focus *string    `json:"focus"`
	Chats []Followed `json:"chats"`
	Lines []Line     `json:"lines"`
}

Talk is the whole state.

Jump to

Keyboard shortcuts

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