@ai-sdk/amazon-bedrock 4.0.157 → 4.0.159
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/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 +89 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -30
- package/dist/index.mjs.map +1 -1
- package/dist/mantle/index.js +1 -1
- package/dist/mantle/index.mjs +1 -1
- package/package.json +2 -2
- package/src/bedrock-api-types.ts +7 -0
- package/src/bedrock-chat-language-model.ts +62 -1
- package/src/bedrock-event-stream-decoder.ts +12 -3
- package/src/bedrock-event-stream-response-handler.ts +31 -22
- package/src/bedrock-reasoning-metadata.ts +1 -0
- package/src/convert-to-bedrock-chat-messages.ts +6 -0
package/dist/index.js
CHANGED
|
@@ -154,7 +154,7 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
154
154
|
return body.pipeThrough(
|
|
155
155
|
new TransformStream({
|
|
156
156
|
async transform(chunk, controller) {
|
|
157
|
-
var _a, _b;
|
|
157
|
+
var _a, _b, _c;
|
|
158
158
|
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
159
159
|
newBuffer.set(buffer);
|
|
160
160
|
newBuffer.set(chunk, buffer.length);
|
|
@@ -173,8 +173,12 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
173
173
|
buffer = buffer.slice(totalLength);
|
|
174
174
|
const messageType = (_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value;
|
|
175
175
|
const eventType = (_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value;
|
|
176
|
+
const exceptionType = (_c = decoded.headers[":exception-type"]) == null ? void 0 : _c.value;
|
|
176
177
|
const data = textDecoder.decode(decoded.body);
|
|
177
|
-
await processEvent(
|
|
178
|
+
await processEvent(
|
|
179
|
+
{ messageType, eventType, exceptionType, data },
|
|
180
|
+
controller
|
|
181
|
+
);
|
|
178
182
|
}
|
|
179
183
|
},
|
|
180
184
|
flush() {
|
|
@@ -199,29 +203,31 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
199
203
|
value: createBedrockEventStreamDecoder(
|
|
200
204
|
response.body,
|
|
201
205
|
async (event, controller) => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
206
|
+
const payloadType = event.messageType === "event" ? event.eventType : event.messageType === "exception" ? event.exceptionType : void 0;
|
|
207
|
+
if (payloadType == null) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const parsedDataResult = await (0, import_provider_utils.safeParseJSON)({ text: event.data });
|
|
211
|
+
if (!parsedDataResult.success) {
|
|
212
|
+
controller.enqueue(parsedDataResult);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
delete parsedDataResult.value.p;
|
|
216
|
+
const wrappedData = {
|
|
217
|
+
[payloadType]: parsedDataResult.value
|
|
218
|
+
};
|
|
219
|
+
const validatedWrappedData = await (0, import_provider_utils.safeValidateTypes)({
|
|
220
|
+
value: wrappedData,
|
|
221
|
+
schema: chunkSchema
|
|
222
|
+
});
|
|
223
|
+
if (!validatedWrappedData.success) {
|
|
224
|
+
controller.enqueue(validatedWrappedData);
|
|
225
|
+
} else {
|
|
226
|
+
controller.enqueue({
|
|
227
|
+
success: true,
|
|
228
|
+
value: validatedWrappedData.value,
|
|
229
|
+
rawValue: wrappedData
|
|
215
230
|
});
|
|
216
|
-
if (!validatedWrappedData.success) {
|
|
217
|
-
controller.enqueue(validatedWrappedData);
|
|
218
|
-
} else {
|
|
219
|
-
controller.enqueue({
|
|
220
|
-
success: true,
|
|
221
|
-
value: validatedWrappedData.value,
|
|
222
|
-
rawValue: wrappedData
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
233
|
)
|
|
@@ -417,7 +423,8 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
|
417
423
|
var import_v43 = require("zod/v4");
|
|
418
424
|
var bedrockReasoningMetadataSchema = import_v43.z.object({
|
|
419
425
|
signature: import_v43.z.string().optional(),
|
|
420
|
-
redactedData: import_v43.z.string().optional()
|
|
426
|
+
redactedData: import_v43.z.string().optional(),
|
|
427
|
+
redactedContent: import_v43.z.string().optional()
|
|
421
428
|
});
|
|
422
429
|
|
|
423
430
|
// src/normalize-tool-call-id.ts
|
|
@@ -731,6 +738,12 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
731
738
|
}
|
|
732
739
|
}
|
|
733
740
|
});
|
|
741
|
+
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedContent) != null) {
|
|
742
|
+
bedrockContent.push({
|
|
743
|
+
reasoningContent: {
|
|
744
|
+
redactedContent: reasoningMetadata.redactedContent
|
|
745
|
+
}
|
|
746
|
+
});
|
|
734
747
|
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
|
|
735
748
|
bedrockContent.push({
|
|
736
749
|
reasoningContent: {
|
|
@@ -1217,6 +1230,16 @@ var BedrockChatLanguageModel = class {
|
|
|
1217
1230
|
}
|
|
1218
1231
|
}
|
|
1219
1232
|
});
|
|
1233
|
+
} else if ("redactedContent" in part.reasoningContent) {
|
|
1234
|
+
content.push({
|
|
1235
|
+
type: "reasoning",
|
|
1236
|
+
text: "",
|
|
1237
|
+
providerMetadata: {
|
|
1238
|
+
bedrock: {
|
|
1239
|
+
redactedContent: part.reasoningContent.redactedContent
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
});
|
|
1220
1243
|
}
|
|
1221
1244
|
}
|
|
1222
1245
|
if (part.toolUse) {
|
|
@@ -1330,7 +1353,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1330
1353
|
});
|
|
1331
1354
|
},
|
|
1332
1355
|
transform(chunk, controller) {
|
|
1333
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1356
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1334
1357
|
function enqueueError(bedrockError) {
|
|
1335
1358
|
finishReason = { unified: "error", raw: void 0 };
|
|
1336
1359
|
controller.enqueue({ type: "error", error: bedrockError });
|
|
@@ -1351,6 +1374,10 @@ var BedrockChatLanguageModel = class {
|
|
|
1351
1374
|
enqueueError(value.modelStreamErrorException);
|
|
1352
1375
|
return;
|
|
1353
1376
|
}
|
|
1377
|
+
if (value.serviceUnavailableException) {
|
|
1378
|
+
enqueueError(value.serviceUnavailableException);
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1354
1381
|
if (value.throttlingException) {
|
|
1355
1382
|
enqueueError(value.throttlingException);
|
|
1356
1383
|
return;
|
|
@@ -1434,9 +1461,15 @@ var BedrockChatLanguageModel = class {
|
|
|
1434
1461
|
const contentBlock = contentBlocks[blockIndex];
|
|
1435
1462
|
if (contentBlock != null) {
|
|
1436
1463
|
if (contentBlock.type === "reasoning") {
|
|
1464
|
+
const redactedPayload = contentBlock.redactedContent != null ? { redactedContent: contentBlock.redactedContent } : null;
|
|
1437
1465
|
controller.enqueue({
|
|
1438
1466
|
type: "reasoning-end",
|
|
1439
|
-
id: String(blockIndex)
|
|
1467
|
+
id: String(blockIndex),
|
|
1468
|
+
...redactedPayload != null ? {
|
|
1469
|
+
providerMetadata: {
|
|
1470
|
+
bedrock: redactedPayload
|
|
1471
|
+
}
|
|
1472
|
+
} : {}
|
|
1440
1473
|
});
|
|
1441
1474
|
} else if (contentBlock.type === "text") {
|
|
1442
1475
|
controller.enqueue({
|
|
@@ -1527,10 +1560,22 @@ var BedrockChatLanguageModel = class {
|
|
|
1527
1560
|
}
|
|
1528
1561
|
}
|
|
1529
1562
|
});
|
|
1563
|
+
} else if ("redactedContent" in reasoningContent && reasoningContent.redactedContent) {
|
|
1564
|
+
if (contentBlocks[blockIndex] == null) {
|
|
1565
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
1566
|
+
controller.enqueue({
|
|
1567
|
+
type: "reasoning-start",
|
|
1568
|
+
id: String(blockIndex)
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
const contentBlock = contentBlocks[blockIndex];
|
|
1572
|
+
if (contentBlock.type === "reasoning") {
|
|
1573
|
+
contentBlock.redactedContent = ((_p = contentBlock.redactedContent) != null ? _p : "") + reasoningContent.redactedContent;
|
|
1574
|
+
}
|
|
1530
1575
|
}
|
|
1531
1576
|
}
|
|
1532
1577
|
const contentBlockStart = value.contentBlockStart;
|
|
1533
|
-
if (((
|
|
1578
|
+
if (((_q = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _q.toolUse) != null) {
|
|
1534
1579
|
const toolUse = contentBlockStart.start.toolUse;
|
|
1535
1580
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
1536
1581
|
const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
|
|
@@ -1558,7 +1603,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1558
1603
|
const blockIndex = contentBlockDelta.contentBlockIndex;
|
|
1559
1604
|
const contentBlock = contentBlocks[blockIndex];
|
|
1560
1605
|
if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
|
|
1561
|
-
const delta = (
|
|
1606
|
+
const delta = (_r = contentBlockDelta.delta.toolUse.input) != null ? _r : "";
|
|
1562
1607
|
if (!contentBlock.isJsonResponseTool) {
|
|
1563
1608
|
controller.enqueue({
|
|
1564
1609
|
type: "tool-input-delta",
|
|
@@ -1696,6 +1741,13 @@ var BedrockResponseSchema = import_v44.z.object({
|
|
|
1696
1741
|
}),
|
|
1697
1742
|
import_v44.z.object({
|
|
1698
1743
|
redactedReasoning: BedrockRedactedReasoningSchema
|
|
1744
|
+
}),
|
|
1745
|
+
// `redactedContent` is a member of the documented
|
|
1746
|
+
// ReasoningContentBlock union. OpenAI models on Bedrock
|
|
1747
|
+
// (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
|
|
1748
|
+
// reasoning in this shape.
|
|
1749
|
+
import_v44.z.object({
|
|
1750
|
+
redactedContent: import_v44.z.string()
|
|
1699
1751
|
})
|
|
1700
1752
|
]).nullish()
|
|
1701
1753
|
})
|
|
@@ -1733,6 +1785,12 @@ var BedrockStreamSchema = import_v44.z.object({
|
|
|
1733
1785
|
}),
|
|
1734
1786
|
import_v44.z.object({
|
|
1735
1787
|
reasoningContent: import_v44.z.object({ data: import_v44.z.string() })
|
|
1788
|
+
}),
|
|
1789
|
+
// `redactedContent` is a member of the documented
|
|
1790
|
+
// ReasoningContentBlockDelta union. OpenAI models on Bedrock stream
|
|
1791
|
+
// their encrypted reasoning in this shape.
|
|
1792
|
+
import_v44.z.object({
|
|
1793
|
+
reasoningContent: import_v44.z.object({ redactedContent: import_v44.z.string() })
|
|
1736
1794
|
})
|
|
1737
1795
|
]).nullish()
|
|
1738
1796
|
}).nullish(),
|
|
@@ -1763,6 +1821,7 @@ var BedrockStreamSchema = import_v44.z.object({
|
|
|
1763
1821
|
}).nullish()
|
|
1764
1822
|
}).nullish(),
|
|
1765
1823
|
modelStreamErrorException: import_v44.z.record(import_v44.z.string(), import_v44.z.unknown()).nullish(),
|
|
1824
|
+
serviceUnavailableException: import_v44.z.record(import_v44.z.string(), import_v44.z.unknown()).nullish(),
|
|
1766
1825
|
throttlingException: import_v44.z.record(import_v44.z.string(), import_v44.z.unknown()).nullish(),
|
|
1767
1826
|
validationException: import_v44.z.record(import_v44.z.string(), import_v44.z.unknown()).nullish()
|
|
1768
1827
|
});
|
|
@@ -2171,7 +2230,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
2171
2230
|
var import_aws4fetch = require("aws4fetch");
|
|
2172
2231
|
|
|
2173
2232
|
// src/version.ts
|
|
2174
|
-
var VERSION = true ? "4.0.
|
|
2233
|
+
var VERSION = true ? "4.0.159" : "0.0.0-test";
|
|
2175
2234
|
|
|
2176
2235
|
// src/bedrock-sigv4-fetch.ts
|
|
2177
2236
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|