🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
import { APPLE_APP_STORE_ID, BRANDING_NAME, ORG_NAME } from '@lobechat/business-const';
import { OG_URL } from '@lobechat/const';
import { getServerFeatureFlagsValue } from '@/config/featureFlags';
import { OFFICIAL_URL } from '@/const/url';
import { isCustomORG, isDesktop } from '@/const/version';
import { appEnv } from '@/envs/app';
import { fileEnv } from '@/envs/file';
import { pythonEnv } from '@/envs/python';
import { translation } from '@/libs/i18n/serverTranslation';
import { buildAnalyticsConfig, fetchViteDevTemplate, renderSpaHtml } from '@/libs/spaHtml';
import { type Locales } from '@/locales/resources';
import { getServerGlobalConfig } from '@/server/globalConfig';
import { type SPAClientEnv, type SPAServerConfig } from '@/types/spaServerConfig';
import { RouteVariants } from '@/utils/server/routeVariants';
export function generateStaticParams() {
const mobileOptions = isDesktop ? [false] : [true, false];
const staticLocales: Locales[] = ['en-US', 'zh-CN'];
const variants: { variants: string }[] = [];
for (const locale of staticLocales) {
for (const isMobile of mobileOptions) {
variants.push({
variants: RouteVariants.serializeVariants({ isMobile, locale }),
});
}
}
return variants;
}
const isDev = process.env.NODE_ENV === 'development';
async function getTemplate(isMobile: boolean): Promise<string> {
if (isDev) return fetchViteDevTemplate();
const { desktopHtmlTemplate, mobileHtmlTemplate } = await import('./spaHtmlTemplates');
return isMobile ? mobileHtmlTemplate : desktopHtmlTemplate;
}
function buildClientEnv(): SPAClientEnv {
return {
marketBaseUrl: appEnv.MARKET_BASE_URL,
marketSkillInstallBaseUrl: appEnv.MARKET_SKILL_INSTALL_BASE_URL,
pyodideIndexUrl: pythonEnv.NEXT_PUBLIC_PYODIDE_INDEX_URL,
pyodidePipIndexUrl: pythonEnv.NEXT_PUBLIC_PYODIDE_PIP_INDEX_URL,
s3FilePath: fileEnv.NEXT_PUBLIC_S3_FILE_PATH,
};
}
async function buildSeoMeta(locale: string, isMobile: boolean): Promise<string> {
const { t } = await translation('metadata', locale);
const title = t('chat.title', { appName: BRANDING_NAME });
const description = t('chat.description', { appName: BRANDING_NAME });
const metas = [
`<title>${title}</title>`,
`<meta name="description" content="${description}" />`,
`<meta property="og:title" content="${title}" />`,
`<meta property="og:description" content="${description}" />`,
`<meta property="og:type" content="website" />`,
`<meta property="og:url" content="${OFFICIAL_URL}" />`,
`<meta property="og:image" content="${OG_URL}" />`,
`<meta property="og:site_name" content="${BRANDING_NAME}" />`,
`<meta property="og:locale" content="${locale}" />`,
`<meta name="twitter:card" content="summary_large_image" />`,
`<meta name="twitter:title" content="${title}" />`,
`<meta name="twitter:description" content="${description}" />`,
`<meta name="twitter:image" content="${OG_URL}" />`,
`<meta name="twitter:site" content="${isCustomORG ? `@${ORG_NAME}` : '@lobehub'}" />`,
];
if (isMobile && APPLE_APP_STORE_ID) {
metas.push(`<meta name="apple-itunes-app" content="app-id=${APPLE_APP_STORE_ID}" />`);
}
return metas.join('\n ');
}
export async function GET(
_request: Request,
{ params }: { params: Promise<{ path?: string[]; variants: string }> },
) {
const { variants } = await params;
const { locale, isMobile } = RouteVariants.deserializeVariants(variants);
const spaConfig: SPAServerConfig = {
analyticsConfig: buildAnalyticsConfig({ desktop: true }),
clientEnv: buildClientEnv(),
config: await getServerGlobalConfig(),
featureFlags: getServerFeatureFlagsValue(),
isMobile,
};
const template = await getTemplate(isMobile);
const seoMeta = await buildSeoMeta(locale, isMobile);
return renderSpaHtml(template, { seoMeta, serverConfig: spaConfig });
}