@ai-sdk/anthropic 3.0.0-beta.30 → 3.0.0-beta.32
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/dist/index.d.mts +41 -2
- package/dist/index.d.ts +41 -2
- package/dist/index.js +165 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +165 -39
- 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 +164 -38
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +164 -38
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.32
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f4db7b5: feat(provider/anthropic): expose container from response in provider metadata
|
|
8
|
+
|
|
9
|
+
## 3.0.0-beta.31
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- ca07285: feat(anthropic): add prompt caching validation
|
|
14
|
+
|
|
3
15
|
## 3.0.0-beta.30
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,47 @@
|
|
|
1
|
+
import { JSONObject, ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
1
2
|
import { z } from 'zod/v4';
|
|
2
|
-
import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
5
5
|
|
|
6
|
+
interface AnthropicMessageMetadata {
|
|
7
|
+
usage: JSONObject;
|
|
8
|
+
cacheCreationInputTokens: number | null;
|
|
9
|
+
stopSequence: string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Information about the container used in this request.
|
|
12
|
+
*
|
|
13
|
+
* This will be non-null if a container tool (e.g., code execution) was used.
|
|
14
|
+
* Information about the container used in the request (for the code execution tool).
|
|
15
|
+
*/
|
|
16
|
+
container: {
|
|
17
|
+
/**
|
|
18
|
+
* The time at which the container will expire (RFC3339 timestamp).
|
|
19
|
+
*/
|
|
20
|
+
expiresAt: string;
|
|
21
|
+
/**
|
|
22
|
+
* Identifier for the container used in this request.
|
|
23
|
+
*/
|
|
24
|
+
id: string;
|
|
25
|
+
/**
|
|
26
|
+
* Skills loaded in the container.
|
|
27
|
+
*/
|
|
28
|
+
skills: Array<{
|
|
29
|
+
/**
|
|
30
|
+
* Type of skill: either 'anthropic' (built-in) or 'custom' (user-defined).
|
|
31
|
+
*/
|
|
32
|
+
type: 'anthropic' | 'custom';
|
|
33
|
+
/**
|
|
34
|
+
* Skill ID (1-64 characters).
|
|
35
|
+
*/
|
|
36
|
+
skillId: string;
|
|
37
|
+
/**
|
|
38
|
+
* Skill version or 'latest' for most recent version (1-64 characters).
|
|
39
|
+
*/
|
|
40
|
+
version: string;
|
|
41
|
+
}> | null;
|
|
42
|
+
} | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
6
45
|
type AnthropicMessagesModelId = 'claude-haiku-4-5' | 'claude-haiku-4-5-20251001' | 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (string & {});
|
|
7
46
|
declare const anthropicProviderOptions: z.ZodObject<{
|
|
8
47
|
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -514,4 +553,4 @@ declare const anthropic: AnthropicProvider;
|
|
|
514
553
|
|
|
515
554
|
declare const VERSION: string;
|
|
516
555
|
|
|
517
|
-
export { type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, VERSION, anthropic, createAnthropic };
|
|
556
|
+
export { type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, VERSION, anthropic, createAnthropic };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,47 @@
|
|
|
1
|
+
import { JSONObject, ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
1
2
|
import { z } from 'zod/v4';
|
|
2
|
-
import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
5
5
|
|
|
6
|
+
interface AnthropicMessageMetadata {
|
|
7
|
+
usage: JSONObject;
|
|
8
|
+
cacheCreationInputTokens: number | null;
|
|
9
|
+
stopSequence: string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Information about the container used in this request.
|
|
12
|
+
*
|
|
13
|
+
* This will be non-null if a container tool (e.g., code execution) was used.
|
|
14
|
+
* Information about the container used in the request (for the code execution tool).
|
|
15
|
+
*/
|
|
16
|
+
container: {
|
|
17
|
+
/**
|
|
18
|
+
* The time at which the container will expire (RFC3339 timestamp).
|
|
19
|
+
*/
|
|
20
|
+
expiresAt: string;
|
|
21
|
+
/**
|
|
22
|
+
* Identifier for the container used in this request.
|
|
23
|
+
*/
|
|
24
|
+
id: string;
|
|
25
|
+
/**
|
|
26
|
+
* Skills loaded in the container.
|
|
27
|
+
*/
|
|
28
|
+
skills: Array<{
|
|
29
|
+
/**
|
|
30
|
+
* Type of skill: either 'anthropic' (built-in) or 'custom' (user-defined).
|
|
31
|
+
*/
|
|
32
|
+
type: 'anthropic' | 'custom';
|
|
33
|
+
/**
|
|
34
|
+
* Skill ID (1-64 characters).
|
|
35
|
+
*/
|
|
36
|
+
skillId: string;
|
|
37
|
+
/**
|
|
38
|
+
* Skill version or 'latest' for most recent version (1-64 characters).
|
|
39
|
+
*/
|
|
40
|
+
version: string;
|
|
41
|
+
}> | null;
|
|
42
|
+
} | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
6
45
|
type AnthropicMessagesModelId = 'claude-haiku-4-5' | 'claude-haiku-4-5-20251001' | 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (string & {});
|
|
7
46
|
declare const anthropicProviderOptions: z.ZodObject<{
|
|
8
47
|
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -514,4 +553,4 @@ declare const anthropic: AnthropicProvider;
|
|
|
514
553
|
|
|
515
554
|
declare const VERSION: string;
|
|
516
555
|
|
|
517
|
-
export { type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, VERSION, anthropic, createAnthropic };
|
|
556
|
+
export { type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, VERSION, anthropic, createAnthropic };
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
31
31
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/version.ts
|
|
34
|
-
var VERSION = true ? "3.0.0-beta.
|
|
34
|
+
var VERSION = true ? "3.0.0-beta.32" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -263,7 +263,18 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
263
263
|
output_tokens: import_v42.z.number(),
|
|
264
264
|
cache_creation_input_tokens: import_v42.z.number().nullish(),
|
|
265
265
|
cache_read_input_tokens: import_v42.z.number().nullish()
|
|
266
|
-
})
|
|
266
|
+
}),
|
|
267
|
+
container: import_v42.z.object({
|
|
268
|
+
expires_at: import_v42.z.string(),
|
|
269
|
+
id: import_v42.z.string(),
|
|
270
|
+
skills: import_v42.z.array(
|
|
271
|
+
import_v42.z.object({
|
|
272
|
+
type: import_v42.z.union([import_v42.z.literal("anthropic"), import_v42.z.literal("custom")]),
|
|
273
|
+
skill_id: import_v42.z.string(),
|
|
274
|
+
version: import_v42.z.string()
|
|
275
|
+
})
|
|
276
|
+
).nullish()
|
|
277
|
+
}).nullish()
|
|
267
278
|
})
|
|
268
279
|
)
|
|
269
280
|
);
|
|
@@ -511,7 +522,21 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
511
522
|
type: import_v42.z.literal("message_delta"),
|
|
512
523
|
delta: import_v42.z.object({
|
|
513
524
|
stop_reason: import_v42.z.string().nullish(),
|
|
514
|
-
stop_sequence: import_v42.z.string().nullish()
|
|
525
|
+
stop_sequence: import_v42.z.string().nullish(),
|
|
526
|
+
container: import_v42.z.object({
|
|
527
|
+
expires_at: import_v42.z.string(),
|
|
528
|
+
id: import_v42.z.string(),
|
|
529
|
+
skills: import_v42.z.array(
|
|
530
|
+
import_v42.z.object({
|
|
531
|
+
type: import_v42.z.union([
|
|
532
|
+
import_v42.z.literal("anthropic"),
|
|
533
|
+
import_v42.z.literal("custom")
|
|
534
|
+
]),
|
|
535
|
+
skill_id: import_v42.z.string(),
|
|
536
|
+
version: import_v42.z.string()
|
|
537
|
+
})
|
|
538
|
+
).nullish()
|
|
539
|
+
}).nullish()
|
|
515
540
|
}),
|
|
516
541
|
usage: import_v42.z.looseObject({
|
|
517
542
|
output_tokens: import_v42.z.number(),
|
|
@@ -613,12 +638,46 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
613
638
|
var import_provider = require("@ai-sdk/provider");
|
|
614
639
|
|
|
615
640
|
// src/get-cache-control.ts
|
|
641
|
+
var MAX_CACHE_BREAKPOINTS = 4;
|
|
616
642
|
function getCacheControl(providerMetadata) {
|
|
617
643
|
var _a;
|
|
618
644
|
const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
619
645
|
const cacheControlValue = (_a = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
620
646
|
return cacheControlValue;
|
|
621
647
|
}
|
|
648
|
+
var CacheControlValidator = class {
|
|
649
|
+
constructor() {
|
|
650
|
+
this.breakpointCount = 0;
|
|
651
|
+
this.warnings = [];
|
|
652
|
+
}
|
|
653
|
+
getCacheControl(providerMetadata, context) {
|
|
654
|
+
const cacheControlValue = getCacheControl(providerMetadata);
|
|
655
|
+
if (!cacheControlValue) {
|
|
656
|
+
return void 0;
|
|
657
|
+
}
|
|
658
|
+
if (!context.canCache) {
|
|
659
|
+
this.warnings.push({
|
|
660
|
+
type: "unsupported-setting",
|
|
661
|
+
setting: "cacheControl",
|
|
662
|
+
details: `cache_control cannot be set on ${context.type}. It will be ignored.`
|
|
663
|
+
});
|
|
664
|
+
return void 0;
|
|
665
|
+
}
|
|
666
|
+
this.breakpointCount++;
|
|
667
|
+
if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {
|
|
668
|
+
this.warnings.push({
|
|
669
|
+
type: "unsupported-setting",
|
|
670
|
+
setting: "cacheControl",
|
|
671
|
+
details: `Maximum ${MAX_CACHE_BREAKPOINTS} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`
|
|
672
|
+
});
|
|
673
|
+
return void 0;
|
|
674
|
+
}
|
|
675
|
+
return cacheControlValue;
|
|
676
|
+
}
|
|
677
|
+
getWarnings() {
|
|
678
|
+
return this.warnings;
|
|
679
|
+
}
|
|
680
|
+
};
|
|
622
681
|
|
|
623
682
|
// src/tool/text-editor_20250728.ts
|
|
624
683
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
@@ -764,11 +823,13 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
764
823
|
async function prepareTools({
|
|
765
824
|
tools,
|
|
766
825
|
toolChoice,
|
|
767
|
-
disableParallelToolUse
|
|
826
|
+
disableParallelToolUse,
|
|
827
|
+
cacheControlValidator
|
|
768
828
|
}) {
|
|
769
829
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
770
830
|
const toolWarnings = [];
|
|
771
831
|
const betas = /* @__PURE__ */ new Set();
|
|
832
|
+
const validator = cacheControlValidator || new CacheControlValidator();
|
|
772
833
|
if (tools == null) {
|
|
773
834
|
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
774
835
|
}
|
|
@@ -776,7 +837,10 @@ async function prepareTools({
|
|
|
776
837
|
for (const tool of tools) {
|
|
777
838
|
switch (tool.type) {
|
|
778
839
|
case "function": {
|
|
779
|
-
const cacheControl = getCacheControl(tool.providerOptions
|
|
840
|
+
const cacheControl = validator.getCacheControl(tool.providerOptions, {
|
|
841
|
+
type: "tool definition",
|
|
842
|
+
canCache: true
|
|
843
|
+
});
|
|
780
844
|
anthropicTools2.push({
|
|
781
845
|
name: tool.name,
|
|
782
846
|
description: tool.description,
|
|
@@ -791,7 +855,8 @@ async function prepareTools({
|
|
|
791
855
|
betas.add("code-execution-2025-05-22");
|
|
792
856
|
anthropicTools2.push({
|
|
793
857
|
type: "code_execution_20250522",
|
|
794
|
-
name: "code_execution"
|
|
858
|
+
name: "code_execution",
|
|
859
|
+
cache_control: void 0
|
|
795
860
|
});
|
|
796
861
|
break;
|
|
797
862
|
}
|
|
@@ -810,7 +875,8 @@ async function prepareTools({
|
|
|
810
875
|
type: "computer_20250124",
|
|
811
876
|
display_width_px: tool.args.displayWidthPx,
|
|
812
877
|
display_height_px: tool.args.displayHeightPx,
|
|
813
|
-
display_number: tool.args.displayNumber
|
|
878
|
+
display_number: tool.args.displayNumber,
|
|
879
|
+
cache_control: void 0
|
|
814
880
|
});
|
|
815
881
|
break;
|
|
816
882
|
}
|
|
@@ -821,7 +887,8 @@ async function prepareTools({
|
|
|
821
887
|
type: "computer_20241022",
|
|
822
888
|
display_width_px: tool.args.displayWidthPx,
|
|
823
889
|
display_height_px: tool.args.displayHeightPx,
|
|
824
|
-
display_number: tool.args.displayNumber
|
|
890
|
+
display_number: tool.args.displayNumber,
|
|
891
|
+
cache_control: void 0
|
|
825
892
|
});
|
|
826
893
|
break;
|
|
827
894
|
}
|
|
@@ -829,7 +896,8 @@ async function prepareTools({
|
|
|
829
896
|
betas.add("computer-use-2025-01-24");
|
|
830
897
|
anthropicTools2.push({
|
|
831
898
|
name: "str_replace_editor",
|
|
832
|
-
type: "text_editor_20250124"
|
|
899
|
+
type: "text_editor_20250124",
|
|
900
|
+
cache_control: void 0
|
|
833
901
|
});
|
|
834
902
|
break;
|
|
835
903
|
}
|
|
@@ -837,7 +905,8 @@ async function prepareTools({
|
|
|
837
905
|
betas.add("computer-use-2024-10-22");
|
|
838
906
|
anthropicTools2.push({
|
|
839
907
|
name: "str_replace_editor",
|
|
840
|
-
type: "text_editor_20241022"
|
|
908
|
+
type: "text_editor_20241022",
|
|
909
|
+
cache_control: void 0
|
|
841
910
|
});
|
|
842
911
|
break;
|
|
843
912
|
}
|
|
@@ -845,7 +914,8 @@ async function prepareTools({
|
|
|
845
914
|
betas.add("computer-use-2025-01-24");
|
|
846
915
|
anthropicTools2.push({
|
|
847
916
|
name: "str_replace_based_edit_tool",
|
|
848
|
-
type: "text_editor_20250429"
|
|
917
|
+
type: "text_editor_20250429",
|
|
918
|
+
cache_control: void 0
|
|
849
919
|
});
|
|
850
920
|
break;
|
|
851
921
|
}
|
|
@@ -857,7 +927,8 @@ async function prepareTools({
|
|
|
857
927
|
anthropicTools2.push({
|
|
858
928
|
name: "str_replace_based_edit_tool",
|
|
859
929
|
type: "text_editor_20250728",
|
|
860
|
-
max_characters: args.maxCharacters
|
|
930
|
+
max_characters: args.maxCharacters,
|
|
931
|
+
cache_control: void 0
|
|
861
932
|
});
|
|
862
933
|
break;
|
|
863
934
|
}
|
|
@@ -865,7 +936,8 @@ async function prepareTools({
|
|
|
865
936
|
betas.add("computer-use-2025-01-24");
|
|
866
937
|
anthropicTools2.push({
|
|
867
938
|
name: "bash",
|
|
868
|
-
type: "bash_20250124"
|
|
939
|
+
type: "bash_20250124",
|
|
940
|
+
cache_control: void 0
|
|
869
941
|
});
|
|
870
942
|
break;
|
|
871
943
|
}
|
|
@@ -873,7 +945,8 @@ async function prepareTools({
|
|
|
873
945
|
betas.add("computer-use-2024-10-22");
|
|
874
946
|
anthropicTools2.push({
|
|
875
947
|
name: "bash",
|
|
876
|
-
type: "bash_20241022"
|
|
948
|
+
type: "bash_20241022",
|
|
949
|
+
cache_control: void 0
|
|
877
950
|
});
|
|
878
951
|
break;
|
|
879
952
|
}
|
|
@@ -898,7 +971,8 @@ async function prepareTools({
|
|
|
898
971
|
allowed_domains: args.allowedDomains,
|
|
899
972
|
blocked_domains: args.blockedDomains,
|
|
900
973
|
citations: args.citations,
|
|
901
|
-
max_content_tokens: args.maxContentTokens
|
|
974
|
+
max_content_tokens: args.maxContentTokens,
|
|
975
|
+
cache_control: void 0
|
|
902
976
|
});
|
|
903
977
|
break;
|
|
904
978
|
}
|
|
@@ -913,7 +987,8 @@ async function prepareTools({
|
|
|
913
987
|
max_uses: args.maxUses,
|
|
914
988
|
allowed_domains: args.allowedDomains,
|
|
915
989
|
blocked_domains: args.blockedDomains,
|
|
916
|
-
user_location: args.userLocation
|
|
990
|
+
user_location: args.userLocation,
|
|
991
|
+
cache_control: void 0
|
|
917
992
|
});
|
|
918
993
|
break;
|
|
919
994
|
}
|
|
@@ -1125,11 +1200,13 @@ function convertToString(data) {
|
|
|
1125
1200
|
async function convertToAnthropicMessagesPrompt({
|
|
1126
1201
|
prompt,
|
|
1127
1202
|
sendReasoning,
|
|
1128
|
-
warnings
|
|
1203
|
+
warnings,
|
|
1204
|
+
cacheControlValidator
|
|
1129
1205
|
}) {
|
|
1130
1206
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1131
1207
|
const betas = /* @__PURE__ */ new Set();
|
|
1132
1208
|
const blocks = groupIntoBlocks(prompt);
|
|
1209
|
+
const validator = cacheControlValidator || new CacheControlValidator();
|
|
1133
1210
|
let system = void 0;
|
|
1134
1211
|
const messages = [];
|
|
1135
1212
|
async function shouldEnableCitations(providerMetadata) {
|
|
@@ -1166,7 +1243,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1166
1243
|
system = block.messages.map(({ content, providerOptions }) => ({
|
|
1167
1244
|
type: "text",
|
|
1168
1245
|
text: content,
|
|
1169
|
-
cache_control: getCacheControl(providerOptions
|
|
1246
|
+
cache_control: validator.getCacheControl(providerOptions, {
|
|
1247
|
+
type: "system message",
|
|
1248
|
+
canCache: true
|
|
1249
|
+
})
|
|
1170
1250
|
}));
|
|
1171
1251
|
break;
|
|
1172
1252
|
}
|
|
@@ -1179,7 +1259,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1179
1259
|
for (let j = 0; j < content.length; j++) {
|
|
1180
1260
|
const part = content[j];
|
|
1181
1261
|
const isLastPart = j === content.length - 1;
|
|
1182
|
-
const cacheControl = (_a = getCacheControl(part.providerOptions
|
|
1262
|
+
const cacheControl = (_a = validator.getCacheControl(part.providerOptions, {
|
|
1263
|
+
type: "user message part",
|
|
1264
|
+
canCache: true
|
|
1265
|
+
})) != null ? _a : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1266
|
+
type: "user message",
|
|
1267
|
+
canCache: true
|
|
1268
|
+
}) : void 0;
|
|
1183
1269
|
switch (part.type) {
|
|
1184
1270
|
case "text": {
|
|
1185
1271
|
anthropicContent.push({
|
|
@@ -1267,7 +1353,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1267
1353
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
1268
1354
|
const part = content[i2];
|
|
1269
1355
|
const isLastPart = i2 === content.length - 1;
|
|
1270
|
-
const cacheControl = (_d = getCacheControl(part.providerOptions
|
|
1356
|
+
const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
|
|
1357
|
+
type: "tool result part",
|
|
1358
|
+
canCache: true
|
|
1359
|
+
})) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1360
|
+
type: "tool result message",
|
|
1361
|
+
canCache: true
|
|
1362
|
+
}) : void 0;
|
|
1271
1363
|
const output = part.output;
|
|
1272
1364
|
let contentValue;
|
|
1273
1365
|
switch (output.type) {
|
|
@@ -1277,8 +1369,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1277
1369
|
case "text":
|
|
1278
1370
|
return {
|
|
1279
1371
|
type: "text",
|
|
1280
|
-
text: contentPart.text
|
|
1281
|
-
cache_control: cacheControl
|
|
1372
|
+
text: contentPart.text
|
|
1282
1373
|
};
|
|
1283
1374
|
case "image-data": {
|
|
1284
1375
|
return {
|
|
@@ -1287,8 +1378,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1287
1378
|
type: "base64",
|
|
1288
1379
|
media_type: contentPart.mediaType,
|
|
1289
1380
|
data: contentPart.data
|
|
1290
|
-
}
|
|
1291
|
-
cache_control: cacheControl
|
|
1381
|
+
}
|
|
1292
1382
|
};
|
|
1293
1383
|
}
|
|
1294
1384
|
case "file-data": {
|
|
@@ -1300,8 +1390,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1300
1390
|
type: "base64",
|
|
1301
1391
|
media_type: contentPart.mediaType,
|
|
1302
1392
|
data: contentPart.data
|
|
1303
|
-
}
|
|
1304
|
-
cache_control: cacheControl
|
|
1393
|
+
}
|
|
1305
1394
|
};
|
|
1306
1395
|
}
|
|
1307
1396
|
warnings.push({
|
|
@@ -1362,7 +1451,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1362
1451
|
for (let k = 0; k < content.length; k++) {
|
|
1363
1452
|
const part = content[k];
|
|
1364
1453
|
const isLastContentPart = k === content.length - 1;
|
|
1365
|
-
const cacheControl = (_f = getCacheControl(part.providerOptions
|
|
1454
|
+
const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
|
|
1455
|
+
type: "assistant message part",
|
|
1456
|
+
canCache: true
|
|
1457
|
+
})) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
1458
|
+
type: "assistant message",
|
|
1459
|
+
canCache: true
|
|
1460
|
+
}) : void 0;
|
|
1366
1461
|
switch (part.type) {
|
|
1367
1462
|
case "text": {
|
|
1368
1463
|
anthropicContent.push({
|
|
@@ -1386,17 +1481,23 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1386
1481
|
});
|
|
1387
1482
|
if (reasoningMetadata != null) {
|
|
1388
1483
|
if (reasoningMetadata.signature != null) {
|
|
1484
|
+
validator.getCacheControl(part.providerOptions, {
|
|
1485
|
+
type: "thinking block",
|
|
1486
|
+
canCache: false
|
|
1487
|
+
});
|
|
1389
1488
|
anthropicContent.push({
|
|
1390
1489
|
type: "thinking",
|
|
1391
1490
|
thinking: part.text,
|
|
1392
|
-
signature: reasoningMetadata.signature
|
|
1393
|
-
cache_control: cacheControl
|
|
1491
|
+
signature: reasoningMetadata.signature
|
|
1394
1492
|
});
|
|
1395
1493
|
} else if (reasoningMetadata.redactedData != null) {
|
|
1494
|
+
validator.getCacheControl(part.providerOptions, {
|
|
1495
|
+
type: "redacted thinking block",
|
|
1496
|
+
canCache: false
|
|
1497
|
+
});
|
|
1396
1498
|
anthropicContent.push({
|
|
1397
1499
|
type: "redacted_thinking",
|
|
1398
|
-
data: reasoningMetadata.redactedData
|
|
1399
|
-
cache_control: cacheControl
|
|
1500
|
+
data: reasoningMetadata.redactedData
|
|
1400
1501
|
});
|
|
1401
1502
|
} else {
|
|
1402
1503
|
warnings.push({
|
|
@@ -1809,10 +1910,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1809
1910
|
providerOptions,
|
|
1810
1911
|
schema: anthropicProviderOptions
|
|
1811
1912
|
});
|
|
1913
|
+
const cacheControlValidator = new CacheControlValidator();
|
|
1812
1914
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1813
1915
|
prompt,
|
|
1814
1916
|
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
1815
|
-
warnings
|
|
1917
|
+
warnings,
|
|
1918
|
+
cacheControlValidator
|
|
1816
1919
|
});
|
|
1817
1920
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
1818
1921
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
@@ -1926,20 +2029,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1926
2029
|
jsonResponseTool != null ? {
|
|
1927
2030
|
tools: [jsonResponseTool],
|
|
1928
2031
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name },
|
|
1929
|
-
disableParallelToolUse: true
|
|
2032
|
+
disableParallelToolUse: true,
|
|
2033
|
+
cacheControlValidator
|
|
1930
2034
|
} : {
|
|
1931
2035
|
tools: tools != null ? tools : [],
|
|
1932
2036
|
toolChoice,
|
|
1933
|
-
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
2037
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
|
|
2038
|
+
cacheControlValidator
|
|
1934
2039
|
}
|
|
1935
2040
|
);
|
|
2041
|
+
const cacheWarnings = cacheControlValidator.getWarnings();
|
|
1936
2042
|
return {
|
|
1937
2043
|
args: {
|
|
1938
2044
|
...baseArgs,
|
|
1939
2045
|
tools: anthropicTools2,
|
|
1940
2046
|
tool_choice: anthropicToolChoice
|
|
1941
2047
|
},
|
|
1942
|
-
warnings: [...warnings, ...toolWarnings],
|
|
2048
|
+
warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
|
|
1943
2049
|
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
|
|
1944
2050
|
usesJsonResponseTool: jsonResponseTool != null
|
|
1945
2051
|
};
|
|
@@ -1986,7 +2092,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1986
2092
|
});
|
|
1987
2093
|
}
|
|
1988
2094
|
async doGenerate(options) {
|
|
1989
|
-
var _a, _b, _c, _d, _e, _f;
|
|
2095
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1990
2096
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
1991
2097
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
1992
2098
|
const {
|
|
@@ -2269,7 +2375,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2269
2375
|
anthropic: {
|
|
2270
2376
|
usage: response.usage,
|
|
2271
2377
|
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
|
|
2272
|
-
stopSequence: (_f = response.stop_sequence) != null ? _f : null
|
|
2378
|
+
stopSequence: (_f = response.stop_sequence) != null ? _f : null,
|
|
2379
|
+
container: response.container ? {
|
|
2380
|
+
expiresAt: response.container.expires_at,
|
|
2381
|
+
id: response.container.id,
|
|
2382
|
+
skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
|
|
2383
|
+
type: skill.type,
|
|
2384
|
+
skillId: skill.skill_id,
|
|
2385
|
+
version: skill.version
|
|
2386
|
+
}))) != null ? _h : null
|
|
2387
|
+
} : null
|
|
2273
2388
|
}
|
|
2274
2389
|
}
|
|
2275
2390
|
};
|
|
@@ -2300,6 +2415,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2300
2415
|
let rawUsage = void 0;
|
|
2301
2416
|
let cacheCreationInputTokens = null;
|
|
2302
2417
|
let stopSequence = null;
|
|
2418
|
+
let container = null;
|
|
2303
2419
|
let blockType = void 0;
|
|
2304
2420
|
const generateId3 = this.generateId;
|
|
2305
2421
|
return {
|
|
@@ -2309,7 +2425,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2309
2425
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2310
2426
|
},
|
|
2311
2427
|
transform(chunk, controller) {
|
|
2312
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2428
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2313
2429
|
if (options.includeRawChunks) {
|
|
2314
2430
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2315
2431
|
}
|
|
@@ -2718,6 +2834,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2718
2834
|
isJsonResponseFromTool: usesJsonResponseTool
|
|
2719
2835
|
});
|
|
2720
2836
|
stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
|
|
2837
|
+
container = value.delta.container != null ? {
|
|
2838
|
+
expiresAt: value.delta.container.expires_at,
|
|
2839
|
+
id: value.delta.container.id,
|
|
2840
|
+
skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
2841
|
+
type: skill.type,
|
|
2842
|
+
skillId: skill.skill_id,
|
|
2843
|
+
version: skill.version
|
|
2844
|
+
}))) != null ? _j : null
|
|
2845
|
+
} : null;
|
|
2721
2846
|
rawUsage = {
|
|
2722
2847
|
...rawUsage,
|
|
2723
2848
|
...value.usage
|
|
@@ -2733,7 +2858,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2733
2858
|
anthropic: {
|
|
2734
2859
|
usage: rawUsage != null ? rawUsage : null,
|
|
2735
2860
|
cacheCreationInputTokens,
|
|
2736
|
-
stopSequence
|
|
2861
|
+
stopSequence,
|
|
2862
|
+
container
|
|
2737
2863
|
}
|
|
2738
2864
|
}
|
|
2739
2865
|
});
|