fix the learning
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-06-26 16:09:04 +01:00
parent 4ae37e84dd
commit 1e0a4c97b3
9 changed files with 623 additions and 32 deletions

View File

@@ -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 {