@tbox.cn/app-template-agent 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.
- package/.gitignore +7 -0
- package/.tbox/app.json +1 -1
- package/.tbox/default-modules.json +1 -1
- package/.tbox/factory/chat.json +9 -0
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +11 -8
- package/apps/client/index.html +0 -43
- package/apps/client/package.json +1 -0
- package/apps/client/scripts/acceptance-changes.test.mjs +97 -0
- package/apps/client/scripts/check-evidence.mjs +625 -108
- package/apps/client/scripts/color-scan.mjs +66 -0
- package/apps/client/scripts/color-scan.test.mjs +25 -0
- package/apps/client/scripts/evidence-gate.mjs +337 -0
- package/apps/client/scripts/evidence-gate.test.mjs +135 -0
- package/apps/client/scripts/experience-checks.mjs +163 -0
- package/apps/client/scripts/geometry-kernel.test.mjs +92 -0
- package/apps/client/scripts/in-process-checks.mjs +51 -0
- package/apps/client/scripts/lib/card-registry.mjs +81 -0
- package/apps/client/scripts/lib/card-registry.test.mjs +59 -0
- package/apps/client/scripts/lib/evidence-inputs.mjs +91 -0
- package/apps/client/scripts/lib/evidence-inputs.test.mjs +27 -0
- package/apps/client/scripts/lib/static-render.mjs +35 -0
- package/apps/client/scripts/lib/static-render.test.mjs +21 -0
- package/apps/client/scripts/probe-checks.mjs +85 -0
- package/apps/client/scripts/render-card.mjs +95 -126
- package/apps/client/scripts/sample-entries.test.mjs +31 -0
- package/apps/client/scripts/storyboard.test.mjs +149 -0
- package/apps/client/scripts/surface-css.mjs +54 -0
- package/apps/client/scripts/theme-kernel.mjs +236 -0
- package/apps/client/scripts/theme-kernel.test.mjs +136 -0
- package/apps/client/src/app.config.ts +4 -1
- package/apps/client/src/styles/brand.css +13 -14
- package/apps/client/src/styles/tailwind.css +20 -21
- package/apps/client/vite.config.ts +2 -1
- package/apps/server/scripts/probe.mjs +6 -1
- package/apps/server/scripts/scenario-lib.mjs +56 -8
- package/apps/server/scripts/scenario.mjs +41 -7
- package/config/AGENTS.md +1 -0
- package/config/chat.json +21 -9
- package/docs/agent/agent-prompt.md +1 -1
- package/docs/agent/card-action.md +5 -0
- package/docs/agent/card.md +45 -2
- package/docs/agent/kit.md +3 -3
- package/docs/agent/shell.md +1 -0
- package/docs/agent/style.md +11 -3
- package/docs/agent/tool-emits-card.md +7 -2
- package/docs/agent/tool.md +2 -0
- package/docs/agent/verify.md +59 -16
- package/package.json +21 -7
- package/packages/agent-ui-kit/AGENTS.md +1 -1
- package/packages/agent-ui-kit/README.md +21 -1
- package/packages/agent-ui-kit/catalog.json +8 -4
- package/packages/agent-ui-kit/package.json +9 -1
- package/packages/agent-ui-kit/src/._surface.tsx +0 -0
- package/packages/agent-ui-kit/src/ChatPage.tsx +70 -17
- package/packages/agent-ui-kit/src/card/._action-list-pending.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._define-card.test.ts +0 -0
- package/packages/agent-ui-kit/src/card/._view-card-inline.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._view-card.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._view-card.tsx +0 -0
- package/packages/agent-ui-kit/src/card/action-list-pending.test.tsx +91 -0
- package/packages/agent-ui-kit/src/card/define-card.test.ts +25 -0
- package/packages/agent-ui-kit/src/card/define-card.ts +18 -5
- package/packages/agent-ui-kit/src/card/primitives.test.tsx +10 -0
- package/packages/agent-ui-kit/src/card/primitives.tsx +136 -37
- package/packages/agent-ui-kit/src/card/view-card-inline.test.tsx +42 -0
- package/packages/agent-ui-kit/src/card/view-card.test.tsx +79 -0
- package/packages/agent-ui-kit/src/card/view-card.tsx +250 -0
- package/packages/agent-ui-kit/src/chat-config.ts +11 -7
- package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.test.tsx +3 -0
- package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.tsx +2 -7
- package/packages/agent-ui-kit/src/components/BottomSheet/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/index.test.tsx +90 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/index.tsx +129 -0
- package/packages/agent-ui-kit/src/components/ChatInput/index.test.tsx +2 -2
- package/packages/agent-ui-kit/src/components/ChatInput/index.tsx +22 -17
- package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +3 -2
- package/packages/agent-ui-kit/src/components/MessageBubble/index.tsx +11 -5
- package/packages/agent-ui-kit/src/components/QuickCommands/index.test.tsx +3 -1
- package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +31 -8
- package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.tsx +7 -3
- package/packages/agent-ui-kit/src/components/ToolCallBlock/index.tsx +4 -2
- package/packages/agent-ui-kit/src/index.ts +8 -0
- package/packages/agent-ui-kit/src/preview-provider.tsx +47 -0
- package/packages/agent-ui-kit/src/shell.contract.json +9 -0
- package/packages/agent-ui-kit/src/shell.test.ts +10 -0
- package/packages/agent-ui-kit/src/shell.ts +15 -0
- package/packages/agent-ui-kit/src/surface.test.tsx +35 -0
- package/packages/agent-ui-kit/src/surface.tsx +44 -0
- package/packages/agent-ui-kit/src/theme/base.css +9 -11
- package/packages/agent-ui-kit/src/theme/contract.json +123 -2
- package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +16 -0
- package/packages/agent-ui-kit/src/theme/tokens.css +9 -12
- package/pnpm-lock.template.yaml +97 -91
- package/pnpm-workspace.template.yaml +10 -10
- package/profiles/mall/._chat.overrides.json +0 -0
- package/profiles/mall/chat.overrides.json +12 -0
- package/profiles/mall/config/chat.json +14 -6
- package/profiles/mall.json +1 -1
- package/scripts/._assert-pack.mjs +0 -0
- package/scripts/._deliver.mjs +0 -0
- package/scripts/._shell-probe.mjs +0 -0
- package/scripts/._storyboard.mjs +0 -0
- package/scripts/assert-pack.mjs +48 -0
- package/scripts/check-css-target.mjs +6 -3
- package/scripts/check-fast.mjs +1 -0
- package/scripts/checks.json +400 -26
- package/scripts/deliver.mjs +183 -0
- package/scripts/lib/._chrome-pipe.mjs +0 -0
- package/scripts/lib/._geometry-kernel.mjs +0 -0
- package/scripts/lib/chrome-pipe.mjs +95 -0
- package/scripts/lib/geometry-kernel.mjs +137 -0
- package/scripts/shell-probe.mjs +283 -0
- package/scripts/storyboard.mjs +350 -0
- package/.tbox/card-render/baseline/demo.png +0 -0
- package/.tbox/card-render/demo.html +0 -342
- package/.tbox/card-render/demo.png +0 -0
- package/.tbox/card-render/scale-demo.audit.html +0 -984
- package/.tbox/card-render/scale-demo.html +0 -939
- package/.tbox/evidence/cards.txt +0 -1
- package/.tbox/evidence/gate.json +0 -1
- package/.tbox/evidence/last-gate.json +0 -1
- package/.tbox/evidence/scenarios.json +0 -1
- package/apps/client/.tbox-gen/app-registry.ts +0 -3
- package/apps/client/.tbox-gen/documents/_tbox/card-preview.html +0 -62
- package/apps/client/.tbox-gen/documents/index.html +0 -63
- package/apps/client/.tbox-gen/entries/card-preview.tsx +0 -6
- package/apps/client/.tbox-gen/entries/index.tsx +0 -11
- package/apps/client/.tbox-gen/manifest.json +0 -17
- package/apps/client/.tbox-gen/registry.client.ts +0 -6
- package/apps/client/.tbox-gen/registry.server.ts +0 -15
- package/apps/client/STYLE_GUIDE.md +0 -48
- package/apps/client/VISUAL_RESTORE.md +0 -90
- package/profiles/mall/config/llm_provider.json +0 -5
- package/profiles/mall/config/plugins.json +0 -3
- package/scripts/compat-probe.mjs +0 -108
- package/scripts/gen-tailwind-sources.mjs +0 -55
- /package/.tbox/{card-render/._demo.html → factory/._chat.json} +0 -0
- /package/{.tbox/card-render/._demo.png → apps/client/scripts/._acceptance-changes.test.mjs} +0 -0
- /package/{.tbox/card-render/._scale-demo.audit.html → apps/client/scripts/._color-scan.mjs} +0 -0
- /package/{.tbox/card-render/._scale-demo.html → apps/client/scripts/._color-scan.test.mjs} +0 -0
- /package/{.tbox/card-render/baseline/._demo.png → apps/client/scripts/._evidence-gate.mjs} +0 -0
- /package/{.tbox/evidence/._cards.txt → apps/client/scripts/._evidence-gate.test.mjs} +0 -0
- /package/{.tbox/evidence/._gate.json → apps/client/scripts/._experience-checks.mjs} +0 -0
- /package/{.tbox/evidence/._last-gate.json → apps/client/scripts/._geometry-kernel.test.mjs} +0 -0
- /package/{.tbox/evidence/._scenarios.json → apps/client/scripts/._in-process-checks.mjs} +0 -0
- /package/apps/client/{._STYLE_GUIDE.md → scripts/._probe-checks.mjs} +0 -0
- /package/apps/client/{._VISUAL_RESTORE.md → scripts/._sample-entries.test.mjs} +0 -0
- /package/apps/client/{.tbox-gen/._app-registry.ts → scripts/._storyboard.test.mjs} +0 -0
- /package/apps/client/{.tbox-gen/._manifest.json → scripts/._surface-css.mjs} +0 -0
- /package/apps/client/{.tbox-gen/._registry.client.ts → scripts/._theme-kernel.mjs} +0 -0
- /package/apps/client/{.tbox-gen/._registry.server.ts → scripts/._theme-kernel.test.mjs} +0 -0
- /package/apps/client/{.tbox-gen/documents/._index.html → scripts/lib/._card-registry.mjs} +0 -0
- /package/apps/client/{.tbox-gen/documents/_tbox/._card-preview.html → scripts/lib/._card-registry.test.mjs} +0 -0
- /package/apps/client/{.tbox-gen/entries/._card-preview.tsx → scripts/lib/._evidence-inputs.mjs} +0 -0
- /package/apps/client/{.tbox-gen/entries/._index.tsx → scripts/lib/._evidence-inputs.test.mjs} +0 -0
- /package/{profiles/mall/config/._llm_provider.json → apps/client/scripts/lib/._static-render.mjs} +0 -0
- /package/{profiles/mall/config/._plugins.json → apps/client/scripts/lib/._static-render.test.mjs} +0 -0
- /package/{scripts/._compat-probe.mjs → packages/agent-ui-kit/src/._preview-provider.tsx} +0 -0
- /package/{scripts/._gen-tailwind-sources.mjs → packages/agent-ui-kit/src/._surface.test.tsx} +0 -0
package/docs/agent/verify.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
## T0 做什么
|
|
18
18
|
|
|
19
|
-
1. `pnpm generate`——生成 registry
|
|
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` 全部执行 → 验收项覆盖与裁决。
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"warnings": [{ "id": "card-sample-coverage", "message": "parking-card.status 的状态 [\"paid\"] 没有样例" }],
|
|
31
31
|
"verdict": "deliverable",
|
|
32
32
|
"acceptance": { "items": 3, "covered": 3, "handoff": 0, "uncovered": [] },
|
|
33
|
-
"policy": "
|
|
34
|
-
"coverage": { "logic": "已验证:2 个场景 / 12 步 / 3 项", "visual": "
|
|
33
|
+
"policy": "visual",
|
|
34
|
+
"coverage": { "logic": "已验证:2 个场景 / 12 步 / 3 项", "visual": "未运行:本轮未执行浏览器" },
|
|
35
35
|
"handoff": [],
|
|
36
36
|
"next": "交付条件已满足:总结并结束。不要继续复审或打磨。",
|
|
37
37
|
"notRun": [] }
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
- `verdict` 是交付裁决:`failing` / `incomplete` / `unspecified` / `deliverable`;`next` 就是下一步;
|
|
40
|
+
- `verdict` 是交付裁决:`failing` / `incomplete` / `unspecified` / `deliverable` / `reopened`;`next` 就是下一步;
|
|
41
41
|
- `warnings` 不阻断,但每条都带「修复」提示与配方名;
|
|
42
42
|
- `notRun` 说明哪一步没跑(例如没有场景文件);
|
|
43
43
|
- 失败时输出首个失败步骤的全部错误,每条带 `file:line` 与修复建议。
|
|
@@ -48,21 +48,30 @@
|
|
|
48
48
|
|
|
49
49
|
```jsonc
|
|
50
50
|
{
|
|
51
|
-
// 证据策略:本任务允许验到哪一级(static / visual / flow);缺省
|
|
52
|
-
|
|
51
|
+
// 证据策略:本任务允许验到哪一级(static / visual / flow);缺省 visual
|
|
52
|
+
// 降为 static 必须写 policyReason(用户原话);平台可用 TBOX_POLICY 注入
|
|
53
|
+
"policy": "visual",
|
|
53
54
|
"items": [
|
|
54
55
|
{ "id": "join.reward", "text": "入会后获得 100 积分和一张满100减20券" },
|
|
55
56
|
{ "id": "parking.pay", "text": "用停车券抵 10 元,实付 5 元,得 5 积分" },
|
|
56
|
-
{ "id": "ui.mobile", "text": "
|
|
57
|
-
"
|
|
57
|
+
{ "id": "ui.mobile", "text": "移动端为主,卡片与输入区不溢出", "by": "storyboard",
|
|
58
|
+
"frames": ["card:*@320", "shell.empty@320"] },
|
|
59
|
+
{ "id": "ui.brand", "text": "视觉符合商圈氛围", "by": "handoff",
|
|
60
|
+
"reason": "主观判断,机器只能证明它渲染出来了,不能证明好看" }
|
|
58
61
|
]
|
|
59
62
|
}
|
|
60
63
|
```
|
|
61
64
|
|
|
62
65
|
- 一个验收项算覆盖,当且仅当至少一个**通过**的场景在 `covers` 里列了它;
|
|
66
|
+
- `origin: "recorded"` 的场景(`scenario record` 自动写)只作回归,不单独覆盖验收项;摘要里的 `declared` 是含录制场景的声明覆盖数;
|
|
67
|
+
- `lane: "browser" | "model"` 的验收项直接进 `deferred`,不占 `handoff`、不承诺自动补验;
|
|
63
68
|
- `by: "handoff"`(旧名 `review` 仍可用)表示**当前策略下验不了**,必须写 `reason`;门禁把它列进 `handoff`,
|
|
64
69
|
并在 `next` 里要求原样写进交付说明——它不再是一个「待复审」的邀请;
|
|
65
70
|
- 能由场景判定却标 `handoff` 的项(缺 `reason`)计入 `incomplete`,不能用来绕过覆盖;
|
|
71
|
+
- `by: "storyboard"` 表示界面项由故事板证明:`frames` 列的帧(`pnpm storyboard` 出图,`pnpm deliver` 会自动跑)全部生成且没有几何错误才算覆盖,
|
|
72
|
+
计数单列在 `acceptance.storyboard`,不与场景覆盖混算;任一帧溢出或渲染失败则该项按未覆盖处理。
|
|
73
|
+
主观项(「符合氛围」「好看」)只能写 `handoff`——故事板不判美丑;
|
|
74
|
+
- 故事板判据的阈值与 id 见 [checks 报错表](verify.md) 与 `scripts/checks.json` 的 `frames`/`threshold`:`card.overflow-x`(error)、`card.text-clip`/`card.tap-target`/`card.min-font`(warning)、`storyboard.render`(error);
|
|
66
75
|
- 场景里可写 `expect.state`(对登记状态做子集匹配)验证需求里写明的不变量,例如 `{ "member": true, "points": 100 }`;
|
|
67
76
|
- 场景缺省按文件隔离用户,需要共享时在场景顶层写 `user`。
|
|
68
77
|
|
|
@@ -73,11 +82,18 @@
|
|
|
73
82
|
| `failing` | 有检查失败 | 首个根因与修复建议 |
|
|
74
83
|
| `incomplete` | 检查通过但有未覆盖验收项 | 未覆盖的 id |
|
|
75
84
|
| `unspecified` | 有工具/动作但没写验收项 | 先拆验收项 |
|
|
76
|
-
| `deliverable` | 全部覆盖 | 交付;有 handoff 时先写进交付说明 |
|
|
85
|
+
| `deliverable` | 全部覆盖 | 交付;有 handoff / deferred 时先写进交付说明 |
|
|
86
|
+
| `reopened` | 交付后源码内容又变了 | 重跑确认;只降级一次,不阻断 |
|
|
77
87
|
|
|
78
88
|
摘要里的 `coverage` 给每个维度一个状态(结构 / 逻辑 / 渲染 / 视觉 / 模型路由),`handoff` 是当前策略
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
验不了的清单。档位缺省 `visual`(静态 + 布局车道);应用把档位降到 `static` 必须写 `policyReason`(用户原话),否则门禁按 `visual` 执行并告警。平台可用 `TBOX_POLICY` 注入档位。
|
|
90
|
+
|
|
91
|
+
交付用 `pnpm deliver`:它跑 `check:fast`,输出裁决、未运行项、偏离出厂与验收变更,并生成 `DELIVERY.md`;摘要固定给一行「视觉证据:.tbox/evidence/storyboard.png(N 帧,几何问题 k 个)」。`pnpm verify` 只在发布前由人/CI 跑。
|
|
92
|
+
|
|
93
|
+
`pnpm storyboard`:把壳与每张卡的样例在 390 / 320 两个宽度排成一页长图并同时量几何(溢出、截断、点击区、字号)。源文件没变时命中缓存(<2s);没有 Chrome 记 not-run;帧数超预算时截断并注明。看图即可判断「界面到底长什么样」,不需要起 dev server。
|
|
94
|
+
已经 `deliverable` 之后再跑,`sinceDeliverable` 给出其后的门禁次数与改动文件数;源码内容再变会得到 `reopened`(内容哈希),同一份内容再跑一次恢复 `deliverable`。
|
|
95
|
+
|
|
96
|
+
摘要里的 `delivery` 是交付包:`trace` 逐项覆盖、`facts` 视图卡高度、`drift` 验收/期望漂移、`deferred` 浏览器/模型/未接项。交付时把 `deferred` 原样写进说明。
|
|
81
97
|
|
|
82
98
|
## 试跑
|
|
83
99
|
|
|
@@ -86,7 +102,7 @@ pnpm exec tbox-app probe "join-membership{} action:confirm-join{} query-points{}
|
|
|
86
102
|
pnpm exec tbox-app probe "query-points{}" --user u1 --save points-baseline
|
|
87
103
|
```
|
|
88
104
|
|
|
89
|
-
不带 `--save` 只试跑、不落盘;带 `--save` 把本次真实执行录成 `scenarios/<名称>.json
|
|
105
|
+
不带 `--save` 只试跑、不落盘;带 `--save` 把本次真实执行录成 `scenarios/<名称>.json`,并标记 `origin: "recorded"`——录制场景只作回归,不单独覆盖验收项;验收项请手写 spec 场景并在 `covers` 登记。
|
|
90
106
|
|
|
91
107
|
## 常见报错
|
|
92
108
|
|
|
@@ -108,14 +124,11 @@ pnpm exec tbox-app probe "query-points{}" --user u1 --save points-baseline
|
|
|
108
124
|
| `card-sample-coverage`(告警) | 状态枚举有值没有样例 | 在 samples 里给每个状态各补一条([card](card.md)) |
|
|
109
125
|
| `tool-not-registered`(告警) | 工具 id 不在 registry 里 | 检查是否漏了 export const tool([tool](tool.md)) |
|
|
110
126
|
| `card-emission-hint`(告警) | 出卡工具的 description 未声明会附卡片 | 用 withCardEmissionHint 或在 description 里补「命中数据时结果附可展示卡片(cards)。」([tool-emits-card](tool-emits-card.md)) |
|
|
111
|
-
| `font-too-small`(告警) | 旧 Less 里的设计稿字号低于可读下限 22px | 迁移后应用侧不再写字号:样式用工具类六档字号([style](style.md)) |
|
|
112
|
-
| `color-syntax`(告警) | 用了旧 web-view 不支持的 rgb(r g b / a) 语法 | 改 rgba(r, g, b, a)([style](style.md)) |
|
|
113
127
|
| `styles-entry-missing`(告警) | 没有 apps/client/src/styles/brand.css | 新建 brand.css(只放品牌变量覆写)并在 app.config.ts 里 import(模板出厂自带)([style](style.md)) |
|
|
114
128
|
| `card-client-missing`(错误) | 服务端有卡但客户端没有同名组件 | 补 apps/client/src/cards/<id>.card.tsx(export const card = defineCard({ type: '<id>' }, …))([card](card.md)) |
|
|
115
129
|
| `registry-load-failed`(错误) | .tbox-gen 注册表加载失败 | 跑 pnpm generate 重新生成 .tbox-gen([verify](verify.md)) |
|
|
116
130
|
| `palette-color`(错误) | 用了 Tailwind 默认调色板(不生成 CSS) | 换成语义色 `text-foreground` / `bg-card` / `border-border`([style](style.md)) |
|
|
117
|
-
| `
|
|
118
|
-
| `font-size-off-scale`(错误) | 字号越档(只有 12/14/16/18/20/24/30 六档) | 用 `text-xs/sm/base/lg/xl/2xl/3xl`([style](style.md)) |
|
|
131
|
+
| `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)) |
|
|
119
132
|
| `class-before-interpolation`(错误) | 类名紧贴 `${`,扫描器拿不到完整候选(样式静默不生效) | 在 `${` 前留空格:`text-xs ${cond ? … : …}`([style](style.md)) |
|
|
120
133
|
| `element-asset-declaration`(错误) | 在元素上声明 `--tbox-asset-*`(截断主题覆写继承) | 素材变量归主题包,元素只消费 `var(--tbox-asset-*, 兜底)`([style](style.md)) |
|
|
121
134
|
| `handoff-misuse`(告警) | handoff 项没有 reason(可能借移交绕过覆盖) | 补 reason 说明当前策略为什么验不了,或补一条场景并写 covers([verify](verify.md)) |
|
|
@@ -124,6 +137,36 @@ pnpm exec tbox-app probe "query-points{}" --user u1 --save points-baseline
|
|
|
124
137
|
| `render-identical`(告警) | 同一卡片的多份样例渲染结果完全相同 | 给不同状态不同的可见内容,或删掉重复样例([card](card.md)) |
|
|
125
138
|
| `tool-description-empty`(告警) | 工具 description 为空 | 写「什么时候用」,不要写「做什么」([tool](tool.md)) |
|
|
126
139
|
| `tool-description-duplicate`(告警) | 两个工具的 description 完全相同 | 让两个工具的描述各自说明触发场景([tool](tool.md)) |
|
|
140
|
+
| `boot.inline-script`(错误) | 入口 HTML 有内联脚本(解析期执行,body 可能还是 null) | 删掉内联脚本;启动逻辑放打包后的模块里([verify](verify.md)) |
|
|
141
|
+
| `shell.identity`(错误) | 发送者名写死「AI 助手」,已配置的身份没用上 | 从 chat.json identity.name 取,缺省再回落([shell](shell.md)) |
|
|
142
|
+
| `shell.type-scale`(错误) | 写了档外字号(text-[13px] 之类) | 用 12/14/16/18/20/24/30/36 档:正文 16、卡片正文 14、说明 12([style](style.md)) |
|
|
143
|
+
| `css.sentinel`(错误) | 证据 CSS 为空、缺模块源码或模块类未生成 | 确认 `vite.config.ts` 的 `tboxModuleSourcesPlugin` 在 `tailwindcss()` 之前;证据与 dev/build 共用 app-build 的 `collectModuleSourceDirs`([style](style.md)) |
|
|
144
|
+
| `card.states`(错误) | 卡片历史态渲染失败或为空 | 用 isHistory 只禁用动作,不隐藏内容([card](card.md)) |
|
|
145
|
+
| `shell.hit-target`(错误) | 可交互元素命中区小于 44px | 用 kit 按钮与 min-h-11;视觉尺寸可小,命中区要足([shell](shell.md)) |
|
|
146
|
+
| `shell.quick-visible`(错误) | 空态快捷问题没有全部可见(横向溢出或贴底) | 空态用两列 grid,对话态才用单行([shell](shell.md)) |
|
|
147
|
+
| `flow.persist`(告警) | 状态没有跨进程重启验证 | 用 createUserState({ persist: "file" }) 并加重启探针([state](state.md)) |
|
|
148
|
+
| `shell.contrast`(错误) | 令牌对比度低于阈值(文字看不清) | 调 brand.css 的令牌值;color-mix 派生的由浏览器车道补验([style](style.md)) |
|
|
149
|
+
| `shell.blank`(错误) | 内容块之间空白过大(看起来没做完) | 空态成组居中、补服务入口;只算块间空白,不算首尾对称留白([shell](shell.md)) |
|
|
150
|
+
| `card.height`(错误) | 视图卡过高(一屏放不下) | 按预算减积木或拆卡;详情用单独的卡承接([card](card.md)) |
|
|
151
|
+
| `CARD_TYPE_INVALID`(错误) | 卡片类型含路径分隔符或非法字符 | 改成小写 kebab(字母/数字/点/下划线/中划线),不要用 ../ 或斜杠([card](card.md)) |
|
|
152
|
+
| `shell.icon-render`(错误) | 快捷问题图标不可见(遮罩失效或节点被隐藏) | 修正 maskImage 引号或改用可见元素;应用自绘图标时保证按钮内有可见内容([shell](shell.md)) |
|
|
153
|
+
| `shell.controls-semantic`(错误) | 核心控件不是 button/a(键盘与读屏不可用) | 用 button + aria-label + focus-visible;保留原类名([shell](shell.md)) |
|
|
154
|
+
| `shell.control-present`(错误) | 能力开启但对应控件不可见 | 按能力配置渲染控件;关闭能力时才隐藏([shell](shell.md)) |
|
|
155
|
+
| `shell.a11y-name`(错误) | 控件缺可访问名 | aria-label 或可见文本([shell](shell.md)) |
|
|
156
|
+
| `meta.brand`(告警) | 页面标题/主题色未跟品牌 | 由 identity 注入 title 与 theme-color([shell](shell.md)) |
|
|
157
|
+
| `quick.label-query`(告警) | 快捷问题按钮文案与发送文本不一致 | query 缺省等于 label,或让 query 包含 label([shell](shell.md)) |
|
|
158
|
+
| `card.action-primary`(告警) | 卡片动作无主次 | 第一个动作 primary,其余 secondary([card](card.md)) |
|
|
159
|
+
| `kit.color-literal`(告警) | kit 样式里出现令牌之外的颜色字面量 | 改用主题令牌(标签色随主色派生)([style](style.md)) |
|
|
160
|
+
| `style.url-quoted`(告警) | 样式里的 url() 未加引号,data URI 会被 CSSOM 拒绝 | 写 url("…")([style](style.md)) |
|
|
161
|
+
| `checks.registry`(错误) | checks.json 登记了门禁未实现的检查项 | 补实现或删登记;sync-check-docs 会同步报错表([verify](verify.md)) |
|
|
162
|
+
| `shell.turn-visible`(错误) | 新回合把问题顶出视口,用户看不到自己在问什么 | 修回合锚定与浮标;不要用定时器追底([shell](shell.md)) |
|
|
163
|
+
| `shell.console-clean`(错误) | 水合时控制台出现告警/错误(重复注册、未知属性、SSR 警告) | 按告警修源头;不要静音 console([shell](shell.md)) |
|
|
164
|
+
| `storyboard.render`(错误) | 故事板渲染失败(帧没跑完) | 看 storyboard.json 的 reason;多为样例数据不合 schema 或 Chrome 未就绪([verify](verify.md)) |
|
|
165
|
+
| `card.overflow-x`(错误) | 卡片在窄屏横向溢出 | 去掉定宽;长文本允许换行(break-words),图片用 max-w-full([card](card.md)) |
|
|
166
|
+
| `card.text-clip`(告警) | 文本被容器截断且没有省略号 | 加 truncate(省略号)或允许换行;数字与金额不要截断([card](card.md)) |
|
|
167
|
+
| `card.tap-target`(告警) | 卡片上的按钮点击区小于 44px | 用 kit Button;视觉尺寸小时给外层留 min-h-11([card](card.md)) |
|
|
168
|
+
| `card.min-font`(告警) | 卡片里有小于 12px 的文字 | 用 text-xs 及以上;次要信息降级不如减少信息([card](card.md)) |
|
|
169
|
+
| `style.color-repeat`(告警) | 同一色值在卡片/组件里出现 3 次以上(该进令牌) | 换成语义类;确需新色就写进 brand.css 的令牌,再用 bg-[var(--tbox-*)] 或语义类([style](style.md)) |
|
|
127
170
|
<!-- check-docs:errors end -->
|
|
128
171
|
|
|
129
172
|
## 用户说「不要测试」时
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-template-agent",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
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,18 +48,23 @@
|
|
|
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.
|
|
45
|
-
"@tbox.cn/app-build": "1.0.0-alpha.
|
|
46
|
-
"@tbox.cn/app-cli": "1.0.0-alpha.
|
|
51
|
+
"@tbox.cn/app-sdk-server": "1.0.0-alpha.9",
|
|
52
|
+
"@tbox.cn/app-build": "1.0.0-alpha.9",
|
|
53
|
+
"@tbox.cn/app-cli": "1.0.0-alpha.9"
|
|
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",
|
|
55
|
-
"generate": "node scripts/
|
|
67
|
+
"generate": "node scripts/generate.mjs",
|
|
56
68
|
"build": "pnpm check && pnpm generate && pnpm --filter ./apps/server build && pnpm --filter ./apps/client build && node scripts/check-css-target.mjs",
|
|
57
69
|
"build:client": "pnpm check && pnpm generate && pnpm --filter ./apps/client build",
|
|
58
70
|
"typecheck": "pnpm generate && pnpm -r --filter \"./{apps,packages,modules}/*\" typecheck",
|
|
@@ -64,13 +76,15 @@
|
|
|
64
76
|
"verify:generated": "node scripts/verify-generated.mjs",
|
|
65
77
|
"check": "pnpm check:workspace && pnpm check:inspector",
|
|
66
78
|
"check:fast": "node scripts/check-fast.mjs",
|
|
79
|
+
"deliver": "node scripts/deliver.mjs",
|
|
80
|
+
"probe:shell": "node scripts/shell-probe.mjs",
|
|
67
81
|
"check:css": "node scripts/check-css-target.mjs",
|
|
68
|
-
"compat:probe": "node scripts/compat-probe.mjs",
|
|
69
82
|
"scenario": "pnpm --filter ./apps/server exec node --import tsx scripts/scenario.mjs",
|
|
70
83
|
"card:render": "pnpm --filter ./apps/client exec node scripts/render-card.mjs",
|
|
71
84
|
"check:workspace": "node scripts/check-workspace.mjs",
|
|
72
85
|
"check:inspector": "tbox-inspector-check",
|
|
73
86
|
"plugin:inspect": "pnpm --filter ./apps/server exec node --import tsx src/cli/plugin-inspect.ts",
|
|
74
|
-
"plugin:doctor": "pnpm --filter ./apps/server exec node --import tsx src/cli/plugin-doctor.ts"
|
|
87
|
+
"plugin:doctor": "pnpm --filter ./apps/server exec node --import tsx src/cli/plugin-doctor.ts",
|
|
88
|
+
"storyboard": "node scripts/storyboard.mjs"
|
|
75
89
|
}
|
|
76
90
|
}
|
|
@@ -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.css
|
|
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`。
|
|
@@ -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.
|
|
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`,避免引入完整聊天壳。
|
|
@@ -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
|
},
|
|
@@ -398,7 +404,7 @@
|
|
|
398
404
|
},
|
|
399
405
|
{
|
|
400
406
|
"name": "tone",
|
|
401
|
-
"type": "'primary' | 'warm' | 'jade' | 'neutral'",
|
|
407
|
+
"type": "'primary' | 'warm' | 'jade' | 'inverse' | 'neutral'",
|
|
402
408
|
"optional": true
|
|
403
409
|
}
|
|
404
410
|
]
|
|
@@ -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.
|
|
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
|
"scripts": {
|
|
Binary file
|
|
@@ -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
|
-
|
|
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
|
-
//
|
|
265
|
+
// 回合锚定:新回合把本轮用户消息置顶,流式期间不追底。
|
|
266
|
+
// 贴底滚动会把问题顶出视口(实测卡片 648px 时问题上移 244px),用户看不到自己在问什么。
|
|
267
|
+
const turnAnchorRef = useRef<string | null>(null);
|
|
245
268
|
useEffect(() => {
|
|
246
|
-
const
|
|
247
|
-
if (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
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
|
-
|
|
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=
|
|
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-
|
|
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
|
-
|
|
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}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -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
|
+
});
|