@pega/cosmos-react-work 10.0.0-build.7.0 → 10.0.0-build.8.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.
- package/lib/components/GenAICoach/GenAICoach.d.ts.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.js +40 -41
- package/lib/components/GenAICoach/GenAICoach.js.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.styles.d.ts +1 -0
- package/lib/components/GenAICoach/GenAICoach.styles.d.ts.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.styles.js +18 -1
- package/lib/components/GenAICoach/GenAICoach.styles.js.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.types.d.ts +2 -0
- package/lib/components/GenAICoach/GenAICoach.types.d.ts.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.types.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenAICoach.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAICoach.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GenAICoach.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAICoach.tsx"],"names":[],"mappings":"AAgHA,OAAO,EAAyC,KAAK,eAAe,EAAE,MAAM,GAAG,CAAC;AAiDhF,eAAO,MAAM,SAAS,+CA2GrB,CAAC;AAEF,eAAO,MAAM,gBAAgB,+CAQ5B,CAAC;iCA28DyB,eAAe;;;AAQ1C,wBAA6D"}
|
|
@@ -17,24 +17,30 @@ import * as dockIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/doc
|
|
|
17
17
|
import * as undockIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/undock.icon';
|
|
18
18
|
import * as caretLeftIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/caret-left.icon';
|
|
19
19
|
import * as caretRightIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/caret-right.icon';
|
|
20
|
+
import * as clockSlaIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/clock-sla.icon';
|
|
20
21
|
import { getGenAICoachTestIds } from './GenAICoach.test-ids';
|
|
21
22
|
import { getSelectedKeys, isCoachMessage, isInUtilities, isUserMessage } from './GenAICoach.utils';
|
|
22
|
-
import { StyledMessagesContainer, StyledDisclaimerText, StyledGenAICoachContainer, StyledGenAIOptionsMenu, StyledInitialMessageContainer, StyledInputContainer, StyledMenuSuggestions, StyledMessagesList, StyledGridContainer, StyledFlexWrapper, StyledErrorContainer, StyledInput, StyledGuidedSuggestions, StyledComposerSection, StyledSendButton, StyledStopGeneratingButton, StyledGenAIFormControl, StyledGenAITextArea, StyledInitialMessageGrid, StyledGenAIFooter, StyledAgentIcon, StyledActionsContainer, StyledHeaderContainer, StyledFullscreenWrapper, StyledScrollButton, StyledSuggestionCardsView, StyledSuggestionCardsBottomHalf, StyledStickyComposer, StyledAISuggestedBadge, StyledSalutation, StyledSubHeading, StyledComposerWrapper, StyledBannerSalutationBlock, StyledComposerSelector, StyledSimplifiedInitialMessageGrid } from './GenAICoach.styles';
|
|
23
|
+
import { StyledMessagesContainer, StyledDisclaimerText, StyledGenAICoachContainer, StyledGenAIOptionsMenu, StyledInitialMessageContainer, StyledInputContainer, StyledMenuSuggestions, StyledMessagesList, StyledGridContainer, StyledFlexWrapper, StyledErrorContainer, StyledInput, StyledGuidedSuggestions, StyledComposerSection, StyledSendButton, StyledStopGeneratingButton, StyledGenAIFormControl, StyledGenAITextArea, StyledInitialMessageGrid, StyledGenAIFooter, StyledAgentIcon, StyledActionsContainer, StyledHeaderContainer, StyledFullscreenWrapper, StyledScrollButton, StyledSuggestionCardsView, StyledSuggestionCardsBottomHalf, StyledStickyComposer, StyledAISuggestedBadge, StyledSalutation, StyledSubHeading, StyledComposerWrapper, StyledBannerSalutationBlock, StyledComposerSelector, StyledSimplifiedInitialMessageGrid, StyledConversationHistoryButton } from './GenAICoach.styles';
|
|
23
24
|
import ActiveCases from './ActiveCases';
|
|
24
25
|
import CaseWorkflow from './CaseWorkflow';
|
|
25
26
|
import ConversationHistory from './ConversationHistory';
|
|
26
27
|
import Questionnaire from './Questionnaire';
|
|
27
28
|
import { GenAIMessage, InitialSuggestedMessage } from '.';
|
|
28
|
-
registerIcon(caretUpIcon, timesIcon, caretDownIcon, minusIcon, polarisSolidIcon, paperClipIcon, warnSolidIcon, squareSolidIcon, sendSolidIcon, plusIcon, dockIcon, undockIcon, caretLeftIcon, caretRightIcon, moreAltIcon);
|
|
29
|
+
registerIcon(caretUpIcon, timesIcon, caretDownIcon, minusIcon, polarisSolidIcon, paperClipIcon, warnSolidIcon, squareSolidIcon, sendSolidIcon, plusIcon, dockIcon, undockIcon, caretLeftIcon, caretRightIcon, clockSlaIcon, moreAltIcon);
|
|
29
30
|
const onHeightTransitionEnd = (el, callback) => {
|
|
30
31
|
const handler = (e) => {
|
|
31
32
|
if (e.propertyName !== 'height' || e.target !== el)
|
|
32
33
|
return;
|
|
33
34
|
el.removeEventListener('transitionend', handler);
|
|
35
|
+
el.removeEventListener('transitioncancel', handler);
|
|
34
36
|
callback();
|
|
35
37
|
};
|
|
36
38
|
el.addEventListener('transitionend', handler);
|
|
37
|
-
|
|
39
|
+
el.addEventListener('transitioncancel', handler);
|
|
40
|
+
return () => {
|
|
41
|
+
el.removeEventListener('transitionend', handler);
|
|
42
|
+
el.removeEventListener('transitioncancel', handler);
|
|
43
|
+
};
|
|
38
44
|
};
|
|
39
45
|
const buildInitialFormAnswers = (questions = []) => Object.fromEntries(questions.map(question => [
|
|
40
46
|
question.field,
|
|
@@ -98,7 +104,7 @@ const HeaderActions = ({ actions, allowFullScreen, variant, isUserTriggeredRef,
|
|
|
98
104
|
}
|
|
99
105
|
return (_jsx(Actions, { ...(actions ?? {}), menuAt: 1, "data-testid": actionsTestId, contextualLabel: selectedCoach, items: mergedItems }));
|
|
100
106
|
};
|
|
101
|
-
const GenAICoachContent = ({ testId, coachOptions: coachOptionsProps, onCoachChange: onCoachChangeProp, messages = [], onSend, initialSuggestedMessages, suggestions, loading, error, variant, onOpen, guidedMode = false, actions, onNewChat, conversationHistory, onLayoutChange, onAddAttachment, attachments, attachmentsError, lightboxPreviewProps, allowFullScreen = true, isInLandingPageUtilities, stopProcess, voiceToTextProps, salutation, showSalutation = true, isPortalAgent = false, pagePanel, suggestionCardsView, draftMessage, caseWorkflow, activeCases, onStop, isCreatingConversation, conversationError, questionnaireData, onQuestionnaireDismiss, simplifiedAgent = false, subHeading, operatorName, agentModeProps, modelSelectorProps, ...restProps }) => {
|
|
107
|
+
const GenAICoachContent = ({ testId, coachOptions: coachOptionsProps, onCoachChange: onCoachChangeProp, messages = [], onSend, initialSuggestedMessages, suggestions, loading, error, variant, onOpen, guidedMode = false, actions, onNewChat, conversationHistory, onConversationHistoryOpen, onLayoutChange, onAddAttachment, attachments, attachmentsError, lightboxPreviewProps, allowFullScreen = true, isInLandingPageUtilities, stopProcess, voiceToTextProps, salutation, showSalutation = true, isPortalAgent = false, pagePanel, suggestionCardsView, draftMessage, caseWorkflow, activeCases, onStop, isCreatingConversation, conversationError, questionnaireData, onQuestionnaireDismiss, simplifiedAgent = false, subHeading, operatorName, agentModeProps, modelSelectorProps, ...restProps }) => {
|
|
102
108
|
const scrollTolerancePx = 2;
|
|
103
109
|
const scrollThresholdPx = 50;
|
|
104
110
|
const streamBufferLh = simplifiedAgent ? 15 : 5;
|
|
@@ -115,15 +121,15 @@ const GenAICoachContent = ({ testId, coachOptions: coachOptionsProps, onCoachCha
|
|
|
115
121
|
const genAICoachRef = useRef(null);
|
|
116
122
|
const [messageEls, getMessageCbRef] = useRefMap();
|
|
117
123
|
const [showInitialScreen, setShowInitialScreen] = useState(true);
|
|
118
|
-
const prevExpandedHeightRef = useRef(0);
|
|
119
124
|
const agentInBanner = simplifiedAgent && variant.placement === 'fullpage';
|
|
125
|
+
const historyOpen = !!conversationHistory;
|
|
120
126
|
const agentExpanded = simplifiedAgent && messages.length > 0;
|
|
121
127
|
const hasAgentResponse = messages.some(msg => isCoachMessage(msg) && !msg.loading);
|
|
122
128
|
const focusInMessageListRef = useRef(false);
|
|
123
129
|
const mouseTriggeredFocusRef = useRef(false);
|
|
124
130
|
const isUserTriggered = useRef(false);
|
|
125
131
|
const userInitiatedSendRef = useRef(false);
|
|
126
|
-
const
|
|
132
|
+
const prevHeightRef = useRef(0);
|
|
127
133
|
const showNextCoachSender = useRef(true);
|
|
128
134
|
const lastFocusedMessageRef = useRef(null);
|
|
129
135
|
const initialFocusedElementRef = useRef(null);
|
|
@@ -498,6 +504,9 @@ const GenAICoachContent = ({ testId, coachOptions: coachOptionsProps, onCoachCha
|
|
|
498
504
|
return;
|
|
499
505
|
if (simplifiedAgent) {
|
|
500
506
|
userInitiatedSendRef.current = true;
|
|
507
|
+
if (agentInBanner && messages.length === 0) {
|
|
508
|
+
prevHeightRef.current = genAICoachRef.current?.getBoundingClientRect().height ?? 0;
|
|
509
|
+
}
|
|
501
510
|
}
|
|
502
511
|
onSend({
|
|
503
512
|
id: createUID(),
|
|
@@ -542,11 +551,9 @@ const GenAICoachContent = ({ testId, coachOptions: coachOptionsProps, onCoachCha
|
|
|
542
551
|
variant.onStateChange('maximized');
|
|
543
552
|
isUserTriggered.current = true;
|
|
544
553
|
}, children: _jsx(Icon, { name: 'caret-up' }) }) })] })) : (_jsxs(_Fragment, { children: [renderCoachOptions, _jsxs(Flex, { container: { gap: 0.5 }, as: StyledActionsContainer, children: [activeCases && _jsx(ActiveCases, { activeCases: activeCases }), simplifiedAgent && (_jsx(HeaderActions, { actions: actions, allowFullScreen: allowFullScreen, variant: variant, isUserTriggeredRef: isUserTriggered, onFullscreenToggle: toggleFullscreen, isFullscreen: fullScreen, selectedCoach: selectedCoach, actionsTestId: testIds.actions, simplifiedAgent: true })), onNewChat && (_jsx(Button, { icon: true, variant: 'simple', label: simplifiedAgent ? t('close') : t('new_chat'), "aria-label": simplifiedAgent ? t('close_chat_with_ai') : t('new_chat'), onClick: () => {
|
|
545
|
-
if (
|
|
546
|
-
|
|
547
|
-
genAICoachRef.current.getBoundingClientRect().height;
|
|
554
|
+
if (agentInBanner && genAICoachRef.current) {
|
|
555
|
+
prevHeightRef.current = genAICoachRef.current.getBoundingClientRect().height;
|
|
548
556
|
}
|
|
549
|
-
userInitiatedNewChatRef.current = true;
|
|
550
557
|
if (simplifiedAgent && conversationHistory) {
|
|
551
558
|
conversationHistory.onDismiss();
|
|
552
559
|
}
|
|
@@ -607,38 +614,16 @@ const GenAICoachContent = ({ testId, coachOptions: coachOptionsProps, onCoachCha
|
|
|
607
614
|
textAreaRef.current?.focus();
|
|
608
615
|
}
|
|
609
616
|
}, [draftMessage, suggestionCardsView]);
|
|
610
|
-
|
|
611
|
-
if (!agentInBanner ||
|
|
612
|
-
!genAICoachRef.current ||
|
|
613
|
-
messages.length !== 0 ||
|
|
614
|
-
(loading && conversationHistory))
|
|
615
|
-
return;
|
|
617
|
+
const animateHeightFrom = useCallback((fromHeight) => {
|
|
616
618
|
const el = genAICoachRef.current;
|
|
617
|
-
|
|
618
|
-
const storedHeight = parseFloat(el.style.getPropertyValue('--compact-height')) || 0;
|
|
619
|
-
if (storedHeight > 0 && Math.abs(currentHeight - storedHeight) > scrollTolerancePx)
|
|
620
|
-
return;
|
|
621
|
-
el.style.removeProperty('--compact-height');
|
|
622
|
-
const naturalHeight = el.getBoundingClientRect().height;
|
|
623
|
-
el.style.setProperty('--compact-height', `${naturalHeight}px`);
|
|
624
|
-
});
|
|
625
|
-
useLayoutEffect(() => {
|
|
626
|
-
if (!agentInBanner || messages.length !== 0)
|
|
627
|
-
return;
|
|
628
|
-
if (!userInitiatedNewChatRef.current || !genAICoachRef.current)
|
|
619
|
+
if (!el)
|
|
629
620
|
return;
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
const fromHeight = prevExpandedHeightRef.current;
|
|
633
|
-
const toHeight = parseFloat(el.style.getPropertyValue('--compact-height')) || 0;
|
|
634
|
-
if (!fromHeight || !toHeight)
|
|
621
|
+
const toHeight = el.getBoundingClientRect().height;
|
|
622
|
+
if (Math.abs(fromHeight - toHeight) <= scrollTolerancePx)
|
|
635
623
|
return;
|
|
636
|
-
el.style.height = `${fromHeight}px`;
|
|
637
624
|
el.style.transition = 'none';
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
prevExpandedHeightRef.current = 0;
|
|
641
|
-
});
|
|
625
|
+
el.style.height = `${fromHeight}px`;
|
|
626
|
+
const removeListener = onHeightTransitionEnd(el, () => el.style.removeProperty('height'));
|
|
642
627
|
const rafId = requestAnimationFrame(() => {
|
|
643
628
|
el.getBoundingClientRect();
|
|
644
629
|
el.style.removeProperty('transition');
|
|
@@ -647,8 +632,19 @@ const GenAICoachContent = ({ testId, coachOptions: coachOptionsProps, onCoachCha
|
|
|
647
632
|
return () => {
|
|
648
633
|
cancelAnimationFrame(rafId);
|
|
649
634
|
removeListener();
|
|
635
|
+
el.style.removeProperty('height');
|
|
636
|
+
el.style.removeProperty('transition');
|
|
650
637
|
};
|
|
651
|
-
}, [
|
|
638
|
+
}, []);
|
|
639
|
+
useLayoutEffect(() => {
|
|
640
|
+
const fromHeight = prevHeightRef.current;
|
|
641
|
+
if (!agentInBanner || !fromHeight || historyOpen)
|
|
642
|
+
return;
|
|
643
|
+
if (messages.length === 0 && !showInitialScreen)
|
|
644
|
+
return;
|
|
645
|
+
prevHeightRef.current = 0;
|
|
646
|
+
return animateHeightFrom(fromHeight);
|
|
647
|
+
}, [messages.length, agentInBanner, showInitialScreen, historyOpen, animateHeightFrom]);
|
|
652
648
|
useEffect(() => {
|
|
653
649
|
if (!agentInBanner)
|
|
654
650
|
return;
|
|
@@ -890,7 +886,7 @@ const GenAICoachContent = ({ testId, coachOptions: coachOptionsProps, onCoachCha
|
|
|
890
886
|
justify: 'between',
|
|
891
887
|
gap: 2,
|
|
892
888
|
pad: [undefined, 1, 1, 1]
|
|
893
|
-
}, children: [_jsxs(Flex, { container: { alignItems: 'center' }, item: { grow: 1, shrink: 1, basis: '0%' }, children: [!(messages.length === 0 && suggestionCardsView) && suggestions && (_jsx(MenuButton, { text: t('suggestions'), variant: 'simple', icon: 'chat-typing', iconOnly: true, as: StyledMenuSuggestions, menu: {
|
|
889
|
+
}, children: [_jsxs(Flex, { container: { alignItems: 'center' }, item: { grow: 1, shrink: 1, basis: '0%' }, children: [agentInBanner && messages.length === 0 && onConversationHistoryOpen && (_jsx(Flex, { container: { alignItems: 'center' }, as: StyledConversationHistoryButton, children: _jsx(Button, { icon: true, variant: 'simple', label: t('your_chats'), onClick: onConversationHistoryOpen, children: _jsx(Icon, { name: 'clock-sla' }) }) })), !(messages.length === 0 && suggestionCardsView) && suggestions && (_jsx(MenuButton, { text: t('suggestions'), variant: 'simple', icon: 'chat-typing', iconOnly: true, as: StyledMenuSuggestions, menu: {
|
|
894
890
|
items: suggestions,
|
|
895
891
|
onItemClick: id => {
|
|
896
892
|
const selected = menuHelpers.getItem(suggestions, id);
|
|
@@ -960,7 +956,7 @@ const GenAICoachContent = ({ testId, coachOptions: coachOptionsProps, onCoachCha
|
|
|
960
956
|
!fullScreen &&
|
|
961
957
|
!isInLandingPageUtilities &&
|
|
962
958
|
messages.length === 0 &&
|
|
963
|
-
!(
|
|
959
|
+
!(agentInBanner && historyOpen);
|
|
964
960
|
const fullPageAndInitialScreen = (fullScreen || (variant.placement === 'fullpage' && !isInLandingPageUtilities)) &&
|
|
965
961
|
messages.length === 0;
|
|
966
962
|
const renderTextArea = agentInBanner || !fullPageAndInitialScreen ? genAIFooter : null;
|
|
@@ -1181,6 +1177,9 @@ const GenAICoachContent = ({ testId, coachOptions: coachOptionsProps, onCoachCha
|
|
|
1181
1177
|
conversationHistory.onItemClick?.(conversationId);
|
|
1182
1178
|
}, onDismiss: () => {
|
|
1183
1179
|
focusTextArea.current = true;
|
|
1180
|
+
if (agentInBanner && messages.length === 0 && genAICoachRef.current) {
|
|
1181
|
+
prevHeightRef.current = genAICoachRef.current.getBoundingClientRect().height;
|
|
1182
|
+
}
|
|
1184
1183
|
conversationHistory.onDismiss();
|
|
1185
1184
|
}, inFullPage: !condition, ref: historyViewRef }));
|
|
1186
1185
|
return (_jsxs(Flex, { ...restProps, container: { direction: 'column' }, as: StyledGenAICoachContainer, "data-testid": testIds.root, variant: variant, fullScreen: fullScreen, isCompact: isCompact, isPortalAgent: isPortalAgent, simplifiedAgent: simplifiedAgent, ref: genAICoachRef, children: [_jsx(Flex, { as: agentExpanded ? StyledHeaderContainer : undefined, container: {
|