mod color_slots;
mod db;
mod diagnostics;
mod graph;
mod lexer;
mod parser;
mod render;
mod shapes;
mod tokens;
#[cfg(test)]
mod tests;
pub(crate) use db::AgentflowDb;
pub(crate) use render::layout;
use db::AgentflowDbOptions;
use graph::build_agent_graph;
use parser::parse_agentflow;
use crate::errors::Error;
use crate::value::{Map, Value};
const PALETTE: usize = 8;
fn default_curve(config: &Map) -> Option<&str> {
config
.get("flowchart")
.and_then(Value::as_object)
.and_then(|f| f.get("curve"))
.and_then(Value::as_str)
}
pub(crate) fn parse(
source: &str,
config: &Map,
title: Option<&str>,
line_offset: usize,
max_edges: Option<usize>,
) -> Result<AgentflowDb, Error> {
let inherit_dir = config
.get("flowchart")
.and_then(Value::as_object)
.and_then(|f| f.get("inheritDir"))
== Some(&Value::Bool(true));
let mut db = AgentflowDb::new(AgentflowDbOptions {
max_edges,
inherit_dir,
direction: config
.get("direction")
.and_then(Value::as_str)
.map(str::to_string),
line_offset,
source: Some(source.to_string()),
});
if let Some(title) = title.filter(|t| !t.is_empty()) {
db.title = Some(title.to_string());
}
parse_agentflow(source, &mut db)?;
let graph = build_agent_graph(&mut db, PALETTE, default_curve(config));
db.graph = Some(graph);
Ok(db)
}