@anker-in/campaign-ui 0.3.3 → 0.3.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/LiveChatWidget/LiveChatWidget.d.ts +21 -1
- package/dist/cjs/components/LiveChatWidget/LiveChatWidget.js +1 -1
- package/dist/cjs/components/LiveChatWidget/LiveChatWidget.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/api/chat.d.ts +23 -2
- package/dist/cjs/components/LiveChatWidget/api/chat.js +2 -2
- package/dist/cjs/components/LiveChatWidget/api/chat.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/ChatHeader.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/ChatHeader.js.map +2 -2
- package/dist/cjs/components/LiveChatWidget/components/ChatInput.d.ts +5 -0
- package/dist/cjs/components/LiveChatWidget/components/ChatInput.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/ChatInput.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/ChatMessage.js +2 -2
- package/dist/cjs/components/LiveChatWidget/components/ChatMessage.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/ChatWindow.d.ts +5 -0
- package/dist/cjs/components/LiveChatWidget/components/ChatWindow.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/ChatWindow.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/ComplianceDialog.d.ts +51 -0
- package/dist/cjs/components/LiveChatWidget/components/ComplianceDialog.js +33 -0
- package/dist/cjs/components/LiveChatWidget/components/ComplianceDialog.js.map +7 -0
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/CartCard.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/CartCard.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/ErrorBlock.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/ErrorBlock.js.map +2 -2
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/FAQList.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/FAQList.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/PolicyBlock.js +2 -2
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/PolicyBlock.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/ProductCard.d.ts +17 -24
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/ProductCard.js +1 -4
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/ProductCard.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/ProductComparison.d.ts +7 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/ProductComparison.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/ProductComparison.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/ProductList.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/ProductList.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/PromotionList.d.ts +4 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/PromotionList.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/PromotionList.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/QuickReplies.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/QuickReplies.js.map +2 -2
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/TextBlock.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/TextBlock.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageContent.js +1 -1
- package/dist/cjs/components/LiveChatWidget/components/MessageContent.js.map +2 -2
- package/dist/cjs/components/LiveChatWidget/components/MessageList.js +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageList.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/constants.d.ts +5 -0
- package/dist/cjs/components/LiveChatWidget/constants.js +1 -1
- package/dist/cjs/components/LiveChatWidget/constants.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/hooks/useChatAPI.d.ts +9 -0
- package/dist/cjs/components/LiveChatWidget/hooks/useChatAPI.js +1 -1
- package/dist/cjs/components/LiveChatWidget/hooks/useChatAPI.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/hooks/useChatState.d.ts +36 -2
- package/dist/cjs/components/LiveChatWidget/hooks/useChatState.js +1 -1
- package/dist/cjs/components/LiveChatWidget/hooks/useChatState.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/index.d.ts +1 -1
- package/dist/cjs/components/LiveChatWidget/index.js +1 -1
- package/dist/cjs/components/LiveChatWidget/index.js.map +2 -2
- package/dist/cjs/components/LiveChatWidget/types.d.ts +213 -3
- package/dist/cjs/components/LiveChatWidget/types.js +1 -1
- package/dist/cjs/components/LiveChatWidget/types.js.map +1 -1
- package/dist/cjs/components/LiveChatWidget/utils/fetcher.d.ts +42 -0
- package/dist/cjs/components/LiveChatWidget/utils/fetcher.js +2 -0
- package/dist/cjs/components/LiveChatWidget/utils/fetcher.js.map +7 -0
- package/dist/cjs/components/chat/markdown.js +1 -1
- package/dist/cjs/components/chat/markdown.js.map +2 -2
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +1 -1
- package/dist/cjs/components/index.js.map +3 -3
- package/dist/cjs/stories/LiveChatWidget.stories.d.ts +1 -79
- package/dist/cjs/stories/LiveChatWidget.stories.js +3 -49
- package/dist/cjs/stories/LiveChatWidget.stories.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/LiveChatWidget.d.ts +21 -1
- package/dist/esm/components/LiveChatWidget/LiveChatWidget.js +1 -1
- package/dist/esm/components/LiveChatWidget/LiveChatWidget.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/api/chat.d.ts +23 -2
- package/dist/esm/components/LiveChatWidget/api/chat.js +2 -2
- package/dist/esm/components/LiveChatWidget/api/chat.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/ChatHeader.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/ChatHeader.js.map +2 -2
- package/dist/esm/components/LiveChatWidget/components/ChatInput.d.ts +5 -0
- package/dist/esm/components/LiveChatWidget/components/ChatInput.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/ChatInput.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/ChatMessage.js +2 -2
- package/dist/esm/components/LiveChatWidget/components/ChatMessage.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/ChatWindow.d.ts +5 -0
- package/dist/esm/components/LiveChatWidget/components/ChatWindow.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/ChatWindow.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/ComplianceDialog.d.ts +51 -0
- package/dist/esm/components/LiveChatWidget/components/ComplianceDialog.js +33 -0
- package/dist/esm/components/LiveChatWidget/components/ComplianceDialog.js.map +7 -0
- package/dist/esm/components/LiveChatWidget/components/MessageContent/CartCard.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent/CartCard.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageContent/ErrorBlock.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent/ErrorBlock.js.map +2 -2
- package/dist/esm/components/LiveChatWidget/components/MessageContent/FAQList.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent/FAQList.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageContent/PolicyBlock.js +2 -2
- package/dist/esm/components/LiveChatWidget/components/MessageContent/PolicyBlock.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageContent/ProductCard.d.ts +17 -24
- package/dist/esm/components/LiveChatWidget/components/MessageContent/ProductCard.js +1 -4
- package/dist/esm/components/LiveChatWidget/components/MessageContent/ProductCard.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageContent/ProductComparison.d.ts +7 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent/ProductComparison.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent/ProductComparison.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageContent/ProductList.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent/ProductList.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageContent/PromotionList.d.ts +4 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent/PromotionList.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent/PromotionList.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageContent/QuickReplies.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent/QuickReplies.js.map +2 -2
- package/dist/esm/components/LiveChatWidget/components/MessageContent/TextBlock.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent/TextBlock.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageContent.js +1 -1
- package/dist/esm/components/LiveChatWidget/components/MessageContent.js.map +2 -2
- package/dist/esm/components/LiveChatWidget/components/MessageList.js +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageList.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/constants.d.ts +5 -0
- package/dist/esm/components/LiveChatWidget/constants.js +1 -1
- package/dist/esm/components/LiveChatWidget/constants.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/hooks/useChatAPI.d.ts +9 -0
- package/dist/esm/components/LiveChatWidget/hooks/useChatAPI.js +1 -1
- package/dist/esm/components/LiveChatWidget/hooks/useChatAPI.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/hooks/useChatState.d.ts +36 -2
- package/dist/esm/components/LiveChatWidget/hooks/useChatState.js +1 -1
- package/dist/esm/components/LiveChatWidget/hooks/useChatState.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/index.d.ts +1 -1
- package/dist/esm/components/LiveChatWidget/index.js +1 -1
- package/dist/esm/components/LiveChatWidget/index.js.map +2 -2
- package/dist/esm/components/LiveChatWidget/types.d.ts +213 -3
- package/dist/esm/components/LiveChatWidget/utils/fetcher.d.ts +42 -0
- package/dist/esm/components/LiveChatWidget/utils/fetcher.js +2 -0
- package/dist/esm/components/LiveChatWidget/utils/fetcher.js.map +7 -0
- package/dist/esm/components/chat/markdown.js +1 -1
- package/dist/esm/components/chat/markdown.js.map +2 -2
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +1 -1
- package/dist/esm/components/index.js.map +3 -3
- package/dist/esm/stories/LiveChatWidget.stories.d.ts +1 -79
- package/dist/esm/stories/LiveChatWidget.stories.js +3 -49
- package/dist/esm/stories/LiveChatWidget.stories.js.map +3 -3
- package/dist/index.d.mts +1305 -0
- package/dist/index.d.ts +1305 -0
- package/dist/index.js +26656 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +26641 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +8 -1
- package/src/components/LiveChatWidget/LiveChatWidget.tsx +907 -0
- package/src/components/LiveChatWidget/api/chat.ts +175 -0
- package/src/components/LiveChatWidget/components/ChatBubble.tsx +152 -0
- package/src/components/LiveChatWidget/components/ChatHeader.tsx +150 -0
- package/src/components/LiveChatWidget/components/ChatInput.tsx +253 -0
- package/src/components/LiveChatWidget/components/ChatMessage.tsx +190 -0
- package/src/components/LiveChatWidget/components/ChatWindow.tsx +363 -0
- package/src/components/LiveChatWidget/components/ComplianceDialog.tsx +216 -0
- package/src/components/LiveChatWidget/components/MessageContent/CartCard.tsx +202 -0
- package/src/components/LiveChatWidget/components/MessageContent/ErrorBlock.tsx +75 -0
- package/src/components/LiveChatWidget/components/MessageContent/FAQList.tsx +128 -0
- package/src/components/LiveChatWidget/components/MessageContent/PolicyBlock.tsx +152 -0
- package/src/components/LiveChatWidget/components/MessageContent/ProductCard.tsx +227 -0
- package/src/components/LiveChatWidget/components/MessageContent/ProductComparison.tsx +377 -0
- package/src/components/LiveChatWidget/components/MessageContent/ProductList.tsx +293 -0
- package/src/components/LiveChatWidget/components/MessageContent/PromotionList.tsx +170 -0
- package/src/components/LiveChatWidget/components/MessageContent/QuickReplies.tsx +91 -0
- package/src/components/LiveChatWidget/components/MessageContent/TextBlock.tsx +110 -0
- package/src/components/LiveChatWidget/components/MessageContent/ThinkingBlock.tsx +53 -0
- package/src/components/LiveChatWidget/components/MessageContent/index.ts +16 -0
- package/src/components/LiveChatWidget/components/MessageContent.tsx +113 -0
- package/src/components/LiveChatWidget/components/MessageList.tsx +256 -0
- package/src/components/LiveChatWidget/components/ScrollAnchor.tsx +75 -0
- package/src/components/LiveChatWidget/constants.ts +36 -0
- package/src/components/LiveChatWidget/hooks/useChatAPI.ts +146 -0
- package/src/components/LiveChatWidget/hooks/useChatState.ts +1091 -0
- package/src/components/LiveChatWidget/hooks/useSession.ts +123 -0
- package/src/components/LiveChatWidget/index.tsx +63 -0
- package/src/components/LiveChatWidget/types.ts +1012 -0
- package/src/components/LiveChatWidget/utils/cartTransformers.ts +72 -0
- package/src/components/LiveChatWidget/utils/fetcher.ts +131 -0
- package/src/components/LiveChatWidget/utils/messageRenderers.ts +120 -0
- package/src/components/LiveChatWidget/utils/productTransformers.ts +149 -0
- package/src/components/LiveChatWidget/utils/userId.ts +140 -0
- package/src/components/LiveChatWidget/utils/validation.ts +99 -0
- package/src/components/chat/markdown.tsx +1 -1
- package/src/components/index.ts +23 -0
- package/src/stories/LiveChatWidget.stories.tsx +317 -0
- package/src/styles/livechat.css +346 -0
- package/dist/cjs/components/credits/context/hooks/useFunctionMemberPrice.d.ts +0 -7
- package/dist/cjs/components/credits/context/hooks/useFunctionMemberPrice.js +0 -2
- package/dist/cjs/components/credits/context/hooks/useFunctionMemberPrice.js.map +0 -7
- package/dist/cjs/components/credits/context/utils/atobID.d.ts +0 -1
- package/dist/cjs/components/credits/context/utils/atobID.js +0 -2
- package/dist/cjs/components/credits/context/utils/atobID.js.map +0 -7
- package/dist/cjs/components/credits/context/utils/functionDiscountCalculate.d.ts +0 -5
- package/dist/cjs/components/credits/context/utils/functionDiscountCalculate.js +0 -2
- package/dist/cjs/components/credits/context/utils/functionDiscountCalculate.js.map +0 -7
- package/dist/cjs/components/credits/context/utils/getFunctionMemberPrice.d.ts +0 -8
- package/dist/cjs/components/credits/context/utils/getFunctionMemberPrice.js +0 -2
- package/dist/cjs/components/credits/context/utils/getFunctionMemberPrice.js.map +0 -7
- package/dist/cjs/components/credits/context/utils/getFunctionMemberPriceDiscountConfig.d.ts +0 -9
- package/dist/cjs/components/credits/context/utils/getFunctionMemberPriceDiscountConfig.js +0 -2
- package/dist/cjs/components/credits/context/utils/getFunctionMemberPriceDiscountConfig.js.map +0 -7
- package/dist/cjs/components/credits/context/utils/variantGetCoupon.d.ts +0 -6
- package/dist/cjs/components/credits/context/utils/variantGetCoupon.js +0 -2
- package/dist/cjs/components/credits/context/utils/variantGetCoupon.js.map +0 -7
- package/dist/esm/components/credits/context/hooks/useFunctionMemberPrice.d.ts +0 -7
- package/dist/esm/components/credits/context/hooks/useFunctionMemberPrice.js +0 -2
- package/dist/esm/components/credits/context/hooks/useFunctionMemberPrice.js.map +0 -7
- package/dist/esm/components/credits/context/utils/atobID.d.ts +0 -1
- package/dist/esm/components/credits/context/utils/atobID.js +0 -2
- package/dist/esm/components/credits/context/utils/atobID.js.map +0 -7
- package/dist/esm/components/credits/context/utils/functionDiscountCalculate.d.ts +0 -5
- package/dist/esm/components/credits/context/utils/functionDiscountCalculate.js +0 -2
- package/dist/esm/components/credits/context/utils/functionDiscountCalculate.js.map +0 -7
- package/dist/esm/components/credits/context/utils/getFunctionMemberPrice.d.ts +0 -8
- package/dist/esm/components/credits/context/utils/getFunctionMemberPrice.js +0 -2
- package/dist/esm/components/credits/context/utils/getFunctionMemberPrice.js.map +0 -7
- package/dist/esm/components/credits/context/utils/getFunctionMemberPriceDiscountConfig.d.ts +0 -9
- package/dist/esm/components/credits/context/utils/getFunctionMemberPriceDiscountConfig.js +0 -2
- package/dist/esm/components/credits/context/utils/getFunctionMemberPriceDiscountConfig.js.map +0 -7
- package/dist/esm/components/credits/context/utils/variantGetCoupon.d.ts +0 -6
- package/dist/esm/components/credits/context/utils/variantGetCoupon.js +0 -2
- package/dist/esm/components/credits/context/utils/variantGetCoupon.js.map +0 -7
|
@@ -0,0 +1,1012 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LiveChat 组件核心类型定义
|
|
3
|
+
* 基于 specs/livechat-widget/data-model.md
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Session Types (会话)
|
|
8
|
+
// ============================================================================
|
|
9
|
+
|
|
10
|
+
export type SessionStatus = 'active' | 'expired'
|
|
11
|
+
|
|
12
|
+
export interface Session {
|
|
13
|
+
sessionId: string
|
|
14
|
+
userId: string
|
|
15
|
+
site: string
|
|
16
|
+
status: SessionStatus
|
|
17
|
+
createdAt?: number
|
|
18
|
+
lastActivityAt?: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ============================================================================
|
|
22
|
+
// Message Types (消息)
|
|
23
|
+
// ============================================================================
|
|
24
|
+
|
|
25
|
+
export type MessageRole = 'user' | 'assistant' | 'system' | 'tool'
|
|
26
|
+
|
|
27
|
+
export interface MessageMetadata {
|
|
28
|
+
tokenUsage?: {
|
|
29
|
+
inputTokens: number
|
|
30
|
+
outputTokens: number
|
|
31
|
+
}
|
|
32
|
+
toolCalls?: Array<{
|
|
33
|
+
id: string
|
|
34
|
+
type: string
|
|
35
|
+
name: string
|
|
36
|
+
}>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface Message {
|
|
40
|
+
id: string
|
|
41
|
+
sessionId?: string
|
|
42
|
+
role: MessageRole
|
|
43
|
+
content: MessageContent[]
|
|
44
|
+
timestamp: number
|
|
45
|
+
metadata?: MessageMetadata
|
|
46
|
+
structured_content?: Array<{
|
|
47
|
+
type: string
|
|
48
|
+
data: any
|
|
49
|
+
}>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ============================================================================
|
|
53
|
+
// Message Content Types (消息内容)
|
|
54
|
+
// ============================================================================
|
|
55
|
+
|
|
56
|
+
export type MessageContentType =
|
|
57
|
+
| 'text'
|
|
58
|
+
| 'product_card'
|
|
59
|
+
| 'product_list'
|
|
60
|
+
| 'product_comparison'
|
|
61
|
+
| 'policy'
|
|
62
|
+
| 'quick_replies'
|
|
63
|
+
| 'thinking'
|
|
64
|
+
| 'error'
|
|
65
|
+
| 'faq_list'
|
|
66
|
+
| 'cart'
|
|
67
|
+
|
|
68
|
+
export type MessageContent =
|
|
69
|
+
| TextContent
|
|
70
|
+
| ProductCardContent
|
|
71
|
+
| ProductListContent
|
|
72
|
+
| ProductComparisonContent
|
|
73
|
+
| PolicyContent
|
|
74
|
+
| QuickRepliesContent
|
|
75
|
+
| ThinkingContent
|
|
76
|
+
| ErrorContent
|
|
77
|
+
| FAQListContent
|
|
78
|
+
| PromotionListContent
|
|
79
|
+
| CartContent
|
|
80
|
+
|
|
81
|
+
export interface TextContent {
|
|
82
|
+
type: 'text'
|
|
83
|
+
text: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface ProductCardContent {
|
|
87
|
+
type: 'product_card'
|
|
88
|
+
data: {
|
|
89
|
+
product?: Product
|
|
90
|
+
rawProduct?: any // Raw backend product data (for custom render)
|
|
91
|
+
productHandle: string // Product ID from placeholder {{product:ID}}, for app-level product lookup
|
|
92
|
+
onAddToCart?: (product: Product) => void
|
|
93
|
+
productCardRender?: (product: any, productHandle: string) => React.ReactNode
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface ProductListContent {
|
|
98
|
+
type: 'product_list'
|
|
99
|
+
data: {
|
|
100
|
+
products: Product[]
|
|
101
|
+
title?: string
|
|
102
|
+
onAddToCart?: (product: Product) => void
|
|
103
|
+
commonText?: CommonText
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface ProductComparisonContent {
|
|
108
|
+
type: 'product_comparison'
|
|
109
|
+
data: {
|
|
110
|
+
products: Product[]
|
|
111
|
+
dimensions: {
|
|
112
|
+
price?: {
|
|
113
|
+
label: string
|
|
114
|
+
values: Array<{
|
|
115
|
+
product_id: string
|
|
116
|
+
min: number
|
|
117
|
+
max: number
|
|
118
|
+
currency: string
|
|
119
|
+
has_discount: boolean
|
|
120
|
+
}>
|
|
121
|
+
}
|
|
122
|
+
variants?: {
|
|
123
|
+
label: string
|
|
124
|
+
values: Array<{
|
|
125
|
+
product_id: string
|
|
126
|
+
count: number
|
|
127
|
+
}>
|
|
128
|
+
}
|
|
129
|
+
member_price?: {
|
|
130
|
+
label: string
|
|
131
|
+
values: Array<{
|
|
132
|
+
product_id: string
|
|
133
|
+
available: boolean
|
|
134
|
+
min: number
|
|
135
|
+
max: number
|
|
136
|
+
currency: string
|
|
137
|
+
}>
|
|
138
|
+
}
|
|
139
|
+
discount?: {
|
|
140
|
+
label: string
|
|
141
|
+
values: Array<{
|
|
142
|
+
product_id: string
|
|
143
|
+
has_discount: boolean
|
|
144
|
+
}>
|
|
145
|
+
}
|
|
146
|
+
[key: string]: any
|
|
147
|
+
}
|
|
148
|
+
onAddToCart?: (product: Product) => void
|
|
149
|
+
commonText?: CommonText
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface PolicyContent {
|
|
154
|
+
type: 'policy'
|
|
155
|
+
data: {
|
|
156
|
+
title: string
|
|
157
|
+
content: string
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface QuickRepliesContent {
|
|
162
|
+
type: 'quick_replies'
|
|
163
|
+
data: {
|
|
164
|
+
replies: QuickReply[]
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface ThinkingContent {
|
|
169
|
+
type: 'thinking'
|
|
170
|
+
data: {
|
|
171
|
+
status: string
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface ErrorContent {
|
|
176
|
+
type: 'error'
|
|
177
|
+
data: {
|
|
178
|
+
message: string
|
|
179
|
+
code?: string
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface FAQListContent {
|
|
184
|
+
type: 'faq_list'
|
|
185
|
+
data: {
|
|
186
|
+
found: boolean
|
|
187
|
+
count: number
|
|
188
|
+
total?: number
|
|
189
|
+
results: FAQItem[]
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface PromotionListContent {
|
|
194
|
+
type: 'promotion_list'
|
|
195
|
+
data: {
|
|
196
|
+
found: boolean
|
|
197
|
+
count: number
|
|
198
|
+
total?: number
|
|
199
|
+
results: PromotionItem[]
|
|
200
|
+
commonText?: CommonText
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ============================================================================
|
|
205
|
+
// FAQ Types (常见问题)
|
|
206
|
+
// ============================================================================
|
|
207
|
+
|
|
208
|
+
export type FAQCategory = 'shipping' | 'return' | 'product' | 'payment' | 'general'
|
|
209
|
+
|
|
210
|
+
export interface FAQItem {
|
|
211
|
+
id: string
|
|
212
|
+
question: string
|
|
213
|
+
answer: string
|
|
214
|
+
category: FAQCategory
|
|
215
|
+
keywords?: string[]
|
|
216
|
+
relatedQuestions?: string[]
|
|
217
|
+
metadata?: {
|
|
218
|
+
language?: string
|
|
219
|
+
priority?: number
|
|
220
|
+
lastUpdated?: string
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ============================================================================
|
|
225
|
+
// Promotion Types (促销活动)
|
|
226
|
+
// ============================================================================
|
|
227
|
+
|
|
228
|
+
export interface PromotionItem {
|
|
229
|
+
id: string
|
|
230
|
+
title: string
|
|
231
|
+
subtitle?: string
|
|
232
|
+
description?: string
|
|
233
|
+
banner_url?: string
|
|
234
|
+
url?: string
|
|
235
|
+
time_range: {
|
|
236
|
+
start: string
|
|
237
|
+
end?: string | null
|
|
238
|
+
is_active: boolean
|
|
239
|
+
}
|
|
240
|
+
priority?: number
|
|
241
|
+
product_count?: number
|
|
242
|
+
metadata?: {
|
|
243
|
+
display_order?: number
|
|
244
|
+
target_audience?: string
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ============================================================================
|
|
249
|
+
// Product Types (商品)
|
|
250
|
+
// ============================================================================
|
|
251
|
+
|
|
252
|
+
export type StockStatus = 'in_stock' | 'low_stock' | 'out_of_stock'
|
|
253
|
+
|
|
254
|
+
export interface Price {
|
|
255
|
+
amount: number
|
|
256
|
+
currency: string
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export interface PriceRange {
|
|
260
|
+
min: number
|
|
261
|
+
max: number
|
|
262
|
+
currency: string
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface VariantDiscount {
|
|
266
|
+
has_discount: boolean
|
|
267
|
+
discount_price?: number
|
|
268
|
+
discount_code?: string
|
|
269
|
+
discount_percentage?: number
|
|
270
|
+
/** 折扣类型:fixed_amount 固定金额折扣,percentage 百分比折扣 */
|
|
271
|
+
discount_type?: 'fixed_amount' | 'percentage'
|
|
272
|
+
/** 折扣数值(可能是字符串或数字) */
|
|
273
|
+
discount_value?: string | number
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface VariantMemberPrice {
|
|
277
|
+
has_member_price: boolean
|
|
278
|
+
price?: number
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface ProductFeatures {
|
|
282
|
+
is_new?: boolean
|
|
283
|
+
has_rental?: boolean
|
|
284
|
+
has_presale?: boolean
|
|
285
|
+
has_member_price?: boolean
|
|
286
|
+
has_discount?: boolean
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export interface Variant {
|
|
290
|
+
id: string
|
|
291
|
+
title: string
|
|
292
|
+
sku?: string
|
|
293
|
+
price?: Price
|
|
294
|
+
availableForSale: boolean
|
|
295
|
+
color?: string
|
|
296
|
+
discount?: VariantDiscount
|
|
297
|
+
memberPrice?: VariantMemberPrice
|
|
298
|
+
inventoryQuantity?: number
|
|
299
|
+
option1?: string
|
|
300
|
+
option2?: string
|
|
301
|
+
option3?: string
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface Product {
|
|
305
|
+
shopifyId: string
|
|
306
|
+
sku?: string
|
|
307
|
+
handle: string
|
|
308
|
+
title: string
|
|
309
|
+
description?: string
|
|
310
|
+
vendor?: string
|
|
311
|
+
price: Price
|
|
312
|
+
priceRange?: PriceRange
|
|
313
|
+
memberPriceRange?: PriceRange
|
|
314
|
+
imageUrl: string
|
|
315
|
+
productUrl: string
|
|
316
|
+
stockStatus: StockStatus
|
|
317
|
+
hotScore?: number
|
|
318
|
+
averageRating?: number
|
|
319
|
+
reviewCount?: number
|
|
320
|
+
variants?: Variant[]
|
|
321
|
+
variantCount?: number
|
|
322
|
+
availableCount?: number
|
|
323
|
+
features?: ProductFeatures
|
|
324
|
+
tags?: string[]
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// ============================================================================
|
|
328
|
+
// Quick Reply Types (快捷回复)
|
|
329
|
+
// ============================================================================
|
|
330
|
+
|
|
331
|
+
export interface QuickReply {
|
|
332
|
+
id: string
|
|
333
|
+
label: string
|
|
334
|
+
value: string
|
|
335
|
+
icon?: string
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ============================================================================
|
|
339
|
+
// Policy Types (政策)
|
|
340
|
+
// ============================================================================
|
|
341
|
+
|
|
342
|
+
export interface Policy {
|
|
343
|
+
title: string
|
|
344
|
+
content: string
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// ============================================================================
|
|
348
|
+
// Cart Types (购物车)
|
|
349
|
+
// ============================================================================
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* 购物车金额信息
|
|
353
|
+
*/
|
|
354
|
+
export interface CartAmount {
|
|
355
|
+
/** 金额字符串(如 "99.99") */
|
|
356
|
+
amount: string
|
|
357
|
+
/** 货币代码(如 "USD") */
|
|
358
|
+
currencyCode: string
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* 购物车价格汇总
|
|
363
|
+
*/
|
|
364
|
+
export interface CartCost {
|
|
365
|
+
/** 应付总价(已应用折扣) */
|
|
366
|
+
totalAmount: CartAmount
|
|
367
|
+
/** 原价小计(未应用折扣) */
|
|
368
|
+
subtotalAmount: CartAmount
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 购物车商品变体信息
|
|
373
|
+
*/
|
|
374
|
+
export interface CartMerchandise {
|
|
375
|
+
/** 变体 ID (Shopify ProductVariant GID) */
|
|
376
|
+
id: string
|
|
377
|
+
/** 变体标题(如 "Black", "Large" 等) */
|
|
378
|
+
title: string
|
|
379
|
+
/** 单价 */
|
|
380
|
+
price: CartAmount
|
|
381
|
+
/** 商品图片 URL */
|
|
382
|
+
image?: {
|
|
383
|
+
url: string
|
|
384
|
+
altText?: string
|
|
385
|
+
}
|
|
386
|
+
/** 关联的商品信息 */
|
|
387
|
+
product: {
|
|
388
|
+
/** 商品 ID */
|
|
389
|
+
id: string
|
|
390
|
+
/** 商品标题 */
|
|
391
|
+
title: string
|
|
392
|
+
/** 商品 handle */
|
|
393
|
+
handle: string
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 购物车商品行
|
|
399
|
+
*/
|
|
400
|
+
export interface CartLine {
|
|
401
|
+
/** 购物车行 ID (用于更新/删除操作) */
|
|
402
|
+
id: string
|
|
403
|
+
/** 商品数量 */
|
|
404
|
+
quantity: number
|
|
405
|
+
/** 价格信息 */
|
|
406
|
+
cost: {
|
|
407
|
+
/** 行总价(单价 × 数量,已应用折扣) */
|
|
408
|
+
totalAmount: CartAmount
|
|
409
|
+
/** 单价 */
|
|
410
|
+
amountPerQuantity: CartAmount
|
|
411
|
+
/** 行小计(单价 × 数量,未应用折扣) */
|
|
412
|
+
subtotalAmount: CartAmount
|
|
413
|
+
}
|
|
414
|
+
/** 商品变体信息 */
|
|
415
|
+
merchandise: CartMerchandise
|
|
416
|
+
/** 自定义属性(可选) */
|
|
417
|
+
attributes?: Array<{
|
|
418
|
+
key: string
|
|
419
|
+
value: string
|
|
420
|
+
}>
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 购物车折扣码
|
|
425
|
+
*/
|
|
426
|
+
export interface CartDiscountCode {
|
|
427
|
+
/** 折扣码 */
|
|
428
|
+
code: string
|
|
429
|
+
/** 是否有效/适用 */
|
|
430
|
+
applicable: boolean
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* 购物车数据
|
|
435
|
+
*/
|
|
436
|
+
export interface CartData {
|
|
437
|
+
/** 购物车是否为空 */
|
|
438
|
+
isEmpty: boolean
|
|
439
|
+
/** 购物车 ID (Shopify Cart GID) */
|
|
440
|
+
cartId: string
|
|
441
|
+
/** 商品总数量 */
|
|
442
|
+
totalQuantity: number
|
|
443
|
+
/** 商品列表 */
|
|
444
|
+
lines: CartLine[]
|
|
445
|
+
/** 价格汇总 */
|
|
446
|
+
cost: CartCost
|
|
447
|
+
/** 折扣码列表 */
|
|
448
|
+
discountCodes?: CartDiscountCode[]
|
|
449
|
+
/** 结账页面 URL */
|
|
450
|
+
checkoutUrl?: string
|
|
451
|
+
/** 购物车按钮回调函数 */
|
|
452
|
+
onCart?: (cartId: string, checkoutUrl?: string) => void
|
|
453
|
+
/** 通用文案配置 */
|
|
454
|
+
commonText?: CommonText
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* 购物车内容块
|
|
459
|
+
*/
|
|
460
|
+
export interface CartContent {
|
|
461
|
+
type: 'cart'
|
|
462
|
+
data: CartData
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// ============================================================================
|
|
466
|
+
// Backend Cart Types (后端购物车数据格式 - Shopify GraphQL)
|
|
467
|
+
// ============================================================================
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* 后端返回的购物车商品行数据 (Shopify GraphQL 格式)
|
|
471
|
+
*/
|
|
472
|
+
export interface BackendCartLineNode {
|
|
473
|
+
id: string
|
|
474
|
+
quantity: number
|
|
475
|
+
cost: {
|
|
476
|
+
totalAmount: CartAmount
|
|
477
|
+
amountPerQuantity: CartAmount
|
|
478
|
+
compareAtAmountPerQuantity?: CartAmount | null
|
|
479
|
+
subtotalAmount: CartAmount
|
|
480
|
+
}
|
|
481
|
+
discountAllocations: any[]
|
|
482
|
+
merchandise: {
|
|
483
|
+
id: string
|
|
484
|
+
title: string
|
|
485
|
+
availableForSale: boolean
|
|
486
|
+
quantityAvailable?: number
|
|
487
|
+
price: CartAmount
|
|
488
|
+
compareAtPrice?: CartAmount | null
|
|
489
|
+
image?: {
|
|
490
|
+
url: string
|
|
491
|
+
altText?: string | null
|
|
492
|
+
width?: number
|
|
493
|
+
height?: number
|
|
494
|
+
} | null
|
|
495
|
+
product: {
|
|
496
|
+
id: string
|
|
497
|
+
title: string
|
|
498
|
+
handle: string
|
|
499
|
+
vendor?: string
|
|
500
|
+
featuredImage?: {
|
|
501
|
+
url: string
|
|
502
|
+
altText?: string | null
|
|
503
|
+
width?: number
|
|
504
|
+
height?: number
|
|
505
|
+
} | null
|
|
506
|
+
tags?: string[]
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
attributes?: Array<{
|
|
510
|
+
key: string
|
|
511
|
+
value: string
|
|
512
|
+
}>
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* 后端返回的购物车数据 (Shopify GraphQL 格式)
|
|
517
|
+
*/
|
|
518
|
+
export interface BackendCartData {
|
|
519
|
+
id: string
|
|
520
|
+
checkoutUrl?: string
|
|
521
|
+
totalQuantity: number
|
|
522
|
+
lines: {
|
|
523
|
+
edges: Array<{
|
|
524
|
+
node: BackendCartLineNode
|
|
525
|
+
}>
|
|
526
|
+
}
|
|
527
|
+
cost: {
|
|
528
|
+
totalAmount: CartAmount
|
|
529
|
+
subtotalAmount: CartAmount
|
|
530
|
+
checkoutChargeAmount?: CartAmount
|
|
531
|
+
totalAmountEstimated?: boolean
|
|
532
|
+
subtotalAmountEstimated?: boolean
|
|
533
|
+
totalTaxAmount?: CartAmount | null
|
|
534
|
+
totalDutyAmount?: CartAmount | null
|
|
535
|
+
}
|
|
536
|
+
discountAllocations?: any[]
|
|
537
|
+
buyerIdentity?: any
|
|
538
|
+
attributes?: Array<{
|
|
539
|
+
key: string
|
|
540
|
+
value: string
|
|
541
|
+
}>
|
|
542
|
+
discountCodes?: any[]
|
|
543
|
+
createdAt?: string
|
|
544
|
+
updatedAt?: string
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// ============================================================================
|
|
548
|
+
// SSE Event Types (SSE 事件)
|
|
549
|
+
// ============================================================================
|
|
550
|
+
|
|
551
|
+
export type SSEEventType =
|
|
552
|
+
| 'message_start'
|
|
553
|
+
| 'content_delta'
|
|
554
|
+
| 'content_block'
|
|
555
|
+
| 'message_end'
|
|
556
|
+
| 'tool_start'
|
|
557
|
+
| 'tool_end'
|
|
558
|
+
| 'status'
|
|
559
|
+
| 'error'
|
|
560
|
+
| 'done'
|
|
561
|
+
|
|
562
|
+
export interface SSEEvent<T = any> {
|
|
563
|
+
event: SSEEventType | null
|
|
564
|
+
data: T
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// 具体事件数据类型
|
|
568
|
+
export interface MessageStartData {
|
|
569
|
+
sessionId: string
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export interface ContentDeltaData {
|
|
573
|
+
text: string
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export interface ContentBlockData {
|
|
577
|
+
type: string
|
|
578
|
+
data: any
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export interface MessageEndData {
|
|
582
|
+
usage: {
|
|
583
|
+
inputTokens: number
|
|
584
|
+
outputTokens: number
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export interface ToolStartData {
|
|
589
|
+
id: string
|
|
590
|
+
type: string
|
|
591
|
+
name: string
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
export interface ToolEndData {
|
|
595
|
+
id: string
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
export interface StatusData {
|
|
599
|
+
type: string
|
|
600
|
+
message?: string
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export interface ErrorData {
|
|
604
|
+
message: string
|
|
605
|
+
code?: string
|
|
606
|
+
type?: string
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// ============================================================================
|
|
610
|
+
// API Request/Response Types (API 请求响应)
|
|
611
|
+
// ============================================================================
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* 流式对话请求参数
|
|
615
|
+
*/
|
|
616
|
+
export interface ChatStreamRequest {
|
|
617
|
+
/** 用户的消息文本 */
|
|
618
|
+
message: string
|
|
619
|
+
/** 用户标识符 */
|
|
620
|
+
user_id: string
|
|
621
|
+
/** 来自 new-session 端点的会话 ID */
|
|
622
|
+
session_id: string
|
|
623
|
+
/** 可选的上下文信息 */
|
|
624
|
+
context?: {
|
|
625
|
+
/** 用于购物车操作的 Shopify 购物车 ID */
|
|
626
|
+
cartId?: string
|
|
627
|
+
/** Storefront API 访问令牌 */
|
|
628
|
+
accessToken?: string
|
|
629
|
+
/** 已登录用户的 ID */
|
|
630
|
+
real_user_id?: string
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export interface NewSessionRequest {
|
|
635
|
+
user_id: string
|
|
636
|
+
session_id?: string
|
|
637
|
+
site?: string
|
|
638
|
+
channel_code?: string
|
|
639
|
+
real_user_id?: string
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
export interface NewSessionResponse {
|
|
643
|
+
success: boolean
|
|
644
|
+
sessionId: string
|
|
645
|
+
message: string
|
|
646
|
+
resumed?: boolean
|
|
647
|
+
messages?: Message[]
|
|
648
|
+
welcomeMessage?: string
|
|
649
|
+
quickQuestions?: string[]
|
|
650
|
+
brand?: string
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
export interface ErrorResponse {
|
|
654
|
+
success: boolean
|
|
655
|
+
error: string
|
|
656
|
+
code?: string
|
|
657
|
+
details?: any
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// ============================================================================
|
|
661
|
+
// Common Text Types (通用文案)
|
|
662
|
+
// ============================================================================
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* 通用文案配置
|
|
666
|
+
* 用于自定义组件中的按钮文案
|
|
667
|
+
*/
|
|
668
|
+
export interface CommonText {
|
|
669
|
+
/**
|
|
670
|
+
* 产品列表展开按钮文案
|
|
671
|
+
* @default "Learn More"
|
|
672
|
+
*/
|
|
673
|
+
learnMore?: string
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* 产品列表收起按钮文案
|
|
677
|
+
* @default "Show Less"
|
|
678
|
+
*/
|
|
679
|
+
showLess?: string
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* 添加到购物车按钮文案
|
|
683
|
+
* @default "Add to Cart"
|
|
684
|
+
*/
|
|
685
|
+
addToCart?: string
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* 查看购物车/更多按钮文案
|
|
689
|
+
* @default "View More"
|
|
690
|
+
*/
|
|
691
|
+
viewMore?: string
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* 折扣标签后缀文案(如 "20% OFF" 中的 "OFF")
|
|
695
|
+
* @default "OFF"
|
|
696
|
+
*/
|
|
697
|
+
off?: string
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* 购物车总计文案
|
|
701
|
+
* @default "Total"
|
|
702
|
+
*/
|
|
703
|
+
total?: string
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// ============================================================================
|
|
707
|
+
// Compliance Dialog Types (法规协议弹窗)
|
|
708
|
+
// ============================================================================
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* 法规协议弹窗配置
|
|
712
|
+
*/
|
|
713
|
+
export interface ComplianceDialogConfig {
|
|
714
|
+
/**
|
|
715
|
+
* 弹窗标题
|
|
716
|
+
* @example "Hi! I'm your eufy AI assistant."
|
|
717
|
+
*/
|
|
718
|
+
title: string
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* 弹窗内容文本(支持 HTML)
|
|
722
|
+
* @example "AI-generated responses can be inaccurate. Please verify important info. Do not input sensitive personal data"
|
|
723
|
+
*/
|
|
724
|
+
content: string
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* 勾选框文本(支持完整 HTML,包括链接)
|
|
728
|
+
* 可以直接包含 <a> 标签等 HTML 元素
|
|
729
|
+
* @example "By starting to use \"Live Chat\", you agree to Anker's <a href=\"https://www.anker.com/privacy\" target=\"_blank\">LIVE CHAT PRIVACY NOTICE</a>."
|
|
730
|
+
*/
|
|
731
|
+
checkboxText: string
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* 同意按钮文本
|
|
735
|
+
* @default "Agree"
|
|
736
|
+
*/
|
|
737
|
+
agreeButtonText?: string
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Cookie 名称,用于记录用户同意状态
|
|
741
|
+
* Cookie 有效期为 365 天
|
|
742
|
+
* @default "livechat_compliance_agreed"
|
|
743
|
+
*/
|
|
744
|
+
cookieName?: string
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// ============================================================================
|
|
748
|
+
// Component Props Types (组件 Props)
|
|
749
|
+
// ============================================================================
|
|
750
|
+
|
|
751
|
+
export interface LiveChatWidgetProps {
|
|
752
|
+
/**
|
|
753
|
+
* API 基础 URL
|
|
754
|
+
* @example "https://beta-api-livechat.anker.com"
|
|
755
|
+
*/
|
|
756
|
+
apiBaseUrl: string
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* 自定义请求头
|
|
760
|
+
* 将在所有 API 请求中添加这些请求头
|
|
761
|
+
* @example { "Authorization": "Bearer token", "X-Custom-Header": "value" }
|
|
762
|
+
*/
|
|
763
|
+
headers?: Record<string, string>
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* reCAPTCHA site key
|
|
767
|
+
* 提供此参数将自动启用 reCAPTCHA v3 验证
|
|
768
|
+
* @example "6LfS4J4pAAAAACX1e_WrxutmxxzCK7FU4WzVqL14"
|
|
769
|
+
*/
|
|
770
|
+
recaptchaSitekey?: string
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* reCAPTCHA action 前缀
|
|
774
|
+
* 实际使用时会根据不同接口添加后缀(如 chat_stream, new_session)
|
|
775
|
+
* @default "livechat"
|
|
776
|
+
*/
|
|
777
|
+
recaptchaAction?: string
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Shopify 店铺域名
|
|
781
|
+
* @example "www.eufy.com"
|
|
782
|
+
*/
|
|
783
|
+
site?: string
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* 渠道编码
|
|
787
|
+
* 用于标识来源渠道
|
|
788
|
+
* @example "web_homepage"
|
|
789
|
+
*/
|
|
790
|
+
channelCode?: string
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* 已登录用户的 ID(可选)
|
|
794
|
+
* 如果提供,将在 API 请求中传递
|
|
795
|
+
*/
|
|
796
|
+
loginUserId?: string
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Shopify 购物车 ID(可选)
|
|
800
|
+
* 用于购物车操作,将在 stream 接口的 context 中传递
|
|
801
|
+
* @example "gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSkZH..."
|
|
802
|
+
*/
|
|
803
|
+
cartId?: string
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Storefront API 访问令牌(可选)
|
|
807
|
+
* 用于购物车操作,将在 stream 接口的 context 中传递
|
|
808
|
+
*/
|
|
809
|
+
accessToken?: string
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* 气泡按钮位置
|
|
813
|
+
* 自定义位置对象:{ top?: string, bottom?: string, left?: string, right?: string }
|
|
814
|
+
* @default { bottom: "1.5rem", right: "1.5rem" }
|
|
815
|
+
* @example
|
|
816
|
+
* // 自定义位置
|
|
817
|
+
* position={{ bottom: "20px", right: "30px" }}
|
|
818
|
+
* position={{ top: "100px", left: "50px" }}
|
|
819
|
+
*/
|
|
820
|
+
position?: BubblePosition
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* 欢迎消息
|
|
824
|
+
*/
|
|
825
|
+
welcomeMessage?: string
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* 初始快捷回复按钮
|
|
829
|
+
*/
|
|
830
|
+
quickReplies?: QuickReply[]
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* 自定义消息渲染器
|
|
834
|
+
*/
|
|
835
|
+
customRenderers?: Record<string, MessageRenderer>
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Logo URL
|
|
839
|
+
*/
|
|
840
|
+
logoUrl?: string
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* 聊天窗口标题
|
|
844
|
+
* @default "AI 助手"
|
|
845
|
+
*/
|
|
846
|
+
title?: string
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* 聊天气泡按钮图标(图片 URL)
|
|
850
|
+
* 如果提供,将使用图片替代默认的 SVG 图标
|
|
851
|
+
*/
|
|
852
|
+
chatBubbleIcon?: string
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* 受控模式:是否打开聊天窗口
|
|
856
|
+
* 提供此参数时,组件将处于受控模式
|
|
857
|
+
* @example
|
|
858
|
+
* ```tsx
|
|
859
|
+
* const [isOpen, setIsOpen] = useState(false)
|
|
860
|
+
* <LiveChatWidget open={isOpen} onOpenChange={setIsOpen} />
|
|
861
|
+
* ```
|
|
862
|
+
*/
|
|
863
|
+
open?: boolean
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* 受控模式:打开/关闭状态变化回调
|
|
867
|
+
* 【必需】配合 `open` 使用,用于同步状态到父组件
|
|
868
|
+
* 当用户点击打开或关闭按钮时触发
|
|
869
|
+
* @example
|
|
870
|
+
* ```tsx
|
|
871
|
+
* <LiveChatWidget
|
|
872
|
+
* open={isOpen}
|
|
873
|
+
* onOpenChange={setIsOpen} // 必需:同步状态
|
|
874
|
+
* />
|
|
875
|
+
* ```
|
|
876
|
+
*/
|
|
877
|
+
onOpenChange?: (open: boolean) => void
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* 【可选】窗口打开事件监听
|
|
881
|
+
* 用于埋点、日志等副作用,不影响状态控制
|
|
882
|
+
* 在 onOpenChange 之后触发
|
|
883
|
+
* @example
|
|
884
|
+
* ```tsx
|
|
885
|
+
* <LiveChatWidget
|
|
886
|
+
* open={isOpen}
|
|
887
|
+
* onOpenChange={setIsOpen}
|
|
888
|
+
* onOpen={() => trackEvent('chat_opened')} // 可选:埋点
|
|
889
|
+
* />
|
|
890
|
+
* ```
|
|
891
|
+
*/
|
|
892
|
+
onOpen?: () => void
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* 【可选】窗口关闭事件监听
|
|
896
|
+
* 用于埋点、日志等副作用,不影响状态控制
|
|
897
|
+
* 在 onOpenChange 之后触发
|
|
898
|
+
* @example
|
|
899
|
+
* ```tsx
|
|
900
|
+
* <LiveChatWidget
|
|
901
|
+
* open={isOpen}
|
|
902
|
+
* onOpenChange={setIsOpen}
|
|
903
|
+
* onClose={() => trackEvent('chat_closed')} // 可选:埋点
|
|
904
|
+
* />
|
|
905
|
+
* ```
|
|
906
|
+
*/
|
|
907
|
+
onClose?: () => void
|
|
908
|
+
onMessageSend?: (message: string) => void
|
|
909
|
+
onError?: (error: Error) => void
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* AI 消息回调
|
|
913
|
+
*/
|
|
914
|
+
/**
|
|
915
|
+
* AI 回复文本消息时触发
|
|
916
|
+
*/
|
|
917
|
+
onTextMessage?: () => void
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* AI 回复商品列表卡片时触发
|
|
921
|
+
*/
|
|
922
|
+
onProductList?: () => void
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* AI 回复促销卡片时触发
|
|
926
|
+
* @param promotions 促销活动数组数据
|
|
927
|
+
*/
|
|
928
|
+
onPromotionList?: (promotions: PromotionItem[]) => void
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* 商品操作回调
|
|
932
|
+
*/
|
|
933
|
+
onAddToCart?: (product: Product) => void
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* 购物车按钮点击回调
|
|
937
|
+
*/
|
|
938
|
+
onCart?: (cartId: string, checkoutUrl?: string) => void
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* 是否显示新会话按钮
|
|
942
|
+
* @default true
|
|
943
|
+
*/
|
|
944
|
+
showNewSessionButton?: boolean
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* 通用文案配置
|
|
948
|
+
* 用于自定义按钮文案
|
|
949
|
+
*/
|
|
950
|
+
commonText?: CommonText
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* 自定义产品卡片渲染函数
|
|
954
|
+
* 用于自定义渲染 product_card 类型的产品卡片
|
|
955
|
+
* 当提供此函数时,将替代默认的产品卡片渲染逻辑
|
|
956
|
+
* @param product 原始后端产品数据(未经转换的数据),如果在 product_list 中找不到则为 undefined
|
|
957
|
+
* @param productHandle 文本占位符中的产品 ID(如 {{product:ID}} 中的 ID),可用于应用层查询产品数据
|
|
958
|
+
* @returns React 可渲染的内容
|
|
959
|
+
* @example
|
|
960
|
+
* ```tsx
|
|
961
|
+
* <LiveChatWidget
|
|
962
|
+
* productCardRender={(product, productHandle) => {
|
|
963
|
+
* // product 可能为 undefined,此时可用 productHandle 查询产品
|
|
964
|
+
* if (!product) {
|
|
965
|
+
* return <ProductCardByHandle handle={productHandle} />
|
|
966
|
+
* }
|
|
967
|
+
* return (
|
|
968
|
+
* <div>
|
|
969
|
+
* <h3>{product.title}</h3>
|
|
970
|
+
* <p>{product.price_range?.min}</p>
|
|
971
|
+
* </div>
|
|
972
|
+
* )
|
|
973
|
+
* }}
|
|
974
|
+
* />
|
|
975
|
+
* ```
|
|
976
|
+
*/
|
|
977
|
+
productCardRender?: (product: any, productHandle: string) => React.ReactNode
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* 输入框底部提示文本
|
|
981
|
+
* 不传入则不显示
|
|
982
|
+
*/
|
|
983
|
+
bottomTips?: string
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* 法规协议弹窗配置
|
|
987
|
+
* 提供此参数将在用户首次点击聊天气泡时显示法规协议弹窗
|
|
988
|
+
* 用户同意后才会打开聊天窗口
|
|
989
|
+
*/
|
|
990
|
+
complianceConfig?: ComplianceDialogConfig
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
export interface MessageRenderer {
|
|
994
|
+
render: (content: MessageContent, isUser: boolean, isSystem: boolean) => React.ReactNode
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
export interface CustomRendererMap {
|
|
998
|
+
[type: string]: MessageRenderer
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// ============================================================================
|
|
1002
|
+
// Utility Types (工具类型)
|
|
1003
|
+
// ============================================================================
|
|
1004
|
+
|
|
1005
|
+
export interface PositionStyles {
|
|
1006
|
+
bottom?: string
|
|
1007
|
+
top?: string
|
|
1008
|
+
left?: string
|
|
1009
|
+
right?: string
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
export type BubblePosition = PositionStyles
|