multicast-workflows 2.0.0

Durable Code Mode workflows attached to multicast CLIs as first-party commands
Documentation
//! Platform boundary for workflow execution, databases, timers, and fixtures.

use crate::WorkflowDatabase;
use async_trait::async_trait;
use multicast::tool::ToolCatalog;
use multicast_codemode::{CodeModeService, Connector, RetryPolicy};
use std::sync::Arc;

/// Isolated workflow databases supplied by a host.
#[derive(Clone, Copy)]
pub enum WorkflowDatabaseKind {
    /// Run history, counters, trace links, and failure groups.
    Ledger,
    /// Event deduplication, schedule progress, and bound execution identifiers.
    Triggers,
    /// Saved agent archetypes: summaries, instructions, and scopes.
    Archetypes,
}

/// Host capabilities required by the shared workflow commands.
///
/// Hosts own a tenant's execution and database lifetime. The catalog supplied to
/// `service` excludes lifecycle commands; callable workflow composition uses the shared runtime.
#[async_trait]
pub trait WorkflowHost: Send + Sync {
    /// Opens the execution service with isolated host-call options and this retry policy.
    fn service(
        &self,
        catalog: ToolCatalog,
        retry: RetryPolicy,
    ) -> Result<Arc<dyn CodeModeService>, String>;
    /// Opens a service with host-owned composition budgets; older adapters reject custom limits.
    fn service_with_limits(
        &self,
        catalog: ToolCatalog,
        retry: RetryPolicy,
        limits: multicast_codemode::WorkflowLimits,
    ) -> Result<Arc<dyn CodeModeService>, String> {
        if limits != multicast_codemode::WorkflowLimits::default() {
            return Err(
                "WORKFLOW_LIMITS_UNSUPPORTED: adapter must implement service_with_limits".into(),
            );
        }
        self.service(catalog, retry)
    }
    /// Supplies durable SQL storage for the selected workflow subsystem.
    fn database(&self, kind: WorkflowDatabaseKind) -> Result<Arc<dyn WorkflowDatabase>, String>;
    /// Creates an isolated executor that can invoke only these fixture connectors.
    fn fixture_service(
        &self,
        connectors: Vec<Arc<dyn Connector>>,
    ) -> Result<Arc<dyn CodeModeService>, String>;
    /// Persists a wakeup no later than this Unix millisecond timestamp.
    /// Hosts that poll independently may keep the default implementation.
    async fn wake_at(&self, _timestamp: u64) -> Result<(), String> {
        Ok(())
    }
    /// Waits without using a process runtime timer.
    async fn sleep(&self, milliseconds: u64);
    /// Loads a fixture. Hosts without files accept the fixture JSON directly.
    fn read_fixture(&self, source: &str) -> Result<Vec<u8>, String> {
        if source.len() > crate::MAX_FIXTURE_BYTES {
            return Err("Fixture exceeds the 16 MiB limit".into());
        }
        Ok(source.as_bytes().to_vec())
    }
}