@hef2024/llmasaservice-ui 0.22.1 → 0.22.2

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/index.js CHANGED
@@ -3894,6 +3894,7 @@ var AIChatPanel = ({
3894
3894
  const lastScrollTopRef = (0, import_react12.useRef)(0);
3895
3895
  const scrollRAFRef = (0, import_react12.useRef)(null);
3896
3896
  const lastScrollTimeRef = (0, import_react12.useRef)(0);
3897
+ const prevResponseLengthRef = (0, import_react12.useRef)(0);
3897
3898
  const prevIdleRef = (0, import_react12.useRef)(true);
3898
3899
  const hasNotifiedCompletionRef = (0, import_react12.useRef)(true);
3899
3900
  const latestHistoryRef = (0, import_react12.useRef)(initialHistory);
@@ -4368,6 +4369,7 @@ var AIChatPanel = ({
4368
4369
  setCurrentThinkingIndex(0);
4369
4370
  setError(null);
4370
4371
  setUserHasScrolled(false);
4372
+ prevResponseLengthRef.current = 0;
4371
4373
  setResponse("");
4372
4374
  if (!idle) {
4373
4375
  stop(lastController);
@@ -4568,11 +4570,15 @@ var AIChatPanel = ({
4568
4570
  }
4569
4571
  if (!isNowIdle && hasNotifiedCompletionRef.current) {
4570
4572
  hasNotifiedCompletionRef.current = false;
4573
+ prevResponseLengthRef.current = 0;
4571
4574
  }
4572
4575
  }, [idle]);
4573
4576
  (0, import_react12.useEffect)(() => {
4577
+ const currentResponseLength = response.length;
4578
+ const responseGotLonger = currentResponseLength > prevResponseLengthRef.current;
4579
+ prevResponseLengthRef.current = currentResponseLength;
4574
4580
  const shouldAutoScroll = scrollToEnd || !userHasScrolled;
4575
- if (!idle && shouldAutoScroll && response) {
4581
+ if (!idle && shouldAutoScroll && response && responseGotLonger) {
4576
4582
  scrollToBottom(false);
4577
4583
  }
4578
4584
  }, [response, scrollToBottom, idle, userHasScrolled, scrollToEnd]);
package/dist/index.mjs CHANGED
@@ -3861,6 +3861,7 @@ var AIChatPanel = ({
3861
3861
  const lastScrollTopRef = useRef5(0);
3862
3862
  const scrollRAFRef = useRef5(null);
3863
3863
  const lastScrollTimeRef = useRef5(0);
3864
+ const prevResponseLengthRef = useRef5(0);
3864
3865
  const prevIdleRef = useRef5(true);
3865
3866
  const hasNotifiedCompletionRef = useRef5(true);
3866
3867
  const latestHistoryRef = useRef5(initialHistory);
@@ -4335,6 +4336,7 @@ var AIChatPanel = ({
4335
4336
  setCurrentThinkingIndex(0);
4336
4337
  setError(null);
4337
4338
  setUserHasScrolled(false);
4339
+ prevResponseLengthRef.current = 0;
4338
4340
  setResponse("");
4339
4341
  if (!idle) {
4340
4342
  stop(lastController);
@@ -4535,11 +4537,15 @@ var AIChatPanel = ({
4535
4537
  }
4536
4538
  if (!isNowIdle && hasNotifiedCompletionRef.current) {
4537
4539
  hasNotifiedCompletionRef.current = false;
4540
+ prevResponseLengthRef.current = 0;
4538
4541
  }
4539
4542
  }, [idle]);
4540
4543
  useEffect7(() => {
4544
+ const currentResponseLength = response.length;
4545
+ const responseGotLonger = currentResponseLength > prevResponseLengthRef.current;
4546
+ prevResponseLengthRef.current = currentResponseLength;
4541
4547
  const shouldAutoScroll = scrollToEnd || !userHasScrolled;
4542
- if (!idle && shouldAutoScroll && response) {
4548
+ if (!idle && shouldAutoScroll && response && responseGotLonger) {
4543
4549
  scrollToBottom(false);
4544
4550
  }
4545
4551
  }, [response, scrollToBottom, idle, userHasScrolled, scrollToEnd]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hef2024/llmasaservice-ui",
3
- "version": "0.22.1",
3
+ "version": "0.22.2",
4
4
  "description": "Prebuilt UI components for LLMAsAService.io",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -846,6 +846,7 @@ const AIChatPanel: React.FC<AIChatPanelProps> = ({
846
846
  const lastScrollTopRef = useRef<number>(0);
847
847
  const scrollRAFRef = useRef<number | null>(null);
848
848
  const lastScrollTimeRef = useRef<number>(0);
849
+ const prevResponseLengthRef = useRef<number>(0);
849
850
 
850
851
  // === NEW: Clean history management refs ===
851
852
  // Track previous idle state to detect transitions (false→true = completion)
@@ -1521,6 +1522,7 @@ const AIChatPanel: React.FC<AIChatPanelProps> = ({
1521
1522
 
1522
1523
  // Reset scroll tracking for new message - enable auto-scroll
1523
1524
  setUserHasScrolled(false);
1525
+ prevResponseLengthRef.current = 0;
1524
1526
 
1525
1527
  // IMPORTANT: Clear the response BEFORE setting new lastKey
1526
1528
  // This prevents the old response from being written to the new history entry
@@ -1814,17 +1816,24 @@ const AIChatPanel: React.FC<AIChatPanelProps> = ({
1814
1816
  // Reset notification flag when starting a new stream
1815
1817
  if (!isNowIdle && hasNotifiedCompletionRef.current) {
1816
1818
  hasNotifiedCompletionRef.current = false;
1819
+ // Reset response length tracking for new stream
1820
+ prevResponseLengthRef.current = 0;
1817
1821
  }
1818
1822
  }, [idle]); // ONLY depends on idle - no history, no callbacks in deps
1819
-
1823
+
1820
1824
  // Auto-scroll to bottom - only while streaming and user hasn't manually scrolled
1821
1825
  useEffect(() => {
1822
1826
  // Only auto-scroll if:
1823
1827
  // 1. We're actively streaming (!idle)
1824
1828
  // 2. User hasn't manually scrolled up during this response (or scrollToEnd prop is true)
1825
1829
  // 3. We have content to show (response exists)
1830
+ // 4. The response actually got longer (not just a re-render from layout change)
1831
+ const currentResponseLength = response.length;
1832
+ const responseGotLonger = currentResponseLength > prevResponseLengthRef.current;
1833
+ prevResponseLengthRef.current = currentResponseLength;
1834
+
1826
1835
  const shouldAutoScroll = scrollToEnd || !userHasScrolled;
1827
- if (!idle && shouldAutoScroll && response) {
1836
+ if (!idle && shouldAutoScroll && response && responseGotLonger) {
1828
1837
  // Use non-forced scroll - will only scroll if near bottom
1829
1838
  scrollToBottom(false);
1830
1839
  }