Documentation
¶
Overview ¶
Package stream is the daemon's per-run event hub: the runner publishes unified events for a run; the SSE endpoint replays the buffer to a late subscriber and then streams live events until the run completes (or the client disconnects).
A finished run's topic is reaped after a short grace window so memory doesn't grow without bound across the daemon's lifetime, and a subscriber that can't keep up is evicted (its channel closed) rather than silently losing events — the client reconnects and replays the full retained buffer.
Index ¶
- type Hub
- func (h *Hub) Close(id string)
- func (h *Hub) Publish(id string, ev agent.Event)
- func (h *Hub) Snapshot(id string) (Snapshot, bool)
- func (h *Hub) Subscribe(id string) (replay []agent.Event, ch <-chan agent.Event, done bool, cancel func())
- func (h *Hub) SubscribeAfter(id string, after int64) (replay []agent.Event, ch <-chan agent.Event, done bool, cancel func())
- func (h *Hub) SubscribeRetainedAfter(id string, after int64) (replay []agent.Event, ch <-chan agent.Event, done bool, cancel func())
- type Snapshot
- type Transcript
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
func (*Hub) Close ¶
Close marks the run finished, closes all live subscriber channels, and schedules the topic (and its buffer) to be freed after a grace window for late replay subscribers.
func (*Hub) Publish ¶
Publish appends an event to the run's buffer and fans it out to live subscribers.
func (*Hub) Snapshot ¶
Snapshot reads the components and cursor under the same lock as Publish. Looking up a completed/reaped run must not create a new, empty live topic.
func (*Hub) Subscribe ¶
func (h *Hub) Subscribe(id string) (replay []agent.Event, ch <-chan agent.Event, done bool, cancel func())
Subscribe atomically snapshots the replay buffer and (if the run is still live) registers a channel for subsequent events. `done` is true when the run already finished — the caller just sends the replay and stops. Always call cancel().
func (*Hub) SubscribeAfter ¶
func (h *Hub) SubscribeAfter(id string, after int64) (replay []agent.Event, ch <-chan agent.Event, done bool, cancel func())
SubscribeAfter atomically replays events newer than after and subscribes to live updates. Sequence numbers survive reconnects for the lifetime of the run topic.
func (*Hub) SubscribeRetainedAfter ¶
func (h *Hub) SubscribeRetainedAfter(id string, after int64) (replay []agent.Event, ch <-chan agent.Event, done bool, cancel func())
SubscribeRetainedAfter subscribes without creating a topic. Completed runs can outlive their replay buffer (or a daemon restart); they must not acquire an empty live channel that no producer will ever close.
type Snapshot ¶
type Snapshot struct {
Sequence int64 `json:"sequence"`
Parts []agent.Part `json:"parts"`
Result *agent.ResultInfo `json:"result,omitempty"`
Error string `json:"error,omitempty"`
StatusMessage string `json:"statusMessage,omitempty"`
}
Snapshot is a materialized turn at an event cursor. Reading it and then subscribing after Sequence restores a turn without replaying its animation or losing new events.
type Transcript ¶
type Transcript struct {
// contains filtered or unexported fields
}
Transcript is the shared event reducer for persistence and live snapshots, for every harness. Callers serialize access. Parts and tool values are copied before mutation so a previously returned snapshot remains stable while the next event is applied.
func (*Transcript) Apply ¶
func (t *Transcript) Apply(ev agent.Event)
func (*Transcript) Snapshot ¶
func (t *Transcript) Snapshot(final bool) Snapshot