Files
kamidso-back/kamidso/native_connectors/semantic/aggregates.py
T
javadandCursor edbaa2acec Add native Didar connectors so chats can query CRM data reliably.
Connector calls, semantic rules, and DuckDB memory keep long runs stable, and stream retry stops chats from stalling.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-12 19:26:47 +03:30

36 lines
1.1 KiB
Python

"""Search Deal totals come from response aggregates, never from the current page length."""
from __future__ import annotations
from typing import Any, Optional, Tuple
from kamidso.native_connectors.result_store import get_nested
from kamidso.native_connectors.semantic.text import normalize_text
def as_int(value: Any) -> Optional[int]:
if isinstance(value, bool) or value is None:
return None
if isinstance(value, int):
return value
if isinstance(value, str) and value.strip().isdigit():
return int(value.strip())
return None
def aggregate_count(payload: Any, source: str) -> Optional[int]:
return as_int(get_nested(payload, source))
def count_for_question(payload: Any, question: str) -> Tuple[str, Optional[int]]:
text = normalize_text(question)
if "ناموفق" in text:
source = "Response.LostDealsCount"
elif "جاری" in text:
source = "Response.PendingDealsCount"
elif "موفق" in text:
source = "Response.WonDealsCount"
else:
source = "Response.TotalCount"
return source, aggregate_count(payload, source)