@tbox.cn/app-agent-ui-kit 0.0.0-stage → 1.0.0-alpha.1
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/LICENSE +21 -0
- package/README.md +16 -2
- package/assets/keyboard-circle.svg +12 -0
- package/assets/more-circle.svg +3 -0
- package/assets/new-chat.svg +3 -0
- package/assets/quick-command-star.svg +3 -0
- package/assets/send-gradient.svg +14 -0
- package/assets/stop@2x.png +0 -0
- package/assets/voice-circle.svg +3 -0
- package/package.json +55 -3
- package/src/ChatPage.less +62 -0
- package/src/ChatPage.tsx +305 -0
- package/src/chat-config.test.ts +82 -0
- package/src/chat-config.ts +62 -0
- package/src/components/ActionBar/DebugButton.test.tsx +84 -0
- package/src/components/ActionBar/DebugButton.tsx +53 -0
- package/src/components/ActionBar/index.less +123 -0
- package/src/components/ActionBar/index.test.tsx +83 -0
- package/src/components/ActionBar/index.tsx +159 -0
- package/src/components/CardRenderer.tsx +36 -0
- package/src/components/ChatHeader/index.less +148 -0
- package/src/components/ChatHeader/index.test.tsx +74 -0
- package/src/components/ChatHeader/index.tsx +75 -0
- package/src/components/ChatInput/index.less +394 -0
- package/src/components/ChatInput/index.test.tsx +156 -0
- package/src/components/ChatInput/index.tsx +284 -0
- package/src/components/ChatInput/voice/VoicePressField.tsx +34 -0
- package/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +51 -0
- package/src/components/ChatInput/voice/machine.ts +27 -0
- package/src/components/ChatInput/voice/useVoicePress.ts +207 -0
- package/src/components/HistoryEntry/index.less +49 -0
- package/src/components/HistoryEntry/index.tsx +42 -0
- package/src/components/MediaList/index.less +241 -0
- package/src/components/MediaList/index.tsx +256 -0
- package/src/components/MessageBubble/index.less +325 -0
- package/src/components/MessageBubble/index.test.tsx +134 -0
- package/src/components/MessageBubble/index.tsx +177 -0
- package/src/components/PullDownIndicator/index.less +32 -0
- package/src/components/PullDownIndicator/index.tsx +32 -0
- package/src/components/QuickCommands/index.less +63 -0
- package/src/components/QuickCommands/index.test.tsx +99 -0
- package/src/components/QuickCommands/index.tsx +52 -0
- package/src/components/ReasoningBlock/index.less +90 -0
- package/src/components/ReasoningBlock/index.tsx +56 -0
- package/src/components/ScrollToBottomButton/index.less +32 -0
- package/src/components/ScrollToBottomButton/index.tsx +10 -0
- package/src/components/ToolCallBlock/detail.test.ts +346 -0
- package/src/components/ToolCallBlock/detail.ts +204 -0
- package/src/components/ToolCallBlock/index.less +312 -0
- package/src/components/ToolCallBlock/index.test.tsx +261 -0
- package/src/components/ToolCallBlock/index.tsx +212 -0
- package/src/components/ToolCallBlock/titles.ts +102 -0
- package/src/hooks/use-drag-gesture.test.ts +66 -0
- package/src/hooks/use-drag-gesture.ts +129 -0
- package/src/hooks/use-pull-down-history.ts +241 -0
- package/src/hooks/use-pull-down-wheel-native.test.ts +64 -0
- package/src/hooks/useMediaUpload.ts +242 -0
- package/src/hooks/useTTSAutoPlay.ts +82 -0
- package/src/index.ts +69 -0
- package/src/store-context.tsx +92 -0
- package/src/test/setup.ts +7 -0
- package/src/theme/contract.json +72 -0
- package/src/theme/global.less +99 -0
- package/src/theme/motion.less +19 -0
- package/src/theme/theme-contract.test.ts +69 -0
- package/src/theme/theme.ts +17 -0
- package/src/theme/tokens.less +79 -0
- package/src/types.ts +29 -0
- package/src/utils/copyText.ts +11 -0
- package/src/utils/haptics.test.ts +51 -0
- package/src/utils/haptics.ts +44 -0
- package/src/utils/imagePreview.ts +10 -0
- package/src/utils/pull-down-machine.test.ts +188 -0
- package/src/utils/pull-down-machine.ts +157 -0
- package/src/utils/session-error.ts +5 -0
- package/src/utils/toast.ts +15 -0
- package/src/utils/tool-call-display.test.ts +240 -0
- package/src/utils/tool-call-display.ts +146 -0
- package/src/vite-env.d.ts +1 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { X, Warning, Prohibit, Plus, VideoCamera } from '@phosphor-icons/react';
|
|
3
|
+
import { previewImages } from '../../utils/imagePreview';
|
|
4
|
+
import { toast } from '../../utils/toast';
|
|
5
|
+
import type { MediaItem } from '../../types';
|
|
6
|
+
import './index.less';
|
|
7
|
+
|
|
8
|
+
/** 媒体选项图标(远程素材,对齐原模板)。 */
|
|
9
|
+
const POPOVER_ICONS: Record<string, { icon: string; label: string; bg: string }> = {
|
|
10
|
+
image: {
|
|
11
|
+
icon: 'https://mdn.alipayobjects.com/huamei_nzq4hr/afts/img/A*DfDhSYAMzoQAAAAAHiAAAAgAel-hAQ/original',
|
|
12
|
+
label: '相册',
|
|
13
|
+
bg: '#0000001a',
|
|
14
|
+
},
|
|
15
|
+
camera: {
|
|
16
|
+
icon: 'https://mdn.alipayobjects.com/huamei_nzq4hr/afts/img/A*xdKLSabxqmQAAAAAOnAAAAgAel-hAQ/original',
|
|
17
|
+
label: '拍摄',
|
|
18
|
+
bg: '#096bfa26',
|
|
19
|
+
},
|
|
20
|
+
video: {
|
|
21
|
+
icon: 'https://mdn.alipayobjects.com/huamei_nzq4hr/afts/img/A*DfDhSYAMzoQAAAAAHiAAAAgAel-hAQ/original',
|
|
22
|
+
label: '视频',
|
|
23
|
+
bg: '#096bfa26',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function formatSize(bytes?: number): string {
|
|
28
|
+
if (!bytes) return '';
|
|
29
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
30
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
31
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function ImageItemCard({
|
|
35
|
+
item,
|
|
36
|
+
allImages,
|
|
37
|
+
onRemove,
|
|
38
|
+
onRetry,
|
|
39
|
+
}: {
|
|
40
|
+
item: MediaItem;
|
|
41
|
+
allImages: string[];
|
|
42
|
+
onRemove: (id: string) => void;
|
|
43
|
+
onRetry?: (id: string) => void;
|
|
44
|
+
}) {
|
|
45
|
+
const isUploading = !!item.isUploading;
|
|
46
|
+
const isFailed = !!item.uploadFailed;
|
|
47
|
+
const isIllegal = !!item.illegal;
|
|
48
|
+
const progress = item.uploadProgress ?? 0;
|
|
49
|
+
|
|
50
|
+
const onClick = () => {
|
|
51
|
+
if (isUploading) return;
|
|
52
|
+
if (isFailed) return onRetry?.(item.id);
|
|
53
|
+
if (isIllegal) return void toast('内容未过审核');
|
|
54
|
+
previewImages(allImages, allImages.indexOf(item.src));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div className="tbox-media-item tbox-media-item--image" onClick={onClick}>
|
|
59
|
+
<img className="tbox-media-item__thumb" src={item.src} alt="" />
|
|
60
|
+
|
|
61
|
+
{isUploading && (
|
|
62
|
+
<div className="tbox-media-item__overlay">
|
|
63
|
+
<div
|
|
64
|
+
className="tbox-media-item__progress-ring"
|
|
65
|
+
style={{ background: `conic-gradient(#fff ${progress}%, rgba(255,255,255,0.25) ${progress}%)` }}
|
|
66
|
+
>
|
|
67
|
+
<div className="tbox-media-item__progress-inner">
|
|
68
|
+
<span className="tbox-media-item__progress-text">{progress}%</span>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
)}
|
|
73
|
+
|
|
74
|
+
{isFailed && (
|
|
75
|
+
<div className="tbox-media-item__overlay">
|
|
76
|
+
<div className="tbox-media-item__status-icon">
|
|
77
|
+
<Warning size={20} color="#fff" />
|
|
78
|
+
</div>
|
|
79
|
+
<span className="tbox-media-item__status-text">点击重试</span>
|
|
80
|
+
</div>
|
|
81
|
+
)}
|
|
82
|
+
|
|
83
|
+
{isIllegal && (
|
|
84
|
+
<div className="tbox-media-item__overlay">
|
|
85
|
+
<div className="tbox-media-item__status-icon">
|
|
86
|
+
<Prohibit size={20} color="#fff" />
|
|
87
|
+
</div>
|
|
88
|
+
<span className="tbox-media-item__status-text">未过审核</span>
|
|
89
|
+
</div>
|
|
90
|
+
)}
|
|
91
|
+
|
|
92
|
+
{!isUploading && (
|
|
93
|
+
<div className="tbox-media-item__remove" onClick={(e) => { e.stopPropagation(); onRemove(item.id); }}>
|
|
94
|
+
<X size={14} color="#fff" />
|
|
95
|
+
</div>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function FileItemCard({
|
|
102
|
+
item,
|
|
103
|
+
onRemove,
|
|
104
|
+
onRetry,
|
|
105
|
+
}: {
|
|
106
|
+
item: MediaItem;
|
|
107
|
+
onRemove: (id: string) => void;
|
|
108
|
+
onRetry?: (id: string) => void;
|
|
109
|
+
}) {
|
|
110
|
+
const isUploading = !!item.isUploading;
|
|
111
|
+
const isFailed = !!item.uploadFailed;
|
|
112
|
+
|
|
113
|
+
const meta = isUploading
|
|
114
|
+
? `上传中...${item.uploadProgress ?? 0}%`
|
|
115
|
+
: isFailed
|
|
116
|
+
? '上传失败'
|
|
117
|
+
: formatSize(item.size);
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<div className="tbox-file-item" onClick={() => isFailed && onRetry?.(item.id)}>
|
|
121
|
+
<div className="tbox-file-item__icon">
|
|
122
|
+
<VideoCamera size={28} color="#506fff" />
|
|
123
|
+
</div>
|
|
124
|
+
<div className="tbox-file-item__info">
|
|
125
|
+
<span className="tbox-file-item__name">{item.name ?? '未知文件'}</span>
|
|
126
|
+
<span className={`tbox-file-item__meta${isFailed ? ' tbox-file-item__meta--failed' : ''}`}>{meta}</span>
|
|
127
|
+
</div>
|
|
128
|
+
{!isUploading && (
|
|
129
|
+
<div className="tbox-media-item__remove" onClick={(e) => { e.stopPropagation(); onRemove(item.id); }}>
|
|
130
|
+
<X size={14} color="#fff" />
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function MediaPopover({
|
|
138
|
+
visible,
|
|
139
|
+
options,
|
|
140
|
+
onSelect,
|
|
141
|
+
}: {
|
|
142
|
+
visible: boolean;
|
|
143
|
+
options: { type: string; icon: string; label: string; bg: string }[];
|
|
144
|
+
onSelect: (type: string) => void;
|
|
145
|
+
}) {
|
|
146
|
+
return (
|
|
147
|
+
<div className={`tbox-media-popover${visible ? ' tbox-media-popover--visible' : ''}`}>
|
|
148
|
+
{options.map((opt) => (
|
|
149
|
+
<div
|
|
150
|
+
key={opt.type}
|
|
151
|
+
className="tbox-media-popover__item"
|
|
152
|
+
onClick={(e) => { e.stopPropagation(); onSelect(opt.type); }}
|
|
153
|
+
>
|
|
154
|
+
<div className="tbox-media-popover__icon-wrap" style={{ background: opt.bg }}>
|
|
155
|
+
<img className="tbox-media-popover__icon" src={opt.icon} alt="" />
|
|
156
|
+
</div>
|
|
157
|
+
<span className="tbox-media-popover__label">{opt.label}</span>
|
|
158
|
+
</div>
|
|
159
|
+
))}
|
|
160
|
+
</div>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface MediaListProps {
|
|
165
|
+
items: MediaItem[];
|
|
166
|
+
onRemove: (id: string) => void;
|
|
167
|
+
onRetry?: (id: string) => void;
|
|
168
|
+
onPickImage?: () => void;
|
|
169
|
+
onPickCamera?: () => void;
|
|
170
|
+
onPickVideo?: () => void;
|
|
171
|
+
enableImage?: boolean;
|
|
172
|
+
enableVideo?: boolean;
|
|
173
|
+
isWebPc?: boolean;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** 已选媒体预览列表(对齐原模板:进度环 / 失败-未过审 overlay / 删除 / 末尾加号 popover)。 */
|
|
177
|
+
export function MediaList({
|
|
178
|
+
items,
|
|
179
|
+
onRemove,
|
|
180
|
+
onRetry,
|
|
181
|
+
onPickImage,
|
|
182
|
+
onPickCamera,
|
|
183
|
+
onPickVideo,
|
|
184
|
+
enableImage,
|
|
185
|
+
enableVideo,
|
|
186
|
+
isWebPc,
|
|
187
|
+
}: MediaListProps) {
|
|
188
|
+
const [popoverVisible, setPopoverVisible] = useState(false);
|
|
189
|
+
const hasCamera = !!enableImage && !isWebPc;
|
|
190
|
+
|
|
191
|
+
const options = [
|
|
192
|
+
enableImage && { type: 'image', ...POPOVER_ICONS.image },
|
|
193
|
+
hasCamera && { type: 'camera', ...POPOVER_ICONS.camera },
|
|
194
|
+
enableVideo && { type: 'video', ...POPOVER_ICONS.video },
|
|
195
|
+
].filter(Boolean) as { type: string; icon: string; label: string; bg: string }[];
|
|
196
|
+
|
|
197
|
+
const allImages = items
|
|
198
|
+
.filter((i) => i.type === 'image' && !i.isUploading && !i.uploadFailed && !i.illegal)
|
|
199
|
+
.map((i) => i.src);
|
|
200
|
+
|
|
201
|
+
const handleAddClick = useCallback(() => {
|
|
202
|
+
if (options.length <= 1) {
|
|
203
|
+
if (enableImage) onPickImage?.();
|
|
204
|
+
else if (enableVideo) onPickVideo?.();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
setPopoverVisible((v) => !v);
|
|
208
|
+
}, [options.length, enableImage, enableVideo, onPickImage, onPickVideo]);
|
|
209
|
+
|
|
210
|
+
const handleSelect = useCallback(
|
|
211
|
+
(type: string) => {
|
|
212
|
+
setPopoverVisible(false);
|
|
213
|
+
if (type === 'image') onPickImage?.();
|
|
214
|
+
else if (type === 'camera') onPickCamera?.();
|
|
215
|
+
else if (type === 'video') onPickVideo?.();
|
|
216
|
+
},
|
|
217
|
+
[onPickImage, onPickCamera, onPickVideo],
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
if (!popoverVisible) return;
|
|
222
|
+
const onDown = (e: MouseEvent | TouchEvent) => {
|
|
223
|
+
const t = e.target as HTMLElement;
|
|
224
|
+
if (t && !t.closest('.tbox-media-add') && !t.closest('.tbox-media-popover')) setPopoverVisible(false);
|
|
225
|
+
};
|
|
226
|
+
document.addEventListener('mousedown', onDown);
|
|
227
|
+
document.addEventListener('touchstart', onDown, { passive: true });
|
|
228
|
+
return () => {
|
|
229
|
+
document.removeEventListener('mousedown', onDown);
|
|
230
|
+
document.removeEventListener('touchstart', onDown);
|
|
231
|
+
};
|
|
232
|
+
}, [popoverVisible]);
|
|
233
|
+
|
|
234
|
+
if (items.length === 0) return null;
|
|
235
|
+
const showAddButton = options.length > 0;
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<div className="tbox-media-list">
|
|
239
|
+
<div className="tbox-media-list__scroll">
|
|
240
|
+
{items.map((item) =>
|
|
241
|
+
item.type === 'image' ? (
|
|
242
|
+
<ImageItemCard key={item.id} item={item} allImages={allImages} onRemove={onRemove} onRetry={onRetry} />
|
|
243
|
+
) : (
|
|
244
|
+
<FileItemCard key={item.id} item={item} onRemove={onRemove} onRetry={onRetry} />
|
|
245
|
+
),
|
|
246
|
+
)}
|
|
247
|
+
</div>
|
|
248
|
+
{showAddButton && (
|
|
249
|
+
<div className="tbox-media-add" onClick={handleAddClick}>
|
|
250
|
+
<Plus size={22} color="rgba(0,0,0,0.65)" />
|
|
251
|
+
<MediaPopover visible={popoverVisible} options={options} onSelect={handleSelect} />
|
|
252
|
+
</div>
|
|
253
|
+
)}
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
.msg-row {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: flex-start;
|
|
4
|
+
margin-bottom: 20px;
|
|
5
|
+
padding: 0 var(--tbox-page-gutter);
|
|
6
|
+
|
|
7
|
+
&--user {
|
|
8
|
+
flex-direction: row-reverse;
|
|
9
|
+
}
|
|
10
|
+
&--bot {
|
|
11
|
+
flex-direction: row;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.msg-main {
|
|
16
|
+
min-width: 0;
|
|
17
|
+
}
|
|
18
|
+
.msg-row--bot .msg-main {
|
|
19
|
+
flex: 1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.msg-meta {
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
margin-bottom: 6px;
|
|
26
|
+
|
|
27
|
+
&--user {
|
|
28
|
+
justify-content: flex-end;
|
|
29
|
+
margin-right: 0;
|
|
30
|
+
}
|
|
31
|
+
&--bot {
|
|
32
|
+
justify-content: flex-start;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&__role {
|
|
36
|
+
font-size: 19px;
|
|
37
|
+
color: var(--tbox-text-secondary);
|
|
38
|
+
margin-right: 8px;
|
|
39
|
+
}
|
|
40
|
+
&__time {
|
|
41
|
+
font-size: 18px;
|
|
42
|
+
color: var(--tbox-text-muted);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* 意图空文本出卡(无气泡、有卡):卡片前间距由 meta 下边距提供——
|
|
47
|
+
meta 无 border → 折叠语义 max(12, 卡 mt),未来全局卡框间距调整自然跟随 */
|
|
48
|
+
.msg-meta--solo-card {
|
|
49
|
+
margin-bottom: 12px;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* 多卡纵向铺开 wrapper(决策出卡 >1 张时 SDK CardCarousel 外层;单卡直出无此层) */
|
|
53
|
+
.msg-cards {
|
|
54
|
+
margin-top: 8px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.msg-bubble {
|
|
58
|
+
padding: 18px 22px;
|
|
59
|
+
line-height: 1.6;
|
|
60
|
+
/* mall-vis 气泡影(demo .msg-bubble 基座影,用户气泡沿用;bot 气泡自持双层影) */
|
|
61
|
+
box-shadow: 0 4px 16px rgba(50, 65, 92, 0.08);
|
|
62
|
+
|
|
63
|
+
&--user {
|
|
64
|
+
background: rgba(255, 255, 255, 0.9);
|
|
65
|
+
border-radius: 48px 8px 48px 48px;
|
|
66
|
+
width: fit-content;
|
|
67
|
+
max-width: 100%;
|
|
68
|
+
margin-left: auto;
|
|
69
|
+
margin-right: 0;
|
|
70
|
+
margin-bottom: 8px;
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
min-height: 48px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&--bot {
|
|
77
|
+
position: relative;
|
|
78
|
+
font-size: 30px;
|
|
79
|
+
line-height: 1.6;
|
|
80
|
+
padding: 22px;
|
|
81
|
+
color: var(--tbox-text-primary);
|
|
82
|
+
background: rgba(255, 255, 255, 0.4);
|
|
83
|
+
border: 1px solid #edf0f6;
|
|
84
|
+
border-radius: 8px 48px 48px;
|
|
85
|
+
box-shadow:
|
|
86
|
+
0 3px 8px 5px rgba(1, 112, 254, 0.0392),
|
|
87
|
+
0 2px 4px rgba(72, 78, 86, 0.0706);
|
|
88
|
+
/* 卡片在对话气泡之后显示:间距由气泡下边距提供(单一来源;
|
|
89
|
+
不写 .tbox-card 规则——避免特异性压过全局卡框、避免复制全局间距值) */
|
|
90
|
+
margin-bottom: 12px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&__text {
|
|
94
|
+
font-size: 25px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&__error {
|
|
98
|
+
color: var(--tbox-error);
|
|
99
|
+
font-size: 25px;
|
|
100
|
+
line-height: 1.6;
|
|
101
|
+
white-space: pre-wrap;
|
|
102
|
+
overflow-wrap: anywhere;
|
|
103
|
+
|
|
104
|
+
&--with-content {
|
|
105
|
+
margin-top: 14px;
|
|
106
|
+
padding-top: 14px;
|
|
107
|
+
border-top: 1px solid var(--tbox-error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
&--user &__text {
|
|
112
|
+
color: var(--tbox-text-primary);
|
|
113
|
+
font-weight: 500;
|
|
114
|
+
overflow-wrap: break-word;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* 用户消息附带的图片缩略图 */
|
|
119
|
+
.msg-media {
|
|
120
|
+
display: flex;
|
|
121
|
+
flex-wrap: nowrap;
|
|
122
|
+
overflow-x: auto;
|
|
123
|
+
gap: 16px;
|
|
124
|
+
direction: rtl;
|
|
125
|
+
margin-right: 12px;
|
|
126
|
+
margin-top: 4px;
|
|
127
|
+
-webkit-overflow-scrolling: touch;
|
|
128
|
+
|
|
129
|
+
&::-webkit-scrollbar {
|
|
130
|
+
display: none;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&__thumb {
|
|
134
|
+
direction: ltr;
|
|
135
|
+
width: var(--tbox-media-item-size);
|
|
136
|
+
min-width: var(--tbox-media-item-size);
|
|
137
|
+
height: var(--tbox-media-item-size);
|
|
138
|
+
border-radius: var(--tbox-media-item-radius);
|
|
139
|
+
object-fit: cover;
|
|
140
|
+
flex-shrink: 0;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.msg-toolbar {
|
|
145
|
+
display: flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
margin-top: 8px;
|
|
148
|
+
opacity: 0.4;
|
|
149
|
+
|
|
150
|
+
&--user {
|
|
151
|
+
justify-content: flex-end;
|
|
152
|
+
padding-right: 12px;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
&__action {
|
|
156
|
+
display: flex;
|
|
157
|
+
align-items: center;
|
|
158
|
+
justify-content: center;
|
|
159
|
+
width: 34px;
|
|
160
|
+
height: 28px;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.msg-toolbar-row {
|
|
165
|
+
display: flex;
|
|
166
|
+
align-items: center;
|
|
167
|
+
gap: 12px;
|
|
168
|
+
/* 操作栏间距由前元素 margin-bottom 提供(气泡 mb 12 / 卡片 mb 12):
|
|
169
|
+
不能自设 margin-top——气泡有 border 阻断折叠,自设会与气泡 mb 叠加成 24px */
|
|
170
|
+
margin-top: 0;
|
|
171
|
+
flex-wrap: wrap;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* 3 个点 loading 指示器 */
|
|
175
|
+
.msg-thinking,
|
|
176
|
+
.msg-thinking-inline {
|
|
177
|
+
display: flex;
|
|
178
|
+
justify-content: flex-start;
|
|
179
|
+
align-items: center;
|
|
180
|
+
gap: 8px;
|
|
181
|
+
padding: 10px 0;
|
|
182
|
+
margin-left: 12px;
|
|
183
|
+
|
|
184
|
+
&__dot {
|
|
185
|
+
width: 10px;
|
|
186
|
+
height: 10px;
|
|
187
|
+
border-radius: 50%;
|
|
188
|
+
background: #aab3c2; /* mall-vis thinking 点灰(非主色) */
|
|
189
|
+
animation: dot-fade 1.4s ease-in-out infinite;
|
|
190
|
+
|
|
191
|
+
&--2 {
|
|
192
|
+
animation-delay: 0.2s;
|
|
193
|
+
}
|
|
194
|
+
&--3 {
|
|
195
|
+
animation-delay: 0.4s;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
@keyframes dot-fade {
|
|
201
|
+
0%,
|
|
202
|
+
80%,
|
|
203
|
+
100% {
|
|
204
|
+
opacity: 0.3;
|
|
205
|
+
}
|
|
206
|
+
40% {
|
|
207
|
+
opacity: 1;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/* 流式光标 */
|
|
212
|
+
.msg-cursor {
|
|
213
|
+
display: inline-block;
|
|
214
|
+
width: 4px;
|
|
215
|
+
height: 24px;
|
|
216
|
+
background: #5874ff; /* mall-vis 流式光标蓝 */
|
|
217
|
+
margin-left: 4px;
|
|
218
|
+
vertical-align: middle;
|
|
219
|
+
animation: blink 1s step-end infinite;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@keyframes blink {
|
|
223
|
+
0%,
|
|
224
|
+
100% {
|
|
225
|
+
opacity: 1;
|
|
226
|
+
}
|
|
227
|
+
50% {
|
|
228
|
+
opacity: 0;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/* Markdown */
|
|
233
|
+
.msg-markdown {
|
|
234
|
+
font-size: 25px;
|
|
235
|
+
color: var(--tbox-text-primary);
|
|
236
|
+
overflow-wrap: anywhere;
|
|
237
|
+
|
|
238
|
+
h1,
|
|
239
|
+
h2,
|
|
240
|
+
h3,
|
|
241
|
+
h4,
|
|
242
|
+
h5,
|
|
243
|
+
h6 {
|
|
244
|
+
margin: 16px 0 8px;
|
|
245
|
+
font-weight: 600;
|
|
246
|
+
line-height: 1.4;
|
|
247
|
+
}
|
|
248
|
+
h1 {
|
|
249
|
+
font-size: 36px;
|
|
250
|
+
}
|
|
251
|
+
h2 {
|
|
252
|
+
font-size: 32px;
|
|
253
|
+
}
|
|
254
|
+
h3 {
|
|
255
|
+
font-size: 30px;
|
|
256
|
+
}
|
|
257
|
+
h4 {
|
|
258
|
+
font-size: 28px;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
p {
|
|
262
|
+
margin: 8px 0;
|
|
263
|
+
}
|
|
264
|
+
strong {
|
|
265
|
+
font-weight: 600;
|
|
266
|
+
}
|
|
267
|
+
em {
|
|
268
|
+
font-style: italic;
|
|
269
|
+
}
|
|
270
|
+
a {
|
|
271
|
+
color: var(--tbox-primary);
|
|
272
|
+
text-decoration: underline;
|
|
273
|
+
}
|
|
274
|
+
ul,
|
|
275
|
+
ol {
|
|
276
|
+
padding-left: 32px;
|
|
277
|
+
margin: 8px 0;
|
|
278
|
+
}
|
|
279
|
+
li {
|
|
280
|
+
margin: 4px 0;
|
|
281
|
+
}
|
|
282
|
+
blockquote {
|
|
283
|
+
border-left: 4px solid #667eea; /* mall-vis 引用竖条(ReasoningBlock 折叠族同源) */
|
|
284
|
+
padding-left: 16px;
|
|
285
|
+
margin: 12px 0;
|
|
286
|
+
color: var(--tbox-text-secondary);
|
|
287
|
+
}
|
|
288
|
+
code {
|
|
289
|
+
background: rgba(0, 0, 0, 0.06);
|
|
290
|
+
padding: 2px 8px;
|
|
291
|
+
border-radius: 6px;
|
|
292
|
+
font-size: 26px;
|
|
293
|
+
font-family: Menlo, Monaco, Consolas, monospace;
|
|
294
|
+
}
|
|
295
|
+
pre {
|
|
296
|
+
background: #1e1e2e;
|
|
297
|
+
border-radius: 12px;
|
|
298
|
+
padding: 20px;
|
|
299
|
+
margin: 12px 0;
|
|
300
|
+
overflow-x: auto;
|
|
301
|
+
|
|
302
|
+
code {
|
|
303
|
+
background: none;
|
|
304
|
+
padding: 0;
|
|
305
|
+
color: #cdd6f4;
|
|
306
|
+
font-size: 24px;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
table {
|
|
310
|
+
width: 100%;
|
|
311
|
+
border-collapse: collapse;
|
|
312
|
+
margin: 12px 0;
|
|
313
|
+
}
|
|
314
|
+
th,
|
|
315
|
+
td {
|
|
316
|
+
border: 1px solid var(--tbox-border);
|
|
317
|
+
padding: 8px 12px;
|
|
318
|
+
text-align: left;
|
|
319
|
+
font-size: 26px;
|
|
320
|
+
}
|
|
321
|
+
th {
|
|
322
|
+
background: var(--tbox-bg-subtle);
|
|
323
|
+
font-weight: 600;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { act } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import type { TboxCardPayload } from '@tbox.cn/app-contracts';
|
|
6
|
+
|
|
7
|
+
const mocks = vi.hoisted(() => ({
|
|
8
|
+
state: {
|
|
9
|
+
cardsByMessageId: {} as Record<string, TboxCardPayload[]>,
|
|
10
|
+
},
|
|
11
|
+
debugProps: null as Record<string, unknown> | null,
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
vi.mock('../../store-context', () => ({
|
|
15
|
+
useChatStore: (selector: (state: typeof mocks.state) => unknown) => selector(mocks.state),
|
|
16
|
+
// W2-1:内联卡过滤经 context 注入(域语义保持原 witness:会员门禁卡系剥离,
|
|
17
|
+
// 原直连 '@/components/MemberGateSheet/model' 的 MEMBER_GATE_CARD_TYPES 语义)
|
|
18
|
+
useInlineCardFilter: () =>
|
|
19
|
+
(cards: Array<{ cardType: string }>) =>
|
|
20
|
+
cards.filter((c) => !['member-login-cta', 'member-enrollment-cta'].includes(c.cardType)),
|
|
21
|
+
}));
|
|
22
|
+
vi.mock('../CardRenderer', () => ({
|
|
23
|
+
CardRenderer: ({ card }: { card: TboxCardPayload }) => <div data-card-id={card.id} />,
|
|
24
|
+
}));
|
|
25
|
+
vi.mock('../../components/ReasoningBlock', () => ({ default: () => null }));
|
|
26
|
+
vi.mock('../../components/ToolCallBlock', () => ({ default: () => null }));
|
|
27
|
+
vi.mock('../../components/ActionBar', () => ({
|
|
28
|
+
ActionBar: () => null,
|
|
29
|
+
CopyButton: () => null,
|
|
30
|
+
getMessageCopyText: () => '',
|
|
31
|
+
}));
|
|
32
|
+
vi.mock('../../components/ActionBar/DebugButton', () => ({
|
|
33
|
+
DebugButton: (props: Record<string, unknown>) => {
|
|
34
|
+
mocks.debugProps = props;
|
|
35
|
+
return null;
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
import { MessageBubble } from './index';
|
|
40
|
+
|
|
41
|
+
function card(id: string, cardType: string): TboxCardPayload {
|
|
42
|
+
return { id, cardType, data: {}, status: 'ready', meta: { createdAt: 1 } };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const emptyAssistantMessage = {
|
|
46
|
+
id: 'assistant-1',
|
|
47
|
+
role: 'assistant' as const,
|
|
48
|
+
content: '',
|
|
49
|
+
status: 'done' as const,
|
|
50
|
+
createdAt: 1,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
describe('MessageBubble member gate card partition', () => {
|
|
54
|
+
let host: HTMLDivElement;
|
|
55
|
+
let root: ReturnType<typeof createRoot>;
|
|
56
|
+
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
host = document.createElement('div');
|
|
59
|
+
document.body.appendChild(host);
|
|
60
|
+
root = createRoot(host);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
act(() => root.unmount());
|
|
65
|
+
host.remove();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('does not leave an empty message row for a login-only card', () => {
|
|
69
|
+
mocks.state.cardsByMessageId = {
|
|
70
|
+
'assistant-1': [card('login-1', 'member-login-cta')],
|
|
71
|
+
};
|
|
72
|
+
act(() => root.render(<MessageBubble message={emptyAssistantMessage} />));
|
|
73
|
+
expect(host.innerHTML).toBe('');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('keeps ordinary cards while removing the login card from a mixed carousel', () => {
|
|
77
|
+
mocks.state.cardsByMessageId = {
|
|
78
|
+
'assistant-1': [
|
|
79
|
+
card('login-1', 'member-login-cta'),
|
|
80
|
+
card('coupon-1', 'coupon-detail'),
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
act(() => root.render(<MessageBubble message={emptyAssistantMessage} />));
|
|
84
|
+
expect(host.querySelector('[data-card-id="login-1"]')).toBeNull();
|
|
85
|
+
expect(host.querySelector('[data-card-id="coupon-1"]')).not.toBeNull();
|
|
86
|
+
expect(host.querySelector('[aria-label^="第 "]')).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('strips enrollment-cta from inline carousel (module button is a bypassing openLink jump)', () => {
|
|
90
|
+
mocks.state.cardsByMessageId = {
|
|
91
|
+
'assistant-1': [
|
|
92
|
+
card('enroll-1', 'member-enrollment-cta'),
|
|
93
|
+
card('member-card-1', 'member-card-summary'),
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
act(() => root.render(<MessageBubble message={emptyAssistantMessage} />));
|
|
97
|
+
// 入会卡内联渲染会旁路 gate 闭环(openLink 裸外跳)——必须剥离,由 MemberGateSheet 投影
|
|
98
|
+
expect(host.querySelector('[data-card-id="enroll-1"]')).toBeNull();
|
|
99
|
+
expect(host.querySelector('[data-card-id="member-card-1"]')).not.toBeNull();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('多卡决策出卡 → 纵向按序渲染,无轮播圆点', () => {
|
|
103
|
+
mocks.state.cardsByMessageId = {
|
|
104
|
+
'assistant-1': [
|
|
105
|
+
card('coupon-1', 'coupon-detail'),
|
|
106
|
+
card('member-1', 'member-card-summary'),
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
act(() => root.render(<MessageBubble message={emptyAssistantMessage} />));
|
|
110
|
+
const all = host.querySelectorAll('[data-card-id]');
|
|
111
|
+
expect(all.length).toBe(2);
|
|
112
|
+
expect(all[0].getAttribute('data-card-id')).toBe('coupon-1');
|
|
113
|
+
expect(all[1].getAttribute('data-card-id')).toBe('member-1');
|
|
114
|
+
// 纵向铺开:不再有轮播圆点指示器
|
|
115
|
+
expect(host.querySelector('[aria-label^="第 "]')).toBeNull();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('error 消息接线:DebugButton 透传 requestId + conversationId(error 分支守卫——不经 ActionBar 的独立渲染路径)', () => {
|
|
119
|
+
mocks.state.cardsByMessageId = {}; // 用例间隔离:清除前序用例的卡片桶残留
|
|
120
|
+
mocks.debugProps = null;
|
|
121
|
+
act(() => {
|
|
122
|
+
root.render(
|
|
123
|
+
<MessageBubble
|
|
124
|
+
message={{ ...emptyAssistantMessage, status: 'error' as const, error: '失败', requestId: 'req_e', conversationId: 'conv_e' }}
|
|
125
|
+
/>,
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
expect(mocks.debugProps).toMatchObject({
|
|
129
|
+
requestId: 'req_e',
|
|
130
|
+
conversationId: 'conv_e',
|
|
131
|
+
messageId: 'assistant-1',
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|