@hef2024/llmasaservice-ui 0.21.0 → 0.22.0

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.
@@ -96,6 +96,8 @@ export interface AIAgentPanelProps {
96
96
  theme?: 'light' | 'dark';
97
97
  collapsible?: boolean;
98
98
  defaultCollapsed?: boolean;
99
+ isCollapsed?: boolean;
100
+ onCollapsedChange?: (isCollapsed: boolean) => void;
99
101
  defaultWidth?: number;
100
102
  minWidth?: number;
101
103
  maxWidth?: number;
@@ -618,6 +620,8 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
618
620
  theme = 'light',
619
621
  collapsible = true,
620
622
  defaultCollapsed = false,
623
+ isCollapsed: controlledIsCollapsed,
624
+ onCollapsedChange,
621
625
  defaultWidth = 720,
622
626
  minWidth = 520,
623
627
  maxWidth = 1200,
@@ -660,8 +664,36 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
660
664
  customerEmailCaptureMode,
661
665
  customerEmailCapturePlaceholder,
662
666
  }, ref) => {
667
+ // Dev mode warnings for prop conflicts
668
+ useEffect(() => {
669
+ if (process.env.NODE_ENV === 'development') {
670
+ // Warn if isCollapsed is provided without onCollapsedChange (user can't interact)
671
+ if (controlledIsCollapsed !== undefined && !onCollapsedChange) {
672
+ console.warn(
673
+ 'AIAgentPanel: You provided `isCollapsed` prop without `onCollapsedChange`. ' +
674
+ 'This will render a read-only collapsed state. To allow user interaction, provide both props.'
675
+ );
676
+ }
677
+
678
+ // Warn if both isCollapsed and defaultCollapsed are provided (conflicting props)
679
+ if (controlledIsCollapsed !== undefined && defaultCollapsed !== false) {
680
+ console.warn(
681
+ 'AIAgentPanel: You provided both `isCollapsed` and `defaultCollapsed` props. ' +
682
+ 'When using controlled mode (isCollapsed), the defaultCollapsed prop is ignored. ' +
683
+ 'Remove defaultCollapsed to avoid confusion.'
684
+ );
685
+ }
686
+ }
687
+ }, [controlledIsCollapsed, onCollapsedChange, defaultCollapsed]);
688
+
663
689
  // Panel state - only start collapsed if collapsible is true
664
- const [isCollapsed, setIsCollapsed] = useState(collapsible && defaultCollapsed);
690
+ const [uncontrolledIsCollapsed, setUncontrolledIsCollapsed] = useState(collapsible && defaultCollapsed);
691
+
692
+ // Determine if controlled
693
+ const isControlled = controlledIsCollapsed !== undefined;
694
+
695
+ // Use controlled value if provided, otherwise use internal state
696
+ const isCollapsed = isControlled ? controlledIsCollapsed : uncontrolledIsCollapsed;
665
697
  const [isHistoryCollapsed, setIsHistoryCollapsed] = useState(() => {
666
698
  if (typeof window !== 'undefined') {
667
699
  const saved = localStorage.getItem('ai-agent-panel-history-collapsed');
@@ -1876,8 +1908,17 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
1876
1908
  // Toggle collapse - only if collapsible is enabled
1877
1909
  const toggleCollapse = useCallback(() => {
1878
1910
  if (!collapsible) return;
1879
- setIsCollapsed((prev) => !prev);
1880
- }, [collapsible]);
1911
+
1912
+ const newValue = !isCollapsed;
1913
+
1914
+ // Update internal state if uncontrolled
1915
+ if (!isControlled) {
1916
+ setUncontrolledIsCollapsed(newValue);
1917
+ }
1918
+
1919
+ // Call callback if provided
1920
+ onCollapsedChange?.(newValue);
1921
+ }, [collapsible, isCollapsed, isControlled, onCollapsedChange]);
1881
1922
 
1882
1923
  // Toggle history collapse
1883
1924
  const toggleHistoryCollapse = useCallback(() => {
@@ -1927,7 +1968,11 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
1927
1968
  variant="ghost"
1928
1969
  size="icon"
1929
1970
  onClick={() => {
1930
- setIsCollapsed(false);
1971
+ // Expand panel in controlled or uncontrolled mode
1972
+ if (!isControlled) {
1973
+ setUncontrolledIsCollapsed(false);
1974
+ }
1975
+ onCollapsedChange?.(false);
1931
1976
  setShowSearch(true);
1932
1977
  }}
1933
1978
  >
@@ -1941,7 +1986,11 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
1941
1986
  variant="ghost"
1942
1987
  size="icon"
1943
1988
  onClick={() => {
1944
- setIsCollapsed(false);
1989
+ // Expand panel in controlled or uncontrolled mode
1990
+ if (!isControlled) {
1991
+ setUncontrolledIsCollapsed(false);
1992
+ }
1993
+ onCollapsedChange?.(false);
1945
1994
  handleNewConversation();
1946
1995
  }}
1947
1996
  >
@@ -1964,7 +2013,11 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
1964
2013
  variant={agent.id === currentAgentId ? 'secondary' : 'ghost'}
1965
2014
  size="icon"
1966
2015
  onClick={() => {
1967
- setIsCollapsed(false);
2016
+ // Expand panel in controlled or uncontrolled mode
2017
+ if (!isControlled) {
2018
+ setUncontrolledIsCollapsed(false);
2019
+ }
2020
+ onCollapsedChange?.(false);
1968
2021
  if (hasActiveConversation && activeConvForAgent) {
1969
2022
  // Switch to the existing conversation
1970
2023
  setCurrentConversationId(activeConvForAgent.conversationId);
@@ -60,3 +60,5 @@ export default Button;
60
60
 
61
61
 
62
62
 
63
+
64
+
@@ -156,3 +156,5 @@ export default Dialog;
156
156
 
157
157
 
158
158
 
159
+
160
+
@@ -36,3 +36,5 @@ export default Input;
36
36
 
37
37
 
38
38
 
39
+
40
+
@@ -159,3 +159,5 @@ export default Select;
159
159
 
160
160
 
161
161
 
162
+
163
+
@@ -67,3 +67,5 @@ export default ToolInfoModal;
67
67
 
68
68
 
69
69
 
70
+
71
+
@@ -76,3 +76,5 @@ export default Tooltip;
76
76
 
77
77
 
78
78
 
79
+
80
+
@@ -23,3 +23,5 @@ export type { DialogProps, DialogFooterProps } from './Dialog';
23
23
 
24
24
 
25
25
 
26
+
27
+