chat

package
v5.25.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrNoSessions = errors.New("no sessions available")

ErrNoSessions is returned when there are no sessions available.

Functions

func DeleteSession added in v5.25.0

func DeleteSession(id string) error

DeleteSession removes a chat session from disk.

func FormatRelativeTime added in v5.25.0

func FormatRelativeTime(t time.Time) string

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).

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 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

func (m *Model) GetEventChannel() chan tea.Msg

GetEventChannel returns the model's event channel for external use. This is useful for creating permission handlers that can send events to the TUI.

func (*Model) Init

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

Init initializes the model and returns an initial command.

func (*Model) Update

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

Update handles messages and updates the model.

func (*Model) View

func (m *Model) View() string

View renders 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  []MessageMetadata `json:"messages,omitempty"`  // per-message metadata (agentMode for each user message)
	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() (*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() ([]SessionMetadata, error)

ListSessions returns all saved session metadata, sorted by UpdatedAt (most recent first).

func LoadSession added in v5.25.0

func LoadSession(id string) (*SessionMetadata, error)

LoadSession loads session metadata by ID.

type ToolOutputChunkMsg

type ToolOutputChunkMsg struct {
	ToolID string
	Chunk  string
}

ToolOutputChunkMsg is the exported version of toolOutputChunkMsg for external use.

Jump to

Keyboard shortcuts

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