mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 17:26:23 +02:00
fix notion write tools and add retry wrapper
This commit is contained in:
parent
8649ca7ac0
commit
04ea40f0c8
4 changed files with 101 additions and 46 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from langchain_core.tools import tool
|
||||
|
|
@ -5,6 +6,8 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||
|
||||
from app.connectors.notion_history import NotionHistoryConnector
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def create_create_notion_page_tool(
|
||||
db_session: AsyncSession | None = None,
|
||||
|
|
@ -53,7 +56,10 @@ def create_create_notion_page_tool(
|
|||
- "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}")
|
||||
|
||||
if db_session is None or search_space_id is None:
|
||||
logger.error("Notion tool not properly configured - missing db_session or search_space_id")
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Notion tool not properly configured. Please contact support.",
|
||||
|
|
@ -61,7 +67,8 @@ def create_create_notion_page_tool(
|
|||
|
||||
try:
|
||||
# Get connector ID if not provided
|
||||
if connector_id is None:
|
||||
actual_connector_id = connector_id
|
||||
if actual_connector_id is None:
|
||||
from sqlalchemy.future import select
|
||||
|
||||
from app.db import SearchSourceConnector, SearchSourceConnectorType
|
||||
|
|
@ -71,37 +78,41 @@ def create_create_notion_page_tool(
|
|||
SearchSourceConnector.search_space_id == search_space_id,
|
||||
SearchSourceConnector.connector_type
|
||||
== SearchSourceConnectorType.NOTION_CONNECTOR,
|
||||
SearchSourceConnector.is_enabled == True,
|
||||
)
|
||||
)
|
||||
connector = result.scalars().first()
|
||||
|
||||
if not connector:
|
||||
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.",
|
||||
}
|
||||
|
||||
connector_id = connector.id
|
||||
actual_connector_id = connector.id
|
||||
logger.info(f"Found Notion connector: id={actual_connector_id}")
|
||||
|
||||
# Create connector instance
|
||||
notion_connector = NotionHistoryConnector(
|
||||
session=db_session,
|
||||
connector_id=connector_id,
|
||||
connector_id=actual_connector_id,
|
||||
)
|
||||
|
||||
# Create the page
|
||||
result = await notion_connector.create_page(
|
||||
title=title, content=content, parent_page_id=parent_page_id
|
||||
)
|
||||
logger.info(f"create_page result: {result.get('status')} - {result.get('message', '')}")
|
||||
return result
|
||||
|
||||
except ValueError as e:
|
||||
logger.error(f"ValueError creating Notion page: {e}")
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Unexpected error creating Notion page: {e}", exc_info=True)
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Unexpected error creating Notion page: {str(e)}",
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ def create_delete_notion_page_tool(
|
|||
SearchSourceConnector.search_space_id == search_space_id,
|
||||
SearchSourceConnector.connector_type
|
||||
== SearchSourceConnectorType.NOTION_CONNECTOR,
|
||||
SearchSourceConnector.is_enabled == True,
|
||||
)
|
||||
)
|
||||
connector = result.scalars().first()
|
||||
|
|
|
|||
|
|
@ -77,7 +77,6 @@ def create_update_notion_page_tool(
|
|||
SearchSourceConnector.search_space_id == search_space_id,
|
||||
SearchSourceConnector.connector_type
|
||||
== SearchSourceConnectorType.NOTION_CONNECTOR,
|
||||
SearchSourceConnector.is_enabled == True,
|
||||
)
|
||||
)
|
||||
connector = result.scalars().first()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue