Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-bedrock-multibyte-stream-chars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ai-sdk/amazon-bedrock': patch
---

fix(amazon-bedrock): preserve multibyte characters in streamed event payloads
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function createAmazonBedrockEventStreamDecoder<T>(
const exceptionType = decoded.headers[':exception-type']?.value as
| string
| undefined;
const data = textDecoder.decode(decoded.body);
const data = textDecoder.decode(decoded.body, { stream: true });

await processEvent(
{ messageType, eventType, exceptionType, data },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function transformAmazonBedrockEventStreamToSSE(
body: ReadableStream<Uint8Array>,
): ReadableStream<Uint8Array> {
const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();

return createAmazonBedrockEventStreamDecoder(
body,
Expand All @@ -81,8 +82,9 @@ function transformAmazonBedrockEventStreamToSSE(
}
const bytes = (parsed.value as { bytes?: string }).bytes;
if (bytes) {
const anthropicEvent = new TextDecoder().decode(
const anthropicEvent = textDecoder.decode(
convertBase64ToUint8Array(bytes),
{ stream: true },
);
controller.enqueue(
textEncoder.encode(`data: ${anthropicEvent}\n\n`),
Expand Down