@ai-sdk/amazon-bedrock 4.0.55 → 4.0.57
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 +15 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +63 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -25
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +29 -6
- package/package.json +4 -4
- package/src/bedrock-chat-language-model.ts +72 -12
- package/src/bedrock-chat-options.ts +4 -2
- package/src/index.ts +10 -2
- package/src/reranking/bedrock-reranking-model.ts +2 -2
- package/src/reranking/bedrock-reranking-options.ts +2 -2
package/dist/index.mjs
CHANGED
|
@@ -64,7 +64,7 @@ var bedrockFilePartProviderOptions = z.object({
|
|
|
64
64
|
enabled: z.boolean()
|
|
65
65
|
}).optional()
|
|
66
66
|
});
|
|
67
|
-
var
|
|
67
|
+
var amazonBedrockLanguageModelOptions = z.object({
|
|
68
68
|
/**
|
|
69
69
|
* Additional inference parameters that the model supports,
|
|
70
70
|
* beyond the base set of inference parameters that Converse
|
|
@@ -768,7 +768,7 @@ var BedrockChatLanguageModel = class {
|
|
|
768
768
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
769
769
|
provider: "bedrock",
|
|
770
770
|
providerOptions,
|
|
771
|
-
schema:
|
|
771
|
+
schema: amazonBedrockLanguageModelOptions
|
|
772
772
|
})) != null ? _a : {};
|
|
773
773
|
const warnings = [];
|
|
774
774
|
if (frequencyPenalty != null) {
|
|
@@ -999,7 +999,7 @@ var BedrockChatLanguageModel = class {
|
|
|
999
999
|
return combineHeaders(await resolve(this.config.headers), headers);
|
|
1000
1000
|
}
|
|
1001
1001
|
async doGenerate(options) {
|
|
1002
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1002
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1003
1003
|
const {
|
|
1004
1004
|
command: args,
|
|
1005
1005
|
warnings,
|
|
@@ -1076,12 +1076,23 @@ var BedrockChatLanguageModel = class {
|
|
|
1076
1076
|
}
|
|
1077
1077
|
}
|
|
1078
1078
|
const stopSequence = (_j = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.delta) == null ? void 0 : _i.stop_sequence) != null ? _j : null;
|
|
1079
|
-
const providerMetadata = response.trace || response.usage || isJsonResponseFromTool || stopSequence ? {
|
|
1079
|
+
const providerMetadata = response.trace || response.usage || response.performanceConfig || response.serviceTier || isJsonResponseFromTool || stopSequence ? {
|
|
1080
1080
|
bedrock: {
|
|
1081
1081
|
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
1082
|
-
...
|
|
1082
|
+
...response.performanceConfig && {
|
|
1083
|
+
performanceConfig: response.performanceConfig
|
|
1084
|
+
},
|
|
1085
|
+
...response.serviceTier && {
|
|
1086
|
+
serviceTier: response.serviceTier
|
|
1087
|
+
},
|
|
1088
|
+
...(((_k = response.usage) == null ? void 0 : _k.cacheWriteInputTokens) != null || ((_l = response.usage) == null ? void 0 : _l.cacheDetails) != null) && {
|
|
1083
1089
|
usage: {
|
|
1084
|
-
|
|
1090
|
+
...response.usage.cacheWriteInputTokens != null && {
|
|
1091
|
+
cacheWriteInputTokens: response.usage.cacheWriteInputTokens
|
|
1092
|
+
},
|
|
1093
|
+
...response.usage.cacheDetails != null && {
|
|
1094
|
+
cacheDetails: response.usage.cacheDetails
|
|
1095
|
+
}
|
|
1085
1096
|
}
|
|
1086
1097
|
},
|
|
1087
1098
|
...isJsonResponseFromTool && { isJsonResponseFromTool: true },
|
|
@@ -1095,11 +1106,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1095
1106
|
response.stopReason,
|
|
1096
1107
|
isJsonResponseFromTool
|
|
1097
1108
|
),
|
|
1098
|
-
raw: (
|
|
1109
|
+
raw: (_m = response.stopReason) != null ? _m : void 0
|
|
1099
1110
|
},
|
|
1100
1111
|
usage: convertBedrockUsage(response.usage),
|
|
1101
1112
|
response: {
|
|
1102
|
-
|
|
1113
|
+
id: (_n = responseHeaders == null ? void 0 : responseHeaders["x-amzn-requestid"]) != null ? _n : void 0,
|
|
1114
|
+
timestamp: (responseHeaders == null ? void 0 : responseHeaders["date"]) != null ? new Date(responseHeaders["date"]) : void 0,
|
|
1115
|
+
modelId: this.modelId,
|
|
1103
1116
|
headers: responseHeaders
|
|
1104
1117
|
},
|
|
1105
1118
|
warnings,
|
|
@@ -1112,8 +1125,9 @@ var BedrockChatLanguageModel = class {
|
|
|
1112
1125
|
warnings,
|
|
1113
1126
|
usesJsonResponseTool
|
|
1114
1127
|
} = await this.getArgs(options);
|
|
1115
|
-
const
|
|
1116
|
-
const
|
|
1128
|
+
const modelId = this.modelId;
|
|
1129
|
+
const isMistral = isMistralModel(modelId);
|
|
1130
|
+
const url = `${this.getUrl(modelId)}/converse-stream`;
|
|
1117
1131
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1118
1132
|
url,
|
|
1119
1133
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
@@ -1139,10 +1153,17 @@ var BedrockChatLanguageModel = class {
|
|
|
1139
1153
|
stream: response.pipeThrough(
|
|
1140
1154
|
new TransformStream({
|
|
1141
1155
|
start(controller) {
|
|
1156
|
+
var _a;
|
|
1142
1157
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1158
|
+
controller.enqueue({
|
|
1159
|
+
type: "response-metadata",
|
|
1160
|
+
id: (_a = responseHeaders == null ? void 0 : responseHeaders["x-amzn-requestid"]) != null ? _a : void 0,
|
|
1161
|
+
timestamp: (responseHeaders == null ? void 0 : responseHeaders["date"]) != null ? new Date(responseHeaders["date"]) : void 0,
|
|
1162
|
+
modelId
|
|
1163
|
+
});
|
|
1143
1164
|
},
|
|
1144
1165
|
transform(chunk, controller) {
|
|
1145
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1166
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1146
1167
|
function enqueueError(bedrockError) {
|
|
1147
1168
|
finishReason = { unified: "error", raw: void 0 };
|
|
1148
1169
|
controller.enqueue({ type: "error", error: bedrockError });
|
|
@@ -1185,24 +1206,35 @@ var BedrockChatLanguageModel = class {
|
|
|
1185
1206
|
if (value.metadata.usage) {
|
|
1186
1207
|
usage = value.metadata.usage;
|
|
1187
1208
|
}
|
|
1188
|
-
const cacheUsage = ((_e = value.metadata.usage) == null ? void 0 : _e.cacheWriteInputTokens) != null ? {
|
|
1209
|
+
const cacheUsage = ((_e = value.metadata.usage) == null ? void 0 : _e.cacheWriteInputTokens) != null || ((_f = value.metadata.usage) == null ? void 0 : _f.cacheDetails) != null ? {
|
|
1189
1210
|
usage: {
|
|
1190
|
-
|
|
1211
|
+
...((_g = value.metadata.usage) == null ? void 0 : _g.cacheWriteInputTokens) != null && {
|
|
1212
|
+
cacheWriteInputTokens: value.metadata.usage.cacheWriteInputTokens
|
|
1213
|
+
},
|
|
1214
|
+
...((_h = value.metadata.usage) == null ? void 0 : _h.cacheDetails) != null && {
|
|
1215
|
+
cacheDetails: value.metadata.usage.cacheDetails
|
|
1216
|
+
}
|
|
1191
1217
|
}
|
|
1192
1218
|
} : void 0;
|
|
1193
1219
|
const trace = value.metadata.trace ? {
|
|
1194
1220
|
trace: value.metadata.trace
|
|
1195
1221
|
} : void 0;
|
|
1196
|
-
if (cacheUsage || trace) {
|
|
1222
|
+
if (cacheUsage || trace || value.metadata.performanceConfig || value.metadata.serviceTier) {
|
|
1197
1223
|
providerMetadata = {
|
|
1198
1224
|
bedrock: {
|
|
1199
1225
|
...cacheUsage,
|
|
1200
|
-
...trace
|
|
1226
|
+
...trace,
|
|
1227
|
+
...value.metadata.performanceConfig && {
|
|
1228
|
+
performanceConfig: value.metadata.performanceConfig
|
|
1229
|
+
},
|
|
1230
|
+
...value.metadata.serviceTier && {
|
|
1231
|
+
serviceTier: value.metadata.serviceTier
|
|
1232
|
+
}
|
|
1201
1233
|
}
|
|
1202
1234
|
};
|
|
1203
1235
|
}
|
|
1204
1236
|
}
|
|
1205
|
-
if (((
|
|
1237
|
+
if (((_i = value.contentBlockStart) == null ? void 0 : _i.contentBlockIndex) != null && !((_k = (_j = value.contentBlockStart) == null ? void 0 : _j.start) == null ? void 0 : _k.toolUse)) {
|
|
1206
1238
|
const blockIndex = value.contentBlockStart.contentBlockIndex;
|
|
1207
1239
|
contentBlocks[blockIndex] = { type: "text" };
|
|
1208
1240
|
controller.enqueue({
|
|
@@ -1210,7 +1242,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1210
1242
|
id: String(blockIndex)
|
|
1211
1243
|
});
|
|
1212
1244
|
}
|
|
1213
|
-
if (((
|
|
1245
|
+
if (((_l = value.contentBlockDelta) == null ? void 0 : _l.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
|
|
1214
1246
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
1215
1247
|
if (contentBlocks[blockIndex] == null) {
|
|
1216
1248
|
contentBlocks[blockIndex] = { type: "text" };
|
|
@@ -1225,7 +1257,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1225
1257
|
delta: value.contentBlockDelta.delta.text
|
|
1226
1258
|
});
|
|
1227
1259
|
}
|
|
1228
|
-
if (((
|
|
1260
|
+
if (((_m = value.contentBlockStop) == null ? void 0 : _m.contentBlockIndex) != null) {
|
|
1229
1261
|
const blockIndex = value.contentBlockStop.contentBlockIndex;
|
|
1230
1262
|
const contentBlock = contentBlocks[blockIndex];
|
|
1231
1263
|
if (contentBlock != null) {
|
|
@@ -1271,7 +1303,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1271
1303
|
delete contentBlocks[blockIndex];
|
|
1272
1304
|
}
|
|
1273
1305
|
}
|
|
1274
|
-
if (((
|
|
1306
|
+
if (((_n = value.contentBlockDelta) == null ? void 0 : _n.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
|
|
1275
1307
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
1276
1308
|
const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
|
|
1277
1309
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
@@ -1312,7 +1344,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1312
1344
|
}
|
|
1313
1345
|
}
|
|
1314
1346
|
const contentBlockStart = value.contentBlockStart;
|
|
1315
|
-
if (((
|
|
1347
|
+
if (((_o = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _o.toolUse) != null) {
|
|
1316
1348
|
const toolUse = contentBlockStart.start.toolUse;
|
|
1317
1349
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
1318
1350
|
const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
|
|
@@ -1340,7 +1372,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1340
1372
|
const blockIndex = contentBlockDelta.contentBlockIndex;
|
|
1341
1373
|
const contentBlock = contentBlocks[blockIndex];
|
|
1342
1374
|
if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
|
|
1343
|
-
const delta = (
|
|
1375
|
+
const delta = (_p = contentBlockDelta.delta.toolUse.input) != null ? _p : "";
|
|
1344
1376
|
if (!contentBlock.isJsonResponseTool) {
|
|
1345
1377
|
controller.enqueue({
|
|
1346
1378
|
type: "tool-input-delta",
|
|
@@ -1438,12 +1470,15 @@ var BedrockResponseSchema = z3.object({
|
|
|
1438
1470
|
stopReason: BedrockStopReasonSchema,
|
|
1439
1471
|
additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
|
|
1440
1472
|
trace: z3.unknown().nullish(),
|
|
1473
|
+
performanceConfig: z3.object({ latency: z3.string() }).nullish(),
|
|
1474
|
+
serviceTier: z3.object({ type: z3.string() }).nullish(),
|
|
1441
1475
|
usage: z3.object({
|
|
1442
1476
|
inputTokens: z3.number(),
|
|
1443
1477
|
outputTokens: z3.number(),
|
|
1444
1478
|
totalTokens: z3.number(),
|
|
1445
1479
|
cacheReadInputTokens: z3.number().nullish(),
|
|
1446
|
-
cacheWriteInputTokens: z3.number().nullish()
|
|
1480
|
+
cacheWriteInputTokens: z3.number().nullish(),
|
|
1481
|
+
cacheDetails: z3.array(z3.object({ inputTokens: z3.number(), ttl: z3.string() })).nullish()
|
|
1447
1482
|
})
|
|
1448
1483
|
});
|
|
1449
1484
|
var BedrockStreamSchema = z3.object({
|
|
@@ -1481,9 +1516,12 @@ var BedrockStreamSchema = z3.object({
|
|
|
1481
1516
|
}).nullish(),
|
|
1482
1517
|
metadata: z3.object({
|
|
1483
1518
|
trace: z3.unknown().nullish(),
|
|
1519
|
+
performanceConfig: z3.object({ latency: z3.string() }).nullish(),
|
|
1520
|
+
serviceTier: z3.object({ type: z3.string() }).nullish(),
|
|
1484
1521
|
usage: z3.object({
|
|
1485
1522
|
cacheReadInputTokens: z3.number().nullish(),
|
|
1486
1523
|
cacheWriteInputTokens: z3.number().nullish(),
|
|
1524
|
+
cacheDetails: z3.array(z3.object({ inputTokens: z3.number(), ttl: z3.string() })).nullish(),
|
|
1487
1525
|
inputTokens: z3.number(),
|
|
1488
1526
|
outputTokens: z3.number()
|
|
1489
1527
|
}).nullish()
|
|
@@ -1911,7 +1949,7 @@ import {
|
|
|
1911
1949
|
import { AwsV4Signer } from "aws4fetch";
|
|
1912
1950
|
|
|
1913
1951
|
// src/version.ts
|
|
1914
|
-
var VERSION = true ? "4.0.
|
|
1952
|
+
var VERSION = true ? "4.0.57" : "0.0.0-test";
|
|
1915
1953
|
|
|
1916
1954
|
// src/bedrock-sigv4-fetch.ts
|
|
1917
1955
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
@@ -2024,7 +2062,7 @@ var bedrockRerankingResponseSchema = lazySchema(
|
|
|
2024
2062
|
// src/reranking/bedrock-reranking-options.ts
|
|
2025
2063
|
import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
|
|
2026
2064
|
import { z as z8 } from "zod/v4";
|
|
2027
|
-
var
|
|
2065
|
+
var amazonBedrockRerankingModelOptionsSchema = lazySchema2(
|
|
2028
2066
|
() => zodSchema2(
|
|
2029
2067
|
z8.object({
|
|
2030
2068
|
/**
|
|
@@ -2058,7 +2096,7 @@ var BedrockRerankingModel = class {
|
|
|
2058
2096
|
const bedrockOptions = await parseProviderOptions4({
|
|
2059
2097
|
provider: "bedrock",
|
|
2060
2098
|
providerOptions,
|
|
2061
|
-
schema:
|
|
2099
|
+
schema: amazonBedrockRerankingModelOptionsSchema
|
|
2062
2100
|
});
|
|
2063
2101
|
const {
|
|
2064
2102
|
value: response,
|