Files
ai-kit/package.json
T
0bd6c38103 feat(tool-protocol): read the OTHER way models ask for a tool (#50)
`chain.ts` carries a probe table from nine free models called with a real tool.
Four answered with native `tool_calls`. Five answered only in TEXT. Three of the
seven models in the chain this package ships TODAY are in that second group:

  google/gemma-4-26b-a4b-it:free      text
  cohere/north-mini-code:free         text
  openrouter/free                     text

`complete()` read only `message.tool_calls`. So on nearly half its own chain it
returned ZERO tool calls — and handed the model's narration of the call back as
ordinary content. A turn that should have looked up a record instead returns a
confident sentence describing the lookup it never performed, and every layer
downstream treats that as an answer.

That is not a missing feature. It is a fabrication path, and the package's own
evidence said it was open.

The old comment called text parsing "the caller's business, because its
convention differs per app". True of the convention; false of the consequence.
An app that declines to parse does not get less capability, it gets invented
answers — and the one app in this fleet that does parse had to keep its whole
HTTP client to do it, which is why "put every app on one caller" was blocked.

WHAT CHANGES

`complete()` now reads both protocols and merges them, native winning ties so a
model emitting the real call plus a prose echo runs the tool once. Parsed lines
are stripped from `text`, because a narrated call must never reach a user as
prose.

Inert unless you use tools: parsing is skipped when no `tools` are supplied — a
model does not narrate a call it was never offered. No consumer passes `tools`
to complete() today, so this changes behaviour for nobody and unblocks the one
that needs it. `toolProtocol: "native"` opts out for a caller that parses the
lines itself and would otherwise execute each call twice.

Ordering matters: after stripping, a reply that was ONLY a narrated call has
empty text. `complete()` treats an empty 200 as a link failure, so tool calls
are counted first or a working model gets demoted off the chain.

DETAILS WORTH THE TESTS

- The closed set comes from the `tools` array the caller already passed. Two
  lists that must agree are one list that cannot disagree, and the split version
  fails silently — a missing name makes the parser ignore a real call.
- The JSON walker is string-aware. Naive brace counting closes at the `}` inside
  `{"q": "a } b"}` and the arguments vanish.
- Unparseable stays null, distinct from `{}`. Returning `{}` satisfies a
  caller's `?? {}` and silently drops arguments the model put on the next line —
  exactly what a ```json fence after ARGS: produces.
- Every tolerated shape (markdown bolding, list bullets, `=`, copied parens,
  fenced or multi-line ARGS, a missing ARGS line) is one a small model actually
  emitted. Rejecting any is a turn failed over formatting.
- `TEXT_TOOL_PROTOCOL_HINT` ships the prompt wording beside the parser that has
  to read it back. A prompt and its parser are one contract.

232 tests, up from 211.

Co-authored-by: Cato <georgy.butaev@revamp-it.ch>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-12 01:59:27 -07:00

112 lines
2.7 KiB
JSON

{
"name": "@bitbaum/ai-kit",
"version": "1.4.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"
},
"./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.4.1",
"eslint": "^10.9.1",
"globals": "^17.12.0",
"prettier": "3.9.6",
"typescript": "^6.0.3",
"typescript-eslint": "^8.69.0"
},
"dependencies": {
"ai-forms": "^0.1.2"
},
"peerDependencies": {
"react": ">=18"
},
"peerDependenciesMeta": {
"react": {
"optional": true
}
}
}