/** Synthetic connectivity example. Node.js 22.18+. No payment is executed. */ const base = 'https://agent-trust-firewall.andrea-vignoni.workers.dev'; type Verdict = { ok: boolean; verdict: 'ALLOW' | 'BLOCK'; reasons: unknown[] }; export async function check(amount: number): Promise { const key = process.env.AGENT_GUARD_KEY; const path = key ? '/trial/api/trust_check_spend' : '/v1/trust/spend-guard'; const headers: Record = { 'content-type': 'application/json', 'x-agent-source': 'docs-example', 'x-agent-name': 'typescript-example' }; if (key) headers.authorization = `Bearer ${key}`; const response = await fetch(base + path, { method: 'POST', headers, signal: AbortSignal.timeout(15000), body: JSON.stringify({ amount, remaining_budget: 10 }) }); if (!response.ok) throw new Error(`HTTP ${response.status}: stop execution`); const result = await response.json() as Verdict; if (result.ok !== true || !['ALLOW', 'BLOCK'].includes(result.verdict)) throw new Error('Invalid response: stop execution'); return result; } for (const [amount, expected] of [[2, 'ALLOW'], [11, 'BLOCK']] as const) { const result = await check(amount); if (result.verdict !== expected) throw new Error('Unexpected verdict: stop execution'); console.log(JSON.stringify({ amount, verdict: result.verdict })); }