Class AgentHttpService

java.lang.Object
ai.singlr.runtime.AgentHttpService
All Implemented Interfaces:
io.helidon.webserver.http.HttpService, io.helidon.webserver.ServerLifecycle

public final class AgentHttpService extends Object implements io.helidon.webserver.http.HttpService
Helidon HttpService that exposes one SessionRegistry's sessions over HTTP. The five Phase 1 routes mirror the spec §15.1 sketch and are mounted by the caller under whatever prefix fits the deployment (routing.register("/v1", new AgentHttpService(...))).
  • POST /sessions — create a fresh session; returns {sessionId, eventsUrl} with 201 Created.
  • POST /sessions/{sessionId}/messages — body {text: "..."}; queues the message and returns 202 Accepted.
  • POST /sessions/{sessionId}/interrupt — body {reason: "..."}; queues a synthetic interrupt message and returns 202 Accepted.
  • GET /sessions/{sessionId}/events — opens an SSE stream of QueryEvents. The handler blocks the request thread until the publisher signals onComplete or the client disconnects.
  • GET /sessions/{sessionId}/result?timeout=<seconds> — long-poll for the terminal ResultMessage. Returns 200 OK with body {type: "<SubtypeName>", result: <record-fields>} when terminal; 204 No Content when the timeout elapses with no terminal. timeout defaults to 60 s and is clamped to [0, 300] so a single request cannot pin a server thread longer than five minutes.
  • DELETE /sessions/{sessionId} — closes and unregisters the session; returns 204 No Content.

The optionsFactory is the seam through which deployments choose how a new session is configured: the runtime takes the generated session id and produces a fully-populated SessionOptions. For Phase 1 the typical impl returns the same Model for every session.

Thread-safety

Thread-safe. Each request runs on its own virtual thread; SessionRegistry synchronises shared session state.
  • Constructor Details

    • AgentHttpService

      public AgentHttpService(SessionRegistry registry, Function<String, ai.singlr.session.SessionOptions> optionsFactory, tools.jackson.databind.ObjectMapper objectMapper, String eventsPathPrefix)
      Build a service.
      Parameters:
      registry - registry of live sessions; non-null
      optionsFactory - function that maps a generated session id to a fully-configured SessionOptions; non-null
      objectMapper - mapper for request/response bodies; non-null
      eventsPathPrefix - prefix used to build the eventsUrl returned by POST /sessions (e.g. "/v1"); non-null
      Throws:
      NullPointerException - if any argument is null
  • Method Details

    • routing

      public void routing(io.helidon.webserver.http.HttpRules rules)
      Specified by:
      routing in interface io.helidon.webserver.http.HttpService