mirror of
https://github.com/bitbaum/ai-kit.git
synced 2026-12-04 04:47:42 +01:00
Merging #32 gave this package an HTTP client but published nothing: the version stayed at 0.6.2, so no consumer could reach it. This releases it. It also closes the gap that a shared engine makes dangerous. Every check in this repo was hermetic — `test/` drives an injected fetch, `check-catalog` asks whether ids still EXIST — so all of them could be green while the package could not complete one real turn. That was survivable while two repos imported it. It stops being survivable when one engine sits behind every app, because then its bugs arrive everywhere simultaneously. scripts/smoke.mjs makes a real generation against the live free tier. It earned its place on first run, finding two things no hermetic test could: - `maxTokens: 16` made groq/openai/gpt-oss-20b return 200 with EMPTY content. The chain leads with REASONING models, which spend the budget thinking before emitting a visible token — so a small budget makes a healthy model indistinguishable from a dead one, walks the entire chain, and reports every link broken. Documented on CompleteOptions.maxTokens where a consumer will actually hit it, and the smoke now asks for 256. - A single-quoted value in a .env inlines its QUOTES into the key, and OpenRouter answers that with "Missing Authentication header" — which reads as a missing key rather than a malformed one. Scheduled, never a PR gate: it calls other people's servers, so as a required check it would redden pull requests for a vendor's 500 and train everyone to ignore red. The `|| status=$?` in the workflow is load-bearing — Actions runs steps under `bash -e`, so a bare failing command aborts before its exit code can be read, and the "no keys" branch would be unreachable. Both scheduled jobs refuse to pass while blind: a probe that looked at nothing has told us nothing, and green would be a lie. Verified: catalog check run live — all 7 default pins present at their vendor, confirmed both locally and in Actions ("7 id(s) confirmed present"). Smoke run live — groq/openai/gpt-oss-120b answered "blue" in 878ms. verify green: format + lint + typecheck + build + 91 tests. Claude-Session: https://claude.ai/code/session_01NHDLTKGirKU7He8q2YR2y4 Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
100 lines
4.5 KiB
JavaScript
100 lines
4.5 KiB
JavaScript
/**
|
|
* Does the engine actually WORK, against real vendors, today?
|
|
*
|
|
* Every other check in this repo is hermetic: `test/` drives `complete()`
|
|
* through an injected fetch, and `check-catalog.mjs` asks whether the pinned
|
|
* ids still exist. Both can be green while the package cannot complete a single
|
|
* real turn — a changed request shape, a header a vendor started rejecting, a
|
|
* response envelope that moved. Nothing here has ever made a real generation.
|
|
*
|
|
* That gap matters more now than it did. This package is becoming the one
|
|
* engine behind every app in the fleet, and a shared engine converts its own
|
|
* bugs into a fleet-wide outage: the same defect, in every app, at once. The
|
|
* hermetic tests say the LOGIC is right. This says the THING RUNS.
|
|
*
|
|
* ── WHY THIS IS NOT A PR GATE ────────────────────────────────────────────────
|
|
* It calls other people's servers, so it fails for reasons that have nothing to
|
|
* do with the diff: a vendor 500, a spent daily budget, a retired id. Wired into
|
|
* PR CI it would redden an unrelated pull request and teach everyone to ignore
|
|
* a red check — the failure mode where a live smoke arms a trap that springs on
|
|
* whoever pushes next. So it runs on a SCHEDULE, where a failure means what it
|
|
* says: the engine could not complete a turn today.
|
|
*
|
|
* Exit 1 only when the chain was walked and every link failed. No keys means
|
|
* nothing was attempted, which is a different sentence, and it is the caller's
|
|
* job (the workflow) to decide whether being unable to look is acceptable.
|
|
*
|
|
* Run: node scripts/smoke.mjs (pnpm run smoke)
|
|
*/
|
|
import { complete, freeChain, usableChain, ChainExhaustedError } from "../dist/index.js";
|
|
|
|
const chain = usableChain(freeChain());
|
|
|
|
if (chain.length === 0) {
|
|
console.log("NO KEYS — nothing was attempted. Set GROQ_API_KEY / OPENROUTER_API_KEY.");
|
|
// Not a pass and not a failure: it is a non-answer. The workflow decides.
|
|
process.exit(2);
|
|
}
|
|
|
|
console.log(`Walking ${chain.length} link(s).`);
|
|
|
|
// A question with exactly one right answer, short enough that no model needs a
|
|
// large budget, and phrased so a correct reply cannot be produced by a model
|
|
// that is echoing the prompt back — the failure that "200 with empty content"
|
|
// is the extreme version of.
|
|
const messages = [
|
|
{ role: "system", content: "Answer with a single word, no punctuation." },
|
|
{ role: "user", content: "What colour is a clear midday sky? Answer in one word." },
|
|
];
|
|
|
|
const started = Date.now();
|
|
try {
|
|
const result = await complete({
|
|
messages,
|
|
// Generous for a one-word answer, and deliberately so: the default chain
|
|
// leads with REASONING models, which spend this budget thinking before they
|
|
// emit a single visible token. At 16 the thinking consumes all of it and the
|
|
// vendor returns 200 with empty content — indistinguishable, from the
|
|
// outside, from the dead-model case this script exists to detect. Verified
|
|
// 2026-09-05: groq/openai/gpt-oss-20b answered empty at 16, fine at 256.
|
|
maxTokens: 256,
|
|
temperature: 0,
|
|
onLinkFailure: (link, error) =>
|
|
console.log(` demoted ${link.provider.id}/${link.model} — ${error.message}`),
|
|
});
|
|
|
|
const ms = Date.now() - started;
|
|
const answer = result.text.trim();
|
|
console.log(`\nserved by : ${result.id}`);
|
|
console.log(`answered : ${JSON.stringify(answer)} (${ms}ms)`);
|
|
|
|
// The point is that a real model produced real words. Asserting the answer is
|
|
// literally "blue" would make a vendor's phrasing ("Blue.") fail a working
|
|
// engine, so the bar is: non-empty, and short enough to be an answer rather
|
|
// than a refusal or an error page that arrived with a 200.
|
|
if (answer.length === 0) {
|
|
console.error(
|
|
"::error::Empty answer survived the chain — the empty-content guard is not working.",
|
|
);
|
|
process.exit(1);
|
|
}
|
|
if (answer.length > 120) {
|
|
console.error(
|
|
`::error::Answer implausibly long for a one-word question (${answer.length} chars) — likely an error body returned as content.`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log("\nThe engine completed a real turn.");
|
|
} catch (error) {
|
|
if (error instanceof ChainExhaustedError) {
|
|
console.error(`\n::error::Every link failed — the engine cannot complete a turn.`);
|
|
for (const f of error.failures) console.error(` ${f.message}`);
|
|
process.exit(1);
|
|
}
|
|
console.error(
|
|
`\n::error::Unexpected failure (not a chain exhaustion) — ${error?.stack ?? error}`,
|
|
);
|
|
process.exit(1);
|
|
}
|