@tbox.cn/app-template-agent 1.0.0-alpha.6 → 1.0.0-alpha.8

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 (92) hide show
  1. package/.tbox/app.json +1 -1
  2. package/.tbox/default-modules.json +1 -1
  3. package/.tbox/miniapp-containers.json +1 -1
  4. package/AGENTS.md +8 -7
  5. package/apps/client/index.html +0 -43
  6. package/apps/client/scripts/check-evidence.mjs +475 -82
  7. package/apps/client/scripts/evidence-gate.mjs +135 -0
  8. package/apps/client/scripts/evidence-gate.test.mjs +77 -0
  9. package/apps/client/scripts/render-card.mjs +20 -67
  10. package/apps/client/scripts/surface-css.mjs +51 -0
  11. package/apps/client/src/app.config.ts +4 -1
  12. package/apps/client/src/styles/brand.css +2 -3
  13. package/apps/client/src/styles/tailwind.css +17 -17
  14. package/apps/server/scripts/scenario-lib.mjs +28 -3
  15. package/apps/server/src/tools/AGENTS.md +12 -9
  16. package/docs/agent/agent-prompt.md +1 -1
  17. package/docs/agent/card-action.md +5 -0
  18. package/docs/agent/card.md +44 -2
  19. package/docs/agent/kit.md +2 -2
  20. package/docs/agent/style.md +8 -2
  21. package/docs/agent/tool-emits-card.md +8 -3
  22. package/docs/agent/tool.md +2 -0
  23. package/docs/agent/verify.md +42 -12
  24. package/package.json +16 -5
  25. package/packages/agent-ui-kit/AGENTS.md +1 -1
  26. package/packages/agent-ui-kit/catalog.json +7 -3
  27. package/packages/agent-ui-kit/package.json +1 -1
  28. package/packages/agent-ui-kit/src/ChatPage.tsx +40 -16
  29. package/packages/agent-ui-kit/src/card/action-list-pending.test.tsx +91 -0
  30. package/packages/agent-ui-kit/src/card/define-card.test.ts +25 -0
  31. package/packages/agent-ui-kit/src/card/define-card.ts +18 -5
  32. package/packages/agent-ui-kit/src/card/primitives.tsx +122 -27
  33. package/packages/agent-ui-kit/src/card/view-card-inline.test.tsx +42 -0
  34. package/packages/agent-ui-kit/src/card/view-card.test.tsx +79 -0
  35. package/packages/agent-ui-kit/src/card/view-card.tsx +245 -0
  36. package/packages/agent-ui-kit/src/components/ChatInput/index.tsx +1 -1
  37. package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +2 -2
  38. package/packages/agent-ui-kit/src/components/MessageBubble/index.tsx +11 -5
  39. package/packages/agent-ui-kit/src/components/QuickCommands/index.test.tsx +3 -1
  40. package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +31 -8
  41. package/packages/agent-ui-kit/src/index.ts +4 -0
  42. package/packages/agent-ui-kit/src/preview-provider.tsx +47 -0
  43. package/packages/agent-ui-kit/src/surface.test.tsx +35 -0
  44. package/packages/agent-ui-kit/src/surface.tsx +44 -0
  45. package/packages/agent-ui-kit/src/theme/base.css +9 -11
  46. package/packages/agent-ui-kit/src/theme/contract.json +45 -1
  47. package/packages/agent-ui-kit/src/theme/tokens.css +8 -11
  48. package/pnpm-lock.template.yaml +91 -91
  49. package/pnpm-workspace.template.yaml +10 -10
  50. package/scenarios/README.md +1 -1
  51. package/scripts/assert-pack.mjs +48 -0
  52. package/scripts/check-css-target.mjs +6 -3
  53. package/scripts/check-fast.mjs +5 -0
  54. package/scripts/checks.json +171 -26
  55. package/.tbox/card-render/baseline/demo.png +0 -0
  56. package/.tbox/card-render/demo.html +0 -342
  57. package/.tbox/card-render/demo.png +0 -0
  58. package/.tbox/card-render/scale-demo.audit.html +0 -984
  59. package/.tbox/card-render/scale-demo.html +0 -939
  60. package/.tbox/evidence/cards.txt +0 -1
  61. package/.tbox/evidence/gate.json +0 -1
  62. package/.tbox/evidence/last-gate.json +0 -1
  63. package/.tbox/evidence/scenarios.json +0 -1
  64. package/apps/client/.tbox-gen/._registry.client.ts +0 -0
  65. package/apps/client/.tbox-gen/._registry.server.ts +0 -0
  66. package/apps/client/.tbox-gen/documents/._index.html +0 -0
  67. package/apps/client/.tbox-gen/documents/_tbox/._card-preview.html +0 -0
  68. package/apps/client/.tbox-gen/documents/_tbox/card-preview.html +0 -62
  69. package/apps/client/.tbox-gen/documents/index.html +0 -63
  70. package/apps/client/.tbox-gen/entries/._card-preview.tsx +0 -0
  71. package/apps/client/.tbox-gen/entries/._index.tsx +0 -0
  72. package/apps/client/.tbox-gen/entries/card-preview.tsx +0 -6
  73. package/apps/client/.tbox-gen/entries/index.tsx +0 -11
  74. package/apps/client/.tbox-gen/manifest.json +0 -17
  75. package/apps/client/.tbox-gen/registry.client.ts +0 -6
  76. package/apps/client/.tbox-gen/registry.server.ts +0 -15
  77. package/apps/client/STYLE_GUIDE.md +0 -48
  78. package/apps/client/VISUAL_RESTORE.md +0 -90
  79. package/scripts/._compat-probe.mjs +0 -0
  80. package/scripts/compat-probe.mjs +0 -108
  81. /package/{.tbox/card-render/._demo.html → apps/client/scripts/._evidence-gate.mjs} +0 -0
  82. /package/{.tbox/card-render/._demo.png → apps/client/scripts/._evidence-gate.test.mjs} +0 -0
  83. /package/{.tbox/card-render/._scale-demo.audit.html → apps/client/scripts/._surface-css.mjs} +0 -0
  84. /package/{.tbox/card-render/._scale-demo.html → packages/agent-ui-kit/src/._preview-provider.tsx} +0 -0
  85. /package/{.tbox/card-render/baseline/._demo.png → packages/agent-ui-kit/src/._surface.test.tsx} +0 -0
  86. /package/{.tbox/evidence/._cards.txt → packages/agent-ui-kit/src/._surface.tsx} +0 -0
  87. /package/{.tbox/evidence/._gate.json → packages/agent-ui-kit/src/card/._action-list-pending.test.tsx} +0 -0
  88. /package/{.tbox/evidence/._last-gate.json → packages/agent-ui-kit/src/card/._define-card.test.ts} +0 -0
  89. /package/{.tbox/evidence/._scenarios.json → packages/agent-ui-kit/src/card/._view-card-inline.test.tsx} +0 -0
  90. /package/{apps/client/._STYLE_GUIDE.md → packages/agent-ui-kit/src/card/._view-card.test.tsx} +0 -0
  91. /package/{apps/client/._VISUAL_RESTORE.md → packages/agent-ui-kit/src/card/._view-card.tsx} +0 -0
  92. /package/{apps/client/.tbox-gen/._manifest.json → scripts/._assert-pack.mjs} +0 -0
