@ai-sdk/anthropic 1.2.10 → 2.0.0-alpha.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.
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(internal_exports);
28
28
  // src/anthropic-messages-language-model.ts
29
29
  var import_provider3 = require("@ai-sdk/provider");
30
30
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
31
- var import_zod2 = require("zod");
31
+ var import_zod3 = require("zod");
32
32
 
33
33
  // src/anthropic-error.ts
34
34
  var import_provider_utils = require("@ai-sdk/provider-utils");
@@ -45,15 +45,32 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
45
45
  errorToMessage: (data) => data.error.message
46
46
  });
47
47
 
48
+ // src/anthropic-messages-options.ts
49
+ var import_zod2 = require("zod");
50
+ var anthropicProviderOptions = import_zod2.z.object({
51
+ /**
52
+ Include reasoning content in requests sent to the model. Defaults to `true`.
53
+
54
+ If you are experiencing issues with the model handling requests involving
55
+ */
56
+ sendReasoning: import_zod2.z.boolean().optional(),
57
+ thinking: import_zod2.z.object({
58
+ type: import_zod2.z.union([import_zod2.z.literal("enabled"), import_zod2.z.literal("disabled")]),
59
+ budgetTokens: import_zod2.z.number().optional()
60
+ }).optional()
61
+ });
62
+
48
63
  // src/anthropic-prepare-tools.ts
49
64
  var import_provider = require("@ai-sdk/provider");
