@copilotkit/react-ui 1.7.2-next.0 → 1.7.2-next.2

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 (67) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/{chunk-AZU4QOV5.mjs → chunk-AELKLZSG.mjs} +5 -5
  3. package/dist/{chunk-3PJA5MFR.mjs → chunk-DLG7BZTA.mjs} +2 -2
  4. package/dist/chunk-EJG6RRSX.mjs +138 -0
  5. package/dist/chunk-EJG6RRSX.mjs.map +1 -0
  6. package/dist/chunk-MCO235PS.mjs +164 -0
  7. package/dist/chunk-MCO235PS.mjs.map +1 -0
  8. package/dist/chunk-MWC5OV7Z.mjs +1 -0
  9. package/dist/chunk-N7LTE54T.mjs +1 -0
  10. package/dist/chunk-N7LTE54T.mjs.map +1 -0
  11. package/dist/{chunk-2C3ANQCY.mjs → chunk-QXQDIFOC.mjs} +9 -9
  12. package/dist/{chunk-ADTTDBLB.mjs → chunk-R2O33F44.mjs} +2 -2
  13. package/dist/chunk-UCVCAGU7.mjs +1 -0
  14. package/dist/chunk-UCVCAGU7.mjs.map +1 -0
  15. package/dist/{chunk-22K5DDPF.mjs → chunk-ZIF5JJCH.mjs} +8 -8
  16. package/dist/components/chat/Chat.mjs +7 -7
  17. package/dist/components/chat/Modal.mjs +8 -8
  18. package/dist/components/chat/Popup.mjs +9 -9
  19. package/dist/components/chat/Sidebar.mjs +9 -9
  20. package/dist/components/chat/index.mjs +12 -12
  21. package/dist/components/crew/DefaultResponseRenderer.d.ts +110 -0
  22. package/dist/components/crew/DefaultResponseRenderer.js +175 -0
  23. package/dist/components/crew/DefaultResponseRenderer.js.map +1 -0
  24. package/dist/components/crew/DefaultResponseRenderer.mjs +10 -0
  25. package/dist/components/crew/DefaultResponseRenderer.mjs.map +1 -0
  26. package/dist/components/crew/DefaultStateRenderer.d.ts +88 -0
  27. package/dist/components/crew/DefaultStateRenderer.js +198 -0
  28. package/dist/components/crew/DefaultStateRenderer.js.map +1 -0
  29. package/dist/components/crew/DefaultStateRenderer.mjs +8 -0
  30. package/dist/components/crew/DefaultStateRenderer.mjs.map +1 -0
  31. package/dist/components/crew/index.d.ts +4 -0
  32. package/dist/components/crew/index.js +335 -0
  33. package/dist/components/crew/index.js.map +1 -0
  34. package/dist/components/crew/index.mjs +16 -0
  35. package/dist/components/crew/index.mjs.map +1 -0
  36. package/dist/components/crew/types.d.ts +340 -0
  37. package/dist/components/crew/types.js +19 -0
  38. package/dist/components/crew/types.js.map +1 -0
  39. package/dist/components/crew/types.mjs +2 -0
  40. package/dist/components/crew/types.mjs.map +1 -0
  41. package/dist/components/dev-console/console.mjs +3 -3
  42. package/dist/components/dev-console/index.mjs +4 -4
  43. package/dist/components/index.d.ts +3 -0
  44. package/dist/components/index.js +290 -0
  45. package/dist/components/index.js.map +1 -1
  46. package/dist/components/index.mjs +26 -14
  47. package/dist/index.css +227 -0
  48. package/dist/index.css.map +1 -1
  49. package/dist/index.d.ts +3 -0
  50. package/dist/index.js +292 -2
  51. package/dist/index.js.map +1 -1
  52. package/dist/index.mjs +26 -14
  53. package/package.json +4 -4
  54. package/src/components/crew/DefaultResponseRenderer.tsx +298 -0
  55. package/src/components/crew/DefaultStateRenderer.tsx +326 -0
  56. package/src/components/crew/index.ts +3 -0
  57. package/src/components/crew/types.ts +398 -0
  58. package/src/components/index.ts +1 -0
  59. package/src/css/crew.css +277 -0
  60. package/src/styles.css +1 -0
  61. package/dist/chunk-MMVDU6DF.mjs +0 -1
  62. /package/dist/{chunk-AZU4QOV5.mjs.map → chunk-AELKLZSG.mjs.map} +0 -0
  63. /package/dist/{chunk-3PJA5MFR.mjs.map → chunk-DLG7BZTA.mjs.map} +0 -0
  64. /package/dist/{chunk-MMVDU6DF.mjs.map → chunk-MWC5OV7Z.mjs.map} +0 -0
  65. /package/dist/{chunk-2C3ANQCY.mjs.map → chunk-QXQDIFOC.mjs.map} +0 -0
  66. /package/dist/{chunk-ADTTDBLB.mjs.map → chunk-R2O33F44.mjs.map} +0 -0
  67. /package/dist/{chunk-22K5DDPF.mjs.map → chunk-ZIF5JJCH.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,21 +1,34 @@
1
1
  "use client";
2
2
  import "./chunk-EFZPSZWO.mjs";
3
- import "./chunk-MMVDU6DF.mjs";
3
+ import "./chunk-MWC5OV7Z.mjs";
4
+ import "./chunk-UCVCAGU7.mjs";
5
+ import "./chunk-N7LTE54T.mjs";
4
6
  import "./chunk-SQMEPWVT.mjs";
5
7
  import {
6
8
  CopilotSidebar
7
- } from "./chunk-3PJA5MFR.mjs";
9
+ } from "./chunk-DLG7BZTA.mjs";
8
10
  import "./chunk-WB3YULQ4.mjs";
