@tbox.cn/app-agent-ui-kit 0.0.0-stage → 1.0.0-alpha.6
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 +58 -3
- package/src/ChatPage.tsx +332 -0
- package/src/card/define-card.ts +34 -0
- package/src/card/primitives.test.tsx +147 -0
- package/src/card/primitives.tsx +627 -0
- package/src/card/use-card-actions.ts +86 -0
- package/src/chat-config.test.ts +46 -0
- package/src/chat-config.ts +80 -0
- package/src/components/ActionBar/DebugButton.test.tsx +84 -0
- package/src/components/ActionBar/DebugButton.tsx +53 -0
- package/src/components/ActionBar/index.test.tsx +83 -0
- package/src/components/ActionBar/index.tsx +158 -0
- package/src/components/CardRenderer.tsx +36 -0
- package/src/components/ChatHeader/index.test.tsx +74 -0
- package/src/components/ChatHeader/index.tsx +77 -0
- package/src/components/ChatInput/index.test.tsx +156 -0
- package/src/components/ChatInput/index.tsx +290 -0
- package/src/components/ChatInput/voice/VoicePressField.tsx +43 -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.tsx +41 -0
- package/src/components/MediaList/index.tsx +270 -0
- package/src/components/MessageBubble/index.test.tsx +134 -0
- package/src/components/MessageBubble/index.tsx +202 -0
- package/src/components/PullDownIndicator/index.tsx +31 -0
- package/src/components/QuickCommands/index.test.tsx +99 -0
- package/src/components/QuickCommands/index.tsx +52 -0
- package/src/components/ReasoningBlock/index.tsx +61 -0
- package/src/components/ScrollToBottomButton/index.tsx +8 -0
- package/src/components/ToolCallBlock/detail.test.ts +346 -0
- package/src/components/ToolCallBlock/detail.ts +204 -0
- package/src/components/ToolCallBlock/index.test.tsx +261 -0
- package/src/components/ToolCallBlock/index.tsx +230 -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/icons.ts +39 -0
- package/src/index.ts +122 -0
- package/src/shell.contract.json +59 -0
- package/src/shell.test.ts +61 -0
- package/src/shell.ts +45 -0
- package/src/store-context.tsx +92 -0
- package/src/test/setup.ts +7 -0
- package/src/theme/base.css +132 -0
- package/src/theme/contract.json +72 -0
- package/src/theme/motion.css +19 -0
- package/src/theme/theme-contract.test.ts +69 -0
- package/src/theme/theme.ts +17 -0
- package/src/theme/tokens.css +81 -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,147 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
3
|
+
import {
|
|
4
|
+
ActionList,
|
|
5
|
+
ActionRow,
|
|
6
|
+
Bill,
|
|
7
|
+
Card,
|
|
8
|
+
CardButton,
|
|
9
|
+
CardHeader,
|
|
10
|
+
CheckRow,
|
|
11
|
+
ConfirmSheet,
|
|
12
|
+
EmptyState,
|
|
13
|
+
EntityRow,
|
|
14
|
+
Hero,
|
|
15
|
+
KeyValueList,
|
|
16
|
+
MediaRow,
|
|
17
|
+
Notice,
|
|
18
|
+
StatGrid,
|
|
19
|
+
StatusTag,
|
|
20
|
+
Steps,
|
|
21
|
+
TagList,
|
|
22
|
+
Ticket,
|
|
23
|
+
Timeline,
|
|
24
|
+
} from './primitives';
|
|
25
|
+
|
|
26
|
+
const html = (node: React.ReactElement) => renderToStaticMarkup(node);
|
|
27
|
+
|
|
28
|
+
describe('卡片基元', () => {
|
|
29
|
+
it('容器 + 标题 + 属性列表成套渲染', () => {
|
|
30
|
+
const markup = html(
|
|
31
|
+
<Card footer="数据更新于刚刚">
|
|
32
|
+
<CardHeader eyebrow="订单" title="待支付" status={<StatusTag tone="warning">待支付</StatusTag>} />
|
|
33
|
+
<KeyValueList items={[{ label: '车牌', value: '浙A·12345' }, { label: '入场', value: '12:01' }]} />
|
|
34
|
+
</Card>,
|
|
35
|
+
);
|
|
36
|
+
expect(markup).toContain('tbox-card-primitive');
|
|
37
|
+
expect(markup).toContain('待支付');
|
|
38
|
+
expect(markup).toContain('浙A·12345');
|
|
39
|
+
expect(markup).toContain('数据更新于刚刚');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('明细带合计', () => {
|
|
43
|
+
const markup = html(
|
|
44
|
+
<Bill lines={[{ label: '停车费', value: '15.00 元' }, { label: '券抵扣', value: '-10.00 元', muted: true }]} total={{ label: '应付', value: '5.00 元' }} />,
|
|
45
|
+
);
|
|
46
|
+
expect(markup).toContain('应付');
|
|
47
|
+
expect(markup).toContain('tbox-bill__row--muted');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('提示条按 tone 变体', () => {
|
|
51
|
+
expect(html(<Notice tone="warning">额度不足</Notice>)).toContain('tbox-notice--warning');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('按钮行在禁用态加类名', () => {
|
|
55
|
+
const markup = html(
|
|
56
|
+
<ActionRow disabled primary={<CardButton>立即支付</CardButton>} secondary={<CardButton variant="secondary">取消</CardButton>} />,
|
|
57
|
+
);
|
|
58
|
+
expect(markup).toContain('tbox-actions--disabled');
|
|
59
|
+
expect(markup).toContain('立即支付');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('确认弹层关闭时渲染为空', () => {
|
|
63
|
+
expect(
|
|
64
|
+
html(
|
|
65
|
+
<ConfirmSheet open={false} title="确认" onConfirm={() => {}} onCancel={() => {}} />,
|
|
66
|
+
),
|
|
67
|
+
).toBe('');
|
|
68
|
+
expect(
|
|
69
|
+
html(<ConfirmSheet open title="确认入会" description="将获得 100 积分" onConfirm={() => {}} onCancel={() => {}} />),
|
|
70
|
+
).toContain('确认入会');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('票券、步骤、图文条目可渲染', () => {
|
|
74
|
+
expect(html(<Ticket amount="20 元" condition="满 100 可用" meta="有效期至 12-31" />)).toContain('tbox-ticket__amount');
|
|
75
|
+
expect(html(<Steps steps={[{ title: 'B2 层', detail: '靠近 3 号电梯' }, { title: '取车' }]} />)).toContain('tbox-steps__index');
|
|
76
|
+
expect(html(<MediaRow title="江南小馆" meta="B1 · 人均 60" action={<CardButton variant="link">去看看</CardButton>} />)).toContain('江南小馆');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
describe('第二版基元', () => {
|
|
82
|
+
it('Hero / StatGrid / Timeline 渲染品牌块与数值', () => {
|
|
83
|
+
const markup = html(
|
|
84
|
+
<>
|
|
85
|
+
<Hero eyebrow="MEMBER" title="我的积分" value={100} unit="积分" footnote="可兑停车券" />
|
|
86
|
+
<StatGrid items={[{ label: '积分', value: 100 }, { label: '券', value: 2, hint: '本月' }]} />
|
|
87
|
+
<Timeline items={[{ label: '入会礼', amount: '+100', tone: 'gain', time: '11/18' }]} />
|
|
88
|
+
</>,
|
|
89
|
+
);
|
|
90
|
+
expect(markup).toContain('tbox-hero');
|
|
91
|
+
expect(markup).toContain('我的积分');
|
|
92
|
+
expect(markup).toContain('tbox-stats__value');
|
|
93
|
+
expect(markup).toContain('tbox-timeline__item--gain');
|
|
94
|
+
expect(markup).toContain('+100');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('EntityRow 支持价格与说明,EmptyState 给下一步', () => {
|
|
98
|
+
const markup = html(
|
|
99
|
+
<>
|
|
100
|
+
<EntityRow title="江南小馆" meta="餐饮 · L1" price="¥80/人" tags={<TagList tags={['满100减15']} />} />
|
|
101
|
+
<EmptyState title="暂无停车券" description="缴费或参加活动可攒积分" />
|
|
102
|
+
</>,
|
|
103
|
+
);
|
|
104
|
+
expect(markup).toContain('tbox-entity__price');
|
|
105
|
+
expect(markup).toContain('¥80/人');
|
|
106
|
+
expect(markup).toContain('tbox-empty__desc');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('CheckRow 只读态不带交互语义', () => {
|
|
110
|
+
const readOnly = html(<CheckRow label="使用停车券" checked />);
|
|
111
|
+
expect(readOnly).toContain('tbox-check--on');
|
|
112
|
+
expect(readOnly).toContain('tbox-check--static');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('ActionList 点击前确认时先开弹层,确认后才调用动作', () => {
|
|
116
|
+
const calls: string[] = [];
|
|
117
|
+
const api = {
|
|
118
|
+
send: (text: string) => calls.push(`send:${text}`),
|
|
119
|
+
invoke: (id: string, input?: Record<string, unknown>) => calls.push(`invoke:${id}:${JSON.stringify(input ?? {})}`),
|
|
120
|
+
disabled: false,
|
|
121
|
+
isHistory: false,
|
|
122
|
+
isGenerating: false,
|
|
123
|
+
};
|
|
124
|
+
const markup = html(
|
|
125
|
+
<ActionList
|
|
126
|
+
api={api}
|
|
127
|
+
actions={[
|
|
128
|
+
{ label: '确认支付', invoke: { id: 'pay-parking', input: { plate: '浙A' } }, confirm: { title: '确认支付 ¥5?' } },
|
|
129
|
+
{ label: '再想想', send: { text: '先不付', displayText: '先不付' } },
|
|
130
|
+
]}
|
|
131
|
+
/>,
|
|
132
|
+
);
|
|
133
|
+
expect(markup).toContain('确认支付');
|
|
134
|
+
expect(markup).toContain('再想想');
|
|
135
|
+
expect(calls).toEqual([]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('ActionList 禁用时按钮带 disabled', () => {
|
|
139
|
+
const markup = html(
|
|
140
|
+
<ActionList
|
|
141
|
+
api={{ send: () => {}, invoke: () => {}, disabled: true, isHistory: false, isGenerating: false }}
|
|
142
|
+
actions={[{ label: '领券', invoke: { id: 'claim' } }]}
|
|
143
|
+
/>,
|
|
144
|
+
);
|
|
145
|
+
expect(markup).toContain('disabled');
|
|
146
|
+
});
|
|
147
|
+
});
|