pub mod ai_schema_response;
pub mod config;
pub mod core;
pub mod error;
pub mod file_upload;
pub mod ingestion_spawner;
pub mod json_processor;
pub mod multipart_parser;
pub mod mutation_generator;
pub mod ollama_service;
pub mod openrouter_service;
pub mod progress;
pub mod routes;
pub mod simple_service;
pub mod structure_analyzer;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use utoipa::ToSchema;
pub use ai_schema_response::AISchemaResponse;
pub use config::IngestionConfig;
pub use core::IngestionCore;
pub use error::IngestionError;
pub use progress::{
create_progress_tracker, IngestionProgress, IngestionResults, IngestionStep, ProgressService,
ProgressTracker,
};
pub use structure_analyzer::StructureAnalyzer;
pub type IngestionResult<T> = Result<T, IngestionError>;
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct IngestionResponse {
pub success: bool,
pub progress_id: Option<String>,
pub schema_used: Option<String>,
pub new_schema_created: bool,
pub mutations_generated: usize,
pub mutations_executed: usize,
pub errors: Vec<String>,
}
impl IngestionResponse {
pub fn success(
schema_used: String,
new_schema_created: bool,
mutations_generated: usize,
mutations_executed: usize,
) -> Self {
Self {
success: true,
progress_id: None,
schema_used: Some(schema_used),
new_schema_created,
mutations_generated,
mutations_executed,
errors: Vec::new(),
}
}
pub fn success_with_progress(
progress_id: String,
schema_used: String,
new_schema_created: bool,
mutations_generated: usize,
mutations_executed: usize,
) -> Self {
Self {
success: true,
progress_id: Some(progress_id),
schema_used: Some(schema_used),
new_schema_created,
mutations_generated,
mutations_executed,
errors: Vec::new(),
}
}
pub fn failure(errors: Vec<String>) -> Self {
Self {
success: false,
progress_id: None,
schema_used: None,
new_schema_created: false,
mutations_generated: 0,
mutations_executed: 0,
errors,
}
}
pub fn add_error(&mut self, error: String) {
self.errors.push(error);
self.success = false;
}
}
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
pub struct IngestionStatus {
pub enabled: bool,
pub configured: bool,
pub provider: String,
pub model: String,
pub auto_execute_mutations: bool,
pub default_trust_distance: u32,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SimplifiedSchema {
pub name: String,
pub fields: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SimplifiedSchemaMap {
pub schemas: HashMap<String, SimplifiedSchema>,
}
impl SimplifiedSchemaMap {
pub fn new() -> Self {
Self {
schemas: HashMap::new(),
}
}
pub fn insert(&mut self, name: String, schema: SimplifiedSchema) {
self.schemas.insert(name, schema);
}
pub fn len(&self) -> usize {
self.schemas.len()
}
pub fn is_empty(&self) -> bool {
self.schemas.is_empty()
}
pub fn to_json_value(&self) -> serde_json::Value {
serde_json::to_value(&self.schemas)
.unwrap_or(serde_json::Value::Object(serde_json::Map::new()))
}
}
impl Default for SimplifiedSchemaMap {
fn default() -> Self {
Self::new()
}
}