fix(bot): eliminate double feedback, fix gemini model, fix multilingual prompts
Browse files1. Double feedback (critical):
Bridge was enqueuing both download-media AND handle-inbound for every audio/image
message. Both paths independently transcribed the audio and called
WhatsAppLogic.handleIncomingMessage → two generate-feedback jobs → user received
two Coach responses. Fix: remove handle-inbound and send-message-direct from bridge
for media. MediaHandler (download-media) already handles full pipeline.
MediaHandler now sends a localized spinner after user lookup (sendSpinner flag).
2. gemini-1.5-pro → 404:
gemini-1.5-pro is deprecated via Google API v1beta. Updated GeminiProvider to use
gemini-2.0-flash for both flash and complex (pro) requests.
3. Multilingual deep-dive invitation (EN/ES/PT):
action-feedback-standard.md only had FR and WO variants for the APPROFONDIR/SUITE
invitation at end of feedback. Added EN, ES, PT — AI was mixing languages for
English/Spanish/Portuguese users.
4. InboundHandler [object Object] bug:
aiService.transcribeAudio returns { text, confidence }, not a string. Template
literal was stringifying the object. Fixed to use result.text.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- apps/whatsapp-worker/src/handlers/InboundHandler.ts +4 -4
- apps/whatsapp-worker/src/handlers/MediaHandler.ts +13 -0
- apps/whatsapp-worker/src/handlers/types.ts +1 -0
- apps/whatsapp-worker/src/index.ts +6 -21
- docs/organisation-onboarding/configuration-reference-2026-05-12.md +202 -0
- packages/ai-sdk/src/gemini-provider.ts +3 -4
- packages/prompts/src/templates/action-feedback-standard.md +3 -0
|
@@ -51,10 +51,10 @@ export class InboundHandler implements JobHandler {
|
|
| 51 |
baseURL: '' // The URL is absolute
|
| 52 |
});
|
| 53 |
const audioBuffer = audioRes.data;
|
| 54 |
-
const
|
| 55 |
-
|
| 56 |
-
if (
|
| 57 |
-
text =
|
| 58 |
}
|
| 59 |
}
|
| 60 |
}
|
|
|
|
| 51 |
baseURL: '' // The URL is absolute
|
| 52 |
});
|
| 53 |
const audioBuffer = audioRes.data;
|
| 54 |
+
const transcribeResult = await aiService.transcribeAudio(Buffer.from(audioBuffer), `msg_${mediaId}.ogg`);
|
| 55 |
+
|
| 56 |
+
if (transcribeResult?.text) {
|
| 57 |
+
text = transcribeResult.text;
|
| 58 |
}
|
| 59 |
}
|
| 60 |
}
|
|
@@ -69,6 +69,19 @@ export class MediaHandler implements JobHandler {
|
|
| 69 |
organizationId: organizationId || user.organizationId
|
| 70 |
}
|
| 71 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
}
|
| 73 |
|
| 74 |
if (mimeType && mimeType.startsWith('audio/')) {
|
|
|
|
| 69 |
organizationId: organizationId || user.organizationId
|
| 70 |
}
|
| 71 |
});
|
| 72 |
+
|
| 73 |
+
// Send localized spinner (bridge no longer sends send-message-direct for media)
|
| 74 |
+
if (job.data.sendSpinner) {
|
| 75 |
+
const isImage = mimeType?.startsWith('image/');
|
| 76 |
+
const spinnerMsg = isImage ? {
|
| 77 |
+
FR: "⏳ J'analyse ton image...", WOLOF: "⏳ Defar ak sa nataal...",
|
| 78 |
+
EN: "⏳ Analysing your image...", ES: "⏳ Analizando tu imagen...", PT: "⏳ Analisando sua imagem..."
|
| 79 |
+
}[user.language] ?? "⏳ Analysing..." : {
|
| 80 |
+
FR: "⏳ J'analyse ton audio...", WOLOF: "⏳ Defar ak sa kàddu...",
|
| 81 |
+
EN: "⏳ Analysing your audio...", ES: "⏳ Analizando tu audio...", PT: "⏳ Analisando seu áudio..."
|
| 82 |
+
}[user.language] ?? "⏳ Analysing...";
|
| 83 |
+
await sendTextMessage(phone, spinnerMsg, tenantConfig);
|
| 84 |
+
}
|
| 85 |
}
|
| 86 |
|
| 87 |
if (mimeType && mimeType.startsWith('audio/')) {
|
|
@@ -88,6 +88,7 @@ export interface JobData {
|
|
| 88 |
adminId?: string;
|
| 89 |
accessToken?: string;
|
| 90 |
overrideAudioUrl?: string;
|
|
|
|
| 91 |
|
| 92 |
// Interactive components
|
| 93 |
buttons?: Array<{ id: string; title: string }>;
|
|
|
|
| 88 |
adminId?: string;
|
| 89 |
accessToken?: string;
|
| 90 |
overrideAudioUrl?: string;
|
| 91 |
+
sendSpinner?: boolean;
|
| 92 |
|
| 93 |
// Interactive components
|
| 94 |
buttons?: Array<{ id: string; title: string }>;
|
|
@@ -135,33 +135,18 @@ server.post('/v1/internal/whatsapp/inbound', async (req: FastifyRequest, reply:
|
|
| 135 |
const isImage = msg.mediaType === 'image';
|
| 136 |
|
| 137 |
logger.info(`[BRIDGE] Enqueuing inbound media (${msg.mediaType}) from ${msg.phone}`);
|
| 138 |
-
|
| 139 |
-
//
|
|
|
|
|
|
|
| 140 |
await whatsappQueue.add('download-media', {
|
| 141 |
mediaId: msg.mediaId,
|
| 142 |
mimeType: isImage ? 'image/jpeg' : 'audio/ogg',
|
| 143 |
phone: msg.phone,
|
| 144 |
organizationId,
|
| 145 |
-
caption: msg.caption
|
|
|
|
| 146 |
}, { priority: 1, attempts: 3, backoff: { type: 'exponential', delay: 2000 } });
|
| 147 |
-
|
| 148 |
-
// 2. New CRM Inbox flow
|
| 149 |
-
await whatsappQueue.add('handle-inbound', {
|
| 150 |
-
phone: msg.phone,
|
| 151 |
-
text: msg.caption || '', // Use caption as text if available
|
| 152 |
-
audioUrl: !isImage ? msg.mediaId : undefined,
|
| 153 |
-
imageUrl: isImage ? msg.mediaId : undefined,
|
| 154 |
-
organizationId
|
| 155 |
-
}, {
|
| 156 |
-
attempts: 3,
|
| 157 |
-
backoff: { type: 'exponential', delay: 1000 }
|
| 158 |
-
});
|
| 159 |
-
|
| 160 |
-
await whatsappQueue.add('send-message-direct', {
|
| 161 |
-
phone: msg.phone,
|
| 162 |
-
text: isImage ? "⏳ J'analyse ton image..." : "⏳ J'analyse ton audio...",
|
| 163 |
-
organizationId
|
| 164 |
-
});
|
| 165 |
}
|
| 166 |
}
|
| 167 |
|
|
|
|
| 135 |
const isImage = msg.mediaType === 'image';
|
| 136 |
|
| 137 |
logger.info(`[BRIDGE] Enqueuing inbound media (${msg.mediaType}) from ${msg.phone}`);
|
| 138 |
+
|
| 139 |
+
// Single media job: MediaHandler handles transcription + DB logging + pedagogy.
|
| 140 |
+
// A second handle-inbound job was previously enqueued here, causing double
|
| 141 |
+
// transcription and double generate-feedback jobs for every audio message.
|
| 142 |
await whatsappQueue.add('download-media', {
|
| 143 |
mediaId: msg.mediaId,
|
| 144 |
mimeType: isImage ? 'image/jpeg' : 'audio/ogg',
|
| 145 |
phone: msg.phone,
|
| 146 |
organizationId,
|
| 147 |
+
caption: msg.caption,
|
| 148 |
+
sendSpinner: true // MediaHandler will send a localized spinner after user lookup
|
| 149 |
}, { priority: 1, attempts: 3, backoff: { type: 'exponential', delay: 2000 } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
}
|
| 151 |
}
|
| 152 |
|
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Configuration de Référence — Bot XAMLÉ Fonctionnel
|
| 2 |
+
**Date de validation** : 12 Mai 2026
|
| 3 |
+
**Statut** : ✅ Testé en production (flux complet EN validé)
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## Architecture de Déploiement
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
Meta WhatsApp Cloud API
|
| 11 |
+
│
|
| 12 |
+
▼ webhook POST
|
| 13 |
+
┌─────────────────────────────┐
|
| 14 |
+
│ HuggingFace Space │ safetrack/edtech
|
| 15 |
+
│ CPU Basic (free) │ port 7860 (PM2)
|
| 16 |
+
│ │
|
| 17 |
+
│ ├─ apps/api (Fastify) │ ← reçoit le webhook Meta
|
| 18 |
+
│ │ └─ /v1/whatsapp/webhook│ → valide, répond 200ms
|
| 19 |
+
│ │ └─ /v1/ai/tts │ ← TTS audio
|
| 20 |
+
│ │ └─ /v1/ai/transcribe │ ← transcription audio
|
| 21 |
+
│ │ └─ /v1/ai/store-audio │ ← stockage R2
|
| 22 |
+
│ │ │
|
| 23 |
+
│ └─ apps/whatsapp-worker │ DISABLE_WORKER_CONSUMER=true
|
| 24 |
+
│ └─ Bridge :8082 │ → forward vers Railway
|
| 25 |
+
│ /v1/internal/ │
|
| 26 |
+
│ whatsapp/inbound │
|
| 27 |
+
└─────────────────────────────┘
|
| 28 |
+
│ HTTP POST (ADMIN_API_KEY)
|
| 29 |
+
▼
|
| 30 |
+
┌─────────────────────────────┐
|
| 31 |
+
│ Railway (US West) │ whatsapp-worker service
|
| 32 |
+
│ whatsapp-worker │
|
| 33 |
+
│ │
|
| 34 |
+
│ ├─ BullMQ Worker │ ← consomme whatsapp-queue
|
| 35 |
+
│ ├─ Bridge :8082 │ ← reçoit de HuggingFace
|
| 36 |
+
│ └─ Redis (shared) │ ← Upstash Redis
|
| 37 |
+
└─────────────────────────────┘
|
| 38 |
+
│
|
| 39 |
+
▼
|
| 40 |
+
┌─────────────────────────────┐
|
| 41 |
+
│ Neon PostgreSQL │ ep-divine-boat-a8pfifri
|
| 42 |
+
│ (Base de données prod) │
|
| 43 |
+
└─────────────────────────────┘
|
| 44 |
+
│
|
| 45 |
+
▼
|
| 46 |
+
┌─────────────────────────────┐
|
| 47 |
+
│ Cloudflare R2 │ pub-e770286d...r2.dev
|
| 48 |
+
│ (Stockage audio/images) │
|
| 49 |
+
└─────────────────────────────┘
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
## Variables d'Environnement Critiques
|
| 55 |
+
|
| 56 |
+
### HuggingFace (api + worker en bridge mode)
|
| 57 |
+
|
| 58 |
+
| Variable | Rôle |
|
| 59 |
+
|----------|------|
|
| 60 |
+
| `DISABLE_WORKER_CONSUMER` | **`true`** — empêche HF de consommer la queue BullMQ (seul Railway consomme) |
|
| 61 |
+
| `DATABASE_URL` | Neon PostgreSQL |
|
| 62 |
+
| `REDIS_URL` | Upstash Redis (même instance que Railway) |
|
| 63 |
+
| `ADMIN_API_KEY` | Auth interne HF → Railway bridge |
|
| 64 |
+
| `RAILWAY_INTERNAL_URL` | URL du bridge Railway (`:8082`) |
|
| 65 |
+
| `WHATSAPP_VERIFY_TOKEN` | Vérification webhook Meta |
|
| 66 |
+
| `WHATSAPP_ACCESS_TOKEN` | Token Meta global (fallback si pas de token org) |
|
| 67 |
+
| `WHATSAPP_PHONE_NUMBER_ID` | ID numéro Meta |
|
| 68 |
+
| `OPENAI_API_KEY` | Whisper STT + TTS + GPT-4o |
|
| 69 |
+
| `GOOGLE_AI_API_KEY` | Gemini (avec fallback OpenAI si quota épuisé) |
|
| 70 |
+
| `ENCRYPTION_SECRET` | **Doit être identique à Railway** — clé de déchiffrement des tokens org |
|
| 71 |
+
| `JWT_SECRET` | Auth admin dashboard |
|
| 72 |
+
| `R2_*` | Cloudflare R2 (store-audio, images) |
|
| 73 |
+
|
| 74 |
+
### Railway (worker — consommateur BullMQ)
|
| 75 |
+
|
| 76 |
+
| Variable | Valeur critique | Rôle |
|
| 77 |
+
|----------|----------------|------|
|
| 78 |
+
| `ENCRYPTION_SECRET` | **Même valeur que HuggingFace** | Déchiffre `systemUserToken` en DB |
|
| 79 |
+
| `DATABASE_URL` | Neon PostgreSQL (même instance) | |
|
| 80 |
+
| `REDIS_URL` | Upstash Redis (même instance que HF) | |
|
| 81 |
+
| `ADMIN_API_KEY` | Min 32 chars (même valeur que HF) | Auth bridge |
|
| 82 |
+
| `API_URL` | URL interne HF (port 7860) | Appels TTS, transcription, store-audio |
|
| 83 |
+
| `DISABLE_WORKER_CONSUMER` | **absent ou `false`** | Railway DOIT consommer la queue |
|
| 84 |
+
| `WORKER_CONCURRENCY` | `5` | Jobs parallèles |
|
| 85 |
+
|
| 86 |
+
> **⚠️ Règle ENCRYPTION_SECRET** : La valeur en DB est chiffrée avec la clé qui était active lors de l'exécution de `apps/api/scratch/encrypt_existing_secrets.ts`. Si cette clé change, toutes les tentatives de déchiffrement retournent le ciphertext `enc:...` → Authentication Error sur Meta. Ne jamais changer cette clé sans exécuter `apps/api/scratch/rotate_encryption_key.ts`.
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## Flux Utilisateur Validé (12 Mai 2026)
|
| 91 |
+
|
| 92 |
+
```
|
| 93 |
+
Utilisateur → "INSCRIPTION"
|
| 94 |
+
→ OnboardingHandler : Hard Reset (delete enrollments, activity=null)
|
| 95 |
+
→ Liste des langues envoyée
|
| 96 |
+
|
| 97 |
+
Utilisateur → "English 🇬🇧" (LANG_EN)
|
| 98 |
+
→ OnboardingHandler : user.language = EN
|
| 99 |
+
→ Liste des secteurs envoyée
|
| 100 |
+
|
| 101 |
+
Utilisateur → "Tech / Digital" (SEC_TECH)
|
| 102 |
+
→ OnboardingHandler : user.activity = "Tech / Digital"
|
| 103 |
+
[FIX 2026-05-12 : guard !user.activity au lieu de !activeEnrollment]
|
| 104 |
+
→ send-message "Sector noted: Tech / Digital"
|
| 105 |
+
→ enroll-user → EnrollHandler → enrollment créé (token décrypté via getCachedOrganization)
|
| 106 |
+
→ send-content (Day 1)
|
| 107 |
+
|
| 108 |
+
ContentHandler → Day 1
|
| 109 |
+
→ sendLessonDay() → Gemini 429 → fallback OpenAI GPT-4o ✅
|
| 110 |
+
→ Contenu généré + TTS audio envoyé
|
| 111 |
+
→ Video + textes envoyés
|
| 112 |
+
|
| 113 |
+
Utilisateur → [Message vocal]
|
| 114 |
+
→ Bridge HF : download-media job enqueué
|
| 115 |
+
→ MediaHandler : télécharge, stocke sur R2, transcrit (OpenAI Whisper)
|
| 116 |
+
→ WhatsAppLogic.handleIncomingMessage (transcribed text)
|
| 117 |
+
→ ExerciseHandler : génère generate-feedback
|
| 118 |
+
→ FeedbackHandler : Gemini 429 → fallback OpenAI ✅
|
| 119 |
+
→ Feedback Coach XAMLÉ envoyé (une seule fois)
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
---
|
| 123 |
+
|
| 124 |
+
## Organisations en Base
|
| 125 |
+
|
| 126 |
+
| ID | Nom | systemUserToken |
|
| 127 |
+
|----|-----|----------------|
|
| 128 |
+
| `default-org-id` | XAMLÉ Global | ✅ Chiffré avec ENCRYPTION_SECRET local |
|
| 129 |
+
| `136f72d9-...` | test | vide |
|
| 130 |
+
| `ba012b65-...` | testcrm | vide |
|
| 131 |
+
|
| 132 |
+
L'organisation active est `default-org-id`. Le token Meta déchiffré commence par `EAAURe...` (199 chars).
|
| 133 |
+
|
| 134 |
+
---
|
| 135 |
+
|
| 136 |
+
## Modèles AI Utilisés
|
| 137 |
+
|
| 138 |
+
| Tâche | Provider | Modèle | Fallback |
|
| 139 |
+
|-------|----------|--------|---------|
|
| 140 |
+
| Génération contenu leçon | Gemini (priorité 100) | `gemini-2.0-flash` | OpenAI `gpt-4o` |
|
| 141 |
+
| Génération feedback | Gemini (priorité 100) | `gemini-2.0-flash` | OpenAI `gpt-4o` |
|
| 142 |
+
| Transcription audio (STT) | OpenAI (seul provider) | `whisper-1` | — |
|
| 143 |
+
| TTS audio | OpenAI (seul provider) | `tts-1` | — |
|
| 144 |
+
|
| 145 |
+
> **Note Gemini** : Le quota free tier (`generativelanguage.googleapis.com/generate_content_free_tier_requests`) est régulièrement épuisé. Le fallback OpenAI est automatique et transparent. Ajouter une clé Gemini payante en `Organization.googleAiApiKey` pour s'affranchir du quota global.
|
| 146 |
+
|
| 147 |
+
---
|
| 148 |
+
|
| 149 |
+
## Chaîne de Handlers (whatsapp-logic.ts)
|
| 150 |
+
|
| 151 |
+
Ordre d'exécution, premier `canHandle() = true` gagne :
|
| 152 |
+
|
| 153 |
+
1. **AIAgentHandler** — si `organization.mode === 'AI_AGENT'`
|
| 154 |
+
2. **OnboardingHandler** — INSCRIPTION, LANG_*, SEC_* (si `!user.activity`), free-text activité
|
| 155 |
+
3. **CommandHandler** — SEED, MENU_HISTORIQUE, DAY{n}_{ACTION}, ADMIN_*
|
| 156 |
+
4. **NavigationHandler** — MENU, SUITE, CONTINUER, DAY{n}, langue
|
| 157 |
+
5. **ExerciseHandler** — si `activeEnrollment` existe (catch-all pour les réponses pédagogiques)
|
| 158 |
+
|
| 159 |
+
---
|
| 160 |
+
|
| 161 |
+
## Jobs BullMQ — Nommage
|
| 162 |
+
|
| 163 |
+
| Job | Handler | Déclencheur |
|
| 164 |
+
|-----|---------|------------|
|
| 165 |
+
| `handle-inbound` | InboundHandler | Texte entrant |
|
| 166 |
+
| `download-media` | MediaHandler | Audio/image entrant |
|
| 167 |
+
| `enroll-user` | EnrollHandler | Sélection secteur |
|
| 168 |
+
| `send-content` | ContentHandler | Après enrollment, après exercice validé |
|
| 169 |
+
| `generate-feedback` | FeedbackHandler | Après réponse exercice |
|
| 170 |
+
| `send-message` | MessageHandler | Toute sortie texte |
|
| 171 |
+
| `send-interactive-list` | MessageHandler | Listes interactives |
|
| 172 |
+
| `send-nudge` | NudgeHandler | Relances planifiées |
|
| 173 |
+
| `send-broadcast` | BroadcastHandler | Campagnes |
|
| 174 |
+
|
| 175 |
+
---
|
| 176 |
+
|
| 177 |
+
## Limitations Connues (à surveiller)
|
| 178 |
+
|
| 179 |
+
| Limitation | Impact | Mitigation |
|
| 180 |
+
|-----------|--------|-----------|
|
| 181 |
+
| Gemini free tier quota épuisé | Latence +2-3s (fallback OpenAI) | Ajouter clé payante dans org |
|
| 182 |
+
| `SERPER_API_KEY` absent | Search mock → données marché non réelles | Ajouter clé Serper |
|
| 183 |
+
| HuggingFace sleep après 48h inactivité | Premier message lent (~30s cold start) | Envoyer un ping quotidien |
|
| 184 |
+
| `gemini-1.5-pro` déprécié via v1beta | Erreur 404 → fallback OpenAI | Migré vers gemini-2.0-flash |
|
| 185 |
+
|
| 186 |
+
---
|
| 187 |
+
|
| 188 |
+
## Commandes de Diagnostic
|
| 189 |
+
|
| 190 |
+
```bash
|
| 191 |
+
# Vérifier si ENCRYPTION_SECRET peut déchiffrer les secrets en DB
|
| 192 |
+
ENCRYPTION_SECRET="..." DATABASE_URL="..." \
|
| 193 |
+
npx tsx apps/api/scratch/check_encryption.ts
|
| 194 |
+
|
| 195 |
+
# Faire tourner le diagnostic d'encodage des orgs
|
| 196 |
+
ENCRYPTION_SECRET="..." DATABASE_URL="..." \
|
| 197 |
+
npx tsx apps/api/scratch/audit_db.ts
|
| 198 |
+
|
| 199 |
+
# Rotation de clé (si ENCRYPTION_SECRET a changé)
|
| 200 |
+
OLD_ENCRYPTION_SECRET="..." NEW_ENCRYPTION_SECRET="..." DATABASE_URL="..." \
|
| 201 |
+
npx tsx apps/api/scratch/rotate_encryption_key.ts
|
| 202 |
+
```
|
|
@@ -11,10 +11,9 @@ export class GeminiProvider implements LLMProvider {
|
|
| 11 |
constructor(apiKey: string) {
|
| 12 |
logger.info('[GEMINI] Initializing SDK...');
|
| 13 |
this.genAI = new GoogleGenerativeAI(apiKey);
|
| 14 |
-
// Standard model for normal requests
|
| 15 |
this.flashModel = this.genAI.getGenerativeModel({ model: 'gemini-2.0-flash' });
|
| 16 |
-
//
|
| 17 |
-
this.proModel = this.genAI.getGenerativeModel({ model: 'gemini-
|
| 18 |
}
|
| 19 |
|
| 20 |
async generateStructuredData<T>(prompt: string, _schema: z.ZodSchema<T>, temperature?: number, imageUrl?: string): Promise<T> {
|
|
@@ -22,7 +21,7 @@ export class GeminiProvider implements LLMProvider {
|
|
| 22 |
// Use Pro for complex docs (OnePager/PitchDeck) - detected by prompt length or keyword
|
| 23 |
const isComplex = prompt.includes('PITCH_DECK') || prompt.includes('ONE_PAGER') || prompt.length > 2000;
|
| 24 |
const model = isComplex ? this.proModel : this.flashModel;
|
| 25 |
-
const modelName = isComplex ? 'gemini-
|
| 26 |
|
| 27 |
logger.info(`[GEMINI] Generating structured data with ${modelName}... (Vision: ${!!imageUrl})`);
|
| 28 |
|
|
|
|
| 11 |
constructor(apiKey: string) {
|
| 12 |
logger.info('[GEMINI] Initializing SDK...');
|
| 13 |
this.genAI = new GoogleGenerativeAI(apiKey);
|
|
|
|
| 14 |
this.flashModel = this.genAI.getGenerativeModel({ model: 'gemini-2.0-flash' });
|
| 15 |
+
// gemini-1.5-pro is deprecated via v1beta; use gemini-2.0-flash for all requests
|
| 16 |
+
this.proModel = this.genAI.getGenerativeModel({ model: 'gemini-2.0-flash' });
|
| 17 |
}
|
| 18 |
|
| 19 |
async generateStructuredData<T>(prompt: string, _schema: z.ZodSchema<T>, temperature?: number, imageUrl?: string): Promise<T> {
|
|
|
|
| 21 |
// Use Pro for complex docs (OnePager/PitchDeck) - detected by prompt length or keyword
|
| 22 |
const isComplex = prompt.includes('PITCH_DECK') || prompt.includes('ONE_PAGER') || prompt.length > 2000;
|
| 23 |
const model = isComplex ? this.proModel : this.flashModel;
|
| 24 |
+
const modelName = isComplex ? 'gemini-2.0-flash (complex)' : 'gemini-2.0-flash';
|
| 25 |
|
| 26 |
logger.info(`[GEMINI] Generating structured data with ${modelName}... (Vision: ${!!imageUrl})`);
|
| 27 |
|
|
@@ -32,5 +32,8 @@ INVITATION DEEP-DIVE OBLIGATOIRE :
|
|
| 32 |
Termine EXACTEMENT ton pilier 3 par cette phrase selon la langue :
|
| 33 |
(FR): "Si tu veux affiner ce point avec une donnée de ton propre terrain, tape 1️⃣ APPROFONDIR, sinon tape 2️⃣ SUITE."
|
| 34 |
(WO): "Su nga bëggee yokk leneen ci li nga xam, bindal 1️⃣ APPROFONDIR, wala nga bind 2️⃣ SUITE."
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
{{buttonBypassBlock}}
|
|
|
|
| 32 |
Termine EXACTEMENT ton pilier 3 par cette phrase selon la langue :
|
| 33 |
(FR): "Si tu veux affiner ce point avec une donnée de ton propre terrain, tape 1️⃣ APPROFONDIR, sinon tape 2️⃣ SUITE."
|
| 34 |
(WO): "Su nga bëggee yokk leneen ci li nga xam, bindal 1️⃣ APPROFONDIR, wala nga bind 2️⃣ SUITE."
|
| 35 |
+
(EN): "To refine this point with data from your own field, type 1️⃣ DEEP DIVE, otherwise type 2️⃣ CONTINUE."
|
| 36 |
+
(ES): "Para profundizar este punto con datos de tu propio campo, escribe 1️⃣ PROFUNDIZAR, de lo contrario escribe 2️⃣ CONTINUAR."
|
| 37 |
+
(PT): "Para aprofundar este ponto com dados do seu próprio campo, escreva 1️⃣ APROFUNDAR, caso contrário escreva 2️⃣ CONTINUAR."
|
| 38 |
|
| 39 |
{{buttonBypassBlock}}
|