(text: string, bridgeSessionId: string)
| 319 | ) |
| 320 | } |
| 321 | const onUserMessage = (text: string, bridgeSessionId: string): boolean => { |
| 322 | if (hasExplicitTitle || getCurrentSessionTitle(getSessionId())) { |
| 323 | return true |
| 324 | } |
| 325 | // v1 env-lost re-creates the session with a new ID. Reset the count so |
| 326 | // the new session gets its own count-3 derivation; hasTitle stays true |
| 327 | // (new session was created via getCurrentTitle(), which reads the count-1 |
| 328 | // title from this closure), so count-1 of the fresh cycle correctly skips. |
| 329 | if ( |
| 330 | lastBridgeSessionId !== undefined && |
| 331 | lastBridgeSessionId !== bridgeSessionId |
| 332 | ) { |
| 333 | userMessageCount = 0 |
| 334 | } |
| 335 | lastBridgeSessionId = bridgeSessionId |
| 336 | userMessageCount++ |
| 337 | if (userMessageCount === 1 && !hasTitle) { |
| 338 | const placeholder = deriveTitle(text) |
| 339 | if (placeholder) patch(placeholder, bridgeSessionId, userMessageCount) |
| 340 | generateAndPatch(text, bridgeSessionId) |
| 341 | } else if (userMessageCount === 3) { |
| 342 | const msgs = getMessages?.() |
| 343 | const input = msgs |
| 344 | ? extractConversationText(getMessagesAfterCompactBoundary(msgs)) |
| 345 | : text |
| 346 | generateAndPatch(input, bridgeSessionId) |
| 347 | } |
| 348 | // Also re-latches if v1 env-lost resets the transport's done flag past 3. |
| 349 | return userMessageCount >= 3 |
| 350 | } |
| 351 | |
| 352 | const initialHistoryCap = getFeatureValue_CACHED_WITH_REFRESH( |
| 353 | 'ncode_bridge_initial_history_cap', |
no test coverage detected