chat

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmdResume = "/resume"
	CmdModels = "/models"
	CmdQuit   = "/quit"
	CmdExit   = "/exit"
	CmdNew    = "/new"
	CmdClear  = "/clear"
)

Command constants for chat commands.

Variables

This section is empty.

Functions

func Run

func Run(client api.Client, modelName string, session *config.Session) error

Run starts the chat TUI.

Types

type AutocompleteState

type AutocompleteState struct {
	// contains filtered or unexported fields
}

AutocompleteState manages command autocomplete state.

func NewAutocompleteState

func NewAutocompleteState() *AutocompleteState

NewAutocompleteState creates a new AutocompleteState.

func (*AutocompleteState) Down

func (a *AutocompleteState) Down()

Down moves selection down in the autocomplete list.

func (*AutocompleteState) Filtered

func (a *AutocompleteState) Filtered() []Command

Filtered returns the filtered commands.

func (*AutocompleteState) Hide

func (a *AutocompleteState) Hide()

Hide hides the autocomplete dropdown.

func (*AutocompleteState) Index

func (a *AutocompleteState) Index() int

Index returns the current selection index.

func (*AutocompleteState) Select

func (a *AutocompleteState) Select() string

Select returns the currently selected command name. Returns empty string if no valid selection.

func (*AutocompleteState) Up

func (a *AutocompleteState) Up()

Up moves selection up in the autocomplete list.

func (*AutocompleteState) Update

func (a *AutocompleteState) Update(input string)

Update updates the autocomplete state based on the current input.

func (*AutocompleteState) Visible

func (a *AutocompleteState) Visible() bool

Visible returns whether autocomplete is currently showing.

type ChatState

type ChatState int

ChatState represents the current state of the chat UI.

const (
	// StateIdle is the default state, ready for user input.
	StateIdle ChatState = iota
	// StateStreaming indicates an active streaming response.
	StateStreaming
	// StateEscPending indicates waiting for a second ESC press.
	StateEscPending
)

func (ChatState) String

func (s ChatState) String() string

String returns a human-readable name for the state.

type Command

type Command struct {
	Name        string
	Description string
}

Command represents a chat command with autocomplete support.

func AvailableCommands

func AvailableCommands() []Command

AvailableCommands returns all available chat commands.

func FilterCommands

func FilterCommands(prefix string) []Command

FilterCommands returns commands matching the given prefix.

type Config

type Config struct {
	Client          api.Client
	ModelName       string
	ExistingSession *config.Session
}

Config holds configuration for creating a new chat model.

type EscAction

type EscAction int

EscAction represents the action to take on double ESC press.

const (
	// EscActionClear clears the input.
	EscActionClear EscAction = iota
	// EscActionExit exits the application.
	EscActionExit
)

type EscTimeoutMsg

type EscTimeoutMsg struct{}

Message types for tea.Msg

type HistoryNavigator

type HistoryNavigator struct {
	// contains filtered or unexported fields
}

HistoryNavigator manages navigation through input history.

func NewHistoryNavigator

func NewHistoryNavigator() *HistoryNavigator

NewHistoryNavigator creates a new HistoryNavigator.

func (*HistoryNavigator) Add

func (h *HistoryNavigator) Add(entry string)

Add adds an entry to history (skip consecutive duplicates).

func (*HistoryNavigator) Down

func (h *HistoryNavigator) Down() string

Down navigates to a newer history entry. Returns the history entry to display, or the draft if at bottom.

func (*HistoryNavigator) HistoryLen

func (h *HistoryNavigator) HistoryLen() int

HistoryLen returns the length of history.

func (*HistoryNavigator) Index

func (h *HistoryNavigator) Index() int

Index returns the current history index.

func (*HistoryNavigator) IsBrowsing

func (h *HistoryNavigator) IsBrowsing() bool

IsBrowsing returns true if currently browsing history.

func (*HistoryNavigator) Reset

func (h *HistoryNavigator) Reset()

Reset resets the history navigation state.

func (*HistoryNavigator) SetHistory

func (h *HistoryNavigator) SetHistory(history []string)

SetHistory sets the history list.

func (*HistoryNavigator) Up

func (h *HistoryNavigator) Up(currentInput string) string

Up navigates to an older history entry. Returns the history entry to display, or empty string if no change.

type Model

type Model struct {

	// Picker state (managed by parent)
	ShowingPicker      bool
	ShowingModelPicker bool
	// contains filtered or unexported fields
}

Model is the Bubble Tea model for the chat TUI.

func New

func New(cfg Config) Model

New creates a new chat Model.

func (*Model) Err

func (m *Model) Err() error

Err returns the last error.

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the chat model.

func (*Model) IsResumed

func (m *Model) IsResumed() bool

IsResumed returns whether this is a resumed session.

func (*Model) Messages

func (m *Model) Messages() []api.Message

Messages returns the current messages.

func (*Model) ModelName

func (m *Model) ModelName() string

ModelName returns the current model name.

func (*Model) Session

func (m *Model) Session() *config.Session

Session returns the current session.

func (*Model) SetErr

func (m *Model) SetErr(err error)

SetErr sets an error.

func (*Model) SetMessages

func (m *Model) SetMessages(messages []api.Message)

SetMessages sets the messages (used when resuming).

func (*Model) SetModelName

func (m *Model) SetModelName(name string)

SetModelName sets the model name and updates the session.

func (*Model) SetSession

func (m *Model) SetSession(session *config.Session)

SetSession sets a new session.

func (*Model) StartStream

func (m *Model) StartStream() tea.Cmd

StartStream starts a new streaming request. It creates a StreamState and returns a command that reads from the API. The StreamState is stored in m.activeStream before the command runs.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages for the chat model.

func (Model) View

func (m Model) View() string

View renders the chat model.

func (*Model) WaitForChunk

func (m *Model) WaitForChunk() tea.Cmd

WaitForChunk returns a command to wait for the next stream chunk.

type StreamChunkMsg

type StreamChunkMsg string

Message types for tea.Msg

type StreamDoneMsg

type StreamDoneMsg string

Message types for tea.Msg

type StreamErrMsg

type StreamErrMsg struct{ Err error }

Message types for tea.Msg

type StreamState

type StreamState struct {
	// contains filtered or unexported fields
}

StreamState manages the state of an active stream. This replaces the global activeStream variable for better encapsulation.

func NewStreamState

func NewStreamState() *StreamState

NewStreamState creates a new StreamState.

func (*StreamState) Cancel

func (s *StreamState) Cancel()

Cancel cancels the stream by closing the reader.

func (*StreamState) Chunks

func (s *StreamState) Chunks() <-chan string

Chunks returns the channel for receiving stream chunks.

func (*StreamState) Close

func (s *StreamState) Close()

Close marks the stream as done and closes channels.

func (*StreamState) ErrChan

func (s *StreamState) ErrChan() <-chan error

ErrChan returns the channel for receiving stream errors.

func (*StreamState) IsCancelled

func (s *StreamState) IsCancelled() bool

IsCancelled returns whether the stream was explicitly cancelled by the user.

func (*StreamState) IsDone

func (s *StreamState) IsDone() bool

IsDone returns whether the stream is done.

func (*StreamState) SendChunk

func (s *StreamState) SendChunk(chunk string)

SendChunk sends a chunk to the chunks channel.

func (*StreamState) SendError

func (s *StreamState) SendError(err error)

SendError sends an error to the error channel.

func (*StreamState) SetReader

func (s *StreamState) SetReader(reader *api.StreamReader)

SetReader sets the stream reader.

Jump to

Keyboard shortcuts

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