@tbox.cn/app-agent-ui-kit 1.0.0-alpha.7 → 1.0.0-alpha.9

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 (35) hide show
  1. package/README.md +21 -1
  2. package/package.json +11 -3
  3. package/src/ChatPage.tsx +70 -17
  4. package/src/card/action-list-pending.test.tsx +91 -0
  5. package/src/card/define-card.test.ts +25 -0
  6. package/src/card/define-card.ts +18 -5
  7. package/src/card/primitives.test.tsx +10 -0
  8. package/src/card/primitives.tsx +136 -37
  9. package/src/card/view-card-inline.test.tsx +42 -0
  10. package/src/card/view-card.test.tsx +79 -0
  11. package/src/card/view-card.tsx +250 -0
  12. package/src/chat-config.ts +11 -7
  13. package/src/components/ActionBar/DebugButton.test.tsx +3 -0
  14. package/src/components/ActionBar/DebugButton.tsx +2 -7
  15. package/src/components/BottomSheet/index.test.tsx +90 -0
  16. package/src/components/BottomSheet/index.tsx +129 -0
  17. package/src/components/ChatInput/index.test.tsx +2 -2
  18. package/src/components/ChatInput/index.tsx +22 -17
  19. package/src/components/HistoryEntry/index.tsx +3 -2
  20. package/src/components/MessageBubble/index.tsx +11 -5
  21. package/src/components/QuickCommands/index.test.tsx +3 -1
  22. package/src/components/QuickCommands/index.tsx +31 -8
  23. package/src/components/ScrollToBottomButton/index.tsx +7 -3
  24. package/src/components/ToolCallBlock/index.tsx +4 -2
  25. package/src/index.ts +8 -0
  26. package/src/preview-provider.tsx +47 -0
  27. package/src/shell.contract.json +9 -0
  28. package/src/shell.test.ts +10 -0
  29. package/src/shell.ts +15 -0
  30. package/src/surface.test.tsx +35 -0
  31. package/src/surface.tsx +44 -0
  32. package/src/theme/base.css +9 -11
  33. package/src/theme/contract.json +123 -2
  34. package/src/theme/theme-contract.test.ts +16 -0
  35. package/src/theme/tokens.css +9 -12
package/README.md CHANGED
@@ -6,12 +6,32 @@ Agent 对话壳 UI 组件包(源码发布)——单一模板统一化 W2-1
6
6
  (name 改写 `@tbox.cn/app-agent-ui-kit` → `@tbox.cn/app-agent-ui-kit`),guard identity 锁定一致。
7
7
  - **消费面**:应用 `<ChatPage store={useChatStore} cards={CHAT_REGISTRY} slots={clientCtx.slots}/>`
8
8
  单点装配;域 UI(如商圈主屏)经 home 槽渲染函数自带。
9
- - **主题**:kit 默认 tokens(`src/theme/tokens.less`);品牌资产包经 `html[data-theme]` 级联覆写 +
9
+ - **主题**:kit 默认 tokens(`src/theme/tokens.css`);品牌资产包经 `html[data-theme]` 级联覆写 +
10
10
  接线三行(`import '<pkg>/index.css'` + `import '<pkg>/brand.js'`[可选] + `applyTheme(id)`;见 docs/reference/templates.md)。
11
11
 
