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 config_flow;
8pub mod error;
9pub mod flow_bundle;
10pub mod ir;
11pub mod json_output;
12pub mod lint;
13pub mod loader;
14pub mod model;
15pub mod path_safety;
16pub mod registry;
17pub mod resolve;
18pub mod util;
19
20pub use flow_bundle::{
21    ComponentPin, FlowBundle, NodeRef, blake3_hex, canonicalize_json, extract_component_pins,
22    load_and_validate_bundle, load_and_validate_bundle_with_ir,
23};
24pub use json_output::{JsonDiagnostic, LintJsonOutput, lint_to_stdout_json};
25
26use crate::{
27    error::Result,
28    ir::{FlowIR, NodeIR, RouteIR},
29    model::FlowDoc,
30};
31use indexmap::IndexMap;
32
33/// Convert a `FlowDoc` into its compact intermediate representation.
34pub fn to_ir(flow: FlowDoc) -> Result<FlowIR> {
35    let mut nodes: IndexMap<String, NodeIR> = IndexMap::new();
36    for (id, node) in flow.nodes {
37        nodes.insert(
38            id,
39            NodeIR {
40                component: node.component,
41                payload_expr: node.payload,
42                routes: node
43                    .routing
44                    .into_iter()
45                    .map(|route| RouteIR {
46                        to: route.to,
47                        out: route.out.unwrap_or(false),
48                    })
49                    .collect(),
50            },
51        );
52    }
53
54    Ok(FlowIR {
55        id: flow.id,
56        flow_type: flow.flow_type,
57        start: flow.start,
58        parameters: flow.parameters,
59        nodes,
60    })
61}