50
- function prepareTools(mode) {
51
- var _a;
52
- const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
65
+ function prepareTools({
66
+ tools,
67
+ toolChoice
68
+ }) {
69
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
53
70
  const toolWarnings = [];
54
71
  const betas = /* @__PURE__ */ new Set();
55
72
  if (tools == null) {
56
- return { tools: void 0, tool_choice: void 0, toolWarnings, betas };
73
+ return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
57
74
  }
58
75
  const anthropicTools2 = [];
59
76
  for (const tool of tools) {
@@ -125,11 +142,10 @@ function prepareTools(mode) {
125
142
  break;
126
143
  }
127
144
  }
128
- const toolChoice = mode.toolChoice;
129
145
  if (toolChoice == null) {
130
146
  return {
131
147
  tools: anthropicTools2,
132
- tool_choice: void 0,
148
+ toolChoice: void 0,
133
149
  toolWarnings,
134
150
  betas
135
151
  };
@@ -139,30 +155,30 @@ function prepareTools(mode) {
139
155
  case "auto":
140
156
  return {
141
157
  tools: anthropicTools2,
142
- tool_choice: { type: "auto" },
158
+ toolChoice: { type: "auto" },
143
159
  toolWarnings,
144
160
  betas
145
161
  };
146
162
  case "required":
147
163
  return {
148
164
  tools: anthropicTools2,
149
- tool_choice: { type: "any" },
165
+ toolChoice: { type: "any" },
150
166
  toolWarnings,
151
167
  betas
152
168
  };
153
169
  case "none":
154
- return { tools: void 0, tool_choice: void 0, toolWarnings, betas };
170
+ return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
155
171
  case "tool":
156
172
  return {
157
173
  tools: anthropicTools2,
158
- tool_choice: { type: "tool", name: toolChoice.toolName },
174
+ toolChoice: { type: "tool", name: toolChoice.toolName },
159
175
  toolWarnings,
160
176
  betas
161
177
  };
162
178
  default: {
163
179
  const _exhaustiveCheck = type;
164
180
  throw new import_provider.UnsupportedFunctionalityError({
165
- functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
181
+ functionality: `tool choice type: ${_exhaustiveCheck}`
166
182
  });
167
183
  }
168
184
  }
@@ -171,12 +187,12 @@ function prepareTools(mode) {
171
187
  // src/convert-to-anthropic-messages-prompt.ts
172
188
  var import_provider2 = require("@ai-sdk/provider");
173
189
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
174
- function convertToAnthropicMessagesPrompt({
190
+ async function convertToAnthropicMessagesPrompt({
175
191
  prompt,
176
192
  sendReasoning,
177
193
  warnings
178
194
  }) {
179
- var _a, _b, _c, _d;
195
+ var _a, _b, _c;
180
196
  const betas = /* @__PURE__ */ new Set();
181
197
  const blocks = groupIntoBlocks(prompt);
182
198
  let system = void 0;
@@ -198,10 +214,10 @@ function convertToAnthropicMessagesPrompt({
198
214
  functionality: "Multiple system messages that are separated by user/assistant messages"
199
215
  });
200
216
  }
201
- system = block.messages.map(({ content, providerMetadata }) => ({
217
+ system = block.messages.map(({ content, providerOptions }) => ({
202
218
  type: "text",
203
219
  text: content,
204
- cache_control: getCacheControl(providerMetadata)
220
+ cache_control: getCacheControl(providerOptions)
205
221
  }));
206
222
  break;
207
223
  }
@@ -214,7 +230,7 @@ function convertToAnthropicMessagesPrompt({
214
230
  for (let j = 0; j < content.length; j++) {
215
231
  const part = content[j];
216
232
  const isLastPart = j === content.length - 1;
217
- const cacheControl = (_a = getCacheControl(part.providerMetadata)) != null ? _a : isLastPart ? getCacheControl(message.providerMetadata) : void 0;
233
+ const cacheControl = (_a = getCacheControl(part.providerOptions)) != null ? _a : isLastPart ? getCacheControl(message.providerOptions) : void 0;
218
234
  switch (part.type) {
219
235
  case "text": {
220
236
  anthropicContent.push({
@@ -224,40 +240,39 @@ function convertToAnthropicMessagesPrompt({
224
240
  });
225
241
  break;
226
242
  }
227
- case "image": {
228
- anthropicContent.push({
229
- type: "image",
230
- source: part.image instanceof URL ? {
231
- type: "url",
232
- url: part.image.toString()
233
- } : {
234
- type: "base64",
235
- media_type: (_b = part.mimeType) != null ? _b : "image/jpeg",
236
- data: (0, import_provider_utils2.convertUint8ArrayToBase64)(part.image)
237
- },
238
- cache_control: cacheControl
239
- });
240
- break;
241
- }
242
243
  case "file": {
243
- if (part.mimeType !== "application/pdf") {
244
+ if (part.mediaType.startsWith("image/")) {
245
+ anthropicContent.push({
246
+ type: "image",
247
+ source: part.data instanceof URL ? {
248
+ type: "url",
249
+ url: part.data.toString()
250
+ } : {
251
+ type: "base64",
252
+ media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
253
+ data: (0, import_provider_utils2.convertToBase64)(part.data)
254
+ },
255
+ cache_control: cacheControl
256
+ });
257
+ } else if (part.mediaType === "application/pdf") {
258
+ betas.add("pdfs-2024-09-25");
259
+ anthropicContent.push({
260
+ type: "document",
261
+ source: part.data instanceof URL ? {
262
+ type: "url",
263
+ url: part.data.toString()
264
+ } : {
265
+ type: "base64",
266
+ media_type: "application/pdf",
267
+ data: (0, import_provider_utils2.convertToBase64)(part.data)
268
+ },
269
+ cache_control: cacheControl
270
+ });
271
+ } else {
244
272
  throw new import_provider2.UnsupportedFunctionalityError({
245
- functionality: "Non-PDF files in user messages"
273
+ functionality: `media type: ${part.mediaType}`
246
274
  });
247
275
  }
248
- betas.add("pdfs-2024-09-25");
249
- anthropicContent.push({
250
- type: "document",
251
- source: part.data instanceof URL ? {
252
- type: "url",
253
- url: part.data.toString()
254
- } : {
255
- type: "base64",
256
- media_type: "application/pdf",
257
- data: part.data
258
- },
259
- cache_control: cacheControl
260
- });
261
276
  break;
262
277
  }
263
278
  }
@@ -268,7 +283,7 @@ function convertToAnthropicMessagesPrompt({
268
283
  for (let i2 = 0; i2 < content.length; i2++) {
269
284
  const part = content[i2];
270
285
  const isLastPart = i2 === content.length - 1;
271
- const cacheControl = (_c = getCacheControl(part.providerMetadata)) != null ? _c : isLastPart ? getCacheControl(message.providerMetadata) : void 0;
286
+ const cacheControl = (_b = getCacheControl(part.providerOptions)) != null ? _b : isLastPart ? getCacheControl(message.providerOptions) : void 0;
272
287
  const toolResultContent = part.content != null ? part.content.map((part2) => {
273
288
  var _a2;
274
289
  switch (part2.type) {
@@ -283,7 +298,7 @@ function convertToAnthropicMessagesPrompt({
283
298
  type: "image",
284
299
  source: {
285
300
  type: "base64",
286
- media_type: (_a2 = part2.mimeType) != null ? _a2 : "image/jpeg",
301
+ media_type: (_a2 = part2.mediaType) != null ? _a2 : "image/jpeg",
287
302
  data: part2.data
288
303
  },
289
304
  cache_control: void 0
@@ -318,7 +333,7 @@ function convertToAnthropicMessagesPrompt({
318
333
  for (let k = 0; k < content.length; k++) {
319
334
  const part = content[k];
320
335
  const isLastContentPart = k === content.length - 1;
321
- const cacheControl = (_d = getCacheControl(part.providerMetadata)) != null ? _d : isLastContentPart ? getCacheControl(message.providerMetadata) : void 0;
336
+ const cacheControl = (_c = getCacheControl(part.providerOptions)) != null ? _c : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
322
337
  switch (part.type) {
323
338
  case "text": {
324
339
  anthropicContent.push({
@@ -335,12 +350,37 @@ function convertToAnthropicMessagesPrompt({
335
350
  }
336
351
  case "reasoning": {
337
352
  if (sendReasoning) {
338
- anthropicContent.push({
339
- type: "thinking",
340
- thinking: part.text,
341
- signature: part.signature,
342
- cache_control: cacheControl
353
+ const reasoningMetadata = await (0, import_provider_utils2.parseProviderOptions)({
354
+ provider: "anthropic",
355
+ providerOptions: part.providerOptions,
356
+ schema: anthropicReasoningMetadataSchema
343
357
  });
358
+ if (reasoningMetadata != null) {
359
+ if (reasoningMetadata.signature != null) {
360
+ anthropicContent.push({
361
+ type: "thinking",
362
+ thinking: part.text,
363
+ signature: reasoningMetadata.signature,
364
+ cache_control: cacheControl
365
+ });
366
+ } else if (reasoningMetadata.redactedData != null) {
367
+ anthropicContent.push({
368
+ type: "redacted_thinking",
369
+ data: reasoningMetadata.redactedData,
370
+ cache_control: cacheControl
371
+ });
372
+ } else {
373
+ warnings.push({
374
+ type: "other",
375
+ message: "unsupported reasoning metadata"
376
+ });
377
+ }
378
+ } else {
379
+ warnings.push({
380
+ type: "other",
381
+ message: "unsupported reasoning metadata"
382
+ });
383
+ }
344
384
  } else {
345
385
  warnings.push({
346
386
  type: "other",
@@ -349,14 +389,6 @@ function convertToAnthropicMessagesPrompt({
349
389
  }
350
390
  break;
351
391
  }
352
- case "redacted-reasoning": {
353
- anthropicContent.push({
354
- type: "redacted_thinking",
355
- data: part.data,
356
- cache_control: cacheControl
357
- });
358
- break;
359
- }
360
392
  case "tool-call": {
361
393
  anthropicContent.push({
362
394
  type: "tool_use",
@@ -375,7 +407,7 @@ function convertToAnthropicMessagesPrompt({
375
407
  }
376
408
  default: {
377
409
  const _exhaustiveCheck = type;
378
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
410
+ throw new Error(`content type: ${_exhaustiveCheck}`);
379
411
  }
380
412
  }
381
413
  }
@@ -448,11 +480,9 @@ function mapAnthropicStopReason(finishReason) {
448
480
 
449
481
  // src/anthropic-messages-language-model.ts
450
482
  var AnthropicMessagesLanguageModel = class {
451
- constructor(modelId, settings, config) {
452
- this.specificationVersion = "v1";
453
- this.defaultObjectGenerationMode = "tool";
483
+ constructor(modelId, config) {
484
+ this.specificationVersion = "v2";
454
485
  this.modelId = modelId;
455
- this.settings = settings;
456
486
  this.config = config;
457
487
  }
458
488
  supportsUrl(url) {
@@ -461,13 +491,13 @@ var AnthropicMessagesLanguageModel = class {
461
491
  get provider() {
462
492
  return this.config.provider;
463
493
  }
464
- get supportsImageUrls() {
465
- return this.config.supportsImageUrls;
494
+ get supportedUrls() {
495
+ var _a, _b, _c;
496
+ return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
466
497
  }
467
498
  async getArgs({
468
- mode,
469
499
  prompt,
470
- maxTokens = 4096,
500
+ maxOutputTokens = 4096,
471
501
  // 4096: max model output tokens TODO update default in v5
472
502
  temperature,
473
503
  topP,
@@ -477,10 +507,11 @@ var AnthropicMessagesLanguageModel = class {
477
507
  stopSequences,
478
508
  responseFormat,
479
509
  seed,
480
- providerMetadata: providerOptions
510
+ tools,
511
+ toolChoice,
512
+ providerOptions
481
513
  }) {
482
514
  var _a, _b, _c;
483
- const type = mode.type;
484
515
  const warnings = [];
485
516
  if (frequencyPenalty != null) {
486
517
  warnings.push({
@@ -507,15 +538,15 @@ var AnthropicMessagesLanguageModel = class {
507
538
  details: "JSON response format is not supported."
508
539
  });
509
540
  }
510
- const { prompt: messagesPrompt, betas: messagesBetas } = convertToAnthropicMessagesPrompt({
511
- prompt,
512
- sendReasoning: (_a = this.settings.sendReasoning) != null ? _a : true,
513
- warnings
514
- });
515
- const anthropicOptions = (0, import_provider_utils3.parseProviderOptions)({
541
+ const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
516
542
  provider: "anthropic",
517
543
  providerOptions,
518
- schema: anthropicProviderOptionsSchema
544
+ schema: anthropicProviderOptions
545
+ });
546
+ const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
547
+ prompt,
548
+ sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
549
+ warnings
519
550
  });
520
551
  const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
521
552
  const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
@@ -523,7 +554,7 @@ var AnthropicMessagesLanguageModel = class {
523
554
  // model id:
524
555
  model: this.modelId,
525
556
  // standardized settings:
526
- max_tokens: maxTokens,
557
+ max_tokens: maxOutputTokens,
527
558
  temperature,
528
559
  top_k: topK,
529
560
  top_p: topP,
@@ -566,44 +597,23 @@ var AnthropicMessagesLanguageModel = class {
566
597
  details: "topP is not supported when thinking is enabled"
567
598
  });
568
599
  }
569
- baseArgs.max_tokens = maxTokens + thinkingBudget;
570
- }
571
- switch (type) {
572
- case "regular": {
573
- const {
574
- tools,
575
- tool_choice,
576
- toolWarnings,
577
- betas: toolsBetas
578
- } = prepareTools(mode);
579
- return {
580
- args: { ...baseArgs, tools, tool_choice },
581
- warnings: [...warnings, ...toolWarnings],
582
- betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
583
- };
584
- }
585
- case "object-json": {
586
- throw new import_provider3.UnsupportedFunctionalityError({
587
- functionality: "json-mode object generation"
588
- });
589
- }
590
- case "object-tool": {
591
- const { name, description, parameters } = mode.tool;
592
- return {
593
- args: {
594
- ...baseArgs,
595
- tools: [{ name, description, input_schema: parameters }],
596
- tool_choice: { type: "tool", name }
597
- },
598
- warnings,
599
- betas: messagesBetas
600
- };
601
- }
602
- default: {
603
- const _exhaustiveCheck = type;
604
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
605
- }
600
+ baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
606
601
  }
602
+ const {
603
+ tools: anthropicTools2,
604
+ toolChoice: anthropicToolChoice,
605
+ toolWarnings,
606
+ betas: toolsBetas
607
+ } = prepareTools({ tools, toolChoice });
608
+ return {
609
+ args: {
610
+ ...baseArgs,
611
+ tools: anthropicTools2,
612
+ tool_choice: anthropicToolChoice
613
+ },
614
+ warnings: [...warnings, ...toolWarnings],
615
+ betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
616
+ };
607
617
  }
608
618
  async getHeaders({
609
619
  betas,
@@ -641,65 +651,71 @@ var AnthropicMessagesLanguageModel = class {
641
651
  abortSignal: options.abortSignal,
642
652
  fetch: this.config.fetch
643
653
  });
644
- const { messages: rawPrompt, ...rawSettings } = args;
645
- let text = "";
646
- for (const content of response.content) {
647
- if (content.type === "text") {
648
- text += content.text;
649
- }
650
- }
651
- let toolCalls = void 0;
652
- if (response.content.some((content) => content.type === "tool_use")) {
653
- toolCalls = [];
654
- for (const content of response.content) {
655
- if (content.type === "tool_use") {
656
- toolCalls.push({
654
+ const content = [];
655
+ for (const part of response.content) {
656
+ switch (part.type) {
657
+ case "text": {
658
+ content.push({ type: "text", text: part.text });
659
+ break;
660
+ }
661
+ case "thinking": {
662
+ content.push({
663
+ type: "reasoning",
664
+ text: part.thinking,
665
+ providerMetadata: {
666
+ anthropic: {
667
+ signature: part.signature
668
+ }
669
+ }
670
+ });
671
+ break;
672
+ }
673
+ case "redacted_thinking": {
674
+ content.push({
675
+ type: "reasoning",
676
+ text: "",
677
+ providerMetadata: {
678
+ anthropic: {
679
+ redactedData: part.data
680
+ }
681
+ }
682
+ });
683
+ break;
684
+ }
685
+ case "tool_use": {
686
+ content.push({
687
+ type: "tool-call",
657
688
  toolCallType: "function",
658
- toolCallId: content.id,
659
- toolName: content.name,
660
- args: JSON.stringify(content.input)
689
+ toolCallId: part.id,
690
+ toolName: part.name,
691
+ args: JSON.stringify(part.input)
661
692
  });
693
+ break;
662
694
  }
663
695
  }
664
696
  }
665
- const reasoning = response.content.filter(
666
- (content) => content.type === "redacted_thinking" || content.type === "thinking"
667
- ).map(
668
- (content) => content.type === "thinking" ? {
669
- type: "text",
670
- text: content.thinking,
671
- signature: content.signature
672
- } : {
673
- type: "redacted",
674
- data: content.data
675
- }
676
- );
677
697
  return {
678
- text,
679
- reasoning: reasoning.length > 0 ? reasoning : void 0,
680
- toolCalls,
698
+ content,
681
699
  finishReason: mapAnthropicStopReason(response.stop_reason),
682
700
  usage: {
683
- promptTokens: response.usage.input_tokens,
684
- completionTokens: response.usage.output_tokens
701
+ inputTokens: response.usage.input_tokens,
702
+ outputTokens: response.usage.output_tokens,
703
+ totalTokens: response.usage.input_tokens + response.usage.output_tokens,
704
+ cachedInputTokens: (_a = response.usage.cache_read_input_tokens) != null ? _a : void 0
685
705
  },
686
- rawCall: { rawPrompt, rawSettings },
687
- rawResponse: {
706
+ request: { body: args },
707
+ response: {
708
+ id: (_b = response.id) != null ? _b : void 0,
709
+ modelId: (_c = response.model) != null ? _c : void 0,
688
710
  headers: responseHeaders,
689
711
  body: rawResponse
690
712
  },
691
- response: {
692
- id: (_a = response.id) != null ? _a : void 0,
693
- modelId: (_b = response.model) != null ? _b : void 0
694
- },
695
713
  warnings,
696
714
  providerMetadata: {
697
715
  anthropic: {
698
- cacheCreationInputTokens: (_c = response.usage.cache_creation_input_tokens) != null ? _c : null,
699
- cacheReadInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : null
716
+ cacheCreationInputTokens: (_d = response.usage.cache_creation_input_tokens) != null ? _d : null
700
717
  }
701
- },
702
- request: { body: JSON.stringify(args) }
718
+ }
703
719
  };
704
720
  }
705
721
  async doStream(options) {
@@ -716,11 +732,11 @@ var AnthropicMessagesLanguageModel = class {
716
732
  abortSignal: options.abortSignal,
717
733
  fetch: this.config.fetch
718
734
  });
719
- const { messages: rawPrompt, ...rawSettings } = args;
720
735
  let finishReason = "unknown";
721
736
  const usage = {
722
- promptTokens: Number.NaN,
723
- completionTokens: Number.NaN
737
+ inputTokens: void 0,
738
+ outputTokens: void 0,
739
+ totalTokens: void 0
724
740
  };
725
741
  const toolCallContentBlocks = {};
726
742
  let providerMetadata = void 0;
@@ -728,8 +744,11 @@ var AnthropicMessagesLanguageModel = class {
728
744
  return {
729
745
  stream: response.pipeThrough(
730
746
  new TransformStream({
747
+ start(controller) {
748
+ controller.enqueue({ type: "stream-start", warnings });
749
+ },
731
750
  transform(chunk, controller) {
732
- var _a, _b, _c, _d;
751
+ var _a, _b, _c, _d, _e, _f;
733
752
  if (!chunk.success) {
734
753
  controller.enqueue({ type: "error", error: chunk.error });
735
754
  return;
@@ -749,9 +768,15 @@ var AnthropicMessagesLanguageModel = class {
749
768
  }
750
769
  case "redacted_thinking": {
751
770
  controller.enqueue({
752
- type: "redacted-reasoning",
753
- data: value.content_block.data
771
+ type: "reasoning",
772
+ text: "",
773
+ providerMetadata: {
774
+ anthropic: {
775
+ redactedData: value.content_block.data
776
+ }
777
+ }
754
778
  });
779
+ controller.enqueue({ type: "reasoning-part-finish" });
755
780
  return;
756
781
  }
757
782
  case "tool_use": {
@@ -790,24 +815,30 @@ var AnthropicMessagesLanguageModel = class {
790
815
  switch (deltaType) {
791
816
  case "text_delta": {
792
817
  controller.enqueue({
793
- type: "text-delta",
794
- textDelta: value.delta.text
818
+ type: "text",
819
+ text: value.delta.text
795
820
  });
796
821
  return;
797
822
  }
798
823
  case "thinking_delta": {
799
824
  controller.enqueue({
800
825
  type: "reasoning",
801
- textDelta: value.delta.thinking
826
+ text: value.delta.thinking
802
827
  });
803
828
  return;
804
829
  }
805
830
  case "signature_delta": {
806
831
  if (blockType === "thinking") {
807
832
  controller.enqueue({
808
- type: "reasoning-signature",
809
- signature: value.delta.signature
833
+ type: "reasoning",
834
+ text: "",
835
+ providerMetadata: {
836
+ anthropic: {
837
+ signature: value.delta.signature
838
+ }
839
+ }
810
840
  });
841
+ controller.enqueue({ type: "reasoning-part-finish" });
811
842
  }
812
843
  return;
813
844
  }
@@ -832,12 +863,11 @@ var AnthropicMessagesLanguageModel = class {
832
863
  }
833
864
  }
834
865
  case "message_start": {
835
- usage.promptTokens = value.message.usage.input_tokens;
836
- usage.completionTokens = value.message.usage.output_tokens;
866
+ usage.inputTokens = value.message.usage.input_tokens;
867
+ usage.cachedInputTokens = (_a = value.message.usage.cache_read_input_tokens) != null ? _a : void 0;
837
868
  providerMetadata = {
838
869
  anthropic: {
839
- cacheCreationInputTokens: (_a = value.message.usage.cache_creation_input_tokens) != null ? _a : null,
840
- cacheReadInputTokens: (_b = value.message.usage.cache_read_input_tokens) != null ? _b : null
870
+ cacheCreationInputTokens: (_b = value.message.usage.cache_creation_input_tokens) != null ? _b : null
841
871
  }
842
872
  };
843
873
  controller.enqueue({
@@ -848,7 +878,8 @@ var AnthropicMessagesLanguageModel = class {
848
878
  return;
849
879
  }
850
880
  case "message_delta": {
851
- usage.completionTokens = value.usage.output_tokens;
881
+ usage.outputTokens = value.usage.output_tokens;
882
+ usage.totalTokens = ((_e = usage.inputTokens) != null ? _e : 0) + ((_f = value.usage.output_tokens) != null ? _f : 0);
852
883
  finishReason = mapAnthropicStopReason(value.delta.stop_reason);
853
884
  return;
854
885
  }
@@ -873,142 +904,138 @@ var AnthropicMessagesLanguageModel = class {
873
904
  }
874
905
  })
875
906
  ),
876
- rawCall: { rawPrompt, rawSettings },
877
- rawResponse: { headers: responseHeaders },
878
- warnings,
879
- request: { body: JSON.stringify(body) }
907
+ request: { body },
908
+ response: { headers: responseHeaders }
880
909
  };
881
910
  }
882
911
  };
883
- var anthropicMessagesResponseSchema = import_zod2.z.object({
884
- type: import_zod2.z.literal("message"),
885
- id: import_zod2.z.string().nullish(),
886
- model: import_zod2.z.string().nullish(),
887
- content: import_zod2.z.array(
888
- import_zod2.z.discriminatedUnion("type", [
889
- import_zod2.z.object({
890
- type: import_zod2.z.literal("text"),
891
- text: import_zod2.z.string()
912
+ var anthropicMessagesResponseSchema = import_zod3.z.object({
913
+ type: import_zod3.z.literal("message"),
914
+ id: import_zod3.z.string().nullish(),
915
+ model: import_zod3.z.string().nullish(),
916
+ content: import_zod3.z.array(
917
+ import_zod3.z.discriminatedUnion("type", [
918
+ import_zod3.z.object({
919
+ type: import_zod3.z.literal("text"),
920
+ text: import_zod3.z.string()
892
921
  }),
893
- import_zod2.z.object({
894
- type: import_zod2.z.literal("thinking"),
895
- thinking: import_zod2.z.string(),
896
- signature: import_zod2.z.string()
922
+ import_zod3.z.object({
923
+ type: import_zod3.z.literal("thinking"),
924
+ thinking: import_zod3.z.string(),
925
+ signature: import_zod3.z.string()
897
926
  }),
898
- import_zod2.z.object({
899
- type: import_zod2.z.literal("redacted_thinking"),
900
- data: import_zod2.z.string()
927
+ import_zod3.z.object({
928
+ type: import_zod3.z.literal("redacted_thinking"),
929
+ data: import_zod3.z.string()
901
930
  }),
902
- import_zod2.z.object({
903
- type: import_zod2.z.literal("tool_use"),
904
- id: import_zod2.z.string(),
905
- name: import_zod2.z.string(),
906
- input: import_zod2.z.unknown()
931
+ import_zod3.z.object({
932
+ type: import_zod3.z.literal("tool_use"),
933
+ id: import_zod3.z.string(),
934
+ name: import_zod3.z.string(),
935
+ input: import_zod3.z.unknown()
907
936
  })
908
937
  ])
909
938
  ),
910
- stop_reason: import_zod2.z.string().nullish(),
911
- usage: import_zod2.z.object({
912
- input_tokens: import_zod2.z.number(),
913
- output_tokens: import_zod2.z.number(),
914
- cache_creation_input_tokens: import_zod2.z.number().nullish(),
915
- cache_read_input_tokens: import_zod2.z.number().nullish()
939
+ stop_reason: import_zod3.z.string().nullish(),
940
+ usage: import_zod3.z.object({
941
+ input_tokens: import_zod3.z.number(),
942
+ output_tokens: import_zod3.z.number(),
943
+ cache_creation_input_tokens: import_zod3.z.number().nullish(),
944
+ cache_read_input_tokens: import_zod3.z.number().nullish()
916
945
  })
917
946
  });
918
- var anthropicMessagesChunkSchema = import_zod2.z.discriminatedUnion("type", [
919
- import_zod2.z.object({
920
- type: import_zod2.z.literal("message_start"),
921
- message: import_zod2.z.object({
922
- id: import_zod2.z.string().nullish(),
923
- model: import_zod2.z.string().nullish(),
924
- usage: import_zod2.z.object({
925
- input_tokens: import_zod2.z.number(),
926
- output_tokens: import_zod2.z.number(),
927
- cache_creation_input_tokens: import_zod2.z.number().nullish(),
928
- cache_read_input_tokens: import_zod2.z.number().nullish()
947
+ var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
948
+ import_zod3.z.object({
949
+ type: import_zod3.z.literal("message_start"),
950
+ message: import_zod3.z.object({
951
+ id: import_zod3.z.string().nullish(),
952
+ model: import_zod3.z.string().nullish(),
953
+ usage: import_zod3.z.object({
954
+ input_tokens: import_zod3.z.number(),
955
+ output_tokens: import_zod3.z.number(),
956
+ cache_creation_input_tokens: import_zod3.z.number().nullish(),
957
+ cache_read_input_tokens: import_zod3.z.number().nullish()
929
958
  })
930
959
  })
931
960
  }),
932
- import_zod2.z.object({
933
- type: import_zod2.z.literal("content_block_start"),
934
- index: import_zod2.z.number(),
935
- content_block: import_zod2.z.discriminatedUnion("type", [
936
- import_zod2.z.object({
937
- type: import_zod2.z.literal("text"),
938
- text: import_zod2.z.string()
961
+ import_zod3.z.object({
962
+ type: import_zod3.z.literal("content_block_start"),
963
+ index: import_zod3.z.number(),
964
+ content_block: import_zod3.z.discriminatedUnion("type", [
965
+ import_zod3.z.object({
966
+ type: import_zod3.z.literal("text"),
967
+ text: import_zod3.z.string()
939
968
  }),
940
- import_zod2.z.object({
941
- type: import_zod2.z.literal("thinking"),
942
- thinking: import_zod2.z.string()
969
+ import_zod3.z.object({
970
+ type: import_zod3.z.literal("thinking"),
971
+ thinking: import_zod3.z.string()
943
972
  }),
944
- import_zod2.z.object({
945
- type: import_zod2.z.literal("tool_use"),
946
- id: import_zod2.z.string(),
947
- name: import_zod2.z.string()
973
+ import_zod3.z.object({
974
+ type: import_zod3.z.literal("tool_use"),
975
+ id: import_zod3.z.string(),
976
+ name: import_zod3.z.string()
948
977
  }),
949
- import_zod2.z.object({
950
- type: import_zod2.z.literal("redacted_thinking"),
951
- data: import_zod2.z.string()
978
+ import_zod3.z.object({
979
+ type: import_zod3.z.literal("redacted_thinking"),
980
+ data: import_zod3.z.string()
952
981
  })
953
982
  ])
954
983
  }),
955
- import_zod2.z.object({
956
- type: import_zod2.z.literal("content_block_delta"),
957
- index: import_zod2.z.number(),
958
- delta: import_zod2.z.discriminatedUnion("type", [
959
- import_zod2.z.object({
960
- type: import_zod2.z.literal("input_json_delta"),
961
- partial_json: import_zod2.z.string()
984
+ import_zod3.z.object({
985
+ type: import_zod3.z.literal("content_block_delta"),
986
+ index: import_zod3.z.number(),
987
+ delta: import_zod3.z.discriminatedUnion("type", [
988
+ import_zod3.z.object({
989
+ type: import_zod3.z.literal("input_json_delta"),
990
+ partial_json: import_zod3.z.string()
962
991
  }),
963
- import_zod2.z.object({
964
- type: import_zod2.z.literal("text_delta"),
965
- text: import_zod2.z.string()
992
+ import_zod3.z.object({
993
+ type: import_zod3.z.literal("text_delta"),
994
+ text: import_zod3.z.string()
966
995
  }),
967
- import_zod2.z.object({
968
- type: import_zod2.z.literal("thinking_delta"),
969
- thinking: import_zod2.z.string()
996
+ import_zod3.z.object({
997
+ type: import_zod3.z.literal("thinking_delta"),
998
+ thinking: import_zod3.z.string()
970
999
  }),
971
- import_zod2.z.object({
972
- type: import_zod2.z.literal("signature_delta"),
973
- signature: import_zod2.z.string()
1000
+ import_zod3.z.object({
1001
+ type: import_zod3.z.literal("signature_delta"),
1002
+ signature: import_zod3.z.string()
974
1003
  })
975
1004
  ])
976
1005
  }),
977
- import_zod2.z.object({
978
- type: import_zod2.z.literal("content_block_stop"),
979
- index: import_zod2.z.number()
1006
+ import_zod3.z.object({
1007
+ type: import_zod3.z.literal("content_block_stop"),
1008
+ index: import_zod3.z.number()
980
1009
  }),
981
- import_zod2.z.object({
982
- type: import_zod2.z.literal("error"),
983
- error: import_zod2.z.object({
984
- type: import_zod2.z.string(),
985
- message: import_zod2.z.string()
1010
+ import_zod3.z.object({
1011
+ type: import_zod3.z.literal("error"),
1012
+ error: import_zod3.z.object({
1013
+ type: import_zod3.z.string(),
1014
+ message: import_zod3.z.string()
986
1015
  })
987
1016
  }),
988
- import_zod2.z.object({
989
- type: import_zod2.z.literal("message_delta"),
990
- delta: import_zod2.z.object({ stop_reason: import_zod2.z.string().nullish() }),
991
- usage: import_zod2.z.object({ output_tokens: import_zod2.z.number() })
1017
+ import_zod3.z.object({
1018
+ type: import_zod3.z.literal("message_delta"),
1019
+ delta: import_zod3.z.object({ stop_reason: import_zod3.z.string().nullish() }),
1020
+ usage: import_zod3.z.object({ output_tokens: import_zod3.z.number() })
992
1021
  }),
993
- import_zod2.z.object({
994
- type: import_zod2.z.literal("message_stop")
1022
+ import_zod3.z.object({
1023
+ type: import_zod3.z.literal("message_stop")
995
1024
  }),
996
- import_zod2.z.object({
997
- type: import_zod2.z.literal("ping")
1025
+ import_zod3.z.object({
1026
+ type: import_zod3.z.literal("ping")
998
1027
  })
999
1028
  ]);
1000
- var anthropicProviderOptionsSchema = import_zod2.z.object({
1001
- thinking: import_zod2.z.object({
1002
- type: import_zod2.z.union([import_zod2.z.literal("enabled"), import_zod2.z.literal("disabled")]),
1003
- budgetTokens: import_zod2.z.number().optional()
1004
- }).optional()
1029
+ var anthropicReasoningMetadataSchema = import_zod3.z.object({
1030
+ signature: import_zod3.z.string().optional(),
1031
+ redactedData: import_zod3.z.string().optional()
1005
1032
  });
1006
1033
 
1007
1034
  // src/anthropic-tools.ts
1008
- var import_zod3 = require("zod");
1009
- var Bash20241022Parameters = import_zod3.z.object({
1010
- command: import_zod3.z.string(),
1011
- restart: import_zod3.z.boolean().optional()
1035
+ var import_zod4 = require("zod");
1036
+ var Bash20241022Parameters = import_zod4.z.object({
1037
+ command: import_zod4.z.string(),
1038
+ restart: import_zod4.z.boolean().optional()
1012
1039
  });
1013
1040
  function bashTool_20241022(options = {}) {
1014
1041
  return {
@@ -1020,9 +1047,9 @@ function bashTool_20241022(options = {}) {
1020
1047
  experimental_toToolResultContent: options.experimental_toToolResultContent
1021
1048
  };
1022
1049
  }
1023
- var Bash20250124Parameters = import_zod3.z.object({
1024
- command: import_zod3.z.string(),
1025
- restart: import_zod3.z.boolean().optional()
1050
+ var Bash20250124Parameters = import_zod4.z.object({
1051
+ command: import_zod4.z.string(),
1052
+ restart: import_zod4.z.boolean().optional()
1026
1053
  });
1027
1054
  function bashTool_20250124(options = {}) {
1028
1055
  return {
@@ -1034,14 +1061,14 @@ function bashTool_20250124(options = {}) {
1034
1061
  experimental_toToolResultContent: options.experimental_toToolResultContent
1035
1062
  };
1036
1063
  }
1037
- var TextEditor20241022Parameters = import_zod3.z.object({
1038
- command: import_zod3.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1039
- path: import_zod3.z.string(),
1040
- file_text: import_zod3.z.string().optional(),
1041
- insert_line: import_zod3.z.number().int().optional(),
1042
- new_str: import_zod3.z.string().optional(),
1043
- old_str: import_zod3.z.string().optional(),
1044
- view_range: import_zod3.z.array(import_zod3.z.number().int()).optional()
1064
+ var TextEditor20241022Parameters = import_zod4.z.object({
1065
+ command: import_zod4.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1066
+ path: import_zod4.z.string(),
1067
+ file_text: import_zod4.z.string().optional(),
1068
+ insert_line: import_zod4.z.number().int().optional(),
1069
+ new_str: import_zod4.z.string().optional(),
1070
+ old_str: import_zod4.z.string().optional(),
1071
+ view_range: import_zod4.z.array(import_zod4.z.number().int()).optional()
1045
1072
  });
1046
1073
  function textEditorTool_20241022(options = {}) {
1047
1074
  return {
@@ -1053,14 +1080,14 @@ function textEditorTool_20241022(options = {}) {
1053
1080
  experimental_toToolResultContent: options.experimental_toToolResultContent
1054
1081
  };
1055
1082
  }
1056
- var TextEditor20250124Parameters = import_zod3.z.object({
1057
- command: import_zod3.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1058
- path: import_zod3.z.string(),
1059
- file_text: import_zod3.z.string().optional(),
1060
- insert_line: import_zod3.z.number().int().optional(),
1061
- new_str: import_zod3.z.string().optional(),
1062
- old_str: import_zod3.z.string().optional(),
1063
- view_range: import_zod3.z.array(import_zod3.z.number().int()).optional()
1083
+ var TextEditor20250124Parameters = import_zod4.z.object({
1084
+ command: import_zod4.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1085
+ path: import_zod4.z.string(),
1086
+ file_text: import_zod4.z.string().optional(),
1087
+ insert_line: import_zod4.z.number().int().optional(),
1088
+ new_str: import_zod4.z.string().optional(),
1089
+ old_str: import_zod4.z.string().optional(),
1090
+ view_range: import_zod4.z.array(import_zod4.z.number().int()).optional()
1064
1091
  });
1065
1092
  function textEditorTool_20250124(options = {}) {
1066
1093
  return {
@@ -1072,8 +1099,8 @@ function textEditorTool_20250124(options = {}) {
1072
1099
  experimental_toToolResultContent: options.experimental_toToolResultContent
1073
1100
  };
1074
1101
  }
1075
- var Computer20241022Parameters = import_zod3.z.object({
1076
- action: import_zod3.z.enum([
1102
+ var Computer20241022Parameters = import_zod4.z.object({
1103
+ action: import_zod4.z.enum([
1077
1104
  "key",
1078
1105
  "type",
1079
1106
  "mouse_move",
@@ -1085,8 +1112,8 @@ var Computer20241022Parameters = import_zod3.z.object({
1085
1112
  "screenshot",
1086
1113
  "cursor_position"
1087
1114
  ]),
1088
- coordinate: import_zod3.z.array(import_zod3.z.number().int()).optional(),
1089
- text: import_zod3.z.string().optional()
1115
+ coordinate: import_zod4.z.array(import_zod4.z.number().int()).optional(),
1116
+ text: import_zod4.z.string().optional()
1090
1117
  });
1091
1118
  function computerTool_20241022(options) {
1092
1119
  return {
@@ -1102,8 +1129,8 @@ function computerTool_20241022(options) {
1102
1129
  experimental_toToolResultContent: options.experimental_toToolResultContent
1103
1130
  };
1104
1131
  }
1105
- var Computer20250124Parameters = import_zod3.z.object({
1106
- action: import_zod3.z.enum([
1132
+ var Computer20250124Parameters = import_zod4.z.object({
1133
+ action: import_zod4.z.enum([
1107
1134
  "key",
1108
1135
  "hold_key",
1109
1136
  "type",
@@ -1121,12 +1148,12 @@ var Computer20250124Parameters = import_zod3.z.object({
1121
1148
  "wait",
1122
1149
  "screenshot"
1123
1150
  ]),
1124
- coordinate: import_zod3.z.tuple([import_zod3.z.number().int(), import_zod3.z.number().int()]).optional(),
1125
- duration: import_zod3.z.number().optional(),
1126
- scroll_amount: import_zod3.z.number().optional(),
1127
- scroll_direction: import_zod3.z.enum(["up", "down", "left", "right"]).optional(),
1128
- start_coordinate: import_zod3.z.tuple([import_zod3.z.number().int(), import_zod3.z.number().int()]).optional(),
1129
- text: import_zod3.z.string().optional()
1151
+ coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
1152
+ duration: import_zod4.z.number().optional(),
1153
+ scroll_amount: import_zod4.z.number().optional(),
1154
+ scroll_direction: import_zod4.z.enum(["up", "down", "left", "right"]).optional(),
1155
+ start_coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
1156
+ text: import_zod4.z.string().optional()
1130
1157
  });
1131
1158
  function computerTool_20250124(options) {
1132
1159
  return {