@pega/cosmos-react-work 9.0.0-build.9.9 → 9.0.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/AppAnnouncement/AppAnnouncement.d.ts +2 -1
- package/lib/components/AppAnnouncement/AppAnnouncement.d.ts.map +1 -1
- package/lib/components/AppAnnouncement/AppAnnouncement.js +36 -21
- package/lib/components/AppAnnouncement/AppAnnouncement.js.map +1 -1
- package/lib/components/Article/ArticleRating.d.ts +1 -1
- package/lib/components/Article/ArticleRating.d.ts.map +1 -1
- package/lib/components/ArticleList/AIArticleSummary.d.ts +3 -1
- package/lib/components/ArticleList/AIArticleSummary.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleBuddy.d.ts +1 -1
- package/lib/components/ArticleList/ArticleBuddy.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleBuddy.js +5 -1
- package/lib/components/ArticleList/ArticleBuddy.js.map +1 -1
- package/lib/components/ArticleList/ArticleBuddyList.d.ts +1 -1
- package/lib/components/ArticleList/ArticleBuddyList.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleBuddyResponse.d.ts +189 -3
- package/lib/components/ArticleList/ArticleBuddyResponse.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleBuddyResponse.js +1 -1
- package/lib/components/ArticleList/ArticleBuddyResponse.js.map +1 -1
- package/lib/components/ArticleList/ArticleFeedback.d.ts +3 -1
- package/lib/components/ArticleList/ArticleFeedback.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleList.d.ts +2 -2
- package/lib/components/ArticleList/ArticleList.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleList.js +6 -0
- package/lib/components/ArticleList/ArticleList.js.map +1 -1
- package/lib/components/ArticleList/ArticleList.types.d.ts +17 -2
- package/lib/components/ArticleList/ArticleList.types.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleList.types.js.map +1 -1
- package/lib/components/ArticleList/ArticleListHeader.d.ts +183 -1
- package/lib/components/ArticleList/ArticleListHeader.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleSummary.styles.d.ts +2 -2
- package/lib/components/ArticleList/ArticleSummary.styles.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleSummaryHeader.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleSummaryHeader.js +3 -1
- package/lib/components/ArticleList/ArticleSummaryHeader.js.map +1 -1
- package/lib/components/ArticleList/QuestionList.d.ts +5 -3
- package/lib/components/ArticleList/QuestionList.d.ts.map +1 -1
- package/lib/components/ArticleList/RelatedQuestions.d.ts +4 -2
- package/lib/components/ArticleList/RelatedQuestions.d.ts.map +1 -1
- package/lib/components/Assignments/Assignments.d.ts +2 -2
- package/lib/components/Assignments/Assignments.d.ts.map +1 -1
- package/lib/components/Assignments/Assignments.js +1 -1
- package/lib/components/Assignments/Assignments.js.map +1 -1
- package/lib/components/Assignments/Assignments.styles.d.ts +7 -3
- package/lib/components/Assignments/Assignments.styles.d.ts.map +1 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.d.ts +2 -2
- package/lib/components/CaseHierarchy/CaseHierarchy.d.ts.map +1 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.js +4 -3
- package/lib/components/CaseHierarchy/CaseHierarchy.js.map +1 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.styles.d.ts +7 -3
- package/lib/components/CaseHierarchy/CaseHierarchy.styles.d.ts.map +1 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.styles.js +9 -7
- package/lib/components/CaseHierarchy/CaseHierarchy.styles.js.map +1 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.test-ids.d.ts +1 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.test-ids.d.ts.map +1 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.test-ids.js +2 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.test-ids.js.map +1 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.types.d.ts +7 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.types.d.ts.map +1 -1
- package/lib/components/CaseHierarchy/CaseHierarchy.types.js.map +1 -1
- package/lib/components/CasePreview/CasePreview.d.ts +1 -1
- package/lib/components/CasePreview/CasePreview.d.ts.map +1 -1
- package/lib/components/CasePreview/CasePreview.js +83 -115
- package/lib/components/CasePreview/CasePreview.js.map +1 -1
- package/lib/components/CaseView/CaseHeader/CaseHeader.d.ts.map +1 -1
- package/lib/components/CaseView/CaseHeader/CaseHeader.js +97 -27
- package/lib/components/CaseView/CaseHeader/CaseHeader.js.map +1 -1
- package/lib/components/CaseView/CaseHeader/Summary.d.ts.map +1 -1
- package/lib/components/CaseView/CaseHeader/Summary.js +8 -1
- package/lib/components/CaseView/CaseHeader/Summary.js.map +1 -1
- package/lib/components/CaseView/CaseSummaryFields.js +1 -1
- package/lib/components/CaseView/CaseSummaryFields.js.map +1 -1
- package/lib/components/CaseView/CaseView.d.ts.map +1 -1
- package/lib/components/CaseView/CaseView.js +49 -20
- package/lib/components/CaseView/CaseView.js.map +1 -1
- package/lib/components/CaseView/CaseView.styles.d.ts +83 -47
- package/lib/components/CaseView/CaseView.styles.d.ts.map +1 -1
- package/lib/components/CaseView/CaseView.styles.js +329 -122
- package/lib/components/CaseView/CaseView.styles.js.map +1 -1
- package/lib/components/CaseView/CaseView.types.d.ts +24 -8
- package/lib/components/CaseView/CaseView.types.d.ts.map +1 -1
- package/lib/components/CaseView/CaseView.types.js.map +1 -1
- package/lib/components/CaseView/UtilitiesSummary.d.ts +1 -1
- package/lib/components/CaseView/UtilitiesSummary.d.ts.map +1 -1
- package/lib/components/CaseView/UtilitiesSummary.js +14 -4
- package/lib/components/CaseView/UtilitiesSummary.js.map +1 -1
- package/lib/components/CaseView/UtilitySummaryItemDialog.d.ts.map +1 -1
- package/lib/components/CaseView/UtilitySummaryItemDialog.js +10 -4
- package/lib/components/CaseView/UtilitySummaryItemDialog.js.map +1 -1
- package/lib/components/ConfigurableLayout/LayoutCell.d.ts.map +1 -1
- package/lib/components/ConfigurableLayout/LayoutCell.js +25 -25
- package/lib/components/ConfigurableLayout/LayoutCell.js.map +1 -1
- package/lib/components/Confirmation/Confirmation.d.ts +10 -0
- package/lib/components/Confirmation/Confirmation.d.ts.map +1 -1
- package/lib/components/Confirmation/Confirmation.js +2 -2
- package/lib/components/Confirmation/Confirmation.js.map +1 -1
- package/lib/components/Confirmation/index.d.ts +1 -1
- package/lib/components/Confirmation/index.d.ts.map +1 -1
- package/lib/components/Confirmation/index.js.map +1 -1
- package/lib/components/Details/Details.d.ts +3 -2
- package/lib/components/Details/Details.d.ts.map +1 -1
- package/lib/components/Details/Details.js +6 -5
- package/lib/components/Details/Details.js.map +1 -1
- package/lib/components/Details/Details.styles.d.ts +17 -15
- package/lib/components/Details/Details.styles.d.ts.map +1 -1
- package/lib/components/Details/Details.styles.js +28 -15
- package/lib/components/Details/Details.styles.js.map +1 -1
- package/lib/components/Details/Details.test-ids.d.ts +1 -1
- package/lib/components/Details/Details.test-ids.d.ts.map +1 -1
- package/lib/components/Details/Details.test-ids.js +2 -1
- package/lib/components/Details/Details.test-ids.js.map +1 -1
- package/lib/components/Details/DetailsList.d.ts.map +1 -1
- package/lib/components/Details/DetailsList.js +1 -5
- package/lib/components/Details/DetailsList.js.map +1 -1
- package/lib/components/GenAICoach/ActiveCases.d.ts +5 -0
- package/lib/components/GenAICoach/ActiveCases.d.ts.map +1 -0
- package/lib/components/GenAICoach/ActiveCases.js +50 -0
- package/lib/components/GenAICoach/ActiveCases.js.map +1 -0
- package/lib/components/GenAICoach/CaseWorkflow.d.ts +5 -0
- package/lib/components/GenAICoach/CaseWorkflow.d.ts.map +1 -0
- package/lib/components/GenAICoach/CaseWorkflow.js +111 -0
- package/lib/components/GenAICoach/CaseWorkflow.js.map +1 -0
- package/lib/components/GenAICoach/ConversationHistory.d.ts.map +1 -1
- package/lib/components/GenAICoach/ConversationHistory.js +11 -13
- package/lib/components/GenAICoach/ConversationHistory.js.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.d.ts +4 -3
- package/lib/components/GenAICoach/GenAICoach.d.ts.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.js +721 -141
- package/lib/components/GenAICoach/GenAICoach.js.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.styles.d.ts +1639 -35
- package/lib/components/GenAICoach/GenAICoach.styles.d.ts.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.styles.js +867 -82
- package/lib/components/GenAICoach/GenAICoach.styles.js.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.test-ids.d.ts +3 -2
- package/lib/components/GenAICoach/GenAICoach.test-ids.d.ts.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.test-ids.js +6 -1
- package/lib/components/GenAICoach/GenAICoach.test-ids.js.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.types.d.ts +215 -9
- package/lib/components/GenAICoach/GenAICoach.types.d.ts.map +1 -1
- package/lib/components/GenAICoach/GenAICoach.types.js.map +1 -1
- package/lib/components/GenAICoach/GenAIMessage.d.ts +6 -0
- package/lib/components/GenAICoach/GenAIMessage.d.ts.map +1 -1
- package/lib/components/GenAICoach/GenAIMessage.js +101 -52
- package/lib/components/GenAICoach/GenAIMessage.js.map +1 -1
- package/lib/components/GenAICoach/GenAIMessageFeedback.d.ts +4 -0
- package/lib/components/GenAICoach/GenAIMessageFeedback.d.ts.map +1 -0
- package/lib/components/GenAICoach/GenAIMessageFeedback.js +95 -0
- package/lib/components/GenAICoach/GenAIMessageFeedback.js.map +1 -0
- package/lib/components/GenAICoach/GenAIMessageProgress.d.ts +4 -1
- package/lib/components/GenAICoach/GenAIMessageProgress.d.ts.map +1 -1
- package/lib/components/GenAICoach/GenAIMessageProgress.js +11 -35
- package/lib/components/GenAICoach/GenAIMessageProgress.js.map +1 -1
- package/lib/components/GenAICoach/InitialSuggestedMessage.d.ts.map +1 -1
- package/lib/components/GenAICoach/InitialSuggestedMessage.js +5 -6
- package/lib/components/GenAICoach/InitialSuggestedMessage.js.map +1 -1
- package/lib/components/GenAICoach/PortalAgentSplitView.d.ts +6 -0
- package/lib/components/GenAICoach/PortalAgentSplitView.d.ts.map +1 -0
- package/lib/components/GenAICoach/PortalAgentSplitView.js +75 -0
- package/lib/components/GenAICoach/PortalAgentSplitView.js.map +1 -0
- package/lib/components/GenAICoach/Questionnaire.d.ts +4 -0
- package/lib/components/GenAICoach/Questionnaire.d.ts.map +1 -0
- package/lib/components/GenAICoach/Questionnaire.js +155 -0
- package/lib/components/GenAICoach/Questionnaire.js.map +1 -0
- package/lib/components/GenAICoach/ToolCandidates.d.ts +4 -0
- package/lib/components/GenAICoach/ToolCandidates.d.ts.map +1 -0
- package/lib/components/GenAICoach/ToolCandidates.js +19 -0
- package/lib/components/GenAICoach/ToolCandidates.js.map +1 -0
- package/lib/components/GenAICoach/ToolConfirmationMessage.d.ts +4 -0
- package/lib/components/GenAICoach/ToolConfirmationMessage.d.ts.map +1 -0
- package/lib/components/GenAICoach/ToolConfirmationMessage.js +20 -0
- package/lib/components/GenAICoach/ToolConfirmationMessage.js.map +1 -0
- package/lib/components/GenAICoach/ToolDetails.d.ts +5 -0
- package/lib/components/GenAICoach/ToolDetails.d.ts.map +1 -0
- package/lib/components/GenAICoach/ToolDetails.js +99 -0
- package/lib/components/GenAICoach/ToolDetails.js.map +1 -0
- package/lib/components/GenAICoach/index.d.ts +5 -3
- package/lib/components/GenAICoach/index.d.ts.map +1 -1
- package/lib/components/GenAICoach/index.js +4 -2
- package/lib/components/GenAICoach/index.js.map +1 -1
- package/lib/components/HierarchicalAssignments/Assignments.styles.d.ts +55 -34
- package/lib/components/HierarchicalAssignments/Assignments.styles.d.ts.map +1 -1
- package/lib/components/HierarchicalAssignments/Assignments.styles.js +41 -11
- package/lib/components/HierarchicalAssignments/Assignments.styles.js.map +1 -1
- package/lib/components/HierarchicalAssignments/HierarchicalAssignments.types.d.ts +2 -0
- package/lib/components/HierarchicalAssignments/HierarchicalAssignments.types.d.ts.map +1 -1
- package/lib/components/HierarchicalAssignments/HierarchicalAssignments.types.js.map +1 -1
- package/lib/components/HierarchicalAssignments/nodeItems/AssignmentItem.d.ts +1 -1
- package/lib/components/HierarchicalAssignments/nodeItems/AssignmentItem.d.ts.map +1 -1
- package/lib/components/HierarchicalAssignments/nodeItems/AssignmentItem.js +7 -4
- package/lib/components/HierarchicalAssignments/nodeItems/AssignmentItem.js.map +1 -1
- package/lib/components/HierarchicalAssignments/nodeItems/CaseDetail.d.ts.map +1 -1
- package/lib/components/HierarchicalAssignments/nodeItems/CaseDetail.js +2 -2
- package/lib/components/HierarchicalAssignments/nodeItems/CaseDetail.js.map +1 -1
- package/lib/components/IntelligentGuidance/IntelligentGuidance.d.ts.map +1 -1
- package/lib/components/IntelligentGuidance/IntelligentGuidance.js +1 -1
- package/lib/components/IntelligentGuidance/IntelligentGuidance.js.map +1 -1
- package/lib/components/IntelligentGuidance/IntelligentGuidance.styles.d.ts +9 -5
- package/lib/components/IntelligentGuidance/IntelligentGuidance.styles.d.ts.map +1 -1
- package/lib/components/IntelligentGuidance/IntelligentGuidance.styles.js +17 -3
- package/lib/components/IntelligentGuidance/IntelligentGuidance.styles.js.map +1 -1
- package/lib/components/InteractionNotification/InteractionNotification.d.ts +31 -8
- package/lib/components/InteractionNotification/InteractionNotification.d.ts.map +1 -1
- package/lib/components/InteractionNotification/InteractionNotification.js +17 -10
- package/lib/components/InteractionNotification/InteractionNotification.js.map +1 -1
- package/lib/components/Predictions/Predictions.d.ts.map +1 -1
- package/lib/components/Predictions/Predictions.js +11 -2
- package/lib/components/Predictions/Predictions.js.map +1 -1
- package/lib/components/SearchResults/ActiveFilter.d.ts +1 -1
- package/lib/components/SearchResults/ActiveFilter.d.ts.map +1 -1
- package/lib/components/SearchResults/Filter.d.ts.map +1 -1
- package/lib/components/SearchResults/Filter.js +1 -1
- package/lib/components/SearchResults/Filter.js.map +1 -1
- package/lib/components/SearchResults/SearchResult.d.ts.map +1 -1
- package/lib/components/SearchResults/SearchResult.js +14 -6
- package/lib/components/SearchResults/SearchResult.js.map +1 -1
- package/lib/components/SearchResults/SearchResults.d.ts.map +1 -1
- package/lib/components/SearchResults/SearchResults.js +18 -3
- package/lib/components/SearchResults/SearchResults.js.map +1 -1
- package/lib/components/SearchResults/SearchResults.styles.d.ts +12 -10
- package/lib/components/SearchResults/SearchResults.styles.d.ts.map +1 -1
- package/lib/components/Shortcuts/Shortcuts.d.ts +7 -0
- package/lib/components/Shortcuts/Shortcuts.d.ts.map +1 -0
- package/lib/components/Shortcuts/Shortcuts.js +47 -0
- package/lib/components/Shortcuts/Shortcuts.js.map +1 -0
- package/lib/components/Shortcuts/Shortcuts.styles.d.ts +22 -0
- package/lib/components/Shortcuts/Shortcuts.styles.d.ts.map +1 -0
- package/lib/components/Shortcuts/Shortcuts.styles.js +114 -0
- package/lib/components/Shortcuts/Shortcuts.styles.js.map +1 -0
- package/lib/components/Shortcuts/Shortcuts.test-ids.d.ts +2 -0
- package/lib/components/Shortcuts/Shortcuts.test-ids.d.ts.map +1 -0
- package/lib/components/Shortcuts/Shortcuts.test-ids.js +8 -0
- package/lib/components/Shortcuts/Shortcuts.test-ids.js.map +1 -0
- package/lib/components/Shortcuts/Shortcuts.types.d.ts +64 -0
- package/lib/components/Shortcuts/Shortcuts.types.d.ts.map +1 -0
- package/lib/components/Shortcuts/Shortcuts.types.js +2 -0
- package/lib/components/Shortcuts/Shortcuts.types.js.map +1 -0
- package/lib/components/Shortcuts/index.d.ts +3 -0
- package/lib/components/Shortcuts/index.d.ts.map +1 -0
- package/lib/components/Shortcuts/index.js +2 -0
- package/lib/components/Shortcuts/index.js.map +1 -0
- package/lib/components/Stages/Stages.d.ts.map +1 -1
- package/lib/components/Stages/Stages.js +37 -12
- package/lib/components/Stages/Stages.js.map +1 -1
- package/lib/components/Stages/Stages.styles.d.ts +22 -15
- package/lib/components/Stages/Stages.styles.d.ts.map +1 -1
- package/lib/components/Stages/Stages.styles.js +285 -119
- package/lib/components/Stages/Stages.styles.js.map +1 -1
- package/lib/components/Stages/Stages.types.d.ts +5 -0
- package/lib/components/Stages/Stages.types.d.ts.map +1 -1
- package/lib/components/Stages/Stages.types.js.map +1 -1
- package/lib/components/Stakeholders/Stakeholders.d.ts.map +1 -1
- package/lib/components/Stakeholders/Stakeholders.js +109 -145
- package/lib/components/Stakeholders/Stakeholders.js.map +1 -1
- package/lib/components/Tags/Tags.d.ts +2 -2
- package/lib/components/Tags/Tags.d.ts.map +1 -1
- package/lib/components/Tags/Tags.js +12 -2
- package/lib/components/Tags/Tags.js.map +1 -1
- package/lib/components/Tasks/TaskList.d.ts +10 -3
- package/lib/components/Tasks/TaskList.d.ts.map +1 -1
- package/lib/components/Tasks/TaskList.js +59 -5
- package/lib/components/Tasks/TaskList.js.map +1 -1
- package/lib/components/Tasks/Tasks.d.ts +10 -3
- package/lib/components/Tasks/Tasks.d.ts.map +1 -1
- package/lib/components/Tasks/Tasks.js +29 -5
- package/lib/components/Tasks/Tasks.js.map +1 -1
- package/lib/components/UtilitiesLayout/UtilitiesLayout.d.ts.map +1 -1
- package/lib/components/UtilitiesLayout/UtilitiesLayout.js +3 -2
- package/lib/components/UtilitiesLayout/UtilitiesLayout.js.map +1 -1
- package/lib/components/UtilitiesLayout/UtilitiesLayout.styles.d.ts +2 -2
- package/lib/components/UtilitiesLayout/UtilitiesLayout.styles.d.ts.map +1 -1
- package/lib/components/UtilitiesLayout/UtilitiesLayout.styles.js +3 -2
- package/lib/components/UtilitiesLayout/UtilitiesLayout.styles.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/package.json +6 -7
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { type ForwardRefForwardPropsComponent } from '@pega/cosmos-react-core';
|
|
2
2
|
import type { GenAIMessageProps } from './GenAICoach.types';
|
|
3
|
+
type StreamingContextProps = {
|
|
4
|
+
isStreamingMessage?: boolean;
|
|
5
|
+
isStreamingInProgress?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/** Metadata Context */
|
|
8
|
+
export declare const StreamingContext: import("react").Context<StreamingContextProps | undefined>;
|
|
3
9
|
declare const GenAIMessage: ForwardRefForwardPropsComponent<GenAIMessageProps>;
|
|
4
10
|
export default GenAIMessage;
|
|
5
11
|
//# sourceMappingURL=GenAIMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenAIMessage.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessage.tsx"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"GenAIMessage.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessage.tsx"],"names":[],"mappings":"AAGA,OAAO,EASL,KAAK,+BAA+B,EAIrC,MAAM,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAA4B,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAmBtF,KAAK,qBAAqB,GAAG;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,uBAAuB;AACvB,eAAO,MAAM,gBAAgB,4DAE3B,CAAC;AAwBH,QAAA,MAAM,YAAY,EAAE,+BAA+B,CAAC,iBAAiB,CAgTpE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,52 +1,97 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useEffect,
|
|
3
|
-
import { Button, Flex,
|
|
2
|
+
import { createContext, forwardRef, useEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import { Button, Flex, Progress, registerIcon, useI18n, useTestIds, ErrorState, markdownToPlainText, Actions, Icon, useModalManager } from '@pega/cosmos-react-core';
|
|
4
4
|
import * as polarisSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/polaris-solid.icon';
|
|
5
|
-
import * as
|
|
6
|
-
import * as thumbsUpIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up.icon';
|
|
7
|
-
import * as thumbsDownSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down-solid.icon';
|
|
8
|
-
import * as thumbsDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down.icon';
|
|
5
|
+
import * as brainIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/brain.icon';
|
|
9
6
|
import { RichTextViewer } from '@pega/cosmos-react-rte';
|
|
10
7
|
import { useAnimatedText } from '@pega/cosmos-react-core';
|
|
11
|
-
import { StyledAttachmentsList, StyledMessage, StyledSuggestion, StyledSuggestionsContainer, StyledUserMessage } from './GenAICoach.styles';
|
|
8
|
+
import { StyledActionsContainer, StyledAttachmentsList, StyledMessage, StyledSuggestion, StyledSuggestionsContainer, StyledSystemMessage, StyledUserMessage } from './GenAICoach.styles';
|
|
12
9
|
import { getGenAICoachTestIds } from './GenAICoach.test-ids';
|
|
13
10
|
import { isCoachMessage, isUserMessage } from './GenAICoach.utils';
|
|
14
11
|
import GenAIMessageProgress from './GenAIMessageProgress';
|
|
15
|
-
|
|
12
|
+
import ToolConfirmationMessage from './ToolConfirmationMessage';
|
|
13
|
+
import GenAIMessageFeedbackButtons from './GenAIMessageFeedback';
|
|
14
|
+
import ToolCandidates from './ToolCandidates';
|
|
15
|
+
registerIcon(polarisSolidIcon, brainIcon);
|
|
16
|
+
/** Metadata Context */
|
|
17
|
+
export const StreamingContext = createContext({
|
|
18
|
+
isStreamingMessage: false
|
|
19
|
+
});
|
|
20
|
+
const LoadingContent = ({ message, markdownMap, progressSteps, progressStepsCompleted }) => {
|
|
21
|
+
if (!progressSteps?.length) {
|
|
22
|
+
return _jsx(GenAIMessageProgress, { messages: message ? [message] : undefined });
|
|
23
|
+
}
|
|
24
|
+
if (message) {
|
|
25
|
+
return (_jsxs(_Fragment, { children: [_jsx(RichTextViewer, { content: message, type: 'markdown', markdownMap: markdownMap }), _jsx(Progress, { variant: 'ellipsis', placement: 'inline' })] }));
|
|
26
|
+
}
|
|
27
|
+
return _jsx(GenAIMessageProgress, { messages: progressSteps, completedSteps: progressStepsCompleted });
|
|
28
|
+
};
|
|
16
29
|
const GenAIMessage = forwardRef(function GenAIMessage(props, ref) {
|
|
17
30
|
const testIds = useTestIds(props.testId, getGenAICoachTestIds);
|
|
18
|
-
const theme = useTheme();
|
|
19
31
|
const t = useI18n();
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const [showDialog, setShowDialog] = useState(false);
|
|
23
|
-
const focusOnInteractionRef = useRef(false);
|
|
32
|
+
const { create } = useModalManager();
|
|
33
|
+
const modalMethodsRef = useRef(null);
|
|
24
34
|
const { message, announceInteraction, ...restProps } = props;
|
|
25
|
-
const
|
|
35
|
+
const isStringMessage = typeof message === 'string';
|
|
36
|
+
const rawPlainTextMessage = isStringMessage ? markdownToPlainText(message ?? '') : '';
|
|
37
|
+
let fallbackAriaLabel = '';
|
|
38
|
+
if (isCoachMessage(props)) {
|
|
39
|
+
fallbackAriaLabel = t('agent_message');
|
|
40
|
+
}
|
|
41
|
+
else if (isUserMessage(props)) {
|
|
42
|
+
fallbackAriaLabel = t('user_message');
|
|
43
|
+
}
|
|
44
|
+
const plainTextMessage = rawPlainTextMessage || fallbackAriaLabel;
|
|
26
45
|
let ariaLabel = plainTextMessage;
|
|
46
|
+
const toolCandidates = isCoachMessage(props) ? props.toolCandidates : undefined;
|
|
27
47
|
const isStreamingMessage = isCoachMessage(props) && props.enableStreaming;
|
|
28
48
|
const allChunksReceived = isCoachMessage(props) && props.allChunksReceived;
|
|
29
49
|
const enableStreaming = !!isStreamingMessage && !allChunksReceived;
|
|
30
|
-
const { text: streamingMessage, isAnimationDone: isStreamingDone } = useAnimatedText({
|
|
31
|
-
text: message
|
|
50
|
+
const { text: streamingMessage, isAnimationDone: isStreamingDone, animatedTillCursor } = useAnimatedText({
|
|
51
|
+
text: isStringMessage ? message : '',
|
|
32
52
|
allContentReceived: allChunksReceived === undefined ? true : allChunksReceived,
|
|
33
|
-
enabled: enableStreaming,
|
|
34
|
-
tokenizeMarkdown: true
|
|
53
|
+
enabled: isStringMessage && enableStreaming,
|
|
54
|
+
tokenizeMarkdown: true,
|
|
55
|
+
cursorStartIndex: isCoachMessage(props) && props.animationInitialCursorPos
|
|
56
|
+
? props.animationInitialCursorPos
|
|
57
|
+
: undefined
|
|
35
58
|
});
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (isCoachMessage(props) && props.onAnimationCursorUpdate) {
|
|
61
|
+
props.onAnimationCursorUpdate(animatedTillCursor);
|
|
62
|
+
}
|
|
63
|
+
}, [animatedTillCursor]);
|
|
36
64
|
useEffect(() => {
|
|
37
65
|
if (isStreamingMessage && props.onStreamingUpdate) {
|
|
38
66
|
props.onStreamingUpdate(!!allChunksReceived && isStreamingDone);
|
|
39
67
|
}
|
|
40
68
|
}, [enableStreaming, isStreamingDone, allChunksReceived]);
|
|
41
|
-
useElementFocus(wrapperEl, { shouldFocus: !showDialog && focusOnInteractionRef.current });
|
|
42
69
|
useEffect(() => {
|
|
43
|
-
if (
|
|
44
|
-
|
|
70
|
+
if (isCoachMessage(props) && toolCandidates && modalMethodsRef.current) {
|
|
71
|
+
modalMethodsRef.current.update({
|
|
72
|
+
loading: toolCandidates.toolState?.loading,
|
|
73
|
+
error: toolCandidates.toolState?.error,
|
|
74
|
+
renderCandidatesTable: toolCandidates.toolState?.renderCandidatesTable
|
|
75
|
+
});
|
|
45
76
|
}
|
|
46
|
-
}, [
|
|
77
|
+
}, [toolCandidates]);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
return () => {
|
|
80
|
+
const modalMethods = modalMethodsRef.current;
|
|
81
|
+
if (!modalMethods) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
modalMethods.dismiss();
|
|
85
|
+
modalMethods.unmount();
|
|
86
|
+
};
|
|
87
|
+
}, []);
|
|
88
|
+
const streamingContext = useMemo(() => {
|
|
89
|
+
return { isStreamingMessage, isStreamingInProgress: isCoachMessage(props) && props.loading };
|
|
90
|
+
}, [isStreamingMessage, props]);
|
|
47
91
|
if (isCoachMessage(props)) {
|
|
48
|
-
const { id: messageId, coachName, suggestions, onSend, loading, error, feedback } = props;
|
|
49
|
-
const { reaction
|
|
92
|
+
const { id: messageId, coachName, suggestions, onSend, loading, error, feedback, markdownMap, messageActions } = props;
|
|
93
|
+
const { reaction } = feedback ?? {};
|
|
94
|
+
const { toolState, onViewToolsConsidered } = toolCandidates ?? {};
|
|
50
95
|
let selectedFeedbackResponse;
|
|
51
96
|
let feedbackAriaLabel = t('sender_replied_message', [coachName, plainTextMessage ?? '']);
|
|
52
97
|
if (feedback && reaction) {
|
|
@@ -59,35 +104,32 @@ const GenAIMessage = forwardRef(function GenAIMessage(props, ref) {
|
|
|
59
104
|
suggestions && suggestions.length > 0
|
|
60
105
|
? `${feedbackAriaLabel} ${t('suggestions_in_message', [suggestions.length])}`
|
|
61
106
|
: feedbackAriaLabel;
|
|
62
|
-
|
|
107
|
+
const hasInteractiveContent = !!(suggestions?.length ||
|
|
108
|
+
feedback ||
|
|
109
|
+
messageActions ||
|
|
110
|
+
toolState?.renderCandidatesTable);
|
|
111
|
+
if (announceInteraction && hasInteractiveContent) {
|
|
63
112
|
ariaLabel = `${ariaLabel} ${t('interaction_message')}`;
|
|
64
113
|
}
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
focusOnInteractionRef.current = true;
|
|
85
|
-
}, children: _jsx(Icon, { name: 'thumbs-up' }) }), _jsx(Button, { label: t('bad_response'), variant: 'simple', icon: true, compact: true, onClick: () => {
|
|
86
|
-
setShowDialog(true);
|
|
87
|
-
onReaction?.(messageId, 'disliked');
|
|
88
|
-
}, children: _jsx(Icon, { name: 'thumbs-down' }) })] })) })), suggestions && (_jsx(Flex, { as: StyledSuggestionsContainer, container: { direction: 'column', gap: 1 }, children: suggestions.map(({ id, message: prompt }) => {
|
|
89
|
-
return (_jsx(Button, { as: StyledSuggestion, onClick: onSend ? () => onSend({ id, message: prompt }) : undefined, children: prompt }, id));
|
|
90
|
-
}) }))] }))] })] }));
|
|
114
|
+
const onClickToolsConsidered = () => {
|
|
115
|
+
modalMethodsRef.current = create(ToolCandidates, {
|
|
116
|
+
loading: toolState?.loading,
|
|
117
|
+
error: toolState?.error,
|
|
118
|
+
renderCandidatesTable: toolState?.renderCandidatesTable
|
|
119
|
+
});
|
|
120
|
+
onViewToolsConsidered?.(messageId);
|
|
121
|
+
};
|
|
122
|
+
const streamingContent = isStreamingMessage && (_jsx(_Fragment, { children: message ? (_jsxs(_Fragment, { children: [_jsx(StreamingContext.Provider, { value: streamingContext, children: isStringMessage ? (_jsx(RichTextViewer, { content: isStreamingMessage ? streamingMessage : message, type: 'markdown', markdownMap: markdownMap })) : (message) }), loading && _jsx(Progress, { variant: 'ellipsis', placement: 'inline' })] })) : ((loading || props.progressSteps?.length) && (_jsx(GenAIMessageProgress, { messages: props.progressSteps?.length ? props.progressSteps : undefined, completedSteps: props.progressSteps?.length ? props.progressStepsCompleted : undefined }))) }));
|
|
123
|
+
return (_jsx(Flex, { as: 'li', "data-testid": testIds.coachMessage, ...restProps, container: { direction: 'row', pad: [1, 0], gap: 1 }, type: 'message', "aria-label": ariaLabel, ref: ref, children: _jsxs(StyledMessage, { children: [streamingContent, loading || error ? (_jsxs(_Fragment, { children: [loading && !isStreamingMessage && (_jsx(LoadingContent, { message: isStringMessage ? message : undefined, markdownMap: markdownMap, progressSteps: props.progressSteps, progressStepsCompleted: props.progressStepsCompleted })), error && _jsx(ErrorState, { message: error })] })) : (_jsxs(_Fragment, { children: [!isStreamingMessage &&
|
|
124
|
+
message &&
|
|
125
|
+
(isStringMessage ? (_jsx(RichTextViewer, { content: message, type: 'markdown', markdownMap: markdownMap })) : (message)), props.isToolConfirmation && _jsx(ToolConfirmationMessage, { ...props }), (feedback || messageActions || onViewToolsConsidered) && (_jsxs(Flex, { container: {
|
|
126
|
+
direction: 'row',
|
|
127
|
+
gap: 1,
|
|
128
|
+
pad: [1, undefined],
|
|
129
|
+
alignItems: 'center'
|
|
130
|
+
}, as: StyledActionsContainer, children: [feedback && (_jsx(GenAIMessageFeedbackButtons, { messageId: messageId, feedback: feedback })), onViewToolsConsidered && (_jsx(Button, { label: t('semantic_discovery_results'), variant: 'simple', icon: true, compact: true, onClick: onClickToolsConsidered, children: _jsx(Icon, { name: 'brain' }) })), messageActions && _jsx(Actions, { ...messageActions })] })), suggestions && suggestions.length > 0 && (_jsx(Flex, { as: StyledSuggestionsContainer, container: { gap: 1, justify: 'end', wrap: 'wrap' }, children: suggestions.map(({ id, message: prompt }) => {
|
|
131
|
+
return (_jsx(Button, { as: StyledSuggestion, onClick: onSend ? () => onSend({ id, message: prompt }) : undefined, children: prompt }, id));
|
|
132
|
+
}) }))] }))] }) }));
|
|
91
133
|
}
|
|
92
134
|
if (isUserMessage(props)) {
|
|
93
135
|
if (plainTextMessage) {
|
|
@@ -96,7 +138,14 @@ const GenAIMessage = forwardRef(function GenAIMessage(props, ref) {
|
|
|
96
138
|
if (announceInteraction) {
|
|
97
139
|
ariaLabel = `${ariaLabel} ${t('interaction_message')}`;
|
|
98
140
|
}
|
|
99
|
-
return (_jsxs(StyledUserMessage, { as: StyledUserMessage, "data-testid": testIds.userMessage, ...restProps,
|
|
141
|
+
return (_jsxs(StyledUserMessage, { as: StyledUserMessage, "data-testid": testIds.userMessage, ...restProps,
|
|
142
|
+
// @ts-expect-error FIXME: Need to validate if we can remove message, and double 'as'
|
|
143
|
+
type: 'message', "aria-label": ariaLabel, ref: ref, children: [props.attachments && props.attachments.length > 0 && (_jsx(StyledAttachmentsList, { type: 'display', items: props.attachments })), props.message && _jsx(RichTextViewer, { content: props.message, type: 'markdown' })] }));
|
|
144
|
+
}
|
|
145
|
+
if (props.from === 'system') {
|
|
146
|
+
const displayMessage = props.stopped && !message ? t('generation_stopped') : message;
|
|
147
|
+
const systemAriaLabel = typeof displayMessage === 'string' ? displayMessage : ariaLabel;
|
|
148
|
+
return (_jsx(StyledSystemMessage, { stopped: props.stopped, "data-testid": testIds.userMessage, "aria-label": systemAriaLabel, ref: ref, children: displayMessage }));
|
|
100
149
|
}
|
|
101
150
|
return null;
|
|
102
151
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenAIMessage.js","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGhE,OAAO,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,EACP,QAAQ,EACR,UAAU,EACV,eAAe,EACf,mBAAmB,EAEpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,gBAAgB,MAAM,sEAAsE,CAAC;AACzG,OAAO,KAAK,iBAAiB,MAAM,wEAAwE,CAAC;AAC5G,OAAO,KAAK,YAAY,MAAM,kEAAkE,CAAC;AACjG,OAAO,KAAK,mBAAmB,MAAM,0EAA0E,CAAC;AAChH,OAAO,KAAK,cAAc,MAAM,oEAAoE,CAAC;AACrG,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,EACl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,CAAC;QAED,IAAI,mBAAmB,EAAE,CAAC;YACxB,SAAS,GAAG,GAAG,SAAS,IAAI,CAAC,CAAC,qBAAqB,CAAC,EAAE,CAAC;QACzD,CAAC;QAED,OAAO,CACL,MAAC,iBAAiB,IAChB,EAAE,EAAE,iBAAiB,iBACR,OAAO,CAAC,WAAW,KAC5B,SAAS,EACb,IAAI,EAAC,SAAS,gBACF,SAAS,EACrB,GAAG,EAAE,GAAG,aAEP,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,CACpD,KAAC,qBAAqB,IAAC,IAAI,EAAC,SAAS,EAAC,KAAK,EAAE,KAAK,CAAC,WAAW,GAAI,CACnE,EACA,OAAO,IAAI,KAAC,cAAc,IAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,UAAU,GAAG,IAC9C,CACrB,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { forwardRef, useEffect, useRef, useState } from 'react';\nimport type { KeyboardEvent, PropsWithoutRef } from 'react';\n\nimport {\n Button,\n Flex,\n Icon,\n Progress,\n registerIcon,\n useI18n,\n useTheme,\n Text,\n useTestIds,\n ErrorState,\n useElement,\n Tooltip,\n TextArea,\n FormDialog,\n useElementFocus,\n markdownToPlainText,\n type ForwardRefForwardPropsComponent\n} from '@pega/cosmos-react-core';\nimport * as polarisSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/polaris-solid.icon';\nimport * as thumbsUpSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up-solid.icon';\nimport * as thumbsUpIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up.icon';\nimport * as thumbsDownSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down-solid.icon';\nimport * as thumbsDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down.icon';\nimport { RichTextViewer } from '@pega/cosmos-react-rte';\nimport { useAnimatedText } from '@pega/cosmos-react-core';\n\nimport type { GenAIMessageProps } from './GenAICoach.types';\nimport {\n StyledAttachmentsList,\n StyledMessage,\n StyledSuggestion,\n StyledSuggestionsContainer,\n StyledUserMessage\n} from './GenAICoach.styles';\nimport { getGenAICoachTestIds } from './GenAICoach.test-ids';\nimport { isCoachMessage, isUserMessage } from './GenAICoach.utils';\nimport GenAIMessageProgress from './GenAIMessageProgress';\n\nregisterIcon(\n polarisSolidIcon,\n thumbsUpSolidIcon,\n thumbsUpIcon,\n thumbsDownSolidIcon,\n thumbsDownIcon\n);\n\nconst GenAIMessage: ForwardRefForwardPropsComponent<GenAIMessageProps> = forwardRef(\n function GenAIMessage(props: PropsWithoutRef<GenAIMessageProps>, ref: GenAIMessageProps['ref']) {\n const testIds = useTestIds(props.testId, getGenAICoachTestIds);\n const theme = useTheme();\n const t = useI18n();\n const [wrapperEl, setWrapperEl] = useElement<HTMLDivElement>(null);\n const [feedbackVal, setFeedbackVal] = useState('');\n const [showDialog, setShowDialog] = useState(false);\n const focusOnInteractionRef = useRef(false);\n\n const { message, announceInteraction, ...restProps } = props;\n const plainTextMessage = markdownToPlainText(message ?? '');\n let ariaLabel = plainTextMessage;\n\n const isStreamingMessage = isCoachMessage(props) && props.enableStreaming;\n const allChunksReceived = isCoachMessage(props) && props.allChunksReceived;\n const enableStreaming = !!isStreamingMessage && !allChunksReceived;\n\n const { text: streamingMessage, isAnimationDone: isStreamingDone } = useAnimatedText({\n text: message ?? '',\n allContentReceived: allChunksReceived === undefined ? true : allChunksReceived,\n enabled: enableStreaming,\n tokenizeMarkdown: true\n });\n\n useEffect(() => {\n if (isStreamingMessage && props.onStreamingUpdate) {\n props.onStreamingUpdate(!!allChunksReceived && isStreamingDone);\n }\n }, [enableStreaming, isStreamingDone, allChunksReceived]);\n\n useElementFocus(wrapperEl, { shouldFocus: !showDialog && focusOnInteractionRef.current });\n\n useEffect(() => {\n if (!showDialog && focusOnInteractionRef.current) {\n focusOnInteractionRef.current = false;\n }\n }, [showDialog]);\n\n if (isCoachMessage(props)) {\n const { id: messageId, coachName, suggestions, onSend, loading, error, feedback } = props;\n\n const { reaction, onReaction, onFeedbackComplete } = feedback ?? {};\n\n let selectedFeedbackResponse;\n\n let feedbackAriaLabel = t('sender_replied_message', [coachName, plainTextMessage ?? '']);\n\n if (feedback && reaction) {\n selectedFeedbackResponse = t('selected_noun', [\n reaction === 'liked' ? t('good_response') : t('bad_response')\n ]);\n\n feedbackAriaLabel = `${feedbackAriaLabel} ${selectedFeedbackResponse}`;\n }\n\n ariaLabel =\n suggestions && suggestions.length > 0\n ? `${feedbackAriaLabel} ${t('suggestions_in_message', [suggestions.length])}`\n : feedbackAriaLabel;\n\n if (announceInteraction) {\n ariaLabel = `${ariaLabel} ${t('interaction_message')}`;\n }\n\n const streamingContent = isStreamingMessage && (\n <>\n {message ? (\n <>\n <RichTextViewer\n content={isStreamingMessage ? streamingMessage : message}\n type='markdown'\n />\n {loading && <Progress variant='ellipsis' placement='inline' />}\n </>\n ) : (\n loading && <GenAIMessageProgress />\n )}\n </>\n );\n\n return (\n <Flex\n as='li'\n data-testid={testIds.coachMessage}\n {...restProps}\n container={{ direction: 'column', pad: [1, 0] }}\n type='message'\n aria-label={ariaLabel}\n ref={ref}\n >\n <Flex container={{ gap: 1 }}>\n <Icon name='polaris-solid' color={theme.base.palette.ai} size='s' />\n <Text as='span' variant='h4'>\n {coachName}\n </Text>\n </Flex>\n <StyledMessage>\n {/* Streaming loader and content */}\n {streamingContent}\n {loading || error ? (\n <>\n {loading && !isStreamingMessage && <GenAIMessageProgress />}\n {error && <ErrorState message={error} />}\n </>\n ) : (\n <>\n {/* Non streaming content */}\n {!isStreamingMessage && message && (\n <RichTextViewer content={message} type='markdown' />\n )}\n {feedback && (\n <Flex container={{ pad: [0.5, undefined] }}>\n {reaction ? (\n <>\n <Flex\n container={{ pad: 0.5 }}\n aria-label={selectedFeedbackResponse}\n ref={setWrapperEl}\n tabIndex={-1}\n >\n <Icon\n name={reaction === 'liked' ? 'thumbs-up-solid' : 'thumbs-down-solid'}\n />\n </Flex>\n {showDialog ? (\n onFeedbackComplete &&\n wrapperEl && (\n <FormDialog\n target={wrapperEl}\n heading={t('share_feedback')}\n onCancel={() => {\n focusOnInteractionRef.current = true;\n setShowDialog(false);\n onFeedbackComplete(messageId);\n }}\n onSubmit={() => {\n focusOnInteractionRef.current = true;\n setShowDialog(false);\n onFeedbackComplete(messageId, feedbackVal);\n }}\n onKeyDown={e => e.stopPropagation()}\n >\n <TextArea\n value={feedbackVal}\n onChange={e => setFeedbackVal(e.target.value)}\n onKeyDown={(e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n focusOnInteractionRef.current = true;\n setShowDialog(false);\n onFeedbackComplete(messageId, feedbackVal);\n }\n }}\n autoResize={false}\n />\n </FormDialog>\n )\n ) : (\n <Tooltip target={wrapperEl} describeTarget={false}>\n {reaction === 'liked' ? t('good_response') : t('bad_response')}\n </Tooltip>\n )}\n </>\n ) : (\n <>\n <Button\n label={t('good_response')}\n variant='simple'\n icon\n compact\n onClick={() => {\n onReaction?.(messageId, 'liked');\n focusOnInteractionRef.current = true;\n }}\n >\n <Icon name='thumbs-up' />\n </Button>\n\n <Button\n label={t('bad_response')}\n variant='simple'\n icon\n compact\n onClick={() => {\n setShowDialog(true);\n onReaction?.(messageId, 'disliked');\n }}\n >\n <Icon name='thumbs-down' />\n </Button>\n </>\n )}\n </Flex>\n )}\n {suggestions && (\n <Flex as={StyledSuggestionsContainer} container={{ direction: 'column', gap: 1 }}>\n {suggestions.map(({ id, message: prompt }) => {\n return (\n <Button\n as={StyledSuggestion}\n onClick={onSend ? () => onSend({ id, message: prompt }) : undefined}\n key={id}\n >\n {prompt}\n </Button>\n );\n })}\n </Flex>\n )}\n </>\n )}\n </StyledMessage>\n </Flex>\n );\n }\n\n if (isUserMessage(props)) {\n if (plainTextMessage) {\n ariaLabel = t('you_asked', [plainTextMessage]);\n }\n\n if (announceInteraction) {\n ariaLabel = `${ariaLabel} ${t('interaction_message')}`;\n }\n\n return (\n <StyledUserMessage\n as={StyledUserMessage}\n data-testid={testIds.userMessage}\n {...restProps}\n type='message'\n aria-label={ariaLabel}\n ref={ref}\n >\n {props.attachments && props.attachments.length > 0 && (\n <StyledAttachmentsList type='display' items={props.attachments} />\n )}\n {message && <RichTextViewer content={message} type='markdown' />}\n </StyledUserMessage>\n );\n }\n\n return null;\n }\n);\n\nexport default GenAIMessage;\n"]}
|
|
1
|
+
{"version":3,"file":"GenAIMessage.js","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG9E,OAAO,EACL,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,UAAU,EACV,UAAU,EACV,mBAAmB,EAEnB,OAAO,EACP,IAAI,EACJ,eAAe,EAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,gBAAgB,MAAM,sEAAsE,CAAC;AACzG,OAAO,KAAK,SAAS,MAAM,8DAA8D,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,gBAAgB,EAChB,0BAA0B,EAC1B,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAC1D,OAAO,uBAAuB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sourcesContent":["import { createContext, forwardRef, useEffect, useMemo, useRef } from 'react';\nimport type { PropsWithoutRef } from 'react';\n\nimport {\n Button,\n Flex,\n Progress,\n registerIcon,\n useI18n,\n useTestIds,\n ErrorState,\n markdownToPlainText,\n type ForwardRefForwardPropsComponent,\n Actions,\n Icon,\n useModalManager\n} from '@pega/cosmos-react-core';\nimport * as polarisSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/polaris-solid.icon';\nimport * as brainIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/brain.icon';\nimport { RichTextViewer } from '@pega/cosmos-react-rte';\nimport { useAnimatedText } from '@pega/cosmos-react-core';\n\nimport type { CoachLoadingContentProps, GenAIMessageProps } from './GenAICoach.types';\nimport {\n StyledActionsContainer,\n StyledAttachmentsList,\n StyledMessage,\n StyledSuggestion,\n StyledSuggestionsContainer,\n StyledSystemMessage,\n StyledUserMessage\n} from './GenAICoach.styles';\nimport { getGenAICoachTestIds } from './GenAICoach.test-ids';\nimport { isCoachMessage, isUserMessage } from './GenAICoach.utils';\nimport GenAIMessageProgress from './GenAIMessageProgress';\nimport ToolConfirmationMessage from './ToolConfirmationMessage';\nimport GenAIMessageFeedbackButtons from './GenAIMessageFeedback';\nimport ToolCandidates from './ToolCandidates';\n\nregisterIcon(polarisSolidIcon, brainIcon);\n\ntype StreamingContextProps = {\n isStreamingMessage?: boolean;\n isStreamingInProgress?: boolean;\n};\n\n/** Metadata Context */\nexport const StreamingContext = createContext<StreamingContextProps | undefined>({\n isStreamingMessage: false\n});\n\nconst LoadingContent = ({\n message,\n markdownMap,\n progressSteps,\n progressStepsCompleted\n}: CoachLoadingContentProps) => {\n if (!progressSteps?.length) {\n return <GenAIMessageProgress messages={message ? [message] : undefined} />;\n }\n\n if (message) {\n return (\n <>\n <RichTextViewer content={message} type='markdown' markdownMap={markdownMap} />\n <Progress variant='ellipsis' placement='inline' />\n </>\n );\n }\n\n return <GenAIMessageProgress messages={progressSteps} completedSteps={progressStepsCompleted} />;\n};\n\nconst GenAIMessage: ForwardRefForwardPropsComponent<GenAIMessageProps> = forwardRef(\n function GenAIMessage(props: PropsWithoutRef<GenAIMessageProps>, ref: GenAIMessageProps['ref']) {\n const testIds = useTestIds(props.testId, getGenAICoachTestIds);\n const t = useI18n();\n const { create } = useModalManager();\n\n const modalMethodsRef = useRef<ReturnType<typeof create> | null>(null);\n\n const { message, announceInteraction, ...restProps } = props;\n const isStringMessage = typeof message === 'string';\n const rawPlainTextMessage = isStringMessage ? markdownToPlainText(message ?? '') : '';\n\n let fallbackAriaLabel = '';\n if (isCoachMessage(props)) {\n fallbackAriaLabel = t('agent_message');\n } else if (isUserMessage(props)) {\n fallbackAriaLabel = t('user_message');\n }\n const plainTextMessage = rawPlainTextMessage || fallbackAriaLabel;\n let ariaLabel = plainTextMessage;\n\n const toolCandidates = isCoachMessage(props) ? props.toolCandidates : undefined;\n\n const isStreamingMessage = isCoachMessage(props) && props.enableStreaming;\n const allChunksReceived = isCoachMessage(props) && props.allChunksReceived;\n const enableStreaming = !!isStreamingMessage && !allChunksReceived;\n\n const {\n text: streamingMessage,\n isAnimationDone: isStreamingDone,\n animatedTillCursor\n } = useAnimatedText({\n text: isStringMessage ? message : '',\n allContentReceived: allChunksReceived === undefined ? true : allChunksReceived,\n enabled: isStringMessage && enableStreaming,\n tokenizeMarkdown: true,\n cursorStartIndex:\n isCoachMessage(props) && props.animationInitialCursorPos\n ? props.animationInitialCursorPos\n : undefined\n });\n\n useEffect(() => {\n if (isCoachMessage(props) && props.onAnimationCursorUpdate) {\n props.onAnimationCursorUpdate(animatedTillCursor);\n }\n }, [animatedTillCursor]);\n\n useEffect(() => {\n if (isStreamingMessage && props.onStreamingUpdate) {\n props.onStreamingUpdate(!!allChunksReceived && isStreamingDone);\n }\n }, [enableStreaming, isStreamingDone, allChunksReceived]);\n\n useEffect(() => {\n if (isCoachMessage(props) && toolCandidates && modalMethodsRef.current) {\n modalMethodsRef.current.update({\n loading: toolCandidates.toolState?.loading,\n error: toolCandidates.toolState?.error,\n renderCandidatesTable: toolCandidates.toolState?.renderCandidatesTable\n });\n }\n }, [toolCandidates]);\n\n useEffect(() => {\n return () => {\n const modalMethods = modalMethodsRef.current;\n\n if (!modalMethods) {\n return;\n }\n\n modalMethods.dismiss();\n modalMethods.unmount();\n };\n }, []);\n\n const streamingContext: StreamingContextProps = useMemo(() => {\n return { isStreamingMessage, isStreamingInProgress: isCoachMessage(props) && props.loading };\n }, [isStreamingMessage, props]);\n\n if (isCoachMessage(props)) {\n const {\n id: messageId,\n coachName,\n suggestions,\n onSend,\n loading,\n error,\n feedback,\n markdownMap,\n messageActions\n } = props;\n\n const { reaction } = feedback ?? {};\n const { toolState, onViewToolsConsidered } = toolCandidates ?? {};\n\n let selectedFeedbackResponse;\n\n let feedbackAriaLabel = t('sender_replied_message', [coachName, plainTextMessage ?? '']);\n\n if (feedback && reaction) {\n selectedFeedbackResponse = t('selected_noun', [\n reaction === 'liked' ? t('good_response') : t('bad_response')\n ]);\n\n feedbackAriaLabel = `${feedbackAriaLabel} ${selectedFeedbackResponse}`;\n }\n\n ariaLabel =\n suggestions && suggestions.length > 0\n ? `${feedbackAriaLabel} ${t('suggestions_in_message', [suggestions.length])}`\n : feedbackAriaLabel;\n\n const hasInteractiveContent = !!(\n suggestions?.length ||\n feedback ||\n messageActions ||\n toolState?.renderCandidatesTable\n );\n\n if (announceInteraction && hasInteractiveContent) {\n ariaLabel = `${ariaLabel} ${t('interaction_message')}`;\n }\n\n const onClickToolsConsidered = () => {\n modalMethodsRef.current = create(ToolCandidates, {\n loading: toolState?.loading,\n error: toolState?.error,\n renderCandidatesTable: toolState?.renderCandidatesTable\n });\n\n onViewToolsConsidered?.(messageId);\n };\n\n const streamingContent = isStreamingMessage && (\n <>\n {message ? (\n <>\n <StreamingContext.Provider value={streamingContext}>\n {isStringMessage ? (\n <RichTextViewer\n content={isStreamingMessage ? streamingMessage : message}\n type='markdown'\n markdownMap={markdownMap}\n />\n ) : (\n message\n )}\n </StreamingContext.Provider>\n\n {loading && <Progress variant='ellipsis' placement='inline' />}\n </>\n ) : (\n (loading || props.progressSteps?.length) && (\n <GenAIMessageProgress\n messages={props.progressSteps?.length ? props.progressSteps : undefined}\n completedSteps={\n props.progressSteps?.length ? props.progressStepsCompleted : undefined\n }\n />\n )\n )}\n </>\n );\n\n return (\n <Flex\n as='li'\n data-testid={testIds.coachMessage}\n {...restProps}\n container={{ direction: 'row', pad: [1, 0], gap: 1 }}\n type='message'\n aria-label={ariaLabel}\n ref={ref}\n >\n <StyledMessage>\n {/* Streaming loader and content */}\n {streamingContent}\n\n {loading || error ? (\n <>\n {loading && !isStreamingMessage && (\n <LoadingContent\n message={isStringMessage ? message : undefined}\n markdownMap={markdownMap}\n progressSteps={props.progressSteps}\n progressStepsCompleted={props.progressStepsCompleted}\n />\n )}\n {error && <ErrorState message={error} />}\n </>\n ) : (\n <>\n {/* Non streaming content */}\n {!isStreamingMessage &&\n message &&\n (isStringMessage ? (\n <RichTextViewer content={message} type='markdown' markdownMap={markdownMap} />\n ) : (\n message\n ))}\n\n {props.isToolConfirmation && <ToolConfirmationMessage {...props} />}\n\n {(feedback || messageActions || onViewToolsConsidered) && (\n <Flex\n container={{\n direction: 'row',\n gap: 1,\n pad: [1, undefined],\n alignItems: 'center'\n }}\n as={StyledActionsContainer}\n >\n {feedback && (\n <GenAIMessageFeedbackButtons messageId={messageId} feedback={feedback} />\n )}\n\n {onViewToolsConsidered && (\n <Button\n label={t('semantic_discovery_results')}\n variant='simple'\n icon\n compact\n onClick={onClickToolsConsidered}\n >\n <Icon name='brain' />\n </Button>\n )}\n\n {messageActions && <Actions {...messageActions} />}\n </Flex>\n )}\n\n {suggestions && suggestions.length > 0 && (\n <Flex\n as={StyledSuggestionsContainer}\n container={{ gap: 1, justify: 'end', wrap: 'wrap' }}\n >\n {suggestions.map(({ id, message: prompt }) => {\n return (\n <Button\n as={StyledSuggestion}\n onClick={onSend ? () => onSend({ id, message: prompt }) : undefined}\n key={id}\n >\n {prompt}\n </Button>\n );\n })}\n </Flex>\n )}\n </>\n )}\n </StyledMessage>\n </Flex>\n );\n }\n\n if (isUserMessage(props)) {\n if (plainTextMessage) {\n ariaLabel = t('you_asked', [plainTextMessage]);\n }\n\n if (announceInteraction) {\n ariaLabel = `${ariaLabel} ${t('interaction_message')}`;\n }\n\n return (\n <StyledUserMessage\n as={StyledUserMessage}\n data-testid={testIds.userMessage}\n {...restProps}\n // @ts-expect-error FIXME: Need to validate if we can remove message, and double 'as'\n type='message'\n aria-label={ariaLabel}\n ref={ref}\n >\n {props.attachments && props.attachments.length > 0 && (\n <StyledAttachmentsList type='display' items={props.attachments} />\n )}\n {props.message && <RichTextViewer content={props.message} type='markdown' />}\n </StyledUserMessage>\n );\n }\n\n if (props.from === 'system') {\n const displayMessage = props.stopped && !message ? t('generation_stopped') : message;\n const systemAriaLabel = typeof displayMessage === 'string' ? displayMessage : ariaLabel;\n return (\n <StyledSystemMessage\n stopped={props.stopped}\n data-testid={testIds.userMessage}\n aria-label={systemAriaLabel}\n ref={ref}\n >\n {displayMessage}\n </StyledSystemMessage>\n );\n }\n\n return null;\n }\n);\n\nexport default GenAIMessage;\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MessageFeedbackProps } from './GenAICoach.types';
|
|
2
|
+
declare const GenAIMessageFeedbackButtons: ({ messageId, feedback }: MessageFeedbackProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export default GenAIMessageFeedbackButtons;
|
|
4
|
+
//# sourceMappingURL=GenAIMessageFeedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenAIMessageFeedback.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessageFeedback.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,oBAAoB,EAAY,MAAM,oBAAoB,CAAC;AAIzE,QAAA,MAAM,2BAA2B,GAAI,yBAAyB,oBAAoB,4CAmLjF,CAAC;AAEF,eAAe,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Button, Flex, FormDialog, Icon, TextArea, Tooltip, registerIcon, useElement, useI18n } from '@pega/cosmos-react-core';
|
|
4
|
+
import * as thumbsUpSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up-solid.icon';
|
|
5
|
+
import * as thumbsUpIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up.icon';
|
|
6
|
+
import * as thumbsDownSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down-solid.icon';
|
|
7
|
+
import * as thumbsDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down.icon';
|
|
8
|
+
registerIcon(thumbsUpSolidIcon, thumbsUpIcon, thumbsDownSolidIcon, thumbsDownIcon);
|
|
9
|
+
const GenAIMessageFeedbackButtons = ({ messageId, feedback }) => {
|
|
10
|
+
const { reaction, feedbackText = '', allowFeedbackResubmission = false, promptFeedbackOn = 'disliked', onReaction, onFeedbackComplete } = feedback ?? {};
|
|
11
|
+
const t = useI18n();
|
|
12
|
+
const [feedbackVal, setFeedbackVal] = useState(feedbackText);
|
|
13
|
+
const [showDialog, setShowDialog] = useState(false);
|
|
14
|
+
const likeButtonRef = useRef(null);
|
|
15
|
+
const dislikeButtonRef = useRef(null);
|
|
16
|
+
const shouldOpenDialogRef = useRef(false);
|
|
17
|
+
const [iconEl, seticonEl] = useElement();
|
|
18
|
+
const isLikeActive = reaction === 'liked';
|
|
19
|
+
const isDislikeActive = reaction === 'disliked';
|
|
20
|
+
const needsDialog = (reactionType) => {
|
|
21
|
+
switch (promptFeedbackOn) {
|
|
22
|
+
case 'disliked':
|
|
23
|
+
return reactionType === 'disliked';
|
|
24
|
+
case 'liked':
|
|
25
|
+
return reactionType === 'liked';
|
|
26
|
+
case 'both':
|
|
27
|
+
return true;
|
|
28
|
+
default:
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const handleReactionClick = useCallback((reactionType) => {
|
|
33
|
+
if (reaction === reactionType) {
|
|
34
|
+
if (allowFeedbackResubmission) {
|
|
35
|
+
onReaction?.(messageId, undefined);
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
onReaction?.(messageId, reactionType);
|
|
40
|
+
if (needsDialog(reactionType)) {
|
|
41
|
+
if (reaction !== reactionType) {
|
|
42
|
+
setFeedbackVal('');
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
setFeedbackVal(feedbackText);
|
|
46
|
+
}
|
|
47
|
+
if (!allowFeedbackResubmission) {
|
|
48
|
+
shouldOpenDialogRef.current = true;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
setShowDialog(true);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, [reaction, feedbackText, allowFeedbackResubmission, promptFeedbackOn, messageId, onReaction]);
|
|
55
|
+
const closeDialog = useCallback((comment) => {
|
|
56
|
+
setShowDialog(false);
|
|
57
|
+
shouldOpenDialogRef.current = false;
|
|
58
|
+
onFeedbackComplete?.(messageId, comment);
|
|
59
|
+
if (!allowFeedbackResubmission && iconEl) {
|
|
60
|
+
iconEl.focus();
|
|
61
|
+
}
|
|
62
|
+
}, [allowFeedbackResubmission, onFeedbackComplete, messageId, iconEl]);
|
|
63
|
+
const getDialogTarget = () => {
|
|
64
|
+
if (!allowFeedbackResubmission && iconEl) {
|
|
65
|
+
return iconEl;
|
|
66
|
+
}
|
|
67
|
+
return isLikeActive ? likeButtonRef.current : dislikeButtonRef.current;
|
|
68
|
+
};
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (iconEl && shouldOpenDialogRef.current && !allowFeedbackResubmission) {
|
|
71
|
+
setShowDialog(true);
|
|
72
|
+
shouldOpenDialogRef.current = false;
|
|
73
|
+
}
|
|
74
|
+
}, [iconEl, allowFeedbackResubmission]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!showDialog && reaction && allowFeedbackResubmission) {
|
|
77
|
+
const reactionButton = reaction === 'liked' ? likeButtonRef.current : dislikeButtonRef.current;
|
|
78
|
+
reactionButton?.focus();
|
|
79
|
+
}
|
|
80
|
+
}, [showDialog, reaction, allowFeedbackResubmission]);
|
|
81
|
+
const dialogTarget = getDialogTarget();
|
|
82
|
+
const feedbackDialog = showDialog && dialogTarget && (_jsx(FormDialog, { target: dialogTarget, heading: t('share_feedback'), onCancel: () => closeDialog(), onSubmit: () => closeDialog(feedbackVal), onKeyDown: e => e.stopPropagation(), children: _jsx(TextArea, { value: feedbackVal, onChange: e => setFeedbackVal(e.target.value), onKeyDown: (e) => {
|
|
83
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
closeDialog(feedbackVal);
|
|
86
|
+
}
|
|
87
|
+
}, autoResize: false }) }));
|
|
88
|
+
const shouldShowIcon = !allowFeedbackResubmission && reaction;
|
|
89
|
+
if (shouldShowIcon) {
|
|
90
|
+
return (_jsxs(Flex, { container: { pad: [0.5, undefined] }, ref: seticonEl, tabIndex: -1, "aria-label": t('selected_noun', [isLikeActive ? t('good_response') : t('bad_response')]), role: 'status', children: [_jsx(Icon, { name: isLikeActive ? 'thumbs-up-solid' : 'thumbs-down-solid' }), _jsx(Tooltip, { target: iconEl, describeTarget: false, children: isLikeActive ? t('good_response') : t('bad_response') }), feedbackDialog] }));
|
|
91
|
+
}
|
|
92
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Flex, { container: { gap: 1 }, children: [_jsx(Button, { label: t('good_response'), variant: 'simple', icon: true, compact: true, ref: likeButtonRef, onClick: () => handleReactionClick('liked'), "aria-pressed": isLikeActive, children: _jsx(Icon, { name: isLikeActive ? 'thumbs-up-solid' : 'thumbs-up' }) }), _jsx(Button, { label: t('bad_response'), variant: 'simple', icon: true, compact: true, ref: dislikeButtonRef, onClick: () => handleReactionClick('disliked'), "aria-pressed": isDislikeActive, children: _jsx(Icon, { name: isDislikeActive ? 'thumbs-down-solid' : 'thumbs-down' }) })] }), feedbackDialog] }));
|
|
93
|
+
};
|
|
94
|
+
export default GenAIMessageFeedbackButtons;
|
|
95
|
+
//# sourceMappingURL=GenAIMessageFeedback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenAIMessageFeedback.js","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessageFeedback.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjE,OAAO,EACL,MAAM,EACN,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,UAAU,EACV,OAAO,EACR,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,iBAAiB,MAAM,wEAAwE,CAAC;AAC5G,OAAO,KAAK,YAAY,MAAM,kEAAkE,CAAC;AACjG,OAAO,KAAK,mBAAmB,MAAM,0EAA0E,CAAC;AAChH,OAAO,KAAK,cAAc,MAAM,oEAAoE,CAAC;AAIrG,YAAY,CAAC,iBAAiB,EAAE,YAAY,EAAE,mBAAmB,EAAE,cAAc,CAAC,CAAC;AAEnF,MAAM,2BAA2B,GAAG,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAwB,EAAE,EAAE;IACpF,MAAM,EACJ,QAAQ,EACR,YAAY,GAAG,EAAE,EACjB,yBAAyB,GAAG,KAAK,EACjC,gBAAgB,GAAG,UAAU,EAC7B,UAAU,EACV,kBAAkB,EACnB,GAAG,QAAQ,IAAI,EAAE,CAAC;IAEnB,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,C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GAC9D,IACJ,EAEN,cAAc,IACd,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,2BAA2B,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport type { KeyboardEvent } from 'react';\n\nimport {\n Button,\n Flex,\n FormDialog,\n Icon,\n TextArea,\n Tooltip,\n registerIcon,\n useElement,\n useI18n\n} from '@pega/cosmos-react-core';\nimport * as thumbsUpSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up-solid.icon';\nimport * as thumbsUpIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up.icon';\nimport * as thumbsDownSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down-solid.icon';\nimport * as thumbsDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down.icon';\n\nimport type { MessageFeedbackProps, Reaction } from './GenAICoach.types';\n\nregisterIcon(thumbsUpSolidIcon, thumbsUpIcon, thumbsDownSolidIcon, thumbsDownIcon);\n\nconst GenAIMessageFeedbackButtons = ({ messageId, feedback }: MessageFeedbackProps) => {\n const {\n reaction,\n feedbackText = '',\n allowFeedbackResubmission = false,\n promptFeedbackOn = 'disliked',\n onReaction,\n onFeedbackComplete\n } = feedback ?? {};\n\n const t = useI18n();\n\n const [feedbackVal, setFeedbackVal] = useState(feedbackText);\n const [showDialog, setShowDialog] = useState(false);\n\n const likeButtonRef = useRef<HTMLButtonElement>(null);\n const dislikeButtonRef = useRef<HTMLButtonElement>(null);\n const shouldOpenDialogRef = useRef(false);\n const [iconEl, seticonEl] = useElement<HTMLDivElement>();\n\n const isLikeActive = reaction === 'liked';\n const isDislikeActive = reaction === 'disliked';\n\n const needsDialog = (reactionType: Reaction) => {\n switch (promptFeedbackOn) {\n case 'disliked':\n return reactionType === 'disliked';\n case 'liked':\n return reactionType === 'liked';\n case 'both':\n return true;\n default:\n return false;\n }\n };\n\n const handleReactionClick = useCallback(\n (reactionType: Reaction) => {\n if (reaction === reactionType) {\n if (allowFeedbackResubmission) {\n onReaction?.(messageId, undefined);\n }\n\n return;\n }\n\n onReaction?.(messageId, reactionType);\n\n if (needsDialog(reactionType)) {\n if (reaction !== reactionType) {\n setFeedbackVal('');\n } else {\n setFeedbackVal(feedbackText);\n }\n\n if (!allowFeedbackResubmission) {\n shouldOpenDialogRef.current = true;\n } else {\n setShowDialog(true);\n }\n }\n },\n [reaction, feedbackText, allowFeedbackResubmission, promptFeedbackOn, messageId, onReaction]\n );\n\n const closeDialog = useCallback(\n (comment?: string) => {\n setShowDialog(false);\n shouldOpenDialogRef.current = false;\n\n onFeedbackComplete?.(messageId, comment);\n\n if (!allowFeedbackResubmission && iconEl) {\n iconEl.focus();\n }\n },\n [allowFeedbackResubmission, onFeedbackComplete, messageId, iconEl]\n );\n\n const getDialogTarget = () => {\n if (!allowFeedbackResubmission && iconEl) {\n return iconEl;\n }\n\n return isLikeActive ? likeButtonRef.current : dislikeButtonRef.current;\n };\n\n useEffect(() => {\n if (iconEl && shouldOpenDialogRef.current && !allowFeedbackResubmission) {\n setShowDialog(true);\n shouldOpenDialogRef.current = false;\n }\n }, [iconEl, allowFeedbackResubmission]);\n\n useEffect(() => {\n if (!showDialog && reaction && allowFeedbackResubmission) {\n const reactionButton =\n reaction === 'liked' ? likeButtonRef.current : dislikeButtonRef.current;\n reactionButton?.focus();\n }\n }, [showDialog, reaction, allowFeedbackResubmission]);\n\n const dialogTarget = getDialogTarget();\n\n const feedbackDialog = showDialog && dialogTarget && (\n <FormDialog\n target={dialogTarget}\n heading={t('share_feedback')}\n onCancel={() => closeDialog()}\n onSubmit={() => closeDialog(feedbackVal)}\n onKeyDown={e => e.stopPropagation()}\n >\n <TextArea\n value={feedbackVal}\n onChange={e => setFeedbackVal(e.target.value)}\n onKeyDown={(e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n closeDialog(feedbackVal);\n }\n }}\n autoResize={false}\n />\n </FormDialog>\n );\n\n const shouldShowIcon = !allowFeedbackResubmission && reaction;\n\n if (shouldShowIcon) {\n return (\n <Flex\n container={{ pad: [0.5, undefined] }}\n ref={seticonEl}\n tabIndex={-1}\n aria-label={t('selected_noun', [isLikeActive ? t('good_response') : t('bad_response')])}\n role='status'\n >\n <Icon name={isLikeActive ? 'thumbs-up-solid' : 'thumbs-down-solid'} />\n\n <Tooltip target={iconEl} describeTarget={false}>\n {isLikeActive ? t('good_response') : t('bad_response')}\n </Tooltip>\n\n {feedbackDialog}\n </Flex>\n );\n }\n\n return (\n <>\n <Flex container={{ gap: 1 }}>\n <Button\n label={t('good_response')}\n variant='simple'\n icon\n compact\n ref={likeButtonRef}\n onClick={() => handleReactionClick('liked')}\n aria-pressed={isLikeActive}\n >\n <Icon name={isLikeActive ? 'thumbs-up-solid' : 'thumbs-up'} />\n </Button>\n\n <Button\n label={t('bad_response')}\n variant='simple'\n icon\n compact\n ref={dislikeButtonRef}\n onClick={() => handleReactionClick('disliked')}\n aria-pressed={isDislikeActive}\n >\n <Icon name={isDislikeActive ? 'thumbs-down-solid' : 'thumbs-down'} />\n </Button>\n </Flex>\n\n {feedbackDialog}\n </>\n );\n};\n\nexport default GenAIMessageFeedbackButtons;\n"]}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
declare const GenAIMessageProgress: (
|
|
1
|
+
declare const GenAIMessageProgress: ({ messages, completedSteps }: {
|
|
2
|
+
messages?: string[];
|
|
3
|
+
completedSteps?: number;
|
|
4
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
2
5
|
export default GenAIMessageProgress;
|
|
3
6
|
//# sourceMappingURL=GenAIMessageProgress.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenAIMessageProgress.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessageProgress.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GenAIMessageProgress.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessageProgress.tsx"],"names":[],"mappings":"AAoBA,QAAA,MAAM,oBAAoB,GAAI,8BAG3B;IACD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,4CAmCA,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -1,39 +1,15 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Flex, Icon, Progress, registerIcon, Text, useI18n, useTheme } from '@pega/cosmos-react-core';
|
|
3
|
+
import * as checkIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/check.icon';
|
|
4
|
+
import { ProgressAngleStyle, StyledProgressContainer, StyledProgressContent, StyledProgressText } from './GenAICoach.styles';
|
|
5
|
+
registerIcon(checkIcon);
|
|
6
|
+
const GenAIMessageProgress = ({ messages, completedSteps }) => {
|
|
6
7
|
const t = useI18n();
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{ message: t('finalizing_response'), duration: baseDuration * 5 },
|
|
13
|
-
{ message: t('double_checking_results'), duration: baseDuration * 7 },
|
|
14
|
-
{ message: t('analyzing_data_sources'), duration: baseDuration * 9 },
|
|
15
|
-
{ message: t('finalizing_response'), duration: baseDuration * 10 }
|
|
16
|
-
], [t]);
|
|
17
|
-
const [currentIndex, setCurrentIndex] = useState(0);
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
let timeoutId;
|
|
20
|
-
const scheduleNextMessage = (index) => {
|
|
21
|
-
if (index >= progressMessages.length - 1)
|
|
22
|
-
return;
|
|
23
|
-
const currentMessage = progressMessages[index];
|
|
24
|
-
timeoutId = setTimeout(() => {
|
|
25
|
-
setCurrentIndex(index + 1);
|
|
26
|
-
scheduleNextMessage(index + 1);
|
|
27
|
-
}, currentMessage.duration);
|
|
28
|
-
};
|
|
29
|
-
// Start with the first message and schedule the next one
|
|
30
|
-
scheduleNextMessage(0);
|
|
31
|
-
return () => {
|
|
32
|
-
if (timeoutId)
|
|
33
|
-
clearTimeout(timeoutId);
|
|
34
|
-
};
|
|
35
|
-
}, [progressMessages]);
|
|
36
|
-
return (_jsxs(_Fragment, { children: [_jsx(Text, { children: progressMessages[currentIndex].message }), _jsx(Progress, { variant: 'ellipsis', placement: 'inline' })] }));
|
|
8
|
+
const theme = useTheme();
|
|
9
|
+
return (_jsxs(_Fragment, { children: [_jsx(ProgressAngleStyle, {}), _jsx(StyledProgressContainer, { children: _jsxs(Flex, { container: { direction: 'column', gap: 1 }, as: StyledProgressContent, children: [_jsx(StyledProgressText, { children: t('working_on_request') }), messages && messages.length > 0 && (_jsx(Flex, { container: { direction: 'column', gap: 1 }, children: messages.map((message, idx) => {
|
|
10
|
+
const isCompleted = completedSteps !== undefined ? idx < completedSteps : idx < messages.length - 1;
|
|
11
|
+
return (_jsxs(Flex, { container: { direction: 'row', gap: 1, alignItems: 'start' }, children: [isCompleted ? (_jsx(Icon, { name: 'check', color: theme.base.palette.success })) : (_jsx(Progress, { variant: 'ring', placement: 'inline' })), _jsx(Text, { children: message })] }, message));
|
|
12
|
+
}) }))] }) })] }));
|
|
37
13
|
};
|
|
38
14
|
export default GenAIMessageProgress;
|
|
39
15
|
//# sourceMappingURL=GenAIMessageProgress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenAIMessageProgress.js","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessageProgress.tsx"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"GenAIMessageProgress.js","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessageProgress.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,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AI,CAAC,OAAO,CAAC,OAAO,GAAI,CACzD,CAAC,CAAC,CAAC,CACF,KAAC,QAAQ,IAAC,OAAO,EAAC,MAAM,EAAC,SAAS,EAAC,QAAQ,GAAG,CAC/C,EAED,KAAC,IAAI,cAAE,OAAO,GAAQ,KAPb,OAAO,CAQX,CACR,CAAC;4BACJ,CAAC,CAAC,GACG,CACR,IACI,GACiB,IACzB,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,oBAAoB,CAAC","sourcesContent":["import {\n Flex,\n Icon,\n Progress,\n registerIcon,\n Text,\n useI18n,\n useTheme\n} from '@pega/cosmos-react-core';\nimport * as checkIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/check.icon';\n\nimport {\n ProgressAngleStyle,\n StyledProgressContainer,\n StyledProgressContent,\n StyledProgressText\n} from './GenAICoach.styles';\n\nregisterIcon(checkIcon);\n\nconst GenAIMessageProgress = ({\n messages,\n completedSteps\n}: {\n messages?: string[];\n completedSteps?: number;\n}) => {\n const t = useI18n();\n const theme = useTheme();\n\n return (\n <>\n <ProgressAngleStyle />\n <StyledProgressContainer>\n <Flex container={{ direction: 'column', gap: 1 }} as={StyledProgressContent}>\n <StyledProgressText>{t('working_on_request')}</StyledProgressText>\n\n {messages && messages.length > 0 && (\n <Flex container={{ direction: 'column', gap: 1 }}>\n {messages.map((message, idx) => {\n const isCompleted =\n completedSteps !== undefined ? idx < completedSteps : idx < messages.length - 1;\n\n return (\n <Flex key={message} container={{ direction: 'row', gap: 1, alignItems: 'start' }}>\n {isCompleted ? (\n <Icon name='check' color={theme.base.palette.success} />\n ) : (\n <Progress variant='ring' placement='inline' />\n )}\n\n <Text>{message}</Text>\n </Flex>\n );\n })}\n </Flex>\n )}\n </Flex>\n </StyledProgressContainer>\n </>\n );\n};\n\nexport default GenAIMessageProgress;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InitialSuggestedMessage.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/InitialSuggestedMessage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,OAAO,CAAC;AAIhE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAIvE,QAAA,MAAM,uBAAuB,EAAE,iBAAiB,CAAC,4BAA4B,
|
|
1
|
+
{"version":3,"file":"InitialSuggestedMessage.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/InitialSuggestedMessage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,OAAO,CAAC;AAIhE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAIvE,QAAA,MAAM,uBAAuB,EAAE,iBAAiB,CAAC,4BAA4B,CAyB1E,CAAC;AAEJ,eAAe,uBAAuB,CAAC"}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import {
|
|
3
|
-
import { StyledSuggestedMessage } from './GenAICoach.styles';
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useTestIds } from '@pega/cosmos-react-core';
|
|
4
3
|
import { getGenAICoachTestIds } from './GenAICoach.test-ids';
|
|
4
|
+
import { StyledInitialMessageButton, StyledInitialMessageText } from './GenAICoach.styles';
|
|
5
5
|
const InitialSuggestedMessage = function SuggestionCard({ id, message, testId, onSend }) {
|
|
6
6
|
const testIds = useTestIds(testId, getGenAICoachTestIds);
|
|
7
|
-
|
|
8
|
-
return (_jsxs(Card, { container: { justify: 'between' }, as: StyledSuggestedMessage, onClick: () => {
|
|
7
|
+
return (_jsx(StyledInitialMessageButton, { onClick: () => {
|
|
9
8
|
onSend({ id, message });
|
|
10
9
|
}, onKeyDown: (e) => {
|
|
11
10
|
if (e.key === 'Enter') {
|
|
12
11
|
e.preventDefault();
|
|
13
12
|
onSend({ id, message });
|
|
14
13
|
}
|
|
15
|
-
}, "data-testid": testIds.root, children:
|
|
14
|
+
}, "data-testid": testIds.root, children: _jsx(StyledInitialMessageText, { children: message }) }));
|
|
16
15
|
};
|
|
17
16
|
export default InitialSuggestedMessage;
|
|
18
17
|
//# sourceMappingURL=InitialSuggestedMessage.js.map
|