chat

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 43 Imported by: 0

Documentation

Overview

Package chat provides UI components for rendering chat messages and managing the chat interface in the OpenCode TUI.

This subpackage contains bubble components for distinct user and assistant messages.

Package chat provides UI components for rendering chat messages and managing the chat interface in the OpenCode TUI. It includes components for viewing messages, editing input, displaying diffs, and navigating the chat sidebar.

Package chat provides UI components for rendering chat messages and diffs. This file contains the diff viewer with the half-block indicator (▐).

Package chat provides UI components for rendering chat messages and managing the chat interface in the OpenCode TUI.

Package chat provides UI components for rendering chat messages and managing the chat interface in the OpenCode TUI.

Package chat provides UI components for rendering chat messages and managing the chat interface in the OpenCode TUI.

Package chat provides UI components for rendering chat messages and managing the chat interface in the OpenCode TUI.

Package chat provides UI components for rendering chat messages and diffs. This file contains the main chat viewer with border container.

Index

Constants

This section is empty.

Variables

View Source
var BubbleRendererInstance = NewBubbleRenderer()

BubbleRendererInstance is a global instance for convenient bubble rendering.

View Source
var DeleteKeyMaps = DeleteAttachmentKeyMaps{
	AttachmentDeleteMode: key.NewBinding(
		key.WithKeys("ctrl+r"),
		key.WithHelp("ctrl+r+{i}", "delete attachment at index i"),
	),
	Escape: key.NewBinding(
		key.WithKeys("esc"),
		key.WithHelp("esc", "cancel delete mode"),
	),
	DeleteAllAttachments: key.NewBinding(
		key.WithKeys("r"),
		key.WithHelp("ctrl+r+r", "delete all attchments"),
	),
}

Functions

func CreateTextArea

func CreateTextArea(existing *textarea.Model) textarea.Model

CreateTextArea creates a new text area component with the given theme and existing text area. It sets the text area's properties such as prompt, line numbers, and character limit. It also applies the theme's styles to the text area.

func NewEditorCmp

func NewEditorCmp(app *app.App) tea.Model

NewEditorCmp creates a new instance of the editor component.

func NewMessagesCmp

func NewMessagesCmp(app *app.App) tea.Model

NewMessagesCmp creates a new instance of the messages component. It initializes the spinner and viewport, sets up key bindings for pagination, and returns the component ready for use in the TUI.

func NewSidebarCmp

func NewSidebarCmp(s session.Session, sessions session.Service, history history.Service) tea.Model

NewSidebarCmp creates a new sidebar component.

func ParseUnifiedDiff added in v1.10.0

func ParseUnifiedDiff(diffContent string) []diff.DiffHunk

ParseUnifiedDiff parses a unified diff string into structured DiffHunks. This is a wrapper that delegates to the shared diff package.

Types

type BubbleOption added in v1.10.0

type BubbleOption func(*bubbleConfig)

BubbleOption is a functional option for configuring bubble styles.

func WithBubbleFocused added in v1.10.0

func WithBubbleFocused(focused bool) BubbleOption

WithBubbleFocused sets the focused state for the bubble.

func WithBubbleMaxWidth added in v1.10.0

func WithBubbleMaxWidth(maxWidth int) BubbleOption

WithBubbleMaxWidth sets the maximum width for the bubble.

func WithBubblePadding added in v1.10.0

func WithBubblePadding(padding int) BubbleOption

WithBubblePadding sets the padding for the bubble.

func WithBubbleWidth added in v1.10.0

func WithBubbleWidth(width int) BubbleOption

WithBubbleWidth sets the width for the bubble.

type BubbleRenderer added in v1.10.0

type BubbleRenderer struct{}

BubbleRenderer provides methods to render chat bubbles with different styles.

func NewBubbleRenderer added in v1.10.0

func NewBubbleRenderer() *BubbleRenderer

NewBubbleRenderer creates a new BubbleRenderer instance.

func (*BubbleRenderer) AssistantBubble added in v1.10.0

func (r *BubbleRenderer) AssistantBubble(content string, opts ...BubbleOption) string

AssistantBubble renders a message bubble for the AI assistant (typically on the left side). It uses the BackgroundSecondary color from the theme and rounded borders.

func (*BubbleRenderer) SystemBubble added in v1.10.0

