Spaces:
Sleeping
Sleeping
| """Regulation API — schema registry and structured rules.""" | |
| from __future__ import annotations | |
| from typing import Any, Optional | |
| from fastapi import APIRouter, Depends, HTTPException, Query | |
| from pydantic import BaseModel, Field | |
| from core.regulation.schema_registry import get_all_schemas, get_schema, list_schema_ids | |
| from core.search.regulation_engine import regulation_engine | |
| from core.subscription.middleware import verify_token | |
| router = APIRouter(prefix="/api/regulation", tags=["regulation"]) | |
| class StructuredRulesResponse(BaseModel): | |
| program: str | |
| rules: dict[str, Any] | |
| async def regulation_schemas( | |
| schema_id: Optional[str] = Query(None, description="Opcjonalny identyfikator schematu"), | |
| token_data: dict = Depends(verify_token), | |
| ): | |
| _ = token_data | |
| if schema_id: | |
| schema = get_schema(schema_id) | |
| if not schema: | |
| raise HTTPException(status_code=404, detail=f"Nieznany schemat: {schema_id}") | |
| return {"schema_id": schema_id, "schema": schema} | |
| return { | |
| "schema_ids": list_schema_ids(), | |
| "schemas": get_all_schemas(), | |
| } | |
| async def structured_rules_for_program( | |
| program_name: str, | |
| token_data: dict = Depends(verify_token), | |
| ): | |
| _ = token_data | |
| rules = regulation_engine.get_structured_rules_for_program(program_name) | |
| return StructuredRulesResponse(program=program_name, rules=rules) | |