anyclaw-sdk-service 0.2.0

SDK for building anyclaw service extensions
Documentation
use crate::error::ServiceSdkError;
use crate::types::{ServiceHealthStatus, ServiceInitializeParams, ServiceInitializeResult};

/// Trait for building service extensions.
///
/// Implement this trait to create a service binary that the supervisor manages
/// via JSON-RPC over stdio. The [`ServiceHarness`](crate::ServiceHarness)
/// handles all framing — implementors only need to provide the business logic.
pub trait Service: Send + 'static {
    /// Called when the supervisor sends the `initialize` request.
    ///
    /// The service should bind to a port (using `params.port` as a hint if
    /// provided) and return the actual port and any installation metadata.
    fn on_initialize(
        &mut self,
        params: ServiceInitializeParams,
    ) -> impl std::future::Future<Output = Result<ServiceInitializeResult, ServiceSdkError>> + Send;

    /// Called when the supervisor sends a `health` request.
    ///
    /// Return the current health status of the service.
    fn on_health(&self) -> impl std::future::Future<Output = ServiceHealthStatus> + Send;

    /// Called when the supervisor sends the `shutdown` request.
    ///
    /// The service should perform graceful cleanup (drain connections, flush
    /// state) and return. The harness exits after this method returns.
    fn on_shutdown(
        &mut self,
    ) -> impl std::future::Future<Output = Result<(), ServiceSdkError>> + Send;
}