Skip to main content

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//! `greentic:component@0.6.0` exports descriptor/schema/runtime/qa/i18n and is bound via
5//! [`component_v0_6`].
6
7#[cfg(target_arch = "wasm32")]
8compile_error!("greentic-interfaces-host is intended for native host targets.");
9
10pub use greentic_interfaces::{bindings, mappers, validate};
11
12/// Host bindings for `greentic:component/component@0.6.0` (world `component-v0-v6-v0`).
13pub mod component_v0_6 {
14    pub use greentic_interfaces::component_v0_6::*;
15
16    /// Back-compat alias for older host helper code/tests.
17    pub type ComponentV0V6V0 = Component;
18}
19
20/// Component control and exports.
21pub mod component {
22    /// Component ABI with descriptor/schema/runtime/qa/i18n exports `greentic:component/component@0.6.0`.
23    pub mod v0_6 {
24        pub use greentic_interfaces::component_v0_6::*;
25    }
26    /// Component ABI with config surface `greentic:component/component@0.5.0`.
27    pub mod v0_5 {
28        pub use greentic_interfaces::component_v0_5::*;
29    }
30    /// Component ABI with optional config schema export `greentic:component/component-configurable@0.5.0`.
31    pub mod v0_5_configurable {
32        pub use greentic_interfaces::component_configurable_v0_5::*;
33    }
34    /// Compatibility exports for `greentic:component/component@0.4.0`.
35    pub mod v0_4 {
36        pub use greentic_interfaces::component_v0_4::*;
37    }
38    /// Generic component invocation world `greentic:component-v1/component-host@0.1.0`.
39    pub mod v1 {
40        pub use greentic_interfaces::component_v1::*;
41        pub use greentic_interfaces::mappers::ComponentOutcome;
42        pub use greentic_interfaces::mappers::ComponentOutcomeStatus;
43    }
44    /// Describe-only schema export world `greentic:component/component@1.0.0`.
45    pub mod describe_v1 {
46        pub use greentic_interfaces::component_describe_v1::*;
47    }
48    /// Lifecycle hooks world `greentic:lifecycle/component-lifecycle@1.0.0`.
49    pub mod lifecycle_v1 {
50        pub use greentic_interfaces::component_lifecycle_v1::*;
51    }
52}
53
54/// Runner host bundle `greentic:host@1.0.0`.
55pub mod runner_host_v1 {
56    pub use greentic_interfaces::runner_host_v1::*;
57}
58
59/// Operator hook contracts `greentic:operator/hook-provider@1.0.0`.
60pub mod operator_v1 {
61    pub use greentic_interfaces::operator_hook_provider_v1::*;
62}
63
64/// Pack exporters.
65pub mod pack_exports {
66    /// Pack exports `0.2.0` world.
67    pub mod v0_2 {
68        pub use greentic_interfaces::pack_export_v0_2::*;
69    }
70    /// Pack exports `0.4.0` world.
71    pub mod v0_4 {
72        pub use greentic_interfaces::pack_export_v0_4::*;
73    }
74    /// Pack metadata/flow discovery world `greentic:pack-export-v1/pack-host@0.1.0`.
75    pub mod v1 {
76        pub use greentic_interfaces::mappers::{
77            FlowDescriptor as HostFlowDescriptor, PackDescriptor as HostPackDescriptor,
78        };
79        pub use greentic_interfaces::pack_export_v1::*;
80    }
81}
82
83/// Core types.
84pub mod types {
85    /// Shared flow/component fundamentals `greentic:common-types/common@0.1.0`.
86    pub mod common_v0_1 {
87        pub use greentic_interfaces::common_types_v0_1::*;
88    }
89    /// Core type defs for the 0.2 line.
90    pub mod types_core_v0_2 {
91        pub use greentic_interfaces::types_core_v0_2::*;
92    }
93    /// Core type defs for the 0.4 line.
94    pub mod types_core_v0_4 {
95        pub use greentic_interfaces::types_core_v0_4::*;
96    }
97}
98
99/// v1 host capability contracts.
100pub mod secrets {
101    /// `greentic:secrets-store/store@1.0.0` host imports.
102    pub mod store_v1 {
103        pub use greentic_interfaces::secrets_store_v1::*;
104    }
105}
106
107/// Provider core schema world `greentic:provider-schema-core@1.0.0`.
108#[cfg(feature = "provider-core-v1")]
109pub mod provider_core_v1 {
110    pub use greentic_interfaces::provider_schema_core_v1::*;
111}
112
113/// Shared messaging provider metadata/render helpers.
114pub mod provider_common {
115    pub use greentic_interfaces::bindings::provider_common_0_0_2_common::exports::provider::common::capabilities::*;
116    pub use greentic_interfaces::bindings::provider_common_0_0_2_common::exports::provider::common::render::*;
117}
118
119/// v1 host capability contracts.
120pub mod state {
121    pub use greentic_interfaces::state_store_v1::*;
122}
123
124/// v1 host capability contracts.
125pub mod http_client {
126    /// `greentic:http/client@1.0.0` bindings.
127    pub use greentic_interfaces::http_client_v1::*;
128
129    /// `greentic:http/client@1.1.0` bindings with request options + tenant context.
130    pub mod v1_1 {
131        pub use greentic_interfaces::http_client_v1_1::*;
132    }
133}
134
135/// v1 host capability contracts.
136pub mod telemetry {
137    pub use greentic_interfaces::telemetry_logger_v1::*;
138}
139
140/// v1 host capability contracts.
141#[cfg(feature = "oauth-broker-v1")]
142pub mod oauth_broker {
143    pub use greentic_interfaces::oauth_broker_v1::*;
144}
145
146/// v1 OAuth broker client imports.
147#[cfg(feature = "oauth-broker-v1")]
148pub mod oauth_broker_client {
149    pub use greentic_interfaces::oauth_broker_client_v1::*;
150}
151
152/// Generic worker ABI world.
153#[cfg(feature = "worker-v1")]
154pub mod worker {
155    use greentic_interfaces::bindings::greentic::interfaces_types::types as interfaces_types;
156    use greentic_interfaces::worker_v1::exports::greentic::worker::worker_api::{
157        TenantCtx as WitWorkerTenantCtx, WorkerMessage as WitWorkerMessage,
158        WorkerRequest as WitWorkerRequest, WorkerResponse as WitWorkerResponse,
159    };
160    use greentic_interfaces::worker_v1::greentic::types_core::types::{
161        Cloud, DeploymentCtx, Platform,
162    };
163    use greentic_types::{ErrorCode, GreenticError, TenantCtx};
164    use serde::{Deserialize, Serialize};
165    use serde_json::Value;
166
167    pub use greentic_interfaces::worker_v1::*;
168
169    type MapperResult<T> = Result<T, GreenticError>;
170
171    fn to_worker_tenant(ctx: TenantCtx) -> MapperResult<WitWorkerTenantCtx> {
172        let base = crate::mappers::tenant_ctx_to_wit(ctx)?;
173        Ok(WitWorkerTenantCtx {
174            tenant: base.tenant,
175            team: base.team,
176            user: base.user,
177            deployment: DeploymentCtx {
178                cloud: Cloud::Other,
179                region: None,
180                platform: Platform::Other,
181                runtime: None,
182                i18n_id: base.i18n_id.clone(),
183            },
184            trace_id: base.trace_id,
185            i18n_id: base.i18n_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 team = ctx.team.clone();
195        let user = ctx.user.clone();
196        let base = interfaces_types::TenantCtx {
197            env: "unknown".to_string(),
198            tenant: ctx.tenant.clone(),
199            tenant_id: ctx.tenant,
200            team,
201            team_id: ctx.team,
202            user,
203            user_id: ctx.user,
204            trace_id: ctx.trace_id,
205            i18n_id: ctx.i18n_id.or(ctx.deployment.i18n_id),
206            correlation_id: None,
207            session_id: ctx.session_id,
208            flow_id: ctx.flow_id,
209            node_id: ctx.node_id,
210            provider_id: ctx.provider_id,
211            deadline_ms: None,
212            attempt: 0,
213            idempotency_key: None,
214            impersonation: None,
215            attributes: Vec::new(),
216        };
217        crate::mappers::tenant_ctx_from_wit(base)
218    }
219
220    /// Host-friendly request wrapper for worker invocations (uses `greentic-types` and `serde_json` payloads).
221    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
222    pub struct HostWorkerRequest {
223        /// ABI version identifier (e.g. "1.0").
224        pub version: String,
225        /// Shared tenant context from `greentic-types`.
226        pub tenant: TenantCtx,
227        /// Target worker identifier.
228        pub worker_id: String,
229        /// JSON payload for the worker.
230        pub payload: Value,
231        /// ISO8601 UTC timestamp of the request.
232        pub timestamp_utc: String,
233        /// Optional correlation identifier.
234        pub correlation_id: Option<String>,
235        /// Optional session identifier.
236        pub session_id: Option<String>,
237        /// Optional thread identifier.
238        pub thread_id: Option<String>,
239    }
240
241    /// Host-friendly worker message envelope.
242    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
243    pub struct HostWorkerMessage {
244        /// Message kind (e.g. "text", "card").
245        pub kind: String,
246        /// JSON payload content.
247        pub payload: Value,
248    }
249
250    /// Host-friendly worker response wrapper with typed tenant context.
251    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
252    pub struct HostWorkerResponse {
253        /// Mirrors the request version.
254        pub version: String,
255        /// Shared tenant context from `greentic-types`.
256        pub tenant: TenantCtx,
257        /// Worker identifier that produced the response.
258        pub worker_id: String,
259        /// ISO8601 UTC timestamp.
260        pub timestamp_utc: String,
261        /// Accumulated worker messages.
262        pub messages: Vec<HostWorkerMessage>,
263        /// Optional correlation identifier.
264        pub correlation_id: Option<String>,
265        /// Optional session identifier.
266        pub session_id: Option<String>,
267        /// Optional thread identifier.
268        pub thread_id: Option<String>,
269    }
270
271    impl TryFrom<HostWorkerMessage> for WitWorkerMessage {
272        type Error = GreenticError;
273
274        fn try_from(value: HostWorkerMessage) -> MapperResult<Self> {
275            let payload_json = serde_json::to_string(&value.payload)
276                .map_err(|err| GreenticError::new(ErrorCode::InvalidInput, err.to_string()))?;
277            Ok(Self {
278                kind: value.kind,
279                payload_json,
280            })
281        }
282    }
283
284    impl TryFrom<WitWorkerMessage> for HostWorkerMessage {
285        type Error = GreenticError;
286
287        fn try_from(value: WitWorkerMessage) -> MapperResult<Self> {
288            let payload = serde_json::from_str(&value.payload_json).map_err(|err| {
289                GreenticError::new(
290                    ErrorCode::InvalidInput,
291                    format!("invalid worker payload: {err}"),
292                )
293            })?;
294            Ok(Self {
295                kind: value.kind,
296                payload,
297            })
298        }
299    }
300
301    impl TryFrom<HostWorkerRequest> for WitWorkerRequest {
302        type Error = GreenticError;
303
304        fn try_from(value: HostWorkerRequest) -> MapperResult<Self> {
305            let payload_json = serde_json::to_string(&value.payload)
306                .map_err(|err| GreenticError::new(ErrorCode::InvalidInput, err.to_string()))?;
307            Ok(Self {
308                version: value.version,
309                tenant: to_worker_tenant(value.tenant)?,
310                worker_id: value.worker_id,
311                correlation_id: value.correlation_id,
312                session_id: value.session_id,
313                thread_id: value.thread_id,
314                payload_json,
315                timestamp_utc: value.timestamp_utc,
316            })
317        }
318    }
319
320    impl TryFrom<WitWorkerRequest> for HostWorkerRequest {
321        type Error = GreenticError;
322
323        fn try_from(value: WitWorkerRequest) -> MapperResult<Self> {
324            let payload: Value = serde_json::from_str(&value.payload_json).map_err(|err| {
325                GreenticError::new(
326                    ErrorCode::InvalidInput,
327                    format!("invalid worker payload: {err}"),
328                )
329            })?;
330            Ok(Self {
331                version: value.version,
332                tenant: from_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,
338                timestamp_utc: value.timestamp_utc,
339            })
340        }
341    }
342
343    impl TryFrom<HostWorkerResponse> for WitWorkerResponse {
344        type Error = GreenticError;
345
346        fn try_from(value: HostWorkerResponse) -> MapperResult<Self> {
347            let messages = value
348                .messages
349                .into_iter()
350                .map(WitWorkerMessage::try_from)
351                .collect::<MapperResult<Vec<_>>>()?;
352            Ok(Self {
353                version: value.version,
354                tenant: to_worker_tenant(value.tenant)?,
355                worker_id: value.worker_id,
356                correlation_id: value.correlation_id,
357                session_id: value.session_id,
358                thread_id: value.thread_id,
359                messages,
360                timestamp_utc: value.timestamp_utc,
361            })
362        }
363    }
364
365    impl TryFrom<WitWorkerResponse> for HostWorkerResponse {
366        type Error = GreenticError;
367
368        fn try_from(value: WitWorkerResponse) -> MapperResult<Self> {
369            let messages = value
370                .messages
371                .into_iter()
372                .map(HostWorkerMessage::try_from)
373                .collect::<MapperResult<Vec<_>>>()?;
374            Ok(Self {
375                version: value.version,
376                tenant: from_worker_tenant(value.tenant)?,
377                worker_id: value.worker_id,
378                correlation_id: value.correlation_id,
379                session_id: value.session_id,
380                thread_id: value.thread_id,
381                messages,
382                timestamp_utc: value.timestamp_utc,
383            })
384        }
385    }
386}
387
388/// GUI fragment renderers implemented by components.
389#[cfg(feature = "gui-fragment")]
390pub mod gui_fragment {
391    pub use greentic_interfaces::bindings::greentic_gui_1_0_0_gui_fragment::exports::greentic::gui::fragment_api as bindings;
392    pub use bindings::FragmentContext;
393    pub use bindings::Guest as GuiFragment;
394}
395
396/// Supply-chain provider contracts.
397pub mod supply_chain {
398    /// Source provider world `greentic:source/source-sync@1.0.0`.
399    pub mod source {
400        pub use greentic_interfaces::bindings::greentic_source_1_0_0_source_sync::exports::greentic::source::source_api::*;
401    }
402    /// Build provider world `greentic:build/builder@1.0.0`.
403    pub mod build {
404        pub use greentic_interfaces::bindings::greentic_build_1_0_0_builder::exports::greentic::build::builder_api::*;
405    }
406    /// Scanner world `greentic:scan/scanner@1.0.0`.
407    pub mod scan {
408        pub use greentic_interfaces::bindings::greentic_scan_1_0_0_scanner::exports::greentic::scan::scanner_api::*;
409    }
410    /// Signing world `greentic:signing/signer@1.0.0`.
411    pub mod signing {
412        pub use greentic_interfaces::bindings::greentic_signing_1_0_0_signer::exports::greentic::signing::signer_api::*;
413    }
414    /// Attestation world `greentic:attestation/attester@1.0.0`.
415    pub mod attestation {
416        pub use greentic_interfaces::bindings::greentic_attestation_1_0_0_attester::exports::greentic::attestation::attester_api::*;
417    }
418    /// Policy evaluation world `greentic:policy/policy-evaluator@1.0.0`.
419    pub mod policy {
420        pub use greentic_interfaces::bindings::greentic_policy_1_0_0_policy_evaluator::exports::greentic::policy::policy_api::*;
421    }
422    /// Metadata store world `greentic:metadata/metadata-store@1.0.0`.
423    pub mod metadata {
424        pub use greentic_interfaces::bindings::greentic_metadata_1_0_0_metadata_store::exports::greentic::metadata::metadata_api::*;
425    }
426    /// OCI distribution world `greentic:oci/oci-distribution@1.0.0`.
427    pub mod oci {
428        pub use greentic_interfaces::bindings::greentic_oci_1_0_0_oci_distribution::exports::greentic::oci::oci_api::*;
429    }
430}
431
432/// Desired state distribution contracts.
433pub mod distribution {
434    /// `greentic:distribution/distribution@1.0.0`.
435    pub mod v1 {
436        pub use greentic_interfaces::bindings::greentic_distribution_1_0_0_distribution::exports::greentic::distribution::distribution_api::*;
437    }
438}
439
440/// Distributor API contracts.
441pub mod distributor_api {
442    /// `greentic:distributor-api/distributor-api@1.0.0`.
443    pub mod v1 {
444        pub use greentic_interfaces::bindings::greentic_distributor_api_1_0_0_distributor_api::exports::greentic::distributor_api::distributor::*;
445    }
446    /// `greentic:distributor-api/distributor-api@1.1.0`.
447    pub mod v1_1 {
448        pub use greentic_interfaces::bindings::greentic_distributor_api_1_1_0_distributor_api::exports::greentic::distributor_api::distributor::*;
449    }
450
451    /// Resolved component metadata returned by a ref-based lookup.
452    #[derive(Debug, Clone)]
453    pub struct ResolvedComponent {
454        /// Digest returned by the distributor (opaque string).
455        pub digest: String,
456        /// Metadata returned by `resolve-ref`.
457        pub metadata: v1_1::ResolveRefMetadata,
458    }
459
460    /// Resolved component artifact content.
461    #[derive(Debug, Clone, PartialEq)]
462    pub enum ResolvedArtifact {
463        /// Raw component bytes.
464        Bytes(Vec<u8>),
465        /// Filesystem path to the component.
466        Path(String),
467    }
468
469    /// Host-side resolver for ref-based component lookup.
470    pub trait ComponentResolver {
471        /// Resolve a component reference string to a digest plus metadata.
472        fn resolve_ref(&self, component_ref: &str) -> ResolvedComponent;
473
474        /// Fetch a resolved component artifact by digest.
475        fn fetch_digest(&self, digest: &str) -> ResolvedArtifact;
476    }
477}
478
479/// Stable alias for HTTP client imports.
480pub mod http {
481    pub use super::http_client::*;
482}
483
484/// Stable alias for OAuth broker imports.
485#[cfg(feature = "oauth-broker-v1")]
486pub mod oauth {
487    pub use super::oauth_broker::*;
488}
489
490/// MCP router surfaces (multiple protocol snapshots).
491pub mod mcp {
492    /// `wasix:mcp@24.11.5` snapshot (2024-11-05 spec).
493    #[cfg(feature = "wasix-mcp-24-11-05-host")]
494    pub mod v24_11_05 {
495        pub use greentic_interfaces::wasix_mcp_24_11_05::*;
496    }
497
498    /// `wasix:mcp@25.3.26` snapshot with annotations/audio/completions/progress.
499    #[cfg(feature = "wasix-mcp-25-03-26-host")]
500    pub mod v25_03_26 {
501        pub use greentic_interfaces::wasix_mcp_25_03_26::*;
502    }
503
504    /// `wasix:mcp@25.6.18` snapshot with structured output/resources/elicitation.
505    #[cfg(feature = "wasix-mcp-25-06-18-host")]
506    pub mod v25_06_18 {
507        pub use greentic_interfaces::wasix_mcp_25_06_18::*;
508    }
509}
510
511/// UI action handler contracts.
512pub mod ui_actions {
513    /// UI action handler world `greentic:repo-ui-actions/repo-ui-worker@1.0.0`.
514    pub mod repo_ui_worker {
515        pub use greentic_interfaces::bindings::greentic_repo_ui_actions_1_0_0_repo_ui_worker::exports::greentic::repo_ui_actions::ui_action_api::*;
516    }
517}