From a7409737079b0d9a6450460b8f1f00faf8f9155e Mon Sep 17 00:00:00 2001 From: Kang Kaihui Date: Thu, 30 Apr 2026 15:56:13 +0800 Subject: [PATCH] src: Fix variable 'endTime' used before its declaration Co-authored-by: Copilot --- src/agents/pi-embedded-subscribe.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/agents/pi-embedded-subscribe.ts b/src/agents/pi-embedded-subscribe.ts index 0d0a6c6102dee..3eaeec6110a51 100644 --- a/src/agents/pi-embedded-subscribe.ts +++ b/src/agents/pi-embedded-subscribe.ts @@ -526,7 +526,10 @@ export function subscribeEmbeddedPiSession(params: SubscribeEmbeddedPiSessionPar const startTime = Date.now(); log.info(`[TRACE] stripBlockTags start textLength=${text.length} timestamp=${startTime}`); if (!text) { - log.info(`[TRACE] stripBlockTags end textLength=${text.length}RdurationMs=${endTime - startTime} timestamp=${endTime}`); + const endTime = Date.now(); + log.info( + `[TRACE] stripBlockTags end textLength=${text.length}RdurationMs=${endTime - startTime} timestamp=${endTime}`, + ); return text; } @@ -573,8 +576,11 @@ export function subscribeEmbeddedPiSession(params: SubscribeEmbeddedPiSessionPar if (!params.enforceFinalTag) { state.inlineCode = finalCodeSpans.inlineState; FINAL_TAG_SCAN_RE.lastIndex = 0; - out = stripTagsOutsideCodeSpans(processed, FINAL_TAG_SCAN_RE, finalCodeSpans.isInside); - log.info(`[TRACE] stripBlockTags end textLength=${text.length}RdurationMs=${endTime - startTime} timestamp=${endTime}`); + const out = stripTagsOutsideCodeSpans(processed, FINAL_TAG_SCAN_RE, finalCodeSpans.isInside); + const endTime = Date.now(); + log.info( + `[TRACE] stripBlockTags end textLength=${text.length}RdurationMs=${endTime - startTime} timestamp=${endTime}`, + ); return out; } @@ -614,7 +620,10 @@ export function subscribeEmbeddedPiSession(params: SubscribeEmbeddedPiSessionPar // we have seen a tag. Otherwise, we leak "thinking out loud" text // (e.g. "**Locating Manulife**...") that the model emitted without tags. if (!everInFinal) { - log.info(`[TRACE] stripBlockTags end textLength=${text.length}RdurationMs=${endTime - startTime} timestamp=${endTime}`); + const endTime = Date.now(); + log.info( + `[TRACE] stripBlockTags end textLength=${text.length}RdurationMs=${endTime - startTime} timestamp=${endTime}`, + ); return ""; } @@ -623,8 +632,10 @@ export function subscribeEmbeddedPiSession(params: SubscribeEmbeddedPiSessionPar const resultCodeSpans = buildCodeSpanIndex(result, inlineStateStart); state.inlineCode = resultCodeSpans.inlineState; const endTime = Date.now(); - out = stripTagsOutsideCodeSpans(result, FINAL_TAG_SCAN_RE, resultCodeSpans.isInside); - log.info(`[TRACE] stripBlockTags end textLength=${text.length}RdurationMs=${endTime - startTime} timestamp=${endTime}`); + const out = stripTagsOutsideCodeSpans(result, FINAL_TAG_SCAN_RE, resultCodeSpans.isInside); + log.info( + `[TRACE] stripBlockTags end textLength=${text.length}RdurationMs=${endTime - startTime} timestamp=${endTime}`, + ); return out; };