diff --git a/api/src/utils/tools/file_tools/common.rs b/api/src/utils/tools/file_tools/common.rs index 41f176596..abe16b4ea 100644 --- a/api/src/utils/tools/file_tools/common.rs +++ b/api/src/utils/tools/file_tools/common.rs @@ -46,6 +46,394 @@ pub async fn validate_metric_ids(ids: &[Uuid]) -> Result> { Ok(missing_ids) } +pub const METRIC_YML_SCHEMA: &str = r##" +# METRIC CONFIGURATION - YAML STRUCTURE +# ------------------------------------- +# Required top-level fields: +# +# title: "Your Metric Title" +# dataset_ids: ["uuid1", "uuid2"] # Dataset UUIDs this metric belongs to +# time_frame: "Last 30 days" # Human-readable time period covered by the query +# sql: | +# SELECT +# date, +# SUM(amount) AS total +# FROM sales +# GROUP BY date +# +# chart_config: +# selected_chart_type: "bar" # One of: bar, line, scatter, pie, combo, metric, table +# selected_view: "view_name" +# column_label_formats: {...} # Required formatting for columns +# # Additional properties based on chart type +# +# data_metadata: # Column definitions +# - name: "date" +# data_type: "date" +# - name: "total" +# data_type: "number" +# ------------------------------------- + +type: object +title: "Metric Configuration Schema" +description: "Metric definition with SQL query and visualization settings" + +properties: + # TITLE + title: + type: string + description: "Human-readable title (e.g., 'Total Sales')" + + # DATASET IDS + dataset_ids: + type: array + description: "UUIDs of datasets this metric belongs to" + + # TIME FRAME + time_frame: + type: string + description: "Human-readable time period covered by the query (e.g., 'Last 30 days', 'All time', 'August 1, 2024 - January 1, 2025', 'Comparison: August 2025 to August 2024')" + + # SQL QUERY + sql: + type: string + description: "SQL query using YAML pipe syntax (|)" + + # CHART CONFIGURATION + chart_config: + description: "Visualization settings (must match one chart type)" + oneOf: + - $ref: "#/definitions/bar_line_chart_config" + - $ref: "#/definitions/scatter_chart_config" + - $ref: "#/definitions/pie_chart_config" + - $ref: "#/definitions/combo_chart_config" + - $ref: "#/definitions/metric_chart_config" + - $ref: "#/definitions/table_chart_config" + + # DATA METADATA + data_metadata: + type: array + description: "Column definitions with name and data_type" + items: + type: object + properties: + name: + type: string + description: "Column name" + data_type: + type: string + description: "Data type (string, number, date)" + required: + - name + - data_type + +required: + - title + - dataset_ids + - time_frame + - sql + - chart_config + +definitions: + # BASE CHART CONFIG (common to all chart types) + base_chart_config: + type: object + properties: + selected_chart_type: + type: string + description: "Chart type (bar, line, scatter, pie, combo, metric, table)" + selected_view: + type: string + description: "View name" + column_label_formats: + type: object + description: "Column formatting {columnId: formatObject}" + additionalProperties: + $ref: "#/definitions/i_column_label_format" + column_settings: + type: object + description: "Visual settings {columnId: settingsObject}" + additionalProperties: + $ref: "#/definitions/column_settings" + colors: + type: array + items: + type: string + show_legend: + type: boolean + grid_lines: + type: boolean + goal_lines: + type: array + items: + $ref: "#/definitions/goal_line" + trendlines: + type: array + items: + $ref: "#/definitions/trendline" + required: + - selected_chart_type + - selected_view + - column_label_formats + + # COLUMN FORMATTING + i_column_label_format: + type: object + properties: + column_type: + type: string + description: "number, string, date" + style: + type: string + enum: ["currency", "percent", "number", "date", "string"] + display_name: + type: string + prefix: + type: string + suffix: + type: string + required: + - column_type + - style + + # COLUMN VISUAL SETTINGS + column_settings: + type: object + properties: + show_data_labels: + type: boolean + column_visualization: + type: string + enum: ["bar", "line", "dot"] + line_width: + type: number + line_style: + type: string + enum: ["area", "line"] + line_type: + type: string + enum: ["normal", "smooth", "step"] + + # CHART-SPECIFIC CONFIGURATIONS + bar_line_chart_config: + allOf: + - $ref: "#/definitions/base_chart_config" + - type: object + properties: + selected_chart_type: + enum: ["bar", "line"] + bar_and_line_axis: + type: object + properties: + x: + type: array + items: + type: string + y: + type: array + items: + type: string + category: + type: array + items: + type: string + required: + - x + - y + - category + bar_layout: + type: string + enum: ["horizontal", "vertical"] + bar_group_type: + type: string + enum: ["stack", "group", "percentage-stack"] + required: + - bar_and_line_axis + + scatter_chart_config: + allOf: + - $ref: "#/definitions/base_chart_config" + - type: object + properties: + selected_chart_type: + enum: ["scatter"] + scatter_axis: + type: object + properties: + x: + type: array + items: + type: string + y: + type: array + items: + type: string + required: + - x + - y + required: + - scatter_axis + + pie_chart_config: + allOf: + - $ref: "#/definitions/base_chart_config" + - type: object + properties: + selected_chart_type: + enum: ["pie"] + pie_chart_axis: + type: object + properties: + x: + type: array + items: + type: string + y: + type: array + items: + type: string + required: + - x + - y + required: + - pie_chart_axis + + combo_chart_config: + allOf: + - $ref: "#/definitions/base_chart_config" + - type: object + properties: + selected_chart_type: + enum: ["combo"] + combo_chart_axis: + type: object + properties: + x: + type: array + items: + type: string + y: + type: array + items: + type: string + required: + - x + - y + required: + - combo_chart_axis + + metric_chart_config: + allOf: + - $ref: "#/definitions/base_chart_config" + - type: object + properties: + selected_chart_type: + enum: ["metric"] + metric_column_id: + type: string + metric_value_aggregate: + type: string + enum: ["sum", "average", "median", "max", "min", "count", "first"] + required: + - metric_column_id + + table_chart_config: + allOf: + - $ref: "#/definitions/base_chart_config" + - type: object + properties: + selected_chart_type: + enum: ["table"] + table_column_order: + type: array + items: + type: string + + # HELPER OBJECTS + goal_line: + type: object + properties: + show: + type: boolean + value: + type: number + goal_line_label: + type: string + + trendline: + type: object + properties: + type: + type: string + enum: ["average", "linear_regression", "min", "max", "median"] + column_id: + type: string + required: + - type + - column_id +"##; + +pub const DASHBOARD_YML_SCHEMA: &str = r##" +# DASHBOARD CONFIGURATION - YAML STRUCTURE +# ---------------------------------------- +# Required fields: +# +# title: "Your Dashboard Title" +# rows: +# - items: +# - id: "metric-uuid-1" # UUIDv4 of an existing metric +# width: 6 # Width value between 3-12 +# - id: "metric-uuid-2" +# width: 6 +# - items: +# - id: "metric-uuid-3" +# width: 12 +# +# Rules: +# 1. Each row can have up to 4 items +# 2. Each item width must be between 3-12 +# 3. Sum of widths in a row must not exceed 12 +# ---------------------------------------- + +type: object +title: 'Dashboard Configuration Schema' +description: 'Specifies the structure and constraints of a dashboard config file.' +properties: + title: + type: string + description: "The title of the dashboard (e.g. 'Sales & Marketing Dashboard')" + rows: + type: array + description: "Array of row objects, each containing metric items" + items: + type: object + properties: + items: + type: array + description: "Array of metrics to display in this row (max 4 items)" + max_items: 4 + items: + type: object + properties: + id: + type: string + description: "UUIDv4 identifier of an existing metric" + width: + type: integer + description: "Width value (3-12, sum per row ≤ 12)" + minimum: 3 + maximum: 12 + required: + - id + - width + required: + - items +required: + - title + - rows +"##; + + #[cfg(test)] mod tests { use super::*; diff --git a/api/src/utils/tools/file_tools/create_dashboard_files.rs b/api/src/utils/tools/file_tools/create_dashboard_files.rs index 97a4f05b3..2b7ff9370 100644 --- a/api/src/utils/tools/file_tools/create_dashboard_files.rs +++ b/api/src/utils/tools/file_tools/create_dashboard_files.rs @@ -13,11 +13,16 @@ use uuid::Uuid; use crate::{ database_dep::{lib::get_pg_pool, models::DashboardFile, schema::dashboard_files}, - utils::{agent::Agent, tools::ToolExecutor}, + utils::{agent::Agent, tools::{file_tools::common::DASHBOARD_YML_SCHEMA, ToolExecutor}}, }; use super::{ - common::validate_metric_ids, file_types::{dashboard_yml::DashboardYml, file::{FileEnum, FileWithId}}, FileModificationTool, + common::validate_metric_ids, + file_types::{ + dashboard_yml::DashboardYml, + file::{FileEnum, FileWithId}, + }, + FileModificationTool, }; use litellm::ToolCall; @@ -253,7 +258,7 @@ impl ToolExecutor for CreateDashboardFilesTool { }, "yml_content": { "type": "string", - "description": "# DASHBOARD SCHEMA (DOCUMENTATION + SPEC)# --- # This YAML file demonstrates how to structure a 'dashboard configuration' file.# The file is annotated with comments that serve as documentation for users.## Each dashboard should have:# 1) A top-level 'title; (string).# 2) A 'rows' field, which is an array of row definitions.# 3) Each row contains an array called 'items' with up to 4 metric objects.# 4) Each metric object has:# - id (string) : The UUIDv4 identifier of the metric. You should know which metric you want to reference before putting it here.# - width (int) : must be at least 3 and at most 12# 5) The sum of all widths within a given row should not exceed 12.## This file uses a JSON Schema-like structure but written in YAML. You could# place this in a 'dashboard-schema.yml' for reference or use it as documentation# within your code repository.## ------------------------------------------------------------------------------type: objecttitle: 'Dashboard Configuration Schema'description: 'Specifies the structure and constraints of a dashboard config file.'properties: # ---------------------- # 1. TITLE # ---------------------- title: type: string description: > The title of the entire dashboard (e.g. 'Sales & Marketing Dashboard'). This field is mandatory. # ---------------------- # 2. ROWS # ---------------------- rows: type: array description: > An array of row objects. Each row represents a 'horizontal band' of metrics or widgets across the dashboard. items: # We define the schema for each row object here. type: object properties: # The row object has 'items' that define individual metrics/widgets. items: type: array description: > A list (array) of metric definitions. Each metric is represented by an object that must specify an 'id' and a 'width'. - Up to 4 items per row (no more). - Each 'width' must be between 3 and 12. - The sum of all 'width' values in a single row should not exceed 12. # We limit the number of items to 4. max_items: 4 # Each array entry must conform to the schema below. items: type: object properties: id: type: string description: > The metric's UUIDv4 identifier. You should know which metric you want to reference before putting it here. Example: '123e4567-e89b-12d3-a456-426614174000' width: type: integer description: > The width allocated to this metric within the row. Valid values range from 3 to 12. Combined with other items in the row, the total 'width' must not exceed 12. minimum: 3 maximum: 12 # Both fields are mandatory for each item. required: - id - width # The 'items' field must be present in each row. required: - items # Top-level 'title' and 'rows' are required for every valid dashboard config. required: - title # ------------------------------------------------------------------------------ # NOTE ON WIDTH SUM VALIDATION: # ------------------------------------------------------------------------------ # Classic JSON Schema doesn't have a direct, simple way to enforce that the sum # of all 'width' fields in a row is <= 12. One common approach is to use # 'allOf', 'if/then' or 'contains' with advanced constructs, or simply rely on # custom validation logic in your application. # # If you rely on external validation logic, you can highlight in your docs that # end users must ensure each row's total width does not exceed 12. # ------------------------------------------------------------------------------ ```" + "description": DASHBOARD_YML_SCHEMA } }, "additionalProperties": false diff --git a/api/src/utils/tools/file_tools/create_metric_files.rs b/api/src/utils/tools/file_tools/create_metric_files.rs index 0c88e86f3..75df27289 100644 --- a/api/src/utils/tools/file_tools/create_metric_files.rs +++ b/api/src/utils/tools/file_tools/create_metric_files.rs @@ -15,7 +15,7 @@ use crate::{ database_dep::{ enums::Verification, lib::get_pg_pool, models::MetricFile, schema::metric_files, }, - utils::{agent::Agent, tools::ToolExecutor}, + utils::{agent::Agent, tools::{file_tools::common::METRIC_YML_SCHEMA, ToolExecutor}}, }; use super::{ @@ -250,7 +250,7 @@ impl ToolExecutor for CreateMetricFilesTool { }, "yml_content": { "type": "string", - "description": "METRIC CONFIGURATION SCHEMA (DOCUMENTATION + SPEC) # This YAML file shows a JSON Schema-like specification for defining a 'metric.'# # REQUIRED at the top level:# 1) title: string# 2) dataset_ids: array of strings# 2) sql: multi-line string (YAML pipe recommended)# 3) chart_config: must match exactly one of the possible chart sub-schemas # (bar/line, scatter, pie, combo, metric, table).# 4) data_metadata: array of columns. Each with { name, data_type }.# # 'columnLabelFormats' is a required field under chartConfig (in the base).## If a field is null or empty, simply omit it from your YAML rather than # including it with 'null.' That way, you keep the configuration clean.# ------------------------------------------------------------------------------type: objecttitle: 'Metric Configuration Schema'description: 'Specifies structure for a metric file, including SQL + one chart type.'properties: # ---------------------- # 1. TITLE (REQUIRED) # ---------------------- title: type: string description: > A human-readable title for this metric (e.g. 'Total Sales'). Always required. # ---------------------- # 2. DATASET IDS (REQUIRED) # ---------------------- dataset_ids: type: array description: > An array of dataset IDs that the metric belongs to. This is the UUID of the dataset/model # ---------------------- # 3. SQL (REQUIRED, multi-line recommended) # ---------------------- sql: type: string description: > A SQL query string used to compute or retrieve the metric's data. It should be well-formatted, typically using YAML's pipe syntax (|). Example: sql: | SELECT date, SUM(sales_amount) AS total_sales FROM sales GROUP BY date ORDER BY date DESC Always required. # ---------------------- # 4. CHART CONFIG (REQUIRED, EXACTLY ONE TYPE) # ---------------------- chart_config: description: > Defines visualization settings. Must match exactly one sub-schema via oneOf: bar/line, scatter, pie, combo, metric, or table. oneOf: - $ref: '#/definitions/bar_line_chart_config' - $ref: '#/definitions/scatter_chart_config' - $ref: '#/definitions/pie_chart_config' - $ref: '#/definitions/combo_chart_config' - $ref: '#/definitions/metric_chart_config' - $ref: '#/definitions/table_chart_config' # ---------------------- # 5. DATA METADATA (REQUIRED) # ---------------------- data_metadata: type: array description: > An array describing each column in the metric's dataset. Each item has a 'name' and a 'dataType'. items: type: object properties: name: type: string description: 'Column name.' data_type: type: string description: 'Data type of the column (e.g., 'string', 'number', 'date').' required: - name - data_typerequired: - title - sql - chart_configdefinitions: goal_line: type: object description: 'A line drawn on the chart to represent a goal/target.' properties: show: type: boolean description: > If true, display the goal line. If you don't need it, omit the property. value: type: number description: > Numeric value of the goal line. Omit if unused. show_goal_line_label: type: boolean description: > If true, show a label on the goal line. Omit if you want the default behavior. goal_line_label: type: string description: > The label text to display near the goal line (if show_goal_line_label = true). goal_line_color: type: string description: > Color for the goal line (e.g., '#FF0000'). Omit if not specified. trendline: type: object description: 'A trendline overlay (e.g. average line, regression).' properties: show: type: boolean show_trendline_label: type: boolean trendline_label: type: string description: 'Label text if show_trendline_label is true (e.g., 'Slope').' type: type: string enum: - average - linear_regression - logarithmic_regression - exponential_regression - polynomial_regression - min - max - median description: > Trendline algorithm to use. Required. trend_line_color: type: string description: 'Color for the trendline (e.g. '#000000').' column_id: type: string description: > Column ID to which this trendline applies. Required. required: - type - column_id bar_and_line_axis: type: object description: > Axis definitions for bar or line charts: x, y, category, and optional tooltip. properties: x: type: array items: type: string description: 'Column ID(s) for the x-axis.' y: type: array items: type: string description: 'Column ID(s) for the y-axis.' category: type: array items: type: string description: 'Column ID(s) representing categories/groups.' tooltip: type: array items: type: string description: 'Columns used in tooltips. Omit if you want the defaults.' required: - x - y - category scatter_axis: type: object description: 'Axis definitions for scatter charts: x, y, optional category/size/tooltip.' properties: x: type: array items: type: string y: type: array items: type: string category: type: array items: type: string description: 'Optional. Omit if not used.' size: type: array maxItems: 1 items: type: string description: 'If omitted, no size-based variation. If present, exactly one column ID.' tooltip: type: array items: type: string description: 'Columns used in tooltips.' required: - x - y pie_chart_axis: type: object description: 'Axis definitions for pie charts: x, y, optional tooltip.' properties: x: type: array items: type: string y: type: array items: type: string tooltip: type: array items: type: string required: - x - y combo_chart_axis: type: object description: 'Axis definitions for combo charts: x, y, optional y2/category/tooltip.' properties: x: type: array items: type: string y: type: array items: type: string y2: type: array items: type: string description: 'Optional secondary y-axis. Omit if unused.' category: type: array items: type: string tooltip: type: array items: type: string required: - x - y i_column_label_format: type: object description: > Describes how a column's data is formatted (currency, percent, date, etc.). If you do not need special formatting for a column, omit it from 'column_label_formats'. properties: column_type: type: string description: 'e.g., 'number', 'string', 'date'' style: type: string enum: - currency - percent - number - date - string description: 'Defines how values are displayed.' display_name: type: string description: 'Override for the column label. Omit if unused.' number_separator_style: type: string description: 'E.g., ',' for thousands separator or omit if no special style.' minimum_fraction_digits: type: number description: 'Min decimal places. Omit if default is fine.' maximum_fraction_digits: type: number description: 'Max decimal places. Omit if default is fine.' multiplier: type: number description: 'E.g., 100 for percents. Omit if default is 1.' prefix: type: string description: 'String to add before each value (e.g. '$').' suffix: type: string description: 'String to add after each value (e.g. '%').' replace_missing_data_with: type: [ 'number', 'string' ] description: 'If data is missing, use this value. Omit if default 0 is fine.' compact_numbers: type: boolean description: 'If true, 10000 => 10K. Omit if not needed.' currency: type: string description: 'ISO code for style=currency. Default 'USD' if omitted.' date_format: type: string description: 'Dayjs format if style=date. Default 'LL' if omitted.' use_relative_time: type: boolean description: 'If true, e.g., '2 days ago' might be used. Omit if not used.' is_utc: type: boolean description: 'If true, interpret date as UTC. Omit if local time.' convert_number_to: type: string description: 'Used if style=number but want day_of_week, etc. Omit if not used.' required: - column_type - style column_settings: type: object description: 'Overrides per-column for visualization (bar, line, dot, etc.).' properties: show_data_labels: type: boolean show_data_labels_as_percentage: type: boolean column_visualization: type: string enum: [ 'bar', 'line', 'dot' ] description: > If omitted, chart-level default is used. line_width: type: number description: 'Thickness of the line. Omit if default is OK.' line_style: type: string enum: [ 'area', 'line' ] line_type: type: string enum: [ 'normal', 'smooth', 'step' ] line_symbol_size: type: number description: 'Size of dots on a line. Omit if default is OK.' bar_roundness: type: number description: 'Roundness of bar corners (0-50). Omit if default is OK.' line_symbol_size_dot: type: number description: 'If column_visualization='dot', size of the dots. Omit if default is OK.' base_chart_config: type: object properties: selected_chart_type: type: string description: > Must match the chart type in the sub-schema. E.g., 'bar', 'line', 'scatter', 'pie', 'combo', 'metric', 'table'. column_label_formats: type: object description: > A map of columnId => label format object (i_column_label_format). If you truly have no column formatting, you can provide an empty object, but do not omit this field. additionalProperties: $ref: '#/definitions/i_column_label_format' column_settings: type: object description: > A map of columnId => column_settings. Omit columns if no special customization is needed. additionalProperties: $ref: '#/definitions/column_settings' colors: type: array items: type: string description: > Array of color hex codes or color names. If omitted, use defaults. show_legend: type: boolean description: 'Whether to display the legend. Omit if defaults apply.' grid_lines: type: boolean description: 'Toggle grid lines. Omit if defaults apply.' show_legend_headline: type: string description: 'Additional legend headline text. Omit if not used.' goal_lines: type: array description: 'Array of goal_line objects. Omit if none.' items: $ref: '#/definitions/goal_line' trendlines: type: array description: 'Array of trendline objects. Omit if none.' items: $ref: '#/definitions/trendline' disable_tooltip: type: boolean description: 'If true, tooltips are disabled. Omit if not needed.' y_axis_config: type: object description: 'If omitted, defaults apply.' additionalProperties: true x_axis_config: type: object additionalProperties: true category_axis_style_config: type: object additionalProperties: true y2_axis_config: type: object additionalProperties: true required: - selected_chart_type - selected_view - column_label_formats bar_line_chart_config: allOf: - $ref: '#/definitions/base_chart_config' - type: object properties: selected_chart_type: enum: [ 'bar', 'line' ] bar_and_line_axis: $ref: '#/definitions/bar_and_line_axis' bar_layout: type: string enum: [ 'horizontal', 'vertical' ] bar_sort_by: type: string bar_group_type: type: string enum: [ 'stack', 'group', 'percentage-stack' ] bar_show_total_at_top: type: boolean line_group_type: type: string enum: [ 'stack', 'percentage-stack' ] required: - bar_and_line_axis scatter_chart_config: allOf: - $ref: '#/definitions/base_chart_config' - type: object properties: selected_chart_type: enum: [ 'scatter' ] scatter_axis: $ref: '#/definitions/scatter_axis' scatter_dot_size: type: array minItems: 2 maxItems: 2 items: type: number description: 'If omitted, scatter dot sizes may follow a default range.' required: - scatter_axis pie_chart_config: allOf: - $ref: '#/definitions/base_chart_config' - type: object properties: selected_chart_type: enum: [ 'pie' ] pie_chart_axis: $ref: '#/definitions/pie_chart_axis' pie_display_label_as: type: string enum: [ 'percent', 'number' ] pie_show_inner_label: type: boolean pie_inner_label_aggregate: type: string enum: [ 'sum', 'average', 'median', 'max', 'min', 'count' ] pie_inner_label_title: type: string pie_label_position: type: string enum: [ 'inside', 'outside', 'none' ] pie_donut_width: type: number pie_minimum_slice_percentage: type: number required: - pie_chart_axis combo_chart_config: allOf: - $ref: '#/definitions/base_chart_config' - type: object properties: selected_chart_type: enum: [ 'combo' ] combo_chart_axis: $ref: '#/definitions/combo_chart_axis' required: - combo_chart_axis metric_chart_config: allOf: - $ref: '#/definitions/base_chart_config' - type: object properties: selected_chart_type: enum: [ 'metric' ] metric_column_id: type: string description: 'Required. The column used for the metric's numeric value.' metric_value_aggregate: type: string enum: [ 'sum', 'average', 'median', 'max', 'min', 'count', 'first' ] metric_header: type: string description: 'If omitted, the column_id is used as default label.' metric_sub_header: type: string metric_value_label: type: string description: 'If omitted, the label is derived from metric_column_id + aggregator.' required: - metric_column_id table_chart_config: allOf: - $ref: '#/definitions/base_chart_config' - type: object properties: selected_chart_type: enum: [ 'table' ] table_column_order: type: array items: type: string table_column_widths: type: object additionalProperties: type: number table_header_background_color: type: string table_header_font_color: type: string table_column_font_color: type: string required: [] description: > For table type, the axis concept is irrelevant; user may specify column order, widths, colors, etc." + "description": METRIC_YML_SCHEMA } }, "additionalProperties": false @@ -262,4 +262,4 @@ impl ToolExecutor for CreateMetricFilesTool { } }) } -} +} \ No newline at end of file diff --git a/api/src/utils/tools/file_tools/modify_dashboard_files.rs b/api/src/utils/tools/file_tools/modify_dashboard_files.rs index 5e08f724e..b6c224bf9 100644 --- a/api/src/utils/tools/file_tools/modify_dashboard_files.rs +++ b/api/src/utils/tools/file_tools/modify_dashboard_files.rs @@ -13,12 +13,18 @@ use uuid::Uuid; use super::{ common::validate_metric_ids, - file_types::{dashboard_yml::DashboardYml, file::{FileEnum, FileWithId}}, + file_types::{ + dashboard_yml::DashboardYml, + file::{FileEnum, FileWithId}, + }, FileModificationTool, }; use crate::{ database_dep::{lib::get_pg_pool, models::DashboardFile, schema::dashboard_files}, - utils::{agent::Agent, tools::ToolExecutor}, + utils::{ + agent::Agent, + tools::{file_tools::common::DASHBOARD_YML_SCHEMA, ToolExecutor}, + }, }; use litellm::ToolCall; @@ -347,12 +353,16 @@ impl ToolExecutor for ModifyDashboardFilesTool { { Ok(_) => { output.files.extend( - batch.dashboard_files.iter().zip(batch.dashboard_ymls.iter()).map(|(file, yml)| FileWithId { - id: file.id, - name: file.name.clone(), - file_type: "dashboard".to_string(), - yml_content: serde_yaml::to_string(&yml).unwrap_or_default(), - }) + batch + .dashboard_files + .iter() + .zip(batch.dashboard_ymls.iter()) + .map(|(file, yml)| FileWithId { + id: file.id, + name: file.name.clone(), + file_type: "dashboard".to_string(), + yml_content: serde_yaml::to_string(&yml).unwrap_or_default(), + }), ); } Err(e) => { @@ -444,7 +454,7 @@ impl ToolExecutor for ModifyDashboardFilesTool { }, "additionalProperties": false }, - "description": "Array of dashboard files to modify with their modifications." + "description": DASHBOARD_YML_SCHEMA } }, "additionalProperties": false diff --git a/api/src/utils/tools/file_tools/modify_metric_files.rs b/api/src/utils/tools/file_tools/modify_metric_files.rs index 9e13c9eb9..39c7215e1 100644 --- a/api/src/utils/tools/file_tools/modify_metric_files.rs +++ b/api/src/utils/tools/file_tools/modify_metric_files.rs @@ -23,7 +23,7 @@ use crate::{ models::{DashboardFile, MetricFile}, schema::{dashboard_files, metric_files}, }, - utils::{agent::Agent, tools::ToolExecutor}, + utils::{agent::Agent, tools::{file_tools::common::METRIC_YML_SCHEMA, ToolExecutor}}, }; use litellm::ToolCall; @@ -415,7 +415,7 @@ impl ToolExecutor for ModifyMetricFilesTool { "properties": { "files": { "type": "array", - "description": "List of files to modify with their corresponding modifications", + "description": METRIC_YML_SCHEMA, "items": { "type": "object", "required": [