Skip to main content

soma_provider_core/
provider.rs

1use async_trait::async_trait;
2use serde_json::Value;
3
4use crate::{ProviderCall, ProviderCatalog, ProviderError, ProviderOutput};
5
6#[async_trait]
7pub trait Provider: Send + Sync {
8    fn catalog(&self) -> ProviderCatalog;
9
10    async fn call(&self, call: ProviderCall) -> Result<ProviderOutput, ProviderError>;
11
12    /// Stop accepting new work and release provider-owned runtime resources.
13    ///
14    /// Stateless providers use the default no-op. Registries call this after
15    /// an atomic generation swap, outside registry locks.
16    async fn retire(&self) {}
17
18    /// Parks runtime resources while keeping a retained generation callable.
19    async fn suspend(&self) {}
20
21    /// Returns product-neutral operator status for a stateful runtime.
22    fn runtime_status(&self) -> Option<Value> {
23        None
24    }
25
26    /// Cancels active runtime work without waiting for the provider call lock.
27    fn cancel_active(&self) -> bool {
28        false
29    }
30
31    /// Clears runtime quarantine after explicit operator authorization.
32    async fn reset_quarantine(&self) {}
33
34    /// Stops new work on a retained generation while in-flight work drains.
35    fn deactivate(&self) {}
36
37    /// Re-enables a retained generation selected by operator rollback.
38    fn activate(&self) {}
39
40    /// Acquires a dispatch lease while the provider is still active.
41    ///
42    /// Registries call this while holding their generation read lock so an
43    /// already-routed invocation can drain safely across an atomic swap.
44    fn acquire_dispatch(&self) -> bool {
45        true
46    }
47
48    /// Releases a dispatch lease acquired by [`Provider::acquire_dispatch`].
49    fn release_dispatch(&self) {}
50}