bubbletea

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package bubbletea provides a BubbleTea-based TUI for Echoryn. It implements the Elm MVU architecture for terminal user interaction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MemberRoleIcon

func MemberRoleIcon(role TeamRole, isLeader bool) string

MemberRoleIcon returns an icon for the member role.

func MemberStatusIcon

func MemberStatusIcon(status MemberStatus) string

MemberStatusIcon returns an icon for the member status.

func View

func View(m AppModel) string

View renders the current model state as a string.

Types

type AppModel

type AppModel struct {
	// === Session State ===
	SessionID string
	AgentID   string
	ModelName string
	AuthState AuthState

	// === Conversation State ===
	Messages  []HistoryItem
	MsgList   *MsgListState
	Streaming StreamingState

	// === Input State ===
	InputBuffer  *textbuffer.Buffer
	InputHistory []string
	HistoryIndex int

	// === Completion State ===
	CompletionMgr   *completion.Manager
	Completions     []completion.Completion
	CompletionIndex int
	ShowCompletion  bool
	GhostText       string

	// === Team State ===
	Team *TeamState

	// === UI State ===
	Width         int
	Height        int
	Focus         FocusArea
	ShowTeamPanel bool
	Ready         bool
	Spinner       spinner.SpinnerModel

	// === Layout ===
	Layout *Layout

	// === Theme ===
	Theme  *theme.SemanticColors
	Styles *theme.Styles

	// === Error State ===
	LastError string

	// === Dependencies ===
	Client     client.StreamClient
	TeamClient client.TeamClient
	Config     *Config
}

AppModel is the central state for the BubbleTea application. It follows the Elm architecture's single source of truth principle.

func NewAppModel

func NewAppModel(streamClient client.StreamClient, teamClient client.TeamClient, cfg *Config) AppModel

NewAppModel creates a new AppModel with the given clients.

func (*AppModel) CalculateLayout

func (m *AppModel) CalculateLayout()

CalculateLayout updates layout dimensions.

func (AppModel) CanSendInput

func (m AppModel) CanSendInput() bool

CanSendInput returns true if user input can be processed.

func (AppModel) CursorPosition

func (m AppModel) CursorPosition() (int, int)

CursorPosition returns the current cursor position.

func (AppModel) Init

func (m AppModel) Init() tea.Cmd

func (AppModel) InputText

func (m AppModel) InputText() string

InputText returns the current input text.

func (AppModel) IsStreaming

func (m AppModel) IsStreaming() bool

IsStreaming returns true if currently receiving a stream.

func (AppModel) ShortSessionID

func (m AppModel) ShortSessionID() string

ShortSessionID returns a truncated session ID for display.

func (AppModel) Update

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

func (AppModel) View

func (m AppModel) View() string

type AuthState

type AuthState int

AuthState represents the authentication status.

const (
	AuthUnauthenticated AuthState = iota
	AuthAuthenticated
)

type Config

type Config struct {
	Prompt          string
	MultilinePrompt string
	RequestTimeout  time.Duration
	ShowLineNumbers bool
}

Config holds application configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with sensible defaults.

type ErrorMsg

type ErrorMsg struct {
	Error error
	Time  time.Time
}

ErrorMsg represents a generic error to display.

type FocusArea

type FocusArea int

FocusArea indicates which UI element has focus.

const (
	FocusInput FocusArea = iota
	FocusHistory
	FocusTeamPanel
	FocusCompletion
)

type HistoryItem

type HistoryItem interface {
	Timestamp() time.Time
}

HistoryItem represents a single entry in the conversation history.

func AddAssistantMessage

func AddAssistantMessage(messages []HistoryItem, content string, streaming bool) []HistoryItem

AddAssistantMessage adds an assistant message to the history.

func AddInfoMessage

func AddInfoMessage(messages []HistoryItem, content string, level InfoLevel) []HistoryItem

AddInfoMessage adds an info message to the history.

func AddTeamMessage

func AddTeamMessage(messages []HistoryItem, from, content string) []HistoryItem

AddTeamMessage adds a team message to the history.

func AddToolGroup

func AddToolGroup(messages []HistoryItem, calls []ToolCallInfo, status ToolGroupStatus) []HistoryItem

AddToolGroup adds a tool group to the history.

func AddUserMessage

func AddUserMessage(messages []HistoryItem, content string) []HistoryItem

AddUserMessage adds a user message to the history.

