Files
openclaw/src/gateway/server.ts
T
2026-07-27 05:44:16 -04:00

43 lines
1.7 KiB
TypeScript

/**
* Lazy public entrypoint for the gateway server implementation.
*
* Keeping `server.impl` behind dynamic import lets light-weight callers import
* server types and helpers without paying the full startup dependency graph.
*/
export { truncateCloseReason } from "./server/close-reason.js";
export type { GatewayServer, GatewayServerOptions } from "./server.impl.js";
async function emitStartupTrace(name: string, durationMs: number, totalMs: number): Promise<void> {
if (!process.env.OPENCLAW_GATEWAY_STARTUP_TRACE) {
return;
}
const { formatConsoleDiagnosticLine } = await import("../logging/json-console-line.js");
const message = `[gateway] startup trace: ${name} ${durationMs.toFixed(1)}ms total=${totalMs.toFixed(1)}ms`;
process.stderr.write(`${formatConsoleDiagnosticLine({ level: "info", message })}\n`);
}
async function loadServerImpl() {
const startupStartedAt = performance.now();
const before = performance.now();
try {
return await import("./server.impl.js");
} finally {
const now = performance.now();
await emitStartupTrace("gateway.server-impl-import", now - before, now - startupStartedAt);
}
}
/** Starts the gateway server after lazily loading the full server implementation. */
export async function startGatewayServer(
...args: Parameters<typeof import("./server.impl.js").startGatewayServer>
): ReturnType<typeof import("./server.impl.js").startGatewayServer> {
const mod = await loadServerImpl();
return await mod.startGatewayServer(...args);
}
/** Clears prepared model-catalog generations between tests. */
export async function resetPreparedModelCatalogForTest(): Promise<void> {
const mod = await loadServerImpl();
await mod.resetPreparedModelCatalogForTest();
}