@copilotkit/react-ui 1.51.5-next.0 → 1.51.5-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.attw.json +3 -0
- package/CHANGELOG.md +17 -0
- package/dist/index.cjs +2737 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +258 -70
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +781 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +781 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2685 -81
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +2750 -25
- package/dist/index.umd.js.map +1 -1
- package/package.json +19 -18
- package/src/components/chat/Popup.tsx +1 -1
- package/src/components/chat/Sidebar.tsx +1 -1
- package/tsdown.config.ts +58 -0
- package/vitest.config.mjs +11 -0
- package/dist/chunk-2QEDCM6H.mjs +0 -150
- package/dist/chunk-2QEDCM6H.mjs.map +0 -1
- package/dist/chunk-6SMTHXVA.mjs +0 -28
- package/dist/chunk-6SMTHXVA.mjs.map +0 -1
- package/dist/chunk-6TLDRWAD.mjs +0 -95
- package/dist/chunk-6TLDRWAD.mjs.map +0 -1
- package/dist/chunk-72FQQMQ2.mjs +0 -25
- package/dist/chunk-72FQQMQ2.mjs.map +0 -1
- package/dist/chunk-AOUHT4JR.mjs +0 -34
- package/dist/chunk-AOUHT4JR.mjs.map +0 -1
- package/dist/chunk-BNJX66OH.mjs +0 -118
- package/dist/chunk-BNJX66OH.mjs.map +0 -1
- package/dist/chunk-C27LZFA5.mjs +0 -97
- package/dist/chunk-C27LZFA5.mjs.map +0 -1
- package/dist/chunk-C7WM7GM3.mjs +0 -235
- package/dist/chunk-C7WM7GM3.mjs.map +0 -1
- package/dist/chunk-CNIC5HO5.mjs +0 -36
- package/dist/chunk-CNIC5HO5.mjs.map +0 -1
- package/dist/chunk-CQCXH5LY.mjs +0 -143
- package/dist/chunk-CQCXH5LY.mjs.map +0 -1
- package/dist/chunk-DM2V5WTG.mjs +0 -34
- package/dist/chunk-DM2V5WTG.mjs.map +0 -1
- package/dist/chunk-DSHTRV2R.mjs +0 -140
- package/dist/chunk-DSHTRV2R.mjs.map +0 -1
- package/dist/chunk-EACIYBQH.mjs +0 -32
- package/dist/chunk-EACIYBQH.mjs.map +0 -1
- package/dist/chunk-EFZPSZWO.mjs +0 -1
- package/dist/chunk-EFZPSZWO.mjs.map +0 -1
- package/dist/chunk-GBAPANZE.mjs +0 -323
- package/dist/chunk-GBAPANZE.mjs.map +0 -1
- package/dist/chunk-GFE5ZSPV.mjs +0 -112
- package/dist/chunk-GFE5ZSPV.mjs.map +0 -1
- package/dist/chunk-HHLX4MQN.mjs +0 -31
- package/dist/chunk-HHLX4MQN.mjs.map +0 -1
- package/dist/chunk-ICA2EXIX.mjs +0 -187
- package/dist/chunk-ICA2EXIX.mjs.map +0 -1
- package/dist/chunk-IU3WTXLQ.mjs +0 -1
- package/dist/chunk-IU3WTXLQ.mjs.map +0 -1
- package/dist/chunk-IWOCQACI.mjs +0 -73
- package/dist/chunk-IWOCQACI.mjs.map +0 -1
- package/dist/chunk-JGMFJZMG.mjs +0 -11
- package/dist/chunk-JGMFJZMG.mjs.map +0 -1
- package/dist/chunk-JYHRHKV5.mjs +0 -90
- package/dist/chunk-JYHRHKV5.mjs.map +0 -1
- package/dist/chunk-KXE2JCUH.mjs +0 -1
- package/dist/chunk-KXE2JCUH.mjs.map +0 -1
- package/dist/chunk-LIXN3OVQ.mjs +0 -405
- package/dist/chunk-LIXN3OVQ.mjs.map +0 -1
- package/dist/chunk-MC6PY7XH.mjs +0 -456
- package/dist/chunk-MC6PY7XH.mjs.map +0 -1
- package/dist/chunk-MMVDU6DF.mjs +0 -1
- package/dist/chunk-MMVDU6DF.mjs.map +0 -1
- package/dist/chunk-MRXNTQOX.mjs +0 -59
- package/dist/chunk-MRXNTQOX.mjs.map +0 -1
- package/dist/chunk-OQWEOBRX.mjs +0 -120
- package/dist/chunk-OQWEOBRX.mjs.map +0 -1
- package/dist/chunk-P34CL4LC.mjs +0 -82
- package/dist/chunk-P34CL4LC.mjs.map +0 -1
- package/dist/chunk-PF3QBO7V.mjs +0 -133
- package/dist/chunk-PF3QBO7V.mjs.map +0 -1
- package/dist/chunk-PLHTVHUW.mjs +0 -82
- package/dist/chunk-PLHTVHUW.mjs.map +0 -1
- package/dist/chunk-PP2A5RP6.mjs +0 -21
- package/dist/chunk-PP2A5RP6.mjs.map +0 -1
- package/dist/chunk-Q64GLWPQ.mjs +0 -30
- package/dist/chunk-Q64GLWPQ.mjs.map +0 -1
- package/dist/chunk-SC6JRFAJ.mjs +0 -1
- package/dist/chunk-SC6JRFAJ.mjs.map +0 -1
- package/dist/chunk-T26KLXLH.mjs +0 -1
- package/dist/chunk-T26KLXLH.mjs.map +0 -1
- package/dist/chunk-T4NNQG6T.mjs +0 -231
- package/dist/chunk-T4NNQG6T.mjs.map +0 -1
- package/dist/chunk-TGM5PKBF.mjs +0 -44
- package/dist/chunk-TGM5PKBF.mjs.map +0 -1
- package/dist/chunk-V7W6IM2V.mjs +0 -1
- package/dist/chunk-V7W6IM2V.mjs.map +0 -1
- package/dist/chunk-WB3YULQ4.mjs +0 -1
- package/dist/chunk-WB3YULQ4.mjs.map +0 -1
- package/dist/chunk-Y4FKRAKJ.mjs +0 -12
- package/dist/chunk-Y4FKRAKJ.mjs.map +0 -1
- package/dist/chunk-YDJ4YUUF.mjs +0 -141
- package/dist/chunk-YDJ4YUUF.mjs.map +0 -1
- package/dist/components/chat/Button.d.ts +0 -9
- package/dist/components/chat/Button.js +0 -73
- package/dist/components/chat/Button.js.map +0 -1
- package/dist/components/chat/Button.mjs +0 -10
- package/dist/components/chat/Button.mjs.map +0 -1
- package/dist/components/chat/Chat.d.ts +0 -204
- package/dist/components/chat/Chat.js +0 -2428
- package/dist/components/chat/Chat.js.map +0 -1
- package/dist/components/chat/Chat.mjs +0 -29
- package/dist/components/chat/Chat.mjs.map +0 -1
- package/dist/components/chat/ChatContext.d.ts +0 -145
- package/dist/components/chat/ChatContext.js +0 -383
- package/dist/components/chat/ChatContext.js.map +0 -1
- package/dist/components/chat/ChatContext.mjs +0 -13
- package/dist/components/chat/ChatContext.mjs.map +0 -1
- package/dist/components/chat/CodeBlock.d.ts +0 -14
- package/dist/components/chat/CodeBlock.js +0 -524
- package/dist/components/chat/CodeBlock.js.map +0 -1
- package/dist/components/chat/CodeBlock.mjs +0 -14
- package/dist/components/chat/CodeBlock.mjs.map +0 -1
- package/dist/components/chat/Header.d.ts +0 -9
- package/dist/components/chat/Header.js +0 -642
- package/dist/components/chat/Header.js.map +0 -1
- package/dist/components/chat/Header.mjs +0 -17
- package/dist/components/chat/Header.mjs.map +0 -1
- package/dist/components/chat/Icons.d.ts +0 -20
- package/dist/components/chat/Icons.js +0 -362
- package/dist/components/chat/Icons.js.map +0 -1
- package/dist/components/chat/Icons.mjs +0 -38
- package/dist/components/chat/Icons.mjs.map +0 -1
- package/dist/components/chat/ImageUploadQueue.d.ts +0 -13
- package/dist/components/chat/ImageUploadQueue.js +0 -106
- package/dist/components/chat/ImageUploadQueue.js.map +0 -1
- package/dist/components/chat/ImageUploadQueue.mjs +0 -8
- package/dist/components/chat/ImageUploadQueue.mjs.map +0 -1
- package/dist/components/chat/Input.d.ts +0 -9
- package/dist/components/chat/Input.js +0 -424
- package/dist/components/chat/Input.js.map +0 -1
- package/dist/components/chat/Input.mjs +0 -14
- package/dist/components/chat/Input.mjs.map +0 -1
- package/dist/components/chat/Markdown.d.ts +0 -10
- package/dist/components/chat/Markdown.js +0 -678
- package/dist/components/chat/Markdown.js.map +0 -1
- package/dist/components/chat/Markdown.mjs +0 -11
- package/dist/components/chat/Markdown.mjs.map +0 -1
- package/dist/components/chat/Messages.d.ts +0 -13
- package/dist/components/chat/Messages.js +0 -1242
- package/dist/components/chat/Messages.js.map +0 -1
- package/dist/components/chat/Messages.mjs +0 -20
- package/dist/components/chat/Messages.mjs.map +0 -1
- package/dist/components/chat/Modal.d.ts +0 -51
- package/dist/components/chat/Modal.js +0 -3294
- package/dist/components/chat/Modal.js.map +0 -1
- package/dist/components/chat/Modal.mjs +0 -38
- package/dist/components/chat/Modal.mjs.map +0 -1
- package/dist/components/chat/Popup.d.ts +0 -13
- package/dist/components/chat/Popup.js +0 -3305
- package/dist/components/chat/Popup.js.map +0 -1
- package/dist/components/chat/Popup.mjs +0 -39
- package/dist/components/chat/Popup.mjs.map +0 -1
- package/dist/components/chat/PoweredByTag.d.ts +0 -7
- package/dist/components/chat/PoweredByTag.js +0 -63
- package/dist/components/chat/PoweredByTag.js.map +0 -1
- package/dist/components/chat/PoweredByTag.mjs +0 -9
- package/dist/components/chat/PoweredByTag.mjs.map +0 -1
- package/dist/components/chat/Sidebar.d.ts +0 -13
- package/dist/components/chat/Sidebar.js +0 -3314
- package/dist/components/chat/Sidebar.js.map +0 -1
- package/dist/components/chat/Sidebar.mjs +0 -39
- package/dist/components/chat/Sidebar.mjs.map +0 -1
- package/dist/components/chat/Suggestion.d.ts +0 -12
- package/dist/components/chat/Suggestion.js +0 -68
- package/dist/components/chat/Suggestion.js.map +0 -1
- package/dist/components/chat/Suggestion.mjs +0 -9
- package/dist/components/chat/Suggestion.mjs.map +0 -1
- package/dist/components/chat/Suggestions.d.ts +0 -9
- package/dist/components/chat/Suggestions.js +0 -93
- package/dist/components/chat/Suggestions.js.map +0 -1
- package/dist/components/chat/Suggestions.mjs +0 -10
- package/dist/components/chat/Suggestions.mjs.map +0 -1
- package/dist/components/chat/Textarea.d.ts +0 -15
- package/dist/components/chat/Textarea.js +0 -87
- package/dist/components/chat/Textarea.js.map +0 -1
- package/dist/components/chat/Textarea.mjs +0 -8
- package/dist/components/chat/Textarea.mjs.map +0 -1
- package/dist/components/chat/Window.d.ts +0 -9
- package/dist/components/chat/Window.js +0 -166
- package/dist/components/chat/Window.js.map +0 -1
- package/dist/components/chat/Window.mjs +0 -10
- package/dist/components/chat/Window.mjs.map +0 -1
- package/dist/components/chat/index.d.ts +0 -18
- package/dist/components/chat/index.js +0 -3341
- package/dist/components/chat/index.js.map +0 -1
- package/dist/components/chat/index.mjs +0 -69
- package/dist/components/chat/index.mjs.map +0 -1
- package/dist/components/chat/messages/AssistantMessage.d.ts +0 -9
- package/dist/components/chat/messages/AssistantMessage.js +0 -807
- package/dist/components/chat/messages/AssistantMessage.js.map +0 -1
- package/dist/components/chat/messages/AssistantMessage.mjs +0 -13
- package/dist/components/chat/messages/AssistantMessage.mjs.map +0 -1
- package/dist/components/chat/messages/ErrorMessage.d.ts +0 -9
- package/dist/components/chat/messages/ErrorMessage.js +0 -756
- package/dist/components/chat/messages/ErrorMessage.js.map +0 -1
- package/dist/components/chat/messages/ErrorMessage.mjs +0 -72
- package/dist/components/chat/messages/ErrorMessage.mjs.map +0 -1
- package/dist/components/chat/messages/ImageRenderer.d.ts +0 -12
- package/dist/components/chat/messages/ImageRenderer.js +0 -68
- package/dist/components/chat/messages/ImageRenderer.js.map +0 -1
- package/dist/components/chat/messages/ImageRenderer.mjs +0 -8
- package/dist/components/chat/messages/ImageRenderer.mjs.map +0 -1
- package/dist/components/chat/messages/LegacyRenderMessage.d.ts +0 -28
- package/dist/components/chat/messages/LegacyRenderMessage.js +0 -1067
- package/dist/components/chat/messages/LegacyRenderMessage.js.map +0 -1
- package/dist/components/chat/messages/LegacyRenderMessage.mjs +0 -17
- package/dist/components/chat/messages/LegacyRenderMessage.mjs.map +0 -1
- package/dist/components/chat/messages/RenderMessage.d.ts +0 -9
- package/dist/components/chat/messages/RenderMessage.js +0 -942
- package/dist/components/chat/messages/RenderMessage.js.map +0 -1
- package/dist/components/chat/messages/RenderMessage.mjs +0 -16
- package/dist/components/chat/messages/RenderMessage.mjs.map +0 -1
- package/dist/components/chat/messages/UserMessage.d.ts +0 -9
- package/dist/components/chat/messages/UserMessage.js +0 -58
- package/dist/components/chat/messages/UserMessage.js.map +0 -1
- package/dist/components/chat/messages/UserMessage.mjs +0 -8
- package/dist/components/chat/messages/UserMessage.mjs.map +0 -1
- package/dist/components/chat/props.d.ts +0 -298
- package/dist/components/chat/props.js +0 -19
- package/dist/components/chat/props.js.map +0 -1
- package/dist/components/chat/props.mjs +0 -2
- package/dist/components/chat/props.mjs.map +0 -1
- package/dist/components/dev-console/console.d.ts +0 -11
- package/dist/components/dev-console/console.js +0 -595
- package/dist/components/dev-console/console.js.map +0 -1
- package/dist/components/dev-console/console.mjs +0 -17
- package/dist/components/dev-console/console.mjs.map +0 -1
- package/dist/components/dev-console/icons.d.ts +0 -9
- package/dist/components/dev-console/icons.js +0 -140
- package/dist/components/dev-console/icons.js.map +0 -1
- package/dist/components/dev-console/icons.mjs +0 -16
- package/dist/components/dev-console/icons.mjs.map +0 -1
- package/dist/components/dev-console/index.d.ts +0 -3
- package/dist/components/dev-console/index.js +0 -595
- package/dist/components/dev-console/index.js.map +0 -1
- package/dist/components/dev-console/index.mjs +0 -18
- package/dist/components/dev-console/index.mjs.map +0 -1
- package/dist/components/dev-console/types.d.ts +0 -9
- package/dist/components/dev-console/types.js +0 -19
- package/dist/components/dev-console/types.js.map +0 -1
- package/dist/components/dev-console/types.mjs +0 -1
- package/dist/components/dev-console/types.mjs.map +0 -1
- package/dist/components/dev-console/utils.d.ts +0 -10
- package/dist/components/dev-console/utils.js +0 -183
- package/dist/components/dev-console/utils.js.map +0 -1
- package/dist/components/dev-console/utils.mjs +0 -16
- package/dist/components/dev-console/utils.mjs.map +0 -1
- package/dist/components/help-modal/icons.d.ts +0 -9
- package/dist/components/help-modal/icons.js +0 -116
- package/dist/components/help-modal/icons.js.map +0 -1
- package/dist/components/help-modal/icons.mjs +0 -12
- package/dist/components/help-modal/icons.mjs.map +0 -1
- package/dist/components/help-modal/index.d.ts +0 -2
- package/dist/components/help-modal/index.js +0 -144
- package/dist/components/help-modal/index.js.map +0 -1
- package/dist/components/help-modal/index.mjs +0 -10
- package/dist/components/help-modal/index.mjs.map +0 -1
- package/dist/components/help-modal/modal.d.ts +0 -5
- package/dist/components/help-modal/modal.js +0 -142
- package/dist/components/help-modal/modal.js.map +0 -1
- package/dist/components/help-modal/modal.mjs +0 -9
- package/dist/components/help-modal/modal.mjs.map +0 -1
- package/dist/components/index.d.ts +0 -19
- package/dist/components/index.js +0 -3345
- package/dist/components/index.js.map +0 -1
- package/dist/components/index.mjs +0 -76
- package/dist/components/index.mjs.map +0 -1
- package/dist/context/index.d.ts +0 -2
- package/dist/context/index.js +0 -19
- package/dist/context/index.js.map +0 -1
- package/dist/context/index.mjs +0 -2
- package/dist/context/index.mjs.map +0 -1
- package/dist/hooks/index.d.ts +0 -2
- package/dist/hooks/index.js +0 -36
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/index.mjs +0 -9
- package/dist/hooks/index.mjs.map +0 -1
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +0 -66
- package/dist/hooks/use-copilot-chat-suggestions.js +0 -34
- package/dist/hooks/use-copilot-chat-suggestions.js.map +0 -1
- package/dist/hooks/use-copilot-chat-suggestions.mjs +0 -8
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +0 -1
- package/dist/hooks/use-copy-to-clipboard.d.ts +0 -9
- package/dist/hooks/use-copy-to-clipboard.js +0 -62
- package/dist/hooks/use-copy-to-clipboard.js.map +0 -1
- package/dist/hooks/use-copy-to-clipboard.mjs +0 -8
- package/dist/hooks/use-copy-to-clipboard.mjs.map +0 -1
- package/dist/hooks/use-dark-mode.d.ts +0 -3
- package/dist/hooks/use-dark-mode.js +0 -35
- package/dist/hooks/use-dark-mode.js.map +0 -1
- package/dist/hooks/use-dark-mode.mjs +0 -8
- package/dist/hooks/use-dark-mode.mjs.map +0 -1
- package/dist/hooks/use-push-to-talk.d.ts +0 -19
- package/dist/hooks/use-push-to-talk.js +0 -202
- package/dist/hooks/use-push-to-talk.js.map +0 -1
- package/dist/hooks/use-push-to-talk.mjs +0 -12
- package/dist/hooks/use-push-to-talk.mjs.map +0 -1
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -3354
- package/dist/index.js.map +0 -1
- package/dist/lib/utils.d.ts +0 -4
- package/dist/lib/utils.js +0 -76
- package/dist/lib/utils.js.map +0 -1
- package/dist/lib/utils.mjs +0 -34
- package/dist/lib/utils.mjs.map +0 -1
- package/dist/types/css.d.ts +0 -22
- package/dist/types/css.js +0 -19
- package/dist/types/css.js.map +0 -1
- package/dist/types/css.mjs +0 -1
- package/dist/types/css.mjs.map +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.js +0 -19
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/suggestions.d.ts +0 -9
- package/dist/types/suggestions.js +0 -19
- package/dist/types/suggestions.js.map +0 -1
- package/dist/types/suggestions.mjs +0 -1
- package/dist/types/suggestions.mjs.map +0 -1
- package/dist/v2/index.css +0 -4
- package/dist/v2/index.css.map +0 -1
- package/dist/v2/index.d.ts +0 -2
- package/dist/v2/index.js +0 -2
- package/dist/v2/index.js.map +0 -1
- package/dist/v2/index.mjs +0 -2
- package/dist/v2/index.mjs.map +0 -1
- package/jest.config.js +0 -5
- package/rollup.config.mjs +0 -64
- package/tsup.config.ts +0 -15
package/dist/index.mjs
CHANGED
|
@@ -1,84 +1,2688 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
} from "
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import "
|
|
13
|
-
import "
|
|
14
|
-
import "
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
2
|
+
|
|
3
|
+
import * as React$1 from "react";
|
|
4
|
+
import React, { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { defaultCopilotContextCategories, shouldShowDevConsole, useCopilotChatInternal, useCopilotChatSuggestions as useCopilotChatSuggestions$1, useCopilotContext, useCopilotMessagesContext } from "@copilotkit/react-core";
|
|
7
|
+
import { COPILOTKIT_VERSION, CopilotKitError, CopilotKitErrorCode, ErrorVisibility, Severity, isMacOS, randomUUID, styledConsole } from "@copilotkit/shared";
|
|
8
|
+
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react";
|
|
9
|
+
import ReactMarkdown from "react-markdown";
|
|
10
|
+
import { Light, Prism } from "react-syntax-highlighter";
|
|
11
|
+
import remarkGfm from "remark-gfm";
|
|
12
|
+
import remarkMath from "remark-math";
|
|
13
|
+
import rehypeRaw from "rehype-raw";
|
|
14
|
+
import { aguiToGQL, gqlToAGUI } from "@copilotkit/runtime-client-gql";
|
|
15
|
+
|
|
16
|
+
//#region src/components/chat/Icons.tsx
|
|
17
|
+
const OpenIcon = /* @__PURE__ */ jsx("svg", {
|
|
18
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
19
|
+
viewBox: "0 0 24 24",
|
|
20
|
+
fill: "currentColor",
|
|
21
|
+
width: "24",
|
|
22
|
+
height: "24",
|
|
23
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
24
|
+
transform: "translate(24, 0) scale(-1, 1)",
|
|
25
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
26
|
+
fillRule: "evenodd",
|
|
27
|
+
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",
|
|
28
|
+
clipRule: "evenodd"
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
const CloseIcon$1 = /* @__PURE__ */ jsx("svg", {
|
|
33
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
34
|
+
fill: "none",
|
|
35
|
+
viewBox: "0 0 24 24",
|
|
36
|
+
strokeWidth: "1.5",
|
|
37
|
+
stroke: "currentColor",
|
|
38
|
+
width: "24",
|
|
39
|
+
height: "24",
|
|
40
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
41
|
+
strokeLinecap: "round",
|
|
42
|
+
strokeLinejoin: "round",
|
|
43
|
+
d: "M19.5 8.25l-7.5 7.5-7.5-7.5"
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
const HeaderCloseIcon = /* @__PURE__ */ jsx("svg", {
|
|
47
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
48
|
+
fill: "none",
|
|
49
|
+
viewBox: "0 0 24 24",
|
|
50
|
+
strokeWidth: "1.5",
|
|
51
|
+
stroke: "currentColor",
|
|
52
|
+
width: "24",
|
|
53
|
+
height: "24",
|
|
54
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
55
|
+
strokeLinecap: "round",
|
|
56
|
+
strokeLinejoin: "round",
|
|
57
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
const SendIcon = /* @__PURE__ */ jsx("svg", {
|
|
61
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
62
|
+
fill: "none",
|
|
63
|
+
viewBox: "0 0 24 24",
|
|
64
|
+
strokeWidth: "1.5",
|
|
65
|
+
stroke: "currentColor",
|
|
66
|
+
width: "24",
|
|
67
|
+
height: "24",
|
|
68
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
69
|
+
strokeLinecap: "round",
|
|
70
|
+
strokeLinejoin: "round",
|
|
71
|
+
d: "M12 19V5m0 0l-7 7m7-7l7 7"
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
const MicrophoneIcon = /* @__PURE__ */ jsx("svg", {
|
|
75
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
76
|
+
fill: "none",
|
|
77
|
+
viewBox: "0 0 24 24",
|
|
78
|
+
strokeWidth: "1.5",
|
|
79
|
+
stroke: "currentColor",
|
|
80
|
+
width: "24",
|
|
81
|
+
height: "24",
|
|
82
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
83
|
+
strokeLinecap: "round",
|
|
84
|
+
strokeLinejoin: "round",
|
|
85
|
+
d: "M12 18.75a6 6 0 006-6v-1.5m-6 7.5a6 6 0 01-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 01-3-3V4.5a3 3 0 116 0v8.25a3 3 0 01-3 3z"
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
const StopIcon = /* @__PURE__ */ jsx("svg", {
|
|
89
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
90
|
+
fill: "none",
|
|
91
|
+
viewBox: "0 0 24 24",
|
|
92
|
+
strokeWidth: "1.5",
|
|
93
|
+
stroke: "currentColor",
|
|
94
|
+
width: "24",
|
|
95
|
+
height: "24",
|
|
96
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
97
|
+
strokeLinecap: "round",
|
|
98
|
+
strokeLinejoin: "round",
|
|
99
|
+
d: "M5.25 7.5A2.25 2.25 0 017.5 5.25h9a2.25 2.25 0 012.25 2.25v9a2.25 2.25 0 01-2.25 2.25h-9a2.25 2.25 0 01-2.25-2.25v-9z"
|
|
100
|
+
})
|
|
101
|
+
});
|
|
102
|
+
const RegenerateIcon = /* @__PURE__ */ jsx("svg", {
|
|
103
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
104
|
+
fill: "none",
|
|
105
|
+
viewBox: "0 0 24 24",
|
|
106
|
+
strokeWidth: "2",
|
|
107
|
+
stroke: "currentColor",
|
|
108
|
+
width: "16",
|
|
109
|
+
height: "16",
|
|
110
|
+
style: {
|
|
111
|
+
minWidth: "16px",
|
|
112
|
+
minHeight: "16px"
|
|
113
|
+
},
|
|
114
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
115
|
+
strokeLinecap: "round",
|
|
116
|
+
strokeLinejoin: "round",
|
|
117
|
+
d: "M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99"
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
const CopyIcon = /* @__PURE__ */ jsx("svg", {
|
|
121
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
122
|
+
fill: "none",
|
|
123
|
+
viewBox: "0 0 24 24",
|
|
124
|
+
strokeWidth: "2",
|
|
125
|
+
stroke: "currentColor",
|
|
126
|
+
width: "16",
|
|
127
|
+
height: "16",
|
|
128
|
+
style: {
|
|
129
|
+
minWidth: "16px",
|
|
130
|
+
minHeight: "16px"
|
|
131
|
+
},
|
|
132
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
133
|
+
strokeLinecap: "round",
|
|
134
|
+
strokeLinejoin: "round",
|
|
135
|
+
d: "M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 00-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 01-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 00-3.375-3.375h-1.5a1.125 1.125 0 01-1.125-1.125v-1.5a3.375 3.375 0 00-3.375-3.375H9.75"
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
const SmallSpinnerIcon = /* @__PURE__ */ jsx("span", {
|
|
139
|
+
className: "copilotKitSpinner",
|
|
140
|
+
style: {
|
|
141
|
+
width: "13px",
|
|
142
|
+
height: "13px"
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const SpinnerIcon = /* @__PURE__ */ jsx("span", {
|
|
146
|
+
className: "copilotKitSpinner",
|
|
147
|
+
style: {
|
|
148
|
+
width: "24px",
|
|
149
|
+
height: "24px"
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const ActivityIcon = /* @__PURE__ */ jsxs("div", {
|
|
153
|
+
style: {
|
|
154
|
+
display: "flex",
|
|
155
|
+
alignItems: "center",
|
|
156
|
+
gap: "4px"
|
|
157
|
+
},
|
|
158
|
+
children: [
|
|
159
|
+
/* @__PURE__ */ jsx("span", {
|
|
160
|
+
className: "copilotKitActivityDot",
|
|
161
|
+
style: { animationDelay: "0s" }
|
|
162
|
+
}),
|
|
163
|
+
/* @__PURE__ */ jsx("span", {
|
|
164
|
+
className: "copilotKitActivityDot",
|
|
165
|
+
style: { animationDelay: "0.2s" }
|
|
166
|
+
}),
|
|
167
|
+
/* @__PURE__ */ jsx("span", {
|
|
168
|
+
className: "copilotKitActivityDot",
|
|
169
|
+
style: { animationDelay: "0.4s" }
|
|
170
|
+
})
|
|
171
|
+
]
|
|
172
|
+
});
|
|
173
|
+
const ThumbsUpIcon = /* @__PURE__ */ jsx("svg", {
|
|
174
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
175
|
+
fill: "none",
|
|
176
|
+
viewBox: "0 0 24 24",
|
|
177
|
+
strokeWidth: "2",
|
|
178
|
+
stroke: "currentColor",
|
|
179
|
+
width: "16",
|
|
180
|
+
height: "16",
|
|
181
|
+
style: {
|
|
182
|
+
minWidth: "16px",
|
|
183
|
+
minHeight: "16px"
|
|
184
|
+
},
|
|
185
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
186
|
+
strokeLinecap: "round",
|
|
187
|
+
strokeLinejoin: "round",
|
|
188
|
+
d: "M6.633 10.5c.806 0 1.533-.446 2.031-1.08a9.041 9.041 0 012.861-2.4c.723-.384 1.35-.956 1.653-1.715a4.498 4.498 0 00.322-1.672V3a.75.75 0 01.75-.75A2.25 2.25 0 0116.5 4.5c0 1.152-.26 2.243-.723 3.218-.266.558.107 1.282.725 1.282h3.126c1.026 0 1.945.694 2.054 1.715.045.422.068.85.068 1.285a11.95 11.95 0 01-2.649 7.521c-.388.482-.987.729-1.605.729H13.48c-.483 0-.964-.078-1.423-.23l-3.114-1.04a4.501 4.501 0 00-1.423-.23H5.904M14.25 9h2.25M5.904 18.75c.083.205.173.405.27.602.197.4-.078.898-.523.898h-.908c-.889 0-1.713-.518-1.972-1.368a12 12 0 01-.521-3.507c0-1.553.295-3.036.831-4.398C3.387 10.203 4.167 9.75 5 9.75h1.053c.472 0 .745.556.5.96a8.958 8.958 0 00-1.302 4.665c0 1.194.232 2.333.654 3.375z"
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
const ThumbsDownIcon = /* @__PURE__ */ jsx("svg", {
|
|
192
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
193
|
+
fill: "none",
|
|
194
|
+
viewBox: "0 0 24 24",
|
|
195
|
+
strokeWidth: "2",
|
|
196
|
+
stroke: "currentColor",
|
|
197
|
+
width: "16",
|
|
198
|
+
height: "16",
|
|
199
|
+
style: {
|
|
200
|
+
minWidth: "16px",
|
|
201
|
+
minHeight: "16px"
|
|
202
|
+
},
|
|
203
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
204
|
+
strokeLinecap: "round",
|
|
205
|
+
strokeLinejoin: "round",
|
|
206
|
+
d: "M7.5 15h2.25m8.024-9.75c.011.05.028.1.052.148.591 1.2.924 2.55.924 3.977a8.96 8.96 0 01-.999 4.125m.023-8.25c-.076-.365.183-.75.575-.75h.908c.889 0 1.713.518 1.972 1.368.339 1.11.521 2.287.521 3.507 0 1.553-.295 3.036-.831 4.398C20.613 14.547 19.833 15 19 15h-1.053c-.472 0-.745-.556-.5-.96a8.95 8.95 0 00.303-.54m.023-8.25H16.48a4.5 4.5 0 01-1.423-.23l-3.114-1.04a4.5 4.5 0 00-1.423-.23H6.504c-.618 0-1.217.247-1.605.729A11.95 11.95 0 002.25 12c0 .434.023.863.068 1.285C2.427 14.306 3.346 15 4.372 15h3.126c.618 0 .991.724.725 1.282A7.471 7.471 0 007.5 19.5a2.25 2.25 0 002.25 2.25.75.75 0 00.75-.75v-.633c0-.573.11-1.14.322-1.672.304-.76.93-1.33 1.653-1.715a9.04 9.04 0 002.86-2.4c.498-.634 1.226-1.08 2.032-1.08h.384"
|
|
207
|
+
})
|
|
208
|
+
});
|
|
209
|
+
const DownloadIcon = /* @__PURE__ */ jsx("svg", {
|
|
210
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
211
|
+
fill: "none",
|
|
212
|
+
viewBox: "0 0 24 24",
|
|
213
|
+
strokeWidth: "2",
|
|
214
|
+
stroke: "currentColor",
|
|
215
|
+
width: "16",
|
|
216
|
+
height: "16",
|
|
217
|
+
style: {
|
|
218
|
+
minWidth: "16px",
|
|
219
|
+
minHeight: "16px"
|
|
220
|
+
},
|
|
221
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
222
|
+
strokeLinecap: "round",
|
|
223
|
+
strokeLinejoin: "round",
|
|
224
|
+
d: "M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3"
|
|
225
|
+
})
|
|
226
|
+
});
|
|
227
|
+
const UploadIcon = /* @__PURE__ */ jsx("svg", {
|
|
228
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
229
|
+
fill: "none",
|
|
230
|
+
viewBox: "0 0 24 24",
|
|
231
|
+
strokeWidth: "1.5",
|
|
232
|
+
stroke: "currentColor",
|
|
233
|
+
width: "24",
|
|
234
|
+
height: "24",
|
|
235
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
236
|
+
strokeLinecap: "round",
|
|
237
|
+
strokeLinejoin: "round",
|
|
238
|
+
d: "M12 4.5v15m7.5-7.5h-15"
|
|
239
|
+
})
|
|
240
|
+
});
|
|
241
|
+
const CheckIcon$1 = /* @__PURE__ */ jsx("svg", {
|
|
242
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
243
|
+
fill: "none",
|
|
244
|
+
viewBox: "0 0 24 24",
|
|
245
|
+
strokeWidth: "2",
|
|
246
|
+
stroke: "currentColor",
|
|
247
|
+
width: "16",
|
|
248
|
+
height: "16",
|
|
249
|
+
style: {
|
|
250
|
+
minWidth: "16px",
|
|
251
|
+
minHeight: "16px"
|
|
252
|
+
},
|
|
253
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
254
|
+
strokeLinecap: "round",
|
|
255
|
+
strokeLinejoin: "round",
|
|
256
|
+
d: "M4.5 12.75l6 6 9-13.5"
|
|
257
|
+
})
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/components/chat/ChatContext.tsx
|
|
262
|
+
const ChatContext = React.createContext(void 0);
|
|
263
|
+
function useChatContext() {
|
|
264
|
+
const context = React.useContext(ChatContext);
|
|
265
|
+
if (context === void 0) throw new Error("Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?");
|
|
266
|
+
return context;
|
|
267
|
+
}
|
|
268
|
+
const ChatContextProvider = ({ labels, icons, children, open, setOpen }) => {
|
|
269
|
+
const memoizedLabels = useMemo(() => ({
|
|
270
|
+
initial: "",
|
|
271
|
+
title: "CopilotKit",
|
|
272
|
+
placeholder: "Type a message...",
|
|
273
|
+
error: "❌ An error occurred. Please try again.",
|
|
274
|
+
stopGenerating: "Stop generating",
|
|
275
|
+
regenerateResponse: "Regenerate response",
|
|
276
|
+
copyToClipboard: "Copy to clipboard",
|
|
277
|
+
thumbsUp: "Thumbs up",
|
|
278
|
+
thumbsDown: "Thumbs down",
|
|
279
|
+
copied: "Copied!",
|
|
280
|
+
...labels
|
|
281
|
+
}), [labels]);
|
|
282
|
+
const memoizedIcons = useMemo(() => ({
|
|
283
|
+
openIcon: OpenIcon,
|
|
284
|
+
closeIcon: CloseIcon$1,
|
|
285
|
+
headerCloseIcon: HeaderCloseIcon,
|
|
286
|
+
sendIcon: SendIcon,
|
|
287
|
+
activityIcon: ActivityIcon,
|
|
288
|
+
spinnerIcon: SpinnerIcon,
|
|
289
|
+
stopIcon: StopIcon,
|
|
290
|
+
regenerateIcon: RegenerateIcon,
|
|
291
|
+
pushToTalkIcon: MicrophoneIcon,
|
|
292
|
+
copyIcon: CopyIcon,
|
|
293
|
+
thumbsUpIcon: ThumbsUpIcon,
|
|
294
|
+
thumbsDownIcon: ThumbsDownIcon,
|
|
295
|
+
uploadIcon: UploadIcon,
|
|
296
|
+
...icons
|
|
297
|
+
}), [icons]);
|
|
298
|
+
const context = useMemo(() => ({
|
|
299
|
+
labels: memoizedLabels,
|
|
300
|
+
icons: memoizedIcons,
|
|
301
|
+
open,
|
|
302
|
+
setOpen
|
|
303
|
+
}), [
|
|
304
|
+
memoizedLabels,
|
|
305
|
+
memoizedIcons,
|
|
306
|
+
open,
|
|
307
|
+
setOpen
|
|
308
|
+
]);
|
|
309
|
+
return /* @__PURE__ */ jsx(ChatContext.Provider, {
|
|
310
|
+
value: context,
|
|
311
|
+
children
|
|
312
|
+
});
|
|
83
313
|
};
|
|
314
|
+
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/components/chat/Window.tsx
|
|
317
|
+
const Window = ({ children, clickOutsideToClose, shortcut, hitEscapeToClose }) => {
|
|
318
|
+
const windowRef = React.useRef(null);
|
|
319
|
+
useCopilotContext();
|
|
320
|
+
const { open, setOpen } = useChatContext();
|
|
321
|
+
const handleClickOutside = useCallback((event) => {
|
|
322
|
+
if (!clickOutsideToClose) return;
|
|
323
|
+
const parentElement = windowRef.current?.parentElement;
|
|
324
|
+
let className = "";
|
|
325
|
+
if (event.target instanceof HTMLElement) className = event.target.className;
|
|
326
|
+
if (open && parentElement && !parentElement.contains(event.target) && !className.includes("copilotKitDebugMenu")) setOpen(false);
|
|
327
|
+
}, [
|
|
328
|
+
clickOutsideToClose,
|
|
329
|
+
open,
|
|
330
|
+
setOpen
|
|
331
|
+
]);
|
|
332
|
+
const handleKeyDown = useCallback((event) => {
|
|
333
|
+
const target = event.target;
|
|
334
|
+
const isInput = target.tagName === "INPUT" || target.tagName === "SELECT" || target.tagName === "TEXTAREA" || target.isContentEditable;
|
|
335
|
+
const isDescendantOfWrapper = windowRef.current?.contains(target);
|
|
336
|
+
if (open && event.key === "Escape" && (!isInput || isDescendantOfWrapper) && hitEscapeToClose) setOpen(false);
|
|
337
|
+
else if (event.key === shortcut && (isMacOS() && event.metaKey || !isMacOS() && event.ctrlKey) && (!isInput || isDescendantOfWrapper)) setOpen(!open);
|
|
338
|
+
}, [
|
|
339
|
+
hitEscapeToClose,
|
|
340
|
+
shortcut,
|
|
341
|
+
open,
|
|
342
|
+
setOpen
|
|
343
|
+
]);
|
|
344
|
+
const adjustForMobile = useCallback(() => {
|
|
345
|
+
const copilotKitWindow = windowRef.current;
|
|
346
|
+
const vv = window.visualViewport;
|
|
347
|
+
if (!copilotKitWindow || !vv) return;
|
|
348
|
+
if (window.innerWidth < 640 && open) {
|
|
349
|
+
copilotKitWindow.style.height = `${vv.height}px`;
|
|
350
|
+
copilotKitWindow.style.left = `${vv.offsetLeft}px`;
|
|
351
|
+
copilotKitWindow.style.top = `${vv.offsetTop}px`;
|
|
352
|
+
document.body.style.position = "fixed";
|
|
353
|
+
document.body.style.width = "100%";
|
|
354
|
+
document.body.style.height = `${window.innerHeight}px`;
|
|
355
|
+
document.body.style.overflow = "hidden";
|
|
356
|
+
document.body.style.touchAction = "none";
|
|
357
|
+
document.body.addEventListener("touchmove", preventScroll, { passive: false });
|
|
358
|
+
} else {
|
|
359
|
+
copilotKitWindow.style.height = "";
|
|
360
|
+
copilotKitWindow.style.left = "";
|
|
361
|
+
copilotKitWindow.style.top = "";
|
|
362
|
+
document.body.style.position = "";
|
|
363
|
+
document.body.style.height = "";
|
|
364
|
+
document.body.style.width = "";
|
|
365
|
+
document.body.style.overflow = "";
|
|
366
|
+
document.body.style.top = "";
|
|
367
|
+
document.body.style.touchAction = "";
|
|
368
|
+
document.body.removeEventListener("touchmove", preventScroll);
|
|
369
|
+
}
|
|
370
|
+
}, [open]);
|
|
371
|
+
useEffect(() => {
|
|
372
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
373
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
374
|
+
if (window.visualViewport) {
|
|
375
|
+
window.visualViewport.addEventListener("resize", adjustForMobile);
|
|
376
|
+
adjustForMobile();
|
|
377
|
+
}
|
|
378
|
+
return () => {
|
|
379
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
380
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
381
|
+
if (window.visualViewport) window.visualViewport.removeEventListener("resize", adjustForMobile);
|
|
382
|
+
};
|
|
383
|
+
}, [
|
|
384
|
+
adjustForMobile,
|
|
385
|
+
handleClickOutside,
|
|
386
|
+
handleKeyDown
|
|
387
|
+
]);
|
|
388
|
+
return /* @__PURE__ */ jsx("div", {
|
|
389
|
+
className: `copilotKitWindow ${open ? " open" : ""}`,
|
|
390
|
+
ref: windowRef,
|
|
391
|
+
children
|
|
392
|
+
});
|
|
393
|
+
};
|
|
394
|
+
const preventScroll = (event) => {
|
|
395
|
+
let targetElement = event.target;
|
|
396
|
+
const hasParentWithClass = (element, className) => {
|
|
397
|
+
while (element && element !== document.body) {
|
|
398
|
+
if (element.classList.contains(className)) return true;
|
|
399
|
+
element = element.parentElement;
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
402
|
+
};
|
|
403
|
+
if (!hasParentWithClass(targetElement, "copilotKitMessages")) event.preventDefault();
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region src/components/chat/Button.tsx
|
|
408
|
+
const Button = ({}) => {
|
|
409
|
+
const { open, setOpen, icons } = useChatContext();
|
|
410
|
+
return /* @__PURE__ */ jsx("div", {
|
|
411
|
+
onClick: () => setOpen(!open),
|
|
412
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
413
|
+
className: `copilotKitButton ${open ? "open" : ""}`,
|
|
414
|
+
"aria-label": open ? "Close Chat" : "Open Chat",
|
|
415
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
416
|
+
className: "copilotKitButtonIcon copilotKitButtonIconOpen",
|
|
417
|
+
children: icons.openIcon
|
|
418
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
419
|
+
className: "copilotKitButtonIcon copilotKitButtonIconClose",
|
|
420
|
+
children: icons.closeIcon
|
|
421
|
+
})]
|
|
422
|
+
})
|
|
423
|
+
});
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region src/components/dev-console/utils.ts
|
|
428
|
+
async function getPublishedCopilotKitVersion(current, forceCheck = false) {
|
|
429
|
+
const LOCAL_STORAGE_KEY = "__copilotkit_version_check__";
|
|
430
|
+
const serializedVersion = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
431
|
+
if (serializedVersion && !forceCheck) try {
|
|
432
|
+
const parsedVersion = JSON.parse(serializedVersion);
|
|
433
|
+
const oneHour = 3600 * 1e3;
|
|
434
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
435
|
+
if (parsedVersion.current === current && now - new Date(parsedVersion.lastChecked).getTime() < oneHour) return parsedVersion;
|
|
436
|
+
} catch (error) {
|
|
437
|
+
console.error("Failed to parse CopilotKitVersion from localStorage", error);
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
const data = await (await fetch("https://api.cloud.copilotkit.ai/check-for-updates", {
|
|
441
|
+
method: "POST",
|
|
442
|
+
headers: { "Content-Type": "application/json" },
|
|
443
|
+
body: JSON.stringify({ packages: [{
|
|
444
|
+
packageName: "@copilotkit/shared",
|
|
445
|
+
packageVersion: current
|
|
446
|
+
}] })
|
|
447
|
+
})).json();
|
|
448
|
+
const version = {
|
|
449
|
+
current,
|
|
450
|
+
lastChecked: (/* @__PURE__ */ new Date()).getTime(),
|
|
451
|
+
latest: data.packages[0].latestVersion,
|
|
452
|
+
severity: data.packages[0].severity,
|
|
453
|
+
advisory: data.packages[0].advisory || null
|
|
454
|
+
};
|
|
455
|
+
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(version));
|
|
456
|
+
return version;
|
|
457
|
+
} catch (error) {
|
|
458
|
+
console.error("Failed to check for updates", error);
|
|
459
|
+
throw error;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
function logReadables(context) {
|
|
463
|
+
console.log("%cCurrent Readables:", "font-size: 16px; font-weight: bold;");
|
|
464
|
+
const readables = context.getContextString([], defaultCopilotContextCategories).trim();
|
|
465
|
+
if (readables.length === 0) {
|
|
466
|
+
console.log("No readables found");
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
console.log(readables);
|
|
470
|
+
}
|
|
471
|
+
function logActions(context) {
|
|
472
|
+
console.log("%cCurrent Actions:", "font-size: 16px; font-weight: bold;");
|
|
473
|
+
if (Object.values(context.actions).length === 0) {
|
|
474
|
+
console.log("No actions found");
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
for (const action of Object.values(context.actions)) {
|
|
478
|
+
console.group(action.name);
|
|
479
|
+
console.log("name", action.name);
|
|
480
|
+
console.log("description", action.description);
|
|
481
|
+
console.log("parameters", action.parameters);
|
|
482
|
+
console.groupEnd();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function logMessages(context) {
|
|
486
|
+
console.log("%cCurrent Messages:", "font-size: 16px; font-weight: bold;");
|
|
487
|
+
if (context.messages.length === 0) {
|
|
488
|
+
console.log("No messages found");
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
const tableData = context.messages.map((message) => {
|
|
492
|
+
if (message.isTextMessage()) return {
|
|
493
|
+
id: message.id,
|
|
494
|
+
type: "TextMessage",
|
|
495
|
+
role: message.role,
|
|
496
|
+
name: void 0,
|
|
497
|
+
scope: void 0,
|
|
498
|
+
content: message.content
|
|
499
|
+
};
|
|
500
|
+
else if (message.isActionExecutionMessage()) return {
|
|
501
|
+
id: message.id,
|
|
502
|
+
type: "ActionExecutionMessage",
|
|
503
|
+
role: void 0,
|
|
504
|
+
name: message.name,
|
|
505
|
+
scope: message.parentMessageId,
|
|
506
|
+
content: message.arguments
|
|
507
|
+
};
|
|
508
|
+
else if (message.isResultMessage()) return {
|
|
509
|
+
id: message.id,
|
|
510
|
+
type: "ResultMessage",
|
|
511
|
+
role: void 0,
|
|
512
|
+
name: message.actionName,
|
|
513
|
+
scope: message.actionExecutionId,
|
|
514
|
+
content: message.result
|
|
515
|
+
};
|
|
516
|
+
else if (message.isAgentStateMessage()) return {
|
|
517
|
+
id: message.id,
|
|
518
|
+
type: `AgentStateMessage (running: ${message.running})`,
|
|
519
|
+
role: message.role,
|
|
520
|
+
name: void 0,
|
|
521
|
+
scope: message.threadId,
|
|
522
|
+
content: message.state
|
|
523
|
+
};
|
|
524
|
+
});
|
|
525
|
+
console.table(tableData);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
//#endregion
|
|
529
|
+
//#region src/components/dev-console/icons.tsx
|
|
530
|
+
const ExclamationMarkTriangleIcon = /* @__PURE__ */ jsx("svg", {
|
|
531
|
+
width: "13.3967723px",
|
|
532
|
+
height: "12px",
|
|
533
|
+
viewBox: "0 0 13.3967723 12",
|
|
534
|
+
version: "1.1",
|
|
535
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
536
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
537
|
+
id: "Page-1",
|
|
538
|
+
stroke: "none",
|
|
539
|
+
strokeWidth: "1",
|
|
540
|
+
fill: "none",
|
|
541
|
+
fillRule: "evenodd",
|
|
542
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
543
|
+
id: "exclamation-triangle",
|
|
544
|
+
fill: "#CD2121",
|
|
545
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
546
|
+
d: "M5.39935802,0.75 C5.97670802,-0.25 7.42007802,-0.25 7.99742802,0.75 L13.193588,9.75 C13.770888,10.75 13.049288,12 11.894588,12 L1.50223802,12 C0.34753802,12 -0.37414898,10.75 0.20319802,9.75 L5.39935802,0.75 Z M6.69838802,2.5 C7.11260802,2.5 7.44838802,2.83579 7.44838802,3.25 L7.44838802,6.25 C7.44838802,6.66421 7.11260802,7 6.69838802,7 C6.28417802,7 5.94838802,6.66421 5.94838802,6.25 L5.94838802,3.25 C5.94838802,2.83579 6.28417802,2.5 6.69838802,2.5 Z M6.69838802,10.5 C7.25067802,10.5 7.69838802,10.0523 7.69838802,9.5 C7.69838802,8.9477 7.25067802,8.5 6.69838802,8.5 C6.14610802,8.5 5.69838802,8.9477 5.69838802,9.5 C5.69838802,10.0523 6.14610802,10.5 6.69838802,10.5 Z",
|
|
547
|
+
id: "Shape"
|
|
548
|
+
})
|
|
549
|
+
})
|
|
550
|
+
})
|
|
551
|
+
});
|
|
552
|
+
const ExclamationMarkIcon = /* @__PURE__ */ jsx("svg", {
|
|
553
|
+
width: "14px",
|
|
554
|
+
height: "14px",
|
|
555
|
+
viewBox: "0 0 14 14",
|
|
556
|
+
version: "1.1",
|
|
557
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
558
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
559
|
+
id: "Page-1",
|
|
560
|
+
stroke: "none",
|
|
561
|
+
strokeWidth: "1",
|
|
562
|
+
fill: "none",
|
|
563
|
+
fillRule: "evenodd",
|
|
564
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
565
|
+
id: "exclamation-circle",
|
|
566
|
+
fill: "#EC662C",
|
|
567
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
568
|
+
d: "M7,14 C10.866,14 14,10.866 14,7 C14,3.13401 10.866,0 7,0 C3.13401,0 0,3.13401 0,7 C0,10.866 3.13401,14 7,14 Z M7,3 C7.41421,3 7.75,3.33579 7.75,3.75 L7.75,6.75 C7.75,7.16421 7.41421,7.5 7,7.5 C6.58579,7.5 6.25,7.16421 6.25,6.75 L6.25,3.75 C6.25,3.33579 6.58579,3 7,3 Z M7,11 C7.55228,11 8,10.5523 8,10 C8,9.4477 7.55228,9 7,9 C6.44772,9 6,9.4477 6,10 C6,10.5523 6.44772,11 7,11 Z",
|
|
569
|
+
id: "Shape"
|
|
570
|
+
})
|
|
571
|
+
})
|
|
572
|
+
})
|
|
573
|
+
});
|
|
574
|
+
const ChevronDownIcon = /* @__PURE__ */ jsx("svg", {
|
|
575
|
+
width: "7px",
|
|
576
|
+
height: "4px",
|
|
577
|
+
viewBox: "0 0 7 4",
|
|
578
|
+
version: "1.1",
|
|
579
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
580
|
+
fill: "currentColor",
|
|
581
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
582
|
+
id: "Page-1",
|
|
583
|
+
stroke: "none",
|
|
584
|
+
strokeWidth: "1",
|
|
585
|
+
fill: "none",
|
|
586
|
+
fillRule: "evenodd",
|
|
587
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
588
|
+
id: "Group",
|
|
589
|
+
fill: "currentColor",
|
|
590
|
+
fillRule: "nonzero",
|
|
591
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
592
|
+
d: "M3.71690723,3.90271086 C3.59268176,4.03242971 3.39143629,4.03242971 3.26721082,3.90271086 L0.0853966595,0.57605615 C-0.0314221035,0.444981627 -0.0279751448,0.240725043 0.0931934622,0.114040675 C0.214362069,-0.0126436935 0.409725445,-0.0162475626 0.535093061,0.105888951 L3.49205902,3.19746006 L6.44902499,0.105888951 C6.52834574,0.0168884389 6.64780588,-0.0197473458 6.7605411,0.0103538404 C6.87327633,0.0404550266 6.96130636,0.132492308 6.99009696,0.250359396 C7.01888756,0.368226483 6.98384687,0.493124608 6.89872139,0.57605615 L3.71690723,3.90271086 Z",
|
|
593
|
+
id: "Path"
|
|
594
|
+
})
|
|
595
|
+
})
|
|
596
|
+
})
|
|
597
|
+
});
|
|
598
|
+
const CheckIcon = /* @__PURE__ */ jsx("svg", {
|
|
599
|
+
width: "14px",
|
|
600
|
+
height: "14px",
|
|
601
|
+
viewBox: "0 0 14 14",
|
|
602
|
+
version: "1.1",
|
|
603
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
604
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
605
|
+
id: "Page-1",
|
|
606
|
+
stroke: "none",
|
|
607
|
+
strokeWidth: "1",
|
|
608
|
+
fill: "none",
|
|
609
|
+
fillRule: "evenodd",
|
|
610
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
611
|
+
id: "Group-2",
|
|
612
|
+
transform: "translate(-118, 0)",
|
|
613
|
+
fill: "#1BC030",
|
|
614
|
+
fillRule: "nonzero",
|
|
615
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
616
|
+
id: "Group",
|
|
617
|
+
transform: "translate(118, 0)",
|
|
618
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
619
|
+
d: "M0,7 C0,3.13384615 3.13384615,0 7,0 C10.8661538,0 14,3.13384615 14,7 C14,10.8661538 10.8661538,14 7,14 C3.13384615,14 0,10.8661538 0,7 Z M9.59179487,5.69764103 C9.70905818,5.54139023 9.73249341,5.33388318 9.65303227,5.15541491 C9.57357113,4.97694665 9.40367989,4.85551619 9.20909814,4.83811118 C9.01451638,4.82070616 8.82577109,4.91005717 8.71589744,5.07158974 L6.39261538,8.32389744 L5.22666667,7.15794872 C5.01450582,6.96025518 4.68389046,6.9660885 4.47883563,7.17114332 C4.27378081,7.37619815 4.26794748,7.70681351 4.46564103,7.91897436 L6.08102564,9.53435897 C6.19289944,9.64614839 6.3482622,9.70310251 6.50588106,9.69010587 C6.66349993,9.67710922 6.80743532,9.59547613 6.89948718,9.46687179 L9.59179487,5.69764103 L9.59179487,5.69764103 Z",
|
|
620
|
+
id: "Shape"
|
|
621
|
+
})
|
|
622
|
+
})
|
|
623
|
+
})
|
|
624
|
+
})
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
//#endregion
|
|
628
|
+
//#region src/components/help-modal/icons.tsx
|
|
629
|
+
const CloseIcon = () => /* @__PURE__ */ jsx("svg", {
|
|
630
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
631
|
+
fill: "none",
|
|
632
|
+
viewBox: "0 0 24 24",
|
|
633
|
+
strokeWidth: "1.5",
|
|
634
|
+
stroke: "currentColor",
|
|
635
|
+
width: "20",
|
|
636
|
+
height: "20",
|
|
637
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
638
|
+
strokeLinecap: "round",
|
|
639
|
+
strokeLinejoin: "round",
|
|
640
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
641
|
+
})
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
//#endregion
|
|
645
|
+
//#region src/components/help-modal/modal.tsx
|
|
646
|
+
function CopilotKitHelpModal() {
|
|
647
|
+
const [showHelpModal, setShowHelpModal] = useState(false);
|
|
648
|
+
const buttonRef = useRef(null);
|
|
649
|
+
const popoverRef = useRef(null);
|
|
650
|
+
useEffect(() => {
|
|
651
|
+
const handleClickOutside = (event) => {
|
|
652
|
+
if (popoverRef.current && !popoverRef.current.contains(event.target) && buttonRef.current && !buttonRef.current.contains(event.target)) setShowHelpModal(false);
|
|
653
|
+
};
|
|
654
|
+
if (showHelpModal) document.addEventListener("mousedown", handleClickOutside);
|
|
655
|
+
return () => {
|
|
656
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
657
|
+
};
|
|
658
|
+
}, [showHelpModal]);
|
|
659
|
+
const HelpButton = () => /* @__PURE__ */ jsx("button", {
|
|
660
|
+
ref: buttonRef,
|
|
661
|
+
onClick: () => setShowHelpModal(!showHelpModal),
|
|
662
|
+
className: "copilotKitDebugMenuTriggerButton relative",
|
|
663
|
+
"aria-label": "Open Help",
|
|
664
|
+
children: "Help"
|
|
665
|
+
});
|
|
666
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
667
|
+
className: "relative",
|
|
668
|
+
children: [/* @__PURE__ */ jsx(HelpButton, {}), showHelpModal && /* @__PURE__ */ jsx("div", {
|
|
669
|
+
ref: popoverRef,
|
|
670
|
+
className: "absolute mt-2 z-50",
|
|
671
|
+
style: {
|
|
672
|
+
top: "100%",
|
|
673
|
+
right: "-120px",
|
|
674
|
+
width: "380px"
|
|
675
|
+
},
|
|
676
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
677
|
+
className: "copilotKitHelpModal rounded-lg shadow-xl w-full p-4 flex-col relative",
|
|
678
|
+
children: [
|
|
679
|
+
/* @__PURE__ */ jsx("button", {
|
|
680
|
+
className: "copilotKitHelpModalCloseButton absolute text-gray-400 hover:text-gray-600 focus:outline-none",
|
|
681
|
+
style: {
|
|
682
|
+
top: "10px",
|
|
683
|
+
right: "10px"
|
|
684
|
+
},
|
|
685
|
+
onClick: () => setShowHelpModal(false),
|
|
686
|
+
"aria-label": "Close",
|
|
687
|
+
children: /* @__PURE__ */ jsx(CloseIcon, {})
|
|
688
|
+
}),
|
|
689
|
+
/* @__PURE__ */ jsx("div", {
|
|
690
|
+
className: "w-full flex mb-6 justify-center",
|
|
691
|
+
children: /* @__PURE__ */ jsx("h2", {
|
|
692
|
+
className: "text-2xl font-bold",
|
|
693
|
+
children: "Help Options"
|
|
694
|
+
})
|
|
695
|
+
}),
|
|
696
|
+
/* @__PURE__ */ jsxs("div", {
|
|
697
|
+
className: "space-y-4 mb-4",
|
|
698
|
+
children: [
|
|
699
|
+
/* @__PURE__ */ jsx("div", {
|
|
700
|
+
className: "copilotKitHelpItemButton",
|
|
701
|
+
children: /* @__PURE__ */ jsx("a", {
|
|
702
|
+
href: "https://docs.copilotkit.ai/coagents/troubleshooting/common-issues",
|
|
703
|
+
target: "_blank",
|
|
704
|
+
rel: "noopener noreferrer",
|
|
705
|
+
children: "Visit the Troubleshooting and FAQ section in the docs"
|
|
706
|
+
})
|
|
707
|
+
}),
|
|
708
|
+
/* @__PURE__ */ jsx("div", {
|
|
709
|
+
className: "copilotKitHelpItemButton",
|
|
710
|
+
children: /* @__PURE__ */ jsx("a", {
|
|
711
|
+
href: "https://go.copilotkit.ai/dev-console-support-discord",
|
|
712
|
+
target: "_blank",
|
|
713
|
+
rel: "noopener noreferrer",
|
|
714
|
+
children: "Go to Discord Support Channel (Community Support)"
|
|
715
|
+
})
|
|
716
|
+
}),
|
|
717
|
+
/* @__PURE__ */ jsx("div", {
|
|
718
|
+
className: "copilotKitHelpItemButton",
|
|
719
|
+
children: /* @__PURE__ */ jsx("a", {
|
|
720
|
+
href: "https://go.copilotkit.ai/dev-console-support-slack",
|
|
721
|
+
target: "_blank",
|
|
722
|
+
rel: "noopener noreferrer",
|
|
723
|
+
children: "Apply for Priority Direct Slack Support"
|
|
724
|
+
})
|
|
725
|
+
})
|
|
726
|
+
]
|
|
727
|
+
})
|
|
728
|
+
]
|
|
729
|
+
})
|
|
730
|
+
})]
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region src/components/dev-console/console.tsx
|
|
736
|
+
function CopilotDevConsole() {
|
|
737
|
+
const currentVersion = COPILOTKIT_VERSION;
|
|
738
|
+
const context = useCopilotContext();
|
|
739
|
+
const [showDevConsole, setShowDevConsole] = useState(false);
|
|
740
|
+
useEffect(() => {
|
|
741
|
+
setShowDevConsole(shouldShowDevConsole(context.showDevConsole));
|
|
742
|
+
}, [context.showDevConsole]);
|
|
743
|
+
const dontRunTwiceInDevMode = useRef(false);
|
|
744
|
+
const [versionStatus, setVersionStatus] = useState("unknown");
|
|
745
|
+
const [latestVersion, setLatestVersion] = useState("");
|
|
746
|
+
const consoleRef = useRef(null);
|
|
747
|
+
const [debugButtonMode, setDebugButtonMode] = useState("full");
|
|
748
|
+
const checkForUpdates = (force = false) => {
|
|
749
|
+
setVersionStatus("checking");
|
|
750
|
+
getPublishedCopilotKitVersion(currentVersion, force).then((v) => {
|
|
751
|
+
setLatestVersion(v.latest);
|
|
752
|
+
let versionOk = false;
|
|
753
|
+
if (v.current === v.latest) versionOk = true;
|
|
754
|
+
else if (/[a-zA-Z]/.test(v.current)) versionOk = true;
|
|
755
|
+
if (versionOk) setVersionStatus("latest");
|
|
756
|
+
else if (v.severity !== "low") setVersionStatus("outdated");
|
|
757
|
+
else setVersionStatus("update-available");
|
|
758
|
+
}).catch((e) => {
|
|
759
|
+
console.error(e);
|
|
760
|
+
setVersionStatus("unknown");
|
|
761
|
+
});
|
|
762
|
+
};
|
|
763
|
+
useEffect(() => {
|
|
764
|
+
if (dontRunTwiceInDevMode.current === true) return;
|
|
765
|
+
dontRunTwiceInDevMode.current = true;
|
|
766
|
+
checkForUpdates();
|
|
767
|
+
}, []);
|
|
768
|
+
if (!showDevConsole) return null;
|
|
769
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
770
|
+
ref: consoleRef,
|
|
771
|
+
className: "copilotKitDevConsole " + (versionStatus === "update-available" ? "copilotKitDevConsoleUpgrade" : "") + (versionStatus === "outdated" ? "copilotKitDevConsoleWarnOutdated" : ""),
|
|
772
|
+
children: [
|
|
773
|
+
/* @__PURE__ */ jsx(VersionInfo, {
|
|
774
|
+
showDevConsole: context.showDevConsole,
|
|
775
|
+
versionStatus,
|
|
776
|
+
currentVersion,
|
|
777
|
+
latestVersion
|
|
778
|
+
}),
|
|
779
|
+
/* @__PURE__ */ jsx(CopilotKitHelpModal, {}),
|
|
780
|
+
/* @__PURE__ */ jsx(DebugMenuButton, {
|
|
781
|
+
setShowDevConsole,
|
|
782
|
+
checkForUpdates,
|
|
783
|
+
mode: debugButtonMode
|
|
784
|
+
})
|
|
785
|
+
]
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
function VersionInfo({ showDevConsole, versionStatus, currentVersion, latestVersion }) {
|
|
789
|
+
const [copyStatus, setCopyStatus] = useState("");
|
|
790
|
+
let versionIcon = "";
|
|
791
|
+
let currentVersionLabel = currentVersion;
|
|
792
|
+
if (versionStatus === "latest") versionIcon = CheckIcon;
|
|
793
|
+
else if (versionStatus === "checking") versionIcon = SmallSpinnerIcon;
|
|
794
|
+
else if (versionStatus === "update-available") {
|
|
795
|
+
versionIcon = ExclamationMarkIcon;
|
|
796
|
+
currentVersionLabel = `${currentVersion} → ${latestVersion}`;
|
|
797
|
+
} else if (versionStatus === "outdated") {
|
|
798
|
+
versionIcon = ExclamationMarkTriangleIcon;
|
|
799
|
+
currentVersionLabel = `${currentVersion} → ${latestVersion}`;
|
|
800
|
+
}
|
|
801
|
+
if (showDevConsole === true) {}
|
|
802
|
+
const installCommand = [
|
|
803
|
+
`npm install`,
|
|
804
|
+
`@copilotkit/react-core@${latestVersion}`,
|
|
805
|
+
`@copilotkit/react-ui@${latestVersion}`,
|
|
806
|
+
`@copilotkit/react-textarea@${latestVersion}`,
|
|
807
|
+
`&& npm install @copilotkit/runtime@${latestVersion}`
|
|
808
|
+
].join(" ");
|
|
809
|
+
const handleCopyClick = () => {
|
|
810
|
+
navigator.clipboard.writeText(installCommand.trim()).then(() => {
|
|
811
|
+
setCopyStatus("Command copied to clipboard!");
|
|
812
|
+
setTimeout(() => setCopyStatus(""), 1e3);
|
|
813
|
+
});
|
|
814
|
+
};
|
|
815
|
+
if (versionStatus === "update-available" || versionStatus === "outdated") return /* @__PURE__ */ jsxs("div", {
|
|
816
|
+
className: "copilotKitVersionInfo",
|
|
817
|
+
children: [/* @__PURE__ */ jsxs("p", { children: [
|
|
818
|
+
currentVersionLabel,
|
|
819
|
+
" ",
|
|
820
|
+
versionIcon
|
|
821
|
+
] }), /* @__PURE__ */ jsx("button", {
|
|
822
|
+
onClick: handleCopyClick,
|
|
823
|
+
children: copyStatus || installCommand
|
|
824
|
+
})]
|
|
825
|
+
});
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
function DebugMenuButton({ setShowDevConsole, checkForUpdates, mode }) {
|
|
829
|
+
const context = useCopilotContext();
|
|
830
|
+
const messagesContext = useCopilotMessagesContext();
|
|
831
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(MenuButton, {
|
|
832
|
+
className: `copilotKitDebugMenuTriggerButton ${mode === "compact" ? "compact" : ""}`,
|
|
833
|
+
children: mode == "compact" ? "Debug" : /* @__PURE__ */ jsxs(Fragment, { children: ["Debug ", ChevronDownIcon] })
|
|
834
|
+
}), /* @__PURE__ */ jsxs(MenuItems, {
|
|
835
|
+
transition: true,
|
|
836
|
+
anchor: "bottom end",
|
|
837
|
+
className: "copilotKitDebugMenu",
|
|
838
|
+
style: { zIndex: 40 },
|
|
839
|
+
children: [
|
|
840
|
+
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx("button", {
|
|
841
|
+
className: "copilotKitDebugMenuItem",
|
|
842
|
+
onClick: () => logReadables(context),
|
|
843
|
+
children: "Log Readables"
|
|
844
|
+
}) }),
|
|
845
|
+
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx("button", {
|
|
846
|
+
className: "copilotKitDebugMenuItem",
|
|
847
|
+
onClick: () => logActions(context),
|
|
848
|
+
children: "Log Actions"
|
|
849
|
+
}) }),
|
|
850
|
+
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx("button", {
|
|
851
|
+
className: "copilotKitDebugMenuItem",
|
|
852
|
+
onClick: () => logMessages(messagesContext),
|
|
853
|
+
children: "Log Messages"
|
|
854
|
+
}) }),
|
|
855
|
+
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx("button", {
|
|
856
|
+
className: "copilotKitDebugMenuItem",
|
|
857
|
+
onClick: () => checkForUpdates(true),
|
|
858
|
+
children: "Check for Updates"
|
|
859
|
+
}) }),
|
|
860
|
+
/* @__PURE__ */ jsx("hr", {}),
|
|
861
|
+
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx("button", {
|
|
862
|
+
className: "copilotKitDebugMenuItem",
|
|
863
|
+
onClick: () => setShowDevConsole(false),
|
|
864
|
+
children: "Hide Dev Console"
|
|
865
|
+
}) })
|
|
866
|
+
]
|
|
867
|
+
})] }) });
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
//#endregion
|
|
871
|
+
//#region src/components/chat/Header.tsx
|
|
872
|
+
const Header = ({}) => {
|
|
873
|
+
const { setOpen, icons, labels } = useChatContext();
|
|
874
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
875
|
+
className: "copilotKitHeader",
|
|
876
|
+
children: [/* @__PURE__ */ jsx("div", { children: labels.title }), /* @__PURE__ */ jsxs("div", {
|
|
877
|
+
className: "copilotKitHeaderControls",
|
|
878
|
+
children: [/* @__PURE__ */ jsx(CopilotDevConsole, {}), /* @__PURE__ */ jsx("button", {
|
|
879
|
+
onClick: () => setOpen(false),
|
|
880
|
+
"aria-label": "Close",
|
|
881
|
+
className: "copilotKitHeaderCloseButton",
|
|
882
|
+
children: icons.headerCloseIcon
|
|
883
|
+
})]
|
|
884
|
+
})]
|
|
885
|
+
});
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
//#endregion
|
|
889
|
+
//#region src/components/chat/messages/UserMessage.tsx
|
|
890
|
+
const getTextContent = (content) => {
|
|
891
|
+
if (typeof content === "undefined") return;
|
|
892
|
+
if (typeof content === "string") return content;
|
|
893
|
+
return content.map((part) => {
|
|
894
|
+
if (part.type === "text") return part.text;
|
|
895
|
+
}).filter((value) => typeof value === "string" && value.length > 0).join(" ").trim() || void 0;
|
|
896
|
+
};
|
|
897
|
+
const UserMessage = (props) => {
|
|
898
|
+
const { message, ImageRenderer } = props;
|
|
899
|
+
if (message && "image" in message && Boolean(message.image)) {
|
|
900
|
+
const imageMessage = message;
|
|
901
|
+
const content = getTextContent(imageMessage?.content);
|
|
902
|
+
return /* @__PURE__ */ jsx("div", {
|
|
903
|
+
className: "copilotKitMessage copilotKitUserMessage",
|
|
904
|
+
children: /* @__PURE__ */ jsx(ImageRenderer, {
|
|
905
|
+
image: imageMessage.image,
|
|
906
|
+
content
|
|
907
|
+
})
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
return /* @__PURE__ */ jsx("div", {
|
|
911
|
+
className: "copilotKitMessage copilotKitUserMessage",
|
|
912
|
+
children: getTextContent(message?.content)
|
|
913
|
+
});
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
//#endregion
|
|
917
|
+
//#region src/hooks/use-copy-to-clipboard.tsx
|
|
918
|
+
function useCopyToClipboard({ timeout = 2e3 }) {
|
|
919
|
+
const [isCopied, setIsCopied] = React$1.useState(false);
|
|
920
|
+
const copyToClipboard = (value) => {
|
|
921
|
+
if (typeof window === "undefined" || !navigator.clipboard?.writeText) return;
|
|
922
|
+
if (!value) return;
|
|
923
|
+
navigator.clipboard.writeText(value).then(() => {
|
|
924
|
+
setIsCopied(true);
|
|
925
|
+
setTimeout(() => {
|
|
926
|
+
setIsCopied(false);
|
|
927
|
+
}, timeout);
|
|
928
|
+
});
|
|
929
|
+
};
|
|
930
|
+
return {
|
|
931
|
+
isCopied,
|
|
932
|
+
copyToClipboard
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
//#endregion
|
|
937
|
+
//#region src/components/chat/CodeBlock.tsx
|
|
938
|
+
const programmingLanguages = {
|
|
939
|
+
javascript: ".js",
|
|
940
|
+
python: ".py",
|
|
941
|
+
java: ".java",
|
|
942
|
+
c: ".c",
|
|
943
|
+
cpp: ".cpp",
|
|
944
|
+
"c++": ".cpp",
|
|
945
|
+
"c#": ".cs",
|
|
946
|
+
ruby: ".rb",
|
|
947
|
+
php: ".php",
|
|
948
|
+
swift: ".swift",
|
|
949
|
+
"objective-c": ".m",
|
|
950
|
+
kotlin: ".kt",
|
|
951
|
+
typescript: ".ts",
|
|
952
|
+
go: ".go",
|
|
953
|
+
perl: ".pl",
|
|
954
|
+
rust: ".rs",
|
|
955
|
+
scala: ".scala",
|
|
956
|
+
haskell: ".hs",
|
|
957
|
+
lua: ".lua",
|
|
958
|
+
shell: ".sh",
|
|
959
|
+
sql: ".sql",
|
|
960
|
+
html: ".html",
|
|
961
|
+
css: ".css"
|
|
962
|
+
};
|
|
963
|
+
const generateRandomString = (length, lowercase = false) => {
|
|
964
|
+
const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789";
|
|
965
|
+
let result = "";
|
|
966
|
+
for (let i = 0; i < length; i++) result += chars.charAt(Math.floor(Math.random() * 30));
|
|
967
|
+
return lowercase ? result.toLowerCase() : result;
|
|
968
|
+
};
|
|
969
|
+
const CodeBlock = memo(({ language, value }) => {
|
|
970
|
+
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
|
|
971
|
+
const [SyntaxHighlighter, setSyntaxHighlighter] = useState(() => Light);
|
|
972
|
+
useEffect(() => {
|
|
973
|
+
try {
|
|
974
|
+
setSyntaxHighlighter(() => Prism);
|
|
975
|
+
} catch {
|
|
976
|
+
setSyntaxHighlighter(() => Light);
|
|
977
|
+
}
|
|
978
|
+
}, []);
|
|
979
|
+
const downloadAsFile = () => {
|
|
980
|
+
if (typeof window === "undefined") return;
|
|
981
|
+
const fileExtension = programmingLanguages[language] || ".file";
|
|
982
|
+
const suggestedFileName = `file-${generateRandomString(3, true)}${fileExtension}`;
|
|
983
|
+
const fileName = window.prompt("Enter file name", suggestedFileName);
|
|
984
|
+
if (!fileName) return;
|
|
985
|
+
const blob = new Blob([value], { type: "text/plain" });
|
|
986
|
+
const url = URL.createObjectURL(blob);
|
|
987
|
+
const link = document.createElement("a");
|
|
988
|
+
link.download = fileName;
|
|
989
|
+
link.href = url;
|
|
990
|
+
link.style.display = "none";
|
|
991
|
+
document.body.appendChild(link);
|
|
992
|
+
link.click();
|
|
993
|
+
document.body.removeChild(link);
|
|
994
|
+
URL.revokeObjectURL(url);
|
|
995
|
+
};
|
|
996
|
+
const onCopy = () => {
|
|
997
|
+
if (isCopied) return;
|
|
998
|
+
copyToClipboard(value);
|
|
999
|
+
};
|
|
1000
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1001
|
+
className: "copilotKitCodeBlock",
|
|
1002
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1003
|
+
className: "copilotKitCodeBlockToolbar",
|
|
1004
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1005
|
+
className: "copilotKitCodeBlockToolbarLanguage",
|
|
1006
|
+
children: language
|
|
1007
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1008
|
+
className: "copilotKitCodeBlockToolbarButtons",
|
|
1009
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
1010
|
+
className: "copilotKitCodeBlockToolbarButton",
|
|
1011
|
+
onClick: downloadAsFile,
|
|
1012
|
+
children: DownloadIcon
|
|
1013
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
1014
|
+
className: "copilotKitCodeBlockToolbarButton",
|
|
1015
|
+
onClick: onCopy,
|
|
1016
|
+
children: isCopied ? CheckIcon$1 : CopyIcon
|
|
1017
|
+
})]
|
|
1018
|
+
})]
|
|
1019
|
+
}), /* @__PURE__ */ jsx(SyntaxHighlighter, {
|
|
1020
|
+
language,
|
|
1021
|
+
style: highlightStyle,
|
|
1022
|
+
PreTag: "div",
|
|
1023
|
+
customStyle: {
|
|
1024
|
+
margin: 0,
|
|
1025
|
+
borderBottomLeftRadius: "0.375rem",
|
|
1026
|
+
borderBottomRightRadius: "0.375rem"
|
|
1027
|
+
},
|
|
1028
|
+
children: value
|
|
1029
|
+
})]
|
|
1030
|
+
});
|
|
1031
|
+
});
|
|
1032
|
+
CodeBlock.displayName = "CodeBlock";
|
|
1033
|
+
const highlightStyle = {
|
|
1034
|
+
"pre[class*=\"language-\"]": {
|
|
1035
|
+
color: "#d4d4d4",
|
|
1036
|
+
fontSize: "13px",
|
|
1037
|
+
textShadow: "none",
|
|
1038
|
+
fontFamily: "Menlo, Monaco, Consolas, \"Andale Mono\", \"Ubuntu Mono\", \"Courier New\", monospace",
|
|
1039
|
+
direction: "ltr",
|
|
1040
|
+
textAlign: "left",
|
|
1041
|
+
whiteSpace: "pre",
|
|
1042
|
+
wordSpacing: "normal",
|
|
1043
|
+
wordBreak: "normal",
|
|
1044
|
+
lineHeight: "1.5",
|
|
1045
|
+
MozTabSize: "4",
|
|
1046
|
+
OTabSize: "4",
|
|
1047
|
+
tabSize: "4",
|
|
1048
|
+
WebkitHyphens: "none",
|
|
1049
|
+
MozHyphens: "none",
|
|
1050
|
+
msHyphens: "none",
|
|
1051
|
+
hyphens: "none",
|
|
1052
|
+
padding: "1em",
|
|
1053
|
+
margin: ".5em 0",
|
|
1054
|
+
overflow: "auto",
|
|
1055
|
+
background: "#1e1e1e"
|
|
1056
|
+
},
|
|
1057
|
+
"code[class*=\"language-\"]": {
|
|
1058
|
+
color: "#d4d4d4",
|
|
1059
|
+
fontSize: "13px",
|
|
1060
|
+
textShadow: "none",
|
|
1061
|
+
fontFamily: "Menlo, Monaco, Consolas, \"Andale Mono\", \"Ubuntu Mono\", \"Courier New\", monospace",
|
|
1062
|
+
direction: "ltr",
|
|
1063
|
+
textAlign: "left",
|
|
1064
|
+
whiteSpace: "pre",
|
|
1065
|
+
wordSpacing: "normal",
|
|
1066
|
+
wordBreak: "normal",
|
|
1067
|
+
lineHeight: "1.5",
|
|
1068
|
+
MozTabSize: "4",
|
|
1069
|
+
OTabSize: "4",
|
|
1070
|
+
tabSize: "4",
|
|
1071
|
+
WebkitHyphens: "none",
|
|
1072
|
+
MozHyphens: "none",
|
|
1073
|
+
msHyphens: "none",
|
|
1074
|
+
hyphens: "none"
|
|
1075
|
+
},
|
|
1076
|
+
"pre[class*=\"language-\"]::selection": {
|
|
1077
|
+
textShadow: "none",
|
|
1078
|
+
background: "#264F78"
|
|
1079
|
+
},
|
|
1080
|
+
"code[class*=\"language-\"]::selection": {
|
|
1081
|
+
textShadow: "none",
|
|
1082
|
+
background: "#264F78"
|
|
1083
|
+
},
|
|
1084
|
+
"pre[class*=\"language-\"] *::selection": {
|
|
1085
|
+
textShadow: "none",
|
|
1086
|
+
background: "#264F78"
|
|
1087
|
+
},
|
|
1088
|
+
"code[class*=\"language-\"] *::selection": {
|
|
1089
|
+
textShadow: "none",
|
|
1090
|
+
background: "#264F78"
|
|
1091
|
+
},
|
|
1092
|
+
":not(pre) > code[class*=\"language-\"]": {
|
|
1093
|
+
padding: ".1em .3em",
|
|
1094
|
+
borderRadius: ".3em",
|
|
1095
|
+
color: "#db4c69",
|
|
1096
|
+
background: "#1e1e1e"
|
|
1097
|
+
},
|
|
1098
|
+
".namespace": { Opacity: ".7" },
|
|
1099
|
+
"doctype.doctype-tag": { color: "#569CD6" },
|
|
1100
|
+
"doctype.name": { color: "#9cdcfe" },
|
|
1101
|
+
comment: { color: "#6a9955" },
|
|
1102
|
+
prolog: { color: "#6a9955" },
|
|
1103
|
+
punctuation: { color: "#d4d4d4" },
|
|
1104
|
+
".language-html .language-css .token.punctuation": { color: "#d4d4d4" },
|
|
1105
|
+
".language-html .language-javascript .token.punctuation": { color: "#d4d4d4" },
|
|
1106
|
+
property: { color: "#9cdcfe" },
|
|
1107
|
+
tag: { color: "#569cd6" },
|
|
1108
|
+
boolean: { color: "#569cd6" },
|
|
1109
|
+
number: { color: "#b5cea8" },
|
|
1110
|
+
constant: { color: "#9cdcfe" },
|
|
1111
|
+
symbol: { color: "#b5cea8" },
|
|
1112
|
+
inserted: { color: "#b5cea8" },
|
|
1113
|
+
unit: { color: "#b5cea8" },
|
|
1114
|
+
selector: { color: "#d7ba7d" },
|
|
1115
|
+
"attr-name": { color: "#9cdcfe" },
|
|
1116
|
+
string: { color: "#ce9178" },
|
|
1117
|
+
char: { color: "#ce9178" },
|
|
1118
|
+
builtin: { color: "#ce9178" },
|
|
1119
|
+
deleted: { color: "#ce9178" },
|
|
1120
|
+
".language-css .token.string.url": { textDecoration: "underline" },
|
|
1121
|
+
operator: { color: "#d4d4d4" },
|
|
1122
|
+
entity: { color: "#569cd6" },
|
|
1123
|
+
"operator.arrow": { color: "#569CD6" },
|
|
1124
|
+
atrule: { color: "#ce9178" },
|
|
1125
|
+
"atrule.rule": { color: "#c586c0" },
|
|
1126
|
+
"atrule.url": { color: "#9cdcfe" },
|
|
1127
|
+
"atrule.url.function": { color: "#dcdcaa" },
|
|
1128
|
+
"atrule.url.punctuation": { color: "#d4d4d4" },
|
|
1129
|
+
keyword: { color: "#569CD6" },
|
|
1130
|
+
"keyword.module": { color: "#c586c0" },
|
|
1131
|
+
"keyword.control-flow": { color: "#c586c0" },
|
|
1132
|
+
function: { color: "#dcdcaa" },
|
|
1133
|
+
"function.maybe-class-name": { color: "#dcdcaa" },
|
|
1134
|
+
regex: { color: "#d16969" },
|
|
1135
|
+
important: { color: "#569cd6" },
|
|
1136
|
+
italic: { fontStyle: "italic" },
|
|
1137
|
+
"class-name": { color: "#4ec9b0" },
|
|
1138
|
+
"maybe-class-name": { color: "#4ec9b0" },
|
|
1139
|
+
console: { color: "#9cdcfe" },
|
|
1140
|
+
parameter: { color: "#9cdcfe" },
|
|
1141
|
+
interpolation: { color: "#9cdcfe" },
|
|
1142
|
+
"punctuation.interpolation-punctuation": { color: "#569cd6" },
|
|
1143
|
+
variable: { color: "#9cdcfe" },
|
|
1144
|
+
"imports.maybe-class-name": { color: "#9cdcfe" },
|
|
1145
|
+
"exports.maybe-class-name": { color: "#9cdcfe" },
|
|
1146
|
+
escape: { color: "#d7ba7d" },
|
|
1147
|
+
"tag.punctuation": { color: "#808080" },
|
|
1148
|
+
cdata: { color: "#808080" },
|
|
1149
|
+
"attr-value": { color: "#ce9178" },
|
|
1150
|
+
"attr-value.punctuation": { color: "#ce9178" },
|
|
1151
|
+
"attr-value.punctuation.attr-equals": { color: "#d4d4d4" },
|
|
1152
|
+
namespace: { color: "#4ec9b0" },
|
|
1153
|
+
"pre[class*=\"language-javascript\"]": { color: "#9cdcfe" },
|
|
1154
|
+
"code[class*=\"language-javascript\"]": { color: "#9cdcfe" },
|
|
1155
|
+
"pre[class*=\"language-jsx\"]": { color: "#9cdcfe" },
|
|
1156
|
+
"code[class*=\"language-jsx\"]": { color: "#9cdcfe" },
|
|
1157
|
+
"pre[class*=\"language-typescript\"]": { color: "#9cdcfe" },
|
|
1158
|
+
"code[class*=\"language-typescript\"]": { color: "#9cdcfe" },
|
|
1159
|
+
"pre[class*=\"language-tsx\"]": { color: "#9cdcfe" },
|
|
1160
|
+
"code[class*=\"language-tsx\"]": { color: "#9cdcfe" },
|
|
1161
|
+
"pre[class*=\"language-css\"]": { color: "#ce9178" },
|
|
1162
|
+
"code[class*=\"language-css\"]": { color: "#ce9178" },
|
|
1163
|
+
"pre[class*=\"language-html\"]": { color: "#d4d4d4" },
|
|
1164
|
+
"code[class*=\"language-html\"]": { color: "#d4d4d4" },
|
|
1165
|
+
".language-regex .token.anchor": { color: "#dcdcaa" },
|
|
1166
|
+
".language-html .token.punctuation": { color: "#808080" },
|
|
1167
|
+
"pre[class*=\"language-\"] > code[class*=\"language-\"]": {
|
|
1168
|
+
position: "relative",
|
|
1169
|
+
zIndex: "1"
|
|
1170
|
+
},
|
|
1171
|
+
".line-highlight.line-highlight": {
|
|
1172
|
+
background: "#f7ebc6",
|
|
1173
|
+
boxShadow: "inset 5px 0 0 #f7d87c",
|
|
1174
|
+
zIndex: "0"
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
|
|
1178
|
+
//#endregion
|
|
1179
|
+
//#region src/components/chat/Markdown.tsx
|
|
1180
|
+
const defaultComponents = {
|
|
1181
|
+
a({ children, ...props }) {
|
|
1182
|
+
return /* @__PURE__ */ jsx("a", {
|
|
1183
|
+
className: "copilotKitMarkdownElement",
|
|
1184
|
+
...props,
|
|
1185
|
+
target: "_blank",
|
|
1186
|
+
rel: "noopener noreferrer",
|
|
1187
|
+
children
|
|
1188
|
+
});
|
|
1189
|
+
},
|
|
1190
|
+
code({ children, className, inline, ...props }) {
|
|
1191
|
+
if (Array.isArray(children) && children.length) {
|
|
1192
|
+
if (children[0] == "▍") return /* @__PURE__ */ jsx("span", {
|
|
1193
|
+
style: {
|
|
1194
|
+
animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
1195
|
+
marginTop: "0.25rem"
|
|
1196
|
+
},
|
|
1197
|
+
children: "▍"
|
|
1198
|
+
});
|
|
1199
|
+
children[0] = (children?.[0]).replace("`▍`", "▍");
|
|
1200
|
+
}
|
|
1201
|
+
const match = /language-(\w+)/.exec(className || "");
|
|
1202
|
+
const hasLanguage = match && match[1];
|
|
1203
|
+
const hasNewlines = String(children).includes("\n");
|
|
1204
|
+
if (!hasLanguage && !hasNewlines) return /* @__PURE__ */ jsx("code", {
|
|
1205
|
+
className: `copilotKitMarkdownElement copilotKitInlineCode ${className || ""}`,
|
|
1206
|
+
...props,
|
|
1207
|
+
children
|
|
1208
|
+
});
|
|
1209
|
+
return /* @__PURE__ */ jsx(CodeBlock, {
|
|
1210
|
+
language: match && match[1] || "",
|
|
1211
|
+
value: String(children).replace(/\n$/, ""),
|
|
1212
|
+
...props
|
|
1213
|
+
}, Math.random());
|
|
1214
|
+
},
|
|
1215
|
+
h1: ({ children, ...props }) => /* @__PURE__ */ jsx("h1", {
|
|
1216
|
+
className: "copilotKitMarkdownElement",
|
|
1217
|
+
...props,
|
|
1218
|
+
children
|
|
1219
|
+
}),
|
|
1220
|
+
h2: ({ children, ...props }) => /* @__PURE__ */ jsx("h2", {
|
|
1221
|
+
className: "copilotKitMarkdownElement",
|
|
1222
|
+
...props,
|
|
1223
|
+
children
|
|
1224
|
+
}),
|
|
1225
|
+
h3: ({ children, ...props }) => /* @__PURE__ */ jsx("h3", {
|
|
1226
|
+
className: "copilotKitMarkdownElement",
|
|
1227
|
+
...props,
|
|
1228
|
+
children
|
|
1229
|
+
}),
|
|
1230
|
+
h4: ({ children, ...props }) => /* @__PURE__ */ jsx("h4", {
|
|
1231
|
+
className: "copilotKitMarkdownElement",
|
|
1232
|
+
...props,
|
|
1233
|
+
children
|
|
1234
|
+
}),
|
|
1235
|
+
h5: ({ children, ...props }) => /* @__PURE__ */ jsx("h5", {
|
|
1236
|
+
className: "copilotKitMarkdownElement",
|
|
1237
|
+
...props,
|
|
1238
|
+
children
|
|
1239
|
+
}),
|
|
1240
|
+
h6: ({ children, ...props }) => /* @__PURE__ */ jsx("h6", {
|
|
1241
|
+
className: "copilotKitMarkdownElement",
|
|
1242
|
+
...props,
|
|
1243
|
+
children
|
|
1244
|
+
}),
|
|
1245
|
+
p: ({ children, ...props }) => /* @__PURE__ */ jsx("p", {
|
|
1246
|
+
className: "copilotKitMarkdownElement",
|
|
1247
|
+
...props,
|
|
1248
|
+
children
|
|
1249
|
+
}),
|
|
1250
|
+
pre: ({ children, ...props }) => /* @__PURE__ */ jsx("pre", {
|
|
1251
|
+
className: "copilotKitMarkdownElement",
|
|
1252
|
+
...props,
|
|
1253
|
+
children
|
|
1254
|
+
}),
|
|
1255
|
+
blockquote: ({ children, ...props }) => /* @__PURE__ */ jsx("blockquote", {
|
|
1256
|
+
className: "copilotKitMarkdownElement",
|
|
1257
|
+
...props,
|
|
1258
|
+
children
|
|
1259
|
+
}),
|
|
1260
|
+
ul: ({ children, ...props }) => /* @__PURE__ */ jsx("ul", {
|
|
1261
|
+
className: "copilotKitMarkdownElement",
|
|
1262
|
+
...props,
|
|
1263
|
+
children
|
|
1264
|
+
}),
|
|
1265
|
+
li: ({ children, ...props }) => /* @__PURE__ */ jsx("li", {
|
|
1266
|
+
className: "copilotKitMarkdownElement",
|
|
1267
|
+
...props,
|
|
1268
|
+
children
|
|
1269
|
+
})
|
|
1270
|
+
};
|
|
1271
|
+
const MemoizedReactMarkdown = memo(ReactMarkdown, (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components);
|
|
1272
|
+
const Markdown = ({ content, components }) => {
|
|
1273
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1274
|
+
className: "copilotKitMarkdown",
|
|
1275
|
+
children: /* @__PURE__ */ jsx(MemoizedReactMarkdown, {
|
|
1276
|
+
components: {
|
|
1277
|
+
...defaultComponents,
|
|
1278
|
+
...components
|
|
1279
|
+
},
|
|
1280
|
+
remarkPlugins: [remarkGfm, [remarkMath, { singleDollarTextMath: false }]],
|
|
1281
|
+
rehypePlugins: [rehypeRaw],
|
|
1282
|
+
children: content
|
|
1283
|
+
})
|
|
1284
|
+
});
|
|
1285
|
+
};
|
|
1286
|
+
|
|
1287
|
+
//#endregion
|
|
1288
|
+
//#region src/components/chat/messages/AssistantMessage.tsx
|
|
1289
|
+
const AssistantMessage = (props) => {
|
|
1290
|
+
const { icons, labels } = useChatContext();
|
|
1291
|
+
const { message, isLoading, onRegenerate, onCopy, onThumbsUp, onThumbsDown, isCurrentMessage, feedback, markdownTagRenderers } = props;
|
|
1292
|
+
const [copied, setCopied] = useState(false);
|
|
1293
|
+
const handleCopy = () => {
|
|
1294
|
+
const content = message?.content || "";
|
|
1295
|
+
if (content && onCopy) {
|
|
1296
|
+
navigator.clipboard.writeText(content);
|
|
1297
|
+
setCopied(true);
|
|
1298
|
+
onCopy(content);
|
|
1299
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
1300
|
+
} else if (content) {
|
|
1301
|
+
navigator.clipboard.writeText(content);
|
|
1302
|
+
setCopied(true);
|
|
1303
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
const handleRegenerate = () => {
|
|
1307
|
+
if (onRegenerate) onRegenerate();
|
|
1308
|
+
};
|
|
1309
|
+
const handleThumbsUp = () => {
|
|
1310
|
+
if (onThumbsUp && message) onThumbsUp(message);
|
|
1311
|
+
};
|
|
1312
|
+
const handleThumbsDown = () => {
|
|
1313
|
+
if (onThumbsDown && message) onThumbsDown(message);
|
|
1314
|
+
};
|
|
1315
|
+
const LoadingIcon = () => /* @__PURE__ */ jsx("span", { children: icons.activityIcon });
|
|
1316
|
+
const content = message?.content || "";
|
|
1317
|
+
const subComponent = message?.generativeUI?.() ?? props.subComponent;
|
|
1318
|
+
const subComponentPosition = message?.generativeUIPosition ?? "after";
|
|
1319
|
+
const renderBefore = subComponent && subComponentPosition === "before";
|
|
1320
|
+
const renderAfter = subComponent && subComponentPosition !== "before";
|
|
1321
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1322
|
+
renderBefore ? /* @__PURE__ */ jsx("div", {
|
|
1323
|
+
style: { marginBottom: "0.5rem" },
|
|
1324
|
+
children: subComponent
|
|
1325
|
+
}) : null,
|
|
1326
|
+
content && /* @__PURE__ */ jsxs("div", {
|
|
1327
|
+
className: "copilotKitMessage copilotKitAssistantMessage",
|
|
1328
|
+
children: [content && /* @__PURE__ */ jsx(Markdown, {
|
|
1329
|
+
content,
|
|
1330
|
+
components: markdownTagRenderers
|
|
1331
|
+
}), content && !isLoading && /* @__PURE__ */ jsxs("div", {
|
|
1332
|
+
className: `copilotKitMessageControls ${isCurrentMessage ? "currentMessage" : ""}`,
|
|
1333
|
+
children: [
|
|
1334
|
+
/* @__PURE__ */ jsx("button", {
|
|
1335
|
+
className: "copilotKitMessageControlButton",
|
|
1336
|
+
onClick: handleRegenerate,
|
|
1337
|
+
"aria-label": labels.regenerateResponse,
|
|
1338
|
+
title: labels.regenerateResponse,
|
|
1339
|
+
children: icons.regenerateIcon
|
|
1340
|
+
}),
|
|
1341
|
+
/* @__PURE__ */ jsx("button", {
|
|
1342
|
+
className: "copilotKitMessageControlButton",
|
|
1343
|
+
onClick: handleCopy,
|
|
1344
|
+
"aria-label": labels.copyToClipboard,
|
|
1345
|
+
title: labels.copyToClipboard,
|
|
1346
|
+
children: copied ? /* @__PURE__ */ jsx("span", {
|
|
1347
|
+
style: {
|
|
1348
|
+
fontSize: "10px",
|
|
1349
|
+
fontWeight: "bold"
|
|
1350
|
+
},
|
|
1351
|
+
children: "✓"
|
|
1352
|
+
}) : icons.copyIcon
|
|
1353
|
+
}),
|
|
1354
|
+
onThumbsUp && /* @__PURE__ */ jsx("button", {
|
|
1355
|
+
className: `copilotKitMessageControlButton ${feedback === "thumbsUp" ? "active" : ""}`,
|
|
1356
|
+
onClick: handleThumbsUp,
|
|
1357
|
+
"aria-label": labels.thumbsUp,
|
|
1358
|
+
title: labels.thumbsUp,
|
|
1359
|
+
children: icons.thumbsUpIcon
|
|
1360
|
+
}),
|
|
1361
|
+
onThumbsDown && /* @__PURE__ */ jsx("button", {
|
|
1362
|
+
className: `copilotKitMessageControlButton ${feedback === "thumbsDown" ? "active" : ""}`,
|
|
1363
|
+
onClick: handleThumbsDown,
|
|
1364
|
+
"aria-label": labels.thumbsDown,
|
|
1365
|
+
title: labels.thumbsDown,
|
|
1366
|
+
children: icons.thumbsDownIcon
|
|
1367
|
+
})
|
|
1368
|
+
]
|
|
1369
|
+
})]
|
|
1370
|
+
}),
|
|
1371
|
+
renderAfter ? /* @__PURE__ */ jsx("div", {
|
|
1372
|
+
style: { marginBottom: "0.5rem" },
|
|
1373
|
+
children: subComponent
|
|
1374
|
+
}) : null,
|
|
1375
|
+
isLoading && /* @__PURE__ */ jsx(LoadingIcon, {})
|
|
1376
|
+
] });
|
|
1377
|
+
};
|
|
1378
|
+
|
|
1379
|
+
//#endregion
|
|
1380
|
+
//#region src/components/chat/messages/ImageRenderer.tsx
|
|
1381
|
+
/**
|
|
1382
|
+
* Default image rendering component that can be customized by users.
|
|
1383
|
+
* Uses CSS classes for styling so users can override styles.
|
|
1384
|
+
*/
|
|
1385
|
+
const ImageRenderer = ({ image, content, className = "" }) => {
|
|
1386
|
+
const [imageError, setImageError] = useState(false);
|
|
1387
|
+
const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
|
|
1388
|
+
const altText = content || "User uploaded image";
|
|
1389
|
+
const handleImageError = () => {
|
|
1390
|
+
setImageError(true);
|
|
1391
|
+
};
|
|
1392
|
+
if (imageError) return /* @__PURE__ */ jsxs("div", {
|
|
1393
|
+
className: `copilotKitImageRendering copilotKitImageRenderingError ${className}`,
|
|
1394
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
1395
|
+
className: "copilotKitImageRenderingErrorMessage",
|
|
1396
|
+
children: "Failed to load image"
|
|
1397
|
+
}), content && /* @__PURE__ */ jsx("div", {
|
|
1398
|
+
className: "copilotKitImageRenderingContent",
|
|
1399
|
+
children: content
|
|
1400
|
+
})]
|
|
1401
|
+
});
|
|
1402
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1403
|
+
className: `copilotKitImageRendering ${className}`,
|
|
1404
|
+
children: [/* @__PURE__ */ jsx("img", {
|
|
1405
|
+
src: imageSrc,
|
|
1406
|
+
alt: altText,
|
|
1407
|
+
className: "copilotKitImageRenderingImage",
|
|
1408
|
+
onError: handleImageError
|
|
1409
|
+
}), content && /* @__PURE__ */ jsx("div", {
|
|
1410
|
+
className: "copilotKitImageRenderingContent",
|
|
1411
|
+
children: content
|
|
1412
|
+
})]
|
|
1413
|
+
});
|
|
1414
|
+
};
|
|
1415
|
+
|
|
1416
|
+
//#endregion
|
|
1417
|
+
//#region src/components/chat/messages/RenderMessage.tsx
|
|
1418
|
+
function RenderMessage({ UserMessage: UserMessage$4 = UserMessage, AssistantMessage: AssistantMessage$3 = AssistantMessage, ImageRenderer: ImageRenderer$2 = ImageRenderer, ...props }) {
|
|
1419
|
+
const { message, messages, inProgress, index, isCurrentMessage, onRegenerate, onCopy, onThumbsUp, onThumbsDown, messageFeedback, markdownTagRenderers } = props;
|
|
1420
|
+
switch (message.role) {
|
|
1421
|
+
case "user": return /* @__PURE__ */ jsx(UserMessage$4, {
|
|
1422
|
+
rawData: message,
|
|
1423
|
+
"data-message-role": "user",
|
|
1424
|
+
message,
|
|
1425
|
+
ImageRenderer: ImageRenderer$2
|
|
1426
|
+
}, index);
|
|
1427
|
+
case "assistant": return /* @__PURE__ */ jsx(AssistantMessage$3, {
|
|
1428
|
+
"data-message-role": "assistant",
|
|
1429
|
+
subComponent: message.generativeUI?.(),
|
|
1430
|
+
rawData: message,
|
|
1431
|
+
message,
|
|
1432
|
+
messages,
|
|
1433
|
+
isLoading: inProgress && isCurrentMessage && !message.content,
|
|
1434
|
+
isGenerating: inProgress && isCurrentMessage && !!message.content,
|
|
1435
|
+
isCurrentMessage,
|
|
1436
|
+
onRegenerate: () => onRegenerate?.(message.id),
|
|
1437
|
+
onCopy,
|
|
1438
|
+
onThumbsUp,
|
|
1439
|
+
onThumbsDown,
|
|
1440
|
+
feedback: messageFeedback?.[message.id] || null,
|
|
1441
|
+
markdownTagRenderers,
|
|
1442
|
+
ImageRenderer: ImageRenderer$2
|
|
1443
|
+
}, index);
|
|
1444
|
+
default: return null;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
//#endregion
|
|
1449
|
+
//#region src/components/chat/messages/LegacyRenderMessage.tsx
|
|
1450
|
+
/**
|
|
1451
|
+
* Legacy message adapter component that maps old render props to new message types.
|
|
1452
|
+
* This component provides backwards compatibility for the deprecated render props.
|
|
1453
|
+
*/
|
|
1454
|
+
const LegacyRenderMessage = ({ message, messages, inProgress, index, isCurrentMessage, actionResult, AssistantMessage, UserMessage, ImageRenderer, onRegenerate, onCopy, onThumbsUp, onThumbsDown, markdownTagRenderers, legacyProps }) => {
|
|
1455
|
+
const { RenderTextMessage, RenderActionExecutionMessage, RenderAgentStateMessage, RenderResultMessage, RenderImageMessage } = legacyProps;
|
|
1456
|
+
const deprecatedMessage = aguiToGQL(message)[0] ?? void 0;
|
|
1457
|
+
if (deprecatedMessage.isTextMessage() && RenderTextMessage) return /* @__PURE__ */ jsx(RenderTextMessage, {
|
|
1458
|
+
message,
|
|
1459
|
+
messages,
|
|
1460
|
+
inProgress,
|
|
1461
|
+
index,
|
|
1462
|
+
isCurrentMessage,
|
|
1463
|
+
AssistantMessage,
|
|
1464
|
+
UserMessage,
|
|
1465
|
+
onRegenerate,
|
|
1466
|
+
onCopy,
|
|
1467
|
+
onThumbsUp,
|
|
1468
|
+
onThumbsDown,
|
|
1469
|
+
markdownTagRenderers
|
|
1470
|
+
});
|
|
1471
|
+
if (deprecatedMessage.isActionExecutionMessage() && RenderActionExecutionMessage) return /* @__PURE__ */ jsx(RenderActionExecutionMessage, {
|
|
1472
|
+
messages,
|
|
1473
|
+
message,
|
|
1474
|
+
inProgress,
|
|
1475
|
+
index,
|
|
1476
|
+
isCurrentMessage,
|
|
1477
|
+
actionResult,
|
|
1478
|
+
AssistantMessage,
|
|
1479
|
+
UserMessage
|
|
1480
|
+
});
|
|
1481
|
+
if (deprecatedMessage.isAgentStateMessage() && RenderAgentStateMessage) return /* @__PURE__ */ jsx(RenderAgentStateMessage, {
|
|
1482
|
+
messages,
|
|
1483
|
+
message,
|
|
1484
|
+
inProgress,
|
|
1485
|
+
index,
|
|
1486
|
+
isCurrentMessage,
|
|
1487
|
+
AssistantMessage,
|
|
1488
|
+
UserMessage
|
|
1489
|
+
});
|
|
1490
|
+
if (deprecatedMessage.isResultMessage() && RenderResultMessage) return /* @__PURE__ */ jsx(RenderResultMessage, {
|
|
1491
|
+
messages,
|
|
1492
|
+
message,
|
|
1493
|
+
inProgress,
|
|
1494
|
+
index,
|
|
1495
|
+
isCurrentMessage,
|
|
1496
|
+
AssistantMessage,
|
|
1497
|
+
UserMessage
|
|
1498
|
+
});
|
|
1499
|
+
if (deprecatedMessage.isImageMessage() && RenderImageMessage) return /* @__PURE__ */ jsx(RenderImageMessage, {
|
|
1500
|
+
messages,
|
|
1501
|
+
message,
|
|
1502
|
+
inProgress,
|
|
1503
|
+
index,
|
|
1504
|
+
isCurrentMessage,
|
|
1505
|
+
AssistantMessage,
|
|
1506
|
+
UserMessage
|
|
1507
|
+
});
|
|
1508
|
+
return /* @__PURE__ */ jsx(RenderMessage, {
|
|
1509
|
+
messages,
|
|
1510
|
+
message,
|
|
1511
|
+
inProgress,
|
|
1512
|
+
index,
|
|
1513
|
+
isCurrentMessage,
|
|
1514
|
+
AssistantMessage,
|
|
1515
|
+
UserMessage,
|
|
1516
|
+
ImageRenderer,
|
|
1517
|
+
onRegenerate,
|
|
1518
|
+
onCopy,
|
|
1519
|
+
onThumbsUp,
|
|
1520
|
+
onThumbsDown,
|
|
1521
|
+
markdownTagRenderers
|
|
1522
|
+
});
|
|
1523
|
+
};
|
|
1524
|
+
|
|
1525
|
+
//#endregion
|
|
1526
|
+
//#region src/components/chat/Messages.tsx
|
|
1527
|
+
const Messages = ({ inProgress, children, RenderMessage, AssistantMessage, UserMessage, ErrorMessage, ImageRenderer, onRegenerate, onCopy, onThumbsUp, onThumbsDown, messageFeedback, markdownTagRenderers, chatError, RenderTextMessage, RenderActionExecutionMessage, RenderAgentStateMessage, RenderResultMessage, RenderImageMessage }) => {
|
|
1528
|
+
const { labels, icons } = useChatContext();
|
|
1529
|
+
const { messages: visibleMessages, interrupt } = useCopilotChatInternal();
|
|
1530
|
+
const messages = [...useMemo(() => makeInitialMessages(labels.initial), [labels.initial]), ...visibleMessages];
|
|
1531
|
+
const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
|
|
1532
|
+
const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
|
|
1533
|
+
useEffect(() => {
|
|
1534
|
+
if (hasLegacyProps) console.warn("[CopilotKit] Legacy message render props (RenderTextMessage, RenderActionExecutionMessage, etc.) are deprecated. Please use the unified 'RenderMessage' prop instead. See migration guide: https://docs.copilotkit.ai/migration/render-message");
|
|
1535
|
+
}, [hasLegacyProps]);
|
|
1536
|
+
const legacyProps = useMemo(() => ({
|
|
1537
|
+
RenderTextMessage,
|
|
1538
|
+
RenderActionExecutionMessage,
|
|
1539
|
+
RenderAgentStateMessage,
|
|
1540
|
+
RenderResultMessage,
|
|
1541
|
+
RenderImageMessage
|
|
1542
|
+
}), [
|
|
1543
|
+
RenderTextMessage,
|
|
1544
|
+
RenderActionExecutionMessage,
|
|
1545
|
+
RenderAgentStateMessage,
|
|
1546
|
+
RenderResultMessage,
|
|
1547
|
+
RenderImageMessage
|
|
1548
|
+
]);
|
|
1549
|
+
const MessageRenderer = hasLegacyProps ? (props) => /* @__PURE__ */ jsx(LegacyRenderMessage, {
|
|
1550
|
+
...props,
|
|
1551
|
+
legacyProps
|
|
1552
|
+
}) : RenderMessage;
|
|
1553
|
+
const LoadingIcon = () => /* @__PURE__ */ jsx("span", { children: icons.activityIcon });
|
|
1554
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1555
|
+
className: "copilotKitMessages",
|
|
1556
|
+
ref: messagesContainerRef,
|
|
1557
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1558
|
+
className: "copilotKitMessagesContainer",
|
|
1559
|
+
children: [
|
|
1560
|
+
messages.map((message, index) => {
|
|
1561
|
+
return /* @__PURE__ */ jsx(MessageRenderer, {
|
|
1562
|
+
message,
|
|
1563
|
+
messages,
|
|
1564
|
+
inProgress,
|
|
1565
|
+
index,
|
|
1566
|
+
isCurrentMessage: index === messages.length - 1,
|
|
1567
|
+
AssistantMessage,
|
|
1568
|
+
UserMessage,
|
|
1569
|
+
ImageRenderer,
|
|
1570
|
+
onRegenerate,
|
|
1571
|
+
onCopy,
|
|
1572
|
+
onThumbsUp,
|
|
1573
|
+
onThumbsDown,
|
|
1574
|
+
messageFeedback,
|
|
1575
|
+
markdownTagRenderers
|
|
1576
|
+
}, index);
|
|
1577
|
+
}),
|
|
1578
|
+
messages[messages.length - 1]?.role === "user" && inProgress && /* @__PURE__ */ jsx(LoadingIcon, {}),
|
|
1579
|
+
interrupt,
|
|
1580
|
+
chatError && ErrorMessage && /* @__PURE__ */ jsx(ErrorMessage, {
|
|
1581
|
+
error: chatError,
|
|
1582
|
+
isCurrentMessage: true
|
|
1583
|
+
})
|
|
1584
|
+
]
|
|
1585
|
+
}), /* @__PURE__ */ jsx("footer", {
|
|
1586
|
+
className: "copilotKitMessagesFooter",
|
|
1587
|
+
ref: messagesEndRef,
|
|
1588
|
+
children
|
|
1589
|
+
})]
|
|
1590
|
+
});
|
|
1591
|
+
};
|
|
1592
|
+
function makeInitialMessages(initial) {
|
|
1593
|
+
if (!initial) return [];
|
|
1594
|
+
if (Array.isArray(initial)) return initial.map((message) => {
|
|
1595
|
+
return {
|
|
1596
|
+
id: message,
|
|
1597
|
+
role: "assistant",
|
|
1598
|
+
content: message
|
|
1599
|
+
};
|
|
1600
|
+
});
|
|
1601
|
+
return [{
|
|
1602
|
+
id: initial,
|
|
1603
|
+
role: "assistant",
|
|
1604
|
+
content: initial
|
|
1605
|
+
}];
|
|
1606
|
+
}
|
|
1607
|
+
function useScrollToBottom(messages) {
|
|
1608
|
+
const messagesEndRef = useRef(null);
|
|
1609
|
+
const messagesContainerRef = useRef(null);
|
|
1610
|
+
const isProgrammaticScrollRef = useRef(false);
|
|
1611
|
+
const isUserScrollUpRef = useRef(false);
|
|
1612
|
+
const scrollToBottom = () => {
|
|
1613
|
+
if (messagesContainerRef.current && messagesEndRef.current) {
|
|
1614
|
+
isProgrammaticScrollRef.current = true;
|
|
1615
|
+
messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
const handleScroll = () => {
|
|
1619
|
+
if (isProgrammaticScrollRef.current) {
|
|
1620
|
+
isProgrammaticScrollRef.current = false;
|
|
1621
|
+
return;
|
|
1622
|
+
}
|
|
1623
|
+
if (messagesContainerRef.current) {
|
|
1624
|
+
const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
|
|
1625
|
+
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
1626
|
+
}
|
|
1627
|
+
};
|
|
1628
|
+
useEffect(() => {
|
|
1629
|
+
const container = messagesContainerRef.current;
|
|
1630
|
+
if (container) container.addEventListener("scroll", handleScroll);
|
|
1631
|
+
return () => {
|
|
1632
|
+
if (container) container.removeEventListener("scroll", handleScroll);
|
|
1633
|
+
};
|
|
1634
|
+
}, []);
|
|
1635
|
+
useEffect(() => {
|
|
1636
|
+
const container = messagesContainerRef.current;
|
|
1637
|
+
if (!container) return;
|
|
1638
|
+
const mutationObserver = new MutationObserver(() => {
|
|
1639
|
+
if (!isUserScrollUpRef.current) scrollToBottom();
|
|
1640
|
+
});
|
|
1641
|
+
mutationObserver.observe(container, {
|
|
1642
|
+
childList: true,
|
|
1643
|
+
subtree: true,
|
|
1644
|
+
characterData: true
|
|
1645
|
+
});
|
|
1646
|
+
return () => {
|
|
1647
|
+
mutationObserver.disconnect();
|
|
1648
|
+
};
|
|
1649
|
+
}, []);
|
|
1650
|
+
useEffect(() => {
|
|
1651
|
+
isUserScrollUpRef.current = false;
|
|
1652
|
+
scrollToBottom();
|
|
1653
|
+
}, [messages.filter((m) => m.role === "user").length]);
|
|
1654
|
+
return {
|
|
1655
|
+
messagesEndRef,
|
|
1656
|
+
messagesContainerRef
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
//#endregion
|
|
1661
|
+
//#region src/components/chat/Textarea.tsx
|
|
1662
|
+
const AutoResizingTextarea = forwardRef(({ maxRows = 1, placeholder, value, onChange, onKeyDown, onCompositionStart, onCompositionEnd, autoFocus }, ref) => {
|
|
1663
|
+
const internalTextareaRef = useRef(null);
|
|
1664
|
+
const [maxHeight, setMaxHeight] = useState(0);
|
|
1665
|
+
useImperativeHandle(ref, () => internalTextareaRef.current);
|
|
1666
|
+
useEffect(() => {
|
|
1667
|
+
const calculateMaxHeight = () => {
|
|
1668
|
+
const textarea = internalTextareaRef.current;
|
|
1669
|
+
if (textarea) {
|
|
1670
|
+
textarea.style.height = "auto";
|
|
1671
|
+
const singleRowHeight = textarea.scrollHeight;
|
|
1672
|
+
setMaxHeight(singleRowHeight * maxRows);
|
|
1673
|
+
if (autoFocus) textarea.focus();
|
|
1674
|
+
}
|
|
1675
|
+
};
|
|
1676
|
+
calculateMaxHeight();
|
|
1677
|
+
}, [maxRows]);
|
|
1678
|
+
useEffect(() => {
|
|
1679
|
+
const textarea = internalTextareaRef.current;
|
|
1680
|
+
if (textarea) {
|
|
1681
|
+
textarea.style.height = "auto";
|
|
1682
|
+
textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
|
|
1683
|
+
}
|
|
1684
|
+
}, [value, maxHeight]);
|
|
1685
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
1686
|
+
ref: internalTextareaRef,
|
|
1687
|
+
value,
|
|
1688
|
+
onChange,
|
|
1689
|
+
onKeyDown,
|
|
1690
|
+
onCompositionStart,
|
|
1691
|
+
onCompositionEnd,
|
|
1692
|
+
placeholder,
|
|
1693
|
+
style: {
|
|
1694
|
+
overflow: "auto",
|
|
1695
|
+
resize: "none",
|
|
1696
|
+
maxHeight: `${maxHeight}px`
|
|
1697
|
+
},
|
|
1698
|
+
rows: 1
|
|
1699
|
+
});
|
|
1700
|
+
});
|
|
1701
|
+
|
|
1702
|
+
//#endregion
|
|
1703
|
+
//#region src/hooks/use-push-to-talk.tsx
|
|
1704
|
+
const startRecording = async (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => {
|
|
1705
|
+
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
1706
|
+
mediaStreamRef.current = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1707
|
+
audioContextRef.current = new window.AudioContext();
|
|
1708
|
+
await audioContextRef.current.resume();
|
|
1709
|
+
}
|
|
1710
|
+
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
1711
|
+
mediaRecorderRef.current.start(1e3);
|
|
1712
|
+
mediaRecorderRef.current.ondataavailable = (event) => {
|
|
1713
|
+
recordedChunks.push(event.data);
|
|
1714
|
+
};
|
|
1715
|
+
mediaRecorderRef.current.onstop = onStop;
|
|
1716
|
+
};
|
|
1717
|
+
const stopRecording = (mediaRecorderRef) => {
|
|
1718
|
+
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") mediaRecorderRef.current.stop();
|
|
1719
|
+
};
|
|
1720
|
+
const transcribeAudio = async (recordedChunks, transcribeAudioUrl) => {
|
|
1721
|
+
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
1722
|
+
const formData = new FormData();
|
|
1723
|
+
formData.append("file", completeBlob, "recording.mp4");
|
|
1724
|
+
const response = await fetch(transcribeAudioUrl, {
|
|
1725
|
+
method: "POST",
|
|
1726
|
+
body: formData
|
|
1727
|
+
});
|
|
1728
|
+
if (!response.ok) throw new Error(`Error: ${response.statusText}`);
|
|
1729
|
+
return (await response.json()).text;
|
|
1730
|
+
};
|
|
1731
|
+
const playAudioResponse = (text, textToSpeechUrl, audioContext) => {
|
|
1732
|
+
const url = `${textToSpeechUrl}?text=${encodeURIComponent(text)}`;
|
|
1733
|
+
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
1734
|
+
const source = audioContext.createBufferSource();
|
|
1735
|
+
source.buffer = audioBuffer;
|
|
1736
|
+
source.connect(audioContext.destination);
|
|
1737
|
+
source.start(0);
|
|
1738
|
+
}).catch((error) => {
|
|
1739
|
+
console.error("Error with decoding audio data", error);
|
|
1740
|
+
});
|
|
1741
|
+
};
|
|
1742
|
+
const usePushToTalk = ({ sendFunction, inProgress }) => {
|
|
1743
|
+
const [pushToTalkState, setPushToTalkState] = useState("idle");
|
|
1744
|
+
const mediaStreamRef = useRef(null);
|
|
1745
|
+
const audioContextRef = useRef(null);
|
|
1746
|
+
const mediaRecorderRef = useRef(null);
|
|
1747
|
+
const recordedChunks = useRef([]);
|
|
1748
|
+
const generalContext = useCopilotContext();
|
|
1749
|
+
const messagesContext = useCopilotMessagesContext();
|
|
1750
|
+
const context = {
|
|
1751
|
+
...generalContext,
|
|
1752
|
+
...messagesContext
|
|
1753
|
+
};
|
|
1754
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = useState(null);
|
|
1755
|
+
useEffect(() => {
|
|
1756
|
+
if (pushToTalkState === "recording") startRecording(mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks.current, () => {
|
|
1757
|
+
setPushToTalkState("transcribing");
|
|
1758
|
+
});
|
|
1759
|
+
else {
|
|
1760
|
+
stopRecording(mediaRecorderRef);
|
|
1761
|
+
if (pushToTalkState === "transcribing") transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(async (transcription) => {
|
|
1762
|
+
recordedChunks.current = [];
|
|
1763
|
+
setPushToTalkState("idle");
|
|
1764
|
+
setStartReadingFromMessageId((await sendFunction(transcription)).id);
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
return () => {
|
|
1768
|
+
stopRecording(mediaRecorderRef);
|
|
1769
|
+
};
|
|
1770
|
+
}, [pushToTalkState]);
|
|
1771
|
+
useEffect(() => {
|
|
1772
|
+
if (inProgress === false && startReadingFromMessageId) {
|
|
1773
|
+
const lastMessageIndex = context.messages.findIndex((message) => message.id === startReadingFromMessageId);
|
|
1774
|
+
playAudioResponse(gqlToAGUI(context.messages).slice(lastMessageIndex + 1).filter((message) => message.role === "assistant").map((message) => message.content).join("\n"), context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
1775
|
+
setStartReadingFromMessageId(null);
|
|
1776
|
+
}
|
|
1777
|
+
}, [startReadingFromMessageId, inProgress]);
|
|
1778
|
+
return {
|
|
1779
|
+
pushToTalkState,
|
|
1780
|
+
setPushToTalkState
|
|
1781
|
+
};
|
|
1782
|
+
};
|
|
1783
|
+
|
|
1784
|
+
//#endregion
|
|
1785
|
+
//#region src/hooks/use-dark-mode.ts
|
|
1786
|
+
const useDarkMode = () => {
|
|
1787
|
+
if (typeof window === "undefined") return false;
|
|
1788
|
+
return document.documentElement.classList.contains("dark") || document.body.classList.contains("dark") || document.documentElement.getAttribute("data-theme") === "dark" || document.body.getAttribute("data-theme") === "dark" || window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
1789
|
+
};
|
|
1790
|
+
|
|
1791
|
+
//#endregion
|
|
1792
|
+
//#region src/components/chat/PoweredByTag.tsx
|
|
1793
|
+
function PoweredByTag({ showPoweredBy = true }) {
|
|
1794
|
+
const [mounted, setMounted] = useState(false);
|
|
1795
|
+
const isDark = useDarkMode();
|
|
1796
|
+
useEffect(() => {
|
|
1797
|
+
setMounted(true);
|
|
1798
|
+
}, []);
|
|
1799
|
+
if (!showPoweredBy) return null;
|
|
1800
|
+
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("p", {
|
|
1801
|
+
className: "poweredBy",
|
|
1802
|
+
style: {
|
|
1803
|
+
visibility: "visible",
|
|
1804
|
+
display: "block",
|
|
1805
|
+
position: "static",
|
|
1806
|
+
textAlign: "center",
|
|
1807
|
+
fontSize: "12px",
|
|
1808
|
+
padding: "3px 0",
|
|
1809
|
+
color: mounted && isDark ? "rgb(69, 69, 69)" : "rgb(214, 214, 214)"
|
|
1810
|
+
},
|
|
1811
|
+
children: "Powered by CopilotKit"
|
|
1812
|
+
}) });
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
//#endregion
|
|
1816
|
+
//#region src/components/chat/Input.tsx
|
|
1817
|
+
const MAX_NEWLINES = 6;
|
|
1818
|
+
const Input = ({ inProgress, onSend, chatReady = false, onStop, onUpload, hideStopButton = false }) => {
|
|
1819
|
+
const context = useChatContext();
|
|
1820
|
+
const copilotContext = useCopilotContext();
|
|
1821
|
+
const showPoweredBy = !copilotContext.copilotApiConfig?.publicApiKey;
|
|
1822
|
+
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
1823
|
+
const textareaRef = useRef(null);
|
|
1824
|
+
const [isComposing, setIsComposing] = useState(false);
|
|
1825
|
+
const handleDivClick = (event) => {
|
|
1826
|
+
const target = event.target;
|
|
1827
|
+
if (target.closest("button")) return;
|
|
1828
|
+
if (target.tagName === "TEXTAREA") return;
|
|
1829
|
+
textareaRef.current?.focus();
|
|
1830
|
+
};
|
|
1831
|
+
const [text, setText] = useState("");
|
|
1832
|
+
const send = () => {
|
|
1833
|
+
if (inProgress) return;
|
|
1834
|
+
onSend(text);
|
|
1835
|
+
setText("");
|
|
1836
|
+
textareaRef.current?.focus();
|
|
1837
|
+
};
|
|
1838
|
+
const { pushToTalkState, setPushToTalkState } = usePushToTalk({
|
|
1839
|
+
sendFunction: onSend,
|
|
1840
|
+
inProgress
|
|
1841
|
+
});
|
|
1842
|
+
const isInProgress = inProgress || pushToTalkState === "transcribing";
|
|
1843
|
+
const { buttonIcon, buttonAlt } = useMemo(() => {
|
|
1844
|
+
if (!chatReady) return {
|
|
1845
|
+
buttonIcon: context.icons.spinnerIcon,
|
|
1846
|
+
buttonAlt: "Loading"
|
|
1847
|
+
};
|
|
1848
|
+
return isInProgress && !hideStopButton && chatReady ? {
|
|
1849
|
+
buttonIcon: context.icons.stopIcon,
|
|
1850
|
+
buttonAlt: "Stop"
|
|
1851
|
+
} : {
|
|
1852
|
+
buttonIcon: context.icons.sendIcon,
|
|
1853
|
+
buttonAlt: "Send"
|
|
1854
|
+
};
|
|
1855
|
+
}, [
|
|
1856
|
+
isInProgress,
|
|
1857
|
+
chatReady,
|
|
1858
|
+
hideStopButton,
|
|
1859
|
+
context.icons.stopIcon,
|
|
1860
|
+
context.icons.sendIcon
|
|
1861
|
+
]);
|
|
1862
|
+
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
1863
|
+
const { interrupt } = useCopilotChatInternal();
|
|
1864
|
+
const canSend = useMemo(() => {
|
|
1865
|
+
return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
|
|
1866
|
+
}, [
|
|
1867
|
+
interrupt,
|
|
1868
|
+
isInProgress,
|
|
1869
|
+
text,
|
|
1870
|
+
pushToTalkState
|
|
1871
|
+
]);
|
|
1872
|
+
const canStop = useMemo(() => {
|
|
1873
|
+
return isInProgress && !hideStopButton;
|
|
1874
|
+
}, [isInProgress, hideStopButton]);
|
|
1875
|
+
const sendDisabled = !canSend && !canStop;
|
|
1876
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1877
|
+
className: `copilotKitInputContainer ${showPoweredBy ? "poweredByContainer" : ""}`,
|
|
1878
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1879
|
+
className: "copilotKitInput",
|
|
1880
|
+
onClick: handleDivClick,
|
|
1881
|
+
children: [/* @__PURE__ */ jsx(AutoResizingTextarea, {
|
|
1882
|
+
ref: textareaRef,
|
|
1883
|
+
placeholder: context.labels.placeholder,
|
|
1884
|
+
autoFocus: false,
|
|
1885
|
+
maxRows: MAX_NEWLINES,
|
|
1886
|
+
value: text,
|
|
1887
|
+
onChange: (event) => setText(event.target.value),
|
|
1888
|
+
onCompositionStart: () => setIsComposing(true),
|
|
1889
|
+
onCompositionEnd: () => setIsComposing(false),
|
|
1890
|
+
onKeyDown: (event) => {
|
|
1891
|
+
if (event.key === "Enter" && !event.shiftKey && !isComposing) {
|
|
1892
|
+
event.preventDefault();
|
|
1893
|
+
if (canSend) send();
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1897
|
+
className: "copilotKitInputControls",
|
|
1898
|
+
children: [
|
|
1899
|
+
onUpload && /* @__PURE__ */ jsx("button", {
|
|
1900
|
+
onClick: onUpload,
|
|
1901
|
+
className: "copilotKitInputControlButton",
|
|
1902
|
+
children: context.icons.uploadIcon
|
|
1903
|
+
}),
|
|
1904
|
+
/* @__PURE__ */ jsx("div", { style: { flexGrow: 1 } }),
|
|
1905
|
+
showPushToTalk && /* @__PURE__ */ jsx("button", {
|
|
1906
|
+
onClick: () => setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing"),
|
|
1907
|
+
className: pushToTalkState === "recording" ? "copilotKitInputControlButton copilotKitPushToTalkRecording" : "copilotKitInputControlButton",
|
|
1908
|
+
children: context.icons.pushToTalkIcon
|
|
1909
|
+
}),
|
|
1910
|
+
/* @__PURE__ */ jsx("button", {
|
|
1911
|
+
disabled: sendDisabled,
|
|
1912
|
+
onClick: isInProgress && !hideStopButton ? onStop : send,
|
|
1913
|
+
"data-copilotkit-in-progress": inProgress,
|
|
1914
|
+
"data-test-id": inProgress ? "copilot-chat-request-in-progress" : "copilot-chat-ready",
|
|
1915
|
+
className: "copilotKitInputControlButton",
|
|
1916
|
+
"aria-label": buttonAlt,
|
|
1917
|
+
children: buttonIcon
|
|
1918
|
+
})
|
|
1919
|
+
]
|
|
1920
|
+
})]
|
|
1921
|
+
}), /* @__PURE__ */ jsx(PoweredByTag, { showPoweredBy })]
|
|
1922
|
+
});
|
|
1923
|
+
};
|
|
1924
|
+
|
|
1925
|
+
//#endregion
|
|
1926
|
+
//#region src/components/chat/ImageUploadQueue.tsx
|
|
1927
|
+
const ImageUploadQueue = ({ images, onRemoveImage, className = "" }) => {
|
|
1928
|
+
if (images.length === 0) return null;
|
|
1929
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1930
|
+
className: `copilotKitImageUploadQueue ${className}`,
|
|
1931
|
+
style: {
|
|
1932
|
+
display: "flex",
|
|
1933
|
+
flexWrap: "wrap",
|
|
1934
|
+
gap: "8px",
|
|
1935
|
+
margin: "8px",
|
|
1936
|
+
padding: "8px"
|
|
1937
|
+
},
|
|
1938
|
+
children: images.map((image, index) => /* @__PURE__ */ jsxs("div", {
|
|
1939
|
+
className: "copilotKitImageUploadQueueItem",
|
|
1940
|
+
style: {
|
|
1941
|
+
position: "relative",
|
|
1942
|
+
display: "inline-block",
|
|
1943
|
+
width: "60px",
|
|
1944
|
+
height: "60px",
|
|
1945
|
+
borderRadius: "4px",
|
|
1946
|
+
overflow: "hidden"
|
|
1947
|
+
},
|
|
1948
|
+
children: [/* @__PURE__ */ jsx("img", {
|
|
1949
|
+
src: `data:${image.contentType};base64,${image.bytes}`,
|
|
1950
|
+
alt: `Selected image ${index + 1}`,
|
|
1951
|
+
style: {
|
|
1952
|
+
width: "100%",
|
|
1953
|
+
height: "100%",
|
|
1954
|
+
objectFit: "cover"
|
|
1955
|
+
}
|
|
1956
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
1957
|
+
onClick: () => onRemoveImage(index),
|
|
1958
|
+
className: "copilotKitImageUploadQueueRemoveButton",
|
|
1959
|
+
style: {
|
|
1960
|
+
position: "absolute",
|
|
1961
|
+
top: "2px",
|
|
1962
|
+
right: "2px",
|
|
1963
|
+
background: "rgba(0,0,0,0.6)",
|
|
1964
|
+
color: "white",
|
|
1965
|
+
border: "none",
|
|
1966
|
+
borderRadius: "50%",
|
|
1967
|
+
width: "18px",
|
|
1968
|
+
height: "18px",
|
|
1969
|
+
display: "flex",
|
|
1970
|
+
alignItems: "center",
|
|
1971
|
+
justifyContent: "center",
|
|
1972
|
+
cursor: "pointer",
|
|
1973
|
+
fontSize: "10px",
|
|
1974
|
+
padding: 0
|
|
1975
|
+
},
|
|
1976
|
+
children: "✕"
|
|
1977
|
+
})]
|
|
1978
|
+
}, index))
|
|
1979
|
+
});
|
|
1980
|
+
};
|
|
1981
|
+
|
|
1982
|
+
//#endregion
|
|
1983
|
+
//#region src/components/chat/Suggestion.tsx
|
|
1984
|
+
function Suggestion({ title, onClick, partial, className }) {
|
|
1985
|
+
const { isLoading } = useCopilotChatInternal();
|
|
1986
|
+
if (!title) return null;
|
|
1987
|
+
return /* @__PURE__ */ jsx("button", {
|
|
1988
|
+
disabled: partial || isLoading,
|
|
1989
|
+
onClick: (e) => {
|
|
1990
|
+
e.preventDefault();
|
|
1991
|
+
onClick();
|
|
1992
|
+
},
|
|
1993
|
+
className: `suggestion ${className ?? ""} ${partial ? "loading" : ""}`,
|
|
1994
|
+
"data-test-id": "suggestion",
|
|
1995
|
+
type: "button",
|
|
1996
|
+
children: partial ? SmallSpinnerIcon : /* @__PURE__ */ jsx("span", { children: title })
|
|
1997
|
+
});
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
//#endregion
|
|
2001
|
+
//#region src/components/chat/Suggestions.tsx
|
|
2002
|
+
function Suggestions({ suggestions, onSuggestionClick, isLoading }) {
|
|
2003
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2004
|
+
className: "suggestions",
|
|
2005
|
+
children: suggestions.map((suggestion, index) => /* @__PURE__ */ jsx(Suggestion, {
|
|
2006
|
+
title: suggestion.title,
|
|
2007
|
+
message: suggestion.message,
|
|
2008
|
+
partial: suggestion.isLoading ?? suggestion.partial ?? isLoading,
|
|
2009
|
+
className: suggestion.className,
|
|
2010
|
+
onClick: () => onSuggestionClick(suggestion.message)
|
|
2011
|
+
}, index))
|
|
2012
|
+
});
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
//#endregion
|
|
2016
|
+
//#region src/components/chat/Chat.tsx
|
|
2017
|
+
/**
|
|
2018
|
+
* <br/>
|
|
2019
|
+
* <img src="https://cdn.copilotkit.ai/docs/copilotkit/images/CopilotChat.gif" width="500" />
|
|
2020
|
+
*
|
|
2021
|
+
* A chatbot panel component for the CopilotKit framework. The component allows for a high degree
|
|
2022
|
+
* of customization through various props and custom CSS.
|
|
2023
|
+
*
|
|
2024
|
+
* ## Install Dependencies
|
|
2025
|
+
*
|
|
2026
|
+
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
2027
|
+
*
|
|
2028
|
+
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
2029
|
+
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
2030
|
+
* ```
|
|
2031
|
+
*
|
|
2032
|
+
* ## Usage
|
|
2033
|
+
*
|
|
2034
|
+
* ```tsx
|
|
2035
|
+
* import { CopilotChat } from "@copilotkit/react-ui";
|
|
2036
|
+
* import "@copilotkit/react-ui/styles.css";
|
|
2037
|
+
*
|
|
2038
|
+
* <CopilotChat
|
|
2039
|
+
* labels={{
|
|
2040
|
+
* title: "Your Assistant",
|
|
2041
|
+
* initial: "Hi! 👋 How can I assist you today?",
|
|
2042
|
+
* }}
|
|
2043
|
+
* />
|
|
2044
|
+
* ```
|
|
2045
|
+
*
|
|
2046
|
+
* ### With Observability Hooks
|
|
2047
|
+
*
|
|
2048
|
+
* To monitor user interactions, provide the `observabilityHooks` prop.
|
|
2049
|
+
* **Note:** This requires a `publicApiKey` in the `<CopilotKit>` provider.
|
|
2050
|
+
*
|
|
2051
|
+
* ```tsx
|
|
2052
|
+
* <CopilotKit publicApiKey="YOUR_PUBLIC_API_KEY">
|
|
2053
|
+
* <CopilotChat
|
|
2054
|
+
* observabilityHooks={{
|
|
2055
|
+
* onMessageSent: (message) => {
|
|
2056
|
+
* console.log("Message sent:", message);
|
|
2057
|
+
* },
|
|
2058
|
+
* }}
|
|
2059
|
+
* />
|
|
2060
|
+
* </CopilotKit>
|
|
2061
|
+
* ```
|
|
2062
|
+
*
|
|
2063
|
+
* ### Look & Feel
|
|
2064
|
+
*
|
|
2065
|
+
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
2066
|
+
* ```tsx title="YourRootComponent.tsx"
|
|
2067
|
+
* ...
|
|
2068
|
+
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
2069
|
+
*
|
|
2070
|
+
* export function YourRootComponent() {
|
|
2071
|
+
* return (
|
|
2072
|
+
* <CopilotKit>
|
|
2073
|
+
* ...
|
|
2074
|
+
* </CopilotKit>
|
|
2075
|
+
* );
|
|
2076
|
+
* }
|
|
2077
|
+
* ```
|
|
2078
|
+
* For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
|
|
2079
|
+
*/
|
|
2080
|
+
function CopilotChat({ instructions, suggestions = "auto", onSubmitMessage, makeSystemMessage, disableSystemMessage, onInProgress, onStopGeneration, onReloadMessages, onRegenerate, onCopy, onThumbsUp, onThumbsDown, markdownTagRenderers, Messages: Messages$2 = Messages, RenderMessage: RenderMessage$1 = RenderMessage, RenderSuggestionsList = Suggestions, Input: Input$2 = Input, className, icons, labels, AssistantMessage: AssistantMessage$2 = AssistantMessage, UserMessage: UserMessage$3 = UserMessage, ImageRenderer: ImageRenderer$1 = ImageRenderer, ErrorMessage, imageUploadsEnabled, inputFileAccept = "image/*", hideStopButton, observabilityHooks, renderError, onError, RenderTextMessage, RenderActionExecutionMessage, RenderAgentStateMessage, RenderResultMessage, RenderImageMessage }) {
|
|
2081
|
+
const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError, setInternalErrorHandler, removeInternalErrorHandler } = useCopilotContext();
|
|
2082
|
+
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
2083
|
+
const [selectedImages, setSelectedImages] = useState([]);
|
|
2084
|
+
const [chatError, setChatError] = useState(null);
|
|
2085
|
+
const [messageFeedback, setMessageFeedback] = useState({});
|
|
2086
|
+
const fileInputRef = useRef(null);
|
|
2087
|
+
const triggerObservabilityHook = useCallback((hookName, ...args) => {
|
|
2088
|
+
if (publicApiKey && observabilityHooks?.[hookName]) observabilityHooks[hookName](...args);
|
|
2089
|
+
if (observabilityHooks?.[hookName] && !publicApiKey) {
|
|
2090
|
+
setBannerError(new CopilotKitError({
|
|
2091
|
+
message: "observabilityHooks requires a publicApiKey to function.",
|
|
2092
|
+
code: CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
2093
|
+
severity: Severity.CRITICAL,
|
|
2094
|
+
visibility: ErrorVisibility.BANNER
|
|
2095
|
+
}));
|
|
2096
|
+
styledConsole.publicApiKeyRequired("observabilityHooks");
|
|
2097
|
+
}
|
|
2098
|
+
}, [
|
|
2099
|
+
publicApiKey,
|
|
2100
|
+
observabilityHooks,
|
|
2101
|
+
setBannerError
|
|
2102
|
+
]);
|
|
2103
|
+
const triggerChatError = useCallback((error, operation, originalError) => {
|
|
2104
|
+
setChatError({
|
|
2105
|
+
message: error?.message || error?.toString() || "An error occurred",
|
|
2106
|
+
operation,
|
|
2107
|
+
timestamp: Date.now()
|
|
2108
|
+
});
|
|
2109
|
+
const errorEvent = {
|
|
2110
|
+
type: "error",
|
|
2111
|
+
timestamp: Date.now(),
|
|
2112
|
+
context: {
|
|
2113
|
+
source: "ui",
|
|
2114
|
+
request: {
|
|
2115
|
+
operation,
|
|
2116
|
+
url: chatApiEndpoint,
|
|
2117
|
+
startTime: Date.now()
|
|
2118
|
+
},
|
|
2119
|
+
technical: {
|
|
2120
|
+
environment: "browser",
|
|
2121
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
2122
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
2123
|
+
}
|
|
2124
|
+
},
|
|
2125
|
+
error
|
|
2126
|
+
};
|
|
2127
|
+
if (onError) onError(errorEvent);
|
|
2128
|
+
if (publicApiKey && observabilityHooks?.onError) observabilityHooks.onError(errorEvent);
|
|
2129
|
+
if (observabilityHooks?.onError && !publicApiKey) {
|
|
2130
|
+
setBannerError(new CopilotKitError({
|
|
2131
|
+
message: "observabilityHooks.onError requires a publicApiKey to function.",
|
|
2132
|
+
code: CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
2133
|
+
severity: Severity.CRITICAL,
|
|
2134
|
+
visibility: ErrorVisibility.BANNER
|
|
2135
|
+
}));
|
|
2136
|
+
styledConsole.publicApiKeyRequired("observabilityHooks.onError");
|
|
2137
|
+
}
|
|
2138
|
+
}, [
|
|
2139
|
+
publicApiKey,
|
|
2140
|
+
chatApiEndpoint,
|
|
2141
|
+
observabilityHooks,
|
|
2142
|
+
setBannerError
|
|
2143
|
+
]);
|
|
2144
|
+
useEffect(() => {
|
|
2145
|
+
const id = "chat-component";
|
|
2146
|
+
setInternalErrorHandler({ [id]: (error) => {
|
|
2147
|
+
if (!error) return;
|
|
2148
|
+
triggerChatError(error.error, "sendMessage");
|
|
2149
|
+
} });
|
|
2150
|
+
return () => {
|
|
2151
|
+
removeInternalErrorHandler?.(id);
|
|
2152
|
+
};
|
|
2153
|
+
}, [
|
|
2154
|
+
triggerChatError,
|
|
2155
|
+
setInternalErrorHandler,
|
|
2156
|
+
removeInternalErrorHandler
|
|
2157
|
+
]);
|
|
2158
|
+
useEffect(() => {
|
|
2159
|
+
if (!imageUploadsEnabled) return;
|
|
2160
|
+
const handlePaste = async (e) => {
|
|
2161
|
+
if (!e.target.parentElement?.classList.contains("copilotKitInput")) return;
|
|
2162
|
+
const imageItems = Array.from(e.clipboardData?.items || []).filter((item) => item.type.startsWith("image/"));
|
|
2163
|
+
if (imageItems.length === 0) return;
|
|
2164
|
+
e.preventDefault();
|
|
2165
|
+
const imagePromises = imageItems.map((item) => {
|
|
2166
|
+
const file = item.getAsFile();
|
|
2167
|
+
if (!file) return Promise.resolve(null);
|
|
2168
|
+
return new Promise((resolve, reject) => {
|
|
2169
|
+
const reader = new FileReader();
|
|
2170
|
+
reader.onload = (e) => {
|
|
2171
|
+
const base64String = (e.target?.result)?.split(",")[1];
|
|
2172
|
+
if (base64String) resolve({
|
|
2173
|
+
contentType: file.type,
|
|
2174
|
+
bytes: base64String
|
|
2175
|
+
});
|
|
2176
|
+
else resolve(null);
|
|
2177
|
+
};
|
|
2178
|
+
reader.onerror = reject;
|
|
2179
|
+
reader.readAsDataURL(file);
|
|
2180
|
+
});
|
|
2181
|
+
});
|
|
2182
|
+
try {
|
|
2183
|
+
const loadedImages = (await Promise.all(imagePromises)).filter((img) => img !== null);
|
|
2184
|
+
setSelectedImages((prev) => [...prev, ...loadedImages]);
|
|
2185
|
+
} catch (error) {
|
|
2186
|
+
triggerChatError(error, "processClipboardImages", error);
|
|
2187
|
+
console.error("Error processing pasted images:", error);
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
document.addEventListener("paste", handlePaste);
|
|
2191
|
+
return () => document.removeEventListener("paste", handlePaste);
|
|
2192
|
+
}, [imageUploadsEnabled, triggerChatError]);
|
|
2193
|
+
useEffect(() => {
|
|
2194
|
+
if (!additionalInstructions?.length) {
|
|
2195
|
+
setChatInstructions(instructions || "");
|
|
2196
|
+
return;
|
|
2197
|
+
}
|
|
2198
|
+
setChatInstructions([
|
|
2199
|
+
instructions,
|
|
2200
|
+
"Additionally, follow these instructions:",
|
|
2201
|
+
...additionalInstructions.map((instruction) => `- ${instruction}`)
|
|
2202
|
+
].join("\n") || "");
|
|
2203
|
+
}, [instructions, additionalInstructions]);
|
|
2204
|
+
const { messages, isLoading, sendMessage, stopGeneration, reloadMessages, suggestions: currentSuggestions, isLoadingSuggestions, agent } = useCopilotChatInternal({
|
|
2205
|
+
suggestions,
|
|
2206
|
+
onInProgress,
|
|
2207
|
+
onSubmitMessage,
|
|
2208
|
+
onStopGeneration,
|
|
2209
|
+
onReloadMessages
|
|
2210
|
+
});
|
|
2211
|
+
const prevIsLoading = useRef(isLoading);
|
|
2212
|
+
useEffect(() => {
|
|
2213
|
+
if (prevIsLoading.current !== isLoading) {
|
|
2214
|
+
if (isLoading) triggerObservabilityHook("onChatStarted");
|
|
2215
|
+
else triggerObservabilityHook("onChatStopped");
|
|
2216
|
+
prevIsLoading.current = isLoading;
|
|
2217
|
+
}
|
|
2218
|
+
}, [isLoading, triggerObservabilityHook]);
|
|
2219
|
+
const handleSendMessage = (text) => {
|
|
2220
|
+
setSelectedImages([]);
|
|
2221
|
+
if (fileInputRef.current) fileInputRef.current.value = "";
|
|
2222
|
+
triggerObservabilityHook("onMessageSent", text);
|
|
2223
|
+
return sendMessage({
|
|
2224
|
+
id: randomUUID(),
|
|
2225
|
+
content: text,
|
|
2226
|
+
role: "user"
|
|
2227
|
+
});
|
|
2228
|
+
};
|
|
2229
|
+
const chatContext = React.useContext(ChatContext);
|
|
2230
|
+
const isVisible = chatContext ? chatContext.open : true;
|
|
2231
|
+
const handleRegenerate = (messageId) => {
|
|
2232
|
+
if (onRegenerate) onRegenerate(messageId);
|
|
2233
|
+
triggerObservabilityHook("onMessageRegenerated", messageId);
|
|
2234
|
+
reloadMessages(messageId);
|
|
2235
|
+
};
|
|
2236
|
+
const handleCopy = (message) => {
|
|
2237
|
+
if (onCopy) onCopy(message);
|
|
2238
|
+
triggerObservabilityHook("onMessageCopied", message);
|
|
2239
|
+
};
|
|
2240
|
+
const handleImageUpload = async (event) => {
|
|
2241
|
+
if (!event.target.files || event.target.files.length === 0) return;
|
|
2242
|
+
const files = Array.from(event.target.files).filter((file) => file.type.startsWith("image/"));
|
|
2243
|
+
if (files.length === 0) return;
|
|
2244
|
+
const fileReadPromises = files.map((file) => {
|
|
2245
|
+
return new Promise((resolve, reject) => {
|
|
2246
|
+
const reader = new FileReader();
|
|
2247
|
+
reader.onload = (e) => {
|
|
2248
|
+
const base64String = (e.target?.result)?.split(",")[1] || "";
|
|
2249
|
+
if (base64String) resolve({
|
|
2250
|
+
contentType: file.type,
|
|
2251
|
+
bytes: base64String
|
|
2252
|
+
});
|
|
2253
|
+
};
|
|
2254
|
+
reader.onerror = reject;
|
|
2255
|
+
reader.readAsDataURL(file);
|
|
2256
|
+
});
|
|
2257
|
+
});
|
|
2258
|
+
try {
|
|
2259
|
+
const loadedImages = await Promise.all(fileReadPromises);
|
|
2260
|
+
setSelectedImages((prev) => [...prev, ...loadedImages]);
|
|
2261
|
+
} catch (error) {
|
|
2262
|
+
triggerChatError(error, "processUploadedImages", error);
|
|
2263
|
+
console.error("Error reading files:", error);
|
|
2264
|
+
}
|
|
2265
|
+
};
|
|
2266
|
+
const removeSelectedImage = (index) => {
|
|
2267
|
+
setSelectedImages((prev) => prev.filter((_, i) => i !== index));
|
|
2268
|
+
};
|
|
2269
|
+
const handleThumbsUp = (message) => {
|
|
2270
|
+
if (onThumbsUp) onThumbsUp(message);
|
|
2271
|
+
setMessageFeedback((prev) => ({
|
|
2272
|
+
...prev,
|
|
2273
|
+
[message.id]: "thumbsUp"
|
|
2274
|
+
}));
|
|
2275
|
+
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
|
|
2276
|
+
};
|
|
2277
|
+
const handleThumbsDown = (message) => {
|
|
2278
|
+
if (onThumbsDown) onThumbsDown(message);
|
|
2279
|
+
setMessageFeedback((prev) => ({
|
|
2280
|
+
...prev,
|
|
2281
|
+
[message.id]: "thumbsDown"
|
|
2282
|
+
}));
|
|
2283
|
+
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
|
|
2284
|
+
};
|
|
2285
|
+
return /* @__PURE__ */ jsxs(WrappedCopilotChat, {
|
|
2286
|
+
icons,
|
|
2287
|
+
labels,
|
|
2288
|
+
className,
|
|
2289
|
+
children: [
|
|
2290
|
+
chatError && renderError && renderError({
|
|
2291
|
+
...chatError,
|
|
2292
|
+
onDismiss: () => setChatError(null),
|
|
2293
|
+
onRetry: () => {
|
|
2294
|
+
setChatError(null);
|
|
2295
|
+
}
|
|
2296
|
+
}),
|
|
2297
|
+
/* @__PURE__ */ jsx(Messages$2, {
|
|
2298
|
+
AssistantMessage: AssistantMessage$2,
|
|
2299
|
+
UserMessage: UserMessage$3,
|
|
2300
|
+
RenderMessage: RenderMessage$1,
|
|
2301
|
+
messages,
|
|
2302
|
+
inProgress: isLoading,
|
|
2303
|
+
onRegenerate: handleRegenerate,
|
|
2304
|
+
onCopy: handleCopy,
|
|
2305
|
+
onThumbsUp: handleThumbsUp,
|
|
2306
|
+
onThumbsDown: handleThumbsDown,
|
|
2307
|
+
messageFeedback,
|
|
2308
|
+
markdownTagRenderers,
|
|
2309
|
+
ImageRenderer: ImageRenderer$1,
|
|
2310
|
+
ErrorMessage,
|
|
2311
|
+
chatError,
|
|
2312
|
+
RenderTextMessage,
|
|
2313
|
+
RenderActionExecutionMessage,
|
|
2314
|
+
RenderAgentStateMessage,
|
|
2315
|
+
RenderResultMessage,
|
|
2316
|
+
RenderImageMessage,
|
|
2317
|
+
children: currentSuggestions.length > 0 && /* @__PURE__ */ jsx(RenderSuggestionsList, {
|
|
2318
|
+
onSuggestionClick: handleSendMessage,
|
|
2319
|
+
suggestions: currentSuggestions,
|
|
2320
|
+
isLoading: isLoadingSuggestions
|
|
2321
|
+
})
|
|
2322
|
+
}),
|
|
2323
|
+
imageUploadsEnabled && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ImageUploadQueue, {
|
|
2324
|
+
images: selectedImages,
|
|
2325
|
+
onRemoveImage: removeSelectedImage
|
|
2326
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
2327
|
+
type: "file",
|
|
2328
|
+
multiple: true,
|
|
2329
|
+
ref: fileInputRef,
|
|
2330
|
+
onChange: handleImageUpload,
|
|
2331
|
+
accept: inputFileAccept,
|
|
2332
|
+
style: { display: "none" }
|
|
2333
|
+
})] }),
|
|
2334
|
+
/* @__PURE__ */ jsx(Input$2, {
|
|
2335
|
+
inProgress: isLoading,
|
|
2336
|
+
chatReady: Boolean(agent),
|
|
2337
|
+
onSend: handleSendMessage,
|
|
2338
|
+
isVisible,
|
|
2339
|
+
onStop: stopGeneration,
|
|
2340
|
+
onUpload: imageUploadsEnabled ? () => fileInputRef.current?.click() : void 0,
|
|
2341
|
+
hideStopButton
|
|
2342
|
+
})
|
|
2343
|
+
]
|
|
2344
|
+
});
|
|
2345
|
+
}
|
|
2346
|
+
function WrappedCopilotChat({ children, icons, labels, className }) {
|
|
2347
|
+
if (!React.useContext(ChatContext)) return /* @__PURE__ */ jsx(ChatContextProvider, {
|
|
2348
|
+
icons,
|
|
2349
|
+
labels,
|
|
2350
|
+
open: true,
|
|
2351
|
+
setOpen: () => {},
|
|
2352
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
2353
|
+
className: `copilotKitChat ${className ?? ""}`,
|
|
2354
|
+
children
|
|
2355
|
+
})
|
|
2356
|
+
});
|
|
2357
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
//#endregion
|
|
2361
|
+
//#region src/components/chat/Modal.tsx
|
|
2362
|
+
const CopilotModalInner = ({ observabilityHooks, onSetOpen, clickOutsideToClose, hitEscapeToClose, shortcut, className, children, Window, Button, Header, ...chatProps }) => {
|
|
2363
|
+
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
2364
|
+
const { publicApiKey } = copilotApiConfig;
|
|
2365
|
+
const triggerObservabilityHook = useCallback((hookName, ...args) => {
|
|
2366
|
+
if (publicApiKey && observabilityHooks?.[hookName]) observabilityHooks[hookName](...args);
|
|
2367
|
+
if (observabilityHooks?.[hookName] && !publicApiKey) {
|
|
2368
|
+
setBannerError(new CopilotKitError({
|
|
2369
|
+
message: "observabilityHooks requires a publicApiKey to function.",
|
|
2370
|
+
code: CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
2371
|
+
severity: Severity.CRITICAL,
|
|
2372
|
+
visibility: ErrorVisibility.BANNER
|
|
2373
|
+
}));
|
|
2374
|
+
styledConsole.publicApiKeyRequired("observabilityHooks");
|
|
2375
|
+
}
|
|
2376
|
+
}, [
|
|
2377
|
+
publicApiKey,
|
|
2378
|
+
observabilityHooks,
|
|
2379
|
+
setBannerError
|
|
2380
|
+
]);
|
|
2381
|
+
const { open } = useChatContext();
|
|
2382
|
+
const prevOpen = useRef(open);
|
|
2383
|
+
useEffect(() => {
|
|
2384
|
+
if (prevOpen.current !== open) {
|
|
2385
|
+
onSetOpen?.(open);
|
|
2386
|
+
if (open) triggerObservabilityHook("onChatExpanded");
|
|
2387
|
+
else triggerObservabilityHook("onChatMinimized");
|
|
2388
|
+
prevOpen.current = open;
|
|
2389
|
+
}
|
|
2390
|
+
}, [
|
|
2391
|
+
open,
|
|
2392
|
+
onSetOpen,
|
|
2393
|
+
triggerObservabilityHook
|
|
2394
|
+
]);
|
|
2395
|
+
const memoizedHeader = useMemo(() => /* @__PURE__ */ jsx(Header, {}), [Header]);
|
|
2396
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [useMemo(() => children, [children]), /* @__PURE__ */ jsxs("div", {
|
|
2397
|
+
className,
|
|
2398
|
+
children: [/* @__PURE__ */ jsx(Button, {}), /* @__PURE__ */ jsxs(Window, {
|
|
2399
|
+
clickOutsideToClose,
|
|
2400
|
+
shortcut,
|
|
2401
|
+
hitEscapeToClose,
|
|
2402
|
+
children: [memoizedHeader, /* @__PURE__ */ jsx(CopilotChat, {
|
|
2403
|
+
...chatProps,
|
|
2404
|
+
observabilityHooks
|
|
2405
|
+
})]
|
|
2406
|
+
})]
|
|
2407
|
+
})] });
|
|
2408
|
+
};
|
|
2409
|
+
const CopilotModal = ({ instructions, defaultOpen = false, clickOutsideToClose = true, hitEscapeToClose = true, onSetOpen, onSubmitMessage, onStopGeneration, onReloadMessages, shortcut = "/", icons, labels, makeSystemMessage, onInProgress, Window: Window$1 = Window, Button: Button$1 = Button, Header: Header$1 = Header, Messages: Messages$1 = Messages, Input: Input$1 = Input, AssistantMessage: AssistantMessage$1 = AssistantMessage, UserMessage: UserMessage$2 = UserMessage, onThumbsUp, onThumbsDown, onCopy, onRegenerate, markdownTagRenderers, className, children, observabilityHooks, ...props }) => {
|
|
2410
|
+
const [openState, setOpenState] = React.useState(defaultOpen);
|
|
2411
|
+
return /* @__PURE__ */ jsx(ChatContextProvider, {
|
|
2412
|
+
icons,
|
|
2413
|
+
labels,
|
|
2414
|
+
open: openState,
|
|
2415
|
+
setOpen: setOpenState,
|
|
2416
|
+
children: /* @__PURE__ */ jsx(CopilotModalInner, {
|
|
2417
|
+
observabilityHooks,
|
|
2418
|
+
onSetOpen,
|
|
2419
|
+
clickOutsideToClose: clickOutsideToClose ?? true,
|
|
2420
|
+
hitEscapeToClose: hitEscapeToClose ?? true,
|
|
2421
|
+
shortcut: shortcut ?? "/",
|
|
2422
|
+
className,
|
|
2423
|
+
Window: Window$1,
|
|
2424
|
+
Button: Button$1,
|
|
2425
|
+
Header: Header$1,
|
|
2426
|
+
instructions,
|
|
2427
|
+
onSubmitMessage,
|
|
2428
|
+
onStopGeneration,
|
|
2429
|
+
onReloadMessages,
|
|
2430
|
+
makeSystemMessage,
|
|
2431
|
+
onInProgress,
|
|
2432
|
+
Messages: Messages$1,
|
|
2433
|
+
Input: Input$1,
|
|
2434
|
+
AssistantMessage: AssistantMessage$1,
|
|
2435
|
+
UserMessage: UserMessage$2,
|
|
2436
|
+
onThumbsUp,
|
|
2437
|
+
onThumbsDown,
|
|
2438
|
+
onCopy,
|
|
2439
|
+
onRegenerate,
|
|
2440
|
+
markdownTagRenderers,
|
|
2441
|
+
...props,
|
|
2442
|
+
children
|
|
2443
|
+
})
|
|
2444
|
+
});
|
|
2445
|
+
};
|
|
2446
|
+
|
|
2447
|
+
//#endregion
|
|
2448
|
+
//#region src/components/chat/Popup.tsx
|
|
2449
|
+
/**
|
|
2450
|
+
* <br/>
|
|
2451
|
+
* <img src="https://cdn.copilotkit.ai/docs/copilotkit/images/CopilotPopup.gif" width="500" />
|
|
2452
|
+
*
|
|
2453
|
+
* A chatbot popup component for the CopilotKit framework. The component allows for a high degree
|
|
2454
|
+
* of customization through various props and custom CSS.
|
|
2455
|
+
*
|
|
2456
|
+
* See [CopilotSidebar](/reference/v1/components/chat/CopilotSidebar) for a sidebar version of this component.
|
|
2457
|
+
*
|
|
2458
|
+
* ## Install Dependencies
|
|
2459
|
+
*
|
|
2460
|
+
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
2461
|
+
*
|
|
2462
|
+
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
2463
|
+
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
2464
|
+
* ```
|
|
2465
|
+
* ## Usage
|
|
2466
|
+
*
|
|
2467
|
+
* ```tsx
|
|
2468
|
+
* import { CopilotPopup } from "@copilotkit/react-ui";
|
|
2469
|
+
* import "@copilotkit/react-ui/styles.css";
|
|
2470
|
+
*
|
|
2471
|
+
* <CopilotPopup
|
|
2472
|
+
* labels={{
|
|
2473
|
+
* title: "Your Assistant",
|
|
2474
|
+
* initial: "Hi! 👋 How can I assist you today?",
|
|
2475
|
+
* }}
|
|
2476
|
+
* />
|
|
2477
|
+
* ```
|
|
2478
|
+
*
|
|
2479
|
+
* ### With Observability Hooks
|
|
2480
|
+
*
|
|
2481
|
+
* To monitor user interactions, provide the `observabilityHooks` prop.
|
|
2482
|
+
* **Note:** This requires a `publicApiKey` in the `<CopilotKit>` provider.
|
|
2483
|
+
*
|
|
2484
|
+
* ```tsx
|
|
2485
|
+
* <CopilotKit publicApiKey="YOUR_PUBLIC_API_KEY">
|
|
2486
|
+
* <CopilotPopup
|
|
2487
|
+
* observabilityHooks={{
|
|
2488
|
+
* onChatExpanded: () => {
|
|
2489
|
+
* console.log("Popup opened");
|
|
2490
|
+
* },
|
|
2491
|
+
* onChatMinimized: () => {
|
|
2492
|
+
* console.log("Popup closed");
|
|
2493
|
+
* },
|
|
2494
|
+
* }}
|
|
2495
|
+
* />
|
|
2496
|
+
* </CopilotKit>
|
|
2497
|
+
* ```
|
|
2498
|
+
*
|
|
2499
|
+
* ### Look & Feel
|
|
2500
|
+
*
|
|
2501
|
+
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
2502
|
+
* ```tsx title="YourRootComponent.tsx"
|
|
2503
|
+
* ...
|
|
2504
|
+
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
2505
|
+
*
|
|
2506
|
+
* export function YourRootComponent() {
|
|
2507
|
+
* return (
|
|
2508
|
+
* <CopilotKit>
|
|
2509
|
+
* ...
|
|
2510
|
+
* </CopilotKit>
|
|
2511
|
+
* );
|
|
2512
|
+
* }
|
|
2513
|
+
* ```
|
|
2514
|
+
* For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
|
|
2515
|
+
*/
|
|
2516
|
+
function CopilotPopup(props) {
|
|
2517
|
+
props = {
|
|
2518
|
+
...props,
|
|
2519
|
+
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup"
|
|
2520
|
+
};
|
|
2521
|
+
return /* @__PURE__ */ jsx(CopilotModal, {
|
|
2522
|
+
...props,
|
|
2523
|
+
children: props.children
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
//#endregion
|
|
2528
|
+
//#region src/components/chat/Sidebar.tsx
|
|
2529
|
+
/**
|
|
2530
|
+
* <br/>
|
|
2531
|
+
* <img src="https://cdn.copilotkit.ai/docs/copilotkit/images/CopilotSidebar.gif" width="500" />
|
|
2532
|
+
*
|
|
2533
|
+
* A chatbot sidebar component for the CopilotKit framework. Highly customizable through various props and custom CSS.
|
|
2534
|
+
*
|
|
2535
|
+
* See [CopilotPopup](/reference/v1/components/chat/CopilotPopup) for a popup version of this component.
|
|
2536
|
+
*
|
|
2537
|
+
* ## Install Dependencies
|
|
2538
|
+
*
|
|
2539
|
+
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
2540
|
+
*
|
|
2541
|
+
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
2542
|
+
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
2543
|
+
* ```
|
|
2544
|
+
*
|
|
2545
|
+
* ## Usage
|
|
2546
|
+
*
|
|
2547
|
+
* ```tsx
|
|
2548
|
+
* import { CopilotSidebar } from "@copilotkit/react-ui";
|
|
2549
|
+
* import "@copilotkit/react-ui/styles.css";
|
|
2550
|
+
*
|
|
2551
|
+
* <CopilotSidebar
|
|
2552
|
+
* labels={{
|
|
2553
|
+
* title: "Your Assistant",
|
|
2554
|
+
* initial: "Hi! 👋 How can I assist you today?",
|
|
2555
|
+
* }}
|
|
2556
|
+
* >
|
|
2557
|
+
* <YourApp/>
|
|
2558
|
+
* </CopilotSidebar>
|
|
2559
|
+
* ```
|
|
2560
|
+
*
|
|
2561
|
+
* ### With Observability Hooks
|
|
2562
|
+
*
|
|
2563
|
+
* To monitor user interactions, provide the `observabilityHooks` prop.
|
|
2564
|
+
* **Note:** This requires a `publicApiKey` in the `<CopilotKit>` provider.
|
|
2565
|
+
*
|
|
2566
|
+
* ```tsx
|
|
2567
|
+
* <CopilotKit publicApiKey="YOUR_PUBLIC_API_KEY">
|
|
2568
|
+
* <CopilotSidebar
|
|
2569
|
+
* observabilityHooks={{
|
|
2570
|
+
* onChatExpanded: () => {
|
|
2571
|
+
* console.log("Sidebar opened");
|
|
2572
|
+
* },
|
|
2573
|
+
* onChatMinimized: () => {
|
|
2574
|
+
* console.log("Sidebar closed");
|
|
2575
|
+
* },
|
|
2576
|
+
* }}
|
|
2577
|
+
* >
|
|
2578
|
+
* <YourApp/>
|
|
2579
|
+
* </CopilotSidebar>
|
|
2580
|
+
* </CopilotKit>
|
|
2581
|
+
* ```
|
|
2582
|
+
*
|
|
2583
|
+
* ### Look & Feel
|
|
2584
|
+
*
|
|
2585
|
+
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
2586
|
+
* ```tsx title="YourRootComponent.tsx"
|
|
2587
|
+
* ...
|
|
2588
|
+
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
2589
|
+
*
|
|
2590
|
+
* export function YourRootComponent() {
|
|
2591
|
+
* return (
|
|
2592
|
+
* <CopilotKit>
|
|
2593
|
+
* ...
|
|
2594
|
+
* </CopilotKit>
|
|
2595
|
+
* );
|
|
2596
|
+
* }
|
|
2597
|
+
* ```
|
|
2598
|
+
* For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
|
|
2599
|
+
*/
|
|
2600
|
+
function CopilotSidebar(props) {
|
|
2601
|
+
props = {
|
|
2602
|
+
...props,
|
|
2603
|
+
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
2604
|
+
};
|
|
2605
|
+
const [expandedClassName, setExpandedClassName] = useState(props.defaultOpen ? "sidebarExpanded" : "");
|
|
2606
|
+
const onSetOpen = (open) => {
|
|
2607
|
+
props.onSetOpen?.(open);
|
|
2608
|
+
setExpandedClassName(open ? "sidebarExpanded" : "");
|
|
2609
|
+
};
|
|
2610
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2611
|
+
className: `copilotKitSidebarContentWrapper ${expandedClassName}`,
|
|
2612
|
+
children: /* @__PURE__ */ jsx(CopilotModal, {
|
|
2613
|
+
...props,
|
|
2614
|
+
onSetOpen,
|
|
2615
|
+
children: props.children
|
|
2616
|
+
})
|
|
2617
|
+
});
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
//#endregion
|
|
2621
|
+
//#region src/hooks/use-copilot-chat-suggestions.tsx
|
|
2622
|
+
/**
|
|
2623
|
+
* <Callout type="warning">
|
|
2624
|
+
* useCopilotChatSuggestions is experimental. The interface is not final and
|
|
2625
|
+
* can change without notice.
|
|
2626
|
+
* </Callout>
|
|
2627
|
+
*
|
|
2628
|
+
* `useCopilotReadable` is a React hook that provides app-state and other information
|
|
2629
|
+
* to the Copilot. Optionally, the hook can also handle hierarchical state within your
|
|
2630
|
+
* application, passing these parent-child relationships to the Copilot.
|
|
2631
|
+
*
|
|
2632
|
+
* <br/>
|
|
2633
|
+
* <img src="https://cdn.copilotkit.ai/docs/copilotkit/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif" width="500" />
|
|
2634
|
+
*
|
|
2635
|
+
* ## Usage
|
|
2636
|
+
*
|
|
2637
|
+
* ### Install Dependencies
|
|
2638
|
+
*
|
|
2639
|
+
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
2640
|
+
*
|
|
2641
|
+
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
2642
|
+
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
2643
|
+
* ```
|
|
2644
|
+
*
|
|
2645
|
+
* ### Simple Usage
|
|
2646
|
+
*
|
|
2647
|
+
* ```tsx
|
|
2648
|
+
* import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
|
|
2649
|
+
*
|
|
2650
|
+
* export function MyComponent() {
|
|
2651
|
+
* const [employees, setEmployees] = useState([]);
|
|
2652
|
+
*
|
|
2653
|
+
* useCopilotChatSuggestions({
|
|
2654
|
+
* instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,
|
|
2655
|
+
* });
|
|
2656
|
+
* }
|
|
2657
|
+
* ```
|
|
2658
|
+
*
|
|
2659
|
+
* ### Dependency Management
|
|
2660
|
+
*
|
|
2661
|
+
* ```tsx
|
|
2662
|
+
* import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
|
|
2663
|
+
*
|
|
2664
|
+
* export function MyComponent() {
|
|
2665
|
+
* useCopilotChatSuggestions(
|
|
2666
|
+
* {
|
|
2667
|
+
* instructions: "Suggest the most relevant next actions.",
|
|
2668
|
+
* },
|
|
2669
|
+
* [appState],
|
|
2670
|
+
* );
|
|
2671
|
+
* }
|
|
2672
|
+
* ```
|
|
2673
|
+
*
|
|
2674
|
+
* In the example above, the suggestions are generated based on the given instructions.
|
|
2675
|
+
* The hook monitors `appState`, and updates suggestions accordingly whenever it changes.
|
|
2676
|
+
*
|
|
2677
|
+
* ### Behavior and Lifecycle
|
|
2678
|
+
*
|
|
2679
|
+
* The hook registers the configuration with the chat context upon component mount and
|
|
2680
|
+
* removes it on unmount, ensuring a clean and efficient lifecycle management.
|
|
2681
|
+
*/
|
|
2682
|
+
function useCopilotChatSuggestions(config, dependencies = []) {
|
|
2683
|
+
useCopilotChatSuggestions$1(config, dependencies);
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
//#endregion
|
|
2687
|
+
export { AssistantMessage, CopilotChat, CopilotDevConsole, CopilotPopup, CopilotSidebar, ImageRenderer, Markdown, Suggestion as RenderSuggestion, Suggestions as RenderSuggestionsList, UserMessage, shouldShowDevConsole, useChatContext, useCopilotChatSuggestions };
|
|
84
2688
|
//# sourceMappingURL=index.mjs.map
|