Skip to main content

multicast_workflows/
host.rs

1//! Platform boundary for workflow execution, databases, timers, and fixtures.
2
3use crate::WorkflowDatabase;
4use async_trait::async_trait;
5use multicast::tool::ToolCatalog;
6use multicast_codemode::{CodeModeService, Connector, RetryPolicy};
7use std::sync::Arc;
8
9/// Isolated workflow databases supplied by a host.
10#[derive(Clone, Copy)]
11pub enum WorkflowDatabaseKind {
12    /// Run history, counters, trace links, and failure groups.
13    Ledger,
14    /// Event deduplication, schedule progress, and bound execution identifiers.
15    Triggers,
16    /// Saved agent archetypes: summaries, instructions, and scopes.
17    Archetypes,
18}
19
20/// Host capabilities required by the shared workflow commands.
21///
22/// Hosts own a tenant's execution and database lifetime. The catalog supplied to
23/// `service` excludes lifecycle commands; callable workflow composition uses the shared runtime.
24#[async_trait]
25pub trait WorkflowHost: Send + Sync {
26    /// Opens the execution service with isolated host-call options and this retry policy.
27    fn service(
28        &self,
29        catalog: ToolCatalog,
30        retry: RetryPolicy,
31    ) -> Result<Arc<dyn CodeModeService>, String>;
32    /// Opens a service with host-owned composition budgets; older adapters reject custom limits.
33    fn service_with_limits(
34        &self,
35        catalog: ToolCatalog,
36        retry: RetryPolicy,
37        limits: multicast_codemode::WorkflowLimits,
38    ) -> Result<Arc<dyn CodeModeService>, String> {
39        if limits != multicast_codemode::WorkflowLimits::default() {
40            return Err(
41                "WORKFLOW_LIMITS_UNSUPPORTED: adapter must implement service_with_limits".into(),
42            );
43        }
44        self.service(catalog, retry)
45    }
46    /// Supplies durable SQL storage for the selected workflow subsystem.
47    fn database(&self, kind: WorkflowDatabaseKind) -> Result<Arc<dyn WorkflowDatabase>, String>;
48    /// Creates an isolated executor that can invoke only these fixture connectors.
49    fn fixture_service(
50        &self,
51        connectors: Vec<Arc<dyn Connector>>,
52    ) -> Result<Arc<dyn CodeModeService>, String>;
53    /// Persists a wakeup no later than this Unix millisecond timestamp.
54    /// Hosts that poll independently may keep the default implementation.
55    async fn wake_at(&self, _timestamp: u64) -> Result<(), String> {
56        Ok(())
57    }
58    /// Waits without using a process runtime timer.
59    async fn sleep(&self, milliseconds: u64);
60    /// Loads a fixture. Hosts without files accept the fixture JSON directly.
61    fn read_fixture(&self, source: &str) -> Result<Vec<u8>, String> {
62        if source.len() > crate::MAX_FIXTURE_BYTES {
63            return Err("Fixture exceeds the 16 MiB limit".into());
64        }
65        Ok(source.as_bytes().to_vec())
66    }
67}