@studious-lms/server 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models/class.d.ts +24 -2
- package/dist/models/class.d.ts.map +1 -1
- package/dist/models/class.js +180 -81
- package/dist/models/class.js.map +1 -1
- package/dist/models/worksheet.d.ts +34 -34
- package/dist/pipelines/aiLabChat.d.ts +57 -2
- package/dist/pipelines/aiLabChat.d.ts.map +1 -1
- package/dist/pipelines/aiLabChat.js +252 -113
- package/dist/pipelines/aiLabChat.js.map +1 -1
- package/dist/pipelines/gradeWorksheet.d.ts +4 -4
- package/dist/routers/_app.d.ts +138 -56
- package/dist/routers/_app.d.ts.map +1 -1
- package/dist/routers/class.d.ts +24 -3
- package/dist/routers/class.d.ts.map +1 -1
- package/dist/routers/class.js +3 -3
- package/dist/routers/class.js.map +1 -1
- package/dist/routers/labChat.d.ts +10 -1
- package/dist/routers/labChat.d.ts.map +1 -1
- package/dist/routers/labChat.js +6 -3
- package/dist/routers/labChat.js.map +1 -1
- package/dist/routers/message.d.ts +11 -0
- package/dist/routers/message.d.ts.map +1 -1
- package/dist/routers/message.js +10 -3
- package/dist/routers/message.js.map +1 -1
- package/dist/routers/worksheet.d.ts +24 -24
- package/dist/services/class.d.ts +24 -2
- package/dist/services/class.d.ts.map +1 -1
- package/dist/services/class.js +18 -6
- package/dist/services/class.js.map +1 -1
- package/dist/services/labChat.d.ts +5 -1
- package/dist/services/labChat.d.ts.map +1 -1
- package/dist/services/labChat.js +96 -4
- package/dist/services/labChat.js.map +1 -1
- package/dist/services/message.d.ts +8 -0
- package/dist/services/message.d.ts.map +1 -1
- package/dist/services/message.js +74 -2
- package/dist/services/message.js.map +1 -1
- package/dist/services/worksheet.d.ts +18 -18
- package/package.json +1 -1
- package/prisma/schema.prisma +1 -1
- package/src/models/class.ts +189 -84
- package/src/pipelines/aiLabChat.ts +291 -118
- package/src/routers/class.ts +1 -1
- package/src/routers/labChat.ts +7 -0
- package/src/routers/message.ts +13 -0
- package/src/services/class.ts +14 -7
- package/src/services/labChat.ts +108 -2
- package/src/services/message.ts +93 -0
package/dist/services/class.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* syllabus, lab drafts, and invite codes.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
6
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f6a97cb7-783f-56a4-ae40-1d145ee5c1ee")}catch(e){}}();
|
|
7
7
|
import { TRPCError } from "@trpc/server";
|
|
8
8
|
import { prisma } from "../lib/prisma.js";
|
|
9
9
|
import { generateInviteCode } from "../utils/generateInviteCode.js";
|
|
@@ -461,14 +461,26 @@ export async function exportClass(classId, userId) {
|
|
|
461
461
|
return classExport;
|
|
462
462
|
}
|
|
463
463
|
export async function importClass(classId, userId, year, classData) {
|
|
464
|
-
|
|
465
|
-
|
|
464
|
+
try {
|
|
465
|
+
const newClassId = await createClassByImport(classId, userId, year, classData);
|
|
466
|
+
if (!newClassId) {
|
|
467
|
+
throw new TRPCError({
|
|
468
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
469
|
+
message: "Failed to import class",
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
return newClassId;
|
|
473
|
+
}
|
|
474
|
+
catch (err) {
|
|
475
|
+
if (err instanceof TRPCError)
|
|
476
|
+
throw err;
|
|
477
|
+
const message = err instanceof Error ? err.message : "Unknown error";
|
|
466
478
|
throw new TRPCError({
|
|
467
479
|
code: "INTERNAL_SERVER_ERROR",
|
|
468
|
-
message:
|
|
480
|
+
message: `Failed to import class: ${message}`,
|
|
481
|
+
cause: err,
|
|
469
482
|
});
|
|
470
483
|
}
|
|
471
|
-
return newClassId;
|
|
472
484
|
}
|
|
473
485
|
//# sourceMappingURL=class.js.map
|
|
474
|
-
//# debugId=
|
|
486
|
+
//# debugId=f6a97cb7-783f-56a4-ae40-1d145ee5c1ee
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class.js","sources":["services/class.ts"],"sourceRoot":"/","sourcesContent":["/**\n * Class service – CRUD for classes, members, grades, mark schemes, grading boundaries,\n * syllabus, lab drafts, and invite codes.\n */\nimport { TRPCError } from \"@trpc/server\";\nimport { prisma } from \"../lib/prisma.js\";\nimport { generateInviteCode } from \"../utils/generateInviteCode.js\";\nimport {\n findTeacherClasses,\n findStudentClasses,\n isTeacherInClass,\n findClassWithAssignments,\n findSectionsByClassId,\n findUserById,\n findSessionByClassCode,\n findSessionByClassId,\n findSubmissionsForGrades,\n findEventsByClassId,\n findMarkSchemesByClassId,\n findGradingBoundariesByClassId,\n findClassSyllabus,\n findLabDraftsByClass,\n findAssignmentsWithFiles,\n findFullExportableClass,\n createClassByImport,\n} from \"../models/class.js\";\nimport { Class, Folder } from \"@prisma/client\";\n\n/** Get all classes where user is teacher or student, with assignments and members. */\nexport async function getAllClasses(userId: string) {\n const [teacherClasses, studentClasses] = await Promise.all([\n findTeacherClasses(userId),\n findStudentClasses(userId),\n ]);\n\n return {\n teacherInClass: teacherClasses.map((cls) => ({\n id: cls.id,\n name: cls.name,\n section: cls.section,\n subject: cls.subject,\n dueToday: cls.assignments,\n assignments: cls.assignments,\n members: [...cls.students, ...cls.teachers],\n color: cls.color,\n })),\n studentInClass: studentClasses.map((cls) => ({\n id: cls.id,\n name: cls.name,\n section: cls.section,\n subject: cls.subject,\n dueToday: cls.assignments,\n assignments: cls.assignments,\n members: [...cls.students, ...cls.teachers],\n color: cls.color,\n })),\n };\n}\n\n/** Get single class with assignments, sections, and submission status. */\nexport async function getClass(userId: string, classId: string) {\n const isTeacher = await isTeacherInClass(classId, userId ?? \"\");\n\n const classData = await findClassWithAssignments(classId, {\n isTeacher: !!isTeacher,\n userId: userId ?? undefined,\n });\n\n if (!classData) {\n throw new Error(\"Class not found\");\n }\n\n const formattedClassData = {\n ...classData,\n assignments: classData.assignments.map((assignment) => ({\n ...assignment,\n late: assignment.dueDate < new Date(),\n submitted: assignment.submissions.find(\n (s) => s.studentId === userId\n )?.submitted,\n returned: assignment.submissions.find(\n (s) => s.studentId === userId\n )?.returned,\n })),\n };\n\n const sections = await findSectionsByClassId(classId);\n\n return {\n class: {\n ...formattedClassData,\n sections,\n },\n };\n}\n\nexport async function updateClass(\n classId: string,\n data: { name?: string; section?: string; subject?: string }\n) {\n const updatedClass = await prisma.class.update({\n where: { id: classId },\n data,\n select: {\n id: true,\n name: true,\n section: true,\n subject: true,\n },\n });\n return { updatedClass };\n}\n\nexport async function createClass(\n userId: string,\n input: {\n students?: string[];\n teachers?: string[];\n name: string;\n section: string;\n subject: string;\n color?: string;\n }\n) {\n const { students, teachers, name, section, subject, color } = input;\n\n if (teachers && teachers.length > 0 && students && students.length > 0) {\n return prisma.class.create({\n data: {\n name,\n section,\n subject,\n color,\n teachers: { connect: teachers.map((id) => ({ id })) },\n students: { connect: students.map((id) => ({ id })) },\n },\n include: { teachers: true, students: true },\n });\n }\n\n return prisma.class.create({\n data: {\n name,\n section,\n subject,\n color,\n teachers: { connect: { id: userId } },\n },\n });\n}\n\nexport async function deleteClass(classId: string) {\n const classToDelete = await prisma.class.findFirst({\n where: { id: classId },\n });\n\n if (!classToDelete) {\n throw new Error(\"Class not found or you don't have permission to delete it\");\n }\n\n await prisma.class.delete({\n where: { id: classId },\n });\n\n return { deletedClass: { id: classId } };\n}\n\nexport async function addStudent(classId: string, studentId: string) {\n const student = await findUserById(studentId);\n if (!student) {\n throw new Error(\"Student not found\");\n }\n\n const updatedClass = await prisma.class.update({\n where: { id: classId },\n data: {\n students: { connect: { id: studentId } },\n },\n select: {\n id: true,\n name: true,\n section: true,\n subject: true,\n },\n });\n\n return { updatedClass, newStudent: student };\n}\n\nexport async function changeRole(\n classId: string,\n userId: string,\n type: \"teacher\" | \"student\"\n) {\n const user = await findUserById(userId);\n if (!user) {\n throw new Error(\"User not found\");\n }\n\n const updatedClass = await prisma.class.update({\n where: { id: classId },\n data: {\n [type === \"teacher\" ? \"teachers\" : \"students\"]: {\n connect: { id: userId },\n },\n [type === \"teacher\" ? \"students\" : \"teachers\"]: {\n disconnect: { id: userId },\n },\n },\n });\n\n return {\n updatedClass,\n user: { ...user, type },\n };\n}\n\nexport async function removeMember(classId: string, userId: string) {\n const updatedClass = await prisma.class.update({\n where: { id: classId },\n data: {\n teachers: { disconnect: { id: userId } },\n students: { disconnect: { id: userId } },\n },\n });\n return { updatedClass, removedUserId: userId };\n}\n\nexport async function leaveClass(userId: string, classId: string) {\n const classData = await prisma.class.findFirst({\n where: {\n id: classId,\n students: { some: { id: userId } },\n },\n });\n\n if (!classData) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Class not found or you are not a student in this class\",\n });\n }\n\n await prisma.class.update({\n where: { id: classId },\n data: {\n students: { disconnect: { id: userId } },\n },\n });\n\n return { success: true, leftClassId: classId };\n}\n\nexport async function joinClass(userId: string, classCode: string) {\n const session = await findSessionByClassCode(classCode);\n\n if (!session || !session.classId) {\n throw new Error(\"Class not found\");\n }\n\n if (session.expiresAt && session.expiresAt < new Date()) {\n throw new Error(\"Session expired\");\n }\n\n const updatedClass = await prisma.class.update({\n where: { id: session.classId },\n data: {\n students: { connect: { id: userId } },\n },\n select: {\n id: true,\n name: true,\n section: true,\n subject: true,\n },\n });\n\n return { joinedClass: updatedClass };\n}\n\nexport async function getInviteCode(classId: string) {\n const session = await findSessionByClassId(classId);\n\n if ((session?.expiresAt && session.expiresAt < new Date()) || !session) {\n const newSession = await prisma.session.create({\n data: {\n id: generateInviteCode(),\n classId,\n expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000),\n },\n });\n return { code: newSession.id };\n }\n\n return { code: session?.id };\n}\n\nexport async function createInviteCode(classId: string) {\n await prisma.session.deleteMany({\n where: { classId },\n });\n\n const session = await prisma.session.create({\n data: {\n id: generateInviteCode(),\n classId,\n expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000),\n },\n });\n\n return { code: session.id };\n}\n\nexport async function getGrades(\n userId: string,\n classId: string,\n targetUserId: string\n) {\n const isTeacher = await isTeacherInClass(classId, userId);\n if (userId !== targetUserId && !isTeacher) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"You can only view your own grades\",\n });\n }\n\n const grades = await findSubmissionsForGrades(targetUserId, classId);\n return { grades };\n}\n\nexport async function updateGrade(\n assignmentId: string,\n submissionId: string,\n gradeReceived: number | null\n) {\n const updatedSubmission = await prisma.submission.update({\n where: { id: submissionId, assignmentId },\n data: { gradeReceived },\n include: {\n assignment: {\n select: {\n id: true,\n title: true,\n maxGrade: true,\n weight: true,\n },\n },\n },\n });\n return updatedSubmission;\n}\n\nexport async function getEvents(classId: string) {\n return findEventsByClassId(classId);\n}\n\nexport async function listMarkSchemes(classId: string) {\n return findMarkSchemesByClassId(classId);\n}\n\nexport async function createMarkScheme(classId: string, structure: string) {\n const validatedStructure = structure.replace(/\\\\n/g, \"\\n\");\n return prisma.markScheme.create({\n data: {\n class: { connect: { id: classId } },\n structured: validatedStructure,\n },\n });\n}\n\nexport async function updateMarkScheme(\n markSchemeId: string,\n classId: string,\n structure: string\n) {\n const validatedStructure = structure.replace(/\\\\n/g, \"\\n\");\n return prisma.markScheme.update({\n where: { id: markSchemeId },\n data: {\n class: { connect: { id: classId } },\n structured: validatedStructure,\n },\n });\n}\n\nexport async function deleteMarkScheme(markSchemeId: string) {\n return prisma.markScheme.delete({\n where: { id: markSchemeId },\n });\n}\n\nexport async function listGradingBoundaries(classId: string) {\n return findGradingBoundariesByClassId(classId);\n}\n\nexport async function createGradingBoundary(classId: string, structure: string) {\n const validatedStructure = structure.replace(/\\\\n/g, \"\\n\");\n return prisma.gradingBoundary.create({\n data: {\n class: { connect: { id: classId } },\n structured: validatedStructure,\n },\n });\n}\n\nexport async function updateGradingBoundary(\n gradingBoundaryId: string,\n classId: string,\n structure: string\n) {\n const validatedStructure = structure.replace(/\\\\n/g, \"\\n\");\n return prisma.gradingBoundary.update({\n where: { id: gradingBoundaryId },\n data: {\n class: { connect: { id: classId } },\n structured: validatedStructure,\n },\n });\n}\n\nexport async function deleteGradingBoundary(gradingBoundaryId: string) {\n return prisma.gradingBoundary.delete({\n where: { id: gradingBoundaryId },\n });\n}\n\nexport async function getSyllabus(classId: string) {\n const classData = await findClassSyllabus(classId);\n const markSchemes = await findMarkSchemesByClassId(classId);\n const gradingBoundaries = await findGradingBoundariesByClassId(classId);\n return {\n syllabus: classData?.syllabus,\n gradingBoundaries,\n markSchemes,\n };\n}\n\nexport async function updateSyllabus(classId: string, contents: string) {\n if (!contents) {\n throw new TRPCError({\n code: \"BAD_REQUEST\",\n message: \"Missing key contents\",\n });\n }\n return prisma.class.update({\n where: { id: classId },\n data: { syllabus: contents },\n });\n}\n\nexport async function listLabDrafts(classId: string, teacherId: string) {\n return findLabDraftsByClass(classId, teacherId);\n}\n\nexport async function createLabDraft(\n classId: string,\n teacherId: string,\n input: {\n title: string;\n type: string;\n instructions: string;\n dueDate?: Date;\n maxGrade?: number;\n weight?: number;\n graded?: boolean;\n sectionId?: string;\n markSchemeId?: string;\n gradingBoundaryId?: string;\n }\n) {\n return prisma.assignment.create({\n data: {\n classId,\n teacherId,\n inProgress: true,\n graded: input.graded ?? false,\n maxGrade: input.maxGrade ?? 0,\n weight: input.weight ?? 1,\n dueDate:\n input.dueDate ||\n new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),\n title: input.title,\n instructions: input.instructions,\n type: input.type as any,\n ...(input.sectionId && { sectionId: input.sectionId }),\n ...(input.markSchemeId && { markSchemeId: input.markSchemeId }),\n ...(input.gradingBoundaryId && {\n gradingBoundaryId: input.gradingBoundaryId,\n }),\n },\n });\n}\n\nexport async function updateLabDraft(\n classId: string,\n teacherId: string,\n draftId: string,\n input: Record<string, unknown>\n) {\n const updateData: Record<string, unknown> = {\n modifiedAt: new Date(),\n };\n if (input.title !== undefined) updateData.title = input.title;\n if (input.instructions !== undefined)\n updateData.instructions = input.instructions;\n if (input.dueDate !== undefined) updateData.dueDate = input.dueDate;\n if (input.maxGrade !== undefined) updateData.maxGrade = input.maxGrade;\n if (input.weight !== undefined) updateData.weight = input.weight;\n if (input.graded !== undefined) updateData.graded = input.graded;\n if (input.sectionId !== undefined) updateData.sectionId = input.sectionId;\n if (input.markSchemeId !== undefined)\n updateData.markSchemeId = input.markSchemeId;\n if (input.gradingBoundaryId !== undefined)\n updateData.gradingBoundaryId = input.gradingBoundaryId;\n\n return prisma.assignment.update({\n where: {\n id: draftId,\n classId,\n teacherId,\n inProgress: true,\n },\n data: updateData as any,\n });\n}\n\nexport async function deleteLabDraft(\n classId: string,\n teacherId: string,\n draftId: string\n) {\n return prisma.assignment.delete({\n where: {\n id: draftId,\n classId,\n teacherId,\n inProgress: true,\n },\n });\n}\n\nexport async function publishLabDraft(\n classId: string,\n teacherId: string,\n draftId: string,\n input: {\n dueDate?: Date;\n maxGrade?: number;\n weight?: number;\n graded?: boolean;\n }\n) {\n const labDraft = await prisma.assignment.findUnique({\n where: {\n id: draftId,\n classId,\n teacherId,\n inProgress: true,\n },\n });\n\n if (!labDraft) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Lab draft not found\",\n });\n }\n\n return prisma.assignment.update({\n where: { id: draftId },\n data: {\n inProgress: false,\n dueDate: input.dueDate || labDraft.dueDate,\n maxGrade: input.maxGrade || labDraft.maxGrade || 100,\n weight: input.weight || labDraft.weight || 1,\n graded: input.graded !== undefined ? input.graded : true,\n modifiedAt: new Date(),\n },\n });\n}\n\nexport async function getFiles(classId: string) {\n const assignments = await findAssignmentsWithFiles(classId);\n return assignments.map((assignment) => ({\n id: assignment.id,\n title: assignment.title,\n teacher: assignment.teacher,\n teacherAttachments: assignment.attachments,\n students: assignment.submissions.map((submission) => ({\n id: submission.student.id,\n username: submission.student.username,\n attachments: submission.attachments,\n annotations: submission.annotations,\n })),\n }));\n}\n\nexport async function exportClass(classId: string, userId: string) {\n const classExport = await findFullExportableClass(classId);\n if (!classExport) {\n throw new TRPCError({\n code: \"INTERNAL_SERVER_ERROR\",\n message: \"Failed to export class\",\n });\n }\n\n return classExport;\n}\n\nexport async function importClass(classId: string, userId: string, year: number, classData: Class & { classFiles: Folder | null }) {\n const newClassId = await createClassByImport(classId, userId, year, classData);\n \n\n if (!newClassId) {\n throw new TRPCError({\n code: \"INTERNAL_SERVER_ERROR\",\n message: \"Failed to import class\",\n });\n }\n\n return newClassId;\n}"],"names":[],"mappings":"AAAA;;;GAGG;;;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,EACxB,8BAA8B,EAC9B,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAG5B,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAc;IAChD,MAAM,CAAC,cAAc,EAAE,cAAc,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACzD,kBAAkB,CAAC,MAAM,CAAC;QAC1B,kBAAkB,CAAC,MAAM,CAAC;KAC3B,CAAC,CAAC;IAEH,OAAO;QACL,cAAc,EAAE,cAAc,CAA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E;YACzB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,QAAQ;YACrC,WAAW,EAAE,UAAU,CAAC,WAAW;YACnC,WAAW,EAAE,UAAU,CAAC,WAAW;SACpC,CAAC,CAAC;KACJ,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAe,EAAE,MAAc;IAC/D,MAAM,WAAW,GAAG,MAAM,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAC3D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,SAAS,CAAC;YAClB,IAAI,EAAE,uBAAuB;YAC7B,OAAO,EAAE,wBAAwB;SAClC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAe,EAAE,MAAc,EAAE,IAAY,EAAE,SAAgD;IAC/H,MAAM,UAAU,GAAG,MAAM,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAG/E,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,SAAS,CAAC;YAClB,IAAI,EAAE,uBAAuB;YAC7B,OAAO,EAAE,wBAAwB;SAClC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","debug_id":"a6ac24ca-d861-59b8-8ab5-1101cf7f1b37"}
|
|
1
|
+
{"version":3,"file":"class.js","sources":["services/class.ts"],"sourceRoot":"/","sourcesContent":["/**\n * Class service – CRUD for classes, members, grades, mark schemes, grading boundaries,\n * syllabus, lab drafts, and invite codes.\n */\nimport { TRPCError } from \"@trpc/server\";\nimport { prisma } from \"../lib/prisma.js\";\nimport { generateInviteCode } from \"../utils/generateInviteCode.js\";\nimport {\n findTeacherClasses,\n findStudentClasses,\n isTeacherInClass,\n findClassWithAssignments,\n findSectionsByClassId,\n findUserById,\n findSessionByClassCode,\n findSessionByClassId,\n findSubmissionsForGrades,\n findEventsByClassId,\n findMarkSchemesByClassId,\n findGradingBoundariesByClassId,\n findClassSyllabus,\n findLabDraftsByClass,\n findAssignmentsWithFiles,\n findFullExportableClass,\n createClassByImport,\n} from \"../models/class.js\";\nimport { Class, Folder } from \"@prisma/client\";\n\n/** Get all classes where user is teacher or student, with assignments and members. */\nexport async function getAllClasses(userId: string) {\n const [teacherClasses, studentClasses] = await Promise.all([\n findTeacherClasses(userId),\n findStudentClasses(userId),\n ]);\n\n return {\n teacherInClass: teacherClasses.map((cls) => ({\n id: cls.id,\n name: cls.name,\n section: cls.section,\n subject: cls.subject,\n dueToday: cls.assignments,\n assignments: cls.assignments,\n members: [...cls.students, ...cls.teachers],\n color: cls.color,\n })),\n studentInClass: studentClasses.map((cls) => ({\n id: cls.id,\n name: cls.name,\n section: cls.section,\n subject: cls.subject,\n dueToday: cls.assignments,\n assignments: cls.assignments,\n members: [...cls.students, ...cls.teachers],\n color: cls.color,\n })),\n };\n}\n\n/** Get single class with assignments, sections, and submission status. */\nexport async function getClass(userId: string, classId: string) {\n const isTeacher = await isTeacherInClass(classId, userId ?? \"\");\n\n const classData = await findClassWithAssignments(classId, {\n isTeacher: !!isTeacher,\n userId: userId ?? undefined,\n });\n\n if (!classData) {\n throw new Error(\"Class not found\");\n }\n\n const formattedClassData = {\n ...classData,\n assignments: classData.assignments.map((assignment) => ({\n ...assignment,\n late: assignment.dueDate < new Date(),\n submitted: assignment.submissions.find(\n (s) => s.studentId === userId\n )?.submitted,\n returned: assignment.submissions.find(\n (s) => s.studentId === userId\n )?.returned,\n })),\n };\n\n const sections = await findSectionsByClassId(classId);\n\n return {\n class: {\n ...formattedClassData,\n sections,\n },\n };\n}\n\nexport async function updateClass(\n classId: string,\n data: { name?: string; section?: string; subject?: string }\n) {\n const updatedClass = await prisma.class.update({\n where: { id: classId },\n data,\n select: {\n id: true,\n name: true,\n section: true,\n subject: true,\n },\n });\n return { updatedClass };\n}\n\nexport async function createClass(\n userId: string,\n input: {\n students?: string[];\n teachers?: string[];\n name: string;\n section: string;\n subject: string;\n color?: string;\n }\n) {\n const { students, teachers, name, section, subject, color } = input;\n\n if (teachers && teachers.length > 0 && students && students.length > 0) {\n return prisma.class.create({\n data: {\n name,\n section,\n subject,\n color,\n teachers: { connect: teachers.map((id) => ({ id })) },\n students: { connect: students.map((id) => ({ id })) },\n },\n include: { teachers: true, students: true },\n });\n }\n\n return prisma.class.create({\n data: {\n name,\n section,\n subject,\n color,\n teachers: { connect: { id: userId } },\n },\n });\n}\n\nexport async function deleteClass(classId: string) {\n const classToDelete = await prisma.class.findFirst({\n where: { id: classId },\n });\n\n if (!classToDelete) {\n throw new Error(\"Class not found or you don't have permission to delete it\");\n }\n\n await prisma.class.delete({\n where: { id: classId },\n });\n\n return { deletedClass: { id: classId } };\n}\n\nexport async function addStudent(classId: string, studentId: string) {\n const student = await findUserById(studentId);\n if (!student) {\n throw new Error(\"Student not found\");\n }\n\n const updatedClass = await prisma.class.update({\n where: { id: classId },\n data: {\n students: { connect: { id: studentId } },\n },\n select: {\n id: true,\n name: true,\n section: true,\n subject: true,\n },\n });\n\n return { updatedClass, newStudent: student };\n}\n\nexport async function changeRole(\n classId: string,\n userId: string,\n type: \"teacher\" | \"student\"\n) {\n const user = await findUserById(userId);\n if (!user) {\n throw new Error(\"User not found\");\n }\n\n const updatedClass = await prisma.class.update({\n where: { id: classId },\n data: {\n [type === \"teacher\" ? \"teachers\" : \"students\"]: {\n connect: { id: userId },\n },\n [type === \"teacher\" ? \"students\" : \"teachers\"]: {\n disconnect: { id: userId },\n },\n },\n });\n\n return {\n updatedClass,\n user: { ...user, type },\n };\n}\n\nexport async function removeMember(classId: string, userId: string) {\n const updatedClass = await prisma.class.update({\n where: { id: classId },\n data: {\n teachers: { disconnect: { id: userId } },\n students: { disconnect: { id: userId } },\n },\n });\n return { updatedClass, removedUserId: userId };\n}\n\nexport async function leaveClass(userId: string, classId: string) {\n const classData = await prisma.class.findFirst({\n where: {\n id: classId,\n students: { some: { id: userId } },\n },\n });\n\n if (!classData) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Class not found or you are not a student in this class\",\n });\n }\n\n await prisma.class.update({\n where: { id: classId },\n data: {\n students: { disconnect: { id: userId } },\n },\n });\n\n return { success: true, leftClassId: classId };\n}\n\nexport async function joinClass(userId: string, classCode: string) {\n const session = await findSessionByClassCode(classCode);\n\n if (!session || !session.classId) {\n throw new Error(\"Class not found\");\n }\n\n if (session.expiresAt && session.expiresAt < new Date()) {\n throw new Error(\"Session expired\");\n }\n\n const updatedClass = await prisma.class.update({\n where: { id: session.classId },\n data: {\n students: { connect: { id: userId } },\n },\n select: {\n id: true,\n name: true,\n section: true,\n subject: true,\n },\n });\n\n return { joinedClass: updatedClass };\n}\n\nexport async function getInviteCode(classId: string) {\n const session = await findSessionByClassId(classId);\n\n if ((session?.expiresAt && session.expiresAt < new Date()) || !session) {\n const newSession = await prisma.session.create({\n data: {\n id: generateInviteCode(),\n classId,\n expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000),\n },\n });\n return { code: newSession.id };\n }\n\n return { code: session?.id };\n}\n\nexport async function createInviteCode(classId: string) {\n await prisma.session.deleteMany({\n where: { classId },\n });\n\n const session = await prisma.session.create({\n data: {\n id: generateInviteCode(),\n classId,\n expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000),\n },\n });\n\n return { code: session.id };\n}\n\nexport async function getGrades(\n userId: string,\n classId: string,\n targetUserId: string\n) {\n const isTeacher = await isTeacherInClass(classId, userId);\n if (userId !== targetUserId && !isTeacher) {\n throw new TRPCError({\n code: \"UNAUTHORIZED\",\n message: \"You can only view your own grades\",\n });\n }\n\n const grades = await findSubmissionsForGrades(targetUserId, classId);\n return { grades };\n}\n\nexport async function updateGrade(\n assignmentId: string,\n submissionId: string,\n gradeReceived: number | null\n) {\n const updatedSubmission = await prisma.submission.update({\n where: { id: submissionId, assignmentId },\n data: { gradeReceived },\n include: {\n assignment: {\n select: {\n id: true,\n title: true,\n maxGrade: true,\n weight: true,\n },\n },\n },\n });\n return updatedSubmission;\n}\n\nexport async function getEvents(classId: string) {\n return findEventsByClassId(classId);\n}\n\nexport async function listMarkSchemes(classId: string) {\n return findMarkSchemesByClassId(classId);\n}\n\nexport async function createMarkScheme(classId: string, structure: string) {\n const validatedStructure = structure.replace(/\\\\n/g, \"\\n\");\n return prisma.markScheme.create({\n data: {\n class: { connect: { id: classId } },\n structured: validatedStructure,\n },\n });\n}\n\nexport async function updateMarkScheme(\n markSchemeId: string,\n classId: string,\n structure: string\n) {\n const validatedStructure = structure.replace(/\\\\n/g, \"\\n\");\n return prisma.markScheme.update({\n where: { id: markSchemeId },\n data: {\n class: { connect: { id: classId } },\n structured: validatedStructure,\n },\n });\n}\n\nexport async function deleteMarkScheme(markSchemeId: string) {\n return prisma.markScheme.delete({\n where: { id: markSchemeId },\n });\n}\n\nexport async function listGradingBoundaries(classId: string) {\n return findGradingBoundariesByClassId(classId);\n}\n\nexport async function createGradingBoundary(classId: string, structure: string) {\n const validatedStructure = structure.replace(/\\\\n/g, \"\\n\");\n return prisma.gradingBoundary.create({\n data: {\n class: { connect: { id: classId } },\n structured: validatedStructure,\n },\n });\n}\n\nexport async function updateGradingBoundary(\n gradingBoundaryId: string,\n classId: string,\n structure: string\n) {\n const validatedStructure = structure.replace(/\\\\n/g, \"\\n\");\n return prisma.gradingBoundary.update({\n where: { id: gradingBoundaryId },\n data: {\n class: { connect: { id: classId } },\n structured: validatedStructure,\n },\n });\n}\n\nexport async function deleteGradingBoundary(gradingBoundaryId: string) {\n return prisma.gradingBoundary.delete({\n where: { id: gradingBoundaryId },\n });\n}\n\nexport async function getSyllabus(classId: string) {\n const classData = await findClassSyllabus(classId);\n const markSchemes = await findMarkSchemesByClassId(classId);\n const gradingBoundaries = await findGradingBoundariesByClassId(classId);\n return {\n syllabus: classData?.syllabus,\n gradingBoundaries,\n markSchemes,\n };\n}\n\nexport async function updateSyllabus(classId: string, contents: string) {\n if (!contents) {\n throw new TRPCError({\n code: \"BAD_REQUEST\",\n message: \"Missing key contents\",\n });\n }\n return prisma.class.update({\n where: { id: classId },\n data: { syllabus: contents },\n });\n}\n\nexport async function listLabDrafts(classId: string, teacherId: string) {\n return findLabDraftsByClass(classId, teacherId);\n}\n\nexport async function createLabDraft(\n classId: string,\n teacherId: string,\n input: {\n title: string;\n type: string;\n instructions: string;\n dueDate?: Date;\n maxGrade?: number;\n weight?: number;\n graded?: boolean;\n sectionId?: string;\n markSchemeId?: string;\n gradingBoundaryId?: string;\n }\n) {\n return prisma.assignment.create({\n data: {\n classId,\n teacherId,\n inProgress: true,\n graded: input.graded ?? false,\n maxGrade: input.maxGrade ?? 0,\n weight: input.weight ?? 1,\n dueDate:\n input.dueDate ||\n new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),\n title: input.title,\n instructions: input.instructions,\n type: input.type as any,\n ...(input.sectionId && { sectionId: input.sectionId }),\n ...(input.markSchemeId && { markSchemeId: input.markSchemeId }),\n ...(input.gradingBoundaryId && {\n gradingBoundaryId: input.gradingBoundaryId,\n }),\n },\n });\n}\n\nexport async function updateLabDraft(\n classId: string,\n teacherId: string,\n draftId: string,\n input: Record<string, unknown>\n) {\n const updateData: Record<string, unknown> = {\n modifiedAt: new Date(),\n };\n if (input.title !== undefined) updateData.title = input.title;\n if (input.instructions !== undefined)\n updateData.instructions = input.instructions;\n if (input.dueDate !== undefined) updateData.dueDate = input.dueDate;\n if (input.maxGrade !== undefined) updateData.maxGrade = input.maxGrade;\n if (input.weight !== undefined) updateData.weight = input.weight;\n if (input.graded !== undefined) updateData.graded = input.graded;\n if (input.sectionId !== undefined) updateData.sectionId = input.sectionId;\n if (input.markSchemeId !== undefined)\n updateData.markSchemeId = input.markSchemeId;\n if (input.gradingBoundaryId !== undefined)\n updateData.gradingBoundaryId = input.gradingBoundaryId;\n\n return prisma.assignment.update({\n where: {\n id: draftId,\n classId,\n teacherId,\n inProgress: true,\n },\n data: updateData as any,\n });\n}\n\nexport async function deleteLabDraft(\n classId: string,\n teacherId: string,\n draftId: string\n) {\n return prisma.assignment.delete({\n where: {\n id: draftId,\n classId,\n teacherId,\n inProgress: true,\n },\n });\n}\n\nexport async function publishLabDraft(\n classId: string,\n teacherId: string,\n draftId: string,\n input: {\n dueDate?: Date;\n maxGrade?: number;\n weight?: number;\n graded?: boolean;\n }\n) {\n const labDraft = await prisma.assignment.findUnique({\n where: {\n id: draftId,\n classId,\n teacherId,\n inProgress: true,\n },\n });\n\n if (!labDraft) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Lab draft not found\",\n });\n }\n\n return prisma.assignment.update({\n where: { id: draftId },\n data: {\n inProgress: false,\n dueDate: input.dueDate || labDraft.dueDate,\n maxGrade: input.maxGrade || labDraft.maxGrade || 100,\n weight: input.weight || labDraft.weight || 1,\n graded: input.graded !== undefined ? input.graded : true,\n modifiedAt: new Date(),\n },\n });\n}\n\nexport async function getFiles(classId: string) {\n const assignments = await findAssignmentsWithFiles(classId);\n return assignments.map((assignment) => ({\n id: assignment.id,\n title: assignment.title,\n teacher: assignment.teacher,\n teacherAttachments: assignment.attachments,\n students: assignment.submissions.map((submission) => ({\n id: submission.student.id,\n username: submission.student.username,\n attachments: submission.attachments,\n annotations: submission.annotations,\n })),\n }));\n}\n\nexport async function exportClass(classId: string, userId: string) {\n const classExport = await findFullExportableClass(classId);\n if (!classExport) {\n throw new TRPCError({\n code: \"INTERNAL_SERVER_ERROR\",\n message: \"Failed to export class\",\n });\n }\n\n return classExport;\n}\n\nexport async function importClass(classId: string, userId: string, year: number, classData: Class & { classFiles: Folder | null }) {\n try {\n const newClassId = await createClassByImport(classId, userId, year, classData);\n if (!newClassId) {\n throw new TRPCError({\n code: \"INTERNAL_SERVER_ERROR\",\n message: \"Failed to import class\",\n });\n }\n return newClassId;\n } catch (err) {\n if (err instanceof TRPCError) throw err;\n const message = err instanceof Error ? err.message : \"Unknown error\";\n throw new TRPCError({\n code: \"INTERNAL_SERVER_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AED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAe,EAAE,MAAc,EAAE,IAAY,EAAE,SAAgD;IAC/H,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QAC/E,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,SAAS,CAAC;gBAClB,IAAI,EAAE,uBAAuB;gBAC7B,OAAO,EAAE,wBAAwB;aAClC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,SAAS;YAAE,MAAM,GAAG,CAAC;QACxC,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QACrE,MAAM,IAAI,SAAS,CAAC;YAClB,IAAI,EAAE,uBAAuB;YAC7B,OAAO,EAAE,2BAA2B,OAAO,EAAE;YAC7C,KAAK,EAAE,GAAG;SACX,CAAC,CAAC;IACL,CAAC;AACH,CAAC","debug_id":"f6a97cb7-783f-56a4-ae40-1d145ee5c1ee"}
|
|
@@ -55,6 +55,7 @@ export declare function createLabChat(userId: string, input: {
|
|
|
55
55
|
createdById: string;
|
|
56
56
|
}>;
|
|
57
57
|
export declare function getLabChat(userId: string, labChatId: string): Promise<{
|
|
58
|
+
pendingGenerationMessageId: string | null;
|
|
58
59
|
class: {
|
|
59
60
|
id: string;
|
|
60
61
|
name: string;
|
|
@@ -96,7 +97,6 @@ export declare function getLabChat(userId: string, labChatId: string): Promise<{
|
|
|
96
97
|
profilePicture: string | null;
|
|
97
98
|
} | null;
|
|
98
99
|
};
|
|
99
|
-
} & {
|
|
100
100
|
context: string;
|
|
101
101
|
id: string;
|
|
102
102
|
createdAt: Date;
|
|
@@ -162,4 +162,8 @@ export declare function postToLabChat(userId: string, input: {
|
|
|
162
162
|
export declare function deleteLabChat(userId: string, labChatId: string): Promise<{
|
|
163
163
|
success: boolean;
|
|
164
164
|
}>;
|
|
165
|
+
/** Rerun the last AI response for a lab chat. Deletes the last AI message and regenerates. */
|
|
166
|
+
export declare function rerunLastResponse(userId: string, labChatId: string): Promise<{
|
|
167
|
+
success: boolean;
|
|
168
|
+
}>;
|
|
165
169
|
//# sourceMappingURL=labChat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"labChat.d.ts","sourceRoot":"/","sources":["services/labChat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"labChat.d.ts","sourceRoot":"/","sources":["services/labChat.ts"],"names":[],"mappings":"AAsBA,sFAAsF;AACtF,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsH3D;AAED,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCjE;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAqBjE;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;IACL,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;;;;;;;;;;;;;;;GAkHF;AAED,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;GAiDpE;AAED,8FAA8F;AAC9F,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;GA2ExE"}
|
package/dist/services/labChat.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* trigger AI responses, and broadcast via Pusher.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
6
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8b239f7a-afdd-5337-8709-287c3ef4c13c")}catch(e){}}();
|
|
7
7
|
import { TRPCError } from "@trpc/server";
|
|
8
|
+
import { GenerationStatus } from "@prisma/client";
|
|
8
9
|
import { prisma } from "../lib/prisma.js";
|
|
9
10
|
import { chatChannel, teacherChannel, pusher } from "../lib/pusher.js";
|
|
10
11
|
import { findClassWithTeachersForLab, findLabChatByMember, findLabChatByTeacher, findLabChatById, findClassMembership, findLabChatsByClass, findLabChatForPost, findLabChatForDelete, findMentionedMemberships, } from "../models/labChat.js";
|
|
@@ -137,7 +138,19 @@ export async function getLabChat(userId, labChatId) {
|
|
|
137
138
|
message: "Lab chat not found or access denied",
|
|
138
139
|
});
|
|
139
140
|
}
|
|
140
|
-
|
|
141
|
+
const pendingMessage = await prisma.message.findFirst({
|
|
142
|
+
where: {
|
|
143
|
+
conversationId: labChat.conversationId,
|
|
144
|
+
status: GenerationStatus.PENDING,
|
|
145
|
+
senderId: { not: "AI_ASSISTANT" },
|
|
146
|
+
},
|
|
147
|
+
orderBy: { createdAt: "desc" },
|
|
148
|
+
select: { id: true },
|
|
149
|
+
});
|
|
150
|
+
return {
|
|
151
|
+
...labChat,
|
|
152
|
+
pendingGenerationMessageId: pendingMessage?.id ?? null,
|
|
153
|
+
};
|
|
141
154
|
}
|
|
142
155
|
export async function listLabChats(userId, classId) {
|
|
143
156
|
const classMembership = await findClassMembership(classId, userId);
|
|
@@ -229,7 +242,21 @@ export async function postToLabChat(userId, input) {
|
|
|
229
242
|
console.error("Failed to broadcast lab chat message:", error);
|
|
230
243
|
}
|
|
231
244
|
if (!isAIUser(userId)) {
|
|
232
|
-
|
|
245
|
+
await prisma.message.update({
|
|
246
|
+
where: { id: result.id },
|
|
247
|
+
data: { status: GenerationStatus.PENDING },
|
|
248
|
+
});
|
|
249
|
+
try {
|
|
250
|
+
await pusher.trigger(teacherChannel(labChat.classId), "lab-response-pending", {
|
|
251
|
+
labChatId,
|
|
252
|
+
messageId: result.id,
|
|
253
|
+
conversationId: labChat.conversationId,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
console.error("Failed to broadcast lab response pending:", error);
|
|
258
|
+
}
|
|
259
|
+
generateAndSendLabResponse(labChatId, content, labChat.conversationId, { classId: labChat.classId, messageId: result.id });
|
|
233
260
|
}
|
|
234
261
|
return {
|
|
235
262
|
id: result.id,
|
|
@@ -285,5 +312,70 @@ export async function deleteLabChat(userId, labChatId) {
|
|
|
285
312
|
}
|
|
286
313
|
return { success: true };
|
|
287
314
|
}
|
|
315
|
+
/** Rerun the last AI response for a lab chat. Deletes the last AI message and regenerates. */
|
|
316
|
+
export async function rerunLastResponse(userId, labChatId) {
|
|
317
|
+
const labChat = await findLabChatForPost(labChatId, userId);
|
|
318
|
+
if (!labChat) {
|
|
319
|
+
throw new TRPCError({
|
|
320
|
+
code: "FORBIDDEN",
|
|
321
|
+
message: "Lab chat not found or access denied",
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
const messages = await prisma.message.findMany({
|
|
325
|
+
where: { conversationId: labChat.conversationId },
|
|
326
|
+
orderBy: { createdAt: "desc" },
|
|
327
|
+
take: 10,
|
|
328
|
+
select: { id: true, content: true, senderId: true, createdAt: true },
|
|
329
|
+
});
|
|
330
|
+
const lastMessage = messages[0];
|
|
331
|
+
if (!lastMessage) {
|
|
332
|
+
throw new TRPCError({
|
|
333
|
+
code: "BAD_REQUEST",
|
|
334
|
+
message: "No messages to rerun",
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
if (!isAIUser(lastMessage.senderId)) {
|
|
338
|
+
throw new TRPCError({
|
|
339
|
+
code: "BAD_REQUEST",
|
|
340
|
+
message: "Last message is not from AI – nothing to rerun",
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
const teacherMessage = messages.find((m) => !isAIUser(m.senderId));
|
|
344
|
+
if (!teacherMessage) {
|
|
345
|
+
throw new TRPCError({
|
|
346
|
+
code: "BAD_REQUEST",
|
|
347
|
+
message: "No teacher message found to rerun from",
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
await prisma.message.delete({
|
|
351
|
+
where: { id: lastMessage.id },
|
|
352
|
+
});
|
|
353
|
+
try {
|
|
354
|
+
await pusher.trigger(chatChannel(labChat.conversationId), "message-deleted", {
|
|
355
|
+
messageId: lastMessage.id,
|
|
356
|
+
conversationId: labChat.conversationId,
|
|
357
|
+
senderId: lastMessage.senderId,
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
console.error("Failed to broadcast message deletion:", error);
|
|
362
|
+
}
|
|
363
|
+
await prisma.message.update({
|
|
364
|
+
where: { id: teacherMessage.id },
|
|
365
|
+
data: { status: GenerationStatus.PENDING },
|
|
366
|
+
});
|
|
367
|
+
try {
|
|
368
|
+
await pusher.trigger(teacherChannel(labChat.classId), "lab-response-pending", {
|
|
369
|
+
labChatId,
|
|
370
|
+
messageId: teacherMessage.id,
|
|
371
|
+
conversationId: labChat.conversationId,
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
console.error("Failed to broadcast lab response pending:", error);
|
|
376
|
+
}
|
|
377
|
+
generateAndSendLabResponse(labChatId, teacherMessage.content, labChat.conversationId, { classId: labChat.classId, messageId: teacherMessage.id });
|
|
378
|
+
return { success: true };
|
|
379
|
+
}
|
|
288
380
|
//# sourceMappingURL=labChat.js.map
|
|
289
|
-
//# debugId=
|
|
381
|
+
//# debugId=8b239f7a-afdd-5337-8709-287c3ef4c13c
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"labChat.js","sources":["services/labChat.ts"],"sourceRoot":"/","sourcesContent":["/**\n * Lab chat service – AI-powered lab conversations. Create lab chats, post messages,\n * trigger AI responses, and broadcast via Pusher.\n */\nimport { TRPCError } from \"@trpc/server\";\nimport { prisma } from \"../lib/prisma.js\";\nimport { chatChannel, teacherChannel, pusher } from \"../lib/pusher.js\";\nimport {\n findClassWithTeachersForLab,\n findLabChatByMember,\n findLabChatByTeacher,\n findLabChatById,\n findClassMembership,\n findLabChatsByClass,\n findLabChatForPost,\n findLabChatForDelete,\n findMentionedMemberships,\n} from \"../models/labChat.js\";\nimport { generateAndSendLabIntroduction, generateAndSendLabResponse } from \"../pipelines/aiLabChat.js\";\nimport { isAIUser } from \"../utils/aiUser.js\";\n\n/** Create a lab chat with conversation and teacher members. Broadcasts via Pusher. */\nexport async function createLabChat(\n userId: string,\n input: { classId: string; title: string; context: string }\n) {\n const { classId, title, context } = input;\n\n const classWithTeachers = await findClassWithTeachersForLab(classId, userId);\n if (!classWithTeachers) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a teacher in this class\",\n });\n }\n\n try {\n JSON.parse(context);\n } catch {\n throw new TRPCError({\n code: \"BAD_REQUEST\",\n message: \"Context must be valid JSON\",\n });\n }\n\n const result = await prisma.$transaction(async (tx) => {\n const conversation = await tx.conversation.create({\n data: {\n type: \"GROUP\",\n name: `Lab: ${title}`,\n displayInChat: false,\n },\n });\n\n const teacherMembers = classWithTeachers.teachers.map((t) => ({\n userId: t.id,\n role: \"ADMIN\" as const,\n }));\n\n await tx.conversationMember.createMany({\n data: teacherMembers.map((member) => ({\n userId: member.userId,\n conversationId: conversation.id,\n role: member.role,\n })),\n });\n\n const labChat = await tx.labChat.create({\n data: {\n title,\n context,\n classId,\n conversationId: conversation.id,\n createdById: userId,\n },\n include: {\n conversation: {\n include: {\n members: {\n include: {\n user: {\n select: {\n id: true,\n username: true,\n profile: {\n select: {\n displayName: true,\n profilePicture: true,\n },\n },\n },\n },\n },\n },\n },\n },\n createdBy: {\n select: {\n id: true,\n username: true,\n profile: {\n select: {\n displayName: true,\n },\n },\n },\n },\n class: {\n select: {\n id: true,\n name: true,\n subject: true,\n section: true,\n },\n },\n },\n });\n\n return labChat;\n });\n\n generateAndSendLabIntroduction(\n result.id,\n result.conversationId,\n context,\n classWithTeachers.subject || \"Lab\"\n );\n\n try {\n await pusher.trigger(teacherChannel(classId), \"lab-chat-created\", {\n id: result.id,\n title: result.title,\n classId: result.classId,\n conversationId: result.conversationId,\n createdBy: result.createdBy,\n createdAt: result.createdAt,\n });\n } catch (error) {\n console.error(\"Failed to broadcast lab chat creation:\", error);\n }\n\n return result;\n}\n\nexport async function getLabChat(userId: string, labChatId: string) {\n let labChat = await findLabChatByMember(labChatId, userId);\n\n if (!labChat) {\n const labChatForTeacher = await findLabChatByTeacher(labChatId, userId);\n if (labChatForTeacher) {\n await prisma.conversationMember.create({\n data: {\n userId,\n conversationId: labChatForTeacher.conversation.id,\n role: \"ADMIN\",\n },\n });\n labChat = await findLabChatById(labChatId);\n }\n }\n\n if (!labChat) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Lab chat not found or access denied\",\n });\n }\n\n return labChat;\n}\n\nexport async function listLabChats(userId: string, classId: string) {\n const classMembership = await findClassMembership(classId, userId);\n if (!classMembership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this class\",\n });\n }\n\n const labChats = await findLabChatsByClass(classId);\n return labChats.map((labChat) => ({\n id: labChat.id,\n title: labChat.title,\n classId: labChat.classId,\n conversationId: labChat.conversationId,\n createdBy: labChat.createdBy,\n createdAt: labChat.createdAt,\n updatedAt: labChat.updatedAt,\n lastMessage: labChat.conversation.messages[0] || null,\n messageCount: labChat.conversation._count.messages,\n }));\n}\n\nexport async function postToLabChat(\n userId: string,\n input: {\n labChatId: string;\n content: string;\n mentionedUserIds?: string[];\n }\n) {\n const { labChatId, content, mentionedUserIds = [] } = input;\n\n const labChat = await findLabChatForPost(labChatId, userId);\n if (!labChat) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Lab chat not found or access denied\",\n });\n }\n\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await findMentionedMemberships(\n labChat.conversationId,\n mentionedUserIds\n );\n if (mentionedMemberships.length !== mentionedUserIds.length) {\n throw new TRPCError({\n code: \"BAD_REQUEST\",\n message: \"Some mentioned users are not members of this lab chat\",\n });\n }\n }\n\n const result = await prisma.$transaction(async (tx) => {\n const message = await tx.message.create({\n data: {\n content,\n senderId: userId,\n conversationId: labChat.conversationId,\n },\n include: {\n sender: {\n select: {\n id: true,\n username: true,\n profile: {\n select: {\n displayName: true,\n profilePicture: true,\n },\n },\n },\n },\n },\n });\n\n if (mentionedUserIds.length > 0) {\n await tx.mention.createMany({\n data: mentionedUserIds.map((mentionedUserId) => ({\n messageId: message.id,\n userId: mentionedUserId,\n })),\n });\n }\n\n await tx.labChat.update({\n where: { id: labChatId },\n data: { updatedAt: new Date() },\n });\n\n return message;\n });\n\n try {\n await pusher.trigger(\n chatChannel(labChat.conversationId),\n \"new-message\",\n {\n id: result.id,\n content: result.content,\n senderId: result.senderId,\n conversationId: result.conversationId,\n createdAt: result.createdAt,\n sender: result.sender,\n mentionedUserIds,\n }\n );\n } catch (error) {\n console.error(\"Failed to broadcast lab chat message:\", error);\n }\n\n if (!isAIUser(userId)) {\n generateAndSendLabResponse(\n labChatId,\n content,\n labChat.conversationId\n );\n }\n\n return {\n id: result.id,\n content: result.content,\n senderId: result.senderId,\n conversationId: result.conversationId,\n createdAt: result.createdAt,\n sender: result.sender,\n mentionedUserIds,\n };\n}\n\nexport async function deleteLabChat(userId: string, labChatId: string) {\n const labChat = await findLabChatForDelete(labChatId, userId);\n if (!labChat) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Lab chat not found or not the creator\",\n });\n }\n\n await prisma.$transaction(async (tx) => {\n await tx.mention.deleteMany({\n where: {\n message: {\n conversationId: labChat.conversationId,\n },\n },\n });\n\n await tx.message.deleteMany({\n where: {\n conversationId: labChat.conversationId,\n },\n });\n\n await tx.conversationMember.deleteMany({\n where: {\n conversationId: labChat.conversationId,\n },\n });\n\n await tx.labChat.delete({\n where: { id: labChatId },\n });\n\n await tx.conversation.delete({\n where: { id: labChat.conversationId },\n });\n });\n\n try {\n await pusher.trigger(teacherChannel(labChat.classId), \"lab-chat-deleted\", {\n labChatId,\n classId: labChat.classId,\n });\n } catch (error) {\n console.error(\"Failed to broadcast lab chat deletion:\", error);\n }\n\n return { success: true };\n}\n"],"names":[],"mappings":"AAAA;;;GAGG;;;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,8BAA8B,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvG,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAc,EACd,KAA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EH,MAAM,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC;YAC1B,KAAK,EAAE;gBACL,cAAc,EAAE,OAAO,CAAC,cAAc;aACvC;SACF,CAAC,CAAC;QAEH,MAAM,EAAE,CAAC,kBAAkB,CAAC,UAAU,CAAC;YACrC,KAAK,EAAE;gBACL,cAAc,EAAE,OAAO,CAAC,cAAc;aACvC;SACF,CAAC,CAAC;QAEH,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;YACtB,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE;SACzB,CAAC,CAAC;QAEH,MAAM,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC;YAC3B,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,cAAc,EAAE;SACtC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,kBAAkB,EAAE;YACxE,SAAS;YACT,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC","debug_id":"4670d854-b077-5066-b467-efb0728256b9"}
|
|
1
|
+
{"version":3,"file":"labChat.js","sources":["services/labChat.ts"],"sourceRoot":"/","sourcesContent":["/**\n * Lab chat service – AI-powered lab conversations. Create lab chats, post messages,\n * trigger AI responses, and broadcast via Pusher.\n */\nimport { TRPCError } from \"@trpc/server\";\nimport { GenerationStatus } from \"@prisma/client\";\nimport { prisma } from \"../lib/prisma.js\";\nimport { chatChannel, teacherChannel, pusher } from \"../lib/pusher.js\";\nimport {\n findClassWithTeachersForLab,\n findLabChatByMember,\n findLabChatByTeacher,\n findLabChatById,\n findClassMembership,\n findLabChatsByClass,\n findLabChatForPost,\n findLabChatForDelete,\n findMentionedMemberships,\n} from \"../models/labChat.js\";\nimport { generateAndSendLabIntroduction, generateAndSendLabResponse } from \"../pipelines/aiLabChat.js\";\nimport { isAIUser } from \"../utils/aiUser.js\";\n\n/** Create a lab chat with conversation and teacher members. Broadcasts via Pusher. */\nexport async function createLabChat(\n userId: string,\n input: { classId: string; title: string; context: string }\n) {\n const { classId, title, context } = input;\n\n const classWithTeachers = await findClassWithTeachersForLab(classId, userId);\n if (!classWithTeachers) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a teacher in this class\",\n });\n }\n\n try {\n JSON.parse(context);\n } catch {\n throw new TRPCError({\n code: \"BAD_REQUEST\",\n message: \"Context must be valid JSON\",\n });\n }\n\n const result = await prisma.$transaction(async (tx) => {\n const conversation = await tx.conversation.create({\n data: {\n type: \"GROUP\",\n name: `Lab: ${title}`,\n displayInChat: false,\n },\n });\n\n const teacherMembers = classWithTeachers.teachers.map((t) => ({\n userId: t.id,\n role: \"ADMIN\" as const,\n }));\n\n await tx.conversationMember.createMany({\n data: teacherMembers.map((member) => ({\n userId: member.userId,\n conversationId: conversation.id,\n role: member.role,\n })),\n });\n\n const labChat = await tx.labChat.create({\n data: {\n title,\n context,\n classId,\n conversationId: conversation.id,\n createdById: userId,\n },\n include: {\n conversation: {\n include: {\n members: {\n include: {\n user: {\n select: {\n id: true,\n username: true,\n profile: {\n select: {\n displayName: true,\n profilePicture: true,\n },\n },\n },\n },\n },\n },\n },\n },\n createdBy: {\n select: {\n id: true,\n username: true,\n profile: {\n select: {\n displayName: true,\n },\n },\n },\n },\n class: {\n select: {\n id: true,\n name: true,\n subject: true,\n section: true,\n },\n },\n },\n });\n\n return labChat;\n });\n\n generateAndSendLabIntroduction(\n result.id,\n result.conversationId,\n context,\n classWithTeachers.subject || \"Lab\"\n );\n\n try {\n await pusher.trigger(teacherChannel(classId), \"lab-chat-created\", {\n id: result.id,\n title: result.title,\n classId: result.classId,\n conversationId: result.conversationId,\n createdBy: result.createdBy,\n createdAt: result.createdAt,\n });\n } catch (error) {\n console.error(\"Failed to broadcast lab chat creation:\", error);\n }\n\n return result;\n}\n\nexport async function getLabChat(userId: string, labChatId: string) {\n let labChat = await findLabChatByMember(labChatId, userId);\n\n if (!labChat) {\n const labChatForTeacher = await findLabChatByTeacher(labChatId, userId);\n if (labChatForTeacher) {\n await prisma.conversationMember.create({\n data: {\n userId,\n conversationId: labChatForTeacher.conversation.id,\n role: \"ADMIN\",\n },\n });\n labChat = await findLabChatById(labChatId);\n }\n }\n\n if (!labChat) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Lab chat not found or access denied\",\n });\n }\n\n const pendingMessage = await prisma.message.findFirst({\n where: {\n conversationId: labChat.conversationId,\n status: GenerationStatus.PENDING,\n senderId: { not: \"AI_ASSISTANT\" },\n },\n orderBy: { createdAt: \"desc\" },\n select: { id: true },\n });\n\n return {\n ...labChat,\n pendingGenerationMessageId: pendingMessage?.id ?? null,\n };\n}\n\nexport async function listLabChats(userId: string, classId: string) {\n const classMembership = await findClassMembership(classId, userId);\n if (!classMembership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this class\",\n });\n }\n\n const labChats = await findLabChatsByClass(classId);\n return labChats.map((labChat) => ({\n id: labChat.id,\n title: labChat.title,\n classId: labChat.classId,\n conversationId: labChat.conversationId,\n createdBy: labChat.createdBy,\n createdAt: labChat.createdAt,\n updatedAt: labChat.updatedAt,\n lastMessage: labChat.conversation.messages[0] || null,\n messageCount: labChat.conversation._count.messages,\n }));\n}\n\nexport async function postToLabChat(\n userId: string,\n input: {\n labChatId: string;\n content: string;\n mentionedUserIds?: string[];\n }\n) {\n const { labChatId, content, mentionedUserIds = [] } = input;\n\n const labChat = await findLabChatForPost(labChatId, userId);\n if (!labChat) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Lab chat not found or access denied\",\n });\n }\n\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await findMentionedMemberships(\n labChat.conversationId,\n mentionedUserIds\n );\n if (mentionedMemberships.length !== mentionedUserIds.length) {\n throw new TRPCError({\n code: \"BAD_REQUEST\",\n message: \"Some mentioned users are not members of this lab chat\",\n });\n }\n }\n\n const result = await prisma.$transaction(async (tx) => {\n const message = await tx.message.create({\n data: {\n content,\n senderId: userId,\n conversationId: labChat.conversationId,\n },\n include: {\n sender: {\n select: {\n id: true,\n username: true,\n profile: {\n select: {\n displayName: true,\n profilePicture: true,\n },\n },\n },\n },\n },\n });\n\n if (mentionedUserIds.length > 0) {\n await tx.mention.createMany({\n data: mentionedUserIds.map((mentionedUserId) => ({\n messageId: message.id,\n userId: mentionedUserId,\n })),\n });\n }\n\n await tx.labChat.update({\n where: { id: labChatId },\n data: { updatedAt: new Date() },\n });\n\n return message;\n });\n\n try {\n await pusher.trigger(\n chatChannel(labChat.conversationId),\n \"new-message\",\n {\n id: result.id,\n content: result.content,\n senderId: result.senderId,\n conversationId: result.conversationId,\n createdAt: result.createdAt,\n sender: result.sender,\n mentionedUserIds,\n }\n );\n } catch (error) {\n console.error(\"Failed to broadcast lab chat message:\", error);\n }\n\n if (!isAIUser(userId)) {\n await prisma.message.update({\n where: { id: result.id },\n data: { status: GenerationStatus.PENDING },\n });\n try {\n await pusher.trigger(teacherChannel(labChat.classId), \"lab-response-pending\", {\n labChatId,\n messageId: result.id,\n conversationId: labChat.conversationId,\n });\n } catch (error) {\n console.error(\"Failed to broadcast lab response pending:\", error);\n }\n generateAndSendLabResponse(\n labChatId,\n content,\n labChat.conversationId,\n { classId: labChat.classId, messageId: result.id }\n );\n }\n\n return {\n id: result.id,\n content: result.content,\n senderId: result.senderId,\n conversationId: result.conversationId,\n createdAt: result.createdAt,\n sender: result.sender,\n mentionedUserIds,\n };\n}\n\nexport async function deleteLabChat(userId: string, labChatId: string) {\n const labChat = await findLabChatForDelete(labChatId, userId);\n if (!labChat) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Lab chat not found or not the creator\",\n });\n }\n\n await prisma.$transaction(async (tx) => {\n await tx.mention.deleteMany({\n where: {\n message: {\n conversationId: labChat.conversationId,\n },\n },\n });\n\n await tx.message.deleteMany({\n where: {\n conversationId: labChat.conversationId,\n },\n });\n\n await tx.conversationMember.deleteMany({\n where: {\n conversationId: labChat.conversationId,\n },\n });\n\n await tx.labChat.delete({\n where: { id: labChatId },\n });\n\n await tx.conversation.delete({\n where: { id: labChat.conversationId },\n });\n });\n\n try {\n await pusher.trigger(teacherChannel(labChat.classId), \"lab-chat-deleted\", {\n labChatId,\n classId: labChat.classId,\n });\n } catch (error) {\n console.error(\"Failed to broadcast lab chat deletion:\", error);\n }\n\n return { success: true };\n}\n\n/** Rerun the last AI response for a lab chat. Deletes the last AI message and regenerates. */\nexport async function rerunLastResponse(userId: string, labChatId: string) {\n const labChat = await findLabChatForPost(labChatId, userId);\n if (!labChat) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Lab chat not found or access denied\",\n });\n }\n\n const messages = await prisma.message.findMany({\n where: { conversationId: labChat.conversationId },\n orderBy: { createdAt: \"desc\" },\n take: 10,\n select: { id: true, content: true, senderId: true, createdAt: true },\n });\n\n const lastMessage = messages[0];\n if (!lastMessage) {\n throw new TRPCError({\n code: \"BAD_REQUEST\",\n message: \"No messages to rerun\",\n });\n }\n\n if (!isAIUser(lastMessage.senderId)) {\n throw new TRPCError({\n code: \"BAD_REQUEST\",\n message: \"Last message is not from AI – nothing to rerun\",\n });\n }\n\n const teacherMessage = messages.find((m) => !isAIUser(m.senderId));\n if (!teacherMessage) {\n throw new TRPCError({\n code: \"BAD_REQUEST\",\n message: \"No teacher message found to rerun from\",\n });\n }\n\n await prisma.message.delete({\n where: { id: lastMessage.id },\n });\n\n try {\n await pusher.trigger(chatChannel(labChat.conversationId), \"message-deleted\", {\n messageId: lastMessage.id,\n conversationId: labChat.conversationId,\n senderId: lastMessage.senderId,\n });\n } catch (error) {\n console.error(\"Failed to broadcast message deletion:\", error);\n }\n\n await prisma.message.update({\n where: { id: teacherMessage.id },\n data: { status: GenerationStatus.PENDING },\n });\n try {\n await pusher.trigger(teacherChannel(labChat.classId), \"lab-response-pending\", {\n labChatId,\n messageId: teacherMessage.id,\n conversationId: labChat.conversationId,\n });\n } catch (error) {\n console.error(\"Failed to broadcast lab response pending:\", error);\n }\n\n generateAndSendLabResponse(\n labChatId,\n teacherMessage.content,\n labChat.conversationId,\n { classId: labChat.classId, messageId: teacherMessage.id }\n );\n\n return { success: true };\n}\n"],"names":[],"mappings":"AAAA;;;GAGG;;;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,8BAA8B,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvG,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAc,EACd,KAA0D;IAE1D,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAE1C,MAAM,iBAAiB,GAAG,MAAM,2BAA2B,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7E,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,MAAM,IAAI,SAAS,CAAC;YAClB,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,6BA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AAE,cAAc,CAAC,EAAE;YAC5B,cAAc,EAAE,OAAO,CAAC,cAAc;SACvC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,KAAK,CAAC,CAAC;IACpE,CAAC;IAED,0BAA0B,CACxB,SAAS,EACT,cAAc,CAAC,OAAO,EACtB,OAAO,CAAC,cAAc,EACtB,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,cAAc,CAAC,EAAE,EAAE,CAC3D,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC","debug_id":"8b239f7a-afdd-5337-8709-287c3ef4c13c"}
|
|
@@ -82,6 +82,14 @@ export declare function deleteMessage(userId: string, messageId: string): Promis
|
|
|
82
82
|
success: boolean;
|
|
83
83
|
messageId: string;
|
|
84
84
|
}>;
|
|
85
|
+
/** Mark an AI-suggested item as created. Stores in message meta for fast reads. */
|
|
86
|
+
export declare function markSuggestionCreated(userId: string, input: {
|
|
87
|
+
messageId: string;
|
|
88
|
+
type: "assignment" | "worksheet" | "section";
|
|
89
|
+
index: number;
|
|
90
|
+
}): Promise<{
|
|
91
|
+
success: boolean;
|
|
92
|
+
}>;
|
|
85
93
|
export declare function markAsRead(userId: string, conversationId: string): Promise<{
|
|
86
94
|
success: boolean;
|
|
87
95
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"/","sources":["services/message.ts"],"names":[],"mappings":"AAkBA,oEAAoE;AACpE,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;IACL,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;;;;;;;;;;;;;;;;;;;;cAoCyB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;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AAM,EAAE,CAAC;CAC7B;;;;;;;;;;;;;;;GAqGF;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;IACL,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;;;;;;;;;;;;;;;GAmHF;AAED,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;;GAuDpE;AAQD,mFAAmF;AACnF,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;IACL,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,YAAY,GAAG,WAAW,GAAG,SAAS,CAAC;IAC7C,KAAK,EAAE,MAAM,CAAC;CACf;;GA8EF;AAED,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;;GA+BtE;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM;;GAgCvB;AAED,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM;;;GA8BvB"}
|
package/dist/services/message.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Broadcasts real-time updates via Pusher.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
6
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e62f686d-b0ff-52aa-9ec8-e3fd9dc8a1a9")}catch(e){}}();
|
|
7
7
|
import { TRPCError } from "@trpc/server";
|
|
8
8
|
import { prisma } from "../lib/prisma.js";
|
|
9
9
|
import { chatChannel, pusher } from "../lib/pusher.js";
|
|
@@ -277,6 +277,78 @@ export async function deleteMessage(userId, messageId) {
|
|
|
277
277
|
}
|
|
278
278
|
return { success: true, messageId };
|
|
279
279
|
}
|
|
280
|
+
const CREATED_INDICES_KEY = {
|
|
281
|
+
assignment: "assignments",
|
|
282
|
+
worksheet: "worksheets",
|
|
283
|
+
section: "sections",
|
|
284
|
+
};
|
|
285
|
+
/** Mark an AI-suggested item as created. Stores in message meta for fast reads. */
|
|
286
|
+
export async function markSuggestionCreated(userId, input) {
|
|
287
|
+
const { messageId, type, index } = input;
|
|
288
|
+
const existingMessage = await findMessageByIdMinimal(messageId);
|
|
289
|
+
if (!existingMessage) {
|
|
290
|
+
throw new TRPCError({
|
|
291
|
+
code: "NOT_FOUND",
|
|
292
|
+
message: "Message not found",
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
const membership = await findConversationMembership(existingMessage.conversationId, userId);
|
|
296
|
+
if (!membership) {
|
|
297
|
+
throw new TRPCError({
|
|
298
|
+
code: "FORBIDDEN",
|
|
299
|
+
message: "Not a member of this conversation",
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
const currentMeta = existingMessage.meta ?? {};
|
|
303
|
+
const createdIndices = currentMeta.createdIndices ?? {};
|
|
304
|
+
const typeIndices = createdIndices[CREATED_INDICES_KEY[type]] ?? [];
|
|
305
|
+
if (typeIndices.includes(index))
|
|
306
|
+
return { success: true };
|
|
307
|
+
const newTypeIndices = [...typeIndices, index].sort((a, b) => a - b);
|
|
308
|
+
const newMeta = {
|
|
309
|
+
...currentMeta,
|
|
310
|
+
createdIndices: {
|
|
311
|
+
...createdIndices,
|
|
312
|
+
[CREATED_INDICES_KEY[type]]: newTypeIndices,
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
const updated = await prisma.message.update({
|
|
316
|
+
where: { id: messageId },
|
|
317
|
+
data: { meta: newMeta },
|
|
318
|
+
include: {
|
|
319
|
+
sender: {
|
|
320
|
+
select: {
|
|
321
|
+
id: true,
|
|
322
|
+
username: true,
|
|
323
|
+
profile: {
|
|
324
|
+
select: { displayName: true, profilePicture: true },
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
attachments: { select: { id: true, name: true, type: true } },
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
try {
|
|
332
|
+
await pusher.trigger(chatChannel(existingMessage.conversationId), "message-updated", {
|
|
333
|
+
id: updated.id,
|
|
334
|
+
content: updated.content,
|
|
335
|
+
senderId: updated.senderId,
|
|
336
|
+
conversationId: updated.conversationId,
|
|
337
|
+
createdAt: updated.createdAt,
|
|
338
|
+
sender: updated.sender,
|
|
339
|
+
attachments: updated.attachments ?? [],
|
|
340
|
+
meta: newMeta,
|
|
341
|
+
mentionedUserIds: [],
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
logger.error("Failed to broadcast suggestion status via Pusher", {
|
|
346
|
+
error,
|
|
347
|
+
messageId,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
return { success: true };
|
|
351
|
+
}
|
|
280
352
|
export async function markAsRead(userId, conversationId) {
|
|
281
353
|
const membership = await findConversationMembership(conversationId, userId);
|
|
282
354
|
if (!membership) {
|
|
@@ -347,4 +419,4 @@ export async function getUnreadCount(userId, conversationId) {
|
|
|
347
419
|
return { unreadCount, unreadMentionCount };
|
|
348
420
|
}
|
|
349
421
|
//# sourceMappingURL=message.js.map
|
|
350
|
-
//# debugId=
|
|
422
|
+
//# debugId=e62f686d-b0ff-52aa-9ec8-e3fd9dc8a1a9
|