@@ -504,6 +504,43 @@ function parseDtalePort(webServerUrl) {
504504 }
505505}
506506
507+ function extractDtaleReadyInfo ( progressPayload ) {
508+ let parsed = progressPayload
509+ if ( typeof parsed === "string" ) {
510+ parsed = cleanGoResponsePayload ( parsed )
511+ }
512+
513+ if ( parsed && typeof parsed === "object" ) {
514+ const remotePort = Number ( parsed . port ) || parseDtalePort ( parsed . web_server_url )
515+ return {
516+ parsed,
517+ error : parsed . error || null ,
518+ remotePort : Number . isFinite ( remotePort ) && remotePort > 0 ? remotePort : null ,
519+ webServerUrl : parsed . web_server_url || null ,
520+ name : parsed . name || null ,
521+ snapshot : JSON . stringify ( parsed )
522+ }
523+ }
524+
525+ const raw = typeof progressPayload === "string" ? progressPayload : String ( progressPayload || "" )
526+ const urlMatch = raw . match ( / " w e b _ s e r v e r _ u r l " \s * : \s * " ( [ ^ " ] + ) " / )
527+ const portMatch = raw . match ( / " p o r t " \s * : \s * ( \d + ) / )
528+ const nameMatch = raw . match ( / " n a m e " \s * : \s * " ( [ ^ " ] + ) " / )
529+ const errorMatch = raw . match ( / " e r r o r " \s * : \s * " ( [ ^ " ] + ) " / )
530+
531+ const urlFromRaw = urlMatch ? urlMatch [ 1 ] : null
532+ const portFromRaw = portMatch ? Number ( portMatch [ 1 ] ) : parseDtalePort ( urlFromRaw )
533+
534+ return {
535+ parsed : null ,
536+ error : errorMatch ? errorMatch [ 1 ] : null ,
537+ remotePort : Number . isFinite ( portFromRaw ) && portFromRaw > 0 ? portFromRaw : null ,
538+ webServerUrl : urlFromRaw ,
539+ name : nameMatch ? nameMatch [ 1 ] : null ,
540+ snapshot : raw
541+ }
542+ }
543+
507544async function waitForDtaleReady ( progressTopic , timeoutMs = 300000 ) {
508545 const start = Date . now ( )
509546 let lastProgress = null
@@ -517,40 +554,26 @@ async function waitForDtaleReady(progressTopic, timeoutMs = 300000) {
517554 continue
518555 }
519556
520- if ( typeof progress === "string" ) {
521- progress = cleanGoResponsePayload ( progress )
557+ const readyInfo = extractDtaleReadyInfo ( progress )
558+ if ( readyInfo . snapshot ) {
559+ lastProgress = readyInfo . snapshot
522560 }
523561
524- if ( progress && typeof progress === "object" ) {
525- lastProgress = progress
562+ if ( readyInfo . error ) {
563+ throw new Error ( `D-Tale startup failed: ${ readyInfo . error } ` )
526564 }
527565
528- if ( progress && typeof progress === "object" && progress . error ) {
529- throw new Error ( `D-Tale startup failed: ${ progress . error } ` )
530- }
531-
532- if ( progress && progress . web_server_url ) {
533- const remotePort = parseDtalePort ( progress . web_server_url )
534- if ( remotePort ) {
535- return {
536- webServerUrl : progress . web_server_url ,
537- remotePort,
538- name : progress . name || "D-Tale"
539- }
540- }
541- }
542-
543- const progressPort = Number ( progress && progress . port )
544- if ( Number . isFinite ( progressPort ) && progressPort > 0 ) {
566+ if ( readyInfo . remotePort ) {
567+ const resolvedUrl = readyInfo . webServerUrl || `http://127.0.0.1:${ readyInfo . remotePort } /`
545568 return {
546- webServerUrl : `http://127.0.0.1: ${ progressPort } /` ,
547- remotePort : progressPort ,
548- name : ( progress && progress . name ) || "D-Tale"
569+ webServerUrl : resolvedUrl ,
570+ remotePort : readyInfo . remotePort ,
571+ name : readyInfo . name || "D-Tale"
549572 }
550573 }
551574 await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
552575 }
553- const lastSnapshot = lastProgress ? JSON . stringify ( lastProgress ) : "no-progress-snapshot"
576+ const lastSnapshot = lastProgress || "no-progress-snapshot"
554577 throw new Error ( `Timed out waiting for D-Tale web server to become ready (last progress: ${ lastSnapshot } )` )
555578}
556579
@@ -620,6 +643,26 @@ expressApp.post("/exploratory/dtale/start", async (req, res) => {
620643 }
621644} )
622645
646+ expressApp . post ( "/exploratory/dtale/progress" , async ( req , res ) => {
647+ try {
648+ const routeId = req ?. body ?. routeId
649+ if ( ! routeId || typeof routeId !== "string" ) {
650+ return res . status ( 400 ) . json ( { success : false , error : "routeId is required" } )
651+ }
652+
653+ if ( ! serviceState . go . running || ! serviceState . go . port ) {
654+ await startGoServer ( )
655+ }
656+
657+ const progress = await callGoEndpoint ( `/exploratory/progress/${ routeId } ` , { } , { timeoutMs : 10000 } )
658+ const parsedProgress = typeof progress === "string" ? cleanGoResponsePayload ( progress ) : progress
659+ return res . json ( { success : true , progress : parsedProgress } )
660+ } catch ( err ) {
661+ console . error ( "Error getting D-Tale progress:" , err )
662+ return res . status ( 500 ) . json ( { success : false , error : err . message } )
663+ }
664+ } )
665+
623666expressApp . post ( "/exploratory/dtale/stop" , async ( req , res ) => {
624667 try {
625668 const body = req . body || { }
0 commit comments