@copilotkit/react-ui 0.0.0-feat-dynamic-copilotcloud-qa-20250117190454
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 +2436 -0
- package/README.md +46 -0
- package/dist/chunk-34FREWVK.mjs +180 -0
- package/dist/chunk-34FREWVK.mjs.map +1 -0
- package/dist/chunk-3VNMQWGT.mjs +25 -0
- package/dist/chunk-3VNMQWGT.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-B23XDGH4.mjs +30 -0
- package/dist/chunk-B23XDGH4.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-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-F7VWGY77.mjs +22 -0
- package/dist/chunk-F7VWGY77.mjs.map +1 -0
- package/dist/chunk-FZC7X5PK.mjs +262 -0
- package/dist/chunk-FZC7X5PK.mjs.map +1 -0
- package/dist/chunk-HEIDCT7I.mjs +10 -0
- package/dist/chunk-HEIDCT7I.mjs.map +1 -0
- package/dist/chunk-I7MG52I5.mjs +314 -0
- package/dist/chunk-I7MG52I5.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-MRXNTQOX.mjs +59 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-O6JFOQQA.mjs +21 -0
- package/dist/chunk-O6JFOQQA.mjs.map +1 -0
- package/dist/chunk-OFYI4UU4.mjs +35 -0
- package/dist/chunk-OFYI4UU4.mjs.map +1 -0
- package/dist/chunk-OTPAZXVR.mjs +92 -0
- package/dist/chunk-OTPAZXVR.mjs.map +1 -0
- package/dist/chunk-P5A3A5FO.mjs +112 -0
- package/dist/chunk-P5A3A5FO.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-S5MBUNGN.mjs +140 -0
- package/dist/chunk-S5MBUNGN.mjs.map +1 -0
- package/dist/chunk-SQMEPWVT.mjs +1 -0
- package/dist/chunk-SQMEPWVT.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-UWWMAJ7R.mjs +100 -0
- package/dist/chunk-UWWMAJ7R.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-VKVNMHM5.mjs +105 -0
- package/dist/chunk-VKVNMHM5.mjs.map +1 -0
- package/dist/chunk-WB3YULQ4.mjs +1 -0
- package/dist/chunk-WB3YULQ4.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/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 +156 -0
- package/dist/components/chat/Chat.js +2540 -0
- package/dist/components/chat/Chat.js.map +1 -0
- package/dist/components/chat/Chat.mjs +36 -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 +227 -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 +2743 -0
- package/dist/components/chat/Modal.js.map +1 -0
- package/dist/components/chat/Modal.mjs +36 -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 +2754 -0
- package/dist/components/chat/Popup.js.map +1 -0
- package/dist/components/chat/Popup.mjs +37 -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 +2763 -0
- package/dist/components/chat/Sidebar.js.map +1 -0
- package/dist/components/chat/Sidebar.mjs +37 -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 +14 -0
- package/dist/components/chat/index.js +2784 -0
- package/dist/components/chat/index.js.map +1 -0
- package/dist/components/chat/index.mjs +58 -0
- package/dist/components/chat/index.mjs.map +1 -0
- package/dist/components/chat/messages/AssistantMessage.d.ts +7 -0
- package/dist/components/chat/messages/AssistantMessage.js +615 -0
- package/dist/components/chat/messages/AssistantMessage.js.map +1 -0
- package/dist/components/chat/messages/AssistantMessage.mjs +13 -0
- package/dist/components/chat/messages/AssistantMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.js +136 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +8 -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 +124 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.mjs +8 -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 +46 -0
- package/dist/components/chat/messages/RenderResultMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderResultMessage.mjs +8 -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 +59 -0
- package/dist/components/chat/messages/RenderTextMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderTextMessage.mjs +8 -0
- package/dist/components/chat/messages/RenderTextMessage.mjs.map +1 -0
- package/dist/components/chat/messages/UserMessage.d.ts +7 -0
- package/dist/components/chat/messages/UserMessage.js +34 -0
- package/dist/components/chat/messages/UserMessage.js.map +1 -0
- package/dist/components/chat/messages/UserMessage.mjs +8 -0
- package/dist/components/chat/messages/UserMessage.mjs.map +1 -0
- package/dist/components/chat/props.d.ts +81 -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 +17 -0
- package/dist/components/index.js +2788 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +65 -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 +19 -0
- package/dist/index.js +2816 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +73 -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 +541 -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 +188 -0
- package/src/components/chat/Modal.tsx +124 -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 +8 -0
- package/src/components/chat/messages/AssistantMessage.tsx +20 -0
- package/src/components/chat/messages/RenderActionExecutionMessage.tsx +122 -0
- package/src/components/chat/messages/RenderAgentStateMessage.tsx +112 -0
- package/src/components/chat/messages/RenderResultMessage.tsx +17 -0
- package/src/components/chat/messages/RenderTextMessage.tsx +29 -0
- package/src/components/chat/messages/UserMessage.tsx +5 -0
- package/src/components/chat/props.ts +92 -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,223 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
export const OpenIcon = (
|
|
4
|
+
<svg
|
|
5
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
6
|
+
viewBox="0 0 24 24"
|
|
7
|
+
fill="currentColor"
|
|
8
|
+
width="24"
|
|
9
|
+
height="24"
|
|
10
|
+
>
|
|
11
|
+
<g transform="translate(24, 0) scale(-1, 1)">
|
|
12
|
+
<path
|
|
13
|
+
fillRule="evenodd"
|
|
14
|
+
d="M5.337 21.718a6.707 6.707 0 01-.533-.074.75.75 0 01-.44-1.223 3.73 3.73 0 00.814-1.686c.023-.115-.022-.317-.254-.543C3.274 16.587 2.25 14.41 2.25 12c0-5.03 4.428-9 9.75-9s9.75 3.97 9.75 9c0 5.03-4.428 9-9.75 9-.833 0-1.643-.097-2.417-.279a6.721 6.721 0 01-4.246.997z"
|
|
15
|
+
clipRule="evenodd"
|
|
16
|
+
/>
|
|
17
|
+
</g>
|
|
18
|
+
</svg>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const CloseIcon = (
|
|
22
|
+
<svg
|
|
23
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
24
|
+
fill="none"
|
|
25
|
+
viewBox="0 0 24 24"
|
|
26
|
+
strokeWidth="1.5"
|
|
27
|
+
stroke="currentColor"
|
|
28
|
+
width="24"
|
|
29
|
+
height="24"
|
|
30
|
+
>
|
|
31
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" />
|
|
32
|
+
</svg>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export const HeaderCloseIcon = (
|
|
36
|
+
<svg
|
|
37
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
38
|
+
fill="none"
|
|
39
|
+
viewBox="0 0 24 24"
|
|
40
|
+
strokeWidth="1.5"
|
|
41
|
+
stroke="currentColor"
|
|
42
|
+
width="24"
|
|
43
|
+
height="24"
|
|
44
|
+
>
|
|
45
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
46
|
+
</svg>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
export const SendIcon = (
|
|
50
|
+
<svg
|
|
51
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
52
|
+
fill="none"
|
|
53
|
+
viewBox="0 0 24 24"
|
|
54
|
+
strokeWidth={1.5}
|
|
55
|
+
stroke="currentColor"
|
|
56
|
+
width="24"
|
|
57
|
+
height="24"
|
|
58
|
+
>
|
|
59
|
+
<path
|
|
60
|
+
strokeLinecap="round"
|
|
61
|
+
strokeLinejoin="round"
|
|
62
|
+
d="M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5"
|
|
63
|
+
/>
|
|
64
|
+
</svg>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
export const SpinnerIcon = (
|
|
68
|
+
<svg
|
|
69
|
+
style={{
|
|
70
|
+
animation: "copilotKitSpinAnimation 1s linear infinite",
|
|
71
|
+
color: "rgb(107 114 128)",
|
|
72
|
+
}}
|
|
73
|
+
width="24"
|
|
74
|
+
height="24"
|
|
75
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
76
|
+
fill="none"
|
|
77
|
+
viewBox="0 0 24 24"
|
|
78
|
+
>
|
|
79
|
+
<circle
|
|
80
|
+
style={{ opacity: 0.25 }}
|
|
81
|
+
cx="12"
|
|
82
|
+
cy="12"
|
|
83
|
+
r="10"
|
|
84
|
+
stroke="currentColor"
|
|
85
|
+
strokeWidth="4"
|
|
86
|
+
></circle>
|
|
87
|
+
<path
|
|
88
|
+
style={{ opacity: 0.75 }}
|
|
89
|
+
fill="currentColor"
|
|
90
|
+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
91
|
+
></path>
|
|
92
|
+
</svg>
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
export const SmallSpinnerIcon = (
|
|
96
|
+
<svg
|
|
97
|
+
style={{
|
|
98
|
+
animation: "copilotKitSpinAnimation 1s linear infinite",
|
|
99
|
+
}}
|
|
100
|
+
width="13"
|
|
101
|
+
height="13"
|
|
102
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
103
|
+
fill="none"
|
|
104
|
+
viewBox="0 0 24 24"
|
|
105
|
+
>
|
|
106
|
+
<circle
|
|
107
|
+
style={{ opacity: 0.25 }}
|
|
108
|
+
cx="12"
|
|
109
|
+
cy="12"
|
|
110
|
+
r="10"
|
|
111
|
+
stroke="currentColor"
|
|
112
|
+
strokeWidth="4"
|
|
113
|
+
></circle>
|
|
114
|
+
<path
|
|
115
|
+
style={{ opacity: 0.75 }}
|
|
116
|
+
fill="currentColor"
|
|
117
|
+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
118
|
+
></path>
|
|
119
|
+
</svg>
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
export const ActivityIcon = (
|
|
123
|
+
<svg
|
|
124
|
+
style={{
|
|
125
|
+
display: "inline-block",
|
|
126
|
+
marginLeft: "0.25rem",
|
|
127
|
+
marginRight: "0.25rem",
|
|
128
|
+
}}
|
|
129
|
+
height="24"
|
|
130
|
+
width="24"
|
|
131
|
+
viewBox="0 0 27 27"
|
|
132
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
133
|
+
fill="currentColor"
|
|
134
|
+
>
|
|
135
|
+
<circle className="copilotKitActivityDot1" cx="4" cy="12" r="3" />
|
|
136
|
+
<circle className="copilotKitActivityDot1 copilotKitActivityDot2" cx="12" cy="12" r="3" />
|
|
137
|
+
<circle className="copilotKitActivityDot1 copilotKitActivityDot3" cx="20" cy="12" r="3" />
|
|
138
|
+
</svg>
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
export function CheckIcon({ className, ...props }: React.ComponentProps<"svg">) {
|
|
142
|
+
return (
|
|
143
|
+
<svg
|
|
144
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
145
|
+
viewBox="0 0 256 256"
|
|
146
|
+
fill="currentColor"
|
|
147
|
+
style={{ height: "1rem", width: "1rem" }}
|
|
148
|
+
className={className}
|
|
149
|
+
{...props}
|
|
150
|
+
>
|
|
151
|
+
<path d="m229.66 77.66-128 128a8 8 0 0 1-11.32 0l-56-56a8 8 0 0 1 11.32-11.32L96 188.69 218.34 66.34a8 8 0 0 1 11.32 11.32Z" />
|
|
152
|
+
</svg>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function DownloadIcon({ className, ...props }: React.ComponentProps<"svg">) {
|
|
157
|
+
return (
|
|
158
|
+
<svg
|
|
159
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
160
|
+
viewBox="0 0 256 256"
|
|
161
|
+
fill="currentColor"
|
|
162
|
+
style={{ height: "1rem", width: "1rem" }}
|
|
163
|
+
className={className}
|
|
164
|
+
{...props}
|
|
165
|
+
>
|
|
166
|
+
<path d="M224 152v56a16 16 0 0 1-16 16H48a16 16 0 0 1-16-16v-56a8 8 0 0 1 16 0v56h160v-56a8 8 0 0 1 16 0Zm-101.66 5.66a8 8 0 0 0 11.32 0l40-40a8 8 0 0 0-11.32-11.32L136 132.69V40a8 8 0 0 0-16 0v92.69l-26.34-26.35a8 8 0 0 0-11.32 11.32Z" />
|
|
167
|
+
</svg>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function CopyIcon({ className, ...props }: React.ComponentProps<"svg">) {
|
|
172
|
+
return (
|
|
173
|
+
<svg
|
|
174
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
175
|
+
viewBox="0 0 256 256"
|
|
176
|
+
fill="currentColor"
|
|
177
|
+
style={{ height: "1rem", width: "1rem" }}
|
|
178
|
+
className={className}
|
|
179
|
+
{...props}
|
|
180
|
+
>
|
|
181
|
+
<path d="M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8Zm-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z" />
|
|
182
|
+
</svg>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export const StopIcon = (
|
|
187
|
+
<svg
|
|
188
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
189
|
+
viewBox="0 0 256 256"
|
|
190
|
+
fill="currentColor"
|
|
191
|
+
style={{ height: "1rem", width: "1rem" }}
|
|
192
|
+
>
|
|
193
|
+
<path d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24Zm0 192a88 88 0 1 1 88-88 88.1 88.1 0 0 1-88 88Zm24-120h-48a8 8 0 0 0-8 8v48a8 8 0 0 0 8 8h48a8 8 0 0 0 8-8v-48a8 8 0 0 0-8-8Zm-8 48h-32v-32h32Z" />
|
|
194
|
+
</svg>
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
export const RegenerateIcon = (
|
|
198
|
+
<svg
|
|
199
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
200
|
+
viewBox="0 0 256 256"
|
|
201
|
+
fill="currentColor"
|
|
202
|
+
style={{ height: "1rem", width: "1rem" }}
|
|
203
|
+
>
|
|
204
|
+
<path d="M197.67 186.37a8 8 0 0 1 0 11.29C196.58 198.73 170.82 224 128 224c-37.39 0-64.53-22.4-80-39.85V208a8 8 0 0 1-16 0v-48a8 8 0 0 1 8-8h48a8 8 0 0 1 0 16H55.44C67.76 183.35 93 208 128 208c36 0 58.14-21.46 58.36-21.68a8 8 0 0 1 11.31.05ZM216 40a8 8 0 0 0-8 8v23.85C192.53 54.4 165.39 32 128 32c-42.82 0-68.58 25.27-69.66 26.34a8 8 0 0 0 11.3 11.34C69.86 69.46 92 48 128 48c35 0 60.24 24.65 72.56 40H168a8 8 0 0 0 0 16h48a8 8 0 0 0 8-8V48a8 8 0 0 0-8-8Z" />
|
|
205
|
+
</svg>
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
export const PushToTalkIcon = (
|
|
209
|
+
<svg
|
|
210
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
211
|
+
fill="none"
|
|
212
|
+
viewBox="0 0 24 24"
|
|
213
|
+
strokeWidth={1.5}
|
|
214
|
+
stroke="currentColor"
|
|
215
|
+
className="w-6 h-6"
|
|
216
|
+
>
|
|
217
|
+
<path
|
|
218
|
+
strokeLinecap="round"
|
|
219
|
+
strokeLinejoin="round"
|
|
220
|
+
d="M12 18.75a6 6 0 0 0 6-6v-1.5m-6 7.5a6 6 0 0 1-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 0 1-3-3V4.5a3 3 0 1 1 6 0v8.25a3 3 0 0 1-3 3Z"
|
|
221
|
+
/>
|
|
222
|
+
</svg>
|
|
223
|
+
);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { InputProps } from "./props";
|
|
3
|
+
import { useChatContext } from "./ChatContext";
|
|
4
|
+
import AutoResizingTextarea from "./Textarea";
|
|
5
|
+
import { usePushToTalk } from "../../hooks/use-push-to-talk";
|
|
6
|
+
import { useCopilotContext } from "@copilotkit/react-core";
|
|
7
|
+
|
|
8
|
+
export const Input = ({ inProgress, onSend, isVisible = false }: InputProps) => {
|
|
9
|
+
const context = useChatContext();
|
|
10
|
+
const copilotContext = useCopilotContext();
|
|
11
|
+
|
|
12
|
+
const pushToTalkConfigured =
|
|
13
|
+
copilotContext.copilotApiConfig.textToSpeechUrl !== undefined &&
|
|
14
|
+
copilotContext.copilotApiConfig.transcribeAudioUrl !== undefined;
|
|
15
|
+
|
|
16
|
+
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
17
|
+
|
|
18
|
+
const handleDivClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
19
|
+
// Check if the clicked element is not the textarea itself
|
|
20
|
+
if (event.target !== event.currentTarget) return;
|
|
21
|
+
|
|
22
|
+
textareaRef.current?.focus();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const [text, setText] = useState("");
|
|
26
|
+
const send = () => {
|
|
27
|
+
if (inProgress) return;
|
|
28
|
+
onSend(text);
|
|
29
|
+
setText("");
|
|
30
|
+
|
|
31
|
+
textareaRef.current?.focus();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (isVisible) {
|
|
36
|
+
textareaRef.current?.focus();
|
|
37
|
+
}
|
|
38
|
+
}, [isVisible]);
|
|
39
|
+
|
|
40
|
+
const { pushToTalkState, setPushToTalkState } = usePushToTalk({
|
|
41
|
+
sendFunction: onSend,
|
|
42
|
+
inProgress,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const sendIcon =
|
|
46
|
+
inProgress || pushToTalkState === "transcribing"
|
|
47
|
+
? context.icons.activityIcon
|
|
48
|
+
: context.icons.sendIcon;
|
|
49
|
+
const showPushToTalk =
|
|
50
|
+
pushToTalkConfigured &&
|
|
51
|
+
(pushToTalkState === "idle" || pushToTalkState === "recording") &&
|
|
52
|
+
!inProgress;
|
|
53
|
+
|
|
54
|
+
const canSend = () => {
|
|
55
|
+
return !inProgress && text.trim().length > 0 && pushToTalkState === "idle";
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const sendDisabled = !canSend();
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className="copilotKitInput" onClick={handleDivClick}>
|
|
62
|
+
<AutoResizingTextarea
|
|
63
|
+
ref={textareaRef}
|
|
64
|
+
placeholder={context.labels.placeholder}
|
|
65
|
+
autoFocus={true}
|
|
66
|
+
maxRows={5}
|
|
67
|
+
value={text}
|
|
68
|
+
onChange={(event) => setText(event.target.value)}
|
|
69
|
+
onKeyDown={(event) => {
|
|
70
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
if (canSend()) {
|
|
73
|
+
send();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}}
|
|
77
|
+
/>
|
|
78
|
+
<div className="copilotKitInputControls">
|
|
79
|
+
{showPushToTalk && (
|
|
80
|
+
<button
|
|
81
|
+
onClick={() =>
|
|
82
|
+
setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing")
|
|
83
|
+
}
|
|
84
|
+
className={pushToTalkState === "recording" ? "copilotKitPushToTalkRecording" : ""}
|
|
85
|
+
>
|
|
86
|
+
{context.icons.pushToTalkIcon}
|
|
87
|
+
</button>
|
|
88
|
+
)}
|
|
89
|
+
<button
|
|
90
|
+
disabled={sendDisabled}
|
|
91
|
+
onClick={send}
|
|
92
|
+
data-copilotkit-in-progress={!!inProgress}
|
|
93
|
+
data-testid={inProgress ? "copilot-chat-request-in-progress" : undefined}
|
|
94
|
+
>
|
|
95
|
+
{sendIcon}
|
|
96
|
+
</button>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { FC, memo } from "react";
|
|
2
|
+
import ReactMarkdown, { Options, Components } from "react-markdown";
|
|
3
|
+
import { CodeBlock } from "./CodeBlock";
|
|
4
|
+
import remarkGfm from "remark-gfm";
|
|
5
|
+
import remarkMath from "remark-math";
|
|
6
|
+
|
|
7
|
+
const MemoizedReactMarkdown: FC<Options> = memo(
|
|
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 = {
|
|
28
|
+
p({ children }) {
|
|
29
|
+
return <p>{children}</p>;
|
|
30
|
+
},
|
|
31
|
+
a({ children, ...props }) {
|
|
32
|
+
return (
|
|
33
|
+
<a
|
|
34
|
+
style={{ color: "blue", textDecoration: "underline" }}
|
|
35
|
+
{...props}
|
|
36
|
+
target="_blank"
|
|
37
|
+
rel="noopener noreferrer"
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</a>
|
|
41
|
+
);
|
|
42
|
+
},
|
|
43
|
+
code({ children, className, inline, ...props }) {
|
|
44
|
+
if (children.length) {
|
|
45
|
+
if (children[0] == "▍") {
|
|
46
|
+
return (
|
|
47
|
+
<span
|
|
48
|
+
style={{
|
|
49
|
+
animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
50
|
+
marginTop: "0.25rem",
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
▍
|
|
54
|
+
</span>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
children[0] = (children[0] as string).replace("`▍`", "▍");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const match = /language-(\w+)/.exec(className || "");
|
|
62
|
+
|
|
63
|
+
if (inline) {
|
|
64
|
+
return (
|
|
65
|
+
<code className={className} {...props}>
|
|
66
|
+
{children}
|
|
67
|
+
</code>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<CodeBlock
|
|
73
|
+
key={Math.random()}
|
|
74
|
+
language={(match && match[1]) || ""}
|
|
75
|
+
value={String(children).replace(/\n$/, "")}
|
|
76
|
+
{...props}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { MessagesProps } from "./props";
|
|
3
|
+
import { useChatContext } from "./ChatContext";
|
|
4
|
+
import { Message, ResultMessage, TextMessage, Role } from "@copilotkit/runtime-client-gql";
|
|
5
|
+
|
|
6
|
+
export const Messages = ({
|
|
7
|
+
messages,
|
|
8
|
+
inProgress,
|
|
9
|
+
children,
|
|
10
|
+
RenderTextMessage,
|
|
11
|
+
RenderActionExecutionMessage,
|
|
12
|
+
RenderAgentStateMessage,
|
|
13
|
+
RenderResultMessage,
|
|
14
|
+
AssistantMessage,
|
|
15
|
+
UserMessage,
|
|
16
|
+
}: MessagesProps) => {
|
|
17
|
+
const context = useChatContext();
|
|
18
|
+
const initialMessages = useMemo(
|
|
19
|
+
() => makeInitialMessages(context.labels.initial),
|
|
20
|
+
[context.labels.initial],
|
|
21
|
+
);
|
|
22
|
+
messages = [...initialMessages, ...messages];
|
|
23
|
+
|
|
24
|
+
const actionResults: Record<string, string> = {};
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < messages.length; i++) {
|
|
27
|
+
if (messages[i].isActionExecutionMessage()) {
|
|
28
|
+
const id = messages[i].id;
|
|
29
|
+
const resultMessage: ResultMessage | undefined = messages.find(
|
|
30
|
+
(message) => message.isResultMessage() && message.actionExecutionId === id,
|
|
31
|
+
) as ResultMessage | undefined;
|
|
32
|
+
|
|
33
|
+
if (resultMessage) {
|
|
34
|
+
actionResults[id] = ResultMessage.decodeResult(resultMessage.result || "");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { messagesEndRef, messagesContainerRef } = useScrollToBottom(messages);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div className="copilotKitMessages" ref={messagesContainerRef}>
|
|
43
|
+
{messages.map((message, index) => {
|
|
44
|
+
const isCurrentMessage = index === messages.length - 1;
|
|
45
|
+
|
|
46
|
+
if (message.isTextMessage()) {
|
|
47
|
+
return (
|
|
48
|
+
<RenderTextMessage
|
|
49
|
+
key={index}
|
|
50
|
+
message={message}
|
|
51
|
+
inProgress={inProgress}
|
|
52
|
+
index={index}
|
|
53
|
+
isCurrentMessage={isCurrentMessage}
|
|
54
|
+
AssistantMessage={AssistantMessage}
|
|
55
|
+
UserMessage={UserMessage}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
} else if (message.isActionExecutionMessage()) {
|
|
59
|
+
return (
|
|
60
|
+
<RenderActionExecutionMessage
|
|
61
|
+
key={index}
|
|
62
|
+
message={message}
|
|
63
|
+
inProgress={inProgress}
|
|
64
|
+
index={index}
|
|
65
|
+
isCurrentMessage={isCurrentMessage}
|
|
66
|
+
actionResult={actionResults[message.id]}
|
|
67
|
+
AssistantMessage={AssistantMessage}
|
|
68
|
+
UserMessage={UserMessage}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
} else if (message.isAgentStateMessage()) {
|
|
72
|
+
return (
|
|
73
|
+
<RenderAgentStateMessage
|
|
74
|
+
key={index}
|
|
75
|
+
message={message}
|
|
76
|
+
inProgress={inProgress}
|
|
77
|
+
index={index}
|
|
78
|
+
isCurrentMessage={isCurrentMessage}
|
|
79
|
+
AssistantMessage={AssistantMessage}
|
|
80
|
+
UserMessage={UserMessage}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
} else if (message.isResultMessage()) {
|
|
84
|
+
return (
|
|
85
|
+
<RenderResultMessage
|
|
86
|
+
key={index}
|
|
87
|
+
message={message}
|
|
88
|
+
inProgress={inProgress}
|
|
89
|
+
index={index}
|
|
90
|
+
isCurrentMessage={isCurrentMessage}
|
|
91
|
+
AssistantMessage={AssistantMessage}
|
|
92
|
+
UserMessage={UserMessage}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
})}
|
|
97
|
+
<footer ref={messagesEndRef}>{children}</footer>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
function makeInitialMessages(initial?: string | string[]): Message[] {
|
|
103
|
+
let initialArray: string[] = [];
|
|
104
|
+
if (initial) {
|
|
105
|
+
if (Array.isArray(initial)) {
|
|
106
|
+
initialArray.push(...initial);
|
|
107
|
+
} else {
|
|
108
|
+
initialArray.push(initial);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return initialArray.map(
|
|
113
|
+
(message) =>
|
|
114
|
+
new TextMessage({
|
|
115
|
+
role: Role.Assistant,
|
|
116
|
+
content: message,
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
export function useScrollToBottom(messages: any[]) {
|
|
121
|
+
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
122
|
+
const messagesContainerRef = useRef<HTMLDivElement | null>(null);
|
|
123
|
+
const isProgrammaticScrollRef = useRef(false);
|
|
124
|
+
const isUserScrollUpRef = useRef(false);
|
|
125
|
+
|
|
126
|
+
const scrollToBottom = () => {
|
|
127
|
+
if (messagesEndRef.current) {
|
|
128
|
+
isProgrammaticScrollRef.current = true;
|
|
129
|
+
messagesEndRef.current.scrollIntoView({
|
|
130
|
+
behavior: "auto",
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const handleScroll = () => {
|
|
136
|
+
if (isProgrammaticScrollRef.current) {
|
|
137
|
+
isProgrammaticScrollRef.current = false;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (messagesContainerRef.current) {
|
|
142
|
+
const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
|
|
143
|
+
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
const container = messagesContainerRef.current;
|
|
149
|
+
if (container) {
|
|
150
|
+
container.addEventListener("scroll", handleScroll);
|
|
151
|
+
}
|
|
152
|
+
return () => {
|
|
153
|
+
if (container) {
|
|
154
|
+
container.removeEventListener("scroll", handleScroll);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}, []);
|
|
158
|
+
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
const container = messagesContainerRef.current;
|
|
161
|
+
if (!container) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const mutationObserver = new MutationObserver(() => {
|
|
166
|
+
if (!isUserScrollUpRef.current) {
|
|
167
|
+
scrollToBottom();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
mutationObserver.observe(container, {
|
|
172
|
+
childList: true,
|
|
173
|
+
subtree: true,
|
|
174
|
+
characterData: true,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return () => {
|
|
178
|
+
mutationObserver.disconnect();
|
|
179
|
+
};
|
|
180
|
+
}, []);
|
|
181
|
+
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
isUserScrollUpRef.current = false;
|
|
184
|
+
scrollToBottom();
|
|
185
|
+
}, [messages.filter((m) => m.isTextMessage() && m.role === Role.User).length]);
|
|
186
|
+
|
|
187
|
+
return { messagesEndRef, messagesContainerRef };
|
|
188
|
+
}
|