@tbox.cn/app-agent-ui-kit 1.0.0-alpha.1 → 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.
Files changed (46) hide show
  1. package/README.md +1 -1
  2. package/package.json +9 -6
  3. package/src/ChatPage.tsx +34 -7
  4. package/src/card/define-card.ts +34 -0
  5. package/src/card/primitives.test.tsx +147 -0
  6. package/src/card/primitives.tsx +627 -0
  7. package/src/card/use-card-actions.ts +86 -0
  8. package/src/chat-config.test.ts +35 -71
  9. package/src/chat-config.ts +18 -0
  10. package/src/components/ActionBar/DebugButton.tsx +3 -3
  11. package/src/components/ActionBar/index.tsx +13 -14
  12. package/src/components/ChatHeader/index.tsx +19 -17
  13. package/src/components/ChatInput/index.tsx +32 -26
  14. package/src/components/ChatInput/voice/VoicePressField.tsx +12 -3
  15. package/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +9 -9
  16. package/src/components/HistoryEntry/index.tsx +3 -4
  17. package/src/components/MediaList/index.tsx +42 -28
  18. package/src/components/MessageBubble/index.tsx +52 -27
  19. package/src/components/PullDownIndicator/index.tsx +3 -4
  20. package/src/components/QuickCommands/index.tsx +6 -6
  21. package/src/components/ReasoningBlock/index.tsx +14 -9
  22. package/src/components/ScrollToBottomButton/index.tsx +2 -4
  23. package/src/components/ToolCallBlock/index.tsx +54 -36
  24. package/src/icons.ts +39 -0
  25. package/src/index.ts +54 -1
  26. package/src/shell.contract.json +59 -0
  27. package/src/shell.test.ts +61 -0
  28. package/src/shell.ts +45 -0
  29. package/src/theme/base.css +132 -0
  30. package/src/theme/contract.json +1 -1
  31. package/src/theme/theme-contract.test.ts +3 -3
  32. package/src/theme/{tokens.less → tokens.css} +14 -12
  33. package/src/ChatPage.less +0 -62
  34. package/src/components/ActionBar/index.less +0 -123
  35. package/src/components/ChatHeader/index.less +0 -148
  36. package/src/components/ChatInput/index.less +0 -394
  37. package/src/components/HistoryEntry/index.less +0 -49
  38. package/src/components/MediaList/index.less +0 -241
  39. package/src/components/MessageBubble/index.less +0 -325
  40. package/src/components/PullDownIndicator/index.less +0 -32
  41. package/src/components/QuickCommands/index.less +0 -63
  42. package/src/components/ReasoningBlock/index.less +0 -90
  43. package/src/components/ScrollToBottomButton/index.less +0 -32
  44. package/src/components/ToolCallBlock/index.less +0 -312
  45. package/src/theme/global.less +0 -99
  46. /package/src/theme/{motion.less → motion.css} +0 -0
@@ -6,7 +6,6 @@ import { buildSummaryText, deriveSummary, deriveToolCallItem, prettyDetailText }
6
6
  import type { ToolCallViewItem } from './detail';
7
7
  import { copyText } from '../../utils/copyText';
8
8
  import { toast } from '../../utils/toast';
9
- import './index.less';
10
9
 
11
10
  const EMPTY_TEXT = '(无)';
12
11
 
@@ -16,13 +15,31 @@ const STATUS_TEXT: Record<ToolCallViewItem['status'], string> = {
16
15
  calling: '执行中',
17
16
  };
18
17
 
18
+ /** 行状态 hook(BEM 修饰类保留;状态 → 完整类名映射,避免动态拼接)。 */
19
+ const ITEM_CLASS: Record<ToolCallViewItem['status'], string> = {
20
+ done: 'tool-calls__item--done',
21
+ error: 'tool-calls__item--error',
22
+ calling: 'tool-calls__item--calling',
23
+ };
24
+
25
+ /** 行标题颜色(旧 Less:--calling 次要 / --error 弱化 / 基态次要)。 */
26
+ const ITEM_NAME_COLOR_CLASS: Record<ToolCallViewItem['status'], string> = {
27
+ done: 'text-secondary-foreground',
28
+ error: 'text-muted-foreground',
29
+ calling: 'text-secondary-foreground',
30
+ };
31
+
32
+ /** 详情 IO 展示块(input/output 两个 pre 共用布局;颜色按错误态另给)。 */
33
+ const DETAIL_BODY_CLASS =
34
+ 'tool-calls__detail-body m-0 max-h-[280px] overflow-auto whitespace-pre-wrap break-all rounded-[8px] bg-muted px-3 py-2.5 font-mono text-xs leading-[1.6] [-webkit-overflow-scrolling:touch] [&::-webkit-scrollbar]:hidden';
35
+
19
36
  /**
20
37
  * Codex 风格工具活动日志:紧凑聚合行 / 流内活动列表 / 行内完整 IO。
21
38
  * 语义判定仍在 SDK describeToolCall + detail.ts 视图模型,本组件只管理展示状态;
22
39
  * debug 门控在渲染层(018 tool-debug):prod 恒无出入参展开入口(I4),
23
40
  * dev 行标题附技术名、详情走紧凑单行格式(复制仍为美化全文);
24
41
  * 图标颜色不传 color prop(phosphor 落 SVG fill 属性,var() 低版本 web-view 不可靠),
25
- * 统一走 currentColor + less token 类。
42
+ * 统一走 currentColor + token 类。
26
43
  */
