"""Wiring for the org-platform workstream (memory, model grants). Foundation defaults: no memory, and every active model granted to every org (today's behaviour). The org-platform agent replaces the bodies with the real services; the function names and return types are FROZEN so other workstreams can call them now. """ from __future__ import annotations from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession from app.application.ports.memory import MemoryPort, NullMemory from app.application.ports.model_grants import ( AllActiveModelsGrants, GrantedModel, ModelGrantPort, tier_for, ) from app.infrastructure.db.models import AiModelRow _null_memory = NullMemory() def build_memory(session: AsyncSession) -> MemoryPort: return _null_memory def build_model_grants(session: AsyncSession) -> ModelGrantPort: async def _all_active() -> list[GrantedModel]: rows = (await session.scalars(select(AiModelRow).where(AiModelRow.is_active))).all() return [ GrantedModel( ai_model_id=row.id, tier=tier_for( capabilities=list(row.capabilities or []), output_price_per_1m=row.output_price_per_1m, ), capabilities=tuple(row.capabilities or []), ) for row in rows ] return AllActiveModelsGrants(_all_active)