greentic-interfaces-host 1.1.0-dev.26865554792

Host-facing bindings and mappers for Greentic WIT packages
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
#![deny(unsafe_code)]
#![warn(missing_docs, clippy::unwrap_used, clippy::expect_used)]
//! Host-facing bindings and mappers re-exported from `greentic-interfaces`.
//! `greentic:component@0.6.0` exports descriptor/schema/runtime/qa/i18n and is bound via
//! [`component_v0_6`].

#[cfg(target_arch = "wasm32")]
compile_error!("greentic-interfaces-host is intended for native host targets.");

pub use greentic_interfaces::{bindings, mappers, validate};

/// Host bindings for `greentic:component/component@0.6.0`.
pub mod component_v0_6 {
    pub use greentic_interfaces::component_v0_6::*;

    /// Back-compat alias for older host helper code/tests.
    pub type ComponentV0V6V0 = Component;
}

/// Component control and exports.
pub mod component {
    /// Component ABI with descriptor/schema/runtime/qa/i18n exports `greentic:component/component@0.6.0`.
    pub mod v0_6 {
        pub use greentic_interfaces::component_v0_6::*;
    }
    /// Generic component invocation world `greentic:component-v1/component-host@0.1.0`.
    pub mod v1 {
        pub use greentic_interfaces::component_v1::*;
        pub use greentic_interfaces::mappers::ComponentOutcome;
        pub use greentic_interfaces::mappers::ComponentOutcomeStatus;
    }
    /// Describe-only schema export world `greentic:component/component@1.0.0`.
    pub mod describe_v1 {
        pub use greentic_interfaces::component_describe_v1::*;
    }
    /// Lifecycle hooks world `greentic:lifecycle/component-lifecycle@1.0.0`.
    pub mod lifecycle_v1 {
        pub use greentic_interfaces::component_lifecycle_v1::*;
    }
}

/// Runner host bundle `greentic:host@1.0.0`.
pub mod runner_host_v1 {
    pub use greentic_interfaces::runner_host_v1::*;
}

/// Operator hook contracts `greentic:operator/hook-provider@1.0.0`.
pub mod operator_v1 {
    pub use greentic_interfaces::operator_hook_provider_v1::*;
}

/// Pack exporters.
pub mod pack_exports {
    /// Pack metadata/flow discovery world `greentic:pack-export-v1/pack-host@0.1.0`.
    pub mod v1 {
        pub use greentic_interfaces::mappers::{
            FlowDescriptor as HostFlowDescriptor, PackDescriptor as HostPackDescriptor,
        };
        pub use greentic_interfaces::pack_export_v1::*;
    }
}

/// Core types.
pub mod types {
    /// Shared flow/component fundamentals `greentic:common-types/common@0.1.0`.
    pub mod common_v0_1 {
        pub use greentic_interfaces::common_types_v0_1::*;
    }
}

/// v1 host capability contracts.
pub mod secrets {
    /// `greentic:secrets-store/store@1.0.0` host imports.
    pub mod store_v1 {
        pub use greentic_interfaces::secrets_store_v1::*;
    }
}

/// Provider core schema world `greentic:provider-schema-core@1.0.0`.
#[cfg(feature = "provider-core-v1")]
pub mod provider_core_v1 {
    pub use greentic_interfaces::provider_schema_core_v1::*;
}

/// Phase M1.4 — per-endpoint instance discrimination
/// (`greentic:provider-instance-identity@0.1.0`).
///
/// Sibling to [`provider_core_v1`]. Providers opt in by exporting this
/// world in addition to `schema-core` when one runtime must host multiple
/// instances of the same `provider_type` (e.g. `teams-legal-bot` and
/// `teams-accounting-bot`). The host probes for this export and falls
/// back to the operator's statically-declared `provider_id` when absent.
#[cfg(feature = "provider-instance-identity-v1")]
pub mod provider_instance_identity_v1 {
    pub use greentic_interfaces::provider_instance_identity_v1::*;
}

