Documentation
¶
Index ¶
- Variables
- func Marker(frame []byte) string
- type Agent
- func (a *Agent) BuildSystemPrompt() string
- func (a *Agent) CancelRequest(string) error
- func (a *Agent) GetMetrics(string) *agentdomain.ChatMetrics
- func (a *Agent) GetReasoningEffort() string
- func (a *Agent) RunWithStream(ctx context.Context, req *agentdomain.AgentRequest) (<-chan agentdomain.ChatEvent, error)
- func (a *Agent) SetReasoningEffort(string) error
- type Models
- type Options
- type Storage
- func (s *Storage) Close() error
- func (s *Storage) DeleteConversation(context.Context, string) error
- func (s *Storage) Health(context.Context) error
- func (s *Storage) ListConversations(ctx context.Context, _ string, _, offset int) ([]convdomain.ConversationSummary, error)
- func (s *Storage) ListConversationsNeedingTitles(context.Context, int) ([]convdomain.ConversationSummary, error)
- func (s *Storage) LoadConversation(ctx context.Context, conversationID string) ([]convdomain.ConversationEntry, convdomain.ConversationMetadata, error)
- func (s *Storage) SaveConversation(context.Context, string, []convdomain.ConversationEntry, ...) error
- func (s *Storage) UpdateConversationMetadata(context.Context, string, convdomain.ConversationMetadata) error
- type Thread
- func (t *Thread) Attach(*agui.Conn)
- func (t *Thread) CancelTeleport() error
- func (t *Thread) Close()
- func (t *Thread) Connect(ctx context.Context) error
- func (t *Thread) Consume() func()
- func (t *Thread) Detach(conn *agui.Conn)
- func (t *Thread) DiscardSettled()
- func (t *Thread) Follow(ctx context.Context, id string, opts sessionsdomain.ThreadOptions) error
- func (t *Thread) Follows(id string) bool
- func (t *Thread) Generation() int
- func (t *Thread) Handle(_ *agui.Conn, data []byte)
- func (t *Thread) ListEnvironments(ctx context.Context) ([]agentdomain.EnvironmentStatus, error)
- func (t *Thread) Live() string
- func (t *Thread) MoveTo(projectDir string)
- func (t *Thread) Next(ctx context.Context) ([]byte, error)
- func (t *Thread) Pending() bool
- func (t *Thread) Placement() tui.SessionPlacement
- func (t *Thread) Request(ctx context.Context, frame any, replyType string) ([]byte, error)
- func (t *Thread) Running() bool
- func (t *Thread) Send(frame any) error
- func (t *Thread) SessionProject(ctx context.Context, id string) string
- func (t *Thread) SetNotifier(notifier agentdomain.UINotifier)
- func (t *Thread) SetSynced(id string, n int)
- func (t *Thread) Synced(id string) int
- func (t *Thread) Teleport(target string, files []string) error
- func (t *Thread) Unfollowed() bool
Constants ¶
This section is empty.
Variables ¶
var ErrOffline = errors.New("lost the connection to infer daemon, reconnecting")
ErrOffline is what a request gets while the daemon connection is down.
Functions ¶
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is the chat TUI's agent in daemon mode: each turn runs on the thread's worker, wherever it runs, and comes back decoded into the chat events the TUI renders. The TUI's conversation is a mirror of the worker's, written as events arrive and reconciled from the worker when a turn ends.
func NewAgent ¶
func NewAgent(thread *Thread, repo convdomain.ConversationRepository, queue convdomain.MessageQueue, modes agentdomain.AgentModeState, models convdomain.ModelService) *Agent
NewAgent builds the daemon-mode agent over thread, mirroring into repo.
func (*Agent) BuildSystemPrompt ¶
func (*Agent) CancelRequest ¶
CancelRequest interrupts the thread's open run.
func (*Agent) GetMetrics ¶
func (a *Agent) GetMetrics(string) *agentdomain.ChatMetrics
func (*Agent) GetReasoningEffort ¶
func (*Agent) RunWithStream ¶
func (a *Agent) RunWithStream(ctx context.Context, req *agentdomain.AgentRequest) (<-chan agentdomain.ChatEvent, error)
RunWithStream sends the user's new messages to the thread, or with none follows the run another client started, and streams the run's events. The stream ends once the run finished and the conversation was reconciled.
func (*Agent) SetReasoningEffort ¶
type Models ¶
type Models struct {
// contains filtered or unexported fields
}
Models is the chat TUI's model service in daemon mode: the models the thread's worker can use, and the one its turns run on.
func (*Models) GetCurrentModel ¶
func (*Models) IsModelAvailable ¶
IsModelAvailable reports whether the worker lists modelID. Before the first listing every model counts as available.
func (*Models) ListModels ¶
ListModels asks the worker for its models, adopting its current one when the TUI has not picked one yet. Their context windows, prices and modalities, which the worker fetched from its gateway, are recorded here too, so the model picker shows them.
func (*Models) SelectModel ¶
SelectModel switches the model the thread's next turns use. The worker learns it when the next turn starts, so a pick made offline is not lost.
func (*Models) ValidateModel ¶
type Options ¶
type Options struct {
ProjectDir string
}
Options name the project a daemon chat runs its threads in.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage is the chat TUI's conversation storage in daemon mode: the thread's worker stores every conversation, and the TUI reads them over the binding. Writes are the worker's own, so saving here does nothing.
func NewStorage ¶
NewStorage builds the daemon-mode conversation storage over thread.
func (*Storage) DeleteConversation ¶
func (*Storage) ListConversations ¶
func (s *Storage) ListConversations(ctx context.Context, _ string, _, offset int) ([]convdomain.ConversationSummary, error)
ListConversations lists the conversations of the environment the session runs on, in the worker's project.
func (*Storage) ListConversationsNeedingTitles ¶
func (s *Storage) ListConversationsNeedingTitles(context.Context, int) ([]convdomain.ConversationSummary, error)
func (*Storage) LoadConversation ¶
func (s *Storage) LoadConversation(ctx context.Context, conversationID string) ([]convdomain.ConversationEntry, convdomain.ConversationMetadata, error)
LoadConversation follows the conversation's thread and reads the conversation as its worker stored it.
func (*Storage) SaveConversation ¶
func (s *Storage) SaveConversation(context.Context, string, []convdomain.ConversationEntry, convdomain.ConversationMetadata) error
func (*Storage) UpdateConversationMetadata ¶
func (s *Storage) UpdateConversationMetadata(context.Context, string, convdomain.ConversationMetadata) error
type Thread ¶
type Thread struct {
// contains filtered or unexported fields
}
Thread is the chat TUI's connection to the local daemon's binding and to the one thread it follows there. Frames never block the socket: run frames queue for the request that reads them, replies go to their waiters, and UI notifications leave through a queue of their own.
func New ¶
func New(cfg *config.Config, opts Options, leases agentdomain.LeaseStore) *Thread
New builds the thread connection for a daemon chat in opts.ProjectDir. It reads the session's lease from leases to tell where it runs.
func (*Thread) CancelTeleport ¶
CancelTeleport stops the running teleport, which leaves the session here.
func (*Thread) Connect ¶
Connect dials the local daemon, starting it when nothing listens on the binding, and fails fast when the binding cannot authenticate the TUI.
func (*Thread) Consume ¶
func (t *Thread) Consume() func()
Consume marks a request as the reader of the run frames until the returned release runs, so a run it started does not ask the TUI to follow it. A run that started while the request was finishing, as an accepted plan's does, asks once the release runs. A request may start before the last one's release ran, so only the last release does.
func (*Thread) Detach ¶
Detach notes the dropped connection: waiting requests fail, the request reading run frames learns of it, and reconnecting starts.
func (*Thread) DiscardSettled ¶
func (t *Thread) DiscardSettled()
DiscardSettled drops queued frames of runs that already ended, which the reconcile of the next turn's history covers, so a new turn reads only what is still to come.
func (*Thread) Follow ¶
func (t *Thread) Follow(ctx context.Context, id string, opts sessionsdomain.ThreadOptions) error
Follow makes the connection follow the conversation id, creating it on the worker when it does not exist yet. opts apply when the daemon starts the thread's worker, and a session that runs remotely is followed there.
func (*Thread) Follows ¶
Follows reports whether the connection follows the conversation id, which it also does once a rollover or an accepted plan moved the thread on to id.
func (*Thread) Generation ¶
Generation counts the connections to the daemon, since a daemon that restarted meanwhile runs a fresh worker behind the same thread.
func (*Thread) ListEnvironments ¶
func (t *Thread) ListEnvironments(ctx context.Context) ([]agentdomain.EnvironmentStatus, error)
ListEnvironments asks the daemon for every environment it knows, the local one first, with whether each is reachable.
func (*Thread) MoveTo ¶
MoveTo makes this a daemon chat in projectDir. It is for attaching, before the thread follows a session, since every request names the project dir.
func (*Thread) Placement ¶
func (t *Thread) Placement() tui.SessionPlacement
Placement is where the followed session runs.
func (*Thread) Request ¶
Request sends frame and returns the first reply of replyType, or the error a RUN_ERROR without a run carries in its place.
func (*Thread) SessionProject ¶
SessionProject is the project dir of a session this machine's daemon runs, from its lease, or "" when another environment runs it or no lease names one.
func (*Thread) SetNotifier ¶
func (t *Thread) SetNotifier(notifier agentdomain.UINotifier)
SetNotifier hands the thread the UI it reports to once the TUI runs.
func (*Thread) Synced ¶
Synced is how many entries of conversation id the worker already has, so a turn sends only the user's new messages.
func (*Thread) Teleport ¶
Teleport starts teleporting the followed session to target. Progress arrives as TeleportProgressEvent, and the teleport as a SessionPlacementChangedEvent.
func (*Thread) Unfollowed ¶
Unfollowed reports whether a run started, or one suspended on a prompt was replayed, with no turn reading the thread since, or a run is under way. A chat that attached before its UI could take the follow request still owes it.