Chat
Conversation turns with tool activity, folded summaries and a glass composer.
Loading the live example…
import (
"fmt"
"strings"
"time"
"unicode/utf8"
"github.com/egoist/mygo/ui"
"github.com/egoist/mygo/ui/markdown"
"github.com/oneo-me/onevra/source/components"
"github.com/oneo-me/onevra/source/components/chat"
"github.com/oneo-me/onevra/source/icons/lucide"
)
// assistantReply is what the simulated model answers; a real application
// would receive it from a network request, off the UI thread.
const assistantReply = "Every Onevra control is drawn by **MyGo**, so a window needs:\n\n" +
"1. A *builder* that runs every frame.\n2. State kept in your own values.\n3. No web view at all.\n\n" +
"```go\ncomponents.Button(c, \"Save\", components.ButtonPrimary)\n```"
type assistantTurn struct {
id, prompt, reply string
status chat.Status
started time.Time
state chat.TurnState
search chat.ActivityState
group chat.GroupState
}
type assistant struct {
layout chat.FloatingConversationState
conversation chat.ConversationState
turns []*assistantTurn
draft string
markdown markdown.Options
}
func (a *assistant) View(c *ui.Context) {
now := c.Now()
running := false
for _, turn := range a.turns {
if turn.status == chat.Running {
running = true
// Reveal the reply over time, as a stream would deliver it.
if n := int(now.Sub(turn.started)/(30*time.Millisecond)) * 4; n < len(assistantReply) {
for n < len(assistantReply) && !utf8.RuneStart(assistantReply[n]) {
n++
}
turn.reply = assistantReply[:n]
c.After(30 * time.Millisecond)
} else {
turn.reply, turn.status = assistantReply, chat.Completed
}
}
}
chat.FloatingConversation(c, &a.layout, &a.conversation, "Latest", func(c *ui.Context) {
for _, turn := range a.turns {
a.turn(c, turn)
}
}, func(c *ui.Context) {
result := chat.GlassComposer(c, &a.layout, &a.draft, chat.ComposerOptions{
Label: "Message", Placeholder: "Ask anything", SendLabel: "Send", StopLabel: "Stop",
Running: running,
})
if result.Send && strings.TrimSpace(a.draft) != "" {
a.turns = append(a.turns, &assistantTurn{
id: fmt.Sprint("turn-", len(a.turns)), prompt: strings.TrimSpace(a.draft),
status: chat.Running, started: now,
})
a.draft = ""
a.conversation.JumpToLatest()
}
if result.Stop {
a.turns[len(a.turns)-1].status = chat.Cancelled
}
})
}
func (a *assistant) turn(c *ui.Context, turn *assistantTurn) {
var steps []chat.Step
var final chat.View
if turn.started != (time.Time{}) {
search := chat.Completed
if turn.status == chat.Running && turn.reply == "" {
search = chat.Running
}
steps = append(steps, chat.Step{ID: "work", Title: "Searched the docs", Group: &turn.group,
Activities: []chat.Activity{{ID: "search", Icon: lucide.Search, Action: "Search", Detail: "docs",
Status: search, State: &turn.search,
Content: func(c *ui.Context) { components.Text(c, "Found 3 pages about builders.") }}}})
}
if turn.status == chat.Running {
if turn.reply != "" {
steps = append(steps, chat.Step{ID: "reply", Message: func(c *ui.Context) {
markdown.Stream(c, turn.reply, &a.markdown).FillWidth()
}})
}
} else if turn.reply != "" {
final = func(c *ui.Context) { markdown.View(c, turn.reply, &a.markdown).FillWidth() }
}
chat.Turn(c, &turn.state, chat.TurnOptions{
ID: turn.id, Status: turn.status, Summary: "Worked for 2s", Working: "Working",
Prompt: func(c *ui.Context) { components.Text(c, turn.prompt) },
Steps: steps, Final: final, HoldOpen: !a.conversation.AtLatest(),
})
}Send a message to see a turn run: an activity group shows the work, the reply streams in, and once the turn completes its steps fold behind a summary. The application owns the turns, their steps with stable IDs, the request and every label; builders never call the network.
chat.FloatingConversation lets the transcript scroll behind chat.GlassComposer, keeping the latest turn clear of it. Enter sends and Shift+Enter inserts a line. Stream replies with MyGo's markdown.Stream, and switch to markdown.View once complete.
The composer's slots hold attachments, pickers, a context meter and a footer; the package supplies chips, pickers, meters and usage limits styled for them. The Gallery shows a complete composer.
API
FloatingConversation
func FloatingConversation(c *ui.Context, layout *FloatingConversationState, state *ConversationState, jumpLabel string, content, composer View) ui.ElementFloatingConversation lets the transcript scroll behind the composer, but reserves enough trailing content space to leave the latest turn unobscured. The transcript blurs progressively from the bottom edge up to the middle of the composer card at rest, without following the card as it grows. Give the parent a bounded height and supply a localized jumpLabel; composer typically builds a GlassComposer. Applications own both states and all content; builders run synchronously.
pkg.go.devConversation
func Conversation(c *ui.Context, state *ConversationState, jumpLabel string, content View) ui.ElementConversation owns a bounded scroll viewport and a jump button. Give its parent a bounded height. Supply a localized jumpLabel. Following uses MyGo's scroll state and yields when the user scrolls up. The button is overlaid so its appearance cannot change viewport height.
pkg.go.devTurn
func Turn(c *ui.Context, state *TurnState, options TurnOptions) ui.ElementTurn displays the prompt, its steps and the final response. A completed turn folds its steps behind a centered summary row, building nothing hidden.
pkg.go.devTurnOptions
TurnOptions describes one request and its response. Supply a stable, nonempty ID. Summary labels the completed turn's fold row ("Worked for 2m") and Working the live indicator ("Working for 12s"). Final is explicit: the last step is never inferred to be the answer.
Prop
Type
Step
Step is either intermediate prose (Message) or a group of activities with an application-summarized Title such as "Ran 2 commands".
Prop
Type
Activity
Activity is one execution step inside an activity group, such as reading a file, running a command or thinking. ID is stable within its turn; update a tool's existing activity by its call ID, even if results arrive out of order. Action is a short verb ("Read") and Detail its target.
Prop
Type
Status
type Status uint8Status describes a turn or activity's application-reported lifecycle. A tool finishing does not finish its turn. Only Completed permits folding.
const (
Running Status = iota
Waiting
Completed
Failed
Cancelled
)GlassComposer
func GlassComposer(c *ui.Context, layout *FloatingConversationState, draft *string, options ComposerOptions) ComposerResultGlassComposer keeps Onevra's editor and actions, replacing only its surface. The footer stays outside the glass so the card remains visually lightweight. layout may be nil outside a floating conversation; with it, the conversation's blur reaches the middle of the card at rest.
pkg.go.devComposerOptions
ComposerOptions supplies localized labels and optional application controls. Enter sends outside input-method composition and Shift+Enter inserts a newline. While Running, Stop is shown, and a nonempty draft also offers Send so the application can interrupt the run with the new message.
Prop
Type
ComposerResult
ComposerResult contains frame-local actions. The application clears the draft after accepting Send and owns request cancellation for Stop. Dropped lists file paths dropped on the card since the last frame; reading or attaching them remains application work. Drop contains host-selected native data, while Dragging reports either kind of accepted drag over the card.
Prop
Type
Attachment
func Attachment(c *ui.Context, options AttachmentOptions) AttachmentResultAttachment shows a compact file chip with an optional remove action, for the composer's Attachments slot or a prompt. It performs no file I/O.
pkg.go.devChip
func Chip(c *ui.Context, label string, options ChipOptions) ui.ElementChip is a compact composer or footer control for a setting such as a model, reasoning level, project or branch. Its label shortens with an ellipsis when the row is tight. Read Clicked or attach a native menu with Element.Menu on interactive chips; a ReadOnly chip is not a button.
pkg.go.devPicker
func Picker(c *ui.Context, state *PickerState, options PickerOptions) PickerResultPicker shows a Chip that opens a popover of grouped, optionally searchable options with a check on the selection. Choosing closes the popover; the application applies and persists the choice.
pkg.go.devEffortPicker
func EffortPicker(c *ui.Context, state *EffortState, options EffortPickerOptions) PickerResultEffortPicker shows a Chip with the icon, the selected level's name and a caret, suited to the composer's Accessory slot, that opens a panel with the selected level's name and a progress bar above the level names, spread from edge to edge; each level fills the bar to the end of its name. Clicking or dragging across the bar or the names, or the arrows, Home and End, choose a level and keep the panel open; the application applies it. The panel widens to fit the names.
The stronger the level, the livelier all three: the icon turns violet and gains a breathing halo, then streams blocks of data outward; the bar's violet fill gains a glint, then streaming blocks of data, a glow, flowing colors, sparkles and rising sparks; the panel gains a violet wash, then drifting aurora, floating motes and a turning border. Motion stays slow, quickening a little at the top, and each effect fades in or out as the level changes. Reduced Motion keeps them still.
pkg.go.devContextMeter
func ContextMeter(c *ui.Context, state *MeterState, options ContextMeterOptions) ui.ElementContextMeter is a small ring gauge, suited to the composer's Trailing slot, that opens a panel with the value and a bar. It fills with the accent, warns from 80% and alerts from 95%. The application measures usage.
pkg.go.devQuotaSummary
func QuotaSummary(c *ui.Context, state *MeterState, options QuotaSummaryOptions) QuotaSummaryResultQuotaSummary is a compact footer control that shows Row's Detail, such as the time to reset, and a small accent bar of what remains, or Value for a balance. Clicking opens a panel with every Quota. The application chooses the row.
pkg.go.devFloatingConversationWith
func FloatingConversationWith(c *ui.Context, layout *FloatingConversationState, state *ConversationState, options FloatingConversationOptions) ui.ElementFloatingConversationWith is FloatingConversation with its views as options.
pkg.go.devComposer
func Composer(c *ui.Context, draft *string, options ComposerOptions) ComposerResultComposer builds a multiline editor card with send/stop and an accessory row. Keep draft outside the frame; a running request never discards the next draft.
pkg.go.devMessage
func Message(c *ui.Context, outgoing bool, content View) ui.ElementMessage lays out a message independently of its surface. Outgoing messages align to the trailing edge; incoming content uses the available width.
pkg.go.devBubble
func Bubble(c *ui.Context, content View) ui.ElementBubble is the raised surface of an outgoing message.
pkg.go.devActivityRow
func ActivityRow(c *ui.Context, a Activity) ui.ElementActivityRow renders one activity as a compact card that can expand to its bounded detail. Content costs and truncation are application-owned.
pkg.go.devResultSummary
func ResultSummary(c *ui.Context, state *SummaryState, options SummaryOptions) SummaryResultResultSummary displays a bounded artifact list outside the execution fold.
pkg.go.devAttachmentPreview
func AttachmentPreview(c *ui.Context, options AttachmentPreviewOptions) AttachmentPreviewResultAttachmentPreview shows a 64-point image tile with an optional remove action. A nil image shows a placeholder, without reading any file. Use it for rows of images only; Attachment keeps mixed rows at one height.
pkg.go.devQuota
func Quota(c *ui.Context, options QuotaOptions) QuotaResultQuota lists an account's limits with accent bars of what remains, warning from 20% left and alerting from 5%. The application reads and refreshes usage.
pkg.go.devShimmer
func Shimmer(c *ui.Context, text string, size float32, color, highlight ui.Color) ui.ElementShimmer draws a single line of text of size in color with a highlight sweeping across it, marking ongoing work such as a live activity title. It keeps its natural width unless the caller lets it shrink, for example with Shrink(1).MinWidth(0); text that then does not fit ends in an ellipsis. Only drawing animates; the text is shaped once per build. Reduced Motion shows plain text.
pkg.go.devGlassPanel
func GlassPanel(c *ui.Context, content View) ui.ElementGlassPanel is a compact card with GlassComposer's surface, for floating status the host overlays on a conversation, such as command output or errors above the composer. Its height follows content, and its tighter radius suits a panel docked near the window edge.
pkg.go.devIconAction
func IconAction(c *ui.Context, label string, icon func() *ui.SVG) ui.ElementIconAction is a keyboard-operable, named icon button with a focus tooltip.
pkg.go.dev