mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
drop_closure exists to refuse a drop that is really a refactor: if code we keep still imports a product, deleting it is a ModuleNotFoundError waiting for the next boot. It only ever read Python, so half the dependency graph was invisible to it and five products whose TypeScript the core still imports were dropped anyway — 21 files left importing 25 specifiers that resolve to nothing, including lib/api.ts, which 760 files import, and seven lazy scene imports in productScenes.tsx. Django booted past it and the bundle did not, which is why the Python-only rule looked like it was working. The closure now reads both module systems through one table of (extensions, pattern) pairs, so a third one is a row rather than a branch. The TypeScript pattern is anchored on the import keyword rather than on the path, because jest's testPathIgnorePatterns and oxlint's ignore list quote a product path precisely because it is NOT built; matching those would hold desktop, the 4,797-file product the drop is mostly for. integrations, wizard, platform_features, visual_review and ai_gateway come back with their Django apps and workspace entries, since the closure now spares them. desktop, field_notes, ingestion and support stay dropped.
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
"""
|
|
Facade for wizard.
|
|
|
|
The ONLY module other products are allowed to import.
|
|
Accept frozen dataclasses, call logic/, return frozen
|
|
dataclasses. Never return ORM instances or import DRF.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import AsyncIterator
|
|
from contextlib import asynccontextmanager
|
|
from typing import Any
|
|
|
|
from products.wizard.backend import metrics
|
|
from products.wizard.backend.facade.contracts import UpsertWizardSessionInput, WizardSessionDTO
|
|
from products.wizard.backend.logic import pubsub, sessions
|
|
|
|
|
|
def upsert(params: UpsertWizardSessionInput) -> tuple[WizardSessionDTO, bool]:
|
|
"""Returns `(dto, created)` so callers can pick 201 vs 200."""
|
|
return sessions.upsert_session(params)
|
|
|
|
|
|
def get(team_id: int, session_id: str) -> WizardSessionDTO | None:
|
|
return sessions.get_session(team_id, session_id)
|
|
|
|
|
|
def get_latest(team_id: int, workflow_id: str, skill_id: str | None = None) -> WizardSessionDTO | None:
|
|
return sessions.get_latest_session(team_id, workflow_id, skill_id)
|
|
|
|
|
|
def list_for_team(
|
|
team_id: int,
|
|
workflow_id: str | None = None,
|
|
skill_id: str | None = None,
|
|
*,
|
|
offset: int = 0,
|
|
limit: int | None = None,
|
|
) -> list[WizardSessionDTO]:
|
|
return sessions.list_sessions(
|
|
team_id,
|
|
workflow_id=workflow_id,
|
|
skill_id=skill_id,
|
|
offset=offset,
|
|
limit=limit,
|
|
)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def subscribe_to_updates(
|
|
team_id: int,
|
|
workflow_id: str,
|
|
skill_id: str | None = None,
|
|
) -> AsyncIterator[Any]:
|
|
async with pubsub.subscribe(team_id, workflow_id, skill_id) as ps:
|
|
yield ps
|
|
|
|
|
|
def serialize_dto(dto: WizardSessionDTO) -> bytes:
|
|
return pubsub.serialize_dto(dto)
|
|
|
|
|
|
def record_latest_session_poll(raw_source: str | None, result: str) -> None:
|
|
metrics.WIZARD_LATEST_SESSION_REQUESTS_TOTAL.labels(
|
|
source=metrics.poll_source_label(raw_source), result=result
|
|
).inc()
|