@agentscope-ai/chat 1.1.20 → 1.1.22

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 (335) hide show
  1. package/bin/client.js +1 -1
  2. package/components/AGUI/components/HelpModal/icons.tsx +68 -0
  3. package/components/AGUI/components/HelpModal/index.tsx +1 -0
  4. package/components/AGUI/components/HelpModal/modal.tsx +101 -0
  5. package/components/AGUI/components/chat/Button.tsx +18 -0
  6. package/components/AGUI/components/chat/Chat.tsx +780 -0
  7. package/components/AGUI/components/chat/ChatContext.tsx +248 -0
  8. package/components/AGUI/components/chat/CodeBlock.tsx +406 -0
  9. package/components/AGUI/components/chat/Header.tsx +22 -0
  10. package/components/AGUI/components/chat/Icons.tsx +237 -0
  11. package/components/AGUI/components/chat/ImageUploadQueue.tsx +77 -0
  12. package/components/AGUI/components/chat/Input.tsx +24 -0
  13. package/components/AGUI/components/chat/Markdown.tsx +134 -0
  14. package/components/AGUI/components/chat/Messages.tsx +259 -0
  15. package/components/AGUI/components/chat/Modal.tsx +133 -0
  16. package/components/AGUI/components/chat/Popup.tsx +57 -0
  17. package/components/AGUI/components/chat/PoweredByTag.tsx +29 -0
  18. package/components/AGUI/components/chat/Sidebar.tsx +74 -0
  19. package/components/AGUI/components/chat/Suggestion.tsx +132 -0
  20. package/components/AGUI/components/chat/Suggestions.tsx +20 -0
  21. package/components/AGUI/components/chat/Textarea.tsx +61 -0
  22. package/components/AGUI/components/chat/Window.tsx +152 -0
  23. package/components/AGUI/components/chat/index.tsx +11 -0
  24. package/components/AGUI/components/chat/messages/AssistantMessage.tsx +69 -0
  25. package/components/AGUI/components/chat/messages/RenderActionExecutionMessage.tsx +129 -0
  26. package/components/AGUI/components/chat/messages/RenderAgentStateMessage.tsx +116 -0
  27. package/components/AGUI/components/chat/messages/RenderImageMessage.tsx +64 -0
  28. package/components/AGUI/components/chat/messages/RenderResultMessage.tsx +26 -0
  29. package/components/AGUI/components/chat/messages/RenderTextMessage.tsx +51 -0
  30. package/components/AGUI/components/chat/messages/UserMessage.tsx +10 -0
  31. package/components/AGUI/components/chat/props.ts +186 -0
  32. package/components/AGUI/components/index.ts +1 -0
  33. package/components/AGUI/context/index.ts +1 -0
  34. package/components/AGUI/hooks/index.ts +1 -0
  35. package/components/AGUI/hooks/use-copilot-chat-suggestions.tsx +122 -0
  36. package/components/AGUI/hooks/use-copy-to-clipboard.tsx +29 -0
  37. package/components/AGUI/hooks/use-dark-mode.ts +10 -0
  38. package/components/AGUI/hooks/use-push-to-talk.tsx +166 -0
  39. package/components/AGUI/index.tsx +4 -0
  40. package/components/AGUI/lib/utils.test.ts +7 -0
  41. package/components/AGUI/lib/utils.ts +27 -0
  42. package/components/AGUI/styles.css +0 -0
  43. package/components/AGUI/types/css.ts +0 -0
  44. package/components/AGUI/types/index.ts +1 -0
  45. package/components/AGUI/types/suggestions.ts +6 -0
  46. package/components/Accordion/Accordion.tsx +203 -0
  47. package/components/Accordion/BodyContent.tsx +28 -0
  48. package/components/Accordion/DeepThinking.tsx +91 -0
  49. package/components/Accordion/SoftLightTitle.tsx +13 -0
  50. package/components/Accordion/demo/search.tsx +39 -0
  51. package/components/Accordion/demo/steps.tsx +135 -0
  52. package/components/Accordion/demo/thinking.tsx +62 -0
  53. package/components/Accordion/index.en-US.md +34 -0
  54. package/components/Accordion/index.tsx +3 -0
  55. package/components/Accordion/index.zh-CN.md +34 -0
  56. package/components/Accordion/style.ts +208 -0
  57. package/components/AgentScopeRuntimeWebUI/demo/index.tsx +4 -0
  58. package/components/AgentScopeRuntimeWebUI/index.tsx +3 -0
  59. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Request/Builder.tsx +82 -0
  60. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Request/Card.tsx +52 -0
  61. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Actions.tsx +39 -0
  62. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Builder.tsx +205 -0
  63. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Card.tsx +44 -0
  64. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Error.tsx +7 -0
  65. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Message.tsx +23 -0
  66. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Reasoning.tsx +16 -0
  67. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Tool.tsx +19 -0
  68. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/index.tsx +0 -0
  69. package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/types.tsx +100 -0
  70. package/components/AgentScopeRuntimeWebUI/lib/Chat/Input/index.tsx +77 -0
  71. package/components/AgentScopeRuntimeWebUI/lib/Chat/Input/useAttachments.tsx +53 -0
  72. package/components/AgentScopeRuntimeWebUI/lib/Chat/MessageList/index.tsx +30 -0
  73. package/components/AgentScopeRuntimeWebUI/lib/Chat/Welcome/index.tsx +66 -0
  74. package/components/AgentScopeRuntimeWebUI/lib/Chat/Welcome/styles.ts +51 -0
  75. package/components/AgentScopeRuntimeWebUI/lib/Chat/hooks/index.tsx +5 -0
  76. package/components/AgentScopeRuntimeWebUI/lib/Chat/hooks/useChatController.tsx +130 -0
  77. package/components/AgentScopeRuntimeWebUI/lib/Chat/hooks/useChatMessageHandler.tsx +87 -0
  78. package/components/AgentScopeRuntimeWebUI/lib/Chat/hooks/useChatRequest.tsx +114 -0
  79. package/components/AgentScopeRuntimeWebUI/lib/Chat/hooks/useChatSessionHandler.tsx +50 -0
  80. package/components/AgentScopeRuntimeWebUI/lib/Chat/index.tsx +18 -0
  81. package/components/AgentScopeRuntimeWebUI/lib/Chat/styles.tsx +59 -0
  82. package/components/AgentScopeRuntimeWebUI/lib/ChatAnywhere/ComposedProvider.tsx +27 -0
  83. package/components/AgentScopeRuntimeWebUI/lib/ChatAnywhere/index.tsx +29 -0
  84. package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereControl.tsx +0 -0
  85. package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereInputContext.tsx +27 -0
  86. package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereLayoutContext.tsx +27 -0
  87. package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereMessagesContext.tsx +82 -0
  88. package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereOptionsContext.tsx +76 -0
  89. package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereSessionsContext.tsx +111 -0
  90. package/components/AgentScopeRuntimeWebUI/lib/Context/useChatAnywhereEventEmitter.tsx +30 -0
  91. package/components/AgentScopeRuntimeWebUI/lib/Header/index.tsx +45 -0
  92. package/components/AgentScopeRuntimeWebUI/lib/Header/styles.ts +23 -0
  93. package/components/AgentScopeRuntimeWebUI/lib/Layout/index.tsx +45 -0
  94. package/components/AgentScopeRuntimeWebUI/lib/Layout/styles.tsx +104 -0
  95. package/components/AgentScopeRuntimeWebUI/lib/Sessions/index.tsx +114 -0
  96. package/components/AgentScopeRuntimeWebUI/lib/Sessions/styles.tsx +0 -0
  97. package/components/AgentScopeRuntimeWebUI/lib/demo/OptionsPanel/FormItem.tsx +37 -0
  98. package/components/AgentScopeRuntimeWebUI/lib/demo/OptionsPanel/OptionsEditor.tsx +163 -0
  99. package/components/AgentScopeRuntimeWebUI/lib/demo/OptionsPanel/defaultConfig.ts +43 -0
  100. package/components/AgentScopeRuntimeWebUI/lib/demo/OptionsPanel/index.tsx +27 -0
  101. package/components/AgentScopeRuntimeWebUI/lib/demo/index.tsx +57 -0
  102. package/components/AgentScopeRuntimeWebUI/lib/demo/sessionApi/index.ts +51 -0
  103. package/components/AgentScopeRuntimeWebUI/lib/types/IChatAnywhere.ts +358 -0
  104. package/components/AgentScopeRuntimeWebUI/lib/types/IMessages.tsx +52 -0
  105. package/components/AgentScopeRuntimeWebUI/lib/types/ISessions.tsx +29 -0
  106. package/components/AgentScopeRuntimeWebUI/lib/types/index.tsx +3 -0
  107. package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/FormItem.tsx +37 -0
  108. package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/OptionsEditor.tsx +163 -0
  109. package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/defaultConfig.ts +43 -0
  110. package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/index.tsx +27 -0
  111. package/components/AgentScopeRuntimeWebUI/starter/index.tsx +57 -0
  112. package/components/AgentScopeRuntimeWebUI/starter/sessionApi/index.ts +51 -0
  113. package/components/Attachments/DropArea.tsx +97 -0
  114. package/components/Attachments/FileList/AudioIcon.tsx +20 -0
  115. package/components/Attachments/FileList/FileListCard.tsx +270 -0
  116. package/components/Attachments/FileList/Progress.tsx +30 -0
  117. package/components/Attachments/FileList/VideoIcon.tsx +20 -0
  118. package/components/Attachments/FileList/index.tsx +201 -0
  119. package/components/Attachments/PlaceholderUploader.tsx +124 -0
  120. package/components/Attachments/SilentUploader.tsx +39 -0
  121. package/components/Attachments/context.tsx +11 -0
  122. package/components/Attachments/demo/basic.tsx +71 -0
  123. package/components/Attachments/index.en-US.md.bk +10 -0
  124. package/components/Attachments/index.tsx +274 -0
  125. package/components/Attachments/index.zh-CN.md.bk +10 -0
  126. package/components/Attachments/style/fileCard.ts +163 -0
  127. package/components/Attachments/style/index.ts +232 -0
  128. package/components/Attachments/util.ts +56 -0
  129. package/components/Bubble/Avatar.tsx +39 -0
  130. package/components/Bubble/Bubble.tsx +131 -0
  131. package/components/Bubble/BubbleList.tsx +105 -0
  132. package/components/Bubble/Cards.tsx +61 -0
  133. package/components/Bubble/Footer.tsx +55 -0
  134. package/components/Bubble/Interrupted.tsx +82 -0
  135. package/components/Bubble/ScrollToBottom.tsx +42 -0
  136. package/components/Bubble/Spin.tsx +13 -0
  137. package/components/Bubble/demo/assistantWithCode.tsx +60 -0
  138. package/components/Bubble/demo/assistantWithErrorStatus.tsx +102 -0
  139. package/components/Bubble/demo/assistantWithImage.tsx +46 -0
  140. package/components/Bubble/demo/assistantWithProcess.tsx +103 -0
  141. package/components/Bubble/demo/assistantWithSearch.tsx +69 -0
  142. package/components/Bubble/demo/assistantWithThinking.tsx +54 -0
  143. package/components/Bubble/demo/basic.tsx +55 -0
  144. package/components/Bubble/demo/userWithFile.tsx +27 -0
  145. package/components/Bubble/demo/userWithImage.tsx +26 -0
  146. package/components/Bubble/hooks/useDisplayData.ts +0 -0
  147. package/components/Bubble/hooks/useListData.ts +0 -0
  148. package/components/Bubble/index.en-US.md +33 -0
  149. package/components/Bubble/index.tsx +21 -0
  150. package/components/Bubble/index.zh-CN.md +33 -0
  151. package/components/Bubble/interface.ts +71 -0
  152. package/components/Bubble/loading.tsx +15 -0
  153. package/components/Bubble/style/avatar.ts +43 -0
  154. package/components/Bubble/style/footer.ts +45 -0
  155. package/components/Bubble/style/index.ts +192 -0
  156. package/components/Bubble/style/list.ts +51 -0
  157. package/components/ChatAnywhere/Chat/Ref.tsx +20 -0
  158. package/components/ChatAnywhere/Chat/index.tsx +56 -0
  159. package/components/ChatAnywhere/Chat/style.ts +59 -0
  160. package/components/ChatAnywhere/Header/index.tsx +37 -0
  161. package/components/ChatAnywhere/Header/style.ts +27 -0
  162. package/components/ChatAnywhere/Input/index.tsx +158 -0
  163. package/components/ChatAnywhere/Input/style.ts +14 -0
  164. package/components/ChatAnywhere/Layout/index.tsx +70 -0
  165. package/components/ChatAnywhere/Layout/style.ts +51 -0
  166. package/components/ChatAnywhere/SessionList/index.tsx +122 -0
  167. package/components/ChatAnywhere/SessionList/style.ts +53 -0
  168. package/components/ChatAnywhere/hooks/ChatAnywhereProvider.tsx +219 -0
  169. package/components/ChatAnywhere/hooks/types.ts +333 -0
  170. package/components/ChatAnywhere/hooks/useInput.tsx +22 -0
  171. package/components/ChatAnywhere/hooks/useMessages.tsx +63 -0
  172. package/components/ChatAnywhere/hooks/useSessionList.tsx +123 -0
  173. package/components/ChatAnywhere/index.tsx +49 -0
  174. package/components/Conversations/GroupTitle.tsx +28 -0
  175. package/components/Conversations/Item.tsx +189 -0
  176. package/components/Conversations/demo/basic.tsx +107 -0
  177. package/components/Conversations/demo/timeline.tsx +111 -0
  178. package/components/Conversations/demo/timestamp.tsx +110 -0
  179. package/components/Conversations/hooks/useGroupable.ts +81 -0
  180. package/components/Conversations/index.en-US.md +32 -0
  181. package/components/Conversations/index.tsx +176 -0
  182. package/components/Conversations/index.zh-CN.md +31 -0
  183. package/components/Conversations/interface.ts +69 -0
  184. package/components/Conversations/style.ts +153 -0
  185. package/components/DefaultCards/DeepThinking/index.tsx +33 -0
  186. package/components/DefaultCards/Files/index.tsx +69 -0
  187. package/components/DefaultCards/Footer/index.tsx +16 -0
  188. package/components/DefaultCards/Images/index.tsx +53 -0
  189. package/components/DefaultCards/Interrupted/index.tsx +13 -0
  190. package/components/DefaultCards/Text/index.tsx +13 -0
  191. package/components/DefaultCards/index.tsx +6 -0
  192. package/components/DeviceAction/actionMap.tsx +100 -0
  193. package/components/DeviceAction/demo/index.tsx +132 -0
  194. package/components/DeviceAction/index.en-US.md +19 -0
  195. package/components/DeviceAction/index.tsx +75 -0
  196. package/components/DeviceAction/index.zh-CN.md +19 -0
  197. package/components/Disclaimer/demo/index.tsx +4 -0
  198. package/components/Disclaimer/demo/withLink.tsx +4 -0
  199. package/components/Disclaimer/index.en-US.md +23 -0
  200. package/components/Disclaimer/index.tsx +42 -0
  201. package/components/Disclaimer/index.zh-CN.md +24 -0
  202. package/components/Disclaimer/style.ts +17 -0
  203. package/components/ImageGenerator/demo/basic.tsx +23 -0
  204. package/components/ImageGenerator/demo/custom.tsx +56 -0
  205. package/components/ImageGenerator/demo/size.tsx +15 -0
  206. package/components/ImageGenerator/index.en-US.md +23 -0
  207. package/components/ImageGenerator/index.tsx +124 -0
  208. package/components/ImageGenerator/index.zh-CN.md +23 -0
  209. package/components/ImageGenerator/style.ts +99 -0
  210. package/components/Markdown/Markdown/AnimationNode.tsx +89 -0
  211. package/components/Markdown/Markdown/Markdown.tsx +61 -0
  212. package/components/Markdown/Markdown/core/Parser.ts +52 -0
  213. package/components/Markdown/Markdown/core/Renderer.ts +121 -0
  214. package/components/Markdown/Markdown/core/index.ts +4 -0
  215. package/components/Markdown/Markdown/defaultComponents/CodeBlock.tsx +113 -0
  216. package/components/Markdown/Markdown/defaultComponents/DisabledImage.tsx +3 -0
  217. package/components/Markdown/Markdown/defaultComponents/Media.tsx +71 -0
  218. package/components/Markdown/Markdown/hooks/index.ts +4 -0
  219. package/components/Markdown/Markdown/hooks/useAnimation.tsx +27 -0
  220. package/components/Markdown/Markdown/hooks/useCitationsData.tsx +36 -0
  221. package/components/Markdown/Markdown/hooks/useStreaming.ts +503 -0
  222. package/components/Markdown/Markdown/hooks/useTyping.ts +22 -0
  223. package/components/Markdown/Markdown/index.tsx +198 -0
  224. package/components/Markdown/Markdown/interface.ts +217 -0
  225. package/components/Markdown/Markdown/style.ts +152 -0
  226. package/components/Markdown/demo/basic.tsx +107 -0
  227. package/components/Markdown/demo/citations.tsx +47 -0
  228. package/components/Markdown/demo/cursor.tsx +9 -0
  229. package/components/Markdown/demo/latex.tsx +77 -0
  230. package/components/Markdown/demo/typing.tsx +82 -0
  231. package/components/Markdown/index.en-US.md +27 -0
  232. package/components/Markdown/index.ts +1 -0
  233. package/components/Markdown/index.zh-CN.md +28 -0
  234. package/components/Markdown/plugins/citations/CitationComponent.tsx +72 -0
  235. package/components/Markdown/plugins/citations/index.tsx +37 -0
  236. package/components/Markdown/plugins/cursor/Dot.tsx +106 -0
  237. package/components/Markdown/plugins/cursor/Underline.tsx +38 -0
  238. package/components/Markdown/plugins/cursor/index.tsx +59 -0
  239. package/components/Markdown/plugins/latex/index.ts +109 -0
  240. package/components/Markdown/plugins/type.ts +71 -0
  241. package/components/Mermaid/demo/basic.tsx +12 -0
  242. package/components/Mermaid/demo/class.tsx +31 -0
  243. package/components/Mermaid/demo/flowchart.tsx +13 -0
  244. package/components/Mermaid/demo/sequence.tsx +18 -0
  245. package/components/Mermaid/demo/state.tsx +16 -0
  246. package/components/Mermaid/demo/timeline.tsx +15 -0
  247. package/components/Mermaid/index.en-US.md +27 -0
  248. package/components/Mermaid/index.tsx +118 -0
  249. package/components/Mermaid/index.zh-CN.md +27 -0
  250. package/components/OperateCard/OperateCard.tsx +93 -0
  251. package/components/OperateCard/demo/index.tsx +35 -0
  252. package/components/OperateCard/demo/rag.tsx +19 -0
  253. package/components/OperateCard/demo/thinking.tsx +17 -0
  254. package/components/OperateCard/demo/todo.tsx +28 -0
  255. package/components/OperateCard/demo/toolCall.tsx +14 -0
  256. package/components/OperateCard/demo/webSearch.tsx +12 -0
  257. package/components/OperateCard/index.en-US.md +51 -0
  258. package/components/OperateCard/index.tsx +1 -0
  259. package/components/OperateCard/index.zh-CN.md +51 -0
  260. package/components/OperateCard/preset/Rag.tsx +90 -0
  261. package/components/OperateCard/preset/Thinking.tsx +45 -0
  262. package/components/OperateCard/preset/TodoList.tsx +73 -0
  263. package/components/OperateCard/preset/ToolCall.tsx +67 -0
  264. package/components/OperateCard/preset/WebSearch.tsx +65 -0
  265. package/components/OperateCard/preset/index.tsx +5 -0
  266. package/components/OperateCard/style.ts +268 -0
  267. package/components/Provider/CustomCardsProvider.tsx +17 -0
  268. package/components/Provider/GlobalProvider.tsx +17 -0
  269. package/components/Provider/index.tsx +33 -0
  270. package/components/Provider/types.ts +23 -0
  271. package/components/ResponsesAPI/index.tsx +0 -0
  272. package/components/Sender/ModeSelect/index.tsx +160 -0
  273. package/components/Sender/ModeSelect/styles.ts +0 -0
  274. package/components/Sender/SenderHeader.tsx +164 -0
  275. package/components/Sender/StopLoading.tsx +48 -0
  276. package/components/Sender/components/ActionButton.tsx +106 -0
  277. package/components/Sender/components/ClearButton.tsx +10 -0
  278. package/components/Sender/components/LoadingButton.tsx +26 -0
  279. package/components/Sender/components/SendButton.tsx +22 -0
  280. package/components/Sender/components/SpeechButton/RecordingIcon.tsx +68 -0
  281. package/components/Sender/components/SpeechButton/index.tsx +30 -0
  282. package/components/Sender/demo/asr.tsx +7 -0
  283. package/components/Sender/demo/basic.tsx +7 -0
  284. package/components/Sender/demo/loading.tsx +5 -0
  285. package/components/Sender/demo/moreMode.tsx +45 -0
  286. package/components/Sender/demo/morePrefixAction.tsx +40 -0
  287. package/components/Sender/demo/withFile.tsx +54 -0
  288. package/components/Sender/demo/withImage.tsx +52 -0
  289. package/components/Sender/index.en-US.md +29 -0
  290. package/components/Sender/index.tsx +491 -0
  291. package/components/Sender/index.zh-CN.md +30 -0
  292. package/components/Sender/style/index.ts +150 -0
  293. package/components/Sender/useSpeech.ts +133 -0
  294. package/components/StatusCard/demo/index.tsx +32 -0
  295. package/components/StatusCard/index.en-US.md +30 -0
  296. package/components/StatusCard/index.tsx +162 -0
  297. package/components/StatusCard/index.zh-CN.md +27 -0
  298. package/components/StatusCard/style.ts +119 -0
  299. package/components/Stream/index.ts +203 -0
  300. package/components/Util/hooks/use-proxy-imperative-handle.ts +25 -0
  301. package/components/Util/sleep.ts +3 -0
  302. package/components/Util/type.ts +1 -0
  303. package/components/Util/warning.ts +118 -0
  304. package/components/Version/index.ts +3 -0
  305. package/components/Voice/Recorder.tsx +3 -0
  306. package/components/Voice/demo/index.tsx +0 -0
  307. package/components/Voice/index.en-US.md +8 -0
  308. package/components/Voice/index.tsx +0 -0
  309. package/components/Voice/index.zh-CN.md +9 -0
  310. package/components/Welcome/demo/EyeFollower.tsx +161 -0
  311. package/components/Welcome/demo/demo0.tsx +14 -0
  312. package/components/Welcome/demo/demo1.tsx +16 -0
  313. package/components/Welcome/demo/demo2.tsx +30 -0
  314. package/components/Welcome/demo/demo3.tsx +16 -0
  315. package/components/Welcome/index.en-US.md +28 -0
  316. package/components/Welcome/index.tsx +72 -0
  317. package/components/Welcome/index.zh-CN.md +28 -0
  318. package/components/index.ts +88 -0
  319. package/components/overview.en-US.md +10 -0
  320. package/components/overview.zh-CN.md +10 -0
  321. package/lib/AgentScopeRuntimeWebUI/index.d.ts +1 -0
  322. package/lib/AgentScopeRuntimeWebUI/index.js +1 -0
  323. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/FormItem.d.ts +9 -0
  324. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/FormItem.js +33 -0
  325. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/OptionsEditor.d.ts +7 -0
  326. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/OptionsEditor.js +188 -0
  327. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/defaultConfig.d.ts +29 -0
  328. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/defaultConfig.js +35 -0
  329. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/index.d.ts +6 -0
  330. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/index.js +49 -0
  331. package/lib/AgentScopeRuntimeWebUI/starter/index.d.ts +1 -0
  332. package/lib/AgentScopeRuntimeWebUI/starter/index.js +70 -0
  333. package/lib/AgentScopeRuntimeWebUI/starter/sessionApi/index.d.ts +14 -0
  334. package/lib/AgentScopeRuntimeWebUI/starter/sessionApi/index.js +143 -0
  335. package/package.json +3 -2
