added quick connect auth from jellyfin, still needs to have some more cleaning before push to prod
This commit is contained in:
+26
-1
@@ -47,6 +47,7 @@ class Skill:
|
||||
prompt_fragment: str = ""
|
||||
tools: List[Dict[str, Any]] = field(default_factory=list)
|
||||
execute: Optional[ToolExecutor] = None
|
||||
requires_auth: List[str] = field(default_factory=list)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -96,9 +97,15 @@ def get_all_tools(skill_names: list[str]) -> List[Dict[str, Any]]:
|
||||
|
||||
|
||||
async def execute_tool(
|
||||
skill_names: list[str], tool_name: str, args: dict
|
||||
skill_names: list[str], tool_name: str, args: dict,
|
||||
discord_user_id: int | None = None,
|
||||
) -> ToolResult | None:
|
||||
"""Find the skill that owns *tool_name* and run its executor.
|
||||
|
||||
If *discord_user_id* is provided, also checks whether the owning skill
|
||||
requires authentication for any services. If auth is missing, returns
|
||||
a friendly ToolResult.fail(...) telling the user how to log in.
|
||||
|
||||
Only logs failures to the console — successful calls are silent.
|
||||
"""
|
||||
import logging
|
||||
@@ -109,6 +116,24 @@ async def execute_tool(
|
||||
if s and s.execute:
|
||||
for t in s.tools:
|
||||
if t.get("function", {}).get("name") == tool_name:
|
||||
# --- Auth gate ---
|
||||
if s.requires_auth and discord_user_id is not None:
|
||||
from core import auth_store
|
||||
from auth import get_auth_service
|
||||
missing: list[str] = []
|
||||
for svc in s.requires_auth:
|
||||
if not auth_store.is_authenticated(discord_user_id, svc):
|
||||
missing.append(svc)
|
||||
if missing:
|
||||
svc_displays = ", ".join(
|
||||
(get_auth_service(m) and get_auth_service(m).display_name) or m
|
||||
for m in missing
|
||||
)
|
||||
return ToolResult.fail(
|
||||
f"You need to log in to {svc_displays} first. "
|
||||
+ " ".join(f"Send `/login {m}` in a DM to get started." for m in missing)
|
||||
)
|
||||
# --- End auth gate ---
|
||||
try:
|
||||
result = await s.execute(tool_name, args)
|
||||
if not result.success:
|
||||
|
||||
Reference in New Issue
Block a user