@amaster.ai/components-templates 1.3.0
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/README.md +193 -0
- package/bin/amaster.js +2 -0
- package/components/ai-assistant/example.md +34 -0
- package/components/ai-assistant/package.json +34 -0
- package/components/ai-assistant/template/ai-assistant.tsx +88 -0
- package/components/ai-assistant/template/components/Markdown.tsx +70 -0
- package/components/ai-assistant/template/components/chat-assistant-message.tsx +190 -0
- package/components/ai-assistant/template/components/chat-banner.tsx +17 -0
- package/components/ai-assistant/template/components/chat-display-mode-switcher.tsx +70 -0
- package/components/ai-assistant/template/components/chat-floating-button.tsx +56 -0
- package/components/ai-assistant/template/components/chat-floating-card.tsx +43 -0
- package/components/ai-assistant/template/components/chat-header.tsx +66 -0
- package/components/ai-assistant/template/components/chat-input.tsx +143 -0
- package/components/ai-assistant/template/components/chat-messages.tsx +81 -0
- package/components/ai-assistant/template/components/chat-recommends.tsx +36 -0
- package/components/ai-assistant/template/components/chat-speech-button.tsx +43 -0
- package/components/ai-assistant/template/components/chat-user-message.tsx +26 -0
- package/components/ai-assistant/template/components/ui-renderer-lazy.tsx +307 -0
- package/components/ai-assistant/template/components/ui-renderer.tsx +34 -0
- package/components/ai-assistant/template/components/voice-input.tsx +43 -0
- package/components/ai-assistant/template/hooks/useAssistantStore.tsx +36 -0
- package/components/ai-assistant/template/hooks/useAutoScroll.ts +90 -0
- package/components/ai-assistant/template/hooks/useConversationProcessor.ts +649 -0
- package/components/ai-assistant/template/hooks/useDisplayMode.tsx +74 -0
- package/components/ai-assistant/template/hooks/useDraggable.ts +125 -0
- package/components/ai-assistant/template/hooks/usePosition.ts +206 -0
- package/components/ai-assistant/template/hooks/useSpeak.ts +50 -0
- package/components/ai-assistant/template/hooks/useVoiceInput.ts +172 -0
- package/components/ai-assistant/template/i18n.ts +114 -0
- package/components/ai-assistant/template/index.ts +6 -0
- package/components/ai-assistant/template/inline-ai-assistant.tsx +78 -0
- package/components/ai-assistant/template/mock/mock-data.ts +643 -0
- package/components/ai-assistant/template/types.ts +72 -0
- package/index.js +13 -0
- package/package.json +67 -0
- package/packages/cli/dist/index.d.ts +3 -0
- package/packages/cli/dist/index.d.ts.map +1 -0
- package/packages/cli/dist/index.js +335 -0
- package/packages/cli/dist/index.js.map +1 -0
- package/packages/cli/package.json +35 -0
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
import type { Conversation, UIRenderMessage } from "../types";
|
|
2
|
+
|
|
3
|
+
export const mockUIConversations: {
|
|
4
|
+
type: "ui";
|
|
5
|
+
spec: any;
|
|
6
|
+
}[] = [
|
|
7
|
+
{
|
|
8
|
+
type: "ui",
|
|
9
|
+
spec: {
|
|
10
|
+
root: "table-card",
|
|
11
|
+
elements: {
|
|
12
|
+
"table-card": {
|
|
13
|
+
type: "Card",
|
|
14
|
+
props: { title: "用户数据", description: "最近活跃用户列表" },
|
|
15
|
+
children: ["table-1"],
|
|
16
|
+
},
|
|
17
|
+
"table-1": {
|
|
18
|
+
type: "Table",
|
|
19
|
+
props: {
|
|
20
|
+
columns: ["用户名", "邮箱", "角色", "状态"],
|
|
21
|
+
rows: [
|
|
22
|
+
["张三", "zhangsan@example.com", "管理员", "活跃"],
|
|
23
|
+
["李四", "lisi@example.com", "用户", "活跃"],
|
|
24
|
+
["王五", "wangwu@example.com", "用户", "禁用"],
|
|
25
|
+
["赵六", "zhaoliu@example.com", "编辑", "活跃"],
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
{
|
|
34
|
+
type: "ui",
|
|
35
|
+
spec: {
|
|
36
|
+
root: "status-1",
|
|
37
|
+
elements: {
|
|
38
|
+
"status-1": {
|
|
39
|
+
type: "Alert",
|
|
40
|
+
props: {
|
|
41
|
+
type: "success",
|
|
42
|
+
title: "系统运行正常",
|
|
43
|
+
message: "所有服务都在正常运行,无需处理",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
{
|
|
51
|
+
type: "ui",
|
|
52
|
+
spec: {
|
|
53
|
+
root: "progress-card",
|
|
54
|
+
elements: {
|
|
55
|
+
"progress-card": {
|
|
56
|
+
type: "Card",
|
|
57
|
+
props: { title: "任务进度" },
|
|
58
|
+
children: ["progress-1"],
|
|
59
|
+
},
|
|
60
|
+
"progress-1": {
|
|
61
|
+
type: "Progress",
|
|
62
|
+
props: {
|
|
63
|
+
value: 65,
|
|
64
|
+
max: 100,
|
|
65
|
+
label: "正在处理数据...",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
{
|
|
73
|
+
type: "ui",
|
|
74
|
+
spec: {
|
|
75
|
+
root: "stats-card",
|
|
76
|
+
elements: {
|
|
77
|
+
"stats-card": {
|
|
78
|
+
type: "Card",
|
|
79
|
+
props: { title: "服务器配置" },
|
|
80
|
+
children: ["stats-stack"],
|
|
81
|
+
},
|
|
82
|
+
"stats-stack": {
|
|
83
|
+
type: "Stack",
|
|
84
|
+
props: { direction: "vertical", gap: "sm" },
|
|
85
|
+
children: [
|
|
86
|
+
"stat-cpu",
|
|
87
|
+
"stat-memory",
|
|
88
|
+
"stat-storage",
|
|
89
|
+
"stat-status",
|
|
90
|
+
"stat-version",
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
"stat-cpu": {
|
|
94
|
+
type: "Text",
|
|
95
|
+
props: { text: "CPU: 8 核", variant: "body" },
|
|
96
|
+
},
|
|
97
|
+
"stat-memory": {
|
|
98
|
+
type: "Text",
|
|
99
|
+
props: { text: "内存: 32 GB", variant: "body" },
|
|
100
|
+
},
|
|
101
|
+
"stat-storage": {
|
|
102
|
+
type: "Text",
|
|
103
|
+
props: { text: "存储: 500 GB SSD", variant: "body" },
|
|
104
|
+
},
|
|
105
|
+
"stat-status": {
|
|
106
|
+
type: "Stack",
|
|
107
|
+
props: { direction: "horizontal", gap: "sm", align: "center" },
|
|
108
|
+
children: ["status-text", "status-badge"],
|
|
109
|
+
},
|
|
110
|
+
"status-text": {
|
|
111
|
+
type: "Text",
|
|
112
|
+
props: { text: "状态:", variant: "body" },
|
|
113
|
+
},
|
|
114
|
+
"status-badge": {
|
|
115
|
+
type: "Badge",
|
|
116
|
+
props: { text: "运行中", variant: "default" },
|
|
117
|
+
},
|
|
118
|
+
"stat-version": {
|
|
119
|
+
type: "Text",
|
|
120
|
+
props: { text: "版本: v2.5.1", variant: "muted" },
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
{
|
|
127
|
+
type: "ui",
|
|
128
|
+
spec: {
|
|
129
|
+
root: "actions-card",
|
|
130
|
+
elements: {
|
|
131
|
+
"actions-card": {
|
|
132
|
+
type: "Card",
|
|
133
|
+
props: {
|
|
134
|
+
title: "确认操作",
|
|
135
|
+
description: "您确定要删除此文件吗?此操作不可撤销。",
|
|
136
|
+
},
|
|
137
|
+
children: ["actions-stack"],
|
|
138
|
+
},
|
|
139
|
+
"actions-stack": {
|
|
140
|
+
type: "Stack",
|
|
141
|
+
props: { direction: "horizontal", gap: "md" },
|
|
142
|
+
children: ["btn-confirm", "btn-cancel"],
|
|
143
|
+
},
|
|
144
|
+
"btn-confirm": {
|
|
145
|
+
type: "Button",
|
|
146
|
+
props: { label: "确认删除", variant: "danger" },
|
|
147
|
+
on: {
|
|
148
|
+
press: {
|
|
149
|
+
action: "confirmSubmit"
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
"btn-cancel": {
|
|
154
|
+
type: "Button",
|
|
155
|
+
props: { label: "取消", variant: "secondary" },
|
|
156
|
+
on: {
|
|
157
|
+
press: {
|
|
158
|
+
action: "confirmCancel",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
{
|
|
167
|
+
type: "ui",
|
|
168
|
+
spec: {
|
|
169
|
+
root: "main-card",
|
|
170
|
+
elements: {
|
|
171
|
+
"main-card": {
|
|
172
|
+
type: "Card",
|
|
173
|
+
props: {
|
|
174
|
+
title: "系统概览",
|
|
175
|
+
description: "当前系统的整体运行状态",
|
|
176
|
+
},
|
|
177
|
+
children: ["stats-grid"],
|
|
178
|
+
},
|
|
179
|
+
"stats-grid": {
|
|
180
|
+
type: "Grid",
|
|
181
|
+
props: { columns: 3, gap: "md" },
|
|
182
|
+
children: ["stat-users", "stat-rps", "stat-error"],
|
|
183
|
+
},
|
|
184
|
+
"stat-users": {
|
|
185
|
+
type: "Card",
|
|
186
|
+
props: {},
|
|
187
|
+
children: ["users-heading", "users-value"],
|
|
188
|
+
},
|
|
189
|
+
"users-heading": {
|
|
190
|
+
type: "Heading",
|
|
191
|
+
props: { level: "h4", text: "在线用户" },
|
|
192
|
+
},
|
|
193
|
+
"users-value": {
|
|
194
|
+
type: "Text",
|
|
195
|
+
props: { text: "1,234", variant: "lead" },
|
|
196
|
+
},
|
|
197
|
+
"stat-rps": {
|
|
198
|
+
type: "Card",
|
|
199
|
+
props: {},
|
|
200
|
+
children: ["rps-heading", "rps-value"],
|
|
201
|
+
},
|
|
202
|
+
"rps-heading": {
|
|
203
|
+
type: "Heading",
|
|
204
|
+
props: { level: "h4", text: "请求/秒" },
|
|
205
|
+
},
|
|
206
|
+
"rps-value": {
|
|
207
|
+
type: "Text",
|
|
208
|
+
props: { text: "856", variant: "lead" },
|
|
209
|
+
},
|
|
210
|
+
"stat-error": {
|
|
211
|
+
type: "Card",
|
|
212
|
+
props: {},
|
|
213
|
+
children: ["error-heading", "error-badge"],
|
|
214
|
+
},
|
|
215
|
+
"error-heading": {
|
|
216
|
+
type: "Heading",
|
|
217
|
+
props: { level: "h4", text: "错误率" },
|
|
218
|
+
},
|
|
219
|
+
"error-badge": {
|
|
220
|
+
type: "Badge",
|
|
221
|
+
props: { text: "0.12%", variant: "secondary" },
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
{
|
|
228
|
+
type: "ui",
|
|
229
|
+
spec: {
|
|
230
|
+
root: "login-container",
|
|
231
|
+
elements: {
|
|
232
|
+
"login-container": {
|
|
233
|
+
type: "Card",
|
|
234
|
+
props: {
|
|
235
|
+
title: "登录",
|
|
236
|
+
description: "请输入您的账号和密码",
|
|
237
|
+
maxWidth: "sm",
|
|
238
|
+
centered: true,
|
|
239
|
+
},
|
|
240
|
+
children: ["login-form"],
|
|
241
|
+
visible: {
|
|
242
|
+
$state: "/showForm",
|
|
243
|
+
not: true,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
"login-form": {
|
|
247
|
+
type: "Stack",
|
|
248
|
+
props: {
|
|
249
|
+
direction: "vertical",
|
|
250
|
+
gap: "md",
|
|
251
|
+
},
|
|
252
|
+
children: ["email-input", "password-input", "submit-button"],
|
|
253
|
+
},
|
|
254
|
+
"email-input": {
|
|
255
|
+
type: "Input",
|
|
256
|
+
props: {
|
|
257
|
+
label: "邮箱",
|
|
258
|
+
name: "email",
|
|
259
|
+
type: "email",
|
|
260
|
+
placeholder: "请输入邮箱",
|
|
261
|
+
value: {
|
|
262
|
+
$bindState: "/form/email",
|
|
263
|
+
},
|
|
264
|
+
checks: [
|
|
265
|
+
{
|
|
266
|
+
type: "required",
|
|
267
|
+
message: "邮箱不能为空",
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
type: "email",
|
|
271
|
+
message: "请输入有效的邮箱地址",
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
children: [],
|
|
276
|
+
},
|
|
277
|
+
"password-input": {
|
|
278
|
+
type: "Input",
|
|
279
|
+
props: {
|
|
280
|
+
label: "密码",
|
|
281
|
+
name: "password",
|
|
282
|
+
type: "password",
|
|
283
|
+
placeholder: "请输入密码",
|
|
284
|
+
value: {
|
|
285
|
+
$bindState: "/form/password",
|
|
286
|
+
},
|
|
287
|
+
checks: [
|
|
288
|
+
{
|
|
289
|
+
type: "required",
|
|
290
|
+
message: "密码不能为空",
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
type: "minLength",
|
|
294
|
+
message: "密码至少需要6个字符",
|
|
295
|
+
args: {
|
|
296
|
+
min: 6,
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
},
|
|
301
|
+
children: [],
|
|
302
|
+
},
|
|
303
|
+
"submit-button": {
|
|
304
|
+
type: "Button",
|
|
305
|
+
props: {
|
|
306
|
+
label: "登录",
|
|
307
|
+
variant: "primary",
|
|
308
|
+
},
|
|
309
|
+
on: {
|
|
310
|
+
press: {
|
|
311
|
+
action: "validateForm",
|
|
312
|
+
params: {
|
|
313
|
+
statePath: "/formValidation",
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
children: [],
|
|
318
|
+
watch: {
|
|
319
|
+
"/formValidation": {
|
|
320
|
+
action: "submitLogin",
|
|
321
|
+
params: {
|
|
322
|
+
email: {
|
|
323
|
+
$state: "/form/email",
|
|
324
|
+
},
|
|
325
|
+
password: {
|
|
326
|
+
$state: "/form/password",
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
state: {
|
|
334
|
+
form: {
|
|
335
|
+
email: "",
|
|
336
|
+
password: "",
|
|
337
|
+
},
|
|
338
|
+
formValidation: {
|
|
339
|
+
valid: false,
|
|
340
|
+
errors: {},
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
{
|
|
347
|
+
type: "ui",
|
|
348
|
+
spec: {
|
|
349
|
+
root: "accordion-card",
|
|
350
|
+
elements: {
|
|
351
|
+
"accordion-card": {
|
|
352
|
+
type: "Card",
|
|
353
|
+
props: { title: "常见问题" },
|
|
354
|
+
children: ["accordion-1"],
|
|
355
|
+
},
|
|
356
|
+
"accordion-1": {
|
|
357
|
+
type: "Accordion",
|
|
358
|
+
props: {
|
|
359
|
+
type: "single",
|
|
360
|
+
items: [
|
|
361
|
+
{
|
|
362
|
+
title: "如何重置密码?",
|
|
363
|
+
content: "点击登录页面的'忘记密码'链接,按提示操作。",
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
title: "支持哪些支付方式?",
|
|
367
|
+
content: "我们支持支付宝、微信支付、银行卡等多种支付方式。",
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
title: "如何联系客服?",
|
|
371
|
+
content: "您可以通过在线客服、电话或邮件联系我们。",
|
|
372
|
+
},
|
|
373
|
+
],
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
{
|
|
381
|
+
type: "ui",
|
|
382
|
+
spec: {
|
|
383
|
+
root: "chart-card",
|
|
384
|
+
elements: {
|
|
385
|
+
"chart-card": {
|
|
386
|
+
type: "Card",
|
|
387
|
+
props: {
|
|
388
|
+
title: "月度销售数据",
|
|
389
|
+
description: "2024年上半年销售额统计",
|
|
390
|
+
},
|
|
391
|
+
children: ["bar-chart-1"],
|
|
392
|
+
},
|
|
393
|
+
"bar-chart-1": {
|
|
394
|
+
type: "BarChart",
|
|
395
|
+
props: {
|
|
396
|
+
data: [
|
|
397
|
+
{ month: "1月", sales: 12000 },
|
|
398
|
+
{ month: "2月", sales: 19000 },
|
|
399
|
+
{ month: "3月", sales: 15000 },
|
|
400
|
+
{ month: "4月", sales: 22000 },
|
|
401
|
+
{ month: "5月", sales: 28000 },
|
|
402
|
+
{ month: "6月", sales: 32000 },
|
|
403
|
+
],
|
|
404
|
+
xKey: "month",
|
|
405
|
+
yKey: "sales",
|
|
406
|
+
height: 300,
|
|
407
|
+
},
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
{
|
|
414
|
+
type: "ui",
|
|
415
|
+
spec: {
|
|
416
|
+
root: "line-chart-card",
|
|
417
|
+
elements: {
|
|
418
|
+
"line-chart-card": {
|
|
419
|
+
type: "Card",
|
|
420
|
+
props: { title: "用户增长趋势", description: "最近7天活跃用户变化" },
|
|
421
|
+
children: ["line-chart-1"],
|
|
422
|
+
},
|
|
423
|
+
"line-chart-1": {
|
|
424
|
+
type: "LineChart",
|
|
425
|
+
props: {
|
|
426
|
+
data: [
|
|
427
|
+
{ day: "周一", users: 1200 },
|
|
428
|
+
{ day: "周二", users: 1350 },
|
|
429
|
+
{ day: "周三", users: 1100 },
|
|
430
|
+
{ day: "周四", users: 1580 },
|
|
431
|
+
{ day: "周五", users: 1890 },
|
|
432
|
+
{ day: "周六", users: 2100 },
|
|
433
|
+
{ day: "周日", users: 1950 },
|
|
434
|
+
],
|
|
435
|
+
xKey: "day",
|
|
436
|
+
yKey: "users",
|
|
437
|
+
height: 300,
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
|
|
444
|
+
{
|
|
445
|
+
type: "ui",
|
|
446
|
+
spec: {
|
|
447
|
+
root: "pie-chart-card",
|
|
448
|
+
elements: {
|
|
449
|
+
"pie-chart-card": {
|
|
450
|
+
type: "Card",
|
|
451
|
+
props: { title: "用户分布", description: "按设备类型统计" },
|
|
452
|
+
children: ["pie-chart-1"],
|
|
453
|
+
},
|
|
454
|
+
"pie-chart-1": {
|
|
455
|
+
type: "PieChart",
|
|
456
|
+
props: {
|
|
457
|
+
data: [
|
|
458
|
+
{ name: "桌面端", value: 450 },
|
|
459
|
+
{ name: "移动端", value: 680 },
|
|
460
|
+
{ name: "平板", value: 120 },
|
|
461
|
+
{ name: "其他", value: 50 },
|
|
462
|
+
],
|
|
463
|
+
nameKey: "name",
|
|
464
|
+
valueKey: "value",
|
|
465
|
+
height: 300,
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
|
|
472
|
+
{
|
|
473
|
+
type: "ui",
|
|
474
|
+
spec: {
|
|
475
|
+
root: "dashboard-card",
|
|
476
|
+
elements: {
|
|
477
|
+
"dashboard-card": {
|
|
478
|
+
type: "Card",
|
|
479
|
+
props: { title: "数据看板", description: "核心业务指标监控" },
|
|
480
|
+
children: ["dashboard-grid"],
|
|
481
|
+
},
|
|
482
|
+
"dashboard-grid": {
|
|
483
|
+
type: "Grid",
|
|
484
|
+
props: { columns: 2, gap: "md" },
|
|
485
|
+
children: ["area-chart-card", "stats-list-card"],
|
|
486
|
+
},
|
|
487
|
+
"area-chart-card": {
|
|
488
|
+
type: "Card",
|
|
489
|
+
props: { title: "收入趋势" },
|
|
490
|
+
children: ["area-chart-1"],
|
|
491
|
+
},
|
|
492
|
+
"area-chart-1": {
|
|
493
|
+
type: "AreaChart",
|
|
494
|
+
props: {
|
|
495
|
+
data: [
|
|
496
|
+
{ month: "1月", revenue: 45000 },
|
|
497
|
+
{ month: "2月", revenue: 52000 },
|
|
498
|
+
{ month: "3月", revenue: 48000 },
|
|
499
|
+
{ month: "4月", revenue: 61000 },
|
|
500
|
+
{ month: "5月", revenue: 75000 },
|
|
501
|
+
{ month: "6月", revenue: 82000 },
|
|
502
|
+
],
|
|
503
|
+
xKey: "month",
|
|
504
|
+
yKey: "revenue",
|
|
505
|
+
height: 250,
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
"stats-list-card": {
|
|
509
|
+
type: "Card",
|
|
510
|
+
props: { title: "关键指标" },
|
|
511
|
+
children: ["stats-stack"],
|
|
512
|
+
},
|
|
513
|
+
"stats-stack": {
|
|
514
|
+
type: "Stack",
|
|
515
|
+
props: { direction: "vertical", gap: "sm" },
|
|
516
|
+
children: ["stat-1", "stat-2", "stat-3", "stat-4"],
|
|
517
|
+
},
|
|
518
|
+
"stat-1": {
|
|
519
|
+
type: "Stack",
|
|
520
|
+
props: { direction: "horizontal", justify: "between" },
|
|
521
|
+
children: ["stat-1-label", "stat-1-value"],
|
|
522
|
+
},
|
|
523
|
+
"stat-1-label": {
|
|
524
|
+
type: "Text",
|
|
525
|
+
props: { text: "总收入", variant: "muted" },
|
|
526
|
+
},
|
|
527
|
+
"stat-1-value": {
|
|
528
|
+
type: "Text",
|
|
529
|
+
props: { text: "¥358,000", variant: "body" },
|
|
530
|
+
},
|
|
531
|
+
"stat-2": {
|
|
532
|
+
type: "Stack",
|
|
533
|
+
props: { direction: "horizontal", justify: "between" },
|
|
534
|
+
children: ["stat-2-label", "stat-2-value"],
|
|
535
|
+
},
|
|
536
|
+
"stat-2-label": {
|
|
537
|
+
type: "Text",
|
|
538
|
+
props: { text: "订单数", variant: "muted" },
|
|
539
|
+
},
|
|
540
|
+
"stat-2-value": {
|
|
541
|
+
type: "Text",
|
|
542
|
+
props: { text: "1,234", variant: "body" },
|
|
543
|
+
},
|
|
544
|
+
"stat-3": {
|
|
545
|
+
type: "Stack",
|
|
546
|
+
props: { direction: "horizontal", justify: "between" },
|
|
547
|
+
children: ["stat-3-label", "stat-3-badge"],
|
|
548
|
+
},
|
|
549
|
+
"stat-3-label": {
|
|
550
|
+
type: "Text",
|
|
551
|
+
props: { text: "转化率", variant: "muted" },
|
|
552
|
+
},
|
|
553
|
+
"stat-3-badge": {
|
|
554
|
+
type: "Badge",
|
|
555
|
+
props: { text: "3.2%", variant: "default" },
|
|
556
|
+
},
|
|
557
|
+
"stat-4": {
|
|
558
|
+
type: "Stack",
|
|
559
|
+
props: { direction: "horizontal", justify: "between" },
|
|
560
|
+
children: ["stat-4-label", "stat-4-badge"],
|
|
561
|
+
},
|
|
562
|
+
"stat-4-label": {
|
|
563
|
+
type: "Text",
|
|
564
|
+
props: { text: "满意度", variant: "muted" },
|
|
565
|
+
},
|
|
566
|
+
"stat-4-badge": {
|
|
567
|
+
type: "Badge",
|
|
568
|
+
props: { text: "4.8/5", variant: "secondary" },
|
|
569
|
+
},
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
];
|
|
574
|
+
|
|
575
|
+
export function generateMockUIStream(
|
|
576
|
+
taskId: string,
|
|
577
|
+
onChunk: (chunk: {
|
|
578
|
+
result: {
|
|
579
|
+
kind: "status-update";
|
|
580
|
+
taskId: string;
|
|
581
|
+
status: {
|
|
582
|
+
state: "working" | "completed";
|
|
583
|
+
timestamp: string;
|
|
584
|
+
message: {
|
|
585
|
+
kind: "message";
|
|
586
|
+
role: "agent";
|
|
587
|
+
parts: Array<{
|
|
588
|
+
kind: "data";
|
|
589
|
+
data: {
|
|
590
|
+
type: "ui";
|
|
591
|
+
spec: Record<string, any>;
|
|
592
|
+
};
|
|
593
|
+
}>;
|
|
594
|
+
messageId: string;
|
|
595
|
+
};
|
|
596
|
+
};
|
|
597
|
+
final: boolean;
|
|
598
|
+
metadata?: Record<string, unknown>;
|
|
599
|
+
};
|
|
600
|
+
}) => void,
|
|
601
|
+
): () => void {
|
|
602
|
+
const chunks = mockUIConversations;
|
|
603
|
+
let index = 0;
|
|
604
|
+
let timeoutId: NodeJS.Timeout | null = null;
|
|
605
|
+
|
|
606
|
+
const next = () => {
|
|
607
|
+
if (index >= chunks.length) return;
|
|
608
|
+
onChunk({
|
|
609
|
+
result: {
|
|
610
|
+
kind: "status-update",
|
|
611
|
+
taskId,
|
|
612
|
+
status: {
|
|
613
|
+
state: index === chunks.length - 1 ? "completed" : "working",
|
|
614
|
+
timestamp: new Date().toISOString(),
|
|
615
|
+
message: {
|
|
616
|
+
kind: "message",
|
|
617
|
+
role: "agent",
|
|
618
|
+
messageId: `mock-message-${index}`,
|
|
619
|
+
parts: [
|
|
620
|
+
{
|
|
621
|
+
kind: "data",
|
|
622
|
+
data: chunks[index],
|
|
623
|
+
},
|
|
624
|
+
],
|
|
625
|
+
},
|
|
626
|
+
},
|
|
627
|
+
final: index === chunks.length - 1,
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
index++;
|
|
631
|
+
if (index < chunks.length) {
|
|
632
|
+
timeoutId = setTimeout(next, 500);
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
next();
|
|
637
|
+
|
|
638
|
+
return () => {
|
|
639
|
+
if (timeoutId) {
|
|
640
|
+
clearTimeout(timeoutId);
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export type Role = "user" | "assistant" | "system";
|
|
2
|
+
|
|
3
|
+
interface BaseMessage {
|
|
4
|
+
messageId: string;
|
|
5
|
+
role?: Role;
|
|
6
|
+
kind: string; // 'message' | 'status-update' | 'text-content' 等
|
|
7
|
+
timestamp?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface TextMessage extends BaseMessage {
|
|
11
|
+
kind: "text-content" | "message";
|
|
12
|
+
content: string; // 最终拼接后的文本
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ErrorMessage extends BaseMessage {
|
|
16
|
+
kind: "error";
|
|
17
|
+
content: string; // 错误信息文本
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ThoughtMessage extends BaseMessage {
|
|
21
|
+
kind: "thought";
|
|
22
|
+
thought: string; // 逐步累积的 thinking 内容
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ToolMessage extends BaseMessage {
|
|
26
|
+
kind: "tool";
|
|
27
|
+
toolName?: string;
|
|
28
|
+
toolStatus?: string;
|
|
29
|
+
toolDescription?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface UIRenderMessage extends BaseMessage {
|
|
33
|
+
kind: "ui-render";
|
|
34
|
+
spec: {
|
|
35
|
+
root: string;
|
|
36
|
+
elements: Record<
|
|
37
|
+
string,
|
|
38
|
+
{
|
|
39
|
+
type: string;
|
|
40
|
+
props?: Record<string, unknown>;
|
|
41
|
+
children?: string[];
|
|
42
|
+
}
|
|
43
|
+
>;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type MessagesItem =
|
|
48
|
+
| TextMessage
|
|
49
|
+
| ThoughtMessage
|
|
50
|
+
| ToolMessage
|
|
51
|
+
| UIRenderMessage
|
|
52
|
+
| BaseMessage;
|
|
53
|
+
|
|
54
|
+
export interface Conversation {
|
|
55
|
+
taskId: string;
|
|
56
|
+
status: "submitted" | "working" | "completed" | "error";
|
|
57
|
+
messages: MessagesItem[];
|
|
58
|
+
lastUpdated: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface Position {
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface InlineAIAssistantProps {
|
|
67
|
+
showBanner?: boolean;
|
|
68
|
+
bannerText?: string;
|
|
69
|
+
className?: string;
|
|
70
|
+
style?: React.CSSProperties;
|
|
71
|
+
greeting?: string;
|
|
72
|
+
}
|