ui

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SlashCommands = []SlashCommand{
	{
		Name:        "/help",
		Description: "Show available commands and usage information",
		Category:    "Info",
		Aliases:     []string{"/h", "/?"},
	},
	{
		Name:        "/tools",
		Description: "List all available MCP tools",
		Category:    "Info",
		Aliases:     []string{"/t"},
	},
	{
		Name:        "/servers",
		Description: "Show connected MCP servers",
		Category:    "Info",
		Aliases:     []string{"/s"},
	},

	{
		Name:        "/clear",
		Description: "Clear conversation and start fresh",
		Category:    "System",
		Aliases:     []string{"/c", "/cls"},
	},
	{
		Name:        "/usage",
		Description: "Show token usage statistics",
		Category:    "Info",
		Aliases:     []string{"/u"},
	},
	{
		Name:        "/reset-usage",
		Description: "Reset usage statistics",
		Category:    "System",
		Aliases:     []string{"/ru"},
	},
	{
		Name:        "/quit",
		Description: "Exit the application",
		Category:    "System",
		Aliases:     []string{"/q", "/exit"},
	},
}

SlashCommands is the registry of all available slash commands

Functions

func BaseStyle

func BaseStyle() lipgloss.Style

BaseStyle returns a basic lipgloss style

func CreateBadge added in v0.17.0

func CreateBadge(text string, color lipgloss.AdaptiveColor) string

CreateBadge creates a styled badge

func CreateGradientText added in v0.17.0

func CreateGradientText(text string, startColor, endColor lipgloss.AdaptiveColor) string

CreateGradientText creates text with gradient-like effect using different shades

func CreateProgressBar added in v0.17.0

func CreateProgressBar(width int, percentage float64, theme Theme) string

CreateProgressBar creates a simple progress bar

func CreateSeparator added in v0.17.0

func CreateSeparator(width int, char string, color lipgloss.AdaptiveColor) string

CreateSeparator creates a styled separator line

func EstimateTokens added in v0.14.0

func EstimateTokens(text string) int

EstimateTokens provides a rough estimate of tokens in text This is a simple approximation - real token counting would require the actual tokenizer

func FormatCompactLine added in v0.19.0

func FormatCompactLine(symbol, label, content string, symbolColor, labelColor, contentColor lipgloss.AdaptiveColor) string

FormatCompactLine formats a complete compact line with consistent spacing

func GetAllCommandNames added in v0.21.0

func GetAllCommandNames() []string

GetAllCommandNames returns all command names and aliases

func GetMarkdownRenderer

func GetMarkdownRenderer(width int) *glamour.TermRenderer

GetMarkdownRenderer returns a glamour TermRenderer configured for our use

func SetTheme added in v0.17.0

func SetTheme(theme Theme)

SetTheme sets the current theme

func StyleCard added in v0.17.0

func StyleCard(width int, theme Theme) lipgloss.Style

StyleCard creates a styled card container

func StyleCompactContent added in v0.19.0

func StyleCompactContent(color lipgloss.AdaptiveColor) lipgloss.Style

StyleCompactContent creates basic content styling for compact mode

func StyleCompactLabel added in v0.19.0

func StyleCompactLabel(color lipgloss.AdaptiveColor) lipgloss.Style

StyleCompactLabel creates a styled label for compact mode

func StyleCompactSymbol added in v0.19.0

func StyleCompactSymbol(symbol string, color lipgloss.AdaptiveColor) lipgloss.Style

StyleCompactSymbol creates a styled symbol for compact mode

func StyleError added in v0.17.0

func StyleError(theme Theme) lipgloss.Style

StyleError creates error text styling

func StyleHeader added in v0.17.0

func StyleHeader(theme Theme) lipgloss.Style

StyleHeader creates a styled header

func StyleInfo added in v0.17.0

func StyleInfo(theme Theme) lipgloss.Style

StyleInfo creates info text styling

func StyleMuted added in v0.17.0

