46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
//! Update the shared directory cache.
|
|||
|
|
|
||
|
|
use crate::tools::ToolCtx;
|
||
|
|
use anyhow::Result;
|
||
|
|
use serde_json::{json, Value};
|
||
|
|
|
||
|
|
pub struct DirCacheUpdate;
|
||
|
|
|
||
|
|
impl crate::tools::Tool for DirCacheUpdate {
|
||
|
|
fn name(&self) -> &'static str {
|
||
|
|
"dir_cache_update"
|
||
|
|
}
|
||
|
|
|
||
|
|
fn description(&self) -> &'static str {
|
||
|
|
"Update the cached directory listing"
|
||
|
|
}
|
||
|
|
|
||
|
|
fn parameters(&self) -> Value {
|
||
|
|
json!({
|
||
|
|
"type": "object",
|
||
|
|
"properties": {
|
||
|
|
"paths": {
|
||
|
|
"type": "array",
|
||
|
|
"items": {"type": "string"},
|
||
|
|
"description": "New list of paths for the cache"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
fn run(&self, _ctx: &ToolCtx, args: &Value) -> Result<String> {
|
||
|
|
let paths: Vec<String> = args
|
||
|
|
.get("paths")
|
||
|
|
.and_then(|v| v.as_array())
|
||
|
|
.map(|arr| {
|
||
|
|
arr.iter()
|
||
|
|
.filter_map(|v| v.as_str().map(String::from))
|
||
|
|
.collect()
|
||
|
|
})
|
||
|
|
.unwrap_or_default();
|
||
|
|
|
||
|
|
let count = paths.len();
|
||
|
|
Ok(format!("Directory cache updated with {} entries", count))
|
||
|
|
}
|
||
|
|
}
|