Skip to content

Commit

Permalink
Update core to have more specific imports
Browse files Browse the repository at this point in the history
  • Loading branch information
stefl committed Oct 29, 2024
1 parent 8553fb0 commit 6cb5cda
Show file tree
Hide file tree
Showing 55 changed files with 138 additions and 71 deletions.
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/api/chat/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
9 changes: 5 additions & 4 deletions apps/nextjs/src/app/api/chat/errorHandling.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -123,4 +124,4 @@ describe("handleChatException", () => {
});
});
});
});
});
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/api/chat/errorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 3 additions & 2 deletions apps/nextjs/src/app/api/chat/user.test.ts
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/api/chat/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
11 changes: 7 additions & 4 deletions apps/nextjs/src/app/api/chat/webActionsPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -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(),
},
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 4 additions & 6 deletions apps/nextjs/src/app/api/chat/webActionsPlugin.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/src/app/api/sanitizeFilename.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
});
});
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/demo/populateDemoStatuses.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lesson/generatePlan.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lesson/summarise.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lesson/summariseAll.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lessonPlan/embed.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lessonPlan/embedAll.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lessonPlan/embedAllParts.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lessonPlan/embedPart.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lessonPlan/generateAll.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { prisma } from "@oakai/db";

import { inngest } from "../../client";
import { inngest } from "../../inngest";

export const generateAllLessonPlans = inngest.createFunction(
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lessonPlan/process.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lessonSummary/embed.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/lessonSummary/embedAll.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/migrations/addIdsToMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/migrations/kvChatsToPrisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/quizAnswer/embedAll.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/quizQuestion/embedAll.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/quizQuestion/generateAll.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/slack/notifyModeration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inngest } from "../../client";
import { inngest } from "../../inngest";
import {
slackNotificationChannelId,
slackWebClient,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/slack/notifyRateLimit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inngest } from "../../client";
import { inngest } from "../../inngest";
import {
slackNotificationChannelId,
slackWebClient,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/slack/notifyUserBan.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inngest } from "../../client";
import { inngest } from "../../inngest";
import {
slackNotificationChannelId,
slackWebClient,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/functions/snippet/embedAll.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { prisma } from "@oakai/db";

import { inngest } from "../../client";
import { inngest } from "../../inngest";

interface SimplifiedLesson {
id: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { prisma } from "@oakai/db";

import { inngest } from "../../client";
import { inngest } from "../../inngest";

interface SimplifiedLesson {
id: string;
Expand Down
Loading

0 comments on commit 6cb5cda

Please sign in to comment.