type HistoryItemAssistant

type HistoryItemAssistant struct {
	Content   string
	Time      string // RunID
	Streaming bool
}

HistoryItemAssistant represents an assistant response.

func (*HistoryItemAssistant) Timestamp

func (h *HistoryItemAssistant) Timestamp() time.Time

Timestamp returns the message timestamp.

type HistoryItemInfo

type HistoryItemInfo struct {
	ID      string
	Content string
	Level   InfoLevel
	Time    time.Time
}

HistoryItemInfo represents a system info/warning/error message.

func (*HistoryItemInfo) GetID

func (h *HistoryItemInfo) GetID() string

GetID returns the message ID.

func (*HistoryItemInfo) Timestamp

func (h *HistoryItemInfo) Timestamp() time.Time

Timestamp returns the message timestamp.

type HistoryItemTeamMessage

type HistoryItemTeamMessage struct {
	ID      string
	From    string
	Content string
	Time    time.Time
}

HistoryItemTeamMessage represents a message from a team member.

func (*HistoryItemTeamMessage) GetID

func (h *HistoryItemTeamMessage) GetID() string

GetID returns the message ID.

func (*HistoryItemTeamMessage) Timestamp

func (h *HistoryItemTeamMessage) Timestamp() time.Time

Timestamp returns the message timestamp.

type HistoryItemToolGroup

type HistoryItemToolGroup struct {
	Calls   []ToolCallInfo
	Results []ToolResultInfo
	Status  ToolGroupStatus
	Time    time.Time
}

HistoryItemToolGroup represents a group of tool calls.

func (*HistoryItemToolGroup) Timestamp

func (h *HistoryItemToolGroup) Timestamp() time.Time

Timestamp returns the message timestamp.

type HistoryItemUser

type HistoryItemUser struct {
	Content string
	Time    time.Time
}

HistoryItemUser represents a user message.

func (*HistoryItemUser) Timestamp

func (h *HistoryItemUser) Timestamp() time.Time

Timestamp returns the message timestamp.

type InfoLevel

type InfoLevel int

InfoLevel represents the severity of an info message.

const (
	InfoInfo InfoLevel = iota
	InfoSuccess
	InfoWarning
	InfoError
)

type InfoMsg

type InfoMsg struct {
	Content string
	Time    time.Time
}

InfoMsg represents a message to display to the user.

type InputMsg

type InputMsg struct {
	Content string
}

InputMsg represents user input submission.

func (InputMsg) Timestamp

func (m InputMsg) Timestamp() time.Time

Timestamp returns the message timestamp.

type Layout

type Layout struct {
	HeaderHeight   int
	FooterHeight   int
	InputHeight    int
	ContentHeight  int
	TeamPanelWidth int
	MainWidth      int
}

Layout holds layout calculations.

type MemberState

type MemberState struct {
	SessionID string
	Label     string
	Role      TeamRole
	Status    MemberStatus
	Progress  string
	LastMsg   string
	NodeID    string
}

MemberState represents a team member's current status.

type MemberStatus

type MemberStatus string

MemberStatus is the current status of a team member.

const (
	StatusIdle      MemberStatus = "idle"
	StatusRunning   MemberStatus = "running"
	StatusCompleted MemberStatus = "completed"
	StatusFailed    MemberStatus = "failed"
)

type MemberStatusMsg

type MemberStatusMsg struct {
	SessionID string
	Status    MemberStatus
	Progress  string
}

MemberStatusMsg indicates a member's status changed.

type MsgListState

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

MsgListState manages the virtual list for messages.

func NewMsgListState

func NewMsgListState() *MsgListState

NewMsgListState creates a new message list state.

func (*MsgListState) ItemCount

func (l *MsgListState) ItemCount() int

ItemCount returns the number of items.

func (*MsgListState) ScrollToBottom

func (l *MsgListState) ScrollToBottom()

ScrollToBottom scrolls to the bottom.

func (*MsgListState) SetItemHeight

func (l *MsgListState) SetItemHeight(id string, height int)

SetItemHeight sets the height for an item.

func (*MsgListState) SetViewport

func (l *MsgListState) SetViewport(height, width int)

SetViewport sets the viewport dimensions.

func (*MsgListState) VisibleItems

func (l *MsgListState) VisibleItems() []VisibleMsg

VisibleItems returns visible items with their positions.

type QuitMsg

type QuitMsg struct{}

QuitMsg indicates the user wants to quit.

