extraction error logging

This commit is contained in:
Storme-bit
2026-04-20 23:19:01 -07:00
parent d2352ea48b
commit 3636ef3ff9

View File

@@ -77,9 +77,12 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
const data = await res.json();
const raw = data.response?.trim() ?? '';
console.log('[entities] raw response:', raw.slice(0, 300));
// Strip markdown fences defensively — small models sometimes add them anyway
const clean = raw.replace(/^```(?:json)?\n?/, '').replace(/\n?```$/, '').trim();
// Extract just the JSON array — everything from [ to the last ]
const match = raw.match(/\[[\s\S]*\]/);
if (!match) throw new Error('No JSON array found in response');
const clean = match[0];
const entities = JSON.parse(clean);
if (!Array.isArray(entities)) throw new Error('Response was not a JSON array');