openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
36 lines (35 loc) • 1.45 kB
JavaScript
import { t as truncateCloseReason } from "./close-reason-C0VVCJld.js";
//#region src/gateway/server.ts
async function emitStartupTrace(name, durationMs, totalMs) {
if (!process.env.OPENCLAW_GATEWAY_STARTUP_TRACE) return;
const { formatConsoleDiagnosticLine } = await import("./json-console-line-kiRP3hor.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 loadServerStart() {
const startupStartedAt = performance.now();
const before = performance.now();
try {
return await import("./server-start-yuOHTviK.js");
} finally {
const now = performance.now();
await emitStartupTrace("gateway.server-start-import", now - before, now - startupStartedAt);
}
}
/** Starts the gateway server after lazily loading the full server implementation. */
async function startGatewayServer(port = 18789, opts = {}) {
const startupStartedAt = opts.startupStartedAt ?? Date.now();
return await (await loadServerStart()).startGatewayServerCore(port, {
...opts,
startupStartedAt
});
}
/** Clears prepared model-catalog generations between tests. */
async function resetPreparedModelCatalogForTest() {
await (await loadServerStart()).resetPreparedModelCatalogForTestCore();
}
//#endregion
export { resetPreparedModelCatalogForTest, startGatewayServer, truncateCloseReason };