11import { setTimeout as delay } from "node:timers/promises" ;
22import type { Command } from "commander" ;
3- import { buildGatewayConnectionDetails } from "../gateway/call.js" ;
43import { parseLogLine } from "../logging/parse-log-line.js" ;
54import { formatTimestamp , isValidTimeZone } from "../logging/timestamps.js" ;
65import { formatDocsLink } from "../terminal/links.js" ;
@@ -10,6 +9,15 @@ import { colorize, isRich, theme } from "../terminal/theme.js";
109import { formatCliCommand } from "./command-format.js" ;
1110import { addGatewayClientOptions , callGatewayFromCli } from "./gateway-rpc.js" ;
1211
12+ type LogsCliRuntimeModule = typeof import ( "./logs-cli.runtime.js" ) ;
13+
14+ let logsCliRuntimePromise : Promise < LogsCliRuntimeModule > | undefined ;
15+
16+ async function loadLogsCliRuntime ( ) : Promise < LogsCliRuntimeModule > {
17+ logsCliRuntimePromise ??= import ( "./logs-cli.runtime.js" ) ;
18+ return logsCliRuntimePromise ;
19+ }
20+
1321type LogsTailPayload = {
1422 file ?: string ;
1523 cursor ?: number ;
@@ -149,19 +157,20 @@ function createLogWriters() {
149157 } ;
150158}
151159
152- function emitGatewayError (
160+ async function emitGatewayError (
153161 err : unknown ,
154162 opts : LogsCliOptions ,
155163 mode : "json" | "text" ,
156164 rich : boolean ,
157165 emitJsonLine : ( payload : Record < string , unknown > , toStdErr ?: boolean ) => boolean ,
158166 errorLine : ( text : string ) => boolean ,
159167) {
160- const details = buildGatewayConnectionDetails ( { url : opts . url } ) ;
168+ const runtime = await loadLogsCliRuntime ( ) ;
161169 const message = "Gateway not reachable. Is it running and accessible?" ;
162170 const hint = `Hint: run \`${ formatCliCommand ( "openclaw doctor" ) } \`.` ;
163171 const errorText = err instanceof Error ? err . message : String ( err ) ;
164172
173+ const details = runtime . buildGatewayConnectionDetails ( { url : opts . url } ) ;
165174 if ( mode === "json" ) {
166175 if (
167176 ! emitJsonLine (
@@ -227,7 +236,14 @@ export function registerLogsCli(program: Command) {
227236 try {
228237 payload = await fetchLogs ( opts , cursor , showProgress ) ;
229238 } catch ( err ) {
230- emitGatewayError ( err , opts , jsonMode ? "json" : "text" , rich , emitJsonLine , errorLine ) ;
239+ await emitGatewayError (
240+ err ,
241+ opts ,
242+ jsonMode ? "json" : "text" ,
243+ rich ,
244+ emitJsonLine ,
245+ errorLine ,
246+ ) ;
231247 process . exit ( 1 ) ;
232248 return ;
233249 }
0 commit comments