@pega/cosmos-react-work 8.9.5 → 8.11.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.
Files changed (32) hide show
  1. package/lib/components/CaseView/CaseHeader/CaseHeader.d.ts.map +1 -1
  2. package/lib/components/CaseView/CaseHeader/CaseHeader.js +10 -2
  3. package/lib/components/CaseView/CaseHeader/CaseHeader.js.map +1 -1
  4. package/lib/components/CaseView/CaseView.styles.d.ts.map +1 -1
  5. package/lib/components/CaseView/CaseView.styles.js +4 -1
  6. package/lib/components/CaseView/CaseView.styles.js.map +1 -1
  7. package/lib/components/GenAICoach/GenAICoach.d.ts.map +1 -1
  8. package/lib/components/GenAICoach/GenAICoach.js +109 -39
  9. package/lib/components/GenAICoach/GenAICoach.js.map +1 -1
  10. package/lib/components/GenAICoach/GenAICoach.styles.d.ts +9 -1
  11. package/lib/components/GenAICoach/GenAICoach.styles.d.ts.map +1 -1
  12. package/lib/components/GenAICoach/GenAICoach.styles.js +70 -16
  13. package/lib/components/GenAICoach/GenAICoach.styles.js.map +1 -1
  14. package/lib/components/GenAICoach/GenAICoach.types.d.ts +12 -1
  15. package/lib/components/GenAICoach/GenAICoach.types.d.ts.map +1 -1
  16. package/lib/components/GenAICoach/GenAICoach.types.js.map +1 -1
  17. package/lib/components/GenAICoach/GenAIMessage.d.ts.map +1 -1
  18. package/lib/components/GenAICoach/GenAIMessage.js +13 -5
  19. package/lib/components/GenAICoach/GenAIMessage.js.map +1 -1
  20. package/lib/components/GenAICoach/GenAIMessageFeedback.d.ts.map +1 -1
  21. package/lib/components/GenAICoach/GenAIMessageFeedback.js +4 -1
  22. package/lib/components/GenAICoach/GenAIMessageFeedback.js.map +1 -1
  23. package/lib/components/GenAICoach/InitialSuggestedMessage.d.ts.map +1 -1
  24. package/lib/components/GenAICoach/InitialSuggestedMessage.js +5 -6
  25. package/lib/components/GenAICoach/InitialSuggestedMessage.js.map +1 -1
  26. package/lib/components/UtilitiesLayout/UtilitiesLayout.d.ts.map +1 -1
  27. package/lib/components/UtilitiesLayout/UtilitiesLayout.js +3 -2
  28. package/lib/components/UtilitiesLayout/UtilitiesLayout.js.map +1 -1
  29. package/lib/components/UtilitiesLayout/UtilitiesLayout.styles.d.ts.map +1 -1
  30. package/lib/components/UtilitiesLayout/UtilitiesLayout.styles.js +2 -1
  31. package/lib/components/UtilitiesLayout/UtilitiesLayout.styles.js.map +1 -1
  32. package/package.json +3 -3
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
- import { Button, Flex, Icon, MenuButton, Progress, Text, createUID, menuHelpers, useI18n, useTestIds, useTheme, withTestIds, registerIcon, usePrevious, getFocusables, isMenuGroupProps, ErrorState, useArrows, focusableSelector, useLiveLog, useOuterEvent, ThemeOverride, hasProp, getActiveElement, useElement, Actions, useBreakpoint, Grid, useRefMap, VisuallyHiddenText, FileList, Lightbox, useUID, FormField } from '@pega/cosmos-react-core';
3
+ import { Button, Flex, Icon, MenuButton, Progress, Text, createUID, menuHelpers, useI18n, useSpeechRecognition, useTestIds, useTheme, withTestIds, registerIcon, usePrevious, getFocusables, isMenuGroupProps, ErrorState, useArrows, focusableSelector, useLiveLog, useOuterEvent, ThemeOverride, hasProp, getActiveElement, useElement, Actions, useBreakpoint, Grid, useRefMap, VisuallyHiddenText, FileList, Lightbox, FullscreenButton, FormField, Fullscreen, useUID, SpeechToTextButton, Toaster, useToaster } from '@pega/cosmos-react-core';
4
4
  import * as caretUpIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/caret-up.icon';
5
5
  import * as timesIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/times.icon';
6
6
  import * as caretDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/caret-down.icon';
@@ -9,12 +9,13 @@ import * as polarisSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/i
9
9
  import * as paperClipIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/paper-clip.icon';