/// Phase D — optional describe-identify-instance metadata
/// (`greentic:provider-instance-identity/instance-identity-describe@0.1.0`).
///
/// Separated from [`provider_instance_identity_v1`] so existing components
/// that only export `instance-identity-api` are not broken. Components opt
/// in by additionally exporting `instance-identity-describe-api`.
#[cfg(feature = "provider-instance-identity-describe-v1")]
pub mod provider_instance_identity_describe_v1 {
    pub use greentic_interfaces::provider_instance_identity_describe_v1::*;
}

/// Shared messaging provider metadata/render helpers.
pub mod provider_common {
    pub use greentic_interfaces::bindings::provider_common_0_0_2_common::exports::provider::common::capabilities::*;
    pub use greentic_interfaces::bindings::provider_common_0_0_2_common::exports::provider::common::render::*;
}

/// v1 host capability contracts.
pub mod state {
    pub use greentic_interfaces::state_store_v1::*;
}

/// v1 host capability contracts.
pub mod http_client {
    /// `greentic:http/client@1.0.0` bindings.
    pub use greentic_interfaces::http_client_v1::*;

    /// `greentic:http/client@1.1.0` bindings with request options + tenant context.
    pub mod v1_1 {
        pub use greentic_interfaces::http_client_v1_1::*;
    }
}

/// v1 host capability contracts.
pub mod telemetry {
    pub use greentic_interfaces::telemetry_logger_v1::*;
}

/// v1 host capability contracts.
#[cfg(feature = "oauth-broker-v1")]
pub mod oauth_broker {
    pub use greentic_interfaces::oauth_broker_v1::*;
}

/// v1 OAuth broker client imports.
#[cfg(feature = "oauth-broker-v1")]
pub mod oauth_broker_client {
    pub use greentic_interfaces::oauth_broker_client_v1::*;
}

/// Generic worker ABI world.
#[cfg(feature = "worker-v1")]
pub mod worker {
    use greentic_interfaces::bindings::greentic::interfaces_types::types as interfaces_types;
    use greentic_interfaces::worker_v1::exports::greentic::worker::worker_api::{
        Cloud, DeploymentCtx, Platform, TenantCtx as WitWorkerTenantCtx,
        WorkerMessage as WitWorkerMessage, WorkerRequest as WitWorkerRequest,
        WorkerResponse as WitWorkerResponse,
    };
    use greentic_types::{ErrorCode, GreenticError, TenantCtx};
    use serde::{Deserialize, Serialize};
    use serde_json::Value;

    pub use greentic_interfaces::worker_v1::*;

    type MapperResult<T> = Result<T, GreenticError>;

    fn to_worker_tenant(ctx: TenantCtx) -> MapperResult<WitWorkerTenantCtx> {
        let base = crate::mappers::tenant_ctx_to_wit(ctx)?;
        Ok(WitWorkerTenantCtx {
            tenant: base.tenant,
            team: base.team,
            user: base.user,
            deployment: DeploymentCtx {
                cloud: Cloud::Other,
                region: None,
                platform: Platform::Other,
                runtime: None,
                i18n_id: base.i18n_id.clone(),
            },
            trace_id: base.trace_id,
            i18n_id: base.i18n_id,
            session_id: base.session_id,
            flow_id: base.flow_id,
            node_id: base.node_id,
            provider_id: base.provider_id,
        })
    }

