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