fix: do not print [object Object] when enhancing prompt

This commit is contained in:
Yoel Cabo 2024-10-07 04:08:48 +02:00
parent 6a9cb78fd6
commit bfe7e12783

View File

@ -34,15 +34,15 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {
const transformStream = new TransformStream({
transform(chunk, controller) {
const processedChunk = decoder
.decode(chunk)
.split('\n')
.filter((line) => line !== '')
.map(parseStreamPart)
.map((part) => part.value)
.join('');
controller.enqueue(encoder.encode(processedChunk));
const decodedChunk = decoder.decode(chunk);
const parts = decodedChunk.split('\n').filter((line) => line !== '');
for (const part of parts) {
const parsed = parseStreamPart(part);
if (parsed.type === 'text') {
controller.enqueue(encoder.encode(parsed.value));
}
// Non-text chunks are ignored
}
},
});