    fn from_worker_tenant(ctx: WitWorkerTenantCtx) -> MapperResult<TenantCtx> {
        let team = ctx.team.clone();
        let user = ctx.user.clone();
        let base = interfaces_types::TenantCtx {
            env: "unknown".to_string(),
            tenant: ctx.tenant.clone(),
            tenant_id: ctx.tenant,
            team,
            team_id: ctx.team,
            user,
            user_id: ctx.user,
            trace_id: ctx.trace_id,
            i18n_id: ctx.i18n_id.or(ctx.deployment.i18n_id),
            correlation_id: None,
            session_id: ctx.session_id,
            flow_id: ctx.flow_id,
            node_id: ctx.node_id,
            provider_id: ctx.provider_id,
            deadline_ms: None,
            attempt: 0,
            idempotency_key: None,
            impersonation: None,
            attributes: Vec::new(),
        };
        crate::mappers::tenant_ctx_from_wit(base)
    }

    /// Host-friendly request wrapper for worker invocations (uses `greentic-types` and `serde_json` payloads).
    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
    pub struct HostWorkerRequest {
        /// ABI version identifier (e.g. "1.0").
        pub version: String,
        /// Shared tenant context from `greentic-types`.
        pub tenant: TenantCtx,
        /// Target worker identifier.
        pub worker_id: String,
        /// JSON payload for the worker.
        pub payload: Value,
        /// ISO8601 UTC timestamp of the request.
        pub timestamp_utc: String,
        /// Optional correlation identifier.
        pub correlation_id: Option<String>,
        /// Optional session identifier.
        pub session_id: Option<String>,
        /// Optional thread identifier.
        pub thread_id: Option<String>,
    }

    /// Host-friendly worker message envelope.
    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
    pub struct HostWorkerMessage {
        /// Message kind (e.g. "text", "card").
        pub kind: String,
        /// JSON payload content.
        pub payload: Value,
    }

    /// Host-friendly worker response wrapper with typed tenant context.
    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
    pub struct HostWorkerResponse {
        /// Mirrors the request version.
        pub version: String,
        /// Shared tenant context from `greentic-types`.
        pub tenant: TenantCtx,
        /// Worker identifier that produced the response.
        pub worker_id: String,
        /// ISO8601 UTC timestamp.
        pub timestamp_utc: String,
        /// Accumulated worker messages.
        pub messages: Vec<HostWorkerMessage>,
        /// Optional correlation identifier.
        pub correlation_id: Option<String>,
        /// Optional session identifier.
        pub session_id: Option<String>,
        /// Optional thread identifier.
        pub thread_id: Option<String>,
    }

    impl TryFrom<HostWorkerMessage> for WitWorkerMessage {
        type Error = GreenticError;

        fn try_from(value: HostWorkerMessage) -> MapperResult<Self> {
            let payload_json = serde_json::to_string(&value.payload)
                .map_err(|err| GreenticError::new(ErrorCode::InvalidInput, err.to_string()))?;
            Ok(Self {
                kind: value.kind,
                payload_json,
            })
        }
    }

    impl TryFrom<WitWorkerMessage> for HostWorkerMessage {
        type Error = GreenticError;

        fn try_from(value: WitWorkerMessage) -> MapperResult<Self> {
            let payload = serde_json::from_str(&value.payload_json).map_err(|err| {
                GreenticError::new(
                    ErrorCode::InvalidInput,
                    format!("invalid worker payload: {err}"),
                )
            })?;
            Ok(Self {
                kind: value.kind,
                payload,
            })
        }
    }

    impl TryFrom<HostWorkerRequest> for WitWorkerRequest {
        type Error = GreenticError;

        fn try_from(value: HostWorkerRequest) -> MapperResult<Self> {
            let payload_json = serde_json::to_string(&value.payload)
                .map_err(|err| GreenticError::new(ErrorCode::InvalidInput, err.to_string()))?;
            Ok(Self {
                version: value.version,
                tenant: to_worker_tenant(value.tenant)?,
                worker_id: value.worker_id,
                correlation_id: value.correlation_id,
                session_id: value.session_id,
                thread_id: value.thread_id,
                payload_json,
                timestamp_utc: value.timestamp_utc,
            })
        }
    }

    impl TryFrom<WitWorkerRequest> for HostWorkerRequest {
        type Error = GreenticError;

