ai fixes
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-06-26 14:44:54 +01:00
parent 25d62ce723
commit 2c4c9b0595
21 changed files with 1553 additions and 259 deletions

View File

@@ -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,
});