@@ -2,6 +2,11 @@ import { and, eq, desc, isNull } from "drizzle-orm";
|
||||
import { db, aiChatSessions, aiChatMessages } from "../db";
|
||||
import { buildMentorContext, formatContextForPrompt } from "./ai-context";
|
||||
import { generateChatReply, getAiAvailability } from "./ai";
|
||||
import {
|
||||
formatLibraryContextForPrompt,
|
||||
getLibraryContextForTopic,
|
||||
shouldIncludeLibraryContextInChat,
|
||||
} from "./library-context";
|
||||
import { listMemories, getProfileSummary } from "./ai-memory";
|
||||
import { MEMORY_CATEGORIES, type MemoryCategory } from "@adventureos/shared";
|
||||
|
||||
@@ -66,6 +71,16 @@ export async function sendChatMessage(userId: string, sessionId: string, content
|
||||
logContext: true,
|
||||
});
|
||||
|
||||
let contextBlock = formatContextForPrompt(ctx);
|
||||
if (shouldIncludeLibraryContextInChat(content)) {
|
||||
try {
|
||||
const libraryPayload = await getLibraryContextForTopic(userId, content);
|
||||
contextBlock = `${contextBlock}\n\n${formatLibraryContextForPrompt(libraryPayload)}`;
|
||||
} catch {
|
||||
/* library optional */
|
||||
}
|
||||
}
|
||||
|
||||
let reply: string;
|
||||
let offline = false;
|
||||
let memoryIdsUsed = ctx.memoryIds;
|
||||
@@ -81,7 +96,7 @@ export async function sendChatMessage(userId: string, sessionId: string, content
|
||||
|
||||
const generated = await generateChatReply(userId, {
|
||||
userMessage: content,
|
||||
contextBlock: formatContextForPrompt(ctx),
|
||||
contextBlock,
|
||||
history,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user