Skip to main content

Module server

Module server 

Source
Expand description

The axum WebSocket server: one /ws endpoint, one task per connection.

Per connection we split the socket and run two tasks joined by an UnboundedSender<serde_json::Value> outbound sink:

  • a writer that drains the sink and writes each event as a JSON text frame, and
  • a reader that reads inbound frames and dispatches them via crate::handler::handle_frame, passing the sink so handlers (including the streaming send_message) can emit events as they happen.

Using a sink channel (instead of writing directly from the handler) is what lets a streaming turn fire many stream_token events from inside the agent loop while the connection is still reading.

Constants§

SEED_ORG_ID
The org the seeded demo docs + their document-set registry entries belong to. Mirrors the org handler::handle_create_session stamps onto reference conversations, so the seeded sets show up for the reference org’s admin caller (and ONLY that org — cross-org scoping).

Functions§

bind
Bind on <SMOOTH_AGENT_BIND>:<port> (default loopback) and serve until the process is killed. Returns the bound TcpListener + the router, used by both the binary and tests (tests bind port 0 for an ephemeral port).
build_state
Build an AppState over a fresh in-memory adapter, seeding the knowledge base when config.seed_kb is set. Exposed for tests + the binary.
build_state_from_env
Build an AppState with the env-configured auth verifier (secure by default — see smooth_operator::auth::AuthConfig). Used by the binary.
build_state_from_env_async
Build an AppState selecting the storage backend (and the matching durable admin stores) from config.storage, then installing the env-configured auth verifier.
router
Build the axum Router for the given application state. Exposed so tests can boot the server in-process. Serves the WebSocket /ws endpoint plus the auth-gated admin HTTP API under /admin (see crate::admin).
run
Run the server to completion (blocks). Logs a single listening line.
seed_knowledge
Seed a couple of distinctive demo docs so knowledge-grounded E2E is deterministic. The 17-day return window is deliberately unusual so an ungrounded answer can’t accidentally match it. Both docs are tagged into the policies document set so the admin API can report it.
serve_state
Serve a pre-built AppState to completion (blocks), binding on state.config.bind:state.config.port.
serve_state_on
Serve a pre-built AppState on an already-bound TcpListener (blocks).