@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.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { AnthropicProviderOptions } from '@ai-sdk/anthropic';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
3
|
import { anthropicTools } from '@ai-sdk/anthropic/internal';
|
|
4
|
-
import {
|
|
4
|
+
import { ProviderV4, LanguageModelV4, EmbeddingModelV4, ImageModelV4, RerankingModelV4 } from '@ai-sdk/provider';
|
|
5
5
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
6
6
|
|
|
7
7
|
type BedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {});
|
|
@@ -140,41 +140,41 @@ interface AmazonBedrockProviderSettings {
|
|
|
140
140
|
credentialProvider?: () => PromiseLike<Omit<BedrockCredentials, 'region'>>;
|
|
141
141
|
generateId?: () => string;
|
|
142
142
|
}
|
|
143
|
-
interface AmazonBedrockProvider extends
|
|
144
|
-
(modelId: BedrockChatModelId):
|
|
145
|
-
languageModel(modelId: BedrockChatModelId):
|
|
143
|
+
interface AmazonBedrockProvider extends ProviderV4 {
|
|
144
|
+
(modelId: BedrockChatModelId): LanguageModelV4;
|
|
145
|
+
languageModel(modelId: BedrockChatModelId): LanguageModelV4;
|
|
146
146
|
/**
|
|
147
147
|
* Creates a model for text embeddings.
|
|
148
148
|
*/
|
|
149
|
-
embedding(modelId: BedrockEmbeddingModelId):
|
|
149
|
+
embedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
150
150
|
/**
|
|
151
151
|
* Creates a model for text embeddings.
|
|
152
152
|
*/
|
|
153
|
-
embeddingModel(modelId: BedrockEmbeddingModelId):
|
|
153
|
+
embeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
154
154
|
/**
|
|
155
155
|
* @deprecated Use `embedding` instead.
|
|
156
156
|
*/
|
|
157
|
-
textEmbedding(modelId: BedrockEmbeddingModelId):
|
|
157
|
+
textEmbedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
158
158
|
/**
|
|
159
159
|
* @deprecated Use `embeddingModel` instead.
|
|
160
160
|
*/
|
|
161
|
-
textEmbeddingModel(modelId: BedrockEmbeddingModelId):
|
|
161
|
+
textEmbeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
162
162
|
/**
|
|
163
163
|
* Creates a model for image generation.
|
|
164
164
|
*/
|
|
165
|
-
image(modelId: BedrockImageModelId):
|
|
165
|
+
image(modelId: BedrockImageModelId): ImageModelV4;
|
|
166
166
|
/**
|
|
167
167
|
* Creates a model for image generation.
|
|
168
168
|
*/
|
|
169
|
-
imageModel(modelId: BedrockImageModelId):
|
|
169
|
+
imageModel(modelId: BedrockImageModelId): ImageModelV4;
|
|
170
170
|
/**
|
|
171
171
|
* Creates a model for reranking documents.
|
|
172
172
|
*/
|
|
173
|
-
reranking(modelId: BedrockRerankingModelId):
|
|
173
|
+
reranking(modelId: BedrockRerankingModelId): RerankingModelV4;
|
|
174
174
|
/**
|
|
175
175
|
* Creates a model for reranking documents.
|
|
176
176
|
*/
|
|
177
|
-
rerankingModel(modelId: BedrockRerankingModelId):
|
|
177
|
+
rerankingModel(modelId: BedrockRerankingModelId): RerankingModelV4;
|
|
178
178
|
/**
|
|
179
179
|
* Anthropic-specific tools that can be used with Anthropic models on Bedrock.
|
|
180
180
|
*/
|
package/dist/index.js
CHANGED
|
@@ -18,20 +18,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
VERSION: () => VERSION,
|
|
24
24
|
bedrock: () => bedrock,
|
|
25
25
|
createAmazonBedrock: () => createAmazonBedrock
|
|
26
26
|
});
|
|
27
|
-
module.exports = __toCommonJS(
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/bedrock-provider.ts
|
|
30
|
-
var
|
|
30
|
+
var import_internal3 = require("@ai-sdk/anthropic/internal");
|
|
31
31
|
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/bedrock-chat-language-model.ts
|
|
34
34
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
35
|
+
var import_internal2 = require("@ai-sdk/anthropic/internal");
|
|
35
36
|
var import_v43 = require("zod/v4");
|
|
36
37
|
|
|
37
38
|
// src/bedrock-api-types.ts
|
|
@@ -246,7 +247,8 @@ async function prepareTools({
|
|
|
246
247
|
} = await (0, import_internal.prepareTools)({
|
|
247
248
|
tools: ProviderTools,
|
|
248
249
|
toolChoice,
|
|
249
|
-
supportsStructuredOutput: false
|
|
250
|
+
supportsStructuredOutput: false,
|
|
251
|
+
supportsStrictTools: false
|
|
250
252
|
});
|
|
251
253
|
toolWarnings.push(...anthropicToolWarnings);
|
|
252
254
|
anthropicBetas.forEach((beta) => betas.add(beta));
|
|
@@ -749,7 +751,7 @@ var BedrockChatLanguageModel = class {
|
|
|
749
751
|
constructor(modelId, config) {
|
|
750
752
|
this.modelId = modelId;
|
|
751
753
|
this.config = config;
|
|
752
|
-
this.specificationVersion = "
|
|
754
|
+
this.specificationVersion = "v4";
|
|
753
755
|
this.provider = "amazon-bedrock";
|
|
754
756
|
this.supportedUrls = {
|
|
755
757
|
// no supported urls for bedrock
|
|
@@ -768,10 +770,11 @@ var BedrockChatLanguageModel = class {
|
|
|
768
770
|
seed,
|
|
769
771
|
tools,
|
|
770
772
|
toolChoice,
|
|
773
|
+
reasoning,
|
|
771
774
|
providerOptions
|
|
772
775
|
}) {
|
|
773
776
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
774
|
-
|
|
777
|
+
let bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
|
|
775
778
|
provider: "bedrock",
|
|
776
779
|
providerOptions,
|
|
777
780
|
schema: amazonBedrockLanguageModelOptions
|
|
@@ -818,6 +821,14 @@ var BedrockChatLanguageModel = class {
|
|
|
818
821
|
});
|
|
819
822
|
}
|
|
820
823
|
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
824
|
+
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
825
|
+
bedrockOptions = resolveBedrockReasoningConfig({
|
|
826
|
+
reasoning,
|
|
827
|
+
bedrockOptions,
|
|
828
|
+
warnings,
|
|
829
|
+
isAnthropicModel,
|
|
830
|
+
modelId: this.modelId
|
|
831
|
+
});
|
|
821
832
|
const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
|
|
822
833
|
const useNativeStructuredOutput = isAnthropicModel && isThinkingEnabled && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
823
834
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
@@ -895,7 +906,6 @@ var BedrockChatLanguageModel = class {
|
|
|
895
906
|
}
|
|
896
907
|
}
|
|
897
908
|
const maxReasoningEffort = (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.maxReasoningEffort;
|
|
898
|
-
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
899
909
|
if (maxReasoningEffort != null) {
|
|
900
910
|
if (isAnthropicModel) {
|
|
901
911
|
bedrockOptions.additionalModelRequestFields = {
|
|
@@ -1554,6 +1564,62 @@ var bedrockReasoningMetadataSchema = import_v43.z.object({
|
|
|
1554
1564
|
signature: import_v43.z.string().optional(),
|
|
1555
1565
|
redactedData: import_v43.z.string().optional()
|
|
1556
1566
|
});
|
|
1567
|
+
var bedrockReasoningEffortMap = {
|
|
1568
|
+
minimal: "low",
|
|
1569
|
+
low: "low",
|
|
1570
|
+
medium: "medium",
|
|
1571
|
+
high: "high",
|
|
1572
|
+
xhigh: "max"
|
|
1573
|
+
};
|
|
1574
|
+
function resolveBedrockReasoningConfig({
|
|
1575
|
+
reasoning,
|
|
1576
|
+
bedrockOptions,
|
|
1577
|
+
warnings,
|
|
1578
|
+
isAnthropicModel,
|
|
1579
|
+
modelId
|
|
1580
|
+
}) {
|
|
1581
|
+
if (!(0, import_provider_utils4.isCustomReasoning)(reasoning) || bedrockOptions.reasoningConfig != null) {
|
|
1582
|
+
return bedrockOptions;
|
|
1583
|
+
}
|
|
1584
|
+
const result = { ...bedrockOptions };
|
|
1585
|
+
if (isAnthropicModel) {
|
|
1586
|
+
const capabilities = (0, import_internal2.getModelCapabilities)(modelId);
|
|
1587
|
+
if (reasoning === "none") {
|
|
1588
|
+
result.reasoningConfig = { type: "disabled" };
|
|
1589
|
+
} else if (capabilities.supportsAdaptiveThinking) {
|
|
1590
|
+
const effort = (0, import_provider_utils4.mapReasoningToProviderEffort)({
|
|
1591
|
+
reasoning,
|
|
1592
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1593
|
+
warnings
|
|
1594
|
+
});
|
|
1595
|
+
result.reasoningConfig = {
|
|
1596
|
+
type: "adaptive",
|
|
1597
|
+
maxReasoningEffort: effort
|
|
1598
|
+
};
|
|
1599
|
+
} else {
|
|
1600
|
+
const budgetTokens = (0, import_provider_utils4.mapReasoningToProviderBudget)({
|
|
1601
|
+
reasoning,
|
|
1602
|
+
maxOutputTokens: capabilities.maxOutputTokens,
|
|
1603
|
+
maxReasoningBudget: capabilities.maxOutputTokens,
|
|
1604
|
+
warnings
|
|
1605
|
+
});
|
|
1606
|
+
if (budgetTokens != null) {
|
|
1607
|
+
result.reasoningConfig = {
|
|
1608
|
+
type: "enabled",
|
|
1609
|
+
budgetTokens
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
} else if (reasoning !== "none") {
|
|
1614
|
+
const effort = (0, import_provider_utils4.mapReasoningToProviderEffort)({
|
|
1615
|
+
reasoning,
|
|
1616
|
+
effortMap: bedrockReasoningEffortMap,
|
|
1617
|
+
warnings
|
|
1618
|
+
});
|
|
1619
|
+
result.reasoningConfig = { maxReasoningEffort: effort };
|
|
1620
|
+
}
|
|
1621
|
+
return result;
|
|
1622
|
+
}
|
|
1557
1623
|
|
|
1558
1624
|
// src/bedrock-embedding-model.ts
|
|
1559
1625
|
var import_provider4 = require("@ai-sdk/provider");
|
|
@@ -1617,7 +1683,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1617
1683
|
constructor(modelId, config) {
|
|
1618
1684
|
this.modelId = modelId;
|
|
1619
1685
|
this.config = config;
|
|
1620
|
-
this.specificationVersion = "
|
|
1686
|
+
this.specificationVersion = "v4";
|
|
1621
1687
|
this.provider = "amazon-bedrock";
|
|
1622
1688
|
this.maxEmbeddingsPerCall = 1;
|
|
1623
1689
|
this.supportsParallelCalls = true;
|
|
@@ -1750,7 +1816,7 @@ var BedrockImageModel = class {
|
|
|
1750
1816
|
constructor(modelId, config) {
|
|
1751
1817
|
this.modelId = modelId;
|
|
1752
1818
|
this.config = config;
|
|
1753
|
-
this.specificationVersion = "
|
|
1819
|
+
this.specificationVersion = "v4";
|
|
1754
1820
|
this.provider = "amazon-bedrock";
|
|
1755
1821
|
}
|
|
1756
1822
|
get maxImagesPerCall() {
|
|
@@ -1948,7 +2014,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
1948
2014
|
var import_aws4fetch = require("aws4fetch");
|
|
1949
2015
|
|
|
1950
2016
|
// src/version.ts
|
|
1951
|
-
var VERSION = true ? "5.0.0-beta.
|
|
2017
|
+
var VERSION = true ? "5.0.0-beta.11" : "0.0.0-test";
|
|
1952
2018
|
|
|
1953
2019
|
// src/bedrock-sigv4-fetch.ts
|
|
1954
2020
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
@@ -2074,7 +2140,7 @@ var BedrockRerankingModel = class {
|
|
|
2074
2140
|
constructor(modelId, config) {
|
|
2075
2141
|
this.modelId = modelId;
|
|
2076
2142
|
this.config = config;
|
|
2077
|
-
this.specificationVersion = "
|
|
2143
|
+
this.specificationVersion = "v4";
|
|
2078
2144
|
this.provider = "amazon-bedrock";
|
|
2079
2145
|
}
|
|
2080
2146
|
async doRerank({
|
|
@@ -2278,7 +2344,7 @@ Original error: ${errorMessage}`
|
|
|
2278
2344
|
headers: getHeaders,
|
|
2279
2345
|
fetch: fetchFunction
|
|
2280
2346
|
});
|
|
2281
|
-
provider.specificationVersion = "
|
|
2347
|
+
provider.specificationVersion = "v4";
|
|
2282
2348
|
provider.languageModel = createChatModel;
|
|
2283
2349
|
provider.embedding = createEmbeddingModel;
|
|
2284
2350
|
provider.embeddingModel = createEmbeddingModel;
|
|
@@ -2288,7 +2354,7 @@ Original error: ${errorMessage}`
|
|
|
2288
2354
|
provider.imageModel = createImageModel;
|
|
2289
2355
|
provider.reranking = createRerankingModel;
|
|
2290
2356
|
provider.rerankingModel = createRerankingModel;
|
|
2291
|
-
provider.tools =
|
|
2357
|
+
provider.tools = import_internal3.anthropicTools;
|
|
2292
2358
|
return provider;
|
|
2293
2359
|
}
|
|
2294
2360
|
var bedrock = createAmazonBedrock();
|