notify.go

 1// Package notify defines domain notification types for agent events.
 2// These types are decoupled from UI concerns so the agent can publish
 3// events without importing UI packages.
 4package notify
 5
 6// Type identifies the kind of agent notification.
 7type Type string
 8
 9const (
10	// TypeAgentFinished indicates the agent has completed its turn.
11	TypeAgentFinished Type = "agent_finished"
12	// TypeReAuthenticate indicates the agent encountered an
13	// authentication error and the user needs to re-authenticate.
14	TypeReAuthenticate Type = "re_authenticate"
15)
16
17// Notification represents a domain event published by the agent.
18type Notification struct {
19	SessionID    string
20	SessionTitle string
21	Type         Type
22	ProviderID   string
23}
24
25// RunComplete is the authoritative end-of-run signal for a session.
26// It is published exactly once per top-level agent run (per
27// [sessionAgent.Run] invocation that actually executed) after all
28// message updates for the turn have been flushed via
29// message.Service.FlushAll. Carries the final assistant text and
30// message ID so non-interactive clients can reconcile stdout even if
31// SSE events arrive out of order or are dropped by the broker. Error
32// is non-empty when the run terminated with an error; Cancelled is
33// true when the run terminated due to context cancellation. The two
34// are mutually exclusive in the success case but may overlap when a
35// cancel triggers a downstream error.
36//
37// RunID identifies the specific request that produced this event.
38// It is the value the caller set on `proto.AgentMessage.RunID` (or
39// equivalently propagated via agent.WithRunID on the context that
40// reaches the coordinator); empty when no caller set one. Filtering
41// by RunID lets a client correlate a SendMessage call with its
42// terminal event even when the session is busy and other turns are
43// finishing on the same session.
44type RunComplete struct {
45	SessionID string
46	RunID     string
47	MessageID string
48	Text      string
49	Error     string
50	Cancelled bool
51}