Skip to main content

parallax_runtime/
adapter.rs

1//! Runtime adapter trait.
2
3use async_trait::async_trait;
4use parallax_core::{
5    ExecutionRequest, ExecutionResult, RestoreResult, RuntimeCapabilities, RuntimeKind,
6    RuntimeMetadata, RuntimeStatus,
7};
8use parallax_ir::PirDocument;
9use parallax_security::SandboxPolicy;
10use std::sync::Arc;
11
12/// Trait implemented by language adapters.
13#[async_trait]
14pub trait RuntimeAdapter: Send + Sync {
15    /// Runtime kind.
16    fn kind(&self) -> RuntimeKind;
17
18    /// Static metadata.
19    fn metadata(&self) -> RuntimeMetadata;
20
21    /// Declared capabilities.
22    fn capabilities(&self) -> RuntimeCapabilities;
23
24    /// Probe host availability (may spawn briefly).
25    async fn probe(&self) -> RuntimeStatus;
26
27    /// Execute a program, optionally capturing bindings listed in the request.
28    async fn execute(
29        &self,
30        request: ExecutionRequest,
31        policy: &SandboxPolicy,
32    ) -> parallax_core::Result<ExecutionResult>;
33
34    /// Restore PIR bindings into a fresh worker context.
35    async fn restore(
36        &self,
37        pir: &PirDocument,
38        policy: &SandboxPolicy,
39    ) -> parallax_core::Result<RestoreResult>;
40}
41
42/// Heap-allocated adapter.
43pub type BoxRuntimeAdapter = Arc<dyn RuntimeAdapter>;
44
45/// Factory fn type.
46pub type AdapterFactory = Arc<dyn Fn() -> BoxRuntimeAdapter + Send + Sync>;