Help us shape the future of Go! Take the 2026 Go Developer Survey

chat

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package chat is the chat area of the native desktop: the sessions list, session history and streaming runs (P0 MVP; P1 brings parity with the Web UI: tool cards, diffs, questions, plan/goal, model picker, slash and @).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	// Text is set for a text block.
	Text *Part
	// Events are the thinking/tool parts of an activity group.
	Events []*Part
}

Block is a run of consecutive tool calls and thinking parts folded into one activity row, or a text part.

func Blocks

func Blocks(parts []*Part) []Block

Blocks groups the parts of an assistant turn: consecutive tool calls and thinking parts become one activity group, text stands alone.

type Category

type Category int

Category is the coarse class of a tool call, used to build the "ran 3 commands · read 2 files" summary of a folded run of calls (web MessageBubble ActivityCategory).

const (
	CatCommands Category = iota
	CatRead
	CatEdited
	CatSearched
	CatFetched
	CatTools
	CatThought
)

Activity categories, in the order the summary lists them.

type Chat

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

Chat is the chat area's state. All fields are owned by the UI thread.

func New

func New(a *app.Context) *Chat

New returns the chat view.

func NewSimple

func NewSimple(a *app.Context) *Chat

NewSimple returns the simple chat view: the conversation alone, with the sessions panel collapsible and no goal/plan banners.

func (*Chat) Build

func (ch *Chat) Build(c *ui.Context, r *ui.Route)

Build shows the sessions pane, the conversation and the info panel.

func (*Chat) Close

func (ch *Chat) Close()

Close stops background work.

func (*Chat) HeaderActions

func (ch *Chat) HeaderActions(c *ui.Context)

HeaderActions adds the context badge, panel toggles and new-session button.

func (*Chat) Open

func (ch *Chat) Open(id string)

Open shows a session, loading its history the first time.

func (*Chat) Send

func (ch *Chat) Send(prompt string)

Send sends the draft: a new run, or feedback steering the running one.

func (*Chat) Stop

func (ch *Chat) Stop()

Stop cancels the active run.

func (*Chat) Title

func (ch *Chat) Title() string

Title is the header title: the open session's.

type Class

type Class int

Class is the display class of a tool call: it picks the detail layout.

const (
	ClassJSON Class = iota // generic: input as JSON, output
	ClassExec
	ClassRead
	ClassSearch
	ClassFetch
	ClassEdit  // old/new replacement
	ClassWrite // whole file content
)

Tool classes.

type Conversation

type Conversation struct {
	// ID is empty until the server assigns the session (new chat).
	ID    string
	Items []*Item
	// List is the transcript list state (follows the end).
	List ui.ListState

	// Loaded reports the history was fetched; Loading while it is.
	Loaded, Loading bool
	LoadErr         string

	// Running: a run is active server side (own, or followed).
	Running bool
	// Streaming: this client has a stream open for the run.
	Streaming bool
	// RunSeq is the last run sequence seen.
	RunSeq int64
	Usage  *client.TokenUsage
	// ContextWindow is the context size of the session's model (0 unknown).
	ContextWindow int64
	// BusyElsewhere: another process (a subagent) runs the session.
	BusyElsewhere bool

	Plan []client.PlanEntry
	Goal *client.GoalStatus
	// Files are the modified files of the session by path.
	Files map[string]*FileChange
	// AutoApprove mirrors the session's auto-approve state.
	AutoApprove bool
	// Permissions and Questions wait for an answer, oldest first.
	Permissions []client.PermissionRequest
	Questions   []client.QuestionRequest

	// Queued is feedback sent while the run goes on, not yet injected.
	Queued []string
	// contains filtered or unexported fields
}

Conversation is the transcript and run state of one session.

func SpikeConversation

func SpikeConversation(n int) *Conversation

SpikeConversation builds n alternating rows of realistic markdown.

func (*Conversation) AddPermission

func (cv *Conversation) AddPermission(p client.PermissionRequest)

AddPermission queues a permission request unless already seen.

func (*Conversation) AddQuestion

func (cv *Conversation) AddQuestion(q client.QuestionRequest)

AddQuestion queues a question request unless already seen.

func (*Conversation) Apply

func (cv *Conversation) Apply(ev client.StreamEvent) (reload bool)

Apply folds a stream event into the transcript. It reports whether the history should be reloaded (a finished run whose replay brought nothing).

func (*Conversation) BeginAttach

func (cv *Conversation) BeginAttach()

BeginAttach marks the conversation as following a run it did not start.

func (*Conversation) BeginRun

func (cv *Conversation) BeginRun(prompt string)

BeginRun adds the user's prompt and marks a run as started by this client.

func (*Conversation) FileList

func (cv *Conversation) FileList() []*FileChange

FileList returns the modified files, most recently updated first.

func (*Conversation) Finish

func (cv *Conversation) Finish() (reload bool)

