ChannelRouter.
Architecture Overview
The framework is divided into three primary layers:- Connector Supervisor: Manages the lifecycle, state, and retries for connector instances.
- Channel Router: Handles message ingestion, pairing logic, concurrency limits, and backpressure.
- Connector Adapters: Implementation-specific logic for external platforms (e.g., Discord, Echo).
System Data Flow
The following diagram illustrates the flow of an inbound message from a platform through the framework into the Palyra core. Diagram: Inbound Message Routing Sources: crates/palyra-daemon/src/channels.rs#112-140, crates/palyra-daemon/src/channel_router.rs#215-226Connector Supervisor & Storage
TheConnectorSupervisor is the central authority for managing ConnectorInstanceRecord entries. It uses a SQLite-backed ConnectorStore to persist the state of all configured connectors, including their readiness and liveness status.
Key Components
ConnectorSupervisor: Orchestrates the starting, stopping, and health monitoring of adapters crates/palyra-connectors/src/lib.rs#7-12.ConnectorStore: Manages theconnectors.dbSQLite database, storing instance configurations and theoutbox_entriestable for reliable message delivery crates/palyra-connectors/src/lib.rs#7-12.ConnectorAdapter: A trait that must be implemented by specific platforms. It defines how tosend_outboundmessages and reports the connector’skindandavailabilitycrates/palyra-connectors/src/connectors/echo.rs#34-76.
Connector Lifecycle States
| State | Description |
|---|---|
Liveness::Running | The connector’s background worker is active. |
Liveness::Stopped | The connector has been manually disabled or failed to start. |
Readiness::Ready | The connector has successfully authenticated with the platform. |
Readiness::Degraded | The connector is operational but experiencing partial failures (e.g., rate limits). |
Channel Router
TheChannelRouter in palyra-daemon acts as the traffic controller between the connectors and the Palyra gateway. It implements security policies, concurrency management, and the “pairing” mechanism for Direct Messages (DMs).
Concurrency & Backpressure
The router enforces aconcurrency_limit per channel crates/palyra-daemon/src/channel_router.rs#174-174. If a channel exceeds its limit, messages are queued or rejected based on the max_retry_queue_depth_per_channel configuration crates/palyra-daemon/src/channel_router.rs#181-181.
Pairing & Security
For platforms like Discord, the router supports aDirectMessagePolicy crates/palyra-daemon/src/channel_router.rs#57-61:
- Deny: No DMs allowed.
- Allow: All DMs processed.
- Pairing: Requires a user to provide a
PairingCodeRecordvia DM before the agent will respond crates/palyra-daemon/src/channel_router.rs#85-91.
Implementation: Echo & Test Connector
TheEchoConnectorAdapter is a reference implementation used for internal testing and CI. It demonstrates idempotency handling and failure simulation.
Features
- Idempotency: Uses
delivered_native_idsto ensure the sameenvelope_idisn’t processed twice crates/palyra-connectors/src/connectors/echo.rs#22-22. - Crash Simulation: If a message contains the string
[connector-crash-once], the adapter simulates aRetryClass::ConnectorRestartingfailure exactly once for that message crates/palyra-connectors/src/connectors/echo.rs#48-61. - Fallback IDs: Generates stable native IDs using a SHA-256 fingerprint of the message payload crates/palyra-connectors/src/connectors/echo.rs#78-91.
Configuration & Setup
Connectors are initialized within theChannelPlatform struct in the daemon.
CLI Integration
The Palyra CLI provides commands for managing these connections, specifically for the Discord onboarding flow, which uses thechannels/discord/onboarding endpoints to validate tokens and apply routing rules crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#33-46.
Sources: crates/palyra-daemon/src/channels.rs#113-132, crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#73-95