@ai-sdk/anthropic 2.0.31 → 2.0.33
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 +12 -0
- package/README.md +1 -1
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +157 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -37
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +21 -2
- package/dist/internal/index.d.ts +21 -2
- package/dist/internal/index.js +156 -36
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +156 -36
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV2, JSONSchema7,
|
|
1
|
+
import { LanguageModelV2, JSONSchema7, SharedV2ProviderMetadata, LanguageModelV2CallWarning, LanguageModelV2CallOptions } from '@ai-sdk/provider';
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
@@ -463,6 +463,7 @@ declare const anthropicTools: {
|
|
|
463
463
|
|
|
464
464
|
type AnthropicCacheControl = {
|
|
465
465
|
type: 'ephemeral';
|
|
466
|
+
ttl?: '5m' | '1h';
|
|
466
467
|
};
|
|
467
468
|
type AnthropicTool = {
|
|
468
469
|
name: string;
|
|
@@ -472,6 +473,7 @@ type AnthropicTool = {
|
|
|
472
473
|
} | {
|
|
473
474
|
type: 'code_execution_20250522';
|
|
474
475
|
name: string;
|
|
476
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
475
477
|
} | {
|
|
476
478
|
type: 'code_execution_20250825';
|
|
477
479
|
name: string;
|
|
@@ -481,16 +483,20 @@ type AnthropicTool = {
|
|
|
481
483
|
display_width_px: number;
|
|
482
484
|
display_height_px: number;
|
|
483
485
|
display_number: number;
|
|
486
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
484
487
|
} | {
|
|
485
488
|
name: string;
|
|
486
489
|
type: 'text_editor_20250124' | 'text_editor_20241022' | 'text_editor_20250429';
|
|
490
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
487
491
|
} | {
|
|
488
492
|
name: string;
|
|
489
493
|
type: 'text_editor_20250728';
|
|
490
494
|
max_characters?: number;
|
|
495
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
491
496
|
} | {
|
|
492
497
|
name: string;
|
|
493
498
|
type: 'bash_20250124' | 'bash_20241022';
|
|
499
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
494
500
|
} | {
|
|
495
501
|
name: string;
|
|
496
502
|
type: 'memory_20250818';
|
|
@@ -504,6 +510,7 @@ type AnthropicTool = {
|
|
|
504
510
|
enabled: boolean;
|
|
505
511
|
};
|
|
506
512
|
max_content_tokens?: number;
|
|
513
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
507
514
|
} | {
|
|
508
515
|
type: 'web_search_20250305';
|
|
509
516
|
name: string;
|
|
@@ -517,6 +524,7 @@ type AnthropicTool = {
|
|
|
517
524
|
country?: string;
|
|
518
525
|
timezone?: string;
|
|
519
526
|
};
|
|
527
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
520
528
|
};
|
|
521
529
|
type AnthropicToolChoice = {
|
|
522
530
|
type: 'auto' | 'any';
|
|
@@ -527,10 +535,21 @@ type AnthropicToolChoice = {
|
|
|
527
535
|
disable_parallel_tool_use?: boolean;
|
|
528
536
|
};
|
|
529
537
|
|
|
530
|
-
declare
|
|
538
|
+
declare class CacheControlValidator {
|
|
539
|
+
private breakpointCount;
|
|
540
|
+
private warnings;
|
|
541
|
+
getCacheControl(providerMetadata: SharedV2ProviderMetadata | undefined, context: {
|
|
542
|
+
type: string;
|
|
543
|
+
canCache: boolean;
|
|
544
|
+
}): AnthropicCacheControl | undefined;
|
|
545
|
+
getWarnings(): LanguageModelV2CallWarning[];
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, }: {
|
|
531
549
|
tools: LanguageModelV2CallOptions['tools'];
|
|
532
550
|
toolChoice?: LanguageModelV2CallOptions['toolChoice'];
|
|
533
551
|
disableParallelToolUse?: boolean;
|
|
552
|
+
cacheControlValidator?: CacheControlValidator;
|
|
534
553
|
}): Promise<{
|
|
535
554
|
tools: Array<AnthropicTool> | undefined;
|
|
536
555
|
toolChoice: AnthropicToolChoice | undefined;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV2, JSONSchema7,
|
|
1
|
+
import { LanguageModelV2, JSONSchema7, SharedV2ProviderMetadata, LanguageModelV2CallWarning, LanguageModelV2CallOptions } from '@ai-sdk/provider';
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
@@ -463,6 +463,7 @@ declare const anthropicTools: {
|
|
|
463
463
|
|
|
464
464
|
type AnthropicCacheControl = {
|
|
465
465
|
type: 'ephemeral';
|
|
466
|
+
ttl?: '5m' | '1h';
|
|
466
467
|
};
|
|
467
468
|
type AnthropicTool = {
|
|
468
469
|
name: string;
|
|
@@ -472,6 +473,7 @@ type AnthropicTool = {
|
|
|
472
473
|
} | {
|
|
473
474
|
type: 'code_execution_20250522';
|
|
474
475
|
name: string;
|
|
476
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
475
477
|
} | {
|
|
476
478
|
type: 'code_execution_20250825';
|
|
477
479
|
name: string;
|
|
@@ -481,16 +483,20 @@ type AnthropicTool = {
|
|
|
481
483
|
display_width_px: number;
|
|
482
484
|
display_height_px: number;
|
|
483
485
|
display_number: number;
|
|
486
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
484
487
|
} | {
|
|
485
488
|
name: string;
|
|
486
489
|
type: 'text_editor_20250124' | 'text_editor_20241022' | 'text_editor_20250429';
|
|
490
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
487
491
|
} | {
|
|
488
492
|
name: string;
|
|
489
493
|
type: 'text_editor_20250728';
|
|
490
494
|
max_characters?: number;
|
|
495
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
491
496
|
} | {
|
|
492
497
|
name: string;
|
|
493
498
|
type: 'bash_20250124' | 'bash_20241022';
|
|
499
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
494
500
|
} | {
|
|
495
501
|
name: string;
|
|
496
502
|
type: 'memory_20250818';
|
|
@@ -504,6 +510,7 @@ type AnthropicTool = {
|
|
|
504
510
|
enabled: boolean;
|
|
505
511
|
};
|
|
506
512
|
max_content_tokens?: number;
|
|
513
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
507
514
|
} | {
|
|
508
515
|
type: 'web_search_20250305';
|
|
509
516
|
name: string;
|
|
@@ -517,6 +524,7 @@ type AnthropicTool = {
|
|
|
517
524
|
country?: string;
|
|
518
525
|
timezone?: string;
|
|
519
526
|
};
|
|
527
|
+
cache_control: AnthropicCacheControl | undefined;
|
|
520
528
|
};
|
|
521
529
|
type AnthropicToolChoice = {
|
|
522
530
|
type: 'auto' | 'any';
|
|
@@ -527,10 +535,21 @@ type AnthropicToolChoice = {
|
|
|
527
535
|
disable_parallel_tool_use?: boolean;
|
|
528
536
|
};
|
|
529
537
|
|
|
530
|
-
declare
|
|
538
|
+
declare class CacheControlValidator {
|
|
539
|
+
private breakpointCount;
|
|
540
|
+
private warnings;
|
|
541
|
+
getCacheControl(providerMetadata: SharedV2ProviderMetadata | undefined, context: {
|
|
542
|
+
type: string;
|
|
543
|
+
canCache: boolean;
|
|
544
|
+
}): AnthropicCacheControl | undefined;
|
|
545
|
+
getWarnings(): LanguageModelV2CallWarning[];
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, }: {
|
|
531
549
|
tools: LanguageModelV2CallOptions['tools'];
|
|
532
550
|
toolChoice?: LanguageModelV2CallOptions['toolChoice'];
|
|
533
551
|
disableParallelToolUse?: boolean;
|
|
552
|
+
cacheControlValidator?: CacheControlValidator;
|
|
534
553
|
}): Promise<{
|
|
535
554
|
tools: Array<AnthropicTool> | undefined;
|
|
536
555
|
toolChoice: AnthropicToolChoice | undefined;
|
package/dist/internal/index.js
CHANGED
|
@@ -536,6 +536,21 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
536
536
|
cacheControl: import_v43.z.object({
|
|
537
537
|
type: import_v43.z.literal("ephemeral"),
|
|
538
538
|
ttl: import_v43.z.union([import_v43.z.literal("5m"), import_v43.z.literal("1h")]).optional()
|
|
539
|
+
}).optional(),
|
|
540
|
+
/**
|
|
541
|
+
* Agent Skills configuration. Skills enable Claude to perform specialized tasks
|
|
542
|
+
* like document processing (PPTX, DOCX, PDF, XLSX) and data analysis.
|
|
543
|
+
* Requires code execution tool to be enabled.
|
|
544
|
+
*/
|
|
545
|
+
container: import_v43.z.object({
|
|
546
|
+
id: import_v43.z.string().optional(),
|
|
547
|
+
skills: import_v43.z.array(
|
|
548
|
+
import_v43.z.object({
|
|
549
|
+
type: import_v43.z.union([import_v43.z.literal("anthropic"), import_v43.z.literal("custom")]),
|
|
550
|
+
skillId: import_v43.z.string(),
|
|
551
|
+
version: import_v43.z.string().optional()
|
|
552
|
+
})
|
|
553
|
+
).optional()
|
|
539
554
|
}).optional()
|
|
540
555
|
});
|
|
541
556
|
|
|
@@ -543,12 +558,46 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
543
558
|
var import_provider = require("@ai-sdk/provider");
|
|
544
559
|
|
|
545
560
|
// src/get-cache-control.ts
|
|
561
|
+
var MAX_CACHE_BREAKPOINTS = 4;
|
|
546
562
|
function getCacheControl(providerMetadata) {
|
|
547
563
|
var _a;
|
|
548
564
|
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
549
565
|
const cacheControlValue = (_a = anthropic == null ? void 0 : anthropic.cacheControl) != null ? _a : anthropic == null ? void 0 : anthropic.cache_control;
|
|
550
566
|
return cacheControlValue;
|
|
551
567
|
}
|
|
568
|
+
var CacheControlValidator = class {
|
|
569
|
+
constructor() {
|
|
570
|
+
this.breakpointCount = 0;
|
|
571
|
+
this.warnings = [];
|
|
572
|
+
}
|
|
573
|
+
getCacheControl(providerMetadata, context) {
|
|
574
|
+
const cacheControlValue = getCacheControl(providerMetadata);
|
|
575
|
+
if (!cacheControlValue) {
|
|
576
|
+
return void 0;
|
|
577
|
+
}
|
|
578
|
+
if (!context.canCache) {
|
|
579
|
+
this.warnings.push({
|
|
580
|
+
type: "unsupported-setting",
|
|
581
|
+
setting: "cacheControl",
|
|
582
|
+
details: `cache_control cannot be set on ${context.type}. It will be ignored.`
|
|
583
|
+
});
|
|
584
|
+
return void 0;
|
|
585
|
+
}
|
|
586
|
+
this.breakpointCount++;
|
|
587
|
+
if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {
|
|
588
|
+
this.warnings.push({
|
|
589
|
+
type: "unsupported-setting",
|
|
590
|
+
setting: "cacheControl",
|
|
591
|
+
details: `Maximum ${MAX_CACHE_BREAKPOINTS} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`
|
|
592
|
+
});
|
|
593
|
+
return void 0;
|
|
594
|
+
}
|
|
595
|
+
return cacheControlValue;
|
|
596
|
+
}
|
|
597
|
+
getWarnings() {
|
|
598
|
+
return this.warnings;
|
|
599
|
+
}
|
|
600
|
+
};
|
|
552
601
|
|
|
553
602
|
// src/tool/text-editor_20250728.ts
|
|
554
603
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
@@ -694,11 +743,13 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
694
743
|
async function prepareTools({
|
|
695
744
|
tools,
|
|
696
745
|
toolChoice,
|
|
697
|
-
disableParallelToolUse
|
|
746
|
+
disableParallelToolUse,
|
|
747
|
+
cacheControlValidator
|
|
698
748
|
}) {
|
|
699
749
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
700
750
|
const toolWarnings = [];
|
|
701
751
|
const betas = /* @__PURE__ */ new Set();
|
|
752
|
+
const validator = cacheControlValidator || new CacheControlValidator();
|
|
702
753
|
if (tools == null) {
|
|
703
754
|
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
704
755
|
}
|
|
@@ -706,7 +757,10 @@ async function prepareTools({
|
|
|
706
757
|
for (const tool of tools) {
|
|
707
758
|
switch (tool.type) {
|
|
708
759
|
case "function": {
|
|
709
|
-
const cacheControl = getCacheControl(tool.providerOptions
|
|
760
|
+
const cacheControl = validator.getCacheControl(tool.providerOptions, {
|
|
761
|
+
type: "tool definition",
|
|
762
|
+
canCache: true
|
|
763
|
+
});
|
|
710
764
|
anthropicTools2.push({
|
|
711
765
|
name: tool.name,
|
|
712
766
|
description: tool.description,
|
|
@@ -721,7 +775,8 @@ async function prepareTools({
|
|
|
721
775
|
betas.add("code-execution-2025-05-22");
|
|
722
776
|
anthropicTools2.push({
|
|
723
777
|
type: "code_execution_20250522",
|
|
724
|
-
name: "code_execution"
|
|
778
|
+
name: "code_execution",
|
|
779
|
+
cache_control: void 0
|
|
725
780
|
});
|
|
726
781
|
break;
|
|
727
782
|
}
|
|
@@ -740,7 +795,8 @@ async function prepareTools({
|
|
|
740
795
|
type: "computer_20250124",
|
|
741
796
|
display_width_px: tool.args.displayWidthPx,
|
|
742
797
|
display_height_px: tool.args.displayHeightPx,
|
|
743
|
-
display_number: tool.args.displayNumber
|
|
798
|
+
display_number: tool.args.displayNumber,
|
|
799
|
+
cache_control: void 0
|
|
744
800
|
});
|
|
745
801
|
break;
|
|
746
802
|
}
|
|
@@ -751,7 +807,8 @@ async function prepareTools({
|
|
|
751
807
|
type: "computer_20241022",
|
|
752
808
|
display_width_px: tool.args.displayWidthPx,
|
|
753
809
|
display_height_px: tool.args.displayHeightPx,
|
|
754
|
-
display_number: tool.args.displayNumber
|
|
810
|
+
display_number: tool.args.displayNumber,
|
|
811
|
+
cache_control: void 0
|
|
755
812
|
});
|
|
756
813
|
break;
|
|
757
814
|
}
|
|
@@ -759,7 +816,8 @@ async function prepareTools({
|
|
|
759
816
|
betas.add("computer-use-2025-01-24");
|
|
760
817
|
anthropicTools2.push({
|
|
761
818
|
name: "str_replace_editor",
|
|
762
|
-
type: "text_editor_20250124"
|
|
819
|
+
type: "text_editor_20250124",
|
|
820
|
+
cache_control: void 0
|
|
763
821
|
});
|
|
764
822
|
break;
|
|
765
823
|
}
|
|
@@ -767,7 +825,8 @@ async function prepareTools({
|
|
|
767
825
|
betas.add("computer-use-2024-10-22");
|
|
768
826
|
anthropicTools2.push({
|
|
769
827
|
name: "str_replace_editor",
|
|
770
|
-
type: "text_editor_20241022"
|
|
828
|
+
type: "text_editor_20241022",
|
|
829
|
+
cache_control: void 0
|
|
771
830
|
});
|
|
772
831
|
break;
|
|
773
832
|
}
|
|
@@ -775,7 +834,8 @@ async function prepareTools({
|
|
|
775
834
|
betas.add("computer-use-2025-01-24");
|
|
776
835
|
anthropicTools2.push({
|
|
777
836
|
name: "str_replace_based_edit_tool",
|
|
778
|
-
type: "text_editor_20250429"
|
|
837
|
+
type: "text_editor_20250429",
|
|
838
|
+
cache_control: void 0
|
|
779
839
|
});
|
|
780
840
|
break;
|
|
781
841
|
}
|
|
@@ -787,7 +847,8 @@ async function prepareTools({
|
|
|
787
847
|
anthropicTools2.push({
|
|
788
848
|
name: "str_replace_based_edit_tool",
|
|
789
849
|
type: "text_editor_20250728",
|
|
790
|
-
max_characters: args.maxCharacters
|
|
850
|
+
max_characters: args.maxCharacters,
|
|
851
|
+
cache_control: void 0
|
|
791
852
|
});
|
|
792
853
|
break;
|
|
793
854
|
}
|
|
@@ -795,7 +856,8 @@ async function prepareTools({
|
|
|
795
856
|
betas.add("computer-use-2025-01-24");
|
|
796
857
|
anthropicTools2.push({
|
|
797
858
|
name: "bash",
|
|
798
|
-
type: "bash_20250124"
|
|
859
|
+
type: "bash_20250124",
|
|
860
|
+
cache_control: void 0
|
|
799
861
|
});
|
|
800
862
|
break;
|
|
801
863
|
}
|
|
@@ -803,7 +865,8 @@ async function prepareTools({
|
|
|
803
865
|
betas.add("computer-use-2024-10-22");
|
|
804
866
|
anthropicTools2.push({
|
|
805
867
|
name: "bash",
|
|
806
|
-
type: "bash_20241022"
|
|
868
|
+
type: "bash_20241022",
|
|
869
|
+
cache_control: void 0
|
|
807
870
|
});
|
|
808
871
|
break;
|
|
809
872
|
}
|
|
@@ -828,7 +891,8 @@ async function prepareTools({
|
|
|
828
891
|
allowed_domains: args.allowedDomains,
|
|
829
892
|
blocked_domains: args.blockedDomains,
|
|
830
893
|
citations: args.citations,
|
|
831
|
-
max_content_tokens: args.maxContentTokens
|
|
894
|
+
max_content_tokens: args.maxContentTokens,
|
|
895
|
+
cache_control: void 0
|
|
832
896
|
});
|
|
833
897
|
break;
|
|
834
898
|
}
|
|
@@ -843,7 +907,8 @@ async function prepareTools({
|
|
|
843
907
|
max_uses: args.maxUses,
|
|
844
908
|
allowed_domains: args.allowedDomains,
|
|
845
909
|
blocked_domains: args.blockedDomains,
|
|
846
|
-
user_location: args.userLocation
|
|
910
|
+
user_location: args.userLocation,
|
|
911
|
+
cache_control: void 0
|
|
847
912
|
});
|
|
848
913
|
break;
|
|
849
914
|
}
|
|
@@ -1055,11 +1120,13 @@ function convertToString(data) {
|
|
|
1055
1120
|
async function convertToAnthropicMessagesPrompt({
|
|
1056
1121
|
prompt,
|
|
1057
1122
|
sendReasoning,
|
|
1058
|
-
warnings
|
|
1123
|
+
warnings,
|
|
1124
|
+
cacheControlValidator
|
|
1059
1125
|
}) {
|
|
1060
1126
|
var _a, _b, _c, _d, _e;
|
|
1061
1127
|
const betas = /* @__PURE__ */ new Set();
|
|
1062
1128
|
const blocks = groupIntoBlocks(prompt);
|
|
1129
|
+
const validator = cacheControlValidator || new CacheControlValidator();
|
|
1063
1130
|
let system = void 0;
|
|
1064
1131
|
const messages = [];
|
|
1065
1132
|
async function shouldEnableCitations(providerMetadata) {
|
|
@@ -1096,7 +1163,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1096
1163
|
system = block.messages.map(({ content, providerOptions }) => ({
|
|
1097
1164
|
type: "text",
|
|
1098
1165
|
text: content,
|
|
1099
|
-
cache_control: getCacheControl(providerOptions
|
|
1166
|
+
cache_control: validator.getCacheControl(providerOptions, {
|
|
1167
|
+
type: "system message",
|
|
1168
|
+
canCache: true
|
|
1169
|
+
})
|
|
1100
1170
|
}));
|
|
1101
1171
|
break;
|
|
1102
1172
|
}
|
|
@@ -1109,7 +1179,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1109
1179
|
for (let j = 0; j < content.length; j++) {
|
|
1110
1180
|
const part = content[j];
|
|
1111
1181
|
const isLastPart = j === content.length - 1;
|
|
1112
|
-
const cacheControl = (_a = getCacheControl(part.providerOptions
|
|
1182
|
+
const cacheControl = (_a = validator.getCacheControl(part.providerOptions, {
|
|
1183
|
+
type: "user message part",
|
|
1184
|
+
canCache: true
|
|
1185
|
+
})) != null ? _a : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1186
|
+
type: "user message",
|
|
1187
|
+
canCache: true
|
|
1188
|
+
}) : void 0;
|
|
1113
1189
|
switch (part.type) {
|
|
1114
1190
|
case "text": {
|
|
1115
1191
|
anthropicContent.push({
|
|
@@ -1197,7 +1273,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1197
1273
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
1198
1274
|
const part = content[i2];
|
|
1199
1275
|
const isLastPart = i2 === content.length - 1;
|
|
1200
|
-
const cacheControl = (_d = getCacheControl(part.providerOptions
|
|
1276
|
+
const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
|
|
1277
|
+
type: "tool result part",
|
|
1278
|
+
canCache: true
|
|
1279
|
+
})) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1280
|
+
type: "tool result message",
|
|
1281
|
+
canCache: true
|
|
1282
|
+
}) : void 0;
|
|
1201
1283
|
const output = part.output;
|
|
1202
1284
|
let contentValue;
|
|
1203
1285
|
switch (output.type) {
|
|
@@ -1207,8 +1289,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1207
1289
|
case "text":
|
|
1208
1290
|
return {
|
|
1209
1291
|
type: "text",
|
|
1210
|
-
text: contentPart.text
|
|
1211
|
-
cache_control: void 0
|
|
1292
|
+
text: contentPart.text
|
|
1212
1293
|
};
|
|
1213
1294
|
case "media": {
|
|
1214
1295
|
if (contentPart.mediaType.startsWith("image/")) {
|
|
@@ -1218,8 +1299,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1218
1299
|
type: "base64",
|
|
1219
1300
|
media_type: contentPart.mediaType,
|
|
1220
1301
|
data: contentPart.data
|
|
1221
|
-
}
|
|
1222
|
-
cache_control: void 0
|
|
1302
|
+
}
|
|
1223
1303
|
};
|
|
1224
1304
|
}
|
|
1225
1305
|
if (contentPart.mediaType === "application/pdf") {
|
|
@@ -1230,8 +1310,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1230
1310
|
type: "base64",
|
|
1231
1311
|
media_type: contentPart.mediaType,
|
|
1232
1312
|
data: contentPart.data
|
|
1233
|
-
}
|
|
1234
|
-
cache_control: void 0
|
|
1313
|
+
}
|
|
1235
1314
|
};
|
|
1236
1315
|
}
|
|
1237
1316
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
@@ -1279,7 +1358,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1279
1358
|
for (let k = 0; k < content.length; k++) {
|
|
1280
1359
|
const part = content[k];
|
|
1281
1360
|
const isLastContentPart = k === content.length - 1;
|
|
1282
|
-
const cacheControl = (_e = getCacheControl(part.providerOptions
|
|
1361
|
+
const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
|
|
1362
|
+
type: "assistant message part",
|
|
1363
|
+
canCache: true
|
|
1364
|
+
})) != null ? _e : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
1365
|
+
type: "assistant message",
|
|
1366
|
+
canCache: true
|
|
1367
|
+
}) : void 0;
|
|
1283
1368
|
switch (part.type) {
|
|
1284
1369
|
case "text": {
|
|
1285
1370
|
anthropicContent.push({
|
|
@@ -1303,17 +1388,23 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1303
1388
|
});
|
|
1304
1389
|
if (reasoningMetadata != null) {
|
|
1305
1390
|
if (reasoningMetadata.signature != null) {
|
|
1391
|
+
validator.getCacheControl(part.providerOptions, {
|
|
1392
|
+
type: "thinking block",
|
|
1393
|
+
canCache: false
|
|
1394
|
+
});
|
|
1306
1395
|
anthropicContent.push({
|
|
1307
1396
|
type: "thinking",
|
|
1308
1397
|
thinking: part.text,
|
|
1309
|
-
signature: reasoningMetadata.signature
|
|
1310
|
-
cache_control: cacheControl
|
|
1398
|
+
signature: reasoningMetadata.signature
|
|
1311
1399
|
});
|
|
1312
1400
|
} else if (reasoningMetadata.redactedData != null) {
|
|
1401
|
+
validator.getCacheControl(part.providerOptions, {
|
|
1402
|
+
type: "redacted thinking block",
|
|
1403
|
+
canCache: false
|
|
1404
|
+
});
|
|
1313
1405
|
anthropicContent.push({
|
|
1314
1406
|
type: "redacted_thinking",
|
|
1315
|
-
data: reasoningMetadata.redactedData
|
|
1316
|
-
cache_control: cacheControl
|
|
1407
|
+
data: reasoningMetadata.redactedData
|
|
1317
1408
|
});
|
|
1318
1409
|
} else {
|
|
1319
1410
|
warnings.push({
|
|
@@ -1642,7 +1733,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1642
1733
|
toolChoice,
|
|
1643
1734
|
providerOptions
|
|
1644
1735
|
}) {
|
|
1645
|
-
var _a, _b, _c;
|
|
1736
|
+
var _a, _b, _c, _d;
|
|
1646
1737
|
const warnings = [];
|
|
1647
1738
|
if (frequencyPenalty != null) {
|
|
1648
1739
|
warnings.push({
|
|
@@ -1688,10 +1779,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1688
1779
|
providerOptions,
|
|
1689
1780
|
schema: anthropicProviderOptions
|
|
1690
1781
|
});
|
|
1691
|
-
const
|
|
1782
|
+
const cacheControlValidator = new CacheControlValidator();
|
|
1783
|
+
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1692
1784
|
prompt,
|
|
1693
1785
|
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
1694
|
-
warnings
|
|
1786
|
+
warnings,
|
|
1787
|
+
cacheControlValidator
|
|
1695
1788
|
});
|
|
1696
1789
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
1697
1790
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
@@ -1710,6 +1803,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1710
1803
|
...isThinking && {
|
|
1711
1804
|
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
1712
1805
|
},
|
|
1806
|
+
// container with agent skills:
|
|
1807
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
1808
|
+
container: {
|
|
1809
|
+
id: anthropicOptions.container.id,
|
|
1810
|
+
skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
|
|
1811
|
+
type: skill.type,
|
|
1812
|
+
skill_id: skill.skillId,
|
|
1813
|
+
version: skill.version
|
|
1814
|
+
}))
|
|
1815
|
+
}
|
|
1816
|
+
},
|
|
1713
1817
|
// prompt:
|
|
1714
1818
|
system: messagesPrompt.system,
|
|
1715
1819
|
messages: messagesPrompt.messages
|
|
@@ -1751,11 +1855,24 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1751
1855
|
warnings.push({
|
|
1752
1856
|
type: "unsupported-setting",
|
|
1753
1857
|
setting: "maxOutputTokens",
|
|
1754
|
-
details: `${
|
|
1858
|
+
details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
|
|
1755
1859
|
});
|
|
1756
1860
|
}
|
|
1757
1861
|
baseArgs.max_tokens = maxOutputTokensForModel;
|
|
1758
1862
|
}
|
|
1863
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
|
|
1864
|
+
betas.add("code-execution-2025-08-25");
|
|
1865
|
+
betas.add("skills-2025-10-02");
|
|
1866
|
+
betas.add("files-api-2025-04-14");
|
|
1867
|
+
if (!(tools == null ? void 0 : tools.some(
|
|
1868
|
+
(tool) => tool.type === "provider-defined" && tool.id === "anthropic.code_execution_20250825"
|
|
1869
|
+
))) {
|
|
1870
|
+
warnings.push({
|
|
1871
|
+
type: "other",
|
|
1872
|
+
message: "code execution tool is required when using skills"
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1759
1876
|
const {
|
|
1760
1877
|
tools: anthropicTools2,
|
|
1761
1878
|
toolChoice: anthropicToolChoice,
|
|
@@ -1765,21 +1882,24 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1765
1882
|
jsonResponseTool != null ? {
|
|
1766
1883
|
tools: [jsonResponseTool],
|
|
1767
1884
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name },
|
|
1768
|
-
disableParallelToolUse: true
|
|
1885
|
+
disableParallelToolUse: true,
|
|
1886
|
+
cacheControlValidator
|
|
1769
1887
|
} : {
|
|
1770
1888
|
tools: tools != null ? tools : [],
|
|
1771
1889
|
toolChoice,
|
|
1772
|
-
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
1890
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
|
|
1891
|
+
cacheControlValidator
|
|
1773
1892
|
}
|
|
1774
1893
|
);
|
|
1894
|
+
const cacheWarnings = cacheControlValidator.getWarnings();
|
|
1775
1895
|
return {
|
|
1776
1896
|
args: {
|
|
1777
1897
|
...baseArgs,
|
|
1778
1898
|
tools: anthropicTools2,
|
|
1779
1899
|
tool_choice: anthropicToolChoice
|
|
1780
1900
|
},
|
|
1781
|
-
warnings: [...warnings, ...toolWarnings],
|
|
1782
|
-
betas: /* @__PURE__ */ new Set([...
|
|
1901
|
+
warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
|
|
1902
|
+
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
|
|
1783
1903
|
usesJsonResponseTool: jsonResponseTool != null
|
|
1784
1904
|
};
|
|
1785
1905
|
}
|