A2aEngine.Transport.Http.Plug (a2a_engine v0.1.0)

Copy Markdown View Source

Plug that receives A2A JSON-RPC requests over HTTP.

Mount in your router:

forward "/a2a", A2aEngine.Transport.Http.Plug,
  handler: MyApp.A2A.Handler,
  auth: A2aEngine.Auth.Bearer,
  auth_opts: [tokens: %{"secret" => "my-agent"}]

Behaviour

  • POST / — unary JSON-RPC. Returns 200 with JSON-RPC response envelope, or 401 / 400 on auth / decode failure.
  • POST / with Accept: text/event-stream AND a method in the streaming set (message/stream, tasks/resubscribe) — responds with SSE chunks. Each event frame follows A2aEngine.Codec.SSE.
  • Any other path or method → 404.

Host must have already parsed the JSON body (e.g. via Plug.Parsers mounted upstream). The plug reads conn.body_params.

Options

  • :handler — required. Module implementing A2aEngine.Handler.
  • :auth — required. Module implementing A2aEngine.Auth.
  • :auth_opts — keyword list passed to the auth module.

Summary

Functions

Whether a method is one of the A2A streaming methods that this plug will respond to with an SSE stream (provided the client sends Accept: text/event-stream).

Functions

streaming?(method)

@spec streaming?(String.t()) :: boolean()

Whether a method is one of the A2A streaming methods that this plug will respond to with an SSE stream (provided the client sends Accept: text/event-stream).