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