Skip to main content
VSM Store’s AI features are implemented as Supabase Edge Functions deployed to Deno. Each function calls the Google Gemini REST API and returns structured JSON to the frontend. The functions are invoked either directly from admin services or via supabase.functions.invoke() from the client.

Architecture

React Frontend
  └─ supabase.functions.invoke('function-name', { body: {...} })
       └─ Supabase Edge Function (Deno runtime)
            └─ Google Gemini REST API
                 └─ gemini-2.0-flash / gemini-2.5-flash-lite / gemini-embedding-001
LayerTechnology
RuntimeDeno (Supabase Edge Functions)
Default modelgemini-2.5-flash-lite (most functions)
Concierge modelsgemini-2.5-flash (Analyst + Sommelier engines)
Embeddings modelgemini-embedding-001 (v1beta API)
API basehttps://generativelanguage.googleapis.com/v1/
JWT verificationDisabled (verify_jwt = false in config.toml)

Required secrets

Configure these in Supabase project settings under Edge Functions → Secrets:
GEMINI_API_KEY               # Google AI Studio API key
SUPABASE_URL                 # Your Supabase project URL
SUPABASE_SERVICE_ROLE_KEY    # Full DB access key (used inside edge functions)
Not all functions need all three secrets. dashboard-intelligence, voice-intelligence, product-intelligence, and embeddings-processor only require GEMINI_API_KEY. The others need all three.

Edge functions

FunctionPurposeSecrets needed
inventory-oracleStock depletion predictions and restock recommendationsAll three
dashboard-intelligenceExecutive business insights for admin dashboardGEMINI_API_KEY
customer-intelligenceMulti-action: NLP concierge, WhatsApp copy, loyalty analysis, supplier messagesAll three
voice-intelligenceNatural language → structured search query conversionGEMINI_API_KEY
product-intelligenceAI product description and marketing copy generationGEMINI_API_KEY
loyalty-intelligenceCustomer loyalty pattern analysis and personalised retention offersAll three
customer-narrativeContextual customer CRM narratives for admin panelAll three
bundle-intelligenceProduct bundle suggestions with AI-generated names and auto-couponsAll three
embeddings-processorVector embeddings using gemini-embedding-001 (v1beta API)GEMINI_API_KEY

Migration history

All functions were updated on 2026-03-15:
DateChangeReason
2026-03-15v1betav1 endpointv1beta deprecated for generative models
2026-03-15gemini-1.5-flashgemini-2.0-flashGemini 1.5 models retired
2026-03-15Removed responseMimeType from generationConfigParameter not supported in API v1
Exception: embeddings-processor intentionally remains on the v1beta endpoint because gemini-embedding-001 is only available there.

CORS configuration

All edge functions return the same CORS headers:
const corsHeaders = {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
};
Each function responds to OPTIONS preflight requests with 200 ok.

Calling from the frontend

// Via Supabase client
const { data, error } = await supabase.functions.invoke('loyalty-intelligence', {
    body: { customerId: user.id }
});

// Direct fetch (used by admin-dashboard.service.ts for diagnostic purposes)
const response = await fetch(
    `${import.meta.env.VITE_SUPABASE_URL}/functions/v1/dashboard-intelligence`,
    {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${import.meta.env.VITE_SUPABASE_ANON_KEY}`,
        },
        body: JSON.stringify({ stats, action: 'get_pulse' }),
    }
);

Build docs developers (and LLMs) love