chat

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteSession

func DeleteSession(name string) error

DeleteSession removes a saved session

func ExpandGlob

func ExpandGlob(pattern string) ([]string, error)

ExpandGlob expands a glob pattern to matching files

func FormatFileSize

func FormatFileSize(bytes int64) string

FormatFileSize returns a human-readable file size

func GetParentOptions

func GetParentOptions(path string) []string

GetParentOptions returns the directory and its parents for approval choices

func ListSessions

func ListSessions() ([]string, error)

ListSessions returns all saved session names

func SaveApprovedDirs

func SaveApprovedDirs(dirs *ApprovedDirs) error

SaveApprovedDirs saves the approved directories to disk

func SaveCurrentSession

func SaveCurrentSession(session *Session) error

SaveCurrentSession saves the current session for auto-restore

func SaveSession

func SaveSession(session *Session, filename string) error

SaveSession saves a session to disk

Types

type ApprovedDirs

type ApprovedDirs struct {
	ApprovedAt  time.Time `json:"approved_at"`
	Directories []string  `json:"directories"`
}

ApprovedDirs stores the list of approved directories

func LoadApprovedDirs

func LoadApprovedDirs() (*ApprovedDirs, error)

LoadApprovedDirs loads the approved directories from disk

func (*ApprovedDirs) AddDirectory

func (d *ApprovedDirs) AddDirectory(dir string) error

AddDirectory adds a directory to the approved list

func (*ApprovedDirs) IsPathApproved

func (d *ApprovedDirs) IsPathApproved(path string) bool

IsPathApproved checks if a path is within an approved directory

func (*ApprovedDirs) RemoveDirectory

func (d *ApprovedDirs) RemoveDirectory(dir string) error

RemoveDirectory removes a directory from the approved list

type ChatMessage

type ChatMessage struct {
	Role       MessageRole `json:"role"`
	Content    string      `json:"content"`
	Files      []string    `json:"files,omitempty"`       // Attached files for user messages
	Tokens     int         `json:"tokens,omitempty"`      // Token count for assistant messages
	DurationMs int64       `json:"duration_ms,omitempty"` // Response time for assistant messages
	WebSearch  bool        `json:"web_search,omitempty"`  // Whether web search was used
	CreatedAt  time.Time   `json:"created_at"`
}

ChatMessage represents a single message in the conversation

func NewAssistantMessage

func NewAssistantMessage(content string, tokens int, durationMs int64, webSearch bool) ChatMessage

NewAssistantMessage creates a new assistant message

func NewUserMessage

func NewUserMessage(content string, files []string) ChatMessage

NewUserMessage creates a new user message

type Command

type Command struct {
	Name        string
	Aliases     []string
	Description string
	Usage       string
	Subcommands []Subcommand // Optional subcommands
}

Command represents a slash command

func AllCommands

func AllCommands() []Command

AllCommands returns all available slash commands

func FilterCommands

func FilterCommands(query string) []Command

FilterCommands returns commands matching the query using fuzzy search If query contains a space (e.g., "mcp "), it returns subcommands for that command

type CommandSource

type CommandSource []Command

CommandSource implements fuzzy.Source for command searching

func (CommandSource) Len

func (c CommandSource) Len() int

func (CommandSource) String

func (c CommandSource) String(i int) string

type CompletionsModel

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

CompletionsModel handles the command completions popup

func NewCompletionsModel

func NewCompletionsModel(styles *ui.Styles) *CompletionsModel

NewCompletionsModel creates a new completions model

func (*CompletionsModel) Hide

func (c *CompletionsModel) Hide()

Hide hides the completions popup

func (*CompletionsModel) IsVisible

func (c *CompletionsModel) IsVisible() bool

IsVisible returns whether the popup is visible

func (*CompletionsModel) Selected

func (c *CompletionsModel) Selected() *Command

Selected returns the currently selected command

func (*CompletionsModel) SetItems

func (c *CompletionsModel) SetItems(items []Command)

SetItems sets custom completion items (for dynamic completions like server names)

func (*CompletionsModel) SetQuery

func (c *CompletionsModel) SetQuery(query string)

SetQuery updates the filter query

func (*CompletionsModel) SetSize

func (c *CompletionsModel) SetSize(width, height int)

SetSize updates the dimensions

func (*CompletionsModel) Show

func (c *CompletionsModel) Show()

Show displays the completions popup

func (*CompletionsModel) Update

func (c *CompletionsModel) Update(msg tea.Msg) (*CompletionsModel, tea.Cmd)

Update handles messages

func (*CompletionsModel) View

func (c *CompletionsModel) View() string

View renders the completions popup

type DialogItem

type DialogItem struct {
	ID          string
	Label       string
	Description string
	Selected    bool
	Category    string
}

DialogItem represents an item in a dialog list

type DialogModel

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

DialogModel handles modal dialogs

func NewDialogModel

func NewDialogModel(styles *ui.Styles) *DialogModel

NewDialogModel creates a new dialog model

func (*DialogModel) Close

func (d *DialogModel) Close()

Close closes the dialog

func (*DialogModel) Cursor

func (d *DialogModel) Cursor() int

Cursor returns the current cursor position

func (*DialogModel) GetDirApprovalPath

func (d *DialogModel) GetDirApprovalPath() string

GetDirApprovalPath returns the path that triggered the approval request

func (*DialogModel) IsOpen

func (d *DialogModel) IsOpen() bool

IsOpen returns whether a dialog is open

func (*DialogModel) ItemAt

func (d *DialogModel) ItemAt(idx int) *DialogItem

ItemAt returns the item at the given index (0-based)

func (*DialogModel) Query

func (d *DialogModel) Query() string

Query returns the current filter query

func (*DialogModel) Selected

