@jovan158/vantage
Version:
See and control what your coding agent does
39 lines (38 loc) • 1.58 kB
JavaScript
// `vantage demo`: the whole chain against a mock upstream, no API key needed.
import { spawn } from "node:child_process";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { startProxy } from "../proxy.js";
import { Meter } from "../meter.js";
import { startMockAnthropic } from "../dev/mock-anthropic.js";
import { formatCost } from "../pricing.js";
import { log } from "./output.js";
const HERE = path.dirname(fileURLToPath(import.meta.url));
export async function cmdDemo() {
log("demo: proving the full chain against a mock upstream (no API key needed)");
const mock = await startMockAnthropic();
const meter = new Meter();
const proxy = await startProxy({
upstream: mock.url,
onUsage: (e) => {
meter.add(e);
log(meter.statusLine());
},
});
const fakeAgent = path.join(HERE, "..", "..", "examples", "fake-agent.mjs");
log(`upstream(mock) ${mock.url} · proxy ${proxy.url} · agent ${path.basename(fakeAgent)}`);
const child = spawn(process.execPath, [fakeAgent], {
stdio: "inherit",
env: { ...process.env, ANTHROPIC_BASE_URL: proxy.url },
});
return await new Promise((resolve) => {
child.on("exit", async (code) => {
const t = meter.snapshot();
log(`demo end · in ${t.input} · out ${t.output} · cache ${t.cacheRead} · ` +
formatCost(t.costUsd, t.unpriced, t.requests));
await proxy.close();
await mock.close();
resolve(code ?? 0);
});
});
}