Skip to content

Commit 2726d4d

Browse files
authored
Merge pull request #3 from Omm2005/main
Feat: Reactions, Supermemory AI reacting on text
2 parents a5982f9 + a74ae46 commit 2726d4d

File tree

4 files changed

+258
-41
lines changed

4 files changed

+258
-41
lines changed

app/(chat)/api/chat/route.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { geolocation } from '@vercel/functions';
2222
import { ChatSDKError } from '@/lib/errors';
2323

2424
export const maxDuration = 60;
25+
const REACTION_MARKER_REGEX =
26+
/<<\s*react\s*:\s*(heart|like|dislike|laugh|emphasize|question)\s*>>/gi;
2527

2628
export 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
},

0 commit comments

Comments
 (0)