@tbox.cn/app-agent-ui-kit 0.0.0-stage → 1.0.0-alpha.1

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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -2
  3. package/assets/keyboard-circle.svg +12 -0
  4. package/assets/more-circle.svg +3 -0
  5. package/assets/new-chat.svg +3 -0
  6. package/assets/quick-command-star.svg +3 -0
  7. package/assets/send-gradient.svg +14 -0
  8. package/assets/stop@2x.png +0 -0
  9. package/assets/voice-circle.svg +3 -0
  10. package/package.json +55 -3
  11. package/src/ChatPage.less +62 -0
  12. package/src/ChatPage.tsx +305 -0
  13. package/src/chat-config.test.ts +82 -0
  14. package/src/chat-config.ts +62 -0
  15. package/src/components/ActionBar/DebugButton.test.tsx +84 -0
  16. package/src/components/ActionBar/DebugButton.tsx +53 -0
  17. package/src/components/ActionBar/index.less +123 -0
  18. package/src/components/ActionBar/index.test.tsx +83 -0
  19. package/src/components/ActionBar/index.tsx +159 -0
  20. package/src/components/CardRenderer.tsx +36 -0
  21. package/src/components/ChatHeader/index.less +148 -0
  22. package/src/components/ChatHeader/index.test.tsx +74 -0
  23. package/src/components/ChatHeader/index.tsx +75 -0
  24. package/src/components/ChatInput/index.less +394 -0
  25. package/src/components/ChatInput/index.test.tsx +156 -0
  26. package/src/components/ChatInput/index.tsx +284 -0
  27. package/src/components/ChatInput/voice/VoicePressField.tsx +34 -0
  28. package/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +51 -0
  29. package/src/components/ChatInput/voice/machine.ts +27 -0
  30. package/src/components/ChatInput/voice/useVoicePress.ts +207 -0
  31. package/src/components/HistoryEntry/index.less +49 -0
  32. package/src/components/HistoryEntry/index.tsx +42 -0
  33. package/src/components/MediaList/index.less +241 -0
  34. package/src/components/MediaList/index.tsx +256 -0
  35. package/src/components/MessageBubble/index.less +325 -0
  36. package/src/components/MessageBubble/index.test.tsx +134 -0
  37. package/src/components/MessageBubble/index.tsx +177 -0
  38. package/src/components/PullDownIndicator/index.less +32 -0
  39. package/src/components/PullDownIndicator/index.tsx +32 -0
  40. package/src/components/QuickCommands/index.less +63 -0
  41. package/src/components/QuickCommands/index.test.tsx +99 -0
  42. package/src/components/QuickCommands/index.tsx +52 -0
  43. package/src/components/ReasoningBlock/index.less +90 -0
  44. package/src/components/ReasoningBlock/index.tsx +56 -0
  45. package/src/components/ScrollToBottomButton/index.less +32 -0
  46. package/src/components/ScrollToBottomButton/index.tsx +10 -0
  47. package/src/components/ToolCallBlock/detail.test.ts +346 -0
  48. package/src/components/ToolCallBlock/detail.ts +204 -0
  49. package/src/components/ToolCallBlock/index.less +312 -0
  50. package/src/components/ToolCallBlock/index.test.tsx +261 -0
  51. package/src/components/ToolCallBlock/index.tsx +212 -0
  52. package/src/components/ToolCallBlock/titles.ts +102 -0
  53. package/src/hooks/use-drag-gesture.test.ts +66 -0
  54. package/src/hooks/use-drag-gesture.ts +129 -0
  55. package/src/hooks/use-pull-down-history.ts +241 -0
  56. package/src/hooks/use-pull-down-wheel-native.test.ts +64 -0
  57. package/src/hooks/useMediaUpload.ts +242 -0
  58. package/src/hooks/useTTSAutoPlay.ts +82 -0
  59. package/src/index.ts +69 -0
  60. package/src/store-context.tsx +92 -0
  61. package/src/test/setup.ts +7 -0
  62. package/src/theme/contract.json +72 -0
  63. package/src/theme/global.less +99 -0
  64. package/src/theme/motion.less +19 -0
  65. package/src/theme/theme-contract.test.ts +69 -0
  66. package/src/theme/theme.ts +17 -0
  67. package/src/theme/tokens.less +79 -0
  68. package/src/types.ts +29 -0
  69. package/src/utils/copyText.ts +11 -0
  70. package/src/utils/haptics.test.ts +51 -0
  71. package/src/utils/haptics.ts +44 -0
  72. package/src/utils/imagePreview.ts +10 -0
  73. package/src/utils/pull-down-machine.test.ts +188 -0
  74. package/src/utils/pull-down-machine.ts +157 -0
  75. package/src/utils/session-error.ts +5 -0
  76. package/src/utils/toast.ts +15 -0
  77. package/src/utils/tool-call-display.test.ts +240 -0
  78. package/src/utils/tool-call-display.ts +146 -0
  79. package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,312 @@
