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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/.gitignore +7 -0
  2. package/.tbox/app.json +1 -1
  3. package/.tbox/default-modules.json +1 -1
  4. package/.tbox/factory/chat.json +9 -0
  5. package/.tbox/miniapp-containers.json +1 -1
  6. package/AGENTS.md +4 -2
  7. package/apps/client/package.json +1 -0
  8. package/apps/client/scripts/._color-scan.test.mjs +0 -0
  9. package/apps/client/scripts/._experience-checks.mjs +0 -0
  10. package/apps/client/scripts/._geometry-kernel.test.mjs +0 -0
  11. package/apps/client/scripts/._in-process-checks.mjs +0 -0
  12. package/apps/client/scripts/._probe-checks.mjs +0 -0
  13. package/apps/client/scripts/._sample-entries.test.mjs +0 -0
  14. package/apps/client/scripts/._storyboard.test.mjs +0 -0
  15. package/apps/client/scripts/._theme-kernel.mjs +0 -0
  16. package/apps/client/scripts/._theme-kernel.test.mjs +0 -0
  17. package/apps/client/scripts/acceptance-changes.test.mjs +97 -0
  18. package/apps/client/scripts/check-evidence.mjs +361 -94
  19. package/apps/client/scripts/color-scan.mjs +66 -0
  20. package/apps/client/scripts/color-scan.test.mjs +25 -0
  21. package/apps/client/scripts/evidence-gate.mjs +248 -46
  22. package/apps/client/scripts/evidence-gate.test.mjs +63 -5
  23. package/apps/client/scripts/experience-checks.mjs +163 -0
  24. package/apps/client/scripts/geometry-kernel.test.mjs +92 -0
  25. package/apps/client/scripts/in-process-checks.mjs +51 -0
  26. package/apps/client/scripts/lib/._card-registry.mjs +0 -0
  27. package/apps/client/scripts/lib/._card-registry.test.mjs +0 -0
  28. package/apps/client/scripts/lib/._evidence-inputs.mjs +0 -0
  29. package/apps/client/scripts/lib/._evidence-inputs.test.mjs +0 -0
  30. package/apps/client/scripts/lib/._static-render.mjs +0 -0
  31. package/apps/client/scripts/lib/._static-render.test.mjs +0 -0
  32. package/apps/client/scripts/lib/card-registry.mjs +81 -0
  33. package/apps/client/scripts/lib/card-registry.test.mjs +59 -0
  34. package/apps/client/scripts/lib/evidence-inputs.mjs +91 -0
  35. package/apps/client/scripts/lib/evidence-inputs.test.mjs +27 -0
  36. package/apps/client/scripts/lib/static-render.mjs +35 -0
  37. package/apps/client/scripts/lib/static-render.test.mjs +21 -0
  38. package/apps/client/scripts/probe-checks.mjs +85 -0
  39. package/apps/client/scripts/render-card.mjs +76 -60
  40. package/apps/client/scripts/sample-entries.test.mjs +31 -0
  41. package/apps/client/scripts/storyboard.test.mjs +149 -0
  42. package/apps/client/scripts/surface-css.mjs +5 -2
  43. package/apps/client/scripts/theme-kernel.mjs +236 -0
  44. package/apps/client/scripts/theme-kernel.test.mjs +136 -0
  45. package/apps/client/src/styles/brand.css +11 -11
  46. package/apps/client/src/styles/tailwind.css +3 -4
  47. package/apps/client/vite.config.ts +2 -1
  48. package/apps/server/scripts/probe.mjs +6 -1
  49. package/apps/server/scripts/scenario-lib.mjs +54 -7
  50. package/apps/server/scripts/scenario.mjs +41 -7
  51. package/config/AGENTS.md +1 -0
  52. package/config/chat.json +21 -9
  53. package/docs/agent/card.md +1 -0
  54. package/docs/agent/kit.md +1 -1
  55. package/docs/agent/shell.md +1 -0
  56. package/docs/agent/style.md +3 -1
  57. package/docs/agent/verify.md +37 -8
  58. package/package.json +9 -6
  59. package/packages/agent-ui-kit/README.md +21 -1
  60. package/packages/agent-ui-kit/catalog.json +1 -1
  61. package/packages/agent-ui-kit/package.json +9 -1
  62. package/packages/agent-ui-kit/src/ChatPage.tsx +30 -1
  63. package/packages/agent-ui-kit/src/card/primitives.test.tsx +10 -0
  64. package/packages/agent-ui-kit/src/card/primitives.tsx +14 -10
  65. package/packages/agent-ui-kit/src/card/view-card.tsx +6 -1
  66. package/packages/agent-ui-kit/src/chat-config.ts +11 -7
  67. package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.test.tsx +3 -0
  68. package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.tsx +2 -7
  69. package/packages/agent-ui-kit/src/components/BottomSheet/._index.test.tsx +0 -0
  70. package/packages/agent-ui-kit/src/components/BottomSheet/._index.tsx +0 -0
  71. package/packages/agent-ui-kit/src/components/BottomSheet/index.test.tsx +90 -0
  72. package/packages/agent-ui-kit/src/components/BottomSheet/index.tsx +129 -0
  73. package/packages/agent-ui-kit/src/components/ChatInput/index.test.tsx +2 -2
  74. package/packages/agent-ui-kit/src/components/ChatInput/index.tsx +21 -16
  75. package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +1 -0
  76. package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +2 -2
  77. package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.tsx +7 -3
  78. package/packages/agent-ui-kit/src/components/ToolCallBlock/index.tsx +4 -2
  79. package/packages/agent-ui-kit/src/index.ts +4 -0
  80. package/packages/agent-ui-kit/src/shell.contract.json +9 -0
  81. package/packages/agent-ui-kit/src/shell.test.ts +10 -0
  82. package/packages/agent-ui-kit/src/shell.ts +15 -0
  83. package/packages/agent-ui-kit/src/theme/contract.json +78 -1
  84. package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +16 -0
  85. package/packages/agent-ui-kit/src/theme/tokens.css +1 -1
  86. package/pnpm-lock.template.yaml +97 -91
  87. package/pnpm-workspace.template.yaml +10 -10
  88. package/profiles/mall/._chat.overrides.json +0 -0
  89. package/profiles/mall/chat.overrides.json +12 -0
  90. package/profiles/mall/config/chat.json +14 -6
  91. package/profiles/mall.json +1 -1
  92. package/scripts/._deliver.mjs +0 -0
  93. package/scripts/._shell-probe.mjs +0 -0
  94. package/scripts/._storyboard.mjs +0 -0
  95. package/scripts/check-fast.mjs +1 -0
  96. package/scripts/checks.json +294 -17
  97. package/scripts/deliver.mjs +183 -0
  98. package/scripts/lib/._chrome-pipe.mjs +0 -0
  99. package/scripts/lib/._geometry-kernel.mjs +0 -0
  100. package/scripts/lib/chrome-pipe.mjs +95 -0
  101. package/scripts/lib/geometry-kernel.mjs +137 -0
  102. package/scripts/shell-probe.mjs +283 -0
  103. package/scripts/storyboard.mjs +350 -0
  104. package/profiles/mall/config/llm_provider.json +0 -5
  105. package/profiles/mall/config/plugins.json +0 -3
  106. package/scripts/gen-tailwind-sources.mjs +0 -55
  107. /package/{profiles/mall/config/._llm_provider.json → .tbox/factory/._chat.json} +0 -0
  108. /package/{profiles/mall/config/._plugins.json → apps/client/scripts/._acceptance-changes.test.mjs} +0 -0
  109. /package/{scripts/._gen-tailwind-sources.mjs → apps/client/scripts/._color-scan.mjs} +0 -0
