diff --git a/packages/memory-service/src/entities/extraction.js b/packages/memory-service/src/entities/extraction.js index 9a953ed..d6ce6dd 100644 --- a/packages/memory-service/src/entities/extraction.js +++ b/packages/memory-service/src/entities/extraction.js @@ -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');