@ai-sdk/amazon-bedrock 4.0.2 → 4.0.4
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 +16 -0
- package/dist/index.js +21 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -913,12 +913,15 @@ var BedrockChatLanguageModel = class {
|
|
|
913
913
|
additionalModelRequestFields: __,
|
|
914
914
|
...filteredBedrockOptions
|
|
915
915
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
916
|
+
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
916
917
|
return {
|
|
917
918
|
command: {
|
|
918
919
|
system,
|
|
919
920
|
messages,
|
|
920
921
|
additionalModelRequestFields: bedrockOptions.additionalModelRequestFields,
|
|
921
|
-
additionalModelResponseFieldPaths
|
|
922
|
+
...additionalModelResponseFieldPaths && {
|
|
923
|
+
additionalModelResponseFieldPaths
|
|
924
|
+
},
|
|
922
925
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
923
926
|
inferenceConfig
|
|
924
927
|
},
|
|
@@ -936,7 +939,7 @@ var BedrockChatLanguageModel = class {
|
|
|
936
939
|
return combineHeaders(await resolve(this.config.headers), headers);
|
|
937
940
|
}
|
|
938
941
|
async doGenerate(options) {
|
|
939
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
942
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
940
943
|
const {
|
|
941
944
|
command: args,
|
|
942
945
|
warnings,
|
|
@@ -1010,11 +1013,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1010
1013
|
}
|
|
1011
1014
|
}
|
|
1012
1015
|
}
|
|
1013
|
-
const stopSequence = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.stop_sequence) != null ?
|
|
1016
|
+
const stopSequence = (_j = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.delta) == null ? void 0 : _i.stop_sequence) != null ? _j : null;
|
|
1014
1017
|
const providerMetadata = response.trace || response.usage || isJsonResponseFromTool || stopSequence ? {
|
|
1015
1018
|
bedrock: {
|
|
1016
1019
|
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
1017
|
-
...((
|
|
1020
|
+
...((_k = response.usage) == null ? void 0 : _k.cacheWriteInputTokens) != null && {
|
|
1018
1021
|
usage: {
|
|
1019
1022
|
cacheWriteInputTokens: response.usage.cacheWriteInputTokens
|
|
1020
1023
|
}
|
|
@@ -1030,7 +1033,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1030
1033
|
response.stopReason,
|
|
1031
1034
|
isJsonResponseFromTool
|
|
1032
1035
|
),
|
|
1033
|
-
raw: (
|
|
1036
|
+
raw: (_l = response.stopReason) != null ? _l : void 0
|
|
1034
1037
|
},
|
|
1035
1038
|
usage: convertBedrockUsage(response.usage),
|
|
1036
1039
|
response: {
|
|
@@ -1076,7 +1079,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1076
1079
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1077
1080
|
},
|
|
1078
1081
|
transform(chunk, controller) {
|
|
1079
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1082
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1080
1083
|
function enqueueError(bedrockError) {
|
|
1081
1084
|
finishReason = { unified: "error", raw: void 0 };
|
|
1082
1085
|
controller.enqueue({ type: "error", error: bedrockError });
|
|
@@ -1113,13 +1116,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1113
1116
|
),
|
|
1114
1117
|
raw: (_a = value.messageStop.stopReason) != null ? _a : void 0
|
|
1115
1118
|
};
|
|
1116
|
-
stopSequence = (_c = (_b = value.messageStop.additionalModelResponseFields) == null ? void 0 : _b.stop_sequence) != null ?
|
|
1119
|
+
stopSequence = (_d = (_c = (_b = value.messageStop.additionalModelResponseFields) == null ? void 0 : _b.delta) == null ? void 0 : _c.stop_sequence) != null ? _d : null;
|
|
1117
1120
|
}
|
|
1118
1121
|
if (value.metadata) {
|
|
1119
1122
|
if (value.metadata.usage) {
|
|
1120
1123
|
usage = value.metadata.usage;
|
|
1121
1124
|
}
|
|
1122
|
-
const cacheUsage = ((
|
|
1125
|
+
const cacheUsage = ((_e = value.metadata.usage) == null ? void 0 : _e.cacheWriteInputTokens) != null ? {
|
|
1123
1126
|
usage: {
|
|
1124
1127
|
cacheWriteInputTokens: value.metadata.usage.cacheWriteInputTokens
|
|
1125
1128
|
}
|
|
@@ -1136,7 +1139,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1136
1139
|
};
|
|
1137
1140
|
}
|
|
1138
1141
|
}
|
|
1139
|
-
if (((
|
|
1142
|
+
if (((_f = value.contentBlockStart) == null ? void 0 : _f.contentBlockIndex) != null && !((_h = (_g = value.contentBlockStart) == null ? void 0 : _g.start) == null ? void 0 : _h.toolUse)) {
|
|
1140
1143
|
const blockIndex = value.contentBlockStart.contentBlockIndex;
|
|
1141
1144
|
contentBlocks[blockIndex] = { type: "text" };
|
|
1142
1145
|
controller.enqueue({
|
|
@@ -1144,7 +1147,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1144
1147
|
id: String(blockIndex)
|
|
1145
1148
|
});
|
|
1146
1149
|
}
|
|
1147
|
-
if (((
|
|
1150
|
+
if (((_i = value.contentBlockDelta) == null ? void 0 : _i.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
|
|
1148
1151
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
1149
1152
|
if (contentBlocks[blockIndex] == null) {
|
|
1150
1153
|
contentBlocks[blockIndex] = { type: "text" };
|
|
@@ -1159,7 +1162,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1159
1162
|
delta: value.contentBlockDelta.delta.text
|
|
1160
1163
|
});
|
|
1161
1164
|
}
|
|
1162
|
-
if (((
|
|
1165
|
+
if (((_j = value.contentBlockStop) == null ? void 0 : _j.contentBlockIndex) != null) {
|
|
1163
1166
|
const blockIndex = value.contentBlockStop.contentBlockIndex;
|
|
1164
1167
|
const contentBlock = contentBlocks[blockIndex];
|
|
1165
1168
|
if (contentBlock != null) {
|
|
@@ -1205,7 +1208,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1205
1208
|
delete contentBlocks[blockIndex];
|
|
1206
1209
|
}
|
|
1207
1210
|
}
|
|
1208
|
-
if (((
|
|
1211
|
+
if (((_k = value.contentBlockDelta) == null ? void 0 : _k.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
|
|
1209
1212
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
1210
1213
|
const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
|
|
1211
1214
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
@@ -1246,7 +1249,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1246
1249
|
}
|
|
1247
1250
|
}
|
|
1248
1251
|
const contentBlockStart = value.contentBlockStart;
|
|
1249
|
-
if (((
|
|
1252
|
+
if (((_l = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _l.toolUse) != null) {
|
|
1250
1253
|
const toolUse = contentBlockStart.start.toolUse;
|
|
1251
1254
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
1252
1255
|
const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
|
|
@@ -1270,7 +1273,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1270
1273
|
const blockIndex = contentBlockDelta.contentBlockIndex;
|
|
1271
1274
|
const contentBlock = contentBlocks[blockIndex];
|
|
1272
1275
|
if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
|
|
1273
|
-
const delta = (
|
|
1276
|
+
const delta = (_m = contentBlockDelta.delta.toolUse.input) != null ? _m : "";
|
|
1274
1277
|
if (!contentBlock.isJsonResponseTool) {
|
|
1275
1278
|
controller.enqueue({
|
|
1276
1279
|
type: "tool-input-delta",
|
|
@@ -1326,7 +1329,9 @@ var BedrockStopReasonSchema = z3.union([
|
|
|
1326
1329
|
z3.string()
|
|
1327
1330
|
]);
|
|
1328
1331
|
var BedrockAdditionalModelResponseFieldsSchema = z3.object({
|
|
1329
|
-
|
|
1332
|
+
delta: z3.object({
|
|
1333
|
+
stop_sequence: z3.string().nullish()
|
|
1334
|
+
}).nullish()
|
|
1330
1335
|
}).catchall(z3.unknown());
|
|
1331
1336
|
var BedrockToolUseSchema = z3.object({
|
|
1332
1337
|
toolUseId: z3.string(),
|
|
@@ -1746,7 +1751,7 @@ import {
|
|
|
1746
1751
|
import { AwsV4Signer } from "aws4fetch";
|
|
1747
1752
|
|
|
1748
1753
|
// src/version.ts
|
|
1749
|
-
var VERSION = true ? "4.0.
|
|
1754
|
+
var VERSION = true ? "4.0.4" : "0.0.0-test";
|
|
1750
1755
|
|
|
1751
1756
|
// src/bedrock-sigv4-fetch.ts
|
|
1752
1757
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|