traverse_runtime/executor/
mod.rs1pub mod native;
12#[cfg(feature = "native-executors")]
13pub mod thread_pool;
14#[cfg(feature = "wasmtime-executor")]
15pub mod wasm;
16
17pub use native::NativeExecutor;
18#[cfg(feature = "native-executors")]
19pub use thread_pool::{ConfigError, ThreadPoolExecutor, ThreadPoolExecutorConfig};
20#[cfg(feature = "wasmtime-executor")]
21pub use wasm::{
22 ActivatedConnector, ConnectorInvokeRequest, ConnectorInvokeResponse, HostAbiImport,
23 HostAbiValidation, MediatedConnector, MediatedConnectorContext, SUPPORTED_HOST_ABI_VERSION,
24 WasmBinaryCacheStats, WasmExecutionLimits, WasmExecutor, WasmModuleCacheConfig,
25 WasmModuleCacheStats, supported_host_abi_versions, verify_wasm_host_abi_bytes,
26};
27
28use crate::events::types::TraverseEvent;
29use serde_json::Value;
30use traverse_contracts::{EventReference, ServiceType};
31
32#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct ConnectorInvocationEvidence {
35 pub connector_id: String,
36 pub resolved_version: Option<String>,
37 pub result_class: String,
38 pub failure_class: Option<String>,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Hash)]
43pub enum ArtifactType {
44 Native,
46 Wasm,
48}
49
50#[derive(Debug, Clone)]
52pub struct ExecutorCapability {
53 pub capability_id: String,
55 pub artifact_type: ArtifactType,
57 pub wasm_binary_path: Option<String>,
59 pub wasm_checksum: Option<String>,
61 pub host_abi_version: Option<String>,
63 pub emits: Vec<EventReference>,
67 pub service_type: ServiceType,
70}
71
72#[derive(Debug, Clone, PartialEq)]
74pub struct ExecutorOutput {
75 pub value: Value,
77 pub emitted_events: Vec<TraverseEvent>,
82 pub connector_invocation_evidence: Vec<ConnectorInvocationEvidence>,
84}
85
86#[derive(Debug, Clone, PartialEq, Eq)]
88pub enum ExecutorError {
89 BinaryLoadFailed(String),
91 ChecksumMismatch { expected: String, actual: String },
93 RuntimeSetupFailed(String),
95 MalformedWasmArtifact { error_code: String, detail: String },
97 UnsupportedAbiVersion {
99 error_code: String,
100 requested: String,
101 supported: String,
102 },
103 UnauthorizedHostImport {
105 error_code: String,
106 abi_version: String,
107 module: String,
108 name: String,
109 },
110 ExecutionFailed(String),
112 Timeout(String),
114 ResourceExhausted(String),
116 OutputDeserializationFailed(String),
118 UnsupportedArtifactType,
120}
121
122impl std::fmt::Display for ExecutorError {
123 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
124 match self {
125 Self::BinaryLoadFailed(msg) => write!(f, "binary load failed: {msg}"),
126 Self::ChecksumMismatch { expected, actual } => {
127 write!(f, "checksum mismatch: expected {expected}, got {actual}")
128 }
129 Self::RuntimeSetupFailed(msg) => write!(f, "runtime setup failed: {msg}"),
130 Self::MalformedWasmArtifact { error_code, detail } => {
131 write!(f, "{error_code}: {detail}")
132 }
133 Self::UnsupportedAbiVersion {
134 error_code,
135 requested,
136 supported,
137 } => write!(
138 f,
139 "{error_code}: requested Traverse Host ABI {requested}, supported {supported}"
140 ),
141 Self::UnauthorizedHostImport {
142 error_code,
143 abi_version,
144 module,
145 name,
146 } => write!(
147 f,
148 "{error_code}: ABI {abi_version} does not allow import {module}::{name}"
149 ),
150 Self::ExecutionFailed(msg) => write!(f, "execution failed: {msg}"),
151 Self::Timeout(msg) => write!(f, "execution timed out: {msg}"),
152 Self::ResourceExhausted(msg) => write!(f, "resource exhausted: {msg}"),
153 Self::OutputDeserializationFailed(msg) => {
154 write!(f, "output deserialization failed: {msg}")
155 }
156 Self::UnsupportedArtifactType => {
157 write!(f, "unsupported artifact type for this executor")
158 }
159 }
160 }
161}
162
163impl std::error::Error for ExecutorError {}
164
165pub trait CapabilityExecutor: Send + Sync {
169 fn execute(
175 &self,
176 capability: &ExecutorCapability,
177 input: &Value,
178 ) -> Result<ExecutorOutput, ExecutorError>;
179}