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

33 lines
1.4 KiB
JavaScript

import jwt from 'jsonwebtoken';
import dotenv from 'dotenv';
dotenv.config();
const BASE = 'http://localhost:4000';
const ADMIN = '6a00cefe524bebd27037a968';
const tok = (id) => jwt.sign({ id }, process.env.CRM_JWT_SECRET, { expiresIn: '30m' });
const H = (id) => ({ 'content-type': 'application/json', authorization: `Bearer ${tok(id)}` });
const approved = process.argv.includes('--approve');
const sid = 'approve-' + Math.random().toString(36).slice(2, 8);
const r1 = await (await fetch(`${BASE}/api/agent/chat`, {
method: 'POST', headers: H(ADMIN),
body: JSON.stringify({ message: 'Add a note to lead 919043104868 saying: Follow up about the AI Basics batch.', session_id: sid }),
})).json();
console.log('--- TURN 1 ---');
for (const b of r1.blocks || []) {
console.log(' ', b.type, b.type === 'approval' ? `${b.tool} risk=${b.risk}` : (b.markdown || '').slice(0, 150));
}
console.log(' interrupt present:', !!r1.interrupt);
if (r1.interrupt) {
const r2 = await (await fetch(`${BASE}/api/agent/approve`, {
method: 'POST', headers: H(ADMIN),
body: JSON.stringify({ session_id: sid, approved, reason: approved ? undefined : 'Declined by test harness.' }),
})).json();
console.log(`\n--- TURN 2 (${approved ? 'APPROVED' : 'declined'}) ---`);
for (const b of r2.blocks || []) console.log(' ', b.type, (b.markdown || b.summary || '').slice(0, 300));
}
process.exit(0);