import type { NextConfig } from "next"; import { readFileSync } from "fs"; import { dirname, join } from "path"; import { fileURLToPath } from "url"; import { createRequire } from "node:module"; // Windows build shim: keeps @vercel/nft from walking the whole user home // (junction EPERM) while tracing pi-coding-agent's homedir() paths. createRequire(import.meta.url)("./scripts/nft-readdir-shim.cjs"); const configDir = dirname(fileURLToPath(import.meta.url)); const { version } = JSON.parse(readFileSync(join(configDir, "package.json"), "utf8")) as { version: string }; let piVersion = "unknown"; try { const piPkgPath = join(configDir, "node_modules/@earendil-works/pi-coding-agent/package.json"); piVersion = (JSON.parse(readFileSync(piPkgPath, "utf8")) as { version: string }).version; } catch { /* package not found, use default */ } const nextConfig: NextConfig = { outputFileTracingRoot: configDir, serverExternalPackages: [ "undici", "@earendil-works/pi-coding-agent", "@earendil-works/pi-agent-core", "@earendil-works/pi-ai", "@earendil-works/pi-tui", ], allowedDevOrigins: ["127.0.0.1", "192.168.*.*"], async headers() { return [ { source: "/", headers: [ { key: "Cache-Control", value: "private, no-cache, max-age=0, must-revalidate" }, ], }, { source: "/sw.js", headers: [ { key: "Cache-Control", value: "public, max-age=0, must-revalidate" }, { key: "Service-Worker-Allowed", value: "/" }, ], }, { source: "/manifest.webmanifest", headers: [ { key: "Cache-Control", value: "public, max-age=0, must-revalidate" }, ], }, ]; }, env: { NEXT_PUBLIC_APP_VERSION: version, NEXT_PUBLIC_PI_VERSION: piVersion, }, }; export default nextConfig;