@studious-lms/server 1.4.0 → 1.4.1
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/pipelines/aiLabChat.d.ts +9 -5
- package/dist/pipelines/aiLabChat.d.ts.map +1 -1
- package/dist/pipelines/aiLabChat.js +37 -144
- package/dist/pipelines/aiLabChat.js.map +1 -1
- package/dist/pipelines/aiLabChatContract.d.ts +413 -0
- package/dist/pipelines/aiLabChatContract.d.ts.map +1 -0
- package/dist/pipelines/aiLabChatContract.js +74 -0
- package/dist/pipelines/aiLabChatContract.js.map +1 -0
- package/dist/pipelines/labChatPrompt.d.ts +2 -0
- package/dist/pipelines/labChatPrompt.d.ts.map +1 -0
- package/dist/pipelines/labChatPrompt.js +72 -0
- package/dist/pipelines/labChatPrompt.js.map +1 -0
- package/dist/routers/_app.d.ts +146 -0
- package/dist/routers/_app.d.ts.map +1 -1
- package/dist/routers/_app.js +4 -2
- package/dist/routers/_app.js.map +1 -1
- package/dist/routers/studentProgress.d.ts +75 -0
- package/dist/routers/studentProgress.d.ts.map +1 -0
- package/dist/routers/studentProgress.js +33 -0
- package/dist/routers/studentProgress.js.map +1 -0
- package/dist/services/labChat.d.ts.map +1 -1
- package/dist/services/labChat.js +31 -15
- package/dist/services/labChat.js.map +1 -1
- package/dist/services/message.d.ts.map +1 -1
- package/dist/services/message.js +90 -48
- package/dist/services/message.js.map +1 -1
- package/dist/services/studentProgress.d.ts +45 -0
- package/dist/services/studentProgress.d.ts.map +1 -0
- package/dist/services/studentProgress.js +291 -0
- package/dist/services/studentProgress.js.map +1 -0
- package/package.json +2 -2
- package/sentry.properties +3 -0
- package/src/pipelines/aiLabChat.ts +37 -148
- package/src/pipelines/aiLabChatContract.ts +75 -0
- package/src/pipelines/labChatPrompt.ts +68 -0
- package/src/routers/_app.ts +4 -2
- package/src/routers/studentProgress.ts +47 -0
- package/src/services/labChat.ts +31 -22
- package/src/services/message.ts +97 -48
- package/src/services/studentProgress.ts +390 -0
- package/tests/lib/aiLabChatContract.test.ts +32 -0
- package/tests/pipelines/aiLabChat.test.ts +95 -0
- package/tests/routers/studentProgress.test.ts +283 -0
- package/tests/utils/aiLabChatPrompt.test.ts +18 -0
- package/vitest.unit.config.ts +7 -1
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]="34cd10db-4918-5874-bb52-7749bd2796dd")}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";
|
|
@@ -282,6 +282,7 @@ const CREATED_INDICES_KEY = {
|
|
|
282
282
|
worksheet: "worksheets",
|
|
283
283
|
section: "sections",
|
|
284
284
|
};
|
|
285
|
+
const MARK_SUGGESTION_MAX_RETRIES = 5;
|
|
285
286
|
/** Mark an AI-suggested item as created. Stores in message meta for fast reads. */
|
|
286
287
|
export async function markSuggestionCreated(userId, input) {
|
|
287
288
|
const { messageId, type, index } = input;
|
|
@@ -299,55 +300,96 @@ export async function markSuggestionCreated(userId, input) {
|
|
|
299
300
|
message: "Not a member of this conversation",
|
|
300
301
|
});
|
|
301
302
|
}
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
303
|
+
const conversationId = existingMessage.conversationId;
|
|
304
|
+
let lastError = null;
|
|
305
|
+
for (let attempt = 0; attempt < MARK_SUGGESTION_MAX_RETRIES; attempt++) {
|
|
306
|
+
const msg = await prisma.message.findUnique({
|
|
307
|
+
where: { id: messageId },
|
|
308
|
+
select: { meta: true },
|
|
309
|
+
});
|
|
310
|
+
if (!msg) {
|
|
311
|
+
throw new TRPCError({
|
|
312
|
+
code: "NOT_FOUND",
|
|
313
|
+
message: "Message not found",
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
const currentMeta = msg.meta ?? {};
|
|
317
|
+
const createdIndices = currentMeta.createdIndices ?? {};
|
|
318
|
+
const typeIndices = createdIndices[CREATED_INDICES_KEY[type]] ?? [];
|
|
319
|
+
if (typeIndices.includes(index))
|
|
320
|
+
return { success: true };
|
|
321
|
+
const newTypeIndices = [...typeIndices, index].sort((a, b) => a - b);
|
|
322
|
+
const newMeta = {
|
|
323
|
+
...currentMeta,
|
|
324
|
+
createdIndices: {
|
|
325
|
+
...createdIndices,
|
|
326
|
+
[CREATED_INDICES_KEY[type]]: newTypeIndices,
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
const newMetaJson = JSON.stringify(newMeta);
|
|
330
|
+
const currentMetaJson = msg.meta === null ? null : JSON.stringify(msg.meta);
|
|
331
|
+
const updatedCount = currentMetaJson === null
|
|
332
|
+
? await prisma.$executeRaw `
|
|
333
|
+
UPDATE "Message" SET meta = ${newMetaJson}::jsonb
|
|
334
|
+
WHERE id = ${messageId} AND meta IS NULL
|
|
335
|
+
`
|
|
336
|
+
: await prisma.$executeRaw `
|
|
337
|
+
UPDATE "Message" SET meta = ${newMetaJson}::jsonb
|
|
338
|
+
WHERE id = ${messageId} AND meta = ${currentMetaJson}::jsonb
|
|
339
|
+
`;
|
|
340
|
+
if (Number(updatedCount) > 0) {
|
|
341
|
+
const updated = await prisma.message.findUnique({
|
|
342
|
+
where: { id: messageId },
|
|
343
|
+
include: {
|
|
344
|
+
sender: {
|
|
345
|
+
select: {
|
|
346
|
+
id: true,
|
|
347
|
+
username: true,
|
|
348
|
+
profile: {
|
|
349
|
+
select: { displayName: true, profilePicture: true },
|
|
350
|
+
},
|
|
351
|
+
},
|
|
325
352
|
},
|
|
353
|
+
attachments: { select: { id: true, name: true, type: true } },
|
|
354
|
+
mentions: { select: { userId: true } },
|
|
326
355
|
},
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
356
|
+
});
|
|
357
|
+
if (updated) {
|
|
358
|
+
const mentionedUserIds = updated.mentions.map((m) => m.userId);
|
|
359
|
+
try {
|
|
360
|
+
await pusher.trigger(chatChannel(conversationId), "message-updated", {
|
|
361
|
+
id: updated.id,
|
|
362
|
+
content: updated.content,
|
|
363
|
+
senderId: updated.senderId,
|
|
364
|
+
conversationId: updated.conversationId,
|
|
365
|
+
createdAt: updated.createdAt,
|
|
366
|
+
sender: updated.sender,
|
|
367
|
+
attachments: updated.attachments ?? [],
|
|
368
|
+
meta: newMeta,
|
|
369
|
+
mentionedUserIds,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
logger.error("Failed to broadcast suggestion status via Pusher", {
|
|
374
|
+
error,
|
|
375
|
+
messageId,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return { success: true };
|
|
380
|
+
}
|
|
381
|
+
lastError = new Error("Concurrent update conflict");
|
|
349
382
|
}
|
|
350
|
-
|
|
383
|
+
logger.error("markSuggestionCreated failed after retries", {
|
|
384
|
+
messageId,
|
|
385
|
+
type,
|
|
386
|
+
index,
|
|
387
|
+
error: lastError,
|
|
388
|
+
});
|
|
389
|
+
throw new TRPCError({
|
|
390
|
+
code: "CONFLICT",
|
|
391
|
+
message: "Failed to update suggestion status after retries due to concurrent updates",
|
|
392
|
+
});
|
|
351
393
|
}
|
|
352
394
|
export async function markAsRead(userId, conversationId) {
|
|
353
395
|
const membership = await findConversationMembership(conversationId, userId);
|
|
@@ -419,4 +461,4 @@ export async function getUnreadCount(userId, conversationId) {
|
|
|
419
461
|
return { unreadCount, unreadMentionCount };
|
|
420
462
|
}
|
|
421
463
|
//# sourceMappingURL=message.js.map
|
|
422
|
-
//# debugId=
|
|
464
|
+
//# debugId=34cd10db-4918-5874-bb52-7749bd2796dd
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sources":["services/message.ts"],"sourceRoot":"/","sourcesContent":["/**\n * Message service – send, update, delete messages; mark as read; track mentions.\n * Broadcasts real-time updates via Pusher.\n */\nimport { TRPCError } from \"@trpc/server\";\nimport { prisma } from \"../lib/prisma.js\";\nimport { chatChannel, pusher } from \"../lib/pusher.js\";\nimport { logger } from \"../utils/logger.js\";\nimport {\n findConversationMembership,\n findMessages,\n findMentionedMemberships,\n findMessageById,\n findMessageByIdMinimal,\n countUnreadMessages,\n countUnreadMentions,\n} from \"../models/message.js\";\n\n/** List messages in a conversation with cursor-based pagination. */\nexport async function listMessages(\n userId: string,\n input: {\n conversationId: string;\n cursor?: string;\n limit: number;\n }\n) {\n const { conversationId, cursor, limit } = input;\n\n const membership = await findConversationMembership(conversationId, userId);\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n const messages = await findMessages(conversationId, {\n cursor: cursor ? new Date(cursor) : undefined,\n limit,\n });\n\n let nextCursor: string | undefined;\n if (messages.length > limit) {\n const nextItem = messages.pop();\n nextCursor = nextItem!.createdAt.toISOString();\n }\n\n return {\n messages: messages.reverse().map((message) => ({\n id: message.id,\n content: message.content,\n senderId: message.senderId,\n conversationId: message.conversationId,\n createdAt: message.createdAt,\n sender: message.sender,\n attachments: message.attachments.map((a) => ({\n id: a.id,\n name: a.name,\n type: a.type,\n })),\n meta: message.meta as Record<string, unknown>,\n mentions: message.mentions.map((m) => ({ user: m.user })),\n mentionsMe: message.mentions.some((m) => m.userId === userId),\n })),\n nextCursor,\n };\n}\n\n/** Send a message. Validates membership, creates message, broadcasts via Pusher. */\nexport async function sendMessage(\n userId: string,\n input: {\n conversationId: string;\n content: string;\n mentionedUserIds?: string[];\n }\n) {\n const { conversationId, content, mentionedUserIds = [] } = input;\n\n const membership = await findConversationMembership(conversationId, userId);\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await findMentionedMemberships(\n 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 conversation\",\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,\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 attachments: {\n select: { id: true, name: true, type: true },\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.conversation.update({\n where: { id: conversationId },\n data: { updatedAt: new Date() },\n });\n\n return message;\n });\n\n try {\n await pusher.trigger(\n chatChannel(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 attachments: result.attachments ?? [],\n meta: (result.meta as Record<string, unknown>) ?? {},\n mentionedUserIds,\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast message via Pusher\", {\n error,\n conversationId,\n 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 updateMessage(\n userId: string,\n input: {\n messageId: string;\n content: string;\n mentionedUserIds?: string[];\n }\n) {\n const { messageId, content, mentionedUserIds = [] } = input;\n\n const existingMessage = await findMessageById(messageId);\n if (!existingMessage) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Message not found\",\n });\n }\n\n if (existingMessage.senderId !== userId) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not the sender of this message\",\n });\n }\n\n const membership = await findConversationMembership(\n existingMessage.conversationId,\n userId\n );\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await findMentionedMemberships(\n existingMessage.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 conversation\",\n });\n }\n }\n\n const updatedMessage = await prisma.$transaction(async (tx) => {\n const message = await tx.message.update({\n where: { id: messageId },\n data: { content },\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 attachments: {\n select: { id: true, name: true, type: true },\n },\n },\n });\n\n await tx.mention.deleteMany({\n where: { messageId },\n });\n\n if (mentionedUserIds.length > 0) {\n await tx.mention.createMany({\n data: mentionedUserIds.map((mentionedUserId) => ({\n messageId,\n userId: mentionedUserId,\n })),\n });\n }\n\n return message;\n });\n\n try {\n await pusher.trigger(\n chatChannel(existingMessage.conversationId),\n \"message-updated\",\n {\n id: updatedMessage.id,\n content: updatedMessage.content,\n senderId: updatedMessage.senderId,\n conversationId: updatedMessage.conversationId,\n createdAt: updatedMessage.createdAt,\n sender: updatedMessage.sender,\n attachments: updatedMessage.attachments ?? [],\n meta: (updatedMessage.meta as Record<string, unknown>) ?? {},\n mentionedUserIds,\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast message update via Pusher\", {\n error,\n conversationId: existingMessage.conversationId,\n messageId,\n });\n }\n\n return {\n id: updatedMessage.id,\n content: updatedMessage.content,\n senderId: updatedMessage.senderId,\n conversationId: updatedMessage.conversationId,\n createdAt: updatedMessage.createdAt,\n sender: updatedMessage.sender,\n mentionedUserIds,\n };\n}\n\nexport async function deleteMessage(userId: string, messageId: string) {\n const existingMessage = await findMessageByIdMinimal(messageId);\n if (!existingMessage) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Message not found\",\n });\n }\n\n if (existingMessage.senderId !== userId) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not the sender of this message\",\n });\n }\n\n const membership = await findConversationMembership(\n existingMessage.conversationId,\n userId\n );\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n await prisma.$transaction(async (tx) => {\n await tx.mention.deleteMany({\n where: { messageId },\n });\n await tx.message.delete({\n where: { id: messageId },\n });\n });\n\n try {\n await pusher.trigger(\n chatChannel(existingMessage.conversationId),\n \"message-deleted\",\n {\n messageId,\n conversationId: existingMessage.conversationId,\n senderId: existingMessage.senderId,\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast message deletion via Pusher\", {\n error,\n conversationId: existingMessage.conversationId,\n messageId,\n });\n }\n\n return { success: true, messageId };\n}\n\nconst CREATED_INDICES_KEY: Record<\"assignment\" | \"worksheet\" | \"section\", string> = {\n assignment: \"assignments\",\n worksheet: \"worksheets\",\n section: \"sections\",\n};\n\n/** Mark an AI-suggested item as created. Stores in message meta for fast reads. */\nexport async function markSuggestionCreated(\n userId: string,\n input: {\n messageId: string;\n type: \"assignment\" | \"worksheet\" | \"section\";\n index: number;\n }\n) {\n const { messageId, type, index } = input;\n\n const existingMessage = await findMessageByIdMinimal(messageId);\n if (!existingMessage) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Message not found\",\n });\n }\n\n const membership = await findConversationMembership(\n existingMessage.conversationId,\n userId\n );\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n const currentMeta = (existingMessage.meta as Record<string, unknown>) ?? {};\n const createdIndices = (currentMeta.createdIndices as Record<string, number[]>) ?? {};\n const typeIndices = createdIndices[CREATED_INDICES_KEY[type]] ?? [];\n if (typeIndices.includes(index)) return { success: true };\n\n const newTypeIndices = [...typeIndices, index].sort((a, b) => a - b);\n const newMeta = {\n ...currentMeta,\n createdIndices: {\n ...createdIndices,\n [CREATED_INDICES_KEY[type]]: newTypeIndices,\n },\n };\n\n const updated = await prisma.message.update({\n where: { id: messageId },\n data: { meta: newMeta as object },\n include: {\n sender: {\n select: {\n id: true,\n username: true,\n profile: {\n select: { displayName: true, profilePicture: true },\n },\n },\n },\n attachments: { select: { id: true, name: true, type: true } },\n },\n });\n\n try {\n await pusher.trigger(\n chatChannel(existingMessage.conversationId),\n \"message-updated\",\n {\n id: updated.id,\n content: updated.content,\n senderId: updated.senderId,\n conversationId: updated.conversationId,\n createdAt: updated.createdAt,\n sender: updated.sender,\n attachments: updated.attachments ?? [],\n meta: newMeta,\n mentionedUserIds: [] as string[],\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast suggestion status via Pusher\", {\n error,\n messageId,\n });\n }\n\n return { success: true };\n}\n\nexport async function markAsRead(userId: string, conversationId: string) {\n const membership = await findConversationMembership(conversationId, userId);\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n await prisma.conversationMember.update({\n where: { id: membership.id },\n data: { lastViewedAt: new Date() },\n });\n\n try {\n await pusher.trigger(\n chatChannel(conversationId),\n \"conversation-viewed\",\n {\n userId,\n viewedAt: new Date(),\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast conversation-viewed via Pusher\", {\n error,\n conversationId,\n });\n }\n\n return { success: true };\n}\n\nexport async function markMentionsAsRead(\n userId: string,\n conversationId: string\n) {\n const membership = await findConversationMembership(conversationId, userId);\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n await prisma.conversationMember.update({\n where: { id: membership.id },\n data: { lastViewedMentionAt: new Date() },\n });\n\n try {\n await pusher.trigger(\n chatChannel(conversationId),\n \"mentions-viewed\",\n {\n userId,\n viewedAt: new Date(),\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast mentions-viewed via Pusher\", {\n error,\n conversationId,\n });\n }\n\n return { success: true };\n}\n\nexport async function getUnreadCount(\n userId: string,\n conversationId: string\n) {\n const membership = await findConversationMembership(conversationId, userId);\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n const unreadCount = await countUnreadMessages(\n conversationId,\n userId,\n membership.lastViewedAt ?? undefined\n );\n\n const mentionCutoffTime =\n membership.lastViewedMentionAt && membership.lastViewedAt\n ? membership.lastViewedMentionAt > membership.lastViewedAt\n ? membership.lastViewedMentionAt\n : membership.lastViewedAt\n : membership.lastViewedMentionAt ?? membership.lastViewedAt;\n\n const unreadMentionCount = await countUnreadMentions(\n conversationId,\n userId,\n mentionCutoffTime ?? undefined\n );\n\n return { unreadCount, unreadMentionCount };\n}\n"],"names":[],"mappings":"AAAA;;;GAGG;;;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAA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,mBAAmB,CAC3C,cAAc,EACd,MAAM,EACN,UAAU,CAAC,YAAY,IAAI,SAAS,CACrC,CAAC;IAEF,MAAM,iBAAiB,GACrB,UAAU,CAAC,mBAAmB,IAAI,UAAU,CAAC,YAAY;QACvD,CAAC,CAAC,UAAU,CAAC,mBAAmB,GAAG,UAAU,CAAC,YAAY;YACxD,CAAC,CAAC,UAAU,CAAC,mBAAmB;YAChC,CAAC,CAAC,UAAU,CAAC,YAAY;QAC3B,CAAC,CAAC,UAAU,CAAC,mBAAmB,IAAI,UAAU,CAAC,YAAY,CAAC;IAEhE,MAAM,kBAAkB,GAAG,MAAM,mBAAmB,CAClD,cAAc,EACd,MAAM,EACN,iBAAiB,IAAI,SAAS,CAC/B,CAAC;IAEF,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;AAC7C,CAAC","debug_id":"e62f686d-b0ff-52aa-9ec8-e3fd9dc8a1a9"}
|
|
1
|
+
{"version":3,"file":"message.js","sources":["services/message.ts"],"sourceRoot":"/","sourcesContent":["/**\n * Message service – send, update, delete messages; mark as read; track mentions.\n * Broadcasts real-time updates via Pusher.\n */\nimport { TRPCError } from \"@trpc/server\";\nimport { prisma } from \"../lib/prisma.js\";\nimport { chatChannel, pusher } from \"../lib/pusher.js\";\nimport { logger } from \"../utils/logger.js\";\nimport {\n findConversationMembership,\n findMessages,\n findMentionedMemberships,\n findMessageById,\n findMessageByIdMinimal,\n countUnreadMessages,\n countUnreadMentions,\n} from \"../models/message.js\";\n\n/** List messages in a conversation with cursor-based pagination. */\nexport async function listMessages(\n userId: string,\n input: {\n conversationId: string;\n cursor?: string;\n limit: number;\n }\n) {\n const { conversationId, cursor, limit } = input;\n\n const membership = await findConversationMembership(conversationId, userId);\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n const messages = await findMessages(conversationId, {\n cursor: cursor ? new Date(cursor) : undefined,\n limit,\n });\n\n let nextCursor: string | undefined;\n if (messages.length > limit) {\n const nextItem = messages.pop();\n nextCursor = nextItem!.createdAt.toISOString();\n }\n\n return {\n messages: messages.reverse().map((message) => ({\n id: message.id,\n content: message.content,\n senderId: message.senderId,\n conversationId: message.conversationId,\n createdAt: message.createdAt,\n sender: message.sender,\n attachments: message.attachments.map((a) => ({\n id: a.id,\n name: a.name,\n type: a.type,\n })),\n meta: message.meta as Record<string, unknown>,\n mentions: message.mentions.map((m) => ({ user: m.user })),\n mentionsMe: message.mentions.some((m) => m.userId === userId),\n })),\n nextCursor,\n };\n}\n\n/** Send a message. Validates membership, creates message, broadcasts via Pusher. */\nexport async function sendMessage(\n userId: string,\n input: {\n conversationId: string;\n content: string;\n mentionedUserIds?: string[];\n }\n) {\n const { conversationId, content, mentionedUserIds = [] } = input;\n\n const membership = await findConversationMembership(conversationId, userId);\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await findMentionedMemberships(\n 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 conversation\",\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,\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 attachments: {\n select: { id: true, name: true, type: true },\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.conversation.update({\n where: { id: conversationId },\n data: { updatedAt: new Date() },\n });\n\n return message;\n });\n\n try {\n await pusher.trigger(\n chatChannel(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 attachments: result.attachments ?? [],\n meta: (result.meta as Record<string, unknown>) ?? {},\n mentionedUserIds,\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast message via Pusher\", {\n error,\n conversationId,\n 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 updateMessage(\n userId: string,\n input: {\n messageId: string;\n content: string;\n mentionedUserIds?: string[];\n }\n) {\n const { messageId, content, mentionedUserIds = [] } = input;\n\n const existingMessage = await findMessageById(messageId);\n if (!existingMessage) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Message not found\",\n });\n }\n\n if (existingMessage.senderId !== userId) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not the sender of this message\",\n });\n }\n\n const membership = await findConversationMembership(\n existingMessage.conversationId,\n userId\n );\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await findMentionedMemberships(\n existingMessage.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 conversation\",\n });\n }\n }\n\n const updatedMessage = await prisma.$transaction(async (tx) => {\n const message = await tx.message.update({\n where: { id: messageId },\n data: { content },\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 attachments: {\n select: { id: true, name: true, type: true },\n },\n },\n });\n\n await tx.mention.deleteMany({\n where: { messageId },\n });\n\n if (mentionedUserIds.length > 0) {\n await tx.mention.createMany({\n data: mentionedUserIds.map((mentionedUserId) => ({\n messageId,\n userId: mentionedUserId,\n })),\n });\n }\n\n return message;\n });\n\n try {\n await pusher.trigger(\n chatChannel(existingMessage.conversationId),\n \"message-updated\",\n {\n id: updatedMessage.id,\n content: updatedMessage.content,\n senderId: updatedMessage.senderId,\n conversationId: updatedMessage.conversationId,\n createdAt: updatedMessage.createdAt,\n sender: updatedMessage.sender,\n attachments: updatedMessage.attachments ?? [],\n meta: (updatedMessage.meta as Record<string, unknown>) ?? {},\n mentionedUserIds,\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast message update via Pusher\", {\n error,\n conversationId: existingMessage.conversationId,\n messageId,\n });\n }\n\n return {\n id: updatedMessage.id,\n content: updatedMessage.content,\n senderId: updatedMessage.senderId,\n conversationId: updatedMessage.conversationId,\n createdAt: updatedMessage.createdAt,\n sender: updatedMessage.sender,\n mentionedUserIds,\n };\n}\n\nexport async function deleteMessage(userId: string, messageId: string) {\n const existingMessage = await findMessageByIdMinimal(messageId);\n if (!existingMessage) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Message not found\",\n });\n }\n\n if (existingMessage.senderId !== userId) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not the sender of this message\",\n });\n }\n\n const membership = await findConversationMembership(\n existingMessage.conversationId,\n userId\n );\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n await prisma.$transaction(async (tx) => {\n await tx.mention.deleteMany({\n where: { messageId },\n });\n await tx.message.delete({\n where: { id: messageId },\n });\n });\n\n try {\n await pusher.trigger(\n chatChannel(existingMessage.conversationId),\n \"message-deleted\",\n {\n messageId,\n conversationId: existingMessage.conversationId,\n senderId: existingMessage.senderId,\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast message deletion via Pusher\", {\n error,\n conversationId: existingMessage.conversationId,\n messageId,\n });\n }\n\n return { success: true, messageId };\n}\n\nconst CREATED_INDICES_KEY: Record<\"assignment\" | \"worksheet\" | \"section\", string> = {\n assignment: \"assignments\",\n worksheet: \"worksheets\",\n section: \"sections\",\n};\n\nconst MARK_SUGGESTION_MAX_RETRIES = 5;\n\n/** Mark an AI-suggested item as created. Stores in message meta for fast reads. */\nexport async function markSuggestionCreated(\n userId: string,\n input: {\n messageId: string;\n type: \"assignment\" | \"worksheet\" | \"section\";\n index: number;\n }\n) {\n const { messageId, type, index } = input;\n\n const existingMessage = await findMessageByIdMinimal(messageId);\n if (!existingMessage) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Message not found\",\n });\n }\n\n const membership = await findConversationMembership(\n existingMessage.conversationId,\n userId\n );\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n const conversationId = existingMessage.conversationId;\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt < MARK_SUGGESTION_MAX_RETRIES; attempt++) {\n const msg = await prisma.message.findUnique({\n where: { id: messageId },\n select: { meta: true },\n });\n if (!msg) {\n throw new TRPCError({\n code: \"NOT_FOUND\",\n message: \"Message not found\",\n });\n }\n\n const currentMeta = (msg.meta as Record<string, unknown>) ?? {};\n const createdIndices = (currentMeta.createdIndices as Record<string, number[]>) ?? {};\n const typeIndices = createdIndices[CREATED_INDICES_KEY[type]] ?? [];\n if (typeIndices.includes(index)) return { success: true };\n\n const newTypeIndices = [...typeIndices, index].sort((a, b) => a - b);\n const newMeta = {\n ...currentMeta,\n createdIndices: {\n ...createdIndices,\n [CREATED_INDICES_KEY[type]]: newTypeIndices,\n },\n };\n\n const newMetaJson = JSON.stringify(newMeta);\n const currentMetaJson = msg.meta === null ? null : JSON.stringify(msg.meta);\n\n const updatedCount =\n currentMetaJson === null\n ? await prisma.$executeRaw`\n UPDATE \"Message\" SET meta = ${newMetaJson}::jsonb\n WHERE id = ${messageId} AND meta IS NULL\n `\n : await prisma.$executeRaw`\n UPDATE \"Message\" SET meta = ${newMetaJson}::jsonb\n WHERE id = ${messageId} AND meta = ${currentMetaJson}::jsonb\n `;\n\n if (Number(updatedCount) > 0) {\n const updated = await prisma.message.findUnique({\n where: { id: messageId },\n include: {\n sender: {\n select: {\n id: true,\n username: true,\n profile: {\n select: { displayName: true, profilePicture: true },\n },\n },\n },\n attachments: { select: { id: true, name: true, type: true } },\n mentions: { select: { userId: true } },\n },\n });\n\n if (updated) {\n const mentionedUserIds = updated.mentions.map((m) => m.userId);\n try {\n await pusher.trigger(\n chatChannel(conversationId),\n \"message-updated\",\n {\n id: updated.id,\n content: updated.content,\n senderId: updated.senderId,\n conversationId: updated.conversationId,\n createdAt: updated.createdAt,\n sender: updated.sender,\n attachments: updated.attachments ?? [],\n meta: newMeta,\n mentionedUserIds,\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast suggestion status via Pusher\", {\n error,\n messageId,\n });\n }\n }\n return { success: true };\n }\n\n lastError = new Error(\"Concurrent update conflict\");\n }\n\n logger.error(\"markSuggestionCreated failed after retries\", {\n messageId,\n type,\n index,\n error: lastError,\n });\n throw new TRPCError({\n code: \"CONFLICT\",\n message: \"Failed to update suggestion status after retries due to concurrent updates\",\n });\n}\n\nexport async function markAsRead(userId: string, conversationId: string) {\n const membership = await findConversationMembership(conversationId, userId);\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n await prisma.conversationMember.update({\n where: { id: membership.id },\n data: { lastViewedAt: new Date() },\n });\n\n try {\n await pusher.trigger(\n chatChannel(conversationId),\n \"conversation-viewed\",\n {\n userId,\n viewedAt: new Date(),\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast conversation-viewed via Pusher\", {\n error,\n conversationId,\n });\n }\n\n return { success: true };\n}\n\nexport async function markMentionsAsRead(\n userId: string,\n conversationId: string\n) {\n const membership = await findConversationMembership(conversationId, userId);\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n await prisma.conversationMember.update({\n where: { id: membership.id },\n data: { lastViewedMentionAt: new Date() },\n });\n\n try {\n await pusher.trigger(\n chatChannel(conversationId),\n \"mentions-viewed\",\n {\n userId,\n viewedAt: new Date(),\n }\n );\n } catch (error) {\n logger.error(\"Failed to broadcast mentions-viewed via Pusher\", {\n error,\n conversationId,\n });\n }\n\n return { success: true };\n}\n\nexport async function getUnreadCount(\n userId: string,\n conversationId: string\n) {\n const membership = await findConversationMembership(conversationId, userId);\n if (!membership) {\n throw new TRPCError({\n code: \"FORBIDDEN\",\n message: \"Not a member of this conversation\",\n });\n }\n\n const unreadCount = await countUnreadMessages(\n conversationId,\n userId,\n membership.lastViewedAt ?? undefined\n );\n\n const mentionCutoffTime =\n membership.lastViewedMentionAt && membership.lastViewedAt\n ? membership.lastViewedMentionAt > membership.lastViewedAt\n ? membership.lastViewedMentionAt\n : membership.lastViewedAt\n : membership.lastViewedMentionAt ?? membership.lastViewedAt;\n\n const unreadMentionCount = await countUnreadMentions(\n conversationId,\n userId,\n mentionCutoffTime ?? undefined\n );\n\n return { unreadCount, unreadMentionCount };\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,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACZ,wBAAwB,EACxB,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAE9B,oEAAoE;AACpE,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAc,EACd,KAIC;IAED,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAEhD,MAAM,UAAU,GAAG,MAAM,0BAA0B,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAC5E,IAAI,CA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AC,UAAU,CAAC,mBAAmB;YAChC,CAAC,CAAC,UAAU,CAAC,YAAY;QAC3B,CAAC,CAAC,UAAU,CAAC,mBAAmB,IAAI,UAAU,CAAC,YAAY,CAAC;IAEhE,MAAM,kBAAkB,GAAG,MAAM,mBAAmB,CAClD,cAAc,EACd,MAAM,EACN,iBAAiB,IAAI,SAAS,CAC/B,CAAC;IAEF,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;AAC7C,CAAC","debug_id":"34cd10db-4918-5874-bb52-7749bd2796dd"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
type ProgressChatMessage = {
|
|
2
|
+
role: "user" | "assistant";
|
|
3
|
+
content: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function getStudentProgressRecommendations(viewerId: string, classId: string, studentId: string): Promise<{
|
|
6
|
+
student: {
|
|
7
|
+
id: string;
|
|
8
|
+
username: string;
|
|
9
|
+
displayName: string;
|
|
10
|
+
};
|
|
11
|
+
summary: {
|
|
12
|
+
overallGrade: number | null;
|
|
13
|
+
trend: number;
|
|
14
|
+
completedAssignments: number;
|
|
15
|
+
totalAssignments: number;
|
|
16
|
+
missingCount: number;
|
|
17
|
+
lowScoreCount: number;
|
|
18
|
+
};
|
|
19
|
+
recommendations: {
|
|
20
|
+
assignmentId: string;
|
|
21
|
+
submissionId: string;
|
|
22
|
+
title: string;
|
|
23
|
+
type: import(".prisma/client").$Enums.AssignmentType;
|
|
24
|
+
sectionName: string | null;
|
|
25
|
+
dueDate: Date;
|
|
26
|
+
gradeReceived: number | null;
|
|
27
|
+
maxGrade: number | null;
|
|
28
|
+
percentage: number | null;
|
|
29
|
+
submitted: boolean;
|
|
30
|
+
returned: boolean;
|
|
31
|
+
reasons: string[];
|
|
32
|
+
}[];
|
|
33
|
+
nextSteps: string[];
|
|
34
|
+
}>;
|
|
35
|
+
export declare function chatAboutStudentProgress(viewerId: string, input: {
|
|
36
|
+
classId: string;
|
|
37
|
+
studentId: string;
|
|
38
|
+
message: string;
|
|
39
|
+
history?: ProgressChatMessage[];
|
|
40
|
+
}): Promise<{
|
|
41
|
+
message: string;
|
|
42
|
+
isFallback: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=studentProgress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studentProgress.d.ts","sourceRoot":"/","sources":["services/studentProgress.ts"],"names":[],"mappings":"AAUA,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AA2IF,wBAAsB,iCAAiC,CACrD,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoHlB;AAgBD,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE;IACL,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACjC;;;GA+FF"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Student progress service - assignment recommendations and progress chat.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
!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]="e4b426af-1ccd-5152-a996-9a03a09b6503")}catch(e){}}();
|
|
6
|
+
import { TRPCError } from "@trpc/server";
|
|
7
|
+
import { prisma } from "../lib/prisma.js";
|
|
8
|
+
import { inference } from "../utils/inference.js";
|
|
9
|
+
import { logger } from "../utils/logger.js";
|
|
10
|
+
import { isTeacherInClass } from "../models/class.js";
|
|
11
|
+
function calculatePercentage(submission) {
|
|
12
|
+
if (submission.gradeReceived == null || !submission.assignment.maxGrade)
|
|
13
|
+
return null;
|
|
14
|
+
return (Math.round((submission.gradeReceived / submission.assignment.maxGrade) * 1000) / 10);
|
|
15
|
+
}
|
|
16
|
+
function calculateTrend(submissions) {
|
|
17
|
+
const graded = submissions
|
|
18
|
+
.filter((submission) => submission.gradeReceived != null && submission.assignment.maxGrade)
|
|
19
|
+
.sort((a, b) => {
|
|
20
|
+
const aTime = a.submittedAt?.getTime() ?? a.assignment.dueDate.getTime();
|
|
21
|
+
const bTime = b.submittedAt?.getTime() ?? b.assignment.dueDate.getTime();
|
|
22
|
+
return aTime - bTime;
|
|
23
|
+
})
|
|
24
|
+
.map((submission) => calculatePercentage(submission))
|
|
25
|
+
.filter((value) => value != null);
|
|
26
|
+
if (graded.length < 2)
|
|
27
|
+
return 0;
|
|
28
|
+
const midpoint = Math.floor(graded.length / 2);
|
|
29
|
+
const first = graded.slice(0, midpoint);
|
|
30
|
+
const second = graded.slice(midpoint);
|
|
31
|
+
const average = (values) => values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
32
|
+
return Math.round((average(second) - average(first)) * 10) / 10;
|
|
33
|
+
}
|
|
34
|
+
function getOverallGrade(submissions) {
|
|
35
|
+
let totalWeighted = 0;
|
|
36
|
+
let totalWeight = 0;
|
|
37
|
+
for (const submission of submissions) {
|
|
38
|
+
if (submission.gradeReceived != null &&
|
|
39
|
+
submission.assignment.maxGrade &&
|
|
40
|
+
submission.assignment.weight) {
|
|
41
|
+
totalWeighted +=
|
|
42
|
+
(submission.gradeReceived / submission.assignment.maxGrade) *
|
|
43
|
+
submission.assignment.weight;
|
|
44
|
+
totalWeight += submission.assignment.weight;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return totalWeight > 0
|
|
48
|
+
? Math.round((totalWeighted / totalWeight) * 1000) / 10
|
|
49
|
+
: null;
|
|
50
|
+
}
|
|
51
|
+
async function loadStudentProgressContext(viewerId, classId, studentId) {
|
|
52
|
+
const isTeacher = await isTeacherInClass(classId, viewerId);
|
|
53
|
+
if (viewerId !== studentId && !isTeacher) {
|
|
54
|
+
throw new TRPCError({
|
|
55
|
+
code: "UNAUTHORIZED",
|
|
56
|
+
message: "You can only view your own progress",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const [classData, student, submissions] = await Promise.all([
|
|
60
|
+
prisma.class.findUnique({
|
|
61
|
+
where: { id: classId },
|
|
62
|
+
select: { id: true, name: true, subject: true },
|
|
63
|
+
}),
|
|
64
|
+
prisma.user.findFirst({
|
|
65
|
+
where: {
|
|
66
|
+
id: studentId,
|
|
67
|
+
studentIn: { some: { id: classId } },
|
|
68
|
+
},
|
|
69
|
+
select: {
|
|
70
|
+
id: true,
|
|
71
|
+
username: true,
|
|
72
|
+
profile: { select: { displayName: true } },
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
prisma.submission.findMany({
|
|
76
|
+
where: {
|
|
77
|
+
studentId,
|
|
78
|
+
assignment: { classId, graded: true },
|
|
79
|
+
},
|
|
80
|
+
include: {
|
|
81
|
+
assignment: {
|
|
82
|
+
select: {
|
|
83
|
+
id: true,
|
|
84
|
+
title: true,
|
|
85
|
+
dueDate: true,
|
|
86
|
+
maxGrade: true,
|
|
87
|
+
weight: true,
|
|
88
|
+
type: true,
|
|
89
|
+
section: { select: { id: true, name: true } },
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
orderBy: { assignment: { dueDate: "asc" } },
|
|
94
|
+
}),
|
|
95
|
+
]);
|
|
96
|
+
if (!classData) {
|
|
97
|
+
throw new TRPCError({ code: "NOT_FOUND", message: "Class not found" });
|
|
98
|
+
}
|
|
99
|
+
if (!student) {
|
|
100
|
+
throw new TRPCError({
|
|
101
|
+
code: "NOT_FOUND",
|
|
102
|
+
message: "Student not found in this class",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return { classData, student, submissions };
|
|
106
|
+
}
|
|
107
|
+
export async function getStudentProgressRecommendations(viewerId, classId, studentId) {
|
|
108
|
+
const { student, submissions } = await loadStudentProgressContext(viewerId, classId, studentId);
|
|
109
|
+
const now = new Date();
|
|
110
|
+
const recommendationCandidates = submissions
|
|
111
|
+
.map((submission) => {
|
|
112
|
+
const percentage = calculatePercentage(submission);
|
|
113
|
+
const isMissing = !submission.submitted &&
|
|
114
|
+
submission.assignment.dueDate.getTime() < now.getTime();
|
|
115
|
+
const isLowScore = percentage != null && percentage < 70;
|
|
116
|
+
const isUnreturned = Boolean(submission.submitted) &&
|
|
117
|
+
submission.gradeReceived == null &&
|
|
118
|
+
!submission.returned;
|
|
119
|
+
const isUpcoming = !Boolean(submission.submitted) &&
|
|
120
|
+
!submission.submittedAt &&
|
|
121
|
+
!submission.returned &&
|
|
122
|
+
submission.gradeReceived == null &&
|
|
123
|
+
submission.assignment.dueDate.getTime() >= now.getTime();
|
|
124
|
+
const reasons = [];
|
|
125
|
+
let priorityScore = 0;
|
|
126
|
+
if (isMissing) {
|
|
127
|
+
reasons.push("Missing past-due work");
|
|
128
|
+
priorityScore += 100;
|
|
129
|
+
}
|
|
130
|
+
if (isLowScore) {
|
|
131
|
+
reasons.push(`Scored ${percentage}%`);
|
|
132
|
+
priorityScore += 85 - (percentage ?? 0);
|
|
133
|
+
}
|
|
134
|
+
if (isUnreturned) {
|
|
135
|
+
reasons.push("Awaiting grade or feedback");
|
|
136
|
+
priorityScore += 15;
|
|
137
|
+
}
|
|
138
|
+
if (isUpcoming) {
|
|
139
|
+
reasons.push("Upcoming graded assignment");
|
|
140
|
+
priorityScore += 5;
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
assignmentId: submission.assignment.id,
|
|
144
|
+
submissionId: submission.id,
|
|
145
|
+
title: submission.assignment.title,
|
|
146
|
+
type: submission.assignment.type,
|
|
147
|
+
sectionName: submission.assignment.section?.name ?? null,
|
|
148
|
+
dueDate: submission.assignment.dueDate,
|
|
149
|
+
gradeReceived: submission.gradeReceived,
|
|
150
|
+
maxGrade: submission.assignment.maxGrade,
|
|
151
|
+
percentage,
|
|
152
|
+
submitted: Boolean(submission.submitted),
|
|
153
|
+
returned: Boolean(submission.returned),
|
|
154
|
+
reasons,
|
|
155
|
+
priorityScore,
|
|
156
|
+
};
|
|
157
|
+
})
|
|
158
|
+
.filter((candidate) => candidate.priorityScore > 0)
|
|
159
|
+
.sort((a, b) => b.priorityScore - a.priorityScore)
|
|
160
|
+
.slice(0, 5);
|
|
161
|
+
const gradedPercentages = submissions
|
|
162
|
+
.map(calculatePercentage)
|
|
163
|
+
.filter((value) => value != null);
|
|
164
|
+
const lowScoreCount = gradedPercentages.filter((percentage) => percentage < 70).length;
|
|
165
|
+
const missingCount = submissions.filter((submission) => !submission.submitted &&
|
|
166
|
+
submission.assignment.dueDate.getTime() < now.getTime()).length;
|
|
167
|
+
const trend = calculateTrend(submissions);
|
|
168
|
+
const overallGrade = getOverallGrade(submissions);
|
|
169
|
+
const nextSteps = [
|
|
170
|
+
missingCount > 0
|
|
171
|
+
? `Prioritize ${missingCount} missing assignment${missingCount === 1 ? "" : "s"}.`
|
|
172
|
+
: null,
|
|
173
|
+
lowScoreCount > 0
|
|
174
|
+
? `Review ${lowScoreCount} low-scoring assignment${lowScoreCount === 1 ? "" : "s"} before introducing new material.`
|
|
175
|
+
: null,
|
|
176
|
+
trend < -5
|
|
177
|
+
? "Schedule a check-in because recent performance is trending down."
|
|
178
|
+
: null,
|
|
179
|
+
recommendationCandidates.length === 0
|
|
180
|
+
? "No urgent assignment issues detected from the available grades."
|
|
181
|
+
: null,
|
|
182
|
+
].filter((step) => Boolean(step));
|
|
183
|
+
return {
|
|
184
|
+
student: {
|
|
185
|
+
id: student.id,
|
|
186
|
+
username: student.username,
|
|
187
|
+
displayName: student.profile?.displayName ?? student.username,
|
|
188
|
+
},
|
|
189
|
+
summary: {
|
|
190
|
+
overallGrade,
|
|
191
|
+
trend,
|
|
192
|
+
completedAssignments: submissions.filter((submission) => Boolean(submission.submitted)).length,
|
|
193
|
+
totalAssignments: submissions.length,
|
|
194
|
+
missingCount,
|
|
195
|
+
lowScoreCount,
|
|
196
|
+
},
|
|
197
|
+
recommendations: recommendationCandidates.map(({ priorityScore, ...candidate }) => candidate),
|
|
198
|
+
nextSteps,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function buildProgressSummary(submissions) {
|
|
202
|
+
return submissions.map((submission) => ({
|
|
203
|
+
title: submission.assignment.title,
|
|
204
|
+
type: submission.assignment.type,
|
|
205
|
+
dueDate: submission.assignment.dueDate.toISOString(),
|
|
206
|
+
submitted: Boolean(submission.submitted),
|
|
207
|
+
returned: Boolean(submission.returned),
|
|
208
|
+
gradeReceived: submission.gradeReceived,
|
|
209
|
+
maxGrade: submission.assignment.maxGrade,
|
|
210
|
+
percentage: calculatePercentage(submission),
|
|
211
|
+
section: submission.assignment.section?.name ?? null,
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
export async function chatAboutStudentProgress(viewerId, input) {
|
|
215
|
+
const { classData, student, submissions } = await loadStudentProgressContext(viewerId, input.classId, input.studentId);
|
|
216
|
+
const displayName = student.profile?.displayName ?? student.username;
|
|
217
|
+
const summary = {
|
|
218
|
+
overallGrade: getOverallGrade(submissions),
|
|
219
|
+
trend: calculateTrend(submissions),
|
|
220
|
+
assignments: buildProgressSummary(submissions),
|
|
221
|
+
};
|
|
222
|
+
const messages = [
|
|
223
|
+
{
|
|
224
|
+
role: "system",
|
|
225
|
+
content: "You are an educational progress assistant for teachers and students. Use only the provided class and grade context. Be concise, specific, supportive, and avoid fabricating grades or assignments.",
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
role: "user",
|
|
229
|
+
content: JSON.stringify({
|
|
230
|
+
class: classData,
|
|
231
|
+
student: { id: student.id, username: student.username, displayName },
|
|
232
|
+
progress: summary,
|
|
233
|
+
}),
|
|
234
|
+
},
|
|
235
|
+
...(input.history ?? []).slice(-8).map((message) => ({
|
|
236
|
+
role: message.role,
|
|
237
|
+
content: message.content,
|
|
238
|
+
})),
|
|
239
|
+
{ role: "user", content: input.message },
|
|
240
|
+
];
|
|
241
|
+
try {
|
|
242
|
+
const response = await inference(messages);
|
|
243
|
+
if (typeof response !== "string" || response.trim().length === 0) {
|
|
244
|
+
throw new Error("Student progress chat returned an empty response");
|
|
245
|
+
}
|
|
246
|
+
return { message: response, isFallback: false };
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
logger.error("Failed to generate student progress chat response", {
|
|
250
|
+
error,
|
|
251
|
+
classId: input.classId,
|
|
252
|
+
studentId: input.studentId,
|
|
253
|
+
});
|
|
254
|
+
const overall = summary.overallGrade == null
|
|
255
|
+
? "not enough graded work"
|
|
256
|
+
: `${summary.overallGrade}%`;
|
|
257
|
+
const missingItems = summary.assignments.filter((assignment) => !assignment.submitted &&
|
|
258
|
+
new Date(assignment.dueDate).getTime() < Date.now()).length;
|
|
259
|
+
const lowScores = summary.assignments.filter((assignment) => assignment.percentage != null && assignment.percentage < 70).length;
|
|
260
|
+
const awaitingFeedback = summary.assignments.filter((assignment) => assignment.submitted &&
|
|
261
|
+
assignment.gradeReceived == null &&
|
|
262
|
+
!assignment.returned).length;
|
|
263
|
+
const trendLabel = summary.overallGrade == null
|
|
264
|
+
? "not enough graded work to determine a recent trend"
|
|
265
|
+
: summary.trend > 5
|
|
266
|
+
? "improving"
|
|
267
|
+
: summary.trend < -5
|
|
268
|
+
? "declining"
|
|
269
|
+
: "stable";
|
|
270
|
+
const advice = [
|
|
271
|
+
missingItems > 0
|
|
272
|
+
? `Review ${missingItems} missing assignment${missingItems === 1 ? "" : "s"}.`
|
|
273
|
+
: null,
|
|
274
|
+
lowScores > 0
|
|
275
|
+
? `Use targeted practice for ${lowScores} low-scoring assignment${lowScores === 1 ? "" : "s"}.`
|
|
276
|
+
: null,
|
|
277
|
+
awaitingFeedback > 0
|
|
278
|
+
? `Check back after feedback is returned for ${awaitingFeedback} submitted assignment${awaitingFeedback === 1 ? "" : "s"}.`
|
|
279
|
+
: null,
|
|
280
|
+
missingItems === 0 && lowScores === 0 && awaitingFeedback === 0
|
|
281
|
+
? "Check upcoming work and ask for feedback as new grades are returned."
|
|
282
|
+
: null,
|
|
283
|
+
].filter((item) => Boolean(item));
|
|
284
|
+
return {
|
|
285
|
+
message: `${displayName}'s current overall progress is ${overall}, with ${trendLabel}. ${advice.join(" ")}`,
|
|
286
|
+
isFallback: true,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=studentProgress.js.map
|
|
291
|
+
//# debugId=e4b426af-1ccd-5152-a996-9a03a09b6503
|