/**
 * Quick smoke test: run mimo-v2-flash on 10 paragraphs to see if it works.
 * Usage: bun ts/scripts/mimo-test.ts
 */
import { readJsonl } from "../src/lib/jsonl.ts";
import { Paragraph } from "@sec-cybert/schemas/paragraph.ts";
import { annotateParagraph } from "../src/label/annotate.ts";
import { v4 as uuidv4 } from "uuid";

const INPUT = new URL("../../data/paragraphs/training.jsonl", import.meta.url).pathname;
const MODEL = "xiaomi/mimo-v2-flash";
const N = 10;

async function main() {
  const { records: paragraphs } = await readJsonl(INPUT, Paragraph);
  const sample = paragraphs.slice(0, N);
  const runId = uuidv4();

  console.log(`Testing ${MODEL} on ${N} paragraphs...\n`);

  let success = 0;
  let failed = 0;

  for (const p of sample) {
    try {
      const ann = await annotateParagraph(p, {
        modelId: MODEL,
        stage: "benchmark",
        runId,
        reasoningEffort: "low",
      });
      success++;
      console.log(`✓ ${p.id.slice(0, 8)} → ${ann.label.content_category} / ${ann.label.specificity_level} (${ann.provenance.outputTokens} out, ${ann.provenance.reasoningTokens} reasoning, ${ann.provenance.latencyMs}ms, $${ann.provenance.costUsd.toFixed(5)})`);
    } catch (err) {
      failed++;
      const msg = err instanceof Error ? err.message : String(err);
      console.log(`✖ ${p.id.slice(0, 8)} → ${msg}`);
    }
  }

  console.log(`\n${success}/${N} succeeded, ${failed} failed`);
}

main().catch(err => { console.error(err); process.exit(1); });