12
+ ## 半屏弹层
13
+
14
+ `BottomSheet` 为统一的受控底部弹层,基于已有 `antd-mobile Popup`,使用 React + Tailwind 工具类 与平台主题变量;不依赖 shadcn/ui。外壳负责 portal、遮罩、滚动锁、安全区、标题、关闭按钮、Escape 和焦点循环/恢复,业务负责请求、加载、错误与内容。
15
+
16
+ ```tsx
17
+ import { BottomSheet } from '@tbox.cn/app-agent-ui-kit/bottom-sheet';
18
+
19
+ <BottomSheet open={open} title="详情" onClose={() => setOpen(false)}>
20
+ <DetailContent />
21
+ </BottomSheet>
22
+ ```
23
+
24
+ 支持 `className` 定制内容区,默认最大高度为视口的 65%,长内容在弹层内部滚动。
25
+
26
+ 模板副本沿用同名 `@tbox.cn/app-agent-ui-kit/bottom-sheet`(`sync-agent-ui-kit` 投影,仅依赖面转 catalog:);仓内模块使用公开名并声明 optional peer,由宿主提供源码包,不从 npm 拉取。
27
+
28
+ **SSR / Node 边界**:`BottomSheet` 对 `antd-mobile` 的 `Popup` 采用浏览器按需加载(`import()`),`bottom-sheet` 子路径在 Vite/Node SSR 里可直接 import,不再触发 antd-mobile CJS 入口的 `global.css` 解析错误。需要首开无等待时,宿主可调用 `preloadBottomSheet()`(根入口或 `bottom-sheet` 子路径)预热;加载失败会在下一次 open 重试。kit **根入口**仍依赖 SVG/PNG/CSS 资产,只承诺 bundler(Vite 等)消费,不承诺 raw-Node 直跑。
29
+
12
30
  ## 验证
13
31
 
14
32
  ```sh
15
33
  pnpm --filter @tbox.cn/app-agent-ui-kit typecheck
16
34
  pnpm --filter @tbox.cn/app-agent-ui-kit test
17
35
  ```
36
+
37
+ 轻提示可从 `@tbox.cn/app-agent-ui-kit/toast` 独立导入 `toast`,避免引入完整聊天壳。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-agent-ui-kit",
3
- "version": "1.0.0-alpha.7",
3
+ "version": "1.0.0-alpha.9",
4
4
  "type": "module",
5
5
  "description": "Agent 对话壳 UI 组件包(源码发布,单一模板统一化 W2-1):ChatPage/壳组件族/主题 tokens。",
6
6
  "exports": {
@@ -18,6 +18,14 @@
18
18
  "./icons": {
19
19
  "types": "./src/icons.ts",
20
20
  "import": "./src/icons.ts"
21
+ },
22
+ "./toast": {
23
+ "types": "./src/utils/toast.ts",
24
+ "import": "./src/utils/toast.ts"
25
+ },
26
+ "./bottom-sheet": {
27
+ "types": "./src/components/BottomSheet/index.tsx",
28
+ "import": "./src/components/BottomSheet/index.tsx"
21
29
  }
22
30
  },
23
31
  "files": [
@@ -32,8 +40,8 @@
32
40
  "react-markdown": "9.1.0",
33
41
  "remark-gfm": "4.0.1",
34
42
  "zustand": "4.5.7",
35
- "@tbox.cn/app-contracts": "1.0.0-alpha.7",
36
- "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.7"
43
+ "@tbox.cn/app-contracts": "1.0.0-alpha.9",
44
+ "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.9"
37
45
  },
