Examples
Working code for the most common flows.
Two minimal agent loops. One in Node/TypeScript, one in Python. That hit /api/decision and present the verdict to the user.
Node / TypeScript
Save as agent-flow.ts, run with:
NIPCODE_API_KEY=nip_xxxxxxxxx node --experimental-strip-types agent-flow.ts "fast xml parser"
const BASE = 'https://nipcode.xyz';
const KEY = process.env.NIPCODE_API_KEY ?? '';
async function decide(query: string) {
const url = `${BASE}/api/decision?q=${encodeURIComponent(query)}&sources=npm,pypi,crates,github&limit=5`;
const r = await fetch(url, { headers: { 'x-nipcode-api-key': KEY } });
if (!r.ok) throw new Error(`decision failed: ${r.status}`);
return r.json();
}
const data = await decide(process.argv.slice(2).join(' ') || 'http client');
const b = data.best;
if (!b) { console.log('no candidates'); process.exit(0); }
console.log(`${b.name} (${b.source}). Decision ${b.decision_score}/100, risk ${b.risk_level}`);
for (const [k, v] of Object.entries(b.blocks)) console.log(` ${k}: ${v}`);
console.log(`\nApprove this? Install: ${b.blocks.install_boundary.split('.')[0]}`);
Python
import os, sys, json, urllib.parse, urllib.request
BASE = "https://nipcode.xyz"
KEY = os.environ["NIPCODE_API_KEY"]
q = " ".join(sys.argv[1:]) or "http client"
qs = urllib.parse.urlencode({"q": q, "sources": "npm,pypi", "limit": "5"})
req = urllib.request.Request(f"{BASE}/api/decision?{qs}")
req.add_header("x-nipcode-api-key", KEY)
with urllib.request.urlopen(req, timeout=20) as r:
d = json.loads(r.read())
b = d.get("best")
if not b: print("no candidates"); sys.exit(0)
print(f"{b['name']} ({b['source']}). Decision {b['decision_score']}/100")
for k, v in b["blocks"].items():
print(f" {k}: {v}")
print(f"\nApprove? Install: {b['blocks']['install_boundary'].split('.')[0]}")
More
Both files live in the repo at github.com/trynipcode/nipcode/tree/main/examples. Patches welcome.
