Pretty print fenced JSON in admin AI replies
Build and publish frontend / publish (push) Successful in 1m14s
Build and publish frontend / publish (push) Successful in 1m14s
This commit is contained in:
@@ -79,3 +79,18 @@ test('admin JSON text decodes common JSON and YAML escapes while retaining the s
|
||||
assert.equal(decode(String.raw`\U0001F642`), '🙂');
|
||||
assert.equal(decode(String.raw`okänt: \q`), String.raw`okänt: \q`);
|
||||
});
|
||||
|
||||
test('fenced JSON in AI replies is parsed for readable formatting', () => {
|
||||
const parser = page.match(/function parseAiResponseSegments\(response\) \{[\s\S]*?\n \}/);
|
||||
assert.ok(parser, 'AI response segment parser should be present');
|
||||
assert.match(page, /renderAdminAiResponse\(card, interaction\.response\)/);
|
||||
assert.match(page, /JSON-svar · formaterat/);
|
||||
assert.match(page, /admin-ai-response-code/);
|
||||
const parseSegments = new Function(`${parser[0]}; return parseAiResponseSegments;`)();
|
||||
const segments = parseSegments('dialogue-turn · completed: ```json { "intent": "speak", "reply": "Rad 1\\nRad 2" }```');
|
||||
|
||||
assert.equal(segments[0].type, 'text');
|
||||
assert.equal(segments[0].value, 'dialogue-turn · completed: ');
|
||||
assert.equal(segments[1].type, 'json');
|
||||
assert.deepEqual(segments[1].value, {intent: 'speak', reply: 'Rad 1\nRad 2'});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user