38
46
  "peerDependencies": {
39
47
  "react": "18.3.1",
package/src/ChatPage.tsx CHANGED
@@ -7,6 +7,9 @@
7
7
  * - 域自持段(首屏数据/门禁/详情弹层/活动预热)经槽渲染函数自带——本页零域语义。
8
8
  */
9
9
  import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
10
+
11
+ // SSR(预览/探针)没有 DOM 可量:useLayoutEffect 会打印不可消除的告警,服务端退化为 useEffect。
12
+ const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
10
13
  import { consumeAutoSendQuery, runAutoSend } from '@tbox.cn/app-agent-sdk-client';
11
14
  import { usePullDownHistory } from './hooks/use-pull-down-history';
12
15
  import type { TboxCardPayload } from '@tbox.cn/app-contracts';
@@ -89,6 +92,23 @@ function ChatPageInner() {
89
92
  const homeSlot = slots?.resolve('home');
90
93
  const identity = useChatConfigStore((s) => s.identity);
91
94
  const welcome = useChatConfigStore((s) => s.welcome);
95
+
96
+ // 页面元信息跟身份与主题走:标题、主题色不再停在模板出厂值(B9)。
97
+ useEffect(() => {
98
+ if (typeof document === 'undefined') return;
99
+ const name = identity?.name;
100
+ if (name) document.title = name;
101
+ const bg = getComputedStyle(document.documentElement).getPropertyValue('--tbox-bg-page').trim();
102
+ if (bg) {
103
+ let meta = document.querySelector('meta[name="theme-color"]');
104
+ if (!meta) {
105
+ meta = document.createElement('meta');
106
+ meta.setAttribute('name', 'theme-color');
107
+ document.head.appendChild(meta);
108
+ }
109
+ meta.setAttribute('content', bg);
110
+ }
111
+ }, [identity?.name]);
92
112
  // 常驻品牌条:chat.json identity.name → HELLO_ACK 的 mallName → 不渲染(壳契约见 shell.ts)
93
113
  const brandName = resolveBrandName(identity, mallName);
94
114
 
@@ -167,7 +187,7 @@ function ChatPageInner() {
167
187
 
168
188
  // 历史插入发生在当前内容上方:绘制前只补一次新增高度,保持用户原本看到的位置。
169
189
  // 不设置定时器、不钉住 scrollTop;补偿后下一次滚动立即由用户接管。
170
- useLayoutEffect(() => {
190
+ useIsomorphicLayoutEffect(() => {
171
191
  const pending = pendingHistoryViewportRef.current;
172
192
  const anchor = historyAnchorRef.current;
173
193
  if (!pending || !anchor) return;
@@ -206,7 +226,9 @@ function ChatPageInner() {
206
226
  && messages.length === 0
207
227
  && inlineOrphanCards.length === 0;
208
228
  const welcomeTitle = welcome?.title ?? identity?.name ?? '开始对话';
209
- const welcomeSubtitle = welcome?.subtitle ?? identity?.tagline;
229
+ const welcomeSubtitle = welcome?.subtitle ?? identity?.tagline ?? '可以直接提问,也可以从下面的问题开始';
230
+ // 空会话(有 home 槽或无 home 槽)走同一套构图:欢迎区 + 快捷问题成组居中。
231
+ const isEmptyState = showHome || showWelcome;
210
232
 
211
233
  const pull = usePullDownHistory({
212
234
  isAtTopRef,
@@ -240,19 +262,42 @@ function ChatPageInner() {
240
262
  return () => ro.disconnect();
241
263
  }, []);
242
264
 
243
- // 仅在已有对话内容且贴近底部时自动滚动,避免打断用户上翻查看历史。
244
- // 依赖含 cardsByMessageId:主卡在文字完成后挂载、消息行增高,需补滚避免卡片截出视口
265
+ // 回合锚定:新回合把本轮用户消息置顶,流式期间不追底。
266
+ // 贴底滚动会把问题顶出视口(实测卡片 648px 时问题上移 244px),用户看不到自己在问什么。
267
+ const turnAnchorRef = useRef<string | null>(null);
245
268
  useEffect(() => {
246
- const hasLiveContent = messages.length > 0 || orphanCards.length > 0;
247
- if (hasLiveContent && isNearBottomRef.current) {
248
- const el = bodyRef.current;
249
- if (el) el.scrollTop = el.scrollHeight;
250
- }
251
- }, [messages, orphanCards, liveCardSignature]);
269
+ const lastUser = [...messages].reverse().find((message) => message.role === 'user');
270
+ if (!lastUser || turnAnchorRef.current === lastUser.id) return;
271
+ turnAnchorRef.current = lastUser.id;
272
+ const body = bodyRef.current;
273
+ const element = body?.querySelector(`[data-message-id="${lastUser.id}"]`);
274
+ if (!body || !element) return;
275
+ const delta = element.getBoundingClientRect().top - body.getBoundingClientRect().top;
276
+ body.scrollTop += delta - 8;
277
+ isNearBottomRef.current = false;
278
+ // 回合锚定后内容通常超出视口:必须让「回到底部」入口出现,否则用户只能靠手势找底。
279
+ if (body.scrollHeight > body.clientHeight + 8) setShowScrollToBottom(true);
280
+ }, [messages]);
281
+
282
+ // 已脱离底部时内容继续变高(流式回复、卡片后挂载):保持浮标可见,不追底。
283
+ useEffect(() => {
284
+ if (isNearBottomRef.current) return;
285
+ const el = bodyRef.current;
286
+ if (el && el.scrollHeight > el.clientHeight + 8) setShowScrollToBottom(true);
287
+ }, [messages, liveCardSignature, orphanCards]);
288
+
289
+ // 没有新回合、但卡片在文字之后挂载时,内容会继续变高:只在用户本来就在底部时补滚,
290
+ // 且不改变「本轮问题已在视口内」的锚点。
291
+ useEffect(() => {
292
+ if (!isNearBottomRef.current) return;
293
+ const el = bodyRef.current;
294
+ if (el && messages.length === 0 && orphanCards.length > 0) el.scrollTop = el.scrollHeight;
295
+ }, [orphanCards, liveCardSignature, messages.length]);
252
296
 
253
297
  return (
254
298
  <div className={`chat-page relative flex h-full w-full min-h-0 flex-col overflow-hidden bg-background ${showHome ? '' : ' chat-page--conversation'}`}>
255
- <div className="chat-page__bg pointer-events-none absolute inset-0 z-0 bg-background" />
299
+ {/* 整页背景独立于滚动内容,覆盖历史入口、首页与底部输入区;图片按视口居中铺满、不重复。 */}
300
+ <div className="chat-page__bg pointer-events-none absolute inset-0 z-0 bg-background bg-center bg-cover bg-no-repeat" />
256
301
 
257
302
  {brandName ? (
258
303
  <div className="chat-page__brand relative z-10 flex items-baseline justify-center gap-3 border-b border-border bg-background px-page pb-3 pt-[calc(16px+env(safe-area-inset-top))]" aria-label={brandName}>
@@ -263,7 +308,7 @@ function ChatPageInner() {
263
308
 
264
309
  <div className="chat-page__body-wrapper relative z-10 flex min-h-0 flex-1 flex-col">
265
310
  <div
266
- className="chat-page__body mx-auto w-full max-w-content flex-1 min-h-0 overflow-y-auto overflow-x-hidden overscroll-contain pb-6 pt-[calc(12px+env(safe-area-inset-top))] [overflow-anchor:none] [scrollbar-width:none] [-webkit-overflow-scrolling:touch] [&::-webkit-scrollbar]:hidden"
311
+ className={`chat-page__body mx-auto w-full max-w-content flex-1 min-h-0 overflow-y-auto overflow-x-hidden overscroll-contain pb-6 pt-[calc(12px+env(safe-area-inset-top))] [overflow-anchor:none] [scrollbar-width:none] [-webkit-overflow-scrolling:touch] [&::-webkit-scrollbar]:hidden ${isEmptyState ? 'flex flex-col justify-center' : ''}`}
267
312
  ref={bodyRef}
268
313
  onScroll={onScroll}
269
314
  onWheel={pull.handleWheel}
@@ -288,17 +333,25 @@ function ChatPageInner() {
288
333
 
289
334
  {/* 空会话欢迎区:没有 home 槽时的首屏落点(文案来自 chat.json welcome / identity) */}
290
335
  {showWelcome ? (
291
- <div className="chat-page__welcome flex flex-col items-center justify-center gap-2 px-page pb-5 pt-15 text-center">
336
+ <div className="chat-page__welcome flex flex-col items-center justify-center gap-2 px-page pb-4 pt-6 text-center">
292
337
  <h2 className="chat-page__welcome-title m-0 text-xl font-bold text-foreground">{welcomeTitle}</h2>
293
338
  {welcomeSubtitle ? <p className="chat-page__welcome-subtitle m-0 text-sm leading-normal text-muted-foreground">{welcomeSubtitle}</p> : null}
294
339
  </div>
295
340
  ) : null}
296
341
 
297
- {/* 历史前插视口锚 + home 槽渲染位(域自持显隐;缺席则不渲染) */}
298
- <div className="chat-page__home-slot" ref={historyAnchorRef}>
342
+ {/* 历史前插视口锚 + home 槽渲染位(域自持显隐;缺席则不渲染)。flow-root 让首页子元素
343
+ 的外边距留在槽内,不折叠到历史入口与首页之间。 */}
344
+ <div className="chat-page__home-slot flow-root" ref={historyAnchorRef}>
299
345
  {homeSlot?.({ onSend: send, ...(mallName ? { mallName } : {}) })}
300
346
  </div>
301
347
 
348
+ {/* 空会话的服务入口:快捷问题与欢迎区成组居中,两列全可见(不再贴底单行溢出)。 */}
349
+ {!blocked && isEmptyState ? (
350
+ <div className="chat-page__home-actions mt-6 flex w-full flex-col items-center">
351
+ <QuickCommands variant="grid" hidden={voiceActive} onCommand={send} />
352
+ </div>
353
+ ) : null}
354
+
302
355
  {/* 业务旁路 emit 的卡片(如欢迎卡) */}
303
356
  {inlineOrphanCards.map((card) => (
304
357
  <div key={card.id} className="chat-page__orphan-card mx-page">
@@ -315,9 +368,9 @@ function ChatPageInner() {
315
368
  <ScrollToBottomButton visible={showScrollToBottom} onClick={scrollToBottom} />
316
369
  </div>
317
370
 
318
- {/* 首页与对话态都保留快捷指令;语音活跃时只隐去胶囊并保留灰底占位,阻断时才卸载。 */}
371
+ {/* 对话态保留底部快捷指令;空会话的快捷问题在正文里成组展示(不重复渲染)。 */}
319
372
  <div ref={chatBottomRef}>
320
- {!blocked && <QuickCommands hidden={voiceActive} onCommand={send} />}
373
+ {!blocked && !isEmptyState && <QuickCommands hidden={voiceActive} onCommand={send} />}
321
374
  <ChatInput
322
375
  generating={isGenerating}
323
376
  blocked={blocked}
@@ -0,0 +1,91 @@
1
+ // @vitest-environment happy-dom
2
+ import { act } from 'react';
3
+ import { afterEach, describe, expect, it, vi } from 'vitest';
4
+ import { flushSync } from 'react-dom';
5
+ import { createRoot, type Root } from 'react-dom/client';
6
+ import { ActionList } from './primitives';
7
+ import type { CardActions } from './use-card-actions';
8
+
9
+ const roots: Root[] = [];
10
+
11
+ afterEach(() => {
12
+ for (const root of roots) root.unmount();
13
+ roots.length = 0;
14
+ document.body.innerHTML = '';
15
+ vi.useRealTimers();
16
+ });
17
+
18
+ function render(node: React.ReactElement): HTMLElement {
19
+ const el = document.createElement('div');
20
+ document.body.appendChild(el);
21
+ const root = createRoot(el);
22
+ roots.push(root);
23
+ flushSync(() => root.render(node));
24
+ return el;
25
+ }
26
+
27
+ function makeApi(calls: string[], generating = false): CardActions {
28
+ return {
29
+ send: (text: string) => calls.push('send:' + text),
30
+ invoke: (id: string) => calls.push('invoke:' + id),
31
+ disabled: generating,
32
+ isHistory: false,
33
+ isGenerating: generating,
34
+ };
35
+ }
36
+
37
+ const actions = [{ label: '领券', invoke: { id: 'claim' } }];
38
+
39
+ describe('ActionList pending(方案 A:不改协议)', () => {
40
+ it('点击后只执行一次、按钮禁用并带 aria-busy;20 秒后解除', () => {
41
+ vi.useFakeTimers();
42
+ const calls: string[] = [];
43
+ const el = render(<ActionList api={makeApi(calls)} actions={actions} />);
44
+ const button = el.querySelector('button')!;
45
+ flushSync(() => button.click());
46
+ expect(calls).toEqual(['invoke:claim']);
47
+ expect(button.disabled).toBe(true);
48
+ expect(button.getAttribute('aria-busy')).toBe('true');
49
+ flushSync(() => button.click());
50
+ expect(calls.length).toBe(1);
51
+ flushSync(() => {
52
+ vi.advanceTimersByTime(20000);
53
+ });
54
+ expect(el.querySelector('button')!.disabled).toBe(false);
55
+ });
56
+
57
+ it('同一 tick 连点两次只执行一次(ref 同步判重)', () => {
58
+ const calls: string[] = [];
59
+ const el = render(<ActionList api={makeApi(calls)} actions={actions} />);
60
+ const button = el.querySelector('button')!;
61
+ act(() => {
62
+ button.click();
63
+ button.click();
64
+ });
65
+ expect(calls).toEqual(['invoke:claim']);
66
+ });
67
+
68
+ it('生成一轮结束后第一次点击仍进入 pending', () => {
69
+ const calls: string[] = [];
70
+ const el = document.createElement('div');
71
+ document.body.appendChild(el);
72
+ const root = createRoot(el);
73
+ roots.push(root);
74
+ act(() => root.render(<ActionList api={makeApi(calls, false)} actions={actions} />));
75
+ act(() => root.render(<ActionList api={makeApi(calls, true)} actions={actions} />));
76
+ act(() => root.render(<ActionList api={makeApi(calls, false)} actions={actions} />));
77
+ const button = el.querySelector('button')!;
78
+ act(() => button.click());
79
+ expect(el.querySelector('button')!.getAttribute('aria-busy')).toBe('true');
80
+ });
81
+
82
+ it('没有 send / invoke 的动作不进入 pending', () => {
83
+ const calls: string[] = [];
84
+ const el = render(<ActionList api={makeApi(calls)} actions={[{ label: '占位' }]} />);
85
+ const button = el.querySelector('button')!;
86
+ act(() => button.click());
87
+ expect(calls).toEqual([]);
88
+ expect(button.disabled).toBe(false);
89
+ expect(button.getAttribute('aria-busy')).toBeNull();
90
+ });
91
+ });
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { defineCard } from './define-card';
3
+
4
+ describe('defineCard', () => {
5
+ const Component = () => null;
6
+
7
+ it('默认交回 SDK 默认按钮条(存量卡兼容)', () => {
8
+ const card = defineCard({ type: 'demo-card' }, Component);
9
+ expect(card.type).toBe('demo-card');
10
+ expect(card.selfRendersActions).toBe(false);
11
+ expect(card.actionsMode).toBe('default');
12
+ });
13
+
14
+ it("actions: 'self' 表示卡片自己渲染动作", () => {
15
+ const card = defineCard({ type: 'view-card', actions: 'self' }, Component);
16
+ expect(card.selfRendersActions).toBe(true);
17
+ expect(card.actionsMode).toBe('self');
18
+ });
19
+
20
+ it("actions: 'auto' 显式交回 SDK 默认条", () => {
21
+ const card = defineCard({ type: 'legacy-card', actions: 'auto' }, Component);
22
+ expect(card.selfRendersActions).toBe(false);
23
+ expect(card.actionsMode).toBe('auto');
24
+ });
25
+ });
@@ -5,6 +5,10 @@
5
5
  * - app-build 扫描器要求 `export const card = defineCard({ type: '…' }, …)` 的首参是对象字面量;
6
6
  * - 生成 registry 把导出值直接当 `CardComponent` 注册,所以运行期必须是组件且带 `.type`。
7
7
  * 手写 Object.assign 每张卡重复一遍形态,且容易漏掉 `.type`——本工厂是唯一写法。
8
+ *
9
+ * 动作所有权:默认 `auto`——SDK 用服务端下发的按钮条渲染动作,保持旧卡兼容;
10
+ * 卡片自己渲染动作(`ActionList` / `ViewCard`)时显式 `actions: 'self'`,SDK 不再叠加
11
+ *(确认弹层、入参、历史禁用都由卡内实现)。视图卡自动派生时由生成器写 `self`。
8
12
  */
9
13
  import type { ComponentType } from 'react';
10
14
  import type { CardComponent } from '@tbox.cn/app-contracts';
@@ -17,18 +21,27 @@ export interface CardRenderProps<T> {
17
21
  actionTokens?: Record<string, string>;
18
22
  }
19
23
 
20
- /** `defineCard` 的返回类型:既是可注册的卡片组件,也带静态 `type`。 */
21
- export type DefinedCard<T> = CardComponent<T> & { type: string };
24
+ /** `defineCard` 的返回类型:既是可注册的卡片组件,也带静态 `type` 与动作所有权标记。 */
25
+ export type DefinedCard<T> = CardComponent<T> & {
26
+ type: string;
27
+ selfRendersActions: boolean;
28
+ /** 动作所有权来源:default = 未显式声明(SDK 默认条),auto / self = 显式 */
29
+ actionsMode: 'default' | 'auto' | 'self';
30
+ };
22
31
 
23
32
  /**
24
33
  * 声明一张应用级卡片。
25
34
  *
26
- * @param meta 卡片类型声明;`type` 必须与同 base 的服务端 meta 的 `cardType` 一致
35
+ * @param meta 卡片类型声明;`type` 必须与同 base 的服务端 meta 的 `cardType` 一致。
36
+ * `actions` 缺省 `'auto'`(SDK 默认按钮条,兼容旧卡);自己渲染动作的卡写 `'self'`,
37
+ * 否则会出现两条按钮或动作被禁用。
27
38
  * @param Component 渲染组件,入参为 `CardRenderProps`
28
39
  */
29
40
  export function defineCard<T>(
30
- meta: { type: string },
41
+ meta: { type: string; actions?: 'self' | 'auto' },
31
42
  Component: ComponentType<CardRenderProps<T>>,
32
43
  ): DefinedCard<T> {
33
- return Object.assign(Component, { type: meta.type }) as unknown as DefinedCard<T>;
44
+ const selfRendersActions = meta.actions === 'self';
45
+ const actionsMode = meta.actions ?? 'default';
46
+ return Object.assign(Component, { type: meta.type, selfRendersActions, actionsMode }) as unknown as DefinedCard<T>;
34
47
  }
@@ -89,6 +89,16 @@ describe('第二版基元', () => {
89
89
  );
90
90
  expect(markup).toContain('tbox-hero');
91
91
  expect(markup).toContain('我的积分');
92
+ // 深底主视觉:底用 primary-dark、字用 primary-foreground,全部走令牌(无字面量色值)。
93
+ const inverse = html(<Hero eyebrow="ROUTE" title="导航" value={8} unit="分钟" tone="inverse" />);
94
+ expect(inverse).toContain('tbox-hero--inverse');
95
+ expect(inverse).toContain('bg-primary-dark');
96
+ expect(inverse).toContain('text-primary-foreground');
97
+ expect(inverse).not.toMatch(/#[0-9a-fA-F]{3,8}\b|rgba?\(/);
98
+ // 未知 tone(旧数据 / 新 kit 错配)回落 primary,不拼空类名。
99
+ const unknown = html(<Hero title="兜底" tone={'legacy' as never} />);
100
+ expect(unknown).toContain('tbox-hero--legacy');
101
+ expect(unknown).toContain('from-primary-foreground');
92
102
  expect(markup).toContain('tbox-stats__value');
93
103
  expect(markup).toContain('tbox-timeline__item--gain');
94
104
  expect(markup).toContain('+100');