10
10
  import * as warnSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/warn-solid.icon';
11
11
  import * as chatTypingIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/chat-typing.icon';
12
+ import * as sendSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/send-solid.icon';
12
13
  import { getGenAICoachTestIds } from './GenAICoach.test-ids';
13
14
  import { isCoachMessage, isInUtilities, isUserMessage } from './GenAICoach.utils';
14
- import { StyledMessagesContainer, StyledDisclaimerText, StyledGenAICoachContainer, StyledGenAIOptionsMenu, StyledInitialMessageContainer, StyledInputContainer, StyledMenuSuggestions, StyledMessagesList, StyledGridContainer, StyledFlexWrapper, StyledErrorContainer, StyledInput, StyledGuidedSuggestions, StyledComposerSection, StyledGenAIFormControl, StyledGenAITextArea, StyledSendButton, StyledGenAIFooter, StyledActionsContainer, StyledAgentIcon } from './GenAICoach.styles';
15
+ import { StyledMessagesContainer, StyledDisclaimerText, StyledGenAICoachContainer, StyledGenAIOptionsMenu, StyledInitialMessageContainer, StyledInputContainer, StyledMenuSuggestions, StyledMessagesList, StyledGridContainer, StyledFlexWrapper, StyledErrorContainer, StyledInput, StyledGuidedSuggestions, StyledComposerSection, StyledSendButton, StyledGenAIFormControl, StyledGenAITextArea, StyledInitialMessageGrid, StyledActionsContainer, StyledGenAIFooter, StyledAgentIcon } from './GenAICoach.styles';
15
16
  import ConversationHistory from './ConversationHistory';
16
17
  import { GenAIMessage, InitialSuggestedMessage } from '.';
