@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
|
@@ -27,7 +27,9 @@ export function MessageBubble({ message }: { message: ChatMessage }) {
|
|
|
27
27
|
const sendMessage = useChatStore((s) => s.sendMessage);
|
|
28
28
|
const generating = useChatStore((s) => s.isGenerating);
|
|
29
29
|
const isUser = message.role === 'user';
|
|
30
|
-
|
|
30
|
+
// 发送者名取应用身份(chat.json identity.name),没有配置才回落通用名。
|
|
31
|
+
const identity = useChatConfigStore((s) => s.identity);
|
|
32
|
+
const roleName = isUser ? '你' : (identity?.name ?? 'AI 助手');
|
|
31
33
|
const timeLabel = new Date(message.createdAt).toLocaleTimeString('zh-CN', {
|
|
32
34
|
hour: '2-digit',
|
|
33
35
|
minute: '2-digit',
|
|
@@ -70,7 +72,11 @@ export function MessageBubble({ message }: { message: ChatMessage }) {
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
return (
|
|
73
|
-
<div
|
|
75
|
+
<div
|
|
76
|
+
className={`msg-row mb-2.5 flex items-start px-page ${isUser ? 'msg-row--user flex-row-reverse' : 'msg-row--bot flex-row'}`}
|
|
77
|
+
data-message-id={message.id}
|
|
78
|
+
data-message-role={message.role}
|
|
79
|
+
>
|
|
74
80
|
<div className={isUser ? 'msg-main min-w-0' : 'msg-main min-w-0 flex-1'}>
|
|
75
81
|
<div
|
|
76
82
|
className={`msg-meta flex items-center ${isUser ? 'msg-meta--user justify-end' : 'msg-meta--bot justify-start'} ${!showBubble && messageCards.length > 0 ? 'msg-meta--solo-card mb-1.5' : 'mb-[3px]'}`}
|
|
@@ -104,17 +110,17 @@ export function MessageBubble({ message }: { message: ChatMessage }) {
|
|
|
104
110
|
className={`msg-bubble leading-[1.6] ${isUser ? 'msg-bubble--user mb-1 ml-auto mr-0 flex min-h-6 w-fit max-w-full items-center rounded-[24px_4px_24px_24px] bg-[rgba(255,255,255,0.9)] px-[11px] py-[9px] shadow-[0_2px_8px_rgba(50,65,92,0.08)]' : 'msg-bubble--bot relative mb-1.5 rounded-[4px_24px_24px] border-[0.5px] border-[#edf0f6] bg-[rgba(255,255,255,0.4)] p-[11px] text-base text-foreground shadow-[0_1.5px_4px_2.5px_rgba(1,112,254,0.0392),0_1px_2px_rgba(72,78,86,0.0706)]'}`}
|
|
105
111
|
>
|
|
106
112
|
{isUser ? (
|
|
107
|
-
<span className="msg-bubble__text text-
|
|
113
|
+
<span className="msg-bubble__text text-base leading-[1.6] font-medium text-foreground [overflow-wrap:break-word]">{message.content}</span>
|
|
108
114
|
) : (
|
|
109
115
|
<>
|
|
110
116
|
{message.content && (
|
|
111
|
-
<div className="msg-markdown text-
|
|
117
|
+
<div className="msg-markdown text-base leading-[1.6] text-foreground [overflow-wrap:anywhere] [&_h1]:mt-2! [&_h1]:mb-1! [&_h1]:text-lg [&_h1]:font-semibold [&_h1]:leading-[1.4] [&_h2]:mt-2! [&_h2]:mb-1! [&_h2]:text-base [&_h2]:font-semibold [&_h2]:leading-[1.4] [&_h3]:mt-2! [&_h3]:mb-1! [&_h3]:text-base [&_h3]:font-semibold [&_h3]:leading-[1.4] [&_h4]:mt-2! [&_h4]:mb-1! [&_h4]:text-sm [&_h4]:font-semibold [&_h4]:leading-[1.4] [&_h5]:mt-2! [&_h5]:mb-1! [&_h5]:font-semibold [&_h5]:leading-[1.4] [&_h6]:mt-2! [&_h6]:mb-1! [&_h6]:font-semibold [&_h6]:leading-[1.4] [&_p]:my-1! [&_strong]:font-semibold [&_em]:italic [&_a]:text-primary [&_a]:underline [&_ul]:my-1! [&_ul]:pl-4 [&_ol]:my-1! [&_ol]:pl-4 [&_li]:my-0.5 [&_blockquote]:my-1.5 [&_blockquote]:border-l-2 [&_blockquote]:border-l-primary [&_blockquote]:pl-2 [&_blockquote]:text-secondary-foreground [&_code]:rounded-[3px] [&_code]:bg-[rgba(0,0,0,0.06)] [&_code]:px-1 [&_code]:py-[1px] [&_code]:text-sm [&_code]:leading-[1.6] [&_code]:font-mono [&_pre]:my-1.5 [&_pre]:overflow-x-auto [&_pre]:rounded-[6px] [&_pre]:bg-[#1e1e2e] [&_pre]:p-2.5 [&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_pre_code]:text-xs [&_pre_code]:leading-[1.6] [&_pre_code]:text-[#cdd6f4] [&_table]:my-1.5 [&_table]:w-full [&_table]:border-collapse [&_th]:border-[0.5px] [&_th]:border-border [&_th]:bg-muted [&_th]:px-1.5 [&_th]:py-1 [&_th]:text-left [&_th]:text-sm [&_th]:leading-[1.6] [&_th]:font-semibold [&_td]:border-[0.5px] [&_td]:border-border [&_td]:px-1.5 [&_td]:py-1 [&_td]:text-left [&_td]:text-sm [&_td]:leading-[1.6]">
|
|
112
118
|
<ReactMarkdown remarkPlugins={[remarkGfm]}>{message.content}</ReactMarkdown>
|
|
113
119
|
</div>
|
|
114
120
|
)}
|
|
115
121
|
{message.error && (
|
|
116
122
|
<div
|
|
117
|
-
className={`msg-bubble__error whitespace-pre-wrap text-
|
|
123
|
+
className={`msg-bubble__error whitespace-pre-wrap text-sm leading-[1.6] text-destructive [overflow-wrap:anywhere] ${message.content ? 'msg-bubble__error--with-content mt-[7px] border-t-[0.5px] border-t-destructive pt-[7px]' : ''}`}
|
|
118
124
|
role="alert"
|
|
119
125
|
>
|
|
120
126
|
{message.error}
|
|
@@ -76,7 +76,9 @@ describe('QuickCommands 快捷胶囊', () => {
|
|
|
76
76
|
const buttons = [...container.querySelectorAll<HTMLButtonElement>('.quick-commands__item')];
|
|
77
77
|
expect(buttons.map((button) => button.textContent)).toEqual(['今日优惠', '品牌导览', '活动中心']);
|
|
78
78
|
expect(container.textContent).not.toContain('找门店');
|
|
79
|
-
|
|
79
|
+
// 图标走 CSS mask + currentColor(换品牌色不再残留固定蓝),断言 mask 的图片地址。
|
|
80
|
+
const iconUrl = buttons[1]?.querySelector<HTMLElement>('.quick-commands__icon')?.getAttribute('data-icon') ?? '';
|
|
81
|
+
expect(iconUrl).toContain('6-OCR5kWFa');
|
|
80
82
|
flushSync(() => buttons[1]!.click());
|
|
81
83
|
expect(onCommand).toHaveBeenCalledWith('服务端品牌导览');
|
|
82
84
|
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// 输入框上方的快捷指令;文案由 chatConfig 驱动,服务端下发不含 icon 时按 label 合并本地配置。
|
|
2
2
|
// 011 I2:服务端 HelloAck.chatConfig.quickCommands 优先(单一真源),本地 chat.json 为 fallback。
|
|
3
3
|
// label 只写纯文字;前面的星标由本组件渲染(icon 字段或默认 ✦),不要把 ✦/emoji 写进 label。
|
|
4
|
+
//
|
|
5
|
+
// 两种排布:空会话用 grid(两列、全可见、每个 44px 命中区),对话态用 row(底部单行、可横滚)。
|
|
6
|
+
// 颜色只用语义令牌:换品牌色后不残留固定蓝。
|
|
4
7
|
import { useChatConfigStore } from '../../chat-config';
|
|
5
8
|
import { useChatStore } from '../../store-context';
|
|
6
9
|
import starIcon from '../../../assets/quick-command-star.svg';
|
|
@@ -8,9 +11,11 @@ import starIcon from '../../../assets/quick-command-star.svg';
|
|
|
8
11
|
export function QuickCommands({
|
|
9
12
|
onCommand,
|
|
10
13
|
hidden = false,
|
|
14
|
+
variant = 'row',
|
|
11
15
|
}: {
|
|
12
16
|
onCommand: (query: string) => void;
|
|
13
17
|
hidden?: boolean;
|
|
18
|
+
variant?: 'row' | 'grid';
|
|
14
19
|
}) {
|
|
15
20
|
const staticCommands = useChatConfigStore((s) => s.quickCommands);
|
|
16
21
|
// chatConfig 可选链:旧 server 的 HELLO_ACK 可能不带该段(与「ack 缺席回落静态」同语义)
|
|
@@ -26,25 +31,43 @@ export function QuickCommands({
|
|
|
26
31
|
: staticCommands;
|
|
27
32
|
if (!commands.length) return null;
|
|
28
33
|
|
|
34
|
+
const grid = variant === 'grid';
|
|
29
35
|
return (
|
|
30
36
|
<div
|
|
31
|
-
className={
|
|
37
|
+
className={
|
|
38
|
+
grid
|
|
39
|
+
? `quick-commands quick-commands--grid relative z-[1] mx-auto grid w-full max-w-content grid-cols-2 gap-2 px-page ${hidden ? ' quick-commands--hidden invisible pointer-events-none' : ''}`
|
|
40
|
+
: `quick-commands relative z-[1] mx-auto flex w-full max-w-content gap-2 overflow-x-auto px-page pb-[9px] [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden ${hidden ? ' quick-commands--hidden invisible pointer-events-none' : ''}`
|
|
41
|
+
}
|
|
32
42
|
aria-hidden={hidden || undefined}
|
|
33
43
|
>
|
|
34
44
|
{commands.map((cmd) => (
|
|
35
45
|
<button
|
|
36
46
|
key={cmd.label}
|
|
37
|
-
className=
|
|
47
|
+
className={
|
|
48
|
+
grid
|
|
49
|
+
? 'quick-commands__item inline-flex min-h-11 w-full appearance-none items-center justify-start gap-1.5 rounded-[22px] border border-border bg-card px-3 py-2 text-left text-foreground shadow-sm transition-colors duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] active:border-primary'
|
|
50
|
+
: 'quick-commands__item inline-flex min-h-11 flex-[1_0_auto] appearance-none items-center justify-center gap-1.5 rounded-[22px] border border-border bg-card px-3 py-2 text-foreground shadow-sm transition-colors duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] active:border-primary'
|
|
51
|
+
}
|
|
38
52
|
disabled={hidden}
|
|
39
53
|
onClick={() => onCommand(cmd.query)}
|
|
40
54
|
>
|
|
41
|
-
<
|
|
42
|
-
className="quick-commands__icon size-4
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
<span
|
|
56
|
+
className="quick-commands__icon size-4 shrink-0 bg-primary"
|
|
57
|
+
aria-hidden="true"
|
|
58
|
+
data-icon={cmd.icon ?? starIcon}
|
|
59
|
+
style={{
|
|
60
|
+
maskImage: `url("${cmd.icon ?? starIcon}")`,
|
|
61
|
+
WebkitMaskImage: `url("${cmd.icon ?? starIcon}")`,
|
|
62
|
+
maskSize: 'contain',
|
|
63
|
+
WebkitMaskSize: 'contain',
|
|
64
|
+
maskRepeat: 'no-repeat',
|
|
65
|
+
WebkitMaskRepeat: 'no-repeat',
|
|
66
|
+
maskPosition: 'center',
|
|
67
|
+
WebkitMaskPosition: 'center',
|
|
68
|
+
}}
|
|
46
69
|
/>
|
|
47
|
-
<span className=
|
|
70
|
+
<span className={`quick-commands__label text-sm font-medium leading-[18px] text-foreground ${grid ? 'line-clamp-2 text-left' : 'whitespace-nowrap'}`}>{cmd.label}</span>
|
|
48
71
|
</button>
|
|
49
72
|
))}
|
|
50
73
|
</div>
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/** 生成时出现的“回到底部”悬浮按钮。 */
|
|
2
2
|
export default function ScrollToBottomButton({ visible, onClick }: { visible: boolean; onClick: () => void }) {
|
|
3
3
|
return (
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
<button
|
|
5
|
+
type="button"
|
|
6
|
+
data-tbox-control="scroll-bottom"
|
|
7
|
+
aria-label="回到底部"
|
|
8
|
+
className={`scroll-to-bottom-btn absolute right-4 bottom-4 z-10 flex size-11 cursor-pointer appearance-none items-center justify-center rounded-full border-0 bg-white p-0 shadow-[0_2px_8px_0_rgba(0,0,0,0.12)] transition-[opacity,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary ${visible ? ' scroll-to-bottom-btn--visible pointer-events-auto opacity-100 [transform:scale(1)]' : ' pointer-events-none opacity-0 [transform:scale(0.8)]'}`} onClick={onClick}>
|
|
9
|
+
<span className="scroll-to-bottom-btn__arrow h-0 w-0 border-x-[6px] border-t-[7px] border-x-transparent border-t-[#666]" aria-hidden="true" />
|
|
10
|
+
</button>
|
|
7
11
|
);
|
|
8
12
|
}
|
|
@@ -54,6 +54,8 @@ export default function ToolCallBlock({
|
|
|
54
54
|
const listId = useId();
|
|
55
55
|
const items = useMemo(() => toolCalls.map(deriveToolCallItem), [toolCalls]);
|
|
56
56
|
const summary = useMemo(() => deriveSummary(items), [items]);
|
|
57
|
+
// 已恢复的失败不打扰用户:只有整批都失败时才展示失败计数与错误图标(B11)。
|
|
58
|
+
const allFailed = summary.failedCount > 0 && summary.failedCount === items.length;
|
|
57
59
|
|
|
58
60
|
const toggleDetail = (id: string) => {
|
|
59
61
|
setExpandedDetailIds((current) => {
|
|
@@ -79,14 +81,14 @@ export default function ToolCallBlock({
|
|
|
79
81
|
className="tool-calls__spinner size-3.5 shrink-0 animate-[tool-spin_0.8s_linear_infinite] rounded-full border-2 border-[rgba(9,107,250,0.2)] border-t-primary motion-reduce:animate-none"
|
|
80
82
|
aria-hidden="true"
|
|
81
83
|
/>
|
|
82
|
-
) :
|
|
84
|
+
) : allFailed ? (
|
|
83
85
|
<X className="tool-calls__icon tool-calls__icon--error shrink-0 self-center text-muted-foreground" size={16} strokeWidth={2.5} />
|
|
84
86
|
) : (
|
|
85
87
|
<Check className="tool-calls__icon tool-calls__icon--success shrink-0 self-center text-muted-foreground" size={16} strokeWidth={2.5} />
|
|
86
88
|
)}
|
|
87
89
|
<span className="tool-calls__summary-text min-w-0 truncate text-xs font-normal leading-[1.4]">
|
|
88
90
|
{buildSummaryText(summary).join(' · ')}
|
|
89
|
-
{
|
|
91
|
+
{allFailed && (
|
|
90
92
|
<span className="tool-calls__failed text-muted-foreground"> · {summary.failedCount} 个失败</span>
|
|
91
93
|
)}
|
|
92
94
|
</span>
|
|
@@ -21,6 +21,9 @@ export {
|
|
|
21
21
|
useClientSlots,
|
|
22
22
|
} from './store-context';
|
|
23
23
|
export type { KitChatContextValue } from './store-context';
|
|
24
|
+
export { KitPreviewProvider, createPreviewStore } from './preview-provider';
|
|
25
|
+
export { createSurfaceHarness } from './surface';
|
|
26
|
+
export type { SurfaceHarness, SurfaceHarnessOptions } from './surface';
|
|
24
27
|
|
|
25
28
|
// ── chat 设置(构建期快照 + HELLO_ACK 水合) ──
|
|
26
29
|
export { configureChatConfigDefaults, useChatConfigStore } from './chat-config';
|
|
@@ -38,6 +41,7 @@ export { CardRenderer, RawCardRenderer } from './components/CardRenderer';
|
|
|
38
41
|
|
|
39
42
|
// ── 应用级卡片工厂与卡片内交互 ──
|
|
40
43
|
export { defineCard } from './card/define-card';
|
|
44
|
+
export { ViewCard } from './card/view-card';
|
|
41
45
|
export type { CardRenderProps, DefinedCard } from './card/define-card';
|
|
42
46
|
export { useCardActions } from './card/use-card-actions';
|
|
43
47
|
export type { CardActions, UseCardActionsOptions } from './card/use-card-actions';
|
|
@@ -120,3 +124,7 @@ export type {
|
|
|
120
124
|
MessageStatus,
|
|
121
125
|
ToolCallInfo,
|
|
122
126
|
} from './types';
|
|
127
|
+
|
|
128
|
+
// ── 通用弹层 ──
|
|
129
|
+
export { BottomSheet, preloadBottomSheet } from './components/BottomSheet';
|
|
130
|
+
export type { BottomSheetProps } from './components/BottomSheet';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KitPreviewProvider:卡片预览面的最小装配根。
|
|
3
|
+
*
|
|
4
|
+
* 预览页直接渲染 SDK CardRenderer,没有应用 store——kit 卡片的 `useCardActions`
|
|
5
|
+
* 会因「KitChatProvider 缺席」抛错(预览 7/7 全红)。这里给一个只读预览 store:
|
|
6
|
+
* 动作写通道是空实现(预览页自己的动作通道另经 bindCardActionChannel 接管),
|
|
7
|
+
* 卡片能渲染、按钮能显示、历史/禁用态照常。
|
|
8
|
+
*
|
|
9
|
+
* 应用接线:app.config.ts 的 `wrapPreview` 返回 `createElement(KitPreviewProvider, null, node)`。
|
|
10
|
+
*/
|
|
11
|
+
import { useMemo, type ReactNode } from 'react';
|
|
12
|
+
import { useStore } from 'zustand';
|
|
13
|
+
import { createStore } from 'zustand/vanilla';
|
|
14
|
+
import type { CardComponent } from '@tbox.cn/app-contracts';
|
|
15
|
+
import type { CoreChatState, CoreChatStore } from '@tbox.cn/app-agent-sdk-client';
|
|
16
|
+
import { KitChatProvider } from './store-context';
|
|
17
|
+
|
|
18
|
+
/** 预览用 store:只满足壳与卡片的读取(sendUiAction 空实现、不在生成中)。 */
|
|
19
|
+
export function createPreviewStore(state: Partial<CoreChatState> = {}): CoreChatStore {
|
|
20
|
+
const vanilla = createStore<CoreChatState>(() => ({
|
|
21
|
+
sendUiAction: () => {},
|
|
22
|
+
isGenerating: false,
|
|
23
|
+
...state,
|
|
24
|
+
} as unknown as CoreChatState));
|
|
25
|
+
const hook = ((selector: (state: CoreChatState) => unknown) =>
|
|
26
|
+
useStore(vanilla, selector)) as unknown as CoreChatStore;
|
|
27
|
+
hook.getState = vanilla.getState;
|
|
28
|
+
hook.setState = vanilla.setState;
|
|
29
|
+
hook.subscribe = vanilla.subscribe;
|
|
30
|
+
return hook;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function KitPreviewProvider({
|
|
34
|
+
cards = {},
|
|
35
|
+
children,
|
|
36
|
+
}: {
|
|
37
|
+
/** 预览页的卡片注册表(缺省空表;动作由预览页接管) */
|
|
38
|
+
cards?: Record<string, CardComponent>;
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
}) {
|
|
41
|
+
const store = useMemo(() => createPreviewStore(), []);
|
|
42
|
+
return (
|
|
43
|
+
<KitChatProvider store={store} cards={cards} rawCards={cards}>
|
|
44
|
+
{children}
|
|
45
|
+
</KitChatProvider>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -51,6 +51,15 @@
|
|
|
51
51
|
"brandable": false
|
|
52
52
|
}
|
|
53
53
|
],
|
|
54
|
+
"controls": [
|
|
55
|
+
{ "id": "new-chat", "selector": "[data-tbox-control='new-chat']", "name": "新建对话", "minHit": 44 },
|
|
56
|
+
{ "id": "voice-toggle", "selector": "[data-tbox-control='voice-toggle']", "name": "语音输入", "minHit": 44, "capability": "input.voice" },
|
|
57
|
+
{ "id": "send", "selector": "[data-tbox-control='send']", "name": "发送", "minHit": 44 },
|
|
58
|
+
{ "id": "stop", "selector": "[data-tbox-control='stop']", "name": "停止生成", "minHit": 44 },
|
|
59
|
+
{ "id": "media-add", "selector": "[data-tbox-control='media-add']", "name": "添加图片或视频", "minHit": 44, "capability": ["input.image", "input.video"] },
|
|
60
|
+
{ "id": "history", "selector": "[data-tbox-control='history']", "name": "历史记录", "minHit": 44 },
|
|
61
|
+
{ "id": "scroll-bottom", "selector": "[data-tbox-control='scroll-bottom']", "name": "回到底部", "minHit": 44 }
|
|
62
|
+
],
|
|
54
63
|
"internal": [
|
|
55
64
|
"MessageBubble 内部结构(.msg-row / .msg-main / .msg-thinking)",
|
|
56
65
|
"ChatInput 内部结构(.tbox-media-picker、发送按钮)",
|
|
@@ -43,6 +43,16 @@ describe('壳契约', () => {
|
|
|
43
43
|
expect(region.drivenBy.length, `${region.id} 缺 drivenBy`).toBeGreaterThan(0);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
+
|
|
47
|
+
it('控件契约的 data-tbox-control 都在源码里', () => {
|
|
48
|
+
const sources = ['components/ChatInput/index.tsx', 'components/HistoryEntry/index.tsx', 'components/ScrollToBottomButton/index.tsx'];
|
|
49
|
+
for (const control of SHELL_CONTRACT.controls ?? []) {
|
|
50
|
+
const attr = /data-tbox-control=['"]([^'"]+)['"]/.exec(control.selector)?.[1];
|
|
51
|
+
expect(attr, `控件 ${control.id} 的选择器必须用 data-tbox-control`).toBeTruthy();
|
|
52
|
+
expect(sources.some((file) => read(file).includes('data-tbox-control="' + attr + '"')), `控件 ${control.id} 在源码里不存在`).toBe(true);
|
|
53
|
+
expect(control.minHit).toBeGreaterThanOrEqual(44);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
46
56
|
});
|
|
47
57
|
|
|
48
58
|
describe('品牌名三级来源', () => {
|
|
@@ -28,8 +28,23 @@ export interface ShellRegion {
|
|
|
28
28
|
brandable: boolean;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export interface ShellControl {
|
|
32
|
+
/** 稳定 id(探针与文档引用) */
|
|
33
|
+
id: string;
|
|
34
|
+
/** 可定位的选择器(data-tbox-control) */
|
|
35
|
+
selector: string;
|
|
36
|
+
/** 可访问名 */
|
|
37
|
+
name: string;
|
|
38
|
+
/** 最小命中区(px) */
|
|
39
|
+
minHit: number;
|
|
40
|
+
/** 能力开关(关闭时控件可缺席) */
|
|
41
|
+
capability?: string | string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
31
44
|
export interface ShellContract {
|
|
32
45
|
regions: ShellRegion[];
|
|
46
|
+
/** 交互控件契约:探针按它查,不按内部类名猜 */
|
|
47
|
+
controls?: ShellControl[];
|
|
33
48
|
/** 不承诺稳定、不要覆写的内部结构 */
|
|
34
49
|
internal: string[];
|
|
35
50
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
4
|
+
import { Card, CardButton, CardHeader, defineCard, useCardActions } from './index';
|
|
5
|
+
import { createSurfaceHarness } from './surface';
|
|
6
|
+
|
|
7
|
+
/** 一张用 kit 动作的卡:没有 provider 会抛「KitChatProvider 缺席」。 */
|
|
8
|
+
const DemoCard = defineCard({ type: 'demo-card' }, ({ data, cardId, isHistory }) => {
|
|
9
|
+
const api = useCardActions({ cardId, isHistory });
|
|
10
|
+
return (
|
|
11
|
+
<Card>
|
|
12
|
+
<CardHeader title={String((data as { title: string }).title)} />
|
|
13
|
+
<CardButton onClick={() => api.send('继续')}>继续</CardButton>
|
|
14
|
+
</Card>
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('createSurfaceHarness', () => {
|
|
19
|
+
it('给出与运行时同形的 provider,kit 卡片可直接渲染', () => {
|
|
20
|
+
const harness = createSurfaceHarness({ cards: { 'demo-card': DemoCard } });
|
|
21
|
+
const html = renderToStaticMarkup(
|
|
22
|
+
harness.wrap(createElement(DemoCard, { data: { title: '停车订单' }, cardId: 'c1', isHistory: false })),
|
|
23
|
+
);
|
|
24
|
+
expect(html).toContain('停车订单');
|
|
25
|
+
expect(html).toContain('继续');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('历史态可渲染且动作禁用', () => {
|
|
29
|
+
const harness = createSurfaceHarness({ cards: { 'demo-card': DemoCard } });
|
|
30
|
+
const html = renderToStaticMarkup(
|
|
31
|
+
harness.wrap(createElement(DemoCard, { data: { title: '停车订单' }, cardId: 'c1', isHistory: true })),
|
|
32
|
+
);
|
|
33
|
+
expect(html).toContain('disabled');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SurfaceHarness:卡片/聊天表面的唯一装配入口。
|
|
3
|
+
*
|
|
4
|
+
* 证据(check:fast)、截图(card render)、预览页都要渲染真实组件——但每个入口都手搭
|
|
5
|
+
* provider 栈,就会出现「预览崩、证据过、运行时坏」的分裂。这里把 store + provider 收成
|
|
6
|
+
* 一个工厂:看到的就是运行时看到的。
|
|
7
|
+
*
|
|
8
|
+
* 用法:
|
|
9
|
+
* const harness = createSurfaceHarness({ cards, state });
|
|
10
|
+
* renderToStaticMarkup(harness.wrap(<MyCard ... />));
|
|
11
|
+
*/
|
|
12
|
+
import type { ReactNode } from 'react';
|
|
13
|
+
import type { CardComponent } from '@tbox.cn/app-contracts';
|
|
14
|
+
import type { ClientSlotRegistry, CoreChatState } from '@tbox.cn/app-agent-sdk-client';
|
|
15
|
+
import { KitChatProvider } from './store-context';
|
|
16
|
+
import { createPreviewStore } from './preview-provider';
|
|
17
|
+
|
|
18
|
+
export interface SurfaceHarnessOptions {
|
|
19
|
+
/** cards = 组合层注册表(含覆盖);rawCards 缺省同 cards。 */
|
|
20
|
+
cards?: Record<string, CardComponent>;
|
|
21
|
+
rawCards?: Record<string, CardComponent>;
|
|
22
|
+
/** 客户端槽(home);缺省无。 */
|
|
23
|
+
slots?: ClientSlotRegistry;
|
|
24
|
+
/** store 初值覆盖(如 isGenerating / 历史态)。 */
|
|
25
|
+
state?: Partial<CoreChatState>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SurfaceHarness {
|
|
29
|
+
store: ReturnType<typeof createPreviewStore>;
|
|
30
|
+
/** 把一个元素包进与运行时同形的 provider 树。 */
|
|
31
|
+
wrap: (node: ReactNode) => ReactNode;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createSurfaceHarness(options: SurfaceHarnessOptions = {}): SurfaceHarness {
|
|
35
|
+
const cards = options.cards ?? {};
|
|
36
|
+
const rawCards = options.rawCards ?? cards;
|
|
37
|
+
const store = createPreviewStore(options.state);
|
|
38
|
+
const wrap = (node: ReactNode): ReactNode => (
|
|
39
|
+
<KitChatProvider store={store} cards={cards} rawCards={rawCards} {...(options.slots ? { slots: options.slots } : {})}>
|
|
40
|
+
{node}
|
|
41
|
+
</KitChatProvider>
|
|
42
|
+
);
|
|
43
|
+
return { store, wrap };
|
|
44
|
+
}
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
- 间距:卡片与上下元素(工具调用 / 气泡)的间距,与 .tool-calls 一致;
|
|
46
46
|
- 外观:默认背景(白) / 1px 边框 / 圆角 / 阴影;`overflow:hidden` 把内容裁进圆角;
|
|
47
47
|
- 入场动效:mount 即播(0.36s 上浮淡入,对齐 mall-vis 消息卡节奏)。
|
|
48
|
-
值为物理 px(大写 PX
|
|
48
|
+
值为物理 px(大写 PX):圆角 var(--tbox-radius-lg)=24、边框 1、阴影 var(--tbox-shadow-sm)=0 4 13。
|
|
49
49
|
⚠️ **内边距不在卡框里**——由卡片自己写。卡框给 padding 会让「自带背景色的卡」在外面露一圈白边(卡里套卡)。
|
|
50
50
|
宽度也不在卡框里:默认占满整列(≈移动端 350~400px 设计宽),紧凑卡自己写 max-width。
|
|
51
51
|
单卡组件(.tbox-<type>)只画内容;**要整卡换底色 / 出血图,直接在自己 root 上 `background:<色>` 或铺满图**——
|
|
@@ -104,6 +104,14 @@
|
|
|
104
104
|
--adm-z-index-mask: 1200;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/* 表单控件继承排版:模板不引 preflight,原生 button/input 否则落到浏览器默认 13.33px(越档字号)。
|
|
108
|
+
作用域限定在壳与卡片内,工具类仍可覆写。 */
|
|
109
|
+
:where(.tbox-app, .chat-page, .tbox-card) :where(button, input, textarea, select) {
|
|
110
|
+
font: inherit;
|
|
111
|
+
color: inherit;
|
|
112
|
+
letter-spacing: inherit;
|
|
113
|
+
}
|
|
114
|
+
|
|
107
115
|
/* 基元/模块迁移后不再各自写 margin reset:标题、段落、列表统一归零(在 base 层,工具类可覆写)。 */
|
|
108
116
|
h1, h2, h3, h4, h5, h6, p, dl, dd, dt, ul, ol {
|
|
109
117
|
margin: 0;
|
|
@@ -120,13 +128,3 @@
|
|
|
120
128
|
-webkit-touch-callout: none !important;
|
|
121
129
|
-webkit-user-drag: none !important;
|
|
122
130
|
}
|
|
123
|
-
|
|
124
|
-
/* 顶部历史入口在场时欢迎区不再叠加自身顶部留白(壳的跨组件规则)。 */
|
|
125
|
-
.history-entry ~ .mall-home {
|
|
126
|
-
padding-top: 0;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/* 顶部历史入口在场时商圈主屏不再叠加自身顶部留白(ChatPage 槽位包裹层)。 */
|
|
130
|
-
.history-entry ~ .chat-page__home-slot .mall-home {
|
|
131
|
-
padding-top: 0;
|
|
132
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$comment": "主题可覆写变量封闭清单(主题轨 W-T2;doctor theme-package-structure 消费——超集即 error;theme-contract.test.ts 锁 tokens.css+motion.css 的平台键 ⊆ platform 段)。domains 段 = 域色两段式通道(identity/surface/border 三角色,v1 封闭;promotion 按域色矩阵无描边列)。assets 段 = 素材变量链语义位(W-T3 铺开,铺开后逐一核对)。",
|
|
2
|
+
"$comment": "主题可覆写变量封闭清单(主题轨 W-T2;doctor theme-package-structure 消费——超集即 error;theme-contract.test.ts 锁 tokens.css+motion.css 的平台键 ⊆ platform 段)。domains 段 = 域色两段式通道(identity/surface/border 三角色,v1 封闭;promotion 按域色矩阵无描边列)。assets 段 = 素材变量链语义位(W-T3 铺开,铺开后逐一核对)。 pairs 段 = 对比度对账清单(fg/bg 都是 platform 键;min 为 WCAG 阈值;color-mix 派生的由浏览器车道补验)。",
|
|
3
3
|
"platform": [
|
|
4
4
|
"--tbox-accent",
|
|
5
5
|
"--tbox-accent-light",
|
|
@@ -68,5 +68,126 @@
|
|
|
68
68
|
"--tbox-asset-promotion-activity-header",
|
|
69
69
|
"--tbox-asset-promotion-coupon-header",
|
|
70
70
|
"--tbox-asset-sg-header"
|
|
71
|
-
]
|
|
71
|
+
],
|
|
72
|
+
"pairs": [
|
|
73
|
+
{
|
|
74
|
+
"fg": "--tbox-text-primary",
|
|
75
|
+
"bg": "--tbox-bg-card",
|
|
76
|
+
"min": 4.5,
|
|
77
|
+
"usage": "正文"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"fg": "--tbox-text-primary",
|
|
81
|
+
"bg": "--tbox-bg-page",
|
|
82
|
+
"min": 4.5,
|
|
83
|
+
"usage": "正文"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"fg": "--tbox-text-secondary",
|
|
87
|
+
"bg": "--tbox-bg-card",
|
|
88
|
+
"min": 4.5,
|
|
89
|
+
"usage": "次要文字"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"fg": "--tbox-text-secondary",
|
|
93
|
+
"bg": "--tbox-bg-page",
|
|
94
|
+
"min": 4.5,
|
|
95
|
+
"usage": "次要文字"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"fg": "--tbox-text-muted",
|
|
99
|
+
"bg": "--tbox-bg-card",
|
|
100
|
+
"min": 4.5,
|
|
101
|
+
"usage": "说明文字"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"fg": "--tbox-text-muted",
|
|
105
|
+
"bg": "--tbox-bg-page",
|
|
106
|
+
"min": 4.5,
|
|
107
|
+
"usage": "说明文字"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"fg": "--tbox-primary",
|
|
111
|
+
"bg": "--tbox-bg-card",
|
|
112
|
+
"min": 4.5,
|
|
113
|
+
"usage": "链接与主色文字"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"fg": "--tbox-primary-light",
|
|
117
|
+
"bg": "--tbox-primary-dark",
|
|
118
|
+
"min": 4.5,
|
|
119
|
+
"usage": "深底主视觉文字(hero tone=inverse)"
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
"derive": {
|
|
123
|
+
"$comment": "浅色模式派生规则(pnpm exec tbox-app theme derive 消费):from = seed | accent;l 为相对种子的 L 增量,L/C 为绝对目标;派生结果须 pairs 全部闭合。键必须 ⊆ platform。",
|
|
124
|
+
"--tbox-primary": {
|
|
125
|
+
"from": "seed"
|
|
126
|
+
},
|
|
127
|
+
"--tbox-primary-dark": {
|
|
128
|
+
"from": "seed",
|
|
129
|
+
"l": -0.12
|
|
130
|
+
},
|
|
131
|
+
"--tbox-primary-light": {
|
|
132
|
+
"from": "seed",
|
|
133
|
+
"L": 0.96,
|
|
134
|
+
"C": 0.03
|
|
135
|
+
},
|
|
136
|
+
"--tbox-accent": {
|
|
137
|
+
"from": "accent"
|
|
138
|
+
},
|
|
139
|
+
"--tbox-accent-light": {
|
|
140
|
+
"from": "accent",
|
|
141
|
+
"L": 0.96,
|
|
142
|
+
"C": 0.03
|
|
143
|
+
},
|
|
144
|
+
"--tbox-bg-page": {
|
|
145
|
+
"from": "seed",
|
|
146
|
+
"L": 0.975,
|
|
147
|
+
"C": 0.008,
|
|
148
|
+
"mood": {
|
|
149
|
+
"warm": {
|
|
150
|
+
"H": 80
|
|
151
|
+
},
|
|
152
|
+
"cool": {
|
|
153
|
+
"H": 240
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
"--tbox-bg-card": {
|
|
158
|
+
"from": "seed",
|
|
159
|
+
"L": 0.99,
|
|
160
|
+
"C": 0.004
|
|
161
|
+
},
|
|
162
|
+
"--tbox-bg-subtle": {
|
|
163
|
+
"from": "seed",
|
|
164
|
+
"L": 0.95,
|
|
165
|
+
"C": 0.01
|
|
166
|
+
},
|
|
167
|
+
"--tbox-text-primary": {
|
|
168
|
+
"from": "seed",
|
|
169
|
+
"L": 0.25,
|
|
170
|
+
"C": 0.02
|
|
171
|
+
},
|
|
172
|
+
"--tbox-text-secondary": {
|
|
173
|
+
"from": "seed",
|
|
174
|
+
"L": 0.42,
|
|
175
|
+
"C": 0.02
|
|
176
|
+
},
|
|
177
|
+
"--tbox-text-muted": {
|
|
178
|
+
"from": "seed",
|
|
179
|
+
"L": 0.52,
|
|
180
|
+
"C": 0.015
|
|
181
|
+
},
|
|
182
|
+
"--tbox-border": {
|
|
183
|
+
"from": "seed",
|
|
184
|
+
"L": 0.9,
|
|
185
|
+
"C": 0.01
|
|
186
|
+
},
|
|
187
|
+
"--tbox-border-strong": {
|
|
188
|
+
"from": "seed",
|
|
189
|
+
"L": 0.82,
|
|
190
|
+
"C": 0.015
|
|
191
|
+
}
|
|
192
|
+
}
|
|
72
193
|
}
|
|
@@ -18,6 +18,7 @@ const contract = JSON.parse(readFileSync(path.join(themeDir, 'contract.json'), '
|
|
|
18
18
|
platform: string[];
|
|
19
19
|
domains: string[];
|
|
20
20
|
assets: string[];
|
|
21
|
+
derive?: Record<string, { from: 'seed' | 'accent'; L?: number; C?: number; l?: number; mood?: Record<string, { H: number }> }>;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
function extractRootVars(file: string): string[] {
|
|
@@ -55,6 +56,21 @@ describe('主题契约(contract.json)', () => {
|
|
|
55
56
|
for (const key of contract.assets) expect(key.startsWith('--tbox-asset-')).toBe(true);
|
|
56
57
|
});
|
|
57
58
|
|
|
59
|
+
it('derive 段的键 ⊆ platform,且带 from 来源', () => {
|
|
60
|
+
const derive = contract.derive ?? {};
|
|
61
|
+
const allowed = new Set(contract.platform);
|
|
62
|
+
const drift = Object.entries(derive)
|
|
63
|
+
.filter(([key]) => !key.startsWith('$'))
|
|
64
|
+
.filter(([key]) => !allowed.has(key))
|
|
65
|
+
.map(([key]) => key);
|
|
66
|
+
expect(drift, 'derive 声明了契约外的令牌:' + drift.join(', ')).toEqual([]);
|
|
67
|
+
for (const [key, rule] of Object.entries(derive)) {
|
|
68
|
+
if (key.startsWith('$')) continue;
|
|
69
|
+
expect(['seed', 'accent']).toContain(rule.from);
|
|
70
|
+
}
|
|
71
|
+
expect(Object.keys(derive).length).toBeGreaterThan(8);
|
|
72
|
+
});
|
|
73
|
+
|
|
58
74
|
it('motion 族 5 键在清单内(主题轨 T-2.1 契约)', () => {
|
|
59
75
|
for (const key of [
|
|
60
76
|
'--tbox-motion-duration-fast',
|