@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.
- package/dist/cjs/components/chat/Messages.d.ts +1 -1
- package/dist/cjs/components/chat/action.d.ts +2 -1
- package/dist/cjs/components/chat/action.js +1 -1
- package/dist/cjs/components/chat/action.js.map +3 -3
- package/dist/cjs/components/chat/index.d.ts +7 -0
- package/dist/cjs/components/chat/index.js +1 -1
- package/dist/cjs/components/chat/index.js.map +3 -3
- package/dist/cjs/components/chat/messages.js +1 -1
- package/dist/cjs/components/chat/messages.js.map +3 -3
- package/dist/cjs/components/chat/props.d.ts +1 -0
- package/dist/cjs/components/chat/props.js +1 -1
- package/dist/cjs/components/chat/props.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/components/chat/Messages.d.ts +1 -1
- package/dist/esm/components/chat/action.d.ts +2 -1
- package/dist/esm/components/chat/action.js +1 -1
- package/dist/esm/components/chat/action.js.map +3 -3
- package/dist/esm/components/chat/index.d.ts +7 -0
- package/dist/esm/components/chat/index.js +1 -1
- package/dist/esm/components/chat/index.js.map +3 -3
- package/dist/esm/components/chat/messages.js +1 -1
- package/dist/esm/components/chat/messages.js.map +3 -3
- package/dist/esm/components/chat/props.d.ts +1 -0
- package/dist/esm/components/chat/props.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/chat/action.tsx +12 -0
- package/src/components/chat/index.tsx +11 -0
- package/src/components/chat/messages.tsx +5 -1
- 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
|
|