chat

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

SPDX-License-Identifier: MIT Purpose: chat input widget — textarea with attachment support and slash commands. Used by the TUI 2.0 chat mode (Phase 5 of st-3t5v).

SPDX-License-Identifier: MIT Purpose: async LLM runner for the TUI chat view. Translates the `chat.SubmitMsg` payload (system + last 5 history turns + current prompt) into an `llm.ChatRequest` and returns the assistant text. Provider is resolved via `llm.ProviderFromConfig("nim", ...)`, which reads `SIN_NIM_API_KEY` from the environment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendChatResponse

func SendChatResponse(text string, err error) tea.Cmd

SendChatResponse is a tea.Cmd that produces a ChatResponseMsg. Useful for callers that drive the chat synchronously (e.g. tests). The chat input normally spawns a goroutine and uses *tea.Program.Send to push ChatResponseMsg into the event loop directly.

Types

type ChatResponseMsg

type ChatResponseMsg struct {
	Text  string
	Error error
}

ChatResponseMsg is fired by the background goroutine when the LLM returns. The TUI Update handler appends it to ChatHistory.

type Input

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

func NewInput

func NewInput(store *attachments.Store) *Input

func (*Input) Attach

func (i *Input) Attach(path string) error

func (*Input) AttachBytes

func (i *Input) AttachBytes(data []byte, name string) error

func (*Input) Attachments

func (i *Input) Attachments() []*attachments.Attachment

func (*Input) Blur

func (i *Input) Blur()

func (*Input) Clear

func (i *Input) Clear()

func (*Input) Focus

func (i *Input) Focus() tea.Cmd

func (*Input) HandlePasteBytes

func (i *Input) HandlePasteBytes(data []byte)

HandlePasteBytes is a public entry-point for paste events that carry raw bytes (e.g. an image dragged into the terminal, or a future Bubbletea v2 tea.PasteMsg adapter). The Bubbletea v1 KeyMsg.Paste path runs the payload through utf8.DecodeRune which corrupts non-UTF-8 image data, so programmatic callers (tests, future drag-and-drop handlers) should use this method to preserve byte fidelity.

func (*Input) HandleSlashCommand

func (i *Input) HandleSlashCommand(line string) (handled bool, err error)

func (*Input) Init

func (i *Input) Init() tea.Cmd

func (*Input) RawValue

func (i *Input) RawValue() string

func (*Input) RenderStatus

func (i *Input) RenderStatus() string

func (*Input) SetSize

func (i *Input) SetSize(w, h int)

func (*Input) Update

func (i *Input) Update(msg tea.Msg) (tea.Cmd, *SubmitMsg)

func (*Input) Value

func (i *Input) Value() string

func (*Input) View

func (i *Input) View() string

type Runner

type Runner struct {
	Client       *llm.Client
	Model        string
	SystemPrompt string
}

Runner wraps an LLM client + model + system prompt. One Runner per TUI session; the chat view holds a singleton and reuses it across submits.

func NewRunner

func NewRunner() (*Runner, error)

NewRunner builds a Runner from the current environment. Returns an error if no API key is configured (env SIN_NIM_API_KEY).

func NewRunnerWithClient

func NewRunnerWithClient(c *llm.Client, model, system string) *Runner

NewRunnerWithClient builds a Runner from a pre-configured client. Used by tests and by callers that want to override the base URL.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, prompt string, history []string) (string, error)

Run builds a ChatRequest from system + last 5 history entries + current prompt and returns the assistant text. history is the full m.ChatHistory slice; the most recent `historyKeepN` entries are folded in.

type SubmitMsg

type SubmitMsg struct {
	Text        string
	Attachments []*attachments.Attachment
}

Jump to

Keyboard shortcuts

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