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:
parent
fa835e4f56
commit
40a0513b05
|
|
@ -61,7 +61,9 @@ export class InputGateService {
|
||||||
temperature: 0,
|
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 parsed = JSON.parse(text);
|
||||||
|
|
||||||
const classification: InputClassification = parsed.classification || 'ON_TOPIC';
|
const classification: InputClassification = parsed.classification || 'ON_TOPIC';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue