{"repo": "caffeinepub/local-eyes", "files": {"spec.md": {"1b5e740b792a636c35de064a1ac790e30294e53a": {"t": 1785846896.2421653, "n": 2746, "h": "b12edb7d77e2c3c5", "c": "# Local-Eyes — AI Chatbot Internet Mode\n\n## Current State\nThe AIAssistant component is a floating chat panel with an offline knowledge base (18 topics). It matches keywords and returns pre-written responses. The status shows 'Smart Mode — Offline' always. No internet mode exists.\n\n## Requested Changes (Diff)\n\n### Add\n- Online/Offline mode toggle switch inside the chatbot header (next to the status badge)\n- When online mode is ON: send user messages to Google Gemini API (gemini-1.5-flash, free tier) from the frontend using fetch. System prompt instructs Gemini to act as a disaster survival expert for India/Andhra Pradesh, giving step-by-step, actionable answers about water purification, food safety, first aid, evacuation, disaster precautions, medicines, etc.\n- API key input prompt: if online mode is toggled ON and no API key is stored in localStorage, show a small inline prompt in the chat to enter a Gemini API key. Store in localStorage.\n- Online mode indicator: when ON, show a yellow/amber badge \"Online Mode\" instead of green \"Offline\" badge\n- Auto-fallback: if Gemini API call fails (network error, bad key, rate limit), silently fall back to offline KB and show a brief note in the AI response: \"(Online unavailable — using offline guide)\"\n- Connection detection: detect navigator.onLine; if user switches to online mode while offline, show a warning message in the chat\n- Welcome message update: mention that Online mode is available for richer AI answers\n\n### Modify\n- AIAssistant.tsx: add internetMode state (boolean), apiKey state, send function to branch between Gemini API call and local KB lookup\n- Status badge in header: dynamically shows Online/Offline based on mode\n- Initial welcome message: note that users can enable Online Mode for live AI answers\n\n### Remove\n- Nothing removed\n\n## Implementation Plan\n1. Add `internetMode` (boolean) and `geminiApiKey` (string) state; load key from localStorage on mount\n2. Add a toggle switch in chatbot header (right side, next to refresh button) with label \"Online\"\n3. When toggled ON: if no API key, inject an assistant message prompting user to type their Gemini API key. On next user message, detect if it looks like an API key (starts with 'AIza') and store it, then confirm with a message\n4. `send()` function: if internetMode && apiKey, call Gemini API; else use local KB\n5. Gemini API call: POST to `https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${apiKey}` with a system prompt focused on disaster survival in India\n6. On Gemini error or network failure: fall back to offline KB, append note to response\n7. Dynamic status badge: amber for online, green for offline\n8. navigator.onLine check when toggling to online mode\n"}}}}