fix(agents): strip markdown code fences from InputGate Haiku response

Haiku sometimes returns JSON wrapped in ```json ... ``` code blocks,
causing JSON.parse to fail. Strip markdown fences before parsing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-07 08:59:19 -08:00
parent fa835e4f56
commit 40a0513b05
1 changed files with 3 additions and 1 deletions

View File

@ -61,7 +61,9 @@ export class InputGateService {
temperature: 0,
});
const text = (response.content[0] as { type: string; text?: string })?.text || '';
const rawText = (response.content[0] as { type: string; text?: string })?.text || '';
// Haiku sometimes wraps JSON in ```json ... ``` — strip markdown code fences
const text = rawText.replace(/^```(?:json)?\s*\n?/i, '').replace(/\n?```\s*$/i, '').trim();
const parsed = JSON.parse(text);
const classification: InputClassification = parsed.classification || 'ON_TOPIC';