UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

59 lines (58 loc) 2.73 kB
import { a as writeRuntimeJson } from "./runtime-CF2WjnNZ.js"; //#region src/cli/gateway-cli/health-route.ts async function resolveRouteRpcOptions(args, deps) { if (args.localPortOverride === void 0) return args.rpc; const config = await (deps.readNonObservingHealthConfig ?? (await import("./health-YMSl1wN1.js")).readNonObservingHealthConfig)(); return { ...args.rpc, localPortOverride: args.localPortOverride, config: { ...config, gateway: { ...config.gateway, mode: "local", port: args.localPortOverride } } }; } /** Run the successful JSON path without loading text presentation modules. */ async function runGatewayHealthJsonRoute(args, runtime, deps = {}) { let rpc; try { rpc = await resolveRouteRpcOptions(args, deps); const callGateway = deps.callGateway ?? (await import("./gateway-rpc-CsophNA8.js")).callGatewayFromCliWithTransport; writeRuntimeJson(runtime, await callGateway("health", rpc, void 0, { defaultTimeoutMs: 1e4, sharedStateMode: "read-only" })); } catch (error) { if (!rpc) throw error; const [healthModule, callModule] = await Promise.all([deps.emitReachableGatewayAuthDiagnostic && deps.readNonObservingHealthConfig ? void 0 : import("./health-YMSl1wN1.js"), deps.formatGatewayAuthErrorJson && deps.formatGatewayClientRequestErrorJson && deps.formatGatewayTransportErrorJson ? void 0 : import("./call-Bo4Qx1ax.js")]); const emitReachableGatewayAuthDiagnostic = deps.emitReachableGatewayAuthDiagnostic ?? healthModule?.emitReachableGatewayAuthDiagnostic; const readNonObservingHealthConfig = deps.readNonObservingHealthConfig ?? healthModule?.readNonObservingHealthConfig; if (!emitReachableGatewayAuthDiagnostic || !readNonObservingHealthConfig) throw error; if (await emitReachableGatewayAuthDiagnostic({ error, config: rpc.config ?? await readNonObservingHealthConfig(), runtime, timeoutMs: Number(rpc.timeout ?? "10000"), token: rpc.token, password: rpc.password, localPortOverride: rpc.localPortOverride, json: true })) return; const formatGatewayAuthErrorJson = deps.formatGatewayAuthErrorJson ?? callModule?.formatGatewayAuthErrorJson; const formatGatewayClientRequestErrorJson = deps.formatGatewayClientRequestErrorJson ?? callModule?.formatGatewayClientRequestErrorJson; const formatGatewayTransportErrorJson = deps.formatGatewayTransportErrorJson ?? callModule?.formatGatewayTransportErrorJson; const payload = formatGatewayAuthErrorJson?.(error) ?? formatGatewayClientRequestErrorJson?.(error) ?? formatGatewayTransportErrorJson?.(error); if (payload) { writeRuntimeJson(runtime, payload); runtime.exit(1); return; } throw error; } } //#endregion export { runGatewayHealthJsonRoute };