@studious-lms/server 1.2.46 → 1.2.48
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/index.js +22 -18
- package/dist/index.js.map +1 -1
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +3 -2
- package/dist/middleware/auth.js.map +1 -1
- package/dist/middleware/security.d.ts.map +1 -1
- package/dist/middleware/security.js +4 -4
- package/dist/middleware/security.js.map +1 -1
- package/dist/routers/_app.d.ts +126 -26
- package/dist/routers/_app.d.ts.map +1 -1
- package/dist/routers/assignment.d.ts +10 -0
- package/dist/routers/assignment.d.ts.map +1 -1
- package/dist/routers/assignment.js +18 -3
- package/dist/routers/assignment.js.map +1 -1
- package/dist/routers/class.d.ts +18 -0
- package/dist/routers/class.d.ts.map +1 -1
- package/dist/routers/class.js +56 -2
- package/dist/routers/class.js.map +1 -1
- package/dist/routers/conversation.d.ts +1 -0
- package/dist/routers/conversation.d.ts.map +1 -1
- package/dist/routers/labChat.d.ts +1 -0
- package/dist/routers/labChat.d.ts.map +1 -1
- package/dist/routers/labChat.js +5 -321
- package/dist/routers/labChat.js.map +1 -1
- package/dist/routers/message.d.ts +1 -0
- package/dist/routers/message.d.ts.map +1 -1
- package/dist/routers/message.js +3 -2
- package/dist/routers/message.js.map +1 -1
- package/dist/routers/newtonChat.d.ts.map +1 -1
- package/dist/routers/newtonChat.js +6 -183
- package/dist/routers/newtonChat.js.map +1 -1
- package/dist/routers/section.d.ts +10 -0
- package/dist/routers/section.d.ts.map +1 -1
- package/dist/routers/section.js +21 -3
- package/dist/routers/section.js.map +1 -1
- package/dist/routers/worksheet.d.ts +22 -13
- package/dist/routers/worksheet.d.ts.map +1 -1
- package/dist/routers/worksheet.js +16 -3
- package/dist/routers/worksheet.js.map +1 -1
- package/dist/seedDatabase.d.ts.map +1 -1
- package/dist/seedDatabase.js +34 -8
- package/dist/seedDatabase.js.map +1 -1
- package/dist/server/pipelines/aiLabChat.d.ts +12 -1
- package/dist/server/pipelines/aiLabChat.d.ts.map +1 -1
- package/dist/server/pipelines/aiLabChat.js +388 -15
- package/dist/server/pipelines/aiLabChat.js.map +1 -1
- package/dist/server/pipelines/aiNewtonChat.d.ts +30 -0
- package/dist/server/pipelines/aiNewtonChat.d.ts.map +1 -0
- package/dist/server/pipelines/aiNewtonChat.js +280 -0
- package/dist/server/pipelines/aiNewtonChat.js.map +1 -0
- package/dist/server/pipelines/gradeWorksheet.d.ts +14 -1
- package/dist/server/pipelines/gradeWorksheet.d.ts.map +1 -1
- package/dist/server/pipelines/gradeWorksheet.js +6 -5
- package/dist/server/pipelines/gradeWorksheet.js.map +1 -1
- package/dist/utils/inference.d.ts +3 -1
- package/dist/utils/inference.d.ts.map +1 -1
- package/dist/utils/inference.js +34 -4
- package/dist/utils/inference.js.map +1 -1
- package/package.json +1 -1
- package/prisma/schema.prisma +2 -0
- package/src/index.ts +24 -22
- package/src/middleware/auth.ts +1 -0
- package/src/middleware/security.ts +2 -2
- package/src/routers/assignment.ts +17 -2
- package/src/routers/class.ts +55 -0
- package/src/routers/labChat.ts +3 -366
- package/src/routers/message.ts +1 -1
- package/src/routers/newtonChat.ts +8 -231
- package/src/routers/section.ts +21 -1
- package/src/routers/worksheet.ts +17 -1
- package/src/seedDatabase.ts +38 -6
- package/src/server/pipelines/aiLabChat.ts +434 -19
- package/src/server/pipelines/aiNewtonChat.ts +338 -0
- package/src/server/pipelines/gradeWorksheet.ts +3 -4
- package/src/utils/inference.ts +40 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sources":["routers/message.ts"],"sourceRoot":"/","sourcesContent":["import { z } from 'zod';\nimport { createTRPCRouter, protectedProcedure } from '../trpc.js';\nimport { prisma } from '../lib/prisma.js';\nimport { pusher } from '../lib/pusher.js';\nimport { TRPCError } from '@trpc/server';\nimport { logger } from '../utils/logger.js';\n\nexport const messageRouter = createTRPCRouter({\n list: protectedProcedure\n .input(\n z.object({\n conversationId: z.string(),\n cursor: z.string().optional(),\n limit: z.number().min(1).max(100).default(50),\n })\n )\n .query(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { conversationId, cursor, limit } = input;\n\n // Verify user is a member of the conversation\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId,\n userId,\n },\n });\n\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 prisma.message.findMany({\n where: {\n conversationId,\n ...(cursor && {\n createdAt: {\n lt: new Date(cursor),\n },\n }),\n },\n include: {\n attachments: {\n select: {\n id: true,\n name: true,\n type: true,\n },\n },\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 mentions: {\n include: {\n user: {\n select: {\n id: true,\n username: true,\n profile: {\n select: {\n displayName: true,\n },\n },\n },\n },\n },\n },\n },\n orderBy: {\n createdAt: 'desc',\n },\n take: limit + 1,\n });\n\n let nextCursor: string | undefined = 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((attachment) => ({\n id: attachment.id,\n name: attachment.name,\n type: attachment.type,\n })),\n mentions: message.mentions.map((mention) => ({\n user: mention.user,\n })),\n mentionsMe: message.mentions.some((mention) => mention.userId === userId),\n })),\n nextCursor,\n };\n }),\n\n send: protectedProcedure\n .input(\n z.object({\n conversationId: z.string(),\n content: z.string().min(1).max(4000),\n mentionedUserIds: z.array(z.string()).optional(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { conversationId, content, mentionedUserIds = [] } = input;\n\n // Verify user is a member of the conversation\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Verify mentioned users are members of the conversation\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await prisma.conversationMember.findMany({\n where: {\n conversationId,\n userId: { in: mentionedUserIds },\n },\n });\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 // Create message, mentions, and update conversation timestamp\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 },\n });\n\n // Create mentions\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 // Update conversation timestamp\n await tx.conversation.update({\n where: { id: conversationId },\n data: { updatedAt: new Date() },\n });\n\n return message;\n });\n\n // Broadcast to Pusher channel\n try {\n await pusher.trigger(`conversation-${conversationId}`, 'new-message', {\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 } catch (error) {\n logger.error('Failed to broadcast message:', {error});\n // Don't fail the request if Pusher fails\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 update: protectedProcedure\n .input(\n z.object({\n messageId: z.string(),\n content: z.string().min(1).max(4000),\n mentionedUserIds: z.array(z.string()).optional(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { messageId, content, mentionedUserIds = [] } = input;\n\n // Get the existing message and verify user is the sender\n const existingMessage = await prisma.message.findUnique({\n where: { id: messageId },\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 (!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 // Verify user is still a member of the conversation\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId: existingMessage.conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Verify mentioned users are members of the conversation\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await prisma.conversationMember.findMany({\n where: {\n conversationId: existingMessage.conversationId,\n userId: { in: mentionedUserIds },\n },\n });\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 // Update message and mentions in transaction\n const updatedMessage = await prisma.$transaction(async (tx) => {\n // Update the message content\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 },\n });\n\n // Delete existing mentions\n await tx.mention.deleteMany({\n where: { messageId },\n });\n\n // Create new mentions if any\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 // Broadcast message update to Pusher\n try {\n await pusher.trigger(`conversation-${existingMessage.conversationId}`, 'message-updated', {\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 } catch (error) {\n logger.error('Failed to broadcast message update:', {error});\n // Don't fail the request if Pusher fails\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\n delete: protectedProcedure\n .input(\n z.object({\n messageId: z.string(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { messageId } = input;\n\n // Get the message and verify user is the sender\n const existingMessage = await prisma.message.findUnique({\n where: { id: messageId },\n include: {\n sender: {\n select: {\n id: true,\n username: true,\n },\n },\n },\n });\n\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 // Verify user is still a member of the conversation\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId: existingMessage.conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Delete message and all related mentions in transaction\n await prisma.$transaction(async (tx) => {\n // Delete mentions first (due to foreign key constraint)\n await tx.mention.deleteMany({\n where: { messageId },\n });\n\n // Delete the message\n await tx.message.delete({\n where: { id: messageId },\n });\n });\n\n // Broadcast message deletion to Pusher\n try {\n await pusher.trigger(`conversation-${existingMessage.conversationId}`, 'message-deleted', {\n messageId,\n conversationId: existingMessage.conversationId,\n senderId: existingMessage.senderId,\n });\n } catch (error) {\n logger.error('Failed to broadcast message deletion:', {error});\n // Don't fail the request if Pusher fails\n }\n\n return {\n success: true,\n messageId,\n };\n }),\n markAsRead: protectedProcedure\n .input(\n z.object({\n conversationId: z.string(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { conversationId } = input;\n\n // Verify user is a member of the conversation and update lastViewedAt\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Update the user's lastViewedAt timestamp for this conversation\n await prisma.conversationMember.update({\n where: {\n id: membership.id,\n },\n data: {\n lastViewedAt: new Date(),\n },\n });\n\n // Broadcast that user has viewed the conversation\n try {\n await pusher.trigger(`conversation-${conversationId}`, 'conversation-viewed', {\n userId,\n viewedAt: new Date(),\n });\n } catch (error) {\n logger.error('Failed to broadcast conversation view:', {error});\n // Don't fail the request if Pusher fails\n }\n\n return { success: true };\n }),\n\n markMentionsAsRead: protectedProcedure\n .input(\n z.object({\n conversationId: z.string(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { conversationId } = input;\n\n // Verify user is a member of the conversation and update lastViewedMentionAt\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Update the user's lastViewedMentionAt timestamp for this conversation\n await prisma.conversationMember.update({\n where: {\n id: membership.id,\n },\n data: {\n lastViewedMentionAt: new Date(),\n },\n });\n\n // Broadcast that user has viewed mentions\n try {\n await pusher.trigger(`conversation-${conversationId}`, 'mentions-viewed', {\n userId,\n viewedAt: new Date(),\n });\n } catch (error) {\n logger.error('Failed to broadcast mentions view:', {error});\n // Don't fail the request if Pusher fails\n }\n\n return { success: true };\n }),\n\n getUnreadCount: protectedProcedure\n .input(z.object({ conversationId: z.string() }))\n .query(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { conversationId } = input;\n\n // Get user's membership with lastViewedAt and lastViewedMentionAt\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Count regular unread messages\n const unreadCount = await prisma.message.count({\n where: {\n conversationId,\n senderId: { not: userId },\n ...(membership.lastViewedAt && {\n createdAt: { gt: membership.lastViewedAt }\n }),\n },\n });\n\n // Count unread mentions\n // Use the later of lastViewedAt or lastViewedMentionAt\n // This means if user viewed conversation after mention, mention is considered read\n const mentionCutoffTime = membership.lastViewedMentionAt && membership.lastViewedAt \n ? (membership.lastViewedMentionAt > membership.lastViewedAt ? membership.lastViewedMentionAt : membership.lastViewedAt)\n : (membership.lastViewedMentionAt || membership.lastViewedAt);\n \n const unreadMentionCount = await prisma.mention.count({\n where: {\n userId,\n message: {\n conversationId,\n senderId: { not: userId },\n ...(mentionCutoffTime && {\n createdAt: { gt: mentionCutoffTime }\n }),\n },\n },\n });\n\n return { \n unreadCount, \n unreadMentionCount \n };\n }),\n});\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC;IAC5C,IAAI,EAAE,kBAAkB;SACrB,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;QACP,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;QAC1B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC7B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;KAC9C,CAAC,CACH;SACA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AG,UAAU,CAAC,mBAAmB,IAAI,UAAU,CAAC,YAAY;YACjF,CAAC,CAAC,CAAC,UAAU,CAAC,mBAAmB,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC;YACvH,CAAC,CAAC,CAAC,UAAU,CAAC,mBAAmB,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;QAEhE,MAAM,kBAAkB,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YACpD,KAAK,EAAE;gBACL,MAAM;gBACN,OAAO,EAAE;oBACP,cAAc;oBACd,QAAQ,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE;oBACzB,GAAG,CAAC,iBAAiB,IAAI;wBACvB,SAAS,EAAE,EAAE,EAAE,EAAE,iBAAiB,EAAE;qBACrC,CAAC;iBACH;aACF;SACF,CAAC,CAAC;QAEH,OAAO;YACL,WAAW;YACX,kBAAkB;SACnB,CAAC;IACJ,CAAC,CAAC;CACL,CAAC,CAAC","debug_id":"e87ffb37-b6d4-561f-b90e-225fc519823a"}
|
|
1
|
+
{"version":3,"file":"message.js","sources":["routers/message.ts"],"sourceRoot":"/","sourcesContent":["import { z } from 'zod';\nimport { createTRPCRouter, protectedProcedure } from '../trpc.js';\nimport { prisma } from '../lib/prisma.js';\nimport { pusher } from '../lib/pusher.js';\nimport { TRPCError } from '@trpc/server';\nimport { logger } from '../utils/logger.js';\n\nexport const messageRouter = createTRPCRouter({\n list: protectedProcedure\n .input(\n z.object({\n conversationId: z.string(),\n cursor: z.string().optional(),\n limit: z.number().min(1).max(100).default(50),\n })\n )\n .query(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { conversationId, cursor, limit } = input;\n\n // Verify user is a member of the conversation\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId,\n userId,\n },\n });\n\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 prisma.message.findMany({\n where: {\n conversationId,\n ...(cursor && {\n createdAt: {\n lt: new Date(cursor),\n },\n }),\n },\n include: {\n attachments: {\n select: {\n id: true,\n name: true,\n type: true,\n },\n },\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 mentions: {\n include: {\n user: {\n select: {\n id: true,\n username: true,\n profile: {\n select: {\n displayName: true,\n },\n },\n },\n },\n },\n },\n },\n orderBy: {\n createdAt: 'desc',\n },\n take: limit + 1,\n });\n\n let nextCursor: string | undefined = 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((attachment) => ({\n id: attachment.id,\n name: attachment.name,\n type: attachment.type,\n })),\n meta: message.meta as Record<string, any>,\n mentions: message.mentions.map((mention) => ({\n user: mention.user,\n })),\n mentionsMe: message.mentions.some((mention) => mention.userId === userId),\n })),\n nextCursor,\n };\n }),\n send: protectedProcedure\n .input(\n z.object({\n conversationId: z.string(),\n content: z.string().min(1).max(4000),\n mentionedUserIds: z.array(z.string()).optional(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { conversationId, content, mentionedUserIds = [] } = input;\n\n // Verify user is a member of the conversation\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Verify mentioned users are members of the conversation\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await prisma.conversationMember.findMany({\n where: {\n conversationId,\n userId: { in: mentionedUserIds },\n },\n });\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 // Create message, mentions, and update conversation timestamp\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 },\n });\n\n // Create mentions\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 // Update conversation timestamp\n await tx.conversation.update({\n where: { id: conversationId },\n data: { updatedAt: new Date() },\n });\n\n return message;\n });\n\n // Broadcast to Pusher channel\n try {\n await pusher.trigger(`conversation-${conversationId}`, 'new-message', {\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 } catch (error) {\n logger.error('Failed to broadcast message:', {error});\n // Don't fail the request if Pusher fails\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 update: protectedProcedure\n .input(\n z.object({\n messageId: z.string(),\n content: z.string().min(1).max(4000),\n mentionedUserIds: z.array(z.string()).optional(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { messageId, content, mentionedUserIds = [] } = input;\n\n // Get the existing message and verify user is the sender\n const existingMessage = await prisma.message.findUnique({\n where: { id: messageId },\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 (!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 // Verify user is still a member of the conversation\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId: existingMessage.conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Verify mentioned users are members of the conversation\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await prisma.conversationMember.findMany({\n where: {\n conversationId: existingMessage.conversationId,\n userId: { in: mentionedUserIds },\n },\n });\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 // Update message and mentions in transaction\n const updatedMessage = await prisma.$transaction(async (tx) => {\n // Update the message content\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 },\n });\n\n // Delete existing mentions\n await tx.mention.deleteMany({\n where: { messageId },\n });\n\n // Create new mentions if any\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 // Broadcast message update to Pusher\n try {\n await pusher.trigger(`conversation-${existingMessage.conversationId}`, 'message-updated', {\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 } catch (error) {\n logger.error('Failed to broadcast message update:', {error});\n // Don't fail the request if Pusher fails\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\n delete: protectedProcedure\n .input(\n z.object({\n messageId: z.string(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { messageId } = input;\n\n // Get the message and verify user is the sender\n const existingMessage = await prisma.message.findUnique({\n where: { id: messageId },\n include: {\n sender: {\n select: {\n id: true,\n username: true,\n },\n },\n },\n });\n\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 // Verify user is still a member of the conversation\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId: existingMessage.conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Delete message and all related mentions in transaction\n await prisma.$transaction(async (tx) => {\n // Delete mentions first (due to foreign key constraint)\n await tx.mention.deleteMany({\n where: { messageId },\n });\n\n // Delete the message\n await tx.message.delete({\n where: { id: messageId },\n });\n });\n\n // Broadcast message deletion to Pusher\n try {\n await pusher.trigger(`conversation-${existingMessage.conversationId}`, 'message-deleted', {\n messageId,\n conversationId: existingMessage.conversationId,\n senderId: existingMessage.senderId,\n });\n } catch (error) {\n logger.error('Failed to broadcast message deletion:', {error});\n // Don't fail the request if Pusher fails\n }\n\n return {\n success: true,\n messageId,\n };\n }),\n markAsRead: protectedProcedure\n .input(\n z.object({\n conversationId: z.string(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { conversationId } = input;\n\n // Verify user is a member of the conversation and update lastViewedAt\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Update the user's lastViewedAt timestamp for this conversation\n await prisma.conversationMember.update({\n where: {\n id: membership.id,\n },\n data: {\n lastViewedAt: new Date(),\n },\n });\n\n // Broadcast that user has viewed the conversation\n try {\n await pusher.trigger(`conversation-${conversationId}`, 'conversation-viewed', {\n userId,\n viewedAt: new Date(),\n });\n } catch (error) {\n logger.error('Failed to broadcast conversation view:', {error});\n // Don't fail the request if Pusher fails\n }\n\n return { success: true };\n }),\n\n markMentionsAsRead: protectedProcedure\n .input(\n z.object({\n conversationId: z.string(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { conversationId } = input;\n\n // Verify user is a member of the conversation and update lastViewedMentionAt\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Update the user's lastViewedMentionAt timestamp for this conversation\n await prisma.conversationMember.update({\n where: {\n id: membership.id,\n },\n data: {\n lastViewedMentionAt: new Date(),\n },\n });\n\n // Broadcast that user has viewed mentions\n try {\n await pusher.trigger(`conversation-${conversationId}`, 'mentions-viewed', {\n userId,\n viewedAt: new Date(),\n });\n } catch (error) {\n logger.error('Failed to broadcast mentions view:', {error});\n // Don't fail the request if Pusher fails\n }\n\n return { success: true };\n }),\n\n getUnreadCount: protectedProcedure\n .input(z.object({ conversationId: z.string() }))\n .query(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { conversationId } = input;\n\n // Get user's membership with lastViewedAt and lastViewedMentionAt\n const membership = await prisma.conversationMember.findFirst({\n where: {\n conversationId,\n userId,\n },\n });\n\n if (!membership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a member of this conversation',\n });\n }\n\n // Count regular unread messages\n const unreadCount = await prisma.message.count({\n where: {\n conversationId,\n senderId: { not: userId },\n ...(membership.lastViewedAt && {\n createdAt: { gt: membership.lastViewedAt }\n }),\n },\n });\n\n // Count unread mentions\n // Use the later of lastViewedAt or lastViewedMentionAt\n // This means if user viewed conversation after mention, mention is considered read\n const mentionCutoffTime = membership.lastViewedMentionAt && membership.lastViewedAt \n ? (membership.lastViewedMentionAt > membership.lastViewedAt ? membership.lastViewedMentionAt : membership.lastViewedAt)\n : (membership.lastViewedMentionAt || membership.lastViewedAt);\n \n const unreadMentionCount = await prisma.mention.count({\n where: {\n userId,\n message: {\n conversationId,\n senderId: { not: userId },\n ...(mentionCutoffTime && {\n createdAt: { gt: mentionCutoffTime }\n }),\n },\n },\n });\n\n return { \n unreadCount, \n unreadMentionCount \n };\n }),\n});\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC;IAC5C,IAAI,EAAE,kBAAkB;SACrB,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;QACP,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;QAC1B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC7B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;KAC9C,CAAC,CACH;SACA,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,IAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QAEhD,8CAA8C;QAC9C,MAAM,UAAU,GA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,CAAC,CAAC,CAAC,UAAU,CAAC,mBAAmB,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;QAEhE,MAAM,kBAAkB,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YACpD,KAAK,EAAE;gBACL,MAAM;gBACN,OAAO,EAAE;oBACP,cAAc;oBACd,QAAQ,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE;oBACzB,GAAG,CAAC,iBAAiB,IAAI;wBACvB,SAAS,EAAE,EAAE,EAAE,EAAE,iBAAiB,EAAE;qBACrC,CAAC;iBACH;aACF;SACF,CAAC,CAAC;QAEH,OAAO;YACL,WAAW;YACX,kBAAkB;SACnB,CAAC;IACJ,CAAC,CAAC;CACL,CAAC,CAAC","debug_id":"5d4423a2-9e56-5193-8c62-5a133744ca99"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"newtonChat.d.ts","sourceRoot":"/","sources":["routers/newtonChat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"newtonChat.d.ts","sourceRoot":"/","sources":["routers/newtonChat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6R3B,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
|
-
!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]="
|
|
2
|
+
!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]="ce05ab9c-6259-5565-ad40-a8e2dd1beb79")}catch(e){}}();
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { createTRPCRouter, protectedProcedure } from '../trpc.js';
|
|
5
5
|
import { prisma } from '../lib/prisma.js';
|
|
6
6
|
import { pusher } from '../lib/pusher.js';
|
|
7
7
|
import { TRPCError } from '@trpc/server';
|
|
8
|
-
import { inferenceClient, openAIClient, sendAIMessage, } from '../utils/inference.js';
|
|
9
8
|
import { logger } from '../utils/logger.js';
|
|
10
9
|
import { isAIUser } from '../utils/aiUser.js';
|
|
10
|
+
import { generateAndSendNewtonIntroduction, generateAndSendNewtonResponse } from '../server/pipelines/aiNewtonChat.js';
|
|
11
11
|
export const newtonChatRouter = createTRPCRouter({
|
|
12
12
|
getTutorConversation: protectedProcedure
|
|
13
13
|
.input(z.object({
|
|
@@ -108,12 +108,11 @@ export const newtonChatRouter = createTRPCRouter({
|
|
|
108
108
|
title: 'Session with Newton Tutor',
|
|
109
109
|
},
|
|
110
110
|
});
|
|
111
|
+
generateAndSendNewtonIntroduction(newtonChat.id, newtonChat.conversationId, submission.id).catch(error => {
|
|
112
|
+
logger.error('Failed to generate AI introduction:', { error, newtonChatId: result.id });
|
|
113
|
+
});
|
|
111
114
|
return newtonChat;
|
|
112
115
|
});
|
|
113
|
-
// Generate AI introduction message in parallel (don't await - fire and forget)
|
|
114
|
-
generateAndSendNewtonIntroduction(result.id, result.conversationId, submission.id).catch(error => {
|
|
115
|
-
logger.error('Failed to generate AI introduction:', { error, newtonChatId: result.id });
|
|
116
|
-
});
|
|
117
116
|
return {
|
|
118
117
|
conversationId: result.conversationId,
|
|
119
118
|
newtonChatId: result.id,
|
|
@@ -258,181 +257,5 @@ export const newtonChatRouter = createTRPCRouter({
|
|
|
258
257
|
};
|
|
259
258
|
}),
|
|
260
259
|
});
|
|
261
|
-
/**
|
|
262
|
-
* Generate and send AI introduction for Newton chat
|
|
263
|
-
*/
|
|
264
|
-
async function generateAndSendNewtonIntroduction(newtonChatId, conversationId, submissionId) {
|
|
265
|
-
try {
|
|
266
|
-
// Get submission details for context
|
|
267
|
-
const submission = await prisma.submission.findUnique({
|
|
268
|
-
where: { id: submissionId },
|
|
269
|
-
include: {
|
|
270
|
-
assignment: {
|
|
271
|
-
select: {
|
|
272
|
-
title: true,
|
|
273
|
-
instructions: true,
|
|
274
|
-
class: {
|
|
275
|
-
select: {
|
|
276
|
-
subject: true,
|
|
277
|
-
name: true,
|
|
278
|
-
},
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
attachments: {
|
|
283
|
-
select: {
|
|
284
|
-
id: true,
|
|
285
|
-
name: true,
|
|
286
|
-
type: true,
|
|
287
|
-
},
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
});
|
|
291
|
-
if (!submission) {
|
|
292
|
-
throw new Error('Submission not found');
|
|
293
|
-
}
|
|
294
|
-
const systemPrompt = `You are Newton, an AI tutor helping a student with their assignment submission.
|
|
295
|
-
|
|
296
|
-
Assignment: ${submission.assignment.title}
|
|
297
|
-
Subject: ${submission.assignment.class.subject}
|
|
298
|
-
Instructions: ${submission.assignment.instructions || 'No specific instructions provided'}
|
|
299
|
-
|
|
300
|
-
Your role:
|
|
301
|
-
- Help the student understand concepts related to their assignment
|
|
302
|
-
- Provide guidance and explanations without giving away direct answers
|
|
303
|
-
- Encourage learning and critical thinking
|
|
304
|
-
- Be supportive and encouraging
|
|
305
|
-
- Use clear, educational language appropriate for the subject
|
|
306
|
-
|
|
307
|
-
Do not use markdown formatting in your responses - use plain text only.`;
|
|
308
|
-
const completion = await inferenceClient.chat.completions.create({
|
|
309
|
-
model: 'command-a-03-2025',
|
|
310
|
-
messages: [
|
|
311
|
-
{ role: 'system', content: systemPrompt },
|
|
312
|
-
{
|
|
313
|
-
role: 'user',
|
|
314
|
-
content: 'Please introduce yourself to the student. Explain that you are Newton, their AI tutor, and you are here to help them with their assignment. Ask them what they would like help with.'
|
|
315
|
-
},
|
|
316
|
-
],
|
|
317
|
-
max_tokens: 300,
|
|
318
|
-
temperature: 0.8,
|
|
319
|
-
});
|
|
320
|
-
const response = completion.choices[0]?.message?.content;
|
|
321
|
-
if (!response) {
|
|
322
|
-
throw new Error('No response generated from inference API');
|
|
323
|
-
}
|
|
324
|
-
// Send AI introduction using centralized sender
|
|
325
|
-
await sendAIMessage(response, conversationId, {
|
|
326
|
-
subject: submission.assignment.class.subject || 'Assignment',
|
|
327
|
-
});
|
|
328
|
-
logger.info('AI Introduction sent', { newtonChatId, conversationId });
|
|
329
|
-
}
|
|
330
|
-
catch (error) {
|
|
331
|
-
logger.error('Failed to generate AI introduction:', { error, newtonChatId });
|
|
332
|
-
// Send fallback introduction
|
|
333
|
-
try {
|
|
334
|
-
const fallbackIntro = `Hello! I'm Newton, your AI tutor. I'm here to help you with your assignment. I can answer questions, explain concepts, and guide you through your work. What would you like help with today?`;
|
|
335
|
-
await sendAIMessage(fallbackIntro, conversationId, {
|
|
336
|
-
subject: 'Assignment',
|
|
337
|
-
});
|
|
338
|
-
logger.info('Fallback AI introduction sent', { newtonChatId });
|
|
339
|
-
}
|
|
340
|
-
catch (fallbackError) {
|
|
341
|
-
logger.error('Failed to send fallback AI introduction:', { error: fallbackError, newtonChatId });
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Generate and send AI response to student message
|
|
347
|
-
*/
|
|
348
|
-
async function generateAndSendNewtonResponse(newtonChatId, studentMessage, conversationId, submission) {
|
|
349
|
-
try {
|
|
350
|
-
// Get recent conversation history
|
|
351
|
-
const recentMessages = await prisma.message.findMany({
|
|
352
|
-
where: {
|
|
353
|
-
conversationId,
|
|
354
|
-
},
|
|
355
|
-
include: {
|
|
356
|
-
sender: {
|
|
357
|
-
select: {
|
|
358
|
-
id: true,
|
|
359
|
-
username: true,
|
|
360
|
-
profile: {
|
|
361
|
-
select: {
|
|
362
|
-
displayName: true,
|
|
363
|
-
},
|
|
364
|
-
},
|
|
365
|
-
},
|
|
366
|
-
},
|
|
367
|
-
},
|
|
368
|
-
orderBy: {
|
|
369
|
-
createdAt: 'desc',
|
|
370
|
-
},
|
|
371
|
-
take: 10, // Last 10 messages for context
|
|
372
|
-
});
|
|
373
|
-
const systemPrompt = `You are Newton, an AI tutor helping a student with their assignment submission.
|
|
374
|
-
|
|
375
|
-
Assignment: ${submission.assignment.title}
|
|
376
|
-
Subject: ${submission.assignment.class.subject || 'General'}
|
|
377
|
-
Instructions: ${submission.assignment.instructions || 'No specific instructions provided'}
|
|
378
|
-
|
|
379
|
-
Your role:
|
|
380
|
-
- Help the student understand concepts related to their assignment
|
|
381
|
-
- Provide guidance and explanations without giving away direct answers
|
|
382
|
-
- Encourage learning and critical thinking
|
|
383
|
-
- Be supportive and encouraging
|
|
384
|
-
- Use clear, educational language appropriate for the subject
|
|
385
|
-
- If the student asks for direct answers, guide them to think through the problem instead
|
|
386
|
-
- Break down complex concepts into simpler parts
|
|
387
|
-
- Use examples and analogies when helpful
|
|
388
|
-
|
|
389
|
-
IMPORTANT:
|
|
390
|
-
- Do not use markdown formatting in your responses - use plain text only
|
|
391
|
-
- Keep responses conversational and educational
|
|
392
|
-
- Focus on helping the student learn, not just completing the assignment`;
|
|
393
|
-
const messages = [
|
|
394
|
-
{ role: 'system', content: systemPrompt },
|
|
395
|
-
];
|
|
396
|
-
// Add recent conversation history
|
|
397
|
-
recentMessages.reverse().forEach(msg => {
|
|
398
|
-
const role = isAIUser(msg.senderId) ? 'assistant' : 'user';
|
|
399
|
-
const senderName = msg.sender?.profile?.displayName || msg.sender?.username || 'Student';
|
|
400
|
-
const content = isAIUser(msg.senderId) ? msg.content : `${senderName}: ${msg.content}`;
|
|
401
|
-
messages.push({
|
|
402
|
-
role: role,
|
|
403
|
-
content,
|
|
404
|
-
});
|
|
405
|
-
});
|
|
406
|
-
// Add the new student message
|
|
407
|
-
messages.push({
|
|
408
|
-
role: 'user',
|
|
409
|
-
content: `Student: ${studentMessage}`,
|
|
410
|
-
});
|
|
411
|
-
const completion = await openAIClient.chat.completions.create({
|
|
412
|
-
model: 'gpt-5-nano',
|
|
413
|
-
messages,
|
|
414
|
-
temperature: 0.7,
|
|
415
|
-
});
|
|
416
|
-
const response = completion.choices[0]?.message?.content;
|
|
417
|
-
if (!response) {
|
|
418
|
-
throw new Error('No response generated from inference API');
|
|
419
|
-
}
|
|
420
|
-
// Send the text response to the conversation
|
|
421
|
-
await sendAIMessage(response, conversationId, {
|
|
422
|
-
subject: submission.assignment.class.subject || 'Assignment',
|
|
423
|
-
});
|
|
424
|
-
logger.info('AI response sent', { newtonChatId, conversationId });
|
|
425
|
-
}
|
|
426
|
-
catch (error) {
|
|
427
|
-
logger.error('Failed to generate AI response:', {
|
|
428
|
-
error: error instanceof Error ? {
|
|
429
|
-
message: error.message,
|
|
430
|
-
stack: error.stack,
|
|
431
|
-
name: error.name
|
|
432
|
-
} : error,
|
|
433
|
-
newtonChatId
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
260
|
//# sourceMappingURL=newtonChat.js.map
|
|
438
|
-
//# debugId=
|
|
261
|
+
//# debugId=ce05ab9c-6259-5565-ad40-a8e2dd1beb79
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"newtonChat.js","sources":["routers/newtonChat.ts"],"sourceRoot":"/","sourcesContent":["import { z } from 'zod';\nimport { createTRPCRouter, protectedProcedure } from '../trpc.js';\nimport { prisma } from '../lib/prisma.js';\nimport { pusher } from '../lib/pusher.js';\nimport { TRPCError } from '@trpc/server';\nimport { \n inferenceClient,\n openAIClient,\n sendAIMessage,\n} from '../utils/inference.js';\nimport { logger } from '../utils/logger.js';\nimport { isAIUser } from '../utils/aiUser.js';\n\nexport const newtonChatRouter = createTRPCRouter({\n getTutorConversation: protectedProcedure\n .input(\n z.object({\n assignmentId: z.string(),\n classId: z.string(),\n })\n )\n .query(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { assignmentId, classId } = input;\n\n // Verify user is a student in the class\n const classMembership = await prisma.class.findFirst({\n where: {\n id: classId,\n students: {\n some: {\n id: userId,\n },\n },\n },\n });\n\n if (!classMembership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a student in this class',\n });\n }\n\n // Find or create submission for this student and assignment\n const submission = await prisma.submission.findFirst({\n where: {\n assignmentId,\n studentId: userId,\n },\n });\n\n if (!submission) {\n throw new TRPCError({\n code: 'NOT_FOUND',\n message: 'Submission not found. Please create a submission first.',\n });\n }\n\n // Find the latest NewtonChat for this submission, or create a new one\n const result = await prisma.$transaction(async (tx) => {\n // Get the latest NewtonChat for this submission\n const existingNewtonChat = await tx.newtonChat.findFirst({\n where: {\n submissionId: submission.id,\n },\n include: {\n conversation: {\n include: {\n members: {\n where: {\n userId,\n },\n },\n },\n },\n },\n orderBy: {\n createdAt: 'desc',\n },\n });\n\n // If exists and user is already a member, return it\n if (existingNewtonChat && existingNewtonChat.conversation.members.length > 0) {\n return existingNewtonChat;\n }\n\n // If exists but user is not a member, add them\n if (existingNewtonChat) {\n await tx.conversationMember.create({\n data: {\n userId,\n conversationId: existingNewtonChat.conversationId,\n role: 'MEMBER',\n },\n });\n\n return existingNewtonChat;\n }\n\n // Create new NewtonChat with associated conversation\n const conversation = await tx.conversation.create({\n data: {\n type: 'DM',\n name: 'Session with Newton Tutor',\n displayInChat: false, // Newton chats don't show in regular chat list\n },\n });\n\n // Add student to the conversation\n await tx.conversationMember.create({\n data: {\n userId,\n conversationId: conversation.id,\n role: 'MEMBER',\n },\n });\n\n // Create the NewtonChat\n const newtonChat = await tx.newtonChat.create({\n data: {\n submissionId: submission.id,\n conversationId: conversation.id,\n title: 'Session with Newton Tutor',\n },\n });\n\n return newtonChat;\n });\n\n // Generate AI introduction message in parallel (don't await - fire and forget)\n generateAndSendNewtonIntroduction(\n result.id,\n result.conversationId,\n submission.id\n ).catch(error => {\n logger.error('Failed to generate AI introduction:', { error, newtonChatId: result.id });\n });\n\n return {\n conversationId: result.conversationId,\n newtonChatId: result.id,\n };\n }),\n\n postToNewtonChat: protectedProcedure\n .input(\n z.object({\n newtonChatId: z.string(),\n content: z.string().min(1).max(4000),\n mentionedUserIds: z.array(z.string()).optional(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { newtonChatId, content, mentionedUserIds = [] } = input;\n\n // Get newton chat and verify user is a member\n const newtonChat = await prisma.newtonChat.findFirst({\n where: {\n id: newtonChatId,\n conversation: {\n members: {\n some: {\n userId,\n },\n },\n },\n },\n include: {\n conversation: {\n select: {\n id: true,\n },\n },\n submission: {\n include: {\n assignment: {\n select: {\n id: true,\n title: true,\n instructions: true,\n class: {\n select: {\n subject: true,\n },\n },\n },\n },\n },\n },\n },\n });\n\n if (!newtonChat) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Newton chat not found or access denied',\n });\n }\n\n // Verify mentioned users are members of the conversation\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await prisma.conversationMember.findMany({\n where: {\n conversationId: newtonChat.conversationId,\n userId: { in: mentionedUserIds },\n },\n });\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 // Create message and mentions\n const result = await prisma.$transaction(async (tx) => {\n const message = await tx.message.create({\n data: {\n content,\n senderId: userId,\n conversationId: newtonChat.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 // Create mentions\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 // Update newton chat timestamp\n await tx.newtonChat.update({\n where: { id: newtonChatId },\n data: { updatedAt: new Date() },\n });\n\n return message;\n });\n\n // Broadcast to Pusher channel (same format as regular chat)\n try {\n await pusher.trigger(`conversation-${newtonChat.conversationId}`, 'new-message', {\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 } catch (error) {\n console.error('Failed to broadcast newton chat message:', error);\n // Don't fail the request if Pusher fails\n }\n\n // Generate AI response in parallel (don't await - fire and forget)\n if (!isAIUser(userId)) {\n // Run AI response generation in background\n generateAndSendNewtonResponse(\n newtonChatId,\n content,\n newtonChat.conversationId,\n newtonChat.submission\n ).catch(error => {\n logger.error('Failed to generate AI response:', { error });\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});\n\n/**\n * Generate and send AI introduction for Newton chat\n */\nasync function generateAndSendNewtonIntroduction(\n newtonChatId: string,\n conversationId: string,\n submissionId: string\n): Promise<void> {\n try {\n // Get submission details for context\n const submission = await prisma.submission.findUnique({\n where: { id: submissionId },\n include: {\n assignment: {\n select: {\n title: true,\n instructions: true,\n class: {\n select: {\n subject: true,\n name: true,\n },\n },\n },\n },\n attachments: {\n select: {\n id: true,\n name: true,\n type: true,\n },\n },\n },\n });\n\n if (!submission) {\n throw new Error('Submission not found');\n }\n\n const systemPrompt = `You are Newton, an AI tutor helping a student with their assignment submission. \n\nAssignment: ${submission.assignment.title}\nSubject: ${submission.assignment.class.subject}\nInstructions: ${submission.assignment.instructions || 'No specific instructions provided'}\n\nYour role:\n- Help the student understand concepts related to their assignment\n- Provide guidance and explanations without giving away direct answers\n- Encourage learning and critical thinking\n- Be supportive and encouraging\n- Use clear, educational language appropriate for the subject\n\nDo not use markdown formatting in your responses - use plain text only.`;\n\n const completion = await inferenceClient.chat.completions.create({\n model: 'command-a-03-2025',\n messages: [\n { role: 'system', content: systemPrompt },\n { \n role: 'user', \n content: 'Please introduce yourself to the student. Explain that you are Newton, their AI tutor, and you are here to help them with their assignment. Ask them what they would like help with.' \n },\n ],\n max_tokens: 300,\n temperature: 0.8,\n });\n\n const response = completion.choices[0]?.message?.content;\n \n if (!response) {\n throw new Error('No response generated from inference API');\n }\n\n // Send AI introduction using centralized sender\n await sendAIMessage(response, conversationId, {\n subject: submission.assignment.class.subject || 'Assignment',\n });\n\n logger.info('AI Introduction sent', { newtonChatId, conversationId });\n\n } catch (error) {\n logger.error('Failed to generate AI introduction:', { error, newtonChatId });\n \n // Send fallback introduction\n try {\n const fallbackIntro = `Hello! I'm Newton, your AI tutor. I'm here to help you with your assignment. I can answer questions, explain concepts, and guide you through your work. What would you like help with today?`;\n \n await sendAIMessage(fallbackIntro, conversationId, {\n subject: 'Assignment',\n });\n\n logger.info('Fallback AI introduction sent', { newtonChatId });\n\n } catch (fallbackError) {\n logger.error('Failed to send fallback AI introduction:', { error: fallbackError, newtonChatId });\n }\n }\n}\n\n/**\n * Generate and send AI response to student message\n */\nasync function generateAndSendNewtonResponse(\n newtonChatId: string,\n studentMessage: string,\n conversationId: string,\n submission: {\n id: string;\n assignment: {\n id: string;\n title: string;\n instructions: string | null;\n class: {\n subject: string | null;\n };\n };\n }\n): Promise<void> {\n try {\n // Get recent conversation history\n const recentMessages = await prisma.message.findMany({\n where: {\n conversationId,\n },\n include: {\n sender: {\n select: {\n id: true,\n username: true,\n profile: {\n select: {\n displayName: true,\n },\n },\n },\n },\n },\n orderBy: {\n createdAt: 'desc',\n },\n take: 10, // Last 10 messages for context\n });\n\n const systemPrompt = `You are Newton, an AI tutor helping a student with their assignment submission. \n\nAssignment: ${submission.assignment.title}\nSubject: ${submission.assignment.class.subject || 'General'}\nInstructions: ${submission.assignment.instructions || 'No specific instructions provided'}\n\nYour role:\n- Help the student understand concepts related to their assignment\n- Provide guidance and explanations without giving away direct answers\n- Encourage learning and critical thinking\n- Be supportive and encouraging\n- Use clear, educational language appropriate for the subject\n- If the student asks for direct answers, guide them to think through the problem instead\n- Break down complex concepts into simpler parts\n- Use examples and analogies when helpful\n\nIMPORTANT:\n- Do not use markdown formatting in your responses - use plain text only\n- Keep responses conversational and educational\n- Focus on helping the student learn, not just completing the assignment`;\n\n const messages: Array<{ role: 'user' | 'assistant' | 'system'; content: string }> = [\n { role: 'system', content: systemPrompt },\n ];\n\n // Add recent conversation history\n recentMessages.reverse().forEach(msg => {\n const role = isAIUser(msg.senderId) ? 'assistant' : 'user';\n const senderName = msg.sender?.profile?.displayName || msg.sender?.username || 'Student';\n const content = isAIUser(msg.senderId) ? msg.content : `${senderName}: ${msg.content}`;\n \n messages.push({\n role: role as 'user' | 'assistant',\n content,\n });\n });\n\n // Add the new student message\n messages.push({\n role: 'user',\n content: `Student: ${studentMessage}`,\n });\n\n const completion = await openAIClient.chat.completions.create({\n model: 'gpt-5-nano',\n messages,\n temperature: 0.7,\n });\n\n const response = completion.choices[0]?.message?.content;\n \n if (!response) {\n throw new Error('No response generated from inference API');\n }\n\n // Send the text response to the conversation\n await sendAIMessage(response, conversationId, {\n subject: submission.assignment.class.subject || 'Assignment',\n });\n\n logger.info('AI response sent', { newtonChatId, conversationId });\n\n } catch (error) {\n logger.error('Failed to generate AI response:', { \n error: error instanceof Error ? {\n message: error.message,\n stack: error.stack,\n name: error.name\n } : error,\n newtonChatId \n });\n }\n}\n\n\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,eAAe,EACf,YAAY,EACZ,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,Q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AAc,EAAE;YAC5C,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,IAAI,YAAY;SAC7D,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC,CAAC;IAEpE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE;YAC9C,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC;gBAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,IAAI,EAAE,KAAK,CAAC,IAAI;aACjB,CAAC,CAAC,CAAC,KAAK;YACT,YAAY;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC","debug_id":"18a2ffea-1d1f-50ee-b65a-c24303a7a9d9"}
|
|
1
|
+
{"version":3,"file":"newtonChat.js","sources":["routers/newtonChat.ts"],"sourceRoot":"/","sourcesContent":["import { z } from 'zod';\nimport { createTRPCRouter, protectedProcedure } from '../trpc.js';\nimport { prisma } from '../lib/prisma.js';\nimport { pusher } from '../lib/pusher.js';\nimport { TRPCError } from '@trpc/server';\nimport { logger } from '../utils/logger.js';\nimport { isAIUser } from '../utils/aiUser.js';\nimport { generateAndSendNewtonIntroduction, generateAndSendNewtonResponse } from '../server/pipelines/aiNewtonChat.js';\n\nexport const newtonChatRouter = createTRPCRouter({\n getTutorConversation: protectedProcedure\n .input(\n z.object({\n assignmentId: z.string(),\n classId: z.string(),\n })\n )\n .query(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { assignmentId, classId } = input;\n\n // Verify user is a student in the class\n const classMembership = await prisma.class.findFirst({\n where: {\n id: classId,\n students: {\n some: {\n id: userId,\n },\n },\n },\n });\n\n if (!classMembership) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Not a student in this class',\n });\n }\n\n // Find or create submission for this student and assignment\n const submission = await prisma.submission.findFirst({\n where: {\n assignmentId,\n studentId: userId,\n },\n });\n\n if (!submission) {\n throw new TRPCError({\n code: 'NOT_FOUND',\n message: 'Submission not found. Please create a submission first.',\n });\n }\n\n // Find the latest NewtonChat for this submission, or create a new one\n const result = await prisma.$transaction(async (tx) => {\n // Get the latest NewtonChat for this submission\n const existingNewtonChat = await tx.newtonChat.findFirst({\n where: {\n submissionId: submission.id,\n },\n include: {\n conversation: {\n include: {\n members: {\n where: {\n userId,\n },\n },\n },\n },\n },\n orderBy: {\n createdAt: 'desc',\n },\n });\n\n // If exists and user is already a member, return it\n if (existingNewtonChat && existingNewtonChat.conversation.members.length > 0) {\n return existingNewtonChat;\n }\n\n // If exists but user is not a member, add them\n if (existingNewtonChat) {\n await tx.conversationMember.create({\n data: {\n userId,\n conversationId: existingNewtonChat.conversationId,\n role: 'MEMBER',\n },\n });\n\n return existingNewtonChat;\n }\n\n // Create new NewtonChat with associated conversation\n const conversation = await tx.conversation.create({\n data: {\n type: 'DM',\n name: 'Session with Newton Tutor',\n displayInChat: false, // Newton chats don't show in regular chat list\n },\n });\n\n // Add student to the conversation\n await tx.conversationMember.create({\n data: {\n userId,\n conversationId: conversation.id,\n role: 'MEMBER',\n },\n });\n\n // Create the NewtonChat\n const newtonChat = await tx.newtonChat.create({\n data: {\n submissionId: submission.id,\n conversationId: conversation.id,\n title: 'Session with Newton Tutor',\n },\n });\n generateAndSendNewtonIntroduction(\n newtonChat.id,\n newtonChat.conversationId,\n submission.id\n ).catch(error => {\n logger.error('Failed to generate AI introduction:', { error, newtonChatId: result.id });\n });\n\n return newtonChat;\n });\n\n return {\n conversationId: result.conversationId,\n newtonChatId: result.id,\n };\n }),\n\n postToNewtonChat: protectedProcedure\n .input(\n z.object({\n newtonChatId: z.string(),\n content: z.string().min(1).max(4000),\n mentionedUserIds: z.array(z.string()).optional(),\n })\n )\n .mutation(async ({ input, ctx }) => {\n const userId = ctx.user!.id;\n const { newtonChatId, content, mentionedUserIds = [] } = input;\n\n // Get newton chat and verify user is a member\n const newtonChat = await prisma.newtonChat.findFirst({\n where: {\n id: newtonChatId,\n conversation: {\n members: {\n some: {\n userId,\n },\n },\n },\n },\n include: {\n conversation: {\n select: {\n id: true,\n },\n },\n submission: {\n include: {\n assignment: {\n select: {\n id: true,\n title: true,\n instructions: true,\n class: {\n select: {\n subject: true,\n },\n },\n },\n },\n },\n },\n },\n });\n\n if (!newtonChat) {\n throw new TRPCError({\n code: 'FORBIDDEN',\n message: 'Newton chat not found or access denied',\n });\n }\n\n // Verify mentioned users are members of the conversation\n if (mentionedUserIds.length > 0) {\n const mentionedMemberships = await prisma.conversationMember.findMany({\n where: {\n conversationId: newtonChat.conversationId,\n userId: { in: mentionedUserIds },\n },\n });\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 // Create message and mentions\n const result = await prisma.$transaction(async (tx) => {\n const message = await tx.message.create({\n data: {\n content,\n senderId: userId,\n conversationId: newtonChat.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 // Create mentions\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 // Update newton chat timestamp\n await tx.newtonChat.update({\n where: { id: newtonChatId },\n data: { updatedAt: new Date() },\n });\n\n return message;\n });\n\n // Broadcast to Pusher channel (same format as regular chat)\n try {\n await pusher.trigger(`conversation-${newtonChat.conversationId}`, 'new-message', {\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 } catch (error) {\n console.error('Failed to broadcast newton chat message:', error);\n // Don't fail the request if Pusher fails\n }\n\n // Generate AI response in parallel (don't await - fire and forget)\n if (!isAIUser(userId)) {\n // Run AI response generation in background\n generateAndSendNewtonResponse(\n newtonChatId,\n content,\n newtonChat.conversationId,\n newtonChat.submission\n ).catch(error => {\n logger.error('Failed to generate AI response:', { error });\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});\n\n\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,iCAAiC,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAC;AAEvH,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;IAC/C,oBAAoB,EAAE,kBAAkB;SACrC,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;QACP,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;QACxB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;KACpB,CAAC,CACH;SACA,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,IAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;QAExC,wCAAwC;QACxC,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC;YAC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AAM,CAAC,EAAE;YACb,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,gBAAgB;SACjB,CAAC;IACJ,CAAC,CAAC;CACL,CAAC,CAAC","debug_id":"ce05ab9c-6259-5565-ad40-a8e2dd1beb79"}
|
|
@@ -16,11 +16,21 @@ export declare const sectionRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
16
16
|
};
|
|
17
17
|
transformer: false;
|
|
18
18
|
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
19
|
+
exists: import("@trpc/server").TRPCQueryProcedure<{
|
|
20
|
+
input: {
|
|
21
|
+
[x: string]: unknown;
|
|
22
|
+
classId: string;
|
|
23
|
+
id: string;
|
|
24
|
+
};
|
|
25
|
+
output: boolean;
|
|
26
|
+
meta: object;
|
|
27
|
+
}>;
|
|
19
28
|
create: import("@trpc/server").TRPCMutationProcedure<{
|
|
20
29
|
input: {
|
|
21
30
|
[x: string]: unknown;
|
|
22
31
|
classId: string;
|
|
23
32
|
name: string;
|
|
33
|
+
id?: string | undefined;
|
|
24
34
|
color?: string | undefined;
|
|
25
35
|
};
|
|
26
36
|
output: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section.d.ts","sourceRoot":"/","sources":["routers/section.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"section.d.ts","sourceRoot":"/","sources":["routers/section.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAwBxB,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqVxB,CAAC"}
|
package/dist/routers/section.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
!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]="
|
|
2
|
+
!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]="fd56eafe-403c-58b3-b36f-74a278bc60c9")}catch(e){}}();
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { createTRPCRouter, protectedTeacherProcedure } from "../trpc.js";
|
|
4
|
+
import { createTRPCRouter, protectedClassMemberProcedure, protectedTeacherProcedure } from "../trpc.js";
|
|
5
5
|
import { TRPCError } from "@trpc/server";
|
|
6
6
|
import { prisma } from "../lib/prisma.js";
|
|
7
7
|
const createSectionSchema = z.object({
|
|
8
8
|
classId: z.string(),
|
|
9
|
+
id: z.string().optional(),
|
|
9
10
|
name: z.string(),
|
|
10
11
|
color: z.string().optional(),
|
|
11
12
|
});
|
|
@@ -20,6 +21,22 @@ const deleteSectionSchema = z.object({
|
|
|
20
21
|
classId: z.string(),
|
|
21
22
|
});
|
|
22
23
|
export const sectionRouter = createTRPCRouter({
|
|
24
|
+
exists: protectedClassMemberProcedure
|
|
25
|
+
.input(z.object({
|
|
26
|
+
id: z.string(),
|
|
27
|
+
}))
|
|
28
|
+
.query(async ({ ctx, input }) => {
|
|
29
|
+
if (!ctx.user) {
|
|
30
|
+
throw new TRPCError({
|
|
31
|
+
code: "UNAUTHORIZED",
|
|
32
|
+
message: "User must be authenticated",
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const section = await prisma.section.findUnique({
|
|
36
|
+
where: { id: input.id },
|
|
37
|
+
});
|
|
38
|
+
return section ? true : false;
|
|
39
|
+
}),
|
|
23
40
|
create: protectedTeacherProcedure
|
|
24
41
|
.input(createSectionSchema)
|
|
25
42
|
.mutation(async ({ ctx, input }) => {
|
|
@@ -48,6 +65,7 @@ export const sectionRouter = createTRPCRouter({
|
|
|
48
65
|
}
|
|
49
66
|
const section = await prisma.section.create({
|
|
50
67
|
data: {
|
|
68
|
+
...(input.id && { id: input.id }),
|
|
51
69
|
name: input.name,
|
|
52
70
|
order: 0,
|
|
53
71
|
class: {
|
|
@@ -303,4 +321,4 @@ export const sectionRouter = createTRPCRouter({
|
|
|
303
321
|
}),
|
|
304
322
|
});
|
|
305
323
|
//# sourceMappingURL=section.js.map
|
|
306
|
-
//# debugId=
|
|
324
|
+
//# debugId=fd56eafe-403c-58b3-b36f-74a278bc60c9
|