Skip to content
Merged
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
33 changes: 22 additions & 11 deletions packages/web/src/app/[domain]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getRepos, getSearchContexts } from "@/actions";
import { Footer } from "@/app/components/footer";
import { getOrgFromDomain } from "@/data/org";
import { getConfiguredLanguageModelsInfo, getUserChatHistory } from "@/features/chat/actions";
import { isServiceError } from "@/lib/utils";
import { isServiceError, measure } from "@/lib/utils";
import { Homepage } from "./components/homepage";
import { NavigationMenu } from "./components/navigationMenu";
import { PageNotFound } from "./components/pageNotFound";
Expand All @@ -14,25 +14,36 @@ import { AGENTIC_SEARCH_TUTORIAL_DISMISSED_COOKIE_NAME, SEARCH_MODE_COOKIE_NAME
import { env } from "@/env.mjs";
import { loadJsonFile } from "@sourcebot/shared";
import { DemoExamples, demoExamplesSchema } from "@/types";
import { createLogger } from "@sourcebot/logger";

const logger = createLogger('web-homepage');

export default async function Home(props: { params: Promise<{ domain: string }> }) {
logger.debug('Starting homepage load...');
const { data: HomePage, durationMs } = await measure(() => HomeInternal(props), 'HomeInternal', /* outputLog = */ false);
logger.debug(`Homepage load completed in ${durationMs}ms.`);

return HomePage;
}

const HomeInternal = async (props: { params: Promise<{ domain: string }> }) => {
const params = await props.params;

const {
domain
} = params;

const org = await getOrgFromDomain(domain);

const org = (await measure(() => getOrgFromDomain(domain), 'getOrgFromDomain')).data;
if (!org) {
return <PageNotFound />
}

const session = await auth();

const models = await getConfiguredLanguageModelsInfo();
const repos = await getRepos();
const searchContexts = await getSearchContexts(domain);
const chatHistory = session ? await getUserChatHistory(domain) : [];
const session = (await measure(() => auth(), 'auth')).data;
const models = (await measure(() => getConfiguredLanguageModelsInfo(), 'getConfiguredLanguageModelsInfo')).data;
const repos = (await measure(() => getRepos(), 'getRepos')).data;
const searchContexts = (await measure(() => getSearchContexts(domain), 'getSearchContexts')).data;
const chatHistory = session ? (await measure(() => getUserChatHistory(domain), 'getUserChatHistory')).data : [];

if (isServiceError(repos)) {
throw new ServiceErrorException(repos);
Expand All @@ -50,7 +61,7 @@ export default async function Home(props: { params: Promise<{ domain: string }>

// Read search mode from cookie, defaulting to agentic if not set
// (assuming a language model is configured).
const cookieStore = await cookies();
const cookieStore = (await measure(() => cookies(), 'cookies')).data;
const searchModeCookie = cookieStore.get(SEARCH_MODE_COOKIE_NAME);
const initialSearchMode = (
searchModeCookie?.value === "agentic" ||
Expand All @@ -61,7 +72,7 @@ export default async function Home(props: { params: Promise<{ domain: string }>

const demoExamples = env.SOURCEBOT_DEMO_EXAMPLES_PATH ? await (async () => {
try {
return await loadJsonFile<DemoExamples>(env.SOURCEBOT_DEMO_EXAMPLES_PATH!, demoExamplesSchema);
return (await measure(() => loadJsonFile<DemoExamples>(env.SOURCEBOT_DEMO_EXAMPLES_PATH!, demoExamplesSchema), 'loadExamplesJsonFile')).data;
} catch (error) {
console.error('Failed to load demo examples:', error);
return undefined;
Expand All @@ -87,4 +98,4 @@ export default async function Home(props: { params: Promise<{ domain: string }>
<Footer />
</div>
)
}
}