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 host_import {
42 pub mod v0_2 {
44 pub use greentic_interfaces::host_import_v0_2::*;
45 }
46 pub mod v0_4 {
48 pub use greentic_interfaces::host_import_v0_4::*;
49 }
50 pub mod v0_6 {
52 pub use greentic_interfaces::host_import_v0_6::*;
53 }
54 pub mod runner_host_v1 {
56 pub use greentic_interfaces::runner_host_v1::*;
57 }
58}
59
60pub mod pack_exports {
62 pub mod v0_2 {
64 pub use greentic_interfaces::pack_export_v0_2::*;
65 }
66 pub mod v0_4 {
68 pub use greentic_interfaces::pack_export_v0_4::*;
69 }
70 pub mod v1 {
72 pub use greentic_interfaces::mappers::{
73 FlowDescriptor as HostFlowDescriptor, PackDescriptor as HostPackDescriptor,
74 };
75 pub use greentic_interfaces::pack_export_v1::*;
76 }
77}
78
79pub mod types {
81 pub mod common_v0_1 {
83 pub use greentic_interfaces::common_types_v0_1::*;
84 }
85 pub mod events_v1 {
87 pub use greentic_interfaces::events_v1::*;
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 pub mod secrets_v0_1 {
107 pub use greentic_interfaces::secrets_v0_1::*;
108 }
109}
110
111pub mod state {
113 pub use greentic_interfaces::state_store_v1::*;
114}
115
116pub mod messaging_session {
118 pub use greentic_interfaces::messaging_session_v1::*;
119}
120
121pub mod events_broker {
123 pub use greentic_interfaces::events_broker_v1::*;
124}
125
126pub mod events_source {
128 pub use greentic_interfaces::events_source_v1::*;
129}
130
131pub mod events_sink {
133 pub use greentic_interfaces::events_sink_v1::*;
134}
135
136pub mod events_bridge {
138 pub use greentic_interfaces::events_bridge_event_to_message_v1::EventToMessageBridge;
139 pub use greentic_interfaces::events_bridge_message_to_event_v1::MessageToEventBridge;
140
141 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;
142 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;
143}
144
145pub mod http_client {
147 pub use greentic_interfaces::http_client_v1::*;
148}
149
150pub mod telemetry {
152 pub use greentic_interfaces::telemetry_logger_v1::*;
153}
154
155#[cfg(feature = "oauth-broker-v1")]
157pub mod oauth_broker {
158 pub use greentic_interfaces::oauth_broker_v1::*;
159}
160
161#[cfg(feature = "oauth-broker-v1")]
163pub mod oauth_broker_client {
164 pub use greentic_interfaces::oauth_broker_client_v1::*;
165}
166
167#[cfg(feature = "worker-v1")]
169pub mod worker {
170 use greentic_interfaces::bindings::greentic::interfaces_types::types as interfaces_types;
171 use greentic_interfaces::worker_v1::exports::greentic::worker::worker_api::{
172 TenantCtx as WitWorkerTenantCtx, WorkerMessage as WitWorkerMessage,
173 WorkerRequest as WitWorkerRequest, WorkerResponse as WitWorkerResponse,
174 };
175 use greentic_interfaces::worker_v1::greentic::types_core::types::{
176 Cloud, DeploymentCtx, Platform,
177 };
178 use greentic_types::{ErrorCode, GreenticError, TenantCtx};
179 use serde::{Deserialize, Serialize};
180 use serde_json::Value;
181
182 pub use greentic_interfaces::worker_v1::*;
183
184 type MapperResult<T> = Result<T, GreenticError>;
185
186 fn to_worker_tenant(ctx: TenantCtx) -> MapperResult<WitWorkerTenantCtx> {
187 let base = crate::mappers::tenant_ctx_to_wit(ctx)?;
188 Ok(WitWorkerTenantCtx {
189 tenant: base.tenant,
190 team: base.team,
191 user: base.user,
192 deployment: DeploymentCtx {
193 cloud: Cloud::Other,
194 region: None,
195 platform: Platform::Other,
196 runtime: None,
197 },
198 trace_id: base.trace_id,
199 session_id: base.session_id,
200 flow_id: base.flow_id,
201 node_id: base.node_id,
202 provider_id: base.provider_id,
203 })
204 }
205
206 fn from_worker_tenant(ctx: WitWorkerTenantCtx) -> MapperResult<TenantCtx> {
207 let base = interfaces_types::TenantCtx {
208 env: "unknown".to_string(),
209 tenant: ctx.tenant.clone(),
210 tenant_id: ctx.tenant,
211 team: ctx.team.clone(),
212 team_id: ctx.team,
213 user: ctx.user.clone(),
214 user_id: ctx.user,
215 trace_id: ctx.trace_id,
216 correlation_id: None,
217 session_id: ctx.session_id,
218 flow_id: ctx.flow_id,
219 node_id: ctx.node_id,
220 provider_id: ctx.provider_id,
221 deadline_ms: None,
222 attempt: 0,
223 idempotency_key: None,
224 impersonation: None,
225 attributes: Vec::new(),
226 };
227 crate::mappers::tenant_ctx_from_wit(base)
228 }
229
230 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
232 pub struct HostWorkerRequest {
233 pub version: String,
235 pub tenant: TenantCtx,
237 pub worker_id: String,
239 pub payload: Value,
241 pub timestamp_utc: String,
243 pub correlation_id: Option<String>,
245 pub session_id: Option<String>,
247 pub thread_id: Option<String>,
249 }
250
251 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
253 pub struct HostWorkerMessage {
254 pub kind: String,
256 pub payload: Value,
258 }
259
260 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
262 pub struct HostWorkerResponse {
263 pub version: String,
265 pub tenant: TenantCtx,
267 pub worker_id: String,
269 pub timestamp_utc: String,
271 pub messages: Vec<HostWorkerMessage>,
273 pub correlation_id: Option<String>,
275 pub session_id: Option<String>,
277 pub thread_id: Option<String>,
279 }
280
281 impl TryFrom<HostWorkerMessage> for WitWorkerMessage {
282 type Error = GreenticError;
283
284 fn try_from(value: HostWorkerMessage) -> MapperResult<Self> {
285 let payload_json = serde_json::to_string(&value.payload)
286 .map_err(|err| GreenticError::new(ErrorCode::InvalidInput, err.to_string()))?;
287 Ok(Self {
288 kind: value.kind,
289 payload_json,
290 })
291 }
292 }
293
294 impl TryFrom<WitWorkerMessage> for HostWorkerMessage {
295 type Error = GreenticError;
296
297 fn try_from(value: WitWorkerMessage) -> MapperResult<Self> {
298 let payload = serde_json::from_str(&value.payload_json).map_err(|err| {
299 GreenticError::new(
300 ErrorCode::InvalidInput,
301 format!("invalid worker payload: {err}"),
302 )
303 })?;
304 Ok(Self {
305 kind: value.kind,
306 payload,
307 })
308 }
309 }
310
311 impl TryFrom<HostWorkerRequest> for WitWorkerRequest {
312 type Error = GreenticError;
313
314 fn try_from(value: HostWorkerRequest) -> MapperResult<Self> {
315 let payload_json = serde_json::to_string(&value.payload)
316 .map_err(|err| GreenticError::new(ErrorCode::InvalidInput, err.to_string()))?;
317 Ok(Self {
318 version: value.version,
319 tenant: to_worker_tenant(value.tenant)?,
320 worker_id: value.worker_id,
321 correlation_id: value.correlation_id,
322 session_id: value.session_id,
323 thread_id: value.thread_id,
324 payload_json,
325 timestamp_utc: value.timestamp_utc,
326 })
327 }
328 }
329
330 impl TryFrom<WitWorkerRequest> for HostWorkerRequest {
331 type Error = GreenticError;
332
333 fn try_from(value: WitWorkerRequest) -> MapperResult<Self> {
334 let payload: Value = serde_json::from_str(&value.payload_json).map_err(|err| {
335 GreenticError::new(
336 ErrorCode::InvalidInput,
337 format!("invalid worker payload: {err}"),
338 )
339 })?;
340 Ok(Self {
341 version: value.version,
342 tenant: from_worker_tenant(value.tenant)?,
343 worker_id: value.worker_id,
344 correlation_id: value.correlation_id,
345 session_id: value.session_id,
346 thread_id: value.thread_id,
347 payload,
348 timestamp_utc: value.timestamp_utc,
349 })
350 }
351 }
352
353 impl TryFrom<HostWorkerResponse> for WitWorkerResponse {
354 type Error = GreenticError;
355
356 fn try_from(value: HostWorkerResponse) -> MapperResult<Self> {
357 let messages = value
358 .messages
359 .into_iter()
360 .map(WitWorkerMessage::try_from)
361 .collect::<MapperResult<Vec<_>>>()?;
362 Ok(Self {
363 version: value.version,
364 tenant: to_worker_tenant(value.tenant)?,
365 worker_id: value.worker_id,
366 correlation_id: value.correlation_id,
367 session_id: value.session_id,
368 thread_id: value.thread_id,
369 messages,
370 timestamp_utc: value.timestamp_utc,
371 })
372 }
373 }
374
375 impl TryFrom<WitWorkerResponse> for HostWorkerResponse {
376 type Error = GreenticError;
377
378 fn try_from(value: WitWorkerResponse) -> MapperResult<Self> {
379 let messages = value
380 .messages
381 .into_iter()
382 .map(HostWorkerMessage::try_from)
383 .collect::<MapperResult<Vec<_>>>()?;
384 Ok(Self {
385 version: value.version,
386 tenant: from_worker_tenant(value.tenant)?,
387 worker_id: value.worker_id,
388 correlation_id: value.correlation_id,
389 session_id: value.session_id,
390 thread_id: value.thread_id,
391 messages,
392 timestamp_utc: value.timestamp_utc,
393 })
394 }
395 }
396}
397
398#[cfg(feature = "gui-fragment")]
400pub mod gui_fragment {
401 pub use greentic_interfaces::bindings::greentic_gui_1_0_0_gui_fragment::exports::greentic::gui::fragment_api as bindings;
402 pub use bindings::FragmentContext;
403 pub use bindings::Guest as GuiFragment;
404}
405
406pub mod supply_chain {
408 pub mod source {
410 pub use greentic_interfaces::bindings::greentic_source_1_0_0_source_sync::exports::greentic::source::source_api::*;
411 }
412 pub mod build {
414 pub use greentic_interfaces::bindings::greentic_build_1_0_0_builder::exports::greentic::build::builder_api::*;
415 }
416 pub mod scan {
418 pub use greentic_interfaces::bindings::greentic_scan_1_0_0_scanner::exports::greentic::scan::scanner_api::*;
419 }
420 pub mod signing {
422 pub use greentic_interfaces::bindings::greentic_signing_1_0_0_signer::exports::greentic::signing::signer_api::*;
423 }
424 pub mod attestation {
426 pub use greentic_interfaces::bindings::greentic_attestation_1_0_0_attester::exports::greentic::attestation::attester_api::*;
427 }
428 pub mod policy {
430 pub use greentic_interfaces::bindings::greentic_policy_1_0_0_policy_evaluator::exports::greentic::policy::policy_api::*;
431 }
432 pub mod metadata {
434 pub use greentic_interfaces::bindings::greentic_metadata_1_0_0_metadata_store::exports::greentic::metadata::metadata_api::*;
435 }
436 pub mod oci {
438 pub use greentic_interfaces::bindings::greentic_oci_1_0_0_oci_distribution::exports::greentic::oci::oci_api::*;
439 }
440}
441
442pub mod distribution {
444 pub mod v1 {
446 pub use greentic_interfaces::bindings::greentic_distribution_1_0_0_distribution::exports::greentic::distribution::distribution_api::*;
447 }
448}
449
450pub mod distributor_api {
452 pub mod v1 {
454 pub use greentic_interfaces::bindings::greentic_distributor_api_1_0_0_distributor_api::exports::greentic::distributor_api::distributor::*;
455 }
456}
457
458pub mod messaging {
460 pub use super::messaging_session::*;
461}
462
463pub mod http {
465 pub use super::http_client::*;
466}
467
468#[cfg(feature = "oauth-broker-v1")]
470pub mod oauth {
471 pub use super::oauth_broker::*;
472}
473
474pub mod mcp {
476 #[cfg(feature = "wasix-mcp-24-11-05-host")]
478 pub mod v24_11_05 {
479 pub use greentic_interfaces::wasix_mcp_24_11_05::*;
480 }
481
482 #[cfg(feature = "wasix-mcp-25-03-26-host")]
484 pub mod v25_03_26 {
485 pub use greentic_interfaces::wasix_mcp_25_03_26::*;
486 }
487
488 #[cfg(feature = "wasix-mcp-25-06-18-host")]
490 pub mod v25_06_18 {
491 pub use greentic_interfaces::wasix_mcp_25_06_18::*;
492 }
493}
494
495pub mod ui_actions {
497 pub mod repo_ui_worker {
499 pub use greentic_interfaces::bindings::greentic_repo_ui_actions_1_0_0_repo_ui_worker::exports::greentic::repo_ui_actions::ui_action_api::*;
500 }
501}