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