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

@@ -0,0 +1,19 @@
import { handleApi } from "@/lib/api";
import {
formatLibraryContextForPrompt,
getLibraryContextForTopic,
} from "@/lib/services/library-context";
import { requireUser } from "@/lib/services/user";
export async function GET(request: Request) {
return handleApi(async () => {
const { user } = await requireUser();
const { searchParams } = new URL(request.url);
const topic = searchParams.get("topic")?.trim() ?? "";
const payload = await getLibraryContextForTopic(user.id, topic);
return {
...payload,
formatted: formatLibraryContextForPrompt(payload),
};
});
}

View File

@@ -1,5 +1,10 @@
import { handleApi } from "@/lib/api";
import { createTeacherLesson, getTeacherHistory } from "@/lib/services/teacher";
import { ServiceUnavailableError } from "@/lib/errors";
import {
createTeacherLesson,
getTeacherHistory,
TeacherAiUnavailableError,
} from "@/lib/services/teacher";
import { requireUser } from "@/lib/services/user";
import { parseJsonBody } from "@/lib/validation";
import {
@@ -9,20 +14,17 @@ import {
export async function POST(request: Request) {
return handleApi(async () => {
// #region agent log
fetch('http://127.0.0.1:7257/ingest/abfa22e4-3d86-4176-9679-7c59b1f0489f',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'04e12c'},body:JSON.stringify({sessionId:'04e12c',location:'api/teacher/route.ts:POST',message:'teacher POST start',data:{},timestamp:Date.now(),hypothesisId:'H1'})}).catch(()=>{});
// #endregion
const parsed = await parseJsonBody(request, teacherCreateSchema);
const body = normalizeTeacherCreateBody(parsed);
// #region agent log
fetch('http://127.0.0.1:7257/ingest/abfa22e4-3d86-4176-9679-7c59b1f0489f',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'04e12c'},body:JSON.stringify({sessionId:'04e12c',location:'api/teacher/route.ts:POST',message:'teacher body validated',data:{topicLen:body.topic.length,hasExplorationId:!!body.explorationId},timestamp:Date.now(),hypothesisId:'H1'})}).catch(()=>{});
// #endregion
const { user } = await requireUser();
const result = await createTeacherLesson(user.id, body);
// #region agent log
fetch('http://127.0.0.1:7257/ingest/abfa22e4-3d86-4176-9679-7c59b1f0489f',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'04e12c'},body:JSON.stringify({sessionId:'04e12c',location:'api/teacher/route.ts:POST',message:'teacher lesson created',data:{source:result.source,lessonId:result.id},timestamp:Date.now(),hypothesisId:'H2'})}).catch(()=>{});
// #endregion
return result;
try {
return await createTeacherLesson(user.id, body);
} catch (e) {
if (e instanceof TeacherAiUnavailableError) {
throw new ServiceUnavailableError(e.message);
}
throw e;
}
});
}