@agentscope-ai/chat 1.1.39 → 1.1.41-beta.1764749089549

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 (233) hide show
  1. package/bin/starter_webui.zip +0 -0
  2. package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Builder.tsx +8 -4
  3. package/components/ImageGenerator/index.tsx +1 -1
  4. package/components/Markdown/Markdown.tsx +105 -0
  5. package/components/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.tsx +1 -1
  6. package/components/Markdown/core/components/Null.tsx +1 -0
  7. package/components/Markdown/core/components/Raw.tsx +18 -0
  8. package/components/Markdown/{Markdown → core}/hooks/useCitationsData.tsx +3 -7
  9. package/components/Markdown/core/hooks/useCursorContent.tsx +15 -0
  10. package/components/Markdown/{Markdown/hooks/useTyping.ts → core/hooks/useTyping.tsx} +4 -1
  11. package/components/Markdown/core/index.tsx +18 -0
  12. package/components/Markdown/{plugins → core/plugins}/citations/CitationComponent.tsx +5 -3
  13. package/components/Markdown/{plugins → core/plugins}/citations/index.tsx +3 -4
  14. package/components/Markdown/{plugins → core/plugins}/cursor/Underline.tsx +1 -1
  15. package/components/Markdown/{plugins → core/plugins}/cursor/index.tsx +8 -8
  16. package/components/Markdown/demo/cursor.tsx +2 -3
  17. package/components/Markdown/index.en-US.md +1 -2
  18. package/components/Markdown/index.tsx +6 -0
  19. package/components/Markdown/index.zh-CN.md +1 -2
  20. package/components/Markdown/{Markdown/style.ts → styles.ts} +12 -21
  21. package/components/Markdown/types.tsx +94 -0
  22. package/components/index.ts +1 -3
  23. package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Builder.js +5 -3
  24. package/lib/ImageGenerator/index.js +1 -1
  25. package/lib/Markdown/Markdown.d.ts +4 -0
  26. package/lib/Markdown/Markdown.js +110 -0
  27. package/lib/Markdown/core/components/Null.d.ts +2 -0
  28. package/lib/Markdown/core/components/Null.js +3 -0
  29. package/lib/Markdown/core/components/Raw.d.ts +8 -0
  30. package/lib/Markdown/core/components/Raw.js +13 -0
  31. package/lib/Markdown/core/hooks/useCitationsData.d.ts +6 -0
  32. package/lib/Markdown/{Markdown → core}/hooks/useCitationsData.js +1 -1
  33. package/lib/Markdown/core/hooks/useCursorContent.d.ts +4 -0
  34. package/lib/Markdown/core/hooks/useCursorContent.js +14 -0
  35. package/lib/Markdown/core/hooks/useTyping.d.ts +5 -0
  36. package/lib/Markdown/{Markdown → core}/hooks/useTyping.js +3 -2
  37. package/lib/Markdown/core/index.d.ts +2 -0
  38. package/lib/Markdown/{Markdown/hooks/useAnimation.js → core/index.js} +23 -23
  39. package/lib/Markdown/{plugins → core/plugins}/citations/CitationComponent.js +5 -5
  40. package/lib/Markdown/{plugins → core/plugins}/citations/index.d.ts +1 -2
  41. package/lib/Markdown/{plugins → core/plugins}/citations/index.js +1 -1
  42. package/lib/Markdown/{plugins → core/plugins}/cursor/Dot.js +1 -1
  43. package/lib/Markdown/{plugins → core/plugins}/cursor/Underline.js +1 -1
  44. package/lib/Markdown/{plugins → core/plugins}/cursor/index.js +4 -4
  45. package/lib/Markdown/index.d.ts +2 -1
  46. package/lib/Markdown/styles.js +32 -0
  47. package/lib/Markdown/types.d.ts +78 -0
  48. package/lib/index.d.ts +0 -2
  49. package/lib/index.js +0 -2
  50. package/package.json +7 -31
  51. package/components/AGUI/components/HelpModal/icons.tsx +0 -68
  52. package/components/AGUI/components/HelpModal/index.tsx +0 -1
  53. package/components/AGUI/components/HelpModal/modal.tsx +0 -101
  54. package/components/AGUI/components/chat/Button.tsx +0 -18
  55. package/components/AGUI/components/chat/Chat.tsx +0 -780
  56. package/components/AGUI/components/chat/ChatContext.tsx +0 -248
  57. package/components/AGUI/components/chat/CodeBlock.tsx +0 -406
  58. package/components/AGUI/components/chat/Header.tsx +0 -22
  59. package/components/AGUI/components/chat/Icons.tsx +0 -237
  60. package/components/AGUI/components/chat/ImageUploadQueue.tsx +0 -77
  61. package/components/AGUI/components/chat/Input.tsx +0 -24
  62. package/components/AGUI/components/chat/Markdown.tsx +0 -134
  63. package/components/AGUI/components/chat/Messages.tsx +0 -259
  64. package/components/AGUI/components/chat/Modal.tsx +0 -133
  65. package/components/AGUI/components/chat/Popup.tsx +0 -57
  66. package/components/AGUI/components/chat/PoweredByTag.tsx +0 -29
  67. package/components/AGUI/components/chat/Sidebar.tsx +0 -74
  68. package/components/AGUI/components/chat/Suggestion.tsx +0 -132
  69. package/components/AGUI/components/chat/Suggestions.tsx +0 -20
  70. package/components/AGUI/components/chat/Textarea.tsx +0 -61
  71. package/components/AGUI/components/chat/Window.tsx +0 -152
  72. package/components/AGUI/components/chat/index.tsx +0 -11
  73. package/components/AGUI/components/chat/messages/AssistantMessage.tsx +0 -69
  74. package/components/AGUI/components/chat/messages/RenderActionExecutionMessage.tsx +0 -129
  75. package/components/AGUI/components/chat/messages/RenderAgentStateMessage.tsx +0 -116
  76. package/components/AGUI/components/chat/messages/RenderImageMessage.tsx +0 -64
  77. package/components/AGUI/components/chat/messages/RenderResultMessage.tsx +0 -26
  78. package/components/AGUI/components/chat/messages/RenderTextMessage.tsx +0 -51
  79. package/components/AGUI/components/chat/messages/UserMessage.tsx +0 -10
  80. package/components/AGUI/components/chat/props.ts +0 -186
  81. package/components/AGUI/components/index.ts +0 -1
  82. package/components/AGUI/context/index.ts +0 -1
  83. package/components/AGUI/hooks/index.ts +0 -1
  84. package/components/AGUI/hooks/use-copilot-chat-suggestions.tsx +0 -122
  85. package/components/AGUI/hooks/use-copy-to-clipboard.tsx +0 -29
  86. package/components/AGUI/hooks/use-dark-mode.ts +0 -10
  87. package/components/AGUI/hooks/use-push-to-talk.tsx +0 -166
  88. package/components/AGUI/index.tsx +0 -4
  89. package/components/AGUI/lib/utils.test.ts +0 -7
  90. package/components/AGUI/lib/utils.ts +0 -27
  91. package/components/AGUI/styles.css +0 -0
  92. package/components/AGUI/types/css.ts +0 -0
  93. package/components/AGUI/types/index.ts +0 -1
  94. package/components/AGUI/types/suggestions.ts +0 -6
  95. package/components/Markdown/Markdown/AnimationNode.tsx +0 -89
  96. package/components/Markdown/Markdown/Markdown.tsx +0 -61
  97. package/components/Markdown/Markdown/core/Parser.ts +0 -52
  98. package/components/Markdown/Markdown/core/Renderer.ts +0 -121
  99. package/components/Markdown/Markdown/core/index.ts +0 -4
  100. package/components/Markdown/Markdown/hooks/index.ts +0 -4
  101. package/components/Markdown/Markdown/hooks/useAnimation.tsx +0 -27
  102. package/components/Markdown/Markdown/hooks/useStreaming.ts +0 -503
  103. package/components/Markdown/Markdown/index.tsx +0 -198
  104. package/components/Markdown/Markdown/interface.ts +0 -217
  105. package/components/Markdown/demo/typing.tsx +0 -82
  106. package/components/Markdown/index.ts +0 -1
  107. package/components/Markdown/plugins/latex/index.ts +0 -109
  108. package/components/Markdown/plugins/type.ts +0 -71
  109. package/lib/AGUI/components/HelpModal/icons.d.ts +0 -5
  110. package/lib/AGUI/components/HelpModal/icons.js +0 -84
  111. package/lib/AGUI/components/HelpModal/index.d.ts +0 -1
  112. package/lib/AGUI/components/HelpModal/index.js +0 -1
  113. package/lib/AGUI/components/HelpModal/modal.d.ts +0 -1
  114. package/lib/AGUI/components/HelpModal/modal.js +0 -104
  115. package/lib/AGUI/components/chat/Button.d.ts +0 -2
  116. package/lib/AGUI/components/chat/Button.js +0 -27
  117. package/lib/AGUI/components/chat/Chat.d.ts +0 -242
  118. package/lib/AGUI/components/chat/Chat.js +0 -634
  119. package/lib/AGUI/components/chat/ChatContext.d.ts +0 -142
  120. package/lib/AGUI/components/chat/ChatContext.js +0 -75
  121. package/lib/AGUI/components/chat/CodeBlock.d.ts +0 -12
  122. package/lib/AGUI/components/chat/CodeBlock.js +0 -398
  123. package/lib/AGUI/components/chat/Header.d.ts +0 -2
  124. package/lib/AGUI/components/chat/Header.js +0 -28
  125. package/lib/AGUI/components/chat/Icons.d.ts +0 -16
  126. package/lib/AGUI/components/chat/Icons.js +0 -247
  127. package/lib/AGUI/components/chat/ImageUploadQueue.d.ts +0 -11
  128. package/lib/AGUI/components/chat/ImageUploadQueue.js +0 -65
  129. package/lib/AGUI/components/chat/Input.d.ts +0 -2
  130. package/lib/AGUI/components/chat/Input.js +0 -30
  131. package/lib/AGUI/components/chat/Markdown.d.ts +0 -7
  132. package/lib/AGUI/components/chat/Markdown.js +0 -187
  133. package/lib/AGUI/components/chat/Messages.d.ts +0 -7
  134. package/lib/AGUI/components/chat/Messages.js +0 -242
  135. package/lib/AGUI/components/chat/Modal.d.ts +0 -43
  136. package/lib/AGUI/components/chat/Modal.js +0 -113
  137. package/lib/AGUI/components/chat/Popup.d.ts +0 -49
  138. package/lib/AGUI/components/chat/Popup.js +0 -64
  139. package/lib/AGUI/components/chat/PoweredByTag.d.ts +0 -3
  140. package/lib/AGUI/components/chat/PoweredByTag.js +0 -27
  141. package/lib/AGUI/components/chat/Sidebar.d.ts +0 -2
  142. package/lib/AGUI/components/chat/Sidebar.js +0 -85
  143. package/lib/AGUI/components/chat/Suggestion.d.ts +0 -16
  144. package/lib/AGUI/components/chat/Suggestion.js +0 -146
  145. package/lib/AGUI/components/chat/Suggestions.d.ts +0 -2
  146. package/lib/AGUI/components/chat/Suggestions.js +0 -21
  147. package/lib/AGUI/components/chat/Textarea.d.ts +0 -11
  148. package/lib/AGUI/components/chat/Textarea.js +0 -60
  149. package/lib/AGUI/components/chat/Window.d.ts +0 -2
  150. package/lib/AGUI/components/chat/Window.js +0 -115
  151. package/lib/AGUI/components/chat/index.d.ts +0 -11
  152. package/lib/AGUI/components/chat/index.js +0 -11
  153. package/lib/AGUI/components/chat/messages/AssistantMessage.d.ts +0 -2
  154. package/lib/AGUI/components/chat/messages/AssistantMessage.js +0 -56
  155. package/lib/AGUI/components/chat/messages/RenderActionExecutionMessage.d.ts +0 -2
  156. package/lib/AGUI/components/chat/messages/RenderActionExecutionMessage.js +0 -114
  157. package/lib/AGUI/components/chat/messages/RenderAgentStateMessage.d.ts +0 -2
  158. package/lib/AGUI/components/chat/messages/RenderAgentStateMessage.js +0 -97
  159. package/lib/AGUI/components/chat/messages/RenderImageMessage.d.ts +0 -2
  160. package/lib/AGUI/components/chat/messages/RenderImageMessage.js +0 -61
  161. package/lib/AGUI/components/chat/messages/RenderResultMessage.d.ts +0 -2
  162. package/lib/AGUI/components/chat/messages/RenderResultMessage.js +0 -27
  163. package/lib/AGUI/components/chat/messages/RenderTextMessage.d.ts +0 -2
  164. package/lib/AGUI/components/chat/messages/RenderTextMessage.js +0 -47
  165. package/lib/AGUI/components/chat/messages/UserMessage.d.ts +0 -2
  166. package/lib/AGUI/components/chat/messages/UserMessage.js +0 -9
  167. package/lib/AGUI/components/chat/props.d.ts +0 -157
  168. package/lib/AGUI/components/index.d.ts +0 -1
  169. package/lib/AGUI/components/index.js +0 -1
  170. package/lib/AGUI/context/index.d.ts +0 -1
  171. package/lib/AGUI/context/index.js +0 -1
  172. package/lib/AGUI/hooks/index.d.ts +0 -1
  173. package/lib/AGUI/hooks/index.js +0 -1
  174. package/lib/AGUI/hooks/use-copilot-chat-suggestions.d.ts +0 -87
  175. package/lib/AGUI/hooks/use-copilot-chat-suggestions.js +0 -95
  176. package/lib/AGUI/hooks/use-copy-to-clipboard.d.ts +0 -7
  177. package/lib/AGUI/hooks/use-copy-to-clipboard.js +0 -34
  178. package/lib/AGUI/hooks/use-dark-mode.d.ts +0 -1
  179. package/lib/AGUI/hooks/use-dark-mode.js +0 -4
  180. package/lib/AGUI/hooks/use-push-to-talk.d.ts +0 -16
  181. package/lib/AGUI/hooks/use-push-to-talk.js +0 -260
  182. package/lib/AGUI/index.d.ts +0 -4
  183. package/lib/AGUI/index.js +0 -4
  184. package/lib/AGUI/lib/utils.d.ts +0 -2
  185. package/lib/AGUI/lib/utils.js +0 -52
  186. package/lib/AGUI/styles.css +0 -0
  187. package/lib/AGUI/types/css.d.ts +0 -0
  188. package/lib/AGUI/types/css.js +0 -0
  189. package/lib/AGUI/types/index.d.ts +0 -1
  190. package/lib/AGUI/types/index.js +0 -1
  191. package/lib/AGUI/types/suggestions.d.ts +0 -6
  192. package/lib/AGUI/types/suggestions.js +0 -1
  193. package/lib/Markdown/Markdown/AnimationNode.d.ts +0 -20
  194. package/lib/Markdown/Markdown/AnimationNode.js +0 -84
  195. package/lib/Markdown/Markdown/Markdown.d.ts +0 -4
  196. package/lib/Markdown/Markdown/Markdown.js +0 -58
  197. package/lib/Markdown/Markdown/core/Parser.d.ts +0 -16
  198. package/lib/Markdown/Markdown/core/Parser.js +0 -65
  199. package/lib/Markdown/Markdown/core/Renderer.d.ts +0 -24
  200. package/lib/Markdown/Markdown/core/Renderer.js +0 -137
  201. package/lib/Markdown/Markdown/core/index.d.ts +0 -3
  202. package/lib/Markdown/Markdown/core/index.js +0 -3
  203. package/lib/Markdown/Markdown/hooks/index.d.ts +0 -3
  204. package/lib/Markdown/Markdown/hooks/index.js +0 -3
  205. package/lib/Markdown/Markdown/hooks/useAnimation.d.ts +0 -4
  206. package/lib/Markdown/Markdown/hooks/useCitationsData.d.ts +0 -7
  207. package/lib/Markdown/Markdown/hooks/useStreaming.d.ts +0 -3
  208. package/lib/Markdown/Markdown/hooks/useStreaming.js +0 -521
  209. package/lib/Markdown/Markdown/hooks/useTyping.d.ts +0 -4
  210. package/lib/Markdown/Markdown/index.d.ts +0 -84
  211. package/lib/Markdown/Markdown/index.js +0 -161
  212. package/lib/Markdown/Markdown/interface.d.ts +0 -203
  213. package/lib/Markdown/Markdown/interface.js +0 -1
  214. package/lib/Markdown/Markdown/style.js +0 -32
  215. package/lib/Markdown/plugins/latex/index.d.ts +0 -9
  216. package/lib/Markdown/plugins/latex/index.js +0 -97
  217. package/lib/Markdown/plugins/type.d.ts +0 -60
  218. package/lib/Markdown/plugins/type.js +0 -1
  219. /package/components/Markdown/{Markdown/defaultComponents/DisabledImage.tsx → core/components/DisableImage.tsx} +0 -0
  220. /package/components/Markdown/{Markdown/defaultComponents → core/components}/Media.tsx +0 -0
  221. /package/components/Markdown/{plugins → core/plugins}/cursor/Dot.tsx +0 -0
  222. /package/lib/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.d.ts +0 -0
  223. /package/lib/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.js +0 -0
  224. /package/lib/Markdown/{Markdown/defaultComponents/DisabledImage.d.ts → core/components/DisableImage.d.ts} +0 -0
  225. /package/lib/Markdown/{Markdown/defaultComponents/DisabledImage.js → core/components/DisableImage.js} +0 -0
  226. /package/lib/Markdown/{Markdown/defaultComponents → core/components}/Media.d.ts +0 -0
  227. /package/lib/Markdown/{Markdown/defaultComponents → core/components}/Media.js +0 -0
  228. /package/lib/Markdown/{plugins → core/plugins}/citations/CitationComponent.d.ts +0 -0
  229. /package/lib/Markdown/{plugins → core/plugins}/cursor/Dot.d.ts +0 -0
  230. /package/lib/Markdown/{plugins → core/plugins}/cursor/Underline.d.ts +0 -0
  231. /package/lib/Markdown/{plugins → core/plugins}/cursor/index.d.ts +0 -0
  232. /package/lib/Markdown/{Markdown/style.d.ts → styles.d.ts} +0 -0
  233. /package/lib/{AGUI/components/chat/props.js → Markdown/types.js} +0 -0
