@ai-sdk/anthropic 4.0.7 → 4.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "4.0.7",
3
+ "version": "4.0.9",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -422,6 +422,10 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
422
422
  const thinkingType = anthropicOptions?.thinking?.type;
423
423
  const isThinking =
424
424
  thinkingType === 'enabled' || thinkingType === 'adaptive';
425
+ // `disabled` must still be forwarded to the API: some models (e.g. Sonnet 5)
426
+ // default thinking on, so omitting it would leave thinking enabled and
427
+ // consume the max_tokens budget.
428
+ const sendThinking = isThinking || thinkingType === 'disabled';
425
429
  let thinkingBudget =
426
430
  thinkingType === 'enabled'
427
431
  ? anthropicOptions?.thinking?.budgetTokens
@@ -445,7 +449,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
445
449
  stop_sequences: stopSequences,
446
450
 
447
451
  // provider specific settings:
448
- ...(isThinking && {
452
+ ...(sendThinking && {
449
453
  thinking: {
450
454
  type: thinkingType,
451
455
  ...(thinkingBudget != null && { budget_tokens: thinkingBudget }),
@@ -1,5 +1,7 @@
1
1
  import {
2
2
  UnsupportedFunctionalityError,
3
+ type JSONObject,
4
+ type JSONValue,
3
5
  type SharedV4Warning,
4
6
  type LanguageModelV4Message,
5
7
  type LanguageModelV4Prompt,
@@ -801,7 +803,7 @@ export async function convertToAnthropicPrompt({
801
803
  type: 'tool_use',
802
804
  id: part.toolCallId,
803
805
  name: part.toolName,
804
- input: part.input,
806
+ input: toAnthropicToolInput(part.input),
805
807
  ...(caller && { caller }),
806
808
  cache_control: cacheControl,
807
809
  });
@@ -1327,3 +1329,10 @@ function moveToolUseBlocksToEnd(
1327
1329
 
1328
1330
  return result;
1329
1331
  }
1332
+
1333
+ // wrap invalid tool call input because Anthropic requires it to be an object
1334
+ function toAnthropicToolInput(input: unknown): JSONObject {
1335
+ return typeof input === 'object' && input !== null && !Array.isArray(input)
1336
+ ? (input as JSONObject)
1337
+ : { rawInvalidInput: input as JSONValue };
1338
+ }