@patternfly/chatbot 6.5.0-prerelease.22 → 6.5.0-prerelease.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/DeepThinking/DeepThinking.d.ts +11 -0
- package/dist/cjs/DeepThinking/DeepThinking.js +30 -2
- package/dist/cjs/DeepThinking/DeepThinking.test.js +39 -0
- package/dist/cjs/MarkdownContent/MarkdownContent.d.ts +39 -0
- package/dist/cjs/MarkdownContent/MarkdownContent.js +181 -0
- package/dist/cjs/MarkdownContent/MarkdownContent.test.d.ts +1 -0
- package/dist/cjs/MarkdownContent/MarkdownContent.test.js +192 -0
- package/dist/cjs/MarkdownContent/index.d.ts +2 -0
- package/dist/cjs/MarkdownContent/index.js +23 -0
- package/dist/cjs/Message/CodeBlockMessage/CodeBlockMessage.d.ts +3 -1
- package/dist/cjs/Message/CodeBlockMessage/CodeBlockMessage.js +3 -2
- package/dist/cjs/Message/LinkMessage/LinkMessage.d.ts +5 -1
- package/dist/cjs/Message/LinkMessage/LinkMessage.js +4 -3
- package/dist/cjs/Message/ListMessage/OrderedListMessage.d.ts +9 -1
- package/dist/cjs/Message/ListMessage/OrderedListMessage.js +2 -1
- package/dist/cjs/Message/ListMessage/UnorderedListMessage.d.ts +7 -1
- package/dist/cjs/Message/ListMessage/UnorderedListMessage.js +2 -1
- package/dist/cjs/Message/Message.js +2 -155
- package/dist/cjs/Message/TableMessage/TableMessage.d.ts +6 -1
- package/dist/cjs/Message/TableMessage/TableMessage.js +3 -2
- package/dist/cjs/Message/TextMessage/TextMessage.d.ts +8 -1
- package/dist/cjs/Message/TextMessage/TextMessage.js +3 -2
- package/dist/cjs/ToolCall/ToolCall.d.ts +9 -0
- package/dist/cjs/ToolCall/ToolCall.js +19 -3
- package/dist/cjs/ToolCall/ToolCall.test.js +31 -0
- package/dist/cjs/ToolResponse/ToolResponse.d.ts +15 -0
- package/dist/cjs/ToolResponse/ToolResponse.js +48 -2
- package/dist/cjs/ToolResponse/ToolResponse.test.js +60 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +4 -1
- package/dist/css/main.css +48 -0
- package/dist/css/main.css.map +1 -1
- package/dist/dynamic/MarkdownContent/package.json +1 -0
- package/dist/esm/DeepThinking/DeepThinking.d.ts +11 -0
- package/dist/esm/DeepThinking/DeepThinking.js +27 -2
- package/dist/esm/DeepThinking/DeepThinking.test.js +39 -0
- package/dist/esm/MarkdownContent/MarkdownContent.d.ts +39 -0
- package/dist/esm/MarkdownContent/MarkdownContent.js +174 -0
- package/dist/esm/MarkdownContent/MarkdownContent.test.d.ts +1 -0
- package/dist/esm/MarkdownContent/MarkdownContent.test.js +187 -0
- package/dist/esm/MarkdownContent/index.d.ts +2 -0
- package/dist/esm/MarkdownContent/index.js +2 -0
- package/dist/esm/Message/CodeBlockMessage/CodeBlockMessage.d.ts +3 -1
- package/dist/esm/Message/CodeBlockMessage/CodeBlockMessage.js +3 -2
- package/dist/esm/Message/LinkMessage/LinkMessage.d.ts +5 -1
- package/dist/esm/Message/LinkMessage/LinkMessage.js +4 -3
- package/dist/esm/Message/ListMessage/OrderedListMessage.d.ts +9 -1
- package/dist/esm/Message/ListMessage/OrderedListMessage.js +2 -1
- package/dist/esm/Message/ListMessage/UnorderedListMessage.d.ts +7 -1
- package/dist/esm/Message/ListMessage/UnorderedListMessage.js +2 -1
- package/dist/esm/Message/Message.js +3 -156
- package/dist/esm/Message/TableMessage/TableMessage.d.ts +6 -1
- package/dist/esm/Message/TableMessage/TableMessage.js +3 -2
- package/dist/esm/Message/TextMessage/TextMessage.d.ts +8 -1
- package/dist/esm/Message/TextMessage/TextMessage.js +3 -2
- package/dist/esm/ToolCall/ToolCall.d.ts +9 -0
- package/dist/esm/ToolCall/ToolCall.js +16 -3
- package/dist/esm/ToolCall/ToolCall.test.js +31 -0
- package/dist/esm/ToolResponse/ToolResponse.d.ts +15 -0
- package/dist/esm/ToolResponse/ToolResponse.js +45 -2
- package/dist/esm/ToolResponse/ToolResponse.test.js +60 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMarkdownDeepThinking.tsx +26 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMarkdownToolCall.tsx +29 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMarkdownToolResponse.tsx +200 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/Messages.md +32 -0
- package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md +15 -1
- package/src/DeepThinking/DeepThinking.test.tsx +48 -0
- package/src/DeepThinking/DeepThinking.tsx +50 -4
- package/src/MarkdownContent/MarkdownContent.test.tsx +207 -0
- package/src/MarkdownContent/MarkdownContent.tsx +264 -0
- package/src/MarkdownContent/index.ts +2 -0
- package/src/Message/CodeBlockMessage/CodeBlockMessage.scss +4 -0
- package/src/Message/CodeBlockMessage/CodeBlockMessage.tsx +5 -1
- package/src/Message/LinkMessage/LinkMessage.scss +5 -0
- package/src/Message/LinkMessage/LinkMessage.tsx +24 -2
- package/src/Message/ListMessage/ListMessage.scss +8 -0
- package/src/Message/ListMessage/OrderedListMessage.tsx +16 -2
- package/src/Message/ListMessage/UnorderedListMessage.tsx +12 -2
- package/src/Message/Message.tsx +21 -181
- package/src/Message/TableMessage/TableMessage.scss +11 -0
- package/src/Message/TableMessage/TableMessage.tsx +18 -2
- package/src/Message/TextMessage/TextMessage.scss +8 -0
- package/src/Message/TextMessage/TextMessage.tsx +29 -2
- package/src/ToolCall/ToolCall.test.tsx +40 -0
- package/src/ToolCall/ToolCall.tsx +37 -3
- package/src/ToolResponse/ToolResponse.scss +10 -0
- package/src/ToolResponse/ToolResponse.test.tsx +75 -0
- package/src/ToolResponse/ToolResponse.tsx +78 -6
- package/src/index.ts +3 -0
- package/src/main.scss +1 -0
|
@@ -17,15 +17,16 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
17
17
|
// ============================================================================
|
|
18
18
|
const react_core_1 = require("@patternfly/react-core");
|
|
19
19
|
const react_icons_1 = require("@patternfly/react-icons");
|
|
20
|
+
const react_styles_1 = require("@patternfly/react-styles");
|
|
20
21
|
const LinkMessage = (_a) => {
|
|
21
|
-
var { children, target, href, id } = _a, props = __rest(_a, ["children", "target", "href", "id"]);
|
|
22
|
+
var { children, target, href, id, shouldRetainStyles } = _a, props = __rest(_a, ["children", "target", "href", "id", "shouldRetainStyles"]);
|
|
22
23
|
if (target === '_blank') {
|
|
23
24
|
return ((0, jsx_runtime_1.jsx)(react_core_1.Button, Object.assign({ component: "a", variant: "link", href: href, icon: (0, jsx_runtime_1.jsx)(react_icons_1.ExternalLinkSquareAltIcon, {}), iconPosition: "end", isInline: true, target: target,
|
|
24
25
|
// need to explicitly call this out or id doesn't seem to get passed - required for footnotes
|
|
25
|
-
id: id }, props, { children: children })));
|
|
26
|
+
id: id }, props, { className: (0, react_styles_1.css)(shouldRetainStyles && 'pf-m-markdown', props === null || props === void 0 ? void 0 : props.className), children: children })));
|
|
26
27
|
}
|
|
27
28
|
return (
|
|
28
29
|
// need to explicitly call this out or id doesn't seem to get passed - required for footnotes
|
|
29
|
-
(0, jsx_runtime_1.jsx)(react_core_1.Button, Object.assign({ isInline: true, component: "a", href: href, variant: "link", id: id }, props, { children: children })));
|
|
30
|
+
(0, jsx_runtime_1.jsx)(react_core_1.Button, Object.assign({ isInline: true, component: "a", href: href, variant: "link", id: id }, props, { className: (0, react_styles_1.css)(shouldRetainStyles && 'pf-m-markdown', props === null || props === void 0 ? void 0 : props.className), children: children })));
|
|
30
31
|
};
|
|
31
32
|
exports.default = LinkMessage;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import { ExtraProps } from 'react-markdown';
|
|
2
|
-
|
|
2
|
+
export interface OrderedListMessageProps {
|
|
3
|
+
/** The ordered list content */
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
/** The number to start the ordered list at. */
|
|
6
|
+
start?: number;
|
|
7
|
+
/** Flag indicating that the content should retain message styles when using Markdown. */
|
|
8
|
+
shouldRetainStyles?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const OrderedListMessage: ({ children, start, shouldRetainStyles }: OrderedListMessageProps & JSX.IntrinsicElements["ol"] & ExtraProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
11
|
export default OrderedListMessage;
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
4
|
const react_core_1 = require("@patternfly/react-core");
|
|
5
|
-
const
|
|
5
|
+
const react_styles_1 = require("@patternfly/react-styles");
|
|
6
|
+
const OrderedListMessage = ({ children, start, shouldRetainStyles }) => ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)('pf-chatbot__message-ordered-list', shouldRetainStyles && 'pf-m-markdown'), children: (0, jsx_runtime_1.jsx)(react_core_1.List, { component: react_core_1.ListComponent.ol, type: react_core_1.OrderType.number, start: start, children: children }) }));
|
|
6
7
|
exports.default = OrderedListMessage;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { ExtraProps } from 'react-markdown';
|
|
2
|
-
|
|
2
|
+
export interface UnrderedListMessageProps {
|
|
3
|
+
/** The ordered list content */
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
/** Flag indicating that the content should retain message styles when using Markdown. */
|
|
6
|
+
shouldRetainStyles?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const UnorderedListMessage: ({ children, shouldRetainStyles }: UnrderedListMessageProps & JSX.IntrinsicElements["ul"] & ExtraProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
9
|
export default UnorderedListMessage;
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
4
|
const react_core_1 = require("@patternfly/react-core");
|
|
5
|
-
const
|
|
5
|
+
const react_styles_1 = require("@patternfly/react-styles");
|
|
6
|
+
const UnorderedListMessage = ({ children, shouldRetainStyles }) => ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)('pf-chatbot__message-unordered-list', shouldRetainStyles && 'pf-m-markdown'), children: (0, jsx_runtime_1.jsx)(react_core_1.List, { children: children }) }));
|
|
6
7
|
exports.default = UnorderedListMessage;
|
|
@@ -20,43 +20,23 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
20
20
|
// Chatbot Main - Message
|
|
21
21
|
// ============================================================================
|
|
22
22
|
const react_1 = require("react");
|
|
23
|
-
const react_markdown_1 = __importDefault(require("react-markdown"));
|
|
24
|
-
const remark_gfm_1 = __importDefault(require("remark-gfm"));
|
|
25
23
|
const react_core_1 = require("@patternfly/react-core");
|
|
26
24
|
const MessageLoading_1 = __importDefault(require("./MessageLoading"));
|
|
27
|
-
const CodeBlockMessage_1 = __importDefault(require("./CodeBlockMessage/CodeBlockMessage"));
|
|
28
|
-
const TextMessage_1 = __importDefault(require("./TextMessage/TextMessage"));
|
|
29
25
|
const FileDetailsLabel_1 = __importDefault(require("../FileDetailsLabel/FileDetailsLabel"));
|
|
30
26
|
const ResponseActions_1 = __importDefault(require("../ResponseActions/ResponseActions"));
|
|
31
27
|
const SourcesCard_1 = __importDefault(require("../SourcesCard"));
|
|
32
|
-
const ListItemMessage_1 = __importDefault(require("./ListMessage/ListItemMessage"));
|
|
33
|
-
const UnorderedListMessage_1 = __importDefault(require("./ListMessage/UnorderedListMessage"));
|
|
34
|
-
const OrderedListMessage_1 = __importDefault(require("./ListMessage/OrderedListMessage"));
|
|
35
28
|
const QuickStartTile_1 = __importDefault(require("./QuickStarts/QuickStartTile"));
|
|
36
29
|
const QuickResponse_1 = __importDefault(require("./QuickResponse/QuickResponse"));
|
|
37
30
|
const UserFeedback_1 = __importDefault(require("./UserFeedback/UserFeedback"));
|
|
38
31
|
const UserFeedbackComplete_1 = __importDefault(require("./UserFeedback/UserFeedbackComplete"));
|
|
39
|
-
const TableMessage_1 = __importDefault(require("./TableMessage/TableMessage"));
|
|
40
|
-
const TrMessage_1 = __importDefault(require("./TableMessage/TrMessage"));
|
|
41
|
-
const TdMessage_1 = __importDefault(require("./TableMessage/TdMessage"));
|
|
42
|
-
const TbodyMessage_1 = __importDefault(require("./TableMessage/TbodyMessage"));
|
|
43
|
-
const TheadMessage_1 = __importDefault(require("./TableMessage/TheadMessage"));
|
|
44
|
-
const ThMessage_1 = __importDefault(require("./TableMessage/ThMessage"));
|
|
45
|
-
const ImageMessage_1 = __importDefault(require("./ImageMessage/ImageMessage"));
|
|
46
|
-
const rehype_unwrap_images_1 = __importDefault(require("rehype-unwrap-images"));
|
|
47
|
-
const rehype_external_links_1 = __importDefault(require("rehype-external-links"));
|
|
48
|
-
const rehype_sanitize_1 = __importDefault(require("rehype-sanitize"));
|
|
49
|
-
const rehype_highlight_1 = __importDefault(require("rehype-highlight"));
|
|
50
32
|
// see the full list of styles here: https://highlightjs.org/examples
|
|
51
33
|
require("highlight.js/styles/vs2015.css");
|
|
52
|
-
const LinkMessage_1 = __importDefault(require("./LinkMessage/LinkMessage"));
|
|
53
34
|
const ErrorMessage_1 = __importDefault(require("./ErrorMessage/ErrorMessage"));
|
|
54
35
|
const MessageInput_1 = __importDefault(require("./MessageInput"));
|
|
55
|
-
const rehypeMoveImagesOutOfParagraphs_1 = require("./Plugins/rehypeMoveImagesOutOfParagraphs");
|
|
56
36
|
const ToolResponse_1 = __importDefault(require("../ToolResponse"));
|
|
57
37
|
const DeepThinking_1 = __importDefault(require("../DeepThinking"));
|
|
58
|
-
const SuperscriptMessage_1 = __importDefault(require("./SuperscriptMessage/SuperscriptMessage"));
|
|
59
38
|
const ToolCall_1 = __importDefault(require("../ToolCall"));
|
|
39
|
+
const MarkdownContent_1 = __importDefault(require("../MarkdownContent"));
|
|
60
40
|
const MessageBase = (_a) => {
|
|
61
41
|
var { role, content, extraContent, name, avatar, timestamp, isLoading, actions, persistActionSelection, sources, botWord = 'AI', loadingWord = 'Loading message', codeBlockProps, quickResponses, quickResponseContainerProps = { numLabels: 5 }, attachments, hasRoundAvatar = true, avatarProps, quickStarts, userFeedbackForm, userFeedbackComplete, isLiveRegion = true, innerRef, tableProps, openLinkInNewTab = true, additionalRehypePlugins = [], additionalRemarkPlugins = [], linkProps, error, isEditable, editPlaceholder = 'Edit prompt message...', updateWord = 'Update', cancelWord = 'Cancel', onEditUpdate, onEditCancel, inputRef, editFormProps, isCompact, isMarkdownDisabled, reactMarkdownProps, toolResponse, deepThinking, remarkGfmProps, toolCall, hasNoImagesInUserMessages = true, isPrimary } = _a, props = __rest(_a, ["role", "content", "extraContent", "name", "avatar", "timestamp", "isLoading", "actions", "persistActionSelection", "sources", "botWord", "loadingWord", "codeBlockProps", "quickResponses", "quickResponseContainerProps", "attachments", "hasRoundAvatar", "avatarProps", "quickStarts", "userFeedbackForm", "userFeedbackComplete", "isLiveRegion", "innerRef", "tableProps", "openLinkInNewTab", "additionalRehypePlugins", "additionalRemarkPlugins", "linkProps", "error", "isEditable", "editPlaceholder", "updateWord", "cancelWord", "onEditUpdate", "onEditCancel", "inputRef", "editFormProps", "isCompact", "isMarkdownDisabled", "reactMarkdownProps", "toolResponse", "deepThinking", "remarkGfmProps", "toolCall", "hasNoImagesInUserMessages", "isPrimary"]);
|
|
62
42
|
const [messageText, setMessageText] = (0, react_1.useState)(content);
|
|
@@ -64,13 +44,6 @@ const MessageBase = (_a) => {
|
|
|
64
44
|
setMessageText(content);
|
|
65
45
|
}, [content]);
|
|
66
46
|
const { beforeMainContent, afterMainContent, endContent } = extraContent || {};
|
|
67
|
-
let rehypePlugins = [rehype_unwrap_images_1.default, rehypeMoveImagesOutOfParagraphs_1.rehypeMoveImagesOutOfParagraphs, rehype_highlight_1.default];
|
|
68
|
-
if (openLinkInNewTab) {
|
|
69
|
-
rehypePlugins = rehypePlugins.concat([[rehype_external_links_1.default, { target: '_blank' }, rehype_sanitize_1.default]]);
|
|
70
|
-
}
|
|
71
|
-
if (additionalRehypePlugins) {
|
|
72
|
-
rehypePlugins.push(...additionalRehypePlugins);
|
|
73
|
-
}
|
|
74
47
|
let avatarClassName;
|
|
75
48
|
if (avatarProps && 'className' in avatarProps) {
|
|
76
49
|
const { className } = avatarProps, rest = __rest(avatarProps, ["className"]);
|
|
@@ -80,133 +53,7 @@ const MessageBase = (_a) => {
|
|
|
80
53
|
// Keep timestamps consistent between Timestamp component and aria-label
|
|
81
54
|
const date = new Date();
|
|
82
55
|
const dateString = timestamp !== null && timestamp !== void 0 ? timestamp : `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
|
|
83
|
-
const
|
|
84
|
-
if (reactMarkdownProps && reactMarkdownProps.disallowedElements) {
|
|
85
|
-
disallowedElements.push(...reactMarkdownProps.disallowedElements);
|
|
86
|
-
}
|
|
87
|
-
const handleMarkdown = () => {
|
|
88
|
-
if (isMarkdownDisabled) {
|
|
89
|
-
return ((0, jsx_runtime_1.jsx)(TextMessage_1.default, Object.assign({ component: react_core_1.ContentVariants.p }, props, { children: messageText })));
|
|
90
|
-
}
|
|
91
|
-
return ((0, jsx_runtime_1.jsx)(react_markdown_1.default, Object.assign({ components: {
|
|
92
|
-
section: (props) => {
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
94
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
95
|
-
return (0, jsx_runtime_1.jsx)("section", Object.assign({}, rest, { className: `pf-chatbot__message-text ${rest === null || rest === void 0 ? void 0 : rest.className}` }));
|
|
96
|
-
},
|
|
97
|
-
p: (props) => {
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
99
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
100
|
-
return (0, jsx_runtime_1.jsx)(TextMessage_1.default, Object.assign({ component: react_core_1.ContentVariants.p }, rest, { isPrimary: isPrimary }));
|
|
101
|
-
},
|
|
102
|
-
code: (_a) => {
|
|
103
|
-
var { children } = _a, props = __rest(_a, ["children"]);
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
105
|
-
const { node } = props, codeProps = __rest(props, ["node"]);
|
|
106
|
-
return ((0, jsx_runtime_1.jsx)(CodeBlockMessage_1.default, Object.assign({}, codeProps, codeBlockProps, { isPrimary: isPrimary, children: children })));
|
|
107
|
-
},
|
|
108
|
-
h1: (props) => {
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
110
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
111
|
-
return (0, jsx_runtime_1.jsx)(TextMessage_1.default, Object.assign({ component: react_core_1.ContentVariants.h1 }, rest));
|
|
112
|
-
},
|
|
113
|
-
h2: (props) => {
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
115
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
116
|
-
return (0, jsx_runtime_1.jsx)(TextMessage_1.default, Object.assign({ component: react_core_1.ContentVariants.h2 }, rest));
|
|
117
|
-
},
|
|
118
|
-
h3: (props) => {
|
|
119
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
120
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
121
|
-
return (0, jsx_runtime_1.jsx)(TextMessage_1.default, Object.assign({ component: react_core_1.ContentVariants.h3 }, rest));
|
|
122
|
-
},
|
|
123
|
-
h4: (props) => {
|
|
124
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
125
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
126
|
-
return (0, jsx_runtime_1.jsx)(TextMessage_1.default, Object.assign({ component: react_core_1.ContentVariants.h4 }, rest));
|
|
127
|
-
},
|
|
128
|
-
h5: (props) => {
|
|
129
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
130
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
131
|
-
return (0, jsx_runtime_1.jsx)(TextMessage_1.default, Object.assign({ component: react_core_1.ContentVariants.h5 }, rest));
|
|
132
|
-
},
|
|
133
|
-
h6: (props) => {
|
|
134
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
135
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
136
|
-
return (0, jsx_runtime_1.jsx)(TextMessage_1.default, Object.assign({ component: react_core_1.ContentVariants.h6 }, rest));
|
|
137
|
-
},
|
|
138
|
-
blockquote: (props) => {
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
140
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
141
|
-
return (0, jsx_runtime_1.jsx)(TextMessage_1.default, Object.assign({ component: react_core_1.ContentVariants.blockquote }, rest));
|
|
142
|
-
},
|
|
143
|
-
ul: (props) => {
|
|
144
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
145
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
146
|
-
return (0, jsx_runtime_1.jsx)(UnorderedListMessage_1.default, Object.assign({}, rest));
|
|
147
|
-
},
|
|
148
|
-
ol: (props) => {
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
150
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
151
|
-
return (0, jsx_runtime_1.jsx)(OrderedListMessage_1.default, Object.assign({}, rest));
|
|
152
|
-
},
|
|
153
|
-
li: (props) => {
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
155
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
156
|
-
return (0, jsx_runtime_1.jsx)(ListItemMessage_1.default, Object.assign({}, rest));
|
|
157
|
-
},
|
|
158
|
-
// table requires node attribute for calculating headers for mobile breakpoint
|
|
159
|
-
table: (props) => (0, jsx_runtime_1.jsx)(TableMessage_1.default, Object.assign({}, props, tableProps, { isPrimary: isPrimary })),
|
|
160
|
-
tbody: (props) => {
|
|
161
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
162
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
163
|
-
return (0, jsx_runtime_1.jsx)(TbodyMessage_1.default, Object.assign({}, rest));
|
|
164
|
-
},
|
|
165
|
-
thead: (props) => {
|
|
166
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
167
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
168
|
-
return (0, jsx_runtime_1.jsx)(TheadMessage_1.default, Object.assign({}, rest));
|
|
169
|
-
},
|
|
170
|
-
tr: (props) => {
|
|
171
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
172
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
173
|
-
return (0, jsx_runtime_1.jsx)(TrMessage_1.default, Object.assign({}, rest));
|
|
174
|
-
},
|
|
175
|
-
td: (props) => {
|
|
176
|
-
// Conflicts with Td type
|
|
177
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
178
|
-
const { node, width } = props, rest = __rest(props, ["node", "width"]);
|
|
179
|
-
return (0, jsx_runtime_1.jsx)(TdMessage_1.default, Object.assign({}, rest));
|
|
180
|
-
},
|
|
181
|
-
th: (props) => {
|
|
182
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
183
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
184
|
-
return (0, jsx_runtime_1.jsx)(ThMessage_1.default, Object.assign({}, rest));
|
|
185
|
-
},
|
|
186
|
-
img: (props) => {
|
|
187
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
188
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
189
|
-
return (0, jsx_runtime_1.jsx)(ImageMessage_1.default, Object.assign({}, rest));
|
|
190
|
-
},
|
|
191
|
-
a: (props) => {
|
|
192
|
-
// node is just the details of the document structure - not needed
|
|
193
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
194
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
195
|
-
return (
|
|
196
|
-
// some a types conflict with ButtonProps, but it's ok because we are using an a tag
|
|
197
|
-
// there are too many to handle manually
|
|
198
|
-
(0, jsx_runtime_1.jsx)(LinkMessage_1.default, Object.assign({}, rest, linkProps, { children: props.children })));
|
|
199
|
-
},
|
|
200
|
-
// used for footnotes
|
|
201
|
-
sup: (props) => {
|
|
202
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
203
|
-
const { node } = props, rest = __rest(props, ["node"]);
|
|
204
|
-
return (0, jsx_runtime_1.jsx)(SuperscriptMessage_1.default, Object.assign({}, rest));
|
|
205
|
-
}
|
|
206
|
-
}, remarkPlugins: [[remark_gfm_1.default, Object.assign({}, remarkGfmProps)], ...additionalRemarkPlugins], rehypePlugins: rehypePlugins }, reactMarkdownProps, { remarkRehypeOptions: Object.assign({
|
|
207
|
-
// removes sr-only class from footnote labels applied by default
|
|
208
|
-
footnoteLabelProperties: { className: [''] } }, reactMarkdownProps === null || reactMarkdownProps === void 0 ? void 0 : reactMarkdownProps.remarkRehypeOptions), disallowedElements: disallowedElements, children: messageText })));
|
|
209
|
-
};
|
|
56
|
+
const handleMarkdown = () => ((0, jsx_runtime_1.jsx)(MarkdownContent_1.default, { content: messageText, isMarkdownDisabled: isMarkdownDisabled, codeBlockProps: codeBlockProps, tableProps: tableProps, openLinkInNewTab: openLinkInNewTab, additionalRehypePlugins: additionalRehypePlugins, additionalRemarkPlugins: additionalRemarkPlugins, linkProps: linkProps, reactMarkdownProps: reactMarkdownProps, remarkGfmProps: remarkGfmProps, hasNoImages: role === 'user' && hasNoImagesInUserMessages, isPrimary: isPrimary }));
|
|
210
57
|
const renderMessage = () => {
|
|
211
58
|
if (isLoading) {
|
|
212
59
|
return (0, jsx_runtime_1.jsx)(MessageLoading_1.default, { loadingWord: loadingWord, isPrimary: isPrimary });
|
|
@@ -16,7 +16,12 @@ export interface TableNode {
|
|
|
16
16
|
type: string;
|
|
17
17
|
}
|
|
18
18
|
export interface TableMessageProps {
|
|
19
|
+
/** Content of the table */
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
/** Flag indicating whether primary styles should be applied. */
|
|
19
22
|
isPrimary?: boolean;
|
|
23
|
+
/** Flag indicating that the content should retain message styles when using Markdown. */
|
|
24
|
+
shouldRetainStyles?: boolean;
|
|
20
25
|
}
|
|
21
|
-
declare const TableMessage: ({ children, isPrimary, ...props }: Omit<TableProps, "ref"> & ExtraProps & TableMessageProps) => import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
declare const TableMessage: ({ children, isPrimary, shouldRetainStyles, ...props }: Omit<TableProps, "ref"> & ExtraProps & TableMessageProps) => import("react/jsx-runtime").JSX.Element;
|
|
22
27
|
export default TableMessage;
|
|
@@ -17,9 +17,10 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
17
17
|
// ============================================================================
|
|
18
18
|
const react_1 = require("react");
|
|
19
19
|
const react_table_1 = require("@patternfly/react-table");
|
|
20
|
+
const react_styles_1 = require("@patternfly/react-styles");
|
|
20
21
|
const TableMessage = (_a) => {
|
|
21
22
|
var _b;
|
|
22
|
-
var { children, isPrimary } = _a, props = __rest(_a, ["children", "isPrimary"]);
|
|
23
|
+
var { children, isPrimary, shouldRetainStyles } = _a, props = __rest(_a, ["children", "isPrimary", "shouldRetainStyles"]);
|
|
23
24
|
const { className } = props, rest = __rest(props, ["className"]);
|
|
24
25
|
// This allows us to parse the nested data we get back from the 3rd party Markdown parser
|
|
25
26
|
// Open to feedback here if there is a better way to do this
|
|
@@ -60,6 +61,6 @@ const TableMessage = (_a) => {
|
|
|
60
61
|
}
|
|
61
62
|
return (
|
|
62
63
|
// gridBreakPoint is so we show mobile-styled-PF table
|
|
63
|
-
(0, jsx_runtime_1.jsx)(react_table_1.Table, Object.assign({ "aria-label": props['aria-label'], gridBreakPoint: "grid", className:
|
|
64
|
+
(0, jsx_runtime_1.jsx)(react_table_1.Table, Object.assign({ "aria-label": props['aria-label'], gridBreakPoint: "grid", className: (0, react_styles_1.css)('pf-chatbot__message-table', isPrimary && 'pf-m-primary', shouldRetainStyles && 'pf-m-markdown', className) }, rest, { children: modifyChildren(children) })));
|
|
64
65
|
};
|
|
65
66
|
exports.default = TableMessage;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { ExtraProps } from 'react-markdown';
|
|
2
2
|
import { ContentProps } from '@patternfly/react-core';
|
|
3
3
|
export interface TextMessageProps {
|
|
4
|
+
/** The text message content */
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
/** Flag indicating whether primary styling is applied. */
|
|
4
7
|
isPrimary?: boolean;
|
|
8
|
+
/** The wrapper component to use for the PatternFly Content component. Defaults to a div. */
|
|
9
|
+
component?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'a' | 'small' | 'blockquote' | 'pre' | 'hr' | 'ul' | 'ol' | 'dl' | 'li' | 'dt' | 'dd';
|
|
10
|
+
/** Flag indicating that the content should retain message styles when using Markdown. */
|
|
11
|
+
shouldRetainStyles?: boolean;
|
|
5
12
|
}
|
|
6
|
-
declare const TextMessage: ({ component, children, isPrimary, ...props }: Omit<ContentProps, "ref"> & ExtraProps & TextMessageProps) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
declare const TextMessage: ({ component, children, isPrimary, shouldRetainStyles, ...props }: Omit<ContentProps, "ref"> & ExtraProps & TextMessageProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
14
|
export default TextMessage;
|
|
@@ -13,8 +13,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
15
15
|
const react_core_1 = require("@patternfly/react-core");
|
|
16
|
+
const react_styles_1 = require("@patternfly/react-styles");
|
|
16
17
|
const TextMessage = (_a) => {
|
|
17
|
-
var { component, children, isPrimary } = _a, props = __rest(_a, ["component", "children", "isPrimary"]);
|
|
18
|
-
return ((0, jsx_runtime_1.jsx)("span", { className:
|
|
18
|
+
var { component, children, isPrimary, shouldRetainStyles } = _a, props = __rest(_a, ["component", "children", "isPrimary", "shouldRetainStyles"]);
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)('pf-chatbot__message-text', isPrimary && 'pf-m-primary', shouldRetainStyles && 'pf-m-markdown'), children: (0, jsx_runtime_1.jsx)(react_core_1.Content, Object.assign({ component: component }, props, { className: (0, react_styles_1.css)(props === null || props === void 0 ? void 0 : props.className), children: children })) }));
|
|
19
20
|
};
|
|
20
21
|
exports.default = TextMessage;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FunctionComponent } from 'react';
|
|
2
2
|
import { ActionListProps, ActionListGroupProps, ActionListItemProps, ButtonProps, CardProps, CardBodyProps, CardFooterProps, ExpandableSectionProps, SpinnerProps } from '@patternfly/react-core';
|
|
3
|
+
import type { MarkdownContentProps } from '../MarkdownContent';
|
|
3
4
|
export interface ToolCallProps {
|
|
4
5
|
/** Title text for the tool call. */
|
|
5
6
|
titleText: string;
|
|
@@ -41,6 +42,14 @@ export interface ToolCallProps {
|
|
|
41
42
|
cardFooterProps?: CardFooterProps;
|
|
42
43
|
/** Additional props for the expandable section when expandableContent is passed. */
|
|
43
44
|
expandableSectionProps?: Omit<ExpandableSectionProps, 'ref'>;
|
|
45
|
+
/** Whether to enable markdown rendering for titleText. When true, titleText will be parsed as markdown. */
|
|
46
|
+
isTitleMarkdown?: boolean;
|
|
47
|
+
/** Whether to enable markdown rendering for expandableContent. When true and expandableContent is a string, it will be parsed as markdown. */
|
|
48
|
+
isExpandableContentMarkdown?: boolean;
|
|
49
|
+
/** Props passed to MarkdownContent component when markdown is enabled */
|
|
50
|
+
markdownContentProps?: Omit<MarkdownContentProps, 'content'>;
|
|
51
|
+
/** Whether to retain styles in the MarkdownContent component. Defaults to false. */
|
|
52
|
+
shouldRetainStyles?: boolean;
|
|
44
53
|
}
|
|
45
54
|
export declare const ToolCall: FunctionComponent<ToolCallProps>;
|
|
46
55
|
export default ToolCall;
|
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.ToolCall = void 0;
|
|
4
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
8
|
const react_1 = require("react");
|
|
6
9
|
const react_core_1 = require("@patternfly/react-core");
|
|
7
|
-
const
|
|
10
|
+
const MarkdownContent_1 = __importDefault(require("../MarkdownContent"));
|
|
11
|
+
const ToolCall = ({ titleText, loadingText, isLoading, expandableContent, isDefaultExpanded = false, runButtonText = 'Run tool', runButtonProps, runActionItemProps, cancelButtonText = 'Cancel', cancelButtonProps, cancelActionItemProps, actions, actionListProps, actionListGroupProps, actionListItemProps, cardProps, cardBodyProps, cardFooterProps, expandableSectionProps, spinnerProps, isTitleMarkdown, isExpandableContentMarkdown, markdownContentProps, shouldRetainStyles = false }) => {
|
|
8
12
|
const [isExpanded, setIsExpanded] = (0, react_1.useState)(isDefaultExpanded);
|
|
9
13
|
const onToggle = (_event, isExpanded) => {
|
|
10
14
|
setIsExpanded(isExpanded);
|
|
11
15
|
};
|
|
12
|
-
const
|
|
16
|
+
const renderTitle = () => {
|
|
17
|
+
if (isTitleMarkdown) {
|
|
18
|
+
return (0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: titleText }, markdownContentProps));
|
|
19
|
+
}
|
|
20
|
+
return titleText;
|
|
21
|
+
};
|
|
22
|
+
const titleContent = ((0, jsx_runtime_1.jsx)("span", { className: `pf-chatbot__tool-call-title-content`, children: isLoading ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_core_1.Spinner, Object.assign({ diameter: "1em" }, spinnerProps)), ' ', (0, jsx_runtime_1.jsx)("span", { className: "pf-chatbot__tool-call-title-text", children: loadingText })] })) : ((0, jsx_runtime_1.jsx)("span", { className: "pf-chatbot__tool-call-title-text", children: renderTitle() })) }));
|
|
23
|
+
const renderExpandableContent = () => {
|
|
24
|
+
if (isExpandableContentMarkdown && typeof expandableContent === 'string') {
|
|
25
|
+
return ((0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: expandableContent }, markdownContentProps)));
|
|
26
|
+
}
|
|
27
|
+
return expandableContent;
|
|
28
|
+
};
|
|
13
29
|
const defaultActions = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_core_1.ActionListItem, Object.assign({}, actionListItemProps, cancelActionItemProps, { children: (0, jsx_runtime_1.jsx)(react_core_1.Button, Object.assign({ variant: "link" }, cancelButtonProps, { children: cancelButtonText })) })), (0, jsx_runtime_1.jsx)(react_core_1.ActionListItem, Object.assign({}, actionListItemProps, runActionItemProps, { children: (0, jsx_runtime_1.jsx)(react_core_1.Button, Object.assign({ variant: "secondary" }, runButtonProps, { children: runButtonText })) }))] }));
|
|
14
30
|
const customActions = actions &&
|
|
15
31
|
actions.map((action, index) => ((0, jsx_runtime_1.jsx)(react_core_1.ActionListItem, Object.assign({}, actionListItemProps, { children: action }), index)));
|
|
16
|
-
return ((0, jsx_runtime_1.jsxs)(react_core_1.Card, Object.assign({ isCompact: true, className: "pf-chatbot__tool-call" }, cardProps, { children: [(0, jsx_runtime_1.jsx)(react_core_1.CardBody, Object.assign({ className: "pf-chatbot__tool-call-title" }, cardBodyProps, { children: expandableContent && !isLoading ? ((0, jsx_runtime_1.jsx)(react_core_1.ExpandableSection, Object.assign({ className: "pf-chatbot__tool-call-expandable-section", toggleContent: titleContent, onToggle: onToggle, isExpanded: isExpanded, isIndented: true }, expandableSectionProps, { children:
|
|
32
|
+
return ((0, jsx_runtime_1.jsxs)(react_core_1.Card, Object.assign({ isCompact: true, className: "pf-chatbot__tool-call" }, cardProps, { children: [(0, jsx_runtime_1.jsx)(react_core_1.CardBody, Object.assign({ className: "pf-chatbot__tool-call-title" }, cardBodyProps, { children: expandableContent && !isLoading ? ((0, jsx_runtime_1.jsx)(react_core_1.ExpandableSection, Object.assign({ className: "pf-chatbot__tool-call-expandable-section", toggleContent: titleContent, onToggle: onToggle, isExpanded: isExpanded, isIndented: true }, expandableSectionProps, { children: renderExpandableContent() }))) : (titleContent) })), !isLoading && ((0, jsx_runtime_1.jsx)(react_core_1.CardFooter, Object.assign({}, cardFooterProps, { children: (0, jsx_runtime_1.jsx)(react_core_1.ActionList, Object.assign({ className: "pf-chatbot__tool-call-action-list" }, actionListProps, { children: (0, jsx_runtime_1.jsx)(react_core_1.ActionListGroup, Object.assign({}, actionListGroupProps, { children: customActions || defaultActions })) })) })))] })));
|
|
17
33
|
};
|
|
18
34
|
exports.ToolCall = ToolCall;
|
|
19
35
|
exports.default = exports.ToolCall;
|
|
@@ -167,4 +167,35 @@ describe('ToolCall', () => {
|
|
|
167
167
|
expect(toggleButton).toHaveAttribute('aria-expanded', 'false');
|
|
168
168
|
expect(react_1.screen.queryByText('Expandable Content')).not.toBeVisible();
|
|
169
169
|
}));
|
|
170
|
+
it('should render titleText as markdown when isTitleMarkdown is true', () => {
|
|
171
|
+
const titleText = '**Bold title**';
|
|
172
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, { titleText: titleText, isTitleMarkdown: true }));
|
|
173
|
+
expect(container.querySelector('strong')).toBeTruthy();
|
|
174
|
+
expect(react_1.screen.getByText('Bold title')).toBeTruthy();
|
|
175
|
+
});
|
|
176
|
+
it('should not render titleText as markdown when isTitleMarkdown is false', () => {
|
|
177
|
+
const titleText = '**Bold title**';
|
|
178
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, { titleText: titleText }));
|
|
179
|
+
expect(react_1.screen.getByText('**Bold title**')).toBeTruthy();
|
|
180
|
+
});
|
|
181
|
+
it('should render expandableContent as markdown when isExpandableContentMarkdown is true', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
182
|
+
const user = user_event_1.default.setup();
|
|
183
|
+
const expandableContent = '**Bold expandable content**';
|
|
184
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { expandableContent: expandableContent, isExpandableContentMarkdown: true })));
|
|
185
|
+
yield user.click(react_1.screen.getByRole('button', { name: defaultProps.titleText }));
|
|
186
|
+
expect(container.querySelector('strong')).toBeTruthy();
|
|
187
|
+
expect(react_1.screen.getByText('Bold expandable content')).toBeTruthy();
|
|
188
|
+
}));
|
|
189
|
+
it('should not render expandableContent as markdown when isExpandableContentMarkdown is false', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
190
|
+
const user = user_event_1.default.setup();
|
|
191
|
+
const expandableContent = '**Bold expandable content**';
|
|
192
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, Object.assign({}, defaultProps, { expandableContent: expandableContent })));
|
|
193
|
+
yield user.click(react_1.screen.getByRole('button', { name: defaultProps.titleText }));
|
|
194
|
+
expect(react_1.screen.getByText('**Bold expandable content**')).toBeTruthy();
|
|
195
|
+
}));
|
|
196
|
+
it('should pass markdownContentProps to MarkdownContent component', () => {
|
|
197
|
+
const titleText = '**Bold title**';
|
|
198
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolCall_1.default, { titleText: titleText, isTitleMarkdown: true, markdownContentProps: { isPrimary: true } }));
|
|
199
|
+
expect(container.querySelector('.pf-m-primary')).toBeTruthy();
|
|
200
|
+
});
|
|
170
201
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CardBodyProps, CardProps, CardTitleProps, DividerProps, ExpandableSectionProps } from '@patternfly/react-core';
|
|
2
2
|
import { type FunctionComponent } from 'react';
|
|
3
|
+
import type { MarkdownContentProps } from '../MarkdownContent';
|
|
3
4
|
export interface ToolResponseProps {
|
|
4
5
|
/** Toggle content shown for expandable section */
|
|
5
6
|
toggleContent: React.ReactNode;
|
|
@@ -27,6 +28,20 @@ export interface ToolResponseProps {
|
|
|
27
28
|
toolResponseCardDividerProps?: DividerProps;
|
|
28
29
|
/** Additional props passed to tool response card title */
|
|
29
30
|
toolResponseCardTitleProps?: CardTitleProps;
|
|
31
|
+
/** Whether to enable markdown rendering for toggleContent. When true and toggleContent is a string, it will be parsed as markdown. */
|
|
32
|
+
isToggleContentMarkdown?: boolean;
|
|
33
|
+
/** Whether to enable markdown rendering for subheading. When true, subheading will be parsed as markdown. */
|
|
34
|
+
isSubheadingMarkdown?: boolean;
|
|
35
|
+
/** Whether to enable markdown rendering for body. When true and body is a string, it will be parsed as markdown. */
|
|
36
|
+
isBodyMarkdown?: boolean;
|
|
37
|
+
/** Whether to enable markdown rendering for cardBody. When true and cardBody is a string, it will be parsed as markdown. */
|
|
38
|
+
isCardBodyMarkdown?: boolean;
|
|
39
|
+
/** Whether to enable markdown rendering for cardTitle. When true and cardTitle is a string, it will be parsed as markdown. */
|
|
40
|
+
isCardTitleMarkdown?: boolean;
|
|
41
|
+
/** Props passed to MarkdownContent component when markdown is enabled */
|
|
42
|
+
markdownContentProps?: Omit<MarkdownContentProps, 'content'>;
|
|
43
|
+
/** Whether to retain styles in the MarkdownContent component. Defaults to false. */
|
|
44
|
+
shouldRetainStyles?: boolean;
|
|
30
45
|
}
|
|
31
46
|
export declare const ToolResponse: FunctionComponent<ToolResponseProps>;
|
|
32
47
|
export default ToolResponse;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.ToolResponse = void 0;
|
|
4
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
@@ -7,12 +10,55 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
7
10
|
// ============================================================================
|
|
8
11
|
const react_core_1 = require("@patternfly/react-core");
|
|
9
12
|
const react_1 = require("react");
|
|
10
|
-
const
|
|
13
|
+
const MarkdownContent_1 = __importDefault(require("../MarkdownContent"));
|
|
14
|
+
const ToolResponse = ({ body, cardProps, expandableSectionProps, subheading, cardBody, cardTitle, cardBodyProps, toggleContent, isDefaultExpanded = true, toolResponseCardBodyProps, toolResponseCardDividerProps, toolResponseCardProps, toolResponseCardTitleProps, isToggleContentMarkdown, isSubheadingMarkdown, isBodyMarkdown, isCardBodyMarkdown, isCardTitleMarkdown, markdownContentProps, shouldRetainStyles = false }) => {
|
|
11
15
|
const [isExpanded, setIsExpanded] = (0, react_1.useState)(isDefaultExpanded);
|
|
12
16
|
const onToggle = (_event, isExpanded) => {
|
|
13
17
|
setIsExpanded(isExpanded);
|
|
14
18
|
};
|
|
15
|
-
|
|
19
|
+
const renderToggleContent = () => {
|
|
20
|
+
if (isToggleContentMarkdown && typeof toggleContent === 'string') {
|
|
21
|
+
return ((0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: toggleContent }, markdownContentProps)));
|
|
22
|
+
}
|
|
23
|
+
return toggleContent;
|
|
24
|
+
};
|
|
25
|
+
const renderSubheading = () => {
|
|
26
|
+
if (!subheading) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (isSubheadingMarkdown) {
|
|
30
|
+
return (0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: subheading }, markdownContentProps));
|
|
31
|
+
}
|
|
32
|
+
return subheading;
|
|
33
|
+
};
|
|
34
|
+
const renderBody = () => {
|
|
35
|
+
if (!body) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (isBodyMarkdown && typeof body === 'string') {
|
|
39
|
+
return (0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: body }, markdownContentProps));
|
|
40
|
+
}
|
|
41
|
+
return body;
|
|
42
|
+
};
|
|
43
|
+
const renderCardTitle = () => {
|
|
44
|
+
if (!cardTitle) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (isCardTitleMarkdown && typeof cardTitle === 'string') {
|
|
48
|
+
return (0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: cardTitle }, markdownContentProps));
|
|
49
|
+
}
|
|
50
|
+
return cardTitle;
|
|
51
|
+
};
|
|
52
|
+
const renderCardBody = () => {
|
|
53
|
+
if (!cardBody) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (isCardBodyMarkdown && typeof cardBody === 'string') {
|
|
57
|
+
return (0, jsx_runtime_1.jsx)(MarkdownContent_1.default, Object.assign({ shouldRetainStyles: shouldRetainStyles, content: cardBody }, markdownContentProps));
|
|
58
|
+
}
|
|
59
|
+
return cardBody;
|
|
60
|
+
};
|
|
61
|
+
return ((0, jsx_runtime_1.jsx)(react_core_1.Card, Object.assign({ isCompact: true, className: "pf-chatbot__tool-response" }, cardProps, { children: (0, jsx_runtime_1.jsx)(react_core_1.CardBody, Object.assign({}, cardBodyProps, { children: (0, jsx_runtime_1.jsx)(react_core_1.ExpandableSection, Object.assign({ toggleContent: renderToggleContent(), onToggle: onToggle, isExpanded: isExpanded, isIndented: true, className: "pf-chatbot__tool-response-expandable-section" }, expandableSectionProps, { children: (0, jsx_runtime_1.jsxs)("div", { className: "pf-chatbot__tool-response-section", children: [subheading && ((0, jsx_runtime_1.jsx)("div", { className: "pf-chatbot__tool-response-subheading", children: (0, jsx_runtime_1.jsx)("span", { children: renderSubheading() }) })), body && (0, jsx_runtime_1.jsx)("div", { className: "pf-chatbot__tool-response-body", children: renderBody() }), (cardTitle || cardBody) && ((0, jsx_runtime_1.jsxs)(react_core_1.Card, Object.assign({ isCompact: true, className: "pf-chatbot__tool-response-card" }, toolResponseCardProps, { children: [cardTitle && (0, jsx_runtime_1.jsx)(react_core_1.CardTitle, Object.assign({}, toolResponseCardTitleProps, { children: renderCardTitle() })), cardTitle && cardBody && (0, jsx_runtime_1.jsx)(react_core_1.Divider, Object.assign({}, toolResponseCardDividerProps)), cardBody && (0, jsx_runtime_1.jsx)(react_core_1.CardBody, Object.assign({}, toolResponseCardBodyProps, { children: renderCardBody() }))] })))] }) })) })) })));
|
|
16
62
|
};
|
|
17
63
|
exports.ToolResponse = ToolResponse;
|
|
18
64
|
exports.default = exports.ToolResponse;
|
|
@@ -121,4 +121,64 @@ describe('ToolResponse', () => {
|
|
|
121
121
|
expect(react_1.screen.getByText(defaultProps.cardTitle)).not.toBeVisible();
|
|
122
122
|
expect(react_1.screen.getByText(defaultProps.cardBody)).not.toBeVisible();
|
|
123
123
|
}));
|
|
124
|
+
it('should render toggleContent as markdown when isToggleContentMarkdown is true', () => {
|
|
125
|
+
const toggleContent = '**Bold toggle**';
|
|
126
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { toggleContent: toggleContent, isToggleContentMarkdown: true })));
|
|
127
|
+
expect(container.querySelector('strong')).toBeTruthy();
|
|
128
|
+
expect(react_1.screen.getByText('Bold toggle')).toBeTruthy();
|
|
129
|
+
});
|
|
130
|
+
it('should not render toggleContent as markdown when isToggleContentMarkdown is false', () => {
|
|
131
|
+
const toggleContent = '**Bold toggle**';
|
|
132
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { toggleContent: toggleContent })));
|
|
133
|
+
expect(react_1.screen.getByText('**Bold toggle**')).toBeTruthy();
|
|
134
|
+
});
|
|
135
|
+
it('should render subheading as markdown when isSubheadingMarkdown is true', () => {
|
|
136
|
+
const subheading = '**Bold subheading**';
|
|
137
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { subheading: subheading, isSubheadingMarkdown: true })));
|
|
138
|
+
expect(container.querySelector('strong')).toBeTruthy();
|
|
139
|
+
expect(react_1.screen.getByText('Bold subheading')).toBeTruthy();
|
|
140
|
+
});
|
|
141
|
+
it('should not render subheading as markdown when isSubheadingMarkdown is false', () => {
|
|
142
|
+
const subheading = '**Bold subheading**';
|
|
143
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { subheading: subheading })));
|
|
144
|
+
expect(react_1.screen.getByText('**Bold subheading**')).toBeTruthy();
|
|
145
|
+
});
|
|
146
|
+
it('should render body as markdown when isBodyMarkdown is true', () => {
|
|
147
|
+
const body = '**Bold body**';
|
|
148
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { body: body, isBodyMarkdown: true })));
|
|
149
|
+
expect(container.querySelector('strong')).toBeTruthy();
|
|
150
|
+
expect(react_1.screen.getByText('Bold body')).toBeTruthy();
|
|
151
|
+
});
|
|
152
|
+
it('should not render body as markdown when isBodyMarkdown is false', () => {
|
|
153
|
+
const body = '**Bold body**';
|
|
154
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { body: body })));
|
|
155
|
+
expect(react_1.screen.getByText('**Bold body**')).toBeTruthy();
|
|
156
|
+
});
|
|
157
|
+
it('should render cardTitle as markdown when isCardTitleMarkdown is true', () => {
|
|
158
|
+
const cardTitle = '**Bold card title**';
|
|
159
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardTitle: cardTitle, isCardTitleMarkdown: true })));
|
|
160
|
+
expect(container.querySelector('strong')).toBeTruthy();
|
|
161
|
+
expect(react_1.screen.getByText('Bold card title')).toBeTruthy();
|
|
162
|
+
});
|
|
163
|
+
it('should not render cardTitle as markdown when isCardTitleMarkdown is false', () => {
|
|
164
|
+
const cardTitle = '**Bold card title**';
|
|
165
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardTitle: cardTitle })));
|
|
166
|
+
expect(react_1.screen.getByText('**Bold card title**')).toBeTruthy();
|
|
167
|
+
});
|
|
168
|
+
it('should render cardBody as markdown when isCardBodyMarkdown is true', () => {
|
|
169
|
+
const cardBody = '**Bold card body**';
|
|
170
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardBody: cardBody, isCardBodyMarkdown: true })));
|
|
171
|
+
expect(container.querySelector('strong')).toBeTruthy();
|
|
172
|
+
expect(react_1.screen.getByText('Bold card body')).toBeTruthy();
|
|
173
|
+
});
|
|
174
|
+
it('should not render cardBody as markdown when isCardBodyMarkdown is false', () => {
|
|
175
|
+
const cardBody = '**Bold card body**';
|
|
176
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { cardBody: cardBody })));
|
|
177
|
+
expect(react_1.screen.getByText('**Bold card body**')).toBeTruthy();
|
|
178
|
+
});
|
|
179
|
+
it('should pass markdownContentProps to MarkdownContent component', () => {
|
|
180
|
+
const body = '**Bold body**';
|
|
181
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(ToolResponse_1.default, Object.assign({}, defaultProps, { body: body, isBodyMarkdown: true, markdownContentProps: { isPrimary: true } })));
|
|
182
|
+
expect(container.querySelector('.pf-m-primary')).toBeTruthy();
|
|
183
|
+
});
|
|
124
184
|
});
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ export { default as ImagePreview } from './ImagePreview';
|
|
|
40
40
|
export * from './ImagePreview';
|
|
41
41
|
export { default as LoadingMessage } from './LoadingMessage';
|
|
42
42
|
export * from './LoadingMessage';
|
|
43
|
+
export { default as MarkdownContent } from './MarkdownContent';
|
|
44
|
+
export * from './MarkdownContent';
|
|
43
45
|
export { default as Message } from './Message';
|
|
44
46
|
export * from './Message';
|
|
45
47
|
export { default as MessageBar } from './MessageBar';
|