@patternfly/chatbot 6.4.0-prerelease.21 → 6.4.0-prerelease.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/cjs/Message/Message.d.ts +3 -0
  2. package/dist/cjs/Message/Message.js +3 -2
  3. package/dist/cjs/ToolCall/ToolCall.d.ts +44 -0
  4. package/dist/cjs/ToolCall/ToolCall.js +14 -0
  5. package/dist/cjs/ToolCall/ToolCall.test.d.ts +1 -0
  6. package/dist/cjs/ToolCall/ToolCall.test.js +144 -0
  7. package/dist/cjs/ToolCall/index.d.ts +2 -0
  8. package/dist/cjs/ToolCall/index.js +23 -0
  9. package/dist/cjs/index.d.ts +2 -0
  10. package/dist/cjs/index.js +4 -1
  11. package/dist/css/main.css +29 -0
  12. package/dist/css/main.css.map +1 -1
  13. package/dist/dynamic/ToolCall/package.json +1 -0
  14. package/dist/esm/Message/Message.d.ts +3 -0
  15. package/dist/esm/Message/Message.js +3 -2
  16. package/dist/esm/ToolCall/ToolCall.d.ts +44 -0
  17. package/dist/esm/ToolCall/ToolCall.js +10 -0
  18. package/dist/esm/ToolCall/ToolCall.test.d.ts +1 -0
  19. package/dist/esm/ToolCall/ToolCall.test.js +139 -0
  20. package/dist/esm/ToolCall/index.d.ts +2 -0
  21. package/dist/esm/ToolCall/index.js +2 -0
  22. package/dist/esm/index.d.ts +2 -0
  23. package/dist/esm/index.js +2 -0
  24. package/dist/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +1 -1
  26. package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithToolCall.tsx +45 -0
  27. package/patternfly-docs/content/extensions/chatbot/examples/Messages/Messages.md +10 -0
  28. package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md +1 -1
  29. package/src/Message/Message.tsx +5 -0
  30. package/src/ToolCall/ToolCall.scss +37 -0
  31. package/src/ToolCall/ToolCall.test.tsx +184 -0
  32. package/src/ToolCall/ToolCall.tsx +147 -0
  33. package/src/ToolCall/index.ts +3 -0
  34. package/src/index.ts +3 -0
  35. package/src/main.scss +1 -0
@@ -0,0 +1,147 @@
1
+ import { type FunctionComponent } from 'react';
2
+ import {
3
+ ActionList,
4
+ ActionListProps,
5
+ ActionListGroup,
6
+ ActionListGroupProps,
7
+ ActionListItem,
8
+ ActionListItemProps,
9
+ Button,
10
+ ButtonProps,
11
+ Card,
12
+ CardProps,
13
+ CardBody,
14
+ CardBodyProps,
15
+ CardFooter,
16
+ CardFooterProps,
17
+ ExpandableSection,
18
+ ExpandableSectionProps,
19
+ Spinner,
20
+ SpinnerProps
21
+ } from '@patternfly/react-core';
22
+
23
+ export interface ToolCallProps {
24
+ /** Title text for the tool call. */
25
+ titleText: string;
26
+ /** Loading text for the tool call. */
27
+ loadingText?: string;
28
+ /** Flag indicating whether the tool call is loading or not. */
29
+ isLoading?: boolean;
30
+ /** Additional props for the spinner that is rendered when isLoading is true. */
31
+ spinnerProps?: SpinnerProps;
32
+ /** Content to render within an expandable section. */
33
+ expandableContent?: React.ReactNode;
34
+ /** Text content for the "run" action button. */
35
+ runButtonText?: string;
36
+ /** Additional props for the "run" action button. */
37
+ runButtonProps?: ButtonProps;
38
+ /** Additional props for the "run" action list item. */
39
+ runActionItemProps?: ActionListItemProps;
40
+ /** Text content for the "cancel" action button. */
41
+ cancelButtonText?: string;
42
+ /** Additional props for the "cancel" action button. */
43
+ cancelButtonProps?: ButtonProps;
44
+ /** Additional props for the "cancel" action list item. */
45
+ cancelActionItemProps?: ActionListItemProps;
46
+ /** Custom actions to render, typically a "cancel" and "run" action. This will override the default actions. */
47
+ actions?: React.ReactNode[];
48
+ /** Additional props for the action list */
49
+ actionListProps?: ActionListProps;
50
+ /** Additional props for the action list group. */
51
+ actionListGroupProps?: ActionListGroupProps;
52
+ /** Additional props for all action list items. */
53
+ actionListItemProps?: ActionListItemProps;
54
+ /** Additional props for the card. */
55
+ cardProps?: CardProps;
56
+ /** Additional props for the card body that contains the main tool call content. */
57
+ cardBodyProps?: CardBodyProps;
58
+ /** Additional props for the card footer that contains the tool call actions. */
59
+ cardFooterProps?: CardFooterProps;
60
+ /** Additional props for the expandable section when expandableContent is passed. */
61
+ expandableSectionProps?: Omit<ExpandableSectionProps, 'ref'>;
62
+ }
63
+
64
+ export const ToolCall: FunctionComponent<ToolCallProps> = ({
65
+ titleText,
66
+ loadingText,
67
+ isLoading,
68
+ expandableContent,
69
+ runButtonText = 'Run tool',
70
+ runButtonProps,
71
+ runActionItemProps,
72
+ cancelButtonText = 'Cancel',
73
+ cancelButtonProps,
74
+ cancelActionItemProps,
75
+ actions,
76
+ actionListProps,
77
+ actionListGroupProps,
78
+ actionListItemProps,
79
+ cardProps,
80
+ cardBodyProps,
81
+ cardFooterProps,
82
+ expandableSectionProps,
83
+ spinnerProps
84
+ }: ToolCallProps) => {
85
+ const titleContent = (
86
+ <span className={`pf-chatbot__tool-call-title-content`}>
87
+ {isLoading ? (
88
+ <>
89
+ <Spinner diameter="1em" {...spinnerProps} />{' '}
90
+ {<span className="pf-chatbot__tool-call-title-text">{loadingText}</span>}
91
+ </>
92
+ ) : (
93
+ <span className="pf-chatbot__tool-call-title-text">{titleText}</span>
94
+ )}
95
+ </span>
96
+ );
97
+ const defaultActions = (
98
+ <>
99
+ <ActionListItem {...actionListItemProps} {...cancelActionItemProps}>
100
+ <Button variant="link" {...cancelButtonProps}>
101
+ {cancelButtonText}
102
+ </Button>
103
+ </ActionListItem>
104
+ <ActionListItem {...actionListItemProps} {...runActionItemProps}>
105
+ <Button variant="secondary" {...runButtonProps}>
106
+ {runButtonText}
107
+ </Button>
108
+ </ActionListItem>
109
+ </>
110
+ );
111
+
112
+ const customActions =
113
+ actions &&
114
+ actions.map((action, index) => (
115
+ <ActionListItem key={index} {...actionListItemProps}>
116
+ {action}
117
+ </ActionListItem>
118
+ ));
119
+
120
+ return (
121
+ <Card isCompact className="pf-chatbot__tool-call" {...cardProps}>
122
+ <CardBody className="pf-chatbot__tool-call-title" {...cardBodyProps}>
123
+ {expandableContent && !isLoading ? (
124
+ <ExpandableSection
125
+ className="pf-chatbot__tool-call-expandable-section"
126
+ toggleContent={titleContent}
127
+ isIndented
128
+ {...expandableSectionProps}
129
+ >
130
+ {expandableContent}
131
+ </ExpandableSection>
132
+ ) : (
133
+ titleContent
134
+ )}
135
+ </CardBody>
136
+ {!isLoading && (
137
+ <CardFooter {...cardFooterProps}>
138
+ <ActionList className="pf-chatbot__tool-call-action-list" {...actionListProps}>
139
+ <ActionListGroup {...actionListGroupProps}>{customActions || defaultActions}</ActionListGroup>
140
+ </ActionList>
141
+ </CardFooter>
142
+ )}
143
+ </Card>
144
+ );
145
+ };
146
+
147
+ export default ToolCall;
@@ -0,0 +1,3 @@
1
+ export { default } from './ToolCall';
2
+
3
+ export * from './ToolCall';
package/src/index.ts CHANGED
@@ -96,5 +96,8 @@ export * from './TermsOfUse';
96
96
  export { default as ToolResponse } from './ToolResponse';
97
97
  export * from './ToolResponse';
98
98
 
99
+ export { default as ToolCall } from './ToolCall';
100
+ export * from './ToolCall';
101
+
99
102
  export { default as tracking } from './tracking';
100
103
  export * from './tracking';
package/src/main.scss CHANGED
@@ -37,6 +37,7 @@
37
37
  @import './SourceDetailsMenuItem/SourceDetailsMenuItem';
38
38
  @import './TermsOfUse/TermsOfUse';
39
39
  @import './ToolResponse/ToolResponse';
40
+ @import './ToolCall/ToolCall';
40
41
 
41
42
  .ws-full-page-utils {
42
43
  left: 0 !important;