@ai-sdk/amazon-bedrock 5.0.0-beta.1 → 5.0.0-beta.11
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 +86 -4
- package/dist/anthropic/index.d.mts +4 -4
- package/dist/anthropic/index.d.ts +4 -4
- package/dist/anthropic/index.js +5 -5
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +2 -2
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.d.mts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +80 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -9
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +15 -0
- package/package.json +4 -6
- package/src/anthropic/bedrock-anthropic-provider.ts +6 -6
- package/src/bedrock-chat-language-model.ts +113 -28
- package/src/bedrock-embedding-model.ts +5 -5
- package/src/bedrock-image-model.ts +9 -9
- package/src/bedrock-prepare-tools.ts +7 -6
- package/src/bedrock-provider.ts +17 -17
- package/src/convert-bedrock-usage.ts +2 -2
- package/src/convert-to-bedrock-chat-messages.ts +10 -10
- package/src/map-bedrock-finish-reason.ts +2 -2
- package/src/reranking/bedrock-reranking-model.ts +5 -5
package/dist/index.mjs
CHANGED
|
@@ -13,10 +13,14 @@ import {
|
|
|
13
13
|
combineHeaders,
|
|
14
14
|
createJsonErrorResponseHandler,
|
|
15
15
|
createJsonResponseHandler,
|
|
16
|
+
isCustomReasoning,
|
|
17
|
+
mapReasoningToProviderBudget,
|
|
18
|
+
mapReasoningToProviderEffort,
|
|
16
19
|
parseProviderOptions as parseProviderOptions2,
|
|
17
20
|
postJsonToApi,
|
|
18
21
|
resolve
|
|
19
22
|
} from "@ai-sdk/provider-utils";
|
|
23
|
+
import { getModelCapabilities } from "@ai-sdk/anthropic/internal";
|
|
20
24
|
import { z as z3 } from "zod/v4";
|
|
21
25
|
|
|
22
26
|
// src/bedrock-api-types.ts
|
|
@@ -240,7 +244,8 @@ async function prepareTools({
|
|
|
240
244
|
} = await prepareAnthropicTools({
|
|
241
245
|
tools: ProviderTools,
|
|
242
246
|
toolChoice,
|
|
243
|
-
supportsStructuredOutput: false
|
|
247
|
+
supportsStructuredOutput: false,
|
|
248
|
+
supportsStrictTools: false
|
|
244
249
|
});
|
|
245
250
|
toolWarnings.push(...anthropicToolWarnings);
|
|
246
251
|
anthropicBetas.forEach((beta) => betas.add(beta));
|
|
@@ -749,7 +754,7 @@ var BedrockChatLanguageModel = class {
|
|
|
749
754
|
constructor(modelId, config) {
|
|
750
755
|
this.modelId = modelId;
|
|
751
756
|
this.config = config;
|
|
752
|
-
this.specificationVersion = "
|
|
757
|
+
this.specificationVersion = "v4";
|
|
753
758
|
this.provider = "amazon-bedrock";
|
|
754
759
|
this.supportedUrls = {
|
|
755
760
|
// no supported urls for bedrock
|
|
@@ -768,10 +773,11 @@ var BedrockChatLanguageModel = class {
|
|
|
768
773
|
seed,
|
|
769
774
|
tools,
|
|
770
775
|
toolChoice,
|
|
776
|
+
reasoning,
|
|
771
777
|
providerOptions
|
|
772
778
|
}) {
|
|
773
779
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
774
|
-
|
|
780
|
+
let bedrockOptions = (_a = await parseProviderOptions2({
|
|
775
781
|
provider: "bedrock",
|
|
776
782
|
providerOptions,
|
|
777
783
|
schema: amazonBedrockLanguageModelOptions
|
|
@@ -818,6 +824,14 @@ var BedrockChatLanguageModel = class {
|
|
|
818
824
|
});
|
|
819
825
|
}
|
|
820
826
|
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
827
|
+
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
828
|
+
bedrockOptions = resolveBedrockReasoningConfig({
|
|
829
|
+
reasoning,
|
|
830
|
+
bedrockOptions,
|
|
831
|
+
warnings,
|
|
832
|
+
isAnthropicModel,
|
|
833
|
+
modelId: this.modelId
|
|
834
|
+
});
|
|
821
835
|
const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
|
|
822
836
|
const useNativeStructuredOutput = isAnthropicModel && isThinkingEnabled && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
823
837
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
@@ -895,7 +909,6 @@ var BedrockChatLanguageModel = class {
|
|
|
895
909
|
}
|
|
896
910
|
}
|
|
897
911
|
const maxReasoningEffort = (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.maxReasoningEffort;
|
|
898
|
-
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
899
912
|
if (maxReasoningEffort != null) {
|
|
900
913
|
if (isAnthropicModel) {
|
|
901
914
|
bedrockOptions.additionalModelRequestFields = {
|
|
@@ -1554,6 +1567,62 @@ var bedrockReasoningMetadataSchema = z3.object({
|
|
|
1554
1567
|
signature: z3.string().optional(),
|
|
1555
1568
|
redactedData: z3.string().optional()
|
|
1556
1569
|
});
|
|
1570
|
+
var bedrockReasoningEffortMap = {
|
|
1571
|
+
minimal: "low",
|
|
1572
|
+
low: "low",
|
|
1573
|
+
medium: "medium",
|
|
1574
|
+
high: "high",
|
|
1575
|
+
xhigh: "max"
|
|
1576
|
+
};
|
|
1577
|
+
function resolveBedrockReasoningConfig({
|
|
1578
|
+
reasoning,
|
|
1579
|
+
bedrockOptions,
|
|
1580
|
+
warnings,
|
|
1581
|
+
isAnthropicModel,
|
|
1582
|
+
modelId
|
|
1583
|
+
}) {
|
|
1584
|
+
if (!isCustomReasoning(reasoning) || bedrockOptions.reasoningConfig != null) {
|
|
1585
|
+
return bedrockOptions;
|
|
1586
|
+
}
|
|
1587
|
+
const result = { ...bedrockOptions };
|
|
1588
|
+
if (isAnthropicModel) {
|
|
1589
|
+
const capabilities = getModelCapabilities(modelId);
|
|
1590
|
+
if (reasoning === "none") {
|
|
1591
|
+
result.reasoningConfig = { type: "disabled" };
|
|
1592
|
+
} else if (capabilities.supportsAdaptiveThinking) {
|
|
1593
|
+
const effort = mapReasoningToProviderEffort({
|
|
1594
|
+
reasoning,
|
|
1595
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1596
|
+
warnings
|
|
1597
|
+
});
|
|
1598
|
+
result.reasoningConfig = {
|
|
1599
|
+
type: "adaptive",
|
|
1600
|
+
maxReasoningEffort: effort
|
|
1601
|
+
};
|
|
1602
|
+
} else {
|
|
1603
|
+
const budgetTokens = mapReasoningToProviderBudget({
|
|
1604
|
+
reasoning,
|
|
1605
|
+
maxOutputTokens: capabilities.maxOutputTokens,
|
|
1606
|
+
maxReasoningBudget: capabilities.maxOutputTokens,
|
|
1607
|
+
warnings
|
|
1608
|
+
});
|
|
1609
|
+
if (budgetTokens != null) {
|
|
1610
|
+
result.reasoningConfig = {
|
|
1611
|
+
type: "enabled",
|
|
1612
|
+
budgetTokens
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
} else if (reasoning !== "none") {
|
|
1617
|
+
const effort = mapReasoningToProviderEffort({
|
|
1618
|
+
reasoning,
|
|
1619
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1620
|
+
warnings
|
|
1621
|
+
});
|
|
1622
|
+
result.reasoningConfig = { maxReasoningEffort: effort };
|
|
1623
|
+
}
|
|
1624
|
+
return result;
|
|
1625
|
+
}
|
|
1557
1626
|
|
|
1558
1627
|
// src/bedrock-embedding-model.ts
|
|
1559
1628
|
import {
|
|
@@ -1626,7 +1695,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1626
1695
|
constructor(modelId, config) {
|
|
1627
1696
|
this.modelId = modelId;
|
|
1628
1697
|
this.config = config;
|
|
1629
|
-
this.specificationVersion = "
|
|
1698
|
+
this.specificationVersion = "v4";
|
|
1630
1699
|
this.provider = "amazon-bedrock";
|
|
1631
1700
|
this.maxEmbeddingsPerCall = 1;
|
|
1632
1701
|
this.supportsParallelCalls = true;
|
|
@@ -1766,7 +1835,7 @@ var BedrockImageModel = class {
|
|
|
1766
1835
|
constructor(modelId, config) {
|
|
1767
1836
|
this.modelId = modelId;
|
|
1768
1837
|
this.config = config;
|
|
1769
|
-
this.specificationVersion = "
|
|
1838
|
+
this.specificationVersion = "v4";
|
|
1770
1839
|
this.provider = "amazon-bedrock";
|
|
1771
1840
|
}
|
|
1772
1841
|
get maxImagesPerCall() {
|
|
@@ -1969,7 +2038,7 @@ import {
|
|
|
1969
2038
|
import { AwsV4Signer } from "aws4fetch";
|
|
1970
2039
|
|
|
1971
2040
|
// src/version.ts
|
|
1972
|
-
var VERSION = true ? "5.0.0-beta.
|
|
2041
|
+
var VERSION = true ? "5.0.0-beta.11" : "0.0.0-test";
|
|
1973
2042
|
|
|
1974
2043
|
// src/bedrock-sigv4-fetch.ts
|
|
1975
2044
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
@@ -2102,7 +2171,7 @@ var BedrockRerankingModel = class {
|
|
|
2102
2171
|
constructor(modelId, config) {
|
|
2103
2172
|
this.modelId = modelId;
|
|
2104
2173
|
this.config = config;
|
|
2105
|
-
this.specificationVersion = "
|
|
2174
|
+
this.specificationVersion = "v4";
|
|
2106
2175
|
this.provider = "amazon-bedrock";
|
|
2107
2176
|
}
|
|
2108
2177
|
async doRerank({
|
|
@@ -2306,7 +2375,7 @@ Original error: ${errorMessage}`
|
|
|
2306
2375
|
headers: getHeaders,
|
|
2307
2376
|
fetch: fetchFunction
|
|
2308
2377
|
});
|
|
2309
|
-
provider.specificationVersion = "
|
|
2378
|
+
provider.specificationVersion = "v4";
|
|
2310
2379
|
provider.languageModel = createChatModel;
|
|
2311
2380
|
provider.embedding = createEmbeddingModel;
|
|
2312
2381
|
provider.embeddingModel = createEmbeddingModel;
|