Overview
The RPC unions module provides sealed union types that enable exhaustive, type-safe handling of ACP requests, responses, and notifications. These unions ensure you handle all message types correctly and support both standard protocol methods and custom extensions.Key Benefits
Type Safety
Each message type is strongly typed with full IDE support and compile-time checking
Exhaustive Handling
Pattern matching ensures all message types are handled without gaps
Forward Compatibility
Unknown methods are captured as extension types for graceful handling
Method Discovery
Automatic routing from JSON-RPC method names to typed objects
Union Types
Agent Unions
Types used by agents when sending or handling messages:Notifications sent by agents to clients
Requests initiated by agents (handled by clients)
Responses produced by agents for client requests
Client Unions
Types used by clients when sending or handling messages:Requests initiated by clients (handled by agents)
Responses produced by clients for agent requests
Notifications sent by clients to agents
Usage Examples
Handling Agent Requests
Handling Client Requests
Creating Union Instances
Pattern Matching with Notifications
Method Routing
Each union provides afromMethod factory that automatically routes JSON-RPC methods to the correct union variant:
Type Safety Benefits
Using RPC unions ensures compile-time safety:
- No missing cases: The compiler warns if you don’t handle all variants
- No typos: Method names are checked at compile time
- IDE support: Full autocomplete and type hints
- Refactoring: Easy to update when the protocol changes
Related Documentation
Requests
All request types
Responses
All response types
Notifications
All notification types