@@ -1,8 +1,50 @@
1
1
  # 新增一张卡片
2
2
 
3
- > 本页管:卡片的三处落点(数据契约、服务端声明、客户端渲染)与成对规则。|不管:出卡协议 → [tool-emits-card](tool-emits-card.md);按钮 → [card-action](card-action.md)。
3
+ > 本页管:卡片的两种写法(视图卡默认 / 三件套仅富交互)、落点与成对规则。|不管:出卡协议 → [tool-emits-card](tool-emits-card.md);按钮 → [card-action](card-action.md)。
4
4
 
5
- ## 一张卡要有三样东西
5
+ ## 先选写法:默认视图卡
6
+
7
+ 卡片默认写**视图卡**:服务端一个文件,`view(data)` 返回可序列化的视图 JSON(积木 + 动作规格),客户端由 `app-build` 自动派生 `ViewCard`——没有 `apps/client/src/cards/<id>.card.tsx`,也不会报 `CARD_PAIR_MISSING`。
8
+
9
+ 只有需要局部自定义图形或富交互时,才写「数据契约 + 服务端声明 + 客户端渲染」三件套(L3,见本页末节)。
10
+
11
+ ### 视图卡(默认)
12
+
13
+ ```ts
14
+ import { defineViewCard } from '@tbox.cn/app-agent-sdk-server';
15
+
16
+ interface ParkingOrder {
17
+ plate: string;
18
+ payable: number;
19
+ }
20
+
21
+ export const card = defineViewCard<ParkingOrder>({
22
+ cardType: 'parking-order',
23
+ displayName: '停车订单',
24
+ description: '待支付停车订单与支付结果',
25
+ sampleState: { plate: '浙A·12345', payable: 5 },
26
+ view: (order) => ({
27
+ header: { title: '停车订单', status: { text: '待支付', tone: 'warning' } },
28
+ blocks: [
29
+ { kind: 'facts', items: [['车牌', order.plate]] },
30
+ { kind: 'bill', lines: [['停车费', '¥15']], total: ['应付', '¥' + order.payable] },
31
+ ],
32
+ actions: [{ label: '确认支付', invoke: { id: 'pay-parking', input: { plate: order.plate } }, confirm: { title: '确认支付?' } }],
33
+ }),
34
+ });
35
+ ```
36
+
37
+ - 积木:`hero` / `facts` / `bill` / `notice` / `tags` / `steps` / `list` / `ticket` / `timeline` / `empty`;动作规格与 `ActionList` 同形(label / send / invoke / confirm / style)。
38
+ - 预算写进 schema:积木 ≤4、提示 ≤1、属性 ≤5、列表 ≤3、账单行 ≤8、步骤 ≤5、时间线 ≤6、标签 ≤6、卡级动作 ≤2;作者期 `defineViewCard` 直接报错,生产侧 `cardOfView` 先截断再校验,不整张卡丢弃。
39
+ - 样例由 `sampleState` 与 `samples` 派生,不用手写大段 `sampleData`。
40
+ - 出卡用 `cardOfView(card, domainData, note)`:它先跑 `view()`,再走统一的出卡校验。
41
+ - `pnpm exec tbox-app new card <name> --view` 直接生成视图卡单文件;不带 `--view` 才生成三件套(仅富交互卡)。
42
+ - `pnpm exec tbox-app new feature <name> --view` 生成视图卡竖切(工具用 `cardOfView` 出卡);不带 `--view` 才是三件套起手(工具返回 `cards`)。
43
+ - 卡片自己渲染动作(`ActionList` / `ViewCard`)时,`defineCard` 必须写 `actions: 'self'`,否则 SDK 默认按钮条会叠加;不写动作的卡保持默认 `auto`。
44
+
45
+ ### 三件套(仅富交互卡)
46
+
47
+ 一张卡要有三样东西:
6
48
 
7
49
  | 位置 | 文件 | 作用 |
8
50
  |---|---|---|
package/docs/agent/kit.md CHANGED
@@ -23,7 +23,7 @@ import { Card, CardHeader, KeyValueList, StatusTag } from '@tbox.cn/app-agent-ui
23
23
  | `StatusTag` | 状态标签。 * | `children: ReactNode` `tone?: Tone` |
