use std::path::PathBuf;
use std::sync::Arc;
use anyhow::{Context as _, Result};
use forge_domain::{
Context, ContextMessage, DataGenerationParameters, ResultStreamExt, Template, ToolDefinition,
};
use futures::StreamExt;
use futures::stream::{self, BoxStream};
use schemars::Schema;
use tracing::{debug, info};
use crate::{AppConfigService, FsReadService, ProviderService, Services, TemplateEngine};
pub struct DataGenerationApp {
services: Arc,
}
type JsonSchema = String;
type SystemPrompt = String;
type UserPrompt = String;
type Input = Vec;
impl DataGenerationApp {
pub fn new(services: Arc) -> Self {
Self { services }
}
/// Helper function to read a file from a path, resolving it relative to cwd
/// if necessary
async fn read_file(&self, path: PathBuf) -> Result {
let resolved_path = if path.is_absolute() {
path
} else {
let cwd = self.services.get_environment().cwd;
cwd.join(path)
};
let content = self
.services
.read(resolved_path.display().to_string(), None, None)
.await?
.content
.file_content()
.to_owned();
Ok(content)
}
async fn read_file_opt(&self, path: Option) -> Result