greentic_interfaces_host/
lib.rs1#![deny(unsafe_code)]
2#![warn(missing_docs, clippy::unwrap_used, clippy::expect_used)]
3#[cfg(target_arch = "wasm32")]
6compile_error!("greentic-interfaces-host is intended for native host targets.");
7
8pub use greentic_interfaces::{bindings, mappers, validate};
9
10pub mod component {
12 pub mod v0_5 {
14 pub use greentic_interfaces::component_v0_5::*;
15 }
16 pub mod v0_5_configurable {
18 pub use greentic_interfaces::component_configurable_v0_5::*;
19 }
20 pub mod v0_4 {
22 pub use greentic_interfaces::component_v0_4::*;
23 }
24 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 pub mod describe_v1 {
32 pub use greentic_interfaces::component_describe_v1::*;
33 }
34 pub mod lifecycle_v1 {
36 pub use greentic_interfaces::component_lifecycle_v1::*;
37 }
38}
39
40pub mod runner_host_v1 {
42 pub use greentic_interfaces::runner_host_v1::*;
43}
44
45pub mod pack_exports {
47 pub mod v0_2 {
49 pub use greentic_interfaces::pack_export_v0_2::*;
50 }
51 pub mod v0_4 {
53 pub use greentic_interfaces::pack_export_v0_4::*;
54 }
55 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
64pub mod types {
66 pub mod common_v0_1 {
68 pub use greentic_interfaces::common_types_v0_1::*;
69 }
70 pub mod events_v1 {
72 pub use greentic_interfaces::events_v1::*;
73 }
74 pub mod types_core_v0_2 {
76 pub use greentic_interfaces::types_core_v0_2::*;
77 }
78 pub mod types_core_v0_4 {
80 pub use greentic_interfaces::types_core_v0_4::*;
81 }
82}
83
84pub mod secrets {
86 pub mod store_v1 {
88 pub use greentic_interfaces::secrets_store_v1::*;
89 }
90}
91
92pub mod state {
94 pub use greentic_interfaces::state_store_v1::*;
95}
96
97pub mod messaging_session {
99 pub use greentic_interfaces::messaging_session_v1::*;
100}
101
102pub mod events_broker {
104 pub use greentic_interfaces::events_broker_v1::*;
105}
106
107pub mod events_source {
109 pub use greentic_interfaces::events_source_v1::*;
110}
111
112pub mod events_sink {
114 pub use greentic_interfaces::events_sink_v1::*;
115}
116
117pub mod events_bridge {
119 pub use greentic_interfaces::events_bridge_event_to_message_v1::EventToMessageBridge;
120 pub use greentic_interfaces::events_bridge_message_to_event_v1::MessageToEventBridge;
121
122 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;
123 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;
124}
125
126pub mod http_client {
128 pub use greentic_interfaces::http_client_v1::*;
130
131 pub mod v1_1 {
133 pub use greentic_interfaces::http_client_v1_1::*;
134 }
135}
136
137pub mod telemetry {
139 pub use greentic_interfaces::telemetry_logger_v1::*;
140}
141
142#[cfg(feature = "oauth-broker-v1")]
144pub mod oauth_broker {
145 pub use greentic_interfaces::oauth_broker_v1::*;
146}
147
148#[cfg(feature = "oauth-broker-v1")]
150pub mod oauth_broker_client {
151 pub use greentic_interfaces::oauth_broker_client_v1::*;
152}
153
154#[cfg(feature = "worker-v1")]
156pub mod worker {
157 use greentic_interfaces::bindings::greentic::interfaces_types::types as interfaces_types;
158 use greentic_interfaces::worker_v1::exports::greentic::worker::worker_api::{
159 TenantCtx as WitWorkerTenantCtx, WorkerMessage as WitWorkerMessage,
160 WorkerRequest as WitWorkerRequest, WorkerResponse as WitWorkerResponse,
161 };
162 use greentic_interfaces::worker_v1::greentic::types_core::types::{
163 Cloud, DeploymentCtx, Platform,
164 };
165 use greentic_types::{ErrorCode, GreenticError, TenantCtx};
166 use serde::{Deserialize, Serialize};
167 use serde_json::Value;
168
169 pub use greentic_interfaces::worker_v1::*;
170
171 type MapperResult<T> = Result<T, GreenticError>;
172
173 fn to_worker_tenant(ctx: TenantCtx) -> MapperResult<WitWorkerTenantCtx> {
174 let base = crate::mappers::tenant_ctx_to_wit(ctx)?;
175 Ok(WitWorkerTenantCtx {
176 tenant: base.tenant,
177 team: base.team,
178 user: base.user,
179 deployment: DeploymentCtx {
180 cloud: Cloud::Other,
181 region: None,
182 platform: Platform::Other,
183 runtime: None,
184 },
185 trace_id: base.trace_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 base = interfaces_types::TenantCtx {
195 env: "unknown".to_string(),
196 tenant: ctx.tenant.clone(),
197 tenant_id: ctx.tenant,
198 team: ctx.team.clone(),
199 team_id: ctx.team,
200 user: ctx.user.clone(),
201 user_id: ctx.user,
202 trace_id: ctx.trace_id,
203 correlation_id: None,
204 session_id: ctx.session_id,
205 flow_id: ctx.flow_id,
206 node_id: ctx.node_id,
207 provider_id: ctx.provider_id,
208 deadline_ms: None,
209 attempt: 0,
210 idempotency_key: None,
211 impersonation: None,
212 attributes: Vec::new(),
213 };
214 crate::mappers::tenant_ctx_from_wit(base)
215 }
216
217 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
219 pub struct HostWorkerRequest {
220 pub version: String,
222 pub tenant: TenantCtx,
224 pub worker_id: String,
226 pub payload: Value,
228 pub timestamp_utc: String,
230 pub correlation_id: Option<String>,
232 pub session_id: Option<String>,
234 pub thread_id: Option<String>,
236 }
237
238 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
240 pub struct HostWorkerMessage {
241 pub kind: String,
243 pub payload: Value,
245 }
246
247 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
249 pub struct HostWorkerResponse {
250 pub version: String,
252 pub tenant: TenantCtx,
254 pub worker_id: String,
256 pub timestamp_utc: String,
258 pub messages: Vec<HostWorkerMessage>,
260 pub correlation_id: Option<String>,
262 pub session_id: Option<String>,
264 pub thread_id: Option<String>,
266 }
267
268 impl TryFrom<HostWorkerMessage> for WitWorkerMessage {
269 type Error = GreenticError;
270
271 fn try_from(value: HostWorkerMessage) -> MapperResult<Self> {
272 let payload_json = serde_json::to_string(&value.payload)
273 .map_err(|err| GreenticError::new(ErrorCode::InvalidInput, err.to_string()))?;
274 Ok(Self {
275 kind: value.kind,
276 payload_json,
277 })
278 }
279 }
280
281 impl TryFrom<WitWorkerMessage> for HostWorkerMessage {
282 type Error = GreenticError;
283
284 fn try_from(value: WitWorkerMessage) -> MapperResult<Self> {
285 let payload = serde_json::from_str(&value.payload_json).map_err(|err| {
286 GreenticError::new(
287 ErrorCode::InvalidInput,
288 format!("invalid worker payload: {err}"),
289 )
290 })?;
291 Ok(Self {
292 kind: value.kind,
293 payload,
294 })
295 }
296 }
297
298 impl TryFrom<HostWorkerRequest> for WitWorkerRequest {
299 type Error = GreenticError;
300
301 fn try_from(value: HostWorkerRequest) -> MapperResult<Self> {
302 let payload_json = serde_json::to_string(&value.payload)
303 .map_err(|err| GreenticError::new(ErrorCode::InvalidInput, err.to_string()))?;
304 Ok(Self {
305 version: value.version,
306 tenant: to_worker_tenant(value.tenant)?,
307 worker_id: value.worker_id,
308 correlation_id: value.correlation_id,
309 session_id: value.session_id,
310 thread_id: value.thread_id,
311 payload_json,
312 timestamp_utc: value.timestamp_utc,
313 })
314 }
315 }
316
317 impl TryFrom<WitWorkerRequest> for HostWorkerRequest {
318 type Error = GreenticError;
319
320 fn try_from(value: WitWorkerRequest) -> MapperResult<Self> {
321 let payload: Value = serde_json::from_str(&value.payload_json).map_err(|err| {
322 GreenticError::new(
323 ErrorCode::InvalidInput,
324 format!("invalid worker payload: {err}"),
325 )
326 })?;
327 Ok(Self {
328 version: value.version,
329 tenant: from_worker_tenant(value.tenant)?,
330 worker_id: value.worker_id,
331 correlation_id: value.correlation_id,
332 session_id: value.session_id,
333 thread_id: value.thread_id,
334 payload,
335 timestamp_utc: value.timestamp_utc,
336 })
337 }
338 }
339
340 impl TryFrom<HostWorkerResponse> for WitWorkerResponse {
341 type Error = GreenticError;
342
343 fn try_from(value: HostWorkerResponse) -> MapperResult<Self> {
344 let messages = value
345 .messages
346 .into_iter()
347 .map(WitWorkerMessage::try_from)
348 .collect::<MapperResult<Vec<_>>>()?;
349 Ok(Self {
350 version: value.version,
351 tenant: to_worker_tenant(value.tenant)?,
352 worker_id: value.worker_id,
353 correlation_id: value.correlation_id,
354 session_id: value.session_id,
355 thread_id: value.thread_id,
356 messages,
357 timestamp_utc: value.timestamp_utc,
358 })
359 }
360 }
361
362 impl TryFrom<WitWorkerResponse> for HostWorkerResponse {
363 type Error = GreenticError;
364
365 fn try_from(value: WitWorkerResponse) -> MapperResult<Self> {
366 let messages = value
367 .messages
368 .into_iter()
369 .map(HostWorkerMessage::try_from)
370 .collect::<MapperResult<Vec<_>>>()?;
371 Ok(Self {
372 version: value.version,
373 tenant: from_worker_tenant(value.tenant)?,
374 worker_id: value.worker_id,
375 correlation_id: value.correlation_id,
376 session_id: value.session_id,
377 thread_id: value.thread_id,
378 messages,
379 timestamp_utc: value.timestamp_utc,
380 })
381 }
382 }
383}
384
385#[cfg(feature = "gui-fragment")]
387pub mod gui_fragment {
388 pub use greentic_interfaces::bindings::greentic_gui_1_0_0_gui_fragment::exports::greentic::gui::fragment_api as bindings;
389 pub use bindings::FragmentContext;
390 pub use bindings::Guest as GuiFragment;
391}
392
393pub mod supply_chain {
395 pub mod source {
397 pub use greentic_interfaces::bindings::greentic_source_1_0_0_source_sync::exports::greentic::source::source_api::*;
398 }
399 pub mod build {
401 pub use greentic_interfaces::bindings::greentic_build_1_0_0_builder::exports::greentic::build::builder_api::*;
402 }
403 pub mod scan {
405 pub use greentic_interfaces::bindings::greentic_scan_1_0_0_scanner::exports::greentic::scan::scanner_api::*;
406 }
407 pub mod signing {
409 pub use greentic_interfaces::bindings::greentic_signing_1_0_0_signer::exports::greentic::signing::signer_api::*;
410 }
411 pub mod attestation {
413 pub use greentic_interfaces::bindings::greentic_attestation_1_0_0_attester::exports::greentic::attestation::attester_api::*;
414 }
415 pub mod policy {
417 pub use greentic_interfaces::bindings::greentic_policy_1_0_0_policy_evaluator::exports::greentic::policy::policy_api::*;
418 }
419 pub mod metadata {
421 pub use greentic_interfaces::bindings::greentic_metadata_1_0_0_metadata_store::exports::greentic::metadata::metadata_api::*;
422 }
423 pub mod oci {
425 pub use greentic_interfaces::bindings::greentic_oci_1_0_0_oci_distribution::exports::greentic::oci::oci_api::*;
426 }
427}
428
429pub mod distribution {
431 pub mod v1 {
433 pub use greentic_interfaces::bindings::greentic_distribution_1_0_0_distribution::exports::greentic::distribution::distribution_api::*;
434 }
435}
436
437pub mod distributor_api {
439 pub mod v1 {
441 pub use greentic_interfaces::bindings::greentic_distributor_api_1_0_0_distributor_api::exports::greentic::distributor_api::distributor::*;
442 }
443}
444
445pub mod messaging {
447 pub use super::messaging_session::*;
448}
449
450pub mod http {
452 pub use super::http_client::*;
453}
454
455#[cfg(feature = "oauth-broker-v1")]
457pub mod oauth {
458 pub use super::oauth_broker::*;
459}
460
461pub mod mcp {
463 #[cfg(feature = "wasix-mcp-24-11-05-host")]
465 pub mod v24_11_05 {
466 pub use greentic_interfaces::wasix_mcp_24_11_05::*;
467 }
468
469 #[cfg(feature = "wasix-mcp-25-03-26-host")]
471 pub mod v25_03_26 {
472 pub use greentic_interfaces::wasix_mcp_25_03_26::*;
473 }
474
475 #[cfg(feature = "wasix-mcp-25-06-18-host")]
477 pub mod v25_06_18 {
478 pub use greentic_interfaces::wasix_mcp_25_06_18::*;
479 }
480}
481
482pub mod ui_actions {
484 pub mod repo_ui_worker {
486 pub use greentic_interfaces::bindings::greentic_repo_ui_actions_1_0_0_repo_ui_worker::exports::greentic::repo_ui_actions::ui_action_api::*;
487 }
488}