greentic_interfaces_host/
lib.rs1#![deny(unsafe_code)]
2#![warn(missing_docs, clippy::unwrap_used, clippy::expect_used)]
3#[cfg(target_arch = "wasm32")]
8compile_error!("greentic-interfaces-host is intended for native host targets.");
9
10pub use greentic_interfaces::{bindings, mappers, validate};
11
12pub mod component_v0_6 {
14 pub use greentic_interfaces::component_v0_6::*;
15
16 pub type ComponentV0V6V0 = Component;
18}
19
20pub mod component {
22 pub mod v0_6 {
24 pub use greentic_interfaces::component_v0_6::*;
25 }
26 pub mod v0_5 {
28 pub use greentic_interfaces::component_v0_5::*;
29 }
30 pub mod v0_5_configurable {
32 pub use greentic_interfaces::component_configurable_v0_5::*;
33 }
34 pub mod v0_4 {
36 pub use greentic_interfaces::component_v0_4::*;
37 }
38 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 pub mod describe_v1 {
46 pub use greentic_interfaces::component_describe_v1::*;
47 }
48 pub mod lifecycle_v1 {
50 pub use greentic_interfaces::component_lifecycle_v1::*;
51 }
52}
53
54pub mod runner_host_v1 {
56 pub use greentic_interfaces::runner_host_v1::*;
57}
58
59pub mod operator_v1 {
61 pub use greentic_interfaces::operator_hook_provider_v1::*;
62}
63
64pub mod pack_exports {
66 pub mod v0_2 {
68 pub use greentic_interfaces::pack_export_v0_2::*;
69 }
70 pub mod v0_4 {
72 pub use greentic_interfaces::pack_export_v0_4::*;
73 }
74 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
83pub mod types {
85 pub mod common_v0_1 {
87 pub use greentic_interfaces::common_types_v0_1::*;
88 }
89 pub mod types_core_v0_2 {
91 pub use greentic_interfaces::types_core_v0_2::*;
92 }
93 pub mod types_core_v0_4 {
95 pub use greentic_interfaces::types_core_v0_4::*;
96 }
97}
98
99pub mod secrets {
101 pub mod store_v1 {
103 pub use greentic_interfaces::secrets_store_v1::*;
104 }
105}
106
107#[cfg(feature = "provider-core-v1")]
109pub mod provider_core_v1 {
110 pub use greentic_interfaces::provider_schema_core_v1::*;
111}
112
113pub 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
119pub mod state {
121 pub use greentic_interfaces::state_store_v1::*;
122}
123
124pub mod http_client {
126 pub use greentic_interfaces::http_client_v1::*;
128
129 pub mod v1_1 {
131 pub use greentic_interfaces::http_client_v1_1::*;
132 }
133}
134
135pub mod telemetry {
137 pub use greentic_interfaces::telemetry_logger_v1::*;
138}
139
140#[cfg(feature = "oauth-broker-v1")]
142pub mod oauth_broker {
143 pub use greentic_interfaces::oauth_broker_v1::*;
144}
145
146#[cfg(feature = "oauth-broker-v1")]
148pub mod oauth_broker_client {
149 pub use greentic_interfaces::oauth_broker_client_v1::*;
150}
151
152#[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 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
222 pub struct HostWorkerRequest {
223 pub version: String,
225 pub tenant: TenantCtx,
227 pub worker_id: String,
229 pub payload: Value,
231 pub timestamp_utc: String,
233 pub correlation_id: Option<String>,
235 pub session_id: Option<String>,
237 pub thread_id: Option<String>,
239 }
240
241 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
243 pub struct HostWorkerMessage {
244 pub kind: String,
246 pub payload: Value,
248 }
249
250 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
252 pub struct HostWorkerResponse {
253 pub version: String,
255 pub tenant: TenantCtx,
257 pub worker_id: String,
259 pub timestamp_utc: String,
261 pub messages: Vec<HostWorkerMessage>,
263 pub correlation_id: Option<String>,
265 pub session_id: Option<String>,
267 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#[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
396pub mod supply_chain {
398 pub mod source {
400 pub use greentic_interfaces::bindings::greentic_source_1_0_0_source_sync::exports::greentic::source::source_api::*;
401 }
402 pub mod build {
404 pub use greentic_interfaces::bindings::greentic_build_1_0_0_builder::exports::greentic::build::builder_api::*;
405 }
406 pub mod scan {
408 pub use greentic_interfaces::bindings::greentic_scan_1_0_0_scanner::exports::greentic::scan::scanner_api::*;
409 }
410 pub mod signing {
412 pub use greentic_interfaces::bindings::greentic_signing_1_0_0_signer::exports::greentic::signing::signer_api::*;
413 }
414 pub mod attestation {
416 pub use greentic_interfaces::bindings::greentic_attestation_1_0_0_attester::exports::greentic::attestation::attester_api::*;
417 }
418 pub mod policy {
420 pub use greentic_interfaces::bindings::greentic_policy_1_0_0_policy_evaluator::exports::greentic::policy::policy_api::*;
421 }
422 pub mod metadata {
424 pub use greentic_interfaces::bindings::greentic_metadata_1_0_0_metadata_store::exports::greentic::metadata::metadata_api::*;
425 }
426 pub mod oci {
428 pub use greentic_interfaces::bindings::greentic_oci_1_0_0_oci_distribution::exports::greentic::oci::oci_api::*;
429 }
430}
431
432pub mod distribution {
434 pub mod v1 {
436 pub use greentic_interfaces::bindings::greentic_distribution_1_0_0_distribution::exports::greentic::distribution::distribution_api::*;
437 }
438}
439
440pub mod distributor_api {
442 pub mod v1 {
444 pub use greentic_interfaces::bindings::greentic_distributor_api_1_0_0_distributor_api::exports::greentic::distributor_api::distributor::*;
445 }
446 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 #[derive(Debug, Clone)]
453 pub struct ResolvedComponent {
454 pub digest: String,
456 pub metadata: v1_1::ResolveRefMetadata,
458 }
459
460 #[derive(Debug, Clone, PartialEq)]
462 pub enum ResolvedArtifact {
463 Bytes(Vec<u8>),
465 Path(String),
467 }
468
469 pub trait ComponentResolver {
471 fn resolve_ref(&self, component_ref: &str) -> ResolvedComponent;
473
474 fn fetch_digest(&self, digest: &str) -> ResolvedArtifact;
476 }
477}
478
479pub mod http {
481 pub use super::http_client::*;
482}
483
484#[cfg(feature = "oauth-broker-v1")]
486pub mod oauth {
487 pub use super::oauth_broker::*;
488}
489
490pub mod mcp {
492 #[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 #[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 #[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
511pub mod ui_actions {
513 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}