Skip to content

Commit c71509b

Browse files
committed
WIP adding kapa ai to the app
1 parent a99b59a commit c71509b

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

apps/webapp/app/env.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ const EnvironmentSchema = z.object({
672672

673673
QUEUE_SSE_AUTORELOAD_INTERVAL_MS: z.coerce.number().int().default(5_000),
674674
QUEUE_SSE_AUTORELOAD_TIMEOUT_MS: z.coerce.number().int().default(60_000),
675+
676+
// kapa.ai
677+
KAPA_AI_WEBSITE_ID: z.string().optional(),
675678
});
676679

677680
export type Environment = z.infer<typeof EnvironmentSchema>;

apps/webapp/app/root.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { LinksFunction, LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
22
import type { ShouldRevalidateFunction } from "@remix-run/react";
33
import { Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration } from "@remix-run/react";
4-
import { UseDataFunctionReturn, typedjson, useTypedLoaderData } from "remix-typedjson";
4+
import { type UseDataFunctionReturn, typedjson, useTypedLoaderData } from "remix-typedjson";
55
import { ExternalScripts } from "remix-utils/external-scripts";
6-
import type { ToastMessage } from "~/models/message.server";
76
import { commitSession, getSession } from "~/models/message.server";
7+
import type { ToastMessage } from "~/models/message.server";
88
import tailwindStylesheetUrl from "~/tailwind.css";
99
import { RouteErrorDisplay } from "./components/ErrorDisplay";
1010
import { AppContainer, MainCenteredContainer } from "./components/layout/AppLayout";
@@ -14,6 +14,8 @@ import { featuresForRequest } from "./features.server";
1414
import { usePostHog } from "./hooks/usePostHog";
1515
import { getUser } from "./services/session.server";
1616
import { appEnvTitleTag } from "./utils";
17+
import { type Handle } from "./utils/handle";
18+
import { useEffect } from "react";
1719

1820
export const links: LinksFunction = () => {
1921
return [{ rel: "stylesheet", href: tailwindStylesheetUrl }];
@@ -40,6 +42,10 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
4042
const posthogProjectKey = env.POSTHOG_PROJECT_KEY;
4143
const features = featuresForRequest(request);
4244

45+
const kapa = {
46+
websiteId: env.KAPA_AI_WEBSITE_ID,
47+
};
48+
4349
return typedjson(
4450
{
4551
user: await getUser(request),
@@ -48,6 +54,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
4854
features,
4955
appEnv: env.APP_ENV,
5056
appOrigin: env.APP_ORIGIN,
57+
kapa,
5158
},
5259
{ headers: { "Set-Cookie": await commitSession(session) } }
5360
);
@@ -86,8 +93,8 @@ export function ErrorBoundary() {
8693
);
8794
}
8895

89-
function App() {
90-
const { posthogProjectKey } = useTypedLoaderData<typeof loader>();
96+
export default function App() {
97+
const { posthogProjectKey, kapa, features } = useTypedLoaderData<typeof loader>();
9198
usePostHog(posthogProjectKey);
9299

93100
return (
@@ -96,6 +103,17 @@ function App() {
96103
<head>
97104
<Meta />
98105
<Links />
106+
{features.isManagedCloud && (
107+
<script
108+
src="/resources/kapa-widget"
109+
crossOrigin="anonymous"
110+
async
111+
data-website-id={kapa.websiteId}
112+
data-project-name="Trigger.dev"
113+
data-project-color="#ff9900"
114+
data-project-logo="content.trigger.dev/trigger-logo-triangle.png"
115+
/>
116+
)}
99117
</head>
100118
<body className="bg-darkBackground h-full overflow-hidden">
101119
<Outlet />
@@ -109,5 +127,3 @@ function App() {
109127
</>
110128
);
111129
}
112-
113-
export default App;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { type LoaderFunctionArgs } from "@remix-run/node";
2+
3+
export async function loader({ request }: LoaderFunctionArgs) {
4+
const response = await fetch("https://widget.kapa.ai/kapa-widget.bundle.js");
5+
const script = await response.text();
6+
7+
return new Response(script, {
8+
headers: {
9+
"Content-Type": "application/javascript",
10+
"Cache-Control": "public, max-age=86400", // Cache for 1 day
11+
},
12+
});
13+
}

0 commit comments

Comments
 (0)