aboutsummaryrefslogtreecommitdiff
path: root/apps/web/server
diff options
context:
space:
mode:
authorDhravya Shah <[email protected]>2024-06-22 20:38:00 -0500
committerGitHub <[email protected]>2024-06-22 20:38:00 -0500
commit47e7528f675c187b0a771bc4040e8d8108c5ef8e (patch)
tree0a738b7a816f7b61865558be567c88d86db238c3 /apps/web/server
parentdelete packagelock (diff)
parentcleanup (diff)
downloadsupermemory-47e7528f675c187b0a771bc4040e8d8108c5ef8e.tar.xz
supermemory-47e7528f675c187b0a771bc4040e8d8108c5ef8e.zip
Merge pull request #79 from Dhravya/chathistory
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;