Files
Agentic-AI/scripts/t-e2e.mjs
T

61 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import jwt from 'jsonwebtoken';
import dotenv from 'dotenv';
dotenv.config();
const BASE = 'http://localhost:4000';
const ADMIN = '6a00cefe524bebd27037a968'; // Thulasiraman S (admin)
const AGENT = '6a4dfd7ecb0ff97137bc99e5'; // Kavyaa K (agent)
const tok = (id) => jwt.sign({ id }, process.env.CRM_JWT_SECRET, { expiresIn: '30m' });
async function chat(userId, message, sessionId) {
const t0 = Date.now();
const res = await fetch(`${BASE}/api/agent/chat`, {
method: 'POST',
headers: { 'content-type': 'application/json', authorization: `Bearer ${tok(userId)}` },
body: JSON.stringify({ message, session_id: sessionId }),
});
const j = await res.json();
return { ...j, ms: Date.now() - t0, status: res.status };
}
function summarise(r) {
if (!r.ok) return ` ERROR ${r.status}: ${r.error}`;
const lines = [];
for (const b of r.blocks || []) {
if (b.type === 'text') lines.push(` [text] ${b.markdown.replace(/\n+/g, ' ').slice(0, 300)}`);
else if (b.type === 'metrics') lines.push(` [metrics] ${b.items.map((i) => `${i.label}=${i.value}`).join(' ')}`);
else if (b.type === 'chart') lines.push(` [chart] ${b.chart_type} "${b.title}" svg=${b.svg.length}b rows=${b.table.rows.length}`);
else if (b.type === 'table') lines.push(` [table] "${b.title}" ${b.columns.length}cols × ${b.row_count}rows`);
else if (b.type === 'file') lines.push(` [file] ${b.filename} ${(b.bytes / 1024).toFixed(1)}kB → ${b.url}`);
else if (b.type === 'approval') lines.push(` [APPROVE] ${b.tool} (${b.risk}) — ${b.summary}`);
else if (b.type === 'notice') lines.push(` [notice] ${b.level}: ${b.message}`);
}
return lines.join('\n');
}
// ── capabilities ──
const caps = await (await fetch(`${BASE}/api/agent/capabilities`, {
headers: { authorization: `Bearer ${tok(AGENT)}` },
})).json();
console.log('=== CAPABILITIES (agent role: Kavyaa K) ===');
console.log('permissions:', caps.user.permissions.join(', '));
for (const a of caps.agents) console.log(` ${a.available ? '✓' : '✗'} ${a.title.padEnd(20)} ${a.tools.length} tools`);
console.log();
const tests = [
[ADMIN, 'How is the business doing over the last 90 days? Give me the headline numbers and a chart of the pipeline.'],
[ADMIN, 'Which lead sources actually convert? Chart it.'],
[ADMIN, 'Who on the team is performing best this quarter, and who has overdue follow-ups?'],
[ADMIN, 'Build me a PDF report on enrolment and payment performance for the last 90 days.'],
[ADMIN, 'Update the lead 919043104868 — set their tag to hot.'],
];
for (const [uid, msg] of tests) {
console.log(`=== "${msg.slice(0, 78)}" ===`);
const r = await chat(uid, msg, `test-${Math.random().toString(36).slice(2, 8)}`);
console.log(summarise(r));
console.log(` (${(r.ms / 1000).toFixed(1)}s)\n`);
}
process.exit(0);