func StyleMuted(theme Theme) lipgloss.Style

StyleMuted creates muted text styling

func StyleSubheader added in v0.17.0

func StyleSubheader(theme Theme) lipgloss.Style

StyleSubheader creates a styled subheader

func StyleSuccess added in v0.17.0

func StyleSuccess(theme Theme) lipgloss.Style

StyleSuccess creates success text styling

func StyleWarning added in v0.17.0

func StyleWarning(theme Theme) lipgloss.Style

StyleWarning creates warning text styling

func WithAlign added in v0.17.0

func WithAlign(align lipgloss.Position) renderingOption

WithAlign sets the horizontal alignment of the block

func WithBorderColor added in v0.17.0

func WithBorderColor(color lipgloss.AdaptiveColor) renderingOption

WithBorderColor sets the border color

func WithFullWidth added in v0.17.0

func WithFullWidth() renderingOption

WithFullWidth makes the block take full available width

func WithMarginBottom added in v0.17.0

func WithMarginBottom(margin int) renderingOption

WithMarginBottom sets the bottom margin

func WithMarginTop added in v0.17.0

func WithMarginTop(margin int) renderingOption

WithMarginTop sets the top margin

func WithPaddingBottom added in v0.17.0

func WithPaddingBottom(padding int) renderingOption

WithPaddingBottom sets the bottom padding

func WithPaddingLeft added in v0.17.0

func WithPaddingLeft(padding int) renderingOption

WithPaddingLeft sets the left padding

func WithPaddingRight added in v0.17.0

func WithPaddingRight(padding int) renderingOption

WithPaddingRight sets the right padding

func WithPaddingTop added in v0.17.0

func WithPaddingTop(padding int) renderingOption

WithPaddingTop sets the top padding

func WithWidth added in v0.17.0

func WithWidth(width int) renderingOption

WithWidth sets a specific width for the block

Types

type AgentInterface added in v0.19.0

type AgentInterface interface {
	GetLoadingMessage() string
	GetTools() []any                // Using any to avoid importing tool types
	GetLoadedServerNames() []string // Add this method for debug config
}

AgentInterface defines the interface we need from agent to avoid import cycles

type CLI

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

CLI handles the command line interface with improved message rendering

func NewCLI

func NewCLI(debug bool, compact bool) (*CLI, error)

NewCLI creates a new CLI instance with message container

func SetupCLI added in v0.19.0

func SetupCLI(opts *CLISetupOptions) (*CLI, error)

SetupCLI creates and configures CLI with standard info display

func (*CLI) ClearMessages

func (c *CLI) ClearMessages()

ClearMessages clears all messages from the container

func (*CLI) CreateCallbackHandler

func (c *CLI) CreateCallbackHandler() callbacks.Handler

CreateCallbackHandler creates a callback handler using HandlerHelper

func (*CLI) DisplayAssistantMessage

func (c *CLI) DisplayAssistantMessage(message string) error

DisplayAssistantMessage displays the assistant's message using the new renderer

func (*CLI) DisplayAssistantMessageWithModel

func (c *CLI) DisplayAssistantMessageWithModel(message, modelName string) error

DisplayAssistantMessageWithModel displays the assistant's message with model info

func (*CLI) DisplayCancellation added in v0.14.0

func (c *CLI) DisplayCancellation()

DisplayCancellation displays a cancellation message

func (*CLI) DisplayDebugConfig added in v0.12.0

func (c *CLI) DisplayDebugConfig(config map[string]any)

DisplayDebugConfig displays configuration settings using the appropriate renderer

func (*CLI) DisplayDebugMessage added in v0.28.0

func (c *CLI) DisplayDebugMessage(message string)

DisplayDebugMessage displays debug messages using the appropriate renderer

func (*CLI) DisplayError

func (c *CLI) DisplayError(err error)

DisplayError displays an error message using the appropriate renderer

func (*CLI) DisplayHelp

