"""
Search note tool
"""
import os
def file_operations(action: str, path: str, content: str = ""):
"""Basic file operations: read, write, list."""
try:
if action == "read":
with open(path, 'r', encoding='utf-8') as f:
return {"content": f.read(), "path": path}
elif action == "write":
with open(path, 'w', encoding='utf-8') as f:
f.write(content)
return {"message": f"File written successfully", "path": path}
elif action == "list":
if os.path.isdir(path):
items = os.listdir(path)
return {"items": items, "path": path, "count": len(items)}
else:
return {"error": f"Path '{path}' is not a directory"}
else:
return {"error": f"Unknown action: {action}"}
except Exception as e:
return {"error": f"File operation failed: {str(e)}"}
TOOL_INFO = {
"name": "file_operations",
"description": "File operations",
"function": file_operations,
"parameters": {
"action": {
"type": "str",
"required": True,
"description": ""
},
"path": {
"type": "str",
"required": False,
"description": ""
},
"content": {
"type": "str",
"required": False,
"description": ""
},
}
}