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