ozellik: google oauth, gmail-drive araclari ve admin durum kartlarini ekle

This commit is contained in:
2026-03-22 18:50:06 +03:00
parent 177fd8e1a7
commit ad847b1cf4
20 changed files with 970 additions and 14 deletions

View File

@@ -113,6 +113,49 @@ class SecondBrainTool(Tool):
"raw": data,
}
async def status(self) -> dict[str, Any]:
if not self.base_url:
return {"reachable": False, "workspace_found": False, "message": "AnythingLLM base URL is not configured."}
if not self.workspace_slug:
return {
"reachable": False,
"workspace_found": False,
"message": "AnythingLLM workspace slug is not configured.",
}
if not self.api_key:
return {"reachable": False, "workspace_found": False, "message": "AnythingLLM API key is not configured."}
endpoint = f"{self.base_url}/api/v1/workspaces"
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}
try:
async with httpx.AsyncClient(timeout=15.0) as client:
response = await client.get(endpoint, headers=headers)
response.raise_for_status()
except httpx.HTTPError as exc:
return {"reachable": False, "workspace_found": False, "message": str(exc)}
try:
data = response.json()
except ValueError:
return {"reachable": False, "workspace_found": False, "message": "AnythingLLM returned invalid JSON."}
workspaces = self._extract_workspaces(data)
slug_match = next((item for item in workspaces if item == self.workspace_slug), None)
if slug_match:
return {
"reachable": True,
"workspace_found": True,
"message": f"Workspace {self.workspace_slug} is reachable.",
}
return {
"reachable": True,
"workspace_found": False,
"message": f"Workspace {self.workspace_slug} was not found.",
}
def _build_query_prompt(self, query: str, mode: str) -> str:
if mode == "query":
return (
@@ -128,13 +171,18 @@ class SecondBrainTool(Tool):
try:
payload = response.json()
except ValueError:
return f"HTTP {response.status_code}"
text = response.text.strip()
return text or f"HTTP {response.status_code}"
if isinstance(payload, dict):
for key in ("error", "message"):
value = payload.get(key)
if isinstance(value, str) and value.strip():
return value.strip()
return f"HTTP {response.status_code}"
detail = payload.get("detail")
if isinstance(detail, str) and detail.strip():
return detail.strip()
text = response.text.strip()
return text or f"HTTP {response.status_code}"
def _extract_text_response(self, data: Any) -> str:
if isinstance(data, dict):
@@ -162,3 +210,24 @@ class SecondBrainTool(Tool):
}
)
return sources
def _extract_workspaces(self, data: Any) -> list[str]:
if isinstance(data, dict):
for key in ("workspaces", "data"):
value = data.get(key)
if isinstance(value, list):
return self._workspace_slugs_from_list(value)
if isinstance(data, list):
return self._workspace_slugs_from_list(data)
return []
def _workspace_slugs_from_list(self, items: list[Any]) -> list[str]:
slugs: list[str] = []
for item in items:
if isinstance(item, dict):
for key in ("slug", "name"):
value = item.get(key)
if isinstance(value, str) and value.strip():
slugs.append(value.strip())
break
return slugs