Skip to content

Commit 05146c1

Browse files
fix: Prompt Enhance
Prompt Enhance option stopped, this fixes it
1 parent 0ee3736 commit 05146c1

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

app/routes/api.enhancer.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,30 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {
114114

115115
for (const line of lines) {
116116
try {
117-
const parsed = JSON.parse(line);
117+
// Handle token-based streaming format
118+
if (line.includes('0:"')) {
119+
// Extract all token contents and join them
120+
const tokens = line.match(/0:"([^"]+)"/g) || [];
121+
const content = tokens
122+
.map(token => token.slice(3, -1)) // Remove the '0:"' prefix and '"' suffix
123+
.join('');
124+
125+
if (content) {
126+
controller.enqueue(encoder.encode(content));
127+
}
128+
continue;
129+
}
118130

131+
// Try to parse as JSON if it's not token-based format
132+
const parsed = JSON.parse(line);
119133
if (parsed.type === 'text') {
120134
controller.enqueue(encoder.encode(parsed.value));
121135
}
122136
} catch (e) {
123-
// skip invalid JSON lines
124-
console.warn('Failed to parse stream part:', line, e);
137+
// If not JSON and not token-based, treat as plain text
138+
if (!line.includes('e:') && !line.includes('d:')) { // Skip metadata lines
139+
controller.enqueue(encoder.encode(line));
140+
}
125141
}
126142
}
127143
},

0 commit comments

Comments
 (0)