27b66d6753
Introduce an always-on auth layer with auto-created admin on first boot, multi-tenant isolation for threads/stores, and a full setup/login flow. Backend - JWT access tokens with `ver` field for stale-token rejection; bump on password/email change - Password hashing, HttpOnly+Secure cookies (Secure derived from request scheme at runtime) - CSRF middleware covering both REST and LangGraph routes - IP-based login rate limiting (5 attempts / 5-min lockout) with bounded dict growth and X-Forwarded-For bypass fix - Multi-worker-safe admin auto-creation (single DB write, WAL once) - needs_setup + token_version on User model; SQLite schema migration - Thread/store isolation by owner; orphan thread migration on first admin registration - thread_id validated as UUID to prevent log injection - CLI tool to reset admin password - Decorator-based authz module extracted from auth core Frontend - Login and setup pages with SSR guard for needs_setup flow - Account settings page (change password / email) - AuthProvider + route guards; skips redirect when no users registered - i18n (en-US / zh-CN) for auth surfaces - Typed auth API client; parseAuthError unwraps FastAPI detail envelope Infra & tooling - Unified `serve.sh` with gateway mode + auto dep install - Public PyPI uv.toml pin for CI compatibility - Regenerated uv.lock with public index Tests - HTTP vs HTTPS cookie security tests - Auth middleware, rate limiter, CSRF, setup flow coverage
90 lines
2.7 KiB
Python
90 lines
2.7 KiB
Python
"""Subagent registry for managing available subagents."""
|
|
|
|
import logging
|
|
from dataclasses import replace
|
|
|
|
from deerflow.sandbox.security import is_host_bash_allowed
|
|
from deerflow.subagents.builtins import BUILTIN_SUBAGENTS
|
|
from deerflow.subagents.config import SubagentConfig
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def get_subagent_config(name: str) -> SubagentConfig | None:
|
|
"""Get a subagent configuration by name, with config.yaml overrides applied.
|
|
|
|
Args:
|
|
name: The name of the subagent.
|
|
|
|
Returns:
|
|
SubagentConfig if found (with any config.yaml overrides applied), None otherwise.
|
|
"""
|
|
config = BUILTIN_SUBAGENTS.get(name)
|
|
if config is None:
|
|
return None
|
|
|
|
# Apply timeout override from config.yaml (lazy import to avoid circular deps)
|
|
from deerflow.config.subagents_config import get_subagents_app_config
|
|
|
|
app_config = get_subagents_app_config()
|
|
effective_timeout = app_config.get_timeout_for(name)
|
|
effective_max_turns = app_config.get_max_turns_for(name, config.max_turns)
|
|
|
|
overrides = {}
|
|
if effective_timeout != config.timeout_seconds:
|
|
logger.debug(
|
|
"Subagent '%s': timeout overridden by config.yaml (%ss -> %ss)",
|
|
name,
|
|
config.timeout_seconds,
|
|
effective_timeout,
|
|
)
|
|
overrides["timeout_seconds"] = effective_timeout
|
|
if effective_max_turns != config.max_turns:
|
|
logger.debug(
|
|
"Subagent '%s': max_turns overridden by config.yaml (%s -> %s)",
|
|
name,
|
|
config.max_turns,
|
|
effective_max_turns,
|
|
)
|
|
overrides["max_turns"] = effective_max_turns
|
|
if overrides:
|
|
config = replace(config, **overrides)
|
|
|
|
return config
|
|
|
|
|
|
def list_subagents() -> list[SubagentConfig]:
|
|
"""List all available subagent configurations (with config.yaml overrides applied).
|
|
|
|
Returns:
|
|
List of all registered SubagentConfig instances.
|
|
"""
|
|
return [get_subagent_config(name) for name in BUILTIN_SUBAGENTS]
|
|
|
|
|
|
def get_subagent_names() -> list[str]:
|
|
"""Get all available subagent names.
|
|
|
|
Returns:
|
|
List of subagent names.
|
|
"""
|
|
return list(BUILTIN_SUBAGENTS.keys())
|
|
|
|
|
|
def get_available_subagent_names() -> list[str]:
|
|
"""Get subagent names that should be exposed to the active runtime.
|
|
|
|
Returns:
|
|
List of subagent names visible to the current sandbox configuration.
|
|
"""
|
|
names = list(BUILTIN_SUBAGENTS.keys())
|
|
try:
|
|
host_bash_allowed = is_host_bash_allowed()
|
|
except Exception:
|
|
logger.debug("Could not determine host bash availability; exposing all built-in subagents")
|
|
return names
|
|
|
|
if not host_bash_allowed:
|
|
names = [name for name in names if name != "bash"]
|
|
return names
|