Documentation
¶
Overview ¶
Package tui owns the interactive `askit chat` experience. The bubbletea Model drives a scrollable transcript, a multi-line input area, and a slash-command dispatcher that never reaches the model. @path file references in input are expanded at submit time via the prompt package.
NOTE (v0.1.x): The `@`-triggered overlay file picker described in spec §8.2 is DEFERRED to v0.2. In v0.1.x, @path references in typed input are resolved against the filesystem exactly like `askit query`. The slash-command, streaming, cancel, and save flows are complete.
Index ¶
- func IsSlash(input string) bool
- type Entry
- type Model
- type RealRequester
- type Requester
- type Role
- type Session
- func (s *Session) AppendAssistantChunk(delta string)
- func (s *Session) AppendUser(text string)
- func (s *Session) ClearHistory()
- func (s *Session) LastAssistantText() string
- func (s *Session) MarkLastCancelled()
- func (s *Session) RecordReferences(refs []prompt.FileRef)
- func (s *Session) SaveConversation(path string) error
- func (s *Session) SaveLastReply(path string) error
- func (s *Session) StartAssistant() *Entry
- type SlashResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
Entry is one message in the transcript. Streaming assistant replies accumulate into the most recent entry's Text field.
type Model ¶
type Model struct {
Session *Session
Cfg *config.Config
Req Requester
Logger *slog.Logger
NoColor bool
// contains filtered or unexported fields
}
Model is the bubbletea Model driving the chat TUI.
func New ¶
func New(sess *Session, cfg *config.Config, req Requester, logger *slog.Logger, noColor bool) *Model
New builds a chat model from an active session and requester.
type RealRequester ¶
RealRequester is the production Requester implementation backed by a *client.Client.
func (RealRequester) Stream ¶
func (r RealRequester) Stream(ctx context.Context, req *client.Request) (<-chan client.StreamChunk, <-chan error)
Stream delegates to Client.Stream.
type Requester ¶
type Requester interface {
Stream(ctx context.Context, req *client.Request) (<-chan client.StreamChunk, <-chan error)
}
Requester abstracts the HTTP/SSE call for testability. The default implementation is RealRequester which wraps a *client.Client.
type Session ¶
type Session struct {
SystemPrompt string
PresetName string
Model string
ConfigFilePath string
History []Entry
References []prompt.FileRef // all @path refs seen this session
InFlight bool
}
Session is the in-memory state of one interactive run. Never persisted.
func (*Session) AppendAssistantChunk ¶
AppendAssistantChunk adds a streamed delta to the most recent assistant entry (or creates one if none exists).
func (*Session) AppendUser ¶
AppendUser adds a user message to the transcript.
func (*Session) ClearHistory ¶
func (s *Session) ClearHistory()
ClearHistory drops all messages; keeps the system prompt.
func (*Session) LastAssistantText ¶
LastAssistantText returns the text of the most recent assistant message, or the empty string if none.
func (*Session) MarkLastCancelled ¶
func (s *Session) MarkLastCancelled()
MarkLastCancelled tags the most recent assistant entry as cancelled.
func (*Session) RecordReferences ¶
RecordReferences merges newly-resolved file references into the session-wide list. Duplicates are skipped by resolved Path.
func (*Session) SaveConversation ¶
SaveConversation writes the full transcript to path. Format by extension: `.json` = array of entries; `.md` = formatted Markdown; `.txt` = plain role-prefixed lines.
func (*Session) SaveLastReply ¶
SaveLastReply writes the most recent assistant reply to path. The format is chosen by extension per FR-056 (revised): `.json`, `.md`, or `.txt`. Other extensions are rejected.
func (*Session) StartAssistant ¶
StartAssistant opens a new assistant entry ready to receive streamed chunks. Returns a pointer to allow in-place updates by callers.
type SlashResult ¶
type SlashResult struct {
Handled bool // true if the input was a slash command (don't send to model)
Notice string // optional inline transcript message (info/ok)
Err error // inline transcript error; session stays alive
Quit bool // true if /quit or /exit
ClearView bool // true after /clear (UI may want to redraw)
}
SlashResult is produced by DispatchSlash so the bubbletea model can react without the dispatcher itself touching the UI.
func DispatchSlash ¶
DispatchSlash parses and executes a slash command against sess. Presets is passed separately so /preset can introspect the available set without importing config into the model file.
Unrecognized commands produce a SlashResult{Handled: true, Err: ...} so the TUI can render the error inline without re-routing to the model.