"""
Create note tool
"""
import sqlite3
def create_note(title: str, content: str, category: str = "general"):
"""Save a note to local database."""
try:
conn = sqlite3.connect('notes.db')
cursor = conn.cursor()
# Create table if it doesn't exist
cursor.execute('''
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
content TEXT NOT NULL,
category TEXT DEFAULT 'general',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
cursor.execute(
"INSERT INTO notes (title, content, category) VALUES (?, ?, ?)",
(title, content, category)
)
conn.commit()
note_id = cursor.lastrowid
conn.close()
return {"message": f"Note '{title}' saved successfully", "id": note_id}
except Exception as e:
return {"error": f"Failed to save note: {str(e)}"}
TOOL_INFO = {
"name": "create_note",
"description": "Creates note and save in sqlite",
"function": create_note,
"parameters": {
"title": {
"type": "str",
"required": True,
"description": ""
},
"content": {
"type": "str",
"required": False,
"description": ""
},
"category": {
"type": "str",
"required": False,
"description": ""
}
}
}