use saya_agent::ToolError;
use super::DatabaseTools;
pub(crate) const WORKSPACE_LIST_MAX_ENTRIES: usize = 500;
impl DatabaseTools {
pub(super) async fn workspace_list(
&self,
arguments: &serde_json::Value,
) -> Result<serde_json::Value, ToolError> {
let rel = arguments
.get("path")
.and_then(serde_json::Value::as_str)
.unwrap_or_default();
let Some(workspace) = &self.workspace else {
return Err(ToolError::WorkspaceUnavailable);
};
let entries = workspace
.list(rel, WORKSPACE_LIST_MAX_ENTRIES)
.map_err(|error| ToolError::Workspace(error.to_string()))?;
let listed: Vec<serde_json::Value> = entries
.iter()
.map(|entry| {
serde_json::json!({
"name": entry.name,
"kind": kind_label(entry.kind),
"size": entry.size,
})
})
.collect();
Ok(serde_json::json!({
"path": rel,
"entries": listed,
}))
}
}
fn kind_label(kind: saya_harness::workspace::EntryKind) -> &'static str {
match kind {
saya_harness::workspace::EntryKind::File => "file",
saya_harness::workspace::EntryKind::Dir => "dir",
saya_harness::workspace::EntryKind::Symlink => "symlink",
saya_harness::workspace::EntryKind::Other => "other",
}
}