@broberg/ai-sdk 0.54.2 → 0.55.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/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.54.2";
2943
- declare const SDK_TAG: "@broberg/ai-sdk@0.54.2";
2953
+ declare const VERSION: "0.55.0";
2954
+ declare const SDK_TAG: "@broberg/ai-sdk@0.55.0";
2944
2955
 
2945
2956
  /** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
2946
2957
  * per-call override.
package/dist/index.js CHANGED
@@ -652,6 +652,7 @@ function mapAnthropicStop(reason) {
652
652
  }
653
653
 
654
654
  // src/providers/openai-compatible.ts
655
+ var REASONS_BY_DEFAULT = /* @__PURE__ */ new Set(["mistral-large-4", "mistral-large-4-0"]);
655
656
  function autoCacheKey(messages) {
656
657
  const system = messages.find((m) => m.role === "system");
657
658
  if (!system || typeof system.content !== "string" || system.content.length < 200) return void 0;
@@ -759,6 +760,11 @@ function buildChatBody(req, config) {
759
760
  if (req.maxTokens !== void 0) body.max_tokens = req.maxTokens;
760
761
  if (req.temperature !== void 0) body.temperature = req.temperature;
761
762
  if (req.responseFormat === "json") body.response_format = { type: "json_object" };
763
+ if (req.reasoningEffort !== void 0 && !config.supportsReasoningEffort) {
764
+ throw new Error(`${config.name} adapter: reasoningEffort is a Mistral option and is not supported here`);
765
+ }
766
+ const effort = req.reasoningEffort ?? (config.supportsReasoningEffort && REASONS_BY_DEFAULT.has(req.spec.model) ? "none" : void 0);
767
+ if (effort !== void 0) body.reasoning_effort = effort;
762
768
  if (config.supportsPromptCacheKey && req.promptCache !== false) {
763
769
  const k = req.promptCacheKey ?? autoCacheKey(req.messages);
764
770
  if (k !== void 0) body.prompt_cache_key = k;
@@ -1380,7 +1386,7 @@ function deepseekAdapter(config = {}) {
1380
1386
  // src/providers/mistral.ts
1381
1387
  function mistralAdapter(config = {}) {
1382
1388
  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 });
1389
+ const base = makeOpenAICompatibleAdapter({ name: "mistral", baseUrl, apiKey: config.apiKey, fetch: config.fetch, supportsPromptCacheKey: true, supportsPrefix: true, supportsReasoningEffort: true });
1384
1390
  function key() {
1385
1391
  const k = config.apiKey ?? process.env.MISTRAL_API_KEY;
1386
1392
  if (!k) throw new Error("mistral adapter: API key not set (env MISTRAL_API_KEY)");
@@ -3314,6 +3320,9 @@ var chatInputSchema = z.object({
3314
3320
  tools: z.array(toolSchema).optional(),
3315
3321
  maxTokens: z.number().int().positive().optional(),
3316
3322
  temperature: z.number().min(0).max(2).optional(),
3323
+ /** F074.3 — Mistral reasoning ("thinking") before the answer. Large 4 thinks by
3324
+ * default; the SDK sends "none" for it unless you ask for "high". Mistral only. */
3325
+ reasoningEffort: z.enum(["none", "high"]).optional(),
3317
3326
  /** "json" requests JSON-object output (OpenAI-compatible response_format). */
3318
3327
  responseFormat: z.enum(["json", "text"]).optional(),
3319
3328
  ...callOptions
@@ -3530,8 +3539,8 @@ var aiConfigSchema = z.object({
3530
3539
  import { randomUUID } from "crypto";
3531
3540
 
3532
3541
  // src/version.ts
3533
- var VERSION = "0.54.2";
3534
- var SDK_TAG = "@broberg/ai-sdk@0.54.2";
3542
+ var VERSION = "0.55.0";
3543
+ var SDK_TAG = "@broberg/ai-sdk@0.55.0";
3535
3544
 
3536
3545
  // src/cost/sinks/upmetrics.ts
3537
3546
  function isRetryableStatus(status) {
@@ -4060,6 +4069,7 @@ function createAI(config = {}) {
4060
4069
  tools: input.tools,
4061
4070
  maxTokens: input.maxTokens,
4062
4071
  temperature: input.temperature,
4072
+ reasoningEffort: input.reasoningEffort,
4063
4073
  responseFormat: input.responseFormat,
4064
4074
  // F043: these two were dropped here, so a streamed call could not cache even
4065
4075
  // after the adapter learned how. A chat UI streams every turn and repeats the
@@ -4121,7 +4131,7 @@ function createAI(config = {}) {
4121
4131
  invoke: async (spec) => {
4122
4132
  const adapter = pickProvider(spec.provider);
4123
4133
  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 });
4134
+ 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
4135
  }
4126
4136
  });
4127
4137
  },