/* * Live check — sends the exact request shape sux sends (both rules enabled) * to the TypeSafe API using $TYPESAFE_API_KEY, and prints the parsed verdict. * The key is never printed. * * source typesafe_api_key.secret.sh && node scripts/live-check.mjs */ import { createRequire } from "node:module"; const require = createRequire(import.meta.url); const SH = require("../shared.js"); const apiKey = process.env.TYPESAFE_API_KEY; if (!apiKey) { console.error("Set TYPESAFE_API_KEY first: source typesafe_api_key.secret.sh"); process.exit(2); } const settings = SH.normalizeSettings({ enabled: true, ruleA: { enabled: true, word1: "cats", word2: "dogs" }, ruleB: { enabled: true, word: "politics", above: true }, combine: "and", }); const post = { text: "My dog barked at the mail carrier for a solid hour today. Dogs, man.", alt: "", }; const res = await fetch("https://api.typesafe.ai/v1/systemone", { method: "POST", headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, body: JSON.stringify(SH.buildRequest(settings, post)), }); if (!res.ok) { console.error("HTTP " + res.status + ":", (await res.text()).slice(0, 300)); process.exit(1); } const json = await res.json(); const verdict = SH.decideFromAnswers(settings, (json && json.answers) || null); if (verdict === null) { console.error("Unexpected response shape:", JSON.stringify(json).slice(0, 500)); process.exit(1); } const probs = json.answers.compare && json.answers.compare.probabilities; console.log("model: ", json.model); console.log("P(cats/dogs/neither):", probs && probs.cats, probs && probs.dogs, probs && probs.neither); console.log("noul(politics):", json.answers.single && json.answers.single.noul); console.log("sux verdict: ", verdict); console.log("usage: ", JSON.stringify(json.usage)); console.log("LIVE CHECK OK");