<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AgentDB WASM demo</title>
<style>
body { font-family: monospace; background: #0d1117; color: #c9d1d9; padding: 2rem; }
h1 { color: #58a6ff; }
pre { background: #161b22; border: 1px solid #30363d; padding: 1rem; border-radius: 6px;
white-space: pre-wrap; word-break: break-all; }
.ok { color: #3fb950; }
.err { color: #f85149; }
.dim { color: #8b949e; }
</style>
</head>
<body>
<h1>AgentDB WASM demo</h1>
<p class="dim">
Build first:
<code>wasm-pack build --target web --features wasm</code>
then serve this directory with any static file server.
</p>
<pre id="log">Loading…</pre>
<script type="module">
import init, { WasmAgentDB } from '../pkg/agentdb.js';
const log = document.getElementById('log');
function print(msg, cls = '') {
const line = document.createElement('span');
if (cls) line.className = cls;
line.textContent = msg + '\n';
log.appendChild(line);
}
log.textContent = '';
try {
await init();
print('[init] WASM module loaded', 'ok');
const db = WasmAgentDB.open_memory();
print('[open] in-memory database opened', 'ok');
db.execute("CREATE TABLE notes (id TEXT PRIMARY KEY, body TEXT)");
db.execute("INSERT INTO notes VALUES ('n1', 'Remember OPFS for persistence')");
db.execute("INSERT INTO notes VALUES ('n2', 'Vectors go in collections')");
const rows = JSON.parse(db.query_json("SELECT * FROM notes ORDER BY id"));
print('[sql] notes: ' + JSON.stringify(rows), 'ok');
db.vector_upsert('thoughts', 'v1', [0.9, 0.1, 0.0, 0.0], '{"topic":"memory"}');
db.vector_upsert('thoughts', 'v2', [0.1, 0.9, 0.0, 0.0], '{"topic":"vectors"}');
const hits = JSON.parse(db.vector_search('thoughts', [0.85, 0.15, 0.0, 0.0], 2));
print('[vec] search results: ' + JSON.stringify(hits), 'ok');
const stats = JSON.parse(db.stats());
print('[stats] ' + JSON.stringify(stats), 'ok');
db.prompt_create('greet', 'Hello, {{name}}! You have {{n}} notes.', '', 0, '');
const rendered = db.prompt_render('greet', JSON.stringify({ name: 'Agent', n: '2' }));
print('[prompt] ' + rendered, 'ok');
print('\nAll in-memory operations succeeded.', 'ok');
} catch (err) {
print('[error] ' + err, 'err');
console.error(err);
}
</script>
</body>
</html>