feat(MAT-65): Remove WildFiles org-level fallback, require per-user key

No more shared org-level document search for unauthenticated users.
DocumentRAG.search() now returns empty if no API key provided.
Explicit !ai search command tells users to connect first.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Christian Gick
2026-02-28 16:21:01 +02:00
parent 18607e39b5
commit 34f403a066

11
bot.py
View File

@@ -319,15 +319,11 @@ class DocumentRAG:
self.enabled = bool(base_url and org)
async def search(self, query: str, top_k: int = 3, api_key: str | None = None) -> list[dict]:
if not api_key and not self.enabled:
if not api_key:
return []
try:
headers = {}
headers = {"X-API-Key": api_key}
body = {"query": query, "limit": top_k}
if api_key:
headers["X-API-Key"] = api_key
else:
body["organization"] = self.org
async with httpx.AsyncClient(timeout=15.0) as client:
resp = await client.post(
f"{self.base_url}/api/v1/rag/search",
@@ -1809,6 +1805,9 @@ class Bot:
return
sender = event.sender if event else None
user_api_key = self.user_keys.get(sender) if sender else None
if not user_api_key:
await self._send_text(room.room_id, "WildFiles not connected. Use `!ai wildfiles connect` first.")
return
results = await self.rag.search(query, top_k=5, api_key=user_api_key)
if not results:
await self._send_text(room.room_id, "No documents found.")