chore: linting

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-02-15 23:38:15 -08:00
parent b9159a8329
commit 81c70befcf
10 changed files with 265 additions and 180 deletions

View file

@ -55,19 +55,23 @@ def create_create_notion_page_tool(
- url: URL to the created page (if success)
- title: Page title (if success)
- message: Result message
IMPORTANT: If status is "rejected", the user explicitly declined the action.
Respond with a brief acknowledgment (e.g., "Understood, I didn't create the page.")
Respond with a brief acknowledgment (e.g., "Understood, I didn't create the page.")
and move on. Do NOT ask for parent page IDs, troubleshoot, or suggest alternatives.
Examples:
- "Create a Notion page titled 'Meeting Notes' with content 'Discussed project timeline'"
- "Save this to Notion with title 'Research Summary'"
"""
logger.info(f"create_notion_page called: title='{title}', parent_page_id={parent_page_id}")
logger.info(
f"create_notion_page called: title='{title}', parent_page_id={parent_page_id}"
)
if db_session is None or search_space_id is None or user_id is None:
logger.error("Notion tool not properly configured - missing required parameters")
logger.error(
"Notion tool not properly configured - missing required parameters"
)
return {
"status": "error",
"message": "Notion tool not properly configured. Please contact support.",
@ -75,30 +79,34 @@ def create_create_notion_page_tool(
try:
metadata_service = NotionToolMetadataService(db_session)
context = await metadata_service.get_creation_context(search_space_id, user_id)
context = await metadata_service.get_creation_context(
search_space_id, user_id
)
if "error" in context:
logger.error(f"Failed to fetch creation context: {context['error']}")
return {
"status": "error",
"message": context["error"],
}
logger.info(f"Requesting approval for creating Notion page: '{title}'")
approval = interrupt({
"type": "notion_page_creation",
"action": {
"tool": "create_notion_page",
"params": {
"title": title,
"content": content,
"parent_page_id": parent_page_id,
"connector_id": connector_id,
approval = interrupt(
{
"type": "notion_page_creation",
"action": {
"tool": "create_notion_page",
"params": {
"title": title,
"content": content,
"parent_page_id": parent_page_id,
"connector_id": connector_id,
},
},
},
"context": context,
})
"context": context,
}
)
decisions = approval.get("decisions", [])
if not decisions:
logger.warning("No approval decision received")
@ -106,35 +114,37 @@ def create_create_notion_page_tool(
"status": "error",
"message": "No approval decision received",
}
decision = decisions[0]
decision_type = decision.get("type") or decision.get("decision_type")
logger.info(f"User decision: {decision_type}")
if decision_type == "reject":
logger.info("Notion page creation rejected by user")
return {
"status": "rejected",
"message": "User declined. The page was not created. Do not ask again or suggest alternatives.",
}
edited_action = decision.get("edited_action", {})
final_params = edited_action.get("args", {}) if edited_action else {}
final_title = final_params.get("title", title)
final_content = final_params.get("content", content)
final_parent_page_id = final_params.get("parent_page_id", parent_page_id)
final_connector_id = final_params.get("connector_id", connector_id)
if not final_title or not final_title.strip():
logger.error("Title is empty or contains only whitespace")
return {
"status": "error",
"message": "Page title cannot be empty. Please provide a valid title.",
}
logger.info(f"Creating Notion page with final params: title='{final_title}'")
logger.info(
f"Creating Notion page with final params: title='{final_title}'"
)
from sqlalchemy.future import select
from app.db import SearchSourceConnector, SearchSourceConnectorType
@ -152,7 +162,9 @@ def create_create_notion_page_tool(
connector = result.scalars().first()
if not connector:
logger.warning(f"No Notion connector found for search_space_id={search_space_id}")
logger.warning(
f"No Notion connector found for search_space_id={search_space_id}"
)
return {
"status": "error",
"message": "No Notion connector found. Please connect Notion in your workspace settings.",
@ -192,19 +204,23 @@ def create_create_notion_page_tool(
content=final_content,
parent_page_id=final_parent_page_id,
)
logger.info(f"create_page result: {result.get('status')} - {result.get('message', '')}")
logger.info(
f"create_page result: {result.get('status')} - {result.get('message', '')}"
)
return result
except Exception as e:
from langgraph.errors import GraphInterrupt
if isinstance(e, GraphInterrupt):
raise
logger.error(f"Error creating Notion page: {e}", exc_info=True)
return {
"status": "error",
"message": str(e) if isinstance(e, ValueError) else f"Unexpected error: {e!s}",
"message": str(e)
if isinstance(e, ValueError)
else f"Unexpected error: {e!s}",
}
return create_notion_page

View file

@ -59,10 +59,14 @@ def create_delete_notion_page_tool(
- "Remove the 'Old Project Plan' Notion page"
- "Archive the 'Draft Ideas' Notion page"
"""
logger.info(f"delete_notion_page called: page_title='{page_title}', delete_from_db={delete_from_db}")
logger.info(
f"delete_notion_page called: page_title='{page_title}', delete_from_db={delete_from_db}"
)
if db_session is None or search_space_id is None or user_id is None:
logger.error("Notion tool not properly configured - missing required parameters")
logger.error(
"Notion tool not properly configured - missing required parameters"
)
return {
"status": "error",
"message": "Notion tool not properly configured. Please contact support.",
@ -95,8 +99,10 @@ def create_delete_notion_page_tool(
connector_id_from_context = context.get("account", {}).get("id")
document_id = context.get("document_id")
logger.info(f"Requesting approval for deleting Notion page: '{page_title}' (page_id={page_id}, delete_from_db={delete_from_db})")
logger.info(
f"Requesting approval for deleting Notion page: '{page_title}' (page_id={page_id}, delete_from_db={delete_from_db})"
)
# Request approval before deleting
approval = interrupt(
{
@ -137,10 +143,14 @@ def create_delete_notion_page_tool(
final_params = edited_action.get("args", {}) if edited_action else {}
final_page_id = final_params.get("page_id", page_id)
final_connector_id = final_params.get("connector_id", connector_id_from_context)
final_connector_id = final_params.get(
"connector_id", connector_id_from_context
)
final_delete_from_db = final_params.get("delete_from_db", delete_from_db)
logger.info(f"Deleting Notion page with final params: page_id={final_page_id}, connector_id={final_connector_id}, delete_from_db={final_delete_from_db}")
logger.info(
f"Deleting Notion page with final params: page_id={final_page_id}, connector_id={final_connector_id}, delete_from_db={final_delete_from_db}"
)
from sqlalchemy.future import select
@ -184,11 +194,17 @@ def create_delete_notion_page_tool(
# Delete the page from Notion
result = await notion_connector.delete_page(page_id=final_page_id)
logger.info(f"delete_page result: {result.get('status')} - {result.get('message', '')}")
logger.info(
f"delete_page result: {result.get('status')} - {result.get('message', '')}"
)
# If deletion was successful and user wants to delete from DB
deleted_from_db = False
if result.get("status") == "success" and final_delete_from_db and document_id:
if (
result.get("status") == "success"
and final_delete_from_db
and document_id
):
try:
from sqlalchemy.future import select
@ -204,21 +220,27 @@ def create_delete_notion_page_tool(
await db_session.delete(document)
await db_session.commit()
deleted_from_db = True
logger.info(f"Deleted document {document_id} from knowledge base")
logger.info(
f"Deleted document {document_id} from knowledge base"
)
else:
logger.warning(f"Document {document_id} not found in DB")
except Exception as e:
logger.error(f"Failed to delete document from DB: {e}")
# Don't fail the whole operation if DB deletion fails
# The page is already deleted from Notion, so inform the user
result["warning"] = f"Page deleted from Notion, but failed to remove from knowledge base: {e!s}"
result["warning"] = (
f"Page deleted from Notion, but failed to remove from knowledge base: {e!s}"
)
# Update result with DB deletion status
if result.get("status") == "success":
result["deleted_from_db"] = deleted_from_db
if deleted_from_db:
result["message"] = f"{result.get('message', '')} (also removed from knowledge base)"
result["message"] = (
f"{result.get('message', '')} (also removed from knowledge base)"
)
return result
except Exception as e:

View file

@ -51,24 +51,28 @@ def create_update_notion_page_tool(
- url: URL to the updated page (if success)
- title: Current page title (if success)
- message: Result message
IMPORTANT:
IMPORTANT:
- If status is "rejected", the user explicitly declined the action.
Respond with a brief acknowledgment (e.g., "Understood, I didn't update the page.")
Respond with a brief acknowledgment (e.g., "Understood, I didn't update the page.")
and move on. Do NOT ask for alternatives or troubleshoot.
- If status is "not_found", inform the user conversationally using the exact message provided.
Example: "I couldn't find the page '[page_title]' in your indexed Notion pages. [message details]"
Do NOT treat this as an error. Do NOT invent information. Simply relay the message and
Do NOT treat this as an error. Do NOT invent information. Simply relay the message and
ask the user to verify the page title or check if it's been indexed.
Examples:
- "Add 'New meeting notes from today' to the 'Meeting Notes' Notion page"
- "Append the following to the 'Project Plan' Notion page: '# Status Update\n\nCompleted phase 1'"
"""
logger.info(f"update_notion_page called: page_title='{page_title}', content_length={len(content) if content else 0}")
logger.info(
f"update_notion_page called: page_title='{page_title}', content_length={len(content) if content else 0}"
)
if db_session is None or search_space_id is None or user_id is None:
logger.error("Notion tool not properly configured - missing required parameters")
logger.error(
"Notion tool not properly configured - missing required parameters"
)
return {
"status": "error",
"message": "Notion tool not properly configured. Please contact support.",
@ -106,7 +110,9 @@ def create_update_notion_page_tool(
page_id = context.get("page_id")
connector_id_from_context = context.get("account", {}).get("id")
logger.info(f"Requesting approval for updating Notion page: '{page_title}' (page_id={page_id})")
logger.info(
f"Requesting approval for updating Notion page: '{page_title}' (page_id={page_id})"
)
approval = interrupt(
{
"type": "notion_page_update",
@ -146,9 +152,13 @@ def create_update_notion_page_tool(
final_page_id = final_params.get("page_id", page_id)
final_content = final_params.get("content", content)
final_connector_id = final_params.get("connector_id", connector_id_from_context)
final_connector_id = final_params.get(
"connector_id", connector_id_from_context
)
logger.info(f"Updating Notion page with final params: page_id={final_page_id}, has_content={final_content is not None}")
logger.info(
f"Updating Notion page with final params: page_id={final_page_id}, has_content={final_content is not None}"
)
from sqlalchemy.future import select
@ -192,7 +202,9 @@ def create_update_notion_page_tool(
page_id=final_page_id,
content=final_content,
)
logger.info(f"update_page result: {result.get('status')} - {result.get('message', '')}")
logger.info(
f"update_page result: {result.get('status')} - {result.get('message', '')}"
)
return result
except Exception as e: