1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct InputSchema {
6 pub properties: serde_json::Map<String, Value>,
7 pub required: Vec<String>,
8 #[serde(rename = "type")]
9 pub schema_type: String,
10}
11
12impl From<schemars::Schema> for InputSchema {
13 fn from(schema: schemars::Schema) -> Self {
14 let schema_obj = schema.as_object().unwrap();
15 Self {
16 properties: schema_obj
17 .get("properties")
18 .and_then(|v| v.as_object())
19 .cloned()
20 .unwrap_or_default(),
21 required: schema_obj
22 .get("required")
23 .and_then(|v| v.as_array())
24 .map(|arr| {
25 arr.iter()
26 .filter_map(|v| v.as_str().map(String::from))
27 .collect::<Vec<_>>()
28 })
29 .unwrap_or_default(),
30 schema_type: schema_obj
31 .get("type")
32 .and_then(|v| v.as_str())
33 .map(String::from)
34 .unwrap_or_default(),
35 }
36 }
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct ToolSchema {
41 pub name: String,
42 pub description: String,
43 pub input_schema: InputSchema,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
47pub struct ToolCall {
48 pub name: String,
49 pub parameters: Value,
50 pub id: String,
51}