@ai-sdk/amazon-bedrock 5.0.66 → 5.0.68
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 +24 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/index.d.ts +14 -5
- package/dist/index.js +36 -26
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +1 -1
- package/dist/mantle/index.js +1 -1
- package/docs/08-amazon-bedrock.mdx +24 -0
- package/package.json +5 -5
- package/src/amazon-bedrock-chat-language-model.ts +9 -1
- package/src/amazon-bedrock-embedding-model-options.ts +10 -0
- package/src/amazon-bedrock-embedding-model.ts +47 -30
- package/src/amazon-bedrock-provider.ts +25 -6
- package/src/convert-to-amazon-bedrock-chat-messages.ts +1 -1
- package/src/index.ts +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 5.0.68
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 051a41d: Enable Anthropic reasoning budgets for application inference profile ARNs.
|
|
8
|
+
- Updated dependencies [1c68540]
|
|
9
|
+
- Updated dependencies [aa45741]
|
|
10
|
+
- @ai-sdk/openai@4.0.52
|
|
11
|
+
- @ai-sdk/anthropic@4.0.46
|
|
12
|
+
- @ai-sdk/provider@4.0.9
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.34
|
|
14
|
+
|
|
15
|
+
## 5.0.67
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 030b4e1: Omit assistant messages when only cache points remain after unsigned reasoning is filtered.
|
|
20
|
+
- 5d2229e: feat(amazon-bedrock): add model family setting for embeddings to support ARN
|
|
21
|
+
- b2eb608: Accept citation deltas in Amazon Bedrock streaming responses.
|
|
22
|
+
- Updated dependencies [90192f1]
|
|
23
|
+
- @ai-sdk/provider-utils@5.0.33
|
|
24
|
+
- @ai-sdk/anthropic@4.0.45
|
|
25
|
+
- @ai-sdk/openai@4.0.51
|
|
26
|
+
|
|
3
27
|
## 5.0.66
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/anthropic/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import { AwsV4Signer } from "aws4fetch";
|
|
25
25
|
|
|
26
26
|
// src/version.ts
|
|
27
|
-
var VERSION = true ? "5.0.
|
|
27
|
+
var VERSION = true ? "5.0.68" : "0.0.0-test";
|
|
28
28
|
|
|
29
29
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
30
30
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,15 @@ import { anthropicTools } from '@ai-sdk/anthropic/internal';
|
|
|
6
6
|
import { ProviderV4, LanguageModelV4, EmbeddingModelV4, ImageModelV4, RerankingModelV4 } from '@ai-sdk/provider';
|
|
7
7
|
|
|
8
8
|
type AmazonBedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {});
|
|
9
|
+
type AmazonBedrockEmbeddingModelSettings = {
|
|
10
|
+
/**
|
|
11
|
+
* The embedding model family.
|
|
12
|
+
*
|
|
13
|
+
* Specify this when the model ID does not identify the underlying model,
|
|
14
|
+
* such as an application inference profile ARN.
|
|
15
|
+
*/
|
|
16
|
+
modelFamily?: 'titan' | 'cohere' | 'nova';
|
|
17
|
+
};
|
|
9
18
|
declare const amazonBedrockEmbeddingModelOptionsSchema: z.ZodObject<{
|
|
10
19
|
dimensions: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<1024>, z.ZodLiteral<512>, z.ZodLiteral<256>]>>;
|
|
11
20
|
normalize: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -172,19 +181,19 @@ interface AmazonBedrockProvider extends ProviderV4 {
|
|
|
172
181
|
/**
|
|
173
182
|
* Creates a model for text embeddings.
|
|
174
183
|
*/
|
|
175
|
-
embedding(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4;
|
|
184
|
+
embedding(modelId: AmazonBedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV4;
|
|
176
185
|
/**
|
|
177
186
|
* Creates a model for text embeddings.
|
|
178
187
|
*/
|
|
179
|
-
embeddingModel(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4;
|
|
188
|
+
embeddingModel(modelId: AmazonBedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV4;
|
|
180
189
|
/**
|
|
181
190
|
* @deprecated Use `embedding` instead.
|
|
182
191
|
*/
|
|
183
|
-
textEmbedding(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4;
|
|
192
|
+
textEmbedding(modelId: AmazonBedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV4;
|
|
184
193
|
/**
|
|
185
194
|
* @deprecated Use `embeddingModel` instead.
|
|
186
195
|
*/
|
|
187
|
-
textEmbeddingModel(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4;
|
|
196
|
+
textEmbeddingModel(modelId: AmazonBedrockEmbeddingModelId, settings?: AmazonBedrockEmbeddingModelSettings): EmbeddingModelV4;
|
|
188
197
|
/**
|
|
189
198
|
* Creates a model for image generation.
|
|
190
199
|
*/
|
|
@@ -217,4 +226,4 @@ declare const amazonBedrock: AmazonBedrockProvider;
|
|
|
217
226
|
|
|
218
227
|
declare const VERSION: string;
|
|
219
228
|
|
|
220
|
-
export { type AmazonBedrockEmbeddingModelOptions, type AmazonBedrockImageModelOptions, type AmazonBedrockLanguageModelChatOptions, type AmazonBedrockLanguageModelChatOptions as AmazonBedrockLanguageModelOptions, type AmazonBedrockProvider, type AmazonBedrockProviderSettings, type AmazonBedrockRerankingModelOptions, type AmazonBedrockLanguageModelChatOptions as BedrockProviderOptions, type AmazonBedrockRerankingModelOptions as BedrockRerankingOptions, VERSION, amazonBedrock, amazonBedrock as bedrock, createAmazonBedrock };
|
|
229
|
+
export { type AmazonBedrockEmbeddingModelOptions, type AmazonBedrockEmbeddingModelSettings, type AmazonBedrockImageModelOptions, type AmazonBedrockLanguageModelChatOptions, type AmazonBedrockLanguageModelChatOptions as AmazonBedrockLanguageModelOptions, type AmazonBedrockProvider, type AmazonBedrockProviderSettings, type AmazonBedrockRerankingModelOptions, type AmazonBedrockLanguageModelChatOptions as BedrockProviderOptions, type AmazonBedrockRerankingModelOptions as BedrockRerankingOptions, VERSION, amazonBedrock, amazonBedrock as bedrock, createAmazonBedrock };
|
package/dist/index.js
CHANGED
|
@@ -964,7 +964,7 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
|
964
964
|
}
|
|
965
965
|
pushCachePoint(amazonBedrockContent, message.providerOptions);
|
|
966
966
|
}
|
|
967
|
-
if (amazonBedrockContent.
|
|
967
|
+
if (amazonBedrockContent.some((block2) => !("cachePoint" in block2))) {
|
|
968
968
|
messages.push({ role: "assistant", content: amazonBedrockContent });
|
|
969
969
|
}
|
|
970
970
|
break;
|
|
@@ -1131,7 +1131,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1131
1131
|
reasoning,
|
|
1132
1132
|
providerOptions
|
|
1133
1133
|
}) {
|
|
1134
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
1134
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1135
1135
|
let amazonBedrockOptions = (_b = (_a = await parseProviderOptions2({
|
|
1136
1136
|
provider: "amazonBedrock",
|
|
1137
1137
|
providerOptions,
|
|
@@ -1187,10 +1187,10 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1187
1187
|
details: "Only text and json response formats are supported."
|
|
1188
1188
|
});
|
|
1189
1189
|
}
|
|
1190
|
-
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
1191
|
-
const openAIModelId = (
|
|
1190
|
+
const isAnthropicModel = this.modelId.includes("anthropic") || this.modelId.includes(":application-inference-profile/") && ((_c = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _c.budgetTokens) != null;
|
|
1191
|
+
const openAIModelId = (_d = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _d[1];
|
|
1192
1192
|
const isOpenAIModel = openAIModelId != null;
|
|
1193
|
-
const isOpenAIGptOssModel = (
|
|
1193
|
+
const isOpenAIGptOssModel = (_e = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _e : false;
|
|
1194
1194
|
amazonBedrockOptions = resolveAmazonBedrockReasoningConfig({
|
|
1195
1195
|
reasoning,
|
|
1196
1196
|
amazonBedrockOptions,
|
|
@@ -1198,7 +1198,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1198
1198
|
isAnthropicModel,
|
|
1199
1199
|
modelId: this.modelId
|
|
1200
1200
|
});
|
|
1201
|
-
const isThinkingEnabled = ((
|
|
1201
|
+
const isThinkingEnabled = ((_f = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "enabled" || ((_g = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _g.type) === "adaptive";
|
|
1202
1202
|
const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
|
|
1203
1203
|
const useNativeStructuredOutput = isAnthropicModel && supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
1204
1204
|
const useJsonInstructionForStructuredOutput = isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
|
|
@@ -1222,16 +1222,16 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1222
1222
|
};
|
|
1223
1223
|
}
|
|
1224
1224
|
if (betas.size > 0 || amazonBedrockOptions.anthropicBeta) {
|
|
1225
|
-
const existingBetas = (
|
|
1225
|
+
const existingBetas = (_h = amazonBedrockOptions.anthropicBeta) != null ? _h : [];
|
|
1226
1226
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
1227
1227
|
amazonBedrockOptions.additionalModelRequestFields = {
|
|
1228
1228
|
...amazonBedrockOptions.additionalModelRequestFields,
|
|
1229
1229
|
anthropic_beta: mergedBetas
|
|
1230
1230
|
};
|
|
1231
1231
|
}
|
|
1232
|
-
const thinkingType = (
|
|
1233
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
1234
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
1232
|
+
const thinkingType = (_i = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _i.type;
|
|
1233
|
+
const thinkingBudget = thinkingType === "enabled" ? (_j = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _j.budgetTokens : void 0;
|
|
1234
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_k = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _k.display : void 0;
|
|
1235
1235
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
|
|
1236
1236
|
const inferenceConfig = {
|
|
1237
1237
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -1264,7 +1264,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1264
1264
|
};
|
|
1265
1265
|
}
|
|
1266
1266
|
} else if (!isAnthropicModel) {
|
|
1267
|
-
if (((
|
|
1267
|
+
if (((_l = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _l.budgetTokens) != null) {
|
|
1268
1268
|
warnings.push({
|
|
1269
1269
|
type: "unsupported",
|
|
1270
1270
|
feature: "budgetTokens",
|
|
@@ -1279,13 +1279,13 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1279
1279
|
});
|
|
1280
1280
|
}
|
|
1281
1281
|
}
|
|
1282
|
-
const maxReasoningEffort = (
|
|
1282
|
+
const maxReasoningEffort = (_m = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _m.maxReasoningEffort;
|
|
1283
1283
|
if (maxReasoningEffort != null) {
|
|
1284
1284
|
if (isAnthropicModel) {
|
|
1285
1285
|
amazonBedrockOptions.additionalModelRequestFields = {
|
|
1286
1286
|
...amazonBedrockOptions.additionalModelRequestFields,
|
|
1287
1287
|
output_config: {
|
|
1288
|
-
...(
|
|
1288
|
+
...(_n = amazonBedrockOptions.additionalModelRequestFields) == null ? void 0 : _n.output_config,
|
|
1289
1289
|
effort: maxReasoningEffort
|
|
1290
1290
|
}
|
|
1291
1291
|
};
|
|
@@ -1296,7 +1296,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1296
1296
|
} : {
|
|
1297
1297
|
...amazonBedrockOptions.additionalModelRequestFields,
|
|
1298
1298
|
reasoning: {
|
|
1299
|
-
...(
|
|
1299
|
+
...(_o = amazonBedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.reasoning,
|
|
1300
1300
|
effort: maxReasoningEffort
|
|
1301
1301
|
}
|
|
1302
1302
|
};
|
|
@@ -1315,7 +1315,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1315
1315
|
amazonBedrockOptions.additionalModelRequestFields = {
|
|
1316
1316
|
...amazonBedrockOptions.additionalModelRequestFields,
|
|
1317
1317
|
output_config: {
|
|
1318
|
-
...(
|
|
1318
|
+
...(_p = amazonBedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.output_config,
|
|
1319
1319
|
format: {
|
|
1320
1320
|
type: "json_schema",
|
|
1321
1321
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -1347,7 +1347,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1347
1347
|
details: "topK is not supported when thinking is enabled"
|
|
1348
1348
|
});
|
|
1349
1349
|
}
|
|
1350
|
-
const hasAnyTools = ((
|
|
1350
|
+
const hasAnyTools = ((_r = (_q = toolConfig.tools) == null ? void 0 : _q.length) != null ? _r : 0) > 0 || additionalTools;
|
|
1351
1351
|
let filteredPrompt = prompt;
|
|
1352
1352
|
if (!hasAnyTools) {
|
|
1353
1353
|
const hasToolContent = prompt.some(
|
|
@@ -1390,7 +1390,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1390
1390
|
additionalModelRequestFields: __,
|
|
1391
1391
|
serviceTier: ___,
|
|
1392
1392
|
...filteredAmazonBedrockOptions
|
|
1393
|
-
} = (
|
|
1393
|
+
} = (_t = (_s = providerOptions == null ? void 0 : providerOptions.amazonBedrock) != null ? _s : providerOptions == null ? void 0 : providerOptions.bedrock) != null ? _t : {};
|
|
1394
1394
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
1395
1395
|
return {
|
|
1396
1396
|
command: {
|
|
@@ -2066,6 +2066,9 @@ var AmazonBedrockStreamSchema = z4.object({
|
|
|
2066
2066
|
contentBlockIndex: z4.number(),
|
|
2067
2067
|
delta: z4.union([
|
|
2068
2068
|
z4.object({ text: z4.string() }),
|
|
2069
|
+
z4.object({
|
|
2070
|
+
citation: z4.record(z4.string(), z4.unknown())
|
|
2071
|
+
}),
|
|
2069
2072
|
z4.object({ toolUse: z4.object({ input: z4.string() }) }),
|
|
2070
2073
|
z4.object({
|
|
2071
2074
|
reasoningContent: z4.object({ text: z4.string() })
|
|
@@ -2264,7 +2267,11 @@ var AmazonBedrockEmbeddingModel = class _AmazonBedrockEmbeddingModel {
|
|
|
2264
2267
|
this.supportsParallelCalls = true;
|
|
2265
2268
|
}
|
|
2266
2269
|
get maxEmbeddingsPerCall() {
|
|
2267
|
-
return
|
|
2270
|
+
return this.modelFamily === "cohere" ? 96 : 1;
|
|
2271
|
+
}
|
|
2272
|
+
get modelFamily() {
|
|
2273
|
+
var _a;
|
|
2274
|
+
return (_a = this.config.modelFamily) != null ? _a : detectEmbeddingModelFamily(this.modelId);
|
|
2268
2275
|
}
|
|
2269
2276
|
static [WORKFLOW_SERIALIZE2](model) {
|
|
2270
2277
|
return serializeModelOptions2({
|
|
@@ -2303,9 +2310,8 @@ var AmazonBedrockEmbeddingModel = class _AmazonBedrockEmbeddingModel {
|
|
|
2303
2310
|
providerOptions,
|
|
2304
2311
|
schema: amazonBedrockEmbeddingModelOptionsSchema
|
|
2305
2312
|
})) != null ? _b : {};
|
|
2306
|
-
const
|
|
2307
|
-
const
|
|
2308
|
-
const args = isNovaModel ? {
|
|
2313
|
+
const modelFamily = this.modelFamily;
|
|
2314
|
+
const args = modelFamily === "nova" ? {
|
|
2309
2315
|
taskType: "SINGLE_EMBEDDING",
|
|
2310
2316
|
singleEmbeddingParams: {
|
|
2311
2317
|
embeddingPurpose: (_c = amazonBedrockOptions.embeddingPurpose) != null ? _c : "GENERIC_INDEX",
|
|
@@ -2315,7 +2321,7 @@ var AmazonBedrockEmbeddingModel = class _AmazonBedrockEmbeddingModel {
|
|
|
2315
2321
|
value: values[0]
|
|
2316
2322
|
}
|
|
2317
2323
|
}
|
|
2318
|
-
} :
|
|
2324
|
+
} : modelFamily === "cohere" ? {
|
|
2319
2325
|
// Cohere embedding models on Bedrock require `input_type`.
|
|
2320
2326
|
// Without it, the service attempts other schema branches and rejects the request.
|
|
2321
2327
|
input_type: (_f = amazonBedrockOptions.inputType) != null ? _f : "search_query",
|
|
@@ -2375,7 +2381,10 @@ function isCohereEmbeddingModel(modelId) {
|
|
|
2375
2381
|
return modelId.includes("cohere.embed-");
|
|
2376
2382
|
}
|
|
2377
2383
|
function isNovaEmbeddingModel(modelId) {
|
|
2378
|
-
return modelId.
|
|
2384
|
+
return modelId.includes("amazon.nova-") && modelId.includes("embed");
|
|
2385
|
+
}
|
|
2386
|
+
function detectEmbeddingModelFamily(modelId) {
|
|
2387
|
+
return isNovaEmbeddingModel(modelId) ? "nova" : isCohereEmbeddingModel(modelId) ? "cohere" : "titan";
|
|
2379
2388
|
}
|
|
2380
2389
|
var AmazonBedrockEmbeddingResponseSchema = z6.union([
|
|
2381
2390
|
// Titan-style response
|
|
@@ -2690,7 +2699,7 @@ import {
|
|
|
2690
2699
|
import { AwsV4Signer } from "aws4fetch";
|
|
2691
2700
|
|
|
2692
2701
|
// src/version.ts
|
|
2693
|
-
var VERSION = true ? "5.0.
|
|
2702
|
+
var VERSION = true ? "5.0.68" : "0.0.0-test";
|
|
2694
2703
|
|
|
2695
2704
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
2696
2705
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
@@ -3013,10 +3022,11 @@ Original error: ${errorMessage}`
|
|
|
3013
3022
|
}
|
|
3014
3023
|
return createChatModel(modelId);
|
|
3015
3024
|
};
|
|
3016
|
-
const createEmbeddingModel = (modelId) => new AmazonBedrockEmbeddingModel(modelId, {
|
|
3025
|
+
const createEmbeddingModel = (modelId, settings = {}) => new AmazonBedrockEmbeddingModel(modelId, {
|
|
3017
3026
|
baseUrl: getAmazonBedrockRuntimeBaseUrl,
|
|
3018
3027
|
headers: getHeaders,
|
|
3019
|
-
fetch: fetchFunction
|
|
3028
|
+
fetch: fetchFunction,
|
|
3029
|
+
modelFamily: settings.modelFamily
|
|
3020
3030
|
});
|
|
3021
3031
|
const createImageModel = (modelId) => new AmazonBedrockImageModel(modelId, {
|
|
3022
3032
|
baseUrl: getAmazonBedrockRuntimeBaseUrl,
|