refactor(backend): update API routes and service layer

- Update agent router/service/repository with new endpoints
- Update auth routes with phone-based authentication
- Update users service with new phone lookup
- Update schedule_items with new schemas
- Update message schemas with visibility support
- Update settings with new automation scheduler config
- Update CLI with new commands
- Update tests to match new API contracts
This commit is contained in:
qzl
2026-03-19 18:42:59 +08:00
parent 641d847008
commit f0af44d840
36 changed files with 1083 additions and 1853 deletions
+1 -1
View File
@@ -7,5 +7,5 @@ from uuid import UUID
@dataclass(frozen=True)
class CurrentUser:
id: UUID
email: str | None = None
phone: str | None = None
role: str | None = None
+9 -1
View File
@@ -61,6 +61,7 @@ class RuntimeSettings(BaseModel):
]
)
sql_log_queries: bool = False
trusted_proxy_ips: list[str] = Field(default_factory=list)
@field_validator("log_dir", mode="before")
@classmethod
@@ -162,6 +163,12 @@ class AgentRuntimeSettings(BaseModel):
user_context_cache_max_turns: int = Field(default=6, ge=1, le=100)
class AutomationSchedulerSettings(BaseModel):
enabled: bool = True
interval_seconds: int = Field(default=60, ge=5, le=3600)
batch_limit: int = Field(default=100, ge=1, le=1000)
class LlmSettings(BaseModel):
provider_keys: dict[str, str] = Field(default_factory=dict)
@@ -225,7 +232,7 @@ class AppVersionSettings(BaseModel):
class TestSettings(BaseModel):
email: str = ""
phone: str = ""
password: str = ""
@@ -250,6 +257,7 @@ class Settings(BaseSettings):
llm: LlmSettings = LlmSettings()
litellm: LiteLLMSettings = LiteLLMSettings()
agent_runtime: AgentRuntimeSettings = AgentRuntimeSettings()
automation_scheduler: AutomationSchedulerSettings = AutomationSchedulerSettings()
taskiq: TaskiqSettings = TaskiqSettings()
database: DatabaseSettings = DatabaseSettings()
app_version: AppVersionSettings = AppVersionSettings()
+30 -2
View File
@@ -5,6 +5,8 @@ import subprocess
import sys
from pathlib import Path
from core.agentscope.runtime.tasks import run_automation_scheduler_scan
from core.config.settings import config
from core.config.initial.init_data import initialize_data
from core.logging import get_logger
@@ -101,12 +103,34 @@ async def bootstrap() -> bool:
return True
async def run_automation_scheduler_forever() -> bool:
if not config.automation_scheduler.enabled:
logger.info("Automation scheduler disabled by config")
return True
interval_seconds = int(config.automation_scheduler.interval_seconds)
batch_limit = int(config.automation_scheduler.batch_limit)
logger.info(
"Starting automation scheduler loop",
interval_seconds=interval_seconds,
batch_limit=batch_limit,
)
while True:
try:
await run_automation_scheduler_scan(limit=batch_limit)
except Exception as exc:
logger.exception("Automation scheduler scan failed", error=str(exc))
await asyncio.sleep(interval_seconds)
def main() -> int:
"""CLI entry point."""
if len(sys.argv) < 2:
logger.error("No command provided")
logger.info("Usage: python -m core.runtime.cli <command>")
logger.info("Available commands: migrate, init-data, bootstrap")
logger.info(
"Available commands: migrate, init-data, bootstrap, automation-scheduler"
)
return 1
command = sys.argv[1]
@@ -117,9 +141,13 @@ def main() -> int:
success = asyncio.run(run_init_data())
elif command == "bootstrap":
success = asyncio.run(bootstrap())
elif command == "automation-scheduler":
success = asyncio.run(run_automation_scheduler_forever())
else:
logger.error("Unknown command", command=command)
logger.info("Available commands: migrate, init-data, bootstrap")
logger.info(
"Available commands: migrate, init-data, bootstrap, automation-scheduler"
)
return 1
return 0 if success else 1