diff --git a/apps/nextjs/src/app/api/chat/config.ts b/apps/nextjs/src/app/api/chat/config.ts index 645e827a0..be68098d1 100644 --- a/apps/nextjs/src/app/api/chat/config.ts +++ b/apps/nextjs/src/app/api/chat/config.ts @@ -4,7 +4,7 @@ import { prisma as globalPrisma, type PrismaClientWithAccelerate, } from "@oakai/db"; -import { nanoid } from "ai"; +import { nanoid } from "nanoid"; import { createWebActionsPlugin } from "./webActionsPlugin"; diff --git a/apps/nextjs/src/app/api/chat/errorHandling.test.ts b/apps/nextjs/src/app/api/chat/errorHandling.test.ts index 0a454dc8d..33f618225 100644 --- a/apps/nextjs/src/app/api/chat/errorHandling.test.ts +++ b/apps/nextjs/src/app/api/chat/errorHandling.test.ts @@ -1,6 +1,7 @@ -import { AilaAuthenticationError, AilaThreatDetectionError } from "@oakai/aila"; +import { AilaAuthenticationError } from "@oakai/aila/src/core/AilaError"; +import { AilaThreatDetectionError } from "@oakai/aila/src/features/threatDetection/types"; import * as moderationErrorHandling from "@oakai/aila/src/utils/moderation/moderationErrorHandling"; -import { UserBannedError } from "@oakai/core/src/models/safetyViolations"; +import { UserBannedError } from "@oakai/core/src/models/userBannedError"; import type { TracingSpan } from "@oakai/core/src/tracing/serverTracing"; import { RateLimitExceededError } from "@oakai/core/src/utils/rateLimiting/userBasedRateLimiter"; import type { PrismaClientWithAccelerate } from "@oakai/db"; @@ -37,7 +38,7 @@ describe("handleChatException", () => { expect(response.status).toBe(200); - invariant(response.body instanceof ReadableStream); + invariant(response.body); const message = extractStreamMessage(await consumeStream(response.body)); expect(message).toEqual({ @@ -123,4 +124,4 @@ describe("handleChatException", () => { }); }); }); -}); \ No newline at end of file +}); diff --git a/apps/nextjs/src/app/api/chat/errorHandling.ts b/apps/nextjs/src/app/api/chat/errorHandling.ts index 3bdb68096..4bce0e12b 100644 --- a/apps/nextjs/src/app/api/chat/errorHandling.ts +++ b/apps/nextjs/src/app/api/chat/errorHandling.ts @@ -4,7 +4,7 @@ import type { ErrorDocument, } from "@oakai/aila/src/protocol/jsonPatchProtocol"; import { handleHeliconeError } from "@oakai/aila/src/utils/moderation/moderationErrorHandling"; -import { UserBannedError } from "@oakai/core/src/models/safetyViolations"; +import { UserBannedError } from "@oakai/core/src/models/userBannedError"; import type { TracingSpan } from "@oakai/core/src/tracing/serverTracing"; import { RateLimitExceededError } from "@oakai/core/src/utils/rateLimiting/userBasedRateLimiter"; import type { PrismaClientWithAccelerate } from "@oakai/db"; diff --git a/apps/nextjs/src/app/api/chat/user.test.ts b/apps/nextjs/src/app/api/chat/user.test.ts index 4c9c3cedf..79e139e42 100644 --- a/apps/nextjs/src/app/api/chat/user.test.ts +++ b/apps/nextjs/src/app/api/chat/user.test.ts @@ -1,10 +1,9 @@ -import { inngest } from "@oakai/core"; import { posthogAiBetaServerClient } from "@oakai/core/src/analytics/posthogAiBetaServerClient"; import { RateLimitExceededError } from "@oakai/core/src/utils/rateLimiting/userBasedRateLimiter"; import { reportRateLimitError } from "./user"; -jest.mock("@oakai/core/src/client", () => ({ +jest.mock("@oakai/core/src/inngest", () => ({ inngest: { createFunction: jest.fn(), send: jest.fn(), @@ -63,6 +62,8 @@ describe("chat route user functions", () => { await reportRateLimitError(error, userId, chatId); + const { inngest } = await import("@oakai/core/src/inngest"); + expect(inngest.send).toHaveBeenCalledTimes(1); expect(inngest.send).toHaveBeenCalledWith({ name: "app/slack.notifyRateLimit", diff --git a/apps/nextjs/src/app/api/chat/user.ts b/apps/nextjs/src/app/api/chat/user.ts index dfa8bd629..73a19ff42 100644 --- a/apps/nextjs/src/app/api/chat/user.ts +++ b/apps/nextjs/src/app/api/chat/user.ts @@ -2,7 +2,7 @@ import { auth, clerkClient } from "@clerk/nextjs/server"; import { AilaAuthenticationError } from "@oakai/aila"; import { demoUsers, inngest } from "@oakai/core"; import { posthogAiBetaServerClient } from "@oakai/core/src/analytics/posthogAiBetaServerClient"; -import { UserBannedError } from "@oakai/core/src/models/safetyViolations"; +import { UserBannedError } from "@oakai/core/src/models/userBannedError"; import { withTelemetry } from "@oakai/core/src/tracing/serverTracing"; import { rateLimits } from "@oakai/core/src/utils/rateLimiting/rateLimit"; import { RateLimitExceededError } from "@oakai/core/src/utils/rateLimiting/userBasedRateLimiter"; diff --git a/apps/nextjs/src/app/api/chat/webActionsPlugin.test.ts b/apps/nextjs/src/app/api/chat/webActionsPlugin.test.ts index 76cdd2238..7c82e9b47 100644 --- a/apps/nextjs/src/app/api/chat/webActionsPlugin.test.ts +++ b/apps/nextjs/src/app/api/chat/webActionsPlugin.test.ts @@ -1,13 +1,14 @@ -import { AilaThreatDetectionError } from "@oakai/aila"; import type { AilaPluginContext } from "@oakai/aila/src/core/plugins"; -import { inngest } from "@oakai/core"; -import { UserBannedError } from "@oakai/core/src/models/safetyViolations"; +import { AilaThreatDetectionError } from "@oakai/aila/src/features/threatDetection/types"; +import { UserBannedError } from "@oakai/core/src/models/userBannedError"; import type { PrismaClientWithAccelerate } from "@oakai/db"; import type { Moderation } from "@prisma/client"; import { createWebActionsPlugin } from "./webActionsPlugin"; -jest.mock("@oakai/core", () => ({ +jest.mock("@oakai/core/src/inngest", () => ({ + __esModule: true, + inngest: { send: jest.fn(), }, @@ -66,6 +67,8 @@ describe("webActionsPlugin", () => { enqueue: mockEnqueue, }; + const { inngest } = await import("@oakai/core/src/inngest"); + const plugin = createWebActionsPlugin(prisma, safetyViolations); await plugin.onToxicModeration(moderation, pluginContext); diff --git a/apps/nextjs/src/app/api/chat/webActionsPlugin.ts b/apps/nextjs/src/app/api/chat/webActionsPlugin.ts index 24f69be32..3b24fefeb 100644 --- a/apps/nextjs/src/app/api/chat/webActionsPlugin.ts +++ b/apps/nextjs/src/app/api/chat/webActionsPlugin.ts @@ -1,11 +1,9 @@ -import { AilaThreatDetectionError } from "@oakai/aila"; import type { AilaPlugin } from "@oakai/aila/src/core/plugins"; +import { AilaThreatDetectionError } from "@oakai/aila/src/features/threatDetection/types"; import { handleHeliconeError } from "@oakai/aila/src/utils/moderation/moderationErrorHandling"; -import { - SafetyViolations as defaultSafetyViolations, - inngest, -} from "@oakai/core"; -import { UserBannedError } from "@oakai/core/src/models/safetyViolations"; +import { inngest } from "@oakai/core/src/inngest"; +import { SafetyViolations as defaultSafetyViolations } from "@oakai/core/src/models/safetyViolations"; +import { UserBannedError } from "@oakai/core/src/models/userBannedError"; import type { PrismaClientWithAccelerate } from "@oakai/db"; import { aiLogger } from "@oakai/logger"; import { waitUntil } from "@vercel/functions"; diff --git a/apps/nextjs/src/app/api/sanitizeFilename.test.ts b/apps/nextjs/src/app/api/sanitizeFilename.test.ts index ac8b3d888..e0af33511 100644 --- a/apps/nextjs/src/app/api/sanitizeFilename.test.ts +++ b/apps/nextjs/src/app/api/sanitizeFilename.test.ts @@ -3,9 +3,9 @@ import { sanitizeFilename } from "./sanitizeFilename"; describe("sanitizeFilename", () => { test("should remove special characters", () => { const lessonTitle = - "The econonomy: Boom or Bust? You decide! Let's start, shall we?"; + "The economy: Boom or Bust? You decide! Let's start, shall we?"; expect(sanitizeFilename(lessonTitle)).toBe( - "The econonomy Boom or Bust You decide Lets start shall we", + "The economy Boom or Bust You decide Lets start shall we", ); }); }); diff --git a/packages/aila/src/utils/moderation/moderationErrorHandling.ts b/packages/aila/src/utils/moderation/moderationErrorHandling.ts index 67feb2307..7ff04673e 100644 --- a/packages/aila/src/utils/moderation/moderationErrorHandling.ts +++ b/packages/aila/src/utils/moderation/moderationErrorHandling.ts @@ -1,5 +1,5 @@ import { SafetyViolations as defaultSafetyViolations } from "@oakai/core/src/models/safetyViolations"; -import { UserBannedError } from "@oakai/core/src/models/safetyViolations"; +import { UserBannedError } from "@oakai/core/src/models/userBannedError"; import type { PrismaClientWithAccelerate } from "@oakai/db"; import type { AilaThreatDetectionError } from "../../features/threatDetection/types"; diff --git a/packages/api/src/context.ts b/packages/api/src/context.ts index 31fcd29c7..abf9507b0 100644 --- a/packages/api/src/context.ts +++ b/packages/api/src/context.ts @@ -4,7 +4,7 @@ import type { } from "@clerk/backend/internal"; import { getAuth } from "@clerk/nextjs/server"; import { prisma } from "@oakai/db"; -import { type inferAsyncReturnType } from "@trpc/server"; +import type { inferAsyncReturnType } from "@trpc/server"; import type { NodeHTTPCreateContextFnOptions } from "@trpc/server/adapters/node-http"; import type { NextRequest, NextResponse } from "next/server"; diff --git a/packages/api/src/trpc.ts b/packages/api/src/trpc.ts index 6b84936e8..f31c30298 100644 --- a/packages/api/src/trpc.ts +++ b/packages/api/src/trpc.ts @@ -3,7 +3,7 @@ import { initTRPC } from "@trpc/server"; import { ZodError } from "zod"; import { transformer } from "../transformer"; -import { type Context } from "./context"; +import type { Context } from "./context"; const log = aiLogger("trpc"); diff --git a/packages/core/index.ts b/packages/core/index.ts index ef3c66798..597d7e888 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -31,7 +31,7 @@ import { generatePlansForSubjectLessons } from "./src/functions/subject/generate import { summariseSubjectLessons } from "./src/functions/subject/summariseSubjectLessons"; import { generateTranscriptEmbeddings } from "./src/functions/transcript/generateTranscriptEmbeddings"; -export { inngest } from "./src/client"; +export { inngest } from "./src/inngest"; export * from "./src/data/subjectsAndKeyStages"; export * from "./src/models"; //export * from "./src/models/promptVariants"; diff --git a/packages/core/src/functions/demo/populateDemoStatuses.ts b/packages/core/src/functions/demo/populateDemoStatuses.ts index 92259733b..356f01e5d 100644 --- a/packages/core/src/functions/demo/populateDemoStatuses.ts +++ b/packages/core/src/functions/demo/populateDemoStatuses.ts @@ -1,7 +1,7 @@ import { clerkClient } from "@clerk/nextjs/server"; import { aiLogger } from "@oakai/logger"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { populateDemoStatusesSchema } from "./populateDemoStatuses.schema"; const log = aiLogger("demo"); diff --git a/packages/core/src/functions/lesson/generateLessonQuizEmbeddings.ts b/packages/core/src/functions/lesson/generateLessonQuizEmbeddings.ts index eeff94321..36f2e4788 100644 --- a/packages/core/src/functions/lesson/generateLessonQuizEmbeddings.ts +++ b/packages/core/src/functions/lesson/generateLessonQuizEmbeddings.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { Lessons } from "../../models"; export const generateLessonQuizEmbeddings = inngest.createFunction( diff --git a/packages/core/src/functions/lesson/generatePlan.ts b/packages/core/src/functions/lesson/generatePlan.ts index c3d0c9264..2a2c02232 100644 --- a/packages/core/src/functions/lesson/generatePlan.ts +++ b/packages/core/src/functions/lesson/generatePlan.ts @@ -1,7 +1,7 @@ import { prisma } from "@oakai/db"; import { aiLogger } from "@oakai/logger"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { LessonPlans } from "../../models"; const log = aiLogger("lessons"); diff --git a/packages/core/src/functions/lesson/summarise.ts b/packages/core/src/functions/lesson/summarise.ts index 42e43fb09..52e27b512 100644 --- a/packages/core/src/functions/lesson/summarise.ts +++ b/packages/core/src/functions/lesson/summarise.ts @@ -1,7 +1,7 @@ import { LessonSummaryStatus, prisma } from "@oakai/db"; import { aiLogger } from "@oakai/logger"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { Lessons } from "../../models"; const log = aiLogger("lessons"); diff --git a/packages/core/src/functions/lesson/summariseAll.ts b/packages/core/src/functions/lesson/summariseAll.ts index d16c3f13d..f035f7e7a 100644 --- a/packages/core/src/functions/lesson/summariseAll.ts +++ b/packages/core/src/functions/lesson/summariseAll.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { Lessons } from "../../models"; export const summariseAllLessons = inngest.createFunction( diff --git a/packages/core/src/functions/lessonPlan/embed.ts b/packages/core/src/functions/lessonPlan/embed.ts index 76c1801e5..6fe96c5eb 100644 --- a/packages/core/src/functions/lessonPlan/embed.ts +++ b/packages/core/src/functions/lessonPlan/embed.ts @@ -1,6 +1,6 @@ import { LessonPlanStatus, prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { LessonPlans } from "../../models"; export const embedLessonPlan = inngest.createFunction( diff --git a/packages/core/src/functions/lessonPlan/embedAll.ts b/packages/core/src/functions/lessonPlan/embedAll.ts index c7a09a9f3..9de32b0f2 100644 --- a/packages/core/src/functions/lessonPlan/embedAll.ts +++ b/packages/core/src/functions/lessonPlan/embedAll.ts @@ -1,7 +1,7 @@ import { LessonPlanStatus, prisma } from "@oakai/db"; import { aiLogger } from "@oakai/logger"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { LessonPlans } from "../../models"; const log = aiLogger("lessons"); diff --git a/packages/core/src/functions/lessonPlan/embedAllParts.ts b/packages/core/src/functions/lessonPlan/embedAllParts.ts index 8efd6fd74..8b9244eea 100644 --- a/packages/core/src/functions/lessonPlan/embedAllParts.ts +++ b/packages/core/src/functions/lessonPlan/embedAllParts.ts @@ -1,6 +1,6 @@ import { LessonPlanPartStatus, prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { LessonPlans } from "../../models"; export const embedAllLessonPlanParts = inngest.createFunction( diff --git a/packages/core/src/functions/lessonPlan/embedPart.ts b/packages/core/src/functions/lessonPlan/embedPart.ts index 8b2fd5429..4545fe7f1 100644 --- a/packages/core/src/functions/lessonPlan/embedPart.ts +++ b/packages/core/src/functions/lessonPlan/embedPart.ts @@ -1,6 +1,6 @@ import { LessonPlanPartStatus, prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { LessonPlans } from "../../models"; export const embedLessonPlanPart = inngest.createFunction( diff --git a/packages/core/src/functions/lessonPlan/generateAll.ts b/packages/core/src/functions/lessonPlan/generateAll.ts index d07d0f76f..ccda36e9c 100644 --- a/packages/core/src/functions/lessonPlan/generateAll.ts +++ b/packages/core/src/functions/lessonPlan/generateAll.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; export const generateAllLessonPlans = inngest.createFunction( { diff --git a/packages/core/src/functions/lessonPlan/process.ts b/packages/core/src/functions/lessonPlan/process.ts index 634373d85..33b392ff0 100644 --- a/packages/core/src/functions/lessonPlan/process.ts +++ b/packages/core/src/functions/lessonPlan/process.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { LessonPlans } from "../../models"; export const processLessonPlan = inngest.createFunction( diff --git a/packages/core/src/functions/lessonSummary/embed.ts b/packages/core/src/functions/lessonSummary/embed.ts index 8936e5966..eee51a26a 100644 --- a/packages/core/src/functions/lessonSummary/embed.ts +++ b/packages/core/src/functions/lessonSummary/embed.ts @@ -1,6 +1,6 @@ import { LessonSummaryStatus, prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { LessonSummaries } from "../../models"; export const embedLessonSummary = inngest.createFunction( diff --git a/packages/core/src/functions/lessonSummary/embedAll.ts b/packages/core/src/functions/lessonSummary/embedAll.ts index e39ba0d19..b1e69392a 100644 --- a/packages/core/src/functions/lessonSummary/embedAll.ts +++ b/packages/core/src/functions/lessonSummary/embedAll.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { LessonSummaries } from "../../models"; export const embedAllLessonSummaries = inngest.createFunction( diff --git a/packages/core/src/functions/migrations/addIdsToMessages.ts b/packages/core/src/functions/migrations/addIdsToMessages.ts index 2c461d413..5ca7c4577 100644 --- a/packages/core/src/functions/migrations/addIdsToMessages.ts +++ b/packages/core/src/functions/migrations/addIdsToMessages.ts @@ -2,7 +2,7 @@ import { Prisma, prisma } from "@oakai/db"; import crypto from "crypto"; import { z } from "zod"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { addIdsToMessagesSchema } from "./addIdsToMessages.schema"; const chatSchema = z diff --git a/packages/core/src/functions/migrations/kvChatsToPrisma.ts b/packages/core/src/functions/migrations/kvChatsToPrisma.ts index 58a2f7fa8..7861ad6d8 100644 --- a/packages/core/src/functions/migrations/kvChatsToPrisma.ts +++ b/packages/core/src/functions/migrations/kvChatsToPrisma.ts @@ -4,7 +4,7 @@ import { kv } from "@vercel/kv"; import { z } from "zod"; import { LessonPlanSchemaWhilstStreaming } from "../../../../aila/src/protocol/schema"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { kvChatsToPrismaSchema } from "./kvChatsToPrisma.schema"; const chatSchema = z diff --git a/packages/core/src/functions/quizAnswer/embedAll.ts b/packages/core/src/functions/quizAnswer/embedAll.ts index 5cd963c6e..c7054bdc6 100644 --- a/packages/core/src/functions/quizAnswer/embedAll.ts +++ b/packages/core/src/functions/quizAnswer/embedAll.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { QuizAnswers } from "../../models"; export const embedAllQuizAnswers = inngest.createFunction( diff --git a/packages/core/src/functions/quizAnswer/generateQuizAnswerEmbeddings.ts b/packages/core/src/functions/quizAnswer/generateQuizAnswerEmbeddings.ts index a4006643f..4dcd4f82f 100644 --- a/packages/core/src/functions/quizAnswer/generateQuizAnswerEmbeddings.ts +++ b/packages/core/src/functions/quizAnswer/generateQuizAnswerEmbeddings.ts @@ -1,6 +1,6 @@ import { prisma, QuizAnswerStatus } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { QuizAnswers } from "../../models"; export const generateQuizAnswerEmbeddings = inngest.createFunction( diff --git a/packages/core/src/functions/quizQuestion/embedAll.ts b/packages/core/src/functions/quizQuestion/embedAll.ts index 225643212..c9ee08f52 100644 --- a/packages/core/src/functions/quizQuestion/embedAll.ts +++ b/packages/core/src/functions/quizQuestion/embedAll.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { QuizQuestions } from "../../models"; export const embedAllQuizQuestions = inngest.createFunction( diff --git a/packages/core/src/functions/quizQuestion/generateAll.ts b/packages/core/src/functions/quizQuestion/generateAll.ts index 7b6715151..2f0cb5a18 100644 --- a/packages/core/src/functions/quizQuestion/generateAll.ts +++ b/packages/core/src/functions/quizQuestion/generateAll.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { QuizQuestions } from "../../models"; export const generateAllQuizQuestions = inngest.createFunction( diff --git a/packages/core/src/functions/quizQuestion/generateQuizQuestionEmbeddings.ts b/packages/core/src/functions/quizQuestion/generateQuizQuestionEmbeddings.ts index 3ca3ef4e2..b0d144099 100644 --- a/packages/core/src/functions/quizQuestion/generateQuizQuestionEmbeddings.ts +++ b/packages/core/src/functions/quizQuestion/generateQuizQuestionEmbeddings.ts @@ -1,6 +1,6 @@ import { QuizQuestionStatus, prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { QuizQuestions } from "../../models"; export const generateQuizQuestionEmbeddings = inngest.createFunction( diff --git a/packages/core/src/functions/slack/notifyModeration.ts b/packages/core/src/functions/slack/notifyModeration.ts index c2c7d4cc3..52bf6d8cd 100644 --- a/packages/core/src/functions/slack/notifyModeration.ts +++ b/packages/core/src/functions/slack/notifyModeration.ts @@ -1,4 +1,4 @@ -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { slackNotificationChannelId, slackWebClient, diff --git a/packages/core/src/functions/slack/notifyRateLimit.ts b/packages/core/src/functions/slack/notifyRateLimit.ts index 596802c7e..c1bae15b9 100644 --- a/packages/core/src/functions/slack/notifyRateLimit.ts +++ b/packages/core/src/functions/slack/notifyRateLimit.ts @@ -1,4 +1,4 @@ -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { slackNotificationChannelId, slackWebClient, diff --git a/packages/core/src/functions/slack/notifyUserBan.ts b/packages/core/src/functions/slack/notifyUserBan.ts index ea543d202..b8d59b554 100644 --- a/packages/core/src/functions/slack/notifyUserBan.ts +++ b/packages/core/src/functions/slack/notifyUserBan.ts @@ -1,4 +1,4 @@ -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { slackNotificationChannelId, slackWebClient, diff --git a/packages/core/src/functions/snippet/embedAll.ts b/packages/core/src/functions/snippet/embedAll.ts index d017f9198..60558bd67 100644 --- a/packages/core/src/functions/snippet/embedAll.ts +++ b/packages/core/src/functions/snippet/embedAll.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { Snippets } from "../../models"; export const embedAllSnippets = inngest.createFunction( diff --git a/packages/core/src/functions/snippet/generateForAllQuestions.ts b/packages/core/src/functions/snippet/generateForAllQuestions.ts index 346c7e7b5..ff36f1488 100644 --- a/packages/core/src/functions/snippet/generateForAllQuestions.ts +++ b/packages/core/src/functions/snippet/generateForAllQuestions.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { Snippets } from "../../models"; export const generateSnippetsForAllQuestions = inngest.createFunction( diff --git a/packages/core/src/functions/snippet/generateSnippetEmbeddings.ts b/packages/core/src/functions/snippet/generateSnippetEmbeddings.ts index 269264405..2a890d80c 100644 --- a/packages/core/src/functions/snippet/generateSnippetEmbeddings.ts +++ b/packages/core/src/functions/snippet/generateSnippetEmbeddings.ts @@ -1,6 +1,6 @@ import { SnippetStatus, prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { Snippets } from "../../models"; export const generateSnippetEmbeddings = inngest.createFunction( diff --git a/packages/core/src/functions/statistics/recalculateStatistics.ts b/packages/core/src/functions/statistics/recalculateStatistics.ts index a42084325..54f73ecb5 100644 --- a/packages/core/src/functions/statistics/recalculateStatistics.ts +++ b/packages/core/src/functions/statistics/recalculateStatistics.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { Statistics } from "../../models/statistics"; export const recalculateStatistics = inngest.createFunction( diff --git a/packages/core/src/functions/subject/embedSubjectLessonQuizzes.ts b/packages/core/src/functions/subject/embedSubjectLessonQuizzes.ts index 41e354bd2..859249cf9 100644 --- a/packages/core/src/functions/subject/embedSubjectLessonQuizzes.ts +++ b/packages/core/src/functions/subject/embedSubjectLessonQuizzes.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; interface SimplifiedLesson { id: string; diff --git a/packages/core/src/functions/subject/embedSubjectLessonTranscripts.ts b/packages/core/src/functions/subject/embedSubjectLessonTranscripts.ts index c697e3ccf..c4b9254dd 100644 --- a/packages/core/src/functions/subject/embedSubjectLessonTranscripts.ts +++ b/packages/core/src/functions/subject/embedSubjectLessonTranscripts.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; interface SimplifiedLesson { id: string; diff --git a/packages/core/src/functions/subject/generatePlansForSubjectLessons.ts b/packages/core/src/functions/subject/generatePlansForSubjectLessons.ts index 7a1c95e3b..dd734c769 100644 --- a/packages/core/src/functions/subject/generatePlansForSubjectLessons.ts +++ b/packages/core/src/functions/subject/generatePlansForSubjectLessons.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; interface SimplifiedLesson { id: string; diff --git a/packages/core/src/functions/subject/summariseSubjectLessons.ts b/packages/core/src/functions/subject/summariseSubjectLessons.ts index 305c42386..0a79c58d8 100644 --- a/packages/core/src/functions/subject/summariseSubjectLessons.ts +++ b/packages/core/src/functions/subject/summariseSubjectLessons.ts @@ -1,6 +1,6 @@ import { prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; interface SimplifiedLesson { id: string; diff --git a/packages/core/src/functions/transcript/generateTranscriptEmbeddings.ts b/packages/core/src/functions/transcript/generateTranscriptEmbeddings.ts index 20912d10e..65a5e582f 100644 --- a/packages/core/src/functions/transcript/generateTranscriptEmbeddings.ts +++ b/packages/core/src/functions/transcript/generateTranscriptEmbeddings.ts @@ -1,6 +1,6 @@ import { TranscriptStatus, prisma } from "@oakai/db"; -import { inngest } from "../../client"; +import { inngest } from "../../inngest"; import { Transcripts } from "../../models/transcript"; export const generateTranscriptEmbeddings = inngest.createFunction( diff --git a/packages/core/src/inngest/index.ts b/packages/core/src/inngest/index.ts new file mode 100644 index 000000000..9aba0f2c5 --- /dev/null +++ b/packages/core/src/inngest/index.ts @@ -0,0 +1,51 @@ +import { structuredLogger } from "@oakai/logger"; +import { EventSchemas, Inngest } from "inngest"; +import getConfig from "next/config"; + +import types from "../functions/event-types"; +import { eventLogger } from "../middleware/eventLogger"; + +let serverRuntimeConfig; +try { + const { serverRuntimeConfig: nextServerRuntimeConfig } = getConfig(); + serverRuntimeConfig = nextServerRuntimeConfig; +} catch (e) { + //console.log("No Next environment"); +} +const CONTEXT = serverRuntimeConfig?.DEPLOY_CONTEXT; +const BRANCH = serverRuntimeConfig?.BRANCH; + +function getInngestEnv() { + if (CONTEXT === "production") { + return "production"; + } else if (CONTEXT === "deploy-preview" && BRANCH) { + // Naively slugify, removing any non-alphanumeric + return BRANCH.replace(/\W/g, "-"); + } else { + return "development"; + } +} + +function isJestEnvironment() { + return process.env.JEST_WORKER_ID !== undefined; +} + +const inngestEnv = getInngestEnv(); +const inngestEventKey = process.env.INNGEST_EVENT_KEY; + +if (!inngestEventKey) { + throw new Error("Missing env var INNGEST_EVENT_KEY"); +} + +console.log("Inngest env:", inngestEnv); + +export const inngest = new Inngest({ + name: "Oak AI", + id: "oak-ai", + schemas: new EventSchemas().fromZod(types), + eventKey: inngestEventKey, + env: inngestEnv, + logger: structuredLogger, + middleware: [eventLogger(inngestEnv, inngestEventKey)], + isDev: process.env.NODE_ENV === "development" || isJestEnvironment(), +}); diff --git a/packages/core/src/models/lessonPlans.ts b/packages/core/src/models/lessonPlans.ts index ef907ceeb..7505fd60b 100644 --- a/packages/core/src/models/lessonPlans.ts +++ b/packages/core/src/models/lessonPlans.ts @@ -15,7 +15,7 @@ import yaml from "yaml"; import { LLMResponseJsonSchema } from "../../../aila/src/protocol/jsonPatchProtocol"; import { LessonPlanJsonSchema } from "../../../aila/src/protocol/schema"; -import { inngest } from "../client"; +import { inngest } from "../inngest"; import { createOpenAIClient } from "../llm/openai"; import { template } from "../prompts/lesson-assistant"; import { RAG } from "../rag"; diff --git a/packages/core/src/models/lessonSummaries.ts b/packages/core/src/models/lessonSummaries.ts index 111c935ec..edcae0b98 100644 --- a/packages/core/src/models/lessonSummaries.ts +++ b/packages/core/src/models/lessonSummaries.ts @@ -3,7 +3,7 @@ import { Prisma } from "@prisma/client"; import { OpenAIEmbeddings } from "langchain/embeddings/openai"; import { PrismaVectorStore } from "langchain/vectorstores/prisma"; -import { inngest } from "../client"; +import { inngest } from "../inngest"; import { RAG } from "../rag"; import { embedWithCache } from "../utils/embeddings"; diff --git a/packages/core/src/models/lessons.ts b/packages/core/src/models/lessons.ts index 945f174e7..981c1e59d 100644 --- a/packages/core/src/models/lessons.ts +++ b/packages/core/src/models/lessons.ts @@ -16,7 +16,7 @@ import { PromptTemplate } from "langchain/prompts"; import { RunnableSequence } from "langchain/schema/runnable"; import { z } from "zod"; -import { inngest } from "../client"; +import { inngest } from "../inngest"; import { createOpenAILangchainClient } from "../llm/openai"; import type { SnippetWithLesson} from "./snippets"; import { Snippets } from "./snippets"; diff --git a/packages/core/src/models/quizAnswers.ts b/packages/core/src/models/quizAnswers.ts index 1471c884e..7c2739745 100644 --- a/packages/core/src/models/quizAnswers.ts +++ b/packages/core/src/models/quizAnswers.ts @@ -1,6 +1,6 @@ import type { PrismaClientWithAccelerate } from "@oakai/db"; -import { inngest } from "../client"; +import { inngest } from "../inngest"; import { embedWithCache } from "../utils/embeddings"; export class QuizAnswers { diff --git a/packages/core/src/models/quizQuestions.ts b/packages/core/src/models/quizQuestions.ts index ac3229b01..d7ebe51b6 100644 --- a/packages/core/src/models/quizQuestions.ts +++ b/packages/core/src/models/quizQuestions.ts @@ -1,6 +1,6 @@ import type { PrismaClientWithAccelerate } from "@oakai/db"; -import { inngest } from "../client"; +import { inngest } from "../inngest"; import { embedWithCache } from "../utils/embeddings"; export class QuizQuestions { diff --git a/packages/core/src/models/safetyViolations.ts b/packages/core/src/models/safetyViolations.ts index f1b4e98ed..823a02d67 100644 --- a/packages/core/src/models/safetyViolations.ts +++ b/packages/core/src/models/safetyViolations.ts @@ -10,7 +10,8 @@ import { structuredLogger } from "@oakai/logger"; import type { Logger as InngestLogger } from "inngest/middleware/logger"; import { posthogAiBetaServerClient } from "../analytics/posthogAiBetaServerClient"; -import { inngest } from "../client"; +import { inngest } from "../inngest"; +import { UserBannedError } from "./userBannedError"; const ALLOWED_VIOLATIONS = parseInt( process.env.SAFETY_VIOLATIONS_MAX_ALLOWED || "5", @@ -22,12 +23,6 @@ const CHECK_WINDOW_DAYS = parseInt( ); const checkWindowMs = 1000 * 60 * 60 * 24 * CHECK_WINDOW_DAYS; -export class UserBannedError extends Error { - constructor(userId: string) { - super(`User banned: ${userId}`); - } -} - /** * SafetyViolations records safety violations and bans users who exceed the * allowed number of violations in a given time window. diff --git a/packages/core/src/models/snippets.ts b/packages/core/src/models/snippets.ts index 32661b9e8..a7bd528d8 100644 --- a/packages/core/src/models/snippets.ts +++ b/packages/core/src/models/snippets.ts @@ -24,7 +24,7 @@ import { formatDocumentsAsString } from "langchain/util/document"; import { PrismaVectorStore } from "langchain/vectorstores/prisma"; import { difference } from "remeda"; -import { inngest } from "../client"; +import { inngest } from "../inngest"; import { createOpenAILangchainClient } from "../llm/openai"; import { embedWithCache } from "../utils/embeddings"; diff --git a/packages/core/src/models/userBannedError.ts b/packages/core/src/models/userBannedError.ts new file mode 100644 index 000000000..7541c2f88 --- /dev/null +++ b/packages/core/src/models/userBannedError.ts @@ -0,0 +1,5 @@ +export class UserBannedError extends Error { + constructor(userId: string) { + super(`User banned: ${userId}`); + } +} diff --git a/packages/core/src/scripts/processLessons.ts b/packages/core/src/scripts/processLessons.ts index 06e7c20c8..f45348a9b 100644 --- a/packages/core/src/scripts/processLessons.ts +++ b/packages/core/src/scripts/processLessons.ts @@ -1,7 +1,7 @@ // Called with pnpm run process:lessons -- --keyStage=3 --subject=religious-education import invariant from "tiny-invariant"; -import { inngest } from "../client"; +import { inngest } from "../inngest"; const main = async () => { try { diff --git a/packages/core/src/utils/camelCaseConversion.ts b/packages/core/src/utils/camelCaseConversion.ts new file mode 100644 index 000000000..e1a4ae6ac --- /dev/null +++ b/packages/core/src/utils/camelCaseConversion.ts @@ -0,0 +1,13 @@ +export function camelCaseToSentenceCase(str: string) { + return str + .replace(/([A-Z0-9])/g, " $1") + .replace(/^./, (str) => str.toUpperCase()) + .replace(/\s[A-Z]/g, (str) => str.toLowerCase()); +} + +export function camelCaseToTitleCase(str: string) { + return str + .replace(/([A-Z0-9])/g, " $1") + .replace(/^./, (str) => str.toUpperCase()) + .replace(/\s./g, (str) => str.toUpperCase()); +}