@ai-sdk/amazon-bedrock 3.0.70 → 3.0.71
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 +14 -0
- package/dist/index.js +40 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "@ai-sdk/provider-utils";
|
|
9
9
|
|
|
10
10
|
// src/version.ts
|
|
11
|
-
var VERSION = true ? "3.0.
|
|
11
|
+
var VERSION = true ? "3.0.71" : "0.0.0-test";
|
|
12
12
|
|
|
13
13
|
// src/bedrock-provider.ts
|
|
14
14
|
import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
|
|
@@ -872,6 +872,7 @@ var BedrockChatLanguageModel = class {
|
|
|
872
872
|
system,
|
|
873
873
|
messages,
|
|
874
874
|
additionalModelRequestFields: bedrockOptions.additionalModelRequestFields,
|
|
875
|
+
additionalModelResponseFieldPaths: ["/stop_sequence"],
|
|
875
876
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
876
877
|
inferenceConfig
|
|
877
878
|
},
|
|
@@ -889,7 +890,7 @@ var BedrockChatLanguageModel = class {
|
|
|
889
890
|
return combineHeaders(await resolve(this.config.headers), headers);
|
|
890
891
|
}
|
|
891
892
|
async doGenerate(options) {
|
|
892
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
893
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
893
894
|
const {
|
|
894
895
|
command: args,
|
|
895
896
|
warnings,
|
|
@@ -963,15 +964,17 @@ var BedrockChatLanguageModel = class {
|
|
|
963
964
|
}
|
|
964
965
|
}
|
|
965
966
|
}
|
|
966
|
-
const
|
|
967
|
+
const stopSequence = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.stop_sequence) != null ? _i : null;
|
|
968
|
+
const providerMetadata = response.trace || response.usage || isJsonResponseFromTool || stopSequence ? {
|
|
967
969
|
bedrock: {
|
|
968
970
|
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
969
|
-
...((
|
|
971
|
+
...((_j = response.usage) == null ? void 0 : _j.cacheWriteInputTokens) != null && {
|
|
970
972
|
usage: {
|
|
971
973
|
cacheWriteInputTokens: response.usage.cacheWriteInputTokens
|
|
972
974
|
}
|
|
973
975
|
},
|
|
974
|
-
...isJsonResponseFromTool && { isJsonResponseFromTool: true }
|
|
976
|
+
...isJsonResponseFromTool && { isJsonResponseFromTool: true },
|
|
977
|
+
stopSequence
|
|
975
978
|
}
|
|
976
979
|
} : void 0;
|
|
977
980
|
return {
|
|
@@ -981,10 +984,10 @@ var BedrockChatLanguageModel = class {
|
|
|
981
984
|
isJsonResponseFromTool
|
|
982
985
|
),
|
|
983
986
|
usage: {
|
|
984
|
-
inputTokens: (
|
|
985
|
-
outputTokens: (
|
|
986
|
-
totalTokens: ((
|
|
987
|
-
cachedInputTokens: (
|
|
987
|
+
inputTokens: (_k = response.usage) == null ? void 0 : _k.inputTokens,
|
|
988
|
+
outputTokens: (_l = response.usage) == null ? void 0 : _l.outputTokens,
|
|
989
|
+
totalTokens: ((_m = response.usage) == null ? void 0 : _m.inputTokens) + ((_n = response.usage) == null ? void 0 : _n.outputTokens),
|
|
990
|
+
cachedInputTokens: (_p = (_o = response.usage) == null ? void 0 : _o.cacheReadInputTokens) != null ? _p : void 0
|
|
988
991
|
},
|
|
989
992
|
response: {
|
|
990
993
|
// TODO add id, timestamp, etc
|
|
@@ -1021,6 +1024,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1021
1024
|
};
|
|
1022
1025
|
let providerMetadata = void 0;
|
|
1023
1026
|
let isJsonResponseFromTool = false;
|
|
1027
|
+
let stopSequence = null;
|
|
1024
1028
|
const contentBlocks = {};
|
|
1025
1029
|
return {
|
|
1026
1030
|
stream: response.pipeThrough(
|
|
@@ -1029,7 +1033,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1029
1033
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1030
1034
|
},
|
|
1031
1035
|
transform(chunk, controller) {
|
|
1032
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1036
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
1033
1037
|
function enqueueError(bedrockError) {
|
|
1034
1038
|
finishReason = "error";
|
|
1035
1039
|
controller.enqueue({ type: "error", error: bedrockError });
|
|
@@ -1063,13 +1067,14 @@ var BedrockChatLanguageModel = class {
|
|
|
1063
1067
|
value.messageStop.stopReason,
|
|
1064
1068
|
isJsonResponseFromTool
|
|
1065
1069
|
);
|
|
1070
|
+
stopSequence = (_b = (_a = value.messageStop.additionalModelResponseFields) == null ? void 0 : _a.stop_sequence) != null ? _b : null;
|
|
1066
1071
|
}
|
|
1067
1072
|
if (value.metadata) {
|
|
1068
|
-
usage.inputTokens = (
|
|
1069
|
-
usage.outputTokens = (
|
|
1070
|
-
usage.totalTokens = ((
|
|
1071
|
-
usage.cachedInputTokens = (
|
|
1072
|
-
const cacheUsage = ((
|
|
1073
|
+
usage.inputTokens = (_d = (_c = value.metadata.usage) == null ? void 0 : _c.inputTokens) != null ? _d : usage.inputTokens;
|
|
1074
|
+
usage.outputTokens = (_f = (_e = value.metadata.usage) == null ? void 0 : _e.outputTokens) != null ? _f : usage.outputTokens;
|
|
1075
|
+
usage.totalTokens = ((_g = usage.inputTokens) != null ? _g : 0) + ((_h = usage.outputTokens) != null ? _h : 0);
|
|
1076
|
+
usage.cachedInputTokens = (_j = (_i = value.metadata.usage) == null ? void 0 : _i.cacheReadInputTokens) != null ? _j : usage.cachedInputTokens;
|
|
1077
|
+
const cacheUsage = ((_k = value.metadata.usage) == null ? void 0 : _k.cacheWriteInputTokens) != null ? {
|
|
1073
1078
|
usage: {
|
|
1074
1079
|
cacheWriteInputTokens: value.metadata.usage.cacheWriteInputTokens
|
|
1075
1080
|
}
|
|
@@ -1086,7 +1091,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1086
1091
|
};
|
|
1087
1092
|
}
|
|
1088
1093
|
}
|
|
1089
|
-
if (((
|
|
1094
|
+
if (((_l = value.contentBlockStart) == null ? void 0 : _l.contentBlockIndex) != null && !((_n = (_m = value.contentBlockStart) == null ? void 0 : _m.start) == null ? void 0 : _n.toolUse)) {
|
|
1090
1095
|
const blockIndex = value.contentBlockStart.contentBlockIndex;
|
|
1091
1096
|
contentBlocks[blockIndex] = { type: "text" };
|
|
1092
1097
|
controller.enqueue({
|
|
@@ -1094,7 +1099,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1094
1099
|
id: String(blockIndex)
|
|
1095
1100
|
});
|
|
1096
1101
|
}
|
|
1097
|
-
if (((
|
|
1102
|
+
if (((_o = value.contentBlockDelta) == null ? void 0 : _o.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
|
|
1098
1103
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
1099
1104
|
if (contentBlocks[blockIndex] == null) {
|
|
1100
1105
|
contentBlocks[blockIndex] = { type: "text" };
|
|
@@ -1109,7 +1114,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1109
1114
|
delta: value.contentBlockDelta.delta.text
|
|
1110
1115
|
});
|
|
1111
1116
|
}
|
|
1112
|
-
if (((
|
|
1117
|
+
if (((_p = value.contentBlockStop) == null ? void 0 : _p.contentBlockIndex) != null) {
|
|
1113
1118
|
const blockIndex = value.contentBlockStop.contentBlockIndex;
|
|
1114
1119
|
const contentBlock = contentBlocks[blockIndex];
|
|
1115
1120
|
if (contentBlock != null) {
|
|
@@ -1155,7 +1160,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1155
1160
|
delete contentBlocks[blockIndex];
|
|
1156
1161
|
}
|
|
1157
1162
|
}
|
|
1158
|
-
if (((
|
|
1163
|
+
if (((_q = value.contentBlockDelta) == null ? void 0 : _q.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
|
|
1159
1164
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
1160
1165
|
const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
|
|
1161
1166
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
@@ -1196,7 +1201,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1196
1201
|
}
|
|
1197
1202
|
}
|
|
1198
1203
|
const contentBlockStart = value.contentBlockStart;
|
|
1199
|
-
if (((
|
|
1204
|
+
if (((_r = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _r.toolUse) != null) {
|
|
1200
1205
|
const toolUse = contentBlockStart.start.toolUse;
|
|
1201
1206
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
1202
1207
|
const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
|
|
@@ -1220,7 +1225,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1220
1225
|
const blockIndex = contentBlockDelta.contentBlockIndex;
|
|
1221
1226
|
const contentBlock = contentBlocks[blockIndex];
|
|
1222
1227
|
if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
|
|
1223
|
-
const delta = (
|
|
1228
|
+
const delta = (_s = contentBlockDelta.delta.toolUse.input) != null ? _s : "";
|
|
1224
1229
|
if (!contentBlock.isJsonResponseTool) {
|
|
1225
1230
|
controller.enqueue({
|
|
1226
1231
|
type: "tool-input-delta",
|
|
@@ -1233,16 +1238,22 @@ var BedrockChatLanguageModel = class {
|
|
|
1233
1238
|
}
|
|
1234
1239
|
},
|
|
1235
1240
|
flush(controller) {
|
|
1236
|
-
if (isJsonResponseFromTool) {
|
|
1241
|
+
if (isJsonResponseFromTool || stopSequence != null) {
|
|
1237
1242
|
if (providerMetadata) {
|
|
1238
1243
|
providerMetadata.bedrock = {
|
|
1239
1244
|
...providerMetadata.bedrock,
|
|
1240
|
-
isJsonResponseFromTool
|
|
1245
|
+
...isJsonResponseFromTool && {
|
|
1246
|
+
isJsonResponseFromTool: true
|
|
1247
|
+
},
|
|
1248
|
+
stopSequence
|
|
1241
1249
|
};
|
|
1242
1250
|
} else {
|
|
1243
1251
|
providerMetadata = {
|
|
1244
1252
|
bedrock: {
|
|
1245
|
-
isJsonResponseFromTool
|
|
1253
|
+
...isJsonResponseFromTool && {
|
|
1254
|
+
isJsonResponseFromTool: true
|
|
1255
|
+
},
|
|
1256
|
+
stopSequence
|
|
1246
1257
|
}
|
|
1247
1258
|
};
|
|
1248
1259
|
}
|
|
@@ -1269,6 +1280,9 @@ var BedrockStopReasonSchema = z3.union([
|
|
|
1269
1280
|
z3.enum(BEDROCK_STOP_REASONS),
|
|
1270
1281
|
z3.string()
|
|
1271
1282
|
]);
|
|
1283
|
+
var BedrockAdditionalModelResponseFieldsSchema = z3.object({
|
|
1284
|
+
stop_sequence: z3.string().optional()
|
|
1285
|
+
}).catchall(z3.unknown());
|
|
1272
1286
|
var BedrockToolUseSchema = z3.object({
|
|
1273
1287
|
toolUseId: z3.string(),
|
|
1274
1288
|
name: z3.string(),
|
|
@@ -1305,6 +1319,7 @@ var BedrockResponseSchema = z3.object({
|
|
|
1305
1319
|
})
|
|
1306
1320
|
}),
|
|
1307
1321
|
stopReason: BedrockStopReasonSchema,
|
|
1322
|
+
additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
|
|
1308
1323
|
trace: z3.unknown().nullish(),
|
|
1309
1324
|
usage: z3.object({
|
|
1310
1325
|
inputTokens: z3.number(),
|
|
@@ -1344,7 +1359,7 @@ var BedrockStreamSchema = z3.object({
|
|
|
1344
1359
|
}).nullish(),
|
|
1345
1360
|
internalServerException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1346
1361
|
messageStop: z3.object({
|
|
1347
|
-
additionalModelResponseFields:
|
|
1362
|
+
additionalModelResponseFields: BedrockAdditionalModelResponseFieldsSchema.nullish(),
|
|
1348
1363
|
stopReason: BedrockStopReasonSchema
|
|
1349
1364
|
}).nullish(),
|
|
1350
1365
|
metadata: z3.object({
|