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

@ -421,13 +421,14 @@ async def fetch_documents_by_ids(
start_time = metadata.get("start_time", "")
location_name = metadata.get("location_name", "")
meeting_url = metadata.get("meeting_url", "")
title = f"Luma: {event_name}"
if start_time:
# Format the start time for display
try:
if "T" in start_time:
from datetime import datetime
start_dt = datetime.fromisoformat(
start_time.replace("Z", "+00:00")
)
@ -435,7 +436,7 @@ async def fetch_documents_by_ids(
title += f" ({formatted_time})"
except Exception:
pass
description = (
doc.content[:100] + "..."
if len(doc.content) > 100
@ -444,8 +445,8 @@ async def fetch_documents_by_ids(
if location_name:
description += f" | Venue: {location_name}"
elif meeting_url:
description += f" | Online Event"
description += " | Online Event"
url = event_url if event_url else ""
elif doc_type == "EXTENSION":

View file

@ -82,7 +82,9 @@ class LumaConnector:
elif response.status_code == 401:
raise Exception("Unauthorized: Invalid Luma API key")
elif response.status_code == 403:
raise Exception("Forbidden: Access denied or Luma Plus subscription required")
raise Exception(
"Forbidden: Access denied or Luma Plus subscription required"
)
elif response.status_code == 429:
raise Exception("Rate limit exceeded: Too many requests")
else:
@ -106,7 +108,9 @@ class LumaConnector:
except Exception as e:
return None, f"Error fetching user info: {e!s}"
def get_all_events(self, limit: int = 100) -> tuple[list[dict[str, Any]], str | None]:
def get_all_events(
self, limit: int = 100
) -> tuple[list[dict[str, Any]], str | None]:
"""
Fetch all events for the authenticated user.
@ -119,32 +123,34 @@ class LumaConnector:
try:
all_events = []
cursor = None
while True:
params = {"limit": limit}
if cursor:
params["cursor"] = cursor
response = self.make_request("calendar/list-events", params)
if "entries" not in response:
break
events = response["entries"]
all_events.extend(events)
# Check for pagination
if "next_cursor" in response and response["next_cursor"]:
if response.get("next_cursor"):
cursor = response["next_cursor"]
else:
break
return all_events, None
except Exception as e:
return [], f"Error fetching events: {e!s}"
def get_event_details(self, event_id: str) -> tuple[dict[str, Any] | None, str | None]:
def get_event_details(
self, event_id: str
) -> tuple[dict[str, Any] | None, str | None]:
"""
Fetch detailed information about a specific event.
@ -160,7 +166,9 @@ class LumaConnector:
except Exception as e:
return None, f"Error fetching event details for {event_id}: {e!s}"
def get_event_guests(self, event_id: str, limit: int = 100) -> tuple[list[dict[str, Any]], str | None]:
def get_event_guests(
self, event_id: str, limit: int = 100
) -> tuple[list[dict[str, Any]], str | None]:
"""
Fetch guests for a specific event.
@ -174,26 +182,26 @@ class LumaConnector:
try:
all_guests = []
cursor = None
while True:
params = {"limit": limit}
if cursor:
params["cursor"] = cursor
response = self.make_request(f"events/{event_id}/guests", params)
if "entries" not in response:
break
guests = response["entries"]
all_guests.extend(guests)
# Check for pagination
if "next_cursor" in response and response["next_cursor"]:
if response.get("next_cursor"):
cursor = response["next_cursor"]
else:
break
return all_guests, None
except Exception as e:
@ -217,7 +225,7 @@ class LumaConnector:
# Convert date strings to ISO format for comparison
start_dt = datetime.strptime(start_date, "%Y-%m-%d")
end_dt = datetime.strptime(end_date, "%Y-%m-%d")
# Get all events first
all_events, error = self.get_all_events()
if error:
@ -230,19 +238,23 @@ class LumaConnector:
if event_start_time:
try:
# Parse the event start time (assuming ISO format)
event_dt = datetime.fromisoformat(event_start_time.replace("Z", "+00:00"))
event_dt = datetime.fromisoformat(
event_start_time.replace("Z", "+00:00")
)
event_date = event_dt.date()
# Check if event falls within the date range
if start_dt.date() <= event_date <= end_dt.date():
# Add guest information if requested
if include_guests:
event_id = event.get("api_id")
if event_id:
guests, guest_error = self.get_event_guests(event_id)
guests, guest_error = self.get_event_guests(
event_id
)
if not guest_error:
event["guests"] = guests
filtered_events.append(event)
except (ValueError, AttributeError):
# Skip events with invalid dates
@ -270,45 +282,45 @@ class LumaConnector:
"""
# Extract event details
event_data = event.get("event", {})
title = event_data.get("name", "Untitled Event")
description = event_data.get("description", "")
event_id = event.get("api_id", "")
# Extract timing information
start_at = event_data.get("start_at", "")
end_at = event_data.get("end_at", "")
timezone = event_data.get("timezone", "")
# Format dates
start_formatted = self.format_date(start_at) if start_at else "Unknown"
end_formatted = self.format_date(end_at) if end_at else "Unknown"
# Extract location information
geo_info = event_data.get("geo_info", {})
location_name = geo_info.get("name", "")
address = geo_info.get("address", "")
# Extract other details
url = event_data.get("url", "")
visibility = event_data.get("visibility", "")
meeting_url = event_data.get("meeting_url", "")
# Build markdown content
markdown_content = f"# {title}\n\n"
if event_id:
markdown_content += f"**Event ID:** {event_id}\n"
# Add timing information
markdown_content += f"**Start:** {start_formatted}\n"
markdown_content += f"**End:** {end_formatted}\n"
if timezone:
markdown_content += f"**Timezone:** {timezone}\n"
markdown_content += "\n"
# Add location information
if location_name or address:
markdown_content += "## Location\n\n"
@ -317,45 +329,45 @@ class LumaConnector:
if address:
markdown_content += f"**Address:** {address}\n"
markdown_content += "\n"
# Add online meeting info
if meeting_url:
markdown_content += f"**Meeting URL:** {meeting_url}\n\n"
# Add description if available
if description:
markdown_content += f"## Description\n\n{description}\n\n"
# Add event details
markdown_content += "## Event Details\n\n"
if url:
markdown_content += f"- **Event URL:** {url}\n"
if visibility:
markdown_content += f"- **Visibility:** {visibility}\n"
# Add guest information if available
if "guests" in event:
guests = event["guests"]
markdown_content += f"\n## Guests ({len(guests)})\n\n"
for guest in guests[:10]: # Show first 10 guests
guest_data = guest.get("guest", {})
name = guest_data.get("name", "Unknown")
email = guest_data.get("email", "")
status = guest.get("registration_status", "unknown")
markdown_content += f"- **{name}**"
if email:
markdown_content += f" ({email})"
markdown_content += f" - Status: {status}\n"
if len(guests) > 10:
markdown_content += f"- ... and {len(guests) - 10} more guests\n"
markdown_content += "\n"
return markdown_content
@staticmethod

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}")

View file

@ -1951,14 +1951,15 @@ class ConnectorService:
info_parts.append(f"Venue: {location_name}")
elif location_address:
info_parts.append(f"Location: {location_address}")
if meeting_url:
info_parts.append("Online Event")
if end_time:
try:
if "T" in end_time:
from datetime import datetime
end_dt = datetime.fromisoformat(
end_time.replace("Z", "+00:00")
)
@ -1968,10 +1969,10 @@ class ConnectorService:
info_parts.append(f"Ends: {end_time}")
except Exception:
info_parts.append(f"Ends: {end_time}")
if timezone:
info_parts.append(f"TZ: {timezone}")
if visibility:
info_parts.append(f"Visibility: {visibility.title()}")

View file

@ -31,10 +31,10 @@ from .github_indexer import index_github_repos
from .google_calendar_indexer import index_google_calendar_events
from .google_gmail_indexer import index_google_gmail_messages
from .jira_indexer import index_jira_issues
from .luma_indexer import index_luma_events
# Issue tracking and project management
from .linear_indexer import index_linear_issues
from .luma_indexer import index_luma_events
# Documentation and knowledge management
from .notion_indexer import index_notion_pages

View file

@ -84,11 +84,14 @@ async def index_luma_events(
"Connector not found",
{"error_type": "ConnectorNotFound"},
)
return 0, f"Connector with ID {connector_id} not found or is not a Luma connector"
return (
0,
f"Connector with ID {connector_id} not found or is not a Luma connector",
)
# Get the Luma API key from the connector config
api_key = connector.config.get("LUMA_API_KEY")
if not api_key:
await task_logger.log_task_failure(
log_entry,
@ -97,7 +100,7 @@ async def index_luma_events(
{"error_type": "MissingCredentials"},
)
return 0, "Luma API key not found in connector config"
logger.info(f"Starting Luma indexing for connector {connector_id}")
# Initialize Luma client
@ -107,9 +110,7 @@ async def index_luma_events(
{"stage": "client_initialization"},
)
luma_client = LumaConnector(
api_key=api_key
)
luma_client = LumaConnector(api_key=api_key)
# Calculate date range
if start_date is None or end_date is None:
@ -167,9 +168,7 @@ async def index_luma_events(
# Get events within date range from Luma
try:
events, error = luma_client.get_events_by_date_range(
start_date_str,
end_date_str,
include_guests=False
start_date_str, end_date_str, include_guests=False
)
if error:
@ -221,7 +220,7 @@ async def index_luma_events(
event_id = event.get("api_id") or event_data.get("id")
event_name = event_data.get("name", "No Title")
event_url = event_data.get("url", "")
if not event_id:
logger.warning(f"Skipping event with missing ID: {event_name}")
skipped_events.append(f"{event_name} (missing ID)")
@ -240,19 +239,21 @@ async def index_luma_events(
start_at = event_data.get("start_at", "")
end_at = event_data.get("end_at", "")
timezone = event_data.get("timezone", "")
# Location info from geo_info
geo_info = event_data.get("geo_info", {})
location = geo_info.get("address", "")
city = geo_info.get("city", "")
# Host info
hosts = event_data.get("hosts", [])
host_names = ", ".join([host.get("name", "") for host in hosts if host.get("name")])
host_names = ", ".join(
[host.get("name", "") for host in hosts if host.get("name")]
)
description = event_data.get("description", "")
cover_url = event_data.get("cover_url", "")
content_hash = generate_content_hash(event_markdown, search_space_id)
# Duplicate check via simple query using helper in base
@ -311,11 +312,11 @@ async def index_luma_events(
if len(description) > 300:
desc_preview += "..."
summary_content += f"Description: {desc_preview}\n"
summary_embedding = config.embedding_model_instance.embed(
summary_content
)
chunks = await create_document_chunks(event_markdown)
document = Document(
@ -397,4 +398,4 @@ async def index_luma_events(
{"error_type": type(e).__name__},
)
logger.error(f"Failed to index Luma events: {e!s}", exc_info=True)
return 0, f"Failed to index Luma events: {e!s}"
return 0, f"Failed to index Luma events: {e!s}"

View file

@ -53,7 +53,7 @@ const getConnectorTypeDisplay = (type: string): string => {
GOOGLE_CALENDAR_CONNECTOR: "Google Calendar Connector",
GOOGLE_GMAIL_CONNECTOR: "Google Gmail Connector",
AIRTABLE_CONNECTOR: "Airtable Connector",
LUMA_CONNECTOR: "Luma Connector"
LUMA_CONNECTOR: "Luma Connector",
// Add other connector types here as needed
};
return typeMap[type] || type;
@ -72,7 +72,7 @@ const getApiKeyFieldName = (connectorType: string): string => {
GITHUB_CONNECTOR: "GITHUB_PAT",
DISCORD_CONNECTOR: "DISCORD_BOT_TOKEN",
LINKUP_API: "LINKUP_API_KEY",
LUMA_CONNECTOR: "LUMA_API_KEY"
LUMA_CONNECTOR: "LUMA_API_KEY",
};
return fieldMap[connectorType] || "";
};

View file

@ -54,7 +54,7 @@ export default function LumaConnectorPage() {
const searchSpaceId = params.search_space_id as string;
const [isSubmitting, setIsSubmitting] = useState(false);
const [doesConnectorExist, setDoesConnectorExist] = useState(false);
const { fetchConnectors, createConnector } = useSearchSourceConnectors();
// Initialize the form
@ -69,8 +69,7 @@ export default function LumaConnectorPage() {
useEffect(() => {
fetchConnectors().then((data) => {
const connector = data.find(
(c: SearchSourceConnector) =>
c.connector_type === EnumConnectorName.LUMA_CONNECTOR
(c: SearchSourceConnector) => c.connector_type === EnumConnectorName.LUMA_CONNECTOR
);
if (connector) {
setDoesConnectorExist(true);
@ -86,14 +85,14 @@ export default function LumaConnectorPage() {
name: values.name,
connector_type: EnumConnectorName.LUMA_CONNECTOR,
config: {
LUMA_API_KEY: values.api_key
LUMA_API_KEY: values.api_key,
},
is_indexable: true,
last_indexed_at: null,
});
toast.success("Luma connector created successfully!");
// Navigate back to connectors page
router.push(`/dashboard/${searchSpaceId}/connectors`);
} catch (error) {
@ -126,9 +125,7 @@ export default function LumaConnectorPage() {
</div>
<div>
<h1 className="text-3xl font-bold tracking-tight">Connect Luma</h1>
<p className="text-muted-foreground">
Connect your Luma account to search events.
</p>
<p className="text-muted-foreground">Connect your Luma account to search events.</p>
</div>
</div>
</div>
@ -170,11 +167,7 @@ export default function LumaConnectorPage() {
<FormItem>
<FormLabel>API Key</FormLabel>
<FormControl>
<Input
type="password"
placeholder="Enter your Luma API key"
{...field}
/>
<Input type="password" placeholder="Enter your Luma API key" {...field} />
</FormControl>
<FormDescription>
Your API key will be encrypted and stored securely.

View file

@ -146,7 +146,7 @@ const connectorCategories: ConnectorCategory[] = [
description: "Connect to Luma to search events",
icon: getConnectorIcon(EnumConnectorName.LUMA_CONNECTOR, "h-6 w-6"),
status: "available",
}
},
],
},
{

View file

@ -43,6 +43,6 @@ export const editConnectorSchema = z.object({
GOOGLE_CALENDAR_CLIENT_SECRET: z.string().optional(),
GOOGLE_CALENDAR_REFRESH_TOKEN: z.string().optional(),
GOOGLE_CALENDAR_CALENDAR_IDS: z.string().optional(),
LUMA_API_KEY: z.string().optional()
LUMA_API_KEY: z.string().optional(),
});
export type EditConnectorFormValues = z.infer<typeof editConnectorSchema>;

View file

@ -13,5 +13,5 @@ export enum EnumConnectorName {
GOOGLE_CALENDAR_CONNECTOR = "GOOGLE_CALENDAR_CONNECTOR",
GOOGLE_GMAIL_CONNECTOR = "GOOGLE_GMAIL_CONNECTOR",
AIRTABLE_CONNECTOR = "AIRTABLE_CONNECTOR",
LUMA_CONNECTOR = "LUMA_CONNECTOR"
LUMA_CONNECTOR = "LUMA_CONNECTOR",
}

View file

@ -10,10 +10,10 @@ import {
IconLayoutKanban,
IconLinkPlus,
IconMail,
IconSparkles,
IconTable,
IconTicket,
IconWorldWww,
IconSparkles,
} from "@tabler/icons-react";
import { File, Globe, Link, Microscope, Search, Sparkles, Telescope, Webhook } from "lucide-react";
import { EnumConnectorName } from "./connector";

View file

@ -52,7 +52,7 @@ export function useConnectorEditPage(connectorId: number, searchSpaceId: string)
JIRA_BASE_URL: "",
JIRA_EMAIL: "",
JIRA_API_TOKEN: "",
LUMA_API_KEY: ""
LUMA_API_KEY: "",
},
});
@ -79,7 +79,7 @@ export function useConnectorEditPage(connectorId: number, searchSpaceId: string)
JIRA_BASE_URL: config.JIRA_BASE_URL || "",
JIRA_EMAIL: config.JIRA_EMAIL || "",
JIRA_API_TOKEN: config.JIRA_API_TOKEN || "",
LUMA_API_KEY: config.LUMA_API_KEY || ""
LUMA_API_KEY: config.LUMA_API_KEY || "",
});
if (currentConnector.connector_type === "GITHUB_CONNECTOR") {
const savedRepos = config.repo_full_names || [];
@ -312,7 +312,7 @@ export function useConnectorEditPage(connectorId: number, searchSpaceId: string)
setIsSaving(false);
return;
}
newConfig = { LUMA_API_KEY: formData.LUMA_API_KEY};
newConfig = { LUMA_API_KEY: formData.LUMA_API_KEY };
}
break;
}

View file

@ -15,7 +15,7 @@ export const getConnectorTypeDisplay = (type: string): string => {
GOOGLE_CALENDAR_CONNECTOR: "Google Calendar",
GOOGLE_GMAIL_CONNECTOR: "Google Gmail",
AIRTABLE_CONNECTOR: "Airtable",
LUMA_CONNECTOR: "Luma"
LUMA_CONNECTOR: "Luma",
};
return typeMap[type] || type;
};