24
24
  | `Notice` | 提示条:说明、限制、下一步指引。 * | `children: ReactNode` `tone?: Tone` `icon?: ReactNode` |
25
25
  | `ActionRow` | 按钮行:主次两级,禁用整行。 * | `primary?: ReactNode` `secondary?: ReactNode` `disabled?: boolean` |
26
- | `CardButton` | — | `children: ReactNode` `onClick?: () => void` `variant?: 'primary' \| 'secondary' \| 'link'` `disabled?: boolean` |
26
+ | `CardButton` | — | `children: ReactNode` `onClick?: () => void` `variant?: 'primary' \| 'secondary' \| 'link'` `disabled?: boolean` `busy?: boolean` |
27
27
  | `ConfirmSheet` | 确认弹层:写操作前的一次确认。 | `open: boolean` `title: ReactNode` `description?: ReactNode` `confirmText?: string` `cancelText?: string` `onConfirm: () => void` `onCancel: () => void` |
28
28
  | `Ticket` | 票券形:券、凭证、卡包条目。 | `amount: ReactNode` `condition?: ReactNode` `meta?: ReactNode` `status?: ReactNode` `tone?: 'primary' \| 'muted'` |
29
29
  | `Steps` | 步骤/路线:取车路线、办理进度。 | `steps: StepItem[]` |
@@ -35,7 +35,7 @@ import { Card, CardHeader, KeyValueList, StatusTag } from '@tbox.cn/app-agent-ui
35
35
  | `Timeline` | 明细时间线:积分收支、停车计费。 * | `items: TimelineItem[]` |
36
36
  | `EmptyState` | 空态:没券、没订单、没记录时给一句解释与一个下一步。 * | `title: ReactNode` `description?: ReactNode` `action?: ReactNode` |
37
37
  | `TagList` | 标签组:口味、距离、适用条件。 * | `tags: ReactNode[]` `tone?: Tone` |
38
- | `ActionList` | 按钮组(描述对象版):把「发消息 / 确定性动作 / 确认弹层 / 禁用」收进一处。 | `actions: CardActionSpec[]` `api: CardActions` |
38
+ | `ActionList` | — | `actions: CardActionSpec[]` `api: CardActions` |
39
39
 
40
40
  ## 图标
41
41
 
