// ============================================================================
// H33 Agent SDK — Quick Start (5-minute getting started)
// ============================================================================
//
// Run:  npx tsx examples/quickstart.ts
// Env:  H33_API_KEY=your-key-here
//
// This is the killer demo: wrap an existing agent in 5 minutes and
// every action becomes replayable, attestable, independently verifiable.

import { H33Agent } from '@h33/agent';

async function main() {
  // ── 1. Create an attested agent (one line) ──
  const agent = new H33Agent({
    name: 'Claims Review Agent',
    canonicalName: 'h33.agent.acme.claims.review.prod.001',
    tenantId: 'acme-corp',
    allowedTools: ['h33.tool.acme.database.v1', 'h33.tool.acme.classifier.v1'],
    forbiddenDataClasses: ['PII', 'PHI'],
  });

  // ── 2. Start (registers identity + opens attested session) ──
  await agent.start();
  console.log('Agent running:', agent.agentId);

  // ── 3. Wrap a tool — every call automatically attested ──
  const searchClaims = agent.tool('h33.tool.acme.database.v1', async (query: string) => {
    // Your existing code — zero changes needed
    return { results: ['claim-001', 'claim-002'], count: 2 };
  });

  const { result, receipt } = await searchClaims('open claims Q1 2026');
  console.log('Search results:', result.count);
  console.log('Receipt:', receipt.verification_url);

  // ── 4. Attest a decision ──
  const decision = await agent.action(
    'classify',
    'Classified claim-001 as high-risk',
    receipt.node_hash!, // chain to previous action
  );

  // ── 5. Verify — publicly, no API key needed ──
  const proof = await agent.verify(decision);
  console.log('Valid:', proof.valid);          // true
  console.log('Chain:', proof.integrity.chain); // "INTACT"
  console.log('CLI:', proof.cliCommand);        // hats verify --node <id>

  // ── 6. Stop (closes session with H33-74 commitment) ──
  await agent.stop();
  console.log('Total receipts:', agent.receipts.length);
}

main().catch(console.error);