@@ -0,0 +1,780 @@
1
+ /**
2
+ * <br/>
3
+ * <img src="/images/CopilotChat.gif" width="500" />
4
+ *
5
+ * A chatbot panel component for the CopilotKit framework. The component allows for a high degree
6
+ * of customization through various props and custom CSS.
7
+ *
8
+ * ## Install Dependencies
9
+ *
10
+ * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
11
+ *
12
+ * ```shell npm2yarn \"@copilotkit/react-ui"\
13
+ * npm install @copilotkit/react-core @copilotkit/react-ui
14
+ * ```
15
+ *
16
+ * ## Usage
17
+ *
18
+ * ```tsx
19
+ * import { CopilotChat } from "@copilotkit/react-ui";
20
+ * import "@copilotkit/react-ui/styles.css";
21
+ *
22
+ * <CopilotChat
23
+ * labels={{
24
+ * title: "Your Assistant",
25
+ * initial: "Hi! 👋 How can I assist you today?",
26
+ * }}
27
+ * />
28
+ * ```
29
+ *
30
+ * ### Look & Feel
31
+ *
32
+ * By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
33
+ * ```tsx title="YourRootComponent.tsx"
34
+ * ...
35
+ * import "@copilotkit/react-ui/styles.css"; // [!code highlight]
36
+ *
37
+ * export function YourRootComponent() {
38
+ * return (
39
+ * <CopilotKit>
40
+ * ...
41
+ * </CopilotKit>
42
+ * );
43
+ * }
44
+ * ```
45
+ * 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.
46
+ */
47
+
48
+ import {
49
+ ChatContext,
50
+ ChatContextProvider,
51
+ CopilotChatIcons,
52
+ CopilotChatLabels,
53
+ } from "./ChatContext";
54
+ import { Messages as DefaultMessages } from "./Messages";
55
+ import { Input as DefaultInput } from "./Input";
56
+ import { RenderTextMessage as DefaultRenderTextMessage } from "./messages/RenderTextMessage";
57
+ import { RenderActionExecutionMessage as DefaultRenderActionExecutionMessage } from "./messages/RenderActionExecutionMessage";
58
+ import { RenderResultMessage as DefaultRenderResultMessage } from "./messages/RenderResultMessage";
59
+ import { RenderAgentStateMessage as DefaultRenderAgentStateMessage } from "./messages/RenderAgentStateMessage";
60
+ import { RenderImageMessage as DefaultRenderImageMessage } from "./messages/RenderImageMessage";
61
+ import { AssistantMessage as DefaultAssistantMessage } from "./messages/AssistantMessage";
62
+ import { UserMessage as DefaultUserMessage } from "./messages/UserMessage";
63
+ import React, { useEffect, useRef, useState } from "react";
64
+ import {
65
+ SystemMessageFunction,
66
+ useCopilotChat,
67
+ useCopilotContext,
68
+ useCopilotMessagesContext,
69
+ } from "@copilotkit/react-core";
70
+ import { reloadSuggestions } from "./Suggestion";
71
+ import { CopilotChatSuggestion } from "../../types/suggestions";
72
+ import { Message, Role, TextMessage, ImageMessage } from "@copilotkit/runtime-client-gql";
73
+ import { randomId } from "@copilotkit/shared";
74
+ import {
75
+ AssistantMessageProps,
76
+ ComponentsMap,
77
+ InputProps,
78
+ MessagesProps,
79
+ RenderMessageProps,
80
+ RenderSuggestionsListProps,
81
+ UserMessageProps,
82
+ } from "./props";
83
+
84
+ import { HintFunction, runAgent, stopAgent } from "@copilotkit/react-core";
85
+ import { ImageUploadQueue } from "./ImageUploadQueue";
86
+ import { Suggestions as DefaultRenderSuggestionsList } from "./Suggestions";
87
+
88
+ /**
89
+ * Props for CopilotChat component.
90
+ */
91
+ export interface CopilotChatProps {
92
+ /**
93
+ * Custom instructions to be added to the system message. Use this property to
94
+ * provide additional context or guidance to the language model, influencing
95
+ * its responses. These instructions can include specific directions,
96
+ * preferences, or criteria that the model should consider when generating
97
+ * its output, thereby tailoring the conversation more precisely to the
98
+ * user's needs or the application's requirements.
99
+ */
100
+ instructions?: string;
101
+
102
+ /**
103
+ * A callback that gets called when the in progress state changes.
104
+ */
105
+ onInProgress?: (inProgress: boolean) => void;
106
+
107
+ /**
108
+ * A callback that gets called when a new message it submitted.
109
+ */
110
+ onSubmitMessage?: (message: string) => void | Promise<void>;
111
+
112
+ /**
113
+ * A custom stop generation function.
114
+ */
115
+ onStopGeneration?: OnStopGeneration;
116
+
117
+ /**
118
+ * A custom reload messages function.
119
+ */
120
+ onReloadMessages?: OnReloadMessages;
121
+
122
+ /**
123
+ * A callback function to regenerate the assistant's response
124
+ */
125
+ onRegenerate?: (messageId: string) => void;
126
+
127
+ /**
128
+ * A callback function when the message is copied
129
+ */
130
+ onCopy?: (message: string) => void;
131
+
132
+ /**
133
+ * A callback function for thumbs up feedback
134
+ */
135
+ onThumbsUp?: (message: TextMessage) => void;
136
+
137
+ /**
138
+ * A callback function for thumbs down feedback
139
+ */
140
+ onThumbsDown?: (message: TextMessage) => void;
141
+
142
+ /**
143
+ * A list of markdown components to render in assistant message.
144
+ * Useful when you want to render custom elements in the message (e.g a reference tag element)
145
+ */
146
+ markdownTagRenderers?: ComponentsMap;
147
+
148
+ /**
149
+ * Icons can be used to set custom icons for the chat window.
150
+ */
151
+ icons?: CopilotChatIcons;
152
+
153
+ /**
154
+ * Labels can be used to set custom labels for the chat window.
155
+ */
156
+ labels?: CopilotChatLabels;
157
+
158
+ /**
159
+ * Enable image upload button (image inputs only supported on some models)
160
+ */
161
+ imageUploadsEnabled?: boolean;
162
+
163
+ /**
164
+ * The 'accept' attribute for the file input used for image uploads.
165
+ * Defaults to "image/*".
166
+ */
167
+ inputFileAccept?: string;
168
+
169
+ /**
170
+ * A function that takes in context string and instructions and returns
171
+ * the system message to include in the chat request.
172
+ * Use this to completely override the system message, when providing
173
+ * instructions is not enough.
174
+ */
175
+ makeSystemMessage?: SystemMessageFunction;
176
+
177
+ /**
178
+ * A custom assistant message component to use instead of the default.
179
+ */
180
+ AssistantMessage?: React.ComponentType<AssistantMessageProps>;
181
+
182
+ /**
183
+ * A custom user message component to use instead of the default.
184
+ */
185
+ UserMessage?: React.ComponentType<UserMessageProps>;
186
+
187
+ /**
188
+ * A custom Messages component to use instead of the default.
189
+ */
190
+ Messages?: React.ComponentType<MessagesProps>;
191
+
192
+ /**
193
+ * A custom RenderTextMessage component to use instead of the default.
194
+ */
195
+ RenderTextMessage?: React.ComponentType<RenderMessageProps>;
196
+
197
+ /**
198
+ * A custom RenderActionExecutionMessage component to use instead of the default.
199
+ */
200
+ RenderActionExecutionMessage?: React.ComponentType<RenderMessageProps>;
201
+
202
+ /**
203
+ * A custom RenderAgentStateMessage component to use instead of the default.
204
+ */
205
+ RenderAgentStateMessage?: React.ComponentType<RenderMessageProps>;
206
+
207
+ /**
208
+ * A custom RenderResultMessage component to use instead of the default.
209
+ */
210
+ RenderResultMessage?: React.ComponentType<RenderMessageProps>;
211
+
212
+ /**
213
+ * A custom RenderImageMessage component to use instead of the default.
214
+ */
215
+ RenderImageMessage?: React.ComponentType<RenderMessageProps>;
216
+
217
+ /**
218
+ * A custom suggestions list component to use instead of the default.
219
+ */
220
+ RenderSuggestionsList?: React.ComponentType<RenderSuggestionsListProps>;
221
+
222
+ /**
223
+ * A custom Input component to use instead of the default.
224
+ */
225
+ Input?: React.ComponentType<InputProps>;
226
+
227
+ /**
228
+ * A class name to apply to the root element.
229
+ */
230
+ className?: string;
231
+
232
+ /**
233
+ * Children to render.
234
+ */
235
+ children?: React.ReactNode;
236
+
237
+ hideStopButton?: boolean;
238
+ }
239
+
240
+ interface OnStopGenerationArguments {
241
+ /**
242
+ * The name of the currently executing agent.
243
+ */
244
+ currentAgentName: string | undefined;
245
+
246
+ /**
247
+ * The messages in the chat.
248
+ */
249
+ messages: Message[];
250
+
251
+ /**
252
+ * Set the messages in the chat.
253
+ */
254
+ setMessages: (messages: Message[]) => void;
255
+
256
+ /**
257
+ * Stop chat generation.
258
+ */
259
+ stopGeneration: () => void;
260
+
261
+ /**
262
+ * Restart the currently executing agent.
263
+ */
264
+ restartCurrentAgent: () => void;
265
+
266
+ /**
267
+ * Stop the currently executing agent.
268
+ */
269
+ stopCurrentAgent: () => void;
270
+
271
+ /**
272
+ * Run the currently executing agent.
273
+ */
274
+ runCurrentAgent: (hint?: HintFunction) => Promise<void>;
275
+
276
+ /**
277
+ * Set the state of the currently executing agent.
278
+ */
279
+ setCurrentAgentState: (state: any) => void;
280
+ }
281
+
282
+ export type OnReloadMessagesArguments = OnStopGenerationArguments & {
283
+ /**
284
+ * The message on which "regenerate" was pressed
285
+ */
286
+ messageId: string;
287
+ };
288
+
289
+ export type OnStopGeneration = (args: OnStopGenerationArguments) => void;
290
+
291
+ export type OnReloadMessages = (args: OnReloadMessagesArguments) => void;
292
+
293
+ export type ImageUpload = {
294
+ contentType: string;
295
+ bytes: string;
296
+ };
297
+
298
+ export function CopilotChat({
299
+ instructions,
300
+ onSubmitMessage,
301
+ makeSystemMessage,
302
+ onInProgress,
303
+ onStopGeneration,
304
+ onReloadMessages,
305
+ onRegenerate,
306
+ onCopy,
307
+ onThumbsUp,
308
+ onThumbsDown,
309
+ markdownTagRenderers,
310
+ Messages = DefaultMessages,
311
+ RenderTextMessage = DefaultRenderTextMessage,
312
+ RenderActionExecutionMessage = DefaultRenderActionExecutionMessage,
313
+ RenderAgentStateMessage = DefaultRenderAgentStateMessage,
314
+ RenderResultMessage = DefaultRenderResultMessage,
315
+ RenderImageMessage = DefaultRenderImageMessage,
316
+ RenderSuggestionsList = DefaultRenderSuggestionsList,
317
+ Input = DefaultInput,
318
+ className,
319
+ icons,
320
+ labels,
321
+ AssistantMessage = DefaultAssistantMessage,
322
+ UserMessage = DefaultUserMessage,
323
+ imageUploadsEnabled,
324
+ inputFileAccept = "image/*",
325
+ hideStopButton,
326
+ }: CopilotChatProps) {
327
+ const { additionalInstructions, setChatInstructions } = useCopilotContext();
328
+ const [selectedImages, setSelectedImages] = useState<Array<ImageUpload>>([]);
329
+ const fileInputRef = useRef<HTMLInputElement>(null);
330
+
331
+ // Clipboard paste handler
332
+ useEffect(() => {
333
+ if (!imageUploadsEnabled) return;
334
+
335
+ const handlePaste = async (e: ClipboardEvent) => {
336
+ const target = e.target as HTMLElement;
337
+ if (!target.parentElement?.classList.contains("copilotKitInput")) return;
338
+
339
+ const items = Array.from(e.clipboardData?.items || []);
340
+ const imageItems = items.filter((item) => item.type.startsWith("image/"));
341
+
342
+ if (imageItems.length === 0) return;
343
+
344
+ e.preventDefault(); // Prevent default paste behavior for images
345
+
346
+ const imagePromises: Promise<ImageUpload | null>[] = imageItems.map((item) => {
347
+ const file = item.getAsFile();
348
+ if (!file) return Promise.resolve(null);
349
+
350
+ return new Promise<ImageUpload | null>((resolve, reject) => {
351
+ const reader = new FileReader();
352
+ reader.onload = (e) => {
353
+ const base64String = (e.target?.result as string)?.split(",")[1];
354
+ if (base64String) {
355
+ resolve({
356
+ contentType: file.type,
357
+ bytes: base64String,
358
+ });
359
+ } else {
360
+ resolve(null);
361
+ }
362
+ };
363
+ reader.onerror = reject;
364
+ reader.readAsDataURL(file);
365
+ });
366
+ });
367
+
368
+ try {
369
+ const loadedImages = (await Promise.all(imagePromises)).filter((img) => img !== null);
370
+ setSelectedImages((prev) => [...prev, ...loadedImages]);
371
+ } catch (error) {
372
+ // TODO: Show an error message to the user
373
+ console.error("Error processing pasted images:", error);
374
+ }
375
+ };
376
+
377
+ document.addEventListener("paste", handlePaste);
378
+ return () => document.removeEventListener("paste", handlePaste);
379
+ }, [imageUploadsEnabled]);
380
+
381
+ useEffect(() => {
382
+ if (!additionalInstructions?.length) {
383
+ setChatInstructions(instructions || "");
384
+ return;
385
+ }
386
+
387
+ /*
388
+ Will result in a prompt like:
389
+
390
+ You are a helpful assistant.
391
+ Additionally, follow these instructions:
392
+ - Do not answer questions about the weather.
393
+ - Do not answer questions about the stock market."
394
+ */
395
+ const combinedAdditionalInstructions = [
396
+ instructions,
397
+ "Additionally, follow these instructions:",
398
+ ...additionalInstructions.map((instruction) => `- ${instruction}`),
399
+ ];
400
+
401
+ console.log("combinedAdditionalInstructions", combinedAdditionalInstructions);
402
+
403
+ setChatInstructions(combinedAdditionalInstructions.join("\n") || "");
404
+ }, [instructions, additionalInstructions]);
405
+
406
+ const {
407
+ visibleMessages,
408
+ isLoading,
409
+ currentSuggestions,
410
+ sendMessage,
411
+ stopGeneration,
412
+ reloadMessages,
413
+ } = useCopilotChatLogic(
414
+ makeSystemMessage,
415
+ onInProgress,
416
+ onSubmitMessage,
417
+ onStopGeneration,
418
+ onReloadMessages,
419
+ );
420
+
421
+ // Wrapper for sendMessage to clear selected images
422
+ const handleSendMessage = (text: string) => {
423
+ const images = selectedImages;
424
+ setSelectedImages([]);
425
+ if (fileInputRef.current) {
426
+ fileInputRef.current.value = "";
427
+ }
428
+
429
+ return sendMessage(text, images);
430
+ };
431
+
432
+ const chatContext = React.useContext(ChatContext);
433
+ const isVisible = chatContext ? chatContext.open : true;
434
+
435
+ const handleRegenerate = (messageId: string) => {
436
+ if (onRegenerate) {
437
+ onRegenerate(messageId);
438
+ }
439
+
440
+ reloadMessages(messageId);
441
+ };
442
+
443
+ const handleCopy = (message: string) => {
444
+ if (onCopy) {
445
+ onCopy(message);
446
+ }
447
+ };
448
+
449
+ const handleImageUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
450
+ if (!event.target.files || event.target.files.length === 0) {
451
+ return;
452
+ }
453
+
454
+ const files = Array.from(event.target.files).filter((file) => file.type.startsWith("image/"));
455
+ if (files.length === 0) return;
456
+
457
+ const fileReadPromises = files.map((file) => {
458
+ return new Promise<{ contentType: string; bytes: string }>((resolve, reject) => {
459
+ const reader = new FileReader();
460
+ reader.onload = (e) => {
461
+ const base64String = (e.target?.result as string)?.split(",")[1] || "";
462
+ if (base64String) {
463
+ resolve({
464
+ contentType: file.type,
465
+ bytes: base64String,
466
+ });
467
+ }
468
+ };
469
+ reader.onerror = reject;
470
+ reader.readAsDataURL(file);
471
+ });
472
+ });
473
+
474
+ try {
475
+ const loadedImages = await Promise.all(fileReadPromises);
476
+ setSelectedImages((prev) => [...prev, ...loadedImages]);
477
+ } catch (error) {
478
+ // TODO: Show an error message to the user
479
+ console.error("Error reading files:", error);
480
+ }
481
+ };
482
+
483
+ const removeSelectedImage = (index: number) => {
484
+ setSelectedImages((prev) => prev.filter((_, i) => i !== index));
485
+ };
486
+
487
+ return (
488
+ <WrappedCopilotChat icons={icons} labels={labels} className={className}>
489
+ <Messages
490
+ AssistantMessage={AssistantMessage}
491
+ UserMessage={UserMessage}
492
+ RenderTextMessage={RenderTextMessage}
493
+ RenderActionExecutionMessage={RenderActionExecutionMessage}
494
+ RenderAgentStateMessage={RenderAgentStateMessage}
495
+ RenderResultMessage={RenderResultMessage}
496
+ RenderImageMessage={RenderImageMessage}
497
+ messages={visibleMessages}
498
+ inProgress={isLoading}
499
+ onRegenerate={handleRegenerate}
500
+ onCopy={handleCopy}
501
+ onThumbsUp={onThumbsUp}
502
+ onThumbsDown={onThumbsDown}
503
+ markdownTagRenderers={markdownTagRenderers}
504
+ >
505
+ {currentSuggestions.length > 0 && (
506
+ <RenderSuggestionsList
507
+ onSuggestionClick={handleSendMessage}
508
+ suggestions={currentSuggestions}
509
+ />
510
+ )}
511
+ </Messages>
512
+
513
+ {/* {imageUploadsEnabled && (
514
+ <>
515
+ <ImageUploadQueue images={selectedImages} onRemoveImage={removeSelectedImage} />
516
+ <input
517
+ type="file"
518
+ multiple
519
+ ref={fileInputRef}
520
+ onChange={handleImageUpload}
521
+ accept={inputFileAccept}
522
+ style={{ display: "none" }}
523
+ />
524
+ </>
525
+ )} */}
526
+
527
+ <Input
528
+ inProgress={isLoading}
529
+ onSend={handleSendMessage}
530
+ onStop={stopGeneration}
531
+ // onUpload={imageUploadsEnabled ? () => fileInputRef.current?.click() : undefined}
532
+ // hideStopButton={hideStopButton}
533
+ />
534
+ </WrappedCopilotChat>
535
+ );
536
+ }
537
+
538
+
539
+ export function WrappedCopilotChat({
540
+ children,
541
+ icons,
542
+ labels,
543
+ className,
544
+ }: {
545
+ children: React.ReactNode;
546
+ icons?: CopilotChatIcons;
547
+ labels?: CopilotChatLabels;
548
+ className?: string;
549
+ }) {
550
+ const chatContext = React.useContext(ChatContext);
551
+ if (!chatContext) {
552
+ return (
553
+ <ChatContextProvider icons={icons} labels={labels} open={true} setOpen={() => { }}>
554
+ <div className={`copilotKitChat ${className ?? ""}`}>{children}</div>
555
+ </ChatContextProvider>
556
+ );
557
+ }
558
+ return <>{children}</>;
559
+ }
560
+
561
+ const SUGGESTIONS_DEBOUNCE_TIMEOUT = 1000;
562
+
563
+ export const useCopilotChatLogic = (
564
+ makeSystemMessage?: SystemMessageFunction,
565
+ onInProgress?: (isLoading: boolean) => void,
566
+ onSubmitMessage?: (messageContent: string) => Promise<void> | void,
567
+ onStopGeneration?: OnStopGeneration,
568
+ onReloadMessages?: OnReloadMessages,
569
+ ) => {
570
+ const {
571
+ visibleMessages,
572
+ appendMessage,
573
+ reloadMessages: defaultReloadMessages,
574
+ stopGeneration: defaultStopGeneration,
575
+ runChatCompletion,
576
+ isLoading,
577
+ } = useCopilotChat({
578
+ id: randomId(),
579
+ makeSystemMessage,
580
+ });
581
+
582
+ const [currentSuggestions, setCurrentSuggestions] = useState<CopilotChatSuggestion[]>([]);
583
+ const suggestionsAbortControllerRef = useRef<AbortController | null>(null);
584
+ const debounceTimerRef = useRef<any>();
585
+
586
+ const abortSuggestions = () => {
587
+ suggestionsAbortControllerRef.current?.abort();
588
+ suggestionsAbortControllerRef.current = null;
589
+ };
590
+
591
+ const generalContext = useCopilotContext();
592
+ const messagesContext = useCopilotMessagesContext();
593
+ const context = { ...generalContext, ...messagesContext };
594
+
595
+ useEffect(() => {
596
+ onInProgress?.(isLoading);
597
+
598
+ abortSuggestions();
599
+
600
+ debounceTimerRef.current = setTimeout(
601
+ () => {
602
+ if (!isLoading && Object.keys(context.chatSuggestionConfiguration).length !== 0) {
603
+ suggestionsAbortControllerRef.current = new AbortController();
604
+ reloadSuggestions(
605
+ context,
606
+ context.chatSuggestionConfiguration,
607
+ setCurrentSuggestions,
608
+ suggestionsAbortControllerRef,
609
+ );
610
+ }
611
+ },
612
+ currentSuggestions.length == 0 ? 0 : SUGGESTIONS_DEBOUNCE_TIMEOUT,
613
+ );
614
+
615
+ return () => {
616
+ clearTimeout(debounceTimerRef.current);
617
+ };
618
+ }, [
619
+ isLoading,
620
+ context.chatSuggestionConfiguration,
621
+ // hackish way to trigger suggestions reload on reset, but better than moving suggestions to the
622
+ // global context
623
+ visibleMessages.length == 0,
624
+ ]);
625
+
626
+ const sendMessage = async (
627
+ messageContent: string,
628
+ imagesToUse?: Array<{ contentType: string; bytes: string }>,
629
+ ) => {
630
+ // Use images passed in the call OR the ones from the state (passed via props)
631
+ const images = imagesToUse || [];
632
+
633
+ abortSuggestions();
634
+ setCurrentSuggestions([]);
635
+
636
+ let firstMessage: Message | null = null;
637
+
638
+ // If there's text content, send a text message first
639
+ if (messageContent.trim().length > 0) {
640
+ const textMessage = new TextMessage({
641
+ content: messageContent,
642
+ role: Role.User,
643
+ });
644
+
645
+ if (onSubmitMessage) {
646
+ try {
647
+ // Call onSubmitMessage only with text, as image handling is internal right now
648
+ await onSubmitMessage(messageContent);
649
+ } catch (error) {
650
+ console.error("Error in onSubmitMessage:", error);
651
+ }
652
+ }
653
+
654
+ await appendMessage(textMessage, { followUp: images.length === 0 });
655
+
656
+ if (!firstMessage) {
657
+ firstMessage = textMessage;
658
+ }
659
+ }
660
+
661
+ // Send image messages
662
+ if (images.length > 0) {
663
+ for (let i = 0; i < images.length; i++) {
664
+ const imageMessage = new ImageMessage({
665
+ format: images[i].contentType.replace("image/", ""),
666
+ bytes: images[i].bytes,
667
+ role: Role.User,
668
+ });
669
+ await appendMessage(imageMessage, { followUp: i === images.length - 1 });
670
+ if (!firstMessage) {
671
+ firstMessage = imageMessage;
672
+ }
673
+ }
674
+ }
675
+
676
+ if (!firstMessage) {
677
+ // Should not happen if send button is properly disabled, but handle just in case
678
+ return new TextMessage({ content: "", role: Role.User }); // Return a dummy message
679
+ }
680
+
681
+ // The hook implicitly triggers API call on appendMessage.
682
+ // We return the first message sent (either text or first image)
683
+ return firstMessage;
684
+ };
685
+
686
+ const messages = visibleMessages;
687
+ const { setMessages } = messagesContext;
688
+ const currentAgentName = generalContext.agentSession?.agentName;
689
+ const restartCurrentAgent = async (hint?: HintFunction) => {
690
+ if (generalContext.agentSession) {
691
+ generalContext.setAgentSession({
692
+ ...generalContext.agentSession,
693
+ nodeName: undefined,
694
+ threadId: undefined,
695
+ });
696
+ generalContext.setCoagentStates((prevAgentStates) => {
697
+ return {
698
+ ...prevAgentStates,
699
+ [generalContext.agentSession!.agentName]: {
700
+ ...prevAgentStates[generalContext.agentSession!.agentName],
701
+ threadId: undefined,
702
+ nodeName: undefined,
703
+ runId: undefined,
704
+ },
705
+ };
706
+ });
707
+ }
708
+ };
709
+ const runCurrentAgent = async (hint?: HintFunction) => {
710
+ if (generalContext.agentSession) {
711
+ await runAgent(
712
+ generalContext.agentSession.agentName,
713
+ context,
714
+ appendMessage,
715
+ runChatCompletion,
716
+ hint,
717
+ );
718
+ }
719
+ };
720
+ const stopCurrentAgent = () => {
721
+ if (generalContext.agentSession) {
722
+ stopAgent(generalContext.agentSession.agentName, context);
723
+ }
724
+ };
725
+ const setCurrentAgentState = (state: any) => {
726
+ if (generalContext.agentSession) {
727
+ generalContext.setCoagentStates((prevAgentStates) => {
728
+ return {
729
+ ...prevAgentStates,
730
+ [generalContext.agentSession!.agentName]: {
731
+ state,
732
+ },
733
+ } as any;
734
+ });
735
+ }
736
+ };
737
+
738
+ function stopGeneration() {
739
+ if (onStopGeneration) {
740
+ onStopGeneration({
741
+ messages,
742
+ setMessages,
743
+ stopGeneration: defaultStopGeneration,
744
+ currentAgentName,
745
+ restartCurrentAgent,
746
+ stopCurrentAgent,
747
+ runCurrentAgent,
748
+ setCurrentAgentState,
749
+ });
750
+ } else {
751
+ defaultStopGeneration();
752
+ }
753
+ }
754
+ function reloadMessages(messageId: string) {
755
+ if (onReloadMessages) {
756
+ onReloadMessages({
757
+ messages,
758
+ setMessages,
759
+ stopGeneration: defaultStopGeneration,
760
+ currentAgentName,
761
+ restartCurrentAgent,
762
+ stopCurrentAgent,
763
+ runCurrentAgent,
764
+ setCurrentAgentState,
765
+ messageId,
766
+ });
767
+ } else {
768
+ defaultReloadMessages(messageId);
769
+ }
770
+ }
771
+
772
+ return {
773
+ visibleMessages,
774
+ isLoading,
775
+ currentSuggestions,
776
+ sendMessage,
777
+ stopGeneration,
778
+ reloadMessages,
779
+ };
780
+ };