fleetbo-cockpit-cli 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +24 -4
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -163,10 +163,6 @@ if (command === 'alex') {
|
|
|
163
163
|
headers: { 'x-project-id': projectId }
|
|
164
164
|
});
|
|
165
165
|
let aiData = result.data;
|
|
166
|
-
// --- DEBUG (À SUPPRIMER APRÈS) ---
|
|
167
|
-
console.log('\n[DEBUG-1] typeof result.data:', typeof result.data);
|
|
168
|
-
console.log('[DEBUG-2] first 120 chars:', JSON.stringify(result.data).substring(0, 120));
|
|
169
|
-
// --- FIN DEBUG ---
|
|
170
166
|
if (typeof aiData === 'string') {
|
|
171
167
|
try { aiData = JSON.parse(aiData); } catch (_) {}
|
|
172
168
|
}
|
|
@@ -181,6 +177,30 @@ if (command === 'alex') {
|
|
|
181
177
|
if (aiData.status === 'success' || aiData.status === 'message' || aiData.status === 'complex_refusal') {
|
|
182
178
|
console.log('');
|
|
183
179
|
let rawMsg = aiData.message || "I'm ready.";
|
|
180
|
+
|
|
181
|
+
// 🛡️ FIX DÉFINITIF: Gemini imbrique parfois le JSON complet dans "message"
|
|
182
|
+
// Le JSON imbriqué peut être tronqué (4000 tokens), donc JSON.parse échoue.
|
|
183
|
+
// On extrait le vrai message par découpe de string.
|
|
184
|
+
if (typeof rawMsg === 'string' && rawMsg.trimStart().startsWith('{')) {
|
|
185
|
+
// Tentative 1: Parse complet (JSON non tronqué)
|
|
186
|
+
try {
|
|
187
|
+
const nested = JSON.parse(rawMsg);
|
|
188
|
+
if (nested && nested.message) {
|
|
189
|
+
rawMsg = nested.message;
|
|
190
|
+
if (!aiData.moduleData && nested.moduleData) {
|
|
191
|
+
aiData.moduleData = nested.moduleData;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
} catch (_) {
|
|
195
|
+
// Tentative 2: Extraction par regex (JSON tronqué)
|
|
196
|
+
const msgMatch = rawMsg.match(/"message"\s*:\s*"((?:[^"\\]|\\.)*)"/);
|
|
197
|
+
if (msgMatch && msgMatch[1]) {
|
|
198
|
+
rawMsg = msgMatch[1].replace(/\\n/g, '\n').replace(/\\"/g, '"');
|
|
199
|
+
} else {
|
|
200
|
+
rawMsg = "Module generated. Check files below.";
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
184
204
|
|
|
185
205
|
// 🛡️ SAFETY: Si le message est un JSON stringifié ou contient du code brut,
|
|
186
206
|
// on extrait uniquement la partie lisible pour le terminal.
|