Spaces:
Running

File size: 2,843 Bytes
0776bd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Phase 8 (Pakistan COD suite) additions to :class:`packs.ecommerce.pack.EcommercePack`, kept

here so the shared pack module only gains one line per member."""

from __future__ import annotations

from typing import Any

from core.packs.loader import AgentDeps, IntentInfo
from core.tools.spec import RegisteredTool

COD_INTENTS = [
    IntentInfo(
        "ecommerce.cod_confirm",
        "Confirm ONE cash-on-delivery order: score its RTO risk, then auto-confirm and book a "
        "courier (low risk) or ask the customer on WhatsApp (medium/high risk), e.g. "
        "'confirm ORD-1021'.",
    ),
    IntentInfo(
        "ecommerce.cod_sweep",
        "Scheduled: COD confirmations past their deadline become no_answer and are escalated.",
        chat_enabled=False,
    ),
    IntentInfo(
        "ecommerce.courier_status",
        "Courier webhook: a shipment status changed (in transit, delivered, returned...).",
        chat_enabled=False,
    ),
    IntentInfo(
        "ecommerce.courier_poll",
        "Scheduled: poll couriers for active shipments' status.",
        chat_enabled=False,
    ),
    IntentInfo(
        "ecommerce.cod_reconcile",
        "Reconcile COD remittances from couriers against delivered orders and report "
        "mismatches and missing payments, e.g. 'reconcile COD payments'.",
    ),
]

COD_EVENT_TYPES = [i.name for i in COD_INTENTS]

COD_EVENT_ALIASES = {
    # Phase 5 generic signed webhook: {"type": "courier.status", "payload": {"courier", ...}}
    "courier.status": "ecommerce.courier_status",
}


def cod_tools() -> list[RegisteredTool]:
    from packs.ecommerce.tools.cod_tools import cod_tools as tools

    return tools()


def cod_subgraphs(deps: AgentDeps) -> dict[str, Any]:
    from packs.ecommerce import graphs_cod

    return {
        "ecommerce.cod_confirm": graphs_cod.cod_confirm_graph(deps),
        "ecommerce.cod_sweep": graphs_cod.cod_sweep_graph(deps),
        "ecommerce.courier_status": graphs_cod.courier_status_graph(deps),
        "ecommerce.courier_poll": graphs_cod.courier_poll_graph(deps),
        "ecommerce.cod_reconcile": graphs_cod.cod_reconcile_graph(deps),
    }


def order_created_graph(deps: AgentDeps) -> Any:
    """Replaces the Phase 6 ``ecommerce.order.created`` graph: same store-event step, then

    (if the tenant enabled it) the COD confirmation chain."""
    from packs.ecommerce.graphs_cod import order_created_graph as build

    return build(deps)


def cod_routers() -> list[Any]:
    from packs.ecommerce.api_cod import router

    return [router]


def cod_seeders() -> dict[str, Any]:
    from packs.ecommerce.seed_cod import seed_cod_eval, seed_cod_recon_eval

    return {"ecommerce/cod": seed_cod_eval, "ecommerce/cod-recon": seed_cod_recon_eval}