@@ -30,7 +30,7 @@ const TONE = { ok: 'bg-success-soft text-success', warn: 'bg-warning-soft text-w
30
30
  - 字号只有六档:`text-xs`12 / `text-sm`14 / `text-base`16 / `text-lg`18 / `text-xl`20 / `text-2xl`24 / `text-3xl`30。正文 14、辅助 12、卡标题 16–20。**不要写 `text-[13px]`**:档位外的字号在真机上要么糊要么挤。
31
31
  - 行高用 `leading-5`(20px)这类 4 的倍数,精确值写 `leading-[22px]`。
32
32
  - 圆角与阴影优先契约:`rounded-lg/md/sm` 映射 `--tbox-radius-*`,`shadow-sm/md/lg` 映射 `--tbox-shadow-*`。
33
- - **不要用 rem / em 表达尺寸或字号**:宿主的根字号按设计稿动态设置(移动端约 50px),`p-4` 若按 rem 会变成 50px。
33
+ - **尺寸与字号一律物理 px**:模板没有动态根字号、没有 rem 换算,`p-4` 就是 16px;不要用 rem / em 表达尺寸。
34
34
 
35
35
  ## 颜色只能来自语义名
36
36
 
@@ -76,11 +76,17 @@ html[data-theme='tbox'] {
76
76
  - **不要在应用里声明 `--tbox-asset-*`**:元素级声明会截断 `html[data-theme]` 的覆写继承(素材级联门禁拦截)。
77
77
  - 任意值里不留空格(空格写下划线),逗号原样。
78
78
 
79
+ ## 整页背景
80
+
81
+ - 整页背景图或渐变写在壳的 `.chat-page__bg` 层(绝对定位、覆盖历史入口与底部输入区、不随内容滚动),它默认 `bg-center bg-cover bg-no-repeat`。
82
+ - 首页容器保持透明(卡片表面可保留自身底色);把整页背景铺在首页组件上会在历史入口处出现底色断层。
83
+ - home 槽是 `flow-root` 容器,首页子元素的外边距留在槽内;入口到首页的间距由首页自身留白决定。
84
+
79
85
  ## 旧 web-view 兼容
80
86
 
81
87
  - 颜色语法一律 `rgba(r, g, b, a)`;`rgb(r g b / a)` 在旧 WebKit 上整条属性失效(不是降级)。
82
88
  - 断点用 `max-[600px]:` / `min-[820px]:`;容器查询用 `@container/name` + `@min-[820px]/name:`;减动效 `motion-reduce:`;属性状态 `data-[state=open]:` / `group-data-[phase=open]/x:`。
83
- - 产物特征门禁:`pnpm check:css` 读构建产物按 `package.json` 的 `tbox.compat.baseline` 扫越线特性(缺省 safari 15.4)。基线由真机测量得出(安卓/iOS 各跑一次 `pnpm compat:probe`),不要从代码用到的特性反推。
89
+ - 产物特征门禁:`pnpm check:css` 读构建产物按 `package.json` 的 `tbox.compat.baseline` 扫越线特性(缺省 `safari 16.4`,即 Tailwind 4 官方下限;Chrome 111+ 视为满足)。基线只声明一次,构建期守产物;没有运行时探测,也没有旧内核提示页。
84
90
 
85
91
  ## 卡片排版
86
92
 
@@ -7,10 +7,15 @@
7
7
  工具 `execute` 返回的对象里,`cards` 是保留字段:
8
8
 
9
9
  ```ts
10
- return { ...facts, cards: [{ cardType: 'order-status', data: facts, note: '一句话摘要' }] };
10
+ // 视图卡(默认):data 由卡片 view() 生成
11
+ return { ...facts, cards: [cardOfView(orderStatusCard, facts, '一句话摘要')] };
12
+
13
+ // 三件套:手写 cardType + data
14
+ // cards: [{ cardType: 'order-status', data: facts, note: '一句话摘要' }]
11
15
  ```
12
16
 
13
17
  - `data` 进卡片渲染,模型看不到;模型看到的是 `{ id, cardType, note }` 摘要。
18
+ - 视图卡(默认)用 `cardOfView(parkingOrderCard, order, note)` 出卡:它先跑 `view()`,再走同一套校验;三件套才手写 `{ cardType, data, note }`。
14
19
  - `note` 是模型判断要不要展示的依据,超过 120 字符会被截断。
15
20
  - 一次可以带多张卡;同一轮最多展示 3 张(引擎默认值,构造期可调)。
16
21
  - 模型通过回复里的 `<agent-ui-cards>` 标签点选要展示的卡;标签对用户不可见。
@@ -41,7 +46,7 @@ return { ...facts, cards: [{ cardType: 'order-status', data: facts, note: '一
41
46
 
42
47
  ```ts
43
48
  // ① 出卡工具不声明 outputSchema(推荐,最简单)
44
- export const tool = createTool({ id, description, inputSchema, execute });
49
+ export const tool = defineTool({ id, description, inputSchema, execute });
45
50
 
46
51
  // ② 需要约束出参时,用 passthrough 并显式保留 cards
47
52
  outputSchema: z.object({ message: z.string(), cards: z.array(z.record(z.unknown())).optional() }).passthrough(),
@@ -54,4 +59,4 @@ outputSchema: z.object({ message: z.string(), cards: z.array(z.record(z.unknown(
54
59
  | 工具返回了卡但对话里没卡 | `cards` 写在了 `data` 里,或 `cardType` 拼错 |
55
60
  | 卡片内容为空 | `data` 与 `facts` 不是一份数据 |
56
61
  | 卡片总是最后一张 | 模型没收到可点选的摘要——检查 `note` 是否为空 |
57
- | 生成报卡片缺失 | 只写了服务端文件,客户端没有同名 `.card.tsx` |
62
+ | 生成报卡片缺失 | 三件套只写了服务端文件;视图卡请在 meta 上声明 `view`(免成对文件) |
@@ -43,6 +43,8 @@ export const tool = defineTool({
43
43
  ```
44
44
  ```
45
45
 
46
+ > 上面是三件套形态。默认视图卡项目把 return 换成 `cards: [cardOfView(card, facts, note)]`:`facts` 是领域数据,不是视图 JSON;`cardOfView` 先跑卡片的 `view(facts)`,再走统一的出卡校验(见 [card](card.md))。
47
+
46
48
  ## 要点
47
49
 
48
50
  | 项 | 规则 |
@@ -16,7 +16,7 @@
16
16
 
17
17
  ## T0 做什么
18
18
 
19
- 1. `pnpm generate`——生成 registry 与入口;卡片不成对、`cardType` 不一致在这里报错。
19
+ 1. `pnpm generate`——生成 registry 与入口;三件套不成对、`cardType` 不一致在这里报错(视图卡声明了 `view`,免成对)。
20
20
  2. `eslint --fix`——先修复,避免改文件与类型检查竞争。
21
21
  3. 并行:四个包 `tsc --noEmit`(开发期放宽未用变量,`pnpm verify` 仍严格)、`verify-generated` 结构检查、证据包。
22
22
  4. **证据包**(`apps/client/scripts/check-evidence.mjs`,一个进程):品牌变量编译 → 卡片样例 / 出卡类型 / 出卡提示 / `invoke` 与动作对齐 / 字号 / 颜色语法 → 每张卡 × 每个样例经真实 React 组件渲染 → `scenarios/*.json` 全部执行 → 验收项覆盖与裁决。
@@ -29,12 +29,15 @@
29
29
  "registry": { "tools": ["query-points"], "cards": ["points-card"], "actions": ["pay-parking"] },
30
30
  "warnings": [{ "id": "card-sample-coverage", "message": "parking-card.status 的状态 [\"paid\"] 没有样例" }],
31
31
  "verdict": "deliverable",
32
- "acceptance": { "items": 3, "covered": 3, "review": 0, "uncovered": [] },
32
+ "acceptance": { "items": 3, "covered": 3, "handoff": 0, "uncovered": [] },
33
+ "policy": "static",
34
+ "coverage": { "logic": "已验证:2 个场景 / 12 步 / 3 项", "visual": "未运行:当前策略 static" },
35
+ "handoff": [],
33
36
  "next": "交付条件已满足:总结并结束。不要继续复审或打磨。",
34
37
  "notRun": [] }
35
38
  ```
36
39
 
37
- - `verdict` 是交付裁决:`failing` / `incomplete` / `unspecified` / `deliverable`;`next` 就是下一步;
40
+ - `verdict` 是交付裁决:`failing` / `incomplete` / `unspecified` / `deliverable` / `reopened`;`next` 就是下一步;
38
41
  - `warnings` 不阻断,但每条都带「修复」提示与配方名;
39
42
  - `notRun` 说明哪一步没跑(例如没有场景文件);
40
43
  - 失败时输出首个失败步骤的全部错误,每条带 `file:line` 与修复建议。
@@ -45,16 +48,23 @@
45
48
 
46
49
  ```jsonc
47
50
  {
51
+ // 证据策略:本任务允许验到哪一级(static / visual / flow);缺省 static
52
+ "policy": "static",
48
53
  "items": [
49
54
  { "id": "join.reward", "text": "入会后获得 100 积分和一张满100减20券" },
50
55
  { "id": "parking.pay", "text": "用停车券抵 10 元,实付 5 元,得 5 积分" },
51
- { "id": "ui.mobile", "text": "移动端为主,其它尺寸可用", "by": "review" }
56
+ { "id": "ui.mobile", "text": "移动端为主,其它尺寸可用", "by": "handoff",
57
+ "reason": "当前任务要求快速交付,不起浏览器" }
52
58
  ]
53
59
  }
54
60
  ```
55
61
 
56
62
  - 一个验收项算覆盖,当且仅当至少一个**通过**的场景在 `covers` 里列了它;
57
- - `by: "review"` 表示无法由场景判定,列出但不阻塞;
63
+ - `origin: "recorded"` 的场景(`scenario record` 自动写)只作回归,不单独覆盖验收项;摘要里的 `declared` 是含录制场景的声明覆盖数;
64
+ - `lane: "browser" | "model"` 的验收项直接进 `deferred`,不占 `handoff`、不承诺自动补验;
65
+ - `by: "handoff"`(旧名 `review` 仍可用)表示**当前策略下验不了**,必须写 `reason`;门禁把它列进 `handoff`,
66
+ 并在 `next` 里要求原样写进交付说明——它不再是一个「待复审」的邀请;
67
+ - 能由场景判定却标 `handoff` 的项(缺 `reason`)计入 `incomplete`,不能用来绕过覆盖;
58
68
  - 场景里可写 `expect.state`(对登记状态做子集匹配)验证需求里写明的不变量,例如 `{ "member": true, "points": 100 }`;
59
69
  - 场景缺省按文件隔离用户,需要共享时在场景顶层写 `user`。
60
70
 
@@ -65,9 +75,14 @@
65
75
  | `failing` | 有检查失败 | 首个根因与修复建议 |
66
76
  | `incomplete` | 检查通过但有未覆盖验收项 | 未覆盖的 id |
67
77
  | `unspecified` | 有工具/动作但没写验收项 | 先拆验收项 |
68
- | `deliverable` | 全部覆盖 | 交付,不再复审 |
78
+ | `deliverable` | 全部覆盖 | 交付;有 handoff / deferred 时先写进交付说明 |
79
+ | `reopened` | 交付后源码内容又变了 | 重跑确认;只降级一次,不阻断 |
69
80
 
70
- 已经 `deliverable` 之后再跑,摘要里的 `sinceDeliverable` 给出其后的门禁次数与改动文件数。
81
+ 摘要里的 `coverage` 给每个维度一个状态(结构 / 逻辑 / 渲染 / 视觉 / 模型路由),`handoff` 是当前策略
82
+ 验不了的清单。视觉与模型级验收只在 `policy` 允许时运行;`static` 下它们明确写「未运行」,不留作疑问。
83
+ 已经 `deliverable` 之后再跑,`sinceDeliverable` 给出其后的门禁次数与改动文件数;源码内容再变会得到 `reopened`(内容哈希),同一份内容再跑一次恢复 `deliverable`。
84
+
85
+ 摘要里的 `delivery` 是交付包:`trace` 逐项覆盖、`facts` 视图卡高度、`drift` 验收/期望漂移、`deferred` 浏览器/模型/未接项。交付时把 `deferred` 原样写进说明。
71
86
 
72
87
  ## 试跑
73
88
 
@@ -76,7 +91,7 @@ pnpm exec tbox-app probe "join-membership{} action:confirm-join{} query-points{}
76
91
  pnpm exec tbox-app probe "query-points{}" --user u1 --save points-baseline
77
92
  ```
78
93
 
79
- 不带 `--save` 只试跑、不落盘;带 `--save` 把本次真实执行录成 `scenarios/<名称>.json`(可再用 `covers` 登记验收项)。
94
+ 不带 `--save` 只试跑、不落盘;带 `--save` 把本次真实执行录成 `scenarios/<名称>.json`,并标记 `origin: "recorded"`——录制场景只作回归,不单独覆盖验收项;验收项请手写 spec 场景并在 `covers` 登记。
80
95
 
81
96
  ## 常见报错
82
97
 
@@ -98,16 +113,31 @@ pnpm exec tbox-app probe "query-points{}" --user u1 --save points-baseline
98
113
  | `card-sample-coverage`(告警) | 状态枚举有值没有样例 | 在 samples 里给每个状态各补一条([card](card.md)) |
99
114
  | `tool-not-registered`(告警) | 工具 id 不在 registry 里 | 检查是否漏了 export const tool([tool](tool.md)) |
100
115
  | `card-emission-hint`(告警) | 出卡工具的 description 未声明会附卡片 | 用 withCardEmissionHint 或在 description 里补「命中数据时结果附可展示卡片(cards)。」([tool-emits-card](tool-emits-card.md)) |
101
- | `font-too-small`(告警) | 旧 Less 里的设计稿字号低于可读下限 22px | 迁移后应用侧不再写字号:样式用工具类六档字号([style](style.md)) |
102
- | `color-syntax`(告警) | 用了旧 web-view 不支持的 rgb(r g b / a) 语法 | 改 rgba(r, g, b, a)([style](style.md)) |
103
116
  | `styles-entry-missing`(告警) | 没有 apps/client/src/styles/brand.css | 新建 brand.css(只放品牌变量覆写)并在 app.config.ts 里 import(模板出厂自带)([style](style.md)) |
104
117
  | `card-client-missing`(错误) | 服务端有卡但客户端没有同名组件 | 补 apps/client/src/cards/<id>.card.tsx(export const card = defineCard({ type: '<id>' }, …))([card](card.md)) |
105
118
  | `registry-load-failed`(错误) | .tbox-gen 注册表加载失败 | 跑 pnpm generate 重新生成 .tbox-gen([verify](verify.md)) |
106
119
  | `palette-color`(错误) | 用了 Tailwind 默认调色板(不生成 CSS) | 换成语义色 `text-foreground` / `bg-card` / `border-border`([style](style.md)) |
107
- | `color-opacity-modifier`(错误) | 颜色用了 `/50` 这类透明度修饰符(依赖 color-mix,旧内核不透明) | 改带 alpha 的任意值 `bg-[rgba(255,255,255,0.18)]`([style](style.md)) |
108
- | `font-size-off-scale`(错误) | 字号越档(只有 12/14/16/18/20/24/30 六档) | 用 `text-xs/sm/base/lg/xl/2xl/3xl`([style](style.md)) |
120
+ | `font-size-off-scale`(错误) | 字号越档(只有 12/14/16/18/20/24/30/36 七档) | 用 text-xs/sm/base/lg/xl/2xl/3xl/4xl(正文 16、卡片正文 14、说明 12)([style](style.md)) |
109
121
  | `class-before-interpolation`(错误) | 类名紧贴 `${`,扫描器拿不到完整候选(样式静默不生效) | 在 `${` 前留空格:`text-xs ${cond ? … : …}`([style](style.md)) |
110
122
  | `element-asset-declaration`(错误) | 在元素上声明 `--tbox-asset-*`(截断主题覆写继承) | 素材变量归主题包,元素只消费 `var(--tbox-asset-*, 兜底)`([style](style.md)) |
123
+ | `handoff-misuse`(告警) | handoff 项没有 reason(可能借移交绕过覆盖) | 补 reason 说明当前策略为什么验不了,或补一条场景并写 covers([verify](verify.md)) |
124
+ | `policy-unknown`(告警) | acceptance.jsonc 的 policy 值不支持 | 改成 static / visual / flow 之一,或删掉 policy 使用缺省 static([verify](verify.md)) |
125
+ | `render-empty`(告警) | 卡片渲染结果为空 | 检查组件是否按 cardType 注册、样例数据是否为空([card](card.md)) |
126
+ | `render-identical`(告警) | 同一卡片的多份样例渲染结果完全相同 | 给不同状态不同的可见内容,或删掉重复样例([card](card.md)) |
127
+ | `tool-description-empty`(告警) | 工具 description 为空 | 写「什么时候用」,不要写「做什么」([tool](tool.md)) |
128
+ | `tool-description-duplicate`(告警) | 两个工具的 description 完全相同 | 让两个工具的描述各自说明触发场景([tool](tool.md)) |
129
+ | `boot.inline-script`(错误) | 入口 HTML 有内联脚本(解析期执行,body 可能还是 null) | 删掉内联脚本;启动逻辑放打包后的模块里([verify](verify.md)) |
130
+ | `shell.identity`(错误) | 发送者名写死「AI 助手」,已配置的身份没用上 | 从 chat.json identity.name 取,缺省再回落([shell](shell.md)) |
131
+ | `shell.type-scale`(错误) | 写了档外字号(text-[13px] 之类) | 用 12/14/16/18/20/24/30/36 档:正文 16、卡片正文 14、说明 12([style](style.md)) |
132
+ | `css.sentinel`(错误) | 证据 CSS 为空或不完整(样式管线断了) | 确认 tailwind.css 与 @source;证据与 dev/build 共用 surface-css.mjs([style](style.md)) |
133
+ | `card.states`(错误) | 卡片历史态渲染失败或为空 | 用 isHistory 只禁用动作,不隐藏内容([card](card.md)) |
134
+ | `shell.hit-target`(错误) | 可交互元素命中区小于 44px | 用 kit 按钮与 min-h-11;视觉尺寸可小,命中区要足([shell](shell.md)) |
135
+ | `shell.quick-visible`(错误) | 空态快捷问题没有全部可见(横向溢出或贴底) | 空态用两列 grid,对话态才用单行([shell](shell.md)) |
136
+ | `flow.persist`(告警) | 状态没有跨进程重启验证 | 用 createUserState({ persist: "file" }) 并加重启探针([state](state.md)) |
137
+ | `shell.contrast`(错误) | 令牌对比度低于阈值(文字看不清) | 调 brand.css 的令牌值;color-mix 派生的由浏览器车道补验([style](style.md)) |
138
+ | `shell.blank`(错误) | 内容块之间空白过大(看起来没做完) | 空态成组居中、补服务入口;只算块间空白,不算首尾对称留白([shell](shell.md)) |
139
+ | `card.height`(错误) | 视图卡过高(一屏放不下) | 按预算减积木或拆卡;详情用单独的卡承接([card](card.md)) |
140
+ | `CARD_TYPE_INVALID`(错误) | 卡片类型含路径分隔符或非法字符 | 改成小写 kebab(字母/数字/点/下划线/中划线),不要用 ../ 或斜杠([card](card.md)) |
111
141
  <!-- check-docs:errors end -->
112
142
 
113
143
  ## 用户说「不要测试」时
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-template-agent",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.8",
4
4
  "description": "tbox AI Agent 全栈模板(多包 pnpm workspace):apps/client + apps/server。唯一模板(W4 单一模板统一化:缺省带 AI 支付体验的 chat 形态;mall 能力经 profiles/mall 加装),能力经 CLI module add 模块扩展(shopping-guide/member 等)。",
5
5
  "engines": {
6
6
  "node": ">=24.0.0 <25.0.0"
@@ -12,6 +12,8 @@
12
12
  "!apps/**/.vite",
13
13
  "!apps/**/node_modules",
14
14
  "!apps/**/*.tsbuildinfo",
15
+ "!**/._*",
16
+ "!**/.DS_Store",
15
17
  "config",
16
18
  "docs",
17
19
  "profiles",
@@ -24,6 +26,11 @@
24
26
  "scripts",
25
27
  "scenarios",
26
28
  ".tbox",
29
+ "!.tbox-gen",
30
+ "!.tbox/card-render",
31
+ "!.tbox/evidence",
32
+ "!.tbox/state",
33
+ "!.tbox/compat-probe.html",
27
34
  ".gitignore",
28
35
  ".nvmrc",
29
36
  "AGENTS.md",
@@ -41,14 +48,19 @@
41
48
  "typescript-eslint": "8.67.0",
42
49
  "eslint-plugin-react-hooks": "5.2.0",
43
50
  "vite": "6.4.3",
44
- "@tbox.cn/app-sdk-server": "1.0.0-alpha.6",
45
- "@tbox.cn/app-build": "1.0.0-alpha.6",
46
- "@tbox.cn/app-cli": "1.0.0-alpha.6"
51
+ "@tbox.cn/app-sdk-server": "1.0.0-alpha.8",
52
+ "@tbox.cn/app-build": "1.0.0-alpha.8",
53
+ "@tbox.cn/app-cli": "1.0.0-alpha.8"
47
54
  },
48
55
  "license": "MIT",
49
56
  "publishConfig": {
50
57
  "access": "public"
51
58
  },
59
+ "tbox": {
60
+ "compat": {
61
+ "baseline": "safari 16.4"
62
+ }
63
+ },
52
64
  "scripts": {
53
65
  "dev": "pnpm --filter ./apps/server dev",
54
66
  "dev-alipay": "node scripts/dev-alipay.mjs",
@@ -65,7 +77,6 @@
65
77
  "check": "pnpm check:workspace && pnpm check:inspector",
66
78
  "check:fast": "node scripts/check-fast.mjs",
67
79
  "check:css": "node scripts/check-css-target.mjs",
68
- "compat:probe": "node scripts/compat-probe.mjs",
69
80
  "scenario": "pnpm --filter ./apps/server exec node --import tsx scripts/scenario.mjs",
70
81
  "card:render": "pnpm --filter ./apps/client exec node scripts/render-card.mjs",
71
82
  "check:workspace": "node scripts/check-workspace.mjs",
@@ -3,6 +3,6 @@
3
3
  对话壳与卡片基元的源码包(应用内副本由 `scripts/sync-agent-ui-kit.mjs` 派生,手改会被覆盖)。
4
4
 
5
5
  - 用基元与壳配置,不读本包源码:基元目录、图标、主题变量、壳可改范围见应用内 `docs/agent/kit.md`。
6
- - 卡片一律 `defineCard` + 基元拼装;确有应用级样式时写在 `apps/client/src/styles/brand.less`(只改变量)或同目录 `cards.less`。
6
+ - 卡片一律 `defineCard` + 基元拼装;确有应用级样式时写在 `apps/client/src/styles/brand.css`(只改变量),不要新建 CSS 文件。
7
7
  - 壳内部结构(MessageBubble / ChatInput / 卡片渲染器)不承诺稳定,不要按类名覆写。
8
8
  - 本包的契约与测试是真源:改壳要同步 `src/shell.contract.json` 与 `src/shell.test.ts`,并跑 `pnpm gen:kit-catalog` 重生成 `catalog.json` 与 `docs/agent/kit.md`。
@@ -193,7 +193,7 @@
193
193
  },
194
194
  {
195
195
  "name": "CardButton",
196
- "propsType": "{\n children: ReactNode;\n onClick?: () => void;\n variant?: 'primary' | 'secondary' | 'link';\n disabled?: boolean;\n}",
196
+ "propsType": "{\n children: ReactNode;\n onClick?: () => void;\n variant?: 'primary' | 'secondary' | 'link';\n disabled?: boolean;\n /** 动作进行中:只影响可访问性语义,视觉由调用方给 spinner */\n busy?: boolean;\n}",
197
197
  "props": [
198
198
  {
199
199
  "name": "children",
@@ -214,6 +214,12 @@
214
214
  "name": "disabled",
215
215
  "type": "boolean",
216
216
  "optional": true
217
+ },
218
+ {
219
+ "name": "busy",
220
+ "type": "boolean",
221
+ "optional": true,
222
+ "doc": "动作进行中:只影响可访问性语义,视觉由调用方给 spinner"
217
223
  }
218
224
  ]
219
225
  },
@@ -606,8 +612,6 @@
606
612
  },
607
613
  {
608
614
  "name": "ActionList",
609
- "summary": "按钮组(描述对象版):把「发消息 / 确定性动作 / 确认弹层 / 禁用」收进一处。",
610
- "behavior": "纵向排列,每个按钮独占一行;confirm 走 ConfirmSheet;disabled 自动接 api.disabled。",
611
615
  "propsType": "{ actions: CardActionSpec[]; api: CardActions }",
612
616
  "props": [
613
617
  {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-agent-ui-kit",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.8",
4
4
  "type": "module",
5
5
  "description": "Agent 对话壳 UI 组件包(源码发布,单一模板统一化 W2-1):ChatPage/壳组件族/主题 tokens。",
6
6
  "exports": {
@@ -206,7 +206,9 @@ function ChatPageInner() {
206
206
  && messages.length === 0
207
207
  && inlineOrphanCards.length === 0;
208
208
  const welcomeTitle = welcome?.title ?? identity?.name ?? '开始对话';
209
- const welcomeSubtitle = welcome?.subtitle ?? identity?.tagline;
209
+ const welcomeSubtitle = welcome?.subtitle ?? identity?.tagline ?? '可以直接提问,也可以从下面的问题开始';
210
+ // 空会话(有 home 槽或无 home 槽)走同一套构图:欢迎区 + 快捷问题成组居中。
211
+ const isEmptyState = showHome || showWelcome;
210
212
 
211
213
  const pull = usePullDownHistory({
212
214
  isAtTopRef,
@@ -240,19 +242,33 @@ function ChatPageInner() {
240
242
  return () => ro.disconnect();
241
243
  }, []);
242
244
 
243
- // 仅在已有对话内容且贴近底部时自动滚动,避免打断用户上翻查看历史。
244
- // 依赖含 cardsByMessageId:主卡在文字完成后挂载、消息行增高,需补滚避免卡片截出视口
245
+ // 回合锚定:新回合把本轮用户消息置顶,流式期间不追底。
246
+ // 贴底滚动会把问题顶出视口(实测卡片 648px 时问题上移 244px),用户看不到自己在问什么。
247
+ const turnAnchorRef = useRef<string | null>(null);
245
248
  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]);
249
+ const lastUser = [...messages].reverse().find((message) => message.role === 'user');
250
+ if (!lastUser || turnAnchorRef.current === lastUser.id) return;
251
+ turnAnchorRef.current = lastUser.id;
252
+ const body = bodyRef.current;
253
+ const element = body?.querySelector(`[data-message-id="${lastUser.id}"]`);
254
+ if (!body || !element) return;
255
+ const delta = element.getBoundingClientRect().top - body.getBoundingClientRect().top;
256
+ body.scrollTop += delta - 8;
257
+ isNearBottomRef.current = false;
258
+ }, [messages]);
259
+
260
+ // 没有新回合、但卡片在文字之后挂载时,内容会继续变高:只在用户本来就在底部时补滚,
261
+ // 且不改变「本轮问题已在视口内」的锚点。
262
+ useEffect(() => {
263
+ if (!isNearBottomRef.current) return;
264
+ const el = bodyRef.current;
265
+ if (el && messages.length === 0 && orphanCards.length > 0) el.scrollTop = el.scrollHeight;
266
+ }, [orphanCards, liveCardSignature, messages.length]);
252
267
 
253
268
  return (
254
269
  <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" />
270
+ {/* 整页背景独立于滚动内容,覆盖历史入口、首页与底部输入区;图片按视口居中铺满、不重复。 */}
271
+ <div className="chat-page__bg pointer-events-none absolute inset-0 z-0 bg-background bg-center bg-cover bg-no-repeat" />
256
272
 
257
273
  {brandName ? (
258
274
  <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 +279,7 @@ function ChatPageInner() {
263
279
 
264
280
  <div className="chat-page__body-wrapper relative z-10 flex min-h-0 flex-1 flex-col">
265
281
  <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"
282
+ 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
283
  ref={bodyRef}
268
284
  onScroll={onScroll}
269
285
  onWheel={pull.handleWheel}
@@ -288,17 +304,25 @@ function ChatPageInner() {
288
304
 
289
305
  {/* 空会话欢迎区:没有 home 槽时的首屏落点(文案来自 chat.json welcome / identity) */}
290
306
  {showWelcome ? (
291
- <div className="chat-page__welcome flex flex-col items-center justify-center gap-2 px-page pb-5 pt-15 text-center">
307
+ <div className="chat-page__welcome flex flex-col items-center justify-center gap-2 px-page pb-4 pt-6 text-center">
292
308
  <h2 className="chat-page__welcome-title m-0 text-xl font-bold text-foreground">{welcomeTitle}</h2>
293
309
  {welcomeSubtitle ? <p className="chat-page__welcome-subtitle m-0 text-sm leading-normal text-muted-foreground">{welcomeSubtitle}</p> : null}
294
310
  </div>
295
311
  ) : null}
296
312
 
297
- {/* 历史前插视口锚 + home 槽渲染位(域自持显隐;缺席则不渲染) */}
298
- <div className="chat-page__home-slot" ref={historyAnchorRef}>
313
+ {/* 历史前插视口锚 + home 槽渲染位(域自持显隐;缺席则不渲染)。flow-root 让首页子元素
314
+ 的外边距留在槽内,不折叠到历史入口与首页之间。 */}
315
+ <div className="chat-page__home-slot flow-root" ref={historyAnchorRef}>
299
316
  {homeSlot?.({ onSend: send, ...(mallName ? { mallName } : {}) })}
300
317
  </div>
301
318
 
319
+ {/* 空会话的服务入口:快捷问题与欢迎区成组居中,两列全可见(不再贴底单行溢出)。 */}
320
+ {!blocked && isEmptyState ? (
321
+ <div className="chat-page__home-actions mt-6 flex w-full flex-col items-center">
322
+ <QuickCommands variant="grid" hidden={voiceActive} onCommand={send} />
323
+ </div>
324
+ ) : null}
325
+
302
326
  {/* 业务旁路 emit 的卡片(如欢迎卡) */}
303
327
  {inlineOrphanCards.map((card) => (
304
328
  <div key={card.id} className="chat-page__orphan-card mx-page">
@@ -315,9 +339,9 @@ function ChatPageInner() {
315
339
  <ScrollToBottomButton visible={showScrollToBottom} onClick={scrollToBottom} />
316
340
  </div>
317
341
 
318
- {/* 首页与对话态都保留快捷指令;语音活跃时只隐去胶囊并保留灰底占位,阻断时才卸载。 */}
342
+ {/* 对话态保留底部快捷指令;空会话的快捷问题在正文里成组展示(不重复渲染)。 */}
319
343
  <div ref={chatBottomRef}>
320
- {!blocked && <QuickCommands hidden={voiceActive} onCommand={send} />}
344
+ {!blocked && !isEmptyState && <QuickCommands hidden={voiceActive} onCommand={send} />}
321
345
  <ChatInput
322
346
  generating={isGenerating}
323
347
  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
+ });