Files
OpenMAIC/instrumentation.ts
T
wyuc 06f105ed4d feat(server): validate model routing config at startup (#1182)
* feat(server): validate model routing config at startup and deprecate bare model ids

* fix(server): keep the bare-id deprecation warning out of request paths

parseModelString is reachable with request-controlled strings, so warning
there lets clients drive log volume and grow the dedupe set without bound;
the warning now fires only from boot-time validation of config-derived
sites, whose surface is finite. DEFAULT_MODEL missing-key wording no longer
claims requests will fail (unrouted resolution honors client keys), and a
keyless provider with a default base URL is not flagged as unconfigured.
2026-08-26 10:59:47 +08:00

31 lines
1.4 KiB
TypeScript

/**
* Process-scoped startup work.
*
* Next calls `register` once per server instance, before it serves a request.
* That makes it the only place in this app where a background schedule can
* live: a route module has no such guarantee — it can be instantiated more than
* once and gets no shutdown hook — so anything periodic started from one is
* really started per instantiation.
*
* `register` must return before the server is ready, so nothing here may block
* on I/O. Starting a timer does not.
*/
export async function register(): Promise<void> {
// Also invoked for the Edge runtime, which has neither `pg` nor timers we
// want; the persistence stack is Node-only.
if (process.env.NEXT_RUNTIME !== 'nodejs') return;
// Imported dynamically so the Edge bundle never pulls in `pg`.
const { startAssetCollectorSchedule } =
await import('@/lib/persistence/asset-collector-schedule');
startAssetCollectorSchedule();
// Warn-first boot-time validation of model routing config (MODEL_ROUTES,
// DEFAULT_MODEL, <PREFIX>_MODELS). Cheap and non-throwing: broken config
// surfaces here as [config] warnings instead of failing at request time.
// Imported dynamically so the Edge bundle never pulls in the fs/js-yaml
// backed provider config it reads.
const { validateServerConfig } = await import('@/lib/server/config-validation');
validateServerConfig();
}