@broberg/ai-sdk 0.78.4 → 0.78.6
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/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as Usage, C as CostSink, T as Tier, a as ChatResult, b as ChatStreamEvent, c as TranslateResult, I as ImageResult, A as AnimateResult, d as TrainStyleResult, E as EmbeddingResult, e as TranscribeResult, O as OcrResult, M as ModerationResult, J as JudgeResult, V as VectorizeResult, P as PodcastResult, B as BatchRequestItem, f as TierSpec, g as BatchJob, h as BatchResultItem, i as ProviderAdapter, j as ToolCall, k as Tool, l as Transport, m as Capability, R as Region, n as BudgetConfig, o as BudgetStore } from './registry-
|
|
2
|
-
export { p as AlignedWordTimings, q as AvailabilitySource, r as AvailabilityStatus, s as AzureWordBoundary, t as CallOptions, u as ChatRequest, v as ContentPart, D as DialogueRequest, w as DialogueTurn, x as EmbeddingRequest, y as ImageRequest, z as JudgeAnswer, F as JudgeChoiceAnswer, G as JudgeNoulAnswer, H as JudgeQuestion, K as JudgeScoreAnswer, L as LATEST, N as LatestEntry, Q as LoraWeight, S as Message, W as ModelStatus, X as ModelUnavailableError, Y as ModerationItem, Z as ModerationRequest, _ as OcrPage, $ as OcrRequest, a0 as ResolveOptions, a1 as ResolveResult, a2 as Role, a3 as TierDescription, a4 as TrainStyleRequest, a5 as TranscribeRequest, a6 as TtsRequest, a7 as WordTiming, a8 as alignWordTimings, a9 as classifyRegionName, aa as describeTier, ab as listLatest, ac as listModels, ad as regionOfHost, ae as regionOfProvider, af as resolveLatest, ag as resolveModel } from './registry-
|
|
1
|
+
import { U as Usage, C as CostSink, T as Tier, a as ChatResult, b as ChatStreamEvent, c as TranslateResult, I as ImageResult, A as AnimateResult, d as TrainStyleResult, E as EmbeddingResult, e as TranscribeResult, O as OcrResult, M as ModerationResult, J as JudgeResult, V as VectorizeResult, P as PodcastResult, B as BatchRequestItem, f as TierSpec, g as BatchJob, h as BatchResultItem, i as ProviderAdapter, j as ToolCall, k as Tool, l as Transport, m as Capability, R as Region, n as BudgetConfig, o as BudgetStore } from './registry-UIY_A6GR.js';
|
|
2
|
+
export { p as AlignedWordTimings, q as AvailabilitySource, r as AvailabilityStatus, s as AzureWordBoundary, t as CallOptions, u as ChatRequest, v as ContentPart, D as DialogueRequest, w as DialogueTurn, x as EmbeddingRequest, y as ImageRequest, z as JudgeAnswer, F as JudgeChoiceAnswer, G as JudgeNoulAnswer, H as JudgeQuestion, K as JudgeScoreAnswer, L as LATEST, N as LatestEntry, Q as LoraWeight, S as Message, W as ModelStatus, X as ModelUnavailableError, Y as ModerationItem, Z as ModerationRequest, _ as OcrPage, $ as OcrRequest, a0 as ResolveOptions, a1 as ResolveResult, a2 as Role, a3 as TierDescription, a4 as TrainStyleRequest, a5 as TranscribeRequest, a6 as TtsRequest, a7 as WordTiming, a8 as alignWordTimings, a9 as classifyRegionName, aa as describeTier, ab as listLatest, ac as listModels, ad as regionOfHost, ae as regionOfProvider, af as resolveLatest, ag as resolveModel } from './registry-UIY_A6GR.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export { CheapestQuery, CheapestResult, CheapestRow, DEFAULT_CLIP_SEC, MEDIA_PRICING_CHECKED_AT, MediaPrice, MediaUnit, PRICING_STALE_AFTER_DAYS, PriceKind, PricingFreshness, UnitFreshness, UpstreamStatus, cheapestModels, classifyKind, getMediaPrice, listMediaPrices, pricingFreshness, pricingGeneratedAt } from './pricing.js';
|
|
5
5
|
|
|
@@ -1525,6 +1525,10 @@ interface OpenAICompatibleConfig {
|
|
|
1525
1525
|
/** F074.3 — this provider accepts `reasoning_effort` (Mistral). Anywhere else a
|
|
1526
1526
|
* reasoningEffort is REFUSED, like `prefix`: a dropped flag reads as obeyed. */
|
|
1527
1527
|
supportsReasoningEffort?: boolean;
|
|
1528
|
+
/** F101 — this provider takes reasoning as an OBJECT, `reasoning:{effort}` or
|
|
1529
|
+
* `reasoning:{enabled:false}` (OpenRouter), not Mistral's flat `reasoning_effort`.
|
|
1530
|
+
* A reasoningEffort is mapped onto it instead of being refused. */
|
|
1531
|
+
reasoningObject?: boolean;
|
|
1528
1532
|
}
|
|
1529
1533
|
declare function makeOpenAICompatibleAdapter(config: OpenAICompatibleConfig): ProviderAdapter;
|
|
1530
1534
|
|
|
@@ -1596,8 +1600,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
1596
1600
|
* wires the live adapters. */
|
|
1597
1601
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
1598
1602
|
|
|
1599
|
-
declare const VERSION: "0.78.
|
|
1600
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.78.
|
|
1603
|
+
declare const VERSION: "0.78.6";
|
|
1604
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.78.6";
|
|
1601
1605
|
|
|
1602
1606
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
1603
1607
|
* per-call override.
|
package/dist/index.js
CHANGED
|
@@ -1059,6 +1059,9 @@ function mapAnthropicStop(reason) {
|
|
|
1059
1059
|
|
|
1060
1060
|
// src/providers/openai-compatible.ts
|
|
1061
1061
|
var REASONS_BY_DEFAULT = /* @__PURE__ */ new Set(["mistral-large-4", "mistral-large-4-0"]);
|
|
1062
|
+
function openrouterDefaultReasoning(model) {
|
|
1063
|
+
return model.startsWith("deepseek/deepseek-v4") && model.includes("flash") ? "none" : void 0;
|
|
1064
|
+
}
|
|
1062
1065
|
function autoCacheKey(messages) {
|
|
1063
1066
|
const system = messages.find((m) => m.role === "system");
|
|
1064
1067
|
if (!system || typeof system.content !== "string" || system.content.length < 200) return void 0;
|
|
@@ -1166,11 +1169,17 @@ function buildChatBody(req, config) {
|
|
|
1166
1169
|
if (req.maxTokens !== void 0) body.max_tokens = req.maxTokens;
|
|
1167
1170
|
if (req.temperature !== void 0) body.temperature = req.temperature;
|
|
1168
1171
|
if (req.responseFormat === "json") body.response_format = { type: "json_object" };
|
|
1169
|
-
if (req.reasoningEffort !== void 0 && !config.supportsReasoningEffort) {
|
|
1170
|
-
throw new Error(`${config.name} adapter: reasoningEffort is a Mistral option and is not supported here`);
|
|
1172
|
+
if (req.reasoningEffort !== void 0 && !config.supportsReasoningEffort && !config.reasoningObject) {
|
|
1173
|
+
throw new Error(`${config.name} adapter: reasoningEffort is a Mistral/OpenRouter option and is not supported here`);
|
|
1174
|
+
}
|
|
1175
|
+
if (config.reasoningObject) {
|
|
1176
|
+
const eff = req.reasoningEffort ?? openrouterDefaultReasoning(req.spec.model);
|
|
1177
|
+
if (eff === "none") body.reasoning = { enabled: false };
|
|
1178
|
+
else if (eff !== void 0) body.reasoning = { effort: eff };
|
|
1179
|
+
} else {
|
|
1180
|
+
const effort = req.reasoningEffort ?? (config.supportsReasoningEffort && REASONS_BY_DEFAULT.has(req.spec.model) ? "low" : void 0);
|
|
1181
|
+
if (effort !== void 0) body.reasoning_effort = effort;
|
|
1171
1182
|
}
|
|
1172
|
-
const effort = req.reasoningEffort ?? (config.supportsReasoningEffort && REASONS_BY_DEFAULT.has(req.spec.model) ? "low" : void 0);
|
|
1173
|
-
if (effort !== void 0) body.reasoning_effort = effort;
|
|
1174
1183
|
if (config.supportsPromptCacheKey && req.promptCache !== false) {
|
|
1175
1184
|
const k = req.promptCacheKey ?? autoCacheKey(req.messages);
|
|
1176
1185
|
if (k !== void 0) body.prompt_cache_key = k;
|
|
@@ -1208,6 +1217,11 @@ function makeOpenAICompatibleAdapter(config) {
|
|
|
1208
1217
|
const toolCalls = msg?.tool_calls?.map(
|
|
1209
1218
|
(tc) => fromProviderToolCall(tc, "openai")
|
|
1210
1219
|
);
|
|
1220
|
+
if (text.length === 0 && !(toolCalls && toolCalls.length > 0) && hasReasoning(msg)) {
|
|
1221
|
+
throw new Error(
|
|
1222
|
+
`${config.name} chat: the model spent its whole output budget thinking and returned no answer (${data.usage?.completion_tokens ?? "?"} completion tokens, empty content). Raise maxTokens, or bound the thinking with reasoningEffort ("low" or "none").`
|
|
1223
|
+
);
|
|
1224
|
+
}
|
|
1211
1225
|
const cachedIn = data.usage?.prompt_tokens_details?.cached_tokens;
|
|
1212
1226
|
const usage = freshUsage({
|
|
1213
1227
|
provider: config.name,
|
|
@@ -1266,6 +1280,8 @@ function makeOpenAICompatibleAdapter(config) {
|
|
|
1266
1280
|
});
|
|
1267
1281
|
const toolAcc = /* @__PURE__ */ new Map();
|
|
1268
1282
|
let finishReason = null;
|
|
1283
|
+
let sawReasoning = false;
|
|
1284
|
+
let emittedText = false;
|
|
1269
1285
|
for await (const data of stream) {
|
|
1270
1286
|
let chunk;
|
|
1271
1287
|
try {
|
|
@@ -1276,10 +1292,14 @@ function makeOpenAICompatibleAdapter(config) {
|
|
|
1276
1292
|
const choice = chunk.choices?.[0];
|
|
1277
1293
|
if (choice) {
|
|
1278
1294
|
const delta = choice.delta ?? {};
|
|
1295
|
+
if (hasReasoning(delta)) sawReasoning = true;
|
|
1279
1296
|
const piece = contentToText(delta.content);
|
|
1280
1297
|
if (piece.length > 0) {
|
|
1281
1298
|
const out = stripStreamPrefix(piece);
|
|
1282
|
-
if (out.length > 0)
|
|
1299
|
+
if (out.length > 0) {
|
|
1300
|
+
emittedText = true;
|
|
1301
|
+
yield { type: "text", delta: out };
|
|
1302
|
+
}
|
|
1283
1303
|
}
|
|
1284
1304
|
for (const tc of delta.tool_calls ?? []) {
|
|
1285
1305
|
const idx = tc.index ?? 0;
|
|
@@ -1323,7 +1343,8 @@ function makeOpenAICompatibleAdapter(config) {
|
|
|
1323
1343
|
}
|
|
1324
1344
|
yield { type: "tool_call", id: t.id, name: t.name, args };
|
|
1325
1345
|
}
|
|
1326
|
-
|
|
1346
|
+
const reason = mapFinishReason(finishReason);
|
|
1347
|
+
yield { type: "finish", reason: sawReasoning && !emittedText && toolAcc.size === 0 && reason !== "tool_calls" ? "length" : reason };
|
|
1327
1348
|
}
|
|
1328
1349
|
return {
|
|
1329
1350
|
name: config.name,
|
|
@@ -1344,6 +1365,11 @@ function contentToText(content) {
|
|
|
1344
1365
|
}
|
|
1345
1366
|
return "";
|
|
1346
1367
|
}
|
|
1368
|
+
function hasReasoning(m) {
|
|
1369
|
+
if (!m) return false;
|
|
1370
|
+
if (typeof m.reasoning === "string" && m.reasoning.length > 0) return true;
|
|
1371
|
+
return Array.isArray(m.reasoning_details) && m.reasoning_details.length > 0;
|
|
1372
|
+
}
|
|
1347
1373
|
function mapFinishReason(reason) {
|
|
1348
1374
|
switch (reason) {
|
|
1349
1375
|
case "tool_calls":
|
|
@@ -1743,7 +1769,9 @@ function openrouterAdapter(config = {}) {
|
|
|
1743
1769
|
fetch: config.fetch,
|
|
1744
1770
|
// OpenRouter returns ground-truth usage.cost (USD) when usage:{include:true}
|
|
1745
1771
|
// is set — use it over the local pricing-table estimate (F010).
|
|
1746
|
-
costFromResponseField: true
|
|
1772
|
+
costFromResponseField: true,
|
|
1773
|
+
// F101 — OpenRouter takes reasoning as an object ({effort} / {enabled:false}).
|
|
1774
|
+
reasoningObject: true
|
|
1747
1775
|
});
|
|
1748
1776
|
async function image(req) {
|
|
1749
1777
|
const apiKey = config.apiKey ?? env().OPENROUTER_API_KEY;
|
|
@@ -1867,6 +1895,7 @@ function applyPronunciations(haystack, list, render, escape = (s) => s) {
|
|
|
1867
1895
|
|
|
1868
1896
|
// src/providers/mistral.ts
|
|
1869
1897
|
var MISTRAL_TTS_DEFAULT_MODEL = "voxtral-mini-tts-3-0";
|
|
1898
|
+
var BATCH_RATE = 0.5;
|
|
1870
1899
|
var MISTRAL_TTS_MIME = {
|
|
1871
1900
|
mp3: "audio/mpeg",
|
|
1872
1901
|
wav: "audio/wav",
|
|
@@ -2158,7 +2187,23 @@ function mistralAdapter(config = {}) {
|
|
|
2158
2187
|
const lines = (await content.text()).trim().split("\n").filter(Boolean);
|
|
2159
2188
|
return lines.map((line) => {
|
|
2160
2189
|
const row = JSON.parse(line);
|
|
2161
|
-
|
|
2190
|
+
const body = row.response?.body;
|
|
2191
|
+
const item = { customId: row.custom_id ?? "", text: body?.choices?.[0]?.message?.content ?? "" };
|
|
2192
|
+
if (body?.usage && typeof body.usage.prompt_tokens === "number") {
|
|
2193
|
+
const usage = freshUsage({
|
|
2194
|
+
provider: "mistral",
|
|
2195
|
+
model: body.model ?? req.spec.model,
|
|
2196
|
+
transport: "http",
|
|
2197
|
+
capability: "chat",
|
|
2198
|
+
inputTokens: body.usage.prompt_tokens,
|
|
2199
|
+
outputTokens: body.usage.completion_tokens ?? 0,
|
|
2200
|
+
region: regionOfHost(baseUrl)
|
|
2201
|
+
});
|
|
2202
|
+
usage.costUsd *= BATCH_RATE;
|
|
2203
|
+
usage.batch = true;
|
|
2204
|
+
item.usage = usage;
|
|
2205
|
+
}
|
|
2206
|
+
return item;
|
|
2162
2207
|
});
|
|
2163
2208
|
}
|
|
2164
2209
|
return { ...base, ocr, moderate, embedding, transcribe, tts, image, batchSubmit, batchStatus, batchResults };
|
|
@@ -4592,8 +4637,8 @@ var aiConfigSchema = z.object({
|
|
|
4592
4637
|
import { randomUUID } from "crypto";
|
|
4593
4638
|
|
|
4594
4639
|
// src/version.ts
|
|
4595
|
-
var VERSION = "0.78.
|
|
4596
|
-
var SDK_TAG = "@broberg/ai-sdk@0.78.
|
|
4640
|
+
var VERSION = "0.78.6";
|
|
4641
|
+
var SDK_TAG = "@broberg/ai-sdk@0.78.6";
|
|
4597
4642
|
|
|
4598
4643
|
// src/cost/sinks/upmetrics.ts
|
|
4599
4644
|
function isRetryableStatus(status) {
|