@anker-in/campaign-ui 0.1.3 → 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.
Files changed (30) hide show
  1. package/dist/cjs/components/chat/Messages.d.ts +1 -1
  2. package/dist/cjs/components/chat/action.d.ts +2 -1
  3. package/dist/cjs/components/chat/action.js +1 -1
  4. package/dist/cjs/components/chat/action.js.map +3 -3
  5. package/dist/cjs/components/chat/index.d.ts +7 -0
  6. package/dist/cjs/components/chat/index.js +1 -1
  7. package/dist/cjs/components/chat/index.js.map +3 -3
  8. package/dist/cjs/components/chat/messages.js +1 -1
  9. package/dist/cjs/components/chat/messages.js.map +3 -3
  10. package/dist/cjs/components/chat/props.d.ts +1 -0
  11. package/dist/cjs/components/chat/props.js +1 -1
  12. package/dist/cjs/components/chat/props.js.map +1 -1
  13. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  14. package/dist/esm/components/chat/Messages.d.ts +1 -1
  15. package/dist/esm/components/chat/action.d.ts +2 -1
  16. package/dist/esm/components/chat/action.js +1 -1
  17. package/dist/esm/components/chat/action.js.map +3 -3
  18. package/dist/esm/components/chat/index.d.ts +7 -0
  19. package/dist/esm/components/chat/index.js +1 -1
  20. package/dist/esm/components/chat/index.js.map +3 -3
  21. package/dist/esm/components/chat/messages.js +1 -1
  22. package/dist/esm/components/chat/messages.js.map +3 -3
  23. package/dist/esm/components/chat/props.d.ts +1 -0
  24. package/dist/esm/components/chat/props.js.map +1 -1
  25. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +1 -1
  27. package/src/components/chat/action.tsx +12 -0
  28. package/src/components/chat/index.tsx +11 -0
  29. package/src/components/chat/messages.tsx +5 -1
  30. package/src/components/chat/props.ts +1 -0
@@ -16,6 +16,7 @@ export interface ActionProps {
16
16
  history: Message[]
17
17
  addtocartHandler?: (_args: any) => Promise<any>
18
18
  commonRender?: string | ((_props: any) => React.ReactElement)
19
+ pointsExchangeCouponRender?: string | ((_props: any) => React.ReactElement)
19
20
  gotocheckoutRender?: string | ((_props: any) => React.ReactElement)
20
21
  gotocartRender?: string | ((_props: any) => React.ReactElement)
21
22
  addtocartRender?: string | ((_props: any) => React.ReactElement)
@@ -30,6 +31,7 @@ export const CopilotAction = ({
30
31
  history,
31
32
  addtocartHandler,
32
33
  commonRender,
34
+ pointsExchangeCouponRender,
33
35
  gotocheckoutRender,
34
36
  gotocartRender,
35
37
  addtocartRender,
@@ -80,6 +82,16 @@ export const CopilotAction = ({
80
82
  },
81
83
  })
82
84
 
85
+ useCopilotAction({
86
+ name: 'points_exchange_coupon',
87
+ description: 'points exchange coupon',
88
+ parameters: [{ act: '' }] as any,
89
+ render: pointsExchangeCouponRender || (props => <div className="hidden">{JSON.stringify(props)}</div>),
90
+ handler: function () {
91
+ // console.log('points_exchange_coupon', props)
92
+ },
93
+ })
94
+
83
95
  useCopilotAction({
84
96
  name: 'go_to_cart',
85
97
  description: 'go to cart',
@@ -34,9 +34,16 @@ 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)
44
+ /** 通用 积分 换 Coupon 的触发事件
45
+ */
46
+ pointsExchangeCouponRender?: string | ((_props: any) => React.ReactElement)
40
47
  /** 跳转 checkout action 卡片,接受参数: {"status":"complete","args":[{"sku":["A3936031"],"handle":"space-a40-a3936031"}],"result":""}
41
48
  * 后端接口文档:https://anker-in.feishu.cn/wiki/DOYJwE9oxipWmYk072ncnJNznBb
42
49
  */
@@ -80,9 +87,11 @@ const Chat = (props: ChatProps) => {
80
87
  prologue = '',
81
88
  locale = '',
82
89
  query = '',
90
+ messagesCallback,
83
91
  showResponseButton,
84
92
  gotocheckoutRender,
85
93
  commonRender,
94
+ pointsExchangeCouponRender,
86
95
  gotocartRender,
87
96
  addtocartRender,
88
97
  productRender,
@@ -171,6 +180,7 @@ const Chat = (props: ChatProps) => {
171
180
  <Messages
172
181
  messages={messages}
173
182
  inProgress={inProgress}
183
+ messagesCallback={messagesCallback}
174
184
  ResponseButton={showResponseButton === 'follow' ? <ResponseButton /> : undefined}
175
185
  >
176
186
  <Suggestions currentSuggestions={currentSuggestions} />
@@ -208,6 +218,7 @@ const Chat = (props: ChatProps) => {
208
218
  start={start}
209
219
  history={history}
210
220
  commonRender={commonRender}
221
+ pointsExchangeCouponRender={pointsExchangeCouponRender}
211
222
  gotocartRender={gotocartRender}
212
223
  gotocheckoutRender={gotocheckoutRender}
213
224
  addtocartRender={addtocartRender}
@@ -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 {