mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
itjustworks
This commit is contained in:
1 parent
b4099c7a59
commit
63eb9b9d5b
3 files changed
+20
-65
No files matched your search
@@ -1,3 +1,5 @@
|
||||
node_modules
|
||||
.env
|
||||
generated
|
||||
generated
|
||||
|
||||
tmp
|
||||
@@ -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));
|
||||
|
||||
@@ -8,21 +8,6 @@ type SanitizedConversation = Omit<Conversation, "createdAt" | "updatedAt" | "uiM
|
||||
uiMessages: UIMessage[];
|
||||
};
|
||||
|
||||
export async function createNewConversationObject({
|
||||
conversationId
|
||||
}: {
|
||||
conversationId: string;
|
||||
}): Promise<SanitizedConversation> {
|
||||
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,
|
||||
|
||||
Reference in new issue
Block a user