@ai-sdk/amazon-bedrock 3.0.71 → 3.0.72
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 +6 -0
- package/dist/index.js +28 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
30
30
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.72" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/bedrock-provider.ts
|
|
36
36
|
var import_internal2 = require("@ai-sdk/anthropic/internal");
|
|
@@ -871,12 +871,15 @@ var BedrockChatLanguageModel = class {
|
|
|
871
871
|
additionalModelRequestFields: __,
|
|
872
872
|
...filteredBedrockOptions
|
|
873
873
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
874
|
+
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
874
875
|
return {
|
|
875
876
|
command: {
|
|
876
877
|
system,
|
|
877
878
|
messages,
|
|
878
879
|
additionalModelRequestFields: bedrockOptions.additionalModelRequestFields,
|
|
879
|
-
additionalModelResponseFieldPaths
|
|
880
|
+
...additionalModelResponseFieldPaths && {
|
|
881
|
+
additionalModelResponseFieldPaths
|
|
882
|
+
},
|
|
880
883
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
881
884
|
inferenceConfig
|
|
882
885
|
},
|
|
@@ -894,7 +897,7 @@ var BedrockChatLanguageModel = class {
|
|
|
894
897
|
return (0, import_provider_utils4.combineHeaders)(await (0, import_provider_utils4.resolve)(this.config.headers), headers);
|
|
895
898
|
}
|
|
896
899
|
async doGenerate(options) {
|
|
897
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
900
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
898
901
|
const {
|
|
899
902
|
command: args,
|
|
900
903
|
warnings,
|
|
@@ -968,11 +971,11 @@ var BedrockChatLanguageModel = class {
|
|
|
968
971
|
}
|
|
969
972
|
}
|
|
970
973
|
}
|
|
971
|
-
const stopSequence = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.stop_sequence) != null ?
|
|
974
|
+
const stopSequence = (_j = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.delta) == null ? void 0 : _i.stop_sequence) != null ? _j : null;
|
|
972
975
|
const providerMetadata = response.trace || response.usage || isJsonResponseFromTool || stopSequence ? {
|
|
973
976
|
bedrock: {
|
|
974
977
|
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
975
|
-
...((
|
|
978
|
+
...((_k = response.usage) == null ? void 0 : _k.cacheWriteInputTokens) != null && {
|
|
976
979
|
usage: {
|
|
977
980
|
cacheWriteInputTokens: response.usage.cacheWriteInputTokens
|
|
978
981
|
}
|
|
@@ -988,10 +991,10 @@ var BedrockChatLanguageModel = class {
|
|
|
988
991
|
isJsonResponseFromTool
|
|
989
992
|
),
|
|
990
993
|
usage: {
|
|
991
|
-
inputTokens: (
|
|
992
|
-
outputTokens: (
|
|
993
|
-
totalTokens: ((
|
|
994
|
-
cachedInputTokens: (
|
|
994
|
+
inputTokens: (_l = response.usage) == null ? void 0 : _l.inputTokens,
|
|
995
|
+
outputTokens: (_m = response.usage) == null ? void 0 : _m.outputTokens,
|
|
996
|
+
totalTokens: ((_n = response.usage) == null ? void 0 : _n.inputTokens) + ((_o = response.usage) == null ? void 0 : _o.outputTokens),
|
|
997
|
+
cachedInputTokens: (_q = (_p = response.usage) == null ? void 0 : _p.cacheReadInputTokens) != null ? _q : void 0
|
|
995
998
|
},
|
|
996
999
|
response: {
|
|
997
1000
|
// TODO add id, timestamp, etc
|
|
@@ -1037,7 +1040,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1037
1040
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1038
1041
|
},
|
|
1039
1042
|
transform(chunk, controller) {
|
|
1040
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
1043
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1041
1044
|
function enqueueError(bedrockError) {
|
|
1042
1045
|
finishReason = "error";
|
|
1043
1046
|
controller.enqueue({ type: "error", error: bedrockError });
|
|
@@ -1071,14 +1074,14 @@ var BedrockChatLanguageModel = class {
|
|
|
1071
1074
|
value.messageStop.stopReason,
|
|
1072
1075
|
isJsonResponseFromTool
|
|
1073
1076
|
);
|
|
1074
|
-
stopSequence = (_b = (_a = value.messageStop.additionalModelResponseFields) == null ? void 0 : _a.stop_sequence) != null ?
|
|
1077
|
+
stopSequence = (_c = (_b = (_a = value.messageStop.additionalModelResponseFields) == null ? void 0 : _a.delta) == null ? void 0 : _b.stop_sequence) != null ? _c : null;
|
|
1075
1078
|
}
|
|
1076
1079
|
if (value.metadata) {
|
|
1077
|
-
usage.inputTokens = (
|
|
1078
|
-
usage.outputTokens = (
|
|
1079
|
-
usage.totalTokens = ((
|
|
1080
|
-
usage.cachedInputTokens = (
|
|
1081
|
-
const cacheUsage = ((
|
|
1080
|
+
usage.inputTokens = (_e = (_d = value.metadata.usage) == null ? void 0 : _d.inputTokens) != null ? _e : usage.inputTokens;
|
|
1081
|
+
usage.outputTokens = (_g = (_f = value.metadata.usage) == null ? void 0 : _f.outputTokens) != null ? _g : usage.outputTokens;
|
|
1082
|
+
usage.totalTokens = ((_h = usage.inputTokens) != null ? _h : 0) + ((_i = usage.outputTokens) != null ? _i : 0);
|
|
1083
|
+
usage.cachedInputTokens = (_k = (_j = value.metadata.usage) == null ? void 0 : _j.cacheReadInputTokens) != null ? _k : usage.cachedInputTokens;
|
|
1084
|
+
const cacheUsage = ((_l = value.metadata.usage) == null ? void 0 : _l.cacheWriteInputTokens) != null ? {
|
|
1082
1085
|
usage: {
|
|
1083
1086
|
cacheWriteInputTokens: value.metadata.usage.cacheWriteInputTokens
|
|
1084
1087
|
}
|
|
@@ -1095,7 +1098,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1095
1098
|
};
|
|
1096
1099
|
}
|
|
1097
1100
|
}
|
|
1098
|
-
if (((
|
|
1101
|
+
if (((_m = value.contentBlockStart) == null ? void 0 : _m.contentBlockIndex) != null && !((_o = (_n = value.contentBlockStart) == null ? void 0 : _n.start) == null ? void 0 : _o.toolUse)) {
|
|
1099
1102
|
const blockIndex = value.contentBlockStart.contentBlockIndex;
|
|
1100
1103
|
contentBlocks[blockIndex] = { type: "text" };
|
|
1101
1104
|
controller.enqueue({
|
|
@@ -1103,7 +1106,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1103
1106
|
id: String(blockIndex)
|
|
1104
1107
|
});
|
|
1105
1108
|
}
|
|
1106
|
-
if (((
|
|
1109
|
+
if (((_p = value.contentBlockDelta) == null ? void 0 : _p.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
|
|
1107
1110
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
1108
1111
|
if (contentBlocks[blockIndex] == null) {
|
|
1109
1112
|
contentBlocks[blockIndex] = { type: "text" };
|
|
@@ -1118,7 +1121,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1118
1121
|
delta: value.contentBlockDelta.delta.text
|
|
1119
1122
|
});
|
|
1120
1123
|
}
|
|
1121
|
-
if (((
|
|
1124
|
+
if (((_q = value.contentBlockStop) == null ? void 0 : _q.contentBlockIndex) != null) {
|
|
1122
1125
|
const blockIndex = value.contentBlockStop.contentBlockIndex;
|
|
1123
1126
|
const contentBlock = contentBlocks[blockIndex];
|
|
1124
1127
|
if (contentBlock != null) {
|
|
@@ -1164,7 +1167,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1164
1167
|
delete contentBlocks[blockIndex];
|
|
1165
1168
|
}
|
|
1166
1169
|
}
|
|
1167
|
-
if (((
|
|
1170
|
+
if (((_r = value.contentBlockDelta) == null ? void 0 : _r.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
|
|
1168
1171
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
1169
1172
|
const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
|
|
1170
1173
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
@@ -1205,7 +1208,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1205
1208
|
}
|
|
1206
1209
|
}
|
|
1207
1210
|
const contentBlockStart = value.contentBlockStart;
|
|
1208
|
-
if (((
|
|
1211
|
+
if (((_s = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _s.toolUse) != null) {
|
|
1209
1212
|
const toolUse = contentBlockStart.start.toolUse;
|
|
1210
1213
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
1211
1214
|
const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
|
|
@@ -1229,7 +1232,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1229
1232
|
const blockIndex = contentBlockDelta.contentBlockIndex;
|
|
1230
1233
|
const contentBlock = contentBlocks[blockIndex];
|
|
1231
1234
|
if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
|
|
1232
|
-
const delta = (
|
|
1235
|
+
const delta = (_t = contentBlockDelta.delta.toolUse.input) != null ? _t : "";
|
|
1233
1236
|
if (!contentBlock.isJsonResponseTool) {
|
|
1234
1237
|
controller.enqueue({
|
|
1235
1238
|
type: "tool-input-delta",
|
|
@@ -1285,7 +1288,9 @@ var BedrockStopReasonSchema = import_v43.z.union([
|
|
|
1285
1288
|
import_v43.z.string()
|
|
1286
1289
|
]);
|
|
1287
1290
|
var BedrockAdditionalModelResponseFieldsSchema = import_v43.z.object({
|
|
1288
|
-
|
|
1291
|
+
delta: import_v43.z.object({
|
|
1292
|
+
stop_sequence: import_v43.z.string().nullish()
|
|
1293
|
+
}).nullish()
|
|
1289
1294
|
}).catchall(import_v43.z.unknown());
|
|
1290
1295
|
var BedrockToolUseSchema = import_v43.z.object({
|
|
1291
1296
|
toolUseId: import_v43.z.string(),
|