"""
Search note tool
"""
import sqlite3
def search_notes(query: str = "", category: str = ""):
"""Search through saved notes."""
try:
conn = sqlite3.connect('notes.db')
cursor = conn.cursor()
sql = "SELECT id, title, content, category, created_at FROM notes WHERE 1=1"
params = []
if query:
sql += " AND (title LIKE ? OR content LIKE ?)"
params.extend([f"%{query}%", f"%{query}%"])
if category:
sql += " AND category = ?"
params.append(category)
sql += " ORDER BY created_at DESC LIMIT 10"
cursor.execute(sql, params)
notes = cursor.fetchall()
conn.close()
return {
"found": len(notes),
"notes": [
{
"id": note[0],
"title": note[1],
"content": note[2][:100] + "..." if len(note[2]) > 100 else note[2],
"category": note[3],
"created_at": note[4]
}
for note in notes
]
}
except Exception as e:
return {"error": f"Failed to search notes: {str(e)}"}
TOOL_INFO = {
"name": "search_notes",
"description": "Searches note in sqlite",
"function": search_notes,
"parameters": {
"query": {
"type": "str",
"required": True,
"description": ""
},
"category": {
"type": "str",
"required": False,
"description": ""
}
}
}