19
apps/web/src/app/api/library/context/route.ts
Normal file
19
apps/web/src/app/api/library/context/route.ts
Normal 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),
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user