func (r *BubbleRenderer) SystemBubble(content string, opts ...BubbleOption) string

SystemBubble renders a message bubble for system messages. It uses the BackgroundDarker color with a dim border.

func (*BubbleRenderer) ThinkingBubble added in v1.10.0

func (r *BubbleRenderer) ThinkingBubble(opts ...BubbleOption) string

ThinkingBubble renders a thinking/loading bubble for the assistant. This is shown while the assistant is generating a response.

func (*BubbleRenderer) UserBubble added in v1.10.0

func (r *BubbleRenderer) UserBubble(content string, opts ...BubbleOption) string

UserBubble renders a message bubble for the user (typically on the right side). It uses the Primary color from the theme and the rounded border style.

type ChatViewer added in v1.10.0

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

ChatViewer renders the main chat container with messages and border.

func NewChatViewer added in v1.10.0

func NewChatViewer(config ChatViewerConfig) *ChatViewer

NewChatViewer creates a new chat viewer with the given configuration.

func (*ChatViewer) GetDimensions added in v1.10.0

func (cv *ChatViewer) GetDimensions() layout.Dimensions

GetDimensions returns the current dimensions.

func (*ChatViewer) GetMaxWidth added in v1.10.0

func (cv *ChatViewer) GetMaxWidth() int

GetMaxWidth returns the maximum width.

func (*ChatViewer) Render added in v1.10.0

func (cv *ChatViewer) Render(messages []string) string

Render renders the chat viewer and returns the formatted string.

func (*ChatViewer) RenderMessageBubble added in v1.10.0

func (cv *ChatViewer) RenderMessageBubble(role, content string) string

RenderMessageBubble renders a single message bubble.

func (*ChatViewer) RenderToolBadge added in v1.10.0

func (cv *ChatViewer) RenderToolBadge(toolName string, success bool) string

RenderToolBadge renders a tool badge with success/failure indicator.

func (*ChatViewer) RenderToolBadges added in v1.10.0

func (cv *ChatViewer) RenderToolBadges(toolNames []string, successes []bool) string

RenderToolBadges renders multiple tool badges.

func (*ChatViewer) RenderWithDiff added in v1.10.0

func (cv *ChatViewer) RenderWithDiff(messages []string, diffContent string, filePath string) string

RenderWithDiff renders the chat viewer including a diff viewer.

func (*ChatViewer) SetDimensions added in v1.10.0

func (cv *ChatViewer) SetDimensions(dims layout.Dimensions)

SetDimensions sets the layout dimensions for the chat viewer.

func (*ChatViewer) SetMaxWidth added in v1.10.0

func (cv *ChatViewer) SetMaxWidth(width int)

SetMaxWidth sets the maximum width.

func (*ChatViewer) SetTheme added in v1.10.0

func (cv *ChatViewer) SetTheme(t theme.Theme)

SetTheme sets the theme for the chat viewer.

type ChatViewerConfig added in v1.10.0

type ChatViewerConfig struct {
	// MaxWidth is the maximum width of the chat viewer in characters (default: 900)
	MaxWidth int

	// ShowBorder controls whether to show the border around the viewer (default: true)
	ShowBorder bool

	// Title is the title to display in the border (default: "Chat")
	Title string

	// AgentName is the name of the active agent displayed in the border (default: "Coder")
	AgentName string

	// AgentActive indicates if the agent is currently active, displayed in the border status
	AgentActive bool

	// ShowToolBadges indicates whether to show tool badges for tool calls
	ShowToolBadges bool
}

ChatViewerConfig contains configuration options for the ChatViewer. It controls appearance settings like maximum width, borders, titles, and agent status.

func DefaultChatViewerConfig added in v1.10.0

func DefaultChatViewerConfig() ChatViewerConfig

DefaultChatViewerConfig returns a ChatViewerConfig with default values.

type DeleteAttachmentKeyMaps

type DeleteAttachmentKeyMaps struct {
	// AttachmentDeleteMode enters delete mode to remove attachments
	AttachmentDeleteMode key.Binding
	// Escape cancels delete mode
	Escape key.Binding
	// DeleteAllAttachments removes all attachments
	DeleteAllAttachments key.Binding
}

DeleteAttachmentKeyMaps defines key bindings for managing attachments.

