@hef2024/llmasaservice-ui 0.22.2 → 0.22.4

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
@@ -3895,6 +3895,8 @@ var AIChatPanel = ({
3895
3895
  const scrollRAFRef = (0, import_react12.useRef)(null);
3896
3896
  const lastScrollTimeRef = (0, import_react12.useRef)(0);
3897
3897
  const prevResponseLengthRef = (0, import_react12.useRef)(0);
3898
+ const scrollToEndRef = (0, import_react12.useRef)(scrollToEnd || false);
3899
+ const userHasScrolledRef = (0, import_react12.useRef)(userHasScrolled);
3898
3900
  const prevIdleRef = (0, import_react12.useRef)(true);
3899
3901
  const hasNotifiedCompletionRef = (0, import_react12.useRef)(true);
3900
3902
  const latestHistoryRef = (0, import_react12.useRef)(initialHistory);
@@ -4574,18 +4576,35 @@ var AIChatPanel = ({
4574
4576
  }
4575
4577
  }, [idle]);
4576
4578
  (0, import_react12.useEffect)(() => {
4579
+ scrollToEndRef.current = scrollToEnd || false;
4580
+ }, [scrollToEnd]);
4581
+ (0, import_react12.useEffect)(() => {
4582
+ userHasScrolledRef.current = userHasScrolled;
4583
+ }, [userHasScrolled]);
4584
+ (0, import_react12.useEffect)(() => {
4585
+ if (idle) {
4586
+ console.log("AIChatPanel - Auto-scroll effect: SKIPPED (idle)");
4587
+ return;
4588
+ }
4577
4589
  const currentResponseLength = response.length;
4578
4590
  const responseGotLonger = currentResponseLength > prevResponseLengthRef.current;
4591
+ console.log("AIChatPanel - Auto-scroll effect:", {
4592
+ idle,
4593
+ currentResponseLength,
4594
+ prevLength: prevResponseLengthRef.current,
4595
+ responseGotLonger,
4596
+ userHasScrolled: userHasScrolledRef.current,
4597
+ scrollToEnd: scrollToEndRef.current
4598
+ });
4579
4599
  prevResponseLengthRef.current = currentResponseLength;
4580
- const shouldAutoScroll = scrollToEnd || !userHasScrolled;
4581
- if (!idle && shouldAutoScroll && response && responseGotLonger) {
4600
+ const shouldAutoScroll = scrollToEndRef.current || !userHasScrolledRef.current;
4601
+ if (shouldAutoScroll && response && responseGotLonger) {
4602
+ console.log("AIChatPanel - Calling scrollToBottom");
4582
4603
  scrollToBottom(false);
4583
4604
  }
4584
- }, [response, scrollToBottom, idle, userHasScrolled, scrollToEnd]);
4605
+ }, [response, idle]);
4585
4606
  const idleRef = (0, import_react12.useRef)(idle);
4586
4607
  idleRef.current = idle;
