ComuniTEA uses AI in three distinct ways: OpenAI GPT transforms a child’s selected pictogram labels into natural spoken Spanish sentences; ElevenLabs generates neural voice audio clips with child-appropriate tone and rhythm; and a client-side analysis engine surfaces actionable recommendations to caregivers through theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ElthonJohan/comunitea/llms.txt
Use this file to discover all available pages before exploring further.
ai-insights Edge Function. All AI features are optional and degrade gracefully — the app remains fully functional when offline or when API keys are not configured, falling back to system TTS and disabling the Magic Expand button. Every AI call requires Supabase environment variables and a valid authenticated session.
ai-expand Edge Function
Purpose: Accepts an ordered list of pictogram labels selected by the child and returns a single natural-language sentence in Spanish, adapted to the child’s vocabulary level. Endpoint:POST /functions/v1/ai-expand
Request body
The pictogram labels in the order the child selected them (e.g.
["Yo", "Quiero", "Manzana"]). At least one label is required.Controls sentence complexity.
BASICO produces 3–6 word sentences; INTERMEDIO 5–10 words; AVANZADO up to 15 words.Injected as context into the OpenAI prompt (e.g. “Hora del día: mañana”). Helps the model produce contextually appropriate sentences.
The label of the most recently completed routine (e.g.
"Desayuno"). Provides additional context for the expanded sentence.Switches the prompt style.
"formador" optimizes for “Yo quiero + object” patterns. "tablero" optimizes for multi-slot sentence strip output with natural connectors. Omit for default behavior.Response body
A single natural Spanish sentence. For example, given
["Yo", "Quiero", "Manzana"] at BASICO level: "Quiero una manzana.".Error responses
| Status | Body | Cause |
|---|---|---|
400 | { error: "Se requiere al menos un pictograma" } | Empty pictogramLabels array |
405 | { error: "Método no permitido" } | Non-POST request |
500 | { error: "OPENAI_API_KEY no configurada" } | Missing secret |
502 | { error: "OpenAI respondió 4xx/5xx", detail: "..." } | OpenAI API error |
OpenAI model and parameters
How useMagicExpand invokes it
The useMagicExpand hook (client-side) constructs the request and handles session token refresh:
ai-insights Edge Function
Purpose: Analyzes the child’s usage patterns and returns 2–3 actionable, warmly-worded recommendations in Spanish for caregivers and therapists. Endpoint:POST /functions/v1/ai-insights
Request body
The child’s vocabulary level from their profile.
Current PECS game sub-level (1–5). Included in the prompt to give context about game progression.
Mean pictogram count per sentence over the last 30 days. The AI uses this to suggest expanding vocabulary if the average is high.
Total sentences in
sentence_log over the last 30 days.The 5 most-used pictogram labels (human-readable). Included in the prompt for context.
Labels of vocabulary categories not used in more than 14 days. The AI may suggest practicing these.
Response body
Array of 1–3 actionable suggestion strings in Spanish, second-person, positive tone. Example:
["Puedes practicar la categoría Baño esta semana.", "El niño está construyendo frases más largas — considera ampliar el vocabulario."]OpenAI model and parameters
System prompt behavior
The function uses a fixed system prompt instructing GPT to respond exclusively with a valid JSON array of 3 strings. If the model returns malformed JSON, the function falls back to wrapping the raw text in a single-item array. Empty strings are filtered out and the result is capped at 3 items.elevenlabs-tts Edge Function
Purpose: Proxies text-to-speech requests to the ElevenLabs API, returning an MP3 audio buffer. Acts as a secure server-side proxy so the ElevenLabs API key is never exposed to the client. Endpoint:POST /functions/v1/elevenlabs-tts
Request body
The text to synthesize. Must be a non-empty string.
ElevenLabs voice ID. Defaults to
qBvury71WUJfVeT1STkG (Samanta, feminine voice). The app passes the masculine or feminine voice ID based on the user’s voice preference.Synthesis speed multiplier. Clamped to
[0.5, 2.0]. Sourced from parental tts_speed setting (default 1.0).Response
On success, returns the raw MP3 audio as a binary blob:ElevenLabs model settings
How useSpeech invokes it
TTS fallback chain
When
isConnected === false, step 2 is skipped entirely — the app jumps directly to expo-speech without attempting any network call. This keeps pictogram taps responsive even on offline field deployments.delete-user-data Edge Function
Purpose: Implements the right to erasure (GDPR Article 17 / COPPA). Permanently and irreversibly deletes all data associated with the authenticated user. Endpoint:POST /functions/v1/delete-user-data
Authentication: Requires a valid user JWT in the Authorization: Bearer <token> header. Uses a service_role admin client internally to perform privileged deletions.
Deletion sequence
The function executes the following steps in order:Storage files
Lists and removes all files in the
avatars/{userId}/ and pictograms/{userId}/ Storage buckets.Database rows
Deletes
user_id-keyed rows from every data table:
sentence_log, usage_stats, config_audit_log, ai_insights, game_sessions, game_progress, activity_sessions, guided_activities, parental_settings, child_team, share_tokens, child_profiles, tasks, custom_pictograms, categories, profilesResponse
Required secrets
| Secret | Purpose |
|---|---|
SUPABASE_URL | Project URL |
SUPABASE_ANON_KEY | For verifying the user JWT |
SUPABASE_SERVICE_ROLE_KEY | For admin-level deletion operations |
Offline Queue
When the device is offline, telemetry events and sentence log entries that would normally be written directly to Supabase are instead queued inAsyncStorage by lib/offlineQueue.ts. The queue is flushed automatically when NetworkContext detects reconnection.
Flush behavior
flushQueue() partitions the queue by type, runs two parallel supabase.insert() calls (usage_stats and sentence_log) wrapped in Promise.allSettled, and only clears AsyncStorage if both succeed. Failed batches remain queued and are retried on the next flush trigger.
Audit Log
lib/auditLog.ts provides a best-effort audit trail for configuration changes. It records who changed what to the config_audit_log table. Errors are silently suppressed so that audit failures never interrupt the user-facing flow.
What gets logged
| Action | field value | Triggered by |
|---|---|---|
| Pictogram hidden/shown | vocabulary_pictogram_toggle | useDisabledPictograms.toggle() |
| Team member invited | child_team_invite | useChildTeam.inviteMember() |
| Team member revoked | child_team_revoke | useChildTeam.revokeMember() |
| Team permission change | child_team_perm_can_view_reports / child_team_perm_can_edit_vocabulary | useChildTeam.updatePermissions() |
Schema
Usage example
AI feature summary
ai-expand
OpenAI GPT converts selected pictogram labels into a single natural Spanish sentence. Adapts complexity to the child’s vocabulary level. Invoked by
useMagicExpand. Requires OPENAI_API_KEY.ai-insights
OpenAI GPT analyzes 30-day usage data and returns 3 actionable recommendations for caregivers. Invoked from the caregiver report screen. Requires
OPENAI_API_KEY.elevenlabs-tts
ElevenLabs neural TTS proxied through a Supabase Edge Function. Returns MP3 audio for any text. Falls back to
expo-speech on error or offline. Requires ELEVENLABS_API_KEY.delete-user-data
GDPR right to erasure Edge Function. Permanently deletes all user storage files, database rows, and the auth account. Irreversible. Requires
SUPABASE_SERVICE_ROLE_KEY.