@studious-lms/server 1.2.45 → 1.2.46
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/.env.example +45 -0
- package/.env.test.example +37 -0
- package/README.md +34 -7
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +12110 -0
- package/coverage/coverage-final.json +44 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +221 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/server/index.html +116 -0
- package/coverage/server/src/exportType.ts.html +109 -0
- package/coverage/server/src/index.html +161 -0
- package/coverage/server/src/index.ts.html +1702 -0
- package/coverage/server/src/instrument.ts.html +130 -0
- package/coverage/server/src/lib/config/env.ts.html +448 -0
- package/coverage/server/src/lib/config/index.html +116 -0
- package/coverage/server/src/lib/fileUpload.ts.html +1138 -0
- package/coverage/server/src/lib/googleCloudStorage.ts.html +334 -0
- package/coverage/server/src/lib/index.html +206 -0
- package/coverage/server/src/lib/jsonConversion.ts.html +2323 -0
- package/coverage/server/src/lib/jsonStyles.ts.html +193 -0
- package/coverage/server/src/lib/notificationHandler.ts.html +193 -0
- package/coverage/server/src/lib/pusher.ts.html +121 -0
- package/coverage/server/src/lib/thumbnailGenerator.ts.html +592 -0
- package/coverage/server/src/middleware/auth.ts.html +646 -0
- package/coverage/server/src/middleware/index.html +146 -0
- package/coverage/server/src/middleware/logging.ts.html +244 -0
- package/coverage/server/src/middleware/security.ts.html +271 -0
- package/coverage/server/src/routers/_app.ts.html +232 -0
- package/coverage/server/src/routers/agenda.ts.html +319 -0
- package/coverage/server/src/routers/announcement.ts.html +3481 -0
- package/coverage/server/src/routers/assignment.ts.html +7633 -0
- package/coverage/server/src/routers/attendance.ts.html +1030 -0
- package/coverage/server/src/routers/auth.ts.html +1081 -0
- package/coverage/server/src/routers/class.ts.html +3535 -0
- package/coverage/server/src/routers/comment.ts.html +991 -0
- package/coverage/server/src/routers/conversation.ts.html +982 -0
- package/coverage/server/src/routers/event.ts.html +1609 -0
- package/coverage/server/src/routers/file.ts.html +1144 -0
- package/coverage/server/src/routers/folder.ts.html +2797 -0
- package/coverage/server/src/routers/index.html +386 -0
- package/coverage/server/src/routers/labChat.ts.html +3073 -0
- package/coverage/server/src/routers/marketing.ts.html +340 -0
- package/coverage/server/src/routers/message.ts.html +1912 -0
- package/coverage/server/src/routers/notifications.ts.html +364 -0
- package/coverage/server/src/routers/section.ts.html +1120 -0
- package/coverage/server/src/routers/user.ts.html +862 -0
- package/coverage/server/src/routers/worksheet.ts.html +1729 -0
- package/coverage/server/src/trpc.ts.html +397 -0
- package/coverage/server/src/types/index.html +116 -0
- package/coverage/server/src/types/trpc.ts.html +127 -0
- package/coverage/server/src/utils/aiUser.ts.html +280 -0
- package/coverage/server/src/utils/email.ts.html +121 -0
- package/coverage/server/src/utils/generateInviteCode.ts.html +106 -0
- package/coverage/server/src/utils/index.html +206 -0
- package/coverage/server/src/utils/inference.ts.html +709 -0
- package/coverage/server/src/utils/logger.ts.html +664 -0
- package/coverage/server/src/utils/prismaErrorHandler.ts.html +907 -0
- package/coverage/server/src/utils/prismaWrapper.ts.html +355 -0
- package/coverage/server/vitest.config.ts.html +196 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +83 -52
- package/dist/index.js.map +1 -1
- package/dist/instrument.js +15 -8
- package/dist/instrument.js.map +1 -1
- package/dist/lib/config/env.d.ts +169 -0
- package/dist/lib/config/env.d.ts.map +1 -0
- package/dist/lib/config/env.js +115 -0
- package/dist/lib/config/env.js.map +1 -0
- package/dist/lib/fileUpload.d.ts.map +1 -1
- package/dist/lib/fileUpload.js +5 -4
- package/dist/lib/fileUpload.js.map +1 -1
- package/dist/lib/googleCloudStorage.d.ts.map +1 -1
- package/dist/lib/googleCloudStorage.js +7 -8
- package/dist/lib/googleCloudStorage.js.map +1 -1
- package/dist/lib/jsonConversion.d.ts.map +1 -1
- package/dist/lib/jsonConversion.js +14 -16
- package/dist/lib/jsonConversion.js.map +1 -1
- package/dist/lib/notificationHandler.d.ts +2 -2
- package/dist/lib/prisma.d.ts +2 -2
- package/dist/lib/prisma.d.ts.map +1 -1
- package/dist/lib/prisma.js +22 -3
- package/dist/lib/prisma.js.map +1 -1
- package/dist/lib/pusher.d.ts.map +1 -1
- package/dist/lib/pusher.js +8 -7
- package/dist/lib/pusher.js.map +1 -1
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +6 -5
- package/dist/middleware/auth.js.map +1 -1
- package/dist/middleware/security.d.ts +5 -0
- package/dist/middleware/security.d.ts.map +1 -0
- package/dist/middleware/security.js +77 -0
- package/dist/middleware/security.js.map +1 -0
- package/dist/routers/_app.d.ts +294 -98
- 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/agenda.d.ts.map +1 -1
- package/dist/routers/agenda.js +12 -9
- package/dist/routers/agenda.js.map +1 -1
- package/dist/routers/announcement.d.ts +8 -0
- package/dist/routers/announcement.d.ts.map +1 -1
- package/dist/routers/announcement.js +6 -4
- package/dist/routers/announcement.js.map +1 -1
- package/dist/routers/assignment.d.ts +7 -4
- package/dist/routers/assignment.d.ts.map +1 -1
- package/dist/routers/assignment.js +35 -18
- package/dist/routers/assignment.js.map +1 -1
- package/dist/routers/attendance.d.ts +1 -0
- package/dist/routers/attendance.d.ts.map +1 -1
- package/dist/routers/attendance.js +4 -4
- package/dist/routers/attendance.js.map +1 -1
- package/dist/routers/auth.d.ts +20 -0
- package/dist/routers/auth.d.ts.map +1 -1
- package/dist/routers/auth.js +132 -15
- package/dist/routers/auth.js.map +1 -1
- package/dist/routers/class.d.ts +10 -0
- package/dist/routers/class.d.ts.map +1 -1
- package/dist/routers/class.js +49 -5
- package/dist/routers/class.js.map +1 -1
- package/dist/routers/comment.d.ts +2 -0
- package/dist/routers/comment.d.ts.map +1 -1
- package/dist/routers/conversation.d.ts +1 -0
- package/dist/routers/conversation.d.ts.map +1 -1
- package/dist/routers/conversation.js +46 -31
- package/dist/routers/conversation.js.map +1 -1
- package/dist/routers/file.d.ts.map +1 -1
- package/dist/routers/file.js +30 -7
- package/dist/routers/file.js.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 +2 -3
- package/dist/routers/labChat.js.map +1 -1
- package/dist/routers/marketing.d.ts +1 -1
- package/dist/routers/newtonChat.d.ts +55 -0
- package/dist/routers/newtonChat.d.ts.map +1 -0
- package/dist/routers/newtonChat.js +438 -0
- package/dist/routers/newtonChat.js.map +1 -0
- package/dist/routers/notifications.d.ts +4 -4
- package/dist/routers/section.d.ts +9 -4
- package/dist/routers/section.d.ts.map +1 -1
- package/dist/routers/section.js +8 -8
- package/dist/routers/section.js.map +1 -1
- package/dist/routers/user.d.ts.map +1 -1
- package/dist/routers/user.js +5 -4
- package/dist/routers/user.js.map +1 -1
- package/dist/routers/worksheet.d.ts +30 -36
- package/dist/routers/worksheet.d.ts.map +1 -1
- package/dist/routers/worksheet.js +11 -33
- package/dist/routers/worksheet.js.map +1 -1
- package/dist/seedDatabase.d.ts +1 -1
- package/dist/seedDatabase.js +275 -284
- package/dist/seedDatabase.js.map +1 -1
- package/dist/server/pipelines/aiLabChat.d.ts +10 -0
- package/dist/server/pipelines/aiLabChat.d.ts.map +1 -0
- package/dist/server/pipelines/aiLabChat.js +83 -0
- package/dist/server/pipelines/aiLabChat.js.map +1 -0
- package/dist/server/pipelines/gradeWorksheet.d.ts +2 -0
- package/dist/server/pipelines/gradeWorksheet.d.ts.map +1 -0
- package/dist/server/pipelines/gradeWorksheet.js +138 -0
- package/dist/server/pipelines/gradeWorksheet.js.map +1 -0
- package/dist/trpc.d.ts.map +1 -1
- package/dist/trpc.js +2 -2
- package/dist/trpc.js.map +1 -1
- package/dist/utils/email.d.ts +9 -1
- package/dist/utils/email.d.ts.map +1 -1
- package/dist/utils/email.js +20 -5
- package/dist/utils/email.js.map +1 -1
- package/dist/utils/inference.d.ts +3 -0
- package/dist/utils/inference.d.ts.map +1 -1
- package/dist/utils/inference.js +41 -7
- package/dist/utils/inference.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +3 -3
- package/dist/utils/logger.js.map +1 -1
- package/docker-compose.yml +14 -0
- package/package.json +13 -4
- package/prisma/schema.prisma +32 -5
- package/scripts/test-pre-push.ts +14 -0
- package/src/index.ts +98 -54
- package/src/instrument.ts +13 -6
- package/src/lib/config/env.ts +126 -0
- package/src/lib/fileUpload.ts +3 -2
- package/src/lib/googleCloudStorage.ts +6 -6
- package/src/lib/jsonConversion.ts +12 -14
- package/src/lib/prisma.ts +23 -2
- package/src/lib/pusher.ts +6 -5
- package/src/middleware/auth.ts +4 -3
- package/src/middleware/security.ts +80 -0
- package/src/routers/_app.ts +2 -0
- package/src/routers/agenda.ts +10 -7
- package/src/routers/announcement.ts +4 -2
- package/src/routers/assignment.ts +58 -40
- package/src/routers/attendance.ts +2 -2
- package/src/routers/auth.ts +143 -14
- package/src/routers/class.ts +52 -3
- package/src/routers/conversation.ts +49 -29
- package/src/routers/file.ts +29 -5
- package/src/routers/labChat.ts +0 -1
- package/src/routers/newtonChat.ts +520 -0
- package/src/routers/section.ts +6 -6
- package/src/routers/user.ts +3 -2
- package/src/routers/worksheet.ts +9 -37
- package/src/seedDatabase.ts +290 -283
- package/src/server/pipelines/aiLabChat.ts +92 -0
- package/src/server/pipelines/gradeWorksheet.ts +152 -0
- package/src/trpc.ts +2 -0
- package/src/utils/email.ts +30 -3
- package/src/utils/inference.ts +50 -5
- package/src/utils/logger.ts +2 -1
- package/tests/announcement.test.ts +164 -0
- package/tests/assignment.test.ts +296 -0
- package/tests/attendance.test.ts +168 -0
- package/tests/auth.test.ts +33 -10
- package/tests/class.test.ts +34 -9
- package/tests/event.test.ts +228 -0
- package/tests/section.test.ts +216 -0
- package/tests/setup.ts +70 -16
- package/tests/user.test.ts +158 -0
- package/vitest.config.ts +26 -0
- package/API_SPECIFICATION.md +0 -1597
- package/BASE64_REMOVAL_SUMMARY.md +0 -164
- package/CHAT_API_SPEC.md +0 -579
- package/LAB_CHAT_API_SPEC.md +0 -518
- package/dist/routers/school.d.ts +0 -208
- package/dist/routers/school.d.ts.map +0 -1
- package/dist/routers/school.js +0 -483
|
@@ -0,0 +1,83 @@
|
|
|
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]="3bd44f1e-3730-55cd-9d74-98b33bdd6bc1")}catch(e){}}();
|
|
3
|
+
import z from "zod";
|
|
4
|
+
const aiLabChatResponseSchema = z.object({
|
|
5
|
+
content: z.string(),
|
|
6
|
+
attachments: z.array(z.object({
|
|
7
|
+
id: z.string(),
|
|
8
|
+
name: z.string(),
|
|
9
|
+
path: z.string(),
|
|
10
|
+
type: z.string(),
|
|
11
|
+
size: z.number(),
|
|
12
|
+
})),
|
|
13
|
+
assignmentsToCreate: z.array(z.object({
|
|
14
|
+
title: z.string(),
|
|
15
|
+
instructions: z.string(),
|
|
16
|
+
dueDate: z.date(),
|
|
17
|
+
acceptFiles: z.boolean(),
|
|
18
|
+
acceptExtendedResponse: z.boolean(),
|
|
19
|
+
acceptWorksheet: z.boolean(),
|
|
20
|
+
maxGrade: z.number(),
|
|
21
|
+
gradingBoundaryId: z.string(),
|
|
22
|
+
markschemeId: z.string(),
|
|
23
|
+
worksheetIds: z.array(z.string()),
|
|
24
|
+
studentIds: z.array(z.string()),
|
|
25
|
+
sectionId: z.string(),
|
|
26
|
+
type: z.enum(['HOMEWORK', 'QUIZ', 'TEST', 'PROJECT', 'ESSAY', 'DISCUSSION', 'PRESENTATION', 'LAB', 'OTHER']),
|
|
27
|
+
attachments: z.array(z.object({
|
|
28
|
+
id: z.string(),
|
|
29
|
+
})),
|
|
30
|
+
})),
|
|
31
|
+
});
|
|
32
|
+
const getBaseSystemPrompt = (context) => {
|
|
33
|
+
const systemPrompt = `
|
|
34
|
+
# Basic Information
|
|
35
|
+
You are a helpful assistant that helps teachers create course materials for their students.
|
|
36
|
+
You are provided with the following context:
|
|
37
|
+
|
|
38
|
+
Class information: ${context.name} - ${context.subject}
|
|
39
|
+
Students: ${JSON.stringify(context.members)}
|
|
40
|
+
Assignments: ${JSON.stringify(context.assignments)}
|
|
41
|
+
Files: ${JSON.stringify(context.files)}
|
|
42
|
+
|
|
43
|
+
You are to generate a response to the user's message.
|
|
44
|
+
If contextually they would like a file, you are to generate a file.
|
|
45
|
+
And so on... same for assignments, worksheets, etc.
|
|
46
|
+
|
|
47
|
+
You are to generate a response in the following format:
|
|
48
|
+
{
|
|
49
|
+
content: string,
|
|
50
|
+
attachments: File[],
|
|
51
|
+
assignmentsToCreate: Assignment[],
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
NOTE:
|
|
55
|
+
- for attachments in Assignment, you may only attach to existing files, based on the file ids provided. if you need to create files and assignments, let the user know that this will take two operations.
|
|
56
|
+
- the user must accept your changes before they are applied. do know this.
|
|
57
|
+
-
|
|
58
|
+
`;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Generate labchat responses
|
|
62
|
+
* Allow for the generation of the following:
|
|
63
|
+
* - Assignment(s) either individual or bulk as an lesson / course plan.
|
|
64
|
+
* - Worksheet(s) either individual or bulk as an lesson / course plan.
|
|
65
|
+
* - Files (PDFs)
|
|
66
|
+
* @param labChatId
|
|
67
|
+
*/
|
|
68
|
+
// export const sendAiLabChatResponsePipeline = async (labChatId: string) => {
|
|
69
|
+
// const message = await prisma?.message.create({
|
|
70
|
+
// data: {
|
|
71
|
+
// content: "GENERATING_CONTENT",
|
|
72
|
+
// senderId: getAIUserId(),
|
|
73
|
+
// conversationId: labChatId,
|
|
74
|
+
// status: GenerationStatus.PENDING,
|
|
75
|
+
// },
|
|
76
|
+
// });
|
|
77
|
+
// try {
|
|
78
|
+
// inference(`
|
|
79
|
+
// `)
|
|
80
|
+
// }
|
|
81
|
+
// };
|
|
82
|
+
//# sourceMappingURL=aiLabChat.js.map
|
|
83
|
+
//# debugId=3bd44f1e-3730-55cd-9d74-98b33bdd6bc1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aiLabChat.js","sources":["server/pipelines/aiLabChat.ts"],"sourceRoot":"/","sourcesContent":["import { getAIUserId } from \"../../utils/aiUser\";\nimport { prisma } from \"../../lib/prisma.js\";\nimport { Assignment, Class, File, GenerationStatus, User } from \"@prisma/client\";\nimport { inference } from \"../../utils/inference.js\";\nimport z from \"zod\";\n\nconst aiLabChatResponseSchema = z.object({\n content: z.string(),\n attachments: z.array(z.object({\n id: z.string(),\n name: z.string(),\n path: z.string(),\n type: z.string(),\n size: z.number(),\n })),\n assignmentsToCreate: z.array(z.object({\n title: z.string(),\n instructions: z.string(),\n dueDate: z.date(),\n acceptFiles: z.boolean(),\n acceptExtendedResponse: z.boolean(),\n acceptWorksheet: z.boolean(),\n maxGrade: z.number(),\n gradingBoundaryId: z.string(),\n markschemeId: z.string(),\n worksheetIds: z.array(z.string()),\n studentIds: z.array(z.string()),\n sectionId: z.string(),\n type: z.enum(['HOMEWORK', 'QUIZ', 'TEST', 'PROJECT', 'ESSAY', 'DISCUSSION', 'PRESENTATION', 'LAB', 'OTHER']),\n attachments: z.array(z.object({\n id: z.string(),\n })),\n })),\n});\n\n\nconst getBaseSystemPrompt = (context: Class & { members: User[] , assignments: Assignment[], files: File[] }) => {\n const systemPrompt = `\n # Basic Information\n You are a helpful assistant that helps teachers create course materials for their students.\n You are provided with the following context:\n\n Class information: ${context.name} - ${context.subject}\n Students: ${JSON.stringify(context.members)}\n Assignments: ${JSON.stringify(context.assignments)}\n Files: ${JSON.stringify(context.files)}\n\n You are to generate a response to the user's message.\n If contextually they would like a file, you are to generate a file.\n And so on... same for assignments, worksheets, etc.\n\n You are to generate a response in the following format:\n {\n content: string,\n attachments: File[],\n assignmentsToCreate: Assignment[],\n }\n\n NOTE:\n - for attachments in Assignment, you may only attach to existing files, based on the file ids provided. if you need to create files and assignments, let the user know that this will take two operations.\n - the user must accept your changes before they are applied. do know this.\n - \n `;\n}\n\n\n\n/**\n * Generate labchat responses\n * Allow for the generation of the following:\n * - Assignment(s) either individual or bulk as an lesson / course plan.\n * - Worksheet(s) either individual or bulk as an lesson / course plan.\n * - Files (PDFs)\n * @param labChatId \n */\n// export const sendAiLabChatResponsePipeline = async (labChatId: string) => {\n// const message = await prisma?.message.create({\n// data: {\n// content: \"GENERATING_CONTENT\",\n// senderId: getAIUserId(),\n// conversationId: labChatId,\n// status: GenerationStatus.PENDING, \n// },\n// });\n\n// try {\n\n// inference(`\n// `)\n// }\n \n// };"],"names":[],"mappings":";;AAIA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;QAC1B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;QACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;KACnB,CAAC,CAAC;IACH,mBAAmB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;QAClC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;QACxB,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE;QACjB,WAAW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AACnD,aAAa;AACb,UAAU;AAEV,YAAY;AAEZ,sBAAsB;AACtB,aAAa;AACb,QAAQ;AAER,KAAK","debug_id":"3bd44f1e-3730-55cd-9d74-98b33bdd6bc1"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gradeWorksheet.d.ts","sourceRoot":"/","sources":["server/pipelines/gradeWorksheet.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,sBAAsB,GAAU,qBAAqB,MAAM,kBAuIvE,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
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]="6b562003-a444-597f-a796-db17695fff27")}catch(e){}}();
|
|
3
|
+
import { GenerationStatus, WorksheetQuestionType } from "@prisma/client";
|
|
4
|
+
import { prisma } from "../../lib/prisma.js";
|
|
5
|
+
import { logger } from "../../utils/logger.js";
|
|
6
|
+
import z from "zod";
|
|
7
|
+
import { inference } from "../../utils/inference.js";
|
|
8
|
+
import { getAIUserId } from "../../utils/aiUser.js";
|
|
9
|
+
import { pusher } from "../../lib/pusher.js";
|
|
10
|
+
/**
|
|
11
|
+
* Grades and regrades worksheet (can fixed failed responses)
|
|
12
|
+
* @param worksheetResponseId worksheet response id
|
|
13
|
+
* @returns updated worksheet response
|
|
14
|
+
*/
|
|
15
|
+
const DO_NOT_INFERENCE_STATUSES = [GenerationStatus.CANCELLED, GenerationStatus.PENDING, GenerationStatus.COMPLETED];
|
|
16
|
+
export const gradeWorksheetPipeline = async (worksheetResponseId) => {
|
|
17
|
+
logger.info('Grading worksheet response', { worksheetResponseId });
|
|
18
|
+
const worksheetResponse = await prisma.studentWorksheetResponse.findUnique({
|
|
19
|
+
where: { id: worksheetResponseId },
|
|
20
|
+
include: {
|
|
21
|
+
worksheet: true,
|
|
22
|
+
responses: {
|
|
23
|
+
where: {
|
|
24
|
+
status: {
|
|
25
|
+
not: {
|
|
26
|
+
in: DO_NOT_INFERENCE_STATUSES,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
question: {
|
|
30
|
+
type: {
|
|
31
|
+
not: {
|
|
32
|
+
in: [WorksheetQuestionType.MULTIPLE_CHOICE, WorksheetQuestionType.TRUE_FALSE],
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
include: {
|
|
38
|
+
question: true,
|
|
39
|
+
comments: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
console.log(worksheetResponse);
|
|
45
|
+
if (!worksheetResponse) {
|
|
46
|
+
logger.error('Worksheet response not found');
|
|
47
|
+
throw new Error('Worksheet response not found');
|
|
48
|
+
}
|
|
49
|
+
worksheetResponse.responses.forEach(async (response) => {
|
|
50
|
+
logger.info('Grading question', { questionId: response.questionId });
|
|
51
|
+
const question = response.question;
|
|
52
|
+
const comments = response.comments;
|
|
53
|
+
const responseText = response.response;
|
|
54
|
+
const studentQuestionProgress = await prisma.studentQuestionProgress.update({
|
|
55
|
+
where: { id: response.id, status: {
|
|
56
|
+
not: {
|
|
57
|
+
in: DO_NOT_INFERENCE_STATUSES,
|
|
58
|
+
}
|
|
59
|
+
} },
|
|
60
|
+
data: { status: GenerationStatus.PENDING },
|
|
61
|
+
});
|
|
62
|
+
if (studentQuestionProgress.status !== GenerationStatus.PENDING) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const apiResponse = await inference(`Grade the following worksheet response:
|
|
67
|
+
|
|
68
|
+
Question: ${question.question}
|
|
69
|
+
Response: ${responseText}
|
|
70
|
+
|
|
71
|
+
Comments: ${comments.map((comment) => comment.content).join('\n')}
|
|
72
|
+
Mark Scheme: ${JSON.stringify(question.markScheme)}
|
|
73
|
+
|
|
74
|
+
Justify your reasoning by including comment(s) and mark the question please.
|
|
75
|
+
Return ONLY JSON in the following format (fill in the values as per the question):
|
|
76
|
+
{
|
|
77
|
+
"isCorrect": <boolean>,
|
|
78
|
+
"points": <number>,
|
|
79
|
+
"markschemeState": [
|
|
80
|
+
{ "id": <string>, "correct": <boolean> }
|
|
81
|
+
],
|
|
82
|
+
"comments": [<string>, ...]
|
|
83
|
+
}
|
|
84
|
+
`, z.object({
|
|
85
|
+
isCorrect: z.boolean(),
|
|
86
|
+
points: z.number(),
|
|
87
|
+
markschemeState: z.array(z.object({
|
|
88
|
+
id: z.string(),
|
|
89
|
+
correct: z.boolean(),
|
|
90
|
+
})), // @note: this has to be converted to [id: string]: correct boolean
|
|
91
|
+
comments: z.array(z.string()),
|
|
92
|
+
})).catch((error) => {
|
|
93
|
+
logger.error('Failed to grade worksheet response', { error });
|
|
94
|
+
throw error;
|
|
95
|
+
});
|
|
96
|
+
console.log(apiResponse);
|
|
97
|
+
const updatedStudentQuestionProgress = await prisma.studentQuestionProgress.update({
|
|
98
|
+
where: { id: studentQuestionProgress.id, status: {
|
|
99
|
+
not: {
|
|
100
|
+
in: ['CANCELLED'],
|
|
101
|
+
},
|
|
102
|
+
} },
|
|
103
|
+
data: {
|
|
104
|
+
status: GenerationStatus.COMPLETED,
|
|
105
|
+
isCorrect: apiResponse.isCorrect,
|
|
106
|
+
points: apiResponse.points,
|
|
107
|
+
markschemeState: apiResponse.markschemeState.reduce((acc, curr) => {
|
|
108
|
+
acc["item-" + curr.id] = curr.correct;
|
|
109
|
+
return acc;
|
|
110
|
+
}, {}),
|
|
111
|
+
comments: {
|
|
112
|
+
create: apiResponse.comments.map((commentContent) => ({
|
|
113
|
+
content: commentContent,
|
|
114
|
+
authorId: getAIUserId(),
|
|
115
|
+
})),
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
pusher.trigger(`class-${worksheetResponse.worksheet.classId}`, `ai-worksheet-updated-${worksheetResponse.id}`, {
|
|
120
|
+
success: true,
|
|
121
|
+
});
|
|
122
|
+
return updatedStudentQuestionProgress;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
logger.error('Failed to grade worksheet response', { error, worksheetResponseId });
|
|
126
|
+
pusher.trigger(`class-${worksheetResponse.worksheet.classId}`, `ai-worksheet-updated-${worksheetResponse.id}`, {
|
|
127
|
+
success: false,
|
|
128
|
+
});
|
|
129
|
+
await prisma.studentQuestionProgress.update({
|
|
130
|
+
where: { id: studentQuestionProgress.id },
|
|
131
|
+
data: { status: GenerationStatus.FAILED },
|
|
132
|
+
});
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=gradeWorksheet.js.map
|
|
138
|
+
//# debugId=6b562003-a444-597f-a796-db17695fff27
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gradeWorksheet.js","sources":["server/pipelines/gradeWorksheet.ts"],"sourceRoot":"/","sourcesContent":["import { GenerationStatus, WorksheetQuestionType } from \"@prisma/client\";\nimport { prisma } from \"../../lib/prisma.js\";\nimport { logger } from \"../../utils/logger.js\";\nimport z from \"zod\";\nimport { inference } from \"../../utils/inference.js\";\nimport { getAIUserId } from \"../../utils/aiUser.js\";\nimport { pusher } from \"../../lib/pusher.js\";\n\n/**\n * Grades and regrades worksheet (can fixed failed responses)\n * @param worksheetResponseId worksheet response id\n * @returns updated worksheet response\n */\n\nconst DO_NOT_INFERENCE_STATUSES = [GenerationStatus.CANCELLED, GenerationStatus.PENDING, GenerationStatus.COMPLETED];\n\nexport const gradeWorksheetPipeline = async (worksheetResponseId: string) => {\n logger.info('Grading worksheet response', { worksheetResponseId });\n const worksheetResponse = await prisma.studentWorksheetResponse.findUnique({\n where: { id: worksheetResponseId },\n include: {\n worksheet: true,\n responses: {\n where: {\n status: {\n not: {\n in: DO_NOT_INFERENCE_STATUSES,\n },\n },\n question: {\n type: {\n not: {\n in: [WorksheetQuestionType.MULTIPLE_CHOICE, WorksheetQuestionType.TRUE_FALSE],\n }\n },\n },\n },\n include: {\n question: true,\n comments: true,\n },\n },\n },\n });\n\n console.log(worksheetResponse);\n\n if (!worksheetResponse) {\n logger.error('Worksheet response not found');\n throw new Error('Worksheet response not found');\n }\n\n worksheetResponse.responses.forEach(async (response) => {\n logger.info('Grading question', { questionId: response.questionId });\n const question = response.question;\n const comments = response.comments;\n const responseText = response.response;\n\n const studentQuestionProgress = await prisma.studentQuestionProgress.update({\n where: { id: response.id, status: {\n not: {\n in: DO_NOT_INFERENCE_STATUSES,\n }\n } },\n data: { status: GenerationStatus.PENDING },\n });\n\n if (studentQuestionProgress.status !== GenerationStatus.PENDING) {\n return;\n }\n\n try {\n const apiResponse = await inference(\n `Grade the following worksheet response:\n \n Question: ${question.question}\n Response: ${responseText}\n\n Comments: ${comments.map((comment) => comment.content).join('\\n')}\n Mark Scheme: ${JSON.stringify(question.markScheme)}\n \n Justify your reasoning by including comment(s) and mark the question please. \n Return ONLY JSON in the following format (fill in the values as per the question):\n {\n \"isCorrect\": <boolean>,\n \"points\": <number>,\n \"markschemeState\": [\n { \"id\": <string>, \"correct\": <boolean> }\n ],\n \"comments\": [<string>, ...]\n }\n `,\n z.object({\n isCorrect: z.boolean(),\n points: z.number(),\n markschemeState: z.array(z.object({\n id: z.string(),\n correct: z.boolean(),\n })), // @note: this has to be converted to [id: string]: correct boolean\n comments: z.array(z.string()),\n }),\n ).catch((error) => {\n logger.error('Failed to grade worksheet response', { error });\n throw error;\n });\n\n console.log(apiResponse);\n\n const updatedStudentQuestionProgress = await prisma.studentQuestionProgress.update({\n where: { id: studentQuestionProgress.id, status: {\n not: {\n in: ['CANCELLED'],\n },\n } },\n data: {\n status: GenerationStatus.COMPLETED,\n isCorrect: (apiResponse as { isCorrect: boolean }).isCorrect,\n points: (apiResponse as { points: number }).points,\n markschemeState: (apiResponse as {\n markschemeState: { id: string; correct: boolean }[];\n }).markschemeState.reduce((acc, curr) => {\n acc[\"item-\" + curr.id] = curr.correct;\n return acc;\n }, {} as Record<string, boolean>),\n comments: {\n create: (apiResponse as {\n comments: string[];\n }).comments.map((commentContent) => ({\n content: commentContent,\n authorId: getAIUserId(),\n })),\n },\n },\n });\n pusher.trigger(`class-${worksheetResponse.worksheet.classId}`, `ai-worksheet-updated-${worksheetResponse.id}`, {\n success: true,\n });\n\n return updatedStudentQuestionProgress;\n } catch (error) {\n logger.error('Failed to grade worksheet response', { error, worksheetResponseId });\n pusher.trigger(`class-${worksheetResponse.worksheet.classId}`, `ai-worksheet-updated-${worksheetResponse.id}`, {\n success: false,\n });\n await prisma.studentQuestionProgress.update({\n where: { id: studentQuestionProgress.id },\n data: { status: GenerationStatus.FAILED },\n });\n throw error;\n }\n });\n};"],"names":[],"mappings":";;AAAA,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C;;;;GAIG;AAEH,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAErH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,mBAA2B,EAAE,EAAE;IACxE,MAAM,CAAC,IAAI,CAAC,4BAA4B,EAAE,EAAE,mBAAmB,EAAE,CAAC,CAAC;IACnE,MAAM,iBAAiB,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,UAAU,CAAC;QACvE,KAAK,EAA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E,EAAE;gBACzC,IAAI,EAAE,EAAE,MAAM,EAAE,gBAAgB,CAAC,MAAM,EAAE;aAC5C,CAAC,CAAC;YACH,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","debug_id":"6b562003-a444-597f-a796-db17695fff27"}
|
package/dist/trpc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trpc.d.ts","sourceRoot":"/","sources":["trpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,cAAc,CAAC;AAMnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAqB,eAAe,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"trpc.d.ts","sourceRoot":"/","sources":["trpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,cAAc,CAAC;AAMnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAqB,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGnF,UAAU,oBAAoB;IAC5B,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;CACf;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC5B,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAU,MAAM,oBAAoB,KAAG,OAAO,CAAC,OAAO,CAwBnF,CAAC;AAEF,eAAO,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BZ,CAAC;AAOH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;EAAW,CAAC;AACzC,eAAO,MAAM,eAAe,yOAAqC,CAAC;AAIlE,eAAO,MAAM,kBAAkB,yOAAgC,CAAC;AAEhE,eAAO,MAAM,6BAA6B;;;;uHAEnB,CAAC;AAExB,eAAO,MAAM,yBAAyB;;;;uHAEd,CAAC;AAIzB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;EAAwB,CAAC"}
|
package/dist/trpc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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]="fe8afe09-5435-5257-8a3f-ef011f89e860")}catch(e){}}();
|
|
3
3
|
import { initTRPC } from '@trpc/server';
|
|
4
4
|
import { ZodError } from 'zod';
|
|
5
5
|
import { logger } from './utils/logger.js';
|
|
@@ -77,4 +77,4 @@ export const protectedTeacherProcedure = protectedProcedure
|
|
|
77
77
|
// Create caller factory
|
|
78
78
|
export const createCallerFactory = t.createCallerFactory;
|
|
79
79
|
//# sourceMappingURL=trpc.js.map
|
|
80
|
-
//# debugId=
|
|
80
|
+
//# debugId=fe8afe09-5435-5257-8a3f-ef011f89e860
|
package/dist/trpc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trpc.js","sources":["trpc.ts"],"sourceRoot":"/","sourcesContent":["import { initTRPC, TRPCError } from '@trpc/server';\nimport { ZodError } from 'zod';\nimport { logger } from './utils/logger.js';\nimport { prisma } from './lib/prisma.js';\nimport { createLoggingMiddleware } from './middleware/logging.js';\nimport { createAuthMiddleware } from './middleware/auth.js';\nimport { Request, Response } from 'express';\nimport { z } from 'zod';\nimport { handlePrismaError, PrismaErrorInfo } from './utils/prismaErrorHandler.js';\n\ninterface CreateContextOptions {\n req: Request;\n res: Response;\n}\n\nexport type Context = {\n req: Request;\n res: Response;\n user: { id: string } | null;\n meta?: {\n classId?: string;\n institutionId?: string;\n };\n};\n\nexport const createTRPCContext = async (opts: CreateContextOptions): Promise<Context> => {\n const { req, res } = opts;\n \n // Get user from session/token\n const token = req.headers.authorization?.split(' ')[1];\n const user = token ? await prisma.user.findFirst({\n where: {\n sessions: {\n some: {\n id: token\n }\n },\n },\n select: {\n id: true,\n }\n }) : null;\n \n return {\n req,\n res,\n user,\n meta: {},\n };\n};\n\nexport const t = initTRPC.context<Context>().create({\n errorFormatter({ shape, error }) {\n // Handle Prisma errors specifically\n let prismaErrorInfo: PrismaErrorInfo | null = null;\n if (error.cause) {\n try {\n prismaErrorInfo = handlePrismaError(error.cause);\n } catch (e) {\n // If Prisma error handling fails, continue with normal error handling\n }\n }\n\n logger.error('tRPC Error', {\n code: shape.code,\n message: error.message,\n cause: error.cause,\n stack: error.stack,\n prismaError: prismaErrorInfo,\n });\n\n return {\n ...shape,\n data: {\n ...shape.data,\n zodError:\n error.cause instanceof ZodError ? error.cause.flatten() : null,\n prismaError: prismaErrorInfo,\n },\n };\n },\n});\n\n// Create middleware\nconst loggingMiddleware = createLoggingMiddleware(t);\nconst { isAuthed, isMemberInClass, isTeacherInClass } = createAuthMiddleware(t);\n\n// Base procedures\nexport const createTRPCRouter = t.router;\nexport const publicProcedure = t.procedure.use(loggingMiddleware);\n\n// Protected procedures\nexport const protectedProcedure = publicProcedure.use(isAuthed);\n\nexport const protectedClassMemberProcedure = protectedProcedure\n .input(z.object({ classId: z.string() }).passthrough())\n .use(isMemberInClass);\n\nexport const protectedTeacherProcedure = protectedProcedure\n .input(z.object({ classId: z.string() }).passthrough())\n .use(isTeacherInClass);\n\n\n// Create caller factory\nexport const createCallerFactory = t.createCallerFactory; "],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAa,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAmB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"trpc.js","sources":["trpc.ts"],"sourceRoot":"/","sourcesContent":["import { initTRPC, TRPCError } from '@trpc/server';\nimport { ZodError } from 'zod';\nimport { logger } from './utils/logger.js';\nimport { prisma } from './lib/prisma.js';\nimport { createLoggingMiddleware } from './middleware/logging.js';\nimport { createAuthMiddleware } from './middleware/auth.js';\nimport { Request, Response } from 'express';\nimport { z } from 'zod';\nimport { handlePrismaError, PrismaErrorInfo } from './utils/prismaErrorHandler.js';\nimport { generalLimiter } from './middleware/security.js';\n\ninterface CreateContextOptions {\n req: Request;\n res: Response;\n}\n\nexport type Context = {\n req: Request;\n res: Response;\n user: { id: string } | null;\n meta?: {\n classId?: string;\n institutionId?: string;\n };\n};\n\nexport const createTRPCContext = async (opts: CreateContextOptions): Promise<Context> => {\n const { req, res } = opts;\n \n // Get user from session/token\n const token = req.headers.authorization?.split(' ')[1];\n const user = token ? await prisma.user.findFirst({\n where: {\n sessions: {\n some: {\n id: token\n }\n },\n },\n select: {\n id: true,\n }\n }) : null;\n \n return {\n req,\n res,\n user,\n meta: {},\n };\n};\n\nexport const t = initTRPC.context<Context>().create({\n errorFormatter({ shape, error }) {\n // Handle Prisma errors specifically\n let prismaErrorInfo: PrismaErrorInfo | null = null;\n if (error.cause) {\n try {\n prismaErrorInfo = handlePrismaError(error.cause);\n } catch (e) {\n // If Prisma error handling fails, continue with normal error handling\n }\n }\n\n logger.error('tRPC Error', {\n code: shape.code,\n message: error.message,\n cause: error.cause,\n stack: error.stack,\n prismaError: prismaErrorInfo,\n });\n\n return {\n ...shape,\n data: {\n ...shape.data,\n zodError:\n error.cause instanceof ZodError ? error.cause.flatten() : null,\n prismaError: prismaErrorInfo,\n },\n };\n },\n});\n\n// Create middleware\nconst loggingMiddleware = createLoggingMiddleware(t);\nconst { isAuthed, isMemberInClass, isTeacherInClass } = createAuthMiddleware(t);\n\n// Base procedures\nexport const createTRPCRouter = t.router;\nexport const publicProcedure = t.procedure.use(loggingMiddleware);\n\n\n// Protected procedures\nexport const protectedProcedure = publicProcedure.use(isAuthed);\n\nexport const protectedClassMemberProcedure = protectedProcedure\n .input(z.object({ classId: z.string() }).passthrough())\n .use(isMemberInClass);\n\nexport const protectedTeacherProcedure = protectedProcedure\n .input(z.object({ classId: z.string() }).passthrough())\n .use(isTeacherInClass);\n\n\n// Create caller factory\nexport const createCallerFactory = t.createCallerFactory; "],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAa,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,C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mBAAmB,GAAG,CAAC,CAAC,mBAAmB,CAAC","debug_id":"fe8afe09-5435-5257-8a3f-ef011f89e860"}
|
package/dist/utils/email.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import nodemailer from 'nodemailer';
|
|
2
|
-
|
|
2
|
+
type sendMailProps = {
|
|
3
|
+
from: string;
|
|
4
|
+
to: string;
|
|
5
|
+
subject: string;
|
|
6
|
+
text: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const transport: nodemailer.Transporter<import("nodemailer/lib/smtp-transport/index.js").SentMessageInfo, import("nodemailer/lib/smtp-transport/index.js").Options>;
|
|
9
|
+
export declare const sendMail: ({ from, to, subject, text }: sendMailProps) => Promise<void>;
|
|
10
|
+
export {};
|
|
3
11
|
//# sourceMappingURL=email.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.d.ts","sourceRoot":"/","sources":["utils/email.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"/","sources":["utils/email.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAKpC,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAGF,eAAO,MAAM,SAAS,oJAQlB,CAAC;AAGL,eAAO,MAAM,QAAQ,GAAU,6BAA6B,aAAa,kBAaxE,CAAC"}
|
package/dist/utils/email.js
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
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]="cc19d062-bf4e-5d8e-a791-0752f4a45c7d")}catch(e){}}();
|
|
3
3
|
import nodemailer from 'nodemailer';
|
|
4
|
+
import { env } from '../lib/config/env.js';
|
|
5
|
+
import { logger } from './logger.js';
|
|
4
6
|
export const transport = nodemailer.createTransport({
|
|
5
|
-
host:
|
|
7
|
+
host: env.EMAIL_HOST,
|
|
6
8
|
port: 587,
|
|
7
9
|
secure: false,
|
|
8
10
|
auth: {
|
|
9
|
-
user:
|
|
10
|
-
pass:
|
|
11
|
+
user: env.EMAIL_USER,
|
|
12
|
+
pass: env.EMAIL_PASS,
|
|
11
13
|
},
|
|
12
14
|
});
|
|
15
|
+
export const sendMail = async ({ from, to, subject, text }) => {
|
|
16
|
+
// Wrapper function for sending emails
|
|
17
|
+
if (env.EMAIL_DRY_RUN == "true") {
|
|
18
|
+
logger.info(`Email dry run enabled. Would have sent email to ${to} from ${from} with subject ${subject} and text ${text}`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
await transport.sendMail({
|
|
22
|
+
from,
|
|
23
|
+
to,
|
|
24
|
+
subject,
|
|
25
|
+
text,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
13
28
|
//# sourceMappingURL=email.js.map
|
|
14
|
-
//# debugId=
|
|
29
|
+
//# debugId=cc19d062-bf4e-5d8e-a791-0752f4a45c7d
|
package/dist/utils/email.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.js","sources":["utils/email.ts"],"sourceRoot":"/","sourcesContent":["import nodemailer from 'nodemailer';\n\nexport const transport = nodemailer.createTransport({\n host:
|
|
1
|
+
{"version":3,"file":"email.js","sources":["utils/email.ts"],"sourceRoot":"/","sourcesContent":["import nodemailer from 'nodemailer';\nimport { env } from '../lib/config/env.js';\nimport { logger } from './logger.js';\n\n\ntype sendMailProps = {\n from: string;\n to: string;\n subject: string;\n text: string;\n};\n\n\nexport const transport = nodemailer.createTransport({\n host: env.EMAIL_HOST,\n port: 587,\n secure: false,\n auth: {\n user: env.EMAIL_USER,\n pass: env.EMAIL_PASS,\n },\n });\n\n\nexport const sendMail = async ({ from, to, subject, text }: sendMailProps) => {\n // Wrapper function for sending emails\n if (env.EMAIL_DRY_RUN == \"true\") {\n logger.info(`Email dry run enabled. Would have sent email to ${to} from ${from} with subject ${subject} and text ${text}`);\n return;\n }\n \n await transport.sendMail({\n from,\n to,\n subject,\n text,\n });\n};\n"],"names":[],"mappings":";;AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAWrC,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,eAAe,CAAC;IAChD,IAAI,EAAE,GAAG,CAAC,UAAU;IACpB,IAAI,EAAE,GAAG;IACT,MAAM,EAAE,KAAK;IACb,IAAI,EAAE;QACJ,IAAI,EAAE,GAAG,CAAC,UAAU;QACpB,IAAI,EAAE,GAAG,CAAC,UAAU;KACrB;CACF,CAAC,CAAC;AAGL,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAiB,EAAE,EAAE;IAC3E,sCAAsC;IACtC,IAAI,GAAG,CAAC,aAAa,IAAI,MAAM,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,mDAAmD,EAAE,SAAS,IAAI,iBAAiB,OAAO,aAAa,IAAI,EAAE,CAAC,CAAC;QAC3H,OAAO;IACT,CAAC;IAED,MAAM,SAAS,CAAC,QAAQ,CAAC;QACvB,IAAI;QACJ,EAAE;QACF,OAAO;QACP,IAAI;KACL,CAAC,CAAC;AACL,CAAC,CAAC","debug_id":"cc19d062-bf4e-5d8e-a791-0752f4a45c7d"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
|
+
import { ZodSchema } from 'zod';
|
|
2
3
|
export declare const inferenceClient: OpenAI;
|
|
4
|
+
export declare const openAIClient: OpenAI;
|
|
3
5
|
export interface LabChatContext {
|
|
4
6
|
subject: string;
|
|
5
7
|
topic: string;
|
|
@@ -39,6 +41,7 @@ export declare function sendAIMessage(content: string, conversationId: string, o
|
|
|
39
41
|
conversationId: string;
|
|
40
42
|
createdAt: Date;
|
|
41
43
|
}>;
|
|
44
|
+
export declare function inference(content: string, format?: ZodSchema): Promise<string | object>;
|
|
42
45
|
/**
|
|
43
46
|
* Simple inference function for general use
|
|
44
47
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inference.d.ts","sourceRoot":"/","sources":["utils/inference.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"inference.d.ts","sourceRoot":"/","sources":["utils/inference.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAM5B,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAKhC,eAAO,MAAM,eAAe,QAG1B,CAAC;AAEH,eAAO,MAAM,YAAY,QAAe,CAAC;AAGzC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,CAAC;IACrD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,MAA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B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGvD"}
|
package/dist/utils/inference.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
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]="67ba65ca-718b-5e41-8dc8-b8d14965b16a")}catch(e){}}();
|
|
3
3
|
import OpenAI from 'openai';
|
|
4
4
|
import { logger } from './logger.js';
|
|
5
5
|
import { prisma } from '../lib/prisma.js';
|
|
6
6
|
import { pusher } from '../lib/pusher.js';
|
|
7
7
|
import { ensureAIUserExists, getAIUserId } from './aiUser.js';
|
|
8
|
+
import { env } from '../lib/config/env.js';
|
|
9
|
+
import { zodTextFormat } from "openai/helpers/zod";
|
|
8
10
|
export const inferenceClient = new OpenAI({
|
|
9
|
-
apiKey:
|
|
10
|
-
baseURL:
|
|
11
|
+
apiKey: env.INFERENCE_API_KEY,
|
|
12
|
+
baseURL: env.INFERENCE_API_BASE_URL,
|
|
11
13
|
});
|
|
14
|
+
export const openAIClient = new OpenAI();
|
|
12
15
|
/**
|
|
13
16
|
* Centralized function to send AI messages to conversations
|
|
14
17
|
* Handles database storage and Pusher broadcasting
|
|
@@ -77,13 +80,44 @@ export async function sendAIMessage(content, conversationId, options = {}) {
|
|
|
77
80
|
createdAt: aiMessage.createdAt,
|
|
78
81
|
};
|
|
79
82
|
}
|
|
83
|
+
export async function inference(content, format) {
|
|
84
|
+
try {
|
|
85
|
+
const completion = await openAIClient.responses.parse({
|
|
86
|
+
model: 'gpt-5-nano',
|
|
87
|
+
input: [
|
|
88
|
+
{
|
|
89
|
+
role: 'user',
|
|
90
|
+
content: content,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
...(format ? { text: {
|
|
94
|
+
format: zodTextFormat(format, "newton_response_format"),
|
|
95
|
+
},
|
|
96
|
+
} : {}),
|
|
97
|
+
});
|
|
98
|
+
if (!completion) {
|
|
99
|
+
throw new Error('No response generated from inference API');
|
|
100
|
+
}
|
|
101
|
+
// if (format) {
|
|
102
|
+
// if (typeof completion.output === 'string') {
|
|
103
|
+
// return JSON.parse(completion.output);
|
|
104
|
+
// }
|
|
105
|
+
// return JSON.parse(completion.output);
|
|
106
|
+
// }
|
|
107
|
+
return completion.output_parsed;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
logger.error('Failed to generate inference response', { error });
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
80
114
|
/**
|
|
81
115
|
* Simple inference function for general use
|
|
82
116
|
*/
|
|
83
117
|
export async function generateInferenceResponse(subject, question, options = {}) {
|
|
84
|
-
const { model = '
|
|
118
|
+
const { model = 'gpt-5-nano', maxTokens = 500 } = options;
|
|
85
119
|
try {
|
|
86
|
-
const completion = await
|
|
120
|
+
const completion = await openAIClient.chat.completions.create({
|
|
87
121
|
model,
|
|
88
122
|
messages: [
|
|
89
123
|
{
|
|
@@ -119,7 +153,7 @@ export async function generateInferenceResponse(subject, question, options = {})
|
|
|
119
153
|
* Validate inference configuration
|
|
120
154
|
*/
|
|
121
155
|
export function validateInferenceConfig() {
|
|
122
|
-
if (!
|
|
156
|
+
if (!env.INFERENCE_API_KEY) {
|
|
123
157
|
logger.error('Inference API key not configured for Cohere');
|
|
124
158
|
return false;
|
|
125
159
|
}
|
|
@@ -149,4 +183,4 @@ export function estimateTokenCount(text) {
|
|
|
149
183
|
return Math.ceil(text.length / 4);
|
|
150
184
|
}
|
|
151
185
|
//# sourceMappingURL=inference.js.map
|
|
152
|
-
//# debugId=
|
|
186
|
+
//# debugId=67ba65ca-718b-5e41-8dc8-b8d14965b16a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inference.js","sources":["utils/inference.ts"],"sourceRoot":"/","sourcesContent":["import OpenAI from 'openai';\nimport { logger } from './logger.js';\nimport { prisma } from '../lib/prisma.js';\nimport { pusher } from '../lib/pusher.js';\nimport { ensureAIUserExists, getAIUserId } from './aiUser.js';\n\n\nexport const inferenceClient = new OpenAI({\n apiKey: process.env.INFERENCE_API_KEY,\n baseURL: process.env.INFERENCE_API_BASE_URL,\n});\n\n// Types for lab chat context\nexport interface LabChatContext {\n subject: string;\n topic: string;\n difficulty: 'beginner' | 'intermediate' | 'advanced';\n objectives: string[];\n resources?: string[];\n persona: string;\n constraints: string[];\n examples?: any[];\n metadata?: Record<string, any>;\n}\n\nexport interface InferenceResponse {\n content: string;\n model: string;\n tokensUsed: number;\n finishReason: string;\n}\n\n/**\n * Centralized function to send AI messages to conversations\n * Handles database storage and Pusher broadcasting\n */\nexport async function sendAIMessage(\n content: string,\n conversationId: string,\n options: {\n subject?: string;\n attachments?: {\n connect: { id: string }[];\n };\n customSender?: {\n displayName: string;\n profilePicture?: string | null;\n };\n } = {}\n): Promise<{\n id: string;\n content: string;\n senderId: string;\n conversationId: string;\n createdAt: Date;\n}> {\n // Ensure AI user exists\n await ensureAIUserExists();\n\n // Create message in database\n const aiMessage = await prisma.message.create({\n data: {\n content,\n senderId: getAIUserId(),\n conversationId,\n ...(options.attachments && {\n attachments: {\n connect: options.attachments.connect,\n },\n }),\n },\n include: {\n attachments: true,\n },\n });\n\n logger.info('AI Message sent', {\n messageId: aiMessage.id,\n conversationId,\n contentLength: content.length,\n });\n\n // Prepare sender info\n const senderInfo = {\n id: getAIUserId(),\n username: 'Newton_AI',\n profile: {\n displayName: \"Newton AI\",\n profilePicture: options.customSender?.profilePicture || null,\n },\n };\n\n // Broadcast via Pusher\n try {\n await pusher.trigger(`conversation-${conversationId}`, 'new-message', {\n id: aiMessage.id,\n content: aiMessage.content,\n senderId: getAIUserId(),\n conversationId: aiMessage.conversationId,\n createdAt: aiMessage.createdAt,\n sender: senderInfo,\n mentionedUserIds: [],\n attachments: aiMessage.attachments.map(attachment => ({\n id: attachment.id,\n attachmentId: attachment.id,\n name: attachment.name,\n type: attachment.type,\n size: attachment.size,\n path: attachment.path,\n })),\n });\n } catch (error) {\n logger.error('Failed to broadcast AI message:', { error, messageId: aiMessage.id });\n }\n\n return {\n id: aiMessage.id,\n content: aiMessage.content,\n senderId: getAIUserId(),\n conversationId: aiMessage.conversationId,\n createdAt: aiMessage.createdAt,\n };\n}\n\n/**\n * Simple inference function for general use\n */\nexport async function generateInferenceResponse(\n subject: string,\n question: string,\n options: {\n model?: string;\n maxTokens?: number;\n } = {}\n): Promise<InferenceResponse> {\n const { model = 'command-r-plus', maxTokens = 500 } = options;\n\n try {\n const completion = await inferenceClient.chat.completions.create({\n model,\n messages: [\n {\n role: 'system',\n content: `You are a helpful educational assistant for ${subject}. Provide clear, concise, and accurate answers. Keep responses educational and appropriate for students.`,\n },\n {\n role: 'user',\n content: question,\n },\n ],\n max_tokens: maxTokens,\n temperature: 0.5,\n // Remove OpenAI-specific parameters for Cohere compatibility\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 return {\n content: response,\n model,\n tokensUsed: completion.usage?.total_tokens || 0,\n finishReason: completion.choices[0]?.finish_reason || 'unknown',\n };\n\n } catch (error) {\n logger.error('Failed to generate inference response', { error, subject, question: question.substring(0, 50) + '...' });\n throw error;\n }\n}\n\n/**\n * Validate inference configuration\n */\nexport function validateInferenceConfig(): boolean {\n if (!process.env.INFERENCE_API_KEY) {\n logger.error('Inference API key not configured for Cohere');\n return false;\n }\n return true;\n}\n\n/**\n * Get available inference models (for admin/config purposes)\n */\nexport async function getAvailableModels(): Promise<string[]> {\n try {\n const models = await inferenceClient.models.list();\n return models.data\n .filter(model => model.id.includes('command'))\n .map(model => model.id)\n .sort();\n } catch (error) {\n logger.error('Failed to fetch inference models', { error });\n return ['command-r-plus', 'command-r', 'command-light']; // Fallback Cohere models\n }\n}\n\n/**\n * Estimate token count for a message (rough approximation)\n */\nexport function estimateTokenCount(text: string): number {\n // Rough approximation: 1 token ≈ 4 characters for English text\n return Math.ceil(text.length / 4);\n}"],"names":[],"mappings":";;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG9D,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC;IACxC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;IACrC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB;CAC5C,CAAC,CAAC;AAsBH;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAe,EACf,cAAsB,EACtB,UASI,EAAE;IAQN,wBAAwB;IACxB,MAAM,kBAAkB,EAAE,CAAC;IAE3B,6BAA6B;IAC7B,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAC5C,IAAI,EAAE;YACJ,OAAO;YACP,QAAQ,EAAE,WAAW,EAAE;YACvB,cAAc;YACd,GAAG,CAAC,OAAO,CAAC,WAAW,IAAI;gBACzB,WAAW,EAAE;oBACX,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO;iBACrC;aACF,CAAC;SACH;QACD,OAAO,EAAE;YACP,WAAW,EAAE,IAAI;SAClB;KACF,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE;QAC7B,SAAS,EAAE,SAAS,CAAC,EAAE;QACvB,c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vH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAC5D,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACnD,OAAO,MAAM,CAAC,IAAI;aACf,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;aAC7C,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;aACtB,IAAI,EAAE,CAAC;IACZ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,gBAAgB,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,yBAAyB;IACpF,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,+DAA+D;IAC/D,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpC,CAAC","debug_id":"52f0ec7b-6543-5ebc-bde6-cbbfeac779aa"}
|
|
1
|
+
{"version":3,"file":"inference.js","sources":["utils/inference.ts"],"sourceRoot":"/","sourcesContent":["import OpenAI from 'openai';\nimport { logger } from './logger.js';\nimport { prisma } from '../lib/prisma.js';\nimport { pusher } from '../lib/pusher.js';\nimport { ensureAIUserExists, getAIUserId } from './aiUser.js';\nimport { env } from '../lib/config/env.js';\nimport { ZodSchema } from 'zod';\nimport { zodTextFormat } from \"openai/helpers/zod\";\n\n\n\nexport const inferenceClient = new OpenAI({\n apiKey: env.INFERENCE_API_KEY,\n baseURL: env.INFERENCE_API_BASE_URL,\n});\n\nexport const openAIClient = new OpenAI();\n\n// Types for lab chat context\nexport interface LabChatContext {\n subject: string;\n topic: string;\n difficulty: 'beginner' | 'intermediate' | 'advanced';\n objectives: string[];\n resources?: string[];\n persona: string;\n constraints: string[];\n examples?: any[];\n metadata?: Record<string, any>;\n}\n\nexport interface InferenceResponse {\n content: string;\n model: string;\n tokensUsed: number;\n finishReason: string;\n}\n\n/**\n * Centralized function to send AI messages to conversations\n * Handles database storage and Pusher broadcasting\n */\nexport async function sendAIMessage(\n content: string,\n conversationId: string,\n options: {\n subject?: string;\n attachments?: {\n connect: { id: string }[];\n };\n customSender?: {\n displayName: string;\n profilePicture?: string | null;\n };\n } = {}\n): Promise<{\n id: string;\n content: string;\n senderId: string;\n conversationId: string;\n createdAt: Date;\n}> {\n // Ensure AI user exists\n await ensureAIUserExists();\n\n // Create message in database\n const aiMessage = await prisma.message.create({\n data: {\n content,\n senderId: getAIUserId(),\n conversationId,\n ...(options.attachments && {\n attachments: {\n connect: options.attachments.connect,\n },\n }),\n },\n include: {\n attachments: true,\n },\n });\n\n logger.info('AI Message sent', {\n messageId: aiMessage.id,\n conversationId,\n contentLength: content.length,\n });\n\n // Prepare sender info\n const senderInfo = {\n id: getAIUserId(),\n username: 'Newton_AI',\n profile: {\n displayName: \"Newton AI\",\n profilePicture: options.customSender?.profilePicture || null,\n },\n };\n\n // Broadcast via Pusher\n try {\n await pusher.trigger(`conversation-${conversationId}`, 'new-message', {\n id: aiMessage.id,\n content: aiMessage.content,\n senderId: getAIUserId(),\n conversationId: aiMessage.conversationId,\n createdAt: aiMessage.createdAt,\n sender: senderInfo,\n mentionedUserIds: [],\n attachments: aiMessage.attachments.map(attachment => ({\n id: attachment.id,\n attachmentId: attachment.id,\n name: attachment.name,\n type: attachment.type,\n size: attachment.size,\n path: attachment.path,\n })),\n });\n } catch (error) {\n logger.error('Failed to broadcast AI message:', { error, messageId: aiMessage.id });\n }\n\n return {\n id: aiMessage.id,\n content: aiMessage.content,\n senderId: getAIUserId(),\n conversationId: aiMessage.conversationId,\n createdAt: aiMessage.createdAt,\n };\n}\n\nexport async function inference(\n content: string,\n format?: ZodSchema\n): Promise<string | object> {\n try {\n\n const completion = await openAIClient.responses.parse({\n model: 'gpt-5-nano',\n input: [\n {\n role: 'user',\n content: content,\n },\n ],\n ...(format ? { text: {\n format: zodTextFormat(format, \"newton_response_format\"),\n },\n } : {}),\n });\n\n\n if (!completion) {\n throw new Error('No response generated from inference API');\n }\n\n // if (format) {\n // if (typeof completion.output === 'string') {\n // return JSON.parse(completion.output);\n // }\n // return JSON.parse(completion.output);\n // }\n\n return completion.output_parsed;\n } catch (error) {\n logger.error('Failed to generate inference response', { error });\n throw error;\n }\n}\n\n/**\n * Simple inference function for general use\n */\nexport async function generateInferenceResponse(\n subject: string,\n question: string,\n options: {\n model?: string;\n maxTokens?: number;\n } = {}\n): Promise<InferenceResponse> {\n const { model = 'gpt-5-nano', maxTokens = 500 } = options;\n\n try {\n const completion = await openAIClient.chat.completions.create({\n model,\n messages: [\n {\n role: 'system',\n content: `You are a helpful educational assistant for ${subject}. Provide clear, concise, and accurate answers. Keep responses educational and appropriate for students.`,\n },\n {\n role: 'user',\n content: question,\n },\n ],\n max_tokens: maxTokens,\n temperature: 0.5,\n // Remove OpenAI-specific parameters for Cohere compatibility\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 return {\n content: response,\n model,\n tokensUsed: completion.usage?.total_tokens || 0,\n finishReason: completion.choices[0]?.finish_reason || 'unknown',\n };\n\n } catch (error) {\n logger.error('Failed to generate inference response', { error, subject, question: question.substring(0, 50) + '...' });\n throw error;\n }\n}\n\n/**\n * Validate inference configuration\n */\nexport function validateInferenceConfig(): boolean {\n if (!env.INFERENCE_API_KEY) {\n logger.error('Inference API key not configured for Cohere');\n return false;\n }\n return true;\n}\n\n/**\n * Get available inference models (for admin/config purposes)\n */\nexport async function getAvailableModels(): Promise<string[]> {\n try {\n const models = await inferenceClient.models.list();\n return models.data\n .filter(model => model.id.includes('command'))\n .map(model => model.id)\n .sort();\n } catch (error) {\n logger.error('Failed to fetch inference models', { error });\n return ['command-r-plus', 'command-r', 'command-light']; // Fallback Cohere models\n }\n}\n\n/**\n * Estimate token count for a message (rough approximation)\n */\nexport function estimateTokenCount(text: string): number {\n // Rough approximation: 1 token ≈ 4 characters for English text\n return Math.ceil(text.length / 4);\n}"],"names":[],"mappings":";;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAInD,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC;IACxC,MAAM,EAAE,GAAG,CAAC,iBAAiB;IAC7B,OAAO,EAAE,GAAG,CAAC,sBAAsB;CACpC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,MAAM,EAAE,CAAC;AAsBzC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAe,EACf,cAAsB,EACtB,UASI,EAAE;IAQN,wBAAwB;IACxB,MAAM,kBAAkB,EAAE,CAAC;IAE3B,6BAA6B;IAC7B,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAC5C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AAuB;IACrC,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;QAC3B,MAAM,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAC5D,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACnD,OAAO,MAAM,CAAC,IAAI;aACf,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;aAC7C,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;aACtB,IAAI,EAAE,CAAC;IACZ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,gBAAgB,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,yBAAyB;IACpF,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,+DAA+D;IAC/D,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpC,CAAC","debug_id":"67ba65ca-718b-5e41-8dc8-b8d14965b16a"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"/","sources":["utils/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"/","sources":["utils/logger.ts"],"names":[],"mappings":"AACA,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;IACf,KAAK,UAAU;CAChB;AAED,KAAK,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAyC3D,cAAM,MAAM;IACV,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,IAAI,CAAU;IACtB,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,WAAW,CAA2B;IAE9C,OAAO;WA8BO,WAAW,IAAI,MAAM;IAO5B,OAAO,CAAC,IAAI,EAAE,OAAO;IAI5B,OAAO,CAAC,SAAS;IAsBjB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,GAAG;IAqCJ,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAInD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAInD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAIpD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAG5D;AAED,eAAO,MAAM,MAAM,QAAuB,CAAC"}
|
package/dist/utils/logger.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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]="3ad19480-6fd4-5009-abf4-d8f8caeb9a0e")}catch(e){}}();
|
|
3
3
|
export var LogLevel;
|
|
4
4
|
(function (LogLevel) {
|
|
5
5
|
LogLevel["INFO"] = "info";
|
|
@@ -42,7 +42,7 @@ class Logger {
|
|
|
42
42
|
constructor() {
|
|
43
43
|
// this.isDevelopment = process.env.NODE_ENV === 'development';
|
|
44
44
|
this.isDevelopment = true;
|
|
45
|
-
this.mode = process.env.LOG_MODE || 'normal';
|
|
45
|
+
this.mode = (process.env.NODE_ENV === 'test' ? 'silent' : (process.env.LOG_MODE || 'normal'));
|
|
46
46
|
this.levelColors = {
|
|
47
47
|
[LogLevel.INFO]: colors.blue,
|
|
48
48
|
[LogLevel.WARN]: colors.yellow,
|
|
@@ -154,4 +154,4 @@ class Logger {
|
|
|
154
154
|
}
|
|
155
155
|
export const logger = Logger.getInstance();
|
|
156
156
|
//# sourceMappingURL=logger.js.map
|
|
157
|
-
//# debugId=
|
|
157
|
+
//# debugId=3ad19480-6fd4-5009-abf4-d8f8caeb9a0e
|