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