@tbox.cn/app-agent-ui-kit 1.0.0-alpha.15 → 1.0.0-alpha.17

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.
@@ -19,6 +19,7 @@ import {
19
19
  Hero,
20
20
  KeyValueList,
21
21
  Notice,
22
+ StatGrid,
22
23
  StatusTag,
23
24
  Steps,
24
25
  TagList,
@@ -35,15 +36,27 @@ function toSpec(action: CardViewAction): CardActionSpec {
35
36
  label: action.label,
36
37
  ...(action.send !== undefined ? { send: action.send } : {}),
37
38
  ...(action.invoke ? { invoke: action.invoke } : {}),
38
- ...(action.confirm ? { confirm: action.confirm } : {}),
39
+ ...(action.confirm
40
+ ? {
41
+ confirm: {
42
+ title: action.confirm.title,
43
+ ...(action.confirm.description ? { description: action.confirm.description } : {}),
44
+ ...(action.confirm.confirmText ? { confirmText: action.confirm.confirmText } : {}),
45
+ ...(action.confirm.cancelText ? { cancelText: action.confirm.cancelText } : {}),
46
+ ...(action.confirm.tone ? { tone: action.confirm.tone } : {}),
47
+ ...(action.confirm.highlights ? { highlights: action.confirm.highlights } : {}),
48
+ },
49
+ }
50
+ : {}),
39
51
  ...(action.style ? { style: action.style } : {}),
40
52
  };
41
53
  }
42
54
 
43
55
  /** 列表项内联动作:与卡级动作共用确认弹层语义与结算语义,但不占整行。 */
44
56
  function useInlineRunner(api: Api) {
45
- const [pending, setPending] = useState<CardViewAction | null>(null);
46
- const [running, setRunning] = useState(false);
57
+ const [pending, setPending] = useState<{ action: CardViewAction; key: string } | null>(null);
58
+ // 只记「哪一颗」在跑:卡片里多个条目各有按钮时,只让被点那颗转圈,其余仅置灰。
59
+ const [runningKey, setRunningKey] = useState<string | null>(null);
47
60
  const runningRef = useRef(false);
48
61
  /** 挂起令牌:动作结束信号到达时若已换轮次,不再改状态 */
49
62
  const tokenRef = useRef<symbol | null>(null);
@@ -54,12 +67,12 @@ function useInlineRunner(api: Api) {
54
67
  return () => { mountedRef.current = false; };
55
68
  }, []);
56
69
 
