@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.mjs
CHANGED
|
@@ -147,7 +147,7 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
147
147
|
return body.pipeThrough(
|
|
148
148
|
new TransformStream({
|
|
149
149
|
async transform(chunk, controller) {
|
|
150
|
-
var _a, _b;
|
|
150
|
+
var _a, _b, _c;
|
|
151
151
|
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
152
152
|
newBuffer.set(buffer);
|
|
153
153
|
newBuffer.set(chunk, buffer.length);
|
|
@@ -166,8 +166,12 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
166
166
|
buffer = buffer.slice(totalLength);
|
|
167
167
|
const messageType = (_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value;
|
|
168
168
|
const eventType = (_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value;
|
|
169
|
+
const exceptionType = (_c = decoded.headers[":exception-type"]) == null ? void 0 : _c.value;
|
|
169
170
|
const data = textDecoder.decode(decoded.body);
|
|
170
|
-
await processEvent(
|
|
171
|
+
await processEvent(
|
|
172
|
+
{ messageType, eventType, exceptionType, data },
|
|
173
|
+
controller
|
|
174
|
+
);
|
|
171
175
|
}
|
|
172
176
|
},
|
|
173
177
|
flush() {
|
|
@@ -192,29 +196,31 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
192
196
|
value: createBedrockEventStreamDecoder(
|
|
193
197
|
response.body,
|
|
194
198
|
async (event, controller) => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
199
|
+
const payloadType = event.messageType === "event" ? event.eventType : event.messageType === "exception" ? event.exceptionType : void 0;
|
|
200
|
+
if (payloadType == null) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const parsedDataResult = await safeParseJSON({ text: event.data });
|
|
204
|
+
if (!parsedDataResult.success) {
|
|
205
|
+
controller.enqueue(parsedDataResult);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
delete parsedDataResult.value.p;
|
|
209
|
+
const wrappedData = {
|
|
210
|
+
[payloadType]: parsedDataResult.value
|
|
211
|
+
};
|
|
212
|
+
const validatedWrappedData = await safeValidateTypes({
|
|
213
|
+
value: wrappedData,
|
|
214
|
+
schema: chunkSchema
|
|
215
|
+
});
|
|
216
|
+
if (!validatedWrappedData.success) {
|
|
217
|
+
controller.enqueue(validatedWrappedData);
|
|
218
|
+
} else {
|
|
219
|
+
controller.enqueue({
|
|
220
|
+
success: true,
|
|
221
|
+
value: validatedWrappedData.value,
|
|
222
|
+
rawValue: wrappedData
|
|
208
223
|
});
|
|
209
|
-
if (!validatedWrappedData.success) {
|
|
210
|
-
controller.enqueue(validatedWrappedData);
|
|
211
|
-
} else {
|
|
212
|
-
controller.enqueue({
|
|
213
|
-
success: true,
|
|
214
|
-
value: validatedWrappedData.value,
|
|
215
|
-
rawValue: wrappedData
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
224
|
}
|
|
219
225
|
}
|
|
220
226
|
)
|
|
@@ -421,7 +427,8 @@ import {
|
|
|
421
427
|
import { z as z3 } from "zod/v4";
|
|
422
428
|
var bedrockReasoningMetadataSchema = z3.object({
|
|
423
429
|
signature: z3.string().optional(),
|
|
424
|
-
redactedData: z3.string().optional()
|
|
430
|
+
redactedData: z3.string().optional(),
|
|
431
|
+
redactedContent: z3.string().optional()
|
|
425
432
|
});
|
|
426
433
|
|
|
427
434
|
// src/normalize-tool-call-id.ts
|
|
@@ -735,6 +742,12 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
735
742
|
}
|
|
736
743
|
}
|
|
737
744
|
});
|
|
745
|
+
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedContent) != null) {
|
|
746
|
+
bedrockContent.push({
|
|
747
|
+
reasoningContent: {
|
|
748
|
+
redactedContent: reasoningMetadata.redactedContent
|
|
749
|
+
}
|
|
750
|
+
});
|
|
738
751
|
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
|
|
739
752
|
bedrockContent.push({
|
|
740
753
|
reasoningContent: {
|
|
@@ -1221,6 +1234,16 @@ var BedrockChatLanguageModel = class {
|
|
|
1221
1234
|
}
|
|
1222
1235
|
}
|
|
1223
1236
|
});
|
|
1237
|
+
} else if ("redactedContent" in part.reasoningContent) {
|
|
1238
|
+
content.push({
|
|
1239
|
+
type: "reasoning",
|
|
1240
|
+
text: "",
|
|
1241
|
+
providerMetadata: {
|
|
1242
|
+
bedrock: {
|
|
1243
|
+
redactedContent: part.reasoningContent.redactedContent
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1224
1247
|
}
|
|
1225
1248
|
}
|
|
1226
1249
|
if (part.toolUse) {
|
|
@@ -1334,7 +1357,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1334
1357
|
});
|
|
1335
1358
|
},
|
|
1336
1359
|
transform(chunk, controller) {
|
|
1337
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1360
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1338
1361
|
function enqueueError(bedrockError) {
|
|
1339
1362
|
finishReason = { unified: "error", raw: void 0 };
|
|
1340
1363
|
controller.enqueue({ type: "error", error: bedrockError });
|
|
@@ -1355,6 +1378,10 @@ var BedrockChatLanguageModel = class {
|
|
|
1355
1378
|
enqueueError(value.modelStreamErrorException);
|
|
1356
1379
|
return;
|
|
1357
1380
|
}
|
|
1381
|
+
if (value.serviceUnavailableException) {
|
|
1382
|
+
enqueueError(value.serviceUnavailableException);
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1358
1385
|
if (value.throttlingException) {
|
|
1359
1386
|
enqueueError(value.throttlingException);
|
|
1360
1387
|
return;
|
|
@@ -1438,9 +1465,15 @@ var BedrockChatLanguageModel = class {
|
|
|
1438
1465
|
const contentBlock = contentBlocks[blockIndex];
|
|
1439
1466
|
if (contentBlock != null) {
|
|
1440
1467
|
if (contentBlock.type === "reasoning") {
|
|
1468
|
+
const redactedPayload = contentBlock.redactedContent != null ? { redactedContent: contentBlock.redactedContent } : null;
|
|
1441
1469
|
controller.enqueue({
|
|
1442
1470
|
type: "reasoning-end",
|
|
1443
|
-
id: String(blockIndex)
|
|
1471
|
+
id: String(blockIndex),
|
|
1472
|
+
...redactedPayload != null ? {
|
|
1473
|
+
providerMetadata: {
|
|
1474
|
+
bedrock: redactedPayload
|
|
1475
|
+
}
|
|
1476
|
+
} : {}
|
|
1444
1477
|
});
|
|
1445
1478
|
} else if (contentBlock.type === "text") {
|
|
1446
1479
|
controller.enqueue({
|
|
@@ -1531,10 +1564,22 @@ var BedrockChatLanguageModel = class {
|
|
|
1531
1564
|
}
|
|
1532
1565
|
}
|
|
1533
1566
|
});
|
|
1567
|
+
} else if ("redactedContent" in reasoningContent && reasoningContent.redactedContent) {
|
|
1568
|
+
if (contentBlocks[blockIndex] == null) {
|
|
1569
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
1570
|
+
controller.enqueue({
|
|
1571
|
+
type: "reasoning-start",
|
|
1572
|
+
id: String(blockIndex)
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
const contentBlock = contentBlocks[blockIndex];
|
|
1576
|
+
if (contentBlock.type === "reasoning") {
|
|
1577
|
+
contentBlock.redactedContent = ((_p = contentBlock.redactedContent) != null ? _p : "") + reasoningContent.redactedContent;
|
|
1578
|
+
}
|
|
1534
1579
|
}
|
|
1535
1580
|
}
|
|
1536
1581
|
const contentBlockStart = value.contentBlockStart;
|
|
1537
|
-
if (((
|
|
1582
|
+
if (((_q = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _q.toolUse) != null) {
|
|
1538
1583
|
const toolUse = contentBlockStart.start.toolUse;
|
|
1539
1584
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
1540
1585
|
const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
|
|
@@ -1562,7 +1607,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1562
1607
|
const blockIndex = contentBlockDelta.contentBlockIndex;
|
|
1563
1608
|
const contentBlock = contentBlocks[blockIndex];
|
|
1564
1609
|
if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
|
|
1565
|
-
const delta = (
|
|
1610
|
+
const delta = (_r = contentBlockDelta.delta.toolUse.input) != null ? _r : "";
|
|
1566
1611
|
if (!contentBlock.isJsonResponseTool) {
|
|
1567
1612
|
controller.enqueue({
|
|
1568
1613
|
type: "tool-input-delta",
|
|
@@ -1700,6 +1745,13 @@ var BedrockResponseSchema = z4.object({
|
|
|
1700
1745
|
}),
|
|
1701
1746
|
z4.object({
|
|
1702
1747
|
redactedReasoning: BedrockRedactedReasoningSchema
|
|
1748
|
+
}),
|
|
1749
|
+
// `redactedContent` is a member of the documented
|
|
1750
|
+
// ReasoningContentBlock union. OpenAI models on Bedrock
|
|
1751
|
+
// (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
|
|
1752
|
+
// reasoning in this shape.
|
|
1753
|
+
z4.object({
|
|
1754
|
+
redactedContent: z4.string()
|
|
1703
1755
|
})
|
|
1704
1756
|
]).nullish()
|
|
1705
1757
|
})
|
|
@@ -1737,6 +1789,12 @@ var BedrockStreamSchema = z4.object({
|
|
|
1737
1789
|
}),
|
|
1738
1790
|
z4.object({
|
|
1739
1791
|
reasoningContent: z4.object({ data: z4.string() })
|
|
1792
|
+
}),
|
|
1793
|
+
// `redactedContent` is a member of the documented
|
|
1794
|
+
// ReasoningContentBlockDelta union. OpenAI models on Bedrock stream
|
|
1795
|
+
// their encrypted reasoning in this shape.
|
|
1796
|
+
z4.object({
|
|
1797
|
+
reasoningContent: z4.object({ redactedContent: z4.string() })
|
|
1740
1798
|
})
|
|
1741
1799
|
]).nullish()
|
|
1742
1800
|
}).nullish(),
|
|
@@ -1767,6 +1825,7 @@ var BedrockStreamSchema = z4.object({
|
|
|
1767
1825
|
}).nullish()
|
|
1768
1826
|
}).nullish(),
|
|
1769
1827
|
modelStreamErrorException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1828
|
+
serviceUnavailableException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1770
1829
|
throttlingException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1771
1830
|
validationException: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1772
1831
|
});
|
|
@@ -2196,7 +2255,7 @@ import {
|
|
|
2196
2255
|
import { AwsV4Signer } from "aws4fetch";
|
|
2197
2256
|
|
|
2198
2257
|
// src/version.ts
|
|
2199
|
-
var VERSION = true ? "4.0.
|
|
2258
|
+
var VERSION = true ? "4.0.159" : "0.0.0-test";
|
|
2200
2259
|
|
|
2201
2260
|
// src/bedrock-sigv4-fetch.ts
|
|
2202
2261
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|