func (c *CLI) DisplayHelp()

DisplayHelp displays help information in a message block

func (*CLI) DisplayInfo

func (c *CLI) DisplayInfo(message string)

DisplayInfo displays an informational message using the appropriate renderer

func (*CLI) DisplayServers

func (c *CLI) DisplayServers(servers []string)

DisplayServers displays configured MCP servers in a message block

func (*CLI) DisplayToolCallMessage

func (c *CLI) DisplayToolCallMessage(toolName, toolArgs string)

DisplayToolCallMessage displays a tool call in progress

func (*CLI) DisplayToolMessage

func (c *CLI) DisplayToolMessage(toolName, toolArgs, toolResult string, isError bool)

DisplayToolMessage displays a tool call message

func (*CLI) DisplayTools

func (c *CLI) DisplayTools(tools []string)

DisplayTools displays available tools in a message block

func (*CLI) DisplayUsageAfterResponse added in v0.19.0

func (c *CLI) DisplayUsageAfterResponse()

DisplayUsageAfterResponse displays usage information immediately after a response

func (*CLI) DisplayUsageStats added in v0.14.0

func (c *CLI) DisplayUsageStats()

DisplayUsageStats displays current usage statistics

func (*CLI) DisplayUserMessage

func (c *CLI) DisplayUserMessage(message string)

DisplayUserMessage displays the user's message using the appropriate renderer

func (*CLI) GetDebugLogger added in v0.28.0

func (c *CLI) GetDebugLogger() *CLIDebugLogger

GetDebugLogger returns a debug logger that uses the CLI for rendering

func (*CLI) GetPrompt

func (c *CLI) GetPrompt() (string, error)

GetPrompt gets user input using the huh library with divider and padding

func (*CLI) HandleSlashCommand

func (c *CLI) HandleSlashCommand(input string, servers []string, tools []string) SlashCommandResult

HandleSlashCommand handles slash commands and returns the result

func (*CLI) IsSlashCommand

func (c *CLI) IsSlashCommand(input string) bool

IsSlashCommand checks if the input is a slash command

func (*CLI) ResetUsageStats added in v0.14.0

func (c *CLI) ResetUsageStats()

ResetUsageStats resets the usage tracking statistics

func (*CLI) SetModelName added in v0.19.0

func (c *CLI) SetModelName(modelName string)

SetModelName sets the current model name for the CLI

func (*CLI) SetUsageTracker added in v0.14.0

func (c *CLI) SetUsageTracker(tracker *UsageTracker)

SetUsageTracker sets the usage tracker for the CLI

func (*CLI) ShowSpinner

func (c *CLI) ShowSpinner(message string, action func() error) error

ShowSpinner displays a spinner with the given message and executes the action

func (*CLI) StartStreamingMessage added in v0.18.0

func (c *CLI) StartStreamingMessage(modelName string)

StartStreamingMessage starts a streaming assistant message

func (*CLI) UpdateStreamingMessage added in v0.18.0

func (c *CLI) UpdateStreamingMessage(content string)

UpdateStreamingMessage updates the streaming message with new content

func (*CLI) UpdateUsage added in v0.14.0

func (c *CLI) UpdateUsage(inputText, outputText string)

UpdateUsage updates the usage tracker with token counts and costs

func (*CLI) UpdateUsageFromResponse added in v0.14.0

func (c *CLI) UpdateUsageFromResponse(response *schema.Message, inputText string)

UpdateUsageFromResponse updates the usage tracker using token usage from response metadata

type CLIDebugLogger added in v0.28.0

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

CLIDebugLogger implements the tools.DebugLogger interface using CLI rendering

func NewCLIDebugLogger added in v0.28.0

func NewCLIDebugLogger(cli *CLI) *CLIDebugLogger

NewCLIDebugLogger creates a new CLI debug logger

func (*CLIDebugLogger) IsDebugEnabled added in v0.28.0

func (l *CLIDebugLogger) IsDebugEnabled() bool