27
44
  export default function ToolCallBlock({
28
45
  toolCalls,
@@ -48,37 +65,40 @@ export default function ToolCallBlock({
48
65
  };
49
66
 
50
67
  return (
51
- <div className="tool-calls">
68
+ <div className="tool-calls mb-1.5 flex flex-col">
52
69
  <button
53
70
  type="button"
54
- className={`tool-calls__summary${summary.calling ? ' tool-calls__summary--calling' : ''}`}
71
+ className={`tool-calls__summary flex min-h-11 w-full cursor-pointer appearance-none items-center justify-between rounded-[8px] border-0 bg-transparent px-0.5 py-[5px] text-left transition-[color,background] duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] [font-family:inherit] active:bg-[rgba(11,15,23,0.035)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none ${summary.calling ? 'tool-calls__summary--calling text-secondary-foreground' : 'text-muted-foreground'}`}
55
72
  aria-expanded={expanded}
56
73
  aria-controls={listId}
57
74
  onClick={() => setExpanded((current) => !current)}
58
75
  >
59
- <span className="tool-calls__left">
76
+ <span className="tool-calls__left flex min-w-0 flex-1 items-center gap-2">
60
77
  {summary.calling ? (
61
- <span className="tool-calls__spinner" aria-hidden="true" />
78
+ <span
79
+ className="tool-calls__spinner size-3.5 shrink-0 animate-[tool-spin_0.8s_linear_infinite] rounded-full border-2 border-[rgba(9,107,250,0.2)] border-t-primary motion-reduce:animate-none"
80
+ aria-hidden="true"
81
+ />
62
82
  ) : summary.failedCount > 0 ? (
63
- <X className="tool-calls__icon tool-calls__icon--error" size={16} strokeWidth={2.5} />
83
+ <X className="tool-calls__icon tool-calls__icon--error shrink-0 self-center text-muted-foreground" size={16} strokeWidth={2.5} />
64
84
  ) : (
65
- <Check className="tool-calls__icon tool-calls__icon--success" size={16} strokeWidth={2.5} />
85
+ <Check className="tool-calls__icon tool-calls__icon--success shrink-0 self-center text-muted-foreground" size={16} strokeWidth={2.5} />
66
86
  )}
67
- <span className="tool-calls__summary-text">
87
+ <span className="tool-calls__summary-text min-w-0 truncate text-xs font-normal leading-[1.4]">
68
88
  {buildSummaryText(summary).join(' · ')}
69
89
  {summary.failedCount > 0 && (
70
- <span className="tool-calls__failed"> · {summary.failedCount} 个失败</span>
90
+ <span className="tool-calls__failed text-muted-foreground"> · {summary.failedCount} 个失败</span>
71
91
  )}
72
92
  </span>
73
93
  </span>
74
94
  <CaretDown
75
95
  size={14}
76
- className={`tool-calls__chevron${expanded ? ' tool-calls__chevron--up' : ''}`}
96
+ className={`tool-calls__chevron ml-2 shrink-0 text-muted-foreground transition-transform duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] motion-reduce:transition-none ${expanded ? 'tool-calls__chevron--up rotate-180' : ''}`}
77
97
  />
78
98
  </button>
79
99
 
80
100
  {expanded && (
81
- <div id={listId} className="tool-calls__list">
101
+ <div id={listId} className="tool-calls__list mt-0.5 flex flex-col gap-px pl-0.5">
82
102
  {items.map((item) => {
83
103
  // 018 I4:prod(debug=false)恒无出入参展开入口;dev 才有详情交互
84
104
  const hasDetail = debug && !!item.detail;
@@ -86,41 +106,41 @@ export default function ToolCallBlock({
86
106
  const detailId = `${listId}-${item.id}`;
87
107
  const itemContent = (
88
108
  <>
89
- <span className="tool-calls__item-left">
109
+ <span className="tool-calls__item-left flex min-w-0 items-baseline gap-2">
90
110
  {item.status === 'calling' && (
91
- <span className="tool-calls__spinner tool-calls__spinner--sm" />
111
+ <span className="tool-calls__spinner tool-calls__spinner--sm size-3 shrink-0 animate-[tool-spin_0.8s_linear_infinite] rounded-full border-2 border-[rgba(9,107,250,0.2)] border-t-primary motion-reduce:animate-none" />
92
112
  )}
93
113
  {item.status === 'done' && (
94
- <Check className="tool-calls__icon tool-calls__icon--success" size={14} strokeWidth={2.5} />
114
+ <Check className="tool-calls__icon tool-calls__icon--success shrink-0 self-center text-muted-foreground" size={14} strokeWidth={2.5} />
95
115
  )}
96
116
  {item.status === 'error' && (
97
- <X className="tool-calls__icon tool-calls__icon--error" size={14} strokeWidth={2.5} />
117
+ <X className="tool-calls__icon tool-calls__icon--error shrink-0 self-center text-muted-foreground" size={14} strokeWidth={2.5} />
98
118
  )}
99
- <span className="tool-calls__item-name">
119
+ <span className={`tool-calls__item-name min-w-0 truncate text-xs font-normal leading-[1.4] ${ITEM_NAME_COLOR_CLASS[item.status]}`}>
100
120
  {item.label}
101
121
  {debug && item.techName && (
102
- <span className="tool-calls__item-tech"> · {item.techName}</span>
122
+ <span className="tool-calls__item-tech break-all text-xs leading-[1.4] text-muted-foreground [font-family:inherit]"> · {item.techName}</span>
103
123
  )}
104
124
  </span>
105
125
  {item.badge && (
106
- <span className="tool-calls__badge">· {item.badge}</span>
126
+ <span className="tool-calls__badge shrink-0 text-xs leading-[1.4] text-muted-foreground [font-family:inherit]">· {item.badge}</span>
107
127
  )}
108
128
  </span>
109
129
  {hasDetail && (
110
130
  <CaretDown
111
131
  size={12}
112
- className={`tool-calls__item-chevron${detailExpanded ? ' tool-calls__item-chevron--up' : ''}`}
132
+ className={`tool-calls__item-chevron ml-2 shrink-0 text-muted-foreground transition-transform duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] motion-reduce:transition-none ${detailExpanded ? 'tool-calls__item-chevron--up rotate-180' : ''}`}
113
133
  />
114
134
  )}
115
135
  </>
116
136
  );
117
137
 
118
138
  return (
119
- <div key={item.id} className={`tool-calls__item tool-calls__item--${item.status}`}>
139
+ <div key={item.id} className={`tool-calls__item flex min-w-0 flex-col ${ITEM_CLASS[item.status]}`}>
120
140
  {hasDetail ? (
121
141
  <button
122
142
  type="button"
123
- className="tool-calls__item-trigger"
143
+ className="tool-calls__item-trigger flex min-h-11 w-full cursor-pointer appearance-none items-center justify-between rounded-[8px] border-0 bg-transparent px-0.5 py-[5px] text-left text-secondary-foreground transition-[color,background] duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] [font-family:inherit] active:bg-[rgba(11,15,23,0.035)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none"
124
144
  aria-expanded={detailExpanded}
125
145
  aria-controls={detailId}
126
146
  aria-label={`${item.label},${STATUS_TEXT[item.status]},${detailExpanded ? '收起详情' : '查看详情'}`}
@@ -130,7 +150,7 @@ export default function ToolCallBlock({
130
150
  </button>
131
151
  ) : (
132
152
  <div
133
- className="tool-calls__item-trigger tool-calls__item-trigger--static"
153
+ className="tool-calls__item-trigger tool-calls__item-trigger--static flex min-h-11 w-full cursor-default appearance-none items-center justify-between rounded-[8px] border-0 bg-transparent px-0.5 py-[5px] text-left text-secondary-foreground transition-[color,background] duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] [font-family:inherit] motion-reduce:transition-none"
134
154
  role="status"
135
155
  aria-label={`${item.label},${STATUS_TEXT[item.status]}`}
136
156
  >
@@ -170,13 +190,13 @@ function ToolCallInlineDetail({ id, item }: { id: string; item: ToolCallViewItem
170
190
  };
171
191
 
172
192
  return (
173
- <div id={id} className="tool-calls__detail">
174
- <div className="tool-calls__detail-section">
175
- <div className="tool-calls__detail-heading">
176
- <span className="tool-calls__detail-label">输入</span>
193
+ <div id={id} className="tool-calls__detail mt-[1px] mb-2 ml-5 flex flex-col gap-2.5 border-l-2 border-l-border pb-[5px] pl-[14px] pt-[5px]">
194
+ <div className="tool-calls__detail-section flex min-w-0 flex-col gap-[5px]">
195
+ <div className="tool-calls__detail-heading flex items-center justify-between gap-2">
196
+ <span className="tool-calls__detail-label text-xs leading-[1.4] text-muted-foreground">输入</span>
177
197
  <button
178
198
  type="button"
179
- className="tool-calls__copy"
199
+ className="tool-calls__copy inline-flex min-h-11 shrink-0 cursor-pointer appearance-none items-center gap-1 rounded-[6px] border-0 bg-transparent px-[5px] py-[3px] text-xs leading-[1.2] text-muted-foreground [font-family:inherit] active:text-secondary-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary disabled:cursor-default disabled:opacity-[0.55]"
180
200
  aria-label={`复制${item.label}的输入`}
181
201
  disabled={!formatted.inputPretty}
182
202
  onClick={() => void copyIo(formatted.inputPretty, '输入')}
@@ -185,14 +205,14 @@ function ToolCallInlineDetail({ id, item }: { id: string; item: ToolCallViewItem
185
205
  <span>复制</span>
186
206
  </button>
187
207
  </div>
188
- <pre className="tool-calls__detail-body">{formatted.input || EMPTY_TEXT}</pre>
208
+ <pre className={`${DETAIL_BODY_CLASS} text-secondary-foreground`}>{formatted.input || EMPTY_TEXT}</pre>
189
209
  </div>
190
- <div className="tool-calls__detail-section">
191
- <div className="tool-calls__detail-heading">
192
- <span className="tool-calls__detail-label">输出</span>
210
+ <div className="tool-calls__detail-section flex min-w-0 flex-col gap-[5px]">
211
+ <div className="tool-calls__detail-heading flex items-center justify-between gap-2">
212
+ <span className="tool-calls__detail-label text-xs leading-[1.4] text-muted-foreground">输出</span>
193
213
  <button
194
214
  type="button"
195
- className="tool-calls__copy"
215
+ className="tool-calls__copy inline-flex min-h-11 shrink-0 cursor-pointer appearance-none items-center gap-1 rounded-[6px] border-0 bg-transparent px-[5px] py-[3px] text-xs leading-[1.2] text-muted-foreground [font-family:inherit] active:text-secondary-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary disabled:cursor-default disabled:opacity-[0.55]"
196
216
  aria-label={`复制${item.label}的输出`}
197
217
  disabled={!formatted.outputPretty}
198
218
  onClick={() => void copyIo(formatted.outputPretty, '输出')}
@@ -201,9 +221,7 @@ function ToolCallInlineDetail({ id, item }: { id: string; item: ToolCallViewItem
201
221
  <span>复制</span>
202
222
  </button>
203
223
  </div>
204
- <pre
205
- className={`tool-calls__detail-body${item.detail?.isError ? ' tool-calls__detail-body--error' : ''}`}
206
- >
224
+ <pre className={`${DETAIL_BODY_CLASS} ${item.detail?.isError ? 'tool-calls__detail-body--error text-muted-foreground' : 'text-secondary-foreground'}`}>
207
225
  {formatted.output || EMPTY_TEXT}
208
226
  </pre>
209
227
  </div>
package/src/icons.ts ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * 图标入口:应用侧不再直接依赖 `@phosphor-icons/react`。
3
+ *
4
+ * 只再导出卡片与空态常用的一组,含义稳定、体积可控;需要新图标时在此增补,
5
+ * 应用侧 `import { IconName } from '@tbox.cn/app-agent-ui-kit/icons'`。
6
+ */
7
+ export {
8
+ ArrowRight,
9
+ ArrowsClockwise,
10
+ Calendar,
11
+ CaretDown,
12
+ CaretRight,
13
+ Check,
14
+ CheckCircle,
15
+ Clock,
16
+ Coins,
17
+ Copy,
18
+ CreditCard,
19
+ CurrencyCny,
20
+ Gift,
21
+ Info,
22
+ MapPin,
23
+ MapTrifold,
24
+ Plus,
25
+ QrCode,
26
+ Receipt,
27
+ SealCheck,
28
+ ShareNetwork,
29
+ Sparkle,
30
+ Star,
31
+ Storefront,
32
+ Ticket,
33
+ Trash,
34
+ User,
35
+ UserCircle,
36
+ Warning,
37
+ WarningCircle,
38
+ X,
39
+ } from '@phosphor-icons/react';
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 消费面:应用经 `<ChatPage store cards slots .../>` 单点装配(或自组 KitChatProvider 树);
5
5
  * 域模块(如 mall-core)经 home 槽渲染函数自持域 UI——kit 组件零域语义。
6
- * 主题:`@tbox.cn/app-agent-ui-kit/theme`(applyTheme)+ `theme/index.less`(配合纯 CSS 主题包级联)。
6
+ * 主题:`@tbox.cn/app-agent-ui-kit/theme`(applyTheme)+ `theme/tokens.css` + `theme/base.css`(配合纯 CSS 主题包级联)。
7
7
  */
8
8
 
9
9
  // ── 首屏页面与注入位 ──
@@ -29,9 +29,62 @@ export type { QuickCommand } from './chat-config';
29
29
  // ── 主题 ──
30
30
  export { applyTheme, currentTheme } from './theme/theme';
31
31
 
32
+ // ── 壳契约(区域、可覆写选择器、品牌名来源) ──
33
+ export { SHELL_CONTRACT, resolveBrandName } from './shell';
34
+ export type { ShellArea, ShellContract, ShellRegion } from './shell';
35
+
32
36
  // ── 卡片渲染(context 注册表注入) ──
33
37
  export { CardRenderer, RawCardRenderer } from './components/CardRenderer';
34
38
 
39
+ // ── 应用级卡片工厂与卡片内交互 ──
40
+ export { defineCard } from './card/define-card';
41
+ export type { CardRenderProps, DefinedCard } from './card/define-card';
42
+ export { useCardActions } from './card/use-card-actions';
43
+ export type { CardActions, UseCardActionsOptions } from './card/use-card-actions';
44
+
45
+ // ── 卡片基元(信息类卡片直接拼,零样式文件) ──
46
+ export {
47
+ ActionList,
48
+ ActionRow,
49
+ Bill,
50
+ Card,
51
+ CardButton,
52
+ CardHeader,
53
+ CheckRow,
54
+ ConfirmSheet,
55
+ EmptyState,
56
+ EntityRow,
57
+ Hero,
58
+ KeyValueList,
59
+ MediaRow,
60
+ Notice,
61
+ StatGrid,
62
+ StatusTag,
63
+ Steps,
64
+ TagList,
65
+ Ticket,
66
+ Timeline,
67
+ } from './card/primitives';
68
+ export type {
69
+ ActionRowProps,
70
+ BillLine,
71
+ CardActionSpec,
72
+ CardHeaderProps,
73
+ CardProps,
74
+ CheckRowProps,
75
+ ConfirmSheetProps,
76
+ EntityRowProps,
77
+ HeroProps,
78
+ KeyValueItem,
79
+ MediaRowProps,
80
+ NoticeProps,
81
+ StatItem,
82
+ StepItem,
83
+ TicketProps,
84
+ TimelineItem,
85
+ Tone,
86
+ } from './card/primitives';
87
+
35
88
  // ── 壳组件族 ──
36
89
  export { MessageBubble } from './components/MessageBubble';
37
90
  export { ChatInput } from './components/ChatInput';
@@ -0,0 +1,59 @@
1
+ {
2
+ "$comment": "对话壳契约数据(docs/agent/kit.md 与 shell.test.ts 的共同来源;改这里 = 改壳的对外承诺)。regions = ChatPage 渲染的区域;internal = 不承诺稳定的内部结构。",
3
+ "regions": [
4
+ {
5
+ "id": "brand",
6
+ "area": "brand",
7
+ "selector": ".chat-page__brand",
8
+ "drivenBy": ["chat.json identity.name", "chat.json identity.tagline", "HELLO_ACK mallScope.mallName(缺省回落)"],
9
+ "brandable": true
10
+ },
11
+ {
12
+ "id": "welcome",
13
+ "area": "welcome",
14
+ "selector": ".chat-page__welcome",
15
+ "drivenBy": ["chat.json welcome.title", "chat.json welcome.subtitle", "chat.json identity(缺省回落)"],
16
+ "brandable": true
17
+ },
18
+ {
19
+ "id": "messages",
20
+ "area": "messages",
21
+ "selector": ".chat-page__body",
22
+ "drivenBy": ["chat store messages / historyMessages"],
23
+ "brandable": false
24
+ },
25
+ {
26
+ "id": "history-entry",
27
+ "area": "history",
28
+ "selector": ".history-entry",
29
+ "drivenBy": ["chat store historyHasMore / isLoadingHistory"],
30
+ "brandable": false
31
+ },
32
+ {
33
+ "id": "home-slot",
34
+ "area": "home",
35
+ "selector": ".chat-page__home-slot",
36
+ "drivenBy": ["客户端槽 home"],
37
+ "brandable": false
38
+ },
39
+ {
40
+ "id": "quick-commands",
41
+ "area": "quick-commands",
42
+ "selector": ".quick-commands",
43
+ "drivenBy": ["chat.json quickCommands"],
44
+ "brandable": true
45
+ },
46
+ {
47
+ "id": "input",
48
+ "area": "input",
49
+ "selector": ".tbox-chat-input",
50
+ "drivenBy": ["chat.json(enableTTS 等)", "chat store runtimeStatus / isGenerating"],
51
+ "brandable": false
52
+ }
53
+ ],
54
+ "internal": [
55
+ "MessageBubble 内部结构(.msg-row / .msg-main / .msg-thinking)",
56
+ "ChatInput 内部结构(.tbox-media-picker、发送按钮)",
57
+ "卡片渲染器内部结构(.tbox-card-*)"
58
+ ]
59
+ }
@@ -0,0 +1,61 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { describe, expect, it } from 'vitest';
5
+ import { SHELL_CONTRACT, resolveBrandName } from './shell';
6
+
7
+ const here = path.dirname(fileURLToPath(import.meta.url));
8
+ const read = (rel: string) => readFileSync(path.join(here, rel), 'utf8');
9
+
10
+ /** 契约声明的选择器必须真的出现在源码里——「文档说有、代码没接」在这里失败。 */
11
+ const SELECTOR_SOURCES: Record<string, string[]> = {
12
+ '.chat-page__brand': ['ChatPage.tsx'],
13
+ '.chat-page__welcome': ['ChatPage.tsx'],
14
+ '.chat-page__body': ['ChatPage.tsx'],
15
+ '.history-entry': ['components/HistoryEntry/index.tsx'],
16
+ '.chat-page__home-slot': ['ChatPage.tsx'],
17
+ '.quick-commands': ['components/QuickCommands/index.tsx'],
18
+ '.tbox-chat-input': ['components/ChatInput/index.tsx'],
19
+ };
20
+
21
+ describe('壳契约', () => {
22
+ it('区域 id 唯一且每个选择器都有源码出处', () => {
23
+ const ids = SHELL_CONTRACT.regions.map((region) => region.id);
24
+ expect(new Set(ids).size).toBe(ids.length);
25
+ for (const region of SHELL_CONTRACT.regions) {
26
+ const sources = SELECTOR_SOURCES[region.selector];
27
+ expect(sources, `壳契约新增选择器 ${region.selector} 时同步补源码映射`).toBeDefined();
28
+ const className = region.selector.replace(/^\./, '');
29
+ const found = sources.some((file) => read(file).includes(className));
30
+ expect(found, `${region.id}: ${region.selector} 在源码里不存在`).toBe(true);
31
+ }
32
+ });
33
+
34
+ it('可覆写区域只限壳层类名,内部结构排除在外', () => {
35
+ for (const region of SHELL_CONTRACT.regions.filter((item) => item.brandable)) {
36
+ expect(region.selector.startsWith('.chat-page__') || region.selector === '.quick-commands').toBe(true);
37
+ }
38
+ expect(SHELL_CONTRACT.internal.length).toBeGreaterThan(0);
39
+ });
40
+
41
+ it('每个区域都写明驱动来源', () => {
42
+ for (const region of SHELL_CONTRACT.regions) {
43
+ expect(region.drivenBy.length, `${region.id} 缺 drivenBy`).toBeGreaterThan(0);
44
+ }
45
+ });
46
+ });
47
+
48
+ describe('品牌名三级来源', () => {
49
+ it('identity.name 优先', () => {
50
+ expect(resolveBrandName({ name: '悦享里', tagline: '商圈助手' }, '某商场')).toBe('悦享里');
51
+ });
52
+
53
+ it('缺 identity 时回落 HELLO_ACK 的 mallName', () => {
54
+ expect(resolveBrandName(undefined, '某商场')).toBe('某商场');
55
+ });
56
+
57
+ it('都没有则不渲染', () => {
58
+ expect(resolveBrandName(undefined, undefined)).toBeUndefined();
59
+ expect(resolveBrandName({ name: '' }, undefined)).toBeUndefined();
60
+ });
61
+ });
package/src/shell.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 对话壳契约:哪些区域由什么驱动、哪些选择器可以覆写。
3
+ *
4
+ * 数据在 `shell.contract.json`(`docs/agent/kit.md` 与 `shell.test.ts` 的共同来源);
5
+ * 本文件只做类型收口与品牌名解析。
6
+ *
7
+ * - `docs/agent/shell.md` 的「能改什么」表由契约数据生成,杜绝「文档说有、代码没接」;
8
+ * - `shell.test.ts` 断言每条声明在源码里真的成立,声明与实现漂移即失败。
9
+ *
10
+ * 只描述壳层(ChatPage 渲染的区域)。kit 内部组件(MessageBubble、ChatInput 的内部结构)
11
+ * 不承诺稳定;改样式请用契约里 `brandable: true` 的选择器。
12
+ */
13
+ import type { ChatIdentity } from './chat-config';
14
+ import contract from './shell.contract.json';
15
+
16
+ export type ShellArea = 'brand' | 'welcome' | 'messages' | 'history' | 'home' | 'quick-commands' | 'input';
17
+
18
+ export interface ShellRegion {
19
+ /** 稳定 id(文档与测试引用) */
20
+ id: string;
21
+ /** 作用区域 */
22
+ area: ShellArea;
23
+ /** 根类名(应用可据此覆写) */
24
+ selector: string;
25
+ /** 由什么驱动:配置键、槽或 store 字段 */
26
+ drivenBy: string[];
27
+ /** 可覆写(`brand.css` 里改它算受支持用法) */
28
+ brandable: boolean;
29
+ }
30
+
31
+ export interface ShellContract {
32
+ regions: ShellRegion[];
33
+ /** 不承诺稳定、不要覆写的内部结构 */
34
+ internal: string[];
35
+ }
36
+
37
+ export const SHELL_CONTRACT: ShellContract = contract as ShellContract;
38
+
39
+ /**
40
+ * 品牌名三级来源:`chat.json identity.name` → `HELLO_ACK mallScope.mallName` → 无(不渲染品牌条)。
41
+ * 智能体身份是配置项,不是代码:应用只改 `config/chat.json`。
42
+ */
43
+ export function resolveBrandName(identity: ChatIdentity | undefined, mallName: string | undefined): string | undefined {
44
+ return identity?.name || mallName || undefined;
45
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * 基座重置(进 `@layer base`):盒模型、文档级字体、卡框与重置规则都在这一层,
3
+ * 组件上的工具类可以覆写它们;层外的跨组件规则见文件末尾(有意留层外)。
4
+ * token 来自 tokens.css / motion.css。
5
+ */
6
+ @import './tokens.css';
7
+ @import './motion.css';
8
+
9
+ @layer base {
10
+ * {
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ html,
15
+ body,
16
+ #root {
17
+ margin: 0;
18
+ padding: 0;
19
+ height: 100%;
20
+ }
21
+
22
+ body {
23
+ /* mall-vis 字栈:demo 拉丁栈 + 显式 CJK(demo 依赖容器隐式 CJK,模板面向开放浏览器) */
24
+ font-family:
25
+ -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC',
26
+ 'Microsoft YaHei', sans-serif;
27
+ font-size: var(--tbox-fs-body);
28
+ color: var(--tbox-text-primary);
29
+ background: var(--tbox-bg-page);
30
+ -webkit-font-smoothing: antialiased;
31
+ }
32
+
33
+ /* 顶层容器全宽(渐变底铺满),内容区由各处 max-width:800px 居中(对齐原模板 #app)。 */
34
+ #root {
35
+ width: 100%;
36
+ position: relative;
37
+ }
38
+
39
+ /* 去掉移动端点击高亮 */
40
+ * {
41
+ -webkit-tap-highlight-color: transparent;
42
+ }
43
+
44
+ /* 卡片统一外层 = 卡片「卡框」。所有卡片共有的框在这里,单卡组件别重复写:
45
+ - 间距:卡片与上下元素(工具调用 / 气泡)的间距,与 .tool-calls 一致;
46
+ - 外观:默认背景(白) / 1px 边框 / 圆角 / 阴影;`overflow:hidden` 把内容裁进圆角;
47
+ - 入场动效:mount 即播(0.36s 上浮淡入,对齐 mall-vis 消息卡节奏)。
48
+ 值为物理 px(大写 PX,不再经 pxtorem 折半):圆角 var(--tbox-radius-lg)=24、边框 1、阴影 var(--tbox-shadow-sm)=0 4 13。
49
+ ⚠️ **内边距不在卡框里**——由卡片自己写。卡框给 padding 会让「自带背景色的卡」在外面露一圈白边(卡里套卡)。
50
+ 宽度也不在卡框里:默认占满整列(≈移动端 350~400px 设计宽),紧凑卡自己写 max-width。
51
+ 单卡组件(.tbox-<type>)只画内容;**要整卡换底色 / 出血图,直接在自己 root 上 `background:<色>` 或铺满图**——
52
+ 会铺满卡框、裁进圆角、不出白边(别再自己设圆角,卡框已裁)。不写背景则露卡框默认白底,不透明。 */
53
+ .tbox-card {
54
+ margin-bottom: 6PX;
55
+ background: var(--tbox-bg-card);
56
+ border: 1PX solid var(--tbox-border);
57
+ border-radius: var(--tbox-radius-lg);
58
+ box-shadow: var(--tbox-shadow-sm);
59
+ overflow: hidden;
60
+ animation: tbox-card-enter var(--tbox-motion-duration-slow) ease;
61
+ }
62
+
63
+ @keyframes tbox-card-enter {
64
+ from {
65
+ opacity: 0;
66
+ transform: translateY(8PX);
67
+ }
68
+
69
+ to {
70
+ opacity: 1;
71
+ transform: translateY(0);
72
+ }
73
+ }
74
+
75
+ @media (prefers-reduced-motion: reduce) {
76
+ .tbox-card {
77
+ animation: none;
78
+ }
79
+ }
80
+
81
+ /* 多卡纵向容器(SDK CardCarousel 多卡分支):容器内卡片关闭逐卡入场动画——
82
+ 同屏多卡逐张挂载时 0.36s 上浮淡入会交叠抖动;单卡直出与其他场景的入场动画保留
83
+ (命中卡片本体 .tbox-card:卡框动画在自身规则上,item 中间层无动画规则) */
84
+ .tbox-card-stack .tbox-card {
85
+ animation: none;
86
+ }
87
+
88
+ /* 兜底态(未知 cardType / 渲染出错,由 CardRenderer 给外层加此修饰类):
89
+ 复用卡框,弱化成无阴影的虚线提示框(内边距自带,因为卡框不再给 padding) */
90
+ .tbox-card--fallback {
91
+ max-width: 80%;
92
+ padding: 16PX 12PX;
93
+ background: var(--tbox-bg-subtle);
94
+ border: 0.5PX dashed var(--tbox-border);
95
+ box-shadow: none;
96
+ color: var(--tbox-text-muted);
97
+ font-size: var(--tbox-fs-caption);
98
+ }
99
+
100
+ /* ===== antd-mobile 全局弹层层级(2026-09-04):业务半屏浮层(门店详情/门店导览)z-index 1100,
101
+ * Toast/Dialog/Popup 等瞬态反馈弹层默认 1000 会被盖住(门店券行领取的弹出提醒不可见实证)——
102
+ * 统一提至 1200 置于一切业务浮层之上(antd-mobile 官方 :root:root 双写覆盖约定)===== */
103
+ :root:root {
104
+ --adm-z-index-mask: 1200;
105
+ }
106
+
107
+ /* 基元/模块迁移后不再各自写 margin reset:标题、段落、列表统一归零(在 base 层,工具类可覆写)。 */
108
+ h1, h2, h3, h4, h5, h6, p, dl, dd, dt, ul, ol {
109
+ margin: 0;
110
+ }
111
+ }
112
+
113
+ /* ── 层外:壳的跨组件覆写(必须压过工具类,故不进 @layer) ── */
114
+ /* 录音期间锁页面(由 useVoicePress 在 document.body 上 toggle,不是 TSX 元素):
115
+ 禁选中/拖拽/长按菜单,必须压过浏览器默认与页面内联样式。 */
116
+ .tbox-voice-page-lock,
117
+ .tbox-voice-page-lock * {
118
+ -webkit-user-select: none !important;
119
+ user-select: none !important;
120
+ -webkit-touch-callout: none !important;
121
+ -webkit-user-drag: none !important;
122
+ }
123
+
124
+ /* 顶部历史入口在场时欢迎区不再叠加自身顶部留白(壳的跨组件规则)。 */
125
+ .history-entry ~ .mall-home {
126
+ padding-top: 0;
127
+ }
128
+
129
+ /* 顶部历史入口在场时商圈主屏不再叠加自身顶部留白(ChatPage 槽位包裹层)。 */
130
+ .history-entry ~ .chat-page__home-slot .mall-home {
131
+ padding-top: 0;
132
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$comment": "主题可覆写变量封闭清单(主题轨 W-T2;doctor theme-package-structure 消费——超集即 error;theme-contract.test.ts 锁 tokens.less+motion.less 的平台键 ⊆ platform 段)。domains 段 = 域色两段式通道(identity/surface/border 三角色,v1 封闭;promotion 按域色矩阵无描边列)。assets 段 = 素材变量链语义位(W-T3 铺开,铺开后逐一核对)。",
2
+ "$comment": "主题可覆写变量封闭清单(主题轨 W-T2;doctor theme-package-structure 消费——超集即 error;theme-contract.test.ts 锁 tokens.css+motion.css 的平台键 ⊆ platform 段)。domains 段 = 域色两段式通道(identity/surface/border 三角色,v1 封闭;promotion 按域色矩阵无描边列)。assets 段 = 素材变量链语义位(W-T3 铺开,铺开后逐一核对)。",
3
3
  "platform": [
4
4
  "--tbox-accent",
5
5
  "--tbox-accent-light",
@@ -2,7 +2,7 @@
2
2
  * 主题契约锁(主题轨 W-T2):contract.json 单一真源 ↔ kit css 机械一致。
3
3
  *
4
4
  * 断言:
5
- * ① tokens.less + motion.less 的 :root 变量集 ⊆ contract.platform(css 演进不漂移清单);
5
+ * ① tokens.css + motion.css 的 :root 变量集 ⊆ contract.platform(css 演进不漂移清单);
6
6
  * ② contract 三段非空且全局唯一(无重复键);
7
7
  * ③ domains/assets 段命名空间前缀正确(--tbox-domain-* / --tbox-asset-*)。
8
8
  *
@@ -37,8 +37,8 @@ function extractRootVars(file: string): string[] {
37
37
  }
38
38
 
39
39
  describe('主题契约(contract.json)', () => {
40
- it('tokens.less + motion.less 的 :root 变量 ⊆ contract.platform', () => {
41
- const cssVars = [...extractRootVars('tokens.less'), ...extractRootVars('motion.less')];
40
+ it('tokens.css + motion.css 的 :root 变量 ⊆ contract.platform', () => {
41
+ const cssVars = [...extractRootVars('tokens.css'), ...extractRootVars('motion.css')];
42
42
  expect(cssVars.length).toBeGreaterThan(40);
43
43
  const allowed = new Set(contract.platform);
44
44
  const drift = cssVars.filter((v) => !allowed.has(v));