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