@ai-sdk/amazon-bedrock 3.0.108 → 3.0.109
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/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +52 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 3.0.109
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1b0e540: Use native structured output on supported Bedrock Anthropic models when thinking is enabled instead of forcing a JSON tool call.
|
|
8
|
+
- a5065c5: Pass through `s3://` image URLs to Amazon Bedrock Converse as S3 image sources instead of downloading them.
|
|
9
|
+
- 503e809: fix(provider/amazon-bedrock): omit unsigned reasoning from conversation history
|
|
10
|
+
- de443c2: Sanitize invalid characters in replayed tool call names before sending conversation history to Amazon Bedrock.
|
|
11
|
+
- Updated dependencies [1b0e540]
|
|
12
|
+
- Updated dependencies [5bb3ae4]
|
|
13
|
+
- @ai-sdk/anthropic@2.0.89
|
|
14
|
+
|
|
3
15
|
## 3.0.108
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/anthropic/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
|
35
35
|
var import_aws4fetch = require("aws4fetch");
|
|
36
36
|
|
|
37
37
|
// src/version.ts
|
|
38
|
-
var VERSION = true ? "3.0.
|
|
38
|
+
var VERSION = true ? "3.0.109" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
package/dist/anthropic/index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import { AwsV4Signer } from "aws4fetch";
|
|
25
25
|
|
|
26
26
|
// src/version.ts
|
|
27
|
-
var VERSION = true ? "3.0.
|
|
27
|
+
var VERSION = true ? "3.0.109" : "0.0.0-test";
|
|
28
28
|
|
|
29
29
|
// src/bedrock-sigv4-fetch.ts
|
|
30
30
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
package/dist/index.js
CHANGED
|
@@ -30,12 +30,13 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.109" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/bedrock-provider.ts
|
|
36
|
-
var
|
|
36
|
+
var import_internal3 = require("@ai-sdk/anthropic/internal");
|
|
37
37
|
|
|
38
38
|
// src/bedrock-chat-language-model.ts
|
|
39
|
+
var import_internal2 = require("@ai-sdk/anthropic/internal");
|
|
39
40
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
40
41
|
var import_v44 = require("zod/v4");
|
|
41
42
|
|
|
@@ -376,6 +377,9 @@ async function shouldEnableCitations(providerMetadata) {
|
|
|
376
377
|
});
|
|
377
378
|
return (_b = (_a = bedrockOptions == null ? void 0 : bedrockOptions.citations) == null ? void 0 : _a.enabled) != null ? _b : false;
|
|
378
379
|
}
|
|
380
|
+
function sanitizeToolName(toolName) {
|
|
381
|
+
return toolName.replace(/[^a-zA-Z0-9_-]/g, "") || "_";
|
|
382
|
+
}
|
|
379
383
|
async function convertToBedrockChatMessages(prompt) {
|
|
380
384
|
var _a;
|
|
381
385
|
const blocks = groupIntoBlocks(prompt);
|
|
@@ -419,9 +423,22 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
419
423
|
}
|
|
420
424
|
case "file": {
|
|
421
425
|
if (part.data instanceof URL) {
|
|
422
|
-
|
|
423
|
-
|
|
426
|
+
if (part.data.protocol !== "s3:" || !part.mediaType.startsWith("image/")) {
|
|
427
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
428
|
+
functionality: "File URL data"
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
bedrockContent.push({
|
|
432
|
+
image: {
|
|
433
|
+
format: getBedrockImageFormat(part.mediaType),
|
|
434
|
+
source: {
|
|
435
|
+
s3Location: {
|
|
436
|
+
uri: part.data.toString()
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
424
440
|
});
|
|
441
|
+
break;
|
|
425
442
|
}
|
|
426
443
|
if (part.mediaType.startsWith("image/")) {
|
|
427
444
|
bedrockContent.push({
|
|
@@ -581,21 +598,6 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
581
598
|
}
|
|
582
599
|
});
|
|
583
600
|
}
|
|
584
|
-
} else if (part.providerOptions == null || Object.keys(part.providerOptions).every(
|
|
585
|
-
(k2) => k2 === "bedrock" || k2 === "amazonBedrock"
|
|
586
|
-
)) {
|
|
587
|
-
bedrockContent.push({
|
|
588
|
-
reasoningContent: {
|
|
589
|
-
reasoningText: {
|
|
590
|
-
text: trimIfLast(
|
|
591
|
-
isLastBlock,
|
|
592
|
-
isLastMessage,
|
|
593
|
-
isLastContentPart,
|
|
594
|
-
part.text
|
|
595
|
-
)
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
601
|
}
|
|
600
602
|
break;
|
|
601
603
|
}
|
|
@@ -603,7 +605,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
603
605
|
bedrockContent.push({
|
|
604
606
|
toolUse: {
|
|
605
607
|
toolUseId: part.toolCallId,
|
|
606
|
-
name: part.toolName,
|
|
608
|
+
name: sanitizeToolName(part.toolName),
|
|
607
609
|
input: part.input
|
|
608
610
|
}
|
|
609
611
|
});
|
|
@@ -728,7 +730,7 @@ var BedrockChatLanguageModel = class {
|
|
|
728
730
|
this.specificationVersion = "v2";
|
|
729
731
|
this.provider = "amazon-bedrock";
|
|
730
732
|
this.supportedUrls = {
|
|
731
|
-
|
|
733
|
+
"image/*": [/^s3:\/\//]
|
|
732
734
|
};
|
|
733
735
|
}
|
|
734
736
|
async getArgs({
|
|
@@ -746,7 +748,7 @@ var BedrockChatLanguageModel = class {
|
|
|
746
748
|
toolChoice,
|
|
747
749
|
providerOptions
|
|
748
750
|
}) {
|
|
749
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
751
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
750
752
|
const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
|
|
751
753
|
provider: "bedrock",
|
|
752
754
|
providerOptions,
|
|
@@ -793,7 +795,10 @@ var BedrockChatLanguageModel = class {
|
|
|
793
795
|
details: "Only text and json response formats are supported."
|
|
794
796
|
});
|
|
795
797
|
}
|
|
796
|
-
const
|
|
798
|
+
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
799
|
+
const isThinkingRequested = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
|
|
800
|
+
const useNativeStructuredOutput = isAnthropicModel && supportsNativeStructuredOutput(this.modelId) && isThinkingRequested && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
801
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
797
802
|
type: "function",
|
|
798
803
|
name: "json",
|
|
799
804
|
description: "Respond with a JSON object.",
|
|
@@ -812,18 +817,16 @@ var BedrockChatLanguageModel = class {
|
|
|
812
817
|
};
|
|
813
818
|
}
|
|
814
819
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
815
|
-
const existingBetas = (
|
|
820
|
+
const existingBetas = (_d = bedrockOptions.anthropicBeta) != null ? _d : [];
|
|
816
821
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
817
822
|
bedrockOptions.additionalModelRequestFields = {
|
|
818
823
|
...bedrockOptions.additionalModelRequestFields,
|
|
819
824
|
anthropic_beta: mergedBetas
|
|
820
825
|
};
|
|
821
826
|
}
|
|
822
|
-
const
|
|
823
|
-
const
|
|
824
|
-
const
|
|
825
|
-
const thinkingBudget = thinkingType === "enabled" ? (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.budgetTokens : void 0;
|
|
826
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.display : void 0;
|
|
827
|
+
const thinkingType = (_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type;
|
|
828
|
+
const thinkingBudget = thinkingType === "enabled" ? (_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.budgetTokens : void 0;
|
|
829
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_g = bedrockOptions.reasoningConfig) == null ? void 0 : _g.display : void 0;
|
|
827
830
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingRequested;
|
|
828
831
|
const inferenceConfig = {
|
|
829
832
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -856,7 +859,7 @@ var BedrockChatLanguageModel = class {
|
|
|
856
859
|
};
|
|
857
860
|
}
|
|
858
861
|
} else if (!isAnthropicModel) {
|
|
859
|
-
if (((
|
|
862
|
+
if (((_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.budgetTokens) != null) {
|
|
860
863
|
warnings.push({
|
|
861
864
|
type: "unsupported-setting",
|
|
862
865
|
setting: "budgetTokens",
|
|
@@ -871,12 +874,12 @@ var BedrockChatLanguageModel = class {
|
|
|
871
874
|
});
|
|
872
875
|
}
|
|
873
876
|
}
|
|
874
|
-
const maxReasoningEffort = (
|
|
877
|
+
const maxReasoningEffort = (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.maxReasoningEffort;
|
|
875
878
|
if (maxReasoningEffort != null && !isAnthropicModel) {
|
|
876
879
|
bedrockOptions.additionalModelRequestFields = {
|
|
877
880
|
...bedrockOptions.additionalModelRequestFields,
|
|
878
881
|
reasoningConfig: {
|
|
879
|
-
...((
|
|
882
|
+
...((_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.type) != null && {
|
|
880
883
|
type: bedrockOptions.reasoningConfig.type
|
|
881
884
|
},
|
|
882
885
|
maxReasoningEffort
|
|
@@ -890,6 +893,18 @@ var BedrockChatLanguageModel = class {
|
|
|
890
893
|
}
|
|
891
894
|
};
|
|
892
895
|
}
|
|
896
|
+
if (useNativeStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
897
|
+
bedrockOptions.additionalModelRequestFields = {
|
|
898
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
899
|
+
output_config: {
|
|
900
|
+
...(_k = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _k.output_config,
|
|
901
|
+
format: {
|
|
902
|
+
type: "json_schema",
|
|
903
|
+
schema: (0, import_internal2.sanitizeJsonSchema)(responseFormat.schema)
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
}
|
|
893
908
|
if (isAnthropicThinkingEnabled && inferenceConfig.temperature != null) {
|
|
894
909
|
delete inferenceConfig.temperature;
|
|
895
910
|
warnings.push({
|
|
@@ -914,7 +929,7 @@ var BedrockChatLanguageModel = class {
|
|
|
914
929
|
details: "topK is not supported when thinking is enabled"
|
|
915
930
|
});
|
|
916
931
|
}
|
|
917
|
-
const hasAnyTools = ((
|
|
932
|
+
const hasAnyTools = ((_m = (_l = toolConfig.tools) == null ? void 0 : _l.length) != null ? _m : 0) > 0 || additionalTools;
|
|
918
933
|
let filteredPrompt = prompt;
|
|
919
934
|
if (!hasAnyTools) {
|
|
920
935
|
const hasToolContent = prompt.some(
|
|
@@ -1378,6 +1393,9 @@ var BedrockChatLanguageModel = class {
|
|
|
1378
1393
|
return `${this.config.baseUrl()}/model/${encodedModelId}`;
|
|
1379
1394
|
}
|
|
1380
1395
|
};
|
|
1396
|
+
function supportsNativeStructuredOutput(modelId) {
|
|
1397
|
+
return modelId.includes("anthropic.claude-sonnet-4-5") || modelId.includes("anthropic.claude-haiku-4-5") || modelId.includes("anthropic.claude-opus-4-5") || modelId.includes("anthropic.claude-opus-4-6");
|
|
1398
|
+
}
|
|
1381
1399
|
var BedrockStopReasonSchema = import_v44.z.union([
|
|
1382
1400
|
import_v44.z.enum(BEDROCK_STOP_REASONS),
|
|
1383
1401
|
import_v44.z.string()
|
|
@@ -1861,7 +1879,7 @@ Original error: ${errorMessage}`
|
|
|
1861
1879
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
1862
1880
|
provider.image = createImageModel;
|
|
1863
1881
|
provider.imageModel = createImageModel;
|
|
1864
|
-
provider.tools =
|
|
1882
|
+
provider.tools = import_internal3.anthropicTools;
|
|
1865
1883
|
return provider;
|
|
1866
1884
|
}
|
|
1867
1885
|
var bedrock = createAmazonBedrock();
|