GET /api/runs/{id} assembles a run's trail from rows already kept: the event
and trigger that started it, each workflow step, and each model and tool call
from the agent's journal. Investigations end by notifying their findings on
the composer, whose messages are read from a cursor with a live stream that
only says when to read. The binary serves its own SPA entry, archie.html,
calling only the new API. The investigate prompt now treats the event as a
claim to check against what it measures.
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
// Package hub fans notifications out to live subscribers, such as a
|
|
// dashboard's stream. A note carries only what changed, never work: a
|
|
// subscriber that falls behind is cut off and resyncs from its cursor, so
|
|
// nothing depends on a note arriving.
|
|
package hub
|
|
|
|
import "sync"
|
|
|
|
// buffer is how many notes a subscriber may fall behind before it is cut off.
|
|
const buffer = 32
|
|
|
|
// Note says something on a topic changed. Seq is the stream position a
|
|
// subscriber reads from to catch up.
|
|
type Note struct {
|
|
Topic string `json:"topic"`
|
|
Seq int64 `json:"seq"`
|
|
}
|
|
|
|
// Hub holds the live subscribers.
|
|
type Hub struct {
|
|
mu sync.Mutex
|
|
subs map[chan Note]string
|
|
}
|
|
|
|
// New returns an empty hub.
|
|
func New() *Hub { return &Hub{subs: map[chan Note]string{}} }
|
|
|
|
// Publish sends n to every subscriber of its topic. A subscriber whose buffer
|
|
// is full is closed rather than waited for.
|
|
func (h *Hub) Publish(n Note) {
|
|
h.mu.Lock()
|
|
defer h.mu.Unlock()
|
|
for ch, topic := range h.subs {
|
|
if topic != n.Topic {
|
|
continue
|
|
}
|
|
select {
|
|
case ch <- n:
|
|
default:
|
|
delete(h.subs, ch)
|
|
close(ch)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Subscribe returns a channel of notes on topic, closed if the subscriber
|
|
// falls behind, and a function that ends the subscription.
|
|
func (h *Hub) Subscribe(topic string) (<-chan Note, func()) {
|
|
ch := make(chan Note, buffer)
|
|
h.mu.Lock()
|
|
h.subs[ch] = topic
|
|
h.mu.Unlock()
|
|
return ch, func() {
|
|
h.mu.Lock()
|
|
defer h.mu.Unlock()
|
|
if _, ok := h.subs[ch]; ok {
|
|
delete(h.subs, ch)
|
|
close(ch)
|
|
}
|
|
}
|
|
}
|