57
- const run = (action: CardViewAction) => {
70
+ const run = (action: CardViewAction, key: string) => {
58
71
  if (!action.invoke && !action.send) return;
59
72
  const token = Symbol('inline');
60
73
  runningRef.current = true;
61
74
  tokenRef.current = token;
62
- setRunning(true);
75
+ setRunningKey(key);
63
76
  const promise = action.invoke
64
77
  ? api.invoke(action.invoke.id, action.invoke.input)
65
78
  : typeof action.send === 'string'
@@ -70,48 +83,57 @@ function useInlineRunner(api: Api) {
70
83
  if (!mountedRef.current) return;
71
84
  if (tokenRef.current !== token) return;
72
85
  runningRef.current = false;
73
- setRunning(false);
86
+ setRunningKey(null);
74
87
  };
75
88
  void promise.then(clear, clear);
76
89
  };
77
- const trigger = (action: CardViewAction) => {
90
+ const trigger = (action: CardViewAction, key: string) => {
78
91
  if (api.disabled || runningRef.current || pending !== null) return;
79
92
  if (action.confirm) {
80
- setPending(action);
93
+ setPending({ action, key });
81
94
  return;
82
95
  }
83
- run(action);
96
+ run(action, key);
84
97
  };
98
+ const pendingAction = pending?.action;
85
99
  const sheet =
86
- pending && pending.confirm ? (
100
+ pendingAction?.confirm ? (
87
101
  <ConfirmSheet
88
102
  open
89
- title={pending.confirm.title}
90
- {...(pending.confirm.description ? { description: pending.confirm.description } : {})}
91
- {...(pending.confirm.confirmText ? { confirmText: pending.confirm.confirmText } : {})}
92
- {...(pending.confirm.cancelText ? { cancelText: pending.confirm.cancelText } : {})}
103
+ title={pendingAction.confirm.title}
104
+ {...(pendingAction.confirm.description ? { description: pendingAction.confirm.description } : {})}
105
+ {...(pendingAction.confirm.confirmText ? { confirmText: pendingAction.confirm.confirmText } : {})}
106
+ {...(pendingAction.confirm.cancelText ? { cancelText: pendingAction.confirm.cancelText } : {})}
107
+ {...(pendingAction.confirm.tone ? { tone: pendingAction.confirm.tone } : {})}
108
+ {...(pendingAction.confirm.highlights ? { highlights: pendingAction.confirm.highlights } : {})}
93
109
  onConfirm={() => {
94
- const action = pending;
110
+ const next = pending;
95
111
  setPending(null);
96
- run(action);
112
+ if (next) run(next.action, next.key);
97
113
  }}
98
114
  onCancel={() => setPending(null)}
99
115
  />
100
116
  ) : null;
101
- return { trigger, sheet, busy: api.disabled || running || pending !== null };
117
+ return {
118
+ trigger,
119
+ sheet,
120
+ busy: api.disabled || runningKey !== null || pending !== null,
121
+ runningKey,
122
+ };
102
123
  }
103
124
 
104
125
  function renderBlock(
105
126
  block: CardViewBlock,
106
- trigger: (action: CardViewAction) => void,
127
+ trigger: (action: CardViewAction, key: string) => void,
107
128
  disabled: boolean,
129
+ runningKey: string | null = null,
108
130
  ): ReactNode {
109
131
  switch (block.kind) {
110
132
  case 'hero':
111
133
  return (
112
134
  <Hero
113
135
  {...(block.eyebrow ? { eyebrow: block.eyebrow } : {})}
114
- title={block.title}
136
+ {...(block.title ? { title: block.title } : {})}
115
137
  {...(block.value ? { value: block.value } : {})}
116
138
  {...(block.unit ? { unit: block.unit } : {})}
117
139
  {...(block.footnote ? { footnote: block.footnote } : {})}
@@ -133,6 +155,47 @@ function renderBlock(
133
155
  return <TagList tags={block.tags} {...(block.tone ? { tone: block.tone } : {})} />;
134
156
  case 'steps':
135
157
  return <Steps steps={block.steps} />;
158
+ case 'stats':
159
+ return (
160
+ <StatGrid
161
+ items={block.items.map((item) => ({
162
+ label: item.label,
163
+ value: item.value,
164
+ ...(item.hint ? { hint: item.hint } : {}),
165
+ }))}
166
+ />
167
+ );
168
+ case 'tickets':
169
+ return (
170
+ <div className="tbox-view-tickets flex flex-col gap-2.5">
171
+ {block.items.map((item, index) => (
172
+ <Ticket
173
+ key={item.title + '-' + index}
174
+ amount={item.amount}
175
+ {...(item.condition ? { condition: item.condition } : {})}
176
+ {...(item.meta ? { meta: item.meta } : {})}
177
+ {...(item.status ? { status: <StatusTag tone={item.status.tone ?? 'info'}>{item.status.text}</StatusTag> } : {})}
178
+ {...(item.tone ? { tone: item.tone } : {})}
179
+ {...(item.title ? { title: item.title } : {})}
180
+ {...(item.action
181
+ ? {
182
+ action: (
183
+ <CardButton
184
+ size="sm"
185
+ variant={item.action.style === 'primary' ? 'primary' : 'secondary'}
186
+ disabled={disabled}
187
+ loading={runningKey === 'ticket-' + index}
188
+ onClick={() => trigger(item.action as CardViewAction, 'ticket-' + index)}
189
+ >
190
+ {item.action.label}
191
+ </CardButton>
192
+ ),
193
+ }
194
+ : {})}
195
+ />
196
+ ))}
197
+ </div>
198
+ );
136
199
  case 'ticket':
137
200
  return (
138
201
  <Ticket
@@ -163,23 +226,51 @@ function renderBlock(
163
226
  <EntityRow
164
227
  key={item.title + '-' + index}
165
228
  title={item.title}
229
+ {...(item.badge ? { badge: item.badge } : {})}
230
+ {...(item.status
231
+ ? { status: <StatusTag tone={item.status.tone ?? 'info'}>{item.status.text}</StatusTag> }
232
+ : {})}
166
233
  {...(item.meta ? { meta: item.meta } : {})}
167
234
  {...(item.price ? { price: item.price } : {})}
168
235
  {...(item.description ? { description: item.description } : {})}
169
236
  {...(item.tags && item.tags.length > 0 ? { tags: <TagList tags={item.tags} /> } : {})}
170
- {...(item.action
237
+ {...(item.action && !item.actions
171
238
  ? {
172
239
  action: (
173
240
  <CardButton
174
241
  variant={item.action.style === 'primary' ? 'primary' : 'secondary'}
175
242
  disabled={disabled}
176
- onClick={() => trigger(item.action as CardViewAction)}
243
+ loading={runningKey === 'list-' + index}
244
+ onClick={() => trigger(item.action as CardViewAction, 'list-' + index)}
177
245
  >
178
246
  {item.action.label}
179
247
  </CardButton>
180
248
  ),
181
249
  }
182
250
  : {})}
251
+ {...(item.actions && item.actions.length > 0
252
+ ? {
253
+ actions: (
254
+ <>
255
+ {item.actions.map((action, actionIndex) => {
256
+ const actionKey = 'list-' + index + '-' + actionIndex;
257
+ return (
258
+ <CardButton
259
+ key={actionKey}
260
+ size="sm"
261
+ variant={action.style === 'primary' ? 'primary' : 'secondary'}
262
+ disabled={disabled}
263
+ loading={runningKey === actionKey}
264
+ onClick={() => trigger(action, actionKey)}
265
+ >
266
+ {action.label}
267
+ </CardButton>
268
+ );
269
+ })}
270
+ </>
271
+ ),
272
+ }
273
+ : {})}
183
274
  />
184
275
  ))}
185
276
  </div>
@@ -229,7 +320,7 @@ export function ViewCard({
229
320
  : {})}
230
321
  />
231
322
  {safeView.blocks.map((block, index) => (
232
- <div key={block.kind + '-' + index}>{renderBlock(block, inline.trigger, inline.busy)}</div>
323
+ <div key={block.kind + '-' + index}>{renderBlock(block, inline.trigger, inline.busy, inline.runningKey)}</div>
233
324
  ))}
234
325
  {safeView.actions && safeView.actions.length > 0 ? (
235
326
  <ActionList
@@ -20,6 +20,8 @@ export interface QuickCommand {
20
20
  export interface ChatWelcome {
21
21
  title: string;
22
22
  subtitle?: string;
23
+ /** 欢迎区表面变体(只消费既有主题变量;缺省 default) */
24
+ surface?: 'default' | 'brand' | 'subtle';
23
25
  }
24
26
 
25
27
  interface ChatConfigStore {
@@ -40,9 +40,17 @@ export function DebugButton({
40
40
  };
41
41
 
42
42
  return (
43
- <div className="tbox-debug-btn inline-flex h-[26px] items-center justify-center gap-1 rounded-full bg-white px-[11px] text-secondary-foreground transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] active:scale-[0.97] active:bg-muted" onClick={onClick}>
44
- <Bug className="tbox-debug-btn__icon size-[14px] shrink-0" size={22} />
45
- <span className="tbox-debug-btn__text text-xs leading-none">调试</span>
46
- </div>
43
+ // 语义 button + 44px 命中区(与操作栏其余按钮同高);视觉仍是 26px 高的小胶囊。
44
+ <button
45
+ type="button"
46
+ aria-label="调试信息"
47
+ className="tbox-debug-btn flex h-11 shrink-0 cursor-pointer items-center justify-center border-0 bg-transparent p-0 text-secondary-foreground [font-family:inherit]"
48
+ onClick={onClick}
49
+ >
50
+ <span className="tbox-debug-btn__chip inline-flex h-[26px] items-center justify-center gap-1 rounded-full bg-white px-[11px] transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] active:scale-[0.97] active:bg-muted">
51
+ <Bug className="tbox-debug-btn__icon size-[14px] shrink-0" size={22} />
52
+ <span className="tbox-debug-btn__text text-xs leading-none">调试</span>
53
+ </span>
54
+ </button>
47
55
  );
48
56
  }
@@ -37,6 +37,46 @@ export function getMessageCopyText(message: ChatMessage): string {
37
37
  return [message.content, message.error].filter(Boolean).join('\n\n');
38
38
  }
39
39
 
40
+ /**
41
+ * 操作栏按钮基座:外壳 44×44(命中区达标),视觉 28×28 圆底(保持原有轻量感)。
42
+ *
43
+ * 之前 5 个按钮各自写尺寸:朗读/赞/踩被改成 44,复制/调试仍是 26 —— 同一行混排且复制不达标。
44
+ * 统一走这个组件后,尺寸、按压缩放、悬停底色只有一处真源。
45
+ */
46
+ export const ACTION_ICON_BTN_CLASS =
47
+ 'tbox-action-btn tbox-action-icon flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-0 text-muted-foreground transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] [font-family:inherit] active:scale-[0.97]';
48
+
49
+ /** 视觉圆底(28×28):静止时透明,hover/按压出现浅底,与主题浅色面一致。 */
50
+ const ACTION_ICON_CHIP_CLASS =
51
+ 'flex size-7 items-center justify-center rounded-full bg-white transition-colors duration-[var(--tbox-motion-duration-fast)] ease-[ease] group-hover:bg-muted';
52
+
53
+ export function ActionIconButton({
54
+ label,
55
+ onClick,
56
+ active,
57
+ className = '',
58
+ children,
59
+ }: {
60
+ label: string;
61
+ onClick?: () => void;
62
+ /** 选中态(赞/踩/朗读中):图标转主色 */
63
+ active?: boolean;
64
+ className?: string;
65
+ children: React.ReactNode;
66
+ }) {
67
+ return (
68
+ <button
69
+ type="button"
70
+ aria-label={label}
71
+ {...(active === undefined ? {} : { 'aria-pressed': active })}
72
+ className={`${ACTION_ICON_BTN_CLASS} group ${active ? 'text-primary' : ''} ${className}`}
73
+ onClick={onClick}
74
+ >
75
+ <span className={`${ACTION_ICON_CHIP_CLASS} ${active ? 'bg-primary-foreground' : ''}`}>{children}</span>
76
+ </button>
77
+ );
78
+ }
79
+
40
80
  export function CopyButton({ text }: { text: string }) {
41
81
  const copy = async () => {
42
82
  const copied = await copyText(text);
@@ -44,11 +84,9 @@ export function CopyButton({ text }: { text: string }) {
44
84
  };
45
85
 
46
86
  return (
47
- <button type="button" className="tbox-action-btn flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded-full border-0 bg-white p-0 text-muted-foreground transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] [font-family:inherit] active:scale-[0.97] active:bg-muted" onClick={copy} aria-label="复制">
48
- <span className="tbox-action-btn__icon-wrap flex size-[14px] shrink-0 items-center justify-center">
49
- <Copy size={22} />
50
- </span>
51
- </button>
87
+ <ActionIconButton label="复制" onClick={copy}>
88
+ <Copy size={18} />
89
+ </ActionIconButton>
52
90
  );
53
91
  }
54
92
 
@@ -109,41 +147,37 @@ export function ActionBar({ message }: { message: ChatMessage }) {
109
147
  return (
110
148
  <div className="tbox-action-bar flex items-center gap-2">
111
149
  {enableTTS && tts && (
112
- <div className={`tbox-action-btn flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded-full border-0 p-0 transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] [font-family:inherit] active:scale-[0.97] active:bg-muted ${wave ? ' tbox-tts-btn--playing bg-primary-foreground text-primary' : ' bg-white text-muted-foreground'}`} onClick={onTts}>
150
+ <ActionIconButton label={wave ? '暂停朗读' : '朗读这条回复'} onClick={onTts} active={wave}>
113
151
  {wave ? (
114
- <div className="tbox-tts-wave flex size-[14px] items-center justify-center gap-[1.5px]">
115
- <div className="tbox-tts-wave__bar tbox-tts-wave__bar--1 h-[7px] w-[1.5px] origin-bottom rounded-full bg-primary animate-[tbox-tts-wave_0.8s_ease-in-out_infinite] [animation-delay:0s]" />
116
- <div className="tbox-tts-wave__bar tbox-tts-wave__bar--2 h-[9px] w-[1.5px] origin-bottom rounded-full bg-primary animate-[tbox-tts-wave_0.8s_ease-in-out_infinite] [animation-delay:0.15s]" />
117
- <div className="tbox-tts-wave__bar tbox-tts-wave__bar--3 h-[6px] w-[1.5px] origin-bottom rounded-full bg-primary animate-[tbox-tts-wave_0.8s_ease-in-out_infinite] [animation-delay:0.3s]" />
118
- </div>
152
+ <span className="tbox-tts-wave flex size-[14px] items-center justify-center gap-[1.5px]">
153
+ <span className="tbox-tts-wave__bar tbox-tts-wave__bar--1 h-[7px] w-[1.5px] origin-bottom rounded-full bg-primary animate-[tbox-tts-wave_0.8s_ease-in-out_infinite] [animation-delay:0s]" />
154
+ <span className="tbox-tts-wave__bar tbox-tts-wave__bar--2 h-[9px] w-[1.5px] origin-bottom rounded-full bg-primary animate-[tbox-tts-wave_0.8s_ease-in-out_infinite] [animation-delay:0.15s]" />
155
+ <span className="tbox-tts-wave__bar tbox-tts-wave__bar--3 h-[6px] w-[1.5px] origin-bottom rounded-full bg-primary animate-[tbox-tts-wave_0.8s_ease-in-out_infinite] [animation-delay:0.3s]" />
156
+ </span>
119
157
  ) : (
120
- <div className="tbox-action-btn__icon-wrap flex size-[14px] shrink-0 items-center justify-center">
121
- <SpeakerHigh size={22} />
122
- </div>
158
+ <SpeakerHigh size={18} />
123
159
  )}
124
- </div>
160
+ </ActionIconButton>
125
161
  )}
126
162
 
127
163
  <CopyButton text={getMessageCopyText(message)} />
128
164
 
129
165
  {canFeedback && (
130
166
  <>
131
- <div
132
- className={`tbox-action-btn flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded-full border-0 p-0 transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] [font-family:inherit] active:scale-[0.97] active:bg-muted ${message.feedbackState === 'like' ? ' tbox-action-btn--active bg-primary-foreground text-primary' : ' bg-white text-muted-foreground'}`}
167
+ <ActionIconButton
168
+ label="这条回复有帮助"
169
+ active={message.feedbackState === 'like'}
133
170
  onClick={() => onFeedback('like')}
134
171
  >
135
- <div className="tbox-action-btn__icon-wrap flex size-[14px] shrink-0 items-center justify-center">
136
- <ThumbsUp size={22} />
137
- </div>
138
- </div>
139
- <div
140
- className={`tbox-action-btn flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded-full border-0 p-0 transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] [font-family:inherit] active:scale-[0.97] active:bg-muted ${message.feedbackState === 'dislike' ? ' tbox-action-btn--active bg-primary-foreground text-primary' : ' bg-white text-muted-foreground'}`}
172
+ <ThumbsUp size={18} />
173
+ </ActionIconButton>
174
+ <ActionIconButton
175
+ label="这条回复没帮助"
176
+ active={message.feedbackState === 'dislike'}
141
177
  onClick={() => onFeedback('dislike')}
142
178
  >
143
- <div className="tbox-action-btn__icon-wrap flex size-[14px] shrink-0 items-center justify-center">
144
- <ThumbsDown size={22} />
145
- </div>
146
- </div>
179
+ <ThumbsDown size={18} />
180
+ </ActionIconButton>
147
181
  </>
148
182
  )}
149
183
 
@@ -9,6 +9,11 @@ export interface BottomSheetProps {
9
9
  children: ReactNode;
10
10
  /** 内容容器的业务样式;弹层外壳由组件统一管理。 */
11
11
  className?: string;
12
+ /**
13
+ * `default` = 标题栏 + 关闭按钮;
14
+ * `card` = 只留拖拽条与悬浮关闭按钮,让内容里的卡片标题成为唯一主标题(避免「抽屉大标题 + 卡内标题」双头)。
15
+ */
16
+ variant?: 'default' | 'card';
12
17
  }
13
18
 
14
19
  /**
@@ -19,9 +24,10 @@ export interface BottomSheetProps {
19
24
  export async function preloadBottomSheet(): Promise<void> {}
20
25
 
21
26
  /** 受控底部弹层:业务只提供内容与开关,不自行处理遮罩、滚动和焦点。 */
22
- export function BottomSheet({ open, title, onClose, children, className }: BottomSheetProps) {
27
+ export function BottomSheet({ open, title, onClose, children, className, variant = 'default' }: BottomSheetProps) {
23
28
  const titleId = useId();
24
29
  const closeRef = useRef<HTMLButtonElement>(null);
30
+ const cardMode = variant === 'card';
25
31
 
26
32
  return (
27
33
  <Overlay
@@ -35,14 +41,32 @@ export function BottomSheet({ open, title, onClose, children, className }: Botto
35
41
  panelClassName="tbox-bottom-sheet tbox-bottom-sheet__panel flex max-h-[65vh] w-full max-w-content flex-col overflow-hidden rounded-t-[14px] bg-card text-foreground supports-[height:100dvh]:max-h-[65dvh] animate-[tbox-sheet-in_200ms_ease-out] group-data-[state=closed]:animate-[tbox-sheet-out_200ms_ease-in_both] motion-reduce:animate-none"
36
42
  maskClassName="bg-scrim animate-[tbox-fade-in_200ms_ease-out] group-data-[state=closed]:animate-[tbox-fade-out_200ms_ease-in_both] motion-reduce:animate-none"
37
43
  >
44
+ {cardMode ? (
45
+ <>
46
+ <span className="tbox-bottom-sheet__handle mx-auto mt-2 mb-1 block h-1 w-9 shrink-0 rounded-full bg-neutral-soft" aria-hidden="true" />
47
+ <h2 id={titleId} className="sr-only">{title}</h2>
48
+ <button
49
+ className="tbox-bottom-sheet__close absolute right-1.5 top-1.5 z-10 flex size-11 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent text-muted-foreground focus-visible:outline-2 focus-visible:outline-primary"
50
+ ref={closeRef}
51
+ type="button"
52
+ aria-label={`关闭${title}`}
53
+ onClick={onClose}
54
+ >
55
+ <svg className="size-4.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true">
56
+ <path d="m6 6 12 12M6 18 18 6" />
57
+ </svg>
58
+ </button>
59
+ </>
60
+ ) : (
38
61
  <header className="tbox-bottom-sheet__header flex shrink-0 items-center justify-between gap-3 px-3.5 py-3">
39
62
  <h2 id={titleId} className="m-0 text-base font-semibold leading-[21px]">{title}</h2>
40
- <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}>
63
+ <button className="flex size-11 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent text-inherit focus-visible:outline-2 focus-visible:outline-primary" ref={closeRef} type="button" aria-label={`关闭${title}`} onClick={onClose}>
41
64
  <svg className="size-4.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true">
42
65
  <path d="m6 6 12 12M6 18 18 6" />
43
66
  </svg>
44
67
  </button>
45
68
  </header>
69
+ )}
46
70
  <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>
47
71
  </Overlay>
48
72
  );
@@ -2,6 +2,7 @@
2
2
  // label 只写纯文字;前面的星标由本组件渲染(icon 字段或默认 ✦),不要把 ✦/emoji 写进 label。
3
3
  //
4
4
  // 欢迎区用两列;主题选择紧凑布局时输入区使用紧凑单行。
5
+ import { useEffect, useRef, useState } from 'react';
5
6
  import { useChatConfigStore } from '../../chat-config';
6
7
  import { Calendar } from '../../icons';
7
8
  import { useChatStore } from '../../store-context';
@@ -44,35 +45,80 @@ export function QuickCommands({
44
45
  icon: command.icon || staticByLabel.get(command.label)?.icon,
45
46
  }))
46
47
  : staticCommands;
47
- if (!commands.length) return null;
48
-
48
+ // hooks 必须先于任何 early return(否则空态会触发 hook 数量不一致)。
49
49
  const grid = variant === 'grid';
50
50
  const compact = variant === 'compact';
51
+ // 行/紧凑档是横向滚动容器:滚出视口的胶囊没有任何提示。用两侧渐变层给出可滑动暗示
52
+ //(不用 mask-image —— 无前缀写法在 safari 16.4 基线外,会踩兼容门禁)。
53
+ const rowRef = useRef<HTMLDivElement>(null);
54
+ const [overflow, setOverflow] = useState({ left: false, right: false });
55
+ useEffect(() => {
56
+ if (grid) return undefined;
57
+ const el = rowRef.current;
58
+ if (!el) return undefined;
59
+ const update = () => {
60
+ const left = el.scrollLeft > 4;
61
+ const right = el.scrollWidth - el.clientWidth - el.scrollLeft > 4;
62
+ setOverflow((prev) => (prev.left === left && prev.right === right ? prev : { left, right }));
63
+ };
64
+ update();
65
+ el.addEventListener('scroll', update, { passive: true });
66
+ const ro = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(update) : undefined;
67
+ ro?.observe(el);
68
+ return () => {
69
+ el.removeEventListener('scroll', update);
70
+ ro?.disconnect();
71
+ };
72
+ }, [grid, commands.length]);
73
+
74
+ if (!commands.length) return null;
51
75
  const buttonStyle = {
52
76
  grid: 'w-full justify-start gap-1.5 rounded-[22px] border border-border bg-card px-3 py-2 text-left shadow-sm active:border-primary',
53
77
  row: 'flex-[1_0_auto] justify-center gap-1.5 rounded-[22px] border border-border bg-card px-3 py-2 shadow-sm active:border-primary',
54
78
  compact: 'relative isolate flex-[1_0_auto] justify-center gap-[5px] rounded-full border-0 bg-transparent px-3 before:pointer-events-none before:absolute before:inset-x-0 before:inset-y-[5px] before:-z-10 before:rounded-full before:border before:border-border before:bg-card before:shadow-[0_4px_16px_rgba(38,59,92,0.05)] before:transition-colors active:before:border-primary',
55
79
  }[variant];
80
+ // 外层保存 `.quick-commands`(壳契约与紧凑布局的相邻兄弟断言都按它取),
81
+ // 内层 `.quick-commands__scroll` 只负责横向滚动。
82
+ // row 变体的 shadow-sm(0 4px 13px)直接画在 44px 按钮外框上,overflow-x-auto 会隐式裁切垂直溢出:
83
+ // 顶部留 pt-2(8px)防上沿贴边,底部保留 pb-[9px] 容纳下偏移阴影并维持与输入框的原间距;
84
+ // compact 变体靠 before:inset-y-[5px] 已内置 5px 上下缓冲,pb-1 即等价 9px。
85
+ const scrollClass = `quick-commands__scroll flex w-full items-center gap-2 overflow-x-auto px-page [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden ${compact ? 'pb-1' : 'pt-2 pb-[9px]'}`;
86
+ const buttons = commands.map((cmd) => (
87
+ <button
88
+ key={cmd.label}
89
+ className={`quick-commands__item inline-flex min-h-11 appearance-none items-center text-foreground transition-colors duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] ${buttonStyle}`}
90
+ disabled={hidden}
91
+ onClick={() => onCommand(cmd.query)}
92
+ >
93
+ <QuickCommandIcon icon={cmd.icon} />
94
+ <span className={`quick-commands__label text-sm font-medium leading-[18px] text-foreground ${grid ? 'line-clamp-2 text-left' : 'whitespace-nowrap'}`}>{cmd.label}</span>
95
+ </button>
96
+ ));
56
97
  return (
57
98
  <div
58
99
  className={
59
100
  grid
60
101
  ? `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' : ''}`
61
- : `quick-commands relative z-[1] mx-auto flex w-full max-w-content gap-2 overflow-x-auto px-page [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden ${compact ? 'pb-1' : 'pb-[9px]'} ${hidden ? ' quick-commands--hidden invisible pointer-events-none' : ''}`
102
+ : `quick-commands quick-commands--${variant} relative z-[1] mx-auto w-full max-w-content ${hidden ? ' quick-commands--hidden invisible pointer-events-none' : ''}`
62
103
  }
63
104
  aria-hidden={hidden || undefined}
64
105
  >
65
- {commands.map((cmd) => (
66
- <button
67
- key={cmd.label}
68
- className={`quick-commands__item inline-flex min-h-11 appearance-none items-center text-foreground transition-colors duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] ${buttonStyle}`}
69
- disabled={hidden}
70
- onClick={() => onCommand(cmd.query)}
71
- >
72
- <QuickCommandIcon icon={cmd.icon} />
73
- <span className={`quick-commands__label text-sm font-medium leading-[18px] text-foreground ${grid ? 'line-clamp-2 text-left' : 'whitespace-nowrap'}`}>{cmd.label}</span>
74
- </button>
75
- ))}
106
+ {/* 渐隐层必须绝对定位在滚动容器**外层**:放进 flex 流里会和 gap-2 一起撑出 8px 间隙,
107
+ 滚动刚越过阈值时整排胶囊会横向抖一下。外层同时保留 `.quick-commands` 类,
108
+ 紧凑布局下与输入框仍是相邻兄弟(壳契约按相邻关系断言)。 */}
109
+ {!grid && overflow.left ? (
110
+ <span
111
+ className="quick-commands__fade quick-commands__fade--left pointer-events-none absolute inset-y-0 left-0 z-[2] w-6 bg-linear-to-r from-background to-transparent"
112
+ aria-hidden="true"
113
+ />
114
+ ) : null}
115
+ {grid ? buttons : <div ref={rowRef} className={scrollClass}>{buttons}</div>}
116
+ {!grid && overflow.right ? (
117
+ <span
118
+ className="quick-commands__fade quick-commands__fade--right pointer-events-none absolute inset-y-0 right-0 z-[2] w-6 bg-linear-to-l from-background to-transparent"
119
+ aria-hidden="true"
120
+ />
121
+ ) : null}
76
122
  </div>
77
123
  );
78
124
  }
@@ -249,6 +249,8 @@ describe('deriveSummary + buildSummaryText(L1 聚合)', () => {
249
249
  expect(s).toEqual({
250
250
  skillCount: 2,
251
251
  toolCount: 3,
252
+ // 平台内部活动(此处无记忆召回):显式字段,供 dev 视图单列
253
+ internalCount: 0,
252
254
  totalCount: 5,
253
255
  callingCount: 1,
254
256
  activeTitle: '查询停车费用',
@@ -42,8 +42,10 @@ export interface ToolCallViewItem {
42
42
  export interface ToolCallSummary {
43
43
  /** skill 条目总数(含进行中) */
44
44
  skillCount: number;
45
- /** preTool + normal 条目总数 */
45
+ /** 「已调用工具」条数:normal + preTool(预执行按工具计),记忆召回不计入 */
46
46
  toolCount: number;
47
+ /** 平台内部活动(记忆召回)条目数:dev 详情视图单列(可选,避免外部构造打断) */
48
+ internalCount?: number;
47
49
  /** 当前摘要包含的全部活动数 */
48
50
  totalCount: number;
49
51
  /** 当前仍在执行的活动数 */
@@ -160,9 +162,14 @@ export function deriveSummary(items: ToolCallViewItem[]): ToolCallSummary {
160
162
  const skillCount = items.filter((i) => i.kind === 'skill').length;
161
163
  const callingCount = items.filter((i) => i.status === 'calling').length;
162
164
  const activeItem = [...items].reverse().find((item) => item.status === 'calling');
165
+ // 记忆召回(kind=memory)是平台侧背景活动,不计入「已调用工具」
166
+ //(否则一轮 1 次业务调用会显示成「已调用工具 2 个」,用户无从对应);
167
+ // preTool 预执行仍按工具计(与既有聚合契约一致)。
168
+ const memoryCount = items.filter((i) => i.kind === 'memory').length;
163
169
  return {
164
170
  skillCount,
165
- toolCount: items.length - skillCount,
171
+ toolCount: items.length - skillCount - memoryCount,
172
+ internalCount: memoryCount,
166
173
  totalCount: items.length,
167
174
  callingCount,
168
175
  ...(activeItem ? { activeTitle: activeItem.label } : {}),