IsDebugEnabled returns whether debug logging is enabled

func (*CLIDebugLogger) LogDebug added in v0.28.0

func (l *CLIDebugLogger) LogDebug(message string)

LogDebug logs a debug message using the CLI's debug message renderer

type CLISetupOptions added in v0.19.0

type CLISetupOptions struct {
	Agent          AgentInterface
	ModelString    string
	Debug          bool
	Compact        bool
	Quiet          bool
	ShowDebug      bool   // Whether to show debug config
	ProviderAPIKey string // For OAuth detection
}

CLISetupOptions contains options for setting up CLI

type CompactRenderer added in v0.19.0

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

CompactRenderer handles rendering messages in compact format

func NewCompactRenderer added in v0.19.0

func NewCompactRenderer(width int, debug bool) *CompactRenderer

NewCompactRenderer creates a new compact message renderer

func (*CompactRenderer) RenderAssistantMessage added in v0.19.0

func (r *CompactRenderer) RenderAssistantMessage(content string, timestamp time.Time, modelName string) UIMessage

RenderAssistantMessage renders an assistant message in compact format

func (*CompactRenderer) RenderDebugConfigMessage added in v0.19.0

func (r *CompactRenderer) RenderDebugConfigMessage(config map[string]any, timestamp time.Time) UIMessage

RenderDebugConfigMessage renders debug config in compact format

func (*CompactRenderer) RenderDebugMessage added in v0.28.0

func (r *CompactRenderer) RenderDebugMessage(message string, timestamp time.Time) UIMessage

RenderDebugMessage renders debug messages in compact format

func (*CompactRenderer) RenderErrorMessage added in v0.19.0

func (r *CompactRenderer) RenderErrorMessage(errorMsg string, timestamp time.Time) UIMessage

RenderErrorMessage renders an error message in compact format

func (*CompactRenderer) RenderSystemMessage added in v0.19.0

func (r *CompactRenderer) RenderSystemMessage(content string, timestamp time.Time) UIMessage

RenderSystemMessage renders a system message in compact format

func (*CompactRenderer) RenderToolCallMessage added in v0.19.0

func (r *CompactRenderer) RenderToolCallMessage(toolName, toolArgs string, timestamp time.Time) UIMessage

RenderToolCallMessage renders a tool call in progress in compact format

func (*CompactRenderer) RenderToolMessage added in v0.19.0

func (r *CompactRenderer) RenderToolMessage(toolName, toolArgs, toolResult string, isError bool) UIMessage

RenderToolMessage renders a tool result in compact format

func (*CompactRenderer) RenderUserMessage added in v0.19.0

func (r *CompactRenderer) RenderUserMessage(content string, timestamp time.Time) UIMessage

RenderUserMessage renders a user message in compact format

func (*CompactRenderer) SetWidth added in v0.19.0

func (r *CompactRenderer) SetWidth(width int)

SetWidth updates the renderer width

type FuzzyMatch added in v0.21.0

type FuzzyMatch struct {
	Command *SlashCommand
	Score   int
}

FuzzyMatch represents a match result with score

func FuzzyMatchCommands added in v0.21.0

func FuzzyMatchCommands(query string, commands []SlashCommand) []FuzzyMatch

FuzzyMatchCommands performs fuzzy matching on slash commands

type MessageContainer

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

MessageContainer wraps multiple messages in a container

func NewMessageContainer

func NewMessageContainer(width, height int, compact bool) *MessageContainer

NewMessageContainer creates a new message container

func (*MessageContainer) AddMessage

func (c *MessageContainer) AddMessage(msg UIMessage)

AddMessage adds a message to the container

func (*MessageContainer) Clear

func (c *MessageContainer) Clear()

Clear clears all messages from the container

func (*MessageContainer) Render

func (c *MessageContainer) Render() string

Render renders all messages in the container

func (*MessageContainer) SetModelName added in v0.19.0

