Files
ai-kit/package.json
T
CatoandClaude Opus 5 5119b59eb5 feat(stream): the chain can stream, so apps stop going around it (#62)
This package could not stream. `complete()` is request/response only, so every
app that wanted tokens to appear as they arrived used ai-kit to pick the model,
classify the 429 and track health — and then threw all of it away for the one
call that matters. Measured across the fleet on 2026-09-15: six hand-rolled
provider clients, four SSE readers, four emitters with divergent headers, under
~20,800 lines of chat UI in nine apps.

The duplication was real and it was in the wrong place. The apps were not
reinventing streaming because streaming is hard; they were reinventing it
because the package that owned the chain had no door for it.

ONE WALK, NOT TWO

`complete()` and `completeStream()` now share `walkChain`, extracted from
complete() unchanged. They must agree about what a dead vendor is, or the fleet
gets two answers to "is this provider out of budget" and the streaming path —
the one every chat surface uses — is the one that gets it wrong. complete()'s
existing suite is what proves the extraction was faithful; all 278 tests pass.

WHERE FALLBACK STOPS, AND WHY

A non-streaming walk can try every link because nothing has been shown yet. A
streaming walk cannot: once the first token is out, falling back would replay
the answer from the beginning into somebody already reading it. So the boundary
is explicit. Fails before the first delta -> LinkFailure, the walk continues.
Fails after -> StreamInterrupted, carrying the partial text, no silent recovery,
because there is no honest one.

That is also why a link is "served" only once a first token is really out. A 200
that then says nothing demotes, which is the same judgement complete() already
makes about an empty completion.

THE BUG THIS ENDS

ai-kit/sse carries both ends of the wire, lifted from loki, which had them
right. The reader KEEPS THE REMAINDER between chunks. A ReadableStream chunk is
a TCP-sized slice ending wherever the network put the boundary — routinely
mid-frame. Two apps split each chunk on newlines and dropped whatever straddled
it: a word vanishes from a long answer under load, nobody reports it, nobody can
reproduce it, and every short test passes.

12 new tests, choosing their own chunk boundaries because the boundaries ARE the
bug — including a frame cut mid-JSON and a chunk cut inside a two-byte "ü".
Proven by mutation: reintroducing the shipped `split` with no remainder turns
the suite red.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 02:31:37 -07:00

116 lines
2.8 KiB
JSON

{
"name": "@bitbaum/ai-kit",
"version": "1.9.0",
"license": "MIT",
"author": "Mao Nakamoto",
"homepage": "https://github.com/bitbaum/ai-kit#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/bitbaum/ai-kit.git"
},
"bugs": {
"url": "https://github.com/bitbaum/ai-kit/issues"
},
"keywords": [
"ai",
"llm",
"form-fill",
"fallback",
"failover",
"health-check",
"free-tier",
"rate-limit",
"quota",
"fair-share",
"groq",
"openrouter"
],
"type": "module",
"sideEffects": false,
"packageManager": "pnpm@11.25.0",
"engines": {
"node": ">=20"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"files": [
"dist",
"dist-cjs",
"src"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./sse": {
"types": "./dist/sse.d.ts",
"default": "./dist/sse.js"
},
"./forms": {
"types": "./dist/forms.d.ts",
"default": "./dist/forms.js"
},
"./react": {
"types": "./dist/react.d.ts",
"default": "./dist/react.js"
},
"./server": {
"types": "./dist/server.d.ts",
"default": "./dist/server.js"
},
"./registry": {
"types": "./dist/registry.d.ts",
"require": "./dist-cjs/registry.js",
"default": "./dist/registry.js"
},
"./web": {
"types": "./dist/web/index.d.ts",
"default": "./dist/web/index.js"
},
"./capability": {
"types": "./dist/capability/index.d.ts",
"default": "./dist/capability/index.js"
},
"./grounding": {
"types": "./dist/grounding/index.d.ts",
"require": "./dist-cjs/grounding/index.js",
"default": "./dist/grounding/index.js"
}
},
"scripts": {
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist-cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
"lint": "eslint .",
"typecheck": "tsc -p tsconfig.json --noEmit",
"test": "node --test test/*.test.js",
"check:catalog": "pnpm run build && node scripts/check-catalog.mjs",
"smoke": "pnpm run build && node scripts/smoke.mjs",
"verify": "pnpm run format:check && pnpm run lint && pnpm run typecheck && pnpm run build && pnpm test",
"prepare": "pnpm run build",
"format": "prettier --write .",
"format:check": "prettier --check ."
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"@types/node": "^26.5.0",
"eslint": "^10.10.0",
"globals": "^17.12.0",
"prettier": "3.9.6",
"typescript": "^6.0.3",
"typescript-eslint": "^8.70.0"
},
"dependencies": {
"ai-forms": "^0.1.2"
},
"peerDependencies": {
"react": ">=18"
},
"peerDependenciesMeta": {
"react": {
"optional": true
}
}
}