@ai-sdk/amazon-bedrock 4.0.158 → 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 +8 -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 +36 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -25
- 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-chat-language-model.ts +5 -0
- package/src/bedrock-event-stream-decoder.ts +12 -3
- package/src/bedrock-event-stream-response-handler.ts +31 -22
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
|
)
|
|
@@ -1372,6 +1378,10 @@ var BedrockChatLanguageModel = class {
|
|
|
1372
1378
|
enqueueError(value.modelStreamErrorException);
|
|
1373
1379
|
return;
|
|
1374
1380
|
}
|
|
1381
|
+
if (value.serviceUnavailableException) {
|
|
1382
|
+
enqueueError(value.serviceUnavailableException);
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1375
1385
|
if (value.throttlingException) {
|
|
1376
1386
|
enqueueError(value.throttlingException);
|
|
1377
1387
|
return;
|
|
@@ -1815,6 +1825,7 @@ var BedrockStreamSchema = z4.object({
|
|
|
1815
1825
|
}).nullish()
|
|
1816
1826
|
}).nullish(),
|
|
1817
1827
|
modelStreamErrorException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1828
|
+
serviceUnavailableException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1818
1829
|
throttlingException: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
1819
1830
|
validationException: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1820
1831
|
});
|
|
@@ -2244,7 +2255,7 @@ import {
|
|
|
2244
2255
|
import { AwsV4Signer } from "aws4fetch";
|
|
2245
2256
|
|
|
2246
2257
|
// src/version.ts
|
|
2247
|
-
var VERSION = true ? "4.0.
|
|
2258
|
+
var VERSION = true ? "4.0.159" : "0.0.0-test";
|
|
2248
2259
|
|
|
2249
2260
|
// src/bedrock-sigv4-fetch.ts
|
|
2250
2261
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|