use crate::db::models::tool_sources::ToolSourceDBResponse;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use utoipa::ToSchema;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ToolSourceCreate {
#[serde(default = "default_kind")]
pub kind: String,
#[schema(example = "Weather API")]
pub name: String,
#[schema(example = "Fetch current weather for a given location")]
pub description: Option<String>,
pub parameters: Option<Value>,
#[schema(example = "https://api.example.com/tools/weather")]
pub url: String,
pub api_key: Option<String>,
#[serde(default = "default_timeout")]
pub timeout_secs: i32,
}
fn default_kind() -> String {
"http".to_string()
}
fn default_timeout() -> i32 {
30
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ToolSourceUpdate {
pub name: Option<String>,
#[serde(default, with = "::serde_with::rust::double_option")]
pub description: Option<Option<String>>,
#[serde(default, with = "::serde_with::rust::double_option")]
pub parameters: Option<Option<Value>>,
pub url: Option<String>,
#[serde(default, with = "::serde_with::rust::double_option")]
pub api_key: Option<Option<String>>,
pub timeout_secs: Option<i32>,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ToolSourceResponse {
#[schema(value_type = String, format = "uuid")]
pub id: Uuid,
pub kind: String,
pub name: String,
pub description: Option<String>,
pub parameters: Option<Value>,
pub url: String,
pub has_api_key: bool,
pub timeout_secs: i32,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl From<ToolSourceDBResponse> for ToolSourceResponse {
fn from(db: ToolSourceDBResponse) -> Self {
Self {
id: db.id,
kind: db.kind,
name: db.name,
description: db.description,
parameters: db.parameters,
url: db.url,
has_api_key: db.api_key.is_some(),
timeout_secs: db.timeout_secs,
created_at: db.created_at,
updated_at: db.updated_at,
}
}
}