"""Wiring for the AI-workforce workstream (team bootstrap). The org wizard calls ``build_workforce_bootstrap(session)`` after it commits a new organization, then ``bootstrap_team`` creates the starting team. The team is built on the *caller's* session, so the employees and the "waiting for a model" note land in the same transaction as the organization. """ from __future__ import annotations from sqlalchemy.ext.asyncio import AsyncSession from app.application.ports.workforce_bootstrap import WorkforceBootstrapPort class _EngineWorkforceBootstrap: """The real bootstrap: one manager, planner, developer and tester. Everything is built here, lazily, from the session: ``container.py`` is a frozen composition root and the engine must not widen it, so the repos and ports the manager needs are assembled where they are used. """ def __init__(self, session: AsyncSession) -> None: self.session = session async def bootstrap_team(self, *, organization_id: str, project_id: str) -> None: from app.application.container import get_model_provider from app.application.container_org import build_memory, build_model_grants from app.application.engine.manager import ManagerTurns from app.infrastructure.repositories.ai_control import ( AiModelRepository, ModelCredentialRepository, RateCardRepository, ) from app.infrastructure.repositories.audit import UsageLedgerRepository from app.infrastructure.repositories.engine import ( EmployeeProfileRepository, PipelineStateRepository, ) from app.infrastructure.repositories.workforce import ( EmployeeRepository, MessageRepository, TaskRepository, ThreadRepository, ) session = self.session manager = ManagerTurns( provider=get_model_provider(), employees=EmployeeRepository(session), messages=MessageRepository(session), tasks=TaskRepository(session), threads=ThreadRepository(session), models=AiModelRepository(session), credentials=ModelCredentialRepository(session), rate_cards=RateCardRepository(session), ledger=UsageLedgerRepository(session), grants=build_model_grants(session), memory=build_memory(session), profiles=EmployeeProfileRepository(session), states=PipelineStateRepository(session), ) await manager.bootstrap_team( organization_id=organization_id, project_id=project_id ) def build_workforce_bootstrap(session: AsyncSession) -> WorkforceBootstrapPort: return _EngineWorkforceBootstrap(session) __all__ = ["build_workforce_bootstrap"]