@ai-sdk/anthropic 3.0.0-beta.29 → 3.0.0-beta.31
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 +155 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +155 -35
- 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 +154 -34
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +154 -34
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV3, JSONSchema7,
|
|
1
|
+
import { LanguageModelV3, JSONSchema7, SharedV3ProviderMetadata, LanguageModelV3CallWarning, LanguageModelV3CallOptions } 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: SharedV3ProviderMetadata | undefined, context: {
|
|
542
|
+
type: string;
|
|
543
|
+
canCache: boolean;
|
|
544
|
+
}): AnthropicCacheControl | undefined;
|
|
545
|
+
getWarnings(): LanguageModelV3CallWarning[];
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, }: {
|
|
531
549
|
tools: LanguageModelV3CallOptions['tools'];
|
|
532
550
|
toolChoice?: LanguageModelV3CallOptions['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 { LanguageModelV3, JSONSchema7,
|
|
1
|
+
import { LanguageModelV3, JSONSchema7, SharedV3ProviderMetadata, LanguageModelV3CallWarning, LanguageModelV3CallOptions } 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: SharedV3ProviderMetadata | undefined, context: {
|
|
542
|
+
type: string;
|
|
543
|
+
canCache: boolean;
|
|
544
|
+
}): AnthropicCacheControl | undefined;
|
|
545
|
+
getWarnings(): LanguageModelV3CallWarning[];
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, }: {
|
|
531
549
|
tools: LanguageModelV3CallOptions['tools'];
|
|
532
550
|
toolChoice?: LanguageModelV3CallOptions['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
|
@@ -584,19 +584,68 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
584
584
|
allowedTools: import_v43.z.array(import_v43.z.string()).nullish()
|
|
585
585
|
}).nullish()
|
|
586
586
|
})
|
|
587
|
-
).optional()
|
|
587
|
+
).optional(),
|
|
588
|
+
/**
|
|
589
|
+
* Agent Skills configuration. Skills enable Claude to perform specialized tasks
|
|
590
|
+
* like document processing (PPTX, DOCX, PDF, XLSX) and data analysis.
|
|
591
|
+
* Requires code execution tool to be enabled.
|
|
592
|
+
*/
|
|
593
|
+
container: import_v43.z.object({
|
|
594
|
+
id: import_v43.z.string().optional(),
|
|
595
|
+
skills: import_v43.z.array(
|
|
596
|
+
import_v43.z.object({
|
|
597
|
+
type: import_v43.z.union([import_v43.z.literal("anthropic"), import_v43.z.literal("custom")]),
|
|
598
|
+
skillId: import_v43.z.string(),
|
|
599
|
+
version: import_v43.z.string().optional()
|
|
600
|
+
})
|
|
601
|
+
).optional()
|
|
602
|
+
}).optional()
|
|
588
603
|
});
|
|
589
604
|
|
|
590
605
|
// src/anthropic-prepare-tools.ts
|
|
591
606
|
var import_provider = require("@ai-sdk/provider");
|
|
592
607
|
|
|
593
608
|
// src/get-cache-control.ts
|
|
609
|
+
var MAX_CACHE_BREAKPOINTS = 4;
|
|
594
610
|
function getCacheControl(providerMetadata) {
|
|
595
611
|
var _a;
|
|
596
612
|
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
597
613
|
const cacheControlValue = (_a = anthropic == null ? void 0 : anthropic.cacheControl) != null ? _a : anthropic == null ? void 0 : anthropic.cache_control;
|
|
598
614
|
return cacheControlValue;
|
|
599
615
|
}
|
|
616
|
+
var CacheControlValidator = class {
|
|
617
|
+
constructor() {
|
|
618
|
+
this.breakpointCount = 0;
|
|
619
|
+
this.warnings = [];
|
|
620
|
+
}
|
|
621
|
+
getCacheControl(providerMetadata, context) {
|
|
622
|
+
const cacheControlValue = getCacheControl(providerMetadata);
|
|
623
|
+
if (!cacheControlValue) {
|
|
624
|
+
return void 0;
|
|
625
|
+
}
|
|
626
|
+
if (!context.canCache) {
|
|
627
|
+
this.warnings.push({
|
|
628
|
+
type: "unsupported-setting",
|
|
629
|
+
setting: "cacheControl",
|
|
630
|
+
details: `cache_control cannot be set on ${context.type}. It will be ignored.`
|
|
631
|
+
});
|
|
632
|
+
return void 0;
|
|
633
|
+
}
|
|
634
|
+
this.breakpointCount++;
|
|
635
|
+
if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {
|
|
636
|
+
this.warnings.push({
|
|
637
|
+
type: "unsupported-setting",
|
|
638
|
+
setting: "cacheControl",
|
|
639
|
+
details: `Maximum ${MAX_CACHE_BREAKPOINTS} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`
|
|
640
|
+
});
|
|
641
|
+
return void 0;
|
|
642
|
+
}
|
|
643
|
+
return cacheControlValue;
|
|
644
|
+
}
|
|
645
|
+
getWarnings() {
|
|
646
|
+
return this.warnings;
|
|
647
|
+
}
|
|
648
|
+
};
|
|
600
649
|
|
|
601
650
|
// src/tool/text-editor_20250728.ts
|
|
602
651
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
@@ -742,11 +791,13 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
742
791
|
async function prepareTools({
|
|
743
792
|
tools,
|
|
744
793
|
toolChoice,
|
|
745
|
-
disableParallelToolUse
|
|
794
|
+
disableParallelToolUse,
|
|
795
|
+
cacheControlValidator
|
|
746
796
|
}) {
|
|
747
797
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
748
798
|
const toolWarnings = [];
|
|
749
799
|
const betas = /* @__PURE__ */ new Set();
|
|
800
|
+
const validator = cacheControlValidator || new CacheControlValidator();
|
|
750
801
|
if (tools == null) {
|
|
751
802
|
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
752
803
|
}
|
|
@@ -754,7 +805,10 @@ async function prepareTools({
|
|
|
754
805
|
for (const tool of tools) {
|
|
755
806
|
switch (tool.type) {
|
|
756
807
|
case "function": {
|
|
757
|
-
const cacheControl = getCacheControl(tool.providerOptions
|
|
808
|
+
const cacheControl = validator.getCacheControl(tool.providerOptions, {
|
|
809
|
+
type: "tool definition",
|
|
810
|
+
canCache: true
|
|
811
|
+
});
|
|
758
812
|
anthropicTools2.push({
|
|
759
813
|
name: tool.name,
|
|
760
814
|
description: tool.description,
|
|
@@ -769,7 +823,8 @@ async function prepareTools({
|
|
|
769
823
|
betas.add("code-execution-2025-05-22");
|
|
770
824
|
anthropicTools2.push({
|
|
771
825
|
type: "code_execution_20250522",
|
|
772
|
-
name: "code_execution"
|
|
826
|
+
name: "code_execution",
|
|
827
|
+
cache_control: void 0
|
|
773
828
|
});
|
|
774
829
|
break;
|
|
775
830
|
}
|
|
@@ -788,7 +843,8 @@ async function prepareTools({
|
|
|
788
843
|
type: "computer_20250124",
|
|
789
844
|
display_width_px: tool.args.displayWidthPx,
|
|
790
845
|
display_height_px: tool.args.displayHeightPx,
|
|
791
|
-
display_number: tool.args.displayNumber
|
|
846
|
+
display_number: tool.args.displayNumber,
|
|
847
|
+
cache_control: void 0
|
|
792
848
|
});
|
|
793
849
|
break;
|
|
794
850
|
}
|
|
@@ -799,7 +855,8 @@ async function prepareTools({
|
|
|
799
855
|
type: "computer_20241022",
|
|
800
856
|
display_width_px: tool.args.displayWidthPx,
|
|
801
857
|
display_height_px: tool.args.displayHeightPx,
|
|
802
|
-
display_number: tool.args.displayNumber
|
|
858
|
+
display_number: tool.args.displayNumber,
|
|
859
|
+
cache_control: void 0
|
|
803
860
|
});
|
|
804
861
|
break;
|
|
805
862
|
}
|
|
@@ -807,7 +864,8 @@ async function prepareTools({
|
|
|
807
864
|
betas.add("computer-use-2025-01-24");
|
|
808
865
|
anthropicTools2.push({
|
|
809
866
|
name: "str_replace_editor",
|
|
810
|
-
type: "text_editor_20250124"
|
|
867
|
+
type: "text_editor_20250124",
|
|
868
|
+
cache_control: void 0
|
|
811
869
|
});
|
|
812
870
|
break;
|
|
813
871
|
}
|
|
@@ -815,7 +873,8 @@ async function prepareTools({
|
|
|
815
873
|
betas.add("computer-use-2024-10-22");
|
|
816
874
|
anthropicTools2.push({
|
|
817
875
|
name: "str_replace_editor",
|
|
818
|
-
type: "text_editor_20241022"
|
|
876
|
+
type: "text_editor_20241022",
|
|
877
|
+
cache_control: void 0
|
|
819
878
|
});
|
|
820
879
|
break;
|
|
821
880
|
}
|
|
@@ -823,7 +882,8 @@ async function prepareTools({
|
|
|
823
882
|
betas.add("computer-use-2025-01-24");
|
|
824
883
|
anthropicTools2.push({
|
|
825
884
|
name: "str_replace_based_edit_tool",
|
|
826
|
-
type: "text_editor_20250429"
|
|
885
|
+
type: "text_editor_20250429",
|
|
886
|
+
cache_control: void 0
|
|
827
887
|
});
|
|
828
888
|
break;
|
|
829
889
|
}
|
|
@@ -835,7 +895,8 @@ async function prepareTools({
|
|
|
835
895
|
anthropicTools2.push({
|
|
836
896
|
name: "str_replace_based_edit_tool",
|
|
837
897
|
type: "text_editor_20250728",
|
|
838
|
-
max_characters: args.maxCharacters
|
|
898
|
+
max_characters: args.maxCharacters,
|
|
899
|
+
cache_control: void 0
|
|
839
900
|
});
|
|
840
901
|
break;
|
|
841
902
|
}
|
|
@@ -843,7 +904,8 @@ async function prepareTools({
|
|
|
843
904
|
betas.add("computer-use-2025-01-24");
|
|
844
905
|
anthropicTools2.push({
|
|
845
906
|
name: "bash",
|
|
846
|
-
type: "bash_20250124"
|
|
907
|
+
type: "bash_20250124",
|
|
908
|
+
cache_control: void 0
|
|
847
909
|
});
|
|
848
910
|
break;
|
|
849
911
|
}
|
|
@@ -851,7 +913,8 @@ async function prepareTools({
|
|
|
851
913
|
betas.add("computer-use-2024-10-22");
|
|
852
914
|
anthropicTools2.push({
|
|
853
915
|
name: "bash",
|
|
854
|
-
type: "bash_20241022"
|
|
916
|
+
type: "bash_20241022",
|
|
917
|
+
cache_control: void 0
|
|
855
918
|
});
|
|
856
919
|
break;
|
|
857
920
|
}
|
|
@@ -876,7 +939,8 @@ async function prepareTools({
|
|
|
876
939
|
allowed_domains: args.allowedDomains,
|
|
877
940
|
blocked_domains: args.blockedDomains,
|
|
878
941
|
citations: args.citations,
|
|
879
|
-
max_content_tokens: args.maxContentTokens
|
|
942
|
+
max_content_tokens: args.maxContentTokens,
|
|
943
|
+
cache_control: void 0
|
|
880
944
|
});
|
|
881
945
|
break;
|
|
882
946
|
}
|
|
@@ -891,7 +955,8 @@ async function prepareTools({
|
|
|
891
955
|
max_uses: args.maxUses,
|
|
892
956
|
allowed_domains: args.allowedDomains,
|
|
893
957
|
blocked_domains: args.blockedDomains,
|
|
894
|
-
user_location: args.userLocation
|
|
958
|
+
user_location: args.userLocation,
|
|
959
|
+
cache_control: void 0
|
|
895
960
|
});
|
|
896
961
|
break;
|
|
897
962
|
}
|
|
@@ -1103,11 +1168,13 @@ function convertToString(data) {
|
|
|
1103
1168
|
async function convertToAnthropicMessagesPrompt({
|
|
1104
1169
|
prompt,
|
|
1105
1170
|
sendReasoning,
|
|
1106
|
-
warnings
|
|
1171
|
+
warnings,
|
|
1172
|
+
cacheControlValidator
|
|
1107
1173
|
}) {
|
|
1108
1174
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1109
1175
|
const betas = /* @__PURE__ */ new Set();
|
|
1110
1176
|
const blocks = groupIntoBlocks(prompt);
|
|
1177
|
+
const validator = cacheControlValidator || new CacheControlValidator();
|
|
1111
1178
|
let system = void 0;
|
|
1112
1179
|
const messages = [];
|
|
1113
1180
|
async function shouldEnableCitations(providerMetadata) {
|
|
@@ -1144,7 +1211,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1144
1211
|
system = block.messages.map(({ content, providerOptions }) => ({
|
|
1145
1212
|
type: "text",
|
|
1146
1213
|
text: content,
|
|
1147
|
-
cache_control: getCacheControl(providerOptions
|
|
1214
|
+
cache_control: validator.getCacheControl(providerOptions, {
|
|
1215
|
+
type: "system message",
|
|
1216
|
+
canCache: true
|
|
1217
|
+
})
|
|
1148
1218
|
}));
|
|
1149
1219
|
break;
|
|
1150
1220
|
}
|
|
@@ -1157,7 +1227,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1157
1227
|
for (let j = 0; j < content.length; j++) {
|
|
1158
1228
|
const part = content[j];
|
|
1159
1229
|
const isLastPart = j === content.length - 1;
|
|
1160
|
-
const cacheControl = (_a = getCacheControl(part.providerOptions
|
|
1230
|
+
const cacheControl = (_a = validator.getCacheControl(part.providerOptions, {
|
|
1231
|
+
type: "user message part",
|
|
1232
|
+
canCache: true
|
|
1233
|
+
})) != null ? _a : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1234
|
+
type: "user message",
|
|
1235
|
+
canCache: true
|
|
1236
|
+
}) : void 0;
|
|
1161
1237
|
switch (part.type) {
|
|
1162
1238
|
case "text": {
|
|
1163
1239
|
anthropicContent.push({
|
|
@@ -1245,7 +1321,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1245
1321
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
1246
1322
|
const part = content[i2];
|
|
1247
1323
|
const isLastPart = i2 === content.length - 1;
|
|
1248
|
-
const cacheControl = (_d = getCacheControl(part.providerOptions
|
|
1324
|
+
const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
|
|
1325
|
+
type: "tool result part",
|
|
1326
|
+
canCache: true
|
|
1327
|
+
})) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1328
|
+
type: "tool result message",
|
|
1329
|
+
canCache: true
|
|
1330
|
+
}) : void 0;
|
|
1249
1331
|
const output = part.output;
|
|
1250
1332
|
let contentValue;
|
|
1251
1333
|
switch (output.type) {
|
|
@@ -1255,8 +1337,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1255
1337
|
case "text":
|
|
1256
1338
|
return {
|
|
1257
1339
|
type: "text",
|
|
1258
|
-
text: contentPart.text
|
|
1259
|
-
cache_control: cacheControl
|
|
1340
|
+
text: contentPart.text
|
|
1260
1341
|
};
|
|
1261
1342
|
case "image-data": {
|
|
1262
1343
|
return {
|
|
@@ -1265,8 +1346,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1265
1346
|
type: "base64",
|
|
1266
1347
|
media_type: contentPart.mediaType,
|
|
1267
1348
|
data: contentPart.data
|
|
1268
|
-
}
|
|
1269
|
-
cache_control: cacheControl
|
|
1349
|
+
}
|
|
1270
1350
|
};
|
|
1271
1351
|
}
|
|
1272
1352
|
case "file-data": {
|
|
@@ -1278,8 +1358,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1278
1358
|
type: "base64",
|
|
1279
1359
|
media_type: contentPart.mediaType,
|
|
1280
1360
|
data: contentPart.data
|
|
1281
|
-
}
|
|
1282
|
-
cache_control: cacheControl
|
|
1361
|
+
}
|
|
1283
1362
|
};
|
|
1284
1363
|
}
|
|
1285
1364
|
warnings.push({
|
|
@@ -1340,7 +1419,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1340
1419
|
for (let k = 0; k < content.length; k++) {
|
|
1341
1420
|
const part = content[k];
|
|
1342
1421
|
const isLastContentPart = k === content.length - 1;
|
|
1343
|
-
const cacheControl = (_f = getCacheControl(part.providerOptions
|
|
1422
|
+
const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
|
|
1423
|
+
type: "assistant message part",
|
|
1424
|
+
canCache: true
|
|
1425
|
+
})) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
1426
|
+
type: "assistant message",
|
|
1427
|
+
canCache: true
|
|
1428
|
+
}) : void 0;
|
|
1344
1429
|
switch (part.type) {
|
|
1345
1430
|
case "text": {
|
|
1346
1431
|
anthropicContent.push({
|
|
@@ -1364,17 +1449,23 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1364
1449
|
});
|
|
1365
1450
|
if (reasoningMetadata != null) {
|
|
1366
1451
|
if (reasoningMetadata.signature != null) {
|
|
1452
|
+
validator.getCacheControl(part.providerOptions, {
|
|
1453
|
+
type: "thinking block",
|
|
1454
|
+
canCache: false
|
|
1455
|
+
});
|
|
1367
1456
|
anthropicContent.push({
|
|
1368
1457
|
type: "thinking",
|
|
1369
1458
|
thinking: part.text,
|
|
1370
|
-
signature: reasoningMetadata.signature
|
|
1371
|
-
cache_control: cacheControl
|
|
1459
|
+
signature: reasoningMetadata.signature
|
|
1372
1460
|
});
|
|
1373
1461
|
} else if (reasoningMetadata.redactedData != null) {
|
|
1462
|
+
validator.getCacheControl(part.providerOptions, {
|
|
1463
|
+
type: "redacted thinking block",
|
|
1464
|
+
canCache: false
|
|
1465
|
+
});
|
|
1374
1466
|
anthropicContent.push({
|
|
1375
1467
|
type: "redacted_thinking",
|
|
1376
|
-
data: reasoningMetadata.redactedData
|
|
1377
|
-
cache_control: cacheControl
|
|
1468
|
+
data: reasoningMetadata.redactedData
|
|
1378
1469
|
});
|
|
1379
1470
|
} else {
|
|
1380
1471
|
warnings.push({
|
|
@@ -1741,7 +1832,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1741
1832
|
toolChoice,
|
|
1742
1833
|
providerOptions
|
|
1743
1834
|
}) {
|
|
1744
|
-
var _a, _b, _c;
|
|
1835
|
+
var _a, _b, _c, _d;
|
|
1745
1836
|
const warnings = [];
|
|
1746
1837
|
if (frequencyPenalty != null) {
|
|
1747
1838
|
warnings.push({
|
|
@@ -1787,10 +1878,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1787
1878
|
providerOptions,
|
|
1788
1879
|
schema: anthropicProviderOptions
|
|
1789
1880
|
});
|
|
1881
|
+
const cacheControlValidator = new CacheControlValidator();
|
|
1790
1882
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1791
1883
|
prompt,
|
|
1792
1884
|
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
1793
|
-
warnings
|
|
1885
|
+
warnings,
|
|
1886
|
+
cacheControlValidator
|
|
1794
1887
|
});
|
|
1795
1888
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
1796
1889
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
@@ -1822,6 +1915,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1822
1915
|
} : void 0
|
|
1823
1916
|
}))
|
|
1824
1917
|
},
|
|
1918
|
+
// container with agent skills:
|
|
1919
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
1920
|
+
container: {
|
|
1921
|
+
id: anthropicOptions.container.id,
|
|
1922
|
+
skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
|
|
1923
|
+
type: skill.type,
|
|
1924
|
+
skill_id: skill.skillId,
|
|
1925
|
+
version: skill.version
|
|
1926
|
+
}))
|
|
1927
|
+
}
|
|
1928
|
+
},
|
|
1825
1929
|
// prompt:
|
|
1826
1930
|
system: messagesPrompt.system,
|
|
1827
1931
|
messages: messagesPrompt.messages
|
|
@@ -1871,6 +1975,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1871
1975
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
|
|
1872
1976
|
betas.add("mcp-client-2025-04-04");
|
|
1873
1977
|
}
|
|
1978
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
|
|
1979
|
+
betas.add("code-execution-2025-08-25");
|
|
1980
|
+
betas.add("skills-2025-10-02");
|
|
1981
|
+
betas.add("files-api-2025-04-14");
|
|
1982
|
+
if (!(tools == null ? void 0 : tools.some(
|
|
1983
|
+
(tool) => tool.type === "provider-defined" && tool.id === "anthropic.code_execution_20250825"
|
|
1984
|
+
))) {
|
|
1985
|
+
warnings.push({
|
|
1986
|
+
type: "other",
|
|
1987
|
+
message: "code execution tool is required when using skills"
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1874
1991
|
const {
|
|
1875
1992
|
tools: anthropicTools2,
|
|
1876
1993
|
toolChoice: anthropicToolChoice,
|
|
@@ -1880,20 +1997,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1880
1997
|
jsonResponseTool != null ? {
|
|
1881
1998
|
tools: [jsonResponseTool],
|
|
1882
1999
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name },
|
|
1883
|
-
disableParallelToolUse: true
|
|
2000
|
+
disableParallelToolUse: true,
|
|
2001
|
+
cacheControlValidator
|
|
1884
2002
|
} : {
|
|
1885
2003
|
tools: tools != null ? tools : [],
|
|
1886
2004
|
toolChoice,
|
|
1887
|
-
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
2005
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
|
|
2006
|
+
cacheControlValidator
|
|
1888
2007
|
}
|
|
1889
2008
|
);
|
|
2009
|
+
const cacheWarnings = cacheControlValidator.getWarnings();
|
|
1890
2010
|
return {
|
|
1891
2011
|
args: {
|
|
1892
2012
|
...baseArgs,
|
|
1893
2013
|
tools: anthropicTools2,
|
|
1894
2014
|
tool_choice: anthropicToolChoice
|
|
1895
2015
|
},
|
|
1896
|
-
warnings: [...warnings, ...toolWarnings],
|
|
2016
|
+
warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
|
|
1897
2017
|
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
|
|
1898
2018
|
usesJsonResponseTool: jsonResponseTool != null
|
|
1899
2019
|
};
|