func (c *MessageContainer) SetModelName(modelName string)

SetModelName sets the current model name for the container

func (*MessageContainer) SetSize

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

SetSize updates the container size

func (*MessageContainer) UpdateLastMessage added in v0.18.0

func (c *MessageContainer) UpdateLastMessage(content string)

UpdateLastMessage updates the content of the last message efficiently

type MessageRenderer

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

MessageRenderer handles rendering of messages with proper styling

func NewMessageRenderer

func NewMessageRenderer(width int, debug bool) *MessageRenderer

NewMessageRenderer creates a new message renderer

func (*MessageRenderer) RenderAssistantMessage

func (r *MessageRenderer) RenderAssistantMessage(content string, timestamp time.Time, modelName string) UIMessage

RenderAssistantMessage renders an assistant message with left border and background header

func (*MessageRenderer) RenderDebugConfigMessage added in v0.12.0

func (r *MessageRenderer) RenderDebugConfigMessage(config map[string]any, timestamp time.Time) UIMessage

RenderDebugConfigMessage renders debug configuration settings with tool response block styling

func (*MessageRenderer) RenderDebugMessage added in v0.28.0

func (r *MessageRenderer) RenderDebugMessage(message string, timestamp time.Time) UIMessage

RenderDebugMessage renders debug messages with tool response block styling

func (*MessageRenderer) RenderErrorMessage

func (r *MessageRenderer) RenderErrorMessage(errorMsg string, timestamp time.Time) UIMessage

RenderErrorMessage renders an error message with left border and background header

func (*MessageRenderer) RenderSystemMessage

func (r *MessageRenderer) RenderSystemMessage(content string, timestamp time.Time) UIMessage

RenderSystemMessage renders a system message with left border and background header

func (*MessageRenderer) RenderToolCallMessage

func (r *MessageRenderer) RenderToolCallMessage(toolName, toolArgs string, timestamp time.Time) UIMessage

RenderToolCallMessage renders a tool call in progress with left border and background header

func (*MessageRenderer) RenderToolMessage

func (r *MessageRenderer) RenderToolMessage(toolName, toolArgs, toolResult string, isError bool) UIMessage

RenderToolMessage renders a tool call message with proper styling

func (*MessageRenderer) RenderUserMessage

func (r *MessageRenderer) RenderUserMessage(content string, timestamp time.Time) UIMessage

RenderUserMessage renders a user message with right border and background header

func (*MessageRenderer) SetWidth

func (r *MessageRenderer) SetWidth(width int)

SetWidth updates the renderer width

type MessageType

type MessageType int

MessageType represents the type of message

const (
	UserMessage MessageType = iota
	AssistantMessage
	ToolMessage
	ToolCallMessage // New type for showing tool calls in progress
	SystemMessage   // New type for MCPHost system messages (help, tools, etc.)
	ErrorMessage    // New type for error messages
)

type SessionStats added in v0.14.0

type SessionStats struct {
	TotalInputTokens      int
	TotalOutputTokens     int
	TotalCacheReadTokens  int
	TotalCacheWriteTokens int
	TotalCost             float64
	RequestCount          int
}

SessionStats represents cumulative stats for the entire session

type SlashCommand added in v0.21.0

type SlashCommand struct {
	Name        string
	Description string
	Aliases     []string
	Category    string // e.g., "Navigation", "System", "Info"
}

SlashCommand represents a slash command with its metadata

func GetCommandByName added in v0.21.0

func GetCommandByName(name string) *SlashCommand

GetCommandByName returns a command by its name or alias

type SlashCommandInput added in v0.21.0

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

SlashCommandInput is a custom input field with slash command autocomplete

func NewSlashCommandInput added in v0.21.0

func NewSlashCommandInput(width int, title string) *SlashCommandInput

NewSlashCommandInput creates a new slash command input field

func (*SlashCommandInput) Cancelled added in v0.21.0

func (s *SlashCommandInput) Cancelled() bool

