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