koel_http library
HTTP/SSE transport for AG-UI agents — HttpAgent, SseParser, interceptors.
Classes
- AuthInterceptor
- Authenticates every run by composing an interceptor instead of configuring the agent (FR-B2). Takes an async header-builder — a closure that can mint a Bearer token, read a keychain, or refresh on demand — resolves it per run (or per retry attempt, see below), and threads the resolved headers onto the outgoing POST.
- EventTraceInterceptor
-
Captures a structured TraceEntry for every event flowing through a run and
writes it to a consumer-supplied
Sink<TraceEntry>(Story 4.6 / FR-B2). - HttpAgent
-
AbstractAgentover an AG-UI SSE endpoint — the first koel transport that talks to a network (FR-B1, AR-7). - LoggingInterceptor
-
Writes human-readable run logs to
package:loggingat the architecture-§4 per-category levels, gated by a single emissionlevelthreshold (Story 4.6 / FR-B2/B3). The human-readable complement toEventTraceInterceptor's structuredTraceEntrycapture; compose whichever (or both) intoHttpAgent(interceptors: …). - PIIRedactionInterceptor
-
Scrubs consumer-supplied
patternsout of the free-text content anAgUiEventcarries, replacing every match with[REDACTED]before the event reaches subscribers or the reducer (Story 4.7 / FR-I2). Default-OFF — it does nothing unless a consumer adds it toHttpAgent(interceptors: …). - RetryInterceptor
-
Re-runs a failed run with exponential backoff + jitter, emitting a
ConnectionResumedmarker on a recovered reconnect and a terminalTransportError(transportClosed)on exhaustion (FR-B4 / NFR-7). - RetryPolicy
-
Declarative retry/backoff configuration for an
HttpAgentreconnection — the convenience entry point to theRetryInterceptorengine (Story 4.4). - SentryBreadcrumbInterceptor
-
Adds one Sentry breadcrumb per
AgUiEventflowing through a run, so a consumer's later-captured Sentry errors carry the AG-UI run trail that led to them (Story 4.7 / FR-I2). Default-OFF — it is never inHttpAgent's default chain and emits nothing unless a consumer (a) adds it toHttpAgent(interceptors: …)and (b) has calledSentry.initin their app. Even then, breadcrumbs only leave the device when an actual Sentry event is captured: this interceptor generates no standalone network traffic, so "no silent telemetry" holds. - SseParser
-
The wire→domain boundary of
koel_http: a hand-rolled, dependency-free SSE parser that turns a raw byte stream into a typedAgUiEventstream (AR-8). - TraceEntry
-
A single structured observation of a run, written to a consumer's
Sink<TraceEntry>by theEventTraceInterceptor(Story 4.6 / FR-B2).
Enums
- TracePhase
- Where in a run's lifecycle a TraceEntry was captured.
Extensions
- TraceEntryPatterns on TraceEntry
- Adds pattern-matching-related methods to TraceEntry.
Functions
-
retryBackoff(
int attempt, {required Duration baseDelay, required Duration maxDelay, required double jitter, required Random random}) → Duration -
The pure, deterministic backoff schedule:
min(maxDelay, baseDelay·2^(n-1))scaled by a symmetric jitter factor in[1−jitter, 1+jitter).attemptis 1-based;randomis injected so a seededRandommakes tests deterministic. -
transportErrorClassifier(
) → ErrorClassifier -
The koel_http transport
ErrorClassifier, resolved per platform at compile time — the seamHttpAgent.runbuilds itsInterceptorChainover.