@copilotkit/react-core 1.57.2 → 1.57.4

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.
Files changed (266) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +12 -13
  3. package/skills/react-core/SKILL.md +108 -0
  4. package/skills/react-core/references/agent-access.md +288 -0
  5. package/skills/react-core/references/attachments.md +291 -0
  6. package/skills/react-core/references/capabilities.md +138 -0
  7. package/skills/react-core/references/chat-components.md +221 -0
  8. package/skills/react-core/references/client-side-tools.md +358 -0
  9. package/skills/react-core/references/custom-message-renderers.md +226 -0
  10. package/skills/react-core/references/debug-mode.md +153 -0
  11. package/skills/react-core/references/human-in-the-loop.md +312 -0
  12. package/skills/react-core/references/provider-setup.md +326 -0
  13. package/skills/react-core/references/rendering-activity-messages.md +207 -0
  14. package/skills/react-core/references/rendering-tool-calls.md +319 -0
  15. package/skills/react-core/references/suggestions.md +211 -0
  16. package/skills/react-core/references/switching-agents-recipes.md +160 -0
  17. package/skills/react-core/references/switching-agents.md +231 -0
  18. package/skills/react-core/references/threads.md +226 -0
  19. package/.attw.json +0 -3
  20. package/CHANGELOG.md +0 -5043
  21. package/scripts/scope-preflight.mjs +0 -100
  22. package/src/components/CopilotListeners.tsx +0 -137
  23. package/src/components/__tests__/CopilotListeners.test.tsx +0 -38
  24. package/src/components/copilot-provider/__tests__/copilot-messages-key.test.tsx +0 -92
  25. package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +0 -77
  26. package/src/components/copilot-provider/__tests__/error-visibility-prod.test.tsx +0 -70
  27. package/src/components/copilot-provider/__tests__/v1-explicit-threadid-bridge.test.tsx +0 -107
  28. package/src/components/copilot-provider/copilot-messages.tsx +0 -314
  29. package/src/components/copilot-provider/copilotkit-props.tsx +0 -214
  30. package/src/components/copilot-provider/copilotkit.tsx +0 -853
  31. package/src/components/copilot-provider/index.ts +0 -3
  32. package/src/components/dev-console/console-trigger.tsx +0 -283
  33. package/src/components/dev-console/developer-console-modal.tsx +0 -1016
  34. package/src/components/dev-console/icons.tsx +0 -106
  35. package/src/components/error-boundary/error-boundary.tsx +0 -99
  36. package/src/components/error-boundary/error-utils.tsx +0 -105
  37. package/src/components/index.ts +0 -1
  38. package/src/components/toast/exclamation-mark-icon.tsx +0 -27
  39. package/src/components/toast/toast-provider.tsx +0 -448
  40. package/src/components/usage-banner.tsx +0 -266
  41. package/src/context/__tests__/threads-context.test.tsx +0 -141
  42. package/src/context/coagent-state-renders-context.tsx +0 -89
  43. package/src/context/copilot-context.tsx +0 -365
  44. package/src/context/copilot-messages-context.tsx +0 -35
  45. package/src/context/index.ts +0 -22
  46. package/src/context/threads-context.tsx +0 -69
  47. package/src/hooks/__tests__/use-coagent-config.test.ts +0 -352
  48. package/src/hooks/__tests__/use-coagent-state-render-bridge.helpers.test.ts +0 -107
  49. package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +0 -1209
  50. package/src/hooks/__tests__/use-coagent-state-render.test.tsx +0 -356
  51. package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +0 -241
  52. package/src/hooks/__tests__/use-frontend-tool-available.test.tsx +0 -72
  53. package/src/hooks/__tests__/use-frontend-tool-remount.e2e.test.tsx +0 -102
  54. package/src/hooks/index.ts +0 -33
  55. package/src/hooks/use-agent-nodename.ts +0 -33
  56. package/src/hooks/use-coagent-state-render-bridge.helpers.ts +0 -345
  57. package/src/hooks/use-coagent-state-render-bridge.tsx +0 -222
  58. package/src/hooks/use-coagent-state-render-registry.ts +0 -230
  59. package/src/hooks/use-coagent-state-render.ts +0 -163
  60. package/src/hooks/use-coagent.ts +0 -377
  61. package/src/hooks/use-configure-chat-suggestions.tsx +0 -96
  62. package/src/hooks/use-copilot-action.ts +0 -245
  63. package/src/hooks/use-copilot-additional-instructions.ts +0 -98
  64. package/src/hooks/use-copilot-authenticated-action.ts +0 -73
  65. package/src/hooks/use-copilot-chat-headless_c.ts +0 -264
  66. package/src/hooks/use-copilot-chat-suggestions.tsx +0 -134
  67. package/src/hooks/use-copilot-chat.ts +0 -132
  68. package/src/hooks/use-copilot-chat_internal.ts +0 -875
  69. package/src/hooks/use-copilot-readable.ts +0 -135
  70. package/src/hooks/use-copilot-runtime-client.ts +0 -178
  71. package/src/hooks/use-default-tool.ts +0 -13
  72. package/src/hooks/use-flat-category-store.ts +0 -109
  73. package/src/hooks/use-frontend-tool.ts +0 -113
  74. package/src/hooks/use-human-in-the-loop.ts +0 -138
  75. package/src/hooks/use-langgraph-interrupt.ts +0 -103
  76. package/src/hooks/use-lazy-tool-renderer.tsx +0 -30
  77. package/src/hooks/use-make-copilot-document-readable.ts +0 -30
  78. package/src/hooks/use-render-tool-call.ts +0 -89
  79. package/src/hooks/use-tree.ts +0 -222
  80. package/src/index.tsx +0 -7
  81. package/src/lib/copilot-task.ts +0 -215
  82. package/src/lib/index.ts +0 -1
  83. package/src/lib/status-checker.ts +0 -67
  84. package/src/setupTests.ts +0 -37
  85. package/src/test-helpers/copilot-context.ts +0 -91
  86. package/src/types/chat-suggestion-configuration.ts +0 -23
  87. package/src/types/coagent-action.ts +0 -35
  88. package/src/types/coagent-state.ts +0 -13
  89. package/src/types/crew.ts +0 -89
  90. package/src/types/document-pointer.ts +0 -7
  91. package/src/types/frontend-action.ts +0 -213
  92. package/src/types/index.ts +0 -17
  93. package/src/types/interrupt-action.ts +0 -58
  94. package/src/types/system-message.ts +0 -4
  95. package/src/utils/dev-console.ts +0 -19
  96. package/src/utils/index.ts +0 -2
  97. package/src/utils/suggestions-constants.ts +0 -8
  98. package/src/utils/utils.test.ts +0 -7
  99. package/src/utils/utils.ts +0 -6
  100. package/src/v2/__tests__/A2UIMessageRenderer.test.tsx +0 -240
  101. package/src/v2/__tests__/globalSetup.ts +0 -14
  102. package/src/v2/__tests__/setup.ts +0 -93
  103. package/src/v2/__tests__/utils/test-helpers.tsx +0 -570
  104. package/src/v2/a2ui/A2UICatalogContext.tsx +0 -79
  105. package/src/v2/a2ui/A2UIMessageRenderer.tsx +0 -294
  106. package/src/v2/a2ui/A2UIToolCallRenderer.tsx +0 -290
  107. package/src/v2/components/CopilotKitInspector.tsx +0 -52
  108. package/src/v2/components/MCPAppsActivityRenderer.tsx +0 -815
  109. package/src/v2/components/OpenGenerativeUIRenderer.tsx +0 -598
  110. package/src/v2/components/WildcardToolCallRender.tsx +0 -86
  111. package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.tsx +0 -665
  112. package/src/v2/components/chat/CopilotChat.tsx +0 -664
  113. package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +0 -393
  114. package/src/v2/components/chat/CopilotChatAttachmentQueue.tsx +0 -374
  115. package/src/v2/components/chat/CopilotChatAttachmentRenderer.tsx +0 -159
  116. package/src/v2/components/chat/CopilotChatAudioRecorder.tsx +0 -350
  117. package/src/v2/components/chat/CopilotChatInput.tsx +0 -1412
  118. package/src/v2/components/chat/CopilotChatMessageView.tsx +0 -716
  119. package/src/v2/components/chat/CopilotChatReasoningMessage.tsx +0 -265
  120. package/src/v2/components/chat/CopilotChatSuggestionPill.tsx +0 -59
  121. package/src/v2/components/chat/CopilotChatSuggestionView.tsx +0 -134
  122. package/src/v2/components/chat/CopilotChatToggleButton.tsx +0 -171
  123. package/src/v2/components/chat/CopilotChatToolCallsView.tsx +0 -40
  124. package/src/v2/components/chat/CopilotChatUserMessage.tsx +0 -445
  125. package/src/v2/components/chat/CopilotChatView.tsx +0 -890
  126. package/src/v2/components/chat/CopilotModalHeader.tsx +0 -129
  127. package/src/v2/components/chat/CopilotPopup.tsx +0 -81
  128. package/src/v2/components/chat/CopilotPopupView.tsx +0 -317
  129. package/src/v2/components/chat/CopilotSidebar.tsx +0 -80
  130. package/src/v2/components/chat/CopilotSidebarView.tsx +0 -269
  131. package/src/v2/components/chat/Lightbox.tsx +0 -103
  132. package/src/v2/components/chat/__tests__/CopilotChat.absentThreadConnect.test.tsx +0 -66
  133. package/src/v2/components/chat/__tests__/CopilotChat.attachments.test.tsx +0 -168
  134. package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.tsx +0 -1239
  135. package/src/v2/components/chat/__tests__/CopilotChat.onError.test.tsx +0 -73
  136. package/src/v2/components/chat/__tests__/CopilotChat.slots.e2e.test.tsx +0 -432
  137. package/src/v2/components/chat/__tests__/CopilotChat.suggestionsAlways.test.tsx +0 -183
  138. package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +0 -184
  139. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +0 -649
  140. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.tsx +0 -624
  141. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.tsx +0 -702
  142. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.thumbs.test.tsx +0 -72
  143. package/src/v2/components/chat/__tests__/CopilotChatCopyButton.clipboard.test.tsx +0 -241
  144. package/src/v2/components/chat/__tests__/CopilotChatCssClasses.test.tsx +0 -107
  145. package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.tsx +0 -929
  146. package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +0 -1567
  147. package/src/v2/components/chat/__tests__/CopilotChatMessageView.slots.e2e.test.tsx +0 -1004
  148. package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.tsx +0 -279
  149. package/src/v2/components/chat/__tests__/CopilotChatPerf.e2e.test.tsx +0 -296
  150. package/src/v2/components/chat/__tests__/CopilotChatPropsRerender.e2e.test.tsx +0 -249
  151. package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.tsx +0 -530
  152. package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.tsx +0 -785
  153. package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.tsx +0 -2416
  154. package/src/v2/components/chat/__tests__/CopilotChatUserMessage.slots.e2e.test.tsx +0 -621
  155. package/src/v2/components/chat/__tests__/CopilotChatView.connectingGate.test.tsx +0 -56
  156. package/src/v2/components/chat/__tests__/CopilotChatView.inputOverlay.test.tsx +0 -264
  157. package/src/v2/components/chat/__tests__/CopilotChatView.onClick.e2e.test.tsx +0 -853
  158. package/src/v2/components/chat/__tests__/CopilotChatView.pinToSend.test.tsx +0 -94
  159. package/src/v2/components/chat/__tests__/CopilotChatView.slots.e2e.test.tsx +0 -1050
  160. package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.tsx +0 -484
  161. package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.tsx +0 -612
  162. package/src/v2/components/chat/__tests__/CopilotSidebarView.position.test.tsx +0 -159
  163. package/src/v2/components/chat/__tests__/CopilotSidebarView.slots.e2e.test.tsx +0 -502
  164. package/src/v2/components/chat/__tests__/MCPAppsActivityRenderer.e2e.test.tsx +0 -1068
  165. package/src/v2/components/chat/__tests__/MCPAppsProxy.e2e.test.tsx +0 -589
  166. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +0 -403
  167. package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.tsx +0 -137
  168. package/src/v2/components/chat/__tests__/normalize-auto-scroll.test.ts +0 -37
  169. package/src/v2/components/chat/__tests__/setup.ts +0 -1
  170. package/src/v2/components/chat/index.ts +0 -90
  171. package/src/v2/components/chat/last-user-message-context.ts +0 -21
  172. package/src/v2/components/chat/normalize-auto-scroll.ts +0 -17
  173. package/src/v2/components/chat/scroll-element-context.ts +0 -13
  174. package/src/v2/components/index.ts +0 -8
  175. package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +0 -286
  176. package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +0 -464
  177. package/src/v2/components/intelligence-indicator/index.ts +0 -2
  178. package/src/v2/components/license-warning-banner.tsx +0 -217
  179. package/src/v2/components/ui/button.tsx +0 -124
  180. package/src/v2/components/ui/dropdown-menu.tsx +0 -258
  181. package/src/v2/components/ui/tooltip.tsx +0 -60
  182. package/src/v2/context.ts +0 -62
  183. package/src/v2/headless.ts +0 -64
  184. package/src/v2/hooks/__tests__/standard-schema-types.test.tsx +0 -152
  185. package/src/v2/hooks/__tests__/standard-schema.test.tsx +0 -282
  186. package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.tsx +0 -140
  187. package/src/v2/hooks/__tests__/use-agent-context.test.tsx +0 -401
  188. package/src/v2/hooks/__tests__/use-agent-error-state.test.tsx +0 -44
  189. package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +0 -211
  190. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +0 -1029
  191. package/src/v2/hooks/__tests__/use-agent.e2e.test.tsx +0 -159
  192. package/src/v2/hooks/__tests__/use-attachments.test.tsx +0 -169
  193. package/src/v2/hooks/__tests__/use-capabilities.test.tsx +0 -76
  194. package/src/v2/hooks/__tests__/use-component.test.tsx +0 -126
  195. package/src/v2/hooks/__tests__/use-configure-suggestions.e2e.test.tsx +0 -696
  196. package/src/v2/hooks/__tests__/use-default-render-tool.test.tsx +0 -153
  197. package/src/v2/hooks/__tests__/use-frontend-tool-available.test.tsx +0 -167
  198. package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.tsx +0 -2148
  199. package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx +0 -1261
  200. package/src/v2/hooks/__tests__/use-interrupt.test.tsx +0 -397
  201. package/src/v2/hooks/__tests__/use-katex-styles.test.tsx +0 -56
  202. package/src/v2/hooks/__tests__/use-keyboard-height.test.tsx +0 -192
  203. package/src/v2/hooks/__tests__/use-pin-to-send.test.tsx +0 -219
  204. package/src/v2/hooks/__tests__/use-render-custom-messages.test.tsx +0 -55
  205. package/src/v2/hooks/__tests__/use-render-tool.test.tsx +0 -259
  206. package/src/v2/hooks/__tests__/use-suggestions.e2e.test.tsx +0 -524
  207. package/src/v2/hooks/__tests__/use-threads.test.tsx +0 -757
  208. package/src/v2/hooks/__tests__/zod-regression.test.tsx +0 -311
  209. package/src/v2/hooks/index.ts +0 -24
  210. package/src/v2/hooks/use-agent-context.tsx +0 -45
  211. package/src/v2/hooks/use-agent.tsx +0 -227
  212. package/src/v2/hooks/use-attachments.tsx +0 -269
  213. package/src/v2/hooks/use-capabilities.tsx +0 -25
  214. package/src/v2/hooks/use-component.tsx +0 -91
  215. package/src/v2/hooks/use-configure-suggestions.tsx +0 -236
  216. package/src/v2/hooks/use-default-render-tool.tsx +0 -271
  217. package/src/v2/hooks/use-frontend-tool.tsx +0 -46
  218. package/src/v2/hooks/use-human-in-the-loop.tsx +0 -81
  219. package/src/v2/hooks/use-interrupt.tsx +0 -305
  220. package/src/v2/hooks/use-keyboard-height.tsx +0 -67
  221. package/src/v2/hooks/use-pin-to-send.ts +0 -94
  222. package/src/v2/hooks/use-render-activity-message.tsx +0 -72
  223. package/src/v2/hooks/use-render-custom-messages.tsx +0 -93
  224. package/src/v2/hooks/use-render-tool-call.tsx +0 -208
  225. package/src/v2/hooks/use-render-tool.tsx +0 -184
  226. package/src/v2/hooks/use-suggestions.tsx +0 -91
  227. package/src/v2/hooks/use-threads.tsx +0 -325
  228. package/src/v2/hooks/useKatexStyles.ts +0 -27
  229. package/src/v2/index.css +0 -1
  230. package/src/v2/index.ts +0 -27
  231. package/src/v2/lib/__tests__/completePartialMarkdown.test.ts +0 -495
  232. package/src/v2/lib/__tests__/processPartialHtml.test.ts +0 -112
  233. package/src/v2/lib/__tests__/renderSlot.test.tsx +0 -588
  234. package/src/v2/lib/__tests__/slots.test.ts +0 -56
  235. package/src/v2/lib/processPartialHtml.ts +0 -45
  236. package/src/v2/lib/react-core.ts +0 -156
  237. package/src/v2/lib/slots.tsx +0 -184
  238. package/src/v2/lib/transcription-client.ts +0 -184
  239. package/src/v2/lib/utils.ts +0 -8
  240. package/src/v2/providers/CopilotChatConfigurationProvider.tsx +0 -196
  241. package/src/v2/providers/CopilotKitProvider.tsx +0 -800
  242. package/src/v2/providers/SandboxFunctionsContext.ts +0 -10
  243. package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.tsx +0 -652
  244. package/src/v2/providers/__tests__/CopilotKitProvider.license.test.tsx +0 -101
  245. package/src/v2/providers/__tests__/CopilotKitProvider.onError.test.tsx +0 -69
  246. package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.tsx +0 -881
  247. package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.tsx +0 -198
  248. package/src/v2/providers/__tests__/CopilotKitProvider.stability.test.tsx +0 -740
  249. package/src/v2/providers/__tests__/CopilotKitProvider.test.tsx +0 -713
  250. package/src/v2/providers/__tests__/CopilotKitProvider.wildcard.test.tsx +0 -294
  251. package/src/v2/providers/index.ts +0 -21
  252. package/src/v2/styles/globals.css +0 -349
  253. package/src/v2/types/__tests__/defineToolCallRenderer.test.tsx +0 -525
  254. package/src/v2/types/defineToolCallRenderer.ts +0 -68
  255. package/src/v2/types/frontend-tool.ts +0 -8
  256. package/src/v2/types/human-in-the-loop.ts +0 -33
  257. package/src/v2/types/index.ts +0 -8
  258. package/src/v2/types/interrupt.ts +0 -15
  259. package/src/v2/types/react-activity-message-renderer.ts +0 -27
  260. package/src/v2/types/react-custom-message-renderer.ts +0 -17
  261. package/src/v2/types/react-tool-call-renderer.ts +0 -35
  262. package/src/v2/types/sandbox-function.ts +0 -11
  263. package/tsconfig.json +0 -8
  264. package/tsdown.config.ts +0 -193
  265. package/typedoc.json +0 -4
  266. package/vitest.config.mjs +0 -31
