@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
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* Tailwind 入口(S1):只引 theme 与 utilities,不引 preflight——宿主与三方样式不受重置影响。
|
|
3
3
|
*
|
|
4
4
|
* - 主题值经 `@theme inline` 直接投影到 `--tbox-*`:工具类产物是 `var(--tbox-*)`,子树覆写照常生效;
|
|
5
|
-
* - `source(none)` + 显式 @source:只扫应用源码与 kit
|
|
6
|
-
*
|
|
5
|
+
* - `source(none)` + 显式 @source:只扫应用源码与 kit;模块源码由客户端 Vite 插件
|
|
6
|
+
* `@tbox.cn/app-build` 的 tboxModuleSourcesPlugin 在编译期追加,证据包走同一发现函数;
|
|
7
|
+
* - 组件样式全部走工具类与语义令牌,没有 Less,也没有 rem 换算。
|
|
7
8
|
*/
|
|
8
9
|
/* 显式层序:kit 的 base.css 与模块基座进 base 层,工具类恒在最后 */
|
|
9
10
|
@layer theme, base, components, utilities;
|
|
@@ -13,9 +14,6 @@
|
|
|
13
14
|
|
|
14
15
|
@source "../../src";
|
|
15
16
|
@source "../../../../packages/agent-ui-kit/src";
|
|
16
|
-
/* @tbox:module-sources:begin */
|
|
17
|
-
/* 未安装客户端模块 */
|
|
18
|
-
/* @tbox:module-sources:end */
|
|
19
17
|
|
|
20
18
|
@theme inline {
|
|
21
19
|
/* 颜色:清空默认调色板,只留契约里的语义名 */
|
|
@@ -27,6 +25,7 @@
|
|
|
27
25
|
--color-muted-foreground: var(--tbox-text-muted);
|
|
28
26
|
--color-secondary-foreground: var(--tbox-text-secondary);
|
|
29
27
|
--color-primary: var(--tbox-primary);
|
|
28
|
+
--color-primary-dark: var(--tbox-primary-dark);
|
|
30
29
|
--color-primary-foreground: var(--tbox-primary-light);
|
|
31
30
|
--color-accent: var(--tbox-accent);
|
|
32
31
|
--color-border: var(--tbox-border);
|
|
@@ -37,24 +36,25 @@
|
|
|
37
36
|
/* 主色上的文字:契约暂无对应项,先给纯白(E3 语义色) */
|
|
38
37
|
--color-white: #ffffff;
|
|
39
38
|
--color-scrim: rgba(0, 0, 0, 0.45);
|
|
40
|
-
|
|
39
|
+
/* 浅色底由主色派生:换品牌色后不再残留固定蓝。 */
|
|
40
|
+
--color-primary-soft: color-mix(in srgb, var(--tbox-primary) 8%, var(--tbox-bg-card));
|
|
41
41
|
--color-warm: var(--tbox-bg-warm);
|
|
42
42
|
--color-jade: var(--tbox-domain-parking-surface);
|
|
43
|
-
--color-success-soft: var(--tbox-success-
|
|
44
|
-
--color-warning-soft: var(--tbox-warning
|
|
45
|
-
--color-neutral-soft:
|
|
46
|
-
--color-warn-surface: #
|
|
47
|
-
--color-warn-border: #
|
|
48
|
-
--color-warn-ink: #
|
|
43
|
+
--color-success-soft: color-mix(in srgb, var(--tbox-success) 10%, var(--tbox-bg-card));
|
|
44
|
+
--color-warning-soft: color-mix(in srgb, var(--tbox-warning, #d98a1a) 12%, var(--tbox-bg-card));
|
|
45
|
+
--color-neutral-soft: color-mix(in srgb, var(--tbox-text-primary) 6%, var(--tbox-bg-card));
|
|
46
|
+
--color-warn-surface: color-mix(in srgb, var(--tbox-warning, #d98a1a) 8%, var(--tbox-bg-card));
|
|
47
|
+
--color-warn-border: color-mix(in srgb, var(--tbox-warning, #d98a1a) 28%, var(--tbox-bg-card));
|
|
48
|
+
--color-warn-ink: color-mix(in srgb, var(--tbox-warning, #d98a1a) 72%, var(--tbox-ink));
|
|
49
49
|
--color-white-soft: rgba(255, 255, 255, 0.04);
|
|
50
|
-
--color-danger-soft:
|
|
51
|
-
--color-danger-border:
|
|
50
|
+
--color-danger-soft: color-mix(in srgb, var(--tbox-error) 8%, var(--tbox-bg-card));
|
|
51
|
+
--color-danger-border: color-mix(in srgb, var(--tbox-error) 30%, var(--tbox-bg-card));
|
|
52
52
|
--color-white-line: rgba(255, 255, 255, 0.35);
|
|
53
53
|
--color-white-dim: rgba(255, 255, 255, 0.84);
|
|
54
54
|
--color-member-accent: #91ad60;
|
|
55
|
-
--color-focus-ring:
|
|
55
|
+
--color-focus-ring: color-mix(in srgb, var(--tbox-primary) 45%, transparent);
|
|
56
56
|
|
|
57
|
-
/* 圆角:先清空命名空间再用 px
|
|
57
|
+
/* 圆角:先清空命名空间再用 px 补齐(默认档位是 rem,统一改成物理 px)。
|
|
58
58
|
sm/md/lg 来自契约(lg = 卡框 24px),其余档位是物理 px 的常规阶梯。 */
|
|
59
59
|
--radius-*: initial;
|
|
60
60
|
--radius-xs: 4px;
|
|
@@ -71,9 +71,8 @@
|
|
|
71
71
|
--shadow-md: var(--tbox-shadow-md);
|
|
72
72
|
--shadow-lg: var(--tbox-shadow-lg);
|
|
73
73
|
|
|
74
|
-
/* 间距:1 单位 = 4px
|
|
75
|
-
|
|
76
|
-
/* 断点用 px:默认档位是 rem,会被宿主入口的动态根字号放大(40rem 会变成 2000px) */
|
|
74
|
+
/* 间距:1 单位 = 4px,全部物理 px(默认档位是 rem,统一改成 px)。 */
|
|
75
|
+
/* 断点用 px(默认档位是 rem) */
|
|
77
76
|
--breakpoint-sm: 640px;
|
|
78
77
|
--breakpoint-md: 768px;
|
|
79
78
|
--breakpoint-lg: 1024px;
|
|
@@ -82,7 +81,7 @@
|
|
|
82
81
|
|
|
83
82
|
--spacing: 4px;
|
|
84
83
|
|
|
85
|
-
/* 字号同样先清空命名空间再用 px 补齐(默认档位是 rem
|
|
84
|
+
/* 字号同样先清空命名空间再用 px 补齐(默认档位是 rem);档位 12/14/16/18/20/24/30/36。 */
|
|
86
85
|
--text-*: initial;
|
|
87
86
|
--text-xs: 12px;
|
|
88
87
|
--text-xs--line-height: 1.5;
|
|
@@ -220,7 +219,7 @@
|
|
|
220
219
|
}
|
|
221
220
|
|
|
222
221
|
/* 模块动效关键帧集中登记(模块迁 Tailwind 后不再随模块 CSS 出货)。
|
|
223
|
-
值为物理 px
|
|
222
|
+
值为物理 px。 */
|
|
224
223
|
@keyframes member-points-rule-backdrop-in {
|
|
225
224
|
from { opacity: 0; }
|
|
226
225
|
to { opacity: 1; }
|
|
@@ -8,7 +8,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
8
8
|
// 平台微调配套 babel plugin(随 @tbox.cn/app-sdk 分发):给每个 JSX 注入 data-code-inspect-*
|
|
9
9
|
// 源码位置属性,供 inspector runtime(/__vs_inspector__.js) 点选元素→定位源码。仅 dev 启用(见下)。
|
|
10
10
|
import codeInspectPlugin from '@tbox.cn/app-agent-sdk-client/platform/code-inspect';
|
|
11
|
-
import { tboxAppPlugin } from '@tbox.cn/app-build';
|
|
11
|
+
import { tboxAppPlugin, tboxModuleSourcesPlugin } from '@tbox.cn/app-build';
|
|
12
12
|
|
|
13
13
|
export default defineConfig(async ({ command }) => {
|
|
14
14
|
// tbox-app-dev dev 探测行(dev 探针常量;构件区在位时启用原地装配改指,缺席零行为变化。
|
|
@@ -31,6 +31,7 @@ export default defineConfig(async ({ command }) => {
|
|
|
31
31
|
}
|
|
32
32
|
return {
|
|
33
33
|
plugins: [
|
|
34
|
+
tboxModuleSourcesPlugin({ appRoot: resolve(__dirname, '../..') }),
|
|
34
35
|
tboxAppPlugin({ root: resolve(__dirname, '../..') }),
|
|
35
36
|
tailwindcss(),
|
|
36
37
|
react({
|
|
@@ -81,6 +81,7 @@ function readArgs(argv) {
|
|
|
81
81
|
else if (arg === '--record') out.record = take();
|
|
82
82
|
else if (arg === '--steps') out.steps = take();
|
|
83
83
|
else if (arg === '--expect') out.expect = take();
|
|
84
|
+
else if (arg === '--keep') out.keep = take();
|
|
84
85
|
else if (arg.startsWith('-')) throw new Error(`未知参数:${arg}`);
|
|
85
86
|
else out._.push(arg);
|
|
86
87
|
}
|
|
@@ -327,7 +328,11 @@ async function runRecord(args) {
|
|
|
327
328
|
|
|
328
329
|
let scenario;
|
|
329
330
|
try {
|
|
330
|
-
|
|
331
|
+
const keep = (args.keep ?? '').split(',').map((key) => key.trim()).filter(Boolean);
|
|
332
|
+
scenario = await recordScenario({ registry, name: args.record, steps, keep });
|
|
333
|
+
if (scenario.volatile?.length) {
|
|
334
|
+
console.warn('⚠️ 已从期望里剔除易变值(--keep 可保留):' + scenario.volatile.join('、'));
|
|
335
|
+
}
|
|
331
336
|
} catch (error) {
|
|
332
337
|
throw new Error(`录制执行失败:${error?.message ?? error}`);
|
|
333
338
|
}
|
|
@@ -186,11 +186,12 @@ export async function runScenarios({ appDir, registry, files }) {
|
|
|
186
186
|
* 录制:顺序执行每一步并把实际出参写成期望(只保留 `keys` 指定的键,缺省全部)。
|
|
187
187
|
* 返回可直接写入 `scenarios/<name>.json` 的对象。
|
|
188
188
|
*/
|
|
189
|
-
export async function recordScenario({ registry, name, steps, user }) {
|
|
189
|
+
export async function recordScenario({ registry, name, steps, user, keep = [] }) {
|
|
190
190
|
const { createToolHarness } = await import('@tbox.cn/app-agent-sdk-server/testing');
|
|
191
191
|
const harness = createToolHarness({ registry });
|
|
192
192
|
const scenarioUser = typeof user === 'string' ? user : `scenario:${name}`;
|
|
193
|
-
|
|
193
|
+
// 录制产物标记来源:验收闩不允许 recorded 场景单独覆盖验收项。
|
|
194
|
+
const out = { name, user: scenarioUser, origin: 'recorded', steps: [] };
|
|
194
195
|
for (const step of steps) {
|
|
195
196
|
const kind = step.action ? 'action' : 'tool';
|
|
196
197
|
const id = step.action ?? step.tool;
|
|
@@ -202,30 +203,77 @@ export async function recordScenario({ registry, name, steps, user }) {
|
|
|
202
203
|
if (kind === 'action') {
|
|
203
204
|
const result = await harness.act(id, step.input ?? {}, ctx);
|
|
204
205
|
const state = changedLeaves(before, mergedState(harness, stepUser));
|
|
206
|
+
const expected = stripVolatile({ result: pick(result, step.keys), ...(Object.keys(state).length > 0 ? { state } : {}) }, { keep });
|
|
207
|
+
if (expected.removed.length > 0) out.volatile = [...(out.volatile ?? []), ...expected.removed];
|
|
205
208
|
out.steps.push({
|
|
206
209
|
action: id,
|
|
207
210
|
...(step.input ? { input: step.input } : {}),
|
|
208
211
|
...(step.user ? { user: step.user } : {}),
|
|
209
|
-
expect:
|
|
212
|
+
expect: expected.value,
|
|
210
213
|
});
|
|
211
214
|
continue;
|
|
212
215
|
}
|
|
213
216
|
const result = await harness.call(id, step.input ?? {}, ctx);
|
|
214
217
|
const state = changedLeaves(before, mergedState(harness, stepUser));
|
|
218
|
+
const expected = stripVolatile({
|
|
219
|
+
output: pick(result.output, step.keys),
|
|
220
|
+
...(result.cards.length > 0 ? { cards: result.cards.map((card) => card.cardType) } : {}),
|
|
221
|
+
...(Object.keys(state).length > 0 ? { state } : {}),
|
|
222
|
+
}, { keep });
|
|
223
|
+
if (expected.removed.length > 0) out.volatile = [...(out.volatile ?? []), ...expected.removed];
|
|
215
224
|
out.steps.push({
|
|
216
225
|
tool: id,
|
|
217
226
|
...(step.input ? { input: step.input } : {}),
|
|
218
227
|
...(step.user ? { user: step.user } : {}),
|
|
219
|
-
expect:
|
|
220
|
-
output: pick(result.output, step.keys),
|
|
221
|
-
...(result.cards.length > 0 ? { cards: result.cards.map((card) => card.cardType) } : {}),
|
|
222
|
-
...(Object.keys(state).length > 0 ? { state } : {}),
|
|
223
|
-
},
|
|
228
|
+
expect: expected.value,
|
|
224
229
|
});
|
|
225
230
|
}
|
|
226
231
|
return out;
|
|
227
232
|
}
|
|
228
233
|
|
|
234
|
+
/** 易变字段:时间戳/UUID/透明 id。录制期望时剔除,避免「今天过、明天挂」。 */
|
|
235
|
+
const VOLATILE_KEY = /(^|_)(id|timestamp|time|createdat|updatedat|uuid|guid|nonce|token|sessionid|traceid|requestid|messageid)$/i;
|
|
236
|
+
const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})$/;
|
|
237
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
238
|
+
const HEX32 = /^[0-9a-f]{32}$/i;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 剔除期望里的易变值(录制稳定化):键名命中时间/id 词,或值形如 ISO 时间/UUID/32 位哈希。
|
|
242
|
+
* 数组不拆元素(拆了会改变长度语义),整体命中才剔除;--keep 可逐项豁免。
|
|
243
|
+
*/
|
|
244
|
+
export function stripVolatile(value, options = {}) {
|
|
245
|
+
const keep = new Set(options.keep ?? []);
|
|
246
|
+
const removed = [];
|
|
247
|
+
const walk = (node, path) => {
|
|
248
|
+
if (Array.isArray(node)) {
|
|
249
|
+
if (node.some((item) => typeof item === 'string' && (ISO_TIME.test(item) || UUID.test(item)))) {
|
|
250
|
+
removed.push(path);
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
return node.map((item, index) => walk(item, path + '[' + index + ']'));
|
|
254
|
+
}
|
|
255
|
+
if (node !== null && typeof node === 'object') {
|
|
256
|
+
const out = {};
|
|
257
|
+
for (const [key, child] of Object.entries(node)) {
|
|
258
|
+
const childPath = path ? path + '.' + key : key;
|
|
259
|
+
if (!keep.has(key) && VOLATILE_KEY.test(key)) {
|
|
260
|
+
removed.push(childPath);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const next = walk(child, childPath);
|
|
264
|
+
if (next !== undefined) out[key] = next;
|
|
265
|
+
}
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
if (typeof node === 'string' && (ISO_TIME.test(node) || UUID.test(node) || HEX32.test(node))) {
|
|
269
|
+
removed.push(path);
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
return node;
|
|
273
|
+
};
|
|
274
|
+
return { value: walk(value, ''), removed };
|
|
275
|
+
}
|
|
276
|
+
|
|
229
277
|
/**
|
|
230
278
|
* 前后状态的顶层差异:录制 expect.state 用。
|
|
231
279
|
* 取整段顶层值(对象/数组原样),与 `diffPath` 的子集语义兼容——不写点号键。
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* 运行:`pnpm scenario [文件或目录…]`(根脚本转发到本文件;SDK 从 apps/server 依赖解析)。
|
|
9
9
|
*/
|
|
10
10
|
import path from 'node:path';
|
|
11
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
11
12
|
import process from 'node:process';
|
|
12
13
|
import { resolveScenarioFiles, runScenarios } from './scenario-lib.mjs';
|
|
13
14
|
|
|
@@ -22,12 +23,45 @@ if (files.length === 0) {
|
|
|
22
23
|
const { registry } = await import(path.join(appDir, 'apps/client/.tbox-gen/registry.server.ts'));
|
|
23
24
|
const result = await runScenarios({ appDir, registry, files });
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// 人读输出有预算:失败优先、整体 ≤2000 字符;完整结果落 .tbox/logs/scenario.log 并给出路径。
|
|
27
|
+
// --json 只出摘要 JSON(机器消费),--full 直出全部失败行。
|
|
28
|
+
const full = process.argv.includes('--full');
|
|
29
|
+
const jsonOnly = process.argv.includes('--json');
|
|
30
|
+
const MAX_CHARS = 2000;
|
|
31
|
+
const summary = { ok: result.ok, scenarios: result.scenarios, failed: result.failed, tools: result.tools, cards: result.cards };
|
|
32
|
+
|
|
33
|
+
const failedResults = result.results.filter((item) => !item.ok);
|
|
34
|
+
const failureLines = [];
|
|
35
|
+
for (const item of failedResults) {
|
|
36
|
+
failureLines.push(`✗ ${item.scenario}(${item.steps} 步)`);
|
|
37
|
+
for (const line of item.failures) failureLines.push(` - ${line}`);
|
|
38
|
+
}
|
|
39
|
+
const allFailures = result.results.flatMap((item) => item.failures.map((line) => `${item.scenario}: ${line}`));
|
|
40
|
+
let logPath;
|
|
41
|
+
if (failureLines.length > 0 || !jsonOnly) {
|
|
42
|
+
try {
|
|
43
|
+
const dir = path.join(appDir, '.tbox/logs');
|
|
44
|
+
mkdirSync(dir, { recursive: true });
|
|
45
|
+
logPath = path.join(dir, 'scenario.log');
|
|
46
|
+
writeFileSync(logPath, JSON.stringify({ summary, results: result.results }, null, 2) + '\n', 'utf8');
|
|
47
|
+
} catch { /* 只读环境不阻断 */ }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!jsonOnly && failureLines.length > 0) {
|
|
51
|
+
const bounded = [];
|
|
52
|
+
let used = 0;
|
|
53
|
+
for (const line of failureLines) {
|
|
54
|
+
if (!full && used + line.length + 1 > MAX_CHARS - 120) {
|
|
55
|
+
bounded.push(' …(还有 ' + (failureLines.length - bounded.length) + ' 行,全文见 ' + (logPath ? path.relative(appDir, logPath) : '上文') + ')');
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
bounded.push(line);
|
|
59
|
+
used += line.length + 1;
|
|
60
|
+
}
|
|
61
|
+
console.error(bounded.join('\n'));
|
|
62
|
+
}
|
|
63
|
+
console.log(JSON.stringify(summary));
|
|
64
|
+
if (!jsonOnly && !full && logPath && failureLines.length > 0) {
|
|
65
|
+
console.log('全文:' + path.relative(appDir, logPath) + '(--full 直出失败行)');
|
|
29
66
|
}
|
|
30
|
-
console.log(
|
|
31
|
-
JSON.stringify({ ok: result.ok, scenarios: result.scenarios, failed: result.failed, tools: result.tools, cards: result.cards }),
|
|
32
|
-
);
|
|
33
67
|
if (!result.ok) process.exitCode = 1;
|
package/config/AGENTS.md
CHANGED
package/config/chat.json
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"
|
|
2
|
+
"identity": {
|
|
3
|
+
"name": "悦享里",
|
|
4
|
+
"tagline": "商圈智能服务"
|
|
5
|
+
},
|
|
6
|
+
"welcome": {
|
|
7
|
+
"title": "今天想逛点什么?",
|
|
8
|
+
"subtitle": "停车、入会、积分、商户、导航、活动和优惠券都能问我"
|
|
9
|
+
},
|
|
10
|
+
"retryOnError": true,
|
|
7
11
|
"quickCommands": [
|
|
8
12
|
{
|
|
9
|
-
"label": "
|
|
10
|
-
"query": "
|
|
13
|
+
"label": "停车缴费",
|
|
14
|
+
"query": "我要停车缴费"
|
|
11
15
|
},
|
|
12
16
|
{
|
|
13
|
-
"label": "
|
|
14
|
-
"query": "
|
|
17
|
+
"label": "碰一下入会",
|
|
18
|
+
"query": "我要碰一下入会"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"label": "推荐一家餐厅",
|
|
22
|
+
"query": "推荐一家餐厅"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"label": "今天有什么活动",
|
|
26
|
+
"query": "今天有什么活动"
|
|
15
27
|
}
|
|
16
28
|
]
|
|
17
29
|
}
|
|
@@ -20,7 +20,7 @@ pnpm exec tbox-app schema config/chat.json
|
|
|
20
20
|
- 首行写身份句(「你是谁、服务谁」),随后按「服务范围 / 业务规则 / 沟通风格」分段。
|
|
21
21
|
- 数据类问题一律要求「先调工具拿本轮结果再回答」,不要凭历史结论作答。
|
|
22
22
|
- 操作类流程写清楚三类动作:什么时候只给信息、什么时候出确认卡、什么时候执行。
|
|
23
|
-
-
|
|
23
|
+
- 按钮语义要写明:「卡片按钮优先走确定性动作(invoke),不需要模型再判断;只有需要模型补充信息时才走发消息(send)。收到动作结果直接执行,不要重复追问」——否则模型会把每个按钮都当成一轮对话。
|
|
24
24
|
|
|
25
25
|
## 对话配置
|
|
26
26
|
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
> 本页管:卡片按钮的两种语义(发消息 / 触发动作)、确认弹层、禁用规则、动作的入参与返回值。|不管:卡片结构 → [card](card.md);工具出卡 → [tool-emits-card](tool-emits-card.md);基元 props → [kit](kit.md)。
|
|
4
4
|
|
|
5
|
+
> 视图卡的动作与三件套同形:`invoke` / `send` / `confirm` 写在 `view()` 的 `actions` 里,确认弹层、禁用与历史态由平台统一处理。
|
|
6
|
+
> 自己渲染动作的卡(`ActionList`)在 `defineCard` 里写 `actions: 'self'`;不写时 SDK 默认按钮条照旧渲染,容易出现两条动作。
|
|
7
|
+
|
|
5
8
|
## 两种按钮
|
|
6
9
|
|
|
7
10
|
`useCardActions()` 给两个方法:
|
|
@@ -24,6 +27,8 @@
|
|
|
24
27
|
|
|
25
28
|
按钮的 `disabled` 一定要接这个值,否则用户会在错误时机触发写操作。
|
|
26
29
|
|
|
30
|
+
`ActionList` 点击后进入 pending:同一张卡只允许一次在途(连点同 tick 也只执行一次),生成结束自动解除,20 秒兜底。手写按钮时用本地 pending 并把 `disabled` 一并接上。
|
|
31
|
+
|
|
27
32
|
## 令牌
|
|
28
33
|
|
|
29
34
|
`invoke` 需要动作令牌:卡片 payload 的 `actionTokens[actionId]`,由服务端在出卡时签发,随卡片数据传给组件(`CardRenderProps.actionTokens`)。没有令牌时 `invoke` 只提示「该操作不可用」——说明这张卡上的该动作没有注册或没有签发。
|
package/docs/agent/card.md
CHANGED
|
@@ -1,8 +1,51 @@
|
|
|
1
1
|
# 新增一张卡片
|
|
2
2
|
|
|
3
|
-
>
|
|
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
|
+
- `hero` 的 `tone`:`primary`(缺省)/ `warm` / `jade` / `inverse`。**要深色主视觉(金额、路线、会员等级)用 `inverse`**——它用 `--tbox-primary-dark` 底 + `--tbox-primary-light` 字,对比度由门禁 `shell.contrast` 兜底;不要为了深色底去写 `bg-[#173F33]` 这类字面量(`style.color-repeat` 会点名)。
|
|
39
|
+
- 预算写进 schema:积木 ≤4、提示 ≤1、属性 ≤5、列表 ≤3、账单行 ≤8、步骤 ≤5、时间线 ≤6、标签 ≤6、卡级动作 ≤2;作者期 `defineViewCard` 直接报错,生产侧 `cardOfView` 先截断再校验,不整张卡丢弃。
|
|
40
|
+
- 样例由 `sampleState` 与 `samples` 派生,不用手写大段 `sampleData`。
|
|
41
|
+
- 出卡用 `cardOfView(card, domainData, note)`:它先跑 `view()`,再走统一的出卡校验。
|
|
42
|
+
- `pnpm exec tbox-app new card <name> --view` 直接生成视图卡单文件;不带 `--view` 才生成三件套(仅富交互卡)。
|
|
43
|
+
- `pnpm exec tbox-app new feature <name> --view` 生成视图卡竖切(工具用 `cardOfView` 出卡);不带 `--view` 才是三件套起手(工具返回 `cards`)。
|
|
44
|
+
- 卡片自己渲染动作(`ActionList` / `ViewCard`)时,`defineCard` 必须写 `actions: 'self'`,否则 SDK 默认按钮条会叠加;不写动作的卡保持默认 `auto`。
|
|
45
|
+
|
|
46
|
+
### 三件套(仅富交互卡)
|
|
47
|
+
|
|
48
|
+
一张卡要有三样东西:
|
|
6
49
|
|
|
7
50
|
| 位置 | 文件 | 作用 |
|
|
8
51
|
|---|---|---|
|
package/docs/agent/kit.md
CHANGED
|
@@ -23,19 +23,19 @@ 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[]` |
|
|
30
30
|
| `MediaRow` | 图文条目:门店、商品、活动。 | `title: ReactNode` `meta?: ReactNode` `tags?: ReactNode` `action?: ReactNode` `thumb?: ReactNode` |
|
|
31
|
-
| `Hero` | 品牌色块:主数值 + 说明,用于会员、积分、钱包类卡片的头部。 | `eyebrow?: ReactNode` `title: ReactNode` `value?: ReactNode` `unit?: ReactNode` `footnote?: ReactNode` `icon?: ReactNode` `tone?: 'primary' \| 'warm' \| 'jade' \| 'neutral'` |
|
|
31
|
+
| `Hero` | 品牌色块:主数值 + 说明,用于会员、积分、钱包类卡片的头部。 | `eyebrow?: ReactNode` `title: ReactNode` `value?: ReactNode` `unit?: ReactNode` `footnote?: ReactNode` `icon?: ReactNode` `tone?: 'primary' \| 'warm' \| 'jade' \| 'inverse' \| 'neutral'` |
|
|
32
32
|
| `StatGrid` | 并列数值格(两到三格):积分/余额、车位/时长。 | `items: StatItem[]` |
|
|
33
33
|
| `EntityRow` | 实体行(MediaRow 的超集):商户、活动、券包条目,支持价格与展开说明。 | `title: ReactNode` `meta?: ReactNode` `tags?: ReactNode` `price?: ReactNode` `action?: ReactNode` `thumb?: ReactNode` `description?: ReactNode` |
|
|
34
34
|
| `CheckRow` | 勾选行:用券、同意条款、选择车位。 | `label: ReactNode` `description?: ReactNode` `checked: boolean` `onChange?: (checked: boolean) => void` `disabled?: boolean` `trailing?: ReactNode` |
|
|
35
35
|
| `Timeline` | 明细时间线:积分收支、停车计费。 * | `items: TimelineItem[]` |
|
|
36
36
|
| `EmptyState` | 空态:没券、没订单、没记录时给一句解释与一个下一步。 * | `title: ReactNode` `description?: ReactNode` `action?: ReactNode` |
|
|
37
37
|
| `TagList` | 标签组:口味、距离、适用条件。 * | `tags: ReactNode[]` `tone?: Tone` |
|
|
38
|
-
| `ActionList` |
|
|
38
|
+
| `ActionList` | — | `actions: CardActionSpec[]` `api: CardActions` |
|
|
39
39
|
|
|
40
40
|
## 图标
|
|
41
41
|
|
package/docs/agent/shell.md
CHANGED
|
@@ -40,6 +40,7 @@ export default function Index() {
|
|
|
40
40
|
| 空会话欢迎区 | `config/chat.json` 的 `welcome.title` / `welcome.subtitle` |
|
|
41
41
|
| 快捷问题 | `config/chat.json` 的 `quickCommands`(见 [agent-prompt](agent-prompt.md)) |
|
|
42
42
|
| 出错重试 | `config/chat.json` 的 `retryOnError`(缺省 true):错误气泡上给「重试」,重发上一条用户消息 |
|
|
43
|
+
| 出厂能力开关 | 语音输入/播报、图片/视频上传缺省开启;`chat.json` 不写这些键。只有用户明确要求时才写 `false`——门禁会把它记为「偏离出厂」并要求写明依据 |
|
|
43
44
|
| 首屏整体替换 | `slots.home`:注册一个渲染函数,替换主屏内容 |
|
|
44
45
|
| 对话标题 | `apps/client/src/pages/page.tsx` 的 `page.title` |
|
|
45
46
|
| 外观(颜色、圆角、底色) | `apps/client/src/styles/brand.css` 覆写 `--tbox-*` 变量,见 [style](style.md) |
|
package/docs/agent/style.md
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
- 顺序不变:先用 kit 基元;基元表达不了的布局,用工具类包一层 `div`。
|
|
17
|
+
- 模块源码由宿主构建链自动登记(以模块 `src/client/index.ts` 为客户端入口);不要手动往 `tailwind.css` 写模块 `@source`。
|
|
17
18
|
- 类名必须是**完整字面量**——构建期扫源码生成 CSS,`bg-${tone}` 这种拼出来的类不会生成,页面上看到的是「没有样式」而不是报错。
|
|
18
19
|
- 模板里拼完类名要留一个空格再开插值:`text-xs${cond ? … : …}` 会让扫描器丢掉整条 `text-xs`(`check:fast` 会拦)。
|
|
19
20
|
- 动态状态只能写成「整串字面量的三元」或「按状态键取的映射表」,两种都是完整类名:
|
|
@@ -30,7 +31,7 @@ const TONE = { ok: 'bg-success-soft text-success', warn: 'bg-warning-soft text-w
|
|
|
30
31
|
- 字号只有六档:`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
32
|
- 行高用 `leading-5`(20px)这类 4 的倍数,精确值写 `leading-[22px]`。
|
|
32
33
|
- 圆角与阴影优先契约:`rounded-lg/md/sm` 映射 `--tbox-radius-*`,`shadow-sm/md/lg` 映射 `--tbox-shadow-*`。
|
|
33
|
-
-
|
|
34
|
+
- **尺寸与字号一律物理 px**:模板没有动态根字号、没有 rem 换算,`p-4` 就是 16px;不要用 rem / em 表达尺寸。
|
|
34
35
|
|
|
35
36
|
## 颜色只能来自语义名
|
|
36
37
|
|
|
@@ -43,7 +44,8 @@ const TONE = { ok: 'bg-success-soft text-success', warn: 'bg-warning-soft text-w
|
|
|
43
44
|
| 描边 | `border-border` `border-border-strong` `border-warn-border` `border-danger-border` |
|
|
44
45
|
| 主色上的字 | `text-white` `text-primary-foreground` |
|
|
45
46
|
|
|
46
|
-
- 一次性色值用任意值:`bg-[#fff8e9]`、`text-[#0a6eb8]`、`shadow-[0_2px_16px_rgba(106,119,137,0.08)]
|
|
47
|
+
- 一次性色值用任意值:`bg-[#fff8e9]`、`text-[#0a6eb8]`、`shadow-[0_2px_16px_rgba(106,119,137,0.08)]`。同一个色值出现在三处以上,说明它该进契约而不是继续复制——这条由 `style.color-repeat`(warning)兜住,会点名重复的色值与最像的令牌。
|
|
48
|
+
- 想改配色先跑 `pnpm exec tbox-app theme check`(逐对对比度),不达标用 `theme tune --write`(只调亮度、色相不动),新品牌从种子派生用 `theme derive --seed <hex>`。三个命令只写 `brand.css` 的 `@tbox:tokens-begin/end` 标记区。
|
|
47
49
|
- 半透明写带 alpha 的任意值:`bg-[rgba(11,15,23,0.02)]`。
|
|
48
50
|
- 禁用:默认调色板(`bg-red-500` 不生成)、透明度修饰符(`bg-primary/50` 依赖 `color-mix`,旧内核回落为不透明)、`!` 重要性(只在覆写无层的旧规则时用,写在变体尾部如 `rounded-none!`)。
|
|
49
51
|
- 未知类不会报错、只是不生效;上面这几类禁用项由 `check:fast` 的证据包直接判错(`palette-color` / `color-opacity-modifier` / `font-size-off-scale` / `element-asset-declaration`)。
|
|
@@ -76,11 +78,17 @@ html[data-theme='tbox'] {
|
|
|
76
78
|
- **不要在应用里声明 `--tbox-asset-*`**:元素级声明会截断 `html[data-theme]` 的覆写继承(素材级联门禁拦截)。
|
|
77
79
|
- 任意值里不留空格(空格写下划线),逗号原样。
|
|
78
80
|
|
|
81
|
+
## 整页背景
|
|
82
|
+
|
|
83
|
+
- 整页背景图或渐变写在壳的 `.chat-page__bg` 层(绝对定位、覆盖历史入口与底部输入区、不随内容滚动),它默认 `bg-center bg-cover bg-no-repeat`。
|
|
84
|
+
- 首页容器保持透明(卡片表面可保留自身底色);把整页背景铺在首页组件上会在历史入口处出现底色断层。
|
|
85
|
+
- home 槽是 `flow-root` 容器,首页子元素的外边距留在槽内;入口到首页的间距由首页自身留白决定。
|
|
86
|
+
|
|
79
87
|
## 旧 web-view 兼容
|
|
80
88
|
|
|
81
89
|
- 颜色语法一律 `rgba(r, g, b, a)`;`rgb(r g b / a)` 在旧 WebKit 上整条属性失效(不是降级)。
|
|
82
90
|
- 断点用 `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
|
|
91
|
+
- 产物特征门禁:`pnpm check:css` 读构建产物按 `package.json` 的 `tbox.compat.baseline` 扫越线特性(缺省 `safari 16.4`,即 Tailwind 4 官方下限;Chrome 111+ 视为满足)。基线只声明一次,构建期守产物;没有运行时探测,也没有旧内核提示页。
|
|
84
92
|
|
|
85
93
|
## 卡片排版
|
|
86
94
|
|
|
@@ -7,10 +7,15 @@
|
|
|
7
7
|
工具 `execute` 返回的对象里,`cards` 是保留字段:
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
|
|
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>` 标签点选要展示的卡;标签对用户不可见。
|
|
@@ -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
|
-
| 生成报卡片缺失 |
|
|
62
|
+
| 生成报卡片缺失 | 三件套只写了服务端文件;视图卡请在 meta 上声明 `view`(免成对文件) |
|
package/docs/agent/tool.md
CHANGED