11
+ import {
12
+ DefaultResponseRenderer,
13
+ createResponseCache
14
+ } from "./chunk-EJG6RRSX.mjs";
15
+ import {
16
+ DefaultStateRenderer
17
+ } from "./chunk-MCO235PS.mjs";
9
18
  import {
10
19
  CopilotPopup
11
- } from "./chunk-ADTTDBLB.mjs";
12
- import "./chunk-AZU4QOV5.mjs";
20
+ } from "./chunk-R2O33F44.mjs";
21
+ import "./chunk-AELKLZSG.mjs";
13
22
  import "./chunk-YAGE7RCE.mjs";
14
23
  import "./chunk-VEC45H6Q.mjs";
15
24
  import "./chunk-RQNJNK2W.mjs";
16
25
  import {
17
26
  CopilotChat
18
- } from "./chunk-2C3ANQCY.mjs";
27
+ } from "./chunk-QXQDIFOC.mjs";
28
+ import {
29
+ AssistantMessage
30
+ } from "./chunk-3VNMQWGT.mjs";
31
+ import "./chunk-XB6QCUPB.mjs";
19
32
  import "./chunk-UWWMAJ7R.mjs";
20
33
  import "./chunk-WEYDZBT7.mjs";
21
34
  import "./chunk-OFYI4UU4.mjs";
@@ -23,21 +36,17 @@ import {
23
36
  UserMessage
24
37
  } from "./chunk-HEIDCT7I.mjs";
25
38
  import "./chunk-V7W6IM2V.mjs";
26
- import {
27
- AssistantMessage
28
- } from "./chunk-3VNMQWGT.mjs";
29
- import "./chunk-XB6QCUPB.mjs";
30
- import "./chunk-WGAZXTUA.mjs";
31
39
  import {
32
40
  CopilotDevConsole
33
- } from "./chunk-22K5DDPF.mjs";
41
+ } from "./chunk-ZIF5JJCH.mjs";
42
+ import "./chunk-KXE2JCUH.mjs";
43
+ import "./chunk-TI7SY2RI.mjs";
44
+ import "./chunk-OTPAZXVR.mjs";
34
45
  import {
35
46
  shouldShowDevConsole
36
47
  } from "./chunk-6TCUJ3B7.mjs";
37
- import "./chunk-KXE2JCUH.mjs";
38
- import "./chunk-TI7SY2RI.mjs";
39
48
  import "./chunk-BH6PCAAL.mjs";
