Reference

Components

Every Rust module in Whatszara explained — what it does, how it works, and why it exists.

policy.rs

src/whatszara/policy.rs

What it does

Policy engine — the gatekeeper for all actions. Now with image-based reCAPTCHA (beta/experimental) for high-risk actions.

How it works

Defines ToolCategory, ToolPermissions, ContactMode (Assistant/Chat/Summarize/Blocked), RiskLevel, ActionProposal, PolicyDecision, and the PolicyEngine with allowlist support. NEW: CaptchaChallenge struct with render_captcha_image() — generates a local PNG with random characters using the image crate (draw_line + draw_char). verify_captcha() Tauri command validates user input against the generated challenge. Captcha is triggered for high-risk actions to ensure human-in-the-loop.

Why it exists

Separates security policy from action execution. Every action goes through propose → evaluate → execute. The image-based captcha adds an extra security layer for destructive operations — bots/AI can't auto-approve high-risk actions.

actions.rs

src/whatszara/actions.rs

What it does

Structured action executors for shell, apps, media, and file scanning.

How it works

Defines ActionResult with action/params fields. ShellExecutor has blocked commands list. AppLauncher, MediaController, DesktopScanner are platform-aware executors.

Why it exists

No free-form shell by default. Actions are typed structures (open_app, set_volume, play_media) that can be validated, logged, and reversed.

llm.rs

src/whatszara/llm.rs

What it does

Mesh API provider — a single AI router with 1000+ models.

How it works

MeshApiProvider implements the LLMProvider trait. Uses Mesh API's OpenAI-compatible /v1/chat/completions endpoint. list_models() fetches live models from GET /v1/models (flat JSON array of model objects with id, pricing, context_length, capabilities). get_model_details() fetches from GET /v1/models/:id for per-model details. BYOK support: passes x-mesh-openai-key, x-mesh-anthropic-key, x-mesh-groq-key headers when configured. Model persistence via save_model_config() / load_model_config() in keychain.

Why it exists

Single API key for 1000+ models eliminates the need for 5 separate provider integrations. BYOK lets users bring their own subscriptions. Live model listing means the UI is always up to date with Mesh API's catalog. Model details panel shows pricing, capabilities, and context for informed model selection.

orchestrator.rs

src/whatszara/orchestrator.rs

What it does

Central orchestrator — ties policy, Mesh API provider, actions, pending approvals, undo, and multi-action processing together.

How it works

process_message() (&mut self) checks contact mode and routes to the active LLM provider. Enhanced system prompt includes AI contact management instructions — the LLM can list/search contacts, send messages, and manage the WhatsApp contact list autonomously. LLM responses are parsed via parse_ai_response() which returns Vec<ActionStep>. Low-risk actions execute immediately; medium/high-risk actions create PendingAction entries. Batch approval via approve_all_actions() / reject_all_actions(). Holds a ProviderRegistry with the MeshApiProvider.

Why it exists

Single entry point for all message processing. Multi-action support enables complex workflows. The enhanced system prompt gives the AI awareness of the user's contact list for smarter autonomous interactions.

undo.rs

src/whatszara/undo.rs

What it does

Action journal with reversible actions for undo support.

How it works

ActionJournal records every action with its reverse. undo_last() executes the reverse action and marks it as reversed. Supports per-contact undo.

Why it exists

Accidents happen. Every action is reversible — volume changes, music playback, and more can be undone with a single command.

whatsapp.rs

src/whatszara/whatsapp.rs

What it does

WhatsApp integration — reads SQLite from Go bridge, sends messages via HTTP with Bearer auth.

How it works

list_chats() reads the SQLite database directly. search_contacts() and list_contacts() query the contacts table. send_message() calls the Go bridge REST API with an Authorization header if API_KEY is configured.

Why it exists

No Python MCP server needed. Direct SQLite access is faster and more reliable. The contacts table in the bridge allows unified contact management from a single source of truth.