@@ -0,0 +1,129 @@
1
+ import { useEffect, useId, useRef, useState } from 'react';
2
+ import type { ComponentType, ReactNode } from 'react';
3
+ import type { PopupProps } from 'antd-mobile';
4
+
5
+ export interface BottomSheetProps {
6
+ open: boolean;
7
+ title: string;
8
+ onClose: () => void;
9
+ children: ReactNode;
10
+ /** 内容容器的业务样式;弹层外壳由组件统一管理。 */
11
+ className?: string;
12
+ }
13
+
14
+ type PopupComponent = ComponentType<PopupProps>;
15
+
16
+ /**
17
+ * antd-mobile 带 CSS 的运行时依赖只在浏览器按需加载:kit 源码在 Node/Vite SSR 里可直接 import
18
+ * (静态 import 会让 Node 读到 CJS 入口 require 的 global.css,整条证据链/SSR 消费者失败)。
19
+ * 失败时清空缓存,允许下一次交互重试。
20
+ */
21
+ let popupPromise: Promise<PopupComponent> | undefined;
22
+
23
+ export function preloadBottomSheet(): Promise<ComponentType<PopupProps>> {
24
+ popupPromise ??= import('antd-mobile')
25
+ .then((module) => module.Popup as PopupComponent)
26
+ .catch((error: unknown) => {
27
+ popupPromise = undefined;
28
+ throw error;
29
+ });
30
+ return popupPromise;
31
+ }
32
+
33
+ /** 受控底部弹层:业务只提供内容与开关,不自行处理遮罩、滚动和焦点。 */
34
+ export function BottomSheet({ open, title, onClose, children, className }: BottomSheetProps) {
35
+ const titleId = useId();
36
+ const panelRef = useRef<HTMLDivElement>(null);
37
+ const closeRef = useRef<HTMLButtonElement>(null);
38
+ const onCloseRef = useRef(onClose);
39
+ onCloseRef.current = onClose;
40
+ const [Popup, setPopup] = useState<PopupComponent | null>(null);
41
+
42
+ useEffect(() => {
43
+ if (Popup) return;
44
+ let alive = true;
45
+ preloadBottomSheet()
46
+ .then((loaded) => {
47
+ if (alive) setPopup(() => loaded);
48
+ })
49
+ .catch((error: unknown) => {
50
+ // 一次 chunk 失败不应静默:保留可诊断信息;open 变化会再次进入本 effect 重试(promise 已清空)。
51
+ console.warn('BottomSheet: antd-mobile Popup 加载失败', error);
52
+ });
53
+ return () => {
54
+ alive = false;
55
+ };
56
+ }, [open, Popup]);
57
+
58
+ // 懒加载窗口:弹层未就绪时先挡住背景交互(无遮罩会让「模态」破窗)。
59
+ useEffect(() => {
60
+ if (!open || Popup) return;
61
+ const previous = document.body.style.overflow;
62
+ document.body.style.overflow = 'hidden';
63
+ return () => {
64
+ document.body.style.overflow = previous;
65
+ };
66
+ }, [open, Popup]);
67
+
68
+ useEffect(() => {
69
+ if (!open) return;
70
+ const previous = document.activeElement;
71
+ const onKeyDown = (event: KeyboardEvent) => {
72
+ if (event.key === 'Escape') {
73
+ event.preventDefault();
74
+ event.stopPropagation();
75
+ onCloseRef.current();
76
+ }
77
+ if (event.key !== 'Tab' || !panelRef.current) return;
78
+ const focusable = [...panelRef.current.querySelectorAll<HTMLElement>(
79
+ 'button:not(:disabled), a[href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex="0"]',
80
+ )].filter((element) => !element.hidden && element.getAttribute('aria-hidden') !== 'true');
81
+ const first = focusable[0];
82
+ const last = focusable[focusable.length - 1];
83
+ if (!first || !last) return;
84
+ const active = document.activeElement;
85
+ if (event.shiftKey && (active === first || !panelRef.current.contains(active))) {
86
+ event.preventDefault();
87
+ last.focus();
88
+ } else if (!event.shiftKey && (active === last || !panelRef.current.contains(active))) {
89
+ event.preventDefault();
90
+ first.focus();
91
+ }
92
+ };
93
+ document.addEventListener('keydown', onKeyDown);
94
+ return () => {
95
+ document.removeEventListener('keydown', onKeyDown);
96
+ if (previous instanceof HTMLElement && previous.isConnected) previous.focus();
97
+ };
98
+ }, [open]);
99
+
100
+ // Popup 晚于 open 就绪时 afterShow 不保证触发,这里补一次显式聚焦。
101
+ useEffect(() => {
102
+ if (!open || !Popup) return;
103
+ const timer = window.setTimeout(() => closeRef.current?.focus(), 0);
104
+ return () => window.clearTimeout(timer);
105
+ }, [open, Popup]);
106
+
107
+ if (!Popup) {
108
+ return open ? <div className="fixed inset-0 z-[1100] bg-scrim" role="presentation" aria-hidden="true" /> : null;
109
+ }
110
+
111
+ return (
112
+ <Popup className="motion-reduce:[&_.adm-popup-body]:transition-none motion-reduce:[&_.adm-mask]:transition-none" visible={open} position="bottom" onClose={onClose} closeOnMaskClick
113
+ destroyOnClose disableBodyScroll bodyClassName="tbox-bottom-sheet mx-auto w-full overflow-hidden rounded-t-[14px] bg-card text-foreground"
114
+ style={{ '--z-index': '1100' }} afterShow={() => closeRef.current?.focus()}>
115
+ <div ref={panelRef} className="tbox-bottom-sheet__panel flex max-h-[65vh] flex-col supports-[height:100dvh]:max-h-[65dvh]" role="dialog"
116
+ aria-modal="true" aria-labelledby={titleId}>
117
+ <header className="tbox-bottom-sheet__header flex shrink-0 items-center justify-between gap-3 px-3.5 py-3">
118
+ <h2 id={titleId} className="m-0 text-base font-semibold leading-[21px]">{title}</h2>
119
+ <button className="flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-1.5 text-inherit focus-visible:outline-2 focus-visible:outline-primary" ref={closeRef} type="button" aria-label={`关闭${title}`} onClick={onClose}>
120
+ <svg className="size-4.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true">
121
+ <path d="m6 6 12 12M6 18 18 6" />
122
+ </svg>
123
+ </button>
124
+ </header>
125
+ <div className={['tbox-bottom-sheet__body min-h-0 overflow-y-auto overscroll-contain px-3.5 pt-0 pb-[calc(16px+env(safe-area-inset-bottom))] text-sm leading-[19px]', className].filter(Boolean).join(' ')}>{children}</div>
126
+ </div>
127
+ </Popup>
128
+ );
129
+ }
@@ -83,9 +83,9 @@ describe('ChatInput 语音活动状态', () => {
83
83
  });
