@ai-sdk/anthropic 2.0.0-canary.4 → 2.0.0-canary.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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 2.0.0-canary.6
4
+
5
+ ### Patch Changes
6
+
7
+ - f10304b: feat(tool-calling): don't require the user to have to pass parameters
8
+ - Updated dependencies [411e483]
9
+ - Updated dependencies [79457bd]
10
+ - Updated dependencies [ad80501]
11
+ - Updated dependencies [1766ede]
12
+ - Updated dependencies [f10304b]
13
+ - @ai-sdk/provider@2.0.0-canary.5
14
+ - @ai-sdk/provider-utils@3.0.0-canary.6
15
+
16
+ ## 2.0.0-canary.5
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [6f6bb89]
21
+ - @ai-sdk/provider@2.0.0-canary.4
22
+ - @ai-sdk/provider-utils@3.0.0-canary.5
23
+
3
24
  ## 2.0.0-canary.4
4
25
 
5
26
  ### Patch Changes
package/dist/index.js CHANGED
@@ -27,11 +27,11 @@ module.exports = __toCommonJS(src_exports);
27
27
 
28
28
  // src/anthropic-provider.ts
29
29
  var import_provider4 = require("@ai-sdk/provider");
30
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
30
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/anthropic-messages-language-model.ts
33
33
  var import_provider3 = require("@ai-sdk/provider");
34
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
34
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
35
35
  var import_zod2 = require("zod");
36
36
 
37
37
  // src/anthropic-error.ts
