mod facts;
pub(crate) mod procedural;
pub(crate) mod runner;
mod session;
mod stored;
pub(crate) use facts::turn_fields;
pub(crate) use procedural::ProceduralRun;
pub(crate) use runner::GraphState;
pub(crate) use stored::{DialogueCache, Pending};
use lingara_dialogue_ir::{Document, Warning};
use crate::shared::Shared;
use crate::types::{CrossedVia, DialogueId, EmbedEvent, LogLevel, PlanKeptReason, PlanOutcome, TracedBeat};
pub(crate) const TARGET: &str = "lingara_embed::dialogue";
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum Step {
Reached { checkpoint: String, edge: Option<String>, via: CrossedVia },
Ended { outcome: String, checkpoint: String, edge: Option<String>, trace: Option<Vec<TracedBeat>> },
Planned { outcome: PlanOutcome, checkpoints: Vec<String>, reason: Option<PlanKeptReason> },
Log { level: LogLevel, message: String },
}
pub(crate) fn log(level: LogLevel, message: String) -> Step {
Step::Log { level, message }
}
pub(crate) fn emit(shared: &Shared, dialogue: DialogueId, steps: Vec<Step>) {
for step in steps {
match step {
Step::Reached { checkpoint, edge, via } => shared.outbox.push_later(EmbedEvent::CheckpointReached { dialogue, checkpoint, edge, via }),
Step::Ended { outcome, checkpoint, edge, trace } => shared.outbox.push_later(EmbedEvent::DialogueEnded { dialogue, outcome, checkpoint, edge, trace }),
Step::Planned { outcome, checkpoints, reason } => shared.outbox.push_later(EmbedEvent::DialoguePlanned { dialogue, outcome, checkpoints, reason }),
Step::Log { level, message } => shared.diag.emit(level, TARGET, message),
}
}
}
pub(crate) fn load_ir(ir_json: &str) -> Result<(Document, Vec<Warning>), String> {
lingara_dialogue_ir::load_document(ir_json).map_err(|e| e.to_string())
}