mirror of https://github.com/buster-so/buster.git
feat: Implement file creation for metric and dashboard files
- Added implementation for creating metric files with database insertion - Introduced `create_metric_file()` and `create_dashboard_file()` functions - Updated `CreateFilesTool` to handle different file types - Added `data_metadata` field to `MetricFile` struct - Implemented basic file type validation and creation logic
This commit is contained in:
parent
a3ee00ff84
commit
a665648308
|
@ -1,9 +1,15 @@
|
|||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use diesel::insert_into;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::utils::{clients::ai::litellm::ToolCall, tools::ToolExecutor};
|
||||
use crate::{
|
||||
database::{lib::get_pg_pool, schema::metric_files},
|
||||
utils::{clients::ai::litellm::ToolCall, tools::ToolExecutor},
|
||||
};
|
||||
|
||||
use super::file_types::{dashboard_file::DashboardFile, metric_file::MetricFile};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct FileParams {
|
||||
|
@ -39,7 +45,13 @@ impl ToolExecutor for CreateFilesTool {
|
|||
|
||||
let files = params.files;
|
||||
|
||||
for file in files {}
|
||||
for file in files {
|
||||
match file.file_type.as_str() {
|
||||
"metric" => create_metric_file(file)?,
|
||||
"dashboard" => create_dashboard_file(file)?,
|
||||
_ => return Err(anyhow::anyhow!("Invalid file type: {}. Currently only `metric` and `dashboard` types are supported.", file.file_type)),
|
||||
}
|
||||
}
|
||||
Ok(Value::Array(vec![]))
|
||||
}
|
||||
|
||||
|
@ -82,3 +94,38 @@ impl ToolExecutor for CreateFilesTool {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn create_metric_file(file: FileParams) -> Result<()> {
|
||||
let metric_file = match MetricFile::new(file.yml_content) {
|
||||
Ok(metric_file) => metric_file,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
let mut conn = match get_pg_pool().get().await {
|
||||
Ok(conn) => conn,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
// TODO: Add Metric File Record here.
|
||||
|
||||
let metric_file_record = match insert_into(metric_files::table)
|
||||
.values(metric_file)
|
||||
.returning(metric_files::all_columns)
|
||||
.execute(&mut conn)
|
||||
.await
|
||||
{
|
||||
Ok(metric_file_record) => metric_file_record,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_dashboard_file(file: FileParams) -> Result<()> {
|
||||
let dashboard_file = match DashboardFile::new(file.yml_content) {
|
||||
Ok(dashboard_file) => dashboard_file,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -9,6 +9,13 @@ pub struct MetricFile {
|
|||
pub description: Option<String>,
|
||||
pub sql: String,
|
||||
pub chart_config: ChartConfig,
|
||||
pub data_metadata: Vec<DataMetadata>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct DataMetadata {
|
||||
pub name: String,
|
||||
pub data_type: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
@ -287,7 +294,6 @@ impl MetricFile {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Add validation logic here
|
||||
pub fn validate(&self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue