@broberg/ai-sdk 0.54.2 → 0.55.1
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/{chunk-DFTCHTLQ.js → chunk-ZVKHZ4GJ.js} +24 -1
- package/dist/chunk-ZVKHZ4GJ.js.map +1 -0
- package/dist/index.d.ts +23 -2
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/pricing.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-DFTCHTLQ.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -366,6 +366,9 @@ interface ChatRequest {
|
|
|
366
366
|
* exactly the same as a call with no key at all. */
|
|
367
367
|
promptCache?: boolean;
|
|
368
368
|
temperature?: number;
|
|
369
|
+
/** F074.3 — Mistral's `reasoning_effort`. Undefined = the SDK's default: "none" for
|
|
370
|
+
* models that think by default (Large 4), nothing for the rest. */
|
|
371
|
+
reasoningEffort?: "none" | "high";
|
|
369
372
|
/** "json" → request JSON-object output where the provider supports it (F009). */
|
|
370
373
|
responseFormat?: "json" | "text";
|
|
371
374
|
}
|
|
@@ -1175,6 +1178,9 @@ declare const chatInputSchema: z.ZodObject<{
|
|
|
1175
1178
|
}>, "many">>;
|
|
1176
1179
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
1177
1180
|
temperature: z.ZodOptional<z.ZodNumber>;
|
|
1181
|
+
/** F074.3 — Mistral reasoning ("thinking") before the answer. Large 4 thinks by
|
|
1182
|
+
* default; the SDK sends "none" for it unless you ask for "high". Mistral only. */
|
|
1183
|
+
reasoningEffort: z.ZodOptional<z.ZodEnum<["none", "high"]>>;
|
|
1178
1184
|
/** "json" requests JSON-object output (OpenAI-compatible response_format). */
|
|
1179
1185
|
responseFormat: z.ZodOptional<z.ZodEnum<["json", "text"]>>;
|
|
1180
1186
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -1210,6 +1216,7 @@ declare const chatInputSchema: z.ZodObject<{
|
|
|
1210
1216
|
promptCacheKey?: string | undefined;
|
|
1211
1217
|
promptCache?: boolean | undefined;
|
|
1212
1218
|
maxTokens?: number | undefined;
|
|
1219
|
+
reasoningEffort?: "none" | "high" | undefined;
|
|
1213
1220
|
responseFormat?: "text" | "json" | undefined;
|
|
1214
1221
|
override?: {
|
|
1215
1222
|
provider?: string | undefined;
|
|
@@ -1255,6 +1262,7 @@ declare const chatInputSchema: z.ZodObject<{
|
|
|
1255
1262
|
promptCacheKey?: string | undefined;
|
|
1256
1263
|
promptCache?: boolean | undefined;
|
|
1257
1264
|
maxTokens?: number | undefined;
|
|
1265
|
+
reasoningEffort?: "none" | "high" | undefined;
|
|
1258
1266
|
responseFormat?: "text" | "json" | undefined;
|
|
1259
1267
|
override?: {
|
|
1260
1268
|
provider?: string | undefined;
|
|
@@ -2868,6 +2876,9 @@ interface OpenAICompatibleConfig {
|
|
|
2868
2876
|
* AUTOMATICALLY (openai, deepseek, gemini) need no key — they only need their
|
|
2869
2877
|
* cached counts read back, which happens for every provider below. */
|
|
2870
2878
|
supportsPromptCacheKey?: boolean;
|
|
2879
|
+
/** F074.3 — this provider accepts `reasoning_effort` (Mistral). Anywhere else a
|
|
2880
|
+
* reasoningEffort is REFUSED, like `prefix`: a dropped flag reads as obeyed. */
|
|
2881
|
+
supportsReasoningEffort?: boolean;
|
|
2871
2882
|
}
|
|
2872
2883
|
declare function makeOpenAICompatibleAdapter(config: OpenAICompatibleConfig): ProviderAdapter;
|
|
2873
2884
|
|
|
@@ -2939,8 +2950,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
2939
2950
|
* wires the live adapters. */
|
|
2940
2951
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
2941
2952
|
|
|
2942
|
-
declare const VERSION: "0.
|
|
2943
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.
|
|
2953
|
+
declare const VERSION: "0.55.1";
|
|
2954
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.55.1";
|
|
2944
2955
|
|
|
2945
2956
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
2946
2957
|
* per-call override.
|
|
@@ -3319,6 +3330,16 @@ interface PricingEntry {
|
|
|
3319
3330
|
cacheWritePer1M?: number;
|
|
3320
3331
|
/** Pricing snapshot version (date or tag) so stale entries are detectable. */
|
|
3321
3332
|
version: string;
|
|
3333
|
+
/** F075 — a second set of rates for prompts LONGER than `aboveTokens` (input +
|
|
3334
|
+
* cache-read + cache-write). Claude Haiku 5.5 costs 5x above 100k tokens; one row
|
|
3335
|
+
* could only be right for one side of that line. */
|
|
3336
|
+
longPrompt?: {
|
|
3337
|
+
aboveTokens: number;
|
|
3338
|
+
inputPer1M: number;
|
|
3339
|
+
outputPer1M: number;
|
|
3340
|
+
cacheReadPer1M?: number;
|
|
3341
|
+
cacheWritePer1M?: number;
|
|
3342
|
+
};
|
|
3322
3343
|
}
|
|
3323
3344
|
declare function getPrice(provider: string, model: string): PricingEntry | undefined;
|
|
3324
3345
|
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
listMediaPrices,
|
|
22
22
|
pricingFreshness,
|
|
23
23
|
pricingGeneratedAt
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-ZVKHZ4GJ.js";
|
|
25
25
|
|
|
26
26
|
// src/cost/default-hosts.ts
|
|
27
27
|
var DEFAULT_BASE_URLS = {
|
|
@@ -364,8 +364,10 @@ function regionOfProvider(provider) {
|
|
|
364
364
|
|
|
365
365
|
// src/cost/usage.ts
|
|
366
366
|
function computeCost(provider, model, inputTokens, outputTokens, cacheReadTokens = 0, cacheCreationTokens = 0) {
|
|
367
|
-
const
|
|
368
|
-
if (!
|
|
367
|
+
const base = getPrice(provider, model);
|
|
368
|
+
if (!base) return 0;
|
|
369
|
+
const long = base.longPrompt;
|
|
370
|
+
const price = long && inputTokens + cacheReadTokens + cacheCreationTokens > long.aboveTokens ? long : base;
|
|
369
371
|
const perToken = (per1M2) => per1M2 / 1e6;
|
|
370
372
|
const inRate = perToken(price.inputPer1M);
|
|
371
373
|
const outRate = perToken(price.outputPer1M);
|
|
@@ -652,6 +654,7 @@ function mapAnthropicStop(reason) {
|
|
|
652
654
|
}
|
|
653
655
|
|
|
654
656
|
// src/providers/openai-compatible.ts
|
|
657
|
+
var REASONS_BY_DEFAULT = /* @__PURE__ */ new Set(["mistral-large-4", "mistral-large-4-0"]);
|
|
655
658
|
function autoCacheKey(messages) {
|
|
656
659
|
const system = messages.find((m) => m.role === "system");
|
|
657
660
|
if (!system || typeof system.content !== "string" || system.content.length < 200) return void 0;
|
|
@@ -759,6 +762,11 @@ function buildChatBody(req, config) {
|
|
|
759
762
|
if (req.maxTokens !== void 0) body.max_tokens = req.maxTokens;
|
|
760
763
|
if (req.temperature !== void 0) body.temperature = req.temperature;
|
|
761
764
|
if (req.responseFormat === "json") body.response_format = { type: "json_object" };
|
|
765
|
+
if (req.reasoningEffort !== void 0 && !config.supportsReasoningEffort) {
|
|
766
|
+
throw new Error(`${config.name} adapter: reasoningEffort is a Mistral option and is not supported here`);
|
|
767
|
+
}
|
|
768
|
+
const effort = req.reasoningEffort ?? (config.supportsReasoningEffort && REASONS_BY_DEFAULT.has(req.spec.model) ? "none" : void 0);
|
|
769
|
+
if (effort !== void 0) body.reasoning_effort = effort;
|
|
762
770
|
if (config.supportsPromptCacheKey && req.promptCache !== false) {
|
|
763
771
|
const k = req.promptCacheKey ?? autoCacheKey(req.messages);
|
|
764
772
|
if (k !== void 0) body.prompt_cache_key = k;
|
|
@@ -1380,7 +1388,7 @@ function deepseekAdapter(config = {}) {
|
|
|
1380
1388
|
// src/providers/mistral.ts
|
|
1381
1389
|
function mistralAdapter(config = {}) {
|
|
1382
1390
|
const baseUrl = config.baseUrl ?? DEFAULT_BASE_URLS.mistral;
|
|
1383
|
-
const base = makeOpenAICompatibleAdapter({ name: "mistral", baseUrl, apiKey: config.apiKey, fetch: config.fetch, supportsPromptCacheKey: true, supportsPrefix: true });
|
|
1391
|
+
const base = makeOpenAICompatibleAdapter({ name: "mistral", baseUrl, apiKey: config.apiKey, fetch: config.fetch, supportsPromptCacheKey: true, supportsPrefix: true, supportsReasoningEffort: true });
|
|
1384
1392
|
function key() {
|
|
1385
1393
|
const k = config.apiKey ?? process.env.MISTRAL_API_KEY;
|
|
1386
1394
|
if (!k) throw new Error("mistral adapter: API key not set (env MISTRAL_API_KEY)");
|
|
@@ -3314,6 +3322,9 @@ var chatInputSchema = z.object({
|
|
|
3314
3322
|
tools: z.array(toolSchema).optional(),
|
|
3315
3323
|
maxTokens: z.number().int().positive().optional(),
|
|
3316
3324
|
temperature: z.number().min(0).max(2).optional(),
|
|
3325
|
+
/** F074.3 — Mistral reasoning ("thinking") before the answer. Large 4 thinks by
|
|
3326
|
+
* default; the SDK sends "none" for it unless you ask for "high". Mistral only. */
|
|
3327
|
+
reasoningEffort: z.enum(["none", "high"]).optional(),
|
|
3317
3328
|
/** "json" requests JSON-object output (OpenAI-compatible response_format). */
|
|
3318
3329
|
responseFormat: z.enum(["json", "text"]).optional(),
|
|
3319
3330
|
...callOptions
|
|
@@ -3530,8 +3541,8 @@ var aiConfigSchema = z.object({
|
|
|
3530
3541
|
import { randomUUID } from "crypto";
|
|
3531
3542
|
|
|
3532
3543
|
// src/version.ts
|
|
3533
|
-
var VERSION = "0.
|
|
3534
|
-
var SDK_TAG = "@broberg/ai-sdk@0.
|
|
3544
|
+
var VERSION = "0.55.1";
|
|
3545
|
+
var SDK_TAG = "@broberg/ai-sdk@0.55.1";
|
|
3535
3546
|
|
|
3536
3547
|
// src/cost/sinks/upmetrics.ts
|
|
3537
3548
|
function isRetryableStatus(status) {
|
|
@@ -4060,6 +4071,7 @@ function createAI(config = {}) {
|
|
|
4060
4071
|
tools: input.tools,
|
|
4061
4072
|
maxTokens: input.maxTokens,
|
|
4062
4073
|
temperature: input.temperature,
|
|
4074
|
+
reasoningEffort: input.reasoningEffort,
|
|
4063
4075
|
responseFormat: input.responseFormat,
|
|
4064
4076
|
// F043: these two were dropped here, so a streamed call could not cache even
|
|
4065
4077
|
// after the adapter learned how. A chat UI streams every turn and repeats the
|
|
@@ -4121,7 +4133,7 @@ function createAI(config = {}) {
|
|
|
4121
4133
|
invoke: async (spec) => {
|
|
4122
4134
|
const adapter = pickProvider(spec.provider);
|
|
4123
4135
|
if (!adapter.chat) throw new Error(`createAI: provider "${spec.provider}" does not support chat`);
|
|
4124
|
-
return adapter.chat({ messages, spec, tools: input.tools, maxTokens: input.maxTokens, temperature: input.temperature, responseFormat: input.responseFormat, promptCacheKey: input.promptCacheKey, promptCache: input.promptCache ?? cfg.promptCache });
|
|
4136
|
+
return adapter.chat({ messages, spec, tools: input.tools, maxTokens: input.maxTokens, temperature: input.temperature, reasoningEffort: input.reasoningEffort, responseFormat: input.responseFormat, promptCacheKey: input.promptCacheKey, promptCache: input.promptCache ?? cfg.promptCache });
|
|
4125
4137
|
}
|
|
4126
4138
|
});
|
|
4127
4139
|
},
|