17
- registerIcon(caretUpIcon, timesIcon, caretDownIcon, minusIcon, polarisSolidIcon, paperClipIcon, warnSolidIcon, chatTypingIcon);
18
+ registerIcon(caretUpIcon, timesIcon, caretDownIcon, minusIcon, polarisSolidIcon, paperClipIcon, warnSolidIcon, chatTypingIcon, sendSolidIcon);
18
19
  export const AgentIcon = () => {
19
20
  const uid = useUID();
20
21
  const idA = `agent-gradient-a-${uid}`;
@@ -22,16 +23,16 @@ export const AgentIcon = () => {
22
23
  const idC = `agent-clip-${uid}`;
23
24
  return (_jsxs(StyledAgentIcon, { xmlns: 'http://www.w3.org/2000/svg', filter: 'drop-shadow(0 .125rem .125rem rgba(0,0,0,.03)) drop-shadow(.125rem .5rem .5rem rgba(0,0,0,.05)) drop-shadow(.125rem 1rem 1rem rgba(0,0,0,.08))', viewBox: '0 0 60 60', children: [_jsxs("linearGradient", { id: idA, x1: '30.586', x2: '3.059', y1: '58.111', y2: '30.584', gradientUnits: 'userSpaceOnUse', children: [_jsx("stop", { offset: '.115', stopColor: '#681fc3' }), _jsx("stop", { offset: '.418', stopColor: '#9795f3' }), _jsx("stop", { offset: '.591', stopColor: '#b3d2ff' }), _jsx("stop", { offset: '.966', stopColor: '#a467f0' })] }), _jsxs("linearGradient", { id: idB, x1: '7.137', x2: '29.565', y1: '0', y2: '60.151', gradientUnits: 'userSpaceOnUse', children: [_jsx("stop", { offset: '.457', stopColor: '#8165d2', stopOpacity: '0' }), _jsx("stop", { offset: '.524', stopColor: '#280096', stopOpacity: '.4' })] }), _jsx("clipPath", { id: idC, children: _jsx("path", { d: 'M0 0h60v60H0z' }) }), _jsxs("g", { fillRule: 'evenodd', clipPath: `url(#${idC})`, clipRule: 'evenodd', children: [_jsx("path", { fill: `url(#${idA})`, d: 'M60 30.002c-9.023.937-16.054 3.632-20.86 8.203C33.633 43.242 30.586 50.508 30 60c-1.173-9.61-4.453-16.875-9.727-21.914C15.35 33.516 8.555 30.82 0 30c9.023-.703 16.054-3.515 21.093-8.438C26.132 16.523 29.063 9.376 29.999 0c.704 10.43 4.102 18.164 10.313 23.202C45.352 27.186 51.914 29.413 60 30zm-3.75-18.75c-2.228.235-3.984.936-5.391 2.226-1.289 1.289-1.992 3.047-2.109 5.274-.235-2.227-.937-3.983-2.108-5.155-1.289-1.288-3.048-2.109-5.391-2.344 2.227-.116 3.867-.82 5.156-1.991 1.288-1.289 2.108-3.164 2.343-5.508.117 2.46.937 4.336 2.344 5.508 1.288 1.171 2.93 1.875 5.156 1.991zM18.75 48.75c-2.345.236-4.103.937-5.392 2.227-1.288 1.172-1.992 2.93-2.108 5.274-.235-2.46-1.055-4.218-2.46-5.507-1.056-1.055-2.812-1.758-5.04-1.992 1.993-.116 3.633-.703 4.804-1.758 1.524-1.172 2.46-3.047 2.696-5.743.116 1.992.703 3.751 1.875 5.156 1.172 1.288 3.047 2.108 5.626 2.344z' }), _jsx("path", { fill: `url(#${idB})`, d: 'M60 30.002c-9.023.937-16.054 3.632-20.86 8.203C33.633 43.242 30.586 50.508 30 60c-1.173-9.61-4.453-16.875-9.727-21.914C15.35 33.516 8.555 30.82 0 30c9.023-.703 16.054-3.515 21.093-8.438C26.132 16.523 29.063 9.376 29.999 0c.704 10.43 4.102 18.164 10.313 23.202C45.352 27.186 51.914 29.413 60 30zm-3.75-18.75c-2.228.235-3.984.936-5.391 2.226-1.289 1.289-1.992 3.047-2.109 5.274-.235-2.227-.937-3.983-2.108-5.155-1.289-1.288-3.048-2.109-5.391-2.344 2.227-.116 3.867-.82 5.156-1.991 1.288-1.289 2.108-3.164 2.343-5.508.117 2.46.937 4.336 2.344 5.508 1.288 1.171 2.93 1.875 5.156 1.991zM18.75 48.75c-2.345.236-4.103.937-5.392 2.227-1.288 1.172-1.992 2.93-2.108 5.274-.235-2.46-1.055-4.218-2.46-5.507-1.056-1.055-2.812-1.758-5.04-1.992 1.993-.116 3.633-.703 4.804-1.758 1.524-1.172 2.46-3.047 2.696-5.743.116 1.992.703 3.751 1.875 5.156 1.172 1.288 3.047 2.108 5.626 2.344z' })] })] }));
24
25
  };
25
- const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: onCoachChangeProp, messages = [], onSend, initialSuggestedMessages, suggestions, loading, error, variant, onOpen, guidedMode = false, actions, conversationHistory, onLayoutChange, onAddAttachment, attachments, attachmentsError, lightboxPreviewProps, showSalutation = true, salutation, ...restProps }) => {
26
+ const VOICE_ERROR_DISMISS_DURATION = 3000;
27
+ const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: onCoachChangeProp, messages = [], onSend, initialSuggestedMessages, suggestions, loading, error, variant, onOpen, guidedMode = false, actions, conversationHistory, onLayoutChange, onAddAttachment, attachments, attachmentsError, lightboxPreviewProps, showSalutation = true, salutation, allowFullScreen = true, isInLandingPageUtilities, voiceToTextProps, ...restProps }) => {
26
28
  const theme = useTheme();
27
29
  const t = useI18n();
30
+ const testIds = useTestIds(testId, getGenAICoachTestIds);
31
+ const { announcePolite } = useLiveLog();
28
32
  const elementRef = useRef(null);
29
33
  const conversationRef = useRef(null);
30
34
  const genAICoachRef = useRef(null);
31
35
  const [messageEls, getMessageCbRef] = useRefMap();
32
- const isSmallOrAbove = useBreakpoint('sm', {
33
- breakpointRef: genAICoachRef
34
- });
35
36
  const focusInMessageListRef = useRef(false);
36
37
  const isUserTriggered = useRef(false);
37
38
  const lastFocusedMessageRef = useRef(null);
@@ -44,19 +45,26 @@ const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: on
44
45
  const historyViewRef = useRef(null);
45
46
  const fileUploadInputRef = useRef(null);
46
47
  const attachmentsAdded = useRef(false);
48
+ const pendingResult = useRef(false);
49
+ const isSmallOrAbove = useBreakpoint('sm', {
50
+ breakpointRef: genAICoachRef
51
+ });
47
52
  const [message, setMessage] = useState('');
53
+ const [interimMessage, setInterimMessage] = useState('');
48
54
  const [coachOptions, setCoachOptions] = useState(coachOptionsProps);
49
55
  const [arrowKey, setArrowKey] = useState(null);
50
56
  const [isComposerFocused, setIsComposerFocused] = useState(false);
57
+ const [animationInitialCursorPos, setAnimationInitialCursorPos] = useState(0);
58
+ const [fullScreen, setFullScreen] = useState(false);
59
+ const prevFullScreen = usePrevious(fullScreen);
51
60
  const previousMessages = usePrevious(messages);
52
- const testIds = useTestIds(testId, getGenAICoachTestIds);
53
- const { announcePolite } = useLiveLog();
54
61
  const composerId = useUID();
55
62
  const latestMessage = messages.at(-1);
56
- const condition = variant.placement === 'dialog' ||
57
- variant.placement === 'utilities' ||
58
- (variant.placement === 'fullpage' && !isSmallOrAbove) ||
59
- !conversationHistory;
63
+ const condition = !(fullScreen && conversationHistory) &&
64
+ (variant.placement === 'dialog' ||
65
+ variant.placement === 'utilities' ||
66
+ (variant.placement === 'fullpage' && !isSmallOrAbove) ||
67
+ !conversationHistory);
60
68
  const onCoachChange = (id) => {
61
69
  setCoachOptions(cur => {
62
70
  return cur.map(coach => {
@@ -79,6 +87,24 @@ const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: on
79
87
  return coachOptions[0].primary;
80
88
  }
81
89
  }, [coachOptions]);
90
+ const onResult = useCallback(value => {
91
+ pendingResult.current = false;
92
+ setMessage(prevMessage => {
93
+ return prevMessage ? `${prevMessage} ${value}` : value;
94
+ });
95
+ setInterimMessage('');
96
+ }, []);
97
+ const onInterimResult = useCallback(value => {
98
+ if (value) {
99
+ pendingResult.current = true;
100
+ setInterimMessage(message ? ` ${value}` : value);
101
+ }
102
+ }, [message]);
103
+ const { supported, active, start, stop, error: voiceToTextError } = useSpeechRecognition({
104
+ onResult,
105
+ onInterimResult,
106
+ langCode: voiceToTextProps?.langCode
107
+ });
82
108
  const handleSendMessage = useCallback(() => {
83
109
  const isMessageAndAttachmentsEmpty = !message && (!attachments || attachments.length === 0);
84
110
  const hasAttachmentsError = attachments &&
@@ -94,6 +120,9 @@ const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: on
94
120
  attachmentIds: attachments?.map(({ id }) => id)
95
121
  });
96
122
  setMessage('');
123
+ if (active) {
124
+ stop();
125
+ }
97
126
  }, [[message, latestMessage, attachments, attachmentsError]]);
98
127
  const handleEnterKeyDown = (e) => {
99
128
  if (e.key === 'Enter' && !e.shiftKey) {
@@ -110,22 +139,22 @@ const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: on
110
139
  return null;
111
140
  }
112
141
  if (coachOptions.length === 1) {
113
- return (_jsxs(Flex, { container: { gap: 1 }, children: [_jsx(Icon, { name: 'polaris-solid', color: theme.base.palette.ai }), _jsx(Text, { variant: 'h3', children: selectedCoach })] }));
142
+ return _jsx(Text, { variant: 'h2', children: selectedCoach });
114
143
  }
115
- return (_jsx(MenuButton, { text: selectedCoach, "aria-label": t('agent_switcher', [selectedCoach]), variant: 'text', as: StyledGenAIOptionsMenu, icon: 'polaris-solid', menu: {
144
+ return (_jsx(MenuButton, { text: selectedCoach, "aria-label": t('agent_switcher', [selectedCoach]), variant: 'text', as: StyledGenAIOptionsMenu, menu: {
116
145
  mode: 'single-select',
117
146
  items: coachOptions,
118
147
  onItemClick: onCoachChange
119
148
  } }));
120
149
  }, [coachOptions, selectedCoach]);
121
150
  const headerContent = useMemo(() => {
122
- return isInUtilities(variant) && variant.state === 'minimized' ? (_jsxs(_Fragment, { children: [_jsxs(Flex, { container: { gap: 1 }, children: [_jsx(Icon, { name: 'polaris-solid', color: theme.base.palette.ai }), _jsx(Text, { variant: 'h3', children: selectedCoach })] }), _jsx(Flex, { container: { alignItems: 'center' }, children: _jsx(Button, { icon: true, label: t('maximize'), "aria-label": t('agent_noun', [t('maximize')]), variant: 'simple', onClick: () => {
151
+ return isInUtilities(variant) && variant.state === 'minimized' ? (_jsxs(_Fragment, { children: [_jsx(Text, { variant: 'h2', children: selectedCoach }), _jsx(Flex, { container: { alignItems: 'center' }, children: _jsx(Button, { icon: true, label: t('maximize'), "aria-label": t('agent_noun', [t('maximize')]), variant: 'simple', onClick: () => {
123
152
  variant.onStateChange('maximized');
124
153
  isUserTriggered.current = true;
125
154
  }, children: _jsx(Icon, { name: 'caret-up' }) }) })] })) : (_jsxs(_Fragment, { children: [renderCoachOptions, _jsxs(Flex, { container: true, as: StyledActionsContainer, children: [isInUtilities(variant) && (_jsx(Button, { icon: true, label: t('minimize'), "aria-label": t('agent_noun', [t('minimize')]), variant: 'simple', onClick: () => {
126
155
  variant.onStateChange('minimized');
127
156
  isUserTriggered.current = true;
128
- }, children: _jsx(Icon, { name: 'minus' }) })), actions && (_jsx(Actions, { "data-testid": testIds.actions, contextualLabel: selectedCoach, ...actions })), variant.placement === 'dialog' && (_jsx(Button, { icon: true, label: t('close'), "aria-label": t('agent_noun', [t('close')]), variant: 'simple', onClick: variant.onClose, children: _jsx(Icon, { name: 'times' }) }))] })] }));
157
+ }, children: _jsx(Icon, { name: 'minus' }) })), allowFullScreen && _jsx(FullscreenButton, { onClick: () => setFullScreen(prev => !prev) }), actions && (_jsx(Actions, { "data-testid": testIds.actions, contextualLabel: selectedCoach, ...actions })), variant.placement === 'dialog' && (_jsx(Button, { icon: true, label: t('close'), "aria-label": t('agent_noun', [t('close')]), variant: 'simple', onClick: variant.onClose, children: _jsx(Icon, { name: 'times' }) }))] })] }));
129
158
  }, [variant, coachOptions]);
130
159
  const getMessageContainingElement = (element) => {
131
160
  if (element)
@@ -242,14 +271,37 @@ const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: on
242
271
  setArrowKey(null);
243
272
  focusInMessageListRef.current = false;
244
273
  });
274
+ const { push } = useToaster();
275
+ const onSpeechToTextButtonClick = useCallback(() => {
276
+ if (active) {
277
+ stop();
278
+ }
279
+ else {
280
+ start();
281
+ }
282
+ }, [active, stop, start]);
245
283
  const onFileChange = (e) => {
246
284
  if (e.target.files) {
247
285
  const newFiles = Array.from(e.target.files);
248
286
  onAddAttachment?.(newFiles);
249
287
  }
250
288
  };
251
- const genAIFooter = (_jsxs(Flex, { container: { direction: 'column' }, as: StyledGenAIFooter, children: [_jsx(FormField, { label: t('message_pega_gen_ai_coach'), labelHidden: true, labelFor: composerId, children: _jsx(StyledGenAIFormControl, { focused: isComposerFocused, children: _jsxs(Flex, { container: { direction: 'column', gap: 0.25 }, children: [_jsx(StyledGenAITextArea, { id: composerId, ref: textAreaRef, value: message, placeholder: t('write_message'), onKeyDown: handleEnterKeyDown, onChange: handleTextAreaChange, onFocus: () => {
289
+ const getGridColumns = () => {
290
+ const multiCol = 'repeat(auto-fit, minmax(calc(100% / 4 - 1rem), 1fr))';
291
+ const singleCol = '1fr';
292
+ if (!isSmallOrAbove && !fullScreen)
293
+ return singleCol;
294
+ return multiCol;
295
+ };
296
+ useEffect(() => {
297
+ if (voiceToTextError) {
298
+ push({ content: voiceToTextError });
299
+ }
300
+ }, [voiceToTextError]);
301
+ const genAIFooter = (_jsxs(Flex, { container: { direction: 'column' }, as: StyledGenAIFooter, children: [_jsx(FormField, { label: t('message_pega_gen_ai_coach'), labelHidden: true, labelFor: composerId, children: _jsx(StyledGenAIFormControl, { focused: isComposerFocused, children: _jsxs(Flex, { container: { direction: 'column', gap: 0.25 }, children: [_jsx(StyledGenAITextArea, { id: composerId, ref: textAreaRef, value: interimMessage ? `${message}${interimMessage}` : message, placeholder: t('write_message'), onKeyDown: handleEnterKeyDown, onChange: handleTextAreaChange, onFocus: () => {
252
302
  setIsComposerFocused(true);
303
+ if (active)
304
+ stop();
253
305
  }, onBlur: () => {
254
306
  setIsComposerFocused(false);
255
307
  }, autoResize: true }), _jsxs(Flex, { container: {
@@ -262,40 +314,53 @@ const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: on
262
314
  onItemClick: id => {
263
315
  const selected = menuHelpers.getItem(suggestions, id);
264
316
  if (selected) {
265
- onSend({
266
- id: selected.id,
267
- message: selected.primary
268
- });
317
+ setMessage(selected.primary);
318
+ textAreaRef.current?.focus();
269
319
  }
270
320
  }
271
- }, showArrow: false })), onAddAttachment && (_jsxs(_Fragment, { children: [_jsx(Button, { icon: true, onClick: () => {
321
+ }, showArrow: false })), voiceToTextProps?.enableDictation && supported && (_jsx(SpeechToTextButton, { active: active, onClick: onSpeechToTextButtonClick })), onAddAttachment && (_jsxs(_Fragment, { children: [_jsx(Button, { icon: true, onClick: () => {
272
322
  if (fileUploadInputRef.current) {
273
323
  fileUploadInputRef.current.value = '';
274
324
  }
275
325
  fileUploadInputRef.current?.click();
276
- }, variant: 'simple', label: t('add_attachment'), children: _jsx(Icon, { name: 'paper-clip' }) }), _jsx(StyledInput, { type: 'file', ref: fileUploadInputRef, onChange: onFileChange, multiple: false, "data-testid": testIds.attachments })] }))] }), latestMessage && isCoachMessage(latestMessage) && latestMessage.loading ? (_jsxs(Flex, { container: {
326
+ }, variant: 'simple', label: t('add_attachment'), children: _jsx(Icon, { name: 'paper-clip' }) }), _jsx(StyledInput, { type: 'file', ref: fileUploadInputRef, onChange: onFileChange, multiple: false, "data-testid": testIds.attachments })] }))] }), (latestMessage && isCoachMessage(latestMessage) && latestMessage.loading) ||
327
+ (active && pendingResult.current) ? (_jsxs(Flex, { container: {
277
328
  gap: 1,
278
329
  justify: 'end',
279
330
  alignItems: 'center',
280
331
  pad: 1
281
- }, children: [t('generating_response'), _jsx(Progress, { placement: 'inline' })] })) : (_jsx(StyledSendButton, { variant: 'primary', onClick: handleSendMessage, icon: true, label: t('send'), "aria-label": t('send_message'), children: _jsx(Icon, { name: 'send-solid' }) }))] })] }) }) }), attachments && attachments.length > 0 && (_jsxs(_Fragment, { children: [_jsx(Flex, { as: FileList, type: 'item', "aria-label": `${t('attachments')}`, items: attachments, container: { pad: [1, 0] } }), attachmentsError && (_jsxs(Flex, { container: { gap: 1, alignItems: 'center' }, as: StyledErrorContainer, children: [_jsx(Icon, { name: 'warn-solid' }), _jsx(VisuallyHiddenText, { children: `${t('error')} ` }), attachmentsError] }))] })), _jsx(Flex, { container: { justify: 'center' }, children: _jsx(StyledDisclaimerText, { inFullPage: !condition, children: t('ai_disclaimer') }) })] }));
332
+ }, children: [active && pendingResult.current
333
+ ? t('processing_speech')
334
+ : t('generating_response'), _jsx(Progress, { placement: 'inline' })] })) : (_jsx(StyledSendButton, { variant: 'primary', onClick: handleSendMessage, icon: true, label: t('send'), "aria-label": t('send_message'), children: _jsx(Icon, { name: 'send-solid' }) }))] })] }) }) }), attachments && attachments.length > 0 && (_jsxs(_Fragment, { children: [_jsx(Flex, { as: FileList, type: 'item', "aria-label": `${t('attachments')}`, items: attachments, container: { pad: [1, 0] } }), attachmentsError && (_jsxs(Flex, { container: { gap: 1, alignItems: 'center' }, as: StyledErrorContainer, children: [_jsx(Icon, { name: 'warn-solid' }), _jsx(VisuallyHiddenText, { children: `${t('error')} ` }), attachmentsError] }))] })), _jsx(Flex, { container: { justify: 'center' }, children: _jsx(StyledDisclaimerText, { inFullPage: !condition, children: t('ai_disclaimer') }) })] }));
335
+ const isCompact = variant.placement === 'fullpage' &&
336
+ !fullScreen &&
337
+ !isInLandingPageUtilities &&
338
+ messages.length === 0;
339
+ const fullPageAndInitialScreen = (fullScreen || (variant.placement === 'fullpage' && !isInLandingPageUtilities)) &&
340
+ messages.length === 0;
341
+ const renderTextArea = fullPageAndInitialScreen ? null : genAIFooter;
282
342
  const GenAICoachElement = (_jsx(_Fragment, { children: ((isInUtilities(variant) && variant.state !== 'minimized') || !isInUtilities(variant)) && (_jsxs(Flex, { container: { direction: 'column' }, as: StyledFlexWrapper, children: [_jsx(Flex, { as: StyledMessagesContainer, ref: messageContainerRef, container: loading || error
283
343
  ? { direction: 'column', pad: [0, 2], justify: 'center' }
284
344
  : { direction: 'column', pad: [0, 2] }, item: { grow: 1 }, children: loading || error ? (_jsx(Flex, { container: { justify: 'center', alignItems: 'center' }, children: loading ? (_jsx(Progress, { variant: 'ring', placement: 'block', message: typeof loading === 'string' ? loading : t('loading') })) : (_jsx(ErrorState, { message: error })) })) : (_jsx(_Fragment, { children: messages.length === 0 ? (_jsxs(Flex, { as: StyledInitialMessageContainer, container: {
285
- justify: 'center',
345
+ justify: isCompact ? 'start' : 'center',
286
346
  direction: 'column',
287
- gap: 8
347
+ alignItems: 'center',
348
+ gap: 2
288
349
  }, item: { grow: 1 }, children: [((isInUtilities(variant) && variant.state === 'maximized') ||
289
350
  !isInUtilities(variant)) &&
290
- showSalutation && (_jsxs(Flex, { container: {
291
- direction: 'column',
292
- alignItems: 'center',
293
- justify: 'center',
294
- gap: 1
295
- }, children: [_jsx(AgentIcon, {}), _jsx(Text, { variant: 'h3', children: salutation ?? t('welcome_text') })] })), _jsx(Flex, { container: { direction: 'column', gap: 1.5, alignItems: 'center' }, children: initialSuggestedMessages?.map(initialSuggestedMessage => (_jsx(InitialSuggestedMessage, { ...initialSuggestedMessage, onSend: initialMessage => {
296
- onSend(initialMessage);
351
+ showSalutation && (_jsxs(Flex, { container: { direction: 'column', alignItems: 'center', gap: 1 }, children: [_jsx(AgentIcon, {}), _jsx(Text, { variant: 'h3', children: salutation ?? t('welcome_text') })] })), _jsx(Grid, { as: StyledInitialMessageGrid, container: { cols: getGridColumns(), gap: 1.5 }, children: initialSuggestedMessages?.map(initialSuggestedMessage => (_jsx(InitialSuggestedMessage, { ...initialSuggestedMessage, onSend: initialMessage => {
352
+ if (guidedMode) {
353
+ onSend({
354
+ id: initialMessage.id,
355
+ message: initialMessage.message
356
+ });
357
+ }
358
+ else {
359
+ setMessage(initialMessage.message);
360
+ }
297
361
  isUserTriggered.current = true;
298
- }, testId: initialSuggestedMessage.id }))) })] })) : (_jsx(Flex, { as: StyledMessagesList, ref: conversationRef, "aria-label": `${t('conversation')} ${t('view')}`, container: { direction: 'column' }, onFocus: () => {
362
+ textAreaRef.current?.focus();
363
+ }, testId: initialSuggestedMessage.id }))) }), fullPageAndInitialScreen && !guidedMode && genAIFooter] })) : (_jsx(Flex, { as: StyledMessagesList, ref: conversationRef, "aria-label": `${t('conversation')} ${t('view')}`, container: { direction: 'column' }, onFocus: () => {
299
364
  if (!focusInMessageListRef.current) {
300
365
  if (lastFocusedMessageRef.current) {
301
366
  lastFocusedMessageRef.current.focus();
@@ -375,7 +440,11 @@ const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: on
375
440
  onSend
376
441
  }
377
442
  : item;
378
- return (_jsx(GenAIMessage, { ...messageProps, ref: getMessageCbRef(item.id), testId: item.id, announceInteraction: !focusInMessageListRef.current }));
443
+ return (_jsx(GenAIMessage, { ...messageProps, ref: getMessageCbRef(item.id), testId: item.id, announceInteraction: !focusInMessageListRef.current, onAnimationCursorUpdate: animatedTillCursor => {
444
+ if (isCoachMessage(item)) {
445
+ setAnimationInitialCursorPos(animatedTillCursor);
446
+ }
447
+ }, ...(prevFullScreen !== fullScreen ? { animationInitialCursorPos } : {}) }));
379
448
  }) })) })) }), ((isInUtilities(variant) && variant.state !== 'minimized') || !isInUtilities(variant)) &&
380
449
  !loading && (_jsx(Flex, { container: { direction: 'column' }, as: StyledInputContainer, children: _jsx(StyledComposerSection, { children: guidedMode ? (_jsx(_Fragment, { children: suggestions && messages.length > 0 && (_jsxs(_Fragment, { children: [latestMessage &&
381
450
  isCoachMessage(latestMessage) &&
@@ -396,13 +465,14 @@ const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: on
396
465
  items: suggestions,
397
466
  onItemClick: id => {
398
467
  const selected = menuHelpers.getItem(suggestions, id);
399
- if (selected)
468
+ if (selected) {
400
469
  onSend({
401
470
  id: selected.id,
402
471
  message: selected.primary
403
472
  });
473
+ }
404
474
  }
405
- } }) })), _jsx(Flex, { container: { justify: 'center' }, children: _jsx(StyledDisclaimerText, { inFullPage: !condition, children: t('ai_disclaimer') }) })] })) })) : (genAIFooter) }) }))] })) }));
475
+ } }) })), _jsx(Flex, { container: { justify: 'center' }, children: _jsx(StyledDisclaimerText, { inFullPage: !condition, children: t('ai_disclaimer') }) })] })) })) : (renderTextArea) }) }))] })) }));
406
476
  useEffect(() => {
407
477
  if (focusTextArea.current && !conversationHistory && textAreaRef.current) {
408
478
  textAreaRef.current.focus();
@@ -438,7 +508,7 @@ const GenAICoach = ({ testId, coachOptions: coachOptionsProps, onCoachChange: on
438
508
  focusTextArea.current = true;
439
509
  conversationHistory.onDismiss();
440
510
  }, inFullPage: !condition, ref: historyViewRef }));
441
- return (_jsxs(Flex, { container: { direction: 'column' }, as: StyledGenAICoachContainer, "data-testid": testIds.root, variant: variant, ref: genAICoachRef, ...restProps, children: [_jsx(Flex, { container: { justify: 'between', alignItems: 'center', pad: [1.5, 2, 0.5] }, children: headerContent }), condition ? (_jsx(_Fragment, { children: conversationHistory ? historyView : GenAICoachElement })) : (_jsxs(Grid, { container: { gap: 0.5, cols: '2fr 3fr' }, as: StyledGridContainer, conversationHistory: !!conversationHistory, children: [historyView, GenAICoachElement] })), lightboxPreviewProps && _jsx(Lightbox, { ...lightboxPreviewProps })] }));
511
+ return (_jsx(Toaster, { dismissAfter: VOICE_ERROR_DISMISS_DURATION, children: _jsx(Fullscreen, { children: _jsxs(Flex, { container: { direction: 'column' }, as: StyledGenAICoachContainer, "data-testid": testIds.root, variant: variant, fullScreen: fullScreen, isCompact: isCompact, ref: genAICoachRef, ...restProps, children: [_jsx(Flex, { container: { justify: 'between', alignItems: 'center', pad: [1.5, 2, 0.5] }, children: headerContent }), condition ? (_jsx(_Fragment, { children: conversationHistory ? historyView : GenAICoachElement })) : (_jsxs(Grid, { container: { gap: 0.5, cols: '2fr 3fr' }, as: StyledGridContainer, conversationHistory: !!conversationHistory, children: [historyView, GenAICoachElement] })), lightboxPreviewProps && _jsx(Lightbox, { ...lightboxPreviewProps })] }) }) }));
442
512
  };
443
513
  export default withTestIds(GenAICoach, getGenAICoachTestIds);
444
514
  //# sourceMappingURL=GenAICoach.js.map