chore(prep): shared groundwork for the parallel task batch
多 agent 并行批次的协调提交(消除全部共享文件冲突面): - 迁移 0004:id_session + ob_event 两表(T3/T4 用,任务不再写迁移) - ORM:UserSession / ObEvent;错误码:九个新码(40xxx/60006,含 meta) - 配置:四档 tiers / refresh TTL / 任务奖励注册表 / 埋点上限 / COS 直传全套 - 骨架:packages/analytics + packages/storage + events/uploads 空路由(已注册) - deps:AnalyticsServiceDep / StorageServiceDep;DailyBudgetGuard 接收 tiers - uv add cos-python-sdk-v5;import-linter/CI/Makefile 纳入两个新包
This commit is contained in:
Executable → Regular
+13
@@ -16,6 +16,7 @@ from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from packages.agent.service import AgentService
|
||||
from packages.analytics.service import AnalyticsService
|
||||
from packages.billing.service import BillingService
|
||||
from packages.identity.service import IdentityService
|
||||
from packages.llm.budget import DailyBudgetGuard, RedisCostCounter
|
||||
@@ -39,6 +40,7 @@ from packages.shared.db import get_session_factory
|
||||
from packages.shared.errors import AppError, ErrorCode
|
||||
from packages.shared.redis_client import get_redis
|
||||
from packages.shared.security import decode_access_token
|
||||
from packages.storage.service import StorageService
|
||||
from packages.task.service import TaskService
|
||||
|
||||
bearer_scheme = HTTPBearer(auto_error=False)
|
||||
@@ -99,6 +101,7 @@ def build_llm_gateway(settings: Settings) -> LLMGateway:
|
||||
daily_budget_cents=Decimal(settings.llm_daily_budget_cents),
|
||||
enabled=settings.llm_daily_budget_enabled,
|
||||
tz_offset_hours=settings.llm_budget_timezone_offset_hours,
|
||||
tiers=list(settings.llm_budget_tiers),
|
||||
)
|
||||
|
||||
return LLMGateway(
|
||||
@@ -180,6 +183,14 @@ def task_service_dep(session: SessionDep) -> TaskService:
|
||||
return TaskService(session)
|
||||
|
||||
|
||||
def analytics_service_dep(session: SessionDep) -> AnalyticsService:
|
||||
return AnalyticsService(session)
|
||||
|
||||
|
||||
def storage_service_dep(settings: SettingsDep) -> StorageService:
|
||||
return StorageService(settings)
|
||||
|
||||
|
||||
def agent_service_dep(
|
||||
session: SessionDep,
|
||||
gateway: GatewayDep,
|
||||
@@ -191,4 +202,6 @@ def agent_service_dep(
|
||||
IdentityServiceDep = Annotated[IdentityService, Depends(identity_service_dep)]
|
||||
BillingServiceDep = Annotated[BillingService, Depends(billing_service_dep)]
|
||||
TaskServiceDep = Annotated[TaskService, Depends(task_service_dep)]
|
||||
AnalyticsServiceDep = Annotated[AnalyticsService, Depends(analytics_service_dep)]
|
||||
StorageServiceDep = Annotated[StorageService, Depends(storage_service_dep)]
|
||||
AgentServiceDep = Annotated[AgentService, Depends(agent_service_dep)]
|
||||
|
||||
Executable → Regular
+3
-2
@@ -12,7 +12,7 @@ from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
|
||||
from apps.api.deps import build_llm_gateway
|
||||
from apps.api.routers import agent, auth, health, quota, tasks
|
||||
from apps.api.routers import agent, auth, events, health, quota, tasks, uploads
|
||||
from packages.shared.config import Settings, get_settings
|
||||
from packages.shared.db import dispose_engine
|
||||
from packages.shared.handlers import install_exception_handlers
|
||||
@@ -69,7 +69,8 @@ def create_app(settings: Settings | None = None) -> FastAPI:
|
||||
setup_tracing(app, cfg)
|
||||
|
||||
app.include_router(health.router)
|
||||
for router in (auth.router, agent.router, quota.router, tasks.router):
|
||||
routers = (auth.router, agent.router, quota.router, tasks.router, events.router, uploads.router)
|
||||
for router in routers:
|
||||
app.include_router(router, prefix=cfg.api_prefix)
|
||||
|
||||
return app
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
"""``POST /events/batch`` — 客户端埋点批量上报(骨架,T3 填充实现)。
|
||||
|
||||
FR-SYS-06 服务端入口;实现契约见 docs/开发任务包/T3-埋点上报.md。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(prefix="/events", tags=["events"])
|
||||
@@ -0,0 +1,10 @@
|
||||
"""``POST /uploads/presign`` — COS 直传预签名(骨架,T5 填充实现)。
|
||||
|
||||
FR-SYS-03:图片不经应用服务器;实现契约见 docs/开发任务包/T5-上传预签名.md。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(prefix="/uploads", tags=["uploads"])
|
||||
Reference in New Issue
Block a user