mirror of
https://github.com/THU-MAIC/OpenMAIC.git
synced 2026-10-16 05:19:50 +08:00
* fix(ai): let LLM calls outlive undici's 300s headers timeout A non-streaming completion only receives response headers once the whole completion exists, so undici's default 300 s headers timeout bounds total generation time. Thinking models (GLM-5.x at effort=max, MiniMax M3, …) routinely exceed that on large prompts — the request then dies with "Cannot connect to API: Headers Timeout Error" at exactly 300 s and, with maxRetries 0, the scene never generates (observed on a self-hosted deployment with glm-5.2 scene generation). Route every outbound LLM request through an undici Agent with a 15-minute headers/body timeout, attached at the shared transportFetch seam so the OpenAI-compatible, native OpenAI/Responses, Azure, Anthropic-compatible and Google transports all inherit it (same lazy-import dispatcher pattern the Google proxy transport already uses). Native transports now always install the shared transport instead of only when the server injects a validating fetch. * fix(ai): harden the LLM transport timeout fallback Review follow-ups for the undici headers-timeout fix: - getLlmDispatcher(): drop the cached promise on rejection so one transient undici import/Agent failure can't brick every later call; transportFetch falls back to the base transport (no dispatcher) when the dispatcher can't be built, warning once per failure episode - bedrock: install fetch: transportFetch like every other transport - google proxy: build ProxyAgent with the same headers/body timeout budget (http/https proxies; undici's Socks5ProxyAgent drops these options for socks5://) - transportFetch no longer overwrites a caller-supplied dispatcher - tests: dispatcher failure fallback + retry, bedrock transport, caller-dispatcher preservation, google proxy budget --------- Co-authored-by: XingJia He <hexingjia@mobirit.com>
74 lines
3.2 KiB
TypeScript
74 lines
3.2 KiB
TypeScript
import type { NextConfig } from 'next';
|
|
|
|
const nextConfig: NextConfig = {
|
|
output: process.env.VERCEL ? undefined : 'standalone',
|
|
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 so the version matching the loaded sharp binary is
|
|
// always present, across platforms and sharp versions.
|
|
'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: '/(.*)',
|
|
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}`,
|
|
},
|
|
],
|
|
},
|
|
];
|
|
},
|
|
};
|
|
|
|
export default nextConfig;
|