Skip to main content

greentic_interfaces_host/
lib.rs

1#![deny(unsafe_code)]
2#![warn(missing_docs, clippy::unwrap_used, clippy::expect_used)]
3//! Host-facing bindings and mappers re-exported from `greentic-interfaces`.
4
5#[cfg(target_arch = "wasm32")]
6compile_error!("greentic-interfaces-host is intended for native host targets.");
7
8pub use greentic_interfaces::{bindings, mappers, validate};
9
10/// Component control and exports.
11pub mod component {
12    /// Component ABI with config surface `greentic:component/component@0.5.0`.
13    pub mod v0_5 {
14        pub use greentic_interfaces::component_v0_5::*;
15    }
16    /// Component ABI with optional config schema export `greentic:component/component-configurable@0.5.0`.
17    pub mod v0_5_configurable {
18        pub use greentic_interfaces::component_configurable_v0_5::*;
19    }
20    /// Compatibility exports for `greentic:component/component@0.4.0`.
21    pub mod v0_4 {
22        pub use greentic_interfaces::component_v0_4::*;
23    }
24    /// Generic component invocation world `greentic:component-v1/component-host@0.1.0`.
25    pub mod v1 {
26        pub use greentic_interfaces::component_v1::*;
27        pub use greentic_interfaces::mappers::ComponentOutcome;
28        pub use greentic_interfaces::mappers::ComponentOutcomeStatus;
29    }
30    /// Describe-only schema export world `greentic:component/component@1.0.0`.
31    pub mod describe_v1 {
32        pub use greentic_interfaces::component_describe_v1::*;
33    }
34    /// Lifecycle hooks world `greentic:lifecycle/component-lifecycle@1.0.0`.
35    pub mod lifecycle_v1 {
36        pub use greentic_interfaces::component_lifecycle_v1::*;
37    }
38}
39
40/// Runner host bundle `greentic:host@1.0.0`.
41pub mod runner_host_v1 {
42    pub use greentic_interfaces::runner_host_v1::*;
43}
44
45/// Pack exporters.
46pub mod pack_exports {
47    /// Pack exports `0.2.0` world.
48    pub mod v0_2 {
49        pub use greentic_interfaces::pack_export_v0_2::*;
50    }
51    /// Pack exports `0.4.0` world.
52    pub mod v0_4 {
53        pub use greentic_interfaces::pack_export_v0_4::*;
54    }
55    /// Pack metadata/flow discovery world `greentic:pack-export-v1/pack-host@0.1.0`.
56    pub mod v1 {
57        pub use greentic_interfaces::mappers::{
58            FlowDescriptor as HostFlowDescriptor, PackDescriptor as HostPackDescriptor,
59        };
60        pub use greentic_interfaces::pack_export_v1::*;
61    }
62}
63
64/// Core types.
65pub mod types {
66    /// Shared flow/component fundamentals `greentic:common-types/common@0.1.0`.
67    pub mod common_v0_1 {
68        pub use greentic_interfaces::common_types_v0_1::*;
69    }
70    /// Core type defs for the 0.2 line.
71    pub mod types_core_v0_2 {
72        pub use greentic_interfaces::types_core_v0_2::*;
73    }
74    /// Core type defs for the 0.4 line.
75    pub mod types_core_v0_4 {
76        pub use greentic_interfaces::types_core_v0_4::*;
77    }
78}
79
80/// v1 host capability contracts.
81pub mod secrets {
82    /// `greentic:secrets-store/store@1.0.0` host imports.
83    pub mod store_v1 {
84        pub use greentic_interfaces::secrets_store_v1::*;
85    }
86}
87
88/// Provider core schema world `greentic:provider-schema-core@1.0.0`.
89#[cfg(feature = "provider-core-v1")]
90pub mod provider_core_v1 {
91    pub use greentic_interfaces::provider_schema_core_v1::*;
92}
93
94/// Shared messaging provider metadata/render helpers.
95pub mod provider_common {
96    pub use greentic_interfaces::bindings::provider_common_0_0_2_common::exports::provider::common::capabilities::*;
97    pub use greentic_interfaces::bindings::provider_common_0_0_2_common::exports::provider::common::render::*;
98}
99
100/// v1 host capability contracts.
101pub mod state {
102    pub use greentic_interfaces::state_store_v1::*;
103}
104
105/// v1 host capability contracts.
106pub mod http_client {
107    /// `greentic:http/client@1.0.0` bindings.
108    pub use greentic_interfaces::http_client_v1::*;
109
110    /// `greentic:http/client@1.1.0` bindings with request options + tenant context.
111    pub mod v1_1 {
112        pub use greentic_interfaces::http_client_v1_1::*;
113    }
114}
115
116/// v1 host capability contracts.
117pub mod telemetry {
118    pub use greentic_interfaces::telemetry_logger_v1::*;
119}
120
121/// v1 host capability contracts.
122#[cfg(feature = "oauth-broker-v1")]
123pub mod oauth_broker {
124    pub use greentic_interfaces::oauth_broker_v1::*;
125}
126
127/// v1 OAuth broker client imports.
128#[cfg(feature = "oauth-broker-v1")]
129pub mod oauth_broker_client {
130    pub use greentic_interfaces::oauth_broker_client_v1::*;
131}
132
133/// Generic worker ABI world.
134#[cfg(feature = "worker-v1")]
135pub mod worker {
136    use greentic_interfaces::bindings::greentic::interfaces_types::types as interfaces_types;
137    use greentic_interfaces::worker_v1::exports::greentic::worker::worker_api::{
138        TenantCtx as WitWorkerTenantCtx, WorkerMessage as WitWorkerMessage,
139        WorkerRequest as WitWorkerRequest, WorkerResponse as WitWorkerResponse,
140    };
141    use greentic_interfaces::worker_v1::greentic::types_core::types::{
142        Cloud, DeploymentCtx, Platform,
143    };
144    use greentic_types::{ErrorCode, GreenticError, TenantCtx};
145    use serde::{Deserialize, Serialize};
146    use serde_json::Value;
147
148    pub use greentic_interfaces::worker_v1::*;
149
150    type MapperResult<T> = Result<T, GreenticError>;
151
152    fn to_worker_tenant(ctx: TenantCtx) -> MapperResult<WitWorkerTenantCtx> {
153        let base = crate::mappers::tenant_ctx_to_wit(ctx)?;
154        Ok(WitWorkerTenantCtx {
155            tenant: base.tenant,
156            team: base.team,
157            user: base.user,
158            deployment: DeploymentCtx {
159                cloud: Cloud::Other,
160                region: None,
161                platform: Platform::Other,
162                runtime: None,
163            },
164            trace_id: base.trace_id,
165            i18n_id: base.i18n_id.clone(),
166            session_id: base.session_id,
167            flow_id: base.flow_id,
168            node_id: base.node_id,
169            provider_id: base.provider_id,
170        })
171    }
172
173    fn from_worker_tenant(ctx: WitWorkerTenantCtx) -> MapperResult<TenantCtx> {
174        let base = interfaces_types::TenantCtx {
175            env: "unknown".to_string(),
176            tenant: ctx.tenant.clone(),
177            tenant_id: ctx.tenant,
178            team: ctx.team.clone(),
179            team_id: ctx.team,
180            user: ctx.user.clone(),
181            user_id: ctx.user,
182            trace_id: ctx.trace_id,
183            i18n_id: ctx.i18n_id.clone(),
184            correlation_id: None,
185            session_id: ctx.session_id,
186            flow_id: ctx.flow_id,
187            node_id: ctx.node_id,
188            provider_id: ctx.provider_id,
189            deadline_ms: None,
190            attempt: 0,
191            idempotency_key: None,
192            impersonation: None,
193            attributes: Vec::new(),
194        };
195        crate::mappers::tenant_ctx_from_wit(base)
196    }
197
198    /// Host-friendly request wrapper for worker invocations (uses `greentic-types` and `serde_json` payloads).
199    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
200    pub struct HostWorkerRequest {
201        /// ABI version identifier (e.g. "1.0").
202        pub version: String,
203        /// Shared tenant context from `greentic-types`.
204        pub tenant: TenantCtx,
205        /// Target worker identifier.
206        pub worker_id: String,
207        /// JSON payload for the worker.
208        pub payload: Value,
209        /// ISO8601 UTC timestamp of the request.
210        pub timestamp_utc: String,
211        /// Optional correlation identifier.
212        pub correlation_id: Option<String>,
213        /// Optional session identifier.
214        pub session_id: Option<String>,
215        /// Optional thread identifier.
216        pub thread_id: Option<String>,
217    }
218
219    /// Host-friendly worker message envelope.
220    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
221    pub struct HostWorkerMessage {
222        /// Message kind (e.g. "text", "card").
223        pub kind: String,
224        /// JSON payload content.
225        pub payload: Value,
226    }
227
228    /// Host-friendly worker response wrapper with typed tenant context.
229    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
230    pub struct HostWorkerResponse {
231        /// Mirrors the request version.
232        pub version: String,
233        /// Shared tenant context from `greentic-types`.
234        pub tenant: TenantCtx,
235        /// Worker identifier that produced the response.
236        pub worker_id: String,
237        /// ISO8601 UTC timestamp.
238        pub timestamp_utc: String,
239        /// Accumulated worker messages.
240        pub messages: Vec<HostWorkerMessage>,
241        /// Optional correlation identifier.
242        pub correlation_id: Option<String>,
243        /// Optional session identifier.
244        pub session_id: Option<String>,
245        /// Optional thread identifier.
246        pub thread_id: Option<String>,
247    }
248
249    impl TryFrom<HostWorkerMessage> for WitWorkerMessage {
250        type Error = GreenticError;
251
252        fn try_from(value: HostWorkerMessage) -> MapperResult<Self> {
253            let payload_json = serde_json::to_string(&value.payload)
254                .map_err(|err| GreenticError::new(ErrorCode::InvalidInput, err.to_string()))?;
255            Ok(Self {
256                kind: value.kind,
257                payload_json,
258            })
259        }
260    }
261
262    impl TryFrom<WitWorkerMessage> for HostWorkerMessage {
263        type Error = GreenticError;
264
265        fn try_from(value: WitWorkerMessage) -> MapperResult<Self> {
266            let payload = serde_json::from_str(&value.payload_json).map_err(|err| {
267                GreenticError::new(
268                    ErrorCode::InvalidInput,
269                    format!("invalid worker payload: {err}"),
270                )
271            })?;
272            Ok(Self {
273                kind: value.kind,
274                payload,
275            })
276        }
277    }
278
279    impl TryFrom<HostWorkerRequest> for WitWorkerRequest {
280        type Error = GreenticError;
281
282        fn try_from(value: HostWorkerRequest) -> MapperResult<Self> {
283            let payload_json = serde_json::to_string(&value.payload)
284                .map_err(|err| GreenticError::new(ErrorCode::InvalidInput, err.to_string()))?;
285            Ok(Self {
286                version: value.version,
287                tenant: to_worker_tenant(value.tenant)?,
288                worker_id: value.worker_id,
289                correlation_id: value.correlation_id,
290                session_id: value.session_id,
291                thread_id: value.thread_id,
292                payload_json,
293                timestamp_utc: value.timestamp_utc,
294            })
295        }
296    }
297
298    impl TryFrom<WitWorkerRequest> for HostWorkerRequest {
299        type Error = GreenticError;
300
301        fn try_from(value: WitWorkerRequest) -> MapperResult<Self> {
302            let payload: Value = serde_json::from_str(&value.payload_json).map_err(|err| {
303                GreenticError::new(
304                    ErrorCode::InvalidInput,
305                    format!("invalid worker payload: {err}"),
306                )
307            })?;
308            Ok(Self {
309                version: value.version,
310                tenant: from_worker_tenant(value.tenant)?,
311                worker_id: value.worker_id,
312                correlation_id: value.correlation_id,
313                session_id: value.session_id,
314                thread_id: value.thread_id,
315                payload,
316                timestamp_utc: value.timestamp_utc,
317            })
318        }
319    }
320
321    impl TryFrom<HostWorkerResponse> for WitWorkerResponse {
322        type Error = GreenticError;
323
324        fn try_from(value: HostWorkerResponse) -> MapperResult<Self> {
325            let messages = value
326                .messages
327                .into_iter()
328                .map(WitWorkerMessage::try_from)
329                .collect::<MapperResult<Vec<_>>>()?;
330            Ok(Self {
331                version: value.version,
332                tenant: to_worker_tenant(value.tenant)?,
333                worker_id: value.worker_id,
334                correlation_id: value.correlation_id,
335                session_id: value.session_id,
336                thread_id: value.thread_id,
337                messages,
338                timestamp_utc: value.timestamp_utc,
339            })
340        }
341    }
342
343    impl TryFrom<WitWorkerResponse> for HostWorkerResponse {
344        type Error = GreenticError;
345
346        fn try_from(value: WitWorkerResponse) -> MapperResult<Self> {
347            let messages = value
348                .messages
349                .into_iter()
350                .map(HostWorkerMessage::try_from)
351                .collect::<MapperResult<Vec<_>>>()?;
352            Ok(Self {
353                version: value.version,
354                tenant: from_worker_tenant(value.tenant)?,
355                worker_id: value.worker_id,
356                correlation_id: value.correlation_id,
357                session_id: value.session_id,
358                thread_id: value.thread_id,
359                messages,
360                timestamp_utc: value.timestamp_utc,
361            })
362        }
363    }
364}
365
366/// GUI fragment renderers implemented by components.
367#[cfg(feature = "gui-fragment")]
368pub mod gui_fragment {
369    pub use greentic_interfaces::bindings::greentic_gui_1_0_0_gui_fragment::exports::greentic::gui::fragment_api as bindings;
370    pub use bindings::FragmentContext;
371    pub use bindings::Guest as GuiFragment;
372}
373
374/// Supply-chain provider contracts.
375pub mod supply_chain {
376    /// Source provider world `greentic:source/source-sync@1.0.0`.
377    pub mod source {
378        pub use greentic_interfaces::bindings::greentic_source_1_0_0_source_sync::exports::greentic::source::source_api::*;
379    }
380    /// Build provider world `greentic:build/builder@1.0.0`.
381    pub mod build {
382        pub use greentic_interfaces::bindings::greentic_build_1_0_0_builder::exports::greentic::build::builder_api::*;
383    }
384    /// Scanner world `greentic:scan/scanner@1.0.0`.
385    pub mod scan {
386        pub use greentic_interfaces::bindings::greentic_scan_1_0_0_scanner::exports::greentic::scan::scanner_api::*;
387    }
388    /// Signing world `greentic:signing/signer@1.0.0`.
389    pub mod signing {
390        pub use greentic_interfaces::bindings::greentic_signing_1_0_0_signer::exports::greentic::signing::signer_api::*;
391    }
392    /// Attestation world `greentic:attestation/attester@1.0.0`.
393    pub mod attestation {
394        pub use greentic_interfaces::bindings::greentic_attestation_1_0_0_attester::exports::greentic::attestation::attester_api::*;
395    }
396    /// Policy evaluation world `greentic:policy/policy-evaluator@1.0.0`.
397    pub mod policy {
398        pub use greentic_interfaces::bindings::greentic_policy_1_0_0_policy_evaluator::exports::greentic::policy::policy_api::*;
399    }
400    /// Metadata store world `greentic:metadata/metadata-store@1.0.0`.
401    pub mod metadata {
402        pub use greentic_interfaces::bindings::greentic_metadata_1_0_0_metadata_store::exports::greentic::metadata::metadata_api::*;
403    }
404    /// OCI distribution world `greentic:oci/oci-distribution@1.0.0`.
405    pub mod oci {
406        pub use greentic_interfaces::bindings::greentic_oci_1_0_0_oci_distribution::exports::greentic::oci::oci_api::*;
407    }
408}
409
410/// Desired state distribution contracts.
411pub mod distribution {
412    /// `greentic:distribution/distribution@1.0.0`.
413    pub mod v1 {
414        pub use greentic_interfaces::bindings::greentic_distribution_1_0_0_distribution::exports::greentic::distribution::distribution_api::*;
415    }
416}
417
418/// Distributor API contracts.
419pub mod distributor_api {
420    /// `greentic:distributor-api/distributor-api@1.0.0`.
421    pub mod v1 {
422        pub use greentic_interfaces::bindings::greentic_distributor_api_1_0_0_distributor_api::exports::greentic::distributor_api::distributor::*;
423    }
424    /// `greentic:distributor-api/distributor-api@1.1.0`.
425    pub mod v1_1 {
426        pub use greentic_interfaces::bindings::greentic_distributor_api_1_1_0_distributor_api::exports::greentic::distributor_api::distributor::*;
427    }
428
429    /// Resolved component metadata returned by a ref-based lookup.
430    #[derive(Debug, Clone)]
431    pub struct ResolvedComponent {
432        /// Digest returned by the distributor (opaque string).
433        pub digest: String,
434        /// Metadata returned by `resolve-ref`.
435        pub metadata: v1_1::ResolveRefMetadata,
436    }
437
438    /// Resolved component artifact content.
439    #[derive(Debug, Clone, PartialEq)]
440    pub enum ResolvedArtifact {
441        /// Raw component bytes.
442        Bytes(Vec<u8>),
443        /// Filesystem path to the component.
444        Path(String),
445    }
446
447    /// Host-side resolver for ref-based component lookup.
448    pub trait ComponentResolver {
449        /// Resolve a component reference string to a digest plus metadata.
450        fn resolve_ref(&self, component_ref: &str) -> ResolvedComponent;
451
452        /// Fetch a resolved component artifact by digest.
453        fn fetch_digest(&self, digest: &str) -> ResolvedArtifact;
454    }
455}
456
457/// Stable alias for HTTP client imports.
458pub mod http {
459    pub use super::http_client::*;
460}
461
462/// Stable alias for OAuth broker imports.
463#[cfg(feature = "oauth-broker-v1")]
464pub mod oauth {
465    pub use super::oauth_broker::*;
466}
467
468/// MCP router surfaces (multiple protocol snapshots).
469pub mod mcp {
470    /// `wasix:mcp@24.11.5` snapshot (2024-11-05 spec).
471    #[cfg(feature = "wasix-mcp-24-11-05-host")]
472    pub mod v24_11_05 {
473        pub use greentic_interfaces::wasix_mcp_24_11_05::*;
474    }
475
476    /// `wasix:mcp@25.3.26` snapshot with annotations/audio/completions/progress.
477    #[cfg(feature = "wasix-mcp-25-03-26-host")]
478    pub mod v25_03_26 {
479        pub use greentic_interfaces::wasix_mcp_25_03_26::*;
480    }
481
482    /// `wasix:mcp@25.6.18` snapshot with structured output/resources/elicitation.
483    #[cfg(feature = "wasix-mcp-25-06-18-host")]
484    pub mod v25_06_18 {
485        pub use greentic_interfaces::wasix_mcp_25_06_18::*;
486    }
487}
488
489/// UI action handler contracts.
490pub mod ui_actions {
491    /// UI action handler world `greentic:repo-ui-actions/repo-ui-worker@1.0.0`.
492    pub mod repo_ui_worker {
493        pub use greentic_interfaces::bindings::greentic_repo_ui_actions_1_0_0_repo_ui_worker::exports::greentic::repo_ui_actions::ui_action_api::*;
494    }
495}