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