(text: string, bridgeSessionId: string)
| 351 | ) |
| 352 | } |
| 353 | const onUserMessage = (text: string, bridgeSessionId: string): boolean => { |
| 354 | if (hasExplicitTitle || getCurrentSessionTitle(getSessionId())) { |
| 355 | return true |
| 356 | } |
| 357 | // v1 env-lost re-creates the session with a new ID. Reset the count so |
| 358 | // the new session gets its own count-3 derivation; hasTitle stays true |
| 359 | // (new session was created via getCurrentTitle(), which reads the count-1 |
| 360 | // title from this closure), so count-1 of the fresh cycle correctly skips. |
| 361 | if ( |
| 362 | lastBridgeSessionId !== undefined && |
| 363 | lastBridgeSessionId !== bridgeSessionId |
| 364 | ) { |
| 365 | userMessageCount = 0 |
| 366 | } |
| 367 | lastBridgeSessionId = bridgeSessionId |
| 368 | userMessageCount++ |
| 369 | if (userMessageCount === 1 && !hasTitle) { |
| 370 | const placeholder = deriveTitle(text) |
| 371 | if (placeholder) patch(placeholder, bridgeSessionId, userMessageCount) |
| 372 | generateAndPatch(text, bridgeSessionId) |
| 373 | } else if (userMessageCount === 3) { |
| 374 | const msgs = getMessages?.() |
| 375 | const input = msgs |
| 376 | ? extractConversationText(getMessagesAfterCompactBoundary(msgs)) |
| 377 | : text |
| 378 | generateAndPatch(input, bridgeSessionId) |
| 379 | } |
| 380 | // Also re-latches if v1 env-lost resets the transport's done flag past 3. |
| 381 | return userMessageCount >= 3 |
| 382 | } |
| 383 | |
| 384 | const initialHistoryCap = getFeatureValue_CACHED_WITH_REFRESH( |
| 385 | 'tengu_bridge_initial_history_cap', |
no test coverage detected