Skip to content

Commit

Permalink
Merge branch 'main' into fix/dropdown_sections
Browse files Browse the repository at this point in the history
  • Loading branch information
stefl authored Oct 30, 2024
2 parents b2b4267 + 18a0f70 commit 37e46e6
Show file tree
Hide file tree
Showing 25 changed files with 131 additions and 87 deletions.
14 changes: 11 additions & 3 deletions apps/nextjs/src/ai-apps/common/copyLinkToClipboard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { aiLogger } from "@oakai/logger";

const log = aiLogger("chat");
export const copyLinkToClipboard = () => {
const currentURL = window.location.href;
navigator.clipboard.writeText(currentURL).then(() => {
alert("Link copied to clipboard!");
});
navigator.clipboard
.writeText(currentURL)
.then(() => {
alert("Link copied to clipboard!");
})
.catch((error) => {
log.error(error);
});
};
14 changes: 11 additions & 3 deletions apps/nextjs/src/ai-apps/common/copyTextToClipboard.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { aiLogger } from "@oakai/logger";

const log = aiLogger("chat");
export const copyTextToClipboard = () => {
const elementsToCopy =
document.querySelectorAll<HTMLElement>(".copy-to-clipboard");
const textToCopy = Array.from(elementsToCopy)
.map((element) => element.innerText)
.join("\n");

navigator.clipboard.writeText(textToCopy).then(() => {
alert("Text copied to clipboard!");
});
navigator.clipboard
.writeText(textToCopy)
.then(() => {
alert("Text copied to clipboard!");
})
.catch((error) => {
log.error(error);
});
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Message } from "@oakai/aila";
import type { Message } from "@oakai/aila/src/core/chat";
import type { LLMService } from "@oakai/aila/src/core/llm/LLMService";
import { OpenAIService } from "@oakai/aila/src/core/llm/OpenAIService";
import { aiLogger } from "@oakai/logger";
Expand All @@ -8,7 +8,7 @@ import type { ZodSchema } from "zod";
const log = aiLogger("fixtures");

