@flamingo-stack/openframe-frontend-core 0.0.193 → 0.0.194

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.
@@ -5521,6 +5521,28 @@ function CyclingPhrase({
5521
5521
  ] });
5522
5522
  }
5523
5523
 
5524
+ // src/components/chat/types/message.types.ts
5525
+ var MESSAGE_TYPE = {
5526
+ TEXT: "TEXT",
5527
+ THINKING: "THINKING",
5528
+ EXECUTING_TOOL: "EXECUTING_TOOL",
5529
+ EXECUTED_TOOL: "EXECUTED_TOOL",
5530
+ APPROVAL_REQUEST: "APPROVAL_REQUEST",
5531
+ APPROVAL_RESULT: "APPROVAL_RESULT",
5532
+ ERROR: "ERROR",
5533
+ MESSAGE_START: "MESSAGE_START",
5534
+ MESSAGE_END: "MESSAGE_END",
5535
+ MESSAGE_REQUEST: "MESSAGE_REQUEST",
5536
+ AI_METADATA: "AI_METADATA",
5537
+ TOKEN_USAGE: "TOKEN_USAGE",
5538
+ CONTEXT_COMPACTION_START: "CONTEXT_COMPACTION_START",
5539
+ CONTEXT_COMPACTION_END: "CONTEXT_COMPACTION_END",
5540
+ DIRECT_MESSAGE: "DIRECT_MESSAGE",
5541
+ SYSTEM: "SYSTEM",
5542
+ DIALOG_CLOSED: "DIALOG_CLOSED"
5543
+ };
5544
+ var SCROLL_ANCHOR = { TOP: "top", BOTTOM: "bottom" };
5545
+
5524
5546
  // src/components/chat/chat-message-list.tsx
5525
5547
  import { jsx as jsx33, jsxs as jsxs28 } from "react/jsx-runtime";
