Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,48 @@ import { SidebarProvider } from "@/context/sidebar-context";
import { cookies } from "next/headers";
import dynamic from "next/dynamic";
import { redirect } from "next/navigation";
import { UserProvider } from "@/store/user/provider";
import { AssistantSheet } from "@/components/sheets/assistant-sheet";

const HotKeys = dynamic(
() => import("@/components/hot-keys").then((mod) => mod.HotKeys),
{
ssr: true,
},
() => import("@/components/hot-keys").then((mod) => mod.HotKeys),
{
ssr: true,
},
);

export default async function Layout({
children,
params,
children,
params,
}: {
children: React.ReactNode;
params: Promise<{ orgId: string }>;
children: React.ReactNode;
params: Promise<{ orgId: string }>;
}) {
const session = await auth();
const orgId = (await params).orgId;
const cookieStore = await cookies();
const isCollapsed = cookieStore.get("sidebar-collapsed")?.value === "true";
const session = await auth();
const orgId = (await params).orgId;
const cookieStore = await cookies();
const isCollapsed = cookieStore.get("sidebar-collapsed")?.value === "true";

if (!session) {
redirect("/auth");
}
if (!session) {
redirect("/auth");
}

if (!orgId) {
redirect("/");
}
if (!orgId) {
redirect("/");
}

return (
<SidebarProvider initialIsCollapsed={isCollapsed}>
<AnimatedLayout sidebar={<Sidebar />} isCollapsed={isCollapsed}>
<div className="p-4">
<Header />
<main>{children}</main>
</div>
</AnimatedLayout>
<HotKeys />
</SidebarProvider>
);
return (
<UserProvider data={session.user}>
<SidebarProvider initialIsCollapsed={isCollapsed}>
<AnimatedLayout sidebar={<Sidebar />} isCollapsed={isCollapsed}>
<div className="p-4">
<Header />
<main>{children}</main>
</div>
<AssistantSheet />
</AnimatedLayout>
<HotKeys />
</SidebarProvider>
</UserProvider>
);
}
159 changes: 78 additions & 81 deletions apps/app/src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,104 +10,101 @@ import localFont from "next/font/local";
import { NuqsAdapter } from "nuqs/adapters/next/app";
import { Toaster } from "sonner";
import { Providers } from "./providers";
import { ChatProvider } from "@/components/chat/ChatProvider";

export const metadata: Metadata = {
metadataBase: new URL("https://app.trycomp.ai"),
title: "Comp AI | Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
description: "Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
twitter: {
title: "Comp AI | Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
description: "Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
images: [
{
url: "https://cdn.trycomp.ai/opengraph-image.jpg",
width: 800,
height: 600,
},
{
url: "https://cdn.trycomp.ai/opengraph-image.jpg",
width: 1800,
height: 1600,
},
],
},
openGraph: {
title: "Comp AI | Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
description: "Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
url: "https://app.trycomp.ai",
siteName: "Comp AI",
images: [
{
url: "https://cdn.trycomp.ai/opengraph-image.jpg",
width: 800,
height: 600,
},
{
url: "https://cdn.trycomp.ai/opengraph-image.jpg",
width: 1800,
height: 1600,
},
],
locale: "en_US",
type: "website",
},
metadataBase: new URL("https://app.trycomp.ai"),
title: "Comp AI | Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
description: "Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
twitter: {
title: "Comp AI | Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
description: "Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
images: [
{
url: "https://cdn.trycomp.ai/opengraph-image.jpg",
width: 800,
height: 600,
},
{
url: "https://cdn.trycomp.ai/opengraph-image.jpg",
width: 1800,
height: 1600,
},
],
},
openGraph: {
title: "Comp AI | Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
description: "Automate SOC 2, ISO 27001 and GDPR compliance with AI.",
url: "https://app.trycomp.ai",
siteName: "Comp AI",
images: [
{
url: "https://cdn.trycomp.ai/opengraph-image.jpg",
width: 800,
height: 600,
},
{
url: "https://cdn.trycomp.ai/opengraph-image.jpg",
width: 1800,
height: 1600,
},
],
locale: "en_US",
type: "website",
},
};

export const viewport = {
width: "device-width",
initialScale: 1,
maximumScale: 1,
userScalable: false,
themeColor: [
{ media: "(prefers-color-scheme: light)" },
{ media: "(prefers-color-scheme: dark)" },
],
width: "device-width",
initialScale: 1,
maximumScale: 1,
userScalable: false,
themeColor: [
{ media: "(prefers-color-scheme: light)" },
{ media: "(prefers-color-scheme: dark)" },
],
};

const font = localFont({
src: "/../../../public/fonts/GeneralSans-Variable.ttf",
display: "swap",
variable: "--font-general-sans",
src: "/../../../public/fonts/GeneralSans-Variable.ttf",
display: "swap",
variable: "--font-general-sans",
});

export const preferredRegion = ["auto"];
export const maxDuration = 5;

