feat: add BLIF Flow v2 authoritative operational adapter
This commit is contained in:
@@ -321,13 +321,14 @@ def _opportunity_item(
|
||||
rows: list[Mapping[str, Any]],
|
||||
decision: Mapping[str, Any],
|
||||
) -> tuple[dict[str, Any] | None, list[dict[str, Any]]]:
|
||||
authoritative = decision.get("authoritative_v2") is True
|
||||
scheduled_call = next((
|
||||
row for row in rows
|
||||
if row.get("source") == "task"
|
||||
and _s(row.get("status")).lower() == "pending"
|
||||
and _canonical_code(row.get("action_code")) == "CALL_CUSTOMER"
|
||||
), None)
|
||||
if scheduled_call:
|
||||
if scheduled_call and not authoritative:
|
||||
decision = {
|
||||
**dict(decision),
|
||||
"action_code": "CALL_CUSTOMER",
|
||||
@@ -347,26 +348,29 @@ def _opportunity_item(
|
||||
evidence_rows.append(row)
|
||||
|
||||
if action_code in NO_WORK_ACTION_CODES:
|
||||
if not _has_explicit_unresolved_review(evidence_rows):
|
||||
if decision.get("suppress_current_card"):
|
||||
return None, independent_exceptions
|
||||
# The central decision normally wins, but an explicit unresolved review
|
||||
# marker must not be hidden by NO_ACTION/NOT_FOUND.
|
||||
action_code = "REVIEW"
|
||||
decision = {
|
||||
**dict(decision),
|
||||
"action_code": action_code,
|
||||
"label": "Rever evidência pendente",
|
||||
"description": "A decisão central indica que não há ação, mas existe evidência explicitamente marcada para revisão.",
|
||||
"reason": "Existe revisão humana não resolvida apesar da decisão central sem ação.",
|
||||
"priority": "normal",
|
||||
"target_url": f"/opportunities/{opportunity_id}",
|
||||
}
|
||||
keep_authoritative_noncurrent = authoritative and _s(decision.get("operational_queue")) in {"waiting", "backlog"}
|
||||
if not keep_authoritative_noncurrent:
|
||||
if not _has_explicit_unresolved_review(evidence_rows):
|
||||
return None, independent_exceptions
|
||||
# The central decision normally wins, but an explicit unresolved
|
||||
# review marker must not be hidden by NO_ACTION/NOT_FOUND.
|
||||
action_code = "REVIEW"
|
||||
decision = {
|
||||
**dict(decision), "action_code": action_code,
|
||||
"label": "Rever evidência pendente",
|
||||
"description": "A decisão central indica que não há ação, mas existe evidência explicitamente marcada para revisão.",
|
||||
"reason": "Existe revisão humana não resolvida apesar da decisão central sem ação.",
|
||||
"priority": "normal", "target_url": f"/opportunities/{opportunity_id}",
|
||||
}
|
||||
|
||||
matching_task = scheduled_call or _matching_task(evidence_rows, action_code)
|
||||
primary = matching_task or next((row for row in evidence_rows if row.get("source") == "task"), None)
|
||||
primary = primary or (evidence_rows[0] if evidence_rows else {})
|
||||
process_key = f"opportunity:{opportunity_id}"
|
||||
waiting = _is_waiting(decision)
|
||||
decision_queue = _s(decision.get("operational_queue")) if authoritative else ""
|
||||
opportunity_row = next((row for row in evidence_rows if _s(row.get("fiscal_customer_name"))), None)
|
||||
opportunity_row = opportunity_row or next((row for row in evidence_rows if _s(row.get("opportunity_title"))), None)
|
||||
opportunity_row = opportunity_row or primary
|
||||
@@ -383,7 +387,7 @@ def _opportunity_item(
|
||||
"detail": _s(decision.get("description") or decision.get("reason")),
|
||||
"why_human_required": _s(decision.get("reason") or decision.get("description")),
|
||||
"priority": _s(decision.get("priority")) or _best_priority(evidence_rows),
|
||||
"operational_queue": "waiting" if waiting else "do_now",
|
||||
"operational_queue": decision_queue or ("waiting" if waiting else "do_now"),
|
||||
"queue": _s((matching_task or primary).get("queue")) or _s(primary.get("queue")) or "rever",
|
||||
"status": "waiting" if waiting else "pending",
|
||||
"href": _s((matching_task or {}).get("href")) or _s(decision.get("target_url")) or f"/opportunities/{opportunity_id}",
|
||||
@@ -400,6 +404,10 @@ def _opportunity_item(
|
||||
],
|
||||
"decision_version": decision.get("decision_version"),
|
||||
"decision": dict(decision),
|
||||
"business_state": decision.get("business_state"),
|
||||
"business_next_action": decision.get("business_next_action"),
|
||||
"effective_action": decision.get("effective_action"),
|
||||
"canonical_opportunity_id": decision.get("canonical_opportunity_id") or opportunity_id,
|
||||
})
|
||||
return item, independent_exceptions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user