@bitbaum/ai-kit 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/complete.d.ts +13 -0
- package/dist/complete.js +9 -1
- package/package.json +1 -1
- package/src/complete.ts +22 -1
package/dist/complete.d.ts
CHANGED
|
@@ -141,6 +141,19 @@ export interface CompleteOptions {
|
|
|
141
141
|
tools?: unknown[];
|
|
142
142
|
/** Extra body fields for a vendor-specific parameter. Merged last, so it can override. */
|
|
143
143
|
extraBody?: Record<string, unknown>;
|
|
144
|
+
/**
|
|
145
|
+
* Extra request headers. Merged last, so a caller can override `content-type`
|
|
146
|
+
* — but NOT `authorization`, which stays the key this module resolved.
|
|
147
|
+
*
|
|
148
|
+
* Vendors ask for these and quietly change behaviour without them:
|
|
149
|
+
* OpenRouter reads `HTTP-Referer` and `X-Title` for app attribution in its
|
|
150
|
+
* public rankings, and an app that stops sending them simply disappears from
|
|
151
|
+
* that list with no error anywhere. Without this option, adopting `complete`
|
|
152
|
+
* would mean silently dropping them, which is exactly the kind of small,
|
|
153
|
+
* invisible regression that makes a shared engine feel worse than the
|
|
154
|
+
* hand-rolled client it replaced.
|
|
155
|
+
*/
|
|
156
|
+
extraHeaders?: Record<string, string>;
|
|
144
157
|
/** Called on each link's failure before moving on — e.g. to log which id rotted. */
|
|
145
158
|
onLinkFailure?: (link: Link, error: Error) => void;
|
|
146
159
|
/** Injected for tests. Defaults to global `fetch`. */
|
package/dist/complete.js
CHANGED
|
@@ -191,7 +191,15 @@ async function callLink(link, options, key) {
|
|
|
191
191
|
try {
|
|
192
192
|
res = await doFetch(`${link.provider.baseUrl}/chat/completions`, {
|
|
193
193
|
method: "POST",
|
|
194
|
-
headers: {
|
|
194
|
+
headers: {
|
|
195
|
+
"content-type": "application/json",
|
|
196
|
+
...options.extraHeaders,
|
|
197
|
+
// Last on purpose. A caller may add or override any header it likes,
|
|
198
|
+
// but not this one: silently sending someone else's credential — or
|
|
199
|
+
// none — would turn a typo in a caller's header map into an auth
|
|
200
|
+
// failure blamed on the vendor.
|
|
201
|
+
authorization: `Bearer ${key}`,
|
|
202
|
+
},
|
|
195
203
|
body: JSON.stringify(body),
|
|
196
204
|
signal: deadline.signal,
|
|
197
205
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitbaum/ai-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "One install for the AI layer of an app: which model to call, what to do when the vendor retires it, how to walk the fallback chain and know when none of it worked, how to read the three kinds of 429, a fair daily budget across users, headless AI form filling — and now the model registry (one SSOT for every callable id, with the paid/free boundary as a field) and the grounding harness (facts, contract, deterministic fabrication check).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mao Nakamoto",
|
package/src/complete.ts
CHANGED
|
@@ -146,6 +146,19 @@ export interface CompleteOptions {
|
|
|
146
146
|
tools?: unknown[];
|
|
147
147
|
/** Extra body fields for a vendor-specific parameter. Merged last, so it can override. */
|
|
148
148
|
extraBody?: Record<string, unknown>;
|
|
149
|
+
/**
|
|
150
|
+
* Extra request headers. Merged last, so a caller can override `content-type`
|
|
151
|
+
* — but NOT `authorization`, which stays the key this module resolved.
|
|
152
|
+
*
|
|
153
|
+
* Vendors ask for these and quietly change behaviour without them:
|
|
154
|
+
* OpenRouter reads `HTTP-Referer` and `X-Title` for app attribution in its
|
|
155
|
+
* public rankings, and an app that stops sending them simply disappears from
|
|
156
|
+
* that list with no error anywhere. Without this option, adopting `complete`
|
|
157
|
+
* would mean silently dropping them, which is exactly the kind of small,
|
|
158
|
+
* invisible regression that makes a shared engine feel worse than the
|
|
159
|
+
* hand-rolled client it replaced.
|
|
160
|
+
*/
|
|
161
|
+
extraHeaders?: Record<string, string>;
|
|
149
162
|
/** Called on each link's failure before moving on — e.g. to log which id rotted. */
|
|
150
163
|
onLinkFailure?: (link: Link, error: Error) => void;
|
|
151
164
|
/** Injected for tests. Defaults to global `fetch`. */
|
|
@@ -322,7 +335,15 @@ async function callLink(
|
|
|
322
335
|
try {
|
|
323
336
|
res = await doFetch(`${link.provider.baseUrl}/chat/completions`, {
|
|
324
337
|
method: "POST",
|
|
325
|
-
headers: {
|
|
338
|
+
headers: {
|
|
339
|
+
"content-type": "application/json",
|
|
340
|
+
...options.extraHeaders,
|
|
341
|
+
// Last on purpose. A caller may add or override any header it likes,
|
|
342
|
+
// but not this one: silently sending someone else's credential — or
|
|
343
|
+
// none — would turn a typo in a caller's header map into an auth
|
|
344
|
+
// failure blamed on the vendor.
|
|
345
|
+
authorization: `Bearer ${key}`,
|
|
346
|
+
},
|
|
326
347
|
body: JSON.stringify(body),
|
|
327
348
|
signal: deadline.signal,
|
|
328
349
|
});
|