Finish ends the run: every row is done. It reports whether the run delivered no content (a replay of a run already over), in which case the history holds the result and should be reloaded.

func (*Conversation) MergePending

func (cv *Conversation) MergePending(p client.Pending)

MergePending adopts the requests of GET /pending (the poll that catches prompts a dropped stream never delivered) and forgets queued ones the server no longer lists.

func (*Conversation) MergeVCS

func (cv *Conversation) MergeVCS(entries []client.VCSDiffEntry)

MergeVCS adds the paths agent-vcs knows the session touched that the history did not name.

func (*Conversation) Resolve

func (cv *Conversation) Resolve(id string)

Resolve removes an answered request from the queues.

func (*Conversation) SetHistory

func (cv *Conversation) SetHistory(msgs []client.Message)

SetHistory replaces the transcript with folded history.

func (*Conversation) TrimToLastPrompt

func (cv *Conversation) TrimToLastPrompt()

TrimToLastPrompt drops the rows after the last user prompt: a run being attached replays them.

type Edit

type Edit struct{ Old, New string }

Edit is one old -> new replacement of a file.

type FileChange

type FileChange struct {
	Path      string
	Name      string
	Additions int
	Removals  int
	// FromVCS: the entry came from agent-vcs only (no inline edits).
	FromVCS bool
	Edits   []Edit
	Updated int
}

FileChange is a file the session modified (the modified-files panel).

type Item

type Item struct {
	// Key is stable for the life of the row (list identity).
	Key  int
	Kind ItemKind
	// Text is the text of user/notice/error/persona rows.
	Text string
	// Images are data URLs attached to a user message.
	Images []string
	// Parts is the assistant turn: text, thinking and tool calls in order.
	Parts []*Part
	// Done is false while an assistant row is still streaming.
	Done  bool
	Model string
	Time  time.Time

	Routing       *client.RoutingInfo
	ContextFilter *client.ContextFilterInfo

	// Open: a collapsible row (persona, context filter) is expanded.
	Open bool
	// Group expansion state, keyed by the part key that starts the group.
	GroupOpen map[int]bool
}

Item is a row of the transcript.

func FoldHistory

func FoldHistory(msgs []client.Message) []*Item

FoldHistory turns stored messages into transcript rows: tool messages are folded into the call they answer (as the Web UI does), finish and empty parts dropped, and consecutive assistant messages (one per agent step) merged into a single turn.

func (*Item) PlainText

func (it *Item) PlainText() string

PlainText is the text of the row for copying: the text parts of an assistant turn joined by blank lines.

func (*Item) Tools

func (it *Item) Tools() []*Tool

Tools lists the tool calls of an assistant turn.

type ItemKind

type ItemKind int

ItemKind is the kind of a transcript row.

const (
	ItemUser ItemKind = iota
	ItemAssistant
	ItemNotice
	ItemError
	ItemRouting
	ItemContextFilter
	ItemPersona
)

Transcript row kinds.

type Part

type Part struct {
	Key  int
	Kind PartKind
	Text string
	Tool *Tool
	// Open: a thinking part is expanded.
	Open bool
}

Part is one piece of an assistant turn.

type PartKind

type PartKind int

PartKind is the kind of a part of an assistant turn.

const (
	PText PartKind = iota
	PThinking
	PTool
)

Assistant turn parts, in the order they were produced.

type Tool

type Tool struct {
	ID      string
	Name    string
	Title   string
	Kind    string
	Status  string
	Input   string
	Output  string
	IsError bool
	Open    bool

	Locations []client.Location
	Diff      *client.ToolDiff
	Terminal  *client.ToolTerminal
	// Images are data URLs of image results (screenshots).
	Images []string
	// contains filtered or unexported fields
}

Tool is a tool call shown in an assistant turn, with its result once it arrives.

func GroupSummary

func GroupSummary(events []*Part, T func(string, ...any) string) (summary string, failures int, live *Tool)

GroupSummary builds "ran 3 commands · read 2 files" for a group, in the Web UI's category order, with the failure count.

func (*Tool) Failed

func (t *Tool) Failed() bool

Failed reports whether the call failed.

func (*Tool) InputMap

func (t *Tool) InputMap() map[string]any

InputMap returns the call's input as a JSON object (nil if it is not one).

func (*Tool) Label

func (t *Tool) Label() string

Label is the text shown for the call.

func (*Tool) Live

func (t *Tool) Live() bool

Live reports whether the call is still running.

type ToolMeta

type ToolMeta struct {
	Icon     string
	Label    string
	Summary  string
	Category Category
	Class    Class
}

ToolMeta describes how a call is shown.

func MetaOf

func MetaOf(t *Tool) ToolMeta

MetaOf classifies a call by its name and input, then lets the server's kind and title win (they mirror ACP), as the Web UI does.

func (ToolMeta) ProgressLabel

func (m ToolMeta) ProgressLabel() string

ProgressLabel is "bash $ command" style text for the live call of a group.

Jump to

Keyboard shortcuts

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