4587
- const userHasScrolledRef = (0, import_react12.useRef)(userHasScrolled);
4588
- userHasScrolledRef.current = userHasScrolled;
4589
4608
  (0, import_react12.useEffect)(() => {
4590
4609
  const scrollArea = responseAreaRef.current;
4591
4610
  if (!scrollArea) return;
@@ -6273,12 +6292,16 @@ var AIAgentPanel = import_react14.default.forwardRef(({
6273
6292
  }, [context, sharedContextSections, pageContextSections, contextDataSources]);
6274
6293
  (0, import_react14.useEffect)(() => {
6275
6294
  const contextString = JSON.stringify(mergedContext.sections.map((s) => ({ id: s.id, data: s.data })));
6295
+ console.log("AIAgentPanel - Context effect running, sections:", mergedContext.sections.length);
6276
6296
  if (prevContextRef.current === null) {
6297
+ console.log("AIAgentPanel - First render, initializing context ref");
6277
6298
  prevContextRef.current = contextString;
6278
6299
  return;
6279
6300
  }
6280
6301
  if (prevContextRef.current !== contextString) {
6281
6302
  console.log("AIAgentPanel - Context changed, showing notification");
6303
+ console.log("AIAgentPanel - Old context:", prevContextRef.current.substring(0, 100));
6304
+ console.log("AIAgentPanel - New context:", contextString.substring(0, 100));
6282
6305
  prevContextRef.current = contextString;
6283
6306
  if (contextNotificationTimeoutRef.current) {
6284
6307
  clearTimeout(contextNotificationTimeoutRef.current);
@@ -6289,8 +6312,10 @@ var AIAgentPanel = import_react14.default.forwardRef(({
6289
6312
  setShowContextNotification(false);
6290
6313
  contextNotificationTimeoutRef.current = null;
6291
6314
  }, 3e3);
6315
+ } else {
6316
+ console.log("AIAgentPanel - Context unchanged");
6292
6317
  }
6293
- }, [mergedContext.sections]);
6318
+ }, [mergedContext]);
6294
6319
  (0, import_react14.useEffect)(() => {
6295
6320
  return () => {
6296
6321
  if (contextNotificationTimeoutRef.current) {
package/dist/index.mjs CHANGED
@@ -3862,6 +3862,8 @@ var AIChatPanel = ({
3862
3862
  const scrollRAFRef = useRef5(null);
3863
3863
  const lastScrollTimeRef = useRef5(0);
3864
3864
  const prevResponseLengthRef = useRef5(0);
3865
+ const scrollToEndRef = useRef5(scrollToEnd || false);
3866
+ const userHasScrolledRef = useRef5(userHasScrolled);
3865
3867
  const prevIdleRef = useRef5(true);
3866
3868
  const hasNotifiedCompletionRef = useRef5(true);
3867
3869
  const latestHistoryRef = useRef5(initialHistory);
@@ -4541,18 +4543,35 @@ var AIChatPanel = ({
4541
4543
  }
4542
4544
  }, [idle]);
4543
4545
  useEffect7(() => {
4546
+ scrollToEndRef.current = scrollToEnd || false;
4547
+ }, [scrollToEnd]);
4548
+ useEffect7(() => {
4549
+ userHasScrolledRef.current = userHasScrolled;
4550
+ }, [userHasScrolled]);
4551
+ useEffect7(() => {
4552
+ if (idle) {
4553
+ console.log("AIChatPanel - Auto-scroll effect: SKIPPED (idle)");
4554
+ return;
4555
+ }
4544
4556
  const currentResponseLength = response.length;
4545
4557
  const responseGotLonger = currentResponseLength > prevResponseLengthRef.current;
4558
+ console.log("AIChatPanel - Auto-scroll effect:", {
4559
+ idle,
4560
+ currentResponseLength,
4561
+ prevLength: prevResponseLengthRef.current,
4562
+ responseGotLonger,
4563
+ userHasScrolled: userHasScrolledRef.current,
4564
+ scrollToEnd: scrollToEndRef.current
4565
+ });
4546
4566
  prevResponseLengthRef.current = currentResponseLength;
4547
- const shouldAutoScroll = scrollToEnd || !userHasScrolled;
4548
- if (!idle && shouldAutoScroll && response && responseGotLonger) {
4567
+ const shouldAutoScroll = scrollToEndRef.current || !userHasScrolledRef.current;
4568
+ if (shouldAutoScroll && response && responseGotLonger) {
4569
+ console.log("AIChatPanel - Calling scrollToBottom");
4549
4570
  scrollToBottom(false);
4550
4571
  }
4551
- }, [response, scrollToBottom, idle, userHasScrolled, scrollToEnd]);
4572
+ }, [response, idle]);
4552
4573
  const idleRef = useRef5(idle);
4553
4574
  idleRef.current = idle;
4554
- const userHasScrolledRef = useRef5(userHasScrolled);
4555
- userHasScrolledRef.current = userHasScrolled;
4556
4575
  useEffect7(() => {
4557
4576
  const scrollArea = responseAreaRef.current;
4558
4577
  if (!scrollArea) return;
@@ -6240,12 +6259,16 @@ var AIAgentPanel = React13.forwardRef(({
6240
6259
  }, [context, sharedContextSections, pageContextSections, contextDataSources]);
6241
6260
  useEffect9(() => {
6242
6261
  const contextString = JSON.stringify(mergedContext.sections.map((s) => ({ id: s.id, data: s.data })));
6262
+ console.log("AIAgentPanel - Context effect running, sections:", mergedContext.sections.length);
6243
6263
  if (prevContextRef.current === null) {
6264
+ console.log("AIAgentPanel - First render, initializing context ref");
6244
6265
  prevContextRef.current = contextString;
6245
6266
  return;
6246
6267
  }
6247
6268
  if (prevContextRef.current !== contextString) {
6248
6269
  console.log("AIAgentPanel - Context changed, showing notification");
6270
+ console.log("AIAgentPanel - Old context:", prevContextRef.current.substring(0, 100));
6271
+ console.log("AIAgentPanel - New context:", contextString.substring(0, 100));
6249
6272
  prevContextRef.current = contextString;
6250
6273
  if (contextNotificationTimeoutRef.current) {
6251
6274
  clearTimeout(contextNotificationTimeoutRef.current);
@@ -6256,8 +6279,10 @@ var AIAgentPanel = React13.forwardRef(({
6256
6279
  setShowContextNotification(false);
6257
6280
  contextNotificationTimeoutRef.current = null;
6258
6281
  }, 3e3);
6282
+ } else {
6283
+ console.log("AIAgentPanel - Context unchanged");
6259
6284
  }
6260
- }, [mergedContext.sections]);
6285
+ }, [mergedContext]);
6261
6286
  useEffect9(() => {
6262
6287
  return () => {
6263
6288
  if (contextNotificationTimeoutRef.current) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hef2024/llmasaservice-ui",
3
- "version": "0.22.2",
3
+ "version": "0.22.4",
4
4
  "description": "Prebuilt UI components for LLMAsAService.io",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1534,8 +1534,11 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
1534
1534
  // Create a stable string representation of the context for comparison
1535
1535
  const contextString = JSON.stringify(mergedContext.sections.map(s => ({ id: s.id, data: s.data })));
1536
1536
 
1537
+ console.log('AIAgentPanel - Context effect running, sections:', mergedContext.sections.length);
1538
+
1537
1539
  // Skip on first render
1538
1540
  if (prevContextRef.current === null) {
1541
+ console.log('AIAgentPanel - First render, initializing context ref');
1539
1542
  prevContextRef.current = contextString;
1540
1543
  return;
1541
1544
  }
@@ -1543,6 +1546,8 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
1543
1546
  // Check if context actually changed
1544
1547
  if (prevContextRef.current !== contextString) {
1545
1548
  console.log('AIAgentPanel - Context changed, showing notification');
1549
+ console.log('AIAgentPanel - Old context:', prevContextRef.current.substring(0, 100));
1550
+ console.log('AIAgentPanel - New context:', contextString.substring(0, 100));
1546
1551
  prevContextRef.current = contextString;
1547
1552
 
1548
1553
  // Clear any existing timeout before setting a new one
@@ -1559,11 +1564,13 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
1559
1564
  setShowContextNotification(false);
1560
1565
  contextNotificationTimeoutRef.current = null;
1561
1566
  }, 3000);
1567
+ } else {
1568
+ console.log('AIAgentPanel - Context unchanged');
1562
1569
  }
1563
1570
 
1564
1571
  // Note: No cleanup on every re-render - only clear timeout when context changes
1565
1572
  // This prevents race conditions when switching rapidly
1566
- }, [mergedContext.sections]);
1573
+ }, [mergedContext]);
1567
1574
 
1568
1575
  // Separate cleanup effect for unmount only
1569
1576
  useEffect(() => {
@@ -847,6 +847,8 @@ const AIChatPanel: React.FC<AIChatPanelProps> = ({
847
847
  const scrollRAFRef = useRef<number | null>(null);
848
848
  const lastScrollTimeRef = useRef<number>(0);
849
849
  const prevResponseLengthRef = useRef<number>(0);
850
+ const scrollToEndRef = useRef<boolean>(scrollToEnd || false);
851
+ const userHasScrolledRef = useRef<boolean>(userHasScrolled);
850
852
 
851
853
  // === NEW: Clean history management refs ===
852
854
  // Track previous idle state to detect transitions (false→true = completion)
@@ -1821,32 +1823,56 @@ const AIChatPanel: React.FC<AIChatPanelProps> = ({
1821
1823
  }
1822
1824
  }, [idle]); // ONLY depends on idle - no history, no callbacks in deps
1823
1825
 
1826
+ // Keep refs in sync
1827
+ useEffect(() => {
1828
+ scrollToEndRef.current = scrollToEnd || false;
1829
+ }, [scrollToEnd]);
1830
+
1831
+ useEffect(() => {
1832
+ userHasScrolledRef.current = userHasScrolled;
1833
+ }, [userHasScrolled]);
1834
+
1824
1835
  // Auto-scroll to bottom - only while streaming and user hasn't manually scrolled
1836
+ // CRITICAL: Only depends on response and idle to avoid re-running on layout changes
1825
1837
  useEffect(() => {
1838
+ // CRITICAL: Skip entirely if idle - no scrolling when not streaming
1839
+ if (idle) {
1840
+ console.log('AIChatPanel - Auto-scroll effect: SKIPPED (idle)');
1841
+ return;
1842
+ }
1843
+
1826
1844
  // Only auto-scroll if:
1827
- // 1. We're actively streaming (!idle)
1845
+ // 1. We're actively streaming (!idle) - checked above
1828
1846
  // 2. User hasn't manually scrolled up during this response (or scrollToEnd prop is true)
1829
1847
  // 3. We have content to show (response exists)
1830
1848
  // 4. The response actually got longer (not just a re-render from layout change)
1831
1849
  const currentResponseLength = response.length;
1832
1850
  const responseGotLonger = currentResponseLength > prevResponseLengthRef.current;
1851
+
1852
+ console.log('AIChatPanel - Auto-scroll effect:', {
1853
+ idle,
1854
+ currentResponseLength,
1855
+ prevLength: prevResponseLengthRef.current,
1856
+ responseGotLonger,
1857
+ userHasScrolled: userHasScrolledRef.current,
1858
+ scrollToEnd: scrollToEndRef.current,
1859
+ });
1860
+
1833
1861
  prevResponseLengthRef.current = currentResponseLength;
1834
1862
 
1835
- const shouldAutoScroll = scrollToEnd || !userHasScrolled;
1836
- if (!idle && shouldAutoScroll && response && responseGotLonger) {
1863
+ // Only scroll if response actually grew - use refs to avoid unnecessary effect runs
1864
+ const shouldAutoScroll = scrollToEndRef.current || !userHasScrolledRef.current;
1865
+ if (shouldAutoScroll && response && responseGotLonger) {
1866
+ console.log('AIChatPanel - Calling scrollToBottom');
1837
1867
  // Use non-forced scroll - will only scroll if near bottom
1838
1868
  scrollToBottom(false);
1839
1869
  }
1840
- }, [response, scrollToBottom, idle, userHasScrolled, scrollToEnd]); // Removed history dependency
1870
+ }, [response, idle]); // ONLY response and idle - no other dependencies!
1841
1871
 
1842
1872
  // Ref to track idle state for scroll handler (avoids stale closure)
1843
1873
  const idleRef = useRef(idle);
1844
1874
  idleRef.current = idle;
1845
1875
 
1846
- // Ref to track userHasScrolled to avoid redundant state updates
1847
- const userHasScrolledRef = useRef(userHasScrolled);
1848
- userHasScrolledRef.current = userHasScrolled;
1849
-
1850
1876
  // Detect user scroll to disable auto-scroll
1851
1877
  useEffect(() => {
1852
1878
  const scrollArea = responseAreaRef.current;