84
84
 
85
85
  describe('ChatInput 派生模式(服务端 defaultInputMode 水合)', () => {
86
- /** voice 态投影:录音模式显示"键盘"切换图标;text 态显示"语音"切换图标 */
86
+ /** voice 态投影:录音模式的可访问名为「切换到键盘输入」;text 态为「切换到语音输入」 */
87
87
  const inVoiceMode = (container: HTMLElement) =>
88
- container.querySelector('img[alt="键盘"]') !== null;
88
+ container.querySelector('.tbox-voice-toggle[aria-label="切换到键盘输入"]') !== null;
89
89
 
90
90
  const renderInput = async (root: ReturnType<typeof createRoot>) => {
91
91
  await act(async () => root.render(<ChatInput onSend={vi.fn()} />));
@@ -190,9 +190,9 @@ export function ChatInput({
190
190
 
191
191
  <div className="tbox-chat-input__row flex flex-wrap items-end gap-2">
192
192
  {onNewChat && (
193
- <div className="tbox-new-chat-btn flex size-11 shrink-0 items-center justify-center rounded-full bg-[rgba(255,255,255,0.5)] shadow-[0_1px_10px_rgba(110,139,180,0.24)]" onClick={onNewChat}>
194
- <img className="tbox-new-chat-btn__icon size-[22px]" src={newChatIcon} alt="新对话" />
195
- </div>
193
+ <button type="button" data-tbox-control="new-chat" aria-label="新建对话" className="tbox-new-chat-btn flex size-11 shrink-0 cursor-pointer appearance-none items-center justify-center rounded-full border-0 bg-[rgba(255,255,255,0.5)] p-0 shadow-[0_1px_10px_rgba(110,139,180,0.24)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary" onClick={onNewChat}>
194
+ <img className="tbox-new-chat-btn__icon size-[22px]" src={newChatIcon} alt="" />
195
+ </button>
196
196
  )}
197
197
 
198
198
  <div className="tbox-chat-input__wrapper flex min-w-0 flex-1 items-end gap-[14px] rounded-[var(--tbox-input-radius)] border border-border bg-[var(--tbox-input-bg)] p-[var(--tbox-input-padding)] shadow-[0_1px_10px_rgba(110,139,180,0.24)] transition-[border-color,box-shadow] duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] focus-within:border-primary focus-within:shadow-[0_0_0_1.5px_rgba(9,107,250,0.12)]">
@@ -224,31 +224,36 @@ export function ChatInput({
224
224
  )}
225
225
 
226
226
  {enableVoice && (
227
- <div className="tbox-voice-toggle flex size-[22px] shrink-0 items-center justify-center" onClick={toggleMode}>
227
+ <button type="button" data-tbox-control="voice-toggle" aria-label={inputMode === 'voice' ? '切换到键盘输入' : '切换到语音输入'} aria-pressed={inputMode === 'voice'} className="tbox-voice-toggle flex size-11 -m-[11px] shrink-0 cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary" onClick={toggleMode}>
228
228
  <img
229
229
  className="tbox-voice-toggle__icon size-[22px]"
230
230
  src={inputMode === 'voice' ? keyboardIcon : voiceIcon}
231
- alt={inputMode === 'voice' ? '键盘' : '语音'}
231
+ alt=""
232
232
  />
233
- </div>
233
+ </button>
234
234
  )}
235
235
 
236
236
  {blocked ? null : generating ? (
237
- <div className="tbox-chat-input__send tbox-chat-input__send--active flex size-[var(--tbox-send-btn-size)] shrink-0 items-center justify-center" onClick={onCancel}>
238
- <img className="tbox-chat-input__send-img block size-[var(--tbox-send-btn-size)]" src={stopIcon} alt="停止" />
239
- </div>
237
+ <button type="button" data-tbox-control="stop" aria-label="停止生成" className="tbox-chat-input__send tbox-chat-input__send--active flex size-11 -m-[11px] shrink-0 cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary" onClick={onCancel}>
238
+ <img className="tbox-chat-input__send-img block size-[var(--tbox-send-btn-size)]" src={stopIcon} alt="" />
239
+ </button>
240
240
  ) : canSend ? (
241
- <div className="tbox-chat-input__send tbox-chat-input__send--active flex size-[var(--tbox-send-btn-size)] shrink-0 items-center justify-center" onClick={submit}>
242
- <img className="tbox-chat-input__send-img block size-[var(--tbox-send-btn-size)]" src={sendIcon} alt="发送" />
243
- </div>
241
+ <button type="button" data-tbox-control="send" aria-label="发送" className="tbox-chat-input__send tbox-chat-input__send--active flex size-11 -m-[11px] shrink-0 cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary" onClick={submit}>
242
+ <img className="tbox-chat-input__send-img block size-[var(--tbox-send-btn-size)]" src={sendIcon} alt="" />
243
+ </button>
244
244
  ) : menuOptions.length > 0 ? (
245
245
  <div className="tbox-media-picker relative shrink-0">
246
- <div
247
- className={`tbox-media-picker__trigger flex shrink-0 items-center justify-center transition-transform duration-[var(--tbox-motion-duration-base)] ease-[ease] ${menuVisible ? ' tbox-media-picker__trigger--open rotate-45' : ''}`}
246
+ <button
247
+ type="button"
248
+ data-tbox-control="media-add"
249
+ aria-label="添加图片或视频"
250
+ aria-haspopup="menu"
251
+ aria-expanded={menuVisible}
252
+ className={`tbox-media-picker__trigger flex size-11 -m-[11px] shrink-0 cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0 transition-transform duration-[var(--tbox-motion-duration-base)] ease-[ease] ${menuVisible ? ' tbox-media-picker__trigger--open rotate-45' : ''}`}
248
253
  onClick={onPlus}
249
254
  >
250
- <img className="tbox-media-picker__trigger-icon size-[var(--tbox-send-btn-size)]" src={moreIcon} alt="更多" />
251
- </div>
255
+ <img className="tbox-media-picker__trigger-icon size-[var(--tbox-send-btn-size)]" src={moreIcon} alt="" />
256
+ </button>
252
257
  </div>
253
258
  ) : null}
254
259
  </div>
@@ -29,6 +29,7 @@ export default function HistoryEntry({
29
29
  <div className="history-entry flex justify-center p-0">
30
30
  <button
31
31
  type="button"
32
+ data-tbox-control="history"
32
33
  className="history-entry__button inline-flex min-h-11 appearance-none items-center gap-[5px] rounded-[25px] border-0 bg-muted px-4 py-1 text-sm font-normal leading-[18px] text-muted-foreground transition-colors duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] [font-family:inherit] active:bg-border disabled:cursor-default"
33
34
  disabled={disabled}
34
35
  onClick={onLoad}
@@ -57,8 +57,8 @@ export function QuickCommands({
57
57
  aria-hidden="true"
58
58
  data-icon={cmd.icon ?? starIcon}
59
59
  style={{
60
- maskImage: `url(${cmd.icon ?? starIcon})`,
61
- WebkitMaskImage: `url(${cmd.icon ?? starIcon})`,
60
+ maskImage: `url("${cmd.icon ?? starIcon}")`,
61
+ WebkitMaskImage: `url("${cmd.icon ?? starIcon}")`,
62
62
  maskSize: 'contain',
63
63
  WebkitMaskSize: 'contain',
64
64
  maskRepeat: 'no-repeat',
@@ -1,8 +1,12 @@
1
1
  /** 生成时出现的“回到底部”悬浮按钮。 */
2
2
  export default function ScrollToBottomButton({ visible, onClick }: { visible: boolean; onClick: () => void }) {
3
3
  return (
4
- <div className={`scroll-to-bottom-btn absolute right-4 bottom-4 z-10 flex size-9 items-center justify-center rounded-full bg-white shadow-[0_2px_8px_0_rgba(0,0,0,0.12)] transition-[opacity,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] ${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}>
5
- <div className="scroll-to-bottom-btn__arrow h-0 w-0 border-x-[6px] border-t-[7px] border-x-transparent border-t-[#666]" />
6
- </div>
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
- ) : summary.failedCount > 0 ? (
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
- {summary.failedCount > 0 && (
91
+ {allFailed && (
90
92
  <span className="tool-calls__failed text-muted-foreground"> · {summary.failedCount} 个失败</span>
91
93
  )}
92
94
  </span>
@@ -124,3 +124,7 @@ export type {
124
124
  MessageStatus,
125
125
  ToolCallInfo,
126
126
  } from './types';
127
+
128
+ // ── 通用弹层 ──
129
+ export { BottomSheet, preloadBottomSheet } from './components/BottomSheet';
130
+ export type { BottomSheetProps } from './components/BottomSheet';
@@ -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
  }
@@ -111,6 +111,83 @@
111
111
  "bg": "--tbox-bg-card",
112
112
  "min": 4.5,
113
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
114
191
  }
115
- ]
192
+ }
116
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',
@@ -13,7 +13,7 @@
13
13
  :root {
14
14
  /* 主色(mall-vis 蓝系) */
15
15
  --tbox-primary: #096bfa;
16
- --tbox-primary-dark: #2368ec;
16
+ --tbox-primary-dark: #1c61e5;
17
17
  --tbox-primary-light: #eaf3ff;
18
18
  --tbox-accent: #096bfa;
19
19
  --tbox-accent-light: #eaf3ff;