Skip to content

feat(agent): WebSocket + JSON-RPC API gateway (Wave 5, Track C)#1385

Merged
jsmestad merged 2 commits intomainfrom
wave5/api-gateway
Apr 1, 2026
Merged

feat(agent): WebSocket + JSON-RPC API gateway (Wave 5, Track C)#1385
jsmestad merged 2 commits intomainfrom
wave5/api-gateway

Conversation

@breznknecht
Copy link
Copy Markdown
Collaborator

What

WebSocket + JSON-RPC gateway exposing MingaAgent.Runtime to external clients. Uses Bandit + WebSock (~5 new deps, all pure Elixir). No Phoenix.

Plan reference

docs/PLAN-runtime-first.md Wave 5 Track C (PRs C-5.1, C-5.2, C-5.3).

New modules

Module Purpose
MingaAgent.Runtime Public facade: session lifecycle, tool ops, introspection
MingaAgent.Introspection Runtime self-description for external clients
MingaAgent.Gateway.Server GenServer owning the Bandit HTTP/WS listener
MingaAgent.Gateway.Router Plug router: /ws upgrade, /health probe
MingaAgent.Gateway.WebSocket WebSock handler dispatching JSON-RPC
MingaAgent.Gateway.JsonRpc Pure dispatch: decode request, call Runtime, encode response
MingaAgent.Gateway.EventStream Domain event subscription + JSON-RPC notification formatting

Key design decisions

  • Bandit, not Phoenix. One WebSocket endpoint doesn't need a framework. ~5 deps vs 15+.
  • Gateway is opt-in. Never starts in editor mode. Started via MingaAgent.Runtime.start_gateway/1 or Minga.Runtime.start(gateway: true).
  • JsonRpc is a pure function module. No state, no GenServer. Easy to test in isolation.
  • Domain events only. API clients get semantic events (agent_session_stopped, log_message), not rendered state or chrome opcodes.
  • macOS GUI keeps its Port protocol. The Port is binary, zero-overhead, frame-paced. WebSocket is for external tools, not the co-located renderer.

Testing

34 new tests:

  • JsonRpc pure dispatch tests (method routing, error codes, notifications)
  • EventStream formatting tests (per-topic encoding, skip unknown topics)
  • Introspection tests (capabilities, tool/session descriptions)
  • Runtime facade delegation tests
  • WebSocket integration test (raw TCP upgrade, masked frames, JSON-RPC round-trip)

Verification

make lint          # passes
mix test.llm       # 7362+ tests, 0 failures

No Layer 1 to Layer 2 boundary violations in any new code.

Brezn added 2 commits April 1, 2026 11:06
Add Bandit + WebSock deps and build the API gateway that exposes
MingaAgent.Runtime to external clients via WebSocket + JSON-RPC 2.0.

New modules:
- MingaAgent.Runtime: public facade unifying SessionManager, Tool.Registry,
  Tool.Executor, and Introspection into one entry point
- MingaAgent.Introspection: runtime self-description (capabilities, tool
  descriptions, session descriptions) for external client discovery
- MingaAgent.Gateway.Server: GenServer owning the Bandit HTTP/WS listener
- MingaAgent.Gateway.Router: Plug router (/ws upgrade, /health probe)
- MingaAgent.Gateway.WebSocket: WebSock handler dispatching JSON-RPC
- MingaAgent.Gateway.JsonRpc: pure dispatch (decode, call Runtime, encode)
- MingaAgent.Gateway.EventStream: domain event subscription + JSON-RPC
  notification formatting for push delivery

Gateway starts on-demand via MingaAgent.Runtime.start_gateway/1 or
Minga.Runtime.start(gateway: true). Never starts in editor mode.
Default port 4820, configurable. All dispatch routes through Runtime
facade. Domain events (not rendered state) are pushed to clients.

Covers plan items C-5.1 (deps), C-5.2 (gateway modules), C-5.3 (wiring).
34 new tests including WebSocket integration test.
@jsmestad jsmestad merged commit 05e90e8 into main Apr 1, 2026
7 checks passed
@jsmestad jsmestad deleted the wave5/api-gateway branch April 1, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants