greentic_flow/
lib.rs

1//! Downstream runtimes must set the current tenant telemetry context via
2//! `greentic_types::telemetry::set_current_tenant_ctx` before executing flows
3//! (for example, prior to `FlowEngine::run` in the host runner).
4#![forbid(unsafe_code)]
5#![allow(clippy::result_large_err)]
6
7pub mod error;
8pub mod flow_bundle;
9pub mod ir;
10pub mod json_output;
11pub mod lint;
12pub mod loader;
13pub mod model;
14pub mod registry;
15pub mod resolve;
16pub mod util;
17
18pub use flow_bundle::{
19    ComponentPin, FlowBundle, NodeRef, blake3_hex, canonicalize_json, extract_component_pins,
20    load_and_validate_bundle, load_and_validate_bundle_with_ir,
21};
22pub use json_output::{JsonDiagnostic, LintJsonOutput, lint_to_stdout_json};
23
24use crate::{
25    error::Result,
26    ir::{FlowIR, NodeIR, RouteIR},
27    model::FlowDoc,
28};
29use indexmap::IndexMap;
30
31/// Convert a `FlowDoc` into its compact intermediate representation.
32pub fn to_ir(flow: FlowDoc) -> Result<FlowIR> {
33    let mut nodes: IndexMap<String, NodeIR> = IndexMap::new();
34    for (id, node) in flow.nodes {
35        nodes.insert(
36            id,
37            NodeIR {
38                component: node.component,
39                payload_expr: node.payload,
40                routes: node
41                    .routing
42                    .into_iter()
43                    .map(|route| RouteIR {
44                        to: route.to,
45                        out: route.out.unwrap_or(false),
46                    })
47                    .collect(),
48            },
49        );
50    }
51
52    Ok(FlowIR {
53        id: flow.id,
54        flow_type: flow.flow_type,
55        start: flow.start,
56        parameters: flow.parameters,
57        nodes,
58    })
59}