type DiffViewer added in v1.10.0

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

DiffViewer renders unified diff format with the ▐ indicator. Uses the shared diff types and parsing from the diff package.

func NewDiffViewer added in v1.10.0

func NewDiffViewer(maxWidth int) *DiffViewer

NewDiffViewer creates a new diff viewer with the given maximum width.

func (*DiffViewer) Render added in v1.10.0

func (dv *DiffViewer) Render(diffContent string) string

Render renders the diff viewer and returns the formatted string.

func (*DiffViewer) RenderFileHeader added in v1.10.0

func (dv *DiffViewer) RenderFileHeader(filePath string) string

RenderFileHeader renders a file header with the file path.

func (*DiffViewer) SetTheme added in v1.10.0

func (dv *DiffViewer) SetTheme(t theme.Theme)

SetTheme sets the theme for the diff viewer.

type EditorFocusMsg

type EditorFocusMsg bool

EditorFocusMsg is a message sent to focus or unfocus the editor.

type EditorKeyMaps

type EditorKeyMaps struct {
	// Send binds to keys that send the message (Enter, Ctrl+S)
	Send key.Binding
	// OpenEditor binds to keys that open external editor (Ctrl+E)
	OpenEditor key.Binding
}

EditorKeyMaps defines key bindings for the message editor.

type Message added in v1.10.0

type Message struct {
	ID             string
	Role           MessageRole
	Content        string
	Timestamp      time.Time
	IsStreaming    bool
	PartialContent string
}

Message represents a chat message in the UI layer. This is a lightweight representation for rendering purposes.

func NewAssistantMessage added in v1.10.0

func NewAssistantMessage(content string) *Message

NewAssistantMessage creates a new assistant message.

func NewMessage added in v1.10.0

func NewMessage(role MessageRole, content string) *Message

NewMessage creates a new Message with the given role and content.

func NewUserMessage added in v1.10.0

func NewUserMessage(content string) *Message

NewUserMessage creates a new user message.

func (*Message) AppendContent added in v1.10.0

func (m *Message) AppendContent(content string)

AppendContent appends content to the message (for streaming).

func (*Message) Finalize added in v1.10.0

func (m *Message) Finalize()

Finalize marks the message as complete (not streaming anymore).

func (*Message) IsAssistant added in v1.10.0

func (m *Message) IsAssistant() bool

IsAssistant returns true if the message is from the assistant.

func (*Message) IsSystem added in v1.10.0

func (m *Message) IsSystem() bool

IsSystem returns true if the message is a system message.

func (*Message) IsTool added in v1.10.0

func (m *Message) IsTool() bool

IsTool returns true if the message is a tool message.

func (*Message) IsUser added in v1.10.0

func (m *Message) IsUser() bool

IsUser returns true if the message is from the user.

func (*Message) RenderMarkdown added in v1.10.0

func (m *Message) RenderMarkdown(width int) string

RenderMarkdown renders the message content as markdown using the glamour renderer.

func (*Message) RenderPartialMarkdown added in v1.10.0

func (m *Message) RenderPartialMarkdown(width int) string

RenderPartialMarkdown renders partial content for streaming messages.

func (*Message) UpdateContent added in v1.10.0

func (m *Message) UpdateContent(content string)

UpdateContent updates the message content (for streaming).

type MessageKeys

type MessageKeys struct {
	PageDown     key.Binding
	PageUp       key.Binding
	HalfPageUp   key.Binding
	HalfPageDown key.Binding
}

MessageKeys defines the key bindings for the messages component.

type MessageRole added in v1.10.0

type MessageRole string

MessageRole represents the role of a message sender.

const (
	RoleUser      MessageRole = "user"
	RoleAssistant MessageRole = "assistant"
	RoleSystem    MessageRole = "system"
	RoleTool      MessageRole = "tool"
)

Message role constants.

type SendMsg

type SendMsg struct {
	Text        string
	Attachments []message.Attachment
}

SendMsg is a message sent when the user submits a message in the chat.

type SessionClearedMsg

type SessionClearedMsg struct{}

SessionClearedMsg is a message sent when the current session is cleared.

type SessionSelectedMsg

type SessionSelectedMsg = session.Session

SessionSelectedMsg is a message sent when a session is selected.

Jump to

Keyboard shortcuts

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