pub mod agent;
pub mod compression;
pub mod config;
pub mod error_classifier;
pub mod events;
pub mod helpers;
pub mod hooks;
pub mod iteration_budget;
pub mod r#loop;
pub mod persistence;
pub mod prompt;
pub mod prompt_builder;
pub mod request;
pub mod session;
pub mod subagent;
pub mod tool;

use serde::{Deserialize, Serialize};

pub use agent::RigAgent;
pub use compression::{
    CompactionResult, CompressionStrategy, build_branch_summary_prompt,
    build_compression_prompt, build_compression_prompt_with_options,
    estimate_truncation, plan_compaction,
};
pub use config::AgentConfig;
pub use error_classifier::{
    ErrorCategory, RetryPolicy, classify_error, retry_policy_for,
    should_compact_before_retry, should_switch_to_fallback,
};
pub use events::{
    AgentEvent, AgentEventMessage, EventSink, EventToolCall, MessageRole,
};
pub use hooks::{AgentHook, HookChain, ToolCallOutcome, ToolGuardrailDecision};
pub use iteration_budget::IterationBudget;
pub use r#loop::{
    AgentLoopConfig, EnhancedAgent, PrepareNextTurnFn, ShouldStopFn,
    ToolExecutionMode, TurnContext, TurnUpdate,
};
pub use persistence::{
    AgentRealtime, AgentRunContext, AgentRuntime, AgentStreamEvent,
};
pub use prompt_builder::SystemPromptBuilder;
pub use request::{
    AgentContextChunk, AgentExpert, AgentExpertOutput, AgentMessage,
    AgentRequest, AgentResult, AgentStep, ToolCallRecord,
};
pub use session::{
    CompactionOptions, Session, SessionEntry, SessionHeader,
    SessionMessageRole, SessionToolCall, SessionToolResult,
};
pub use tool::{RigTool, RigToolSet};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RigStreamChunk {
    TextDelta {
        index: usize,
        content: String,
    },
    Thinking {
        index: usize,
        content: String,
    },
    ToolCallStarted {
        tool_call_id: String,
        tool_name: String,
        arguments: String,
    },
    ToolCallFinished {
        tool_call_id: String,
        tool_name: String,
        output: String,
        error: Option<String>,
    },
    SubagentStarted {
        subagent_id: String,
        role: String,
        task: String,
    },
    SubagentCompleted {
        subagent_id: String,
        role: String,
        task: String,
        output: String,
    },
    SubagentFailed {
        error: String,
    },
    Final {
        content: String,
        input_tokens: u64,
        output_tokens: u64,
    },
    Failed {
        error: String,
    },
}
