2026-07-11 13:16:10 +07:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct ToolCall {
|
|
|
|
|
pub id: String,
|
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
|
pub type_: String,
|
|
|
|
|
pub function: ToolFunction,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct ToolFunction {
|
|
|
|
|
pub name: String,
|
|
|
|
|
pub arguments: Value,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn sanitize_tool_arguments(args: &Value) -> Value {
|
|
|
|
|
match args {
|
|
|
|
|
Value::String(s) => {
|
2026-07-12 10:23:26 +07:00
|
|
|
match serde_json::from_str::<Value>(s) {
|
|
|
|
|
Ok(v) => v,
|
|
|
|
|
Err(e) => {
|
2026-07-12 10:57:32 +07:00
|
|
|
tracing::warn!(
|
2026-07-12 10:23:26 +07:00
|
|
|
"warning: tool argument is a JSON string but failed to parse: {}. Using raw string.",
|
|
|
|
|
e
|
|
|
|
|
);
|
|
|
|
|
args.clone()
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-11 13:16:10 +07:00
|
|
|
}
|
|
|
|
|
obj @ Value::Object(_) => obj.clone(),
|
|
|
|
|
other => other.clone(),
|
|
|
|
|
}
|
|
|
|
|
}
|