func (d *DialogModel) Selected() *DialogItem

Selected returns the currently highlighted item

func (*DialogModel) SetCursor

func (d *DialogModel) SetCursor(pos int)

SetCursor sets the cursor position, clamping to valid range

func (*DialogModel) SetQuery

func (d *DialogModel) SetQuery(query string)

SetQuery updates the filter query for model picker or MCP picker

func (*DialogModel) SetSize

func (d *DialogModel) SetSize(width, height int)

SetSize updates the dimensions

func (*DialogModel) ShowDirApproval

func (d *DialogModel) ShowDirApproval(filePath string, options []string)

ShowDirApproval opens the directory approval dialog

func (*DialogModel) ShowMCPPicker

func (d *DialogModel) ShowMCPPicker(mcpManager *mcp.Manager)

ShowMCPPicker opens the MCP server picker dialog

func (*DialogModel) ShowModelPicker

func (d *DialogModel) ShowModelPicker(currentModel string, providers []ProviderInfo)

ShowModelPicker opens the model picker dialog

func (*DialogModel) ShowSessionList

func (d *DialogModel) ShowSessionList(sessions []string, currentSession string)

ShowSessionList opens the session list dialog

func (*DialogModel) Type

func (d *DialogModel) Type() DialogType

Type returns the current dialog type

func (*DialogModel) Update

func (d *DialogModel) Update(msg tea.Msg) (*DialogModel, tea.Cmd)

Update handles messages

func (*DialogModel) View

func (d *DialogModel) View() string

View renders the dialog

type DialogType

type DialogType int

DialogType represents the type of dialog

const (
	DialogNone DialogType = iota
	DialogModelPicker
	DialogSessionList
	DialogDirApproval
	DialogMCPPicker
)

type DirApprovalRequest

type DirApprovalRequest struct {
	Path      string   // The file path that triggered the request
	Options   []string // Directory options to approve
	OnApprove func(dir string)
	OnDeny    func()
}

DirApprovalRequest represents a pending directory approval request

type FileAttachment

type FileAttachment struct {
	Path    string
	Name    string
	Content string
	Size    int64
}

FileAttachment represents an attached file

func AttachFile

func AttachFile(path string) (*FileAttachment, error)

AttachFile reads a file and creates an attachment

type FileCompletion

type FileCompletion struct {
	Path    string
	Name    string
	IsDir   bool
	RelPath string
}

FileCompletion represents a file path completion item

func ListFiles

func ListFiles(dir string, query string) []FileCompletion

ListFiles returns files in a directory for completion

type FileCompletionSource

type FileCompletionSource []FileCompletion

FileCompletionSource implements fuzzy.Source for file completions

func (FileCompletionSource) Len

func (f FileCompletionSource) Len() int

func (FileCompletionSource) String

func (f FileCompletionSource) String(i int) string

type KeyMap

type KeyMap struct {
	// Global
	Quit     key.Binding
	Help     key.Binding
	Commands key.Binding

	// Editor
	Send        key.Binding
	Newline     key.Binding
	NewlineAlt  key.Binding
	ClearLine   key.Binding
	DeleteWord  key.Binding
	Cancel      key.Binding
	HistoryUp   key.Binding
	HistoryDown key.Binding
	Tab         key.Binding

	// History navigation
	ScrollUp   key.Binding
	ScrollDown key.Binding
	PageUp     key.Binding
	PageDown   key.Binding
	GoToTop    key.Binding
	GoToBottom key.Binding
	Copy       key.Binding

	// Shortcuts
	SwitchModel key.Binding
	ToggleWeb   key.Binding
	AttachFile  key.Binding
	Clear       key.Binding
	NewSession  key.Binding
	MCPPicker   key.Binding
}

KeyMap defines keybindings for the chat TUI

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns the default keybindings

type MessageRole

type MessageRole string

MessageRole represents who sent the message

const (
	RoleUser      MessageRole = "user"
	RoleAssistant MessageRole = "assistant"
)

type Model

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

Model is the main chat TUI model

func New

func New(cfg *config.Config, provider llm.Provider, engine *llm.Engine, modelName string, mcpManager *mcp.Manager, maxTurns int, forceExternalSearch bool, searchEnabled bool, localTools []string, showStats bool) *Model

New creates a new chat model

func (*Model) ExecuteCommand

func (m *Model) ExecuteCommand(input string) (tea.Model, tea.Cmd)

ExecuteCommand handles slash command execution

func (*Model) Init

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

Init initializes the model

func (*Model) Update

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

Update handles messages

func (*Model) View

func (m *Model) View() string

View renders the model (inline mode - only active frame)

type ProviderInfo

type ProviderInfo struct {
	Name   string
	Models []string
}

ProviderInfo holds provider and model information

func GetAvailableProviders

func GetAvailableProviders(cfg *config.Config) []ProviderInfo

GetAvailableProviders returns providers with their models in consistent order If cfg is provided, custom configured providers are also included

type Session

type Session struct {
	Name      string        `json:"name"`
	CreatedAt time.Time     `json:"created_at"`
	UpdatedAt time.Time     `json:"updated_at"`
	Provider  string        `json:"provider"`
	Model     string        `json:"model"`
	Messages  []ChatMessage `json:"messages"`
}

Session represents a saved chat session

func LoadCurrentSession

func LoadCurrentSession() (*Session, error)

LoadCurrentSession loads the current session if it exists

func LoadSession

func LoadSession(filename string) (*Session, error)

LoadSession loads a session from disk

func NewSession

func NewSession(provider, model string) *Session

NewSession creates a new empty session

type Subcommand

type Subcommand struct {
	Name        string
	Description string
}

Subcommand represents a subcommand of a slash command

Jump to

Keyboard shortcuts

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