@copilotkit/react-ui 0.0.0-test-custom-tag-prerelease-1-20250108200215
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 +2134 -0
- package/README.md +46 -0
- package/dist/chunk-375NVWZM.mjs +21 -0
- package/dist/chunk-375NVWZM.mjs.map +1 -0
- package/dist/chunk-3E7HY2UN.mjs +85 -0
- package/dist/chunk-3E7HY2UN.mjs.map +1 -0
- package/dist/chunk-3XAXY2Z3.mjs +18 -0
- package/dist/chunk-3XAXY2Z3.mjs.map +1 -0
- package/dist/chunk-54JAUBUJ.mjs +26 -0
- package/dist/chunk-54JAUBUJ.mjs.map +1 -0
- package/dist/chunk-6INMITFA.mjs +18 -0
- package/dist/chunk-6INMITFA.mjs.map +1 -0
- package/dist/chunk-7II4YL7R.mjs +170 -0
- package/dist/chunk-7II4YL7R.mjs.map +1 -0
- package/dist/chunk-BH6PCAAL.mjs +81 -0
- package/dist/chunk-BH6PCAAL.mjs.map +1 -0
- package/dist/chunk-CBBFRI3Q.mjs +81 -0
- package/dist/chunk-CBBFRI3Q.mjs.map +1 -0
- package/dist/chunk-DCNCY2PL.mjs +304 -0
- package/dist/chunk-DCNCY2PL.mjs.map +1 -0
- package/dist/chunk-EFZPSZWO.mjs +1 -0
- package/dist/chunk-EFZPSZWO.mjs.map +1 -0
- package/dist/chunk-EMQEEXUB.mjs +97 -0
- package/dist/chunk-EMQEEXUB.mjs.map +1 -0
- package/dist/chunk-F2W5FD7L.mjs +232 -0
- package/dist/chunk-F2W5FD7L.mjs.map +1 -0
- package/dist/chunk-FZC7X5PK.mjs +262 -0
- package/dist/chunk-FZC7X5PK.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +1 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-KXE2JCUH.mjs +1 -0
- package/dist/chunk-KXE2JCUH.mjs.map +1 -0
- package/dist/chunk-MMVDU6DF.mjs +1 -0
- package/dist/chunk-MMVDU6DF.mjs.map +1 -0
- package/dist/chunk-MRFF7GSQ.mjs +1 -0
- package/dist/chunk-MRFF7GSQ.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +59 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-OTPAZXVR.mjs +92 -0
- package/dist/chunk-OTPAZXVR.mjs.map +1 -0
- package/dist/chunk-PNQVKBPN.mjs +146 -0
- package/dist/chunk-PNQVKBPN.mjs.map +1 -0
- package/dist/chunk-RJCZRKTV.mjs +106 -0
- package/dist/chunk-RJCZRKTV.mjs.map +1 -0
- package/dist/chunk-RQNJNK2W.mjs +25 -0
- package/dist/chunk-RQNJNK2W.mjs.map +1 -0
- package/dist/chunk-RU73BEZM.mjs +41 -0
- package/dist/chunk-RU73BEZM.mjs.map +1 -0
- package/dist/chunk-S5MBUNGN.mjs +140 -0
- package/dist/chunk-S5MBUNGN.mjs.map +1 -0
- package/dist/chunk-T26KLXLH.mjs +1 -0
- package/dist/chunk-T26KLXLH.mjs.map +1 -0
- package/dist/chunk-TI7SY2RI.mjs +164 -0
- package/dist/chunk-TI7SY2RI.mjs.map +1 -0
- package/dist/chunk-UPTB2MVO.mjs +395 -0
- package/dist/chunk-UPTB2MVO.mjs.map +1 -0
- package/dist/chunk-UWVGLGFQ.mjs +95 -0
- package/dist/chunk-UWVGLGFQ.mjs.map +1 -0
- package/dist/chunk-V7W6IM2V.mjs +1 -0
- package/dist/chunk-V7W6IM2V.mjs.map +1 -0
- package/dist/chunk-VEC45H6Q.mjs +18 -0
- package/dist/chunk-VEC45H6Q.mjs.map +1 -0
- package/dist/chunk-WB3YULQ4.mjs +1 -0
- package/dist/chunk-WB3YULQ4.mjs.map +1 -0
- package/dist/chunk-WSMMTZCM.mjs +30 -0
- package/dist/chunk-WSMMTZCM.mjs.map +1 -0
- package/dist/chunk-YAGE7RCE.mjs +118 -0
- package/dist/chunk-YAGE7RCE.mjs.map +1 -0
- package/dist/chunk-YQ3D5IQV.mjs +75 -0
- package/dist/chunk-YQ3D5IQV.mjs.map +1 -0
- package/dist/chunk-YQFVRDNC.mjs +53 -0
- package/dist/chunk-YQFVRDNC.mjs.map +1 -0
- package/dist/chunk-Z2UZSN3K.mjs +29 -0
- package/dist/chunk-Z2UZSN3K.mjs.map +1 -0
- package/dist/chunk-ZABXREBH.mjs +65 -0
- package/dist/chunk-ZABXREBH.mjs.map +1 -0
- package/dist/components/chat/Button.d.ts +7 -0
- package/dist/components/chat/Button.js +71 -0
- package/dist/components/chat/Button.js.map +1 -0
- package/dist/components/chat/Button.mjs +10 -0
- package/dist/components/chat/Button.mjs.map +1 -0
- package/dist/components/chat/Chat.d.ts +148 -0
- package/dist/components/chat/Chat.js +2427 -0
- package/dist/components/chat/Chat.js.map +1 -0
- package/dist/components/chat/Chat.mjs +34 -0
- package/dist/components/chat/Chat.mjs.map +1 -0
- package/dist/components/chat/ChatContext.d.ts +105 -0
- package/dist/components/chat/ChatContext.js +279 -0
- package/dist/components/chat/ChatContext.js.map +1 -0
- package/dist/components/chat/ChatContext.mjs +13 -0
- package/dist/components/chat/ChatContext.mjs.map +1 -0
- package/dist/components/chat/CodeBlock.d.ts +14 -0
- package/dist/components/chat/CodeBlock.js +523 -0
- package/dist/components/chat/CodeBlock.js.map +1 -0
- package/dist/components/chat/CodeBlock.mjs +14 -0
- package/dist/components/chat/CodeBlock.mjs.map +1 -0
- package/dist/components/chat/Header.d.ts +7 -0
- package/dist/components/chat/Header.js +64 -0
- package/dist/components/chat/Header.js.map +1 -0
- package/dist/components/chat/Header.mjs +10 -0
- package/dist/components/chat/Header.mjs.map +1 -0
- package/dist/components/chat/Icons.d.ts +18 -0
- package/dist/components/chat/Icons.js +321 -0
- package/dist/components/chat/Icons.js.map +1 -0
- package/dist/components/chat/Icons.mjs +32 -0
- package/dist/components/chat/Icons.mjs.map +1 -0
- package/dist/components/chat/Input.d.ts +7 -0
- package/dist/components/chat/Input.js +324 -0
- package/dist/components/chat/Input.js.map +1 -0
- package/dist/components/chat/Input.mjs +12 -0
- package/dist/components/chat/Input.mjs.map +1 -0
- package/dist/components/chat/Markdown.d.ts +8 -0
- package/dist/components/chat/Markdown.js +583 -0
- package/dist/components/chat/Markdown.js.map +1 -0
- package/dist/components/chat/Markdown.mjs +11 -0
- package/dist/components/chat/Markdown.mjs.map +1 -0
- package/dist/components/chat/Messages.d.ts +12 -0
- package/dist/components/chat/Messages.js +217 -0
- package/dist/components/chat/Messages.js.map +1 -0
- package/dist/components/chat/Messages.mjs +12 -0
- package/dist/components/chat/Messages.mjs.map +1 -0
- package/dist/components/chat/Modal.d.ts +51 -0
- package/dist/components/chat/Modal.js +2626 -0
- package/dist/components/chat/Modal.js.map +1 -0
- package/dist/components/chat/Modal.mjs +34 -0
- package/dist/components/chat/Modal.mjs.map +1 -0
- package/dist/components/chat/Popup.d.ts +13 -0
- package/dist/components/chat/Popup.js +2637 -0
- package/dist/components/chat/Popup.js.map +1 -0
- package/dist/components/chat/Popup.mjs +35 -0
- package/dist/components/chat/Popup.mjs.map +1 -0
- package/dist/components/chat/Response.d.ts +7 -0
- package/dist/components/chat/Response.js +64 -0
- package/dist/components/chat/Response.js.map +1 -0
- package/dist/components/chat/Response.mjs +10 -0
- package/dist/components/chat/Response.mjs.map +1 -0
- package/dist/components/chat/Sidebar.d.ts +13 -0
- package/dist/components/chat/Sidebar.js +2646 -0
- package/dist/components/chat/Sidebar.js.map +1 -0
- package/dist/components/chat/Sidebar.mjs +35 -0
- package/dist/components/chat/Sidebar.mjs.map +1 -0
- package/dist/components/chat/Suggestion.d.ts +14 -0
- package/dist/components/chat/Suggestion.js +181 -0
- package/dist/components/chat/Suggestion.js.map +1 -0
- package/dist/components/chat/Suggestion.mjs +11 -0
- package/dist/components/chat/Suggestion.mjs.map +1 -0
- package/dist/components/chat/Textarea.d.ts +13 -0
- package/dist/components/chat/Textarea.js +73 -0
- package/dist/components/chat/Textarea.js.map +1 -0
- package/dist/components/chat/Textarea.mjs +8 -0
- package/dist/components/chat/Textarea.mjs.map +1 -0
- package/dist/components/chat/Window.d.ts +7 -0
- package/dist/components/chat/Window.js +164 -0
- package/dist/components/chat/Window.js.map +1 -0
- package/dist/components/chat/Window.mjs +10 -0
- package/dist/components/chat/Window.mjs.map +1 -0
- package/dist/components/chat/index.d.ts +11 -0
- package/dist/components/chat/index.js +2661 -0
- package/dist/components/chat/index.js.map +1 -0
- package/dist/components/chat/index.mjs +47 -0
- package/dist/components/chat/index.mjs.map +1 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.js +131 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +10 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.js +111 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.mjs +10 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderResultMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderResultMessage.js +64 -0
- package/dist/components/chat/messages/RenderResultMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderResultMessage.mjs +10 -0
- package/dist/components/chat/messages/RenderResultMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderTextMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderTextMessage.js +629 -0
- package/dist/components/chat/messages/RenderTextMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderTextMessage.mjs +13 -0
- package/dist/components/chat/messages/RenderTextMessage.mjs.map +1 -0
- package/dist/components/chat/props.d.ts +46 -0
- package/dist/components/chat/props.js +19 -0
- package/dist/components/chat/props.js.map +1 -0
- package/dist/components/chat/props.mjs +2 -0
- package/dist/components/chat/props.mjs.map +1 -0
- package/dist/components/dev-console/console.d.ts +10 -0
- package/dist/components/dev-console/console.js +720 -0
- package/dist/components/dev-console/console.js.map +1 -0
- package/dist/components/dev-console/console.mjs +17 -0
- package/dist/components/dev-console/console.mjs.map +1 -0
- package/dist/components/dev-console/icons.d.ts +9 -0
- package/dist/components/dev-console/icons.js +120 -0
- package/dist/components/dev-console/icons.js.map +1 -0
- package/dist/components/dev-console/icons.mjs +16 -0
- package/dist/components/dev-console/icons.mjs.map +1 -0
- package/dist/components/dev-console/index.d.ts +5 -0
- package/dist/components/dev-console/index.js +720 -0
- package/dist/components/dev-console/index.js.map +1 -0
- package/dist/components/dev-console/index.mjs +18 -0
- package/dist/components/dev-console/index.mjs.map +1 -0
- package/dist/components/dev-console/types.d.ts +9 -0
- package/dist/components/dev-console/types.js +19 -0
- package/dist/components/dev-console/types.js.map +1 -0
- package/dist/components/dev-console/types.mjs +1 -0
- package/dist/components/dev-console/types.mjs.map +1 -0
- package/dist/components/dev-console/utils.d.ts +10 -0
- package/dist/components/dev-console/utils.js +188 -0
- package/dist/components/dev-console/utils.js.map +1 -0
- package/dist/components/dev-console/utils.mjs +16 -0
- package/dist/components/dev-console/utils.mjs.map +1 -0
- package/dist/components/help-modal/icons.d.ts +9 -0
- package/dist/components/help-modal/icons.js +107 -0
- package/dist/components/help-modal/icons.js.map +1 -0
- package/dist/components/help-modal/icons.mjs +12 -0
- package/dist/components/help-modal/icons.mjs.map +1 -0
- package/dist/components/help-modal/index.d.ts +2 -0
- package/dist/components/help-modal/index.js +255 -0
- package/dist/components/help-modal/index.js.map +1 -0
- package/dist/components/help-modal/index.mjs +10 -0
- package/dist/components/help-modal/index.mjs.map +1 -0
- package/dist/components/help-modal/modal.d.ts +5 -0
- package/dist/components/help-modal/modal.js +253 -0
- package/dist/components/help-modal/modal.js.map +1 -0
- package/dist/components/help-modal/modal.mjs +9 -0
- package/dist/components/help-modal/modal.mjs.map +1 -0
- package/dist/components/index.d.ts +14 -0
- package/dist/components/index.js +2665 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +54 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.js +19 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +2 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +55 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +9 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +83 -0
- package/dist/hooks/use-copilot-chat-suggestions.js +53 -0
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
- package/dist/hooks/use-copy-to-clipboard.d.ts +9 -0
- package/dist/hooks/use-copy-to-clipboard.js +60 -0
- package/dist/hooks/use-copy-to-clipboard.js.map +1 -0
- package/dist/hooks/use-copy-to-clipboard.mjs +8 -0
- package/dist/hooks/use-copy-to-clipboard.mjs.map +1 -0
- package/dist/hooks/use-push-to-talk.d.ts +19 -0
- package/dist/hooks/use-push-to-talk.js +195 -0
- package/dist/hooks/use-push-to-talk.js.map +1 -0
- package/dist/hooks/use-push-to-talk.mjs +12 -0
- package/dist/hooks/use-push-to-talk.mjs.map +1 -0
- package/dist/index.css +751 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +2693 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +62 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.js +76 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/utils.mjs +34 -0
- package/dist/lib/utils.mjs.map +1 -0
- package/dist/lib/utils.test.d.ts +2 -0
- package/dist/lib/utils.test.js +9 -0
- package/dist/lib/utils.test.js.map +1 -0
- package/dist/lib/utils.test.mjs +7 -0
- package/dist/lib/utils.test.mjs.map +1 -0
- package/dist/types/css.d.ts +16 -0
- package/dist/types/css.js +19 -0
- package/dist/types/css.js.map +1 -0
- package/dist/types/css.mjs +1 -0
- package/dist/types/css.mjs.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +2 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/suggestions.d.ts +8 -0
- package/dist/types/suggestions.js +19 -0
- package/dist/types/suggestions.js.map +1 -0
- package/dist/types/suggestions.mjs +1 -0
- package/dist/types/suggestions.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +78 -0
- package/postcss.config.js +60 -0
- package/src/components/chat/Button.tsx +18 -0
- package/src/components/chat/Chat.tsx +517 -0
- package/src/components/chat/ChatContext.tsx +188 -0
- package/src/components/chat/CodeBlock.tsx +408 -0
- package/src/components/chat/Header.tsx +15 -0
- package/src/components/chat/Icons.tsx +223 -0
- package/src/components/chat/Input.tsx +100 -0
- package/src/components/chat/Markdown.tsx +80 -0
- package/src/components/chat/Messages.tsx +178 -0
- package/src/components/chat/Modal.tsx +117 -0
- package/src/components/chat/Popup.tsx +57 -0
- package/src/components/chat/Response.tsx +12 -0
- package/src/components/chat/Sidebar.tsx +74 -0
- package/src/components/chat/Suggestion.tsx +125 -0
- package/src/components/chat/Textarea.tsx +61 -0
- package/src/components/chat/Window.tsx +153 -0
- package/src/components/chat/index.tsx +5 -0
- package/src/components/chat/messages/RenderActionExecutionMessage.tsx +101 -0
- package/src/components/chat/messages/RenderAgentStateMessage.tsx +92 -0
- package/src/components/chat/messages/RenderResultMessage.tsx +15 -0
- package/src/components/chat/messages/RenderTextMessage.tsx +36 -0
- package/src/components/chat/props.ts +49 -0
- package/src/components/dev-console/console.tsx +281 -0
- package/src/components/dev-console/icons.tsx +92 -0
- package/src/components/dev-console/index.tsx +2 -0
- package/src/components/dev-console/types.ts +7 -0
- package/src/components/dev-console/utils.ts +162 -0
- package/src/components/help-modal/icons.tsx +68 -0
- package/src/components/help-modal/index.tsx +1 -0
- package/src/components/help-modal/modal.tsx +164 -0
- package/src/components/index.ts +2 -0
- package/src/context/index.ts +1 -0
- package/src/css/animations.css +35 -0
- package/src/css/button.css +56 -0
- package/src/css/colors.css +12 -0
- package/src/css/console.css +134 -0
- package/src/css/header.css +43 -0
- package/src/css/input.css +89 -0
- package/src/css/markdown.css +136 -0
- package/src/css/messages.css +73 -0
- package/src/css/panel.css +38 -0
- package/src/css/popup.css +22 -0
- package/src/css/response.css +26 -0
- package/src/css/sidebar.css +34 -0
- package/src/css/suggestions.css +35 -0
- package/src/css/window.css +60 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-copilot-chat-suggestions.tsx +112 -0
- package/src/hooks/use-copy-to-clipboard.tsx +29 -0
- package/src/hooks/use-push-to-talk.tsx +166 -0
- package/src/index.tsx +7 -0
- package/src/lib/utils.test.ts +7 -0
- package/src/lib/utils.ts +27 -0
- package/src/styles.css +14 -0
- package/src/types/css.ts +15 -0
- package/src/types/index.ts +1 -0
- package/src/types/suggestions.ts +6 -0
- package/tailwind.config.js +7 -0
- package/tsconfig.json +12 -0
- package/tsup.config.ts +16 -0
- package/typedoc.json +4 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CopilotContextParams,
|
|
3
|
+
extract,
|
|
4
|
+
CopilotChatSuggestionConfiguration,
|
|
5
|
+
CopilotMessagesContextParams,
|
|
6
|
+
} from "@copilotkit/react-core";
|
|
7
|
+
import { SuggestionsProps } from "./props";
|
|
8
|
+
import { SmallSpinnerIcon } from "./Icons";
|
|
9
|
+
import { CopilotChatSuggestion } from "../../types/suggestions";
|
|
10
|
+
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
11
|
+
import { CopilotRequestType } from "@copilotkit/runtime-client-gql";
|
|
12
|
+
|
|
13
|
+
export function Suggestion({ title, message, onClick, partial, className }: SuggestionsProps) {
|
|
14
|
+
return (
|
|
15
|
+
<button
|
|
16
|
+
disabled={partial}
|
|
17
|
+
onClick={(e) => {
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
onClick(message);
|
|
20
|
+
}}
|
|
21
|
+
className={className || "suggestion"}
|
|
22
|
+
>
|
|
23
|
+
{partial && SmallSpinnerIcon}
|
|
24
|
+
<span>{title}</span>
|
|
25
|
+
</button>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const reloadSuggestions = async (
|
|
30
|
+
context: CopilotContextParams & CopilotMessagesContextParams,
|
|
31
|
+
chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration },
|
|
32
|
+
setCurrentSuggestions: (suggestions: { title: string; message: string }[]) => void,
|
|
33
|
+
abortControllerRef: React.MutableRefObject<AbortController | null>,
|
|
34
|
+
) => {
|
|
35
|
+
const abortController = abortControllerRef.current;
|
|
36
|
+
|
|
37
|
+
const tools = JSON.stringify(
|
|
38
|
+
Object.values(context.actions).map((action) => ({
|
|
39
|
+
name: action.name,
|
|
40
|
+
description: action.description,
|
|
41
|
+
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters)),
|
|
42
|
+
})),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const allSuggestions: CopilotChatSuggestion[] = [];
|
|
46
|
+
|
|
47
|
+
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
48
|
+
try {
|
|
49
|
+
const numOfSuggestionsInstructions =
|
|
50
|
+
config.minSuggestions === 0
|
|
51
|
+
? `Produce up to ${config.maxSuggestions} suggestions. ` +
|
|
52
|
+
`If there are no highly relevant suggestions you can think of, provide an empty array.`
|
|
53
|
+
: `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;
|
|
54
|
+
|
|
55
|
+
const result = await extract({
|
|
56
|
+
context,
|
|
57
|
+
instructions:
|
|
58
|
+
"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. ",
|
|
59
|
+
data:
|
|
60
|
+
config.instructions +
|
|
61
|
+
"\n\n" +
|
|
62
|
+
numOfSuggestionsInstructions +
|
|
63
|
+
"\n\n" +
|
|
64
|
+
"Available tools: " +
|
|
65
|
+
tools +
|
|
66
|
+
"\n\n",
|
|
67
|
+
requestType: CopilotRequestType.Task,
|
|
68
|
+
parameters: [
|
|
69
|
+
{
|
|
70
|
+
name: "suggestions",
|
|
71
|
+
type: "object[]",
|
|
72
|
+
attributes: [
|
|
73
|
+
{
|
|
74
|
+
name: "title",
|
|
75
|
+
description:
|
|
76
|
+
"The title of the suggestion. This is shown as a button and should be short.",
|
|
77
|
+
type: "string",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: "message",
|
|
81
|
+
description:
|
|
82
|
+
"The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.",
|
|
83
|
+
type: "string",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
include: {
|
|
89
|
+
messages: true,
|
|
90
|
+
readable: true,
|
|
91
|
+
},
|
|
92
|
+
abortSignal: abortController?.signal,
|
|
93
|
+
stream: ({ status, args }) => {
|
|
94
|
+
const suggestions = args.suggestions || [];
|
|
95
|
+
const newSuggestions: CopilotChatSuggestion[] = [];
|
|
96
|
+
for (let i = 0; i < suggestions.length; i++) {
|
|
97
|
+
// if GPT provides too many suggestions, limit the number of suggestions
|
|
98
|
+
if (config.maxSuggestions !== undefined && i >= config.maxSuggestions) {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
const { title, message } = suggestions[i];
|
|
102
|
+
|
|
103
|
+
// If this is the last suggestion and the status is not complete, mark it as partial
|
|
104
|
+
const partial = i == suggestions.length - 1 && status !== "complete";
|
|
105
|
+
|
|
106
|
+
newSuggestions.push({
|
|
107
|
+
title,
|
|
108
|
+
message,
|
|
109
|
+
partial,
|
|
110
|
+
className: config.className,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
setCurrentSuggestions([...allSuggestions, ...newSuggestions]);
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
allSuggestions.push(...result.suggestions);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error("Error loading suggestions", error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (abortControllerRef.current === abortController) {
|
|
123
|
+
abortControllerRef.current = null;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from "react";
|
|
2
|
+
|
|
3
|
+
interface AutoResizingTextareaProps {
|
|
4
|
+
maxRows?: number;
|
|
5
|
+
placeholder?: string;
|
|
6
|
+
value: string;
|
|
7
|
+
onChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
8
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;
|
|
9
|
+
autoFocus?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const AutoResizingTextarea = forwardRef<HTMLTextAreaElement, AutoResizingTextareaProps>(
|
|
13
|
+
({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
|
|
14
|
+
const internalTextareaRef = useRef<HTMLTextAreaElement>(null);
|
|
15
|
+
const [maxHeight, setMaxHeight] = useState<number>(0);
|
|
16
|
+
|
|
17
|
+
useImperativeHandle(ref, () => internalTextareaRef.current as HTMLTextAreaElement);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const calculateMaxHeight = () => {
|
|
21
|
+
const textarea = internalTextareaRef.current;
|
|
22
|
+
if (textarea) {
|
|
23
|
+
textarea.style.height = "auto";
|
|
24
|
+
const singleRowHeight = textarea.scrollHeight;
|
|
25
|
+
setMaxHeight(singleRowHeight * maxRows);
|
|
26
|
+
if (autoFocus) {
|
|
27
|
+
textarea.focus();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
calculateMaxHeight();
|
|
33
|
+
}, [maxRows]);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const textarea = internalTextareaRef.current;
|
|
37
|
+
if (textarea) {
|
|
38
|
+
textarea.style.height = "auto";
|
|
39
|
+
textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
|
|
40
|
+
}
|
|
41
|
+
}, [value, maxHeight]);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<textarea
|
|
45
|
+
ref={internalTextareaRef}
|
|
46
|
+
value={value}
|
|
47
|
+
onChange={onChange}
|
|
48
|
+
onKeyDown={onKeyDown}
|
|
49
|
+
placeholder={placeholder}
|
|
50
|
+
style={{
|
|
51
|
+
overflow: "auto",
|
|
52
|
+
resize: "none",
|
|
53
|
+
maxHeight: `${maxHeight}px`,
|
|
54
|
+
}}
|
|
55
|
+
rows={1}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export default AutoResizingTextarea;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import React, { useCallback, useEffect } from "react";
|
|
2
|
+
import { WindowProps } from "./props";
|
|
3
|
+
import { useChatContext } from "./ChatContext";
|
|
4
|
+
|
|
5
|
+
export const Window = ({
|
|
6
|
+
children,
|
|
7
|
+
clickOutsideToClose,
|
|
8
|
+
shortcut,
|
|
9
|
+
hitEscapeToClose,
|
|
10
|
+
}: WindowProps) => {
|
|
11
|
+
const windowRef = React.useRef<HTMLDivElement>(null);
|
|
12
|
+
|
|
13
|
+
const { open, setOpen } = useChatContext();
|
|
14
|
+
|
|
15
|
+
const handleClickOutside = useCallback(
|
|
16
|
+
(event: MouseEvent) => {
|
|
17
|
+
if (!clickOutsideToClose) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const parentElement = windowRef.current?.parentElement;
|
|
22
|
+
|
|
23
|
+
let className = "";
|
|
24
|
+
if (event.target instanceof HTMLElement) {
|
|
25
|
+
className = event.target.className;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
open &&
|
|
30
|
+
parentElement &&
|
|
31
|
+
!parentElement.contains(event.target as any) &&
|
|
32
|
+
// prevent closing the window when clicking on the debug menu
|
|
33
|
+
!className.includes("copilotKitDebugMenu")
|
|
34
|
+
) {
|
|
35
|
+
setOpen(false);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
[clickOutsideToClose, open, setOpen],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const handleKeyDown = useCallback(
|
|
42
|
+
(event: KeyboardEvent) => {
|
|
43
|
+
const target = event.target as HTMLElement;
|
|
44
|
+
const isInput =
|
|
45
|
+
target.tagName === "INPUT" ||
|
|
46
|
+
target.tagName === "SELECT" ||
|
|
47
|
+
target.tagName === "TEXTAREA" ||
|
|
48
|
+
target.isContentEditable;
|
|
49
|
+
|
|
50
|
+
const isDescendantOfWrapper = windowRef.current?.contains(target);
|
|
51
|
+
|
|
52
|
+
if (
|
|
53
|
+
open &&
|
|
54
|
+
event.key === "Escape" &&
|
|
55
|
+
(!isInput || isDescendantOfWrapper) &&
|
|
56
|
+
hitEscapeToClose
|
|
57
|
+
) {
|
|
58
|
+
setOpen(false);
|
|
59
|
+
} else if (
|
|
60
|
+
event.key === shortcut &&
|
|
61
|
+
((isMacOS() && event.metaKey) || (!isMacOS() && event.ctrlKey)) &&
|
|
62
|
+
(!isInput || isDescendantOfWrapper)
|
|
63
|
+
) {
|
|
64
|
+
setOpen(!open);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
[hitEscapeToClose, shortcut, open, setOpen],
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const adjustForMobile = useCallback(() => {
|
|
71
|
+
const copilotKitWindow = windowRef.current;
|
|
72
|
+
const vv = window.visualViewport;
|
|
73
|
+
if (!copilotKitWindow || !vv) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (window.innerWidth < 640 && open) {
|
|
78
|
+
copilotKitWindow.style.height = `${vv.height}px`;
|
|
79
|
+
copilotKitWindow.style.left = `${vv.offsetLeft}px`;
|
|
80
|
+
copilotKitWindow.style.top = `${vv.offsetTop}px`;
|
|
81
|
+
|
|
82
|
+
document.body.style.position = "fixed";
|
|
83
|
+
document.body.style.width = "100%";
|
|
84
|
+
document.body.style.height = `${window.innerHeight}px`;
|
|
85
|
+
document.body.style.overflow = "hidden";
|
|
86
|
+
document.body.style.touchAction = "none";
|
|
87
|
+
|
|
88
|
+
// Prevent scrolling on iOS
|
|
89
|
+
document.body.addEventListener("touchmove", preventScroll, {
|
|
90
|
+
passive: false,
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
copilotKitWindow.style.height = "";
|
|
94
|
+
copilotKitWindow.style.left = "";
|
|
95
|
+
copilotKitWindow.style.top = "";
|
|
96
|
+
document.body.style.position = "";
|
|
97
|
+
document.body.style.height = "";
|
|
98
|
+
document.body.style.width = "";
|
|
99
|
+
document.body.style.overflow = "";
|
|
100
|
+
document.body.style.top = "";
|
|
101
|
+
document.body.style.touchAction = "";
|
|
102
|
+
|
|
103
|
+
document.body.removeEventListener("touchmove", preventScroll);
|
|
104
|
+
}
|
|
105
|
+
}, [open]);
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
109
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
110
|
+
if (window.visualViewport) {
|
|
111
|
+
window.visualViewport.addEventListener("resize", adjustForMobile);
|
|
112
|
+
adjustForMobile();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return () => {
|
|
116
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
117
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
118
|
+
if (window.visualViewport) {
|
|
119
|
+
window.visualViewport.removeEventListener("resize", adjustForMobile);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}, [adjustForMobile, handleClickOutside, handleKeyDown]);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<div className={`copilotKitWindow${open ? " open" : ""}`} ref={windowRef}>
|
|
126
|
+
{children}
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const preventScroll = (event: TouchEvent): void => {
|
|
132
|
+
let targetElement = event.target as Element;
|
|
133
|
+
|
|
134
|
+
// Function to check if the target has the parent with a given class
|
|
135
|
+
const hasParentWithClass = (element: Element, className: string): boolean => {
|
|
136
|
+
while (element && element !== document.body) {
|
|
137
|
+
if (element.classList.contains(className)) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
element = element.parentElement!;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Check if the target of the touch event is inside an element with the 'copilotKitMessages' class
|
|
146
|
+
if (!hasParentWithClass(targetElement, "copilotKitMessages")) {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
function isMacOS() {
|
|
152
|
+
return /Mac|iMac|Macintosh/i.test(navigator.userAgent);
|
|
153
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { MessageStatusCode } from "@copilotkit/runtime-client-gql";
|
|
2
|
+
import { RenderMessageProps } from "../props";
|
|
3
|
+
import { useChatContext } from "../ChatContext";
|
|
4
|
+
import { RenderFunctionStatus, useCopilotContext } from "@copilotkit/react-core";
|
|
5
|
+
|
|
6
|
+
export function RenderActionExecutionMessage(props: RenderMessageProps) {
|
|
7
|
+
const { message, inProgress, index, isCurrentMessage, actionResult } = props;
|
|
8
|
+
const { chatComponentsCache } = useCopilotContext();
|
|
9
|
+
const { icons } = useChatContext();
|
|
10
|
+
|
|
11
|
+
if (message.isActionExecutionMessage()) {
|
|
12
|
+
if (
|
|
13
|
+
chatComponentsCache.current !== null &&
|
|
14
|
+
(chatComponentsCache.current.actions[message.name] ||
|
|
15
|
+
chatComponentsCache.current.actions["*"])
|
|
16
|
+
) {
|
|
17
|
+
const render =
|
|
18
|
+
chatComponentsCache.current.actions[message.name] ||
|
|
19
|
+
chatComponentsCache.current.actions["*"];
|
|
20
|
+
// render a static string
|
|
21
|
+
if (typeof render === "string") {
|
|
22
|
+
// when render is static, we show it only when in progress
|
|
23
|
+
if (isCurrentMessage && inProgress) {
|
|
24
|
+
return (
|
|
25
|
+
<div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>
|
|
26
|
+
{icons.spinnerIcon} <span className="inProgressLabel">{render}</span>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
// Done - silent by default to avoid a series of "done" messages
|
|
31
|
+
else {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// render is a function
|
|
36
|
+
else {
|
|
37
|
+
const args = message.arguments;
|
|
38
|
+
|
|
39
|
+
let status: RenderFunctionStatus = "inProgress";
|
|
40
|
+
|
|
41
|
+
if (actionResult !== undefined) {
|
|
42
|
+
status = "complete";
|
|
43
|
+
} else if (message.status.code !== MessageStatusCode.Pending) {
|
|
44
|
+
status = "executing";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const toRender = render({
|
|
49
|
+
status: status as any,
|
|
50
|
+
args,
|
|
51
|
+
result: actionResult,
|
|
52
|
+
name: message.name,
|
|
53
|
+
});
|
|
54
|
+
// No result and complete: stay silent
|
|
55
|
+
if (!toRender && status === "complete") {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (typeof toRender === "string") {
|
|
59
|
+
return (
|
|
60
|
+
<div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>
|
|
61
|
+
{isCurrentMessage && inProgress && icons.spinnerIcon} {toRender}
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
} else {
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
key={index}
|
|
68
|
+
data-message-type="action-render"
|
|
69
|
+
className="copilotKitCustomAssistantMessage"
|
|
70
|
+
>
|
|
71
|
+
{toRender}
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
console.error(`Error executing render function for action ${message.name}: ${e}`);
|
|
77
|
+
return (
|
|
78
|
+
<div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>
|
|
79
|
+
{isCurrentMessage && inProgress && icons.spinnerIcon}
|
|
80
|
+
<b>❌ Error executing render: {message.name}</b>
|
|
81
|
+
<br />
|
|
82
|
+
{e instanceof Error ? e.message : String(e)}
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// No render function found- show the default message
|
|
89
|
+
else if (!inProgress || !isCurrentMessage) {
|
|
90
|
+
// Done - silent by default to avoid a series of "done" messages
|
|
91
|
+
return null;
|
|
92
|
+
} else {
|
|
93
|
+
// In progress
|
|
94
|
+
return (
|
|
95
|
+
<div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>
|
|
96
|
+
{icons.spinnerIcon}
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { AgentStateMessage } from "@copilotkit/runtime-client-gql";
|
|
2
|
+
import { RenderMessageProps } from "../props";
|
|
3
|
+
import { useChatContext } from "../ChatContext";
|
|
4
|
+
import { CoagentInChatRenderFunction, useCopilotContext } from "@copilotkit/react-core";
|
|
5
|
+
|
|
6
|
+
export function RenderAgentStateMessage(props: RenderMessageProps) {
|
|
7
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
8
|
+
const { chatComponentsCache } = useCopilotContext();
|
|
9
|
+
const { icons } = useChatContext();
|
|
10
|
+
|
|
11
|
+
if (message.isAgentStateMessage()) {
|
|
12
|
+
let render: string | CoagentInChatRenderFunction | undefined;
|
|
13
|
+
|
|
14
|
+
if (chatComponentsCache.current !== null) {
|
|
15
|
+
render =
|
|
16
|
+
chatComponentsCache.current.coAgentStateRenders[
|
|
17
|
+
`${message.agentName}-${message.nodeName}`
|
|
18
|
+
] || chatComponentsCache.current.coAgentStateRenders[`${message.agentName}-global`];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (render) {
|
|
22
|
+
// render a static string
|
|
23
|
+
if (typeof render === "string") {
|
|
24
|
+
// when render is static, we show it only when in progress
|
|
25
|
+
if (isCurrentMessage && inProgress) {
|
|
26
|
+
return (
|
|
27
|
+
<div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>
|
|
28
|
+
{icons.spinnerIcon} <span className="inProgressLabel">{render}</span>
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
// Done - silent by default to avoid a series of "done" messages
|
|
33
|
+
else {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// render is a function
|
|
38
|
+
else {
|
|
39
|
+
const state = message.state;
|
|
40
|
+
|
|
41
|
+
let status = message.active ? "inProgress" : "complete";
|
|
42
|
+
|
|
43
|
+
const toRender = render({
|
|
44
|
+
status: status as any,
|
|
45
|
+
state,
|
|
46
|
+
nodeName: message.nodeName,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// No result and complete: stay silent
|
|
50
|
+
if (!toRender && status === "complete") {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!toRender && isCurrentMessage && inProgress) {
|
|
55
|
+
return (
|
|
56
|
+
<div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>
|
|
57
|
+
{icons.spinnerIcon}
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
} else if (!toRender) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (typeof toRender === "string") {
|
|
65
|
+
return (
|
|
66
|
+
<div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>
|
|
67
|
+
{isCurrentMessage && inProgress && icons.spinnerIcon} {toRender}
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
} else {
|
|
71
|
+
return (
|
|
72
|
+
<div key={index} className="copilotKitCustomAssistantMessage">
|
|
73
|
+
{toRender}
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// No render function found- show the default message
|
|
80
|
+
else if (!inProgress || !isCurrentMessage) {
|
|
81
|
+
// Done - silent by default to avoid a series of "done" messages
|
|
82
|
+
return null;
|
|
83
|
+
} else {
|
|
84
|
+
// In progress
|
|
85
|
+
return (
|
|
86
|
+
<div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>
|
|
87
|
+
{icons.spinnerIcon}
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ResultMessage } from "@copilotkit/runtime-client-gql";
|
|
2
|
+
import { RenderMessageProps } from "../props";
|
|
3
|
+
import { useChatContext } from "../ChatContext";
|
|
4
|
+
|
|
5
|
+
export function RenderResultMessage(props: RenderMessageProps) {
|
|
6
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
7
|
+
const { icons } = useChatContext();
|
|
8
|
+
if (message.isResultMessage() && inProgress && isCurrentMessage) {
|
|
9
|
+
return (
|
|
10
|
+
<div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>
|
|
11
|
+
{icons.spinnerIcon}
|
|
12
|
+
</div>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { TextMessage } from "@copilotkit/runtime-client-gql";
|
|
2
|
+
import { RenderMessageProps } from "../props";
|
|
3
|
+
import { Markdown } from "../Markdown";
|
|
4
|
+
import { useChatContext } from "../ChatContext";
|
|
5
|
+
|
|
6
|
+
export function RenderTextMessage(props: RenderMessageProps) {
|
|
7
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
8
|
+
const { icons } = useChatContext();
|
|
9
|
+
if (message.isTextMessage()) {
|
|
10
|
+
if (message.role === "user") {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
key={index}
|
|
14
|
+
data-message-role="user"
|
|
15
|
+
className="copilotKitMessage copilotKitUserMessage"
|
|
16
|
+
>
|
|
17
|
+
{message.content}
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
} else if (message.role == "assistant") {
|
|
21
|
+
return (
|
|
22
|
+
<div
|
|
23
|
+
key={index}
|
|
24
|
+
data-message-role="assistant"
|
|
25
|
+
className={`copilotKitMessage copilotKitAssistantMessage`}
|
|
26
|
+
>
|
|
27
|
+
{isCurrentMessage && inProgress && !message.content ? (
|
|
28
|
+
icons.spinnerIcon
|
|
29
|
+
) : (
|
|
30
|
+
<Markdown content={message.content} />
|
|
31
|
+
)}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Message } from "@copilotkit/runtime-client-gql";
|
|
2
|
+
|
|
3
|
+
export interface ButtonProps {}
|
|
4
|
+
|
|
5
|
+
export interface WindowProps {
|
|
6
|
+
clickOutsideToClose: boolean;
|
|
7
|
+
hitEscapeToClose: boolean;
|
|
8
|
+
shortcut: string;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface HeaderProps {}
|
|
13
|
+
|
|
14
|
+
export interface SuggestionsProps {
|
|
15
|
+
title: string;
|
|
16
|
+
message: string;
|
|
17
|
+
partial?: boolean;
|
|
18
|
+
className?: string;
|
|
19
|
+
onClick: (message: string) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MessagesProps {
|
|
23
|
+
messages: Message[];
|
|
24
|
+
inProgress: boolean;
|
|
25
|
+
children?: React.ReactNode;
|
|
26
|
+
RenderTextMessage: React.ComponentType<RenderMessageProps>;
|
|
27
|
+
RenderActionExecutionMessage: React.ComponentType<RenderMessageProps>;
|
|
28
|
+
RenderAgentStateMessage: React.ComponentType<RenderMessageProps>;
|
|
29
|
+
RenderResultMessage: React.ComponentType<RenderMessageProps>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface RenderMessageProps {
|
|
33
|
+
message: Message;
|
|
34
|
+
inProgress: boolean;
|
|
35
|
+
index: number;
|
|
36
|
+
isCurrentMessage: boolean;
|
|
37
|
+
actionResult?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface InputProps {
|
|
41
|
+
inProgress: boolean;
|
|
42
|
+
onSend: (text: string) => Promise<Message>;
|
|
43
|
+
isVisible?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ResponseButtonProps {
|
|
47
|
+
onClick: () => void;
|
|
48
|
+
inProgress: boolean;
|
|
49
|
+
}
|