Files
OpenMAIC/next.config.ts
T
wyuc a8c745a791 feat(generation): self-host interactive scene libraries with robust CDN URL mapping (#1972)
Interactive scenes load KaTeX, Three.js (with addons), Chart.js and the Tailwind v4 browser runtime from the deployment (/vendor/interactive, configurable via the build-time INTERACTIVE_ASSET_BASE_URL) instead of public CDNs. KaTeX is injected only into pages with detectable math, synchronously at the start of head (same-origin and immutable-cached), with the #1966 fallback when the asset fails; reprocessing refreshes platform-injected KaTeX tags against the current asset base. A parser-based mapper rewrites compatible public CDN URLs for these libraries to the hosted copies, drops integrity, leaves unknown URLs untouched and is idempotent; stored scenes are reprocessed on open and before export, and exports fetch hosted assets directly. Legacy Tailwind v3 Play CDN is not mapped. @openmaic/generation 0.3.24. Closes #1971.
2026-10-21 22:46:51 +08:00

121 lines
5.3 KiB
TypeScript

import type { NextConfig } from 'next';
import { PHASE_PRODUCTION_BUILD } from 'next/constants';
const nextConfig: NextConfig = {
// Keep Next dev from creating or rewriting repository agent instructions.
agentRules: false,
output: 'standalone',
env: {
INTERACTIVE_ASSET_BASE_URL:
process.env.INTERACTIVE_ASSET_BASE_URL?.trim() || '/vendor/interactive',
},
outputFileTracingIncludes: {
'/*': [
'lib/server/agent-runtime/import-pptx-worker.mjs',
'skills/openmaic/**',
'skills/agent-runtime/**',
// Loaded through a runtime-only `import('undici')` (see the LLM
// dispatcher in lib/ai/providers.ts and the Google proxy transport), so
// the output tracer never sees it and standalone builds ship without it.
'node_modules/undici/**',
// sharp's native libvips libraries are loaded via dlopen and are not
// statically analyzable, so Next.js standalone tracing omits them. Two
// sharp versions resolve in the tree (0.34.5 transitive -> libvips
// 1.2.4, 0.35.4 direct -> libvips 1.3.3); tracing picked the wrong one
// and the runtime dlopen of sharp 0.35.4 failed with
// "libvips-cpp.so.8.18.6: No such file or directory" on self-hosted
// Docker (Alpine/musl) deployments. Force-include every sharp-libvips
// native lib dir.
'node_modules/.pnpm/@img+sharp-libvips-*/node_modules/@img/sharp-libvips-*/lib/**',
],
},
typescript: {
tsconfigPath: process.env.NODE_ENV === 'production' ? 'tsconfig.build.json' : 'tsconfig.json',
},
transpilePackages: ['mathml2omml', 'pptxgenjs', '@openmaic/importer'],
// These agent packages do a runtime `import(specifier)` with a computed
// specifier (to lazily load node:fs/os/path without breaking browser/Vite
// builds). webpack can't statically analyze that and bundling it throws
// "Cannot find module as expression is too dynamic" at runtime on the server
// (the "Edit with AI" Pro-mode path), which broke the #619 keep-alive e2e.
// Mark them server-external so Next loads them natively and the dynamic
// import resolves as a real Node call.
serverExternalPackages: [
'@earendil-works/pi-ai',
'@earendil-works/pi-agent-core',
'@openmaic/generation',
// Optional peers of @openmaic/storage, reached through deliberately
// untraced dynamic imports. Externalizing keeps them out of the bundle,
// and the static anchor in lib/persistence/asset-byte-store.ts gets them
// traced into the standalone image -- without it, S3 mode and redirect
// egress cannot resolve their SDK in the shipped deployment.
'@aws-sdk/client-s3',
'@aws-sdk/s3-request-presigner',
],
experimental: {
proxyClientMaxBodySize: '200mb',
},
async headers() {
const extraAncestors = process.env.ALLOWED_FRAME_ANCESTORS?.trim();
const frameAncestors = extraAncestors ? `'self' ${extraAncestors}` : "'self'";
return [
{
source: '/vendor/interactive/:path*',
headers: [
{ key: 'Access-Control-Allow-Origin', value: '*' },
{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
],
},
{
source: '/(.*)',
headers: [
// X-Frame-Options only supports SAMEORIGIN (no allow-list),
// so we omit it when custom ancestors are configured.
...(!extraAncestors ? [{ key: 'X-Frame-Options', value: 'SAMEORIGIN' }] : []),
{
key: 'Content-Security-Policy',
value: `frame-ancestors ${frameAncestors}`,
},
],
},
{
// Provider logos are drawn wherever services are listed, and each tab
// switch mounts a fresh set of them. With Next's default `max-age=0`
// every one is revalidated first and stays blank until the server
// answers. They are not content-hashed, so cache for a day, not forever.
source: '/logos/:path*',
headers: [
{ key: 'Cache-Control', value: 'public, max-age=86400, stale-while-revalidate=604800' },
],
},
];
},
};
// NEXT_PUBLIC_PI_CHAT_ENABLED used to opt out of Pi into the legacy
// director-graph classroom chat. That runtime is gone, so a production build
// that still carries any value which once selected it fails instead of
// silently switching the deployment to Pi. These values never did.
const PI_CHAT_FLAG_VALUES_STILL_ACCEPTED = new Set(['', 'true', '1']);
export default function config(phase: string): NextConfig {
const piChatFlag = process.env.NEXT_PUBLIC_PI_CHAT_ENABLED;
if (
phase === PHASE_PRODUCTION_BUILD &&
piChatFlag !== undefined &&
!PI_CHAT_FLAG_VALUES_STILL_ACCEPTED.has(piChatFlag)
) {
throw new Error(
`NEXT_PUBLIC_PI_CHAT_ENABLED is set to ${JSON.stringify(piChatFlag)}, but the legacy ` +
'director-graph classroom chat has been removed and this variable can no longer ' +
'select it. Remove NEXT_PUBLIC_PI_CHAT_ENABLED, then select a model that supports ' +
'tool calling for Classroom (Settings → Course Model Config, or the `classroom` ' +
'slot in openmaic.yml and the `llm` slot it inherits from). For Gemini, use the ' +
'native `google` preset. If the model configuration is managed by an administrator, ' +
'ask them to make this change.',
);
}
return nextConfig;
}