Cancelled returns true if the user cancelled

func (*SlashCommandInput) Init added in v0.21.0

func (s *SlashCommandInput) Init() tea.Cmd

Init implements tea.Model

func (*SlashCommandInput) RenderedLines added in v0.21.0

func (s *SlashCommandInput) RenderedLines() int

RenderedLines returns how many lines were rendered

func (*SlashCommandInput) Update added in v0.21.0

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

Update implements tea.Model

func (*SlashCommandInput) Value added in v0.21.0

func (s *SlashCommandInput) Value() string

Value returns the final value

func (*SlashCommandInput) View added in v0.21.0

func (s *SlashCommandInput) View() string

View implements tea.Model

type SlashCommandResult added in v0.17.0

type SlashCommandResult struct {
	Handled      bool
	ClearHistory bool
}

SlashCommandResult represents the result of handling a slash command

type Spinner

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

Spinner wraps the bubbles spinner for both interactive and non-interactive mode

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with enhanced styling

func NewThemedSpinner

func NewThemedSpinner(message string, color lipgloss.AdaptiveColor) *Spinner

NewThemedSpinner creates a new spinner with the given message and color

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop ends the spinner animation

type Theme added in v0.17.0

Theme represents a complete UI theme

func DefaultTheme added in v0.17.0

func DefaultTheme() Theme

DefaultTheme returns the default MCPHost theme (Catppuccin Mocha)

func GetTheme added in v0.17.0

func GetTheme() Theme

GetTheme returns the current theme

type UIMessage

type UIMessage struct {
	ID        string
	Type      MessageType
	Position  int
	Height    int
	Content   string
	Timestamp time.Time
	Streaming bool
}

UIMessage represents a rendered message for display

type UsageStats added in v0.14.0

type UsageStats struct {
	InputTokens      int
	OutputTokens     int
	CacheReadTokens  int
	CacheWriteTokens int
	InputCost        float64
	OutputCost       float64
	CacheReadCost    float64
	CacheWriteCost   float64
	TotalCost        float64
}

UsageStats represents token and cost information for a single request/response

type UsageTracker added in v0.14.0

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

UsageTracker tracks token usage and costs for LLM interactions

func NewUsageTracker added in v0.14.0

func NewUsageTracker(modelInfo *models.ModelInfo, provider string, width int, isOAuth bool) *UsageTracker

NewUsageTracker creates a new usage tracker for the given model

func (*UsageTracker) EstimateAndUpdateUsage added in v0.14.0

func (ut *UsageTracker) EstimateAndUpdateUsage(inputText, outputText string)

EstimateAndUpdateUsage estimates tokens from text and updates usage

func (*UsageTracker) EstimateAndUpdateUsageFromText added in v0.14.0

func (ut *UsageTracker) EstimateAndUpdateUsageFromText(inputText, outputText string)

EstimateAndUpdateUsageFromText estimates tokens from text and updates usage

func (*UsageTracker) GetLastRequestStats added in v0.14.0

func (ut *UsageTracker) GetLastRequestStats() *UsageStats

GetLastRequestStats returns a copy of the last request statistics

func (*UsageTracker) GetSessionStats added in v0.14.0

func (ut *UsageTracker) GetSessionStats() SessionStats

GetSessionStats returns a copy of the current session statistics

func (*UsageTracker) RenderUsageInfo added in v0.14.0

func (ut *UsageTracker) RenderUsageInfo() string

RenderUsageInfo renders enhanced usage information with better styling

func (*UsageTracker) Reset added in v0.14.0

func (ut *UsageTracker) Reset()

Reset clears all usage statistics

func (*UsageTracker) SetWidth added in v0.14.0

func (ut *UsageTracker) SetWidth(width int)

SetWidth updates the display width for rendering

func (*UsageTracker) UpdateUsage added in v0.14.0

func (ut *UsageTracker) UpdateUsage(inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens int)

UpdateUsage updates the tracker with new usage information

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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