mirror of
https://github.com/stackblitz/bolt.new
synced 2025-02-06 04:48:04 +00:00
simplified the fix
This commit is contained in:
parent
05146c18d6
commit
18d04ca065
@ -1 +1 @@
|
|||||||
{ "commit": "1e72d52278730f7d22448be9d5cf2daf12559486", "version": "0.0.2" }
|
{ "commit": "05146c18d6e3b5410100089fed99c30d60dccad7" }
|
||||||
|
@ -5,9 +5,6 @@ import { streamText } from '~/lib/.server/llm/stream-text';
|
|||||||
import { stripIndents } from '~/utils/stripIndent';
|
import { stripIndents } from '~/utils/stripIndent';
|
||||||
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
||||||
|
|
||||||
const encoder = new TextEncoder();
|
|
||||||
const decoder = new TextDecoder();
|
|
||||||
|
|
||||||
export async function action(args: ActionFunctionArgs) {
|
export async function action(args: ActionFunctionArgs) {
|
||||||
return enhancerAction(args);
|
return enhancerAction(args);
|
||||||
}
|
}
|
||||||
@ -107,45 +104,7 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {
|
|||||||
providerSettings,
|
providerSettings,
|
||||||
});
|
});
|
||||||
|
|
||||||
const transformStream = new TransformStream({
|
return new Response(result.textStream, {
|
||||||
transform(chunk, controller) {
|
|
||||||
const text = decoder.decode(chunk);
|
|
||||||
const lines = text.split('\n').filter((line) => line.trim() !== '');
|
|
||||||
|
|
||||||
for (const line of lines) {
|
|
||||||
try {
|
|
||||||
// Handle token-based streaming format
|
|
||||||
if (line.includes('0:"')) {
|
|
||||||
// Extract all token contents and join them
|
|
||||||
const tokens = line.match(/0:"([^"]+)"/g) || [];
|
|
||||||
const content = tokens
|
|
||||||
.map(token => token.slice(3, -1)) // Remove the '0:"' prefix and '"' suffix
|
|
||||||
.join('');
|
|
||||||
|
|
||||||
if (content) {
|
|
||||||
controller.enqueue(encoder.encode(content));
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to parse as JSON if it's not token-based format
|
|
||||||
const parsed = JSON.parse(line);
|
|
||||||
if (parsed.type === 'text') {
|
|
||||||
controller.enqueue(encoder.encode(parsed.value));
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// If not JSON and not token-based, treat as plain text
|
|
||||||
if (!line.includes('e:') && !line.includes('d:')) { // Skip metadata lines
|
|
||||||
controller.enqueue(encoder.encode(line));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const transformedStream = result.toDataStream().pipeThrough(transformStream);
|
|
||||||
|
|
||||||
return new Response(transformedStream, {
|
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'text/plain; charset=utf-8',
|
'Content-Type': 'text/plain; charset=utf-8',
|
||||||
|
Loading…
Reference in New Issue
Block a user