@anker-in/campaign-ui 0.1.4 → 0.1.5

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.
@@ -34,6 +34,10 @@ export interface ChatProps {
34
34
  * unfollow: ResponseButton 在聊天框底部
35
35
  */
36
36
  showResponseButton?: string | boolean
37
+ /** messages 的回调事件
38
+ * 每次生成/接受新的messages,会将 整个 messages list 传递给外部
39
+ */
40
+ messagesCallback?: (messages: any) => void
37
41
  /** 通用 action 的触发事件
38
42
  */
39
43
  commonRender?: string | ((_props: any) => React.ReactElement)
@@ -83,6 +87,7 @@ const Chat = (props: ChatProps) => {
83
87
  prologue = '',
84
88
  locale = '',
85
89
  query = '',
90
+ messagesCallback,
86
91
  showResponseButton,
87
92
  gotocheckoutRender,
88
93
  commonRender,
@@ -175,6 +180,7 @@ const Chat = (props: ChatProps) => {
175
180
  <Messages
176
181
  messages={messages}
177
182
  inProgress={inProgress}
183
+ messagesCallback={messagesCallback}
178
184
  ResponseButton={showResponseButton === 'follow' ? <ResponseButton /> : undefined}
179
185
  >
180
186
  <Suggestions currentSuggestions={currentSuggestions} />
@@ -12,7 +12,7 @@ import {
12
12
  Role,
13
13
  } from '@copilotkit/runtime-client-gql'
14
14
 
15
- const Messages = ({ messages, inProgress, ResponseButton, children }: MessagesProps) => {
15
+ const Messages = ({ messages, inProgress, ResponseButton, messagesCallback, children }: MessagesProps) => {
16
16
  const [isExpanded, setIsExpanded] = useState(true)
17
17
 
18
18
  const { chatComponentsCache } = useCopilotContext()
@@ -51,6 +51,10 @@ const Messages = ({ messages, inProgress, ResponseButton, children }: MessagesPr
51
51
  scrollToBottom()
52
52
  }, [messages])
53
53
 
54
+ useEffect(() => {
55
+ if (messagesCallback) messagesCallback(messages)
56
+ }, [messages])
57
+
54
58
  useEffect(() => {
55
59
  const textarea = document.querySelector('.copilotKitInput textarea') as HTMLTextAreaElement
56
60
 
@@ -36,6 +36,7 @@ export interface MessagesProps {
36
36
  inProgress: boolean
37
37
  ResponseButton?: React.ReactElement
38
38
  children?: React.ReactNode
39
+ messagesCallback?: (messages: any) => void
39
40
  }
40
41
 
41
42
  export interface InputProps {