Documentation
¶
Overview ¶
Package web provides the HTTP server and SSE event streaming for the Arena web UI.
Package web provides the HTTP server and SSE event streaming for the Arena web UI.
Index ¶
- func LoadResultsIntoStore(outDir string, store *statestore.ArenaStateStore) int
- type EventAdapter
- func (a *EventAdapter) AttachAudioRouter(runID string, router *arenaaudio.AudioRouter, rate int)
- func (a *EventAdapter) HandleEvent(event *events.Event)
- func (a *EventAdapter) Register() chan []byte
- func (a *EventAdapter) RegisterAudio(ch chan []byte)
- func (a *EventAdapter) Subscribe(bus events.Bus)
- func (a *EventAdapter) Unregister(ch chan []byte)
- func (a *EventAdapter) UnregisterAudio(ch chan []byte)
- type RunRequest
- type SSEEvent
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadResultsIntoStore ¶ added in v1.3.25
func LoadResultsIntoStore(outDir string, store *statestore.ArenaStateStore) int
LoadResultsIntoStore scans outDir for run-result JSON files and loads each into the in-memory state store. Previously this delegated to JSONResultRepository.LoadResults, which reads run_ids out of index.json — and index.json is rewritten by each CLI invocation, so on server boot only the most recent batch's IDs were hydrated even though every prior <runID>.json sat right there on disk.
Scanning the directory directly means web-triggered runs (which never touch index.json) and old CLI runs both flow into Previous Runs on initial page load.
Types ¶
type EventAdapter ¶
type EventAdapter struct {
// contains filtered or unexported fields
}
EventAdapter subscribes to an events.Bus and fans out JSON-serialized events to registered SSE client channels.
func NewEventAdapter ¶
func NewEventAdapter() *EventAdapter
NewEventAdapter creates a new EventAdapter.
func (*EventAdapter) AttachAudioRouter ¶ added in v1.4.7
func (a *EventAdapter) AttachAudioRouter(runID string, router *arenaaudio.AudioRouter, rate int)
AttachAudioRouter subscribes the adapter to a per-run AudioRouter. Frames are encoded as SSE "audio" events for clients that opted in via ?audio=1. The subscription lives until the router closes.
func (*EventAdapter) HandleEvent ¶
func (a *EventAdapter) HandleEvent(event *events.Event)
HandleEvent converts a runtime event to JSON and broadcasts to all clients.
func (*EventAdapter) Register ¶
func (a *EventAdapter) Register() chan []byte
Register adds a new SSE client and returns its event channel.
func (*EventAdapter) RegisterAudio ¶ added in v1.4.7
func (a *EventAdapter) RegisterAudio(ch chan []byte)
RegisterAudio adds a client channel that receives audio SSE messages. Audio clients are distinct from regular event clients — only clients that explicitly opted in (via ?audio=1) receive audio frames. The same channel may also be registered via Register; the browser EventSource demuxes regular vs audio events by their `event:` line.
func (*EventAdapter) Subscribe ¶
func (a *EventAdapter) Subscribe(bus events.Bus)
Subscribe subscribes the adapter to an event bus.
func (*EventAdapter) Unregister ¶
func (a *EventAdapter) Unregister(ch chan []byte)
Unregister removes an SSE client. The caller is responsible for draining or discarding the channel after unregistering.
func (*EventAdapter) UnregisterAudio ¶ added in v1.4.7
func (a *EventAdapter) UnregisterAudio(ch chan []byte)
UnregisterAudio removes an audio client channel.
type RunRequest ¶
type RunRequest struct {
Providers []string `json:"providers,omitempty"`
Scenarios []string `json:"scenarios,omitempty"`
Regions []string `json:"regions,omitempty"`
}
RunRequest is the JSON body for POST /api/run.
type SSEEvent ¶
type SSEEvent struct {
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
ExecutionID string `json:"executionId,omitempty"`
ConversationID string `json:"conversationId,omitempty"`
Data interface{} `json:"data,omitempty"`
}
SSEEvent is the JSON structure sent to SSE clients.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the Arena web UI HTTP server.
func NewServer ¶
func NewServer(adapter *EventAdapter, eng *engine.Engine, store *statestore.ArenaStateStore, outputDir string) *Server
NewServer creates a new web server. eng and store may be nil (for testing SSE in isolation). outputDir is the path to the results directory (for DELETE /api/results).
When both eng and adapter are non-nil, the server registers an audio monitor hook on the engine so per-run AudioRouters automatically attach to the SSE relay. Audio monitoring still requires explicit opt-in via engine.EnableAudioMonitor — without it, the hook never fires.
func (*Server) WaitBackgroundRuns ¶ added in v1.4.10
func (s *Server) WaitBackgroundRuns()
WaitBackgroundRuns blocks until all goroutines spawned by handleStartRun have finished, including the post-ExecuteRuns persistRunResults fallback. Tests that exercise the run path call this before t.TempDir cleanup so the background goroutine doesn't race with RemoveAll.