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 DeleteSession(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 SaveSession(session *SessionMetadata) error
- 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 DeleteSession ¶ added in v5.25.0
DeleteSession removes a chat session from 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 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 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, ) *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).
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"`
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 ¶
ToolOutputChunkMsg is the exported version of toolOutputChunkMsg for external use.