if (env.NEXT_PUBLIC_POSTHOG_KEY && env.NEXT_PUBLIC_POSTHOG_HOST) {
initializeServer({
apiKey: env.NEXT_PUBLIC_POSTHOG_KEY,
apiHost: env.NEXT_PUBLIC_POSTHOG_HOST,
});
initializeServer({
apiKey: env.NEXT_PUBLIC_POSTHOG_KEY,
apiHost: env.NEXT_PUBLIC_POSTHOG_HOST,
});
}

export default async function Layout(props: {
children: React.ReactNode;
params: Promise<{ locale: string }>;
children: React.ReactNode;
params: Promise<{ locale: string }>;
}) {
const params = await props.params;
const { locale } = params;
const { children } = props;
const params = await props.params;
const { locale } = params;
const { children } = props;

return (
<html lang={locale} suppressHydrationWarning>
<body
className={cn(
`${GeistMono.variable} ${font.variable}`,
"whitespace-pre-line overscroll-none antialiased",
)}
>
<NuqsAdapter>
<SessionProvider>
<Providers locale={locale}>
<ChatProvider>
<main>{children}</main>
</ChatProvider>
</Providers>
</SessionProvider>
</NuqsAdapter>
<Toaster richColors />
</body>
</html>
);
return (
<html lang={locale} suppressHydrationWarning>
<body
className={cn(
`${GeistMono.variable} ${font.variable}`,
"whitespace-pre-line overscroll-none antialiased",
)}
>
<NuqsAdapter>
<SessionProvider>
<Providers locale={locale}>
<main>{children}</main>
</Providers>
</SessionProvider>
</NuqsAdapter>
<Toaster richColors />
</body>
</html>
);
}
92 changes: 66 additions & 26 deletions apps/app/src/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,73 @@
import { openai } from "@ai-sdk/openai";
import { streamText } from "ai";
import { env } from "@/env.mjs";
import { auth } from "@/auth";
import { model, type modelID } from "@/hooks/ai/providers";
import {
getOrgTool,
getVendorsTool,
getPoliciesTool,
getRisksTool,
getCloudTestsTool,
getFrameworkTool,
getVendorDetailsTool,
getPolicyDetails,
} from "@/hooks/ai/tools";
import { db } from "@bubba/db";
import { streamText, type UIMessage } from "ai";

export const maxDuration = 30;

export async function POST(req: Request) {
const { messages } = await req.json();
const {
messages,
selectedModel,
}: { messages: UIMessage[]; selectedModel: modelID } = await req.json();

const session = await auth();

if (!env.OPENAI_API_KEY) {
return new Response(
JSON.stringify({ error: "OpenAI API key is not configured" }),
{ status: 500 },
);
if (!session?.user.organizationId) {
return new Response("Unauthorized", { status: 401 });
}

try {
const result = await streamText({
model: openai("gpt-4o-mini"),
system:
"You are a helpful assistant. Provide concise, accurate, and helpful responses to user queries.",
messages,
});

return result.toDataStreamResponse();
} catch (error) {
console.error("Error in chat API:", error);
return new Response(
JSON.stringify({
error: "An error occurred while processing your request",
}),
{ status: 500 },
);
const org = await db.organization.findUnique({
where: {
id: session.user.organizationId,
},
});

if (!org) {
return new Response("Organization not found", { status: 404 });
}

const systemPrompt = `
You are an expert in governance, risk, and compliance.

You're a helpful assistant in Comp AI, a platform that helps companies
get compliant with frameworks like SOC 2, ISO 27001 and GDPR - similar to Vanta and Drata.

You have access to various tools to help gather information. You can:
1. Use multiple tools in sequence to gather comprehensive information
2. Chain tool calls together to get more detailed information
3. Use tools to verify or expand upon information from previous tool calls

When using tools:
- Start with broader queries to get an overview
- Then use specific queries to get detailed information
`;
Comment on lines +40 to +54

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Extract the system prompt into a dedicated configuration.

The multi-line system prompt could be moved to a separate file or constants configuration, improving readability and maintainability—especially if it grows further or requires updates.


const result = streamText({
model: model.languageModel(selectedModel),
system: systemPrompt,
messages,
tools: {
getOrgTool,
getVendorsTool,
getPoliciesTool,
getRisksTool,
getCloudTestsTool,
getFrameworkTool,
getVendorDetailsTool,
getPolicyDetails,
},
});

return result.toDataStreamResponse({ sendReasoning: true });
}
17 changes: 17 additions & 0 deletions apps/app/src/components/ai/chat-empty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { LogoSpinner } from "../logo-spinner";

type Props = {
firstName: string;
};

export function ChatEmpty({ firstName }: Props) {
return (
<div className="w-full mt-[200px] todesktop:mt-24 md:mt-24 flex flex-col items-center justify-center text-center">
<LogoSpinner raceColor="#00DC73" />
<span className="font-medium text-xl mt-6">
Hi {firstName}, how can I help <br />
you today?
</span>
</div>
);
}
Loading