#!/usr/bin/env node import type { AgentNativeFirstRunOnboardingMode } from "../config.js"; import { copyDir } from "./function-bundle.js"; import { type DiscoveredRoute, type DiscoveredAction } from "./route-discovery.js"; import { type WorkspaceCoreExports } from "./workspace-core.js"; export declare const CLOUDFLARE_MODULE_PRESETS: readonly ["cloudflare_module", "cloudflare-module"]; export declare const AWS_AMPLIFY_PRESETS: readonly ["aws_amplify", "aws-amplify", "awsAmplify"]; export declare const AWS_LAMBDA_PRESETS: readonly ["aws-lambda", "aws_lambda", "awsLambda"]; export declare function isAwsAmplifyPreset(targetPreset: string): boolean; export declare function isAwsLambdaPreset(targetPreset: string): boolean; export declare function isAwsLambdaStreamingBuild(targetPreset: string, env?: NodeJS.ProcessEnv): boolean; export declare function generateAwsLambdaStreamingRuntimeEntry(utilsModule?: string, appModule?: string): string; export declare function isCloudflareModulePreset(targetPreset: string): boolean; export declare const CLOUDFLARE_MODULE_WORKER_ENTRY = "worker.mjs"; export declare function configureAwsAmplifyRuntimeOutput(serverDir: string, appDir: string, env?: NodeJS.ProcessEnv): void; export declare function configureAwsLambdaRuntimeOutput(serverDir: string, appDir: string, env?: NodeJS.ProcessEnv): void; export declare function shimCloudflarePagesModuleTimers(code: string): string; export declare const CLOUDFLARE_SWEEP_CRON = "* * * * *"; /** * The URL path a platform scheduler requests. Under a custom framework route * prefix the request boundary 404s `/_agent-native/*` before any route runs, * and the server is mounted under the app base path, so the internal sweep * path alone never reaches the sweep. */ export declare function publicRecurringJobsSweepPath(env?: NodeJS.ProcessEnv): string; export declare function generateCloudflareModuleWorkerEntry(env?: NodeJS.ProcessEnv): string; export declare function patchCloudflareModuleNitroEntry(code: string): string; export declare function configureCloudflareModuleWorkerOutput(serverDir: string): void; export declare const NITRO_RUNTIME_IGNORE_PATTERNS: string[]; export declare const CLOUDFLARE_WORKER_ESBUILD_EXTERNALS: string[]; export declare const CLOUDFLARE_WORKER_STUB_MODULES: Record; export declare const CLOUDFLARE_WORKER_STUB_SUBPATH_MODULES: Record; export declare function cloudflareWorkerStubAliasArgs(stubDir: string): string[]; export declare function assertNoCloudflareWorkerStubDynamicImports(code: string, sourceName: string): void; export declare const CLOUDFLARE_WORKER_NODE_BUILTIN_STUB_MODULES: Record; export interface GenerateWorkerEntryOptions { includeReactRouterSsr?: boolean; analytics?: { agentNativePublicKey?: string; agentNativeEndpoint?: string; }; } export declare function generateProvidedPluginsNitroPluginSource(pluginStems: string[]): string; type RouteRules = Record; }>; export declare function addImmutableAssetRouteRulesForClientBuild(routeRules: RouteRules, clientDir: string, appBasePath?: string): void; export declare function generateWorkerEntry(routes: DiscoveredRoute[], pluginPaths: string[], defaultPluginStems?: string[], actions?: DiscoveredAction[], workspaceCore?: WorkspaceCoreExports | null, immutableAssetPaths?: string[], builtAppBasePath?: string, options?: GenerateWorkerEntryOptions, builtFrameworkRoutePrefix?: string): string; export declare function getNodeBuiltinNames(): string[]; export type EsbuildCommand = { executable: string; args: string[]; }; export declare function resolveEsbuildCommand(platform?: NodeJS.Platform, resolveModule?: (specifier: string) => string): EsbuildCommand; export { copyDir }; export declare function isServerlessNativePlatformPackage(packageName: string): boolean; type ServerlessFfmpegStaticArch = "arm64" | "x64"; export declare function shouldBundleFfmpegStaticForServerless(hostPlatform?: NodeJS.Platform, hostArch?: NodeJS.Architecture, targetArch?: ServerlessFfmpegStaticArch | null): boolean; export declare function findServerlessBrowserRuntimeConsumer(projectCwd?: string): string | null; export declare function findInstalledPackageRoot(packageName: string, nodeModulesRoots: string[], fromPackageDir?: string): string | null; export declare function copyInstalledBrowserRuntimePackages(serverDir: string | undefined, projectCwd?: string): number; export declare function copyInstalledExternalSsrPackages(serverDir: string | undefined, projectCwd?: string): number; export declare function findInstalledFfmpegStaticPackage(nodeModulesRoots: string[]): string | null; export declare function findInstalledResvgPackages(nodeModulesRoots: string[]): Array<{ packageName: string; packageDir: string; }>; export declare function isDurableBackgroundDeployEnabled(): boolean; export declare const NETLIFY_INTEGRATION_RECOVERY_FUNCTION_NAME = "server-integration-recovery"; export declare function isIntegrationDurableDispatchDeployEnabled(): boolean; export declare const NETLIFY_RECURRING_JOBS_FUNCTION_NAME = "agent-native-recurring-jobs"; export declare function isRecurringJobsDeployEnabled(): boolean; export declare function isKeepWarmDeployEnabled(): boolean; export declare function isKeepWarmBackgroundDeployEnabled(): boolean; export declare function resolveKeepWarmSchedule(): string; export declare function resolveVercelSweepCronSchedule(env?: NodeJS.ProcessEnv): string; export declare function vercelSweepCrons(sweepPaths: readonly string[], env?: NodeJS.ProcessEnv): Array<{ path: string; schedule: string; }>; export declare function addVercelSweepCron(outputDir: string, env?: NodeJS.ProcessEnv): void; /** * Reads back the sweep cron `addVercelSweepCron` wrote for an app mounted at * `basePath`. A workspace deploy must reuse it rather than recompute it: the * app's build resolved its framework route prefix from config files the * workspace build never reads. */ export declare function readVercelSweepCron(outputDir: string, basePath: string): { path: string; schedule: string; }; export declare function emitSingleTemplateNetlifyKeepWarmFunction(projectCwd: string): void; export declare function emitSingleTemplateNetlifyRecurringJobsFunction(projectCwd: string): void; /** * Single-template Netlify build: emit an async (background) function INSIDE the * scanned functions dir so the chat `_process-run` worker runs on Netlify's * 15-min async function instead of the synchronous `/*` catch-all. * Additive + flag-gated (see `isDurableBackgroundDeployEnabled`). * * GROUNDED IN THE REAL NETLIFY BUILD OUTPUT (verified from a local Nitro build) * AND THE NETLIFY DOCS DEFAULT-URL RULE: * - Nitro's `netlify` preset emits exactly ONE function source at * `.netlify/functions-internal/server/`. `server.mjs` re-exports `main.mjs` * and declares `export const config = { path: "/*", excludedPath: * ["/.netlify/*"], preferStatic: true, ... }`. The `/*` catch-all is an * IN-CODE Functions-API-v2 `config.path` and it ALREADY EXCLUDES * `/.netlify/*`. * - The generated `.netlify/netlify.toml` sets * `functionsDirectory = ".netlify/functions-internal"`. Netlify scans EXACTLY * that dir; functions placed anywhere else (e.g. `.netlify/functions/`, which * is the BUILD OUTPUT dir where `@netlify/build` later writes the zipped * functions + `manifest.json`) are NEVER deployed. * - Every scanned function is reachable at its DEFAULT url * `/.netlify/functions/` BY DEFAULT. A custom `config.path` REMOVES * that default url; declaring NO custom `config.path` KEEPS it. * * THEREFORE we: * 1. Emit the background function INTO the scanned dir * (`.netlify/functions-internal/server-agent-background/`), sharing the same * built `main.mjs` bundle, so Netlify discovers it and honors its config. * 2. Give its `export const config` `background: true` (→ async invoke, * immediate 202, 15-min budget) and NO custom `config.path`. With no custom * path the function keeps its DEFAULT url * `/.netlify/functions/server-agent-background`, and because the Nitro * `server` function's `/*` catch-all already excludes `/.netlify/*`, that * default-url namespace is NEVER shadowed by the synchronous function — no * catch-all patch is needed. * 3. The entry NORMALIZES/rewrites the incoming request pathname to * `AGENT_CHAT_PROCESS_RUN_PATH` before delegating to `./main.mjs`. The * function is reached at its default url * (`/.netlify/functions/server-agent-background`), so the Nitro router needs * the path rewritten to the framework `_process-run` route, preserving the * method, ALL headers (the HMAC `Authorization: Bearer` MUST survive), and * the body. * 4. Set `globalThis.__AGENT_NATIVE_BACKGROUND_RUNTIME__ = true` at cold start * (read back by `isInBackgroundFunctionRuntime()` so the worker takes the * ~13-min soft-timeout). A `globalThis` flag — NOT `process.env` — keeps the * no-env-mutation guard satisfied and carries no cross-request state. * * The foreground dispatches to this DEFAULT url on hosted Netlify * (`resolveAgentChatProcessRunDispatchPath` → `AGENT_BACKGROUND_FUNCTION_URL_PATH`). * * WHY THIS IS THE DOC-CORRECT FIX: a prior attempt gave the function a custom * `config.path` (= the framework route) plus a catch-all `excludedPath` patch. * The custom `config.path` was NOT honored as a route in prod — a probe of * `POST /_agent-native/agent-chat/_process-run` returned 404. The doc-correct * approach (confirmed against the Netlify docs) is to use the DEFAULT function * url with no custom path: the function stays reachable at * `/.netlify/functions/` and is never shadowed because `/.netlify/*` is * already excluded from the `server` catch-all. * * Safety net regardless of Netlify routing nuance: if the dispatch fast-fails * (e.g. the function was not emitted), the foreground handler degrades to an * inline 40s synchronous run (see production-agent.ts). */ export declare function emitSingleTemplateNetlifyBackgroundFunction(projectCwd: string): void; export declare function assertEmittedBackgroundFunctionOnDisk(destDir: string, functionName: string): void; export declare function emitSingleTemplateNetlifyIntegrationRecoveryFunction(projectCwd: string): void; /** * Post-build patches for `cloudflare_module` server output. Recurses (via * `walkServerJavaScriptFiles`) because esbuild/Nitro can emit a dependency at * a nested path (e.g. `_libs/@agent-native/core.mjs`) — a flat `readdirSync` * silently skips it, leaving its module-scope `setInterval` call unpatched, * which Cloudflare rejects with error 10021. */ export declare function patchCloudflareModuleServerOutput(serverDir: string): void; export declare function bundleYjsRuntimeForServerlessOutput(serverDir: string, projectCwd: string): string[]; export declare function shouldBundleYjsRuntimeForPreset(targetPreset: string): boolean; export declare function nitroServerCodeSplittingGroupsForPreset(targetPreset: string): { test: RegExp; name: () => string; }[]; export declare function nitroServerCodeSplittingConfigForPreset(targetPreset: string): { output: { codeSplitting: { groups: { test: RegExp; name: () => string; }[]; }; }; } | { output?: undefined; }; export declare function assertSingleTemplateNetlifyBuildOutput(projectCwd: string): void; export declare function writeSingleTemplateNetlifyRedirects(projectCwd: string): void; export declare function shouldRemoveNetlifyStaticRootShell(projectCwd: string, environment?: Record): boolean; export declare function shouldPreserveNetlifyStaticRootShell(projectCwd: string, publishDir: string, environment?: Record): boolean; export declare function removeNetlifyStaticRootShell(publishDir: string): void; export declare function sanitizeServerlessFunctionPackageManifest(functionDir: string | undefined): void; export declare function pruneServerlessFunctionDeadWeight(functionDir: string | undefined): number; export interface NitroBuildHooks { prepare: (nitro: any) => Promise; copyPublicAssets: (nitro: any) => Promise; nitroBuild: (nitro: any) => Promise; } export interface NitroBuildPipelineOptions { nitro: any; hooks: NitroBuildHooks; clientDir: string; publicOutputDir: string | undefined; appBasePath: string; cwd: string; includeImmutableAssetRouteRules?: boolean; } export declare function copyDrizzleMigrationAssets(projectCwd: string, serverDir: string): string[]; /** * Run Nitro's lifecycle in the order required to ship a working React Router * framework-mode build. * * The critical ordering constraint is that the React Router client build must * be copied into `publicOutputDir` *before* `nitroBuild` runs. Nitro generates * the static-asset manifest baked into the server bundle by globbing * `publicDir` during the server build; files copied in after that point exist * on disk but are invisible to the runtime `serveStatic` handler. Every * /assets/* request then falls through to the SSR catch-all, which 404s * anything with a file extension. */ export declare function runNitroBuildPipeline(opts: NitroBuildPipelineOptions): Promise; export declare function publicDirIsMountedAtBasePath(publicOutputDir: string, appBasePath: string): boolean; export declare const CLOUDFLARE_MODULE_STUB_MODULES: readonly ["@napi-rs/canvas", "@resvg/resvg-js", "@sentry/node", "@sparticuz/chromium-min", "chartjs-node-canvas", "chokidar", "fsevents", "node-pty", "playwright", "playwright-core"]; export declare function createCloudflareModuleStubPlugin(): { name: string; resolveId(id: string): string | null; load(id: string): string | null; }; export declare const NITRO_SERVER_RUNTIME_BUNDLED_DEPS: readonly ["yjs"]; export declare function resolveNitroBundledYjsEntry(): string; export declare function nitroNoExternalsForPreset(targetPreset: string): true | readonly string[]; export declare function resolveNitroBuildReplacements(env?: NodeJS.ProcessEnv, deploymentEnvironment?: string, projectCwd?: string, firstRunOnboardingMode?: AgentNativeFirstRunOnboardingMode | "", harnessMode?: string): Record; export declare function assertCloudflarePagesPresetRemoved(targetPreset: string): void;