mirror of
https://github.com/stackblitz/bolt.new
synced 2025-02-05 20:46:43 +00:00
fix: Prompt Enhance
Prompt Enhance option stopped, this fixes it
This commit is contained in:
parent
0ee3736297
commit
05146c18d6
@ -114,14 +114,30 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {
|
|||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(line);
|
// 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') {
|
if (parsed.type === 'text') {
|
||||||
controller.enqueue(encoder.encode(parsed.value));
|
controller.enqueue(encoder.encode(parsed.value));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// skip invalid JSON lines
|
// If not JSON and not token-based, treat as plain text
|
||||||
console.warn('Failed to parse stream part:', line, e);
|
if (!line.includes('e:') && !line.includes('d:')) { // Skip metadata lines
|
||||||
|
controller.enqueue(encoder.encode(line));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user