refactor(amap): 简化输出格式,返回原始API数据

- 移除自定义文本格式化函数(haversine_distance, format_distance, parse_location 等)
- 移除 build_route_output 函数
- execute 函数改为返回简短确认消息 + 原始 API JSON 数据
- CLI 命令同时输出 r.output 和 r.data(JSON)
- 移除 driving/riding API 的 show_fields=cost 参数
- 清理已删除函数的冗余单元测试
This commit is contained in:
2026-06-04 13:27:04 +08:00
parent fec50b7be8
commit 8dc232ebab
2 changed files with 153 additions and 404 deletions
+63 -16
View File
@@ -849,7 +849,6 @@ async fn cmd_send(
}
}
use tools::types::SkillResult;
async fn builtin_approve(ctx: &ExecutionContext, name: &str) -> Result<bool, String> {
@@ -875,7 +874,6 @@ async fn builtin_approve(ctx: &ExecutionContext, name: &str) -> Result<bool, Str
}
}
// ─── 工具 CLI 命令 ───
async fn cmd_tool(cmd: ToolCommand) {
@@ -952,22 +950,48 @@ async fn cmd_amap(action: AmapAction) {
"page": page,
"offset": offset,
});
if let Some(c) = city { params["city"] = serde_json::json!(c); }
if let Some(l) = location { params["location"] = serde_json::json!(l); }
if let Some(r) = radius { params["radius"] = serde_json::json!(r); }
if let Some(c) = city {
params["city"] = serde_json::json!(c);
}
if let Some(l) = location {
params["location"] = serde_json::json!(l);
}
if let Some(r) = radius {
params["radius"] = serde_json::json!(r);
}
let result = tools::builtins::amap::execute("amap_poi_search", params).await;
if let Some(r) = result { println!("{}", r.output); }
if let Some(r) = result {
println!(
"{}\n{}",
r.output,
serde_json::to_string(&r.data).unwrap_or_default()
);
}
}
AmapAction::Geocode { address, city } => {
let mut params = serde_json::json!({"address": address});
if let Some(c) = city { params["city"] = serde_json::json!(c); }
if let Some(c) = city {
params["city"] = serde_json::json!(c);
}
let result = tools::builtins::amap::execute("amap_geocode", params).await;
if let Some(r) = result { println!("{}", r.output); }
if let Some(r) = result {
println!(
"{}\n{}",
r.output,
serde_json::to_string(&r.data).unwrap_or_default()
);
}
}
AmapAction::ReverseGeocode { location } => {
let params = serde_json::json!({"location": location});
let result = tools::builtins::amap::execute("amap_reverse_geocode", params).await;
if let Some(r) = result { println!("{}", r.output); }
if let Some(r) = result {
println!(
"{}\n{}",
r.output,
serde_json::to_string(&r.data).unwrap_or_default()
);
}
}
AmapAction::RoutePlan {
r#type,
@@ -982,11 +1006,23 @@ async fn cmd_amap(action: AmapAction) {
"origin": origin,
"destination": destination,
});
if let Some(c) = city { params["city"] = serde_json::json!(c); }
if let Some(w) = waypoints { params["waypoints"] = serde_json::json!(w); }
if let Some(s) = strategy { params["strategy"] = serde_json::json!(s); }
if let Some(c) = city {
params["city"] = serde_json::json!(c);
}
if let Some(w) = waypoints {
params["waypoints"] = serde_json::json!(w);
}
if let Some(s) = strategy {
params["strategy"] = serde_json::json!(s);
}
let result = tools::builtins::amap::execute("amap_route_plan", params).await;
if let Some(r) = result { println!("{}", r.output); }
if let Some(r) = result {
println!(
"{}\n{}",
r.output,
serde_json::to_string(&r.data).unwrap_or_default()
);
}
}
AmapAction::TravelPlan {
city,
@@ -1003,15 +1039,26 @@ async fn cmd_amap(action: AmapAction) {
"route_type": route_type,
});
let result = tools::builtins::amap::execute("amap_travel_plan", params).await;
if let Some(r) = result { println!("{}", r.output); }
if let Some(r) = result {
println!(
"{}\n{}",
r.output,
serde_json::to_string(&r.data).unwrap_or_default()
);
}
}
AmapAction::MapLink { data } => {
let map_data: serde_json::Value =
serde_json::from_str(&data).unwrap_or(serde_json::json!([]));
let params = serde_json::json!({"map_data": map_data});
let result = tools::builtins::amap::execute("amap_map_link", params).await;
if let Some(r) = result { println!("{}", r.output); }
if let Some(r) = result {
println!(
"{}\n{}",
r.output,
serde_json::to_string(&r.data).unwrap_or_default()
);
}
}
}
}