@@ -1,20 +0,0 @@
1
- import { Suggestion } from "./Suggestion";
2
- import React from "react";
3
- import { RenderSuggestionsListProps } from "./props";
4
-
5
- export function Suggestions({ suggestions, onSuggestionClick }: RenderSuggestionsListProps) {
6
- return (
7
- <div className="suggestions">
8
- {suggestions.map((suggestion, index) => (
9
- <Suggestion
10
- key={index}
11
- title={suggestion.title}
12
- message={suggestion.message}
13
- partial={suggestion.partial}
14
- className={suggestion.className}
15
- onClick={() => onSuggestionClick(suggestion.message)}
16
- />
17
- ))}
18
- </div>
19
- );
20
- }
@@ -1,61 +0,0 @@
1
- import React, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from "react";
2
-
3
- interface AutoResizingTextareaProps {
4
- maxRows?: number;
5
- placeholder?: string;
6
- value: string;
7
- onChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
8
- onKeyDown?: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;
9
- autoFocus?: boolean;
10
- }
11
-
12
- const AutoResizingTextarea = forwardRef<HTMLTextAreaElement, AutoResizingTextareaProps>(
13
- ({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
14
- const internalTextareaRef = useRef<HTMLTextAreaElement>(null);
15
- const [maxHeight, setMaxHeight] = useState<number>(0);
16
-
17
- useImperativeHandle(ref, () => internalTextareaRef.current as HTMLTextAreaElement);
18
-
19
- useEffect(() => {
20
- const calculateMaxHeight = () => {
21
- const textarea = internalTextareaRef.current;
22
- if (textarea) {
23
- textarea.style.height = "auto";
24
- const singleRowHeight = textarea.scrollHeight;
25
- setMaxHeight(singleRowHeight * maxRows);
26
- if (autoFocus) {
27
- textarea.focus();
28
- }
29
- }
30
- };
31
-
32
- calculateMaxHeight();
33
- }, [maxRows]);
34
-
35
- useEffect(() => {
36
- const textarea = internalTextareaRef.current;
37
- if (textarea) {
38
- textarea.style.height = "auto";
39
- textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
40
- }
41
- }, [value, maxHeight]);
42
-
43
- return (
44
- <textarea
45
- ref={internalTextareaRef}
46
- value={value}
47
- onChange={onChange}
48
- onKeyDown={onKeyDown}
49
- placeholder={placeholder}
50
- style={{
51
- overflow: "auto",
52
- resize: "none",
53
- maxHeight: `${maxHeight}px`,
54
- }}
55
- rows={1}
56
- />
57
- );
58
- },
59
- );
60
-
61
- export default AutoResizingTextarea;
@@ -1,152 +0,0 @@
1
- import React, { useCallback, useEffect } from "react";
2
- import { WindowProps } from "./props";
3
- import { useChatContext } from "./ChatContext";
4
- import { useCopilotContext } from "@copilotkit/react-core";
5
- import { isMacOS } from "@copilotkit/shared";
6
-
7
- export const Window = ({
8
- children,
9
- clickOutsideToClose,
10
- shortcut,
11
- hitEscapeToClose,
12
- }: WindowProps) => {
13
- const windowRef = React.useRef<HTMLDivElement>(null);
14
- const context = useCopilotContext();
15
-
16
- const { open, setOpen } = useChatContext();
17
-
18
- const handleClickOutside = useCallback(
19
- (event: MouseEvent) => {
20
- if (!clickOutsideToClose) {
21
- return;
22
- }
23
-
24
- const parentElement = windowRef.current?.parentElement;
25
-
26
- let className = "";
27
- if (event.target instanceof HTMLElement) {
28
- className = event.target.className;
29
- }
30
-
31
- if (
32
- open &&
33
- parentElement &&
34
- !parentElement.contains(event.target as any) &&
35
- // prevent closing the window when clicking on the debug menu
36
- !className.includes("copilotKitDebugMenu")
37
- ) {
38
- setOpen(false);
39
- }
40
- },
41
- [clickOutsideToClose, open, setOpen],
42
- );
43
-
44
- const handleKeyDown = useCallback(
45
- (event: KeyboardEvent) => {
46
- const target = event.target as HTMLElement;
47
- const isInput =
48
- target.tagName === "INPUT" ||
49
- target.tagName === "SELECT" ||
50
- target.tagName === "TEXTAREA" ||
51
- target.isContentEditable;
52
-
53
- const isDescendantOfWrapper = windowRef.current?.contains(target);
54
-
55
- if (
56
- open &&
57
- event.key === "Escape" &&
58
- (!isInput || isDescendantOfWrapper) &&
59
- hitEscapeToClose
60
- ) {
61
- setOpen(false);
62
- } else if (
63
- event.key === shortcut &&
64
- ((isMacOS() && event.metaKey) || (!isMacOS() && event.ctrlKey)) &&
65
- (!isInput || isDescendantOfWrapper)
66
- ) {
67
- setOpen(!open);
68
- }
69
- },
70
- [hitEscapeToClose, shortcut, open, setOpen],
71
- );
72
-
73
- const adjustForMobile = useCallback(() => {
74
- const copilotKitWindow = windowRef.current;
75
- const vv = window.visualViewport;
76
- if (!copilotKitWindow || !vv) {
77
- return;
78
- }
79
-
80
- if (window.innerWidth < 640 && open) {
81
- copilotKitWindow.style.height = `${vv.height}px`;
82
- copilotKitWindow.style.left = `${vv.offsetLeft}px`;
83
- copilotKitWindow.style.top = `${vv.offsetTop}px`;
84
-
85
- document.body.style.position = "fixed";
86
- document.body.style.width = "100%";
87
- document.body.style.height = `${window.innerHeight}px`;
88
- document.body.style.overflow = "hidden";
89
- document.body.style.touchAction = "none";
90
-
91
- // Prevent scrolling on iOS
92
- document.body.addEventListener("touchmove", preventScroll, {
93
- passive: false,
94
- });
95
- } else {
96
- copilotKitWindow.style.height = "";
97
- copilotKitWindow.style.left = "";
98
- copilotKitWindow.style.top = "";
99
- document.body.style.position = "";
100
- document.body.style.height = "";
101
- document.body.style.width = "";
102
- document.body.style.overflow = "";
103
- document.body.style.top = "";
104
- document.body.style.touchAction = "";
105
-
106
- document.body.removeEventListener("touchmove", preventScroll);
107
- }
108
- }, [open]);
109
-
110
- useEffect(() => {
111
- document.addEventListener("mousedown", handleClickOutside);
112
- document.addEventListener("keydown", handleKeyDown);
113
- if (window.visualViewport) {
114
- window.visualViewport.addEventListener("resize", adjustForMobile);
115
- adjustForMobile();
116
- }
117
-
118
- return () => {
119
- document.removeEventListener("mousedown", handleClickOutside);
120
- document.removeEventListener("keydown", handleKeyDown);
121
- if (window.visualViewport) {
122
- window.visualViewport.removeEventListener("resize", adjustForMobile);
123
- }
124
- };
125
- }, [adjustForMobile, handleClickOutside, handleKeyDown]);
126
-
127
- return (
128
- <div className={`copilotKitWindow ${open ? " open" : ""}`} ref={windowRef}>
129
- {children}
130
- </div>
131
- );
132
- };
133
-
134
- const preventScroll = (event: TouchEvent): void => {
135
- let targetElement = event.target as Element;
136
-
137
- // Function to check if the target has the parent with a given class
138
- const hasParentWithClass = (element: Element, className: string): boolean => {
139
- while (element && element !== document.body) {
140
- if (element.classList.contains(className)) {
141
- return true;
142
- }
143
- element = element.parentElement!;
144
- }
145
- return false;
146
- };
147
-
148
- // Check if the target of the touch event is inside an element with the 'copilotKitMessages' class
149
- if (!hasParentWithClass(targetElement, "copilotKitMessages")) {
150
- event.preventDefault();
151
- }
152
- };
@@ -1,11 +0,0 @@
1
- export * from "./props";
2
- export { CopilotPopup } from "./Popup";
3
- export { CopilotSidebar } from "./Sidebar";
4
- export { CopilotChat } from "./Chat";
5
- export { Markdown } from "./Markdown";
6
- export { AssistantMessage } from "./messages/AssistantMessage";
7
- export { UserMessage } from "./messages/UserMessage";
8
- export { useChatContext } from "./ChatContext";
9
- export { RenderImageMessage } from "./messages/RenderImageMessage";
10
- export { Suggestions as RenderSuggestionsList } from "./Suggestions";
11
- export { Suggestion as RenderSuggestion } from "./Suggestion";
@@ -1,69 +0,0 @@
1
- import { AssistantMessageProps } from "../props";
2
- import { Bubble } from "@agentscope-ai/chat";
3
- import compact from 'lodash/compact'
4
-
5
- export const AssistantMessage = (props: AssistantMessageProps) => {
6
- if (props.subComponent) return props.subComponent;
7
-
8
- const hasThink = props.rawData.content?.includes('<think>');
9
- const msgStatus = props.isCurrentMessage && props.isGenerating ? "generating" : void 0;
10
-
11
- if (!hasThink) return <Bubble
12
- role="assistant"
13
- content={props.rawData.content}
14
- id={props.rawData.id}
15
- msgStatus={msgStatus}
16
- ></Bubble>;
17
-
18
- const hasThinkEnd = props.rawData.content.includes('</think>');
19
-
20
- const { content, think } = parseThinkContentIf(props.rawData.content);
21
-
22
- return <Bubble
23
- role="assistant"
24
- cards={compact([
25
- hasThink && {
26
- code: 'DeepThink',
27
- data: {
28
- title: 'AI思考',
29
- loading: !hasThinkEnd,
30
- content: think,
31
- },
32
- },
33
- {
34
- code: 'Text',
35
- data: {
36
- content: content,
37
- msgStatus: msgStatus
38
- },
39
- }
40
- ])}
41
- id={props.rawData.id}
42
- msgStatus={msgStatus}
43
- ></Bubble>;
44
- };
45
-
46
- function parseThinkContentIf(content) {
47
- const reg0 = /<think>([\s\S]*?)<\/think>/g;
48
- const reg1 = /<think>([\s\S]*)/g;
49
-
50
-
51
-
52
- const reg0Result = content.match(reg0);
53
- if (reg0Result) return {
54
- think: reg0Result[0].replace(/<think>/, '').replace(/<\/think>/g, ''),
55
- content: content.replace(reg0Result[0], '')
56
- }
57
-
58
- const reg1Result = content.match(reg1);
59
-
60
- if (reg1Result) return {
61
- think: reg1Result[0].replace(/<think>/, ''),
62
- content: content.replace(reg1Result[0], '')
63
- }
64
-
65
- return {
66
- think: '',
67
- content
68
- }
69
- }
@@ -1,129 +0,0 @@
1
- import { MessageStatusCode } from "@copilotkit/runtime-client-gql";
2
- import { RenderMessageProps } from "../props";
3
- import { RenderFunctionStatus, useCopilotContext } from "@copilotkit/react-core";
4
- import { AssistantMessage as DefaultAssistantMessage } from "./AssistantMessage";
5
-
6
- export function RenderActionExecutionMessage({
7
- AssistantMessage = DefaultAssistantMessage,
8
- ...props
9
- }: RenderMessageProps) {
10
- const { chatComponentsCache } = useCopilotContext();
11
- const { message, inProgress, index, isCurrentMessage, actionResult } = props;
12
-
13
- if (message.isActionExecutionMessage()) {
14
- if (
15
- chatComponentsCache.current !== null &&
16
- (chatComponentsCache.current.actions[message.name] ||
17
- chatComponentsCache.current.actions["*"])
18
- ) {
19
- const render =
20
- chatComponentsCache.current.actions[message.name] ||
21
- chatComponentsCache.current.actions["*"];
22
- // render a static string
23
- if (typeof render === "string") {
24
-
25
- // when render is static, we show it only when in progress
26
- if (isCurrentMessage && inProgress) {
27
- return (
28
- <AssistantMessage
29
- rawData={message}
30
- key={index}
31
- data-message-role="assistant"
32
- isLoading={false}
33
- isGenerating={true}
34
- message={render}
35
- />
36
- );
37
- }
38
- // Done - silent by default to avoid a series of "done" messages
39
- else {
40
- return null;
41
- }
42
- }
43
- // render is a function
44
- else {
45
- const args = message.arguments;
46
-
47
- let status: RenderFunctionStatus = "inProgress";
48
-
49
- if (actionResult !== undefined) {
50
- status = "complete";
51
- } else if (message.status.code !== MessageStatusCode.Pending) {
52
- status = "executing";
53
- }
54
-
55
- try {
56
- const toRender = render({
57
- status: status as any, // Cast to any as RenderFunctionStatus is a union that can be complex to narrow here
58
- args,
59
- result: actionResult,
60
- name: message.name,
61
- messageId: message.id, // Pass messageId for HITL action correlation
62
- } as any);
63
-
64
- // No result and complete: stay silent
65
- if (!toRender && status === "complete") {
66
- return null;
67
- }
68
- if (typeof toRender === "string") {
69
- return (
70
- <AssistantMessage
71
- rawData={message}
72
- data-message-role="assistant"
73
- key={index}
74
- isLoading={false}
75
- isGenerating={false}
76
- message={toRender}
77
- />
78
- );
79
- } else {
80
- return (
81
- <AssistantMessage
82
- rawData={message}
83
- data-message-role="action-render"
84
- key={index}
85
- isLoading={false}
86
- isGenerating={false}
87
- subComponent={toRender}
88
- />
89
- );
90
- }
91
- } catch (e) {
92
- // It's useful to log this error for developers to debug their custom render functions
93
- console.error(`Error executing render function for action ${message.name}: ${e}`);
94
- return (
95
- <AssistantMessage
96
- rawData={message}
97
- data-message-role="assistant"
98
- key={index}
99
- isLoading={false}
100
- isGenerating={false}
101
- subComponent={
102
- <div className="copilotKitMessage copilotKitAssistantMessage">
103
- <b>❌ Error executing render function for action {message.name}:</b>
104
- <pre>{e instanceof Error ? e.message : String(e)}</pre>
105
- </div>
106
- }
107
- />
108
- );
109
- }
110
- }
111
- }
112
- // No render function found- show the default message
113
- else if (!inProgress || !isCurrentMessage) {
114
- // Done - silent by default to avoid a series of "done" messages
115
- return null;
116
- } else {
117
- // In progress
118
- return (
119
- <AssistantMessage
120
- rawData={message}
121
- key={index}
122
- data-message-role="assistant"
123
- isLoading={true}
124
- isGenerating={true}
125
- />
126
- );
127
- }
128
- }
129
- }
@@ -1,116 +0,0 @@
1
- import { RenderMessageProps } from "../props";
2
- import { CoagentInChatRenderFunction, useCopilotContext } from "@copilotkit/react-core";
3
- import { AssistantMessage as DefaultAssistantMessage } from "./AssistantMessage";
4
-
5
- export function RenderAgentStateMessage({
6
- AssistantMessage = DefaultAssistantMessage,
7
- ...props
8
- }: RenderMessageProps) {
9
- const { chatComponentsCache } = useCopilotContext();
10
- const { message, inProgress, index, isCurrentMessage } = props;
11
-
12
- if (message.isAgentStateMessage()) {
13
- let render: string | CoagentInChatRenderFunction | undefined;
14
-
15
- if (chatComponentsCache.current !== null) {
16
- render =
17
- chatComponentsCache.current.coAgentStateRenders[
18
- `${message.agentName}-${message.nodeName}`
19
- ] || chatComponentsCache.current.coAgentStateRenders[`${message.agentName}-global`];
20
- }
21
-
22
- if (render) {
23
- // render a static string
24
- if (typeof render === "string") {
25
- // when render is static, we show it only when in progress
26
- if (isCurrentMessage && inProgress) {
27
- return (
28
- <AssistantMessage
29
- rawData={message}
30
- message={render}
31
- data-message-role="assistant"
32
- key={index}
33
- isLoading={true}
34
- isGenerating={true}
35
- />
36
- );
37
- }
38
- // Done - silent by default to avoid a series of "done" messages
39
- else {
40
- return null;
41
- }
42
- }
43
- // render is a function
44
- else {
45
- const state = message.state;
46
-
47
- let status = message.active ? "inProgress" : "complete";
48
-
49
- const toRender = render({
50
- status: status as any,
51
- state,
52
- nodeName: message.nodeName,
53
- });
54
-
55
- // No result and complete: stay silent
56
- if (!toRender && status === "complete") {
57
- return null;
58
- }
59
-
60
- if (!toRender && isCurrentMessage && inProgress) {
61
- return (
62
- <AssistantMessage
63
- data-message-role="assistant"
64
- key={index}
65
- rawData={message}
66
- isLoading={true}
67
- isGenerating={true}
68
- />
69
- );
70
- } else if (!toRender) {
71
- return null;
72
- }
73
-
74
- if (typeof toRender === "string") {
75
- return (
76
- <AssistantMessage
77
- rawData={message}
78
- message={toRender}
79
- isLoading={true}
80
- isGenerating={true}
81
- data-message-role="assistant"
82
- key={index}
83
- />
84
- );
85
- } else {
86
- return (
87
- <AssistantMessage
88
- rawData={message}
89
- data-message-role="agent-state-render"
90
- key={index}
91
- isLoading={false}
92
- isGenerating={false}
93
- subComponent={toRender}
94
- />
95
- );
96
- }
97
- }
98
- }
99
- // No render function found- show the default message
100
- else if (!inProgress || !isCurrentMessage) {
101
- // Done - silent by default to avoid a series of "done" messages
102
- return null;
103
- } else {
104
- // In progress
105
- return (
106
- <AssistantMessage
107
- rawData={message}
108
- isLoading={true}
109
- isGenerating={true}
110
- data-message-role="assistant"
111
- key={index}
112
- />
113
- );
114
- }
115
- }
116
- }
@@ -1,64 +0,0 @@
1
- import { RenderMessageProps } from "../props";
2
- import { UserMessage as DefaultUserMessage } from "./UserMessage";
3
- import { AssistantMessage as DefaultAssistantMessage } from "./AssistantMessage";
4
-
5
- export function RenderImageMessage({
6
- UserMessage = DefaultUserMessage,
7
- AssistantMessage = DefaultAssistantMessage,
8
- ...props
9
- }: RenderMessageProps) {
10
- const {
11
- message,
12
- inProgress,
13
- index,
14
- isCurrentMessage,
15
- onRegenerate,
16
- onCopy,
17
- onThumbsUp,
18
- onThumbsDown,
19
- } = props;
20
-
21
- if (message.isImageMessage()) {
22
- const imageData = `data:${message.format};base64,${message.bytes}`;
23
- const imageComponent = (
24
- <div className="copilotKitImage">
25
- <img
26
- src={imageData}
27
- alt="User uploaded image"
28
- style={{ maxWidth: "100%", maxHeight: "300px", borderRadius: "8px" }}
29
- />
30
- </div>
31
- );
32
-
33
- if (message.role === "user") {
34
- return (
35
- <UserMessage
36
- key={index}
37
- data-message-role="user"
38
- message=""
39
- rawData={message}
40
- subComponent={imageComponent}
41
- />
42
- );
43
- } else if (message.role === "assistant") {
44
- return (
45
- <AssistantMessage
46
- key={index}
47
- data-message-role="assistant"
48
- message=""
49
- rawData={message}
50
- subComponent={imageComponent}
51
- isLoading={inProgress && isCurrentMessage && !message.bytes}
52
- isGenerating={inProgress && isCurrentMessage && !!message.bytes}
53
- isCurrentMessage={isCurrentMessage}
54
- onRegenerate={() => onRegenerate?.(message.id)}
55
- onCopy={onCopy}
56
- onThumbsUp={onThumbsUp}
57
- onThumbsDown={onThumbsDown}
58
- />
59
- );
60
- }
61
- }
62
-
63
- return null;
64
- }
@@ -1,26 +0,0 @@
1
- import { RenderMessageProps } from "../props";
2
- import { AssistantMessage as DefaultAssistantMessage } from "./AssistantMessage";
3
-
4
- export function RenderResultMessage({
5
- AssistantMessage = DefaultAssistantMessage,
6
- ...props
7
- }: RenderMessageProps) {
8
- const { message, inProgress, index, isCurrentMessage } = props;
9
-
10
- if (message.isResultMessage() && inProgress && isCurrentMessage) {
11
- return (
12
- <AssistantMessage
13
- key={index}
14
- data-message-role="assistant"
15
- rawData={message}
16
- isLoading={true}
17
- isGenerating={true}
18
- />
19
- );
20
- }
21
-
22
- // Avoid 'Nothing was returned from render' React error
23
- else {
24
- return null;
25
- }
26
- }