@flamingo-stack/openframe-frontend-core 0.0.497 → 0.0.498-1506.4000.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat-protocol/decode.d.ts +58 -0
- package/dist/chat-protocol/decode.d.ts.map +1 -0
- package/dist/chat-protocol/encode.d.ts +44 -0
- package/dist/chat-protocol/encode.d.ts.map +1 -0
- package/dist/chat-protocol/env-flag.d.ts +35 -0
- package/dist/chat-protocol/env-flag.d.ts.map +1 -0
- package/dist/chat-protocol/events.d.ts +207 -0
- package/dist/chat-protocol/events.d.ts.map +1 -0
- package/dist/chat-protocol/frames.d.ts +213 -0
- package/dist/chat-protocol/frames.d.ts.map +1 -0
- package/dist/chat-protocol/index.cjs +500 -0
- package/dist/chat-protocol/index.cjs.map +1 -0
- package/dist/chat-protocol/index.d.ts +18 -0
- package/dist/chat-protocol/index.d.ts.map +1 -0
- package/dist/chat-protocol/index.js +484 -0
- package/dist/chat-protocol/index.js.map +1 -0
- package/dist/chat-protocol/ip-normalize.d.ts +44 -0
- package/dist/chat-protocol/ip-normalize.d.ts.map +1 -0
- package/dist/chat-protocol/nats-decoder.d.ts +26 -0
- package/dist/chat-protocol/nats-decoder.d.ts.map +1 -0
- package/dist/{chunk-2DER2JSI.cjs → chunk-242K7LZY.cjs} +11 -11
- package/dist/{chunk-2DER2JSI.cjs.map → chunk-242K7LZY.cjs.map} +1 -1
- package/dist/{chunk-VBSS4TPV.cjs → chunk-2LYA3RBT.cjs} +37 -37
- package/dist/{chunk-VBSS4TPV.cjs.map → chunk-2LYA3RBT.cjs.map} +1 -1
- package/dist/{chunk-ZPUCCSYA.js → chunk-34C2JV2C.js} +2 -2
- package/dist/{chunk-GWVNRXJU.js → chunk-3VGRZ62V.js} +2 -2
- package/dist/{chunk-AAHAVML2.js → chunk-42NYDEHH.js} +2 -2
- package/dist/{chunk-ZEHA4IC7.js → chunk-42SMPKGY.js} +2 -2
- package/dist/{chunk-RTG5DJWM.cjs → chunk-44C23SSC.cjs} +5 -5
- package/dist/{chunk-RTG5DJWM.cjs.map → chunk-44C23SSC.cjs.map} +1 -1
- package/dist/{chunk-SL62IZ3I.cjs → chunk-4KKGHPNE.cjs} +9 -9
- package/dist/{chunk-SL62IZ3I.cjs.map → chunk-4KKGHPNE.cjs.map} +1 -1
- package/dist/{chunk-X2CYUCGL.cjs → chunk-5BQWVNRS.cjs} +62 -62
- package/dist/{chunk-X2CYUCGL.cjs.map → chunk-5BQWVNRS.cjs.map} +1 -1
- package/dist/{chunk-HRUXC3YN.js → chunk-5QWYIPMH.js} +2 -2
- package/dist/{chunk-NT3BKPEC.js → chunk-5ZY5JM4Z.js} +10 -10
- package/dist/chunk-5ZY5JM4Z.js.map +1 -0
- package/dist/{chunk-4C764VBX.cjs → chunk-62TM2RVZ.cjs} +26 -26
- package/dist/{chunk-4C764VBX.cjs.map → chunk-62TM2RVZ.cjs.map} +1 -1
- package/dist/{chunk-YBTYHIXA.js → chunk-632XJ2ZT.js} +6 -5
- package/dist/chunk-632XJ2ZT.js.map +1 -0
- package/dist/{chunk-DGDUOFNY.js → chunk-BUBQEZ5J.js} +2 -2
- package/dist/{chunk-ZAAIVSX6.js → chunk-D3LUKR2Y.js} +11964 -9714
- package/dist/chunk-D3LUKR2Y.js.map +1 -0
- package/dist/{chunk-5KSXMJXF.cjs → chunk-EO35UHFT.cjs} +60 -60
- package/dist/chunk-EO35UHFT.cjs.map +1 -0
- package/dist/{chunk-5YKUEZIA.cjs → chunk-EORFD5WB.cjs} +15 -15
- package/dist/{chunk-5YKUEZIA.cjs.map → chunk-EORFD5WB.cjs.map} +1 -1
- package/dist/{chunk-MEIMDHQ2.cjs → chunk-F7XPMG25.cjs} +28 -27
- package/dist/chunk-F7XPMG25.cjs.map +1 -0
- package/dist/{chunk-I74ADMZS.cjs → chunk-H6GFQ4AO.cjs} +7 -7
- package/dist/{chunk-I74ADMZS.cjs.map → chunk-H6GFQ4AO.cjs.map} +1 -1
- package/dist/{chunk-EOYFMWDT.cjs → chunk-J3NHQ4JB.cjs} +31 -31
- package/dist/{chunk-EOYFMWDT.cjs.map → chunk-J3NHQ4JB.cjs.map} +1 -1
- package/dist/{chunk-23QJPSZJ.cjs → chunk-SS3D3DHL.cjs} +7049 -4799
- package/dist/chunk-SS3D3DHL.cjs.map +1 -0
- package/dist/{chunk-6XQGPFIR.js → chunk-WNXIG6YY.js} +2 -2
- package/dist/{chunk-5INZDVGI.js → chunk-WZCQW4MW.js} +4 -4
- package/dist/{chunk-B3MRHZNZ.js → chunk-ZHC2BCXK.js} +4 -4
- package/dist/components/case-studies/index.cjs +8 -8
- package/dist/components/case-studies/index.js +2 -2
- package/dist/components/chat/chat-message-enhanced.d.ts.map +1 -1
- package/dist/components/chat/chat-message-list.d.ts.map +1 -1
- package/dist/components/chat/hooks/index.d.ts +0 -1
- package/dist/components/chat/hooks/index.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-chat.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-chunk-catchup.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts +15 -48
- package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts +10 -57
- package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +10 -2
- package/dist/components/chat/index.cjs.map +1 -1
- package/dist/components/chat/index.d.ts +1 -0
- package/dist/components/chat/index.d.ts.map +1 -1
- package/dist/components/chat/index.js +21 -13
- package/dist/components/chat/stream/chat-dialog-store.d.ts +184 -0
- package/dist/components/chat/stream/chat-dialog-store.d.ts.map +1 -0
- package/dist/components/chat/stream/chat-stream-reducer.d.ts +367 -0
- package/dist/components/chat/stream/chat-stream-reducer.d.ts.map +1 -0
- package/dist/components/chat/stream/delta-batcher.d.ts +51 -0
- package/dist/components/chat/stream/delta-batcher.d.ts.map +1 -0
- package/dist/components/chat/stream/index.d.ts +17 -0
- package/dist/components/chat/stream/index.d.ts.map +1 -0
- package/dist/components/chat/stream/message-mutations.d.ts +77 -0
- package/dist/components/chat/stream/message-mutations.d.ts.map +1 -0
- package/dist/components/chat/stream/use-chat-stream-reducer.d.ts +22 -0
- package/dist/components/chat/stream/use-chat-stream-reducer.d.ts.map +1 -0
- package/dist/components/chat/types/api.types.d.ts +1 -81
- package/dist/components/chat/types/api.types.d.ts.map +1 -1
- package/dist/components/chat/types/processing.types.d.ts +2 -93
- package/dist/components/chat/types/processing.types.d.ts.map +1 -1
- package/dist/components/chat/utils/extract-incomplete-message-state.d.ts +34 -6
- package/dist/components/chat/utils/extract-incomplete-message-state.d.ts.map +1 -1
- package/dist/components/chat/utils/index.d.ts +2 -3
- package/dist/components/chat/utils/index.d.ts.map +1 -1
- package/dist/components/chat/utils/process-historical-messages.d.ts +59 -11
- package/dist/components/chat/utils/process-historical-messages.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +3 -3
- package/dist/components/contact/index.js +2 -2
- package/dist/components/docs/index.cjs +5 -5
- package/dist/components/docs/index.js +4 -4
- package/dist/components/embeds/index.cjs +3 -3
- package/dist/components/embeds/index.js +2 -2
- package/dist/components/faq/index.cjs +3 -3
- package/dist/components/faq/index.js +2 -2
- package/dist/components/features/index.cjs +2 -2
- package/dist/components/features/index.js +1 -1
- package/dist/components/help-center-pages/index.cjs +20 -20
- package/dist/components/help-center-pages/index.js +11 -11
- package/dist/components/index.cjs +172 -130
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +63 -21
- package/dist/components/index.js.map +1 -1
- package/dist/components/navigation/index.cjs +2 -2
- package/dist/components/navigation/index.js +1 -1
- package/dist/components/onboarding-guides/index.cjs +5 -5
- package/dist/components/onboarding-guides/index.js +4 -4
- package/dist/components/onboarding-guides/onboarding-guide-detail-view.d.ts.map +1 -1
- package/dist/components/related-content/index.cjs +3 -3
- package/dist/components/related-content/index.js +2 -2
- package/dist/components/shared/product-release/release-detail-page.d.ts.map +1 -1
- package/dist/components/tickets/index.cjs +5 -5
- package/dist/components/tickets/index.js +4 -4
- package/dist/components/ui/index.cjs +44 -2
- package/dist/components/ui/index.cjs.map +1 -1
- package/dist/components/ui/index.d.ts +1 -2
- package/dist/components/ui/index.d.ts.map +1 -1
- package/dist/components/ui/index.js +55 -13
- package/dist/components/ui/markdown/base-components.d.ts +51 -0
- package/dist/components/ui/markdown/base-components.d.ts.map +1 -0
- package/dist/components/ui/markdown/engine.d.ts +99 -0
- package/dist/components/ui/markdown/engine.d.ts.map +1 -0
- package/dist/components/ui/markdown/heading-ids.d.ts +65 -0
- package/dist/components/ui/markdown/heading-ids.d.ts.map +1 -0
- package/dist/components/ui/markdown/index.d.ts +18 -0
- package/dist/components/ui/markdown/index.d.ts.map +1 -0
- package/dist/components/ui/markdown/mermaid-diagram.d.ts +79 -0
- package/dist/components/ui/markdown/mermaid-diagram.d.ts.map +1 -0
- package/dist/components/ui/markdown/rich/embed-overrides.d.ts +14 -0
- package/dist/components/ui/markdown/rich/embed-overrides.d.ts.map +1 -0
- package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts +40 -0
- package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts.map +1 -0
- package/dist/components/ui/markdown/rich/shortcodes.d.ts +8 -0
- package/dist/components/ui/markdown/rich/shortcodes.d.ts.map +1 -0
- package/dist/components/ui/markdown/sanitize.d.ts +153 -0
- package/dist/components/ui/markdown/sanitize.d.ts.map +1 -0
- package/dist/components/ui/markdown/simple-markdown-renderer.d.ts +23 -0
- package/dist/components/ui/markdown/simple-markdown-renderer.d.ts.map +1 -0
- package/dist/components/ui/markdown/streaming.d.ts +78 -0
- package/dist/components/ui/markdown/streaming.d.ts.map +1 -0
- package/dist/components/ui/markdown/text-size.d.ts +34 -0
- package/dist/components/ui/markdown/text-size.d.ts.map +1 -0
- package/dist/index.cjs +60 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +71 -13
- package/dist/utils/index.cjs +169 -40
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +162 -41
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/markdown-fences.d.ts +42 -0
- package/dist/utils/markdown-fences.d.ts.map +1 -0
- package/dist/utils/markdown-heading-id.d.ts +85 -0
- package/dist/utils/markdown-heading-id.d.ts.map +1 -0
- package/dist/utils/markdown-section-extractor.d.ts.map +1 -1
- package/package.json +7 -1
- package/src/chat-protocol/__tests__/__snapshots__/nats-decoder-golden.test.ts.snap +317 -0
- package/src/chat-protocol/__tests__/chat-protocol.test.ts +516 -0
- package/src/chat-protocol/__tests__/env-flag.test.ts +52 -0
- package/src/chat-protocol/__tests__/ip-normalize.test.ts +136 -0
- package/src/chat-protocol/__tests__/nats-decoder-golden.test.ts +232 -0
- package/src/chat-protocol/decode.ts +278 -0
- package/src/chat-protocol/encode.ts +71 -0
- package/src/chat-protocol/env-flag.ts +39 -0
- package/src/chat-protocol/events.ts +245 -0
- package/src/chat-protocol/frames.ts +245 -0
- package/src/chat-protocol/index.ts +21 -0
- package/src/chat-protocol/ip-normalize.ts +146 -0
- package/src/chat-protocol/nats-decoder.ts +258 -0
- package/src/components/chat/__tests__/chat-message-list.test.tsx +381 -6
- package/src/components/chat/__tests__/chat-message-streaming-memo.test.tsx +207 -0
- package/src/components/chat/__tests__/chat-pending-turn.test.tsx +250 -0
- package/src/components/chat/chat-message-enhanced.tsx +122 -20
- package/src/components/chat/chat-message-list.tsx +409 -132
- package/src/components/chat/embeddable-chat.tsx +6 -0
- package/src/components/chat/hooks/.index.md +30 -33
- package/src/components/chat/hooks/.use-nats-chat-adapter.md +36 -55
- package/src/components/chat/hooks/__tests__/__snapshots__/conversation-id-persistence-golden.test.ts.snap +37 -0
- package/src/components/chat/hooks/__tests__/__snapshots__/sse-stream-golden.test.ts.snap +0 -0
- package/src/components/chat/hooks/__tests__/chunk-catchup-dialog-staleness.test.ts +92 -0
- package/src/components/chat/hooks/__tests__/conversation-id-persistence-golden.test.ts +438 -0
- package/src/components/chat/hooks/__tests__/sse-stream-golden.test.ts +318 -0
- package/src/components/chat/hooks/index.ts +0 -1
- package/src/components/chat/hooks/use-chat.ts +8 -0
- package/src/components/chat/hooks/use-chunk-catchup.ts +26 -1
- package/src/components/chat/hooks/use-nats-chat-adapter.ts +254 -825
- package/src/components/chat/hooks/use-sse-chat-adapter.ts +380 -684
- package/src/components/chat/index.ts +5 -0
- package/src/components/chat/stream/__tests__/__snapshots__/chat-stream-reducer-golden.test.ts.snap +940 -0
- package/src/components/chat/stream/__tests__/chat-dialog-store.test.ts +806 -0
- package/src/components/chat/stream/__tests__/chat-stream-reducer-golden.test.ts +467 -0
- package/src/components/chat/stream/__tests__/chat-stream-reducer.test.ts +1248 -0
- package/src/components/chat/stream/__tests__/delta-batcher.test.ts +255 -0
- package/src/components/chat/stream/__tests__/use-chat-stream-reducer.test.ts +105 -0
- package/src/components/chat/stream/chat-dialog-store.ts +536 -0
- package/src/components/chat/stream/chat-stream-reducer.ts +1876 -0
- package/src/components/chat/stream/delta-batcher.ts +168 -0
- package/src/components/chat/stream/index.ts +55 -0
- package/src/components/chat/stream/message-mutations.ts +340 -0
- package/src/components/chat/stream/use-chat-stream-reducer.ts +126 -0
- package/src/components/chat/thinking-display.tsx +1 -1
- package/src/components/chat/types/.api.types.md +39 -49
- package/src/components/chat/types/.processing.types.md +29 -58
- package/src/components/chat/types/api.types.ts +6 -73
- package/src/components/chat/types/processing.types.ts +11 -53
- package/src/components/chat/utils/.index.md +31 -40
- package/src/components/chat/utils/__tests__/__snapshots__/process-historical-messages-golden.test.ts.snap +420 -0
- package/src/components/chat/utils/__tests__/__snapshots__/segment-accumulator-golden.test.ts.snap +605 -0
- package/src/components/chat/utils/__tests__/process-historical-messages-approvals.test.ts +61 -0
- package/src/components/chat/utils/__tests__/process-historical-messages-golden.test.ts +394 -0
- package/src/components/chat/utils/__tests__/segment-accumulator-golden.test.ts +270 -0
- package/src/components/chat/utils/extract-incomplete-message-state.ts +63 -5
- package/src/components/chat/utils/index.ts +5 -8
- package/src/components/chat/utils/process-historical-messages.ts +358 -386
- package/src/components/onboarding-guides/onboarding-guide-detail-view.tsx +22 -4
- package/src/components/shared/legal-document/legal-document-page.tsx +1 -1
- package/src/components/shared/product-release/release-detail-page.tsx +19 -4
- package/src/components/ui/__tests__/__snapshots__/markdown-parity.test.tsx.snap +2420 -0
- package/src/components/ui/__tests__/markdown-parity.test.tsx +2540 -0
- package/src/components/ui/index.ts +1 -2
- package/src/components/ui/markdown/__tests__/mermaid-security.test.ts +176 -0
- package/src/components/ui/markdown/__tests__/mermaid-stale-render.test.tsx +151 -0
- package/src/components/ui/markdown/__tests__/sanitize-invariant.test.ts +354 -0
- package/src/components/ui/markdown/__tests__/sanitize-render.test.tsx +118 -0
- package/src/components/ui/markdown/__tests__/streaming.test.tsx +436 -0
- package/src/components/ui/markdown/base-components.tsx +360 -0
- package/src/components/ui/markdown/engine.tsx +315 -0
- package/src/components/ui/markdown/heading-ids.ts +239 -0
- package/src/components/ui/markdown/index.ts +49 -0
- package/src/components/ui/markdown/mermaid-diagram.tsx +323 -0
- package/src/components/ui/markdown/rich/embed-overrides.tsx +199 -0
- package/src/components/ui/markdown/rich/rich-markdown-renderer.tsx +184 -0
- package/src/components/ui/markdown/rich/shortcodes.ts +170 -0
- package/src/components/ui/markdown/sanitize.ts +3584 -0
- package/src/components/ui/markdown/simple-markdown-renderer.tsx +28 -0
- package/src/components/ui/markdown/streaming.ts +390 -0
- package/src/components/ui/markdown/text-size.ts +106 -0
- package/src/components/ui/release-changelog-section.tsx +1 -1
- package/src/components/ui/ticket-info-section.tsx +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/markdown-fences.ts +127 -0
- package/src/utils/markdown-heading-id.ts +348 -0
- package/src/utils/markdown-section-extractor.ts +41 -56
- package/dist/chunk-23QJPSZJ.cjs.map +0 -1
- package/dist/chunk-5KSXMJXF.cjs.map +0 -1
- package/dist/chunk-MEIMDHQ2.cjs.map +0 -1
- package/dist/chunk-NT3BKPEC.js.map +0 -1
- package/dist/chunk-YBTYHIXA.js.map +0 -1
- package/dist/chunk-ZAAIVSX6.js.map +0 -1
- package/dist/components/chat/hooks/use-realtime-chunk-processor.d.ts +0 -6
- package/dist/components/chat/hooks/use-realtime-chunk-processor.d.ts.map +0 -1
- package/dist/components/chat/utils/chunk-parser.d.ts +0 -25
- package/dist/components/chat/utils/chunk-parser.d.ts.map +0 -1
- package/dist/components/ui/rich-markdown-renderer.d.ts +0 -34
- package/dist/components/ui/rich-markdown-renderer.d.ts.map +0 -1
- package/dist/components/ui/simple-markdown-renderer.d.ts +0 -73
- package/dist/components/ui/simple-markdown-renderer.d.ts.map +0 -1
- package/src/components/chat/hooks/.use-realtime-chunk-processor.md +0 -77
- package/src/components/chat/hooks/use-realtime-chunk-processor.ts +0 -489
- package/src/components/chat/utils/.chunk-parser.md +0 -62
- package/src/components/chat/utils/chunk-parser.ts +0 -262
- package/src/components/ui/.simple-markdown-renderer.md +0 -52
- package/src/components/ui/rich-markdown-renderer.tsx +0 -1223
- package/src/components/ui/simple-markdown-renderer.tsx +0 -964
- /package/dist/{chunk-ZPUCCSYA.js.map → chunk-34C2JV2C.js.map} +0 -0
- /package/dist/{chunk-GWVNRXJU.js.map → chunk-3VGRZ62V.js.map} +0 -0
- /package/dist/{chunk-AAHAVML2.js.map → chunk-42NYDEHH.js.map} +0 -0
- /package/dist/{chunk-ZEHA4IC7.js.map → chunk-42SMPKGY.js.map} +0 -0
- /package/dist/{chunk-HRUXC3YN.js.map → chunk-5QWYIPMH.js.map} +0 -0
- /package/dist/{chunk-DGDUOFNY.js.map → chunk-BUBQEZ5J.js.map} +0 -0
- /package/dist/{chunk-6XQGPFIR.js.map → chunk-WNXIG6YY.js.map} +0 -0
- /package/dist/{chunk-5INZDVGI.js.map → chunk-WZCQW4MW.js.map} +0 -0
- /package/dist/{chunk-B3MRHZNZ.js.map → chunk-ZHC2BCXK.js.map} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { useRef, useEffect, useLayoutEffect, useImperativeHandle, forwardRef } from "react"
|
|
3
|
+
import { useRef, useState, useCallback, useEffect, useLayoutEffect, useImperativeHandle, forwardRef } from "react"
|
|
4
4
|
import { useStickToBottom } from "use-stick-to-bottom"
|
|
5
5
|
import { cn } from "../../utils/cn"
|
|
6
6
|
import { ChatMessageEnhanced } from "./chat-message-enhanced"
|
|
7
7
|
import { ChatMessageListSkeleton } from "./chat-message-skeleton"
|
|
8
|
-
import { DotsLoaderIcon } from "../icons-v2-generated"
|
|
8
|
+
import { DotsLoaderIcon, Arrow02DownIcon } from "../icons-v2-generated"
|
|
9
9
|
import { CyclingPhrase } from "./cycling-phrase"
|
|
10
10
|
import type { ChatMessageListProps } from "./types"
|
|
11
11
|
import { SCROLL_ANCHOR } from "./types/message.types"
|
|
@@ -27,6 +27,11 @@ const STREAMING_WORDS = [
|
|
|
27
27
|
'Riffing',
|
|
28
28
|
] as const
|
|
29
29
|
|
|
30
|
+
/** Distance from the bottom (px) still counted as "at the bottom".
|
|
31
|
+
* Mirrors `use-stick-to-bottom`'s internal `STICK_TO_BOTTOM_OFFSET_PX`
|
|
32
|
+
* so the jump-to-bottom button and the library agree on the boundary. */
|
|
33
|
+
const BOTTOM_THRESHOLD_PX = 70
|
|
34
|
+
|
|
30
35
|
/*
|
|
31
36
|
* Stick-to-bottom: `use-stick-to-bottom` (stackblitz-labs)
|
|
32
37
|
*
|
|
@@ -53,6 +58,9 @@ const STREAMING_WORDS = [
|
|
|
53
58
|
* chat / sent a message; show me the bottom immediately").
|
|
54
59
|
* - **Load-more sentinel** (top-of-list IntersectionObserver) for
|
|
55
60
|
* infinite-scroll-UP. Distinct concern from stick-to-bottom.
|
|
61
|
+
* - **Bottom-follow intent** (see `followBottomRef` below). The
|
|
62
|
+
* library's follow is gated on its own `isAtBottom` flag, which this
|
|
63
|
+
* list's layout can lose silently; we own the INTENT and re-assert.
|
|
56
64
|
*
|
|
57
65
|
* `useStickToBottom`'s returned refs are MUTABLE refs + ref callbacks
|
|
58
66
|
* — pass them directly as `ref={scrollRef}` / `ref={contentRef}`.
|
|
@@ -142,6 +150,45 @@ const ChatMessageList = forwardRef<HTMLDivElement, ChatMessageListProps>(
|
|
|
142
150
|
const dialogIdRef = useRef(dialogId)
|
|
143
151
|
dialogIdRef.current = dialogId
|
|
144
152
|
|
|
153
|
+
// ---- Bottom-follow intent (list-owned lock) ----------------------
|
|
154
|
+
// The library follows the bottom only while ITS OWN `isAtBottom` flag
|
|
155
|
+
// is true, and this list's layout loses that flag silently in two
|
|
156
|
+
// ways:
|
|
157
|
+
//
|
|
158
|
+
// 1. **The scroller's own box changes.** The library's
|
|
159
|
+
// ResizeObserver watches `contentRef` (INSIDE the scroller) only.
|
|
160
|
+
// The streaming loader unmounting and the host's source-chip row
|
|
161
|
+
// mounting — both siblings BELOW the scroller (see render) —
|
|
162
|
+
// change the scroller's `clientHeight`, which moves the bottom
|
|
163
|
+
// without emitting anything the library can observe.
|
|
164
|
+
// 2. **Resize-induced scroll events read as a user gesture.**
|
|
165
|
+
// Fetch-mode entity cards mount as a skeleton and settle to a
|
|
166
|
+
// different height; a shrink clamps `scrollTop` down, and the
|
|
167
|
+
// library's scroll handler can see that as a scroll-UP and
|
|
168
|
+
// permanently escape the lock (its `resizeDifference` guard is a
|
|
169
|
+
// `setTimeout(…, 1)` race, so this is intermittent).
|
|
170
|
+
//
|
|
171
|
+
// Either way the thread stops following mid-turn. It bites hardest on
|
|
172
|
+
// card-heavy answers — a slash-command listing (`/getting-started`)
|
|
173
|
+
// renders a dozen fetch-mode cards with cover images that keep
|
|
174
|
+
// resolving for SECONDS after the stream ends, so everything after
|
|
175
|
+
// the lock was lost lands below the fold.
|
|
176
|
+
//
|
|
177
|
+
// Fix: this list owns the INTENT. Sending a message (or opening a
|
|
178
|
+
// dialog) arms it; only a real user scroll-up gesture — or a
|
|
179
|
+
// top-anchored turn, which deliberately parks elsewhere — disarms it.
|
|
180
|
+
// While armed, ANY geometry change re-asserts `scrollToBottom`, and
|
|
181
|
+
// because that call also re-sets the library's `isAtBottom`, a lost
|
|
182
|
+
// lock self-heals instead of being permanent.
|
|
183
|
+
const followBottomRef = useRef(false)
|
|
184
|
+
|
|
185
|
+
// Drives the jump-to-bottom affordance. Derived from GEOMETRY, not
|
|
186
|
+
// from the library's `isAtBottom`: that flag is the one this list
|
|
187
|
+
// loses silently (see above), and a stale `true` would hide the
|
|
188
|
+
// button in exactly the situation it exists for. Threshold mirrors
|
|
189
|
+
// the library's own `STICK_TO_BOTTOM_OFFSET_PX`.
|
|
190
|
+
const [atBottom, setAtBottom] = useState(true)
|
|
191
|
+
|
|
145
192
|
// Tracks previous render state for explicit "force-stick" decisions
|
|
146
193
|
// (dialog change, first message, new user message). The library
|
|
147
194
|
// covers ongoing streaming; these are about INTENT transitions.
|
|
@@ -178,11 +225,13 @@ const ChatMessageList = forwardRef<HTMLDivElement, ChatMessageListProps>(
|
|
|
178
225
|
|
|
179
226
|
if (dialogChanged) {
|
|
180
227
|
// Opening a different chat — instant snap to bottom.
|
|
228
|
+
followBottomRef.current = true
|
|
181
229
|
void scrollToBottom({ animation: 'instant', ignoreEscapes: true })
|
|
182
230
|
return
|
|
183
231
|
}
|
|
184
232
|
if (newCount > 0 && prevCount === 0) {
|
|
185
233
|
// First message arrived in an empty chat — instant snap.
|
|
234
|
+
followBottomRef.current = true
|
|
186
235
|
void scrollToBottom({ animation: 'instant', ignoreEscapes: true })
|
|
187
236
|
return
|
|
188
237
|
}
|
|
@@ -207,54 +256,199 @@ const ChatMessageList = forwardRef<HTMLDivElement, ChatMessageListProps>(
|
|
|
207
256
|
const newSlice = prevLastIdx >= 0 ? messages.slice(prevLastIdx + 1) : messages.slice(prevCount)
|
|
208
257
|
const hasNewUser = newSlice.some((m) => m.role === 'user')
|
|
209
258
|
if (hasNewUser) {
|
|
259
|
+
// Arms the follow intent for the WHOLE turn: the answer's
|
|
260
|
+
// async growth (attachment images, streamed tokens, entity
|
|
261
|
+
// cards resolving out of their skeletons long after the
|
|
262
|
+
// stream ends) is re-asserted by the follow effect below.
|
|
263
|
+
// This replaces the old per-`<img>` `load`-handler hack —
|
|
264
|
+
// same defect class, but the ResizeObserver sees every
|
|
265
|
+
// source of growth, not just images present at send time.
|
|
266
|
+
followBottomRef.current = true
|
|
210
267
|
void scrollToBottom({ animation: 'instant', ignoreEscapes: true })
|
|
211
|
-
|
|
212
|
-
// Image-attachment growth follow-up: if the new user message
|
|
213
|
-
// carries inline `<img>` elements (chat-attachment markdown
|
|
214
|
-
// emits `` which the markdown
|
|
215
|
-
// renderer turns into `<img>` / Next.js `<Image>`), those
|
|
216
|
-
// images load AFTER the initial paint. Each image-load grows
|
|
217
|
-
// the bubble height, but `useStickToBottom`'s `resize:
|
|
218
|
-
// 'smooth'` spring sometimes loses anchor under rapid
|
|
219
|
-
// resize events from Next.js Image's progressive
|
|
220
|
-
// dimensioning (observed: scroll lands 50-100px short of
|
|
221
|
-
// bottom — exactly one image-load short).
|
|
222
|
-
//
|
|
223
|
-
// Fix: after the initial scrollToBottom snaps, scan the
|
|
224
|
-
// content area for `<img>` elements that haven't loaded
|
|
225
|
-
// yet, and attach one-time `load` handlers that re-trigger
|
|
226
|
-
// `scrollToBottom`. Idempotent — runs for any image,
|
|
227
|
-
// affects only the new-user-message diff (effect dep is
|
|
228
|
-
// `messages`).
|
|
229
|
-
//
|
|
230
|
-
// `requestAnimationFrame` so the DOM has the new bubble
|
|
231
|
-
// before we query. Without rAF the new-message `<img>`s
|
|
232
|
-
// haven't been committed yet — querySelectorAll returns
|
|
233
|
-
// an empty set.
|
|
234
|
-
requestAnimationFrame(() => {
|
|
235
|
-
const el = contentRef.current
|
|
236
|
-
if (!el) return
|
|
237
|
-
const imgs = el.querySelectorAll('img')
|
|
238
|
-
imgs.forEach((img) => {
|
|
239
|
-
if (img.complete) return
|
|
240
|
-
const onLoad = () => {
|
|
241
|
-
img.removeEventListener('load', onLoad)
|
|
242
|
-
img.removeEventListener('error', onLoad)
|
|
243
|
-
// `ignoreEscapes: true` because the user may have
|
|
244
|
-
// accidentally moved scroll during the image-load
|
|
245
|
-
// window; we want their fresh send to be visible.
|
|
246
|
-
void scrollToBottom({ animation: 'instant', ignoreEscapes: true })
|
|
247
|
-
}
|
|
248
|
-
img.addEventListener('load', onLoad, { once: true })
|
|
249
|
-
img.addEventListener('error', onLoad, { once: true })
|
|
250
|
-
})
|
|
251
|
-
})
|
|
252
268
|
}
|
|
253
269
|
// Assistant-only new messages → the library's resize-watch
|
|
254
270
|
// already keeps the bottom locked when the user hasn't
|
|
255
271
|
// escaped. No explicit call needed; spring animation runs.
|
|
256
272
|
}
|
|
257
|
-
}, [autoScroll, messages, dialogId, scrollToBottom
|
|
273
|
+
}, [autoScroll, messages, dialogId, scrollToBottom])
|
|
274
|
+
|
|
275
|
+
// ---- Follow the bottom while the intent is armed -----------------
|
|
276
|
+
// Installs once per mount (all deps are stable). See the
|
|
277
|
+
// `followBottomRef` comment above for WHY this exists.
|
|
278
|
+
useEffect(() => {
|
|
279
|
+
if (!autoScroll) return
|
|
280
|
+
const scroller = scrollRef.current
|
|
281
|
+
const content = contentRef.current
|
|
282
|
+
if (!scroller || !content) return
|
|
283
|
+
|
|
284
|
+
// Re-assert on ANY geometry change. Deliberately WITHOUT
|
|
285
|
+
// `ignoreEscapes`: the library must stay free to hand control back
|
|
286
|
+
// on a real gesture mid-animation. Re-asserting is precisely what
|
|
287
|
+
// re-sets its `isAtBottom`, so a silently-lost lock recovers on the
|
|
288
|
+
// next resize instead of staying broken for the rest of the turn.
|
|
289
|
+
// Cheap to call repeatedly — the library returns the in-flight
|
|
290
|
+
// promise when an animation with the same behaviour is running.
|
|
291
|
+
const measure = () => {
|
|
292
|
+
const distance = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight
|
|
293
|
+
setAtBottom(distance <= BOTTOM_THRESHOLD_PX)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const reassert = () => {
|
|
297
|
+
if (followBottomRef.current) void scrollToBottom({ animation: 'smooth' })
|
|
298
|
+
// Measured on every geometry change, follow armed or not: a
|
|
299
|
+
// sibling growing below the scroller moves the bottom without
|
|
300
|
+
// any scroll event, and the button has to notice.
|
|
301
|
+
measure()
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const ro = new ResizeObserver(reassert)
|
|
305
|
+
ro.observe(content) // tokens, entity cards, images
|
|
306
|
+
ro.observe(scroller) // streaming loader / source chips below it
|
|
307
|
+
|
|
308
|
+
// --- user-intent disarm ---------------------------------------
|
|
309
|
+
// Only a deliberate move AWAY from the bottom releases the lock.
|
|
310
|
+
// Resize-derived scroll events are NOT gestures, which is exactly
|
|
311
|
+
// the distinction the library's heuristic gets wrong.
|
|
312
|
+
const disarm = () => {
|
|
313
|
+
followBottomRef.current = false
|
|
314
|
+
}
|
|
315
|
+
const onWheel = (e: WheelEvent) => {
|
|
316
|
+
if (e.deltaY < 0) disarm()
|
|
317
|
+
}
|
|
318
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
319
|
+
if (e.key === 'ArrowUp' || e.key === 'PageUp' || e.key === 'Home') disarm()
|
|
320
|
+
}
|
|
321
|
+
let touchY: number | null = null
|
|
322
|
+
const onTouchStart = (e: TouchEvent) => {
|
|
323
|
+
touchY = e.touches[0]?.clientY ?? null
|
|
324
|
+
}
|
|
325
|
+
const onTouchMove = (e: TouchEvent) => {
|
|
326
|
+
const y = e.touches[0]?.clientY
|
|
327
|
+
if (y == null || touchY == null) return
|
|
328
|
+
if (y > touchY) disarm() // finger travels DOWN → content moves up
|
|
329
|
+
touchY = y
|
|
330
|
+
}
|
|
331
|
+
// Scrollbar drag emits neither wheel nor touch — a scrollTop
|
|
332
|
+
// DECREASE while the pointer is held down is the same intent.
|
|
333
|
+
//
|
|
334
|
+
// ALL pointer listeners are on `window`, deliberately. The scroller is a
|
|
335
|
+
// native `overflow-y-auto` div (OverlayScrollbars was reverted in #1512),
|
|
336
|
+
// so its native scrollbar IS part of `scroller` and a `pointerdown` on the
|
|
337
|
+
// thumb does reach it — but `window` is a safe superset that also survives
|
|
338
|
+
// any future host component (or a return to a custom-scrollbar library
|
|
339
|
+
// that renders the thumb OUTSIDE the viewport) without stranding
|
|
340
|
+
// `pointerDown` at `false` and reintroducing the yank-back-mid-drag bug.
|
|
341
|
+
//
|
|
342
|
+
// The POINTER listeners use CAPTURE phase, so the guarantee is structural
|
|
343
|
+
// rather than contingent on nothing between us and `window` ever calling
|
|
344
|
+
// `stopPropagation` on the pointer path.
|
|
345
|
+
//
|
|
346
|
+
// `blur` deliberately does NOT use capture. Focus events don't bubble
|
|
347
|
+
// but they DO capture, so a capture listener on `window` fires for
|
|
348
|
+
// EVERY element blur in the document (the focus-delegation idiom) —
|
|
349
|
+
// any focus change during a hold, e.g. the chat input blurring as the
|
|
350
|
+
// user presses down on the scrollbar, would clear `pointerDown` and
|
|
351
|
+
// re-open the very yank-back bug this block prevents. A TRUE window
|
|
352
|
+
// blur targets `window` itself, so an at-target (bubble-phase)
|
|
353
|
+
// listener still receives it: capture buys nothing and costs
|
|
354
|
+
// correctness. Verified in jsdom: descendant blur reaches the capture
|
|
355
|
+
// listener only; window blur reaches both.
|
|
356
|
+
//
|
|
357
|
+
// `pointerDown` must be cleared by every way a drag can END, not just
|
|
358
|
+
// `pointerup`: a button released OUTSIDE the window, or the tab losing
|
|
359
|
+
// focus mid-drag, delivers no `pointerup` at all and would leave the
|
|
360
|
+
// flag stuck true. From then on ANY resize-induced scrollTop clamp — a
|
|
361
|
+
// fetch-mode card settling from skeleton to a shorter height, i.e. the
|
|
362
|
+
// exact case this whole block exists for — reads as a scroll-up gesture
|
|
363
|
+
// and drops the lock. Same for merely HOLDING the button down (text
|
|
364
|
+
// selection) while a card shrinks. Hence `pointercancel` + window
|
|
365
|
+
// `blur`.
|
|
366
|
+
let pointerDown = false
|
|
367
|
+
let lastScrollTop = scroller.scrollTop
|
|
368
|
+
const onPointerDown = () => {
|
|
369
|
+
pointerDown = true
|
|
370
|
+
}
|
|
371
|
+
// A drag that RELEASES at the live end expresses the same intent as
|
|
372
|
+
// clicking jump-to-bottom. The scroll events during that drag can't
|
|
373
|
+
// re-arm (see the gate in `onScroll`), and releasing the button emits
|
|
374
|
+
// no further `scroll`, so the re-arm is evaluated once here, when the
|
|
375
|
+
// gesture is actually over.
|
|
376
|
+
const rearmIfAtBottom = () => {
|
|
377
|
+
if (followBottomRef.current) return
|
|
378
|
+
const distance = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight
|
|
379
|
+
if (distance <= BOTTOM_THRESHOLD_PX) followBottomRef.current = true
|
|
380
|
+
}
|
|
381
|
+
const endPointer = () => {
|
|
382
|
+
pointerDown = false
|
|
383
|
+
rearmIfAtBottom()
|
|
384
|
+
}
|
|
385
|
+
const onScroll = () => {
|
|
386
|
+
const st = scroller.scrollTop
|
|
387
|
+
if (pointerDown && st < lastScrollTop) disarm()
|
|
388
|
+
lastScrollTop = st
|
|
389
|
+
// Landing at the bottom by hand is the SAME expressed intent as
|
|
390
|
+
// clicking jump-to-bottom, so it re-arms a lock an earlier scroll-up
|
|
391
|
+
// released. Without it the thread sits at-bottom (button hidden,
|
|
392
|
+
// because `atBottom` is true) and then silently drifts away as the
|
|
393
|
+
// answer grows.
|
|
394
|
+
//
|
|
395
|
+
// Gated on the drag being OVER (`!pointerDown`). A mid-drag `scroll`
|
|
396
|
+
// is not a gesture that has ended, and a short scrollbar drag that
|
|
397
|
+
// starts at the live end stays inside the 70px band — so re-arming
|
|
398
|
+
// here would undo the `disarm()` two lines above on the very same
|
|
399
|
+
// event and yank the reader back down mid-drag. Releasing the button
|
|
400
|
+
// at the bottom still re-arms on the next scroll (or, if none
|
|
401
|
+
// follows, on the next deliberate return to the end).
|
|
402
|
+
if (
|
|
403
|
+
!pointerDown &&
|
|
404
|
+
!followBottomRef.current &&
|
|
405
|
+
scroller.scrollHeight - st - scroller.clientHeight <= BOTTOM_THRESHOLD_PX
|
|
406
|
+
) {
|
|
407
|
+
followBottomRef.current = true
|
|
408
|
+
}
|
|
409
|
+
measure()
|
|
410
|
+
}
|
|
411
|
+
measure()
|
|
412
|
+
|
|
413
|
+
const winCapture = { capture: true, passive: true } as const
|
|
414
|
+
|
|
415
|
+
scroller.addEventListener('wheel', onWheel, { passive: true })
|
|
416
|
+
scroller.addEventListener('keydown', onKeyDown)
|
|
417
|
+
scroller.addEventListener('touchstart', onTouchStart, { passive: true })
|
|
418
|
+
scroller.addEventListener('touchmove', onTouchMove, { passive: true })
|
|
419
|
+
window.addEventListener('pointerdown', onPointerDown, winCapture)
|
|
420
|
+
scroller.addEventListener('scroll', onScroll, { passive: true })
|
|
421
|
+
window.addEventListener('pointerup', endPointer, winCapture)
|
|
422
|
+
window.addEventListener('pointercancel', endPointer, winCapture)
|
|
423
|
+
// Bubble phase, NOT capture — see the note above.
|
|
424
|
+
window.addEventListener('blur', endPointer, { passive: true })
|
|
425
|
+
|
|
426
|
+
return () => {
|
|
427
|
+
ro.disconnect()
|
|
428
|
+
scroller.removeEventListener('wheel', onWheel)
|
|
429
|
+
scroller.removeEventListener('keydown', onKeyDown)
|
|
430
|
+
scroller.removeEventListener('touchstart', onTouchStart)
|
|
431
|
+
scroller.removeEventListener('touchmove', onTouchMove)
|
|
432
|
+
// `capture` must match the add call or the listener is not removed.
|
|
433
|
+
window.removeEventListener('pointerdown', onPointerDown, { capture: true })
|
|
434
|
+
scroller.removeEventListener('scroll', onScroll)
|
|
435
|
+
window.removeEventListener('pointerup', endPointer, { capture: true })
|
|
436
|
+
window.removeEventListener('pointercancel', endPointer, { capture: true })
|
|
437
|
+
// Added WITHOUT capture — the remove must match.
|
|
438
|
+
window.removeEventListener('blur', endPointer)
|
|
439
|
+
}
|
|
440
|
+
// `isLoading` IS load-bearing here, even though the body never reads it.
|
|
441
|
+
// On the loading branch this component returns the skeleton, so
|
|
442
|
+
// `scrollRef.current` is null and the bail-out above fires. With all four
|
|
443
|
+
// other deps identity-stable (`autoScroll` plus three `[]`-memoized values
|
|
444
|
+
// from `useStickToBottom`), the effect then never ran again: no
|
|
445
|
+
// ResizeObserver, no wheel/touch/keyboard escape hatches, `atBottom` stuck
|
|
446
|
+
// at its initial `true` so the jump-to-bottom button could not render, and
|
|
447
|
+
// the follow lock never re-asserted — for the rest of the component's
|
|
448
|
+
// life. A `false → true → false` round trip (host loads another page or
|
|
449
|
+
// dialog) also swaps the scroller element, so the stale closure kept
|
|
450
|
+
// observing and listening on DETACHED nodes.
|
|
451
|
+
}, [autoScroll, scrollRef, contentRef, scrollToBottom, isLoading])
|
|
258
452
|
|
|
259
453
|
// ---- Passive-demo hard pin (pinBottom) ---------------------------
|
|
260
454
|
// Scripted in-page replays (the Fae/Mingo demos) have no human at the
|
|
@@ -384,7 +578,10 @@ const ChatMessageList = forwardRef<HTMLDivElement, ChatMessageListProps>(
|
|
|
384
578
|
// `stopScroll` MUST precede scrollIntoView — the imperative scrollTop
|
|
385
579
|
// write is what the library's geometry tracker uses to flip
|
|
386
580
|
// `escapedFromLock`, so any in-flight scrollToBottom spring is
|
|
387
|
-
// first cancelled.
|
|
581
|
+
// first cancelled. The list-owned follow intent is released for the
|
|
582
|
+
// same reason: this turn deliberately parks at the message TOP, so
|
|
583
|
+
// its own async growth must NOT drag the reader to the bottom.
|
|
584
|
+
followBottomRef.current = false
|
|
388
585
|
stopScroll()
|
|
389
586
|
// Instant (not smooth): the markdown body contains async <img>
|
|
390
587
|
// children whose loads race a 300ms smooth animation and leave
|
|
@@ -471,7 +668,46 @@ const ChatMessageList = forwardRef<HTMLDivElement, ChatMessageListProps>(
|
|
|
471
668
|
// Expose the scroll container ref to parents that need it (rare,
|
|
472
669
|
// but the existing public contract). Library's `scrollRef` is a
|
|
473
670
|
// MutableRefObject<HTMLElement> so we cast to the public type.
|
|
474
|
-
|
|
671
|
+
// `isLoading` for the same reason as the follow effect: on the loading
|
|
672
|
+
// branch `scrollRef.current` is null, and without it in the deps a parent
|
|
673
|
+
// that mounted this list while loading held `null` forever.
|
|
674
|
+
useImperativeHandle(ref, () => scrollRef.current as HTMLDivElement, [scrollRef, isLoading])
|
|
675
|
+
|
|
676
|
+
// Ref adapters — MEMOIZED, and declared above the early return so the hook
|
|
677
|
+
// order is unconditional (see CLAUDE.md rule 3).
|
|
678
|
+
//
|
|
679
|
+
// `useStickToBottom` treats these as ref callbacks: React invokes
|
|
680
|
+
// `ref(null)` then `ref(el)` whenever the callback IDENTITY changes, and the
|
|
681
|
+
// library responds by disconnecting its ResizeObserver and building a fresh
|
|
682
|
+
// one (plus removing/re-adding its scroll and wheel listeners). A plain arrow
|
|
683
|
+
// per render therefore churned all of that on EVERY committed frame — one per
|
|
684
|
+
// batched delta flush, so ~60/s while streaming — and, because the rebuild
|
|
685
|
+
// resets the library's `previousHeight` to undefined, it permanently pinned
|
|
686
|
+
// the library to its `initial` animation and never used `resize`, inverting
|
|
687
|
+
// the policy configured above.
|
|
688
|
+
//
|
|
689
|
+
// The library types its refs against `HTMLElement` (broader than
|
|
690
|
+
// `HTMLDivElement`) and `MutableRefObject` is INVARIANT in its type
|
|
691
|
+
// parameter, so a direct assignment into the JSX `Ref<HTMLDivElement>` slot
|
|
692
|
+
// fails type-check; a callback is contravariant in its argument, so this
|
|
693
|
+
// adapter type-checks AND preserves the library's mount bookkeeping (the
|
|
694
|
+
// intersection `MutableRefObject<T> & RefCallback<T>` means calling
|
|
695
|
+
// `scrollRef(el)` both writes `scrollRef.current` and runs that bookkeeping).
|
|
696
|
+
// The explicit `: void` return is required too: the library's signature
|
|
697
|
+
// returns `void | (() => void)` (React 19's optional ref-cleanup contract),
|
|
698
|
+
// which the hub's React types reject in a `Ref<T>` slot.
|
|
699
|
+
const setScrollRef = useCallback(
|
|
700
|
+
(el: HTMLDivElement | null): void => {
|
|
701
|
+
scrollRef(el)
|
|
702
|
+
},
|
|
703
|
+
[scrollRef],
|
|
704
|
+
)
|
|
705
|
+
const setContentRef = useCallback(
|
|
706
|
+
(el: HTMLDivElement | null): void => {
|
|
707
|
+
contentRef(el)
|
|
708
|
+
},
|
|
709
|
+
[contentRef],
|
|
710
|
+
)
|
|
475
711
|
|
|
476
712
|
if (isLoading) {
|
|
477
713
|
return (
|
|
@@ -485,28 +721,6 @@ const ChatMessageList = forwardRef<HTMLDivElement, ChatMessageListProps>(
|
|
|
485
721
|
)
|
|
486
722
|
}
|
|
487
723
|
|
|
488
|
-
// Adapt the library's refs to React's `Ref<HTMLDivElement>` JSX
|
|
489
|
-
// slot. The library types its refs against `HTMLElement` (broader
|
|
490
|
-
// than `HTMLDivElement`); MutableRefObject is INVARIANT in its
|
|
491
|
-
// type parameter, so a direct assignment fails type-check. The
|
|
492
|
-
// callback form is contravariant in its arg, so a tiny adapter
|
|
493
|
-
// that invokes the library's RefCallback portion type-checks
|
|
494
|
-
// cleanly AND preserves the library's internal observer setup.
|
|
495
|
-
// (The intersection type `MutableRefObject<T> & RefCallback<T>`
|
|
496
|
-
// means calling `scrollRef(el)` writes `el` into `scrollRef.current`
|
|
497
|
-
// AND triggers the library's mount-bookkeeping.)
|
|
498
|
-
// Note the explicit `: void` return type. The library's RefCallback
|
|
499
|
-
// signature returns `void | (() => void)` (React 19's optional ref-
|
|
500
|
-
// cleanup contract). The hub's React types reject that union in a
|
|
501
|
-
// JSX `Ref<T>` slot. Force `void` here — the library doesn't use
|
|
502
|
-
// the cleanup return path in any meaningful way for the public hook.
|
|
503
|
-
const setScrollRef = (el: HTMLDivElement | null): void => {
|
|
504
|
-
scrollRef(el)
|
|
505
|
-
}
|
|
506
|
-
const setContentRef = (el: HTMLDivElement | null): void => {
|
|
507
|
-
contentRef(el)
|
|
508
|
-
}
|
|
509
|
-
|
|
510
724
|
// Footer-pinned streaming loader. Rendered OUTSIDE the scroller (a
|
|
511
725
|
// sibling of the scroll div, like the sticky approvals below) so it
|
|
512
726
|
// stays put while messages stream and grow — no jitter from the
|
|
@@ -528,75 +742,138 @@ const ChatMessageList = forwardRef<HTMLDivElement, ChatMessageListProps>(
|
|
|
528
742
|
!(pendingApprovals && pendingApprovals.length > 0)
|
|
529
743
|
|
|
530
744
|
return (
|
|
531
|
-
<div className="
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
// deck (native body scroll + sticky slide panels) would otherwise
|
|
540
|
-
// advance slides while you scroll the chat (fixed in #1501; kept as
|
|
541
|
-
// the prop default here). Passive in-page DEMO chats disable it so
|
|
542
|
-
// the surrounding page keeps scrolling normally when the pointer is
|
|
543
|
-
// over the (non-interactive) thread.
|
|
544
|
-
overscrollContain && "overscroll-contain",
|
|
545
|
-
"scrollbar-thin scrollbar-track-transparent scrollbar-thumb-ods-border/30 hover:scrollbar-thumb-ods-text-secondary/30",
|
|
546
|
-
className,
|
|
547
|
-
)}
|
|
548
|
-
{...props}
|
|
549
|
-
>
|
|
745
|
+
<div className="flex-1 min-h-0 flex flex-col">
|
|
746
|
+
{/* Positioning box for the jump-to-bottom button: it wraps ONLY the
|
|
747
|
+
scroller, so `absolute bottom-…` really is the scroller's lower
|
|
748
|
+
edge. The outer flex column also holds the streaming loader and the
|
|
749
|
+
approvals bar, and anchoring against THAT box put the button over
|
|
750
|
+
the loader for the whole of every stream — precisely when it is
|
|
751
|
+
most likely to be visible. */}
|
|
752
|
+
<div className="relative flex-1 min-h-0 flex flex-col">
|
|
550
753
|
<div
|
|
551
|
-
ref={
|
|
754
|
+
ref={setScrollRef}
|
|
552
755
|
className={cn(
|
|
553
|
-
|
|
554
|
-
//
|
|
555
|
-
//
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
756
|
+
"flex h-full w-full flex-col overflow-y-auto overflow-x-hidden flex-1",
|
|
757
|
+
// `overscroll-contain` (default ON, opt-out via `overscrollContain={false}`):
|
|
758
|
+
// reaching the top/bottom of the thread must NOT chain the wheel/
|
|
759
|
+
// touch scroll to the page behind the chat — e.g. the company-hub
|
|
760
|
+
// deck (native body scroll + sticky slide panels) would otherwise
|
|
761
|
+
// advance slides while you scroll the chat (fixed in #1501; kept as
|
|
762
|
+
// the prop default here). Passive in-page DEMO chats disable it so
|
|
763
|
+
// the surrounding page keeps scrolling normally when the pointer is
|
|
764
|
+
// over the (non-interactive) thread.
|
|
765
|
+
overscrollContain && "overscroll-contain",
|
|
766
|
+
"scrollbar-thin scrollbar-track-transparent scrollbar-thumb-ods-border/30 hover:scrollbar-thumb-ods-text-secondary/30",
|
|
767
|
+
className,
|
|
560
768
|
)}
|
|
561
|
-
|
|
769
|
+
{...props}
|
|
562
770
|
>
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
771
|
+
<div
|
|
772
|
+
ref={setContentRef}
|
|
773
|
+
className={cn(
|
|
774
|
+
// `fullWidth=true` drops the centered-narrow column for
|
|
775
|
+
// side-panel hosts (e.g. multi-platform-hub Mingo). Same
|
|
776
|
+
// semantics as ChatHeader / ChatInput / ChatFooter.
|
|
777
|
+
fullWidth
|
|
778
|
+
? "flex w-full flex-col pb-[var(--spacing-system-xs)] min-w-0"
|
|
779
|
+
: "mx-auto flex w-full max-w-ods-content-narrow flex-col pb-[var(--spacing-system-xs)] min-w-0",
|
|
780
|
+
contentClassName ?? "px-[var(--spacing-system-m)]",
|
|
781
|
+
)}
|
|
782
|
+
style={{ minHeight: '100%' }}
|
|
783
|
+
>
|
|
784
|
+
{hasNextPage && (
|
|
785
|
+
<div ref={sentinelRef} className="h-px" />
|
|
786
|
+
)}
|
|
787
|
+
<div className="flex-1" />
|
|
788
|
+
{messages.map((message, index) => {
|
|
789
|
+
// Hidden messages (synthetic continuation prompts the host
|
|
790
|
+
// injects after an approval card) are part of the API
|
|
791
|
+
// conversation history but never render. Skipping here
|
|
792
|
+
// keeps the visible thread coherent — see
|
|
793
|
+
// `Message.hidden` doc-comment in message.types.ts.
|
|
794
|
+
if (message.hidden) return null
|
|
795
|
+
// ONE OWNER for the pending turn. Both send paths mint an empty
|
|
796
|
+
// assistant placeholder (the accumulation target — it MUST stay
|
|
797
|
+
// in state) and flip the phase to 'thinking'. Rendering it here
|
|
798
|
+
// too would put an author label with no body in the transcript
|
|
799
|
+
// WHILE the footer loader below already represents the same
|
|
800
|
+
// pending turn — two owners, and an `aria-live` log that
|
|
801
|
+
// announces a bare "Mingo". The footer loader wins (it is
|
|
802
|
+
// already `role="status" aria-live="polite"`, sits outside the
|
|
803
|
+
// scroller so it can't jitter the thread, and cycles the
|
|
804
|
+
// progress phrase), so the placeholder is not rendered AT ALL
|
|
805
|
+
// until it carries something visible — removed from the live
|
|
806
|
+
// region, not merely hidden. Mirrors `endSseTurn`, which prunes
|
|
807
|
+
// an empty trailing assistant AFTER a turn; this closes the same
|
|
808
|
+
// window BEFORE the first token. Any non-text segment (tool
|
|
809
|
+
// execution, approval card, thinking) counts as visible.
|
|
810
|
+
const isEmptyPendingTurn =
|
|
811
|
+
index === messages.length - 1 &&
|
|
812
|
+
isTyping &&
|
|
813
|
+
message.role === 'assistant' &&
|
|
814
|
+
!hasNonEmptyContent(message.content) &&
|
|
815
|
+
(!Array.isArray(message.content) ||
|
|
816
|
+
message.content.every((s) => s.type === 'text'))
|
|
817
|
+
if (isEmptyPendingTurn) return null
|
|
818
|
+
return (
|
|
819
|
+
<ChatMessageEnhanced
|
|
820
|
+
key={message.id}
|
|
821
|
+
ref={getRegisterMessageEl(message.id)}
|
|
822
|
+
role={message.role}
|
|
823
|
+
name={message.name}
|
|
824
|
+
content={message.content}
|
|
825
|
+
timestamp={message.timestamp}
|
|
826
|
+
isTyping={index === messages.length - 1 && isTyping && message.role === 'assistant'}
|
|
827
|
+
avatar={showAvatars ? message.avatar : null}
|
|
828
|
+
showAvatar={showAvatars}
|
|
829
|
+
assistantType={message.assistantType || assistantType}
|
|
830
|
+
approvalVariant={approvalVariant}
|
|
831
|
+
authorType={message.authorType}
|
|
832
|
+
assistantIcon={message.role !== 'user' ? assistantIcon : undefined}
|
|
833
|
+
chatRefs={message.chatRefs}
|
|
834
|
+
contextItems={message.contextItems}
|
|
835
|
+
resolveContextIcon={resolveContextIcon}
|
|
836
|
+
renderContextItem={renderContextItem}
|
|
837
|
+
renderMention={renderMention}
|
|
838
|
+
renderEntityCard={renderEntityCard}
|
|
839
|
+
NavLinkAnchor={NavLinkAnchor}
|
|
840
|
+
/>
|
|
841
|
+
)
|
|
842
|
+
})}
|
|
843
|
+
</div>
|
|
599
844
|
</div>
|
|
845
|
+
|
|
846
|
+
{/* Jump to bottom. The manual escape hatch from auto-scroll that
|
|
847
|
+
every 2026 chat surface ships (AI Elements calls it
|
|
848
|
+
`ConversationScrollButton`) and the WCAG 2.2.2 counterpart to
|
|
849
|
+
moving content: the reader can always get back to the live
|
|
850
|
+
end without hunting for it. Positioned inside the scroller's
|
|
851
|
+
OWN `relative` wrapper above, so `bottom` really is the
|
|
852
|
+
scroller's lower edge and not the outer column's (which also
|
|
853
|
+
carries the streaming loader). It costs the thread no layout
|
|
854
|
+
height either way — a sibling would shrink the scroller and
|
|
855
|
+
move the very bottom it points at. Hidden while at the bottom
|
|
856
|
+
and in passive demo hosts. */}
|
|
857
|
+
{autoScroll && !atBottom && messages.length > 0 && (
|
|
858
|
+
<button
|
|
859
|
+
type="button"
|
|
860
|
+
onClick={() => {
|
|
861
|
+
// Clicking IS the intent to return to the live end, so it
|
|
862
|
+
// re-arms the follow lock a scroll-up had released.
|
|
863
|
+
followBottomRef.current = true
|
|
864
|
+
void scrollToBottom({ animation: 'smooth' })
|
|
865
|
+
}}
|
|
866
|
+
aria-label="Scroll to latest message"
|
|
867
|
+
className={cn(
|
|
868
|
+
"absolute bottom-[var(--spacing-system-s)] left-1/2 -translate-x-1/2 z-10",
|
|
869
|
+
"flex items-center justify-center size-9 rounded-full",
|
|
870
|
+
"bg-ods-card text-ods-text-primary border border-ods-border shadow-lg",
|
|
871
|
+
"hover:bg-ods-bg-hover transition-colors",
|
|
872
|
+
)}
|
|
873
|
+
>
|
|
874
|
+
<Arrow02DownIcon size={16} />
|
|
875
|
+
</button>
|
|
876
|
+
)}
|
|
600
877
|
</div>
|
|
601
878
|
|
|
602
879
|
{/* Footer-pinned streaming loader — outside the scroller so it
|
|
@@ -1531,6 +1531,12 @@ function EmbeddableChatInner({
|
|
|
1531
1531
|
content: m.segments && m.segments.length > 0 ? m.segments : m.content,
|
|
1532
1532
|
timestamp,
|
|
1533
1533
|
assistantType: m.role === 'assistant' ? ('mingo' as const) : undefined,
|
|
1534
|
+
// `hidden` is load-bearing, NOT cosmetic: it carries synthetic rows
|
|
1535
|
+
// (e.g. an auto-continuation directive) that the LLM must see but the
|
|
1536
|
+
// reader must not. Dropping it here made the raw directive text render
|
|
1537
|
+
// as an ordinary bubble. This field-by-field rebuild has to forward it
|
|
1538
|
+
// explicitly — see `Message.hidden` and `chat-message-list`'s skip.
|
|
1539
|
+
...(m.hidden ? { hidden: true } : {}),
|
|
1534
1540
|
...(m.chatRefs ? { chatRefs: m.chatRefs } : {}),
|
|
1535
1541
|
...(m.scrollAnchor ? { scrollAnchor: m.scrollAnchor } : {}),
|
|
1536
1542
|
// Forward attached context items so the user bubble renders its chips.
|