use std::sync::Arc;
use bevy_ecs::prelude::*;
use tokio::runtime::Handle;
use tokio::sync::Notify;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use leviath_providers::{InferenceRequest, Provider, Tool};
use crate::compaction_bridge::{CompactionJob, CompactionOutcome, run_compaction_job};
use crate::components::{
AgentMessage, AgentState, AgentStatus, AwaitingInteraction, ContextWindow, InferenceConfig,
MessageInbox,
};
use crate::fanout::FanOutWaiting;
use crate::inference_bridge::{InferenceJob, InferenceOutcome, run_inference_job};
use crate::inference_pool::InferencePools;
use crate::interaction_hub::InteractionHub;
use crate::persistence::{RunMetadata, TokenTotals, build_context_snapshot, build_run_meta};
use crate::persistence_bridge::PersistJob;
use crate::providers::ProviderRegistry;
use crate::tool_bridge::{BoxedToolExec, ToolJob, ToolOutcome};
mod transition;
pub use transition::*;
mod messaging;
pub use messaging::*;
mod persist;
pub use persist::*;
mod compaction;
pub use compaction::*;
mod tool_results;
pub use tool_results::*;
mod gate;
pub use gate::*;
mod tools;
pub use tools::*;
mod response;
pub use response::*;
mod inference;
pub use inference::*;
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq)]
pub struct ReadyToInfer;
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq)]
pub struct AwaitingInference;
#[derive(Component, Debug, Clone)]
pub struct StageJustEntered {
pub index: usize,
pub name: String,
}
#[derive(Component, Debug, Clone)]
pub struct StageInference {
pub provider_name: String,
pub model: String,
pub tools: Vec<Tool>,
pub tool_filter: Option<Vec<String>>,
}
#[derive(Resource)]
pub struct Providers(pub ProviderRegistry);
#[derive(Resource, Clone)]
pub struct InferenceStage {
pub pools: Arc<InferencePools>,
pub outcomes: UnboundedSender<InferenceOutcome>,
pub transition_outcomes: UnboundedSender<InferenceOutcome>,
pub compaction_outcomes: UnboundedSender<crate::compaction_bridge::CompactionOutcome>,
pub content_summary_outcomes: UnboundedSender<crate::compaction_bridge::CompactionOutcome>,
pub wake: Arc<Notify>,
pub runtime: Handle,
pub exact_token_counting: bool,
}
fn truncate_on_char_boundary(text: &str, max_chars: usize) -> String {
text.chars().take(max_chars).collect()
}
#[cfg(test)]
mod tests;