-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.html
More file actions
130 lines (123 loc) · 5.71 KB
/
examples.html
File metadata and controls
130 lines (123 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preload" href="/nipcode-logo.png" as="image" />
<link rel="stylesheet" href="/_next/static/chunks/0pwsw40vfluf4.css" />
<link rel="icon" href="/nipcode-logo.png" type="image/png" />
<title>Examples · Nipcode docs</title>
<meta name="description" content="Working code snippets in TypeScript and Python." />
<link rel="canonical" href="https://nipcode.xyz/examples" />
<script src="/scramble.js" defer></script>
</head>
<body>
<a class="skip-link" href="#main">Skip to content</a>
<header class="topbar" aria-label="Primary">
<a class="brand" aria-label="Nipcode home" href="/">
<span class="nipcode-mark" aria-hidden="true" style="--mark-size: 54px"><img alt="" height="54" src="/nipcode-logo.png" width="54" /></span>
<span class="brand-word" aria-hidden="true">Nipcode</span>
</a>
<div class="brand-socials" aria-label="Nipcode links">
<a class="brand-docs-link" href="/docs">Docs</a>
<a class="brand-login-link" href="/account">Login</a>
<a class="brand-icon-button" href="https://github.com/trynipcode/nipcode" target="_blank" rel="noreferrer" title="GitHub" aria-label="GitHub"><img alt="" height="18" src="/github-logo.svg" width="18"/></a>
<a class="brand-icon-button" href="https://x.com/trynipcode" target="_blank" rel="noreferrer" title="X" aria-label="X"><svg aria-hidden="true" viewBox="0 0 24 24" width="18" height="18"><path d="M18.24 2.25h3.31l-7.23 8.26 8.5 11.24h-6.66l-5.21-6.82-5.97 6.82H1.67l7.73-8.84L1.25 2.25h6.83l4.71 6.23 5.45-6.23Zm-1.16 17.52h1.83L7.08 4.13H5.11l11.97 15.64Z" fill="currentColor"/></svg></a>
</div>
</header>
<main class="docs-shell" id="main">
<aside class="docs-sidebar" aria-label="Documentation">
<a class="docs-sidebar-title" href="/docs">Nipcode docs</a>
<nav class="docs-sidebar-nav">
<div class="docs-sidebar-group">
<p>Get started</p>
<div>
<a href="/docs">Overview</a>
<a href="/quickstart">Quickstart</a>
</div>
</div>
<div class="docs-sidebar-group">
<p>API</p>
<div>
<a href="/api-access">API reference</a>
<a href="/agents">Agents</a>
<a class="docs-sidebar-active" aria-current="page" href="/examples">Examples</a>
</div>
</div>
<div class="docs-sidebar-group">
<p>How it works</p>
<div>
<a href="/sources">Sources</a>
<a href="/trust">Trust model</a>
<a href="/architecture">Architecture</a>
<a href="/security">Security</a>
</div>
</div>
</nav>
</aside>
<article class="docs-main">
<header class="docs-hero">
<p class="docs-eyebrow" data-scramble-text data-scramble-duration="600">Examples</p>
<h1>Working code for the most common flows.</h1>
<p>Two minimal agent loops. One in Node/TypeScript, one in Python. That hit <code>/api/decision</code> and present the verdict to the user.</p>
</header>
<section class="docs-section" id="ts">
<div class="docs-section-head"><h2>Node / TypeScript</h2></div>
<div class="docs-prose">
<p>Save as <code>agent-flow.ts</code>, run with:</p>
<pre><code>NIPCODE_API_KEY=nip_xxxxxxxxx node --experimental-strip-types agent-flow.ts "fast xml parser"</code></pre>
<pre><code>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]}`);</code></pre>
</div>
</section>
<section class="docs-section" id="python">
<div class="docs-section-head"><h2>Python</h2></div>
<div class="docs-prose">
<pre><code>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]}")</code></pre>
</div>
</section>
<section class="docs-section">
<div class="docs-section-head"><h2>More</h2></div>
<div class="docs-prose">
<p>Both files live in the repo at <a href="https://github.com/trynipcode/nipcode/tree/main/examples">github.com/trynipcode/nipcode/tree/main/examples</a>. Patches welcome.</p>
</div>
</section>
</article>
</main>
<footer class="site-footer" aria-label="Site footer">
<p class="site-footer-copy">Nipcode © 2026</p>
<nav class="site-footer-links" aria-label="Legal">
<a href="/changelog">Changelog</a>
<a href="/privacy">Privacy</a>
<a href="/terms">Terms</a>
<a href="/faq">FAQ</a>
</nav>
</footer>
</body>
</html>