5526
5548
  var STREAMING_WORDS = [
@@ -5535,6 +5557,16 @@ var STREAMING_WORDS = [
5535
5557
  "Conjuring",
5536
5558
  "Riffing"
5537
5559
  ];
5560
+ function hasNonEmptyContent(content) {
5561
+ if (typeof content === "string") return content.length > 0;
5562
+ if (!Array.isArray(content)) return false;
5563
+ return content.some((s) => s.type === "text" && s.text.length > 0);
5564
+ }
5565
+ function disposeAnchorWatcher(w) {
5566
+ if (!w) return;
5567
+ w.ro.disconnect();
5568
+ clearTimeout(w.timer);
5569
+ }
5538
5570
  var ChatMessageList = forwardRef21(
5539
5571
  ({
5540
5572
  className,
@@ -5555,7 +5587,7 @@ var ChatMessageList = forwardRef21(
5555
5587
  NavLinkAnchor,
5556
5588
  ...props
5557
5589
  }, ref) => {
5558
- const { scrollRef, contentRef, scrollToBottom } = useStickToBottom({
5590
+ const { scrollRef, contentRef, scrollToBottom, stopScroll } = useStickToBottom({
5559
5591
  resize: "smooth",
5560
5592
  initial: false
5561
5593
  });
@@ -5619,6 +5651,68 @@ var ChatMessageList = forwardRef21(
5619
5651
  prependRef.current.firstMessageContent = currentFirstContent;
5620
5652
  }
5621
5653
  }, [messages, scrollRef]);
5654
+ const messageElsRef = useRef5(/* @__PURE__ */ new Map());
5655
+ const refCallbacksRef = useRef5(/* @__PURE__ */ new Map());
5656
+ const getRegisterMessageEl = (id) => {
5657
+ let cb = refCallbacksRef.current.get(id);
5658
+ if (cb) return cb;
5659
+ cb = (el) => {
5660
+ if (el) {
5661
+ messageElsRef.current.set(id, el);
5662
+ } else {
5663
+ messageElsRef.current.delete(id);
5664
+ refCallbacksRef.current.delete(id);
5665
+ }
5666
+ };
5667
+ refCallbacksRef.current.set(id, cb);
5668
+ return cb;
5669
+ };
5670
+ const scrolledIdsRef = useRef5(null);
5671
+ if (scrolledIdsRef.current === null) {
5672
+ scrolledIdsRef.current = new Set(
5673
+ messages.filter((m) => hasNonEmptyContent(m.content)).map((m) => m.id)
5674
+ );
5675
+ }
5676
+ const anchorWatcherRef = useRef5(null);
5677
+ useLayoutEffect2(() => {
5678
+ if (!autoScroll) return;
5679
+ const last = messages[messages.length - 1];
5680
+ if (!last || last.role !== "assistant" || last.scrollAnchor !== SCROLL_ANCHOR.TOP) return;
5681
+ if (!hasNonEmptyContent(last.content)) return;
5682
+ const seen = scrolledIdsRef.current;
5683
+ if (seen.has(last.id)) return;
5684
+ const node = messageElsRef.current.get(last.id);
5685
+ const container = scrollRef.current;
5686
+ if (!node || !node.isConnected || !container) return;
5687
+ seen.add(last.id);
5688
+ stopScroll();
5689
+ node.scrollIntoView({ block: "start" });
5690
+ disposeAnchorWatcher(anchorWatcherRef.current);
5691
+ const baselineScrollTop = container.scrollTop;
5692
+ const ro = new ResizeObserver(() => {
5693
+ if (!node.isConnected) {
5694
+ ro.disconnect();
5695
+ return;
5696
+ }
5697
+ if (container.scrollTop > baselineScrollTop + 200) {
5698
+ ro.disconnect();
5699
+ return;
5700
+ }
5701
+ node.scrollIntoView({ block: "start" });
5702
+ });
5703
+ ro.observe(node);
5704
+ const timer = setTimeout(() => {
5705
+ ro.disconnect();
5706
+ if (anchorWatcherRef.current?.id === last.id) {
5707
+ anchorWatcherRef.current = null;
5708
+ }
5709
+ }, 2e3);
5710
+ anchorWatcherRef.current = { id: last.id, ro, timer };
5711
+ }, [messages, autoScroll, stopScroll, scrollRef]);
5712
+ useEffect6(() => () => {
5713
+ disposeAnchorWatcher(anchorWatcherRef.current);
5714
+ anchorWatcherRef.current = null;
5715
+ }, []);
5622
5716
  useEffect6(() => {
5623
5717
  const scrollContainer = scrollRef.current;
5624
5718
  const sentinelElement = sentinelRef.current;
@@ -5686,6 +5780,7 @@ var ChatMessageList = forwardRef21(
5686
5780
  messages.map((message, index) => /* @__PURE__ */ jsx33(
5687
5781
  MemoizedChatMessageEnhanced,
5688
5782
  {
5783
+ ref: getRegisterMessageEl(message.id),
5689
5784
  role: message.role,
5690
5785
  name: message.name,
5691
5786
  content: message.content,
@@ -6924,27 +7019,6 @@ var CONNECTION_STATUS = {
6924
7019
  ERROR: "error"
6925
7020
  };
6926
7021
 
6927
- // src/components/chat/types/message.types.ts
6928
- var MESSAGE_TYPE = {
6929
- TEXT: "TEXT",
6930
- THINKING: "THINKING",
6931
- EXECUTING_TOOL: "EXECUTING_TOOL",
6932
- EXECUTED_TOOL: "EXECUTED_TOOL",
6933
- APPROVAL_REQUEST: "APPROVAL_REQUEST",
6934
- APPROVAL_RESULT: "APPROVAL_RESULT",
6935
- ERROR: "ERROR",
6936
- MESSAGE_START: "MESSAGE_START",
6937
- MESSAGE_END: "MESSAGE_END",
6938
- MESSAGE_REQUEST: "MESSAGE_REQUEST",
6939
- AI_METADATA: "AI_METADATA",
6940
- TOKEN_USAGE: "TOKEN_USAGE",
6941
- CONTEXT_COMPACTION_START: "CONTEXT_COMPACTION_START",
6942
- CONTEXT_COMPACTION_END: "CONTEXT_COMPACTION_END",
6943
- DIRECT_MESSAGE: "DIRECT_MESSAGE",
6944
- SYSTEM: "SYSTEM",
6945
- DIALOG_CLOSED: "DIALOG_CLOSED"
6946
- };
6947
-
6948
7022
  // src/components/chat/types/network.types.ts
6949
7023
  var NETWORK_CONFIG = {
6950
7024
  SHARED_CLOSE_DELAY_MS: 3e3,
@@ -33507,6 +33581,8 @@ export {
33507
33581
  remarkCardLinks,
33508
33582
  BlockCard,
33509
33583
  MemoizedChatMessageEnhanced,
33584
+ MESSAGE_TYPE,
33585
+ SCROLL_ANCHOR,
33510
33586
  ChatMessageList,
33511
33587
  Tabs,
33512
33588
  TabsList,
@@ -33540,7 +33616,6 @@ export {
33540
33616
  AUTHOR_TYPE,
33541
33617
  APPROVAL_STATUS,
33542
33618
  CONNECTION_STATUS,
33543
- MESSAGE_TYPE,
33544
33619
  NETWORK_CONFIG,
33545
33620
  useChunkCatchup,
33546
33621
  useNatsDialogSubscription,
@@ -34008,4 +34083,4 @@ export {
34008
34083
  TMCG_SOCIAL_PLATFORMS,
34009
34084
  assets
34010
34085
  };
34011
- //# sourceMappingURL=chunk-E6VCRL42.js.map
34086
+ //# sourceMappingURL=chunk-C5VTN2SB.js.map