Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultKeyMap = KeyMap{ SelectPrevMessage: key.NewBinding( key.WithKeys("shift+up"), key.WithHelp("shift+↑", "move up")), SelectNextMessage: key.NewBinding( key.WithKeys("shift+down"), key.WithHelp("shift+↓", "move down"), ), UnfocusMessage: key.NewBinding( key.WithKeys("esc", "ctrl+g"), key.WithHelp("esc", "unfocus message"), ), FocusMessage: key.NewBinding( key.WithKeys("enter"), key.WithHelp("enter", "focus message"), ), SubmitMessage: key.NewBinding( key.WithKeys("tab"), key.WithHelp("tab", "submit message"), ), CancelCompletion: key.NewBinding( key.WithKeys("esc", "ctrl+g"), key.WithHelp("esc", "cancel completion"), ), DismissError: key.NewBinding( key.WithKeys("esc", "ctrl+g"), key.WithHelp("esc", "dismiss error"), ), SaveToFile: key.NewBinding( key.WithKeys("ctrl+s", "alt+s"), key.WithHelp("ctrl+s", "save to file"), ), CopyToClipboard: key.NewBinding( key.WithKeys("alt+c"), key.WithHelp("alt+c", "copy selected"), ), CopyLastResponseToClipboard: key.NewBinding( key.WithKeys("alt+l"), key.WithHelp("alt+l", "copy response"), ), CopySourceBlocksToClipboard: key.NewBinding( key.WithKeys("alt+d"), key.WithHelp("alt+d", "copy selected source"), ), CopyLastSourceBlocksToClipboard: key.NewBinding( key.WithKeys("alt+k"), key.WithHelp("alt+k", "copy source"), ), ScrollUp: key.NewBinding( key.WithKeys("shift+pgup"), key.WithHelp("shift+pgup", "scroll up"), ), ScrollDown: key.NewBinding( key.WithKeys("shift+pgdown"), key.WithHelp("shift+pgdown", "scroll down"), ), Quit: key.NewBinding( key.WithKeys("alt+q"), key.WithHelp("alt+q", "quit"), ), Help: key.NewBinding( key.WithKeys("ctrl-?"), key.WithHelp("ctrl-?", "help")), PreviousConversationThread: key.NewBinding( key.WithKeys("left"), key.WithHelp("left", "previous conversation thread"), ), NextConversationThread: key.NewBinding( key.WithKeys("right"), key.WithHelp("right", "next conversation thread"), ), }
Functions ¶
func InitialModel ¶
func InitialModel(manager conversation.Manager, backend Backend, options ...ModelOption) model
func OpenTTY ¶
func OpenTTY() (io.ReadWriteCloser, error)
Types ¶
type Backend ¶
type Backend interface { // Start begins the backend process with the provided context and conversation messages. Start(ctx context.Context, msgs []*conversation.Message) (tea.Cmd, error) // Interrupt signals the backend process to gracefully stop its current operation. Interrupt() // Kill forces the backend process to terminate immediately. This is used in // situations where an immediate halt of the backend process is required, such as // when the application is closing or an unrecoverable error has occurred. Kill() // IsFinished checks if the backend process has completed its tasks. It returns // true if the backend has finished processing and no further Stream*Msg messages // will be sent to the UI. IsFinished() bool }
Backend abstracts initiating and stopping the backend process that is responsible for streaming and processing chat messages.
Communication between the backend and the chat UI is facilitated through a series of Stream*Msg messages that the backend sends to the UI.
The typical flow of communication is as follows:
- The UI invokes the Start method, providing a context and the current conversation messages, to begin the backend streaming process.
- As the backend processes the stream, it sends Stream*Msg messages to the UI: - StreamStartMsg: Indicates the streaming process has started. - StreamStatusMsg: Provides updates on the status of the streaming process. - StreamCompletionMsg: Contains new data from the backend, such as a new message. - StreamDoneMsg: Signals the successful completion of the streaming process. - StreamErrorMsg: Communicates errors that occurred during streaming.
- The UI's Update method receives these messages and updates the chat model and view.
- The Backend interface provides Interrupt and Kill methods to allow the UI to request the backend to gracefully stop or forcefully terminate the streaming process.
- Upon completion of its tasks, the backend sends a BackendFinishedMsg to indicate that it has finished processing and will not send any further messages.
The backend is expected to maintain the context of the conversation, ensuring that new messages sent as completion events are correctly associated with the last message in the conversation to maintain the chat's continuity.
type BackendFinishedMsg ¶ added in v0.0.4
type BackendFinishedMsg struct{}
BackendFinishedMsg is a message sent when the backend process has finished its operation.
type KeyMap ¶
type KeyMap struct { SelectPrevMessage key.Binding `keymap-mode:"moving-around"` SelectNextMessage key.Binding `keymap-mode:"moving-around"` UnfocusMessage key.Binding `keymap-mode:"user-input"` FocusMessage key.Binding `keymap-mode:"moving-around"` SubmitMessage key.Binding `keymap-mode:"user-input"` ScrollUp key.Binding ScrollDown key.Binding CancelCompletion key.Binding `keymap-mode:"stream-completion"` DismissError key.Binding `keymap-mode:"error"` LoadFromFile key.Binding Regenerate key.Binding `keymap-mode:"user-input"` RegenerateFromHere key.Binding `keymap-mode:"moving-around"` EditMessage key.Binding `keymap-mode:"moving-around"` PreviousConversationThread key.Binding `keymap-mode:"moving-around"` NextConversationThread key.Binding `keymap-mode:"moving-around"` SaveToFile key.Binding `keymap-mode:"*"` SaveSourceBlocksToFile key.Binding `keymap-mode:"*"` CopyToClipboard key.Binding `keymap-mode:"moving-around"` CopyLastResponseToClipboard key.Binding `keymap-mode:"user-input"` CopyLastSourceBlocksToClipboard key.Binding `keymap-mode:"user-input"` CopySourceBlocksToClipboard key.Binding `keymap-mode:"moving-around"` Help key.Binding `keymap-mode:"*"` Quit key.Binding `keymap-mode:"*"` }
type ModelOption ¶ added in v0.0.4
type ModelOption func(*model)
func WithTitle ¶ added in v0.0.4
func WithTitle(title string) ModelOption
Click to show internal directories.
Click to hide internal directories.