Skip to content

Commit 18d04ca

Browse files
committed
simplified the fix
1 parent 05146c1 commit 18d04ca

File tree

2 files changed

+2
-43
lines changed

2 files changed

+2
-43
lines changed

app/commit.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "commit": "1e72d52278730f7d22448be9d5cf2daf12559486", "version": "0.0.2" }
1+
{ "commit": "05146c18d6e3b5410100089fed99c30d60dccad7" }

app/routes/api.enhancer.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import { streamText } from '~/lib/.server/llm/stream-text';
55
import { stripIndents } from '~/utils/stripIndent';
66
import type { IProviderSetting, ProviderInfo } from '~/types/model';
77

8-
const encoder = new TextEncoder();
9-
const decoder = new TextDecoder();
10-
118
export async function action(args: ActionFunctionArgs) {
129
return enhancerAction(args);
1310
}
@@ -107,45 +104,7 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {
107104
providerSettings,
108105
});
109106

110-
const transformStream = new TransformStream({
111-
transform(chunk, controller) {
112-
const text = decoder.decode(chunk);
113-
const lines = text.split('\n').filter((line) => line.trim() !== '');
114-
115-
for (const line of lines) {
116-
try {
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-
}
130-
131-
// Try to parse as JSON if it's not token-based format
132-
const parsed = JSON.parse(line);
133-
if (parsed.type === 'text') {
134-
controller.enqueue(encoder.encode(parsed.value));
135-
}
136-
} catch (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-
}
141-
}
142-
}
143-
},
144-
});
145-
146-
const transformedStream = result.toDataStream().pipeThrough(transformStream);
147-
148-
return new Response(transformedStream, {
107+
return new Response(result.textStream, {
149108
status: 200,
150109
headers: {
151110
'Content-Type': 'text/plain; charset=utf-8',

0 commit comments

Comments
 (0)