From 3636ef3ff91377e03dafa3375a5fb108b7f29573 Mon Sep 17 00:00:00 2001 From: Storme-bit Date: Mon, 20 Apr 2026 23:19:01 -0700 Subject: [PATCH] extraction error logging --- packages/memory-service/src/entities/extraction.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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');