pub mod agent;
pub mod client;
pub mod credentials;
pub mod dm_participants;
pub mod error;
pub mod events;
pub mod identity;
pub mod origin_actor;
pub mod registration;
pub mod relay;
pub mod types;
pub mod ws;
pub use agent::{AgentClient, DmOptions, EnsureChannelOutcome};
pub use client::{ClientOptions, HttpClient, RequestOptions};
pub use dm_participants::{
DmParticipantsCache, DmParticipantsCacheEntry, DM_PARTICIPANT_CACHE_TTL,
DM_PARTICIPANT_FAILURE_TTL,
};
pub use error::{RelayError, Result};
pub use events::{
normalize_command_invocation, normalize_inbound_event, normalize_sender_identity,
NormalizedCommandInvocation, NormalizedEventKind, NormalizedInboundEvent, RelayPriority,
SenderKind,
};
pub use identity::{agent_name_eq, is_self_name};
pub use origin_actor::{
sanitize_agent_relay_distinct_id, sanitize_origin_actor, AGENT_RELAY_DISTINCT_ID_HEADER,
AGENT_RELAY_DISTINCT_ID_QUERY, ORIGIN_ACTOR_HEADER,
};
pub use registration::{
format_registration_error, registration_is_retryable, registration_retry_after_secs,
retry_agent_registration, AgentRegistrationClient, AgentRegistrationError,
AgentRegistrationRetryOutcome,
};
pub use relay::{RelayCast, RelayCastOptions};
pub use ws::{
EventReceiver, LifecycleReceiver, RawEventReceiver, WsClient, WsClientOptions, WsLifecycleEvent,
};
pub use types::{
ActionCompletedEvent,
ActionDefinition,
ActionDeniedEvent,
ActionFailedEvent,
ActionInvocation,
ActionInvocationStatus,
ActionInvokedEvent,
Agent,
AgentChannelMembership,
AgentCommand,
AgentListQuery,
AgentPresenceInfo,
AgentStatusEvent,
Channel,
ChannelArchivedEvent,
ChannelCreatedEvent,
ChannelMemberInfo,
ChannelReadStatus,
ChannelUpdatedEvent,
ChannelWithMembers,
CommandInvocation,
CommandInvokedEvent,
CompleteInvocationRequest,
CompletedStatus,
CreateAgentRequest,
CreateAgentResponse,
CreateChannelRequest,
CreateCommandRequest,
CreateCommandResponse,
CreateGroupDmRequest,
CreateSubscriptionRequest,
CreateSubscriptionResponse,
CreateWebhookRequest,
CreateWebhookResponse,
CreateWorkspaceResponse,
DeferDeliveryRequest,
Delivery,
DeliveryAcceptedEvent,
DeliveryDeferredEvent,
DeliveryDeliveredEvent,
DeliveryFailedEvent,
DeliveryItem,
DeliveryMessage,
DeliveryStatus,
DmConversationSummary,
DmReceivedEvent,
DmSendResponse,
EmitSessionEventRequest,
EventSubscription,
FailDeliveryRequest,
FailedStatus,
FileInfo,
FileListOptions,
FileUploadedEvent,
GroupDmConversationResponse,
GroupDmMessageResponse,
GroupDmParticipantRef,
GroupDmParticipantResponse,
GroupDmReceivedEvent,
InboxResponse,
InvokeActionRequest,
InvokeActionResult,
InvokeCommandRequest,
ListDeliveriesOptions,
ListSessionEventsQuery,
MemberJoinedEvent,
MemberLeftEvent,
MessageBlock,
MessageCreatedEvent,
MessageInjectionMode,
MessageListQuery,
MessageReactedEvent,
MessageReadEvent,
MessageUpdatedEvent,
MessageWithMeta,
ObserverScope,
ObserverToken,
ObserverTokenFilters,
PostMessageRequest,
ReactionGroup,
ReaderInfo,
RegisterActionRequest,
ReleaseAgentRequest,
ReleaseAgentResponse,
SearchOptions,
SendDmRequest,
SessionEvent,
SetSystemPromptRequest,
SpawnAgentRequest,
SpawnAgentResponse,
SystemPrompt,
ThreadReplyEvent,
ThreadReplyRequest,
ThreadResponse,
TokenRotateResponse,
UpdateAgentRequest,
UpdateChannelRequest,
CreateObserverTokenRequest,
UpdateObserverTokenRequest,
UpdateWorkspaceRequest,
UploadRequest,
UploadResponse,
Webhook,
WebhookReceivedEvent,
WebhookTriggerRequest,
WebhookTriggerResponse,
Workspace,
WorkspaceDmConversation,
WorkspaceDmMessage,
WorkspaceStats,
WsEvent,
A2aAgentCard,
A2aAgentCardSkill,
A2aAgentRecord,
RegisterA2aOptions,
RegisterA2aResponse,
RemoveA2aAgentResponse,
DirectoryAgent,
DirectoryRating,
DirectorySearchResult,
DirectorySkill,
DirectorySkillInput,
ImportSkillsRequest,
ListDirectoryQuery,
PublishToDirectoryRequest,
RateDirectoryAgentRequest,
SearchDirectoryQuery,
UpdateDirectoryAgentRequest,
RouteFeedbackRequest,
RouteFeedbackResult,
RouteResult,
RoutingConfig,
RoutingWeights,
UpdateRoutingConfigRequest,
UpdateRoutingWeights,
SkillSearchQuery,
SkillSearchResult,
BindAgentToNodeRequest,
CreateNodeRequest,
CreateNodeResponse,
HttpPushNodeDelivery,
NodeAgentBinding,
NodeCapability,
NodeDeliveryAuth,
NodeDeliveryConfig,
NodeListQuery,
NodeRosterEntry,
CreateTriggerRequest,
Trigger,
UpdateTriggerRequest,
CertificationRun,
CertificationTestResult,
MonitorCertificationRequest,
SubmitCertificationRequest,
ConsoleAgentStat,
ConsoleAgentStatsQuery,
ConsoleCostAgent,
ConsoleCostStats,
ConsoleCostTotals,
ConsoleMessageLog,
ConsoleMessagesQuery,
ConsoleOverview,
ConsoleWindowQuery,
WorkspaceLookup,
};
pub const SDK_VERSION: &str = env!("CARGO_PKG_VERSION");
pub(crate) const DEFAULT_BASE_URL: &str = "https://cast.agentrelay.com";
fn ws_base_from_http(base: &str) -> String {
let trimmed = base.trim().trim_end_matches('/');
if let Some(rest) = trimmed.strip_prefix("https://") {
format!("wss://{rest}")
} else if let Some(rest) = trimmed.strip_prefix("http://") {
format!("ws://{rest}")
} else {
trimmed.to_string()
}
}
pub fn node_control_ws_url(base_url: Option<&str>) -> String {
let base = base_url
.map(str::trim)
.filter(|value| !value.is_empty())
.unwrap_or(DEFAULT_BASE_URL);
format!("{}/v1/node/ws", ws_base_from_http(base))
}
#[cfg(test)]
mod base_url_tests {
use super::*;
#[test]
fn node_control_ws_url_defaults_to_hosted_engine() {
assert_eq!(
node_control_ws_url(None),
"wss://cast.agentrelay.com/v1/node/ws"
);
assert_eq!(
node_control_ws_url(Some(" ")),
"wss://cast.agentrelay.com/v1/node/ws"
);
}
#[test]
fn node_control_ws_url_uses_override_and_rewrites_scheme() {
assert_eq!(
node_control_ws_url(Some("https://self.hosted.example/")),
"wss://self.hosted.example/v1/node/ws"
);
assert_eq!(
node_control_ws_url(Some("http://localhost:8787")),
"ws://localhost:8787/v1/node/ws"
);
}
}