render

package
v0.178.2 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package render formats agentdomain.ChatEvent streams for the headless CLI.

Each format function consumes the event channel from AgentService.RunWithStream and writes formatted output to an io.Writer. All renderers drain the channel until it closes (the engine closes it when the run ends), so the producer is never left blocked mid-run.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitPreRunError

func EmitPreRunError(w io.Writer, format string, err error)

EmitPreRunError writes a machine-readable failure line for errors that occur before the event stream starts (gateway down, unknown model, ...), so stdout consumers - the channel manager and agentrunner - see the failure instead of silence. The text format stays quiet; the CLI's stderr prose covers it.

func FormatAgentMessage

func FormatAgentMessage(line []byte) string

FormatAgentMessage parses a JSON line from the agent's stdout and returns a human-readable message to send to the channel. Returns empty string for messages that should not be forwarded (status messages, tool results, etc.).

func RenderAGUI

func RenderAGUI(events <-chan agentdomain.ChatEvent, w io.Writer, approvals <-chan ipc.ApprovalResponse, sessionID, model string) error

RenderAGUI renders events as newline-delimited AG-UI protocol events. The run gets exactly one RUN_STARTED and one terminal event (RUN_FINISHED or RUN_ERROR); per-turn events in between carry deltas, tool calls, and results. When approvals is non-nil it acts as the IPC approval broker, same as RenderJSON. A ComputerUseResumedEvent clears any error carried over from the paused (cancelled) run, same as RenderJSON.

func RenderJSON

func RenderJSON(events <-chan agentdomain.ChatEvent, w io.Writer, approvals <-chan ipc.ApprovalResponse, sessionID, model string, cfg *config.Config, repo convdomain.ConversationRepository) error

RenderJSON renders events as JSON lines, streaming each message as its turn completes: assistant messages on ChatCompleteEvent, tool results on ToolExecutionCompletedEvent, approval requests and errors in real time. After the channel closes only the session stats are read from the repo. When approvals is non-nil it acts as the IPC approval broker: each approval_request line is answered by the next matching ApprovalResponse. A ComputerUseResumedEvent clears any error carried over from the paused (cancelled) run, so a resumed run that completes cleanly exits zero.

func RenderJSONPretty

func RenderJSONPretty(events <-chan agentdomain.ChatEvent, w io.Writer, approvals <-chan ipc.ApprovalResponse, sessionID, model string, cfg *config.Config, repo convdomain.ConversationRepository) error

RenderJSONPretty is RenderJSON with each object indented across multiple lines for human reading. Objects are separated by newlines but are no longer one-per-line, so machine consumers should use RenderJSON.

func RenderText

func RenderText(events <-chan agentdomain.ChatEvent, w io.Writer) error

RenderText streams content deltas as plain text to w, matching the non-interactive chat output style. The engine emits one ChatCompleteEvent per turn, so rendering continues until the channel closes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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