Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AdriP-maker/JAAR_Antigravity/llms.txt
Use this file to discover all available pages before exploring further.
What AI routing does
When a cobrador taps “Ruta IA” on the/cobros screen, the system generates a prioritized visit queue for the day’s collection rounds. Instead of visiting houses in an arbitrary order, the cobrador receives a sorted list that surfaces the households most at risk of becoming delinquent — or already are — at the top, while grouping nearby houses in the same geographic sector to minimize travel time.
This is defined as RF-23 in the SIMAP requirements spec:
The cobrador can activate a mode that orders households by visit priority, combining risk score, urgency (proximity to corte state), and geographic sector grouping. The AI only suggests — the cobrador always decides.The AI routing feature is implemented in
src/services/aiService.js.
How visit priority is determined
Each household receives a composite priority score at routing time based on three factors:- Risk score (0–100): A weighted formula covering payment history, jornal participation, and sector trends. Higher scores push a household toward the top of the queue. See Risk Scoring for the full breakdown.
- Urgency — proximity to
cortestate: Households inmorosoorcortestatus (defined insrc/utils/constants.js) are flagged as urgent and elevated in priority regardless of their absolute risk score. - Geographic sector grouping: After priority ordering, households within the same sector (
sectorfield on the user record) are clustered together. This means the cobrador can complete an entire neighborhood before moving to the next, reducing backtracking.
What the AI does NOT do
The routing engine is a decision-support tool only. It never:- Initiates contact with residents autonomously
- Changes any payment record or account status
- Adjusts tariffs or applies penalties
- Overrides the cobrador’s judgment
Behavior-profile analysis: getSugerenciaCobrador
Beyond route ordering, the AI can generate a personalized, empathic collection message for each resident. The cobrador calls this from the resident’s detail card inside CobroModal.
The function getSugerenciaCobrador(usuarioTarget) in aiService.js works in two stages:
Stage 1 — behavior profiling
| Profile | Condition | Tone of generated message |
|---|---|---|
puntual | deuda === 0 — fully current | Gratitude; reinforces positive behavior |
olvidadizo | mesesDeuda === 1 — one month behind | Gentle, friendly reminder suited for a WhatsApp message |
moroso | mesesDeuda >= 2 — two or more months behind | Firm but empathic; includes an offer to discuss a payment plan with the board |
Stage 2 — message generation
Return shape
Chrome Built-in AI integration
SIMAP Digital targets field devices that may be modern Android or laptop browsers running Chrome. The service first checks forwindow.ai (Chrome’s Built-in AI / Gemini Nano API):
window.ai is not available — older browsers, Firefox, or Safari — the system automatically falls back to a deterministic local template generator. This means AI-generated messages work fully offline on supported devices, consistent with SIMAP’s offline-first architecture.
A future integration path is noted in the source for connecting to OpenAI via process.env.VITE_OPENAI_API_KEY, but the local fallback ensures the cobrador is never left without a message to work with.
The cash-only rule
All messages generated by the AI — whether from Chrome’s Built-in AI or the local template fallback — are instructed to enforce a hard rule:Only cash is accepted. Never suggest Yappy, bank transfers, or deposits.This rule is embedded directly in the prompt text and reflects the operational reality of rural Juntas in Panama, which do not have the infrastructure for digital payment verification in the field.
Sending the message to the resident
The notification flow:- Cobrador reviews the AI-generated message in the modal.
- Cobrador taps “Enviar al cliente”.
- The system writes a record to the
notificacionestable:{ destinatarioId, texto, fecha, leído: false }. - On next sync, the record is pushed to Supabase.
- The resident (
clienterole) sees a notification badge on their dashboard.
olvidadizo profile, where a conversational reminder is the intended channel.