aboutsummaryrefslogtreecommitdiff
path: root/apps/web/server
diff options
context:
space:
mode:
authorDhravya <[email protected]>2024-06-22 17:43:16 -0500
committerDhravya <[email protected]>2024-06-22 17:43:16 -0500
commita2f8a27e771f59380719f2e9997cd926d5d8e83e (patch)
tree58da4ba7bbfc8885d01d79ba01e173f1d1f7906e /apps/web/server
parentadded multi-turn conversations (diff)
downloadsupermemory-a2f8a27e771f59380719f2e9997cd926d5d8e83e.tar.xz
supermemory-a2f8a27e771f59380719f2e9997cd926d5d8e83e.zip
addeed chathistory functionality
Diffstat (limited to 'apps/web/server')
-rw-r--r--apps/web/server/db/schema.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/apps/web/server/db/schema.ts b/apps/web/server/db/schema.ts
index 1ff23c82..f54d2094 100644
--- a/apps/web/server/db/schema.ts
+++ b/apps/web/server/db/schema.ts
@@ -154,3 +154,40 @@ export type StoredSpace = typeof space.$inferSelect;
export type ChachedSpaceContent = StoredContent & {
space: number;
};
+
+export const chatThreads = createTable(
+ "chatThread",
+ {
+ id: text("id")
+ .notNull()
+ .primaryKey()
+ .$defaultFn(() => crypto.randomUUID()),
+ firstMessage: text("firstMessage").notNull(),
+ userId: text("userId")
+ .notNull()
+ .references(() => users.id, { onDelete: "cascade" }),
+ },
+ (thread) => ({
+ userIdx: index("chatThread_user_idx").on(thread.userId),
+ }),
+);
+
+export const chatHistory = createTable(
+ "chatHistory",
+ {
+ id: integer("id").notNull().primaryKey({ autoIncrement: true }),
+ threadId: text("threadId")
+ .notNull()
+ .references(() => chatThreads.id, { onDelete: "cascade" }),
+ question: text("question").notNull(),
+ answer: text("answerParts"), // Single answer part as string
+ answerSources: text("answerSources"), // JSON stringified array of objects
+ answerJustification: text("answerJustification"),
+ },
+ (history) => ({
+ threadIdx: index("chatHistory_thread_idx").on(history.threadId),
+ }),
+);
+
+export type ChatThread = typeof chatThreads.$inferSelect;
+export type ChatHistory = typeof chatHistory.$inferSelect;