40
- import "./chunk-OTPAZXVR.mjs";
49
+ import "./chunk-WGAZXTUA.mjs";
41
50
  import "./chunk-QXTRFMPM.mjs";
42
51
  import "./chunk-YQFVRDNC.mjs";
43
52
  import {
@@ -64,8 +73,11 @@ export {
64
73
  CopilotDevConsole,
65
74
  CopilotPopup,
66
75
  CopilotSidebar,
76
+ DefaultResponseRenderer,
77
+ DefaultStateRenderer,
67
78
  Markdown,
68
79
  UserMessage,
80
+ createResponseCache,
69
81
  shouldShowDevConsole,
70
82
  useChatContext,
71
83
  useCopilotChatSuggestions
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.7.2-next.0",
12
+ "version": "1.7.2-next.2",
13
13
  "sideEffects": [
14
14
  "**/*.css"
15
15
  ],
@@ -50,9 +50,9 @@
50
50
  "react-syntax-highlighter": "^15.5.0",
51
51
  "remark-gfm": "^3.0.1",
52
52
  "remark-math": "^5.1.1",
53
- "@copilotkit/react-core": "1.7.2-next.0",
54
- "@copilotkit/runtime-client-gql": "1.7.2-next.0",
55
- "@copilotkit/shared": "1.7.2-next.0"
53
+ "@copilotkit/react-core": "1.7.2-next.2",
54
+ "@copilotkit/runtime-client-gql": "1.7.2-next.2",
55
+ "@copilotkit/shared": "1.7.2-next.2"
56
56
  },
57
57
  "keywords": [
58
58
  "copilotkit",
@@ -0,0 +1,298 @@
1
+ /**
2
+ * <br/>
3
+ * A response renderer component for the CopilotKit framework. This component displays
4
+ * a response that may require user feedback, such as approving or rejecting a suggestion.
5
+ * It provides a flexible, customizable interface for rendering responses with user interaction.
6
+ *
7
+ * ## Install Dependencies
8
+ *
9
+ * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
10
+ *
11
+ * ```shell npm2yarn \"@copilotkit/react-ui"\
12
+ * npm install @copilotkit/react-core @copilotkit/react-ui
13
+ * ```
14
+ *
15
+ * ## Usage
16
+ *
17
+ * ```tsx
18
+ * import { DefaultResponseRenderer } from "@copilotkit/react-ui";
19
+ * import "@copilotkit/react-ui/styles.css";
20
+ *
21
+ * // Basic usage
22
+ * <DefaultResponseRenderer
23
+ * response={{
24
+ * id: "response-1",
25
+ * content: "I've analyzed your data and found these insights..."
26
+ * }}
27
+ * status="inProgress"
28
+ * onRespond={(input) => console.log(`User responded: ${input}`)}
29
+ * />
30
+ * ```
31
+ *
32
+ * ## Customization
33
+ *
34
+ * You can customize the appearance and behavior of the component:
35
+ *
36
+ * ```tsx
37
+ * // Custom labels and styling
38
+ * <DefaultResponseRenderer
39
+ * response={{
40
+ * id: "task-123",
41
+ * content: "Would you like to proceed with this recommendation?"
42
+ * }}
43
+ * status="inProgress"
44
+ * onRespond={handleResponse}
45
+ * labels={{
46
+ * responseLabel: "AI Recommendation",
47
+ * approveLabel: "Yes, proceed",
48
+ * rejectLabel: "No, cancel",
49
+ * approvedMessage: "Proceeding with recommendation",
50
+ * rejectedMessage: "Recommendation cancelled"
51
+ * }}
52
+ * className="my-custom-response"
53
+ * contentClassName="my-custom-content"
54
+ * buttonClassName="my-custom-button"
55
+ * />
56
+ *
57
+ * // Custom components
58
+ * <DefaultResponseRenderer
59
+ * response={{
60
+ * id: "task-456",
61
+ * content: "# Important Decision\nThis requires your approval"
62
+ * }}
63
+ * status="inProgress"
64
+ * onRespond={handleResponse}
65
+ * ContentRenderer={({ content, className }) => (
66
+ * <MyMarkdownRenderer content={content} className={className} />
67
+ * )}
68
+ * FeedbackButton={({ label, onClick, className }) => (
69
+ * <MyCustomButton label={label} onClick={onClick} className={className} />
70
+ * )}
71
+ * />
72
+ * ```
73
+ *
74
+ * ### Look & Feel
75
+ *
76
+ * By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
77
+ * ```tsx title="YourRootComponent.tsx"
78
+ * ...
79
+ * import "@copilotkit/react-ui/styles.css"; // [!code highlight]
80
+ *
81
+ * export function YourRootComponent() {
82
+ * return (
83
+ * <CopilotKit>
84
+ * ...
85
+ * </CopilotKit>
86
+ * );
87
+ * }
88
+ * ```
89
+ * 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.
90
+ */
91
+
92
+ import React, { useState } from "react";
93
+ import {
94
+ Response,
95
+ ResponseRendererProps,
96
+ ContentRendererProps,
97
+ FeedbackButtonProps,
98
+ CompletedFeedbackProps,
99
+ ResponseRendererIconProps,
100
+ } from "./types";
101
+
102
+ /**
103
+ * Creates a cache for storing response feedback
104
+ */
105
+ const createResponseCache = <T extends { id: string }>() => {
106
+ const responseCache = new Map<string, T>();
107
+
108
+ return {
109
+ getResponse: (id: string) => responseCache.get(id),
110
+ setResponse: (id: string, response: T) => responseCache.set(id, response),
111
+ };
112
+ };
113
+
114
+ /**
115
+ * Default global response cache instance
116
+ */
117
+ const useResponseCache = createResponseCache<Response & { __feedback__?: string }>();
118
+
119
+ /**
120
+ * Default expand icon component
121
+ */
122
+ const DefaultExpandIcon: React.FC<ResponseRendererIconProps> = ({ className }) => (
123
+ <svg
124
+ className={className}
125
+ width="12"
126
+ height="12"
127
+ viewBox="0 0 24 24"
128
+ fill="none"
129
+ stroke="currentColor"
130
+ strokeWidth="2"
131
+ strokeLinecap="round"
132
+ strokeLinejoin="round"
133
+ >
134
+ <polyline points="6 9 12 15 18 9"></polyline>
135
+ </svg>
136
+ );
137
+
138
+ /**
139
+ * Default collapse icon component
140
+ */
141
+ const DefaultCollapseIcon: React.FC<ResponseRendererIconProps> = ({ className }) => (
142
+ <svg
143
+ className={className}
144
+ width="12"
145
+ height="12"
146
+ viewBox="0 0 24 24"
147
+ fill="none"
148
+ stroke="currentColor"
149
+ strokeWidth="2"
150
+ strokeLinecap="round"
151
+ strokeLinejoin="round"
152
+ >
153
+ <polyline points="18 15 12 9 6 15"></polyline>
154
+ </svg>
155
+ );
156
+
157
+ /**
158
+ * Default content renderer that simply displays text
159
+ */
160
+ const DefaultContentRenderer: React.FC<ContentRendererProps> = ({ content, className }) => (
161
+ <div className={className}>{content}</div>
162
+ );
163
+
164
+ /**
165
+ * Default feedback button component
166
+ */
167
+ const DefaultFeedbackButton: React.FC<FeedbackButtonProps> = ({ label, onClick, className }) => (
168
+ <button onClick={onClick} className={className}>
169
+ {label}
170
+ </button>
171
+ );
172
+
173
+ /**
174
+ * Default completed feedback component
175
+ */
176
+ const DefaultCompletedFeedback: React.FC<CompletedFeedbackProps> = ({ message, className }) => (
177
+ <div className={className}>
178
+ <span>{message}</span>
179
+ </div>
180
+ );
181
+
182
+ /**
183
+ * Default response renderer component that handles rendering responses
184
+ * and collecting user feedback
185
+ */
186
+ export const DefaultResponseRenderer: React.FC<ResponseRendererProps> = ({
187
+ response,
188
+ status,
189
+ onRespond,
190
+ icons,
191
+ labels,
192
+ ContentRenderer = DefaultContentRenderer,
193
+ FeedbackButton = DefaultFeedbackButton,
194
+ CompletedFeedback = DefaultCompletedFeedback,
195
+ className = "copilotkit-response",
196
+ contentClassName = "copilotkit-response-content",
197
+ actionsClassName = "copilotkit-response-actions",
198
+ buttonClassName = "copilotkit-response-button",
199
+ completedFeedbackClassName = "copilotkit-response-completed-feedback",
200
+ }) => {
201
+ const [isExpanded, setIsExpanded] = useState(true);
202
+
203
+ // Default label values
204
+ const defaultLabels = {
205
+ responseLabel: "Response",
206
+ approveLabel: "Approve",
207
+ rejectLabel: "Reject",
208
+ approvedMessage: "Approved",
209
+ rejectedMessage: "Rejected",
210
+ feedbackSubmittedMessage: "Feedback submitted",
211
+ };
212
+
213
+ // Merge provided labels with defaults
214
+ const mergedLabels = { ...defaultLabels, ...labels };
215
+
216
+ // Function to render feedback UI based on status
217
+ const renderFeedback = () => {
218
+ if (status === "complete") {
219
+ const cachedResponse = useResponseCache.getResponse(response.id);
220
+ return (
221
+ <CompletedFeedback
222
+ message={
223
+ cachedResponse?.__feedback__
224
+ ? cachedResponse.__feedback__ === mergedLabels.approvedMessage
225
+ ? mergedLabels.approvedMessage
226
+ : mergedLabels.rejectedMessage
227
+ : mergedLabels.feedbackSubmittedMessage
228
+ }
229
+ className={completedFeedbackClassName}
230
+ />
231
+ );
232
+ }
233
+
234
+ if (status === "inProgress" || status === "executing") {
235
+ return (
236
+ <>
237
+ <FeedbackButton
238
+ label={mergedLabels.approveLabel}
239
+ onClick={() => {
240
+ setIsExpanded(false);
241
+ onRespond?.(mergedLabels.approveLabel);
242
+ useResponseCache.setResponse(response.id, {
243
+ ...response,
244
+ __feedback__: mergedLabels.approvedMessage,
245
+ });
246
+ }}
247
+ className={buttonClassName}
248
+ />
249
+ <FeedbackButton
250
+ label={mergedLabels.rejectLabel}
251
+ onClick={() => {
252
+ setIsExpanded(false);
253
+ useResponseCache.setResponse(response.id, {
254
+ ...response,
255
+ __feedback__: mergedLabels.rejectedMessage,
256
+ });
257
+ onRespond?.(mergedLabels.rejectLabel);
258
+ }}
259
+ className={buttonClassName}
260
+ />
261
+ </>
262
+ );
263
+ }
264
+
265
+ return null;
266
+ };
267
+
268
+ // Decide which icon to display
269
+ const ExpandIcon = icons?.expand || DefaultExpandIcon;
270
+ const CollapseIcon = icons?.collapse || DefaultCollapseIcon;
271
+
272
+ return (
273
+ <div className={className}>
274
+ {/* Response content - conditionally expanded */}
275
+ {isExpanded && <ContentRenderer content={response.content} className={contentClassName} />}
276
+
277
+ <div className={actionsClassName}>
278
+ <div className="copilotkit-response-label">
279
+ <button onClick={() => setIsExpanded(!isExpanded)} className="copilotkit-toggle-button">
280
+ {isExpanded ? (
281
+ <CollapseIcon className="copilotkit-icon" />
282
+ ) : (
283
+ <ExpandIcon className="copilotkit-icon" />
284
+ )}
285
+ </button>
286
+ <span>{mergedLabels.responseLabel}</span>
287
+ </div>
288
+
289
+ <div className="copilotkit-response-buttons">{renderFeedback()}</div>
290
+ </div>
291
+ </div>
292
+ );
293
+ };
294
+
295
+ /**
296
+ * Export the response cache for reuse
297
+ */
298
+ export { createResponseCache };