@ai-sdk/amazon-bedrock 3.0.117 → 3.0.119
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 +12 -0
- package/dist/anthropic/index.js +7 -3
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +7 -3
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.js +90 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -30
- 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.119" : "0.0.0-test";
|
|
12
12
|
|
|
13
13
|
// src/bedrock-provider.ts
|
|
14
14
|
import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
|
|
@@ -131,7 +131,7 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
131
131
|
return body.pipeThrough(
|
|
132
132
|
new TransformStream({
|
|
133
133
|
async transform(chunk, controller) {
|
|
134
|
-
var _a, _b;
|
|
134
|
+
var _a, _b, _c;
|
|
135
135
|
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
136
136
|
newBuffer.set(buffer);
|
|
137
137
|
newBuffer.set(chunk, buffer.length);
|
|
@@ -150,8 +150,12 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
150
150
|
buffer = buffer.slice(totalLength);
|
|
151
151
|
const messageType = (_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value;
|
|
152
152
|
const eventType = (_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value;
|
|
153
|
+
const exceptionType = (_c = decoded.headers[":exception-type"]) == null ? void 0 : _c.value;
|
|
153
154
|
const data = textDecoder.decode(decoded.body);
|
|
154
|
-
await processEvent(
|
|
155
|
+
await processEvent(
|
|
156
|
+
{ messageType, eventType, exceptionType, data },
|
|
157
|
+
controller
|
|
158
|
+
);
|
|
155
159
|
}
|
|
156
160
|
},
|
|
157
161
|
flush() {
|
|
@@ -176,29 +180,31 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
176
180
|
value: createBedrockEventStreamDecoder(
|
|
177
181
|
response.body,
|
|
178
182
|
async (event, controller) => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
183
|
+
const payloadType = event.messageType === "event" ? event.eventType : event.messageType === "exception" ? event.exceptionType : void 0;
|
|
184
|
+
if (payloadType == null) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const parsedDataResult = await safeParseJSON({ text: event.data });
|
|
188
|
+
if (!parsedDataResult.success) {
|
|
189
|
+
controller.enqueue(parsedDataResult);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
delete parsedDataResult.value.p;
|
|
193
|
+
const wrappedData = {
|
|
194
|
+
[payloadType]: parsedDataResult.value
|
|
195
|
+
};
|
|
196
|
+
const validatedWrappedData = await safeValidateTypes({
|
|
197
|
+
value: wrappedData,
|
|
198
|
+
schema: chunkSchema
|
|
199
|
+
});
|
|
200
|
+
if (!validatedWrappedData.success) {
|
|
201
|
+
controller.enqueue(validatedWrappedData);
|
|
202
|
+
} else {
|
|
203
|
+
controller.enqueue({
|
|
204
|
+
success: true,
|
|
205
|
+
value: validatedWrappedData.value,
|
|
206
|
+
rawValue: wrappedData
|
|
192
207
|
});
|
|
193
|
-
if (!validatedWrappedData.success) {
|
|
194
|
-
controller.enqueue(validatedWrappedData);
|
|
195
|
-
} else {
|
|
196
|
-
controller.enqueue({
|
|
197
|
-
success: true,
|
|
198
|
-
value: validatedWrappedData.value,
|
|
199
|
-
rawValue: wrappedData
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
208
|
}
|
|
203
209
|
}
|
|
204
210
|
)
|
|
@@ -359,7 +365,8 @@ import { convertToBase64, parseProviderOptions } from "@ai-sdk/provider-utils";
|
|
|
359
365
|
import { z as z3 } from "zod/v4";
|
|
360
366
|
var bedrockReasoningMetadataSchema = z3.object({
|
|
361
367
|
signature: z3.string().optional(),
|
|
362
|
-
redactedData: z3.string().optional()
|
|
368
|
+
redactedData: z3.string().optional(),
|
|
369
|
+
redactedContent: z3.string().optional()
|
|
363
370
|
});
|
|
364
371
|
|
|
365
372
|
// src/convert-to-bedrock-chat-messages.ts
|
|
@@ -588,6 +595,12 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
588
595
|
}
|
|
589
596
|
}
|
|
590
597
|
});
|
|
598
|
+
} else if (reasoningMetadata.redactedContent != null) {
|
|
599
|
+
bedrockContent.push({
|
|
600
|
+
reasoningContent: {
|
|
601
|
+
redactedContent: reasoningMetadata.redactedContent
|
|
602
|
+
}
|
|
603
|
+
});
|
|
591
604
|
} else if (reasoningMetadata.redactedData != null) {
|
|
592
605
|
bedrockContent.push({
|
|
593
606
|
reasoningContent: {
|
|
@@ -1049,6 +1062,16 @@ var BedrockChatLanguageModel = class {
|
|
|
1049
1062
|
}
|
|
1050
1063
|
}
|
|
1051
1064
|
});
|
|
1065
|
+
} else if ("redactedContent" in part.reasoningContent) {
|
|
1066
|
+
content.push({
|
|
1067
|
+
type: "reasoning",
|
|
1068
|
+
text: "",
|
|
1069
|
+
providerMetadata: {
|
|
1070
|
+
bedrock: {
|
|
1071
|
+
redactedContent: part.reasoningContent.redactedContent
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1052
1075
|
}
|
|
1053
1076
|
}
|
|
1054
1077
|
if (part.toolUse) {
|
|
@@ -1138,7 +1161,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1138
1161
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1139
1162
|
},
|
|
1140
1163
|
transform(chunk, controller) {
|
|
1141
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1164
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
1142
1165
|
function enqueueError(bedrockError) {
|
|
1143
1166
|
finishReason = "error";
|
|
1144
1167
|
controller.enqueue({ type: "error", error: bedrockError });
|
|
@@ -1159,6 +1182,10 @@ var BedrockChatLanguageModel = class {
|
|
|
1159
1182
|
enqueueError(value.modelStreamErrorException);
|
|
1160
1183
|
return;
|
|
1161
1184
|
}
|
|
1185
|
+
if (value.serviceUnavailableException) {
|
|
1186
|
+
enqueueError(value.serviceUnavailableException);
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1162
1189
|
if (value.throttlingException) {
|
|
1163
1190
|
enqueueError(value.throttlingException);
|
|
1164
1191
|
return;
|
|
@@ -1226,7 +1253,14 @@ var BedrockChatLanguageModel = class {
|
|
|
1226
1253
|
if (contentBlock.type === "reasoning") {
|
|
1227
1254
|
controller.enqueue({
|
|
1228
1255
|
type: "reasoning-end",
|
|
1229
|
-
id: String(blockIndex)
|
|
1256
|
+
id: String(blockIndex),
|
|
1257
|
+
...contentBlock.redactedContent != null ? {
|
|
1258
|
+
providerMetadata: {
|
|
1259
|
+
bedrock: {
|
|
1260
|
+
redactedContent: contentBlock.redactedContent
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
} : {}
|
|
1230
1264
|
});
|
|
1231
1265
|
} else if (contentBlock.type === "text") {
|
|
1232
1266
|
controller.enqueue({
|
|
@@ -1317,10 +1351,22 @@ var BedrockChatLanguageModel = class {
|
|
|
1317
1351
|
}
|
|
1318
1352
|
}
|
|
1319
1353
|
});
|
|
1354
|
+
} else if ("redactedContent" in reasoningContent && reasoningContent.redactedContent) {
|
|
1355
|
+
if (contentBlocks[blockIndex] == null) {
|
|
1356
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
1357
|
+
controller.enqueue({
|
|
1358
|
+
type: "reasoning-start",
|
|
1359
|
+
id: String(blockIndex)
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
const contentBlock = contentBlocks[blockIndex];
|
|
1363
|
+
if (contentBlock.type === "reasoning") {
|
|
1364
|
+
contentBlock.redactedContent = ((_s = contentBlock.redactedContent) != null ? _s : "") + reasoningContent.redactedContent;
|
|
1365
|
+
}
|
|
1320
1366
|
}
|
|
1321
1367
|
}
|
|
1322
1368
|
const contentBlockStart = value.contentBlockStart;
|
|
1323
|
-
if (((
|
|
1369
|
+
if (((_t = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _t.toolUse) != null) {
|
|
1324
1370
|
const toolUse = contentBlockStart.start.toolUse;
|
|
1325
1371
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
1326
1372
|
const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
|
|
@@ -1344,7 +1390,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1344
1390
|
const blockIndex = contentBlockDelta.contentBlockIndex;
|
|
1345
1391
|
const contentBlock = contentBlocks[blockIndex];
|
|
1346
1392
|
if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
|
|
1347
|
-
const delta = (
|
|
1393
|
+
const delta = (_u = contentBlockDelta.delta.toolUse.input) != null ? _u : "";
|
|
1348
1394
|
if (!contentBlock.isJsonResponseTool) {
|
|
1349
1395
|
controller.enqueue({
|
|
1350
1396
|
type: "tool-input-delta",
|
|
@@ -1435,6 +1481,13 @@ var BedrockResponseSchema = z4.object({
|
|
|
1435
1481
|
}),
|
|
1436
1482
|
z4.object({
|
|
1437
1483
|
redactedReasoning: BedrockRedactedReasoningSchema
|
|
1484
|
+
}),
|
|
1485
|
+
// `redactedContent` is a member of the documented
|
|
1486
|
+
// ReasoningContentBlock union. OpenAI models on Bedrock
|
|
1487
|
+
// (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
|
|
1488
|
+
// reasoning in this shape.
|
|
1489
|
+
z4.object({
|
|
1490
|
+
redactedContent: z4.string()
|
|
1438
1491
|
})
|
|
1439
1492
|
]).nullish()
|
|
1440
1493
|
})
|
|
@@ -1469,6 +1522,12 @@ var BedrockStreamSchema = z4.object({
|
|
|
1469
1522
|
}),
|
|
1470
1523
|
z4.object({
|
|
1471
1524
|
reasoningContent: z4.object({ data: z4.string() })
|
|
1525
|
+
}),
|
|
1526
|
+
// `redactedContent` is a member of the documented
|
|
1527
|
+
// ReasoningContentBlockDelta union. OpenAI models on Bedrock stream
|
|
1528
|
+
// their encrypted reasoning in this shape.
|
|
1529
|
+
z4.object({
|
|
1530
|
+
reasoningContent: z4.object({ redactedContent: z4.string() })
|
|
1472
1531
|
})
|
|
1473
1532
|
]).nullish()
|
|
1474
1533
|
}).nullish(),
|
|
@@ -1496,6 +1555,7 @@ var BedrockStreamSchema = z4.object({
|
|
|
1496
1555
|
}).nullish()
|
|
1497
1556
|
}).nullish(),
|
|
1498
1557
|
modelStreamErrorException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1558
|
+
serviceUnavailableException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1499
1559
|
throttlingException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1500
1560
|
validationException: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1501
1561
|
});
|