From 63eb9b9d5b8cad37a9fbcd2b25ef35844b345370 Mon Sep 17 00:00:00 2001 From: Ariel Weinberger Date: Mon, 14 Jul 2025 19:15:14 -0500 Subject: [PATCH] itjustworks --- ai-service/.gitignore | 4 +- ai-service/src/handlers/chat/route.ts | 19 ++++--- ai-service/src/lib/imagine/conversation.ts | 62 +++------------------- 3 files changed, 20 insertions(+), 65 deletions(-) diff --git a/ai-service/.gitignore b/ai-service/.gitignore index c251e4b02..b1180210d 100644 --- a/ai-service/.gitignore +++ b/ai-service/.gitignore @@ -1,3 +1,5 @@ node_modules .env -generated \ No newline at end of file +generated + +tmp \ No newline at end of file diff --git a/ai-service/src/handlers/chat/route.ts b/ai-service/src/handlers/chat/route.ts index 6f5046e1c..e17e27782 100644 --- a/ai-service/src/handlers/chat/route.ts +++ b/ai-service/src/handlers/chat/route.ts @@ -1,4 +1,4 @@ -import { Context, Next } from 'hono'; +import { Context } from 'hono'; import { chatRequestBodySchema, ChatRequestBodyType } from './types'; import { z } from 'zod'; import { getOrCreateConversation, updateConversation } from '@/lib/imagine/conversation'; @@ -11,7 +11,6 @@ import { import { createRuntimeContext, WriterType } from '@/lib/ai/mastra/utils/runtime-context'; import { mastra } from '@/lib/ai/mastra'; import { ARTIFACT_ID, PROJECT_ID } from '@/constants'; -import { StreamEvent } from '@mastra/core'; export const handleChatRequest = async (c: Context) => { const signal = c.req.raw.signal; @@ -92,14 +91,14 @@ export const handleChatRequest = async (c: Context) => { const { messages } = event; - // await updateConversation({ - // conversation: { - // ...conversation, - // uiMessages: messages, - // }, - // artifactId, - // projectId, - // }); + await updateConversation({ + conversation: { + ...conversation, + uiMessages: messages, + }, + artifactId, + projectId, + }); const savedModelmessages = convertToModelMessages(messages, {}); console.log('savedModelmessages', JSON.stringify(savedModelmessages, null, 2)); diff --git a/ai-service/src/lib/imagine/conversation.ts b/ai-service/src/lib/imagine/conversation.ts index 2fde74271..a25293371 100644 --- a/ai-service/src/lib/imagine/conversation.ts +++ b/ai-service/src/lib/imagine/conversation.ts @@ -8,21 +8,6 @@ type SanitizedConversation = Omit { - return { - id: conversationId, - artifactId: ARTIFACT_ID, - projectId: PROJECT_ID, - title: "New Conversation", - uiMessages: [], - modelMessages: [], - } -} - export async function getOrCreateConversation({ conversationId, artifactId, @@ -42,7 +27,14 @@ export async function getOrCreateConversation({ }); if (!existingConversation) { - const newConversation = await createNewConversationObject({ conversationId }); + const newConversation: SanitizedConversation = { + id: conversationId, + artifactId: ARTIFACT_ID, + projectId: PROJECT_ID, + title: "New Conversation", + uiMessages: [], + modelMessages: [], + }; return { conversation: newConversation, isNewConversation: true, @@ -55,44 +47,6 @@ export async function getOrCreateConversation({ }; } -// export async function createConversationIfNotExists({ -// conversationId, -// }: { -// conversationId: string; -// }) { -// console.log("[createConversationIfNotExists] Called", { conversationId }); -// const existingConversation = await prisma.conversation.findUnique({ -// where: { -// id: conversationId, -// }, -// }); - -// if (!existingConversation) { -// console.log("[createConversationIfNotExists] No existing conversation found, creating new one"); -// const newConversation = await prisma.conversation.create({ -// data: { -// id: conversationId, -// artifactId: ARTIFACT_ID, -// projectId: PROJECT_ID, -// title: "New Conversation", -// uiMessages: [] as unknown as InputJsonValue, -// modelMessages: [] as unknown as InputJsonValue, -// }, -// }); - -// return { -// conversation: newConversation, -// isNewConversation: true, -// }; -// } - -// console.log("[createConversationIfNotExists] Existing conversation found", { conversationId }); -// return { -// conversation: existingConversation, -// isNewConversation: false, -// }; -// } - export async function updateConversation({ conversation, artifactId,