File tree Expand file tree Collapse file tree 4 files changed +258
-41
lines changed
Expand file tree Collapse file tree 4 files changed +258
-41
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ import { geolocation } from '@vercel/functions';
2222import { ChatSDKError } from '@/lib/errors' ;
2323
2424export const maxDuration = 60 ;
25+ const REACTION_MARKER_REGEX =
26+ / < < \s * r e a c t \s * : \s * ( h e a r t | l i k e | d i s l i k e | l a u g h | e m p h a s i z e | q u e s t i o n ) \s * > > / gi;
2527
2628export async function POST ( request : Request ) {
2729 let requestBody : PostRequestBody ;
@@ -235,8 +237,13 @@ export async function POST(request: Request) {
235237 onFinish : async ( { text, steps } ) => {
236238 if ( session . user ?. id ) {
237239 try {
240+ const cleanedText = text . replace ( REACTION_MARKER_REGEX , '' ) . trim ( ) ;
241+ if ( ! cleanedText ) {
242+ return ;
243+ }
244+
238245 // Check if the response contains split delimiter
239- const splitMessages = text
246+ const splitMessages = cleanedText
240247 . split ( '<SPLIT>' )
241248 . map ( ( t ) => t . trim ( ) )
242249 . filter ( ( t ) => t . length > 0 ) ;
@@ -264,7 +271,7 @@ export async function POST(request: Request) {
264271 id : generateUUID ( ) ,
265272 chatId : id ,
266273 role : 'assistant' ,
267- parts : [ { type : 'text' , text } ] ,
274+ parts : [ { type : 'text' , text : cleanedText } ] ,
268275 attachments : [ ] ,
269276 createdAt : new Date ( ) ,
270277 } ,
You can’t perform that action at this time.
0 commit comments