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