type StreamChunkMsg

type StreamChunkMsg struct {
	Content string
	Done    bool
}

StreamChunkMsg represents a chunk of streaming content.

type StreamEndMsg

type StreamEndMsg struct {
	RunID  string
	Reason string // "complete", "error", "cancelled"
}

StreamEndMsg indicates the end of a streaming response.

type StreamErrorMsg

type StreamErrorMsg struct {
	Error error
}

StreamErrorMsg represents an error during streaming.

type StreamStartMsg

type StreamStartMsg struct {
	RunID string
}

StreamStartMsg indicates the start of a streaming response.

type StreamingState

type StreamingState int

StreamingState represents the current streaming response status.

const (
	StreamingIdle StreamingState = iota
	StreamingResponding
	StreamingWaitingConfirmation // waiting for user to confirm tool execution
)

type TeamCreatedMsg

type TeamCreatedMsg struct {
	TeamID   string
	Name     string
	Template string
	Members  []MemberState
}

TeamCreatedMsg indicates a team was successfully created.

type TeamDissolvedMsg

type TeamDissolvedMsg struct {
	TeamID string
}

TeamDissolvedMsg indicates the current team was dissolved.

type TeamMessage

type TeamMessage struct {
	From      string
	Content   string
	Timestamp time.Time
}

TeamMessage is a message from a team member.

type TeamMessageMsg

type TeamMessageMsg struct {
	From      string
	Content   string
	Timestamp time.Time
}

TeamMessageMsg represents a message from a team member.

type TeamRole

type TeamRole string

TeamRole is the member's role in the team.

const (
	RoleLead     TeamRole = "lead"
	RoleWorker   TeamRole = "worker"
	RoleReviewer TeamRole = "reviewer"
)

type TeamState

type TeamState struct {
	Enabled    bool
	ID         string
	Name       string
	TemplateID string
	Strategy   string
	Members    []MemberState
	Messages   []TeamMessage
	FocusIndex int
}

TeamState holds the current team collaboration state.

type TickMsg

type TickMsg time.Time

TickMsg is sent periodically for animations.

type ToolCallInfo

type ToolCallInfo struct {
	ID        string
	Name      string
	Arguments string
}

ToolCallInfo represents information about a tool call.

type ToolCallRequestMsg

type ToolCallRequestMsg struct {
	Calls []ToolCallInfo
}

ToolCallRequestMsg indicates tool calls are pending user confirmation.

type ToolConfirmationMsg

type ToolConfirmationMsg struct {
	Approved bool
	CallIDs  []string
}

ToolConfirmationMsg represents user's tool confirmation decision.

type ToolGroupStatus

type ToolGroupStatus int

ToolGroupStatus represents the status of a group of tool calls.

const (
	ToolGroupPending ToolGroupStatus = iota
	ToolGroupConfirmed
	ToolGroupRunning
	ToolGroupCompleted
	ToolGroupRejected
)

type ToolResultInfo

type ToolResultInfo struct {
	CallID string
	Result string
	Error  error
}

ToolResultInfo represents the result of a tool execution.

type ToolResultMsg

type ToolResultMsg struct {
	CallID string
	Result string
	Error  error
}

ToolResultMsg represents the result of a tool execution.

type VisibleMsg

type VisibleMsg struct {
	Index int
	Item  list.ListItem
	Y     int
}

VisibleMsg represents a visible message in the list.

Directories

Path Synopsis
Package client provides client interfaces for the BubbleTea TUI.
Package client provides client interfaces for the BubbleTea TUI.
Package markdown provides Markdown rendering for terminal output.
Package markdown provides Markdown rendering for terminal output.
completion
Package completion provides auto-completion for commands and suggestions.
Package completion provides auto-completion for commands and suggestions.
list
Package list provides virtualized list rendering for large datasets.
Package list provides virtualized list rendering for large datasets.
markdown
Package markdown provides markdown rendering for terminal output.
Package markdown provides markdown rendering for terminal output.
spinner
Package spinner provides a loading spinner component.
Package spinner provides a loading spinner component.
textbuffer
Package textbuffer provides a multi-line text editor with cursor movement, history navigation, and auto-completion support.
Package textbuffer provides a multi-line text editor with cursor movement, history navigation, and auto-completion support.
Package theme provides semantic theming for the TUI.
Package theme provides semantic theming for the TUI.

Jump to

Keyboard shortcuts

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