palyrad provides the primary web-based interface for management, agent interaction, and system diagnostics. Built on the Axum framework, it organizes functionality into distinct route groups catering to different consumers: the React-based Web Console, administrative CLI tools, and OpenAI-compatible API clients.
AppState and Router Construction
The HTTP server is initialized by building anAppState which acts as the shared context for all request handlers. This state holds references to core subsystems like the GatewayRuntimeState, JournalStore, and IdentityManager crates/palyra-daemon/src/app/runtime.rs#42-83.
The router is constructed in build_router, which partitions the API into four major namespaces crates/palyra-daemon/src/transport/http/router.rs#17-150:
| Route Group | Base Path | Purpose |
|---|---|---|
| Admin API | /admin/v1/ | Low-level system management, channel debugging, and skill quarantine. |
| Console API | /console/v1/ | Backs the Web UI; handles sessions, chat, and resource management. |
| Canvas API | /canvas/v1/ | Specialized endpoints for A2UI (Agent-to-User Interface) interactive components. |
| Compat API | /v1/ | OpenAI-compatible surface for chat completions and model listing. |
System Flow: Request to Handler
The following diagram illustrates how an inbound HTTP request is routed through middleware to the specific domain logic. HTTP Request Dispatch Flow Sources: crates/palyra-daemon/src/transport/http/router.rs#17-150, crates/palyra-daemon/src/app/runtime.rs#42-83Route Groups and Handlers
Admin API (/admin/v1/)
The Admin API is used primarily for system-level introspection and recovery. Key handlers include:
- Journal/Status:
admin_status_handlerandadmin_journal_recent_handlerprovide visibility into theJournalStorecrates/palyra-daemon/src/transport/http/router.rs#19-20. - Channel Management: Comprehensive endpoints for Discord/Slack connector lifecycle, including
admin_channel_health_refresh_handlerandadmin_channel_dead_letter_replay_handlercrates/palyra-daemon/src/transport/http/router.rs#43-60. - Skill Control: Allows administrators to manually
quarantineorenableskills crates/palyra-daemon/src/transport/http/router.rs#119-125.
Console API (/console/v1/)
This group supports the apps/web frontend. It is heavily focused on session-based operations:
- Auth & Access: Handles
console_access_snapshot_handlerand API token rotation crates/palyra-daemon/src/transport/http/router.rs#135-163. - Agent Management:
console_agents_list_handlerandconsole_agent_create_handlerinteract with theAgentRecordlogic crates/palyra-daemon/src/transport/http/handlers/console/agents.rs#44-91. - Diagnostics: The
console_diagnostics_handleraggregates health data from the browser service, plugins, and memory maintenance tasks crates/palyra-daemon/src/transport/http/handlers/console/diagnostics.rs#6-70.
OpenAI Compatibility Layer (/v1/)
Palyra implements a subset of the OpenAI API to allow existing tools to connect seamlessly.
- Chat Completions:
compat_chat_completions_handlermaps OpenAI-styleCompatChatCompletionsRequestto internalRunStreamRequestobjects crates/palyra-daemon/src/transport/http/handlers/compat.rs#128-175. - Models:
compat_models_handlerreturns a list of available model profiles configured in the daemon crates/palyra-daemon/src/transport/http/handlers/compat.rs#105-126.
Middleware and Security
The transport layer enforces several security and resource constraints via Axum middleware:- Rate Limiting: Separate buckets are maintained in
AppStatefor Admin, Canvas, and Compat APIs. Limits are enforced per IP address or per API token crates/palyra-daemon/src/app/runtime.rs#62-66. - CSRF & Session Cookies: The Console API uses
authorize_console_sessionto validate session cookies and CSRF tokens for state-changing (POST/PUT) requests crates/palyra-daemon/src/transport/http/handlers/console/diagnostics.rs#10-11. - Security Headers: The
admin_console_security_headers_middlewareinjectsContent-Security-Policy,X-Frame-Options, andStrict-Transport-Securityto protect the Web UI crates/palyra-daemon/src/transport/http/router.rs#131-133. - Body Limits: A global
HTTP_MAX_REQUEST_BODY_BYTESis enforced to prevent DoS via large payloads crates/palyra-daemon/src/transport/http/router.rs#126.
Web UI Serving
The daemon includes a built-in handler for serving the React dashboard (apps/web). The web_ui_entry_handler resolves assets from the local filesystem or an environment-specified directory crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#16-34.
- Asset Resolution: It searches for a
web/ordist/folder relative to thepalyradexecutable crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#125-148. - Fallback SPA Routing: If a requested path does not exist as a file, the handler serves
index.htmlto support client-side React routing crates/palyra-daemon/src/transport/http/handlers/web_ui.rs#187-192.
Control Plane Client
Thepalyra-control-plane crate provides a Rust-native ControlPlaneClient used by the CLI and desktop app to interact with the HTTP API. It manages:
- CSRF Lifecycle: Automatically extracts and includes CSRF tokens from the
console/v1/auth/sessionendpoint crates/palyra-control-plane/src/client.rs#67-73. - Retry Logic: Implements
safe_read_retriesfor GET requests crates/palyra-control-plane/src/client.rs#12. - Typed Models: Uses shared structs from
models.rs(e.g.,AgentRecord,SecretMetadata) to ensure protocol parity between the daemon and its clients crates/palyra-control-plane/src/models.rs#177-190.