Skip to main content

greentic_interfaces_guest/
lib.rs

1#![deny(unsafe_code)]
2#![warn(missing_docs, clippy::unwrap_used, clippy::expect_used)]
3//! Guest-facing bindings and mappers without host-world leakage.
4
5pub mod bindings;
6
7#[cfg(all(not(target_arch = "wasm32"), feature = "host-bridge"))]
8pub mod host_bridge;
9
10#[cfg(feature = "distributor-api-imports")]
11mod distributor_api_imports;
12#[cfg(feature = "distributor-api-v1-1-imports")]
13mod distributor_api_imports_v1_1;
14
15/// Component exports for `greentic:component/component@0.6.0` plus the
16/// canonical `component-qa` and `component-i18n` guest exports.
17///
18/// Enable feature `component-v0-6` and export your implementation:
19///
20/// ```rust
21/// # use greentic_interfaces_guest::component_v0_6::node;
22/// # use greentic_interfaces_guest::component_v0_6::{component_i18n, component_qa};
23/// # struct MyImpl;
24/// # impl node::Guest for MyImpl {
25/// #     fn describe() -> node::ComponentDescriptor {
26/// #         node::ComponentDescriptor {
27/// #             name: "demo".into(),
28/// #             version: "0.1.0".into(),
29/// #             summary: None,
30/// #             capabilities: vec![],
31/// #             ops: vec![],
32/// #             schemas: vec![],
33/// #             setup: None,
34/// #         }
35/// #     }
36/// #     fn invoke(_op: String, _envelope: node::InvocationEnvelope) -> Result<node::InvocationResult, node::NodeError> {
37/// #         Ok(node::InvocationResult {
38/// #             ok: true,
39/// #             output_cbor: vec![],
40/// #             output_metadata_cbor: None,
41/// #         })
42/// #     }
43/// # }
44/// # impl component_qa::Guest for MyImpl {
45/// #     fn qa_spec(_mode: component_qa::QaMode) -> Vec<u8> {
46/// #         vec![]
47/// #     }
48/// #     fn apply_answers(
49/// #         _mode: component_qa::QaMode,
50/// #         _current_config: Vec<u8>,
51/// #         _answers: Vec<u8>,
52/// #     ) -> Vec<u8> {
53/// #         vec![]
54/// #     }
55/// # }
56/// # impl component_i18n::Guest for MyImpl {
57/// #     fn i18n_keys() -> Vec<String> {
58/// #         vec!["demo.title".into()]
59/// #     }
60/// # }
61/// greentic_interfaces_guest::export_component_v060!(
62///     MyImpl,
63///     component_qa: MyImpl,
64///     component_i18n: MyImpl,
65/// );
66/// ```
67#[cfg(feature = "component-v0-6")]
68pub mod component_v0_6 {
69    pub use crate::bindings::greentic_component_0_6_0_component::exports::greentic::component::*;
70    pub use crate::bindings::greentic_component_0_6_0_component_i18n_support::exports::greentic::component::component_i18n;
71    pub use crate::bindings::greentic_component_0_6_0_component_qa_support::exports::greentic::component::component_qa;
72}
73
74/// Exports a `greentic:component/node@0.6.0` guest implementation, and can
75/// optionally also export `greentic:component/component-qa@0.6.0` and
76/// `greentic:component/component-i18n@0.6.0` from crate-owned canonical
77/// bindings.
78///
79/// `export_component_v060!(MyNode)` preserves the existing node-only behavior.
80/// To add the optional exports without local WIT files:
81///
82/// ```rust
83/// # use greentic_interfaces_guest::component_v0_6::{component_i18n, component_qa, node};
84/// # struct Component;
85/// # impl node::Guest for Component {
86/// #     fn describe() -> node::ComponentDescriptor {
87/// #         node::ComponentDescriptor {
88/// #             name: "demo".into(),
89/// #             version: "0.1.0".into(),
90/// #             summary: None,
91/// #             capabilities: vec![],
92/// #             ops: vec![],
93/// #             schemas: vec![],
94/// #             setup: None,
95/// #         }
96/// #     }
97/// #     fn invoke(
98/// #         _op: String,
99/// #         _envelope: node::InvocationEnvelope,
100/// #     ) -> Result<node::InvocationResult, node::NodeError> {
101/// #         Ok(node::InvocationResult {
102/// #             ok: true,
103/// #             output_cbor: vec![],
104/// #             output_metadata_cbor: None,
105/// #         })
106/// #     }
107/// # }
108/// # impl component_qa::Guest for Component {
109/// #     fn qa_spec(_mode: component_qa::QaMode) -> Vec<u8> { vec![] }
110/// #     fn apply_answers(
111/// #         _mode: component_qa::QaMode,
112/// #         _current_config: Vec<u8>,
113/// #         _answers: Vec<u8>,
114/// #     ) -> Vec<u8> { vec![] }
115/// # }
116/// # impl component_i18n::Guest for Component {
117/// #     fn i18n_keys() -> Vec<String> { vec![] }
118/// # }
119/// greentic_interfaces_guest::export_component_v060!(
120///     Component,
121///     component_qa: Component,
122///     component_i18n: Component,
123/// );
124/// ```
125#[cfg(feature = "component-v0-6")]
126#[macro_export]
127macro_rules! export_component_v060 {
128    ($node_ty:ty $(, component_qa: $qa_ty:ty)? $(, component_i18n: $i18n_ty:ty)? $(,)?) => {
129        const _: () = {
130            use $crate::bindings::greentic_component_0_6_0_component::exports::greentic::component::node;
131
132            #[unsafe(export_name = "greentic:component/node@0.6.0#describe")]
133            unsafe extern "C" fn export_component_v060_describe() -> *mut u8 {
134                unsafe { node::_export_describe_cabi::<$node_ty>() }
135            }
136
137            #[unsafe(export_name = "cabi_post_greentic:component/node@0.6.0#describe")]
138            unsafe extern "C" fn export_component_v060_post_describe(arg0: *mut u8) {
139                unsafe { node::__post_return_describe::<$node_ty>(arg0) }
140            }
141
142            #[unsafe(export_name = "greentic:component/node@0.6.0#invoke")]
143            unsafe extern "C" fn export_component_v060_invoke(arg0: *mut u8) -> *mut u8 {
144                unsafe { node::_export_invoke_cabi::<$node_ty>(arg0) }
145            }
146
147            #[unsafe(export_name = "cabi_post_greentic:component/node@0.6.0#invoke")]
148            unsafe extern "C" fn export_component_v060_post_invoke(arg0: *mut u8) {
149                unsafe { node::__post_return_invoke::<$node_ty>(arg0) }
150            }
151
152            $(
153                use $crate::bindings::greentic_component_0_6_0_component_qa_support::exports::greentic::component::component_qa;
154
155                #[unsafe(export_name = "greentic:component/component-qa@0.6.0#qa-spec")]
156                unsafe extern "C" fn export_component_v060_qa_spec(arg0: i32) -> *mut u8 {
157                    unsafe { component_qa::_export_qa_spec_cabi::<$qa_ty>(arg0) }
158                }
159
160                #[unsafe(export_name = "cabi_post_greentic:component/component-qa@0.6.0#qa-spec")]
161                unsafe extern "C" fn export_component_v060_post_qa_spec(arg0: *mut u8) {
162                    unsafe { component_qa::__post_return_qa_spec::<$qa_ty>(arg0) }
163                }
164
165                #[unsafe(export_name = "greentic:component/component-qa@0.6.0#apply-answers")]
166                unsafe extern "C" fn export_component_v060_apply_answers(
167                    arg0: i32,
168                    arg1: *mut u8,
169                    arg2: usize,
170                    arg3: *mut u8,
171                    arg4: usize,
172                ) -> *mut u8 {
173                    unsafe {
174                        component_qa::_export_apply_answers_cabi::<$qa_ty>(
175                            arg0, arg1, arg2, arg3, arg4,
176                        )
177                    }
178                }
179
180                #[unsafe(export_name = "cabi_post_greentic:component/component-qa@0.6.0#apply-answers")]
181                unsafe extern "C" fn export_component_v060_post_apply_answers(arg0: *mut u8) {
182                    unsafe { component_qa::__post_return_apply_answers::<$qa_ty>(arg0) }
183                }
184            )?
185
186            $(
187                use $crate::bindings::greentic_component_0_6_0_component_i18n_support::exports::greentic::component::component_i18n;
188
189                #[unsafe(export_name = "greentic:component/component-i18n@0.6.0#i18n-keys")]
190                unsafe extern "C" fn export_component_v060_i18n_keys() -> *mut u8 {
191                    unsafe { component_i18n::_export_i18n_keys_cabi::<$i18n_ty>() }
192                }
193
194                #[unsafe(export_name = "cabi_post_greentic:component/component-i18n@0.6.0#i18n-keys")]
195                unsafe extern "C" fn export_component_v060_post_i18n_keys(arg0: *mut u8) {
196                    unsafe { component_i18n::__post_return_i18n_keys::<$i18n_ty>(arg0) }
197                }
198            )?
199        };
200    };
201}
202
203/// Generic component host ABI `greentic:component-v1/component-host@0.1.0`.
204#[cfg(feature = "component-v1")]
205pub mod component_v1 {
206    pub use crate::bindings::greentic_component_v1_0_1_0_component_host::exports::greentic::component_v1::*;
207    #[cfg(not(target_arch = "wasm32"))]
208    pub use greentic_interfaces::mappers::{ComponentOutcome, ComponentOutcomeStatus};
209}
210
211/// Lifecycle hooks for `greentic:lifecycle/component-lifecycle@1.0.0`.
212#[cfg(feature = "lifecycle")]
213pub mod lifecycle {
214    pub use crate::bindings::greentic_lifecycle_1_0_0_component_lifecycle::exports::greentic::lifecycle::*;
215}
216
217/// Secret store imports for `greentic:secrets-store/store@1.0.0`.
218#[cfg(feature = "secrets")]
219pub mod secrets_store {
220    pub use crate::bindings::greentic_secrets_store_1_0_0_store::greentic::secrets_store::secrets_store::*;
221}
222
223// Legacy secrets provider protocol removed; use provider-core instead.
224
225/// Provider core schema exports for `greentic:provider-schema-core@1.0.0`.
226#[cfg(feature = "provider-core-v1")]
227pub mod provider_core {
228    pub use crate::bindings::greentic_provider_schema_core_1_0_0_schema_core::exports::greentic::provider_schema_core::schema_core_api::*;
229}
230
231/// Operator hook-provider exports for `greentic:operator/hook-provider@1.0.0`.
232#[cfg(feature = "operator-hooks-v1")]
233pub mod operator_hooks {
234    pub use crate::bindings::greentic_operator_1_0_0_hook_provider::exports::greentic::operator::hook_api::*;
235}
236
237/// Shared messaging provider metadata/render helpers `provider:common/common@0.0.2`.
238#[cfg(feature = "provider-common")]
239pub mod provider_common {
240    pub use crate::bindings::provider_common_0_0_2_common::exports::provider::common::capabilities::*;
241    pub use crate::bindings::provider_common_0_0_2_common::exports::provider::common::render::*;
242}
243
244/// State store imports for `greentic:state/store@1.0.0`.
245#[cfg(feature = "state-store")]
246pub mod state_store {
247    pub use crate::bindings::greentic_state_1_0_0_store::greentic::state::state_store::*;
248}
249
250/// HTTP client imports for `greentic:http/client@1.0.0`.
251#[cfg(feature = "http-client")]
252pub mod http_client {
253    pub use crate::bindings::greentic_http_1_0_0_client::greentic::http::http_client::*;
254}
255
256/// HTTP client imports for `greentic:http/client@1.1.0`.
257#[cfg(feature = "http-client-v1-1")]
258pub mod http_client_v1_1 {
259    pub use crate::bindings::greentic_http_1_1_0_client::greentic::http::http_client::*;
260}
261
262/// Telemetry logger imports for `greentic:telemetry/logger@1.0.0`.
263#[cfg(feature = "telemetry")]
264pub mod telemetry_logger {
265    pub use crate::bindings::greentic_telemetry_1_0_0_logger::greentic::telemetry::logger_api::*;
266}
267
268/// OAuth broker imports for `greentic:oauth-broker/broker@1.0.0`.
269#[cfg(feature = "oauth-broker")]
270pub mod oauth_broker {
271    pub use crate::bindings::greentic_oauth_broker_1_0_0_broker::exports::greentic::oauth_broker::broker_v1::*;
272}
273
274/// OAuth broker client imports for `greentic:oauth-broker/broker-client@1.0.0`.
275#[cfg(feature = "oauth-broker")]
276pub mod oauth_broker_client {
277    pub use crate::bindings::greentic_oauth_broker_1_0_0_broker_client::greentic::oauth_broker::broker_v1::*;
278}
279
280/// Generic worker world `greentic:worker/worker@1.0.0`.
281#[cfg(feature = "worker")]
282pub mod worker {
283    pub use crate::bindings::greentic_worker_1_0_0_worker::exports::greentic::worker::worker_api::*;
284}
285
286/// GUI fragment world `greentic:gui/gui-fragment@1.0.0`.
287#[cfg(feature = "gui-fragment")]
288pub mod gui_fragment {
289    pub use crate::bindings::greentic_gui_1_0_0_gui_fragment::exports::greentic::gui::fragment_api::*;
290}
291
292/// Pack validator world `greentic:pack-validate/pack-validator@0.1.0`.
293#[cfg(feature = "pack-validate")]
294pub mod pack_validate {
295    pub use crate::bindings::greentic_pack_validate_0_1_0_pack_validator::exports::greentic::pack_validate::validator::*;
296}
297
298/// Provisioning world `greentic:provision/provision-runner@0.1.0`.
299#[cfg(feature = "provision")]
300pub mod provision {
301    pub use crate::bindings::greentic_provision_0_1_0_provision_runner::exports::greentic::provision::provisioner::*;
302}
303
304/// Pack metadata/flow discovery worlds.
305#[cfg(feature = "pack-export-v1")]
306pub mod pack_exports {
307    /// Pack host metadata world `greentic:pack-export-v1/pack-host@0.1.0`.
308    #[cfg(feature = "pack-export-v1")]
309    pub mod v1 {
310        pub use crate::bindings::greentic_pack_export_v1_0_1_0_pack_host::exports::greentic::pack_export_v1::*;
311        #[cfg(not(target_arch = "wasm32"))]
312        pub use greentic_interfaces::mappers::{
313            FlowDescriptor as GuestFlowDescriptor, PackDescriptor as GuestPackDescriptor,
314        };
315    }
316}
317
318/// Supply-chain provider contracts implemented by components.
319#[cfg(any(
320    feature = "repo",
321    feature = "build",
322    feature = "scan",
323    feature = "signing",
324    feature = "attestation",
325    feature = "policy",
326    feature = "metadata",
327    feature = "oci"
328))]
329pub mod supply_chain {
330    /// Source provider world `greentic:source/source-sync@1.0.0`.
331    #[cfg(feature = "repo")]
332    pub mod source {
333        pub use crate::bindings::greentic_source_1_0_0_source_sync::exports::greentic::source::source_api::*;
334    }
335    /// Build provider world `greentic:build/builder@1.0.0`.
336    #[cfg(feature = "build")]
337    pub mod build {
338        pub use crate::bindings::greentic_build_1_0_0_builder::exports::greentic::build::builder_api::*;
339    }
340    /// Scanner world `greentic:scan/scanner@1.0.0`.
341    #[cfg(feature = "scan")]
342    pub mod scan {
343        pub use crate::bindings::greentic_scan_1_0_0_scanner::exports::greentic::scan::scanner_api::*;
344    }
345    /// Signing world `greentic:signing/signer@1.0.0`.
346    #[cfg(feature = "signing")]
347    pub mod signing {
348        pub use crate::bindings::greentic_signing_1_0_0_signer::exports::greentic::signing::signer_api::*;
349    }
350    /// Attestation world `greentic:attestation/attester@1.0.0`.
351    #[cfg(feature = "attestation")]
352    pub mod attestation {
353        pub use crate::bindings::greentic_attestation_1_0_0_attester::exports::greentic::attestation::attester_api::*;
354    }
355    /// Policy evaluation world `greentic:policy/policy-evaluator@1.0.0`.
356    #[cfg(feature = "policy")]
357    pub mod policy {
358        pub use crate::bindings::greentic_policy_1_0_0_policy_evaluator::exports::greentic::policy::policy_api::*;
359    }
360    /// Metadata store world `greentic:metadata/metadata-store@1.0.0`.
361    #[cfg(feature = "metadata")]
362    pub mod metadata {
363        pub use crate::bindings::greentic_metadata_1_0_0_metadata_store::exports::greentic::metadata::metadata_api::*;
364    }
365    /// OCI distribution world `greentic:oci/oci-distribution@1.0.0`.
366    #[cfg(feature = "oci")]
367    pub mod oci {
368        pub use crate::bindings::greentic_oci_1_0_0_oci_distribution::exports::greentic::oci::oci_api::*;
369    }
370}
371
372/// Desired state distribution API (experimental).
373#[cfg(feature = "distribution")]
374pub mod distribution {
375    pub use crate::bindings::greentic_distribution_1_0_0_distribution::exports::greentic::distribution::distribution_api::*;
376}
377
378/// Distributor API for resolving pack components (active).
379#[cfg(any(feature = "distributor-api", feature = "distributor-api-imports"))]
380pub mod distributor_api {
381    #[cfg(feature = "distributor-api")]
382    pub use crate::bindings::greentic_distributor_api_1_0_0_distributor_api::exports::greentic::distributor_api::distributor::*;
383
384    /// Raw imports generated from `greentic:distributor-api@1.0.0`.
385    #[cfg(feature = "distributor-api-imports")]
386    pub mod imports {
387        pub use crate::bindings::greentic_distributor_api_1_0_0_distributor_api_imports::greentic::distributor_api::distributor::*;
388    }
389
390    /// Convenience wrapper around the distributor imports.
391    #[cfg(feature = "distributor-api-imports")]
392    pub use crate::distributor_api_imports::DistributorApiImports;
393}
394
395/// Distributor API for resolving pack components (ref-based v1.1).
396#[cfg(any(
397    feature = "distributor-api-v1-1",
398    feature = "distributor-api-v1-1-imports"
399))]
400pub mod distributor_api_v1_1 {
401    #[cfg(feature = "distributor-api-v1-1")]
402    pub use crate::bindings::greentic_distributor_api_1_1_0_distributor_api::exports::greentic::distributor_api::distributor::*;
403
404    /// Raw imports generated from `greentic:distributor-api@1.1.0`.
405    #[cfg(feature = "distributor-api-v1-1-imports")]
406    pub mod imports {
407        pub use crate::bindings::greentic_distributor_api_1_1_0_distributor_api_imports::greentic::distributor_api::distributor::*;
408    }
409
410    /// Convenience wrapper around the distributor imports.
411    #[cfg(feature = "distributor-api-v1-1-imports")]
412    pub use crate::distributor_api_imports_v1_1::DistributorApiImportsV1_1;
413}
414
415/// MCP router exports for multiple protocol snapshots.
416#[cfg(any(
417    feature = "wasix-mcp-24-11-05-guest",
418    feature = "wasix-mcp-25-03-26-guest",
419    feature = "wasix-mcp-25-06-18-guest"
420))]
421pub mod mcp {
422    /// `wasix:mcp@24.11.5` snapshot (2024-11-05 spec).
423    #[cfg(feature = "wasix-mcp-24-11-05-guest")]
424    pub mod v24_11_05 {
425        pub use crate::bindings::wasix_mcp_24_11_5_mcp_router::exports::wasix::mcp::router::*;
426    }
427
428    /// `wasix:mcp@25.3.26` snapshot with annotations/audio/completions/progress.
429    #[cfg(feature = "wasix-mcp-25-03-26-guest")]
430    pub mod v25_03_26 {
431        pub use crate::bindings::wasix_mcp_25_3_26_mcp_router::exports::wasix::mcp::router::*;
432    }
433
434    /// `wasix:mcp@25.6.18` snapshot with structured output/resources/elicitation.
435    #[cfg(feature = "wasix-mcp-25-06-18-guest")]
436    pub mod v25_06_18 {
437        pub use crate::bindings::wasix_mcp_25_6_18_mcp_router::exports::wasix::mcp::router::*;
438    }
439}
440
441/// UI action handler world `greentic:repo-ui-actions/repo-ui-worker@1.0.0`.
442#[cfg(feature = "repo-ui-actions")]
443pub mod repo_ui_actions {
444    pub use crate::bindings::greentic_repo_ui_actions_1_0_0_repo_ui_worker::exports::greentic::repo_ui_actions::ui_action_api::*;
445}
446
447/// Stable alias for OAuth broker imports.
448#[cfg(feature = "oauth-broker")]
449pub mod oauth {
450    pub use super::oauth_broker::*;
451}