@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,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <Callout type="warning">
|
|
3
|
+
* useCopilotChatSuggestions is experimental. The interface is not final and
|
|
4
|
+
* can change without notice.
|
|
5
|
+
* </Callout>
|
|
6
|
+
*
|
|
7
|
+
* `useCopilotReadable` is a React hook that provides app-state and other information
|
|
8
|
+
* to the Copilot. Optionally, the hook can also handle hierarchical state within your
|
|
9
|
+
* application, passing these parent-child relationships to the Copilot.
|
|
10
|
+
*
|
|
11
|
+
* <br/>
|
|
12
|
+
* <img src="/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif" width="500" />
|
|
13
|
+
*
|
|
14
|
+
* ## Usage
|
|
15
|
+
*
|
|
16
|
+
* ### Install Dependencies
|
|
17
|
+
*
|
|
18
|
+
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
19
|
+
*
|
|
20
|
+
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
21
|
+
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* ### Simple Usage
|
|
25
|
+
*
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
|
|
28
|
+
*
|
|
29
|
+
* export function MyComponent() {
|
|
30
|
+
* const [employees, setEmployees] = useState([]);
|
|
31
|
+
*
|
|
32
|
+
* useCopilotChatSuggestions({
|
|
33
|
+
* instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,
|
|
34
|
+
* });
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* ### Dependency Management
|
|
39
|
+
*
|
|
40
|
+
* ```tsx
|
|
41
|
+
* import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
|
|
42
|
+
*
|
|
43
|
+
* export function MyComponent() {
|
|
44
|
+
* useCopilotChatSuggestions(
|
|
45
|
+
* {
|
|
46
|
+
* instructions: "Suggest the most relevant next actions.",
|
|
47
|
+
* },
|
|
48
|
+
* [appState],
|
|
49
|
+
* );
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* In the example above, the suggestions are generated based on the given instructions.
|
|
54
|
+
* The hook monitors `appState`, and updates suggestions accordingly whenever it changes.
|
|
55
|
+
*
|
|
56
|
+
* ### Behavior and Lifecycle
|
|
57
|
+
*
|
|
58
|
+
* The hook registers the configuration with the chat context upon component mount and
|
|
59
|
+
* removes it on unmount, ensuring a clean and efficient lifecycle management.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
import { useEffect } from "react";
|
|
63
|
+
import { useCopilotContext } from "@copilotkit/react-core";
|
|
64
|
+
import { randomId } from "@copilotkit/shared";
|
|
65
|
+
|
|
66
|
+
interface UseCopilotChatSuggestionsConfiguration {
|
|
67
|
+
/**
|
|
68
|
+
* A prompt or instructions for the GPT to generate suggestions.
|
|
69
|
+
*/
|
|
70
|
+
instructions: string;
|
|
71
|
+
/**
|
|
72
|
+
* The minimum number of suggestions to generate. Defaults to `1`.
|
|
73
|
+
* @default 1
|
|
74
|
+
*/
|
|
75
|
+
minSuggestions?: number;
|
|
76
|
+
/**
|
|
77
|
+
* The maximum number of suggestions to generate. Defaults to `3`.
|
|
78
|
+
* @default 1
|
|
79
|
+
*/
|
|
80
|
+
maxSuggestions?: number;
|
|
81
|
+
/**
|
|
82
|
+
* An optional class name to apply to the suggestions.
|
|
83
|
+
*/
|
|
84
|
+
className?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function useCopilotChatSuggestions(
|
|
88
|
+
{
|
|
89
|
+
instructions,
|
|
90
|
+
className,
|
|
91
|
+
minSuggestions = 1,
|
|
92
|
+
maxSuggestions = 3,
|
|
93
|
+
}: UseCopilotChatSuggestionsConfiguration,
|
|
94
|
+
dependencies: any[] = [],
|
|
95
|
+
) {
|
|
96
|
+
const context = useCopilotContext();
|
|
97
|
+
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const id = randomId();
|
|
100
|
+
|
|
101
|
+
context.addChatSuggestionConfiguration(id, {
|
|
102
|
+
instructions,
|
|
103
|
+
minSuggestions,
|
|
104
|
+
maxSuggestions,
|
|
105
|
+
className,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return () => {
|
|
109
|
+
context.removeChatSuggestionConfiguration(id);
|
|
110
|
+
};
|
|
111
|
+
}, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);
|
|
112
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
export interface useCopyToClipboardProps {
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function useCopyToClipboard({ timeout = 2000 }: useCopyToClipboardProps) {
|
|
8
|
+
const [isCopied, setIsCopied] = React.useState<Boolean>(false);
|
|
9
|
+
|
|
10
|
+
const copyToClipboard = (value: string) => {
|
|
11
|
+
if (typeof window === "undefined" || !navigator.clipboard?.writeText) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!value) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
navigator.clipboard.writeText(value).then(() => {
|
|
20
|
+
setIsCopied(true);
|
|
21
|
+
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
setIsCopied(false);
|
|
24
|
+
}, timeout);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return { isCopied, copyToClipboard };
|
|
29
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { useCopilotContext, useCopilotMessagesContext } from "@copilotkit/react-core";
|
|
2
|
+
import { Message, TextMessage } from "@copilotkit/runtime-client-gql";
|
|
3
|
+
import { MutableRefObject, useEffect, useRef, useState } from "react";
|
|
4
|
+
|
|
5
|
+
export const checkMicrophonePermission = async () => {
|
|
6
|
+
try {
|
|
7
|
+
const permissionStatus = await navigator.permissions.query({
|
|
8
|
+
name: "microphone" as PermissionName,
|
|
9
|
+
});
|
|
10
|
+
if (permissionStatus.state === "granted") {
|
|
11
|
+
return true;
|
|
12
|
+
} else {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
} catch (err) {
|
|
16
|
+
console.error("Error checking microphone permission", err);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const requestMicAndPlaybackPermission = async () => {
|
|
21
|
+
try {
|
|
22
|
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
23
|
+
const audioContext = new window.AudioContext();
|
|
24
|
+
await audioContext.resume();
|
|
25
|
+
return { stream, audioContext };
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.error("Error requesting microphone and playback permissions", err);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const startRecording = async (
|
|
33
|
+
mediaStreamRef: MutableRefObject<MediaStream | null>,
|
|
34
|
+
mediaRecorderRef: MutableRefObject<MediaRecorder | null>,
|
|
35
|
+
audioContextRef: MutableRefObject<AudioContext | null>,
|
|
36
|
+
recordedChunks: Blob[],
|
|
37
|
+
onStop: () => void,
|
|
38
|
+
) => {
|
|
39
|
+
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
40
|
+
mediaStreamRef.current = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
41
|
+
audioContextRef.current = new window.AudioContext();
|
|
42
|
+
await audioContextRef.current.resume();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current!);
|
|
46
|
+
mediaRecorderRef.current.start(1000);
|
|
47
|
+
mediaRecorderRef.current.ondataavailable = (event) => {
|
|
48
|
+
recordedChunks.push(event.data);
|
|
49
|
+
};
|
|
50
|
+
mediaRecorderRef.current.onstop = onStop;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const stopRecording = (mediaRecorderRef: MutableRefObject<MediaRecorder | null>) => {
|
|
54
|
+
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
55
|
+
mediaRecorderRef.current.stop();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const transcribeAudio = async (recordedChunks: Blob[], transcribeAudioUrl: string) => {
|
|
60
|
+
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
61
|
+
const formData = new FormData();
|
|
62
|
+
formData.append("file", completeBlob, "recording.mp4");
|
|
63
|
+
|
|
64
|
+
const response = await fetch(transcribeAudioUrl, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body: formData,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
throw new Error(`Error: ${response.statusText}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const transcription = await response.json();
|
|
74
|
+
return transcription.text;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const playAudioResponse = (text: string, textToSpeechUrl: string, audioContext: AudioContext) => {
|
|
78
|
+
const encodedText = encodeURIComponent(text);
|
|
79
|
+
const url = `${textToSpeechUrl}?text=${encodedText}`;
|
|
80
|
+
|
|
81
|
+
fetch(url)
|
|
82
|
+
.then((response) => response.arrayBuffer())
|
|
83
|
+
.then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer))
|
|
84
|
+
.then((audioBuffer) => {
|
|
85
|
+
const source = audioContext.createBufferSource();
|
|
86
|
+
source.buffer = audioBuffer;
|
|
87
|
+
source.connect(audioContext.destination);
|
|
88
|
+
source.start(0);
|
|
89
|
+
})
|
|
90
|
+
.catch((error) => {
|
|
91
|
+
console.error("Error with decoding audio data", error);
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export type PushToTalkState = "idle" | "recording" | "transcribing";
|
|
96
|
+
|
|
97
|
+
export type SendFunction = (text: string) => Promise<Message>;
|
|
98
|
+
|
|
99
|
+
export const usePushToTalk = ({
|
|
100
|
+
sendFunction,
|
|
101
|
+
inProgress,
|
|
102
|
+
}: {
|
|
103
|
+
sendFunction: SendFunction;
|
|
104
|
+
inProgress: boolean;
|
|
105
|
+
}) => {
|
|
106
|
+
const [pushToTalkState, setPushToTalkState] = useState<PushToTalkState>("idle");
|
|
107
|
+
const mediaStreamRef = useRef<MediaStream | null>(null);
|
|
108
|
+
const audioContextRef = useRef<AudioContext | null>(null);
|
|
109
|
+
const mediaRecorderRef = useRef<MediaRecorder | null>(null);
|
|
110
|
+
const recordedChunks = useRef<Blob[]>([]);
|
|
111
|
+
const generalContext = useCopilotContext();
|
|
112
|
+
const messagesContext = useCopilotMessagesContext();
|
|
113
|
+
const context = { ...generalContext, ...messagesContext };
|
|
114
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = useState<string | null>(null);
|
|
115
|
+
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (pushToTalkState === "recording") {
|
|
118
|
+
startRecording(
|
|
119
|
+
mediaStreamRef,
|
|
120
|
+
mediaRecorderRef,
|
|
121
|
+
audioContextRef,
|
|
122
|
+
recordedChunks.current,
|
|
123
|
+
() => {
|
|
124
|
+
setPushToTalkState("transcribing");
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
} else {
|
|
128
|
+
stopRecording(mediaRecorderRef);
|
|
129
|
+
if (pushToTalkState === "transcribing") {
|
|
130
|
+
transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl!).then(
|
|
131
|
+
async (transcription) => {
|
|
132
|
+
recordedChunks.current = [];
|
|
133
|
+
setPushToTalkState("idle");
|
|
134
|
+
const message = await sendFunction(transcription);
|
|
135
|
+
setStartReadingFromMessageId(message.id);
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return () => {
|
|
142
|
+
stopRecording(mediaRecorderRef);
|
|
143
|
+
};
|
|
144
|
+
}, [pushToTalkState]);
|
|
145
|
+
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (inProgress === false && startReadingFromMessageId) {
|
|
148
|
+
const lastMessageIndex = context.messages.findIndex(
|
|
149
|
+
(message) => message.id === startReadingFromMessageId,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const messagesAfterLast = context.messages
|
|
153
|
+
.slice(lastMessageIndex + 1)
|
|
154
|
+
.filter(
|
|
155
|
+
(message) => message.isTextMessage() && message.role === "assistant",
|
|
156
|
+
) as TextMessage[];
|
|
157
|
+
|
|
158
|
+
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
159
|
+
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl!, audioContextRef.current!);
|
|
160
|
+
|
|
161
|
+
setStartReadingFromMessageId(null);
|
|
162
|
+
}
|
|
163
|
+
}, [startReadingFromMessageId, inProgress]);
|
|
164
|
+
|
|
165
|
+
return { pushToTalkState, setPushToTalkState };
|
|
166
|
+
};
|
package/src/index.tsx
ADDED
package/src/lib/utils.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export async function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON> {
|
|
2
|
+
const res = await fetch(input, init);
|
|
3
|
+
|
|
4
|
+
if (!res.ok) {
|
|
5
|
+
const json = await res.json();
|
|
6
|
+
if (json.error) {
|
|
7
|
+
const error = new Error(json.error) as Error & {
|
|
8
|
+
status: number;
|
|
9
|
+
};
|
|
10
|
+
error.status = res.status;
|
|
11
|
+
throw error;
|
|
12
|
+
} else {
|
|
13
|
+
throw new Error("An unexpected error occurred");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return res.json();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function formatDate(input: string | number | Date): string {
|
|
21
|
+
const date = new Date(input);
|
|
22
|
+
return date.toLocaleDateString("en-US", {
|
|
23
|
+
month: "long",
|
|
24
|
+
day: "numeric",
|
|
25
|
+
year: "numeric",
|
|
26
|
+
});
|
|
27
|
+
}
|
package/src/styles.css
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
@import "./css/colors.css";
|
|
2
|
+
@import "./css/popup.css";
|
|
3
|
+
@import "./css/sidebar.css";
|
|
4
|
+
@import "./css/button.css";
|
|
5
|
+
@import "./css/header.css";
|
|
6
|
+
@import "./css/input.css";
|
|
7
|
+
@import "./css/messages.css";
|
|
8
|
+
@import "./css/window.css";
|
|
9
|
+
@import "./css/animations.css";
|
|
10
|
+
@import "./css/response.css";
|
|
11
|
+
@import "./css/markdown.css";
|
|
12
|
+
@import "./css/suggestions.css";
|
|
13
|
+
@import "./css/panel.css";
|
|
14
|
+
@import "./css/console.css";
|
package/src/types/css.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// autogenerated (see postcss.config.js) - do not edit
|
|
2
|
+
import { CSSProperties } from "react";
|
|
3
|
+
|
|
4
|
+
export interface CopilotKitCSSProperties extends CSSProperties {
|
|
5
|
+
"--copilot-kit-primary-color"?: string;
|
|
6
|
+
"--copilot-kit-contrast-color"?: string;
|
|
7
|
+
"--copilot-kit-secondary-color"?: string;
|
|
8
|
+
"--copilot-kit-secondary-contrast-color"?: string;
|
|
9
|
+
"--copilot-kit-background-color"?: string;
|
|
10
|
+
"--copilot-kit-muted-color"?: string;
|
|
11
|
+
"--copilot-kit-separator-color"?: string;
|
|
12
|
+
"--copilot-kit-scrollbar-color"?: string;
|
|
13
|
+
"--copilot-kit-response-button-color"?: string;
|
|
14
|
+
"--copilot-kit-response-button-background-color"?: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { CopilotKitCSSProperties } from "./css";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../utilities/tsconfig/react-library.json",
|
|
3
|
+
"include": ["."],
|
|
4
|
+
"exclude": [
|
|
5
|
+
"dist",
|
|
6
|
+
"build",
|
|
7
|
+
"node_modules",
|
|
8
|
+
"**/*.test.ts", // Exclude TypeScript test files
|
|
9
|
+
"**/*.test.tsx", // Exclude TypeScript React test files
|
|
10
|
+
"**/__tests__/*" // Exclude any files inside a __tests__ directory
|
|
11
|
+
]
|
|
12
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig, Options } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig((options: Options) => ({
|
|
4
|
+
entry: ["src/**/*.{ts,tsx}"],
|
|
5
|
+
format: ["esm", "cjs"],
|
|
6
|
+
dts: true,
|
|
7
|
+
minify: false,
|
|
8
|
+
external: ["react"],
|
|
9
|
+
sourcemap: true,
|
|
10
|
+
exclude: [
|
|
11
|
+
"**/*.test.ts", // Exclude TypeScript test files
|
|
12
|
+
"**/*.test.tsx", // Exclude TypeScript React test files
|
|
13
|
+
"**/__tests__/*", // Exclude any files inside a __tests__ directory
|
|
14
|
+
],
|
|
15
|
+
...options,
|
|
16
|
+
}));
|
package/typedoc.json
ADDED