@@ -1,890 +0,0 @@
1
- import React, {
2
- useCallback,
3
- useRef,
4
- useState,
5
- useEffect,
6
- useLayoutEffect,
7
- } from "react";
8
- import { ScrollElementContext } from "./scroll-element-context";
9
- import type { WithSlots, SlotValue } from "../../lib/slots";
10
- import { renderSlot } from "../../lib/slots";
11
- import CopilotChatMessageView from "./CopilotChatMessageView";
12
- import type {
13
- CopilotChatInputProps,
14
- CopilotChatInputMode,
15
- } from "./CopilotChatInput";
16
- import CopilotChatInput from "./CopilotChatInput";
17
- import CopilotChatSuggestionView, {
18
- CopilotChatSuggestionViewProps,
19
- } from "./CopilotChatSuggestionView";
20
- import type { Suggestion } from "@copilotkit/core";
21
- import type { Message } from "@ag-ui/core";
22
- import type { Attachment } from "@copilotkit/shared";
23
- import { CopilotChatAttachmentQueue } from "./CopilotChatAttachmentQueue";
24
- import { twMerge } from "tailwind-merge";
25
- import {
26
- StickToBottom,
27
- useStickToBottom,
28
- useStickToBottomContext,
29
- } from "use-stick-to-bottom";
30
- import { ChevronDown, Upload } from "lucide-react";
31
- import { Button } from "../../components/ui/button";
32
- import { cn } from "../../lib/utils";
33
- import {
34
- useCopilotChatConfiguration,
35
- CopilotChatDefaultLabels,
36
- } from "../../providers/CopilotChatConfigurationProvider";
37
- import { useKeyboardHeight } from "../../hooks/use-keyboard-height";
38
- import { normalizeAutoScroll } from "./normalize-auto-scroll";
39
- import type { AutoScrollMode } from "./normalize-auto-scroll";
40
- import { usePinToSend } from "../../hooks/use-pin-to-send";
41
-
42
- // Vertical gap between the scroll-to-bottom button and the input container.
43
- const SCROLL_BUTTON_OFFSET = 16;
44
-
45
- // Forward declaration for WelcomeScreen component type
46
- export type WelcomeScreenProps = WithSlots<
47
- {
48
- welcomeMessage: React.FC<React.HTMLAttributes<HTMLDivElement>>;
49
- },
50
- {
51
- input: React.ReactElement;
52
- suggestionView: React.ReactElement;
53
- } & React.HTMLAttributes<HTMLDivElement>
54
- >;
55
-
56
- export type CopilotChatViewProps = WithSlots<
57
- {
58
- messageView: typeof CopilotChatMessageView;
59
- scrollView: typeof CopilotChatView.ScrollView;
60
- input: typeof CopilotChatInput;
61
- suggestionView: typeof CopilotChatSuggestionView;
62
- },
63
- {
64
- messages?: Message[];
65
- autoScroll?: AutoScrollMode | boolean;
66
- isRunning?: boolean;
67
- suggestions?: Suggestion[];
68
- suggestionLoadingIndexes?: ReadonlyArray<number>;
69
- onSelectSuggestion?: (suggestion: Suggestion, index: number) => void;
70
- welcomeScreen?: SlotValue<React.FC<WelcomeScreenProps>> | boolean;
71
- // Input behavior props
72
- onSubmitMessage?: (value: string) => void;
73
- onStop?: () => void;
74
- inputMode?: CopilotChatInputMode;
75
- inputValue?: string;
76
- onInputChange?: (value: string) => void;
77
- onStartTranscribe?: () => void;
78
- onCancelTranscribe?: () => void;
79
- onFinishTranscribe?: () => void;
80
- onFinishTranscribeWithAudio?: (audioBlob: Blob) => Promise<void>;
81
- // Attachment props
82
- attachments?: Attachment[];
83
- onRemoveAttachment?: (id: string) => void;
84
- onAddFile?: () => void;
85
- dragOver?: boolean;
86
- onDragOver?: (e: React.DragEvent) => void;
87
- onDragLeave?: (e: React.DragEvent) => void;
88
- onDrop?: (e: React.DragEvent) => void;
89
- /**
90
- * When `true`, suppresses the welcome screen while a thread's initial
91
- * connect is in flight. Prevents the "How can I help you today?" flash
92
- * that would otherwise appear between mounting an empty agent instance
93
- * and the bootstrap messages arriving from /connect.
94
- */
95
- isConnecting?: boolean;
96
- /**
97
- * When `true`, the caller has explicitly picked a thread (via `threadId`
98
- * prop or `CopilotChatConfigurationProvider`). Suppresses the welcome
99
- * screen unconditionally — a caller-managed thread targets a specific
100
- * conversation and should render its messages (or an empty panel during
101
- * connect) rather than a generic "start a new chat" greeting.
102
- */
103
- hasExplicitThreadId?: boolean;
104
- /**
105
- * @deprecated Use the `input` slot's `disclaimer` prop instead:
106
- * ```tsx
107
- * <CopilotChat input={{ disclaimer: MyDisclaimer }} />
108
- * ```
109
- */
110
- disclaimer?: SlotValue<React.FC<React.HTMLAttributes<HTMLDivElement>>>;
111
- } & React.HTMLAttributes<HTMLDivElement>
112
- >;
113
-
114
- function DropOverlay() {
115
- return (
116
- <div
117
- className={cn(
118
- "cpk:absolute cpk:inset-0 cpk:z-50 cpk:pointer-events-none",
119
- "cpk:flex cpk:items-center cpk:justify-center",
120
- "cpk:bg-primary/5 cpk:backdrop-blur-[2px]",
121
- "cpk:border-2 cpk:border-dashed cpk:border-primary/40 cpk:rounded-lg cpk:m-2",
122
- )}
123
- >
124
- <div className="cpk:flex cpk:flex-col cpk:items-center cpk:gap-2 cpk:text-primary/70">
125
- <Upload className="cpk:w-8 cpk:h-8" />
126
- <span className="cpk:text-sm cpk:font-medium">Drop files here</span>
127
- </div>
128
- </div>
129
- );
130
- }
131
-
132
- export function CopilotChatView({
133
- messageView,
134
- input,
135
- scrollView,
136
- suggestionView,
137
- welcomeScreen,
138
- messages = [],
139
- autoScroll = true,
140
- isRunning = false,
141
- suggestions,
142
- suggestionLoadingIndexes,
143
- onSelectSuggestion,
144
- // Input behavior props
145
- onSubmitMessage,
146
- onStop,
147
- inputMode,
148
- inputValue,
149
- onInputChange,
150
- onStartTranscribe,
151
- onCancelTranscribe,
152
- onFinishTranscribe,
153
- onFinishTranscribeWithAudio,
154
- // Attachment props
155
- attachments,
156
- onRemoveAttachment,
157
- onAddFile,
158
- dragOver,
159
- onDragOver,
160
- onDragLeave,
161
- onDrop,
162
- isConnecting = false,
163
- hasExplicitThreadId = false,
164
- // Deprecated — forwarded to input slot
165
- disclaimer,
166
- children,
167
- className,
168
- ...props
169
- }: CopilotChatViewProps) {
170
- // Element-as-state via callback ref. The overlay wrapper only renders on the
171
- // chat-view branch (the welcome-screen branch omits it), so a plain
172
- // useRef + `[]` useEffect would observe `null` on mount whenever the chat
173
- // starts on the welcome screen and never re-attach after the user sends
174
- // their first message — leaving inputContainerHeight at 0 and the scroll
175
- // content's reserved bottom padding at 32px instead of ~input height. The
176
- // result is the last messages scrolling underneath the absolute-positioned
177
- // input pill. Subscribing to element state lets the observer attach (and
178
- // detach) reactively as the overlay mounts/unmounts.
179
- const [inputContainerEl, setInputContainerEl] =
180
- useState<HTMLDivElement | null>(null);
181
- const [inputContainerHeight, setInputContainerHeight] = useState(0);
182
- const [isResizing, setIsResizing] = useState(false);
183
- const resizeTimeoutRef = useRef<NodeJS.Timeout | null>(null);
184
-
185
- // Track keyboard state for mobile
186
- const { isKeyboardOpen, keyboardHeight, availableHeight } =
187
- useKeyboardHeight();
188
-
189
- // Track input container height changes
190
- useEffect(() => {
191
- const element = inputContainerEl;
192
- if (!element) {
193
- // Reset measured height so the scroll content's paddingBottom doesn't
194
- // hold a stale value if the overlay unmounts (e.g. messages cleared
195
- // and the welcome screen returns).
196
- setInputContainerHeight(0);
197
- return;
198
- }
199
-
200
- const resizeObserver = new ResizeObserver((entries) => {
201
- for (const entry of entries) {
202
- const newHeight = entry.contentRect.height;
203
-
204
- // Update height and set resizing state
205
- setInputContainerHeight((prevHeight) => {
206
- if (newHeight !== prevHeight) {
207
- setIsResizing(true);
208
-
209
- // Clear existing timeout
210
- if (resizeTimeoutRef.current) {
211
- clearTimeout(resizeTimeoutRef.current);
212
- }
213
-
214
- // Set isResizing to false after a short delay
215
- resizeTimeoutRef.current = setTimeout(() => {
216
- setIsResizing(false);
217
- }, 250);
218
-
219
- return newHeight;
220
- }
221
- return prevHeight;
222
- });
223
- }
224
- });
225
-
226
- resizeObserver.observe(element);
227
-
228
- // Set initial height
229
- setInputContainerHeight(element.offsetHeight);
230
-
231
- return () => {
232
- resizeObserver.disconnect();
233
- if (resizeTimeoutRef.current) {
234
- clearTimeout(resizeTimeoutRef.current);
235
- }
236
- };
237
- }, [inputContainerEl]);
238
-
239
- const BoundMessageView = renderSlot(messageView, CopilotChatMessageView, {
240
- messages,
241
- isRunning,
242
- });
243
-
244
- const BoundInput = renderSlot(input, CopilotChatInput, {
245
- onSubmitMessage,
246
- onStop,
247
- mode: inputMode,
248
- value: inputValue,
249
- onChange: onInputChange,
250
- isRunning,
251
- onStartTranscribe,
252
- onCancelTranscribe,
253
- onFinishTranscribe,
254
- onFinishTranscribeWithAudio,
255
- onAddFile,
256
- positioning: "static",
257
- keyboardHeight: isKeyboardOpen ? keyboardHeight : 0,
258
- showDisclaimer: true,
259
- // The parent overlay wrapper handles absolute bottom-0 positioning.
260
- // `bottomAnchored` still triggers the license-banner offset padding
261
- // inside CopilotChatInput. The welcome-screen input (below) intentionally
262
- // omits this flag.
263
- bottomAnchored: true,
264
- ...(disclaimer !== undefined ? { disclaimer } : {}),
265
- } as CopilotChatInputProps);
266
-
267
- // Hide suggestions while a thread is connecting or a run is in flight.
268
- // Otherwise, mid-replay (bootstrap stream from /connect) or mid-run, the
269
- // suggestions would render against a still-assembling message tree and
270
- // visibly jump as each final text chunk reflows the layout.
271
- const hasSuggestions =
272
- !isConnecting &&
273
- !isRunning &&
274
- Array.isArray(suggestions) &&
275
- suggestions.length > 0;
276
- const BoundSuggestionView = hasSuggestions
277
- ? renderSlot(suggestionView, CopilotChatSuggestionView, {
278
- suggestions,
279
- loadingIndexes: suggestionLoadingIndexes,
280
- onSelectSuggestion,
281
- className: "cpk:mb-3 cpk:lg:ml-4 cpk:lg:mr-4 cpk:ml-0 cpk:mr-0",
282
- })
283
- : null;
284
-
285
- const BoundScrollView = renderSlot(scrollView, CopilotChatView.ScrollView, {
286
- autoScroll,
287
- inputContainerHeight,
288
- isResizing,
289
- children: (
290
- <div
291
- data-testid="copilot-scroll-content"
292
- style={{
293
- paddingBottom: `${inputContainerHeight + (hasSuggestions ? 4 : 32)}px`,
294
- }}
295
- >
296
- <div className="cpk:max-w-3xl cpk:mx-auto">
297
- {BoundMessageView}
298
- {hasSuggestions ? (
299
- <div className="cpk:pl-0 cpk:pr-4 cpk:sm:px-0 cpk:mt-4">
300
- {BoundSuggestionView}
301
- </div>
302
- ) : null}
303
- </div>
304
- </div>
305
- ),
306
- });
307
-
308
- // Welcome screen logic
309
- const isEmpty = messages.length === 0;
310
- // Type assertion needed because TypeScript doesn't fully propagate `| boolean` through WithSlots
311
- const welcomeScreenDisabled = (welcomeScreen as unknown) === false;
312
- // Suppress the welcome screen (1) while the initial connect is in flight
313
- // and (2) whenever the caller has picked a specific thread. The caller-
314
- // managed case targets a conversation directly, so the generic welcome
315
- // greeting is never the right thing to show — even for a thread that
316
- // happens to have no messages yet.
317
- const shouldShowWelcomeScreen =
318
- isEmpty && !welcomeScreenDisabled && !isConnecting && !hasExplicitThreadId;
319
-
320
- if (shouldShowWelcomeScreen) {
321
- // Create a separate input for welcome screen with static positioning and disclaimer visible
322
- const BoundInputForWelcome = renderSlot(input, CopilotChatInput, {
323
- onSubmitMessage,
324
- onStop,
325
- mode: inputMode,
326
- value: inputValue,
327
- onChange: onInputChange,
328
- isRunning,
329
- onStartTranscribe,
330
- onCancelTranscribe,
331
- onFinishTranscribe,
332
- onFinishTranscribeWithAudio,
333
- onAddFile,
334
- positioning: "static",
335
- showDisclaimer: true,
336
- ...(disclaimer !== undefined ? { disclaimer } : {}),
337
- } as CopilotChatInputProps);
338
-
339
- // Convert boolean `true` to undefined (use default), and exclude `false` since we've checked for it
340
- const welcomeScreenSlot = (
341
- welcomeScreen === true ? undefined : welcomeScreen
342
- ) as SlotValue<React.FC<WelcomeScreenProps>> | undefined;
343
- // Wrap the input with attachment queue above it
344
- const inputWithAttachments = (
345
- <div className="cpk:w-full">
346
- {attachments && attachments.length > 0 && (
347
- <CopilotChatAttachmentQueue
348
- attachments={attachments}
349
- onRemoveAttachment={(id) => onRemoveAttachment?.(id)}
350
- className="cpk:mb-2"
351
- />
352
- )}
353
- {BoundInputForWelcome}
354
- </div>
355
- );
356
-
357
- const BoundWelcomeScreen = renderSlot(
358
- welcomeScreenSlot,
359
- CopilotChatView.WelcomeScreen,
360
- {
361
- input: inputWithAttachments,
362
- suggestionView: BoundSuggestionView ?? <></>,
363
- },
364
- );
365
-
366
- return (
367
- <div
368
- data-copilotkit
369
- data-testid="copilot-chat"
370
- data-copilot-running={isRunning ? "true" : "false"}
371
- onDragOver={onDragOver}
372
- onDragLeave={onDragLeave}
373
- onDrop={onDrop}
374
- className={cn(
375
- "copilotKitChat cpk:relative cpk:h-full cpk:flex cpk:flex-col",
376
- className,
377
- )}
378
- {...props}
379
- >
380
- {dragOver && <DropOverlay />}
381
- {BoundWelcomeScreen}
382
- </div>
383
- );
384
- }
385
-
386
- if (children) {
387
- return (
388
- <div data-copilotkit style={{ display: "contents" }}>
389
- {children({
390
- messageView: BoundMessageView,
391
- input: BoundInput,
392
- scrollView: BoundScrollView,
393
- suggestionView: BoundSuggestionView ?? <></>,
394
- })}
395
- </div>
396
- );
397
- }
398
-
399
- return (
400
- <div
401
- data-copilotkit
402
- data-testid="copilot-chat"
403
- data-copilot-running={isRunning ? "true" : "false"}
404
- onDragOver={onDragOver}
405
- onDragLeave={onDragLeave}
406
- onDrop={onDrop}
407
- className={cn(
408
- "copilotKitChat cpk:relative cpk:h-full cpk:flex cpk:flex-col",
409
- className,
410
- )}
411
- {...props}
412
- >
413
- {dragOver && <DropOverlay />}
414
- {BoundScrollView}
415
-
416
- <div
417
- ref={setInputContainerEl}
418
- data-testid="copilot-input-overlay"
419
- className="cpk:absolute cpk:bottom-0 cpk:left-0 cpk:right-0 cpk:z-20 cpk:pointer-events-none"
420
- >
421
- {attachments && attachments.length > 0 && (
422
- <div className="cpk:max-w-3xl cpk:mx-auto cpk:w-full cpk:pointer-events-auto">
423
- <CopilotChatAttachmentQueue
424
- attachments={attachments}
425
- onRemoveAttachment={(id) => onRemoveAttachment?.(id)}
426
- className="cpk:px-4"
427
- />
428
- </div>
429
- )}
430
- {BoundInput}
431
- </div>
432
- </div>
433
- );
434
- }
435
-
436
- export namespace CopilotChatView {
437
- // Inner component that has access to StickToBottom context
438
- const ScrollContent: React.FC<{
439
- children: React.ReactNode;
440
- scrollToBottomButton?: SlotValue<
441
- React.FC<React.ButtonHTMLAttributes<HTMLButtonElement>>
442
- >;
443
- feather?: SlotValue<React.FC<React.HTMLAttributes<HTMLDivElement>>>;
444
- inputContainerHeight: number;
445
- isResizing: boolean;
446
- }> = ({
447
- children,
448
- scrollToBottomButton,
449
- feather,
450
- inputContainerHeight,
451
- isResizing,
452
- }) => {
453
- const { isAtBottom, scrollToBottom, scrollRef } = useStickToBottomContext();
454
-
455
- // Capture the scroll element in state so the context value is reactive —
456
- // consumers re-render when the element is first set rather than reading a
457
- // ref that silently stays null until after their own layout effects fire.
458
- const [scrollEl, setScrollEl] = useState<HTMLElement | null>(null);
459
- useLayoutEffect(() => {
460
- setScrollEl(scrollRef.current ?? null);
461
- // scrollRef is a stable object; omitting from deps is intentional.
462
- // eslint-disable-next-line react-hooks/exhaustive-deps
463
- }, []);
464
-
465
- const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
466
-
467
- return (
468
- // Provide the scroll element so CopilotChatMessageView can feed it to
469
- // useVirtualizer's getScrollElement. Using state (not the raw ref) means
470
- // the context value updates reactively when the element mounts.
471
- <ScrollElementContext.Provider value={scrollEl}>
472
- <>
473
- <StickToBottom.Content
474
- className="cpk:overflow-y-auto cpk:overflow-x-hidden"
475
- style={{ flex: "1 1 0%", minHeight: 0 }}
476
- >
477
- <div className="cpk:px-4 cpk:sm:px-0 cpk:[div[data-sidebar-chat]_&]:px-8 cpk:[div[data-popup-chat]_&]:px-6">
478
- {children}
479
- </div>
480
- </StickToBottom.Content>
481
-
482
- {BoundFeather}
483
-
484
- {/* Scroll to bottom button - hidden during resize */}
485
- {!isAtBottom && !isResizing && (
486
- <div
487
- className="cpk:absolute cpk:inset-x-0 cpk:flex cpk:justify-center cpk:z-30 cpk:pointer-events-none"
488
- style={{
489
- bottom: `${inputContainerHeight + SCROLL_BUTTON_OFFSET}px`,
490
- }}
491
- >
492
- {renderSlot(
493
- scrollToBottomButton,
494
- CopilotChatView.ScrollToBottomButton,
495
- {
496
- onClick: () => scrollToBottom(),
497
- },
498
- )}
499
- </div>
500
- )}
501
- </>
502
- </ScrollElementContext.Provider>
503
- );
504
- };
505
-
506
- // Internal component for pin-to-send scroll behavior — not exported on CopilotChatView.
507
- const PinToSendScrollContainer: React.FC<
508
- React.HTMLAttributes<HTMLDivElement> & {
509
- scrollRef: React.MutableRefObject<HTMLElement | null>;
510
- contentRef: React.MutableRefObject<HTMLElement | null>;
511
- scrollToBottom: () => void;
512
- scrollToBottomButton?: SlotValue<
513
- React.FC<React.ButtonHTMLAttributes<HTMLButtonElement>>
514
- >;
515
- feather?: SlotValue<React.FC<React.HTMLAttributes<HTMLDivElement>>>;
516
- inputContainerHeight: number;
517
- isResizing: boolean;
518
- nonAutoScrollEl: HTMLElement | null;
519
- nonAutoScrollRefCallback: (el: HTMLElement | null) => void;
520
- showScrollButton: boolean;
521
- }
522
- > = ({
523
- children,
524
- scrollRef,
525
- contentRef,
526
- scrollToBottom,
527
- scrollToBottomButton,
528
- feather,
529
- inputContainerHeight,
530
- isResizing,
531
- nonAutoScrollEl,
532
- nonAutoScrollRefCallback,
533
- showScrollButton,
534
- className,
535
- ...props
536
- }) => {
537
- const spacerRef = useRef<HTMLDivElement>(null);
538
-
539
- usePinToSend({
540
- scrollRef,
541
- contentRef,
542
- spacerRef,
543
- topOffset: 16,
544
- });
545
-
546
- // The feather and scroll-to-bottom button live OUTSIDE the scroll
547
- // container. `position: absolute` children of an `overflow: auto` element
548
- // are positioned relative to the scroll *content*, which means they
549
- // scroll away with it. Placing them as siblings of the scroll container
550
- // (inside a `relative` wrapper) keeps them pinned to the viewport bottom.
551
- const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
552
-
553
- return (
554
- <ScrollElementContext.Provider value={nonAutoScrollEl}>
555
- <div
556
- className={cn(
557
- "cpk:h-full cpk:max-h-full cpk:flex cpk:flex-col cpk:min-h-0 cpk:relative",
558
- className,
559
- )}
560
- >
561
- <div
562
- ref={nonAutoScrollRefCallback}
563
- className="cpk:flex-1 cpk:min-h-0 cpk:overflow-y-auto cpk:overflow-x-hidden"
564
- {...props}
565
- >
566
- <div
567
- ref={contentRef}
568
- className="cpk:px-4 cpk:sm:px-0 cpk:[div[data-sidebar-chat]_&]:px-8 cpk:[div[data-popup-chat]_&]:px-6"
569
- >
570
- {children}
571
- </div>
572
- <div
573
- ref={spacerRef}
574
- data-pin-to-send-spacer
575
- aria-hidden="true"
576
- style={{ height: 0, flex: "0 0 auto" }}
577
- />
578
- </div>
579
- {BoundFeather}
580
- {/* Scroll to bottom button */}
581
- {showScrollButton && !isResizing && (
582
- <div
583
- className="cpk:absolute cpk:inset-x-0 cpk:flex cpk:justify-center cpk:z-30 cpk:pointer-events-none"
584
- style={{
585
- bottom: `${inputContainerHeight + SCROLL_BUTTON_OFFSET}px`,
586
- }}
587
- >
588
- {renderSlot(
589
- scrollToBottomButton,
590
- CopilotChatView.ScrollToBottomButton,
591
- {
592
- onClick: () => scrollToBottom(),
593
- },
594
- )}
595
- </div>
596
- )}
597
- </div>
598
- </ScrollElementContext.Provider>
599
- );
600
- };
601
-
602
- export const ScrollView: React.FC<
603
- React.HTMLAttributes<HTMLDivElement> & {
604
- autoScroll?: AutoScrollMode | boolean;
605
- scrollToBottomButton?: SlotValue<
606
- React.FC<React.ButtonHTMLAttributes<HTMLButtonElement>>
607
- >;
608
- feather?: SlotValue<React.FC<React.HTMLAttributes<HTMLDivElement>>>;
609
- inputContainerHeight?: number;
610
- isResizing?: boolean;
611
- }
612
- > = ({
613
- children,
614
- autoScroll = "pin-to-bottom",
615
- scrollToBottomButton,
616
- feather,
617
- inputContainerHeight = 0,
618
- isResizing = false,
619
- className,
620
- ...props
621
- }) => {
622
- const mode = normalizeAutoScroll(autoScroll);
623
- const [hasMounted, setHasMounted] = useState(false);
624
- // Plain refs for the "none" and "pin-to-send" paths. Do NOT use
625
- // useStickToBottom() here — its internal effects would attach scroll-following
626
- // behavior to these refs and fight pin-to-send. The "pin-to-bottom" path
627
- // gets its refs via <StickToBottom> below, scoped to that branch only.
628
- const scrollRef = useRef<HTMLElement | null>(null);
629
- const contentRef = useRef<HTMLElement | null>(null);
630
- const scrollToBottom = useCallback(() => {
631
- const el = scrollRef.current;
632
- if (el) el.scrollTo({ top: el.scrollHeight, behavior: "smooth" });
633
- }, []);
634
- const [showScrollButton, setShowScrollButton] = useState(false);
635
- // Tracks the scroll container element for the non-autoScroll path so the
636
- // context value is reactive (element state, not a ref).
637
- const [nonAutoScrollEl, setNonAutoScrollEl] = useState<HTMLElement | null>(
638
- null,
639
- );
640
-
641
- // Callback ref that keeps scrollRef in sync with the DOM element while also
642
- // updating context state — eliminates the need for a useLayoutEffect.
643
- const nonAutoScrollRefCallback = useCallback(
644
- (el: HTMLElement | null) => {
645
- scrollRef.current = el;
646
- setNonAutoScrollEl(el);
647
- },
648
- // scrollRef is a stable ref object; safe to omit.
649
- // eslint-disable-next-line react-hooks/exhaustive-deps
650
- [],
651
- );
652
-
653
- useEffect(() => {
654
- setHasMounted(true);
655
- }, []);
656
-
657
- // Monitor scroll position for non-autoscroll mode
658
- useEffect(() => {
659
- if (mode === "pin-to-bottom") return; // Skip for autoscroll mode
660
-
661
- const scrollElement = scrollRef.current;
662
- if (!scrollElement) return;
663
-
664
- const checkScroll = () => {
665
- const atBottom =
666
- scrollElement.scrollHeight -
667
- scrollElement.scrollTop -
668
- scrollElement.clientHeight <
669
- 10;
670
- setShowScrollButton(!atBottom);
671
- };
672
-
673
- checkScroll();
674
- scrollElement.addEventListener("scroll", checkScroll);
675
-
676
- // Also check on resize
677
- const resizeObserver = new ResizeObserver(checkScroll);
678
- resizeObserver.observe(scrollElement);
679
-
680
- return () => {
681
- scrollElement.removeEventListener("scroll", checkScroll);
682
- resizeObserver.disconnect();
683
- };
684
- }, [scrollRef, mode]);
685
-
686
- if (!hasMounted) {
687
- return (
688
- <div className="cpk:h-full cpk:max-h-full cpk:flex cpk:flex-col cpk:min-h-0 cpk:overflow-y-auto cpk:overflow-x-hidden">
689
- <div className="cpk:px-4 cpk:sm:px-0 cpk:[div[data-sidebar-chat]_&]:px-8 cpk:[div[data-popup-chat]_&]:px-6">
690
- {children}
691
- </div>
692
- </div>
693
- );
694
- }
695
-
696
- if (mode === "none") {
697
- const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
698
-
699
- return (
700
- // Provide the scroll element so CopilotChatMessageView can use it for
701
- // useVirtualizer. Element state (not a ref) keeps the context reactive.
702
- <ScrollElementContext.Provider value={nonAutoScrollEl}>
703
- <div
704
- ref={nonAutoScrollRefCallback}
705
- className={cn(
706
- "cpk:h-full cpk:max-h-full cpk:flex cpk:flex-col cpk:min-h-0 cpk:overflow-y-auto cpk:overflow-x-hidden cpk:relative",
707
- className,
708
- )}
709
- {...props}
710
- >
711
- <div
712
- ref={contentRef}
713
- className="cpk:px-4 cpk:sm:px-0 cpk:[div[data-sidebar-chat]_&]:px-8 cpk:[div[data-popup-chat]_&]:px-6"
714
- >
715
- {children}
716
- </div>
717
-
718
- {BoundFeather}
719
-
720
- {/* Scroll to bottom button for manual mode */}
721
- {showScrollButton && !isResizing && (
722
- <div
723
- className="cpk:absolute cpk:inset-x-0 cpk:flex cpk:justify-center cpk:z-30 cpk:pointer-events-none"
724
- style={{
725
- bottom: `${inputContainerHeight + SCROLL_BUTTON_OFFSET}px`,
726
- }}
727
- >
728
- {renderSlot(
729
- scrollToBottomButton,
730
- CopilotChatView.ScrollToBottomButton,
731
- {
732
- onClick: () => scrollToBottom(),
733
- },
734
- )}
735
- </div>
736
- )}
737
- </div>
738
- </ScrollElementContext.Provider>
739
- );
740
- }
741
-
742
- if (mode === "pin-to-send") {
743
- return (
744
- <PinToSendScrollContainer
745
- scrollRef={scrollRef}
746
- contentRef={contentRef}
747
- scrollToBottom={scrollToBottom}
748
- scrollToBottomButton={scrollToBottomButton}
749
- feather={feather}
750
- inputContainerHeight={inputContainerHeight}
751
- isResizing={isResizing}
752
- nonAutoScrollEl={nonAutoScrollEl}
753
- nonAutoScrollRefCallback={nonAutoScrollRefCallback}
754
- showScrollButton={showScrollButton}
755
- className={className}
756
- {...props}
757
- >
758
- {children}
759
- </PinToSendScrollContainer>
760
- );
761
- }
762
-
763
- // mode === "pin-to-bottom" (default)
764
- return (
765
- <StickToBottom
766
- className={cn(
767
- "cpk:flex-1 cpk:max-h-full cpk:flex cpk:flex-col cpk:min-h-0",
768
- className,
769
- )}
770
- resize="smooth"
771
- initial="smooth"
772
- {...props}
773
- >
774
- <ScrollContent
775
- scrollToBottomButton={scrollToBottomButton}
776
- feather={feather}
777
- inputContainerHeight={inputContainerHeight}
778
- isResizing={isResizing}
779
- >
780
- {children}
781
- </ScrollContent>
782
- </StickToBottom>
783
- );
784
- };
785
-
786
- export const ScrollToBottomButton: React.FC<
787
- React.ButtonHTMLAttributes<HTMLButtonElement>
788
- > = ({ className, ...props }) => (
789
- <Button
790
- data-testid="copilot-scroll-to-bottom"
791
- variant="outline"
792
- size="sm"
793
- className={twMerge(
794
- "cpk:rounded-full cpk:w-10 cpk:h-10 cpk:p-0 cpk:pointer-events-auto",
795
- "cpk:bg-white cpk:dark:bg-gray-900",
796
- "cpk:shadow-lg cpk:border cpk:border-gray-200 cpk:dark:border-gray-700",
797
- "cpk:hover:bg-gray-50 cpk:dark:hover:bg-gray-800",
798
- "cpk:flex cpk:items-center cpk:justify-center cpk:cursor-pointer",
799
- className,
800
- )}
801
- {...props}
802
- >
803
- <ChevronDown className="cpk:w-4 cpk:h-4 cpk:text-gray-600 cpk:dark:text-white" />
804
- </Button>
805
- );
806
-
807
- // Default renders an empty div — no visual, but the element is still in the
808
- // tree so a slot override of the form `scrollView={{ feather: "my-class" }}`
809
- // can apply classes (and any consumer with a full component override gets
810
- // the className/style forwarding they expect).
811
- export const Feather: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
812
- className,
813
- ...props
814
- }) => <div className={className} {...props} />;
815
-
816
- export const WelcomeMessage: React.FC<
817
- React.HTMLAttributes<HTMLDivElement>
818
- > = ({ className, ...props }) => {
819
- const config = useCopilotChatConfiguration();
820
- const labels = config?.labels ?? CopilotChatDefaultLabels;
821
-
822
- return (
823
- <h1
824
- className={cn(
825
- "cpk:text-xl cpk:sm:text-2xl cpk:font-medium cpk:text-foreground cpk:text-center",
826
- className,
827
- )}
828
- {...props}
829
- >
830
- {labels.welcomeMessageText}
831
- </h1>
832
- );
833
- };
834
-
835
- export const WelcomeScreen: React.FC<WelcomeScreenProps> = ({
836
- welcomeMessage,
837
- input,
838
- suggestionView,
839
- className,
840
- children,
841
- ...props
842
- }) => {
843
- // Render the welcomeMessage slot internally
844
- const BoundWelcomeMessage = renderSlot(
845
- welcomeMessage,
846
- CopilotChatView.WelcomeMessage,
847
- {},
848
- );
849
-
850
- if (children) {
851
- return (
852
- <div data-copilotkit style={{ display: "contents" }}>
853
- {children({
854
- welcomeMessage: BoundWelcomeMessage,
855
- input,
856
- suggestionView,
857
- className,
858
- ...props,
859
- })}
860
- </div>
861
- );
862
- }
863
-
864
- return (
865
- <div
866
- data-testid="copilot-welcome-screen"
867
- className={cn(
868
- "cpk:flex-1 cpk:flex cpk:flex-col cpk:items-center cpk:justify-center cpk:px-4",
869
- className,
870
- )}
871
- {...props}
872
- >
873
- <div className="cpk:w-full cpk:max-w-3xl cpk:flex cpk:flex-col cpk:items-center">
874
- {/* Welcome message */}
875
- <div className="cpk:mb-6">{BoundWelcomeMessage}</div>
876
-
877
- {/* Input */}
878
- <div className="cpk:w-full">{input}</div>
879
-
880
- {/* Suggestions */}
881
- <div className="cpk:mt-4 cpk:flex cpk:justify-center">
882
- {suggestionView}
883
- </div>
884
- </div>
885
- </div>
886
- );
887
- };
888
- }
889
-
890
- export default CopilotChatView;