chore: linting and formatting

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2025-09-28 22:26:26 -07:00
parent ef361e16b4
commit 94367e4226
16 changed files with 143 additions and 131 deletions

View file

@ -4,7 +4,6 @@ from .airtable_add_connector_route import (
router as airtable_add_connector_router,
)
from .chats_routes import router as chats_router
from .luma_add_connector_route import router as luma_add_connector_router
from .documents_routes import router as documents_router
from .google_calendar_add_connector_route import (
router as google_calendar_add_connector_router,
@ -14,6 +13,7 @@ from .google_gmail_add_connector_route import (
)
from .llm_config_routes import router as llm_config_router
from .logs_routes import router as logs_router
from .luma_add_connector_route import router as luma_add_connector_router
from .podcasts_routes import router as podcasts_router
from .search_source_connectors_routes import router as search_source_connectors_router
from .search_spaces_routes import router as search_spaces_router

View file

@ -1,5 +1,4 @@
import logging
from uuid import UUID
from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel, Field
@ -22,7 +21,7 @@ router = APIRouter()
class AddLumaConnectorRequest(BaseModel):
"""Request model for adding a Luma connector."""
api_key: str = Field(..., description="Luma API key")
space_id: int = Field(..., description="Search space ID")
@ -35,15 +34,15 @@ async def add_luma_connector(
):
"""
Add a new Luma connector for the authenticated user.
Args:
request: The request containing Luma API key and space_id
user: Current authenticated user
session: Database session
Returns:
Success message and connector details
Raises:
HTTPException: If connector already exists or validation fails
"""
@ -52,26 +51,27 @@ async def add_luma_connector(
result = await session.execute(
select(SearchSourceConnector).filter(
SearchSourceConnector.user_id == user.id,
SearchSourceConnector.connector_type == SearchSourceConnectorType.LUMA_CONNECTOR,
SearchSourceConnector.connector_type
== SearchSourceConnectorType.LUMA_CONNECTOR,
)
)
existing_connector = result.scalars().first()
if existing_connector:
# Update existing connector with new API key
existing_connector.config = {"api_key": request.api_key}
existing_connector.is_indexable = True
await session.commit()
await session.refresh(existing_connector)
logger.info(f"Updated existing Luma connector for user {user.id}")
return {
"message": "Luma connector updated successfully",
"connector_id": existing_connector.id,
"connector_type": "LUMA_CONNECTOR",
}
# Create new Luma connector
db_connector = SearchSourceConnector(
name="Luma Event Connector",
@ -80,21 +80,21 @@ async def add_luma_connector(
user_id=user.id,
is_indexable=True,
)
session.add(db_connector)
await session.commit()
await session.refresh(db_connector)
logger.info(
f"Successfully created Luma connector for user {user.id} with ID {db_connector.id}"
)
return {
"message": "Luma connector added successfully",
"connector_id": db_connector.id,
"connector_type": "LUMA_CONNECTOR",
}
except IntegrityError as e:
await session.rollback()
logger.error(f"Database integrity error: {e!s}")
@ -118,14 +118,14 @@ async def delete_luma_connector(
):
"""
Delete the Luma connector for the authenticated user.
Args:
user: Current authenticated user
session: Database session
Returns:
Success message
Raises:
HTTPException: If connector doesn't exist
"""
@ -133,24 +133,25 @@ async def delete_luma_connector(
result = await session.execute(
select(SearchSourceConnector).filter(
SearchSourceConnector.user_id == user.id,
SearchSourceConnector.connector_type == SearchSourceConnectorType.LUMA_CONNECTOR,
SearchSourceConnector.connector_type
== SearchSourceConnectorType.LUMA_CONNECTOR,
)
)
connector = result.scalars().first()
if not connector:
raise HTTPException(
status_code=404,
detail="Luma connector not found for this user.",
)
await session.delete(connector)
await session.commit()
logger.info(f"Successfully deleted Luma connector for user {user.id}")
return {"message": "Luma connector deleted successfully"}
except HTTPException:
raise
except Exception as e:
@ -169,14 +170,14 @@ async def test_luma_connector(
):
"""
Test the Luma connector for the authenticated user.
Args:
user: Current authenticated user
session: Database session
Returns:
Test results including user info and event count
Raises:
HTTPException: If connector doesn't exist or test fails
"""
@ -185,20 +186,21 @@ async def test_luma_connector(
result = await session.execute(
select(SearchSourceConnector).filter(
SearchSourceConnector.user_id == user.id,
SearchSourceConnector.connector_type == SearchSourceConnectorType.LUMA_CONNECTOR,
SearchSourceConnector.connector_type
== SearchSourceConnectorType.LUMA_CONNECTOR,
)
)
connector = result.scalars().first()
if not connector:
raise HTTPException(
status_code=404,
detail="Luma connector not found. Please add a connector first.",
)
# Import LumaConnector
from app.connectors.luma_connector import LumaConnector
# Initialize the connector
api_key = connector.config.get("api_key")
if not api_key:
@ -206,9 +208,9 @@ async def test_luma_connector(
status_code=400,
detail="Invalid connector configuration: API key missing.",
)
luma = LumaConnector(api_key=api_key)
# Test the connection by fetching user info
user_info, error = luma.get_user_info()
if error:
@ -216,10 +218,10 @@ async def test_luma_connector(
status_code=400,
detail=f"Failed to connect to Luma: {error}",
)
# Try to fetch events
events, events_error = luma.get_all_events(limit=10)
return {
"message": "Luma connector is working correctly",
"user_info": {
@ -229,7 +231,7 @@ async def test_luma_connector(
"event_count": len(events) if not events_error else 0,
"events_error": events_error,
}
except HTTPException:
raise
except Exception as e:

View file

@ -45,9 +45,9 @@ from app.tasks.connector_indexers import (
index_google_gmail_messages,
index_jira_issues,
index_linear_issues,
index_luma_events,
index_notion_pages,
index_slack_messages,
index_luma_events
)
from app.users import current_active_user
from app.utils.check_ownership import check_ownership
@ -1280,6 +1280,7 @@ async def run_google_gmail_indexing(
)
# Optionally update status in DB to indicate failure
# Add new helper functions for luma indexing
async def run_luma_indexing_with_new_session(
connector_id: int,
@ -1297,6 +1298,7 @@ async def run_luma_indexing_with_new_session(
session, connector_id, search_space_id, user_id, start_date, end_date
)
async def run_luma_indexing(
session: AsyncSession,
connector_id: int,
@ -1338,4 +1340,4 @@ async def run_luma_indexing(
f"Luma indexing failed or no documents processed: {error_or_warning}"
)
except Exception as e:
logger.error(f"Error in background Luma indexing task: {e!s}")
logger.error(f"Error in background Luma indexing task: {e!s}")