export class FixtureRecordLLMService implements LLMService {
name = "FixureRecordLLM";
name = "FixtureRecordLLM";
private _openAIService: OpenAIService;

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from "fs";
const log = aiLogger("fixtures");

export class FixtureReplayLLMService extends MockLLMService {
name = "FixureReplayLLM";
name = "FixtureReplayLLM";

constructor(fixtureName: string) {
const fileUrl = `${process.cwd()}/tests-e2e/recordings/${fixtureName}.chunks.txt`;
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/api/chat/webActionsPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { AilaPlugin } from "@oakai/aila/src/core/plugins";
import { AilaThreatDetectionError } from "@oakai/aila/src/features/threatDetection";
import { handleHeliconeError } from "@oakai/aila/src/utils/moderation/moderationErrorHandling";
import { SafetyViolations as defaultSafetyViolations } from "@oakai/core";
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";
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/app/lesson-planner/preview/[slug]/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const LessonPlanPreview = ({ planSections }) => {
<ol className="list-decimal pl-10">
{planSections?.planSections.keyLearningPoints.map(
(learningPoint) => (
<li key={learningPoint.value} className={`mb-6 list-decimal`}>
<li key={learningPoint.value} className={"mb-6 list-decimal"}>
<p>{learningPoint.value}</p>
</li>
),
Expand All @@ -58,7 +58,7 @@ export const LessonPlanPreview = ({ planSections }) => {
return (
<li
key={miscon.value.misconception}
className={`mb-12 flex flex-col gap-8`}
className={"mb-12 flex flex-col gap-8"}
>
<p className="font-bold">{miscon.value.misconception}</p>
<p>{miscon.value.description}</p>
Expand Down Expand Up @@ -152,7 +152,7 @@ const Quiz = ({ question }: Readonly<QuizProps>) => {
<ul className="mt-10">
{question.distractors.map((distractor) => {
return (
<li key={distractor.value} className={`mb-12 flex flex-col gap-8`}>
<li key={distractor.value} className={"mb-12 flex flex-col gap-8"}>
<p>{distractor.value}</p>
</li>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/user/[[...index]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export default function Page() {
<div>
<UserProfile />
</div>
)
);
}
1 change: 1 addition & 0 deletions apps/nextjs/src/hooks/useGenerationCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import type { z } from "zod";

import useAnalytics from "@/lib/analytics/useAnalytics";

import { usePreviousValue } from "./usePreviousValue";

type UseGenerationCallbackTypes<TSchema extends z.Schema> = {
Expand Down
22 changes: 11 additions & 11 deletions apps/nextjs/src/lib/hooks/use-at-bottom.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import * as React from 'react'
import * as React from "react";

export function useAtBottom(offset = 0) {
const [isAtBottom, setIsAtBottom] = React.useState(false)
const [isAtBottom, setIsAtBottom] = React.useState(false);

React.useEffect(() => {
const handleScroll = () => {
setIsAtBottom(
window.innerHeight + window.scrollY >=
document.body.offsetHeight - offset
)
}
document.body.offsetHeight - offset,
);
};

window.addEventListener('scroll', handleScroll, { passive: true })
handleScroll()
window.addEventListener("scroll", handleScroll, { passive: true });
handleScroll();

return () => {
window.removeEventListener('scroll', handleScroll)
}
}, [offset])
window.removeEventListener("scroll", handleScroll);
};
}, [offset]);

return isAtBottom
return isAtBottom;
}
10 changes: 6 additions & 4 deletions apps/nextjs/src/lib/sentry/SentryIdentify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import * as Sentry from "@sentry/nextjs";

import { useClerkIdentify } from "../clerk/useClerkIdentify";

const sentrySetUser = ({ userId }) => {
Sentry.setUser({
id: userId,
});
const sentrySetUser = ({ userId }: { userId: string }) => {
if (userId) {
Sentry.setUser({
id: userId,
});
}
};
const sentryUnsetUser = () => {
Sentry.setUser(null);
Expand Down
6 changes: 4 additions & 2 deletions apps/nextjs/tests-e2e/tests/aila-chat/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, Page, test, TestInfo } from "@playwright/test";
import type { Page, TestInfo } from "@playwright/test";
import { expect, test } from "@playwright/test";

import { AilaStreamingStatus } from "@/components/AppComponents/Chat/Chat/hooks/useAilaStreamingStatus";
import type { AilaStreamingStatus } from "@/components/AppComponents/Chat/Chat/hooks/useAilaStreamingStatus";

export async function expectStreamingStatus(
page: Page,
Expand All @@ -20,6 +21,7 @@ export async function waitForStreamingStatusChange(
await page.waitForFunction(
([currentStatus, expectedStatus]) => {
const statusElement = document.querySelector(
// eslint-disable-next-line @typescript-eslint/quotes, quotes
'[data-testid="chat-aila-streaming-status"]',
);
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/aila/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./src";
export { Aila } from "./src/core/Aila";
4 changes: 2 additions & 2 deletions packages/aila/src/core/chat/AilaStreamHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class AilaStreamHandler {
await this.readFromStream();
}
} catch (e) {
this.handleStreamError(e);
await this.handleStreamError(e);
log.info("Stream error", e, this._chat.iteration, this._chat.id);
} finally {
this._isStreaming = false;
Expand Down Expand Up @@ -109,7 +109,7 @@ export class AilaStreamHandler {
for (const plugin of this._chat.aila.plugins ?? []) {
await plugin.onStreamError?.(error, {
aila: this._chat.aila,
enqueue: this._chat.enqueue,
enqueue: (patch) => this._chat.enqueue(patch),
});
}

Expand Down
5 changes: 0 additions & 5 deletions packages/aila/src/core/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/aila/src/features/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/aila/src/index.ts

This file was deleted.

7 changes: 7 additions & 0 deletions packages/api/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ["eslint-config-custom"],
parserOptions: {
project: __dirname + "/tsconfig.json",
},
};
50 changes: 25 additions & 25 deletions packages/api/src/router/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ import { router } from "../trpc";

const log = aiLogger("exports");

function getValidLink(
data:
| {
link: string;
canViewSourceDoc: boolean;
}
| {
error: unknown;
message: string;
},
): string | undefined {
if (data && "link" in data && typeof data.link === "string") {
return data.link;
}
if ("error" in data && "message" in data) {
Sentry.captureException(data.error, {
extra: {
error: data.error,
message: data.message,
},
});
throw new Error(data.message);
}
}

export async function ailaSaveExport({
auth,
prisma,
Expand Down Expand Up @@ -643,31 +668,6 @@ export const exportsRouter = router({
}),
]);

function getValidLink(
data:
| {
link: string;
canViewSourceDoc: boolean;
}
| {
error: unknown;
message: string;
},
): string | undefined {
if (data && "link" in data && typeof data.link === "string") {
return data.link;
}
if ("error" in data && "message" in data) {
Sentry.captureException(data.error, {
extra: {
error: data.error,
message: data.message,
},
});
throw new Error(data.message);
}
}

const allExports = {
lessonSlides: getValidLink(lessonSlides),
lessonPlan: getValidLink(lessonPlan),
Expand Down
7 changes: 7 additions & 0 deletions packages/core/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ["eslint-config-custom"],
parserOptions: {
project: __dirname + "/tsconfig.json",
},
};
7 changes: 7 additions & 0 deletions packages/db/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ["eslint-config-custom"],
parserOptions: {
project: __dirname + "/tsconfig.json",
},
};
7 changes: 7 additions & 0 deletions packages/exports/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ["eslint-config-custom"],
parserOptions: {
project: __dirname + "/tsconfig.json",
},
};
7 changes: 7 additions & 0 deletions packages/ingest/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ["eslint-config-custom"],
parserOptions: {
project: __dirname + "/tsconfig.json",
},
};
2 changes: 1 addition & 1 deletion packages/ingest/src/import-lessons/importLessonsFromCSV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from "node:fs";
import { IngestError } from "../IngestError";
import { chunkAndPromiseAll } from "../utils/chunkAndPromiseAll";
import { getDataHash } from "../utils/getDataHash";
import type { RawLesson} from "../zod-schema/zodSchema";
import type { RawLesson } from "../zod-schema/zodSchema";
import { RawLessonSchema } from "../zod-schema/zodSchema";

const log = aiLogger("ingest");
Expand Down
14 changes: 7 additions & 7 deletions packages/ingest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ async function main() {
const ingestId = process.argv[3] ?? (await getLatestIngestId({ prisma }));
switch (command) {
case "start":
ingestStart({ prisma, log });
await ingestStart({ prisma, log });
break;
case "captions":
captions({ prisma, log, ingestId });
await captions({ prisma, log, ingestId });
break;
case "lp-start":
lpBatchStart({ prisma, log, ingestId });
await lpBatchStart({ prisma, log, ingestId });
break;
case "lp-sync":
lpBatchSync({ prisma, log, ingestId });
await lpBatchSync({ prisma, log, ingestId });
break;
case "chunk":
lpChunking({ prisma, log, ingestId });
await lpChunking({ prisma, log, ingestId });
break;
case "embed-start":
lpPartsEmbedStart({ prisma, log, ingestId });
await lpPartsEmbedStart({ prisma, log, ingestId });
break;
case "embed-sync":
lpPartsEmbedSync({ prisma, log, ingestId });
await lpPartsEmbedSync({ prisma, log, ingestId });
break;
default:
log.error("Unknown command");
Expand Down
13 changes: 8 additions & 5 deletions packages/ingest/src/utils/jsonlToArray.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export function jsonlToArray(jsonl: string) {
return jsonl
.split("\n")
.filter((line) => line.trim() !== "")
.map((line) => JSON.parse(line));
export function jsonlToArray(jsonl: string): unknown[] {
return (
jsonl
.split("\n")
.filter((line) => line.trim() !== "")
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
.map((line) => JSON.parse(line))
);
}

0 comments on commit 37e46e6

Please sign in to comment.