@ai-sdk/anthropic 2.0.32 → 2.0.34
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
|
+
## 2.0.34
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 65f2628: feat(provider/anthropic): expose container from response in provider metadata
|
|
8
|
+
|
|
9
|
+
## 2.0.33
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 28c9c6a: feat(anthropic): add prompt caching validation
|
|
14
|
+
|
|
3
15
|
## 2.0.32
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,47 @@
|
|
|
1
|
+
import { JSONObject, ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
|
|
1
2
|
import { z } from 'zod/v4';
|
|
2
|
-
import { ProviderV2, LanguageModelV2 } 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>;
|
|
@@ -504,4 +543,4 @@ declare const anthropic: AnthropicProvider;
|
|
|
504
543
|
|
|
505
544
|
declare const VERSION: string;
|
|
506
545
|
|
|
507
|
-
export { type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, VERSION, anthropic, createAnthropic };
|
|
546
|
+
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, ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
|
|
1
2
|
import { z } from 'zod/v4';
|
|
2
|
-
import { ProviderV2, LanguageModelV2 } 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>;
|
|
@@ -504,4 +543,4 @@ declare const anthropic: AnthropicProvider;
|
|
|
504
543
|
|
|
505
544
|
declare const VERSION: string;
|
|
506
545
|
|
|
507
|
-
export { type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, VERSION, anthropic, createAnthropic };
|
|
546
|
+
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 ? "2.0.
|
|
34
|
+
var VERSION = true ? "2.0.34" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -245,7 +245,18 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
245
245
|
output_tokens: import_v42.z.number(),
|
|
246
246
|
cache_creation_input_tokens: import_v42.z.number().nullish(),
|
|
247
247
|
cache_read_input_tokens: import_v42.z.number().nullish()
|
|
248
|
-
})
|
|
248
|
+
}),
|
|
249
|
+
container: import_v42.z.object({
|
|
250
|
+
expires_at: import_v42.z.string(),
|
|
251
|
+
id: import_v42.z.string(),
|
|
252
|
+
skills: import_v42.z.array(
|
|
253
|
+
import_v42.z.object({
|
|
254
|
+
type: import_v42.z.union([import_v42.z.literal("anthropic"), import_v42.z.literal("custom")]),
|
|
255
|
+
skill_id: import_v42.z.string(),
|
|
256
|
+
version: import_v42.z.string()
|
|
257
|
+
})
|
|
258
|
+
).nullish()
|
|
259
|
+
}).nullish()
|
|
249
260
|
})
|
|
250
261
|
)
|
|
251
262
|
);
|
|
@@ -475,7 +486,21 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
475
486
|
type: import_v42.z.literal("message_delta"),
|
|
476
487
|
delta: import_v42.z.object({
|
|
477
488
|
stop_reason: import_v42.z.string().nullish(),
|
|
478
|
-
stop_sequence: import_v42.z.string().nullish()
|
|
489
|
+
stop_sequence: import_v42.z.string().nullish(),
|
|
490
|
+
container: import_v42.z.object({
|
|
491
|
+
expires_at: import_v42.z.string(),
|
|
492
|
+
id: import_v42.z.string(),
|
|
493
|
+
skills: import_v42.z.array(
|
|
494
|
+
import_v42.z.object({
|
|
495
|
+
type: import_v42.z.union([
|
|
496
|
+
import_v42.z.literal("anthropic"),
|
|
497
|
+
import_v42.z.literal("custom")
|
|
498
|
+
]),
|
|
499
|
+
skill_id: import_v42.z.string(),
|
|
500
|
+
version: import_v42.z.string()
|
|
501
|
+
})
|
|
502
|
+
).nullish()
|
|
503
|
+
}).nullish()
|
|
479
504
|
}),
|
|
480
505
|
usage: import_v42.z.looseObject({
|
|
481
506
|
output_tokens: import_v42.z.number(),
|
|
@@ -565,12 +590,46 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
565
590
|
var import_provider = require("@ai-sdk/provider");
|
|
566
591
|
|
|
567
592
|
// src/get-cache-control.ts
|
|
593
|
+
var MAX_CACHE_BREAKPOINTS = 4;
|
|
568
594
|
function getCacheControl(providerMetadata) {
|
|
569
595
|
var _a;
|
|
570
596
|
const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
571
597
|
const cacheControlValue = (_a = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
572
598
|
return cacheControlValue;
|
|
573
599
|
}
|
|
600
|
+
var CacheControlValidator = class {
|
|
601
|
+
constructor() {
|
|
602
|
+
this.breakpointCount = 0;
|
|
603
|
+
this.warnings = [];
|
|
604
|
+
}
|
|
605
|
+
getCacheControl(providerMetadata, context) {
|
|
606
|
+
const cacheControlValue = getCacheControl(providerMetadata);
|
|
607
|
+
if (!cacheControlValue) {
|
|
608
|
+
return void 0;
|
|
609
|
+
}
|
|
610
|
+
if (!context.canCache) {
|
|
611
|
+
this.warnings.push({
|
|
612
|
+
type: "unsupported-setting",
|
|
613
|
+
setting: "cacheControl",
|
|
614
|
+
details: `cache_control cannot be set on ${context.type}. It will be ignored.`
|
|
615
|
+
});
|
|
616
|
+
return void 0;
|
|
617
|
+
}
|
|
618
|
+
this.breakpointCount++;
|
|
619
|
+
if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {
|
|
620
|
+
this.warnings.push({
|
|
621
|
+
type: "unsupported-setting",
|
|
622
|
+
setting: "cacheControl",
|
|
623
|
+
details: `Maximum ${MAX_CACHE_BREAKPOINTS} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`
|
|
624
|
+
});
|
|
625
|
+
return void 0;
|
|
626
|
+
}
|
|
627
|
+
return cacheControlValue;
|
|
628
|
+
}
|
|
629
|
+
getWarnings() {
|
|
630
|
+
return this.warnings;
|
|
631
|
+
}
|
|
632
|
+
};
|
|
574
633
|
|
|
575
634
|
// src/tool/text-editor_20250728.ts
|
|
576
635
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
@@ -716,11 +775,13 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
716
775
|
async function prepareTools({
|
|
717
776
|
tools,
|
|
718
777
|
toolChoice,
|
|
719
|
-
disableParallelToolUse
|
|
778
|
+
disableParallelToolUse,
|
|
779
|
+
cacheControlValidator
|
|
720
780
|
}) {
|
|
721
781
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
722
782
|
const toolWarnings = [];
|
|
723
783
|
const betas = /* @__PURE__ */ new Set();
|
|
784
|
+
const validator = cacheControlValidator || new CacheControlValidator();
|
|
724
785
|
if (tools == null) {
|
|
725
786
|
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
726
787
|
}
|
|
@@ -728,7 +789,10 @@ async function prepareTools({
|
|
|
728
789
|
for (const tool of tools) {
|
|
729
790
|
switch (tool.type) {
|
|
730
791
|
case "function": {
|
|
731
|
-
const cacheControl = getCacheControl(tool.providerOptions
|
|
792
|
+
const cacheControl = validator.getCacheControl(tool.providerOptions, {
|
|
793
|
+
type: "tool definition",
|
|
794
|
+
canCache: true
|
|
795
|
+
});
|
|
732
796
|
anthropicTools2.push({
|
|
733
797
|
name: tool.name,
|
|
734
798
|
description: tool.description,
|
|
@@ -743,7 +807,8 @@ async function prepareTools({
|
|
|
743
807
|
betas.add("code-execution-2025-05-22");
|
|
744
808
|
anthropicTools2.push({
|
|
745
809
|
type: "code_execution_20250522",
|
|
746
|
-
name: "code_execution"
|
|
810
|
+
name: "code_execution",
|
|
811
|
+
cache_control: void 0
|
|
747
812
|
});
|
|
748
813
|
break;
|
|
749
814
|
}
|
|
@@ -762,7 +827,8 @@ async function prepareTools({
|
|
|
762
827
|
type: "computer_20250124",
|
|
763
828
|
display_width_px: tool.args.displayWidthPx,
|
|
764
829
|
display_height_px: tool.args.displayHeightPx,
|
|
765
|
-
display_number: tool.args.displayNumber
|
|
830
|
+
display_number: tool.args.displayNumber,
|
|
831
|
+
cache_control: void 0
|
|
766
832
|
});
|
|
767
833
|
break;
|
|
768
834
|
}
|
|
@@ -773,7 +839,8 @@ async function prepareTools({
|
|
|
773
839
|
type: "computer_20241022",
|
|
774
840
|
display_width_px: tool.args.displayWidthPx,
|
|
775
841
|
display_height_px: tool.args.displayHeightPx,
|
|
776
|
-
display_number: tool.args.displayNumber
|
|
842
|
+
display_number: tool.args.displayNumber,
|
|
843
|
+
cache_control: void 0
|
|
777
844
|
});
|
|
778
845
|
break;
|
|
779
846
|
}
|
|
@@ -781,7 +848,8 @@ async function prepareTools({
|
|
|
781
848
|
betas.add("computer-use-2025-01-24");
|
|
782
849
|
anthropicTools2.push({
|
|
783
850
|
name: "str_replace_editor",
|
|
784
|
-
type: "text_editor_20250124"
|
|
851
|
+
type: "text_editor_20250124",
|
|
852
|
+
cache_control: void 0
|
|
785
853
|
});
|
|
786
854
|
break;
|
|
787
855
|
}
|
|
@@ -789,7 +857,8 @@ async function prepareTools({
|
|
|
789
857
|
betas.add("computer-use-2024-10-22");
|
|
790
858
|
anthropicTools2.push({
|
|
791
859
|
name: "str_replace_editor",
|
|
792
|
-
type: "text_editor_20241022"
|
|
860
|
+
type: "text_editor_20241022",
|
|
861
|
+
cache_control: void 0
|
|
793
862
|
});
|
|
794
863
|
break;
|
|
795
864
|
}
|
|
@@ -797,7 +866,8 @@ async function prepareTools({
|
|
|
797
866
|
betas.add("computer-use-2025-01-24");
|
|
798
867
|
anthropicTools2.push({
|
|
799
868
|
name: "str_replace_based_edit_tool",
|
|
800
|
-
type: "text_editor_20250429"
|
|
869
|
+
type: "text_editor_20250429",
|
|
870
|
+
cache_control: void 0
|
|
801
871
|
});
|
|
802
872
|
break;
|
|
803
873
|
}
|
|
@@ -809,7 +879,8 @@ async function prepareTools({
|
|
|
809
879
|
anthropicTools2.push({
|
|
810
880
|
name: "str_replace_based_edit_tool",
|
|
811
881
|
type: "text_editor_20250728",
|
|
812
|
-
max_characters: args.maxCharacters
|
|
882
|
+
max_characters: args.maxCharacters,
|
|
883
|
+
cache_control: void 0
|
|
813
884
|
});
|
|
814
885
|
break;
|
|
815
886
|
}
|
|
@@ -817,7 +888,8 @@ async function prepareTools({
|
|
|
817
888
|
betas.add("computer-use-2025-01-24");
|
|
818
889
|
anthropicTools2.push({
|
|
819
890
|
name: "bash",
|
|
820
|
-
type: "bash_20250124"
|
|
891
|
+
type: "bash_20250124",
|
|
892
|
+
cache_control: void 0
|
|
821
893
|
});
|
|
822
894
|
break;
|
|
823
895
|
}
|
|
@@ -825,7 +897,8 @@ async function prepareTools({
|
|
|
825
897
|
betas.add("computer-use-2024-10-22");
|
|
826
898
|
anthropicTools2.push({
|
|
827
899
|
name: "bash",
|
|
828
|
-
type: "bash_20241022"
|
|
900
|
+
type: "bash_20241022",
|
|
901
|
+
cache_control: void 0
|
|
829
902
|
});
|
|
830
903
|
break;
|
|
831
904
|
}
|
|
@@ -850,7 +923,8 @@ async function prepareTools({
|
|
|
850
923
|
allowed_domains: args.allowedDomains,
|
|
851
924
|
blocked_domains: args.blockedDomains,
|
|
852
925
|
citations: args.citations,
|
|
853
|
-
max_content_tokens: args.maxContentTokens
|
|
926
|
+
max_content_tokens: args.maxContentTokens,
|
|
927
|
+
cache_control: void 0
|
|
854
928
|
});
|
|
855
929
|
break;
|
|
856
930
|
}
|
|
@@ -865,7 +939,8 @@ async function prepareTools({
|
|
|
865
939
|
max_uses: args.maxUses,
|
|
866
940
|
allowed_domains: args.allowedDomains,
|
|
867
941
|
blocked_domains: args.blockedDomains,
|
|
868
|
-
user_location: args.userLocation
|
|
942
|
+
user_location: args.userLocation,
|
|
943
|
+
cache_control: void 0
|
|
869
944
|
});
|
|
870
945
|
break;
|
|
871
946
|
}
|
|
@@ -1077,11 +1152,13 @@ function convertToString(data) {
|
|
|
1077
1152
|
async function convertToAnthropicMessagesPrompt({
|
|
1078
1153
|
prompt,
|
|
1079
1154
|
sendReasoning,
|
|
1080
|
-
warnings
|
|
1155
|
+
warnings,
|
|
1156
|
+
cacheControlValidator
|
|
1081
1157
|
}) {
|
|
1082
1158
|
var _a, _b, _c, _d, _e;
|
|
1083
1159
|
const betas = /* @__PURE__ */ new Set();
|
|
1084
1160
|
const blocks = groupIntoBlocks(prompt);
|
|
1161
|
+
const validator = cacheControlValidator || new CacheControlValidator();
|
|
1085
1162
|
let system = void 0;
|
|
1086
1163
|
const messages = [];
|
|
1087
1164
|
async function shouldEnableCitations(providerMetadata) {
|
|
@@ -1118,7 +1195,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1118
1195
|
system = block.messages.map(({ content, providerOptions }) => ({
|
|
1119
1196
|
type: "text",
|
|
1120
1197
|
text: content,
|
|
1121
|
-
cache_control: getCacheControl(providerOptions
|
|
1198
|
+
cache_control: validator.getCacheControl(providerOptions, {
|
|
1199
|
+
type: "system message",
|
|
1200
|
+
canCache: true
|
|
1201
|
+
})
|
|
1122
1202
|
}));
|
|
1123
1203
|
break;
|
|
1124
1204
|
}
|
|
@@ -1131,7 +1211,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1131
1211
|
for (let j = 0; j < content.length; j++) {
|
|
1132
1212
|
const part = content[j];
|
|
1133
1213
|
const isLastPart = j === content.length - 1;
|
|
1134
|
-
const cacheControl = (_a = getCacheControl(part.providerOptions
|
|
1214
|
+
const cacheControl = (_a = validator.getCacheControl(part.providerOptions, {
|
|
1215
|
+
type: "user message part",
|
|
1216
|
+
canCache: true
|
|
1217
|
+
})) != null ? _a : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1218
|
+
type: "user message",
|
|
1219
|
+
canCache: true
|
|
1220
|
+
}) : void 0;
|
|
1135
1221
|
switch (part.type) {
|
|
1136
1222
|
case "text": {
|
|
1137
1223
|
anthropicContent.push({
|
|
@@ -1219,7 +1305,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1219
1305
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
1220
1306
|
const part = content[i2];
|
|
1221
1307
|
const isLastPart = i2 === content.length - 1;
|
|
1222
|
-
const cacheControl = (_d = getCacheControl(part.providerOptions
|
|
1308
|
+
const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
|
|
1309
|
+
type: "tool result part",
|
|
1310
|
+
canCache: true
|
|
1311
|
+
})) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
1312
|
+
type: "tool result message",
|
|
1313
|
+
canCache: true
|
|
1314
|
+
}) : void 0;
|
|
1223
1315
|
const output = part.output;
|
|
1224
1316
|
let contentValue;
|
|
1225
1317
|
switch (output.type) {
|
|
@@ -1229,8 +1321,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1229
1321
|
case "text":
|
|
1230
1322
|
return {
|
|
1231
1323
|
type: "text",
|
|
1232
|
-
text: contentPart.text
|
|
1233
|
-
cache_control: void 0
|
|
1324
|
+
text: contentPart.text
|
|
1234
1325
|
};
|
|
1235
1326
|
case "media": {
|
|
1236
1327
|
if (contentPart.mediaType.startsWith("image/")) {
|
|
@@ -1240,8 +1331,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1240
1331
|
type: "base64",
|
|
1241
1332
|
media_type: contentPart.mediaType,
|
|
1242
1333
|
data: contentPart.data
|
|
1243
|
-
}
|
|
1244
|
-
cache_control: void 0
|
|
1334
|
+
}
|
|
1245
1335
|
};
|
|
1246
1336
|
}
|
|
1247
1337
|
if (contentPart.mediaType === "application/pdf") {
|
|
@@ -1252,8 +1342,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1252
1342
|
type: "base64",
|
|
1253
1343
|
media_type: contentPart.mediaType,
|
|
1254
1344
|
data: contentPart.data
|
|
1255
|
-
}
|
|
1256
|
-
cache_control: void 0
|
|
1345
|
+
}
|
|
1257
1346
|
};
|
|
1258
1347
|
}
|
|
1259
1348
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
@@ -1301,7 +1390,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1301
1390
|
for (let k = 0; k < content.length; k++) {
|
|
1302
1391
|
const part = content[k];
|
|
1303
1392
|
const isLastContentPart = k === content.length - 1;
|
|
1304
|
-
const cacheControl = (_e = getCacheControl(part.providerOptions
|
|
1393
|
+
const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
|
|
1394
|
+
type: "assistant message part",
|
|
1395
|
+
canCache: true
|
|
1396
|
+
})) != null ? _e : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
1397
|
+
type: "assistant message",
|
|
1398
|
+
canCache: true
|
|
1399
|
+
}) : void 0;
|
|
1305
1400
|
switch (part.type) {
|
|
1306
1401
|
case "text": {
|
|
1307
1402
|
anthropicContent.push({
|
|
@@ -1325,17 +1420,23 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1325
1420
|
});
|
|
1326
1421
|
if (reasoningMetadata != null) {
|
|
1327
1422
|
if (reasoningMetadata.signature != null) {
|
|
1423
|
+
validator.getCacheControl(part.providerOptions, {
|
|
1424
|
+
type: "thinking block",
|
|
1425
|
+
canCache: false
|
|
1426
|
+
});
|
|
1328
1427
|
anthropicContent.push({
|
|
1329
1428
|
type: "thinking",
|
|
1330
1429
|
thinking: part.text,
|
|
1331
|
-
signature: reasoningMetadata.signature
|
|
1332
|
-
cache_control: cacheControl
|
|
1430
|
+
signature: reasoningMetadata.signature
|
|
1333
1431
|
});
|
|
1334
1432
|
} else if (reasoningMetadata.redactedData != null) {
|
|
1433
|
+
validator.getCacheControl(part.providerOptions, {
|
|
1434
|
+
type: "redacted thinking block",
|
|
1435
|
+
canCache: false
|
|
1436
|
+
});
|
|
1335
1437
|
anthropicContent.push({
|
|
1336
1438
|
type: "redacted_thinking",
|
|
1337
|
-
data: reasoningMetadata.redactedData
|
|
1338
|
-
cache_control: cacheControl
|
|
1439
|
+
data: reasoningMetadata.redactedData
|
|
1339
1440
|
});
|
|
1340
1441
|
} else {
|
|
1341
1442
|
warnings.push({
|
|
@@ -1710,10 +1811,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1710
1811
|
providerOptions,
|
|
1711
1812
|
schema: anthropicProviderOptions
|
|
1712
1813
|
});
|
|
1814
|
+
const cacheControlValidator = new CacheControlValidator();
|
|
1713
1815
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1714
1816
|
prompt,
|
|
1715
1817
|
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
1716
|
-
warnings
|
|
1818
|
+
warnings,
|
|
1819
|
+
cacheControlValidator
|
|
1717
1820
|
});
|
|
1718
1821
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
1719
1822
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
@@ -1811,20 +1914,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1811
1914
|
jsonResponseTool != null ? {
|
|
1812
1915
|
tools: [jsonResponseTool],
|
|
1813
1916
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name },
|
|
1814
|
-
disableParallelToolUse: true
|
|
1917
|
+
disableParallelToolUse: true,
|
|
1918
|
+
cacheControlValidator
|
|
1815
1919
|
} : {
|
|
1816
1920
|
tools: tools != null ? tools : [],
|
|
1817
1921
|
toolChoice,
|
|
1818
|
-
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
1922
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
|
|
1923
|
+
cacheControlValidator
|
|
1819
1924
|
}
|
|
1820
1925
|
);
|
|
1926
|
+
const cacheWarnings = cacheControlValidator.getWarnings();
|
|
1821
1927
|
return {
|
|
1822
1928
|
args: {
|
|
1823
1929
|
...baseArgs,
|
|
1824
1930
|
tools: anthropicTools2,
|
|
1825
1931
|
tool_choice: anthropicToolChoice
|
|
1826
1932
|
},
|
|
1827
|
-
warnings: [...warnings, ...toolWarnings],
|
|
1933
|
+
warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
|
|
1828
1934
|
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
|
|
1829
1935
|
usesJsonResponseTool: jsonResponseTool != null
|
|
1830
1936
|
};
|
|
@@ -1871,7 +1977,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1871
1977
|
});
|
|
1872
1978
|
}
|
|
1873
1979
|
async doGenerate(options) {
|
|
1874
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1980
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1875
1981
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
1876
1982
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
1877
1983
|
const {
|
|
@@ -2122,7 +2228,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2122
2228
|
anthropic: {
|
|
2123
2229
|
usage: response.usage,
|
|
2124
2230
|
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
|
|
2125
|
-
stopSequence: (_f = response.stop_sequence) != null ? _f : null
|
|
2231
|
+
stopSequence: (_f = response.stop_sequence) != null ? _f : null,
|
|
2232
|
+
container: response.container ? {
|
|
2233
|
+
expiresAt: response.container.expires_at,
|
|
2234
|
+
id: response.container.id,
|
|
2235
|
+
skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
|
|
2236
|
+
type: skill.type,
|
|
2237
|
+
skillId: skill.skill_id,
|
|
2238
|
+
version: skill.version
|
|
2239
|
+
}))) != null ? _h : null
|
|
2240
|
+
} : null
|
|
2126
2241
|
}
|
|
2127
2242
|
}
|
|
2128
2243
|
};
|
|
@@ -2152,6 +2267,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2152
2267
|
let rawUsage = void 0;
|
|
2153
2268
|
let cacheCreationInputTokens = null;
|
|
2154
2269
|
let stopSequence = null;
|
|
2270
|
+
let container = null;
|
|
2155
2271
|
let blockType = void 0;
|
|
2156
2272
|
const generateId3 = this.generateId;
|
|
2157
2273
|
return {
|
|
@@ -2161,7 +2277,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2161
2277
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2162
2278
|
},
|
|
2163
2279
|
transform(chunk, controller) {
|
|
2164
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2280
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2165
2281
|
if (options.includeRawChunks) {
|
|
2166
2282
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2167
2283
|
}
|
|
@@ -2542,6 +2658,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2542
2658
|
isJsonResponseFromTool: usesJsonResponseTool
|
|
2543
2659
|
});
|
|
2544
2660
|
stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
|
|
2661
|
+
container = value.delta.container != null ? {
|
|
2662
|
+
expiresAt: value.delta.container.expires_at,
|
|
2663
|
+
id: value.delta.container.id,
|
|
2664
|
+
skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
2665
|
+
type: skill.type,
|
|
2666
|
+
skillId: skill.skill_id,
|
|
2667
|
+
version: skill.version
|
|
2668
|
+
}))) != null ? _j : null
|
|
2669
|
+
} : null;
|
|
2545
2670
|
rawUsage = {
|
|
2546
2671
|
...rawUsage,
|
|
2547
2672
|
...value.usage
|
|
@@ -2557,7 +2682,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2557
2682
|
anthropic: {
|
|
2558
2683
|
usage: rawUsage != null ? rawUsage : null,
|
|
2559
2684
|
cacheCreationInputTokens,
|
|
2560
|
-
stopSequence
|
|
2685
|
+
stopSequence,
|
|
2686
|
+
container
|
|
2561
2687
|
}
|
|
2562
2688
|
}
|
|
2563
2689
|
});
|