bugfix: route stickness precedences (transaction in the same intent)

This commit is contained in:
2026-08-20 09:22:03 -03:00
parent bb0ef019bf
commit 9df2467deb
434 changed files with 7098 additions and 281 deletions

View File

@@ -37,6 +37,47 @@ class ContasDomainService:
def consultar_faturas(self, *, msisdn: str, **_: Any) -> Any:
return self.client.consultar_faturas(msisdn)
def consultar_plano(self, *, msisdn: str, **args: Any) -> dict[str, Any]:
"""Retorna somente os planos presentes na evidência de billing analysis.
A consulta é deliberadamente determinística: não usa VAS, RAG nem o
workflow de invoice_explanation para responder qual é o plano do cliente.
"""
billing = args.get("billing_analysis")
if not isinstance(billing, dict):
billing = self.client.billing_analysis(
msisdn,
invoice_id=args.get("invoice_id"),
customer_id=args.get("customer_id"),
)
plans: list[dict[str, Any]] = []
for section in billing.get("currentInvoice") or [] if isinstance(billing, dict) else []:
if not isinstance(section, dict):
continue
section_type = str(section.get("type") or "").strip().casefold()
section_desc = str(section.get("desc") or "").strip().casefold()
if section_type not in {"plano", "planos"} and section_desc not in {"plano", "planos"}:
continue
for item in section.get("items") or []:
if not isinstance(item, dict):
continue
name = str(item.get("desc") or item.get("name") or "").strip()
if not name:
continue
plans.append({
"name": name,
"value": item.get("value"),
"type": str(item.get("type") or section.get("type") or "plano"),
"contestable": item.get("contestable"),
})
return {
"plans": plans,
"count": len(plans),
"source": "billing_analysis.currentInvoice",
}
def invoice_explanation(self, *, msisdn: str, **args: Any) -> dict[str, Any]:
# Reuse framework-prefetched evidence when available; the domain never owns
# a second cache/session implementation. Explanation itself is produced by