1
+ // Codex 风格工具活动日志:无卡框、弱层级、流内展开。
2
+ // web-view 约定:颜色走现有 mall token;滚动区隐藏滚动条;图标走 currentColor。
3
+ .tool-calls {
4
+ display: flex;
5
+ flex-direction: column;
6
+ margin: 0 0 12px;
7
+ }
8
+
9
+ .tool-calls__summary,
10
+ .tool-calls__item-trigger,
11
+ .tool-calls__copy {
12
+ appearance: none;
13
+ border: 0;
14
+ font: inherit;
15
+ }
16
+
17
+ // 工具活动区统一沿用摘要字号,保留现有 rem 缩放比例。
18
+ .tool-calls__summary-text,
19
+ .tool-calls__item-name,
20
+ .tool-calls__badge,
21
+ .tool-calls__item-tech,
22
+ .tool-calls__detail-label,
23
+ .tool-calls__detail-body,
24
+ .tool-calls__copy {
25
+ font-size: 24px;
26
+ }
27
+
28
+ .tool-calls__summary {
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: space-between;
32
+ width: 100%;
33
+ min-height: 88px;
34
+ padding: 10px 4px;
35
+ border-radius: 16px;
36
+ background: transparent;
37
+ color: var(--tbox-text-muted);
38
+ text-align: left;
39
+ cursor: pointer;
40
+ transition:
41
+ color var(--tbox-transition-fast),
42
+ background var(--tbox-transition-fast);
43
+
44
+ &:active {
45
+ background: rgba(11, 15, 23, 0.035);
46
+ }
47
+
48
+ &:focus-visible {
49
+ outline: 4px solid var(--tbox-primary);
50
+ outline-offset: 4px;
51
+ }
52
+
53
+ &--calling {
54
+ color: var(--tbox-text-secondary);
55
+ }
56
+ }
57
+
58
+ .tool-calls__left {
59
+ display: flex;
60
+ align-items: center;
61
+ gap: 16px;
62
+ min-width: 0;
63
+ flex: 1;
64
+ }
65
+
66
+ .tool-calls__summary-text {
67
+ min-width: 0;
68
+ overflow: hidden;
69
+ color: currentColor;
70
+ font-weight: 400;
71
+ line-height: 1.4;
72
+ text-overflow: ellipsis;
73
+ white-space: nowrap;
74
+ }
75
+
76
+ .tool-calls__failed {
77
+ color: var(--tbox-text-muted);
78
+ }
79
+
80
+ .tool-calls__chevron,
81
+ .tool-calls__item-chevron {
82
+ color: var(--tbox-text-muted);
83
+ flex-shrink: 0;
84
+ transition: transform var(--tbox-transition-fast);
85
+
86
+ &--up {
87
+ transform: rotate(180deg);
88
+ }
89
+ }
90
+
91
+ .tool-calls__chevron {
92
+ margin-left: 16px;
93
+ }
94
+
95
+ .tool-calls__icon {
96
+ flex-shrink: 0;
97
+
98
+ &--success {
99
+ color: var(--tbox-text-muted);
100
+ }
101
+
102
+ &--error {
103
+ color: var(--tbox-text-muted);
104
+ }
105
+ }
106
+
107
+ .tool-calls__spinner {
108
+ width: 28px;
109
+ height: 28px;
110
+ border: 4px solid rgba(9, 107, 250, 0.2);
111
+ border-top-color: var(--tbox-primary);
112
+ border-radius: 50%;
113
+ flex-shrink: 0;
114
+ animation: tool-spin 0.8s linear infinite;
115
+
116
+ &--sm {
117
+ width: 24px;
118
+ height: 24px;
119
+ }
120
+ }
121
+
122
+ .tool-calls__list {
123
+ display: flex;
124
+ flex-direction: column;
125
+ gap: 2px;
126
+ margin-top: 4px;
127
+ padding-left: 4px;
128
+ }
129
+
130
+ .tool-calls__item {
131
+ display: flex;
132
+ min-width: 0;
133
+ flex-direction: column;
134
+
135
+ &--calling .tool-calls__item-name {
136
+ color: var(--tbox-text-secondary);
137
+ }
138
+
139
+ &--error .tool-calls__item-name {
140
+ color: var(--tbox-text-muted);
141
+ }
142
+ }
143
+
144
+ .tool-calls__item-trigger {
145
+ display: flex;
146
+ align-items: center;
147
+ justify-content: space-between;
148
+ width: 100%;
149
+ min-height: 88px;
150
+ padding: 10px 4px;
151
+ border-radius: 16px;
152
+ background: transparent;
153
+ color: var(--tbox-text-secondary);
154
+ text-align: left;
155
+ cursor: pointer;
156
+ transition:
157
+ color var(--tbox-transition-fast),
158
+ background var(--tbox-transition-fast);
159
+
160
+ &:active {
161
+ background: rgba(11, 15, 23, 0.035);
162
+ }
163
+
164
+ &:focus-visible {
165
+ outline: 4px solid var(--tbox-primary);
166
+ outline-offset: 4px;
167
+ }
168
+
169
+ &--static {
170
+ cursor: default;
171
+ }
172
+ }
173
+
174
+ .tool-calls__item-left {
175
+ display: flex;
176
+ align-items: baseline;
177
+ gap: 16px;
178
+ min-width: 0;
179
+
180
+ > .tool-calls__icon,
181
+ > .tool-calls__spinner {
182
+ align-self: center;
183
+ }
184
+ }
185
+
186
+ .tool-calls__item-name {
187
+ min-width: 0;
188
+ overflow: hidden;
189
+ color: var(--tbox-text-secondary);
190
+ font-weight: 400;
191
+ line-height: 1.4;
192
+ text-overflow: ellipsis;
193
+ white-space: nowrap;
194
+ }
195
+
196
+ .tool-calls__badge,
197
+ .tool-calls__item-tech {
198
+ color: var(--tbox-text-muted);
199
+ font-family: inherit;
200
+ line-height: 1.4;
201
+ }
202
+
203
+ .tool-calls__badge {
204
+ flex-shrink: 0;
205
+ }
206
+
207
+ // 018 dev 视图技术名后缀(debug 态渲染;prod 不出 DOM)
208
+ .tool-calls__item-tech {
209
+ word-break: break-all;
210
+ }
211
+
212
+ .tool-calls__item-chevron {
213
+ margin-left: 16px;
214
+ }
215
+
216
+ .tool-calls__detail {
217
+ display: flex;
218
+ flex-direction: column;
219
+ gap: 20px;
220
+ margin: 2px 0 16px 40px;
221
+ padding: 10px 0 10px 28px;
222
+ border-left: 4px solid var(--tbox-border);
223
+ }
224
+
225
+ .tool-calls__detail-section {
226
+ display: flex;
227
+ min-width: 0;
228
+ flex-direction: column;
229
+ gap: 10px;
230
+ }
231
+
232
+ .tool-calls__detail-heading {
233
+ display: flex;
234
+ align-items: center;
235
+ justify-content: space-between;
236
+ gap: 16px;
237
+ }
238
+
239
+ .tool-calls__detail-label {
240
+ color: var(--tbox-text-muted);
241
+ line-height: 1.4;
242
+ }
243
+
244
+ .tool-calls__detail-body {
245
+ max-height: 560px;
246
+ margin: 0;
247
+ padding: 20px 24px;
248
+ overflow: auto;
249
+ border-radius: 16px;
250
+ background: var(--tbox-bg-subtle);
251
+ color: var(--tbox-text-secondary);
252
+ font-family: Menlo, Monaco, Consolas, monospace;
253
+ line-height: 1.6;
254
+ white-space: pre-wrap;
255
+ word-break: break-all;
256
+ -webkit-overflow-scrolling: touch;
257
+
258
+ &::-webkit-scrollbar {
259
+ display: none;
260
+ }
261
+
262
+ &--error {
263
+ color: var(--tbox-text-muted);
264
+ }
265
+ }
266
+
267
+ .tool-calls__copy {
268
+ display: inline-flex;
269
+ align-items: center;
270
+ gap: 8px;
271
+ min-height: 88px;
272
+ padding: 6px 10px;
273
+ border-radius: 12px;
274
+ background: transparent;
275
+ color: var(--tbox-text-muted);
276
+ line-height: 1.2;
277
+ flex-shrink: 0;
278
+ cursor: pointer;
279
+
280
+ &:active {
281
+ color: var(--tbox-text-secondary);
282
+ }
283
+
284
+ &:focus-visible {
285
+ outline: 4px solid var(--tbox-primary);
286
+ outline-offset: 2px;
287
+ }
288
+
289
+ &:disabled {
290
+ opacity: 0.55;
291
+ cursor: default;
292
+ }
293
+ }
294
+
295
+ @keyframes tool-spin {
296
+ to {
297
+ transform: rotate(360deg);
298
+ }
299
+ }
300
+
301
+ @media (prefers-reduced-motion: reduce) {
302
+ .tool-calls__summary,
303
+ .tool-calls__item-trigger,
304
+ .tool-calls__chevron,
305
+ .tool-calls__item-chevron {
306
+ transition: none;
307
+ }
308
+
309
+ .tool-calls__spinner {
310
+ animation: none;
311
+ }
312
+ }
@@ -0,0 +1,261 @@
1
+ // @vitest-environment happy-dom
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
+ import { createRoot, type Root } from 'react-dom/client';
4
+ import { flushSync } from 'react-dom';
5
+ import {
6
+ buildMemoryToolCallPayload,
7
+ buildPreToolArgsPayload,
8
+ buildPreToolResultPayload,
9
+ buildSkillToolCallPayload,
10
+ MEMORY_TOOL_CALL_NAME,
11
+ PRE_TOOL_CALL_NAME,
12
+ SKILL_TOOL_CALL_NAME,
13
+ } from '@tbox.cn/app-contracts';
14
+ import type { ToolCallInfo } from '../../types';
15
+ import ToolCallBlock from './index';
16
+
17
+ const mocks = vi.hoisted(() => ({
18
+ copyText: vi.fn(async () => true),
19
+ toast: vi.fn(async () => {}),
20
+ }));
21
+
22
+ vi.mock('../../utils/copyText', () => ({ copyText: mocks.copyText }));
23
+ vi.mock('../../utils/toast', () => ({ toast: mocks.toast }));
24
+
25
+ /** 夹具:1 preTool(done) + 1 skill(带 description) + 1 normal(calling),载荷经契约 builder 同构 */
26
+ function makeCalls(): ToolCallInfo[] {
27
+ const skill = buildSkillToolCallPayload({ name: 'member-guide', description: '会员导购技能' });
28
+ return [
29
+ {
30
+ id: 'pre-1',
31
+ name: PRE_TOOL_CALL_NAME,
32
+ args: buildPreToolArgsPayload({
33
+ toolName: 'member-balance',
34
+ description: '会员卡余额查询',
35
+ toolArgs: { cardNo: 'C001' },
36
+ }),
37
+ result: buildPreToolResultPayload({
38
+ toolName: 'member-balance',
39
+ status: 'done',
40
+ result: { balance: 1200 },
41
+ }),
42
+ status: 'done',
43
+ },
44
+ {
45
+ id: 'skill-1',
46
+ name: SKILL_TOOL_CALL_NAME,
47
+ args: skill.args,
48
+ result: skill.result,
49
+ status: 'done',
50
+ },
51
+ { id: 'tool-1', name: 'search_stores', status: 'calling' },
52
+ ];
53
+ }
54
+
55
+ /** 018:memory 伪工具夹具(hit + degraded),载荷经契约 builder 同构 */
56
+ function makeMemoryCalls(): ToolCallInfo[] {
57
+ const hit = buildMemoryToolCallPayload({
58
+ query: '推荐美食',
59
+ status: 'hit',
60
+ records: [{ id: 'm1', kind: 'preference', content: '用户爱吃辣' }],
61
+ });
62
+ const degraded = buildMemoryToolCallPayload({
63
+ query: '今天活动',
64
+ status: 'degraded',
65
+ error: '记忆召回超时',
66
+ });
67
+ return [
68
+ { id: 'mem-hit', name: MEMORY_TOOL_CALL_NAME, args: hit.args, result: hit.result, status: 'done' },
69
+ { id: 'mem-deg', name: MEMORY_TOOL_CALL_NAME, args: degraded.args, result: degraded.result, status: 'done' },
70
+ ];
71
+ }
72
+
73
+ function renderBlock(
74
+ calls: ToolCallInfo[],
75
+ opts: { debug?: boolean } = {},
76
+ ): {
77
+ container: HTMLElement;
78
+ rerender: (next: ToolCallInfo[]) => void;
79
+ unmount: () => void;
80
+ } {
81
+ const container = document.createElement('div');
82
+ document.body.appendChild(container);
83
+ const root: Root = createRoot(container);
84
+ flushSync(() => root.render(<ToolCallBlock toolCalls={calls} debug={opts.debug} />));
85
+ return {
86
+ container,
87
+ rerender: (next) => flushSync(() => root.render(<ToolCallBlock toolCalls={next} debug={opts.debug} />)),
88
+ unmount: () => flushSync(() => root.unmount()),
89
+ };
90
+ }
91
+
92
+ function expandSummary(container: HTMLElement): void {
93
+ flushSync(() => container.querySelector<HTMLButtonElement>('.tool-calls__summary')?.click());
94
+ }
95
+
96
+ beforeEach(() => {
97
+ vi.clearAllMocks();
98
+ });
99
+
100
+ afterEach(() => {
101
+ document.body.innerHTML = '';
102
+ });
103
+
104
+ describe('ToolCallBlock prod 态(018 I4:友好聚合、无出入参展开)', () => {
105
+ it('默认收起为语义按钮,主文案显示当前执行中的中文任务标题', () => {
106
+ const { container, unmount } = renderBlock(makeCalls());
107
+ const summary = container.querySelector<HTMLButtonElement>('.tool-calls__summary');
108
+ expect(summary?.tagName).toBe('BUTTON');
109
+ expect(summary?.type).toBe('button');
110
+ expect(summary?.getAttribute('aria-expanded')).toBe('false');
111
+ expect(summary?.textContent).toContain('正在搜索商场门店');
112
+ expect(summary?.textContent).not.toContain('search_stores');
113
+ expect(container.querySelector('.tool-calls__list')).toBeNull();
114
+ unmount();
115
+ });
116
+
117
+ it('展开后活动行仅状态/中文名/徽标——零详情触发按钮、零技术名(I4)', () => {
118
+ const { container, unmount } = renderBlock(makeCalls());
119
+ expandSummary(container);
120
+
121
+ expect(container.querySelectorAll('.tool-calls__item')).toHaveLength(3);
122
+ expect(container.querySelector('.tool-calls__list')?.textContent).toContain('前置工具');
123
+ expect(container.querySelector('.tool-calls__list')?.textContent).toContain('会员卡余额查询');
124
+ expect(container.querySelector('.tool-calls__list')?.textContent).toContain('搜索商场门店');
125
+ // I4:无任何出入参展开入口(触发按钮/chevron/复制全部不渲染)
126
+ expect(container.querySelectorAll('button.tool-calls__item-trigger')).toHaveLength(0);
127
+ expect(container.querySelector('.tool-calls__item-chevron')).toBeNull();
128
+ expect(container.querySelector('.tool-calls__detail')).toBeNull();
129
+ expect(container.querySelector('.tool-calls__copy')).toBeNull();
130
+ expect(container.querySelector('.tool-calls__item-tech')).toBeNull();
131
+ unmount();
132
+ });
133
+
134
+ it('preTool payload 失败保持失败聚合与失败活动行', () => {
135
+ const failedPreTool: ToolCallInfo = {
136
+ id: 'pre-error',
137
+ name: PRE_TOOL_CALL_NAME,
138
+ args: buildPreToolArgsPayload({ toolName: 'parking-fee', description: '停车费查询' }),
139
+ result: buildPreToolResultPayload({ toolName: 'parking-fee', status: 'error', error: '接口超时' }),
140
+ status: 'done',
141
+ };
142
+ const { container, unmount } = renderBlock([failedPreTool]);
143
+ expect(container.querySelector('.tool-calls__summary')?.textContent).toContain('已调用工具 1 个');
144
+ expect(container.querySelector('.tool-calls__failed')?.textContent).toContain('1 个失败');
145
+
146
+ expandSummary(container);
147
+ expect(container.querySelector('.tool-calls__item--error')).not.toBeNull();
148
+ unmount();
149
+ });
150
+
151
+ it('聚合按钮可由浏览器原生键盘激活', () => {
152
+ const { container, unmount } = renderBlock(makeCalls());
153
+ const summary = container.querySelector<HTMLButtonElement>('.tool-calls__summary');
154
+ summary?.focus();
155
+ expect(document.activeElement).toBe(summary);
156
+ flushSync(() => summary?.click());
157
+ expect(container.querySelector('.tool-calls__list')).not.toBeNull();
158
+ unmount();
159
+ });
160
+ });
161
+
162
+ describe('ToolCallBlock dev 态(018 tool-debug:紧凑详情 + 技术后缀)', () => {
163
+ it('展开后行标题附技术名后缀(协议技术名 dev 可见)', () => {
164
+ const { container, unmount } = renderBlock(makeCalls(), { debug: true });
165
+ expandSummary(container);
166
+
167
+ const tech = container.querySelector('.tool-calls__item-tech');
168
+ expect(tech?.textContent).toBe(' · member-balance');
169
+ expect(container.querySelectorAll('button.tool-calls__item-trigger')).toHaveLength(2);
170
+ unmount();
171
+ });
172
+
173
+ it('详情在消息流内展开:屏显走紧凑单行格式(formatCompactToolIo),双栏输入输出', () => {
174
+ const { container, unmount } = renderBlock(makeCalls(), { debug: true });
175
+ expandSummary(container);
176
+ flushSync(() => container.querySelector<HTMLButtonElement>('.tool-calls__item-trigger')?.click());
177
+
178
+ const detail = container.querySelector('.tool-calls__detail');
179
+ expect(detail).not.toBeNull();
180
+ const bodies = detail?.querySelectorAll('.tool-calls__detail-body');
181
+ // 紧凑单行(无 pretty 缩进空格)
182
+ expect(bodies?.[0].textContent).toContain('{"cardNo":"C001"}');
183
+ expect(bodies?.[1].textContent).toContain('{"balance":1200}');
184
+ expect(bodies?.[0].textContent).not.toContain('"cardNo": "C001"');
185
+ // 输入/输出双栏标签
186
+ expect(detail?.textContent).toContain('输入');
187
+ expect(detail?.textContent).toContain('输出');
188
+ unmount();
189
+ });
190
+
191
+ it('输出复制仍为美化全文(屏显紧凑、粘贴友好分工)', async () => {
192
+ const { container, unmount } = renderBlock(makeCalls(), { debug: true });
193
+ expandSummary(container);
194
+ flushSync(() => container.querySelector<HTMLButtonElement>('.tool-calls__item-trigger')?.click());
195
+ // 第二个复制按钮 = 输出(第一个是输入)
196
+ container.querySelectorAll<HTMLButtonElement>('.tool-calls__copy')[1]?.click();
197
+
198
+ await vi.waitFor(() => expect(mocks.copyText).toHaveBeenCalledTimes(1));
199
+ expect(mocks.copyText).toHaveBeenCalledWith(expect.stringContaining('"balance": 1200'));
200
+ expect(mocks.toast).toHaveBeenCalledWith('输出已复制', 'success');
201
+ unmount();
202
+ });
203
+
204
+ it('聚合与行详情展开状态在流式 rerender 后保持稳定', () => {
205
+ const calls = makeCalls();
206
+ const { container, rerender, unmount } = renderBlock(calls, { debug: true });
207
+ expandSummary(container);
208
+ flushSync(() => container.querySelector<HTMLButtonElement>('.tool-calls__item-trigger')?.click());
209
+ expect(container.querySelector('.tool-calls__detail')).not.toBeNull();
210
+
211
+ rerender(calls.map((item) => item.id === 'tool-1'
212
+ ? { ...item, status: 'done' as const, args: '{"keyword":"咖啡"}', result: '{"total":3}' }
213
+ : item));
214
+
215
+ expect(container.querySelector('.tool-calls__summary')?.getAttribute('aria-expanded')).toBe('true');
216
+ expect(container.querySelector('.tool-calls__list')).not.toBeNull();
217
+ expect(container.querySelector('.tool-calls__detail')).not.toBeNull();
218
+ expect(container.querySelector('.tool-calls__summary')?.textContent).toContain('已调用工具 2 个');
219
+ unmount();
220
+ });
221
+
222
+ it('详情按钮可由浏览器原生键盘激活', () => {
223
+ const { container, unmount } = renderBlock(makeCalls(), { debug: true });
224
+ expandSummary(container);
225
+ const detailTrigger = container.querySelector<HTMLButtonElement>('.tool-calls__item-trigger');
226
+ detailTrigger?.focus();
227
+ expect(document.activeElement).toBe(detailTrigger);
228
+ expect(detailTrigger?.getAttribute('aria-expanded')).toBe('false');
229
+ flushSync(() => detailTrigger?.click());
230
+ expect(detailTrigger?.getAttribute('aria-expanded')).toBe('true');
231
+ unmount();
232
+ });
233
+ });
234
+
235
+ describe('ToolCallBlock memory 伪工具(018)', () => {
236
+ it('hit/degraded 活动行:记忆召回徽标、降级为失败态、dev 详情含记录预览', () => {
237
+ const { container, unmount } = renderBlock(makeMemoryCalls(), { debug: true });
238
+ expandSummary(container);
239
+
240
+ const items = container.querySelectorAll('.tool-calls__item');
241
+ expect(items).toHaveLength(2);
242
+ expect(container.querySelector('.tool-calls__list')?.textContent).toContain('记忆召回 · 1 条命中');
243
+ expect(container.querySelector('.tool-calls__list')?.textContent).toContain('记忆召回降级');
244
+ expect(container.querySelector('.tool-calls__item--error')).not.toBeNull();
245
+ expect(container.querySelector('.tool-calls__list')?.textContent).toContain('记忆召回');
246
+
247
+ flushSync(() => container.querySelector<HTMLButtonElement>('.tool-calls__item-trigger')?.click());
248
+ const bodies = container.querySelectorAll('.tool-calls__detail-body');
249
+ expect(bodies[0].textContent).toBe('推荐美食');
250
+ expect(bodies[1].textContent).toContain('[preference] 用户爱吃辣');
251
+ unmount();
252
+ });
253
+
254
+ it('prod 态 memory 行无展开入口(与其它工具一致)', () => {
255
+ const { container, unmount } = renderBlock(makeMemoryCalls());
256
+ expandSummary(container);
257
+ expect(container.querySelectorAll('button.tool-calls__item-trigger')).toHaveLength(0);
258
+ expect(container.querySelector('.tool-calls__detail')).toBeNull();
259
+ unmount();
260
+ });
261
+ });