@copilotkit/react-ui 1.8.13-next.1 → 1.8.13-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 +18 -0
- package/dist/{chunk-RVLCPPEL.mjs → chunk-5INP2EWU.mjs} +6 -4
- package/dist/chunk-5INP2EWU.mjs.map +1 -0
- package/dist/{chunk-XFCMZH2H.mjs → chunk-6VUDBDUN.mjs} +2 -2
- package/dist/{chunk-24TDU7MY.mjs → chunk-ALWZ35SI.mjs} +2 -2
- package/dist/{chunk-IIRQWGWV.mjs → chunk-B3D7U7TJ.mjs} +5 -3
- package/dist/chunk-B3D7U7TJ.mjs.map +1 -0
- package/dist/{chunk-KQ44Z255.mjs → chunk-EMIYIMQ6.mjs} +4 -4
- package/dist/{chunk-ZDKVXAL3.mjs → chunk-FWKHST6I.mjs} +75 -39
- package/dist/chunk-FWKHST6I.mjs.map +1 -0
- package/dist/{chunk-NWE7CLTB.mjs → chunk-IAHSHPRJ.mjs} +22 -21
- package/dist/chunk-IAHSHPRJ.mjs.map +1 -0
- package/dist/{chunk-XZNY26GH.mjs → chunk-IMBPSLL4.mjs} +3 -3
- package/dist/chunk-IMBPSLL4.mjs.map +1 -0
- package/dist/{chunk-MDMNZ6JL.mjs → chunk-JU3HNL5N.mjs} +2 -2
- package/dist/{chunk-DSQGQJI4.mjs → chunk-MPZAMNCN.mjs} +2 -2
- package/dist/{chunk-K7SXHJRT.mjs → chunk-QEZ3YYLO.mjs} +2 -2
- package/dist/chunk-QGSPTXOV.mjs +24 -0
- package/dist/chunk-QGSPTXOV.mjs.map +1 -0
- package/dist/chunk-SC6JRFAJ.mjs +1 -0
- package/dist/{chunk-LUPGADWY.mjs → chunk-UKWBNVMQ.mjs} +2 -2
- package/dist/{chunk-OZXUB3V7.mjs → chunk-XMNTLIK5.mjs} +5 -4
- package/dist/chunk-XMNTLIK5.mjs.map +1 -0
- package/dist/chunk-YTXEWDNC.mjs +117 -0
- package/dist/chunk-YTXEWDNC.mjs.map +1 -0
- package/dist/components/chat/Button.d.ts +2 -0
- package/dist/components/chat/Chat.d.ts +11 -2
- package/dist/components/chat/Chat.js +117 -50
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +13 -12
- package/dist/components/chat/Header.d.ts +2 -0
- package/dist/components/chat/Input.d.ts +2 -0
- package/dist/components/chat/Input.mjs +2 -2
- package/dist/components/chat/Markdown.d.ts +3 -1
- package/dist/components/chat/Markdown.js +65 -20
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +1 -1
- package/dist/components/chat/Messages.d.ts +2 -1
- package/dist/components/chat/Messages.js +4 -2
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +1 -1
- package/dist/components/chat/Modal.d.ts +2 -2
- package/dist/components/chat/Modal.js +186 -88
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +19 -18
- package/dist/components/chat/Popup.d.ts +1 -1
- package/dist/components/chat/Popup.js +188 -90
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +20 -19
- package/dist/components/chat/Sidebar.d.ts +1 -1
- package/dist/components/chat/Sidebar.js +188 -90
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +20 -19
- package/dist/components/chat/Suggestion.d.ts +8 -3
- package/dist/components/chat/Suggestion.js +2 -2
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +1 -1
- package/dist/components/chat/Suggestions.d.ts +9 -0
- package/dist/components/chat/Suggestions.js +73 -0
- package/dist/components/chat/Suggestions.js.map +1 -0
- package/dist/components/chat/Suggestions.mjs +10 -0
- package/dist/components/chat/Suggestions.mjs.map +1 -0
- package/dist/components/chat/Window.d.ts +2 -0
- package/dist/components/chat/index.d.ts +6 -3
- package/dist/components/chat/index.js +194 -92
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +31 -24
- package/dist/components/chat/messages/AssistantMessage.d.ts +2 -0
- package/dist/components/chat/messages/AssistantMessage.js +68 -22
- package/dist/components/chat/messages/AssistantMessage.js.map +1 -1
- package/dist/components/chat/messages/AssistantMessage.mjs +2 -2
- package/dist/components/chat/messages/RenderActionExecutionMessage.d.ts +2 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.js +68 -22
- package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +3 -3
- package/dist/components/chat/messages/RenderAgentStateMessage.d.ts +2 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.js +68 -22
- package/dist/components/chat/messages/RenderAgentStateMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderAgentStateMessage.mjs +3 -3
- package/dist/components/chat/messages/RenderImageMessage.d.ts +2 -0
- package/dist/components/chat/messages/RenderImageMessage.js +68 -22
- package/dist/components/chat/messages/RenderImageMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderImageMessage.mjs +3 -3
- package/dist/components/chat/messages/RenderResultMessage.d.ts +2 -0
- package/dist/components/chat/messages/RenderResultMessage.js +68 -22
- package/dist/components/chat/messages/RenderResultMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderResultMessage.mjs +3 -3
- package/dist/components/chat/messages/RenderTextMessage.d.ts +2 -0
- package/dist/components/chat/messages/RenderTextMessage.js +72 -24
- package/dist/components/chat/messages/RenderTextMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderTextMessage.mjs +3 -3
- package/dist/components/chat/messages/UserMessage.d.ts +2 -0
- package/dist/components/chat/props.d.ts +27 -1
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +6 -3
- package/dist/components/index.js +194 -92
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +35 -28
- package/dist/index.css +32 -28
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +194 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -28
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +11 -10
- package/src/components/chat/Chat.tsx +21 -13
- package/src/components/chat/Markdown.tsx +86 -29
- package/src/components/chat/Messages.tsx +2 -0
- package/src/components/chat/Modal.tsx +4 -0
- package/src/components/chat/Suggestion.tsx +10 -3
- package/src/components/chat/Suggestions.tsx +20 -0
- package/src/components/chat/index.tsx +2 -0
- package/src/components/chat/messages/AssistantMessage.tsx +2 -1
- package/src/components/chat/messages/RenderTextMessage.tsx +2 -0
- package/src/components/chat/props.ts +29 -0
- package/src/css/markdown.css +33 -28
- package/src/types/index.ts +1 -0
- package/dist/chunk-ABHUX6T6.mjs +0 -72
- package/dist/chunk-ABHUX6T6.mjs.map +0 -1
- package/dist/chunk-IIRQWGWV.mjs.map +0 -1
- package/dist/chunk-NWE7CLTB.mjs.map +0 -1
- package/dist/chunk-OZXUB3V7.mjs.map +0 -1
- package/dist/chunk-PXEVB7IK.mjs +0 -1
- package/dist/chunk-RVLCPPEL.mjs.map +0 -1
- package/dist/chunk-XZNY26GH.mjs.map +0 -1
- package/dist/chunk-ZDKVXAL3.mjs.map +0 -1
- /package/dist/{chunk-XFCMZH2H.mjs.map → chunk-6VUDBDUN.mjs.map} +0 -0
- /package/dist/{chunk-24TDU7MY.mjs.map → chunk-ALWZ35SI.mjs.map} +0 -0
- /package/dist/{chunk-KQ44Z255.mjs.map → chunk-EMIYIMQ6.mjs.map} +0 -0
- /package/dist/{chunk-MDMNZ6JL.mjs.map → chunk-JU3HNL5N.mjs.map} +0 -0
- /package/dist/{chunk-DSQGQJI4.mjs.map → chunk-MPZAMNCN.mjs.map} +0 -0
- /package/dist/{chunk-K7SXHJRT.mjs.map → chunk-QEZ3YYLO.mjs.map} +0 -0
- /package/dist/{chunk-PXEVB7IK.mjs.map → chunk-SC6JRFAJ.mjs.map} +0 -0
- /package/dist/{chunk-LUPGADWY.mjs.map → chunk-UKWBNVMQ.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,55 +1,60 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "./chunk-EFZPSZWO.mjs";
|
|
3
3
|
import "./chunk-MMVDU6DF.mjs";
|
|
4
|
-
import "./chunk-
|
|
4
|
+
import "./chunk-SC6JRFAJ.mjs";
|
|
5
5
|
import "./chunk-WB3YULQ4.mjs";
|
|
6
6
|
import {
|
|
7
7
|
CopilotPopup
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-QEZ3YYLO.mjs";
|
|
9
9
|
import {
|
|
10
10
|
CopilotSidebar
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-JU3HNL5N.mjs";
|
|
12
|
+
import "./chunk-FWKHST6I.mjs";
|
|
13
13
|
import "./chunk-TIDV74OE.mjs";
|
|
14
|
+
import "./chunk-UH2UFL5W.mjs";
|
|
15
|
+
import "./chunk-V7W6IM2V.mjs";
|
|
16
|
+
import {
|
|
17
|
+
CopilotDevConsole
|
|
18
|
+
} from "./chunk-VGPQYMKJ.mjs";
|
|
19
|
+
import "./chunk-Q5V6S67N.mjs";
|
|
20
|
+
import {
|
|
21
|
+
shouldShowDevConsole
|
|
22
|
+
} from "./chunk-6TCUJ3B7.mjs";
|
|
23
|
+
import "./chunk-KXE2JCUH.mjs";
|
|
24
|
+
import "./chunk-NRA3CFEE.mjs";
|
|
25
|
+
import "./chunk-BH6PCAAL.mjs";
|
|
14
26
|
import "./chunk-UFN2VWSR.mjs";
|
|
15
27
|
import {
|
|
16
28
|
CopilotChat
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
29
|
+
} from "./chunk-IAHSHPRJ.mjs";
|
|
30
|
+
import "./chunk-MPZAMNCN.mjs";
|
|
31
|
+
import "./chunk-ALWZ35SI.mjs";
|
|
20
32
|
import {
|
|
21
33
|
RenderImageMessage
|
|
22
|
-
} from "./chunk-
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-
|
|
34
|
+
} from "./chunk-UKWBNVMQ.mjs";
|
|
35
|
+
import "./chunk-6VUDBDUN.mjs";
|
|
36
|
+
import "./chunk-5INP2EWU.mjs";
|
|
25
37
|
import {
|
|
26
38
|
AssistantMessage
|
|
27
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-XMNTLIK5.mjs";
|
|
28
40
|
import {
|
|
29
41
|
UserMessage
|
|
30
42
|
} from "./chunk-HWMFMBJC.mjs";
|
|
31
|
-
import
|
|
43
|
+
import {
|
|
44
|
+
Suggestions
|
|
45
|
+
} from "./chunk-QGSPTXOV.mjs";
|
|
46
|
+
import {
|
|
47
|
+
Suggestion
|
|
48
|
+
} from "./chunk-IMBPSLL4.mjs";
|
|
32
49
|
import "./chunk-PLHTVHUW.mjs";
|
|
33
|
-
import "./chunk-
|
|
50
|
+
import "./chunk-EMIYIMQ6.mjs";
|
|
51
|
+
import "./chunk-CGEAG65D.mjs";
|
|
34
52
|
import "./chunk-YQFVRDNC.mjs";
|
|
35
53
|
import {
|
|
36
54
|
Markdown
|
|
37
|
-
} from "./chunk-
|
|
38
|
-
import "./chunk-IIRQWGWV.mjs";
|
|
39
|
-
import "./chunk-CGEAG65D.mjs";
|
|
55
|
+
} from "./chunk-YTXEWDNC.mjs";
|
|
40
56
|
import "./chunk-KENCH7RN.mjs";
|
|
41
|
-
import "./chunk-
|
|
42
|
-
import "./chunk-V7W6IM2V.mjs";
|
|
43
|
-
import {
|
|
44
|
-
CopilotDevConsole
|
|
45
|
-
} from "./chunk-VGPQYMKJ.mjs";
|
|
46
|
-
import "./chunk-Q5V6S67N.mjs";
|
|
47
|
-
import {
|
|
48
|
-
shouldShowDevConsole
|
|
49
|
-
} from "./chunk-6TCUJ3B7.mjs";
|
|
50
|
-
import "./chunk-KXE2JCUH.mjs";
|
|
51
|
-
import "./chunk-NRA3CFEE.mjs";
|
|
52
|
-
import "./chunk-BH6PCAAL.mjs";
|
|
57
|
+
import "./chunk-B3D7U7TJ.mjs";
|
|
53
58
|
import {
|
|
54
59
|
useChatContext
|
|
55
60
|
} from "./chunk-IEMQ2SQW.mjs";
|
|
@@ -71,6 +76,8 @@ export {
|
|
|
71
76
|
CopilotSidebar,
|
|
72
77
|
Markdown,
|
|
73
78
|
RenderImageMessage,
|
|
79
|
+
Suggestion as RenderSuggestion,
|
|
80
|
+
Suggestions as RenderSuggestionsList,
|
|
74
81
|
UserMessage,
|
|
75
82
|
shouldShowDevConsole,
|
|
76
83
|
useChatContext,
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export type { CopilotKitCSSProperties } from \"./css\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export type { CopilotKitCSSProperties } from \"./css\";\nexport type { CopilotChatSuggestion } from \"./suggestions\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.8.13-next.
|
|
12
|
+
"version": "1.8.13-next.3",
|
|
13
13
|
"sideEffects": [
|
|
14
14
|
"**/*.css"
|
|
15
15
|
],
|
|
@@ -40,19 +40,20 @@
|
|
|
40
40
|
"ts-jest": "^29.1.1",
|
|
41
41
|
"tsup": "^6.7.0",
|
|
42
42
|
"typescript": "^5.2.3",
|
|
43
|
-
"eslint-config-custom": "1.4.6",
|
|
44
43
|
"tailwind-config": "1.4.6",
|
|
45
|
-
"tsconfig": "1.4.6"
|
|
44
|
+
"tsconfig": "1.4.6",
|
|
45
|
+
"eslint-config-custom": "1.4.6"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@headlessui/react": "^2.1.3",
|
|
49
|
-
"react-markdown": "^
|
|
50
|
-
"react-syntax-highlighter": "^15.
|
|
51
|
-
"
|
|
52
|
-
"remark-
|
|
53
|
-
"
|
|
54
|
-
"@copilotkit/
|
|
55
|
-
"@copilotkit/
|
|
49
|
+
"react-markdown": "^10.1.0",
|
|
50
|
+
"react-syntax-highlighter": "^15.6.1",
|
|
51
|
+
"rehype-raw": "^7.0.0",
|
|
52
|
+
"remark-gfm": "^4.0.1",
|
|
53
|
+
"remark-math": "^6.0.0",
|
|
54
|
+
"@copilotkit/react-core": "1.8.13-next.3",
|
|
55
|
+
"@copilotkit/runtime-client-gql": "1.8.13-next.3",
|
|
56
|
+
"@copilotkit/shared": "1.8.13-next.3"
|
|
56
57
|
},
|
|
57
58
|
"keywords": [
|
|
58
59
|
"copilotkit",
|
|
@@ -60,7 +60,6 @@ import { RenderAgentStateMessage as DefaultRenderAgentStateMessage } from "./mes
|
|
|
60
60
|
import { RenderImageMessage as DefaultRenderImageMessage } from "./messages/RenderImageMessage";
|
|
61
61
|
import { AssistantMessage as DefaultAssistantMessage } from "./messages/AssistantMessage";
|
|
62
62
|
import { UserMessage as DefaultUserMessage } from "./messages/UserMessage";
|
|
63
|
-
import { Suggestion } from "./Suggestion";
|
|
64
63
|
import React, { useEffect, useRef, useState } from "react";
|
|
65
64
|
import {
|
|
66
65
|
SystemMessageFunction,
|
|
@@ -74,14 +73,17 @@ import { Message, Role, TextMessage, ImageMessage } from "@copilotkit/runtime-cl
|
|
|
74
73
|
import { randomId } from "@copilotkit/shared";
|
|
75
74
|
import {
|
|
76
75
|
AssistantMessageProps,
|
|
76
|
+
ComponentsMap,
|
|
77
77
|
InputProps,
|
|
78
78
|
MessagesProps,
|
|
79
79
|
RenderMessageProps,
|
|
80
|
+
RenderSuggestionsListProps,
|
|
80
81
|
UserMessageProps,
|
|
81
82
|
} from "./props";
|
|
82
83
|
|
|
83
84
|
import { HintFunction, runAgent, stopAgent } from "@copilotkit/react-core";
|
|
84
85
|
import { ImageUploadQueue } from "./ImageUploadQueue";
|
|
86
|
+
import { Suggestions as DefaultRenderSuggestionsList } from "./Suggestions";
|
|
85
87
|
|
|
86
88
|
/**
|
|
87
89
|
* Props for CopilotChat component.
|
|
@@ -137,6 +139,12 @@ export interface CopilotChatProps {
|
|
|
137
139
|
*/
|
|
138
140
|
onThumbsDown?: (message: string) => void;
|
|
139
141
|
|
|
142
|
+
/**
|
|
143
|
+
* A list of markdown components to render in assistant message.
|
|
144
|
+
* Useful when you want to render custom elements in the message (e.g a reference tag element)
|
|
145
|
+
*/
|
|
146
|
+
markdownTagRenderers?: ComponentsMap;
|
|
147
|
+
|
|
140
148
|
/**
|
|
141
149
|
* Icons can be used to set custom icons for the chat window.
|
|
142
150
|
*/
|
|
@@ -206,6 +214,11 @@ export interface CopilotChatProps {
|
|
|
206
214
|
*/
|
|
207
215
|
RenderImageMessage?: React.ComponentType<RenderMessageProps>;
|
|
208
216
|
|
|
217
|
+
/**
|
|
218
|
+
* A custom suggestions list component to use instead of the default.
|
|
219
|
+
*/
|
|
220
|
+
RenderSuggestionsList?: React.ComponentType<RenderSuggestionsListProps>;
|
|
221
|
+
|
|
209
222
|
/**
|
|
210
223
|
* A custom Input component to use instead of the default.
|
|
211
224
|
*/
|
|
@@ -291,12 +304,14 @@ export function CopilotChat({
|
|
|
291
304
|
onCopy,
|
|
292
305
|
onThumbsUp,
|
|
293
306
|
onThumbsDown,
|
|
307
|
+
markdownTagRenderers,
|
|
294
308
|
Messages = DefaultMessages,
|
|
295
309
|
RenderTextMessage = DefaultRenderTextMessage,
|
|
296
310
|
RenderActionExecutionMessage = DefaultRenderActionExecutionMessage,
|
|
297
311
|
RenderAgentStateMessage = DefaultRenderAgentStateMessage,
|
|
298
312
|
RenderResultMessage = DefaultRenderResultMessage,
|
|
299
313
|
RenderImageMessage = DefaultRenderImageMessage,
|
|
314
|
+
RenderSuggestionsList = DefaultRenderSuggestionsList,
|
|
300
315
|
Input = DefaultInput,
|
|
301
316
|
className,
|
|
302
317
|
icons,
|
|
@@ -482,20 +497,13 @@ export function CopilotChat({
|
|
|
482
497
|
onCopy={handleCopy}
|
|
483
498
|
onThumbsUp={onThumbsUp}
|
|
484
499
|
onThumbsDown={onThumbsDown}
|
|
500
|
+
markdownTagRenderers={markdownTagRenderers}
|
|
485
501
|
>
|
|
486
502
|
{currentSuggestions.length > 0 && (
|
|
487
|
-
<
|
|
488
|
-
{
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
title={suggestion.title}
|
|
492
|
-
message={suggestion.message}
|
|
493
|
-
partial={suggestion.partial}
|
|
494
|
-
className={suggestion.className}
|
|
495
|
-
onClick={(message) => handleSendMessage(message)}
|
|
496
|
-
/>
|
|
497
|
-
))}
|
|
498
|
-
</div>
|
|
503
|
+
<RenderSuggestionsList
|
|
504
|
+
onSuggestionClick={handleSendMessage}
|
|
505
|
+
suggestions={currentSuggestions}
|
|
506
|
+
/>
|
|
499
507
|
)}
|
|
500
508
|
</Messages>
|
|
501
509
|
|
|
@@ -3,42 +3,19 @@ import ReactMarkdown, { Options, Components } from "react-markdown";
|
|
|
3
3
|
import { CodeBlock } from "./CodeBlock";
|
|
4
4
|
import remarkGfm from "remark-gfm";
|
|
5
5
|
import remarkMath from "remark-math";
|
|
6
|
+
import rehypeRaw from "rehype-raw";
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
-
ReactMarkdown,
|
|
9
|
-
(prevProps, nextProps) =>
|
|
10
|
-
prevProps.children === nextProps.children && prevProps.className === nextProps.className,
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
type MarkdownProps = {
|
|
14
|
-
content: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const Markdown = ({ content }: MarkdownProps) => {
|
|
18
|
-
return (
|
|
19
|
-
<div className="copilotKitMarkdown">
|
|
20
|
-
<MemoizedReactMarkdown components={components} remarkPlugins={[remarkGfm, remarkMath]}>
|
|
21
|
-
{content}
|
|
22
|
-
</MemoizedReactMarkdown>
|
|
23
|
-
</div>
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const components: Components = {
|
|
8
|
+
const defaultComponents: Components = {
|
|
28
9
|
a({ children, ...props }) {
|
|
29
10
|
return (
|
|
30
|
-
<a
|
|
31
|
-
style={{ color: "blue", textDecoration: "underline" }}
|
|
32
|
-
{...props}
|
|
33
|
-
target="_blank"
|
|
34
|
-
rel="noopener noreferrer"
|
|
35
|
-
>
|
|
11
|
+
<a className="copilotKitMarkdownElement" {...props} target="_blank" rel="noopener noreferrer">
|
|
36
12
|
{children}
|
|
37
13
|
</a>
|
|
38
14
|
);
|
|
39
15
|
},
|
|
16
|
+
// @ts-expect-error -- inline
|
|
40
17
|
code({ children, className, inline, ...props }) {
|
|
41
|
-
if (children.length) {
|
|
18
|
+
if (Array.isArray(children) && children.length) {
|
|
42
19
|
if (children[0] == "▍") {
|
|
43
20
|
return (
|
|
44
21
|
<span
|
|
@@ -52,7 +29,7 @@ const components: Components = {
|
|
|
52
29
|
);
|
|
53
30
|
}
|
|
54
31
|
|
|
55
|
-
children[0] = (children[0] as string).replace("`▍`", "▍");
|
|
32
|
+
children[0] = (children?.[0] as string).replace("`▍`", "▍");
|
|
56
33
|
}
|
|
57
34
|
|
|
58
35
|
const match = /language-(\w+)/.exec(className || "");
|
|
@@ -74,4 +51,84 @@ const components: Components = {
|
|
|
74
51
|
/>
|
|
75
52
|
);
|
|
76
53
|
},
|
|
54
|
+
h1: ({ children, ...props }) => (
|
|
55
|
+
<h1 className="copilotKitMarkdownElement" {...props}>
|
|
56
|
+
{children}
|
|
57
|
+
</h1>
|
|
58
|
+
),
|
|
59
|
+
h2: ({ children, ...props }) => (
|
|
60
|
+
<h2 className="copilotKitMarkdownElement" {...props}>
|
|
61
|
+
{children}
|
|
62
|
+
</h2>
|
|
63
|
+
),
|
|
64
|
+
h3: ({ children, ...props }) => (
|
|
65
|
+
<h3 className="copilotKitMarkdownElement" {...props}>
|
|
66
|
+
{children}
|
|
67
|
+
</h3>
|
|
68
|
+
),
|
|
69
|
+
h4: ({ children, ...props }) => (
|
|
70
|
+
<h4 className="copilotKitMarkdownElement" {...props}>
|
|
71
|
+
{children}
|
|
72
|
+
</h4>
|
|
73
|
+
),
|
|
74
|
+
h5: ({ children, ...props }) => (
|
|
75
|
+
<h5 className="copilotKitMarkdownElement" {...props}>
|
|
76
|
+
{children}
|
|
77
|
+
</h5>
|
|
78
|
+
),
|
|
79
|
+
h6: ({ children, ...props }) => (
|
|
80
|
+
<h6 className="copilotKitMarkdownElement" {...props}>
|
|
81
|
+
{children}
|
|
82
|
+
</h6>
|
|
83
|
+
),
|
|
84
|
+
p: ({ children, ...props }) => (
|
|
85
|
+
<p className="copilotKitMarkdownElement" {...props}>
|
|
86
|
+
{children}
|
|
87
|
+
</p>
|
|
88
|
+
),
|
|
89
|
+
pre: ({ children, ...props }) => (
|
|
90
|
+
<pre className="copilotKitMarkdownElement" {...props}>
|
|
91
|
+
{children}
|
|
92
|
+
</pre>
|
|
93
|
+
),
|
|
94
|
+
blockquote: ({ children, ...props }) => (
|
|
95
|
+
<blockquote className="copilotKitMarkdownElement" {...props}>
|
|
96
|
+
{children}
|
|
97
|
+
</blockquote>
|
|
98
|
+
),
|
|
99
|
+
ul: ({ children, ...props }) => (
|
|
100
|
+
<ul className="copilotKitMarkdownElement" {...props}>
|
|
101
|
+
{children}
|
|
102
|
+
</ul>
|
|
103
|
+
),
|
|
104
|
+
li: ({ children, ...props }) => (
|
|
105
|
+
<li className="copilotKitMarkdownElement" {...props}>
|
|
106
|
+
{children}
|
|
107
|
+
</li>
|
|
108
|
+
),
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const MemoizedReactMarkdown: FC<Options> = memo(
|
|
112
|
+
ReactMarkdown,
|
|
113
|
+
(prevProps, nextProps) =>
|
|
114
|
+
prevProps.children === nextProps.children && prevProps.components === nextProps.components,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
type MarkdownProps = {
|
|
118
|
+
content: string;
|
|
119
|
+
components?: Components;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const Markdown = ({ content, components }: MarkdownProps) => {
|
|
123
|
+
return (
|
|
124
|
+
<div className="copilotKitMarkdown">
|
|
125
|
+
<MemoizedReactMarkdown
|
|
126
|
+
components={{ ...defaultComponents, ...components }}
|
|
127
|
+
remarkPlugins={[remarkGfm, remarkMath]}
|
|
128
|
+
rehypePlugins={[rehypeRaw]}
|
|
129
|
+
>
|
|
130
|
+
{content}
|
|
131
|
+
</MemoizedReactMarkdown>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
77
134
|
};
|
|
@@ -19,6 +19,7 @@ export const Messages = ({
|
|
|
19
19
|
onCopy,
|
|
20
20
|
onThumbsUp,
|
|
21
21
|
onThumbsDown,
|
|
22
|
+
markdownTagRenderers,
|
|
22
23
|
}: MessagesProps) => {
|
|
23
24
|
const context = useChatContext();
|
|
24
25
|
const initialMessages = useMemo(
|
|
@@ -67,6 +68,7 @@ export const Messages = ({
|
|
|
67
68
|
onCopy={onCopy}
|
|
68
69
|
onThumbsUp={onThumbsUp}
|
|
69
70
|
onThumbsDown={onThumbsDown}
|
|
71
|
+
markdownTagRenderers={markdownTagRenderers}
|
|
70
72
|
/>
|
|
71
73
|
);
|
|
72
74
|
} else if (message.isActionExecutionMessage()) {
|
|
@@ -82,8 +82,10 @@ export const CopilotModal = ({
|
|
|
82
82
|
onThumbsDown,
|
|
83
83
|
onCopy,
|
|
84
84
|
onRegenerate,
|
|
85
|
+
markdownTagRenderers,
|
|
85
86
|
className,
|
|
86
87
|
children,
|
|
88
|
+
...props
|
|
87
89
|
}: CopilotModalProps) => {
|
|
88
90
|
const [openState, setOpenState] = React.useState(defaultOpen);
|
|
89
91
|
|
|
@@ -104,6 +106,7 @@ export const CopilotModal = ({
|
|
|
104
106
|
>
|
|
105
107
|
<Header />
|
|
106
108
|
<CopilotChat
|
|
109
|
+
{...props}
|
|
107
110
|
instructions={instructions}
|
|
108
111
|
onSubmitMessage={onSubmitMessage}
|
|
109
112
|
onStopGeneration={onStopGeneration}
|
|
@@ -118,6 +121,7 @@ export const CopilotModal = ({
|
|
|
118
121
|
onThumbsDown={onThumbsDown}
|
|
119
122
|
onCopy={onCopy}
|
|
120
123
|
onRegenerate={onRegenerate}
|
|
124
|
+
markdownTagRenderers={markdownTagRenderers}
|
|
121
125
|
/>
|
|
122
126
|
</Window>
|
|
123
127
|
</div>
|
|
@@ -4,19 +4,26 @@ import {
|
|
|
4
4
|
CopilotChatSuggestionConfiguration,
|
|
5
5
|
CopilotMessagesContextParams,
|
|
6
6
|
} from "@copilotkit/react-core";
|
|
7
|
-
import { SuggestionsProps } from "./props";
|
|
8
7
|
import { SmallSpinnerIcon } from "./Icons";
|
|
9
8
|
import { CopilotChatSuggestion } from "../../types/suggestions";
|
|
10
9
|
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
11
10
|
import { CopilotRequestType } from "@copilotkit/runtime-client-gql";
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
interface SuggestionsProps {
|
|
13
|
+
title: string;
|
|
14
|
+
message: string;
|
|
15
|
+
partial?: boolean;
|
|
16
|
+
className?: string;
|
|
17
|
+
onClick: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function Suggestion({ title, onClick, partial, className }: SuggestionsProps) {
|
|
14
21
|
return (
|
|
15
22
|
<button
|
|
16
23
|
disabled={partial}
|
|
17
24
|
onClick={(e) => {
|
|
18
25
|
e.preventDefault();
|
|
19
|
-
onClick(
|
|
26
|
+
onClick();
|
|
20
27
|
}}
|
|
21
28
|
className={className || (partial ? "suggestion loading" : "suggestion")}
|
|
22
29
|
data-test-id="suggestion"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Suggestion } from "./Suggestion";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { RenderSuggestionsListProps } from "./props";
|
|
4
|
+
|
|
5
|
+
export function Suggestions({ suggestions, onSuggestionClick }: RenderSuggestionsListProps) {
|
|
6
|
+
return (
|
|
7
|
+
<div className="suggestions">
|
|
8
|
+
{suggestions.map((suggestion, index) => (
|
|
9
|
+
<Suggestion
|
|
10
|
+
key={index}
|
|
11
|
+
title={suggestion.title}
|
|
12
|
+
message={suggestion.message}
|
|
13
|
+
partial={suggestion.partial}
|
|
14
|
+
className={suggestion.className}
|
|
15
|
+
onClick={() => onSuggestionClick(suggestion.message)}
|
|
16
|
+
/>
|
|
17
|
+
))}
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -7,3 +7,5 @@ export { AssistantMessage } from "./messages/AssistantMessage";
|
|
|
7
7
|
export { UserMessage } from "./messages/UserMessage";
|
|
8
8
|
export { useChatContext } from "./ChatContext";
|
|
9
9
|
export { RenderImageMessage } from "./messages/RenderImageMessage";
|
|
10
|
+
export { Suggestions as RenderSuggestionsList } from "./Suggestions";
|
|
11
|
+
export { Suggestion as RenderSuggestion } from "./Suggestion";
|
|
@@ -14,6 +14,7 @@ export const AssistantMessage = (props: AssistantMessageProps) => {
|
|
|
14
14
|
onThumbsUp,
|
|
15
15
|
onThumbsDown,
|
|
16
16
|
isCurrentMessage,
|
|
17
|
+
markdownTagRenderers,
|
|
17
18
|
} = props;
|
|
18
19
|
const [copied, setCopied] = useState(false);
|
|
19
20
|
|
|
@@ -54,7 +55,7 @@ export const AssistantMessage = (props: AssistantMessageProps) => {
|
|
|
54
55
|
<>
|
|
55
56
|
{(message || isLoading) && (
|
|
56
57
|
<div className="copilotKitMessage copilotKitAssistantMessage">
|
|
57
|
-
{message && <Markdown content={message || ""} />}
|
|
58
|
+
{message && <Markdown content={message || ""} components={markdownTagRenderers} />}
|
|
58
59
|
{isLoading && <LoadingIcon />}
|
|
59
60
|
|
|
60
61
|
{message && !isLoading && (
|
|
@@ -16,6 +16,7 @@ export function RenderTextMessage({
|
|
|
16
16
|
onCopy,
|
|
17
17
|
onThumbsUp,
|
|
18
18
|
onThumbsDown,
|
|
19
|
+
markdownTagRenderers,
|
|
19
20
|
} = props;
|
|
20
21
|
|
|
21
22
|
if (message.isTextMessage()) {
|
|
@@ -42,6 +43,7 @@ export function RenderTextMessage({
|
|
|
42
43
|
onCopy={onCopy}
|
|
43
44
|
onThumbsUp={onThumbsUp}
|
|
44
45
|
onThumbsDown={onThumbsDown}
|
|
46
|
+
markdownTagRenderers={markdownTagRenderers}
|
|
45
47
|
/>
|
|
46
48
|
);
|
|
47
49
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Message } from "@copilotkit/runtime-client-gql";
|
|
2
|
+
import { CopilotChatSuggestion } from "../../types/suggestions";
|
|
3
|
+
import { ReactNode } from "react";
|
|
2
4
|
|
|
3
5
|
export interface ButtonProps {}
|
|
4
6
|
|
|
@@ -19,6 +21,10 @@ export interface SuggestionsProps {
|
|
|
19
21
|
onClick: (message: string) => void;
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
export type ComponentsMap<T extends Record<string, object> = Record<string, object>> = {
|
|
25
|
+
[K in keyof T]: React.FC<{ children?: ReactNode } & T[K]>;
|
|
26
|
+
};
|
|
27
|
+
|
|
22
28
|
export interface MessagesProps {
|
|
23
29
|
messages: Message[];
|
|
24
30
|
inProgress: boolean;
|
|
@@ -50,6 +56,12 @@ export interface MessagesProps {
|
|
|
50
56
|
* Callback function for thumbs down feedback
|
|
51
57
|
*/
|
|
52
58
|
onThumbsDown?: (message: string) => void;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A list of markdown components to render in assistant message.
|
|
62
|
+
* Useful when you want to render custom elements in the message (e.g a reference tag element)
|
|
63
|
+
*/
|
|
64
|
+
markdownTagRenderers?: ComponentsMap;
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
export interface Renderer {
|
|
@@ -115,6 +127,12 @@ export interface AssistantMessageProps {
|
|
|
115
127
|
* Callback function for thumbs down feedback
|
|
116
128
|
*/
|
|
117
129
|
onThumbsDown?: (message: string) => void;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A list of markdown components to render in assistant message.
|
|
133
|
+
* Useful when you want to render custom elements in the message (e.g a reference tag element)
|
|
134
|
+
*/
|
|
135
|
+
markdownTagRenderers?: ComponentsMap;
|
|
118
136
|
}
|
|
119
137
|
|
|
120
138
|
export interface RenderMessageProps {
|
|
@@ -145,6 +163,12 @@ export interface RenderMessageProps {
|
|
|
145
163
|
* Callback function for thumbs down feedback
|
|
146
164
|
*/
|
|
147
165
|
onThumbsDown?: (message: string) => void;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A list of markdown components to render in assistant message.
|
|
169
|
+
* Useful when you want to render custom elements in the message (e.g a reference tag element)
|
|
170
|
+
*/
|
|
171
|
+
markdownTagRenderers?: ComponentsMap;
|
|
148
172
|
}
|
|
149
173
|
|
|
150
174
|
export interface InputProps {
|
|
@@ -154,3 +178,8 @@ export interface InputProps {
|
|
|
154
178
|
onStop?: () => void;
|
|
155
179
|
onUpload?: () => void;
|
|
156
180
|
}
|
|
181
|
+
|
|
182
|
+
export interface RenderSuggestionsListProps {
|
|
183
|
+
suggestions: CopilotChatSuggestion[];
|
|
184
|
+
onSuggestionClick: (message: string) => void;
|
|
185
|
+
}
|