@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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -2
  3. package/assets/keyboard-circle.svg +12 -0
  4. package/assets/more-circle.svg +3 -0
  5. package/assets/new-chat.svg +3 -0
  6. package/assets/quick-command-star.svg +3 -0
  7. package/assets/send-gradient.svg +14 -0
  8. package/assets/stop@2x.png +0 -0
  9. package/assets/voice-circle.svg +3 -0
  10. package/package.json +55 -3
  11. package/src/ChatPage.less +62 -0
  12. package/src/ChatPage.tsx +305 -0
  13. package/src/chat-config.test.ts +82 -0
  14. package/src/chat-config.ts +62 -0
  15. package/src/components/ActionBar/DebugButton.test.tsx +84 -0
  16. package/src/components/ActionBar/DebugButton.tsx +53 -0
  17. package/src/components/ActionBar/index.less +123 -0
  18. package/src/components/ActionBar/index.test.tsx +83 -0
  19. package/src/components/ActionBar/index.tsx +159 -0
  20. package/src/components/CardRenderer.tsx +36 -0
  21. package/src/components/ChatHeader/index.less +148 -0
  22. package/src/components/ChatHeader/index.test.tsx +74 -0
  23. package/src/components/ChatHeader/index.tsx +75 -0
  24. package/src/components/ChatInput/index.less +394 -0
  25. package/src/components/ChatInput/index.test.tsx +156 -0
  26. package/src/components/ChatInput/index.tsx +284 -0
  27. package/src/components/ChatInput/voice/VoicePressField.tsx +34 -0
  28. package/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +51 -0
  29. package/src/components/ChatInput/voice/machine.ts +27 -0
  30. package/src/components/ChatInput/voice/useVoicePress.ts +207 -0
  31. package/src/components/HistoryEntry/index.less +49 -0
  32. package/src/components/HistoryEntry/index.tsx +42 -0
  33. package/src/components/MediaList/index.less +241 -0
  34. package/src/components/MediaList/index.tsx +256 -0
  35. package/src/components/MessageBubble/index.less +325 -0
  36. package/src/components/MessageBubble/index.test.tsx +134 -0
  37. package/src/components/MessageBubble/index.tsx +177 -0
  38. package/src/components/PullDownIndicator/index.less +32 -0
  39. package/src/components/PullDownIndicator/index.tsx +32 -0
  40. package/src/components/QuickCommands/index.less +63 -0
  41. package/src/components/QuickCommands/index.test.tsx +99 -0
  42. package/src/components/QuickCommands/index.tsx +52 -0
  43. package/src/components/ReasoningBlock/index.less +90 -0
  44. package/src/components/ReasoningBlock/index.tsx +56 -0
  45. package/src/components/ScrollToBottomButton/index.less +32 -0
  46. package/src/components/ScrollToBottomButton/index.tsx +10 -0
  47. package/src/components/ToolCallBlock/detail.test.ts +346 -0
  48. package/src/components/ToolCallBlock/detail.ts +204 -0
  49. package/src/components/ToolCallBlock/index.less +312 -0
  50. package/src/components/ToolCallBlock/index.test.tsx +261 -0
  51. package/src/components/ToolCallBlock/index.tsx +212 -0
  52. package/src/components/ToolCallBlock/titles.ts +102 -0
  53. package/src/hooks/use-drag-gesture.test.ts +66 -0
  54. package/src/hooks/use-drag-gesture.ts +129 -0
  55. package/src/hooks/use-pull-down-history.ts +241 -0
  56. package/src/hooks/use-pull-down-wheel-native.test.ts +64 -0
  57. package/src/hooks/useMediaUpload.ts +242 -0
  58. package/src/hooks/useTTSAutoPlay.ts +82 -0
  59. package/src/index.ts +69 -0
  60. package/src/store-context.tsx +92 -0
  61. package/src/test/setup.ts +7 -0
  62. package/src/theme/contract.json +72 -0
  63. package/src/theme/global.less +99 -0
  64. package/src/theme/motion.less +19 -0
  65. package/src/theme/theme-contract.test.ts +69 -0
  66. package/src/theme/theme.ts +17 -0
  67. package/src/theme/tokens.less +79 -0
  68. package/src/types.ts +29 -0
  69. package/src/utils/copyText.ts +11 -0
  70. package/src/utils/haptics.test.ts +51 -0
  71. package/src/utils/haptics.ts +44 -0
  72. package/src/utils/imagePreview.ts +10 -0
  73. package/src/utils/pull-down-machine.test.ts +188 -0
  74. package/src/utils/pull-down-machine.ts +157 -0
  75. package/src/utils/session-error.ts +5 -0
  76. package/src/utils/toast.ts +15 -0
  77. package/src/utils/tool-call-display.test.ts +240 -0
  78. package/src/utils/tool-call-display.ts +146 -0
  79. package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,177 @@
