use distri_types::configuration::ObjectStorageConfig;
use distri_types::Part;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
pub struct FileSystemConfig {
pub object_store: ObjectStorageConfig,
pub root_prefix: Option<String>,
}
impl Default for FileSystemConfig {
fn default() -> Self {
Self {
object_store: ObjectStorageConfig::FileSystem {
base_path: ".distri/files".to_string(),
},
root_prefix: Some("runs/default".to_string()),
}
}
}
#[derive(Debug, Clone)]
pub struct ArtifactStorageConfig {
pub data_token_threshold: usize,
pub text_token_threshold: usize,
pub always_store_images: bool,
pub always_store_for_testing: bool,
}
impl Default for ArtifactStorageConfig {
fn default() -> Self {
Self {
data_token_threshold: 1000,
text_token_threshold: 1000,
always_store_images: true,
always_store_for_testing: true,
}
}
}
impl ArtifactStorageConfig {
pub fn for_testing() -> Self {
Self {
data_token_threshold: 0,
text_token_threshold: 0,
always_store_images: true,
always_store_for_testing: true,
}
}
pub fn for_production() -> Self {
Self {
data_token_threshold: 10000,
text_token_threshold: 10000,
always_store_images: false,
always_store_for_testing: false,
}
}
pub fn should_store(&self, part: &Part) -> bool {
if self.always_store_for_testing {
return match part {
Part::ToolCall(_) => false,
Part::Artifact(_) => false,
_ => true,
};
}
match part {
Part::Data(value) => {
let estimated_tokens = estimate_json_tokens(value);
estimated_tokens > self.data_token_threshold
}
Part::Text(text) => {
let estimated_tokens = estimate_text_tokens(text);
estimated_tokens > self.text_token_threshold
}
Part::ToolCall(_) => false,
Part::ToolResult(response) => response.parts.iter().any(|p| self.should_store(p)),
Part::Image(_) => self.always_store_images,
Part::Artifact(_) => false,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ReadParams {
pub start_line: Option<u64>,
pub end_line: Option<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileReadResult {
pub content: String,
pub start_line: u64,
pub end_line: u64,
pub total_lines: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DirectoryListing {
pub path: String,
pub entries: Vec<DirectoryEntry>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DirectoryEntry {
pub name: String,
pub is_file: bool,
pub is_dir: bool,
pub size: Option<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchResult {
pub path: String,
pub matches: Vec<SearchMatch>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchMatch {
pub file_path: String,
pub line_number: Option<u64>,
pub line_content: String,
pub match_text: String,
}
fn estimate_json_tokens(value: &serde_json::Value) -> usize {
let json_string = serde_json::to_string(value).unwrap_or_default();
json_string.len() / 4
}
fn estimate_text_tokens(text: &str) -> usize {
text.len() / 4
}