Documentation
¶
Overview ¶
Package chat provides an interactive Bubbletea TUI for conversing with GitHub Copilot. It renders assistant responses as markdown with syntax highlighting using glamour.
Index ¶
- Variables
- func CreateTUIPermissionHandler(eventChan chan<- tea.Msg) copilot.PermissionHandler
- func DeleteSession(client *copilot.Client, id string) error
- func FormatRelativeTime(t time.Time) string
- func GenerateSessionName(messages []chatMessage) string
- func Run(ctx context.Context, session *copilot.Session, client *copilot.Client, ...) error
- func RunWithEventChannel(ctx context.Context, session *copilot.Session, client *copilot.Client, ...) error
- func RunWithEventChannelAndModeRef(ctx context.Context, session *copilot.Session, client *copilot.Client, ...) error
- func SaveSession(session *SessionMetadata) error
- func SyncSessionMetadata(client *copilot.Client) error
- type AgentModeRef
- type KeyMap
- type MessageMetadata
- type Model
- type PermissionRequestMsg
- type SessionMetadata
- type ToolOutputChunkMsg
Constants ¶
This section is empty.
Variables ¶
var ErrNoSessions = errors.New("no sessions available")
ErrNoSessions is returned when there are no sessions available.
Functions ¶
func CreateTUIPermissionHandler ¶ added in v5.26.0
func CreateTUIPermissionHandler(eventChan chan<- tea.Msg) copilot.PermissionHandler
CreateTUIPermissionHandler creates a permission handler that integrates with the TUI. It sends permission requests to the provided event channel and waits for a response. This allows the TUI to display permission prompts and collect user input.
func DeleteSession ¶ added in v5.25.0
DeleteSession removes a chat session from both SDK and local disk.
func FormatRelativeTime ¶ added in v5.25.0
FormatRelativeTime formats a time as a relative string (e.g., "2 hours ago").
func GenerateSessionName ¶ added in v5.25.0
func GenerateSessionName(messages []chatMessage) string
GenerateSessionName creates a session name from the first user message.
func Run ¶
func Run( ctx context.Context, session *copilot.Session, client *copilot.Client, sessionConfig *copilot.SessionConfig, models []copilot.ModelInfo, currentModel string, timeout time.Duration, ) error
Run starts the chat TUI and returns a permission handler for integration with the Copilot SDK. The returned handler can be used with SessionConfig.OnPermissionRequest to enable interactive permission prompting within the TUI.
func RunWithEventChannel ¶
func RunWithEventChannel( ctx context.Context, session *copilot.Session, client *copilot.Client, sessionConfig *copilot.SessionConfig, models []copilot.ModelInfo, currentModel string, timeout time.Duration, eventChan chan tea.Msg, ) error
RunWithEventChannel starts the chat TUI with a pre-created event channel. This allows external code (like permission handlers) to send events to the TUI.
func RunWithEventChannelAndModeRef ¶ added in v5.25.1
func RunWithEventChannelAndModeRef( ctx context.Context, session *copilot.Session, client *copilot.Client, sessionConfig *copilot.SessionConfig, models []copilot.ModelInfo, currentModel string, timeout time.Duration, eventChan chan tea.Msg, agentModeRef *AgentModeRef, ) error
RunWithEventChannelAndModeRef starts the chat TUI with a pre-created event channel and agent mode reference. This allows external code (like permission handlers) to send events to the TUI and synchronize agent mode state.
func SaveSession ¶ added in v5.25.0
func SaveSession(session *SessionMetadata) error
SaveSession saves session metadata to disk. The ID must be provided (typically from the Copilot SDK session.SessionID).
func SyncSessionMetadata ¶ added in v5.26.0
SyncSessionMetadata synchronizes local session files with SDK sessions. It removes local session files that no longer exist in the SDK (excluding remote sessions). Returns an error if sync fails (caller should display as non-blocking toast).
Types ¶
type AgentModeRef ¶ added in v5.25.1
type AgentModeRef struct {
// contains filtered or unexported fields
}
AgentModeRef is a thread-safe reference to the agent mode state. It allows tool handlers to check the current mode at execution time. The enabled field is unexported to ensure all access goes through mutex-protected methods.
func NewAgentModeRef ¶ added in v5.25.1
func NewAgentModeRef(initial bool) *AgentModeRef
NewAgentModeRef creates a new AgentModeRef with the given initial state.
func (*AgentModeRef) IsEnabled ¶ added in v5.25.1
func (r *AgentModeRef) IsEnabled() bool
IsEnabled returns true if agent mode is enabled (tools can execute).
func (*AgentModeRef) SetEnabled ¶ added in v5.25.1
func (r *AgentModeRef) SetEnabled(enabled bool)
SetEnabled updates the agent mode state.
type KeyMap ¶ added in v5.26.0
type KeyMap struct {
// Navigation
Up key.Binding
Down key.Binding
PageUp key.Binding
PageDown key.Binding
// Actions
Send key.Binding
NewLine key.Binding
Cancel key.Binding
Quit key.Binding
ToggleMode key.Binding
ToggleHelp key.Binding
// Tools
ExpandTools key.Binding
// Output
CopyOutput key.Binding
// Modals
OpenSessions key.Binding
OpenModel key.Binding
NewChat key.Binding
// Permission modal
Allow key.Binding
Deny key.Binding
// Picker navigation
Select key.Binding
Rename key.Binding
Delete key.Binding
// Filter/search
Filter key.Binding
}
KeyMap defines all keybindings for the chat TUI. It implements the help.KeyMap interface for contextual help rendering.
func DefaultKeyMap ¶ added in v5.26.0
func DefaultKeyMap() KeyMap
DefaultKeyMap returns the default keybindings.
func (KeyMap) FullHelp ¶ added in v5.26.0
FullHelp returns keybindings for the expanded help view (overlay). This implements help.KeyMap interface.
func (KeyMap) PermissionShortHelp ¶ added in v5.26.0
PermissionShortHelp returns keybindings for the permission modal.
func (KeyMap) PickerShortHelp ¶ added in v5.26.0
PickerShortHelp returns keybindings for picker modals.
func (KeyMap) SessionPickerShortHelp ¶ added in v5.26.0
SessionPickerShortHelp returns keybindings for the session picker.
type MessageMetadata ¶ added in v5.25.1
type MessageMetadata struct {
AgentMode bool `json:"agentMode"` // true = agent mode, false = plan mode
}
MessageMetadata represents metadata for a single message in a session.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the Bubbletea model for the chat TUI.
func New ¶
func New( session *copilot.Session, client *copilot.Client, sessionConfig *copilot.SessionConfig, models []copilot.ModelInfo, currentModel string, timeout time.Duration, ) *Model
New creates a new chat TUI model.
func NewWithEventChannel ¶
func NewWithEventChannel( session *copilot.Session, client *copilot.Client, sessionConfig *copilot.SessionConfig, models []copilot.ModelInfo, currentModel string, timeout time.Duration, eventChan chan tea.Msg, agentModeRef *AgentModeRef, ) *Model
NewWithEventChannel creates a new chat TUI model with an optional pre-existing event channel. If eventChan is nil, a new channel is created. This allows external code to send events to the TUI (e.g., permission requests). If agentModeRef is provided, it will be used to synchronize agent mode state with tool handlers.
func (*Model) GetEventChannel ¶
GetEventChannel returns the model's event channel for external use. This is useful for creating permission handlers that can send events to the TUI.
type PermissionRequestMsg ¶ added in v5.25.0
type PermissionRequestMsg struct {
ToolCallID string
ToolName string
Command string
Arguments string
Response chan<- bool
}
PermissionRequestMsg is the exported version of permissionRequestMsg for external use.
type SessionMetadata ¶ added in v5.25.0
type SessionMetadata struct {
ID string `json:"id"`
Name string `json:"name"`
Model string `json:"model,omitempty"`
AgentMode *bool `json:"agentMode,omitempty"` // nil or true = agent mode, false = plan mode
// Messages stores per-message metadata (agentMode for each user message).
Messages []MessageMetadata `json:"messages,omitempty"`
SDKMetadata *copilot.SessionMetadata `json:"-"` // SDK metadata (not persisted)
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
SessionMetadata represents metadata for a chat session stored locally. Message content is stored server-side by Copilot and retrieved via ResumeSession.
func GetMostRecentSession ¶ added in v5.25.0
func GetMostRecentSession(client *copilot.Client) (*SessionMetadata, error)
GetMostRecentSession returns the most recently updated session metadata. Returns ErrNoSessions if no sessions exist.
func ListSessions ¶ added in v5.25.0
func ListSessions(client *copilot.Client) ([]SessionMetadata, error)
ListSessions returns all local session metadata from SDK, enriched with local metadata. Remote sessions are excluded from the returned slice. Sessions are sorted by ModifiedTime (most recent first).
func LoadSession ¶ added in v5.25.0
func LoadSession(id string) (*SessionMetadata, error)
LoadSession loads session metadata by ID.
func (*SessionMetadata) GetDisplayName ¶ added in v5.26.0
func (s *SessionMetadata) GetDisplayName() string
GetDisplayName returns the display name using hierarchy: Local Name → SDK Summary → "Unnamed". User-defined names take precedence over SDK-generated summaries.
type ToolOutputChunkMsg ¶
ToolOutputChunkMsg is the exported version of toolOutputChunkMsg for external use.