@@ -5,9 +5,6 @@ import { streamText } from '~/lib/.server/llm/stream-text';
55import { stripIndents } from '~/utils/stripIndent' ;
66import type { IProviderSetting , ProviderInfo } from '~/types/model' ;
77
8- const encoder = new TextEncoder ( ) ;
9- const decoder = new TextDecoder ( ) ;
10-
118export async function action ( args : ActionFunctionArgs ) {
129 return enhancerAction ( args ) ;
1310}
@@ -107,29 +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- const parsed = JSON . parse ( line ) ;
118-
119- if ( parsed . type === 'text' ) {
120- controller . enqueue ( encoder . encode ( parsed . value ) ) ;
121- }
122- } catch ( e ) {
123- // skip invalid JSON lines
124- console . warn ( 'Failed to parse stream part:' , line , e ) ;
125- }
126- }
127- } ,
128- } ) ;
129-
130- const transformedStream = result . toDataStream ( ) . pipeThrough ( transformStream ) ;
131-
132- return new Response ( transformedStream , {
107+ return new Response ( result . textStream , {
133108 status : 200 ,
134109 headers : {
135110 'Content-Type' : 'text/plain; charset=utf-8' ,
0 commit comments