32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
/* Reproduces the multi-turn bug: same session, three different questions. */
|
|
import jwt from 'jsonwebtoken';
|
|
import dotenv from 'dotenv';
|
|
dotenv.config();
|
|
|
|
const BASE = 'http://localhost:4000';
|
|
const ADMIN = '6a00cefe524bebd27037a968';
|
|
const token = jwt.sign({ id: ADMIN }, process.env.CRM_JWT_SECRET, { expiresIn: '30m' });
|
|
const sid = 'multi-' + Math.random().toString(36).slice(2, 8);
|
|
|
|
const asks = [
|
|
'How many leads are in the new_lead stage?',
|
|
'How many leads were created today?',
|
|
'List 3 lost leads with their names.',
|
|
];
|
|
|
|
for (const q of asks) {
|
|
const t0 = Date.now();
|
|
const r = await (await fetch(`${BASE}/api/agent/chat`, {
|
|
method: 'POST',
|
|
headers: { 'content-type': 'application/json', authorization: `Bearer ${token}` },
|
|
body: JSON.stringify({ message: q, session_id: sid }),
|
|
})).json();
|
|
|
|
const text = (r.blocks || []).filter((b) => b.type === 'text').map((b) => b.markdown).join(' ');
|
|
const kinds = (r.blocks || []).map((b) => b.type).join(',');
|
|
console.log(`Q: ${q}`);
|
|
console.log(` blocks=[${kinds}] ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
console.log(` A: ${text.replace(/\n+/g, ' ').slice(0, 170)}\n`);
|
|
}
|
|
process.exit(0);
|