WeLe Agentic AI: LangGraph multi-agent CRM assistant with voice

This commit is contained in:
2026-08-28 02:16:03 +05:30
commit 105e58e02a
69 changed files with 11501 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
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);