This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
} from "./library-context";
|
||||
import { listMemories, getProfileSummary } from "./ai-memory";
|
||||
import { MEMORY_CATEGORIES, type MemoryCategory } from "@adventureos/shared";
|
||||
import { extractMemoryCandidates } from "./memory-extraction";
|
||||
|
||||
export async function listChatSessions(userId: string) {
|
||||
return db
|
||||
@@ -57,11 +58,14 @@ export async function sendChatMessage(userId: string, sessionId: string, content
|
||||
|
||||
const { session, messages } = sessionData;
|
||||
|
||||
await db.insert(aiChatMessages).values({
|
||||
sessionId,
|
||||
role: "user",
|
||||
content: content.trim(),
|
||||
});
|
||||
const [userMsg] = await db
|
||||
.insert(aiChatMessages)
|
||||
.values({
|
||||
sessionId,
|
||||
role: "user",
|
||||
content: content.trim(),
|
||||
})
|
||||
.returning();
|
||||
|
||||
const availability = await getAiAvailability(userId);
|
||||
const ctx = await buildMentorContext(userId, {
|
||||
@@ -83,7 +87,7 @@ export async function sendChatMessage(userId: string, sessionId: string, content
|
||||
|
||||
let reply: string;
|
||||
let offline = false;
|
||||
let memoryIdsUsed = ctx.memoryIds;
|
||||
const memoryIdsUsed = ctx.memoryIds;
|
||||
|
||||
if (!availability.canUse || !availability.online) {
|
||||
offline = true;
|
||||
@@ -116,12 +120,17 @@ export async function sendChatMessage(userId: string, sessionId: string, content
|
||||
})
|
||||
.returning();
|
||||
|
||||
const memorySuggestions = await extractMemoryCandidates(userId, "chat", content, {
|
||||
type: "ai_chat",
|
||||
id: userMsg.id,
|
||||
});
|
||||
|
||||
await db
|
||||
.update(aiChatSessions)
|
||||
.set({ updatedAt: new Date(), title: session.title === "New conversation" ? truncateTitle(content) : session.title })
|
||||
.where(eq(aiChatSessions.id, sessionId));
|
||||
|
||||
return { message: assistantMsg, reply, memoryIdsUsed, offline };
|
||||
return { message: assistantMsg, reply, memoryIdsUsed, offline, memorySuggestions };
|
||||
}
|
||||
|
||||
function truncateTitle(text: string): string {
|
||||
|
||||
Reference in New Issue
Block a user