@@ -175,6 +175,7 @@ function prepareTools({
175
175
 
176
176
  // src/convert-to-anthropic-messages-prompt.ts
177
177
  var import_provider2 = require("@ai-sdk/provider");
178
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
178
179
  function convertToAnthropicMessagesPrompt({
179
180
  prompt,
180
181
  sendReasoning,
@@ -238,7 +239,7 @@ function convertToAnthropicMessagesPrompt({
238
239
  } : {
239
240
  type: "base64",
240
241
  media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
241
- data: part.data
242
+ data: (0, import_provider_utils2.convertToBase64)(part.data)
242
243
  },
243
244
  cache_control: cacheControl
244
245
  });
@@ -252,7 +253,7 @@ function convertToAnthropicMessagesPrompt({
252
253
  } : {
253
254
  type: "base64",
254
255
  media_type: "application/pdf",
255
- data: part.data
256
+ data: (0, import_provider_utils2.convertToBase64)(part.data)
256
257
  },
257
258
  cache_control: cacheControl
258
259
  });
@@ -469,7 +470,7 @@ var AnthropicMessagesLanguageModel = class {
469
470
  }
470
471
  async getArgs({
471
472
  prompt,
472
- maxTokens = 4096,
473
+ maxOutputTokens = 4096,
473
474
  // 4096: max model output tokens TODO update default in v5
474
475
  temperature,
475
476
  topP,
@@ -515,7 +516,7 @@ var AnthropicMessagesLanguageModel = class {
515
516
  sendReasoning: (_a = this.settings.sendReasoning) != null ? _a : true,
516
517
  warnings
517
518
  });
518
- const anthropicOptions = (0, import_provider_utils2.parseProviderOptions)({
519
+ const anthropicOptions = (0, import_provider_utils3.parseProviderOptions)({
519
520
  provider: "anthropic",
520
521
  providerOptions,
521
522
  schema: anthropicProviderOptionsSchema
@@ -526,7 +527,7 @@ var AnthropicMessagesLanguageModel = class {
526
527
  // model id:
527
528
  model: this.modelId,
528
529
  // standardized settings:
529
- max_tokens: maxTokens,
530
+ max_tokens: maxOutputTokens,
530
531
  temperature,
531
532
  top_k: topK,
532
533
  top_p: topP,
@@ -569,7 +570,7 @@ var AnthropicMessagesLanguageModel = class {
569
570
  details: "topP is not supported when thinking is enabled"
570
571
  });
571
572
  }
572
- baseArgs.max_tokens = maxTokens + thinkingBudget;
573
+ baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
573
574
  }
574
575
  const {
575
576
  tools: anthropicTools2,
@@ -591,8 +592,8 @@ var AnthropicMessagesLanguageModel = class {
591
592
  betas,
592
593
  headers
593
594
  }) {
594
- return (0, import_provider_utils2.combineHeaders)(
595
- await (0, import_provider_utils2.resolve)(this.config.headers),
595
+ return (0, import_provider_utils3.combineHeaders)(
596
+ await (0, import_provider_utils3.resolve)(this.config.headers),
596
597
  betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
597
598
  headers
598
599
  );
@@ -612,12 +613,12 @@ var AnthropicMessagesLanguageModel = class {
612
613
  responseHeaders,
613
614
  value: response,
614
615
  rawValue: rawResponse
615
- } = await (0, import_provider_utils2.postJsonToApi)({
616
+ } = await (0, import_provider_utils3.postJsonToApi)({
616
617
  url: this.buildRequestUrl(false),
617
618
  headers: await this.getHeaders({ betas, headers: options.headers }),
618
619
  body: this.transformRequestBody(args),
619
620
  failedResponseHandler: anthropicFailedResponseHandler,
620
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
621
+ successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
621
622
  anthropicMessagesResponseSchema
622
623
  ),
623
624
  abortSignal: options.abortSignal,
@@ -662,10 +663,10 @@ var AnthropicMessagesLanguageModel = class {
662
663
  toolCalls,
663
664
  finishReason: mapAnthropicStopReason(response.stop_reason),
664
665
  usage: {
665
- promptTokens: response.usage.input_tokens,
666
- completionTokens: response.usage.output_tokens
666
+ inputTokens: response.usage.input_tokens,
667
+ outputTokens: response.usage.output_tokens
667
668
  },
668
- rawCall: { rawPrompt, rawSettings },
669
+ request: { body: args },
669
670
  response: {
670
671
  id: (_a = response.id) != null ? _a : void 0,
671
672
  modelId: (_b = response.model) != null ? _b : void 0,
@@ -678,29 +679,27 @@ var AnthropicMessagesLanguageModel = class {
678
679
  cacheCreationInputTokens: (_c = response.usage.cache_creation_input_tokens) != null ? _c : null,
679
680
  cacheReadInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : null
680
681
  }
681
- },
682
- request: { body: JSON.stringify(args) }
682
+ }
683
683
  };
684
684
  }
685
685
  async doStream(options) {
686
686
  const { args, warnings, betas } = await this.getArgs(options);
687
687
  const body = { ...args, stream: true };
688
- const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
688
+ const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
689
689
  url: this.buildRequestUrl(true),
690
690
  headers: await this.getHeaders({ betas, headers: options.headers }),
691
691
  body: this.transformRequestBody(body),
692
692
  failedResponseHandler: anthropicFailedResponseHandler,
693
- successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(
693
+ successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(
694
694
  anthropicMessagesChunkSchema
695
695
  ),
696
696
  abortSignal: options.abortSignal,
697
697
  fetch: this.config.fetch
698
698
  });
699
- const { messages: rawPrompt, ...rawSettings } = args;
700
699
  let finishReason = "unknown";
701
700
  const usage = {
702
- promptTokens: Number.NaN,
703
- completionTokens: Number.NaN
701
+ inputTokens: void 0,
702
+ outputTokens: void 0
704
703
  };
705
704
  const toolCallContentBlocks = {};
706
705
  let providerMetadata = void 0;
@@ -812,8 +811,8 @@ var AnthropicMessagesLanguageModel = class {
812
811
  }
813
812
  }
814
813
  case "message_start": {
815
- usage.promptTokens = value.message.usage.input_tokens;
816
- usage.completionTokens = value.message.usage.output_tokens;
814
+ usage.inputTokens = value.message.usage.input_tokens;
815
+ usage.outputTokens = value.message.usage.output_tokens;
817
816
  providerMetadata = {
818
817
  anthropic: {
819
818
  cacheCreationInputTokens: (_a = value.message.usage.cache_creation_input_tokens) != null ? _a : null,
@@ -828,7 +827,7 @@ var AnthropicMessagesLanguageModel = class {
828
827
  return;
829
828
  }
830
829
  case "message_delta": {
831
- usage.completionTokens = value.usage.output_tokens;
830
+ usage.outputTokens = value.usage.output_tokens;
832
831
  finishReason = mapAnthropicStopReason(value.delta.stop_reason);
833
832
  return;
834
833
  }
@@ -853,10 +852,9 @@ var AnthropicMessagesLanguageModel = class {
853
852
  }
854
853
  })
855
854
  ),
856
- rawCall: { rawPrompt, rawSettings },
855
+ request: { body },
857
856
  response: { headers: responseHeaders },
858
- warnings,
859
- request: { body: JSON.stringify(body) }
857
+ warnings
860
858
  };
861
859
  }
862
860
  };
@@ -1134,10 +1132,10 @@ var anthropicTools = {
1134
1132
  // src/anthropic-provider.ts
1135
1133
  function createAnthropic(options = {}) {
1136
1134
  var _a;
1137
- const baseURL = (_a = (0, import_provider_utils3.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
1135
+ const baseURL = (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
1138
1136
  const getHeaders = () => ({
1139
1137
  "anthropic-version": "2023-06-01",
1140
- "x-api-key": (0, import_provider_utils3.loadApiKey)({
1138
+ "x-api-key": (0, import_provider_utils4.loadApiKey)({
1141
1139
  apiKey: options.apiKey,
1142
1140
  environmentVariableName: "ANTHROPIC_API_KEY",
1143
1141
  description: "Anthropic"