        fn try_from(value: WitWorkerRequest) -> MapperResult<Self> {
            let payload: Value = serde_json::from_str(&value.payload_json).map_err(|err| {
                GreenticError::new(
                    ErrorCode::InvalidInput,
                    format!("invalid worker payload: {err}"),
                )
            })?;
            Ok(Self {
                version: value.version,
                tenant: from_worker_tenant(value.tenant)?,
                worker_id: value.worker_id,
                correlation_id: value.correlation_id,
                session_id: value.session_id,
                thread_id: value.thread_id,
                payload,
                timestamp_utc: value.timestamp_utc,
            })
        }
    }

    impl TryFrom<HostWorkerResponse> for WitWorkerResponse {
        type Error = GreenticError;

        fn try_from(value: HostWorkerResponse) -> MapperResult<Self> {
            let messages = value
                .messages
                .into_iter()
                .map(WitWorkerMessage::try_from)
                .collect::<MapperResult<Vec<_>>>()?;
            Ok(Self {
                version: value.version,
                tenant: to_worker_tenant(value.tenant)?,
                worker_id: value.worker_id,
                correlation_id: value.correlation_id,
                session_id: value.session_id,
                thread_id: value.thread_id,
                messages,
                timestamp_utc: value.timestamp_utc,
            })
        }
    }

    impl TryFrom<WitWorkerResponse> for HostWorkerResponse {
        type Error = GreenticError;

        fn try_from(value: WitWorkerResponse) -> MapperResult<Self> {
            let messages = value
                .messages
                .into_iter()
                .map(HostWorkerMessage::try_from)
                .collect::<MapperResult<Vec<_>>>()?;
            Ok(Self {
                version: value.version,
                tenant: from_worker_tenant(value.tenant)?,
                worker_id: value.worker_id,
                correlation_id: value.correlation_id,
                session_id: value.session_id,
                thread_id: value.thread_id,
                messages,
                timestamp_utc: value.timestamp_utc,
            })
        }
    }
}

/// GUI fragment renderers implemented by components.
#[cfg(feature = "gui-fragment")]
pub mod gui_fragment {
    pub use greentic_interfaces::bindings::greentic_gui_1_0_0_gui_fragment::exports::greentic::gui::fragment_api as bindings;
    pub use bindings::FragmentContext;
    pub use bindings::Guest as GuiFragment;
}

/// Supply-chain provider contracts.
pub mod supply_chain {
    /// Source provider world `greentic:source/source-sync@1.0.0`.
    pub mod source {
        pub use greentic_interfaces::bindings::greentic_source_1_0_0_source_sync::exports::greentic::source::source_api::*;
    }
    /// Build provider world `greentic:build/builder@1.0.0`.
    pub mod build {
        pub use greentic_interfaces::bindings::greentic_build_1_0_0_builder::exports::greentic::build::builder_api::*;
    }
    /// Scanner world `greentic:scan/scanner@1.0.0`.
    pub mod scan {
        pub use greentic_interfaces::bindings::greentic_scan_1_0_0_scanner::exports::greentic::scan::scanner_api::*;
    }
    /// Signing world `greentic:signing/signer@1.0.0`.
    pub mod signing {
        pub use greentic_interfaces::bindings::greentic_signing_1_0_0_signer::exports::greentic::signing::signer_api::*;
    }
    /// Attestation world `greentic:attestation/attester@1.0.0`.
    pub mod attestation {
        pub use greentic_interfaces::bindings::greentic_attestation_1_0_0_attester::exports::greentic::attestation::attester_api::*;
    }
    /// Policy evaluation world `greentic:policy/policy-evaluator@1.0.0`.
    pub mod policy {
        pub use greentic_interfaces::bindings::greentic_policy_1_0_0_policy_evaluator::exports::greentic::policy::policy_api::*;
    }
    /// Metadata store world `greentic:metadata/metadata-store@1.0.0`.
    pub mod metadata {
        pub use greentic_interfaces::bindings::greentic_metadata_1_0_0_metadata_store::exports::greentic::metadata::metadata_api::*;
    }
    /// OCI distribution world `greentic:oci/oci-distribution@1.0.0`.
    pub mod oci {
        pub use greentic_interfaces::bindings::greentic_oci_1_0_0_oci_distribution::exports::greentic::oci::oci_api::*;
    }
}

/// Desired state distribution contracts.
pub mod distribution {
    /// `greentic:distribution/distribution@1.0.0`.
    pub mod v1 {
        pub use greentic_interfaces::bindings::greentic_distribution_1_0_0_distribution::exports::greentic::distribution::distribution_api::*;
    }
}

/// Distributor API contracts.
pub mod distributor_api {
    /// `greentic:distributor-api/distributor-api@1.0.0`.
    pub mod v1 {
        pub use greentic_interfaces::bindings::greentic_distributor_api_1_0_0_distributor_api::exports::greentic::distributor_api::distributor::*;
    }
    /// `greentic:distributor-api/distributor-api@1.1.0`.
    pub mod v1_1 {
        pub use greentic_interfaces::bindings::greentic_distributor_api_1_1_0_distributor_api::exports::greentic::distributor_api::distributor::*;
    }

    /// Resolved component metadata returned by a ref-based lookup.
    #[derive(Debug, Clone)]
    pub struct ResolvedComponent {
        /// Digest returned by the distributor (opaque string).
        pub digest: String,
        /// Metadata returned by `resolve-ref`.
        pub metadata: v1_1::ResolveRefMetadata,
    }

    /// Resolved component artifact content.
    #[derive(Debug, Clone, PartialEq)]
    pub enum ResolvedArtifact {
        /// Raw component bytes.
        Bytes(Vec<u8>),
        /// Filesystem path to the component.
        Path(String),
    }

    /// Host-side resolver for ref-based component lookup.
    pub trait ComponentResolver {
        /// Resolve a component reference string to a digest plus metadata.
        fn resolve_ref(&self, component_ref: &str) -> ResolvedComponent;

        /// Fetch a resolved component artifact by digest.
        fn fetch_digest(&self, digest: &str) -> ResolvedArtifact;
    }
}

/// Stable alias for HTTP client imports.
pub mod http {
    pub use super::http_client::*;
}

/// Stable alias for OAuth broker imports.
#[cfg(feature = "oauth-broker-v1")]
pub mod oauth {
    pub use super::oauth_broker::*;
}

/// MCP router surfaces (multiple protocol snapshots).
pub mod mcp {
    /// `wasix:mcp@24.11.5` snapshot (2024-11-05 spec).
    #[cfg(feature = "wasix-mcp-24-11-05-host")]
    pub mod v24_11_05 {
        pub use greentic_interfaces::wasix_mcp_24_11_05::*;
    }

    /// `wasix:mcp@25.3.26` snapshot with annotations/audio/completions/progress.
    #[cfg(feature = "wasix-mcp-25-03-26-host")]
    pub mod v25_03_26 {
        pub use greentic_interfaces::wasix_mcp_25_03_26::*;
    }

    /// `wasix:mcp@25.6.18` snapshot with structured output/resources/elicitation.
    #[cfg(feature = "wasix-mcp-25-06-18-host")]
    pub mod v25_06_18 {
        pub use greentic_interfaces::wasix_mcp_25_06_18::*;
    }
}

/// UI action handler contracts.
pub mod ui_actions {
    /// UI action handler world `greentic:repo-ui-actions/repo-ui-worker@1.0.0`.
    pub mod repo_ui_worker {
        pub use greentic_interfaces::bindings::greentic_repo_ui_actions_1_0_0_repo_ui_worker::exports::greentic::repo_ui_actions::ui_action_api::*;
    }
}