@copilotkit/react-ui 1.7.2-next.1 → 1.8.0-next.3
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/CHANGELOG.md +21 -0
- package/dist/{chunk-QXTRFMPM.mjs → chunk-2LRE4W6A.mjs} +13 -11
- package/dist/chunk-2LRE4W6A.mjs.map +1 -0
- package/dist/{chunk-2C3ANQCY.mjs → chunk-5GNYGURH.mjs} +53 -42
- package/dist/chunk-5GNYGURH.mjs.map +1 -0
- package/dist/{chunk-CBBFRI3Q.mjs → chunk-5JY5QJ2W.mjs} +9 -5
- package/dist/chunk-5JY5QJ2W.mjs.map +1 -0
- package/dist/{chunk-OFYI4UU4.mjs → chunk-7RIBDD4K.mjs} +19 -3
- package/dist/chunk-7RIBDD4K.mjs.map +1 -0
- package/dist/{chunk-YAGE7RCE.mjs → chunk-CGVOCLHN.mjs} +2 -2
- package/dist/chunk-EJG6RRSX.mjs +138 -0
- package/dist/chunk-EJG6RRSX.mjs.map +1 -0
- package/dist/chunk-FBYETUFL.mjs +118 -0
- package/dist/chunk-FBYETUFL.mjs.map +1 -0
- package/dist/chunk-GDJAAFIK.mjs +24 -0
- package/dist/chunk-GDJAAFIK.mjs.map +1 -0
- package/dist/{chunk-6FTRYYR5.mjs → chunk-GJME6MK4.mjs} +72 -62
- package/dist/chunk-GJME6MK4.mjs.map +1 -0
- package/dist/{chunk-AZU4QOV5.mjs → chunk-KG6DW6R2.mjs} +12 -12
- package/dist/{chunk-3PJA5MFR.mjs → chunk-LKCAF2HG.mjs} +2 -2
- package/dist/{chunk-ADTTDBLB.mjs → chunk-LXCH2BIB.mjs} +2 -2
- package/dist/chunk-MCO235PS.mjs +164 -0
- package/dist/chunk-MCO235PS.mjs.map +1 -0
- package/dist/chunk-MWC5OV7Z.mjs +1 -0
- package/dist/chunk-N7LTE54T.mjs +1 -0
- package/dist/chunk-N7LTE54T.mjs.map +1 -0
- package/dist/chunk-ORSMX3SE.mjs +244 -0
- package/dist/chunk-ORSMX3SE.mjs.map +1 -0
- package/dist/{chunk-UPTB2MVO.mjs → chunk-PCTCOQK2.mjs} +4 -10
- package/dist/chunk-PCTCOQK2.mjs.map +1 -0
- package/dist/{chunk-22K5DDPF.mjs → chunk-QGK5GOSC.mjs} +31 -60
- package/dist/chunk-QGK5GOSC.mjs.map +1 -0
- package/dist/{chunk-WGAZXTUA.mjs → chunk-TOQ7P4DO.mjs} +6 -9
- package/dist/chunk-TOQ7P4DO.mjs.map +1 -0
- package/dist/chunk-UCVCAGU7.mjs +1 -0
- package/dist/chunk-UCVCAGU7.mjs.map +1 -0
- package/dist/{chunk-3XAXY2Z3.mjs → chunk-UZTZXMYS.mjs} +2 -2
- package/dist/{chunk-RQNJNK2W.mjs → chunk-VC4NO5QZ.mjs} +2 -2
- package/dist/{chunk-YQ3D5IQV.mjs → chunk-XNQO5AZZ.mjs} +2 -5
- package/dist/chunk-XNQO5AZZ.mjs.map +1 -0
- package/dist/chunk-YC4NBUGE.mjs +97 -0
- package/dist/chunk-YC4NBUGE.mjs.map +1 -0
- package/dist/components/chat/Button.js.map +1 -1
- package/dist/components/chat/Button.mjs +3 -3
- package/dist/components/chat/Chat.d.ts +17 -1
- package/dist/components/chat/Chat.js +378 -905
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +12 -19
- package/dist/components/chat/ChatContext.d.ts +20 -0
- package/dist/components/chat/ChatContext.js +44 -74
- package/dist/components/chat/ChatContext.js.map +1 -1
- package/dist/components/chat/ChatContext.mjs +2 -2
- package/dist/components/chat/CodeBlock.js +58 -82
- package/dist/components/chat/CodeBlock.js.map +1 -1
- package/dist/components/chat/CodeBlock.mjs +2 -2
- package/dist/components/chat/Header.js +516 -4
- package/dist/components/chat/Header.js.map +1 -1
- package/dist/components/chat/Header.mjs +10 -3
- package/dist/components/chat/Icons.d.ts +10 -9
- package/dist/components/chat/Icons.js +125 -164
- package/dist/components/chat/Icons.js.map +1 -1
- package/dist/components/chat/Icons.mjs +9 -5
- package/dist/components/chat/Input.d.ts +1 -1
- package/dist/components/chat/Input.js +11 -9
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +3 -3
- package/dist/components/chat/Markdown.js +58 -56
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +3 -3
- package/dist/components/chat/Messages.d.ts +1 -1
- package/dist/components/chat/Messages.js +70 -60
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +3 -3
- package/dist/components/chat/Modal.js +1708 -1749
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +23 -23
- package/dist/components/chat/Popup.js +1708 -1749
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +24 -24
- package/dist/components/chat/Response.js.map +1 -1
- package/dist/components/chat/Response.mjs +3 -3
- package/dist/components/chat/Sidebar.js +1710 -1751
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +24 -24
- package/dist/components/chat/Suggestion.js +4 -40
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +2 -2
- package/dist/components/chat/Window.js.map +1 -1
- package/dist/components/chat/Window.mjs +3 -3
- package/dist/components/chat/index.js +1710 -1751
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +27 -27
- package/dist/components/chat/messages/AssistantMessage.js +211 -59
- package/dist/components/chat/messages/AssistantMessage.js.map +1 -1
- package/dist/components/chat/messages/AssistantMessage.mjs +5 -5
- package/dist/components/chat/messages/RenderTextMessage.js +18 -2
- package/dist/components/chat/messages/RenderTextMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderTextMessage.mjs +1 -1
- package/dist/components/chat/props.d.ts +53 -0
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/crew/DefaultResponseRenderer.d.ts +110 -0
- package/dist/components/crew/DefaultResponseRenderer.js +175 -0
- package/dist/components/crew/DefaultResponseRenderer.js.map +1 -0
- package/dist/components/crew/DefaultResponseRenderer.mjs +10 -0
- package/dist/components/crew/DefaultResponseRenderer.mjs.map +1 -0
- package/dist/components/crew/DefaultStateRenderer.d.ts +88 -0
- package/dist/components/crew/DefaultStateRenderer.js +198 -0
- package/dist/components/crew/DefaultStateRenderer.js.map +1 -0
- package/dist/components/crew/DefaultStateRenderer.mjs +8 -0
- package/dist/components/crew/DefaultStateRenderer.mjs.map +1 -0
- package/dist/components/crew/index.d.ts +4 -0
- package/dist/components/crew/index.js +335 -0
- package/dist/components/crew/index.js.map +1 -0
- package/dist/components/crew/index.mjs +16 -0
- package/dist/components/crew/index.mjs.map +1 -0
- package/dist/components/crew/types.d.ts +340 -0
- package/dist/components/crew/types.js +19 -0
- package/dist/components/crew/types.js.map +1 -0
- package/dist/components/crew/types.mjs +2 -0
- package/dist/components/crew/types.mjs.map +1 -0
- package/dist/components/dev-console/console.js +51 -233
- package/dist/components/dev-console/console.js.map +1 -1
- package/dist/components/dev-console/console.mjs +5 -5
- package/dist/components/dev-console/index.js +51 -233
- package/dist/components/dev-console/index.js.map +1 -1
- package/dist/components/dev-console/index.mjs +5 -5
- package/dist/components/help-modal/index.js +29 -147
- package/dist/components/help-modal/index.js.map +1 -1
- package/dist/components/help-modal/index.mjs +1 -1
- package/dist/components/help-modal/modal.js +29 -147
- package/dist/components/help-modal/modal.js.map +1 -1
- package/dist/components/help-modal/modal.mjs +1 -1
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +2191 -1942
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +43 -31
- package/dist/index.css +481 -90
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2192 -1943
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -31
- package/dist/types/css.d.ts +7 -1
- package/dist/types/css.js.map +1 -1
- package/package.json +4 -4
- package/src/components/chat/Chat.tsx +59 -22
- package/src/components/chat/ChatContext.tsx +29 -1
- package/src/components/chat/CodeBlock.tsx +2 -4
- package/src/components/chat/Header.tsx +8 -3
- package/src/components/chat/Icons.tsx +108 -108
- package/src/components/chat/Input.tsx +42 -38
- package/src/components/chat/Markdown.tsx +0 -3
- package/src/components/chat/Messages.tsx +68 -56
- package/src/components/chat/Suggestion.tsx +2 -3
- package/src/components/chat/messages/AssistantMessage.tsx +95 -3
- package/src/components/chat/messages/RenderTextMessage.tsx +17 -1
- package/src/components/chat/props.ts +66 -0
- package/src/components/crew/DefaultResponseRenderer.tsx +298 -0
- package/src/components/crew/DefaultStateRenderer.tsx +326 -0
- package/src/components/crew/index.ts +3 -0
- package/src/components/crew/types.ts +398 -0
- package/src/components/dev-console/console.tsx +16 -54
- package/src/components/help-modal/modal.tsx +38 -101
- package/src/components/index.ts +1 -0
- package/src/css/button.css +15 -4
- package/src/css/colors.css +27 -6
- package/src/css/console.css +46 -39
- package/src/css/crew.css +277 -0
- package/src/css/header.css +22 -5
- package/src/css/input.css +24 -17
- package/src/css/markdown.css +2 -1
- package/src/css/messages.css +125 -15
- package/src/css/panel.css +1 -0
- package/src/css/suggestions.css +14 -6
- package/src/styles.css +1 -0
- package/src/types/css.ts +7 -1
- package/dist/chunk-22K5DDPF.mjs.map +0 -1
- package/dist/chunk-2C3ANQCY.mjs.map +0 -1
- package/dist/chunk-3VNMQWGT.mjs +0 -25
- package/dist/chunk-3VNMQWGT.mjs.map +0 -1
- package/dist/chunk-6FTRYYR5.mjs.map +0 -1
- package/dist/chunk-CBBFRI3Q.mjs.map +0 -1
- package/dist/chunk-FZC7X5PK.mjs +0 -262
- package/dist/chunk-FZC7X5PK.mjs.map +0 -1
- package/dist/chunk-MMVDU6DF.mjs +0 -1
- package/dist/chunk-OFYI4UU4.mjs.map +0 -1
- package/dist/chunk-QXTRFMPM.mjs.map +0 -1
- package/dist/chunk-TI7SY2RI.mjs +0 -164
- package/dist/chunk-TI7SY2RI.mjs.map +0 -1
- package/dist/chunk-UPTB2MVO.mjs.map +0 -1
- package/dist/chunk-VEC45H6Q.mjs +0 -18
- package/dist/chunk-VEC45H6Q.mjs.map +0 -1
- package/dist/chunk-WGAZXTUA.mjs.map +0 -1
- package/dist/chunk-YQ3D5IQV.mjs.map +0 -1
- /package/dist/{chunk-YAGE7RCE.mjs.map → chunk-CGVOCLHN.mjs.map} +0 -0
- /package/dist/{chunk-AZU4QOV5.mjs.map → chunk-KG6DW6R2.mjs.map} +0 -0
- /package/dist/{chunk-3PJA5MFR.mjs.map → chunk-LKCAF2HG.mjs.map} +0 -0
- /package/dist/{chunk-ADTTDBLB.mjs.map → chunk-LXCH2BIB.mjs.map} +0 -0
- /package/dist/{chunk-MMVDU6DF.mjs.map → chunk-MWC5OV7Z.mjs.map} +0 -0
- /package/dist/{chunk-3XAXY2Z3.mjs.map → chunk-UZTZXMYS.mjs.map} +0 -0
- /package/dist/{chunk-RQNJNK2W.mjs.map → chunk-VC4NO5QZ.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/chat/messages/RenderTextMessage.tsx"],"sourcesContent":["import { RenderMessageProps } from \"../props\";\n\nexport function RenderTextMessage(props: RenderMessageProps) {\n const {
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/chat/messages/RenderTextMessage.tsx"],"sourcesContent":["import { RenderMessageProps } from \"../props\";\n\nexport function RenderTextMessage(props: RenderMessageProps) {\n const {\n message,\n inProgress,\n index,\n isCurrentMessage,\n UserMessage,\n AssistantMessage,\n onRegenerate,\n onCopy,\n onThumbsUp,\n onThumbsDown,\n } = props;\n\n if (message.isTextMessage()) {\n if (message.role === \"user\") {\n return (\n <UserMessage\n key={index}\n data-message-role=\"user\"\n message={message.content}\n rawData={message}\n />\n );\n } else if (message.role == \"assistant\") {\n return (\n <AssistantMessage\n key={index}\n data-message-role=\"assistant\"\n message={message.content}\n rawData={message}\n isLoading={inProgress && isCurrentMessage && !message.content}\n isGenerating={inProgress && isCurrentMessage && !!message.content}\n isCurrentMessage={isCurrentMessage}\n onRegenerate={onRegenerate}\n onCopy={onCopy}\n onThumbsUp={onThumbsUp}\n onThumbsDown={onThumbsDown}\n />\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBQ;AAjBD,SAAS,kBAAkB,OAA2B;AAC3D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,QAAQ,cAAc,GAAG;AAC3B,QAAI,QAAQ,SAAS,QAAQ;AAC3B,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,qBAAkB;AAAA,UAClB,SAAS,QAAQ;AAAA,UACjB,SAAS;AAAA;AAAA,QAHJ;AAAA,MAIP;AAAA,IAEJ,WAAW,QAAQ,QAAQ,aAAa;AACtC,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,qBAAkB;AAAA,UAClB,SAAS,QAAQ;AAAA,UACjB,SAAS;AAAA,UACT,WAAW,cAAc,oBAAoB,CAAC,QAAQ;AAAA,UACtD,cAAc,cAAc,oBAAoB,CAAC,CAAC,QAAQ;AAAA,UAC1D;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA;AAAA,QAVK;AAAA,MAWP;AAAA,IAEJ;AAAA,EACF;AACF;","names":[]}
|
|
@@ -27,6 +27,22 @@ interface MessagesProps {
|
|
|
27
27
|
RenderActionExecutionMessage: React.ComponentType<RenderMessageProps>;
|
|
28
28
|
RenderAgentStateMessage: React.ComponentType<RenderMessageProps>;
|
|
29
29
|
RenderResultMessage: React.ComponentType<RenderMessageProps>;
|
|
30
|
+
/**
|
|
31
|
+
* Callback function to regenerate the assistant's response
|
|
32
|
+
*/
|
|
33
|
+
onRegenerate?: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Callback function when the message is copied
|
|
36
|
+
*/
|
|
37
|
+
onCopy?: (message: string) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Callback function for thumbs up feedback
|
|
40
|
+
*/
|
|
41
|
+
onThumbsUp?: (message: string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Callback function for thumbs down feedback
|
|
44
|
+
*/
|
|
45
|
+
onThumbsDown?: (message: string) => void;
|
|
30
46
|
}
|
|
31
47
|
interface Renderer {
|
|
32
48
|
content: string;
|
|
@@ -40,6 +56,10 @@ interface AssistantMessageProps {
|
|
|
40
56
|
* The message content from the assistant
|
|
41
57
|
*/
|
|
42
58
|
message?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Indicates if this is the last message
|
|
61
|
+
*/
|
|
62
|
+
isCurrentMessage?: boolean;
|
|
43
63
|
/**
|
|
44
64
|
* The raw data from the assistant's response
|
|
45
65
|
*/
|
|
@@ -58,6 +78,22 @@ interface AssistantMessageProps {
|
|
|
58
78
|
* Whether a response is generating, this is when the LLM is actively generating and streaming content.
|
|
59
79
|
*/
|
|
60
80
|
isGenerating: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Callback function to regenerate the assistant's response
|
|
83
|
+
*/
|
|
84
|
+
onRegenerate?: () => void;
|
|
85
|
+
/**
|
|
86
|
+
* Callback function when the message is copied
|
|
87
|
+
*/
|
|
88
|
+
onCopy?: (message: string) => void;
|
|
89
|
+
/**
|
|
90
|
+
* Callback function for thumbs up feedback
|
|
91
|
+
*/
|
|
92
|
+
onThumbsUp?: (message: string) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Callback function for thumbs down feedback
|
|
95
|
+
*/
|
|
96
|
+
onThumbsDown?: (message: string) => void;
|
|
61
97
|
}
|
|
62
98
|
interface RenderMessageProps {
|
|
63
99
|
message: Message;
|
|
@@ -67,11 +103,28 @@ interface RenderMessageProps {
|
|
|
67
103
|
actionResult?: string;
|
|
68
104
|
AssistantMessage: React.ComponentType<AssistantMessageProps>;
|
|
69
105
|
UserMessage: React.ComponentType<UserMessageProps>;
|
|
106
|
+
/**
|
|
107
|
+
* Callback function to regenerate the assistant's response
|
|
108
|
+
*/
|
|
109
|
+
onRegenerate?: () => void;
|
|
110
|
+
/**
|
|
111
|
+
* Callback function when the message is copied
|
|
112
|
+
*/
|
|
113
|
+
onCopy?: (message: string) => void;
|
|
114
|
+
/**
|
|
115
|
+
* Callback function for thumbs up feedback
|
|
116
|
+
*/
|
|
117
|
+
onThumbsUp?: (message: string) => void;
|
|
118
|
+
/**
|
|
119
|
+
* Callback function for thumbs down feedback
|
|
120
|
+
*/
|
|
121
|
+
onThumbsDown?: (message: string) => void;
|
|
70
122
|
}
|
|
71
123
|
interface InputProps {
|
|
72
124
|
inProgress: boolean;
|
|
73
125
|
onSend: (text: string) => Promise<Message>;
|
|
74
126
|
isVisible?: boolean;
|
|
127
|
+
onStop?: () => void;
|
|
75
128
|
}
|
|
76
129
|
interface ResponseButtonProps {
|
|
77
130
|
onClick: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/chat/props.ts"],"sourcesContent":["import { Message } from \"@copilotkit/runtime-client-gql\";\n\nexport interface ButtonProps {}\n\nexport interface WindowProps {\n clickOutsideToClose: boolean;\n hitEscapeToClose: boolean;\n shortcut: string;\n children?: React.ReactNode;\n}\n\nexport interface HeaderProps {}\n\nexport interface SuggestionsProps {\n title: string;\n message: string;\n partial?: boolean;\n className?: string;\n onClick: (message: string) => void;\n}\n\nexport interface MessagesProps {\n messages: Message[];\n inProgress: boolean;\n children?: React.ReactNode;\n AssistantMessage: React.ComponentType<AssistantMessageProps>;\n UserMessage: React.ComponentType<UserMessageProps>;\n RenderTextMessage: React.ComponentType<RenderMessageProps>;\n RenderActionExecutionMessage: React.ComponentType<RenderMessageProps>;\n RenderAgentStateMessage: React.ComponentType<RenderMessageProps>;\n RenderResultMessage: React.ComponentType<RenderMessageProps>;\n}\n\nexport interface Renderer {\n content: string;\n}\n\nexport interface UserMessageProps {\n message?: string;\n rawData: any;\n}\n\nexport interface AssistantMessageProps {\n /**\n * The message content from the assistant\n */\n\n message?: string;\n\n /**\n * The raw data from the assistant's response\n */\n rawData: any;\n\n /**\n * A component that was decided to render by the LLM.\n * When working with useCopilotActions and useCoAgentStateRender, this will be\n * the render component that was specified.\n */\n subComponent?: React.JSX.Element;\n\n /**\n * Whether a response is loading, this is when the LLM is thinking of a response but hasn't finished yet.\n */\n isLoading: boolean;\n\n /**\n * Whether a response is generating, this is when the LLM is actively generating and streaming content.\n */\n isGenerating: boolean;\n}\n\nexport interface RenderMessageProps {\n message: Message;\n inProgress: boolean;\n index: number;\n isCurrentMessage: boolean;\n actionResult?: string;\n AssistantMessage: React.ComponentType<AssistantMessageProps>;\n UserMessage: React.ComponentType<UserMessageProps>;\n}\n\nexport interface InputProps {\n inProgress: boolean;\n onSend: (text: string) => Promise<Message>;\n isVisible?: boolean;\n}\n\nexport interface ResponseButtonProps {\n onClick: () => void;\n inProgress: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/chat/props.ts"],"sourcesContent":["import { Message } from \"@copilotkit/runtime-client-gql\";\n\nexport interface ButtonProps {}\n\nexport interface WindowProps {\n clickOutsideToClose: boolean;\n hitEscapeToClose: boolean;\n shortcut: string;\n children?: React.ReactNode;\n}\n\nexport interface HeaderProps {}\n\nexport interface SuggestionsProps {\n title: string;\n message: string;\n partial?: boolean;\n className?: string;\n onClick: (message: string) => void;\n}\n\nexport interface MessagesProps {\n messages: Message[];\n inProgress: boolean;\n children?: React.ReactNode;\n AssistantMessage: React.ComponentType<AssistantMessageProps>;\n UserMessage: React.ComponentType<UserMessageProps>;\n RenderTextMessage: React.ComponentType<RenderMessageProps>;\n RenderActionExecutionMessage: React.ComponentType<RenderMessageProps>;\n RenderAgentStateMessage: React.ComponentType<RenderMessageProps>;\n RenderResultMessage: React.ComponentType<RenderMessageProps>;\n\n /**\n * Callback function to regenerate the assistant's response\n */\n onRegenerate?: () => void;\n\n /**\n * Callback function when the message is copied\n */\n onCopy?: (message: string) => void;\n\n /**\n * Callback function for thumbs up feedback\n */\n onThumbsUp?: (message: string) => void;\n\n /**\n * Callback function for thumbs down feedback\n */\n onThumbsDown?: (message: string) => void;\n}\n\nexport interface Renderer {\n content: string;\n}\n\nexport interface UserMessageProps {\n message?: string;\n rawData: any;\n}\n\nexport interface AssistantMessageProps {\n /**\n * The message content from the assistant\n */\n\n message?: string;\n\n /**\n * Indicates if this is the last message\n */\n isCurrentMessage?: boolean;\n\n /**\n * The raw data from the assistant's response\n */\n rawData: any;\n\n /**\n * A component that was decided to render by the LLM.\n * When working with useCopilotActions and useCoAgentStateRender, this will be\n * the render component that was specified.\n */\n subComponent?: React.JSX.Element;\n\n /**\n * Whether a response is loading, this is when the LLM is thinking of a response but hasn't finished yet.\n */\n isLoading: boolean;\n\n /**\n * Whether a response is generating, this is when the LLM is actively generating and streaming content.\n */\n isGenerating: boolean;\n\n /**\n * Callback function to regenerate the assistant's response\n */\n onRegenerate?: () => void;\n\n /**\n * Callback function when the message is copied\n */\n onCopy?: (message: string) => void;\n\n /**\n * Callback function for thumbs up feedback\n */\n onThumbsUp?: (message: string) => void;\n\n /**\n * Callback function for thumbs down feedback\n */\n onThumbsDown?: (message: string) => void;\n}\n\nexport interface RenderMessageProps {\n message: Message;\n inProgress: boolean;\n index: number;\n isCurrentMessage: boolean;\n actionResult?: string;\n AssistantMessage: React.ComponentType<AssistantMessageProps>;\n UserMessage: React.ComponentType<UserMessageProps>;\n\n /**\n * Callback function to regenerate the assistant's response\n */\n onRegenerate?: () => void;\n\n /**\n * Callback function when the message is copied\n */\n onCopy?: (message: string) => void;\n\n /**\n * Callback function for thumbs up feedback\n */\n onThumbsUp?: (message: string) => void;\n\n /**\n * Callback function for thumbs down feedback\n */\n onThumbsDown?: (message: string) => void;\n}\n\nexport interface InputProps {\n inProgress: boolean;\n onSend: (text: string) => Promise<Message>;\n isVisible?: boolean;\n onStop?: () => void;\n}\n\nexport interface ResponseButtonProps {\n onClick: () => void;\n inProgress: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { ResponseRendererProps } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* <br/>
|
|
6
|
+
* A response renderer component for the CopilotKit framework. This component displays
|
|
7
|
+
* a response that may require user feedback, such as approving or rejecting a suggestion.
|
|
8
|
+
* It provides a flexible, customizable interface for rendering responses with user interaction.
|
|
9
|
+
*
|
|
10
|
+
* ## Install Dependencies
|
|
11
|
+
*
|
|
12
|
+
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
13
|
+
*
|
|
14
|
+
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
15
|
+
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* ## Usage
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { DefaultResponseRenderer } from "@copilotkit/react-ui";
|
|
22
|
+
* import "@copilotkit/react-ui/styles.css";
|
|
23
|
+
*
|
|
24
|
+
* // Basic usage
|
|
25
|
+
* <DefaultResponseRenderer
|
|
26
|
+
* response={{
|
|
27
|
+
* id: "response-1",
|
|
28
|
+
* content: "I've analyzed your data and found these insights..."
|
|
29
|
+
* }}
|
|
30
|
+
* status="inProgress"
|
|
31
|
+
* onRespond={(input) => console.log(`User responded: ${input}`)}
|
|
32
|
+
* />
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* ## Customization
|
|
36
|
+
*
|
|
37
|
+
* You can customize the appearance and behavior of the component:
|
|
38
|
+
*
|
|
39
|
+
* ```tsx
|
|
40
|
+
* // Custom labels and styling
|
|
41
|
+
* <DefaultResponseRenderer
|
|
42
|
+
* response={{
|
|
43
|
+
* id: "task-123",
|
|
44
|
+
* content: "Would you like to proceed with this recommendation?"
|
|
45
|
+
* }}
|
|
46
|
+
* status="inProgress"
|
|
47
|
+
* onRespond={handleResponse}
|
|
48
|
+
* labels={{
|
|
49
|
+
* responseLabel: "AI Recommendation",
|
|
50
|
+
* approveLabel: "Yes, proceed",
|
|
51
|
+
* rejectLabel: "No, cancel",
|
|
52
|
+
* approvedMessage: "Proceeding with recommendation",
|
|
53
|
+
* rejectedMessage: "Recommendation cancelled"
|
|
54
|
+
* }}
|
|
55
|
+
* className="my-custom-response"
|
|
56
|
+
* contentClassName="my-custom-content"
|
|
57
|
+
* buttonClassName="my-custom-button"
|
|
58
|
+
* />
|
|
59
|
+
*
|
|
60
|
+
* // Custom components
|
|
61
|
+
* <DefaultResponseRenderer
|
|
62
|
+
* response={{
|
|
63
|
+
* id: "task-456",
|
|
64
|
+
* content: "# Important Decision\nThis requires your approval"
|
|
65
|
+
* }}
|
|
66
|
+
* status="inProgress"
|
|
67
|
+
* onRespond={handleResponse}
|
|
68
|
+
* ContentRenderer={({ content, className }) => (
|
|
69
|
+
* <MyMarkdownRenderer content={content} className={className} />
|
|
70
|
+
* )}
|
|
71
|
+
* FeedbackButton={({ label, onClick, className }) => (
|
|
72
|
+
* <MyCustomButton label={label} onClick={onClick} className={className} />
|
|
73
|
+
* )}
|
|
74
|
+
* />
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* ### Look & Feel
|
|
78
|
+
*
|
|
79
|
+
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
80
|
+
* ```tsx title="YourRootComponent.tsx"
|
|
81
|
+
* ...
|
|
82
|
+
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
83
|
+
*
|
|
84
|
+
* export function YourRootComponent() {
|
|
85
|
+
* return (
|
|
86
|
+
* <CopilotKit>
|
|
87
|
+
* ...
|
|
88
|
+
* </CopilotKit>
|
|
89
|
+
* );
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
* For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Creates a cache for storing response feedback
|
|
97
|
+
*/
|
|
98
|
+
declare const createResponseCache: <T extends {
|
|
99
|
+
id: string;
|
|
100
|
+
}>() => {
|
|
101
|
+
getResponse: (id: string) => T | undefined;
|
|
102
|
+
setResponse: (id: string, response: T) => Map<string, T>;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Default response renderer component that handles rendering responses
|
|
106
|
+
* and collecting user feedback
|
|
107
|
+
*/
|
|
108
|
+
declare const DefaultResponseRenderer: React__default.FC<ResponseRendererProps>;
|
|
109
|
+
|
|
110
|
+
export { DefaultResponseRenderer, createResponseCache };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
|
|
37
|
+
// src/components/crew/DefaultResponseRenderer.tsx
|
|
38
|
+
var DefaultResponseRenderer_exports = {};
|
|
39
|
+
__export(DefaultResponseRenderer_exports, {
|
|
40
|
+
DefaultResponseRenderer: () => DefaultResponseRenderer,
|
|
41
|
+
createResponseCache: () => createResponseCache
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(DefaultResponseRenderer_exports);
|
|
44
|
+
var import_react = require("react");
|
|
45
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
46
|
+
var createResponseCache = () => {
|
|
47
|
+
const responseCache = /* @__PURE__ */ new Map();
|
|
48
|
+
return {
|
|
49
|
+
getResponse: (id) => responseCache.get(id),
|
|
50
|
+
setResponse: (id, response) => responseCache.set(id, response)
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
var useResponseCache = createResponseCache();
|
|
54
|
+
var DefaultExpandIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
55
|
+
"svg",
|
|
56
|
+
{
|
|
57
|
+
className,
|
|
58
|
+
width: "12",
|
|
59
|
+
height: "12",
|
|
60
|
+
viewBox: "0 0 24 24",
|
|
61
|
+
fill: "none",
|
|
62
|
+
stroke: "currentColor",
|
|
63
|
+
strokeWidth: "2",
|
|
64
|
+
strokeLinecap: "round",
|
|
65
|
+
strokeLinejoin: "round",
|
|
66
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "6 9 12 15 18 9" })
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
var DefaultCollapseIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
70
|
+
"svg",
|
|
71
|
+
{
|
|
72
|
+
className,
|
|
73
|
+
width: "12",
|
|
74
|
+
height: "12",
|
|
75
|
+
viewBox: "0 0 24 24",
|
|
76
|
+
fill: "none",
|
|
77
|
+
stroke: "currentColor",
|
|
78
|
+
strokeWidth: "2",
|
|
79
|
+
strokeLinecap: "round",
|
|
80
|
+
strokeLinejoin: "round",
|
|
81
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "18 15 12 9 6 15" })
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
var DefaultContentRenderer = ({ content, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: content });
|
|
85
|
+
var DefaultFeedbackButton = ({ label, onClick, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick, className, children: label });
|
|
86
|
+
var DefaultCompletedFeedback = ({ message, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: message }) });
|
|
87
|
+
var DefaultResponseRenderer = ({
|
|
88
|
+
response,
|
|
89
|
+
status,
|
|
90
|
+
onRespond,
|
|
91
|
+
icons,
|
|
92
|
+
labels,
|
|
93
|
+
ContentRenderer = DefaultContentRenderer,
|
|
94
|
+
FeedbackButton = DefaultFeedbackButton,
|
|
95
|
+
CompletedFeedback = DefaultCompletedFeedback,
|
|
96
|
+
className = "copilotkit-response",
|
|
97
|
+
contentClassName = "copilotkit-response-content",
|
|
98
|
+
actionsClassName = "copilotkit-response-actions",
|
|
99
|
+
buttonClassName = "copilotkit-response-button",
|
|
100
|
+
completedFeedbackClassName = "copilotkit-response-completed-feedback"
|
|
101
|
+
}) => {
|
|
102
|
+
const [isExpanded, setIsExpanded] = (0, import_react.useState)(true);
|
|
103
|
+
const defaultLabels = {
|
|
104
|
+
responseLabel: "Response",
|
|
105
|
+
approveLabel: "Approve",
|
|
106
|
+
rejectLabel: "Reject",
|
|
107
|
+
approvedMessage: "Approved",
|
|
108
|
+
rejectedMessage: "Rejected",
|
|
109
|
+
feedbackSubmittedMessage: "Feedback submitted"
|
|
110
|
+
};
|
|
111
|
+
const mergedLabels = __spreadValues(__spreadValues({}, defaultLabels), labels);
|
|
112
|
+
const renderFeedback = () => {
|
|
113
|
+
if (status === "complete") {
|
|
114
|
+
const cachedResponse = useResponseCache.getResponse(response.id);
|
|
115
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
116
|
+
CompletedFeedback,
|
|
117
|
+
{
|
|
118
|
+
message: (cachedResponse == null ? void 0 : cachedResponse.__feedback__) ? cachedResponse.__feedback__ === mergedLabels.approvedMessage ? mergedLabels.approvedMessage : mergedLabels.rejectedMessage : mergedLabels.feedbackSubmittedMessage,
|
|
119
|
+
className: completedFeedbackClassName
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (status === "inProgress" || status === "executing") {
|
|
124
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
125
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
126
|
+
FeedbackButton,
|
|
127
|
+
{
|
|
128
|
+
label: mergedLabels.approveLabel,
|
|
129
|
+
onClick: () => {
|
|
130
|
+
setIsExpanded(false);
|
|
131
|
+
onRespond == null ? void 0 : onRespond(mergedLabels.approveLabel);
|
|
132
|
+
useResponseCache.setResponse(response.id, __spreadProps(__spreadValues({}, response), {
|
|
133
|
+
__feedback__: mergedLabels.approvedMessage
|
|
134
|
+
}));
|
|
135
|
+
},
|
|
136
|
+
className: buttonClassName
|
|
137
|
+
}
|
|
138
|
+
),
|
|
139
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
140
|
+
FeedbackButton,
|
|
141
|
+
{
|
|
142
|
+
label: mergedLabels.rejectLabel,
|
|
143
|
+
onClick: () => {
|
|
144
|
+
setIsExpanded(false);
|
|
145
|
+
useResponseCache.setResponse(response.id, __spreadProps(__spreadValues({}, response), {
|
|
146
|
+
__feedback__: mergedLabels.rejectedMessage
|
|
147
|
+
}));
|
|
148
|
+
onRespond == null ? void 0 : onRespond(mergedLabels.rejectLabel);
|
|
149
|
+
},
|
|
150
|
+
className: buttonClassName
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
] });
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
};
|
|
157
|
+
const ExpandIcon = (icons == null ? void 0 : icons.expand) || DefaultExpandIcon;
|
|
158
|
+
const CollapseIcon = (icons == null ? void 0 : icons.collapse) || DefaultCollapseIcon;
|
|
159
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className, children: [
|
|
160
|
+
isExpanded && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContentRenderer, { content: response.content, className: contentClassName }),
|
|
161
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: actionsClassName, children: [
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "copilotkit-response-label", children: [
|
|
163
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => setIsExpanded(!isExpanded), className: "copilotkit-toggle-button", children: isExpanded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollapseIcon, { className: "copilotkit-icon" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ExpandIcon, { className: "copilotkit-icon" }) }),
|
|
164
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: mergedLabels.responseLabel })
|
|
165
|
+
] }),
|
|
166
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "copilotkit-response-buttons", children: renderFeedback() })
|
|
167
|
+
] })
|
|
168
|
+
] });
|
|
169
|
+
};
|
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
+
0 && (module.exports = {
|
|
172
|
+
DefaultResponseRenderer,
|
|
173
|
+
createResponseCache
|
|
174
|
+
});
|
|
175
|
+
//# sourceMappingURL=DefaultResponseRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/crew/DefaultResponseRenderer.tsx"],"sourcesContent":["/**\n * <br/>\n * A response renderer component for the CopilotKit framework. This component displays\n * a response that may require user feedback, such as approving or rejecting a suggestion.\n * It provides a flexible, customizable interface for rendering responses with user interaction.\n *\n * ## Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ## Usage\n *\n * ```tsx\n * import { DefaultResponseRenderer } from \"@copilotkit/react-ui\";\n * import \"@copilotkit/react-ui/styles.css\";\n *\n * // Basic usage\n * <DefaultResponseRenderer\n * response={{\n * id: \"response-1\",\n * content: \"I've analyzed your data and found these insights...\"\n * }}\n * status=\"inProgress\"\n * onRespond={(input) => console.log(`User responded: ${input}`)}\n * />\n * ```\n *\n * ## Customization\n *\n * You can customize the appearance and behavior of the component:\n *\n * ```tsx\n * // Custom labels and styling\n * <DefaultResponseRenderer\n * response={{\n * id: \"task-123\",\n * content: \"Would you like to proceed with this recommendation?\"\n * }}\n * status=\"inProgress\"\n * onRespond={handleResponse}\n * labels={{\n * responseLabel: \"AI Recommendation\",\n * approveLabel: \"Yes, proceed\",\n * rejectLabel: \"No, cancel\",\n * approvedMessage: \"Proceeding with recommendation\",\n * rejectedMessage: \"Recommendation cancelled\"\n * }}\n * className=\"my-custom-response\"\n * contentClassName=\"my-custom-content\"\n * buttonClassName=\"my-custom-button\"\n * />\n *\n * // Custom components\n * <DefaultResponseRenderer\n * response={{\n * id: \"task-456\",\n * content: \"# Important Decision\\nThis requires your approval\"\n * }}\n * status=\"inProgress\"\n * onRespond={handleResponse}\n * ContentRenderer={({ content, className }) => (\n * <MyMarkdownRenderer content={content} className={className} />\n * )}\n * FeedbackButton={({ label, onClick, className }) => (\n * <MyCustomButton label={label} onClick={onClick} className={className} />\n * )}\n * />\n * ```\n *\n * ### Look & Feel\n *\n * By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:\n * ```tsx title=\"YourRootComponent.tsx\"\n * ...\n * import \"@copilotkit/react-ui/styles.css\"; // [!code highlight]\n *\n * export function YourRootComponent() {\n * return (\n * <CopilotKit>\n * ...\n * </CopilotKit>\n * );\n * }\n * ```\n * For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.\n */\n\nimport React, { useState } from \"react\";\nimport {\n Response,\n ResponseRendererProps,\n ContentRendererProps,\n FeedbackButtonProps,\n CompletedFeedbackProps,\n ResponseRendererIconProps,\n} from \"./types\";\n\n/**\n * Creates a cache for storing response feedback\n */\nconst createResponseCache = <T extends { id: string }>() => {\n const responseCache = new Map<string, T>();\n\n return {\n getResponse: (id: string) => responseCache.get(id),\n setResponse: (id: string, response: T) => responseCache.set(id, response),\n };\n};\n\n/**\n * Default global response cache instance\n */\nconst useResponseCache = createResponseCache<Response & { __feedback__?: string }>();\n\n/**\n * Default expand icon component\n */\nconst DefaultExpandIcon: React.FC<ResponseRendererIconProps> = ({ className }) => (\n <svg\n className={className}\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <polyline points=\"6 9 12 15 18 9\"></polyline>\n </svg>\n);\n\n/**\n * Default collapse icon component\n */\nconst DefaultCollapseIcon: React.FC<ResponseRendererIconProps> = ({ className }) => (\n <svg\n className={className}\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <polyline points=\"18 15 12 9 6 15\"></polyline>\n </svg>\n);\n\n/**\n * Default content renderer that simply displays text\n */\nconst DefaultContentRenderer: React.FC<ContentRendererProps> = ({ content, className }) => (\n <div className={className}>{content}</div>\n);\n\n/**\n * Default feedback button component\n */\nconst DefaultFeedbackButton: React.FC<FeedbackButtonProps> = ({ label, onClick, className }) => (\n <button onClick={onClick} className={className}>\n {label}\n </button>\n);\n\n/**\n * Default completed feedback component\n */\nconst DefaultCompletedFeedback: React.FC<CompletedFeedbackProps> = ({ message, className }) => (\n <div className={className}>\n <span>{message}</span>\n </div>\n);\n\n/**\n * Default response renderer component that handles rendering responses\n * and collecting user feedback\n */\nexport const DefaultResponseRenderer: React.FC<ResponseRendererProps> = ({\n response,\n status,\n onRespond,\n icons,\n labels,\n ContentRenderer = DefaultContentRenderer,\n FeedbackButton = DefaultFeedbackButton,\n CompletedFeedback = DefaultCompletedFeedback,\n className = \"copilotkit-response\",\n contentClassName = \"copilotkit-response-content\",\n actionsClassName = \"copilotkit-response-actions\",\n buttonClassName = \"copilotkit-response-button\",\n completedFeedbackClassName = \"copilotkit-response-completed-feedback\",\n}) => {\n const [isExpanded, setIsExpanded] = useState(true);\n\n // Default label values\n const defaultLabels = {\n responseLabel: \"Response\",\n approveLabel: \"Approve\",\n rejectLabel: \"Reject\",\n approvedMessage: \"Approved\",\n rejectedMessage: \"Rejected\",\n feedbackSubmittedMessage: \"Feedback submitted\",\n };\n\n // Merge provided labels with defaults\n const mergedLabels = { ...defaultLabels, ...labels };\n\n // Function to render feedback UI based on status\n const renderFeedback = () => {\n if (status === \"complete\") {\n const cachedResponse = useResponseCache.getResponse(response.id);\n return (\n <CompletedFeedback\n message={\n cachedResponse?.__feedback__\n ? cachedResponse.__feedback__ === mergedLabels.approvedMessage\n ? mergedLabels.approvedMessage\n : mergedLabels.rejectedMessage\n : mergedLabels.feedbackSubmittedMessage\n }\n className={completedFeedbackClassName}\n />\n );\n }\n\n if (status === \"inProgress\" || status === \"executing\") {\n return (\n <>\n <FeedbackButton\n label={mergedLabels.approveLabel}\n onClick={() => {\n setIsExpanded(false);\n onRespond?.(mergedLabels.approveLabel);\n useResponseCache.setResponse(response.id, {\n ...response,\n __feedback__: mergedLabels.approvedMessage,\n });\n }}\n className={buttonClassName}\n />\n <FeedbackButton\n label={mergedLabels.rejectLabel}\n onClick={() => {\n setIsExpanded(false);\n useResponseCache.setResponse(response.id, {\n ...response,\n __feedback__: mergedLabels.rejectedMessage,\n });\n onRespond?.(mergedLabels.rejectLabel);\n }}\n className={buttonClassName}\n />\n </>\n );\n }\n\n return null;\n };\n\n // Decide which icon to display\n const ExpandIcon = icons?.expand || DefaultExpandIcon;\n const CollapseIcon = icons?.collapse || DefaultCollapseIcon;\n\n return (\n <div className={className}>\n {/* Response content - conditionally expanded */}\n {isExpanded && <ContentRenderer content={response.content} className={contentClassName} />}\n\n <div className={actionsClassName}>\n <div className=\"copilotkit-response-label\">\n <button onClick={() => setIsExpanded(!isExpanded)} className=\"copilotkit-toggle-button\">\n {isExpanded ? (\n <CollapseIcon className=\"copilotkit-icon\" />\n ) : (\n <ExpandIcon className=\"copilotkit-icon\" />\n )}\n </button>\n <span>{mergedLabels.responseLabel}</span>\n </div>\n\n <div className=\"copilotkit-response-buttons\">{renderFeedback()}</div>\n </div>\n </div>\n );\n};\n\n/**\n * Export the response cache for reuse\n */\nexport { createResponseCache };\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { StateRendererProps } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* <br/>
|
|
6
|
+
* A state renderer component for the CopilotKit framework. This component displays
|
|
7
|
+
* the internal state of an agent, such as the steps it has taken and the tasks it has performed.
|
|
8
|
+
* It provides a collapsible UI that shows the agent's thought process and actions.
|
|
9
|
+
*
|
|
10
|
+
* ## Install Dependencies
|
|
11
|
+
*
|
|
12
|
+
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
13
|
+
*
|
|
14
|
+
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
15
|
+
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* ## Usage
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { DefaultStateRenderer } from "@copilotkit/react-ui";
|
|
22
|
+
* import "@copilotkit/react-ui/styles.css";
|
|
23
|
+
*
|
|
24
|
+
* // Basic usage
|
|
25
|
+
* <DefaultStateRenderer
|
|
26
|
+
* state={agentState}
|
|
27
|
+
* status="inProgress"
|
|
28
|
+
* />
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* ## Customization
|
|
32
|
+
*
|
|
33
|
+
* You can customize the appearance and behavior of the component:
|
|
34
|
+
*
|
|
35
|
+
* ```tsx
|
|
36
|
+
* // Custom labels and styling
|
|
37
|
+
* <DefaultStateRenderer
|
|
38
|
+
* state={agentState}
|
|
39
|
+
* status="inProgress"
|
|
40
|
+
* labels={{
|
|
41
|
+
* inProgressLabel: "Thinking...",
|
|
42
|
+
* completeLabel: "Finished processing",
|
|
43
|
+
* emptyLabel: "Nothing to show"
|
|
44
|
+
* }}
|
|
45
|
+
* className="my-custom-state"
|
|
46
|
+
* contentClassName="my-custom-content"
|
|
47
|
+
* itemClassName="my-custom-item"
|
|
48
|
+
* maxHeight="300px"
|
|
49
|
+
* defaultCollapsed={false}
|
|
50
|
+
* />
|
|
51
|
+
*
|
|
52
|
+
* // Custom renderers
|
|
53
|
+
* <DefaultStateRenderer
|
|
54
|
+
* state={agentState}
|
|
55
|
+
* status="inProgress"
|
|
56
|
+
* StateItemRenderer={({ item, isNewest, className }) => (
|
|
57
|
+
* <MyCustomItemRenderer item={item} isNewest={isNewest} className={className} />
|
|
58
|
+
* )}
|
|
59
|
+
* SkeletonLoader={({ className }) => (
|
|
60
|
+
* <MyCustomSkeletonLoader className={className} />
|
|
61
|
+
* )}
|
|
62
|
+
* />
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* ### Look & Feel
|
|
66
|
+
*
|
|
67
|
+
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
68
|
+
* ```tsx title="YourRootComponent.tsx"
|
|
69
|
+
* ...
|
|
70
|
+
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
71
|
+
*
|
|
72
|
+
* export function YourRootComponent() {
|
|
73
|
+
* return (
|
|
74
|
+
* <CopilotKit>
|
|
75
|
+
* ...
|
|
76
|
+
* </CopilotKit>
|
|
77
|
+
* );
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
* For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Default state renderer component
|
|
85
|
+
*/
|
|
86
|
+
declare const DefaultStateRenderer: React__default.FC<StateRendererProps>;
|
|
87
|
+
|
|
88
|
+
export { DefaultStateRenderer };
|