1
+ import { useMemo } from 'react';
2
+ import ReactMarkdown from 'react-markdown';
3
+ import remarkGfm from 'remark-gfm';
4
+ import { Copy } from '@phosphor-icons/react';
5
+ import { previewImages } from '../../utils/imagePreview';
6
+ import type { ChatMessage } from '../../types';
7
+ import ReasoningBlock from '../../components/ReasoningBlock';
8
+ import ToolCallBlock from '../../components/ToolCallBlock';
9
+ import { ActionBar, CopyButton, getMessageCopyText } from '../../components/ActionBar';
10
+ import { DebugButton } from '../../components/ActionBar/DebugButton';
11
+ import { CardRenderer } from '../CardRenderer';
12
+ import { CardCarousel } from '@tbox.cn/app-agent-sdk-client';
13
+ import { useChatStore, useInlineCardFilter } from '../../store-context';
14
+ import { copyText } from '../../utils/copyText';
15
+ import { toast } from '../../utils/toast';
16
+ import './index.less';
17
+
18
+ const TBOX_FILE_URL = 'https://mdn.alipayobjects.com/tcmarket/afts/file/';
19
+
20
+ /** 消息气泡(对齐原模板):meta + 思考/工具/卡片 + 气泡 + 媒体 + 操作栏。 */
21
+ export function MessageBubble({ message }: { message: ChatMessage }) {
22
+ const cardsByMessageId = useChatStore((s) => s.cardsByMessageId);
23
+ // 018 tool-debug:服务端旗标单源(HELLO_ACK;无 URL 逃逸——数据面信任锚点在服务端)
24
+ const toolDebug = useChatStore((s) => s.helloAck?.toolDebug === true);
25
+ const isUser = message.role === 'user';
26
+ const roleName = isUser ? '你' : 'AI 助手';
27
+ const timeLabel = new Date(message.createdAt).toLocaleTimeString('zh-CN', {
28
+ hour: '2-digit',
29
+ minute: '2-digit',
30
+ hour12: false,
31
+ });
32
+
33
+ const isThinking = message.status === 'thinking';
34
+ const isStreaming = message.status === 'streaming';
35
+ const hasReasoning = !!message.reasoning;
36
+ // 018:formSubmit 伪工具 prod 过滤不变;dev 放行(防御性——若事件到达则可见)
37
+ const visibleToolCalls = useMemo(
38
+ () => (message.toolCalls || []).filter((tc) => toolDebug || tc.name !== '__a2uiFormSubmit'),
39
+ [message.toolCalls, toolDebug],
40
+ );
41
+ const hasToolCalls = visibleToolCalls.length > 0;
42
+
43
+ const filterInlineCards = useInlineCardFilter();
44
+ const messageCards = useMemo(
45
+ () => (isUser ? [] : filterInlineCards(cardsByMessageId[message.id] || [])),
46
+ [cardsByMessageId, message.id, isUser, filterInlineCards],
47
+ );
48
+ const imageItems = isUser
49
+ ? message.mediaItems?.filter((i) => i.type === 'image' && (i.src || i.fileId))
50
+ : undefined;
51
+
52
+ const isPureThinking = isThinking && !hasReasoning && !message.content && !hasToolCalls;
53
+ const isReasoningActive = isThinking || (isStreaming && !message.content);
54
+ const showBubble = isUser || !!message.content || !!message.error || isStreaming;
55
+
56
+ const copy = async () => {
57
+ const copied = await copyText(message.content);
58
+ void toast(copied ? '复制成功' : '复制失败,请重试', copied ? 'success' : 'error');
59
+ };
60
+
61
+ const imageUrls = (imageItems || []).map((it) => it.src || `${TBOX_FILE_URL}${it.fileId}`);
62
+
63
+ // 登录入口由页面级半屏浮层承载;仅含登录卡的空 assistant 行不进入聊天流。
64
+ if (!isUser && !isPureThinking && !hasReasoning && !hasToolCalls && !showBubble && messageCards.length === 0) {
65
+ return null;
66
+ }
67
+
68
+ return (
69
+ <div className={`msg-row ${isUser ? 'msg-row--user' : 'msg-row--bot'}`}>
70
+ <div className="msg-main">
71
+ <div
72
+ className={`msg-meta ${isUser ? 'msg-meta--user' : 'msg-meta--bot'}${!showBubble && messageCards.length > 0 ? ' msg-meta--solo-card' : ''}`}
73
+ >
74
+ <span className="msg-meta__role">{roleName}</span>
75
+ <span className="msg-meta__time">{timeLabel}</span>
76
+ </div>
77
+
78
+ {isPureThinking && (
79
+ <div className="msg-thinking">
80
+ <div className="msg-thinking__dot" />
81
+ <div className="msg-thinking__dot msg-thinking__dot--2" />
82
+ <div className="msg-thinking__dot msg-thinking__dot--3" />
83
+ </div>
84
+ )}
85
+
86
+ {hasReasoning && <ReasoningBlock reasoning={message.reasoning!} isActive={isReasoningActive} />}
87
+
88
+ {hasToolCalls && <ToolCallBlock toolCalls={visibleToolCalls} debug={toolDebug} />}
89
+
90
+ {isThinking && hasToolCalls && !message.content && (
91
+ <div className="msg-thinking-inline">
92
+ <div className="msg-thinking-inline__dot" />
93
+ <div className="msg-thinking-inline__dot msg-thinking-inline__dot--2" />
94
+ <div className="msg-thinking-inline__dot msg-thinking-inline__dot--3" />
95
+ </div>
96
+ )}
97
+
98
+ {showBubble && (
99
+ <div className={`msg-bubble ${isUser ? 'msg-bubble--user' : 'msg-bubble--bot'}`}>
100
+ {isUser ? (
101
+ <span className="msg-bubble__text">{message.content}</span>
102
+ ) : (
103
+ <>
104
+ {message.content && (
105
+ <div className="msg-markdown">
106
+ <ReactMarkdown remarkPlugins={[remarkGfm]}>{message.content}</ReactMarkdown>
107
+ </div>
108
+ )}
109
+ {message.error && (
110
+ <div
111
+ className={`msg-bubble__error${message.content ? ' msg-bubble__error--with-content' : ''}`}
112
+ role="alert"
113
+ >
114
+ {message.error}
115
+ </div>
116
+ )}
117
+ {isStreaming && <span className="msg-cursor" />}
118
+ </>
119
+ )}
120
+ </div>
121
+ )}
122
+
123
+ {/* 卡片在对话气泡之后显示(决策出卡多张/意图卡/历史卡统一经 cardsByMessageId 挂载,多卡纵向铺开) */}
124
+ <CardCarousel
125
+ className="msg-cards"
126
+ cards={messageCards}
127
+ renderItem={(card) => <CardRenderer key={card.id} card={card} />}
128
+ />
129
+
130
+ {imageItems && imageItems.length > 0 && (
131
+ <div className="msg-media">
132
+ {imageItems.map((item, idx) => (
133
+ <img
134
+ key={item.id}
135
+ className="msg-media__thumb"
136
+ src={item.src || `${TBOX_FILE_URL}${item.fileId}`}
137
+ alt=""
138
+ onClick={() => previewImages(imageUrls, idx)}
139
+ />
140
+ ))}
141
+ </div>
142
+ )}
143
+
144
+ {isUser && !!message.content && (
145
+ <div className="msg-toolbar msg-toolbar--user">
146
+ <div className="msg-toolbar__action" onClick={copy}>
147
+ <Copy size={12} color="#535b6c" />
148
+ </div>
149
+ </div>
150
+ )}
151
+
152
+ {!isUser && message.status === 'done' && !!message.content && (
153
+ <div className="msg-toolbar-row">
154
+ <ActionBar message={message} />
155
+ </div>
156
+ )}
157
+
158
+ {/* 出错消息不提供朗读/反馈,但支持复制错误详情和拉 trace 排查。 */}
159
+ {!isUser && message.status === 'error' && (
160
+ <div className="msg-toolbar-row">
161
+ <div className="tbox-action-bar">
162
+ <CopyButton text={getMessageCopyText(message)} />
163
+ {message.requestId && (
164
+ <DebugButton
165
+ requestId={message.requestId}
166
+ conversationId={message.conversationId}
167
+ messageId={message.id}
168
+ messageCreatedAt={new Date(message.createdAt).getTime()}
169
+ />
170
+ )}
171
+ </div>
172
+ </div>
173
+ )}
174
+ </div>
175
+ </div>
176
+ );
177
+ }
@@ -0,0 +1,32 @@
1
+ .pull-indicator {
2
+ display: flex;
3
+ align-items: center;
4
+ justify-content: center;
5
+ height: 60px;
6
+ gap: 12px;
7
+
8
+ &--animated {
9
+ transition: margin-top var(--tbox-motion-duration-base) ease-out;
10
+ }
11
+
12
+ &__spinner {
13
+ width: 32px;
14
+ height: 32px;
15
+ border: 3px solid var(--tbox-border-strong);
16
+ border-top-color: var(--tbox-primary);
17
+ border-radius: 50%;
18
+ animation: pull-spin 0.6s linear infinite;
19
+ }
20
+
21
+ &__text {
22
+ font-size: 26px;
23
+ color: #8c8c8c;
24
+ line-height: 1;
25
+ }
26
+ }
27
+
28
+ @keyframes pull-spin {
29
+ to {
30
+ transform: rotate(360deg);
31
+ }
32
+ }
@@ -0,0 +1,32 @@
1
+ import type { PullStatus } from '../../utils/pull-down-machine';
2
+ import { PULL_DOWN_THRESHOLD } from '../../utils/pull-down-machine';
3
+ import './index.less';
4
+
5
+ /** 下拉加载历史的顶部指示器。 */
6
+ export default function PullDownIndicator({ status, distance }: { status: PullStatus; distance: number }) {
7
+ if (status === 'idle') return null;
8
+
9
+ const marginTop = status === 'loading' ? 0 : -PULL_DOWN_THRESHOLD + Math.min(distance, PULL_DOWN_THRESHOLD);
10
+ const showTransition = status === 'loading' || status === 'noMore';
11
+
12
+ const content =
13
+ status === 'pulling'
14
+ ? '↓ 下拉加载更多'
15
+ : status === 'ready'
16
+ ? '↑ 释放加载历史'
17
+ : status === 'loading'
18
+ ? '加载中...'
19
+ : status === 'noMore'
20
+ ? '没有更多历史记录'
21
+ : '';
22
+
23
+ return (
24
+ <div
25
+ className={`pull-indicator${showTransition ? ' pull-indicator--animated' : ''}`}
26
+ style={{ marginTop: `${marginTop}px` }}
27
+ >
28
+ {status === 'loading' && <div className="pull-indicator__spinner" />}
29
+ <span className="pull-indicator__text">{content}</span>
30
+ </div>
31
+ );
32
+ }
@@ -0,0 +1,63 @@
1
+ .quick-commands {
2
+ position: relative;
3
+ z-index: 1;
4
+ width: 100%;
5
+ max-width: var(--tbox-content-max-width);
6
+ margin: 0 auto;
7
+ box-sizing: border-box;
8
+ display: flex;
9
+ gap: 8PX;
10
+ overflow-x: auto;
11
+ padding: 0 var(--tbox-page-gutter) 9PX;
12
+ -ms-overflow-style: none;
13
+ scrollbar-width: none;
14
+
15
+ &::-webkit-scrollbar {
16
+ display: none;
17
+ }
18
+
19
+ /* 语音交互时只隐藏胶囊,保留原高度和页面灰底,继续遮挡聊天内容。 */
20
+ &--hidden {
21
+ visibility: hidden;
22
+ pointer-events: none;
23
+ }
24
+
25
+ &__item {
26
+ flex: 1 0 auto;
27
+ display: inline-flex;
28
+ align-items: center;
29
+ justify-content: center;
30
+ gap: 5PX;
31
+ height: 34PX;
32
+ padding: 0 13PX;
33
+ appearance: none;
34
+ /* mall-vis 快捷指令胶囊:白底 + 2px 描边 + 50px 胶囊圆角(数据仍服务端驱动) */
35
+ background: rgba(255, 255, 255, 0.92);
36
+ border: 1PX solid rgba(15, 64, 113, 0.14);
37
+ border-radius: 25PX;
38
+ box-shadow: 0 4PX 16PX rgba(38, 59, 92, 0.05);
39
+ transition: background var(--tbox-transition-fast), border-color var(--tbox-transition-fast);
40
+
41
+ &:active {
42
+ border-color: var(--tbox-primary);
43
+ }
44
+ }
45
+
46
+ &__icon {
47
+ width: 16PX;
48
+ height: 16PX;
49
+ object-fit: contain;
50
+ }
51
+
52
+ &__icon-svg {
53
+ color: var(--tbox-primary);
54
+ }
55
+
56
+ &__label {
57
+ color: var(--tbox-text-primary);
58
+ font-size: 13PX;
59
+ font-weight: 500;
60
+ line-height: 18PX;
61
+ white-space: nowrap;
62
+ }
63
+ }
@@ -0,0 +1,99 @@
1
+ // @vitest-environment happy-dom
2
+ /**
3
+ * QuickCommands 快捷胶囊(W2-1 自 mall 随迁):断言原样——harness 改 kit context 注入形式
4
+ * (原 mock 应用 store → 现最小测试 store + KitChatProvider;本地图文合并经 config store 快照注入)。
5
+ */
6
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
+ import { createRoot } from 'react-dom/client';
8
+ import { flushSync } from 'react-dom';
9
+ import type { ReactNode } from 'react';
10
+ import { create } from 'zustand';
11
+ import type { CoreChatStore } from '@tbox.cn/app-agent-sdk-client';
12
+ import { configureChatConfigDefaults, useChatConfigStore } from '../../chat-config';
13
+ import { KitChatProvider } from '../../store-context';
14
+ import { QuickCommands } from './index';
15
+
16
+ /** 最小测试 store(仅 helloAck 消费面);注入形式经 KitChatProvider。 */
17
+ const testStore = create<{ helloAck: unknown }>(() => ({ helloAck: null })) as unknown as CoreChatStore;
18
+
19
+ /** 构建期快照(对齐 mall config/chat.json 三条——本地图标合并真源) */
20
+ const STATIC_COMMANDS = [
21
+ {
22
+ label: '今日优惠',
23
+ query: '现在有什么优惠?',
24
+ icon: 'https://mdn.alipayobjects.com/agt_content/afts/img/yirAQ7obEFcAAAAAAAAAAAAAehe3AQBr/original',
25
+ },
26
+ {
27
+ label: '品牌导览',
28
+ query: '品牌导览',
29
+ icon: 'https://mdn.alipayobjects.com/agt_content/afts/img/6-OCR5kWFaAAAAAAAAAAAAAAehe3AQBr/original',
30
+ },
31
+ {
32
+ label: '活动中心',
33
+ query: '活动中心',
34
+ icon: 'https://mdn.alipayobjects.com/agt_content/afts/img/yirAQ7obEFcAAAAAAAAAAAAAehe3AQBr/original',
35
+ },
36
+ ];
37
+
38
+ function renderWithKit(container: HTMLElement, node: ReactNode): void {
39
+ flushSync(() =>
40
+ createRoot(container).render(
41
+ <KitChatProvider store={testStore} cards={{}} rawCards={{}}>
42
+ {node}
43
+ </KitChatProvider>,
44
+ ),
45
+ );
46
+ }
47
+
48
+ beforeEach(() => {
49
+ configureChatConfigDefaults({ quickCommands: STATIC_COMMANDS });
50
+ });
51
+
52
+ afterEach(() => {
53
+ testStore.setState({ helloAck: null } as never);
54
+ useChatConfigStore.setState({ quickCommands: [] });
55
+ document.body.innerHTML = '';
56
+ });
57
+
58
+ describe('QuickCommands 快捷胶囊', () => {
59
+ it('按服务端顺序渲染三项、合并本地图标并发送服务端 prompt', () => {
60
+ testStore.setState({
61
+ helloAck: {
62
+ chatConfig: {
63
+ quickCommands: [
64
+ { label: '今日优惠', prompt: '服务端优惠查询' },
65
+ { label: '品牌导览', prompt: '服务端品牌导览' },
66
+ { label: '活动中心', prompt: '服务端活动查询' },
67
+ ],
68
+ },
69
+ },
70
+ } as never);
71
+ const onCommand = vi.fn();
72
+ const container = document.createElement('div');
73
+ document.body.appendChild(container);
74
+ renderWithKit(container, <QuickCommands onCommand={onCommand} />);
75
+
76
+ const buttons = [...container.querySelectorAll<HTMLButtonElement>('.quick-commands__item')];
77
+ expect(buttons.map((button) => button.textContent)).toEqual(['今日优惠', '品牌导览', '活动中心']);
78
+ expect(container.textContent).not.toContain('找门店');
79
+ expect(buttons[1]?.querySelector('img')?.src).toContain('6-OCR5kWFa');
80
+ flushSync(() => buttons[1]!.click());
81
+ expect(onCommand).toHaveBeenCalledWith('服务端品牌导览');
82
+ });
83
+
84
+ it('隐藏时保留胶囊容器,但禁止交互', () => {
85
+ const onCommand = vi.fn();
86
+ const container = document.createElement('div');
87
+ document.body.appendChild(container);
88
+ renderWithKit(container, <QuickCommands hidden onCommand={onCommand} />);
89
+
90
+ const commands = container.querySelector('.quick-commands');
91
+ const button = container.querySelector<HTMLButtonElement>('.quick-commands__item');
92
+ expect(commands).not.toBeNull();
93
+ expect(commands?.classList.contains('quick-commands--hidden')).toBe(true);
94
+ expect(commands?.getAttribute('aria-hidden')).toBe('true');
95
+ expect(button?.disabled).toBe(true);
96
+ flushSync(() => button?.click());
97
+ expect(onCommand).not.toHaveBeenCalled();
98
+ });
99
+ });
@@ -0,0 +1,52 @@
1
+ // 输入框上方的快捷指令;文案由 chatConfig 驱动,服务端下发不含 icon 时按 label 合并本地配置。
2
+ // 011 I2:服务端 HelloAck.chatConfig.quickCommands 优先(单一真源),本地 chat.json 为 fallback。
3
+ // label 只写纯文字;前面的星标由本组件渲染(icon 字段或默认 ✦),不要把 ✦/emoji 写进 label。
4
+ import { useChatConfigStore } from '../../chat-config';
5
+ import { useChatStore } from '../../store-context';
6
+ import starIcon from '../../../assets/quick-command-star.svg';
7
+ import './index.less';
8
+
9
+ export function QuickCommands({
10
+ onCommand,
11
+ hidden = false,
12
+ }: {
13
+ onCommand: (query: string) => void;
14
+ hidden?: boolean;
15
+ }) {
16
+ const staticCommands = useChatConfigStore((s) => s.quickCommands);
17
+ const serverCommands = useChatStore((s) => s.helloAck?.chatConfig.quickCommands);
18
+ // 服务端下发优先;未收到 HELLO_ACK(非 mall 部署)回落本地静态
19
+ const staticByLabel = new Map(staticCommands.map((command) => [command.label, command]));
20
+ const commands = serverCommands && serverCommands.length > 0
21
+ ? serverCommands.map((command) => ({
22
+ label: command.label,
23
+ query: command.prompt,
24
+ icon: staticByLabel.get(command.label)?.icon,
25
+ }))
26
+ : staticCommands;
27
+ if (!commands.length) return null;
28
+
29
+ return (
30
+ <div
31
+ className={`quick-commands${hidden ? ' quick-commands--hidden' : ''}`}
32
+ aria-hidden={hidden || undefined}
33
+ >
34
+ {commands.map((cmd) => (
35
+ <button
36
+ key={cmd.label}
37
+ className="quick-commands__item"
38
+ disabled={hidden}
39
+ onClick={() => onCommand(cmd.query)}
40
+ >
41
+ <img
42
+ className="quick-commands__icon"
43
+ src={cmd.icon ?? starIcon}
44
+ alt=""
45
+ onError={(event) => { event.currentTarget.src = starIcon; }}
46
+ />
47
+ <span className="quick-commands__label">{cmd.label}</span>
48
+ </button>
49
+ ))}
50
+ </div>
51
+ );
52
+ }
@@ -0,0 +1,90 @@
1
+ .reasoning {
2
+ margin: 0 0 16px;
3
+ border-radius: 14px;
4
+ overflow: hidden;
5
+ min-width: 0;
6
+ max-width: 100%;
7
+ box-sizing: border-box;
8
+
9
+ &--active {
10
+ background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.06) 100%);
11
+ }
12
+ &--done {
13
+ background: rgba(0, 0, 0, 0.03);
14
+ }
15
+
16
+ &__header {
17
+ display: flex;
18
+ align-items: center;
19
+ justify-content: space-between;
20
+ padding: 14px 18px;
21
+ }
22
+
23
+ &__left {
24
+ display: flex;
25
+ align-items: center;
26
+ gap: 8px;
27
+ }
28
+
29
+ &__indicator {
30
+ width: 10px;
31
+ height: 10px;
32
+ border-radius: 50%;
33
+ background: #b0bec5;
34
+ flex-shrink: 0;
35
+
36
+ &--pulse {
37
+ background: #667eea;
38
+ animation: reasoning-pulse 1.5s ease-in-out infinite;
39
+ }
40
+ }
41
+
42
+ &__title {
43
+ font-size: 22px;
44
+ font-weight: 600;
45
+ color: #6b7a99;
46
+ }
47
+ &--active &__title {
48
+ color: #667eea;
49
+ }
50
+
51
+ &__duration {
52
+ font-size: 20px;
53
+ color: #9ba7c3;
54
+ }
55
+
56
+ &__toggle {
57
+ font-size: 20px;
58
+ color: #8b95b0;
59
+ }
60
+
61
+ &__content {
62
+ margin: 0 18px 16px;
63
+ padding-left: 42px;
64
+ border-left: 3px solid #d6dce8;
65
+ font-size: 22px;
66
+ color: #8b95b0;
67
+ line-height: 1.7;
68
+ overflow-wrap: break-word;
69
+ overflow: hidden;
70
+
71
+ p {
72
+ margin: 6px 0;
73
+ }
74
+ }
75
+ &--active &__content {
76
+ border-left-color: #667eea;
77
+ }
78
+ }
79
+
80
+ @keyframes reasoning-pulse {
81
+ 0%,
82
+ 100% {
83
+ opacity: 0.4;
84
+ transform: scale(0.8);
85
+ }
86
+ 50% {
87
+ opacity: 1;
88
+ transform: scale(1.2);
89
+ }
90
+ }
@@ -0,0 +1,56 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import ReactMarkdown from 'react-markdown';
3
+ import remarkGfm from 'remark-gfm';
4
+ import './index.less';
5
+
6
+ interface Props {
7
+ reasoning: string;
8
+ /** 是否正在思考中(自动展开 + 计时) */
9
+ isActive?: boolean;
10
+ }
11
+
12
+ /** 思考过程折叠块(思考中自动展开并计时,结束后自动收起)。 */
13
+ export default function ReasoningBlock({ reasoning, isActive }: Props) {
14
+ const [expanded, setExpanded] = useState(!!isActive);
15
+ const startTime = useRef(Date.now());
16
+ const [elapsed, setElapsed] = useState(0);
17
+ const wasActive = useRef(isActive);
18
+
19
+ useEffect(() => {
20
+ if (isActive) {
21
+ wasActive.current = true;
22
+ setExpanded(true);
23
+ startTime.current = Date.now();
24
+ const timer = setInterval(() => {
25
+ setElapsed(Math.floor((Date.now() - startTime.current) / 1000));
26
+ }, 1000);
27
+ return () => clearInterval(timer);
28
+ }
29
+ if (wasActive.current) {
30
+ setExpanded(false);
31
+ wasActive.current = false;
32
+ }
33
+ }, [isActive]);
34
+
35
+ const durationLabel = elapsed > 0 ? `${elapsed}s` : '';
36
+
37
+ return (
38
+ <div className={`reasoning ${isActive ? 'reasoning--active' : 'reasoning--done'}`}>
39
+ <div className="reasoning__header" onClick={() => setExpanded(!expanded)}>
40
+ <div className="reasoning__left">
41
+ <div className={`reasoning__indicator${isActive ? ' reasoning__indicator--pulse' : ''}`} />
42
+ <span className="reasoning__title">{isActive ? '思考中...' : '思考过程'}</span>
43
+ {durationLabel && <span className="reasoning__duration">({durationLabel})</span>}
44
+ </div>
45
+ <span className={`reasoning__toggle${expanded ? ' reasoning__toggle--up' : ''}`}>
46
+ {expanded ? '收起' : '展开'}
47
+ </span>
48
+ </div>
49
+ {expanded && (
50
+ <div className="reasoning__content">
51
+ <ReactMarkdown remarkPlugins={[remarkGfm]}>{reasoning}</ReactMarkdown>
52
+ </div>
53
+ )}
54
+ </div>
55
+ );
56
+ }
@@ -0,0 +1,32 @@
1
+ .scroll-to-bottom-btn {
2
+ position: absolute;
3
+ right: 32px;
4
+ bottom: 32px;
5
+ width: 72px;
6
+ height: 72px;
7
+ border-radius: 50%;
8
+ background: #fff;
9
+ box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.12);
10
+ display: flex;
11
+ align-items: center;
12
+ justify-content: center;
13
+ z-index: 10;
14
+ opacity: 0;
15
+ transform: scale(0.8);
16
+ transition: opacity var(--tbox-motion-duration-fast) ease, transform var(--tbox-motion-duration-fast) ease;
17
+ pointer-events: none;
18
+
19
+ &--visible {
20
+ opacity: 1;
21
+ transform: scale(1);
22
+ pointer-events: auto;
23
+ }
24
+
25
+ &__arrow {
26
+ width: 0;
27
+ height: 0;
28
+ border-left: 12px solid transparent;
29
+ border-right: 12px solid transparent;
30
+ border-top: 14px solid #666;
31
+ }
32
+ }
@@ -0,0 +1,10 @@
1
+ import './index.less';
2
+
3
+ /** 生成时出现的“回到底部”悬浮按钮。 */
4
+ export default function ScrollToBottomButton({ visible, onClick }: { visible: boolean; onClick: () => void }) {
5
+ return (
6
+ <div className={`scroll-to-bottom-btn${visible ? ' scroll-to-bottom-btn--visible' : ''}`} onClick={onClick}>
7
+ <div className="scroll-to-bottom-btn__arrow" />
8
+ </div>
9
+ );
10
+ }