ochreui 0.0.0-stage → 0.0.2

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 (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -2
  3. package/cli/ochreui.mjs +601 -0
  4. package/mcp/core.mjs +126 -0
  5. package/mcp/docs.json +906 -0
  6. package/mcp/server.mjs +23 -0
  7. package/package.json +393 -3
  8. package/registry/agent-team.ts +350 -0
  9. package/registry/avatar.ts +300 -0
  10. package/registry/badge.ts +207 -0
  11. package/registry/breadcrumb.ts +435 -0
  12. package/registry/button.ts +238 -0
  13. package/registry/card.ts +221 -0
  14. package/registry/change-summary.ts +200 -0
  15. package/registry/checkbox.ts +204 -0
  16. package/registry/code-block.ts +332 -0
  17. package/registry/color-picker.ts +720 -0
  18. package/registry/comment-thread.ts +503 -0
  19. package/registry/context-menu.ts +281 -0
  20. package/registry/cover-flow.ts +623 -0
  21. package/registry/date-picker.ts +799 -0
  22. package/registry/decision-inbox.ts +340 -0
  23. package/registry/dialog.ts +577 -0
  24. package/registry/dropdown-menu.ts +864 -0
  25. package/registry/email-draft.ts +916 -0
  26. package/registry/empty-calendar.ts +199 -0
  27. package/registry/empty-state.ts +164 -0
  28. package/registry/enrichment-orbit.ts +164 -0
  29. package/registry/filter-menu.ts +541 -0
  30. package/registry/form-field.ts +308 -0
  31. package/registry/frost-cloud.ts +381 -0
  32. package/registry/ghosted-chat.ts +210 -0
  33. package/registry/glow-cloud.ts +402 -0
  34. package/registry/grid-background.ts +164 -0
  35. package/registry/hover-card.ts +401 -0
  36. package/registry/icon-button.ts +133 -0
  37. package/registry/index.json +2124 -0
  38. package/registry/integration-beam.ts +588 -0
  39. package/registry/integration-grid.ts +209 -0
  40. package/registry/kbd.ts +176 -0
  41. package/registry/layer-stack.ts +351 -0
  42. package/registry/lead-sourcing.ts +285 -0
  43. package/registry/logo-cluster.ts +239 -0
  44. package/registry/logo-marquee.ts +505 -0
  45. package/registry/message-actions.ts +833 -0
  46. package/registry/model-orbit.ts +583 -0
  47. package/registry/model-wheel.ts +372 -0
  48. package/registry/notification-stack.ts +301 -0
  49. package/registry/number-input.ts +552 -0
  50. package/registry/number-ticker.ts +261 -0
  51. package/registry/ochre.css +917 -0
  52. package/registry/otp-input.ts +704 -0
  53. package/registry/overlay.ts +312 -0
  54. package/registry/pagination.ts +362 -0
  55. package/registry/popover.ts +296 -0
  56. package/registry/profile-menu.ts +332 -0
  57. package/registry/progress-tracker.ts +291 -0
  58. package/registry/rating.ts +461 -0
  59. package/registry/reaction-bar.ts +322 -0
  60. package/registry/region-map.ts +537 -0
  61. package/registry/resizable.ts +489 -0
  62. package/registry/scroll-area.ts +271 -0
  63. package/registry/segmented-control.ts +433 -0
  64. package/registry/select.ts +769 -0
  65. package/registry/separator.ts +97 -0
  66. package/registry/shimmer-loader.ts +211 -0
  67. package/registry/side-folder.ts +152 -0
  68. package/registry/skeleton.ts +136 -0
  69. package/registry/skill/INSTRUCTIONS.md +11 -0
  70. package/registry/skill/SKILL.md +65 -0
  71. package/registry/skill/checklist.md +45 -0
  72. package/registry/skill/references/agent-team.md +105 -0
  73. package/registry/skill/references/avatar.md +88 -0
  74. package/registry/skill/references/badge.md +92 -0
  75. package/registry/skill/references/breadcrumb.md +99 -0
  76. package/registry/skill/references/button.md +82 -0
  77. package/registry/skill/references/card.md +111 -0
  78. package/registry/skill/references/catalog.md +114 -0
  79. package/registry/skill/references/change-summary.md +103 -0
  80. package/registry/skill/references/checkbox.md +105 -0
  81. package/registry/skill/references/code-block.md +109 -0
  82. package/registry/skill/references/color-picker.md +138 -0
  83. package/registry/skill/references/comment-thread.md +164 -0
  84. package/registry/skill/references/context-menu.md +205 -0
  85. package/registry/skill/references/cover-flow.md +128 -0
  86. package/registry/skill/references/date-picker.md +154 -0
  87. package/registry/skill/references/decision-inbox.md +126 -0
  88. package/registry/skill/references/dialog.md +155 -0
  89. package/registry/skill/references/dropdown-menu.md +144 -0
  90. package/registry/skill/references/email-draft.md +182 -0
  91. package/registry/skill/references/empty-calendar.md +74 -0
  92. package/registry/skill/references/empty-state.md +118 -0
  93. package/registry/skill/references/enrichment-orbit.md +71 -0
  94. package/registry/skill/references/filter-menu.md +143 -0
  95. package/registry/skill/references/form-field.md +118 -0
  96. package/registry/skill/references/frost-cloud.md +80 -0
  97. package/registry/skill/references/ghosted-chat.md +75 -0
  98. package/registry/skill/references/glow-cloud.md +84 -0
  99. package/registry/skill/references/grid-background.md +76 -0
  100. package/registry/skill/references/hover-card.md +125 -0
  101. package/registry/skill/references/icon-button.md +99 -0
  102. package/registry/skill/references/integration-beam.md +107 -0
  103. package/registry/skill/references/integration-grid.md +100 -0
  104. package/registry/skill/references/kbd.md +65 -0
  105. package/registry/skill/references/layer-stack.md +115 -0
  106. package/registry/skill/references/lead-sourcing.md +92 -0
  107. package/registry/skill/references/logo-cluster.md +92 -0
  108. package/registry/skill/references/logo-marquee.md +123 -0
  109. package/registry/skill/references/message-actions.md +146 -0
  110. package/registry/skill/references/model-orbit.md +106 -0
  111. package/registry/skill/references/model-wheel.md +84 -0
  112. package/registry/skill/references/notification-stack.md +138 -0
  113. package/registry/skill/references/number-input.md +117 -0
  114. package/registry/skill/references/number-ticker.md +73 -0
  115. package/registry/skill/references/otp-input.md +142 -0
  116. package/registry/skill/references/pagination.md +112 -0
  117. package/registry/skill/references/popover.md +143 -0
  118. package/registry/skill/references/profile-menu.md +123 -0
  119. package/registry/skill/references/progress-tracker.md +122 -0
  120. package/registry/skill/references/rating.md +111 -0
  121. package/registry/skill/references/reaction-bar.md +128 -0
  122. package/registry/skill/references/region-map.md +109 -0
  123. package/registry/skill/references/resizable.md +127 -0
  124. package/registry/skill/references/scroll-area.md +113 -0
  125. package/registry/skill/references/segmented-control.md +96 -0
  126. package/registry/skill/references/select.md +122 -0
  127. package/registry/skill/references/separator.md +69 -0
  128. package/registry/skill/references/shimmer-loader.md +83 -0
  129. package/registry/skill/references/side-folder.md +75 -0
  130. package/registry/skill/references/skeleton.md +95 -0
  131. package/registry/skill/references/smart-recommendation.md +132 -0
  132. package/registry/skill/references/spinner.md +84 -0
  133. package/registry/skill/references/switch.md +79 -0
  134. package/registry/skill/references/tab-overload.md +70 -0
  135. package/registry/skill/references/tag-input.md +126 -0
  136. package/registry/skill/references/team-invite.md +94 -0
  137. package/registry/skill/references/testimonial-wall.md +110 -0
  138. package/registry/skill/references/text-area.md +115 -0
  139. package/registry/skill/references/text-field.md +126 -0
  140. package/registry/skill/references/text-reveal.md +71 -0
  141. package/registry/skill/references/thinking-loader.md +87 -0
  142. package/registry/skill/references/time-picker.md +122 -0
  143. package/registry/skill/references/tips-panel.md +115 -0
  144. package/registry/skill/references/toggle-group.md +98 -0
  145. package/registry/skill/references/tool-call-card.md +151 -0
  146. package/registry/skill/references/tooltip.md +94 -0
  147. package/registry/skill/references/tree-view.md +172 -0
  148. package/registry/skill/theming.md +57 -0
  149. package/registry/smart-recommendation.ts +415 -0
  150. package/registry/spinner.ts +67 -0
  151. package/registry/switch.ts +146 -0
  152. package/registry/tab-overload.ts +211 -0
  153. package/registry/tag-input.ts +620 -0
  154. package/registry/team-invite.ts +248 -0
  155. package/registry/testimonial-wall.ts +521 -0
  156. package/registry/text-area.ts +432 -0
  157. package/registry/text-field.ts +415 -0
  158. package/registry/text-reveal.ts +175 -0
  159. package/registry/theme.ts +68 -0
  160. package/registry/thinking-loader.ts +302 -0
  161. package/registry/time-picker.ts +828 -0
  162. package/registry/tips-panel.ts +312 -0
  163. package/registry/toggle-group.ts +357 -0
  164. package/registry/tool-call-card.ts +578 -0
  165. package/registry/tooltip.ts +486 -0
  166. package/registry/tree-view.ts +454 -0
  167. package/styles/base.css +500 -0
  168. package/styles/tokens.css +415 -0
@@ -0,0 +1,578 @@
1
+ // Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
2
+ /**
3
+ * Tool Call Card, from Ochre (https://ochreui.dev).
4
+ * Needs ochre.css (`npx ochreui init`).
5
+ *
6
+ * <ui-tool-call-group>
7
+ * <ui-tool-call-card name="search_docs" icon="search" status="success" summary="Searched the docs" [args]="{ q: 'sso' }" [result]="hits" />
8
+ * </ui-tool-call-group>
9
+ * One line per agent tool call: icon, name, summary, live timer and status. It folds open to the arguments
10
+ * and result as highlighted JSON. The group sums up every call of one assistant turn and folds too.
11
+ *
12
+ * Public styling hooks (set them on the element or any ancestor):
13
+ * --ui-tool-call-radius card corners (default 10px; Classic 12px)
14
+ * --ui-tool-call-code-string JSON strings (default: sky blue; Classic teal)
15
+ * --ui-tool-call-code-number JSON numbers, true, false and null (default: amber)
16
+ */
17
+ import {
18
+ Component,
19
+ DOCUMENT,
20
+ DestroyRef,
21
+ ElementRef,
22
+ afterNextRender,
23
+ afterRenderEffect,
24
+ booleanAttribute,
25
+ computed,
26
+ contentChildren,
27
+ effect,
28
+ inject,
29
+ input,
30
+ isDevMode,
31
+ model,
32
+ numberAttribute,
33
+ output,
34
+ signal,
35
+ untracked,
36
+ viewChild,
37
+ } from '@angular/core';
38
+
39
+ export type ToolCallStatus = 'running' | 'success' | 'error';
40
+ export type ToolCallIconName =
41
+ | 'wrench'
42
+ | 'search'
43
+ | 'file'
44
+ | 'database'
45
+ | 'globe'
46
+ | 'terminal'
47
+ | 'code'
48
+ | 'mail'
49
+ | 'calendar'
50
+ | 'chart'
51
+ | 'cloud'
52
+ | 'user';
53
+ /** A built-in icon name, or the `d` of your own path drawn with a 2px stroke in a 24 × 24 box. */
54
+ export type ToolCallIcon = ToolCallIconName | (string & {});
55
+
56
+ export interface ToolCallLabels {
57
+ arguments: string;
58
+ result: string;
59
+ copyArguments: string;
60
+ copyResult: string;
61
+ copied: string;
62
+ showAll: string;
63
+ showLess: string;
64
+ waiting: string;
65
+ failed: string;
66
+ retry: string;
67
+ /** Read after the name while the call runs, and announced when it starts. */
68
+ running: string;
69
+ /** Read after the name once it succeeded, and announced then. */
70
+ finished: string;
71
+ /** Announced after the name when the call fails, before the error message. */
72
+ failedAnnouncement: string;
73
+ duration: (ms: number) => string;
74
+ }
75
+
76
+ export interface ToolCallGroupLabels {
77
+ running: string;
78
+ used: (count: number) => string;
79
+ failed: (count: number) => string;
80
+ duration: (ms: number) => string;
81
+ }
82
+
83
+ const seconds = (ms: number) => {
84
+ const s = ms / 1000;
85
+ return s < 60 ? `${s.toFixed(1)}s` : `${Math.floor(s / 60)}m ${String(Math.floor(s % 60)).padStart(2, '0')}s`;
86
+ };
87
+
88
+ const LABELS: ToolCallLabels = {
89
+ arguments: 'Arguments',
90
+ result: 'Result',
91
+ copyArguments: 'Copy arguments',
92
+ copyResult: 'Copy result',
93
+ copied: 'Copied',
94
+ showAll: 'Show all',
95
+ showLess: 'Show less',
96
+ waiting: 'Waiting for result…',
97
+ failed: 'Failed',
98
+ retry: 'Retry',
99
+ running: 'running',
100
+ finished: 'finished',
101
+ failedAnnouncement: 'failed',
102
+ duration: seconds,
103
+ };
104
+
105
+ const GROUP_LABELS: ToolCallGroupLabels = {
106
+ running: 'Using tools…',
107
+ used: (n) => (n === 1 ? 'Used 1 tool' : `Used ${n} tools`),
108
+ failed: (n) => `${n} failed`,
109
+ duration: seconds,
110
+ };
111
+
112
+ const ICONS: Record<ToolCallIconName, string> = {
113
+ wrench: 'M14.6 3.4a5.2 5.2 0 0 0-5.3 6.8l-5.7 5.7a2.1 2.1 0 1 0 3 3l5.7-5.7a5.2 5.2 0 0 0 6.8-5.3l-3 3-3-.5-.5-3z',
114
+ search: 'M17.5 11a6.5 6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0zM16 16l4.5 4.5',
115
+ file: 'M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8zM14 3v5h5M9 13h6M9 17h4',
116
+ database: 'M5 6c0-1.7 3.1-3 7-3s7 1.3 7 3-3.1 3-7 3-7-1.3-7-3zM5 6v12c0 1.7 3.1 3 7 3s7-1.3 7-3V6M5 12c0 1.7 3.1 3 7 3s7-1.3 7-3',
117
+ globe: 'M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0zM3.5 12h17M12 3c2.4 2.5 3.6 5.5 3.6 9s-1.2 6.5-3.6 9c-2.4-2.5-3.6-5.5-3.6-9S9.6 5.5 12 3z',
118
+ terminal: 'M5 17l5-5-5-5M12 18h7',
119
+ code: 'M8.5 7.5L4 12l4.5 4.5M15.5 7.5L20 12l-4.5 4.5',
120
+ mail: 'M5 5h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM3.5 6.5l8.5 6 8.5-6',
121
+ calendar: 'M5 5h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM3 10h18M8 3v4M16 3v4',
122
+ chart: 'M4 20V11M10 20V5M16 20v-6M3 20h18',
123
+ cloud: 'M7.5 18.5a4.5 4.5 0 0 1-.7-8.95 6 6 0 0 1 11.4 1.45 3.75 3.75 0 0 1-.7 7.5z',
124
+ user: 'M16 8a4 4 0 1 1-8 0 4 4 0 0 1 8 0zM4.5 20.5a7.5 7.5 0 0 1 15 0',
125
+ };
126
+
127
+ /** The path drawn for an icon: a built-in name, or your own path data as is. */
128
+ export const toolCallIconPath = (icon: ToolCallIcon) => ICONS[icon as ToolCallIconName] ?? icon;
129
+
130
+ type Token = { k: '' | 'k' | 's' | 'n'; t: string };
131
+ const TOKEN = /("(?:[^"\\\n]|\\.)*")(\s*:)?|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|\b(?:true|false|null)\b/g;
132
+
133
+ /** Objects and JSON strings are pretty-printed and highlighted; anything else is plain text. */
134
+ export function formatToolCallValue(value: unknown): { json: boolean; text: string } {
135
+ if (typeof value === 'string') {
136
+ try {
137
+ const parsed: unknown = JSON.parse(value);
138
+ if (parsed && typeof parsed === 'object') return { json: true, text: JSON.stringify(parsed, null, 2) };
139
+ } catch {}
140
+ return { json: false, text: value };
141
+ }
142
+ try {
143
+ const text = JSON.stringify(value, null, 2);
144
+ if (text !== undefined) return { json: true, text };
145
+ } catch {}
146
+ return { json: false, text: String(value) };
147
+ }
148
+
149
+ function tokenize(text: string): Token[] {
150
+ const out: Token[] = [];
151
+ let at = 0;
152
+ for (const m of text.matchAll(TOKEN)) {
153
+ if (m.index > at) out.push({ k: '', t: text.slice(at, m.index) });
154
+ if (m[1]) {
155
+ out.push({ k: m[2] ? 'k' : 's', t: m[1] });
156
+ if (m[2]) out.push({ k: '', t: m[2] });
157
+ } else out.push({ k: 'n', t: m[0] });
158
+ at = m.index + m[0].length;
159
+ }
160
+ if (at < text.length) out.push({ k: '', t: text.slice(at) });
161
+ return out;
162
+ }
163
+
164
+ let nextId = 0;
165
+
166
+ const ALERT = 'M8 4.8v3.6M8 11h.01';
167
+ const SVG = 'flex: none; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round';
168
+
169
+ @Component({
170
+ selector: 'ui-tool-call-section',
171
+ host: { style: 'display: grid; gap: 6px; min-inline-size: 0' },
172
+ template: `
173
+ <div style="display: flex; align-items: center; justify-content: space-between; gap: 8px; min-block-size: calc(28px - 4px * var(--_t))">
174
+ <span class="lb" style="color: var(--ui-text-muted); font: var(--ui-weight-medium) calc(10px + 2px * var(--_t)) / calc(16px + .8px * var(--_t)) var(--ui-font-sans); letter-spacing: calc(.5px * var(--_f))">{{ label() }}</span>
175
+ @if (formatted(); as f) {
176
+ <button type="button" class="cp" [attr.data-copied]="copied() ? '' : null" [attr.aria-label]="copied() ? labels().copied : copyLabel()" [title]="copied() ? labels().copied : copyLabel()" (click)="copy(f.text)"
177
+ style="position: relative; display: grid; place-items: center; flex: none; inline-size: calc(28px - 4px * var(--_t)); block-size: calc(28px - 4px * var(--_t)); padding: 0; border: 0; border-radius: 6px; box-shadow: 0 0 0 calc(.5px * var(--_f)) var(--_e), 0 calc(1px * var(--_f)) calc(2px * var(--_f)) var(--_sh); cursor: pointer; transition: color var(--_d), background-color var(--_d)">
178
+ <svg class="ci" viewBox="0 0 16 16" aria-hidden="true" [style]="icon"><path d="M10.5 3.5V3A1.5 1.5 0 0 0 9 1.5H3A1.5 1.5 0 0 0 1.5 3v6A1.5 1.5 0 0 0 3 10.5h.5" /><rect x="5.5" y="5.5" width="9" height="9" rx="1.75" style="fill: currentColor; fill-opacity: var(--_f)" /></svg>
179
+ <svg class="ok" viewBox="0 0 16 16" aria-hidden="true" [style]="icon + '; color: var(--ui-hue-blue); stroke-width: 1.6'"><path d="M3.5 8.5l3 3 6-7" /></svg>
180
+ </button>
181
+ }
182
+ </div>
183
+ @if (formatted(); as f) {
184
+ <pre #pre class="well" dir="ltr" [attr.data-capped]="capped() && !expanded() ? '' : null" [style.max-block-size.px]="capped() ? (expanded() ? full() : cap()) : null"
185
+ style="position: relative; margin: 0; padding: 10px 12px; overflow: hidden; border-radius: 8px; background: var(--_w); box-shadow: inset 0 0 0 calc(.5px + .5px * var(--_t)) var(--_e); color: var(--ui-text-muted); font: 12px / calc(20px - .8px * var(--_t)) var(--ui-font-mono); white-space: pre-wrap; overflow-wrap: anywhere; transition: max-block-size calc(420ms * var(--_m)) var(--_ease)"><code style="display: block; font: inherit">@for (t of tokens(); track $index) {<span [class]="t.k">{{ t.t }}</span>}</code></pre>
186
+ @if (capped()) {
187
+ <button type="button" class="more" [attr.aria-expanded]="expanded()" (click)="expanded.set(!expanded())"
188
+ style="position: relative; justify-self: start; margin-inline-start: -4px; padding: 2px 4px; border: 0; border-radius: 6px; background: none; font: var(--ui-weight-medium) calc(12px + .5px * var(--_t)) / 16px var(--ui-font-sans); cursor: pointer; transition: color var(--_d)">{{ expanded() ? labels().showLess : labels().showAll }}</button>
189
+ }
190
+ } @else {
191
+ <p dir="auto" style="margin: 0; color: var(--ui-text-muted); font-size: calc(12px + .5px * var(--_t)); line-height: calc(16px + 1.5px * var(--_t))">{{ waiting() }}</p>
192
+ }
193
+ `,
194
+ styles: `
195
+ :host { --_w: color-mix(in srgb, var(--ui-text) 3%, var(--ui-bg-surface)); --_d: calc(160ms * var(--_m)); }
196
+ .lb { text-transform: uppercase; }
197
+ @container style(--ui-look-tray: 1) { .lb { text-transform: none; } }
198
+ .cp { background: color-mix(in srgb, var(--ui-bg-surface) calc(100% * var(--_f)), transparent); color: var(--ui-icon); }
199
+ @media (hover: hover) { .cp:hover { background-color: color-mix(in srgb, var(--ui-text) 4%, color-mix(in srgb, var(--ui-bg-surface) calc(100% * var(--_f)), transparent)); color: var(--ui-icon-active); } }
200
+ .ok, [data-copied] .ci { opacity: 0; scale: .6; filter: blur(2px); }
201
+ [data-copied] .ok { opacity: 1; scale: 1; filter: none; }
202
+ .more { color: var(--ui-text-muted); }
203
+ @media (hover: hover) { .more:hover { color: var(--ui-text); } }
204
+ .more::after { content: ''; position: absolute; inset: -2px 0; }
205
+ :focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
206
+ .well::after { content: ''; position: absolute; inset: auto 0 0; block-size: 56px; background: linear-gradient(transparent, var(--_w)); opacity: 0; pointer-events: none; transition: opacity calc(240ms * var(--_m)); }
207
+ [data-capped]::after { opacity: 1; }
208
+ .k { color: var(--ui-text); }
209
+ .s { color: var(--ui-tool-call-code-string, color-mix(in oklab, light-dark(oklch(from var(--ui-hue-cyan) calc(l - .09) c h), var(--ui-hue-cyan)) calc(100% * var(--_f)), light-dark(oklch(from var(--ui-hue-teal) calc(l - .125) c h), var(--ui-hue-teal)))); }
210
+ .n { color: var(--ui-tool-call-code-number, light-dark(oklch(from var(--ui-hue-amber) calc(l - .2) c h), var(--ui-hue-amber))); }
211
+ @media (pointer: coarse) { .cp::after { content: ''; position: absolute; inset: -8px; } }
212
+ @media (forced-colors: active) { .cp, .well { border: 1px solid; } }
213
+ `,
214
+ })
215
+ class ToolCallSection {
216
+ readonly label = input.required<string>();
217
+ readonly copyLabel = input('');
218
+ readonly value = input<unknown>();
219
+ readonly waiting = input('');
220
+ readonly cap = input(220);
221
+ readonly labels = input(LABELS);
222
+
223
+ protected readonly icon = `grid-area: 1 / 1; inline-size: calc(16px - 2px * var(--_t)); ${SVG}; stroke-width: 1.3; transition: opacity calc(200ms * var(--_m)), scale calc(320ms * var(--_m)) var(--ui-ease-out), filter calc(320ms * var(--_m)) var(--ui-ease-out)`;
224
+ protected readonly formatted = computed(() => (this.value() === undefined ? null : formatToolCallValue(this.value())));
225
+ protected readonly tokens = computed((): Token[] => {
226
+ const f = this.formatted();
227
+ return !f ? [] : f.json ? tokenize(f.text) : [{ k: '', t: f.text }];
228
+ });
229
+ protected readonly copied = signal(false);
230
+ protected readonly expanded = signal(false);
231
+ protected readonly full = signal(0);
232
+ protected readonly capped = computed(() => this.full() > this.cap());
233
+ private readonly pre = viewChild<ElementRef<HTMLPreElement>>('pre');
234
+ private readonly doc = inject(DOCUMENT);
235
+ private timer?: ReturnType<typeof setTimeout>;
236
+
237
+ constructor() {
238
+ afterRenderEffect((onCleanup) => {
239
+ const pre = this.pre()?.nativeElement;
240
+ if (!pre?.firstElementChild || typeof ResizeObserver === 'undefined') return;
241
+ const ro = new ResizeObserver(() => this.full.set(pre.scrollHeight));
242
+ ro.observe(pre.firstElementChild);
243
+ onCleanup(() => ro.disconnect());
244
+ });
245
+ inject(DestroyRef).onDestroy(() => clearTimeout(this.timer));
246
+ }
247
+
248
+ protected copy(text: string) {
249
+ this.doc.defaultView?.navigator.clipboard?.writeText(text).then(
250
+ () => {
251
+ this.copied.set(true);
252
+ clearTimeout(this.timer);
253
+ this.timer = setTimeout(() => this.copied.set(false), 1400);
254
+ },
255
+ () => {},
256
+ );
257
+ }
258
+ }
259
+
260
+ @Component({
261
+ selector: 'ui-tool-call-card',
262
+ imports: [ToolCallSection],
263
+ host: {
264
+ style:
265
+ '--_t: var(--ui-look-tray, 0); --_f: calc(1 - var(--_t)); --_m: var(--ui-motion-scale); --_ease: cubic-bezier(.22, 1, .36, 1); --_r: var(--ui-tool-call-radius, calc(10px + 2px * var(--_t))); --_e: color-mix(in srgb, color-mix(in srgb, var(--ui-bg-muted) 88%, var(--ui-bg-surface)) calc(100% * var(--_f)), var(--ui-hairline)); --_sh: color-mix(in srgb, var(--ui-bg-scrim) 15%, transparent); --_red: color-mix(in oklab, var(--ui-hue-red), var(--ui-danger)); position: relative; border-radius: var(--_r); color: var(--ui-text); font: var(--ui-text-base) / var(--ui-leading-base) var(--ui-font-sans)',
266
+ '[attr.data-status]': 'status()',
267
+ '[attr.data-open]': 'open() ? "" : null',
268
+ },
269
+ template: `
270
+ <span class="ui-sr" role="status" aria-live="polite">{{ live() }}</span>
271
+ <div class="q">
272
+ <button #head type="button" class="head" [attr.aria-expanded]="open()" [attr.aria-controls]="uid" (click)="toggle()"
273
+ style="display: flex; align-items: center; gap: var(--_g); box-sizing: border-box; inline-size: 100%; min-block-size: var(--_hh); margin: 0; padding: calc(8px * var(--_t)) calc(var(--_px) * var(--_f) + 10px * var(--_t)) calc(8px * var(--_t)) calc(var(--_px) * var(--_f) + 9px * var(--_t)); border: 0; color: inherit; font: inherit; text-align: start; cursor: pointer; -webkit-tap-highlight-color: transparent">
274
+ <span aria-hidden="true" style="display: grid; place-items: center; flex: none; inline-size: calc(16px + 10px * var(--_t)); aspect-ratio: 1; border-radius: 7px; background: color-mix(in srgb, var(--ui-bg-subtle) calc(100% * var(--_t)), transparent); box-shadow: inset 0 0 0 calc(1px * var(--_t)) var(--ui-hairline); color: color-mix(in srgb, var(--ui-text) calc(45% + 55% * var(--_t)), var(--ui-text-muted))">
275
+ <svg viewBox="0 0 24 24" [style]="svg + '; inline-size: calc(16px - 2px * var(--_t)); stroke-width: 2.1'"><path [attr.d]="iconPath()" /></svg>
276
+ </span>
277
+ <span style="display: flex; align-items: baseline; gap: 8px; flex: 1; min-inline-size: 0">
278
+ <code dir="ltr" [title]="name()" [style]="clip + '; flex: none; max-inline-size: 100%; font: var(--ui-weight-medium) calc(12px + .5px * var(--_t)) / calc(20px - 2.5px * var(--_t)) var(--ui-font-mono)'">{{ name() }}</code>
279
+ @if (summary()) {
280
+ <span dir="auto" [title]="summary()" [style]="clip + '; flex: 1 1 0; min-inline-size: 0; color: var(--ui-text-muted); font-size: calc(13px + .5px * var(--_t)); line-height: calc(20px - 1.1px * var(--_t)); letter-spacing: calc(-.081px * var(--_t))'">{{ summary() }}</span>
281
+ }
282
+ </span>
283
+ <span class="st" style="display: grid; flex: none; color: var(--ui-text-muted); font-size: calc(12px + .5px * var(--_t)); line-height: calc(16px + 1.5px * var(--_t)); font-variant-numeric: tabular-nums; white-space: nowrap">
284
+ @switch (status()) {
285
+ @case ('running') {
286
+ <span animate.enter="in" animate.leave="out" [style]="stat">
287
+ <svg class="spin" viewBox="0 0 16 16" aria-hidden="true" [style]="svg + '; inline-size: 16px; margin: -1px; color: var(--ui-hue-blue); stroke-width: 2'"><circle cx="8" cy="8" r="6" style="stroke: var(--ui-border)" /><circle cx="8" cy="8" r="6" pathLength="4" stroke-dasharray="1 3" /></svg>{{ time() }}<span class="ui-sr">{{ l().running }}</span>
288
+ </span>
289
+ }
290
+ @case ('success') {
291
+ <span animate.enter="in" animate.leave="out" [style]="stat">
292
+ <svg class="ok" viewBox="0 0 16 16" aria-hidden="true" [style]="svg + '; inline-size: 14px; stroke-width: calc(2px - .6px * var(--_t))'"><circle cx="8" cy="8" r="7" style="fill: var(--ui-hue-blue); fill-opacity: var(--_f); stroke: none; transform-origin: center" /><path d="M5.2 8.3l1.9 1.9 3.8-4" pathLength="1" style="stroke: color-mix(in srgb, var(--ui-bg-knob) calc(100% * var(--_f)), var(--ui-text)); stroke-dasharray: 1; scale: calc(1 + .45 * var(--_t)); transform-origin: center" /></svg>{{ time() }}<span class="ui-sr">{{ l().finished }}</span>
293
+ </span>
294
+ }
295
+ @default {
296
+ <span animate.enter="in" animate.leave="out" [style]="stat + '; color: var(--_red); font-weight: calc(500 - 100 * var(--_t))'">
297
+ <svg viewBox="0 0 16 16" aria-hidden="true" [style]="svg + '; inline-size: 14px; stroke-width: 2'"><circle cx="8" cy="8" r="7" [style]="disc" /><path [attr.d]="alert" [style]="glyph" /></svg>{{ l().failed }}
298
+ </span>
299
+ }
300
+ }
301
+ </span>
302
+ <svg class="chev" viewBox="0 0 16 16" aria-hidden="true" [style]="svg + '; inline-size: calc(12px + 2px * var(--_t)); stroke-width: 1.5'"><path d="M4.5 6.25L8 9.75l3.5-3.5" /></svg>
303
+ </button>
304
+ <div class="body" [id]="uid" [attr.inert]="open() ? null : ''">
305
+ <div style="overflow: hidden; min-block-size: 0">
306
+ <div class="pad" style="display: grid; gap: calc(14px - 2px * var(--_t)); padding: 12px calc(var(--_px) * var(--_f) + 12px * var(--_t)) calc(14px - 2px * var(--_t)); border-block-start: 1px solid var(--_e)">
307
+ @if (status() === 'error' && (error() || retryable())) {
308
+ <div class="err" style="display: flex; align-items: center; gap: 8px; padding: calc(8px + 1px * var(--_t)) calc(8px + 2px * var(--_t)) calc(8px + 1px * var(--_t)) calc(12px - 1px * var(--_t)); border-radius: 8px; background: color-mix(in srgb, var(--ui-hue-red) calc(5% + 3% * var(--_t)), var(--ui-bg-surface)); box-shadow: inset 0 0 0 calc(.5px + .5px * var(--_t)) color-mix(in srgb, var(--ui-hue-red) 22%, transparent); color: var(--_red); font-size: calc(13px + .5px * var(--_t)); line-height: calc(20px - 1.15px * var(--_t))">
309
+ <svg viewBox="0 0 16 16" aria-hidden="true" [style]="svg + '; align-self: flex-start; inline-size: calc(16px - 2px * var(--_t)); margin-block-start: calc(6px - 2px * var(--_t)); stroke-width: 2'"><circle cx="8" cy="8" r="7" [style]="disc" /><path [attr.d]="alert" [style]="glyph" /></svg>
310
+ <p dir="auto" style="flex: 1; min-inline-size: 0; margin: 0; white-space: pre-line; overflow-wrap: anywhere">{{ error() }}</p>
311
+ @if (retryable()) {
312
+ <button type="button" class="retry" (click)="retryIt()"
313
+ style="position: relative; display: inline-flex; align-items: center; flex: none; gap: calc(6px - 1px * var(--_t)); block-size: calc(28px - 2px * var(--_t)); margin-block: calc(-3px * var(--_t)); padding: 0 10px 0 calc(6px + 2px * var(--_t)); border: 0; border-radius: calc(6px + 1px * var(--_t)); color: var(--ui-text); font: var(--ui-weight-medium) calc(13px - .5px * var(--_t)) / 1 var(--ui-font-sans); cursor: pointer; transition: background-color calc(160ms * var(--_m)), box-shadow calc(200ms * var(--_m))">
314
+ <svg viewBox="0 0 16 16" aria-hidden="true" [style]="svg + '; inline-size: calc(16px - 3px * var(--_t)); color: var(--ui-icon); stroke-width: 1.4'"><path d="M2.75 8a5.25 5.25 0 1 0 1.6-3.8L2.75 5.75" /><path d="M2.75 2.5v3.25H6" /></svg>{{ l().retry }}
315
+ </button>
316
+ }
317
+ </div>
318
+ }
319
+ @if (args() !== undefined) {
320
+ <ui-tool-call-section [label]="l().arguments" [copyLabel]="l().copyArguments" [value]="args()" [cap]="maxCodeHeight()" [labels]="l()" />
321
+ }
322
+ @if (status() !== 'error' && (result() !== undefined || status() === 'running')) {
323
+ <ui-tool-call-section [label]="l().result" [copyLabel]="l().copyResult" [value]="result()" [waiting]="l().waiting" [cap]="maxCodeHeight()" [labels]="l()" />
324
+ }
325
+ </div>
326
+ </div>
327
+ </div>
328
+ </div>
329
+ `,
330
+ styles: `
331
+ :host { --_g: 10px; --_hh: 44px; --_px: 14px; display: block; background: var(--ui-bg-surface); box-shadow: 0 0 0 calc(.5px * var(--_f)) var(--_e), 0 calc(1px * var(--_f)) 1px calc(-1px * var(--_f)) var(--_sh), 0 1px 2px var(--_sh); }
332
+ :host::before { content: 'x x x x x x x x' / ''; display: block; block-size: 0; overflow: hidden; font-size: 0; word-spacing: calc(460px / 7); }
333
+ .q { container-type: inline-size; }
334
+ :host::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 calc(1px * var(--_t)) var(--_e); pointer-events: none; }
335
+ .head { border-radius: var(--_r); background: none; transition: background-color calc(160ms * var(--_m)), border-radius 0s calc(380ms * var(--_m)); }
336
+ :host([data-open]) .head { border-end-start-radius: 0; border-end-end-radius: 0; transition-delay: 0s; }
337
+ :focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
338
+ .chev { color: var(--ui-icon); transition: rotate calc(360ms * var(--_m)) var(--_ease), color calc(160ms * var(--_m)); }
339
+ @media (hover: hover) { .head:hover { background: rgb(from var(--ui-text) r g b / calc(.028 + .02 * r / 255 + .01 * var(--_t))); } .head:hover .chev { color: color-mix(in srgb, var(--ui-icon) calc(100% * var(--_t)), var(--ui-icon-active)); } }
340
+ :host([data-open]) .chev { rotate: .5turn; }
341
+ .body { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows calc(380ms * var(--_m)) var(--_ease), opacity calc(240ms * var(--_m)) var(--_ease); }
342
+ :host([data-open]) .body { grid-template-rows: 1fr; opacity: 1; transition-duration: calc(380ms * var(--_m)), 0s; }
343
+ .retry { background: var(--ui-bg-surface); box-shadow: 0 0 0 .5px var(--_e), 0 1px 2px var(--_sh); }
344
+ @media (hover: hover) { .retry:hover { background: color-mix(in srgb, var(--ui-hue-red) 4%, var(--ui-bg-surface)); } }
345
+ .retry:active { box-shadow: 0 0 0 .5px var(--_e); }
346
+ .spin { animation: ui-spin .8s linear infinite; }
347
+ .ok circle { animation: pop calc(460ms * var(--_m)) var(--ui-ease-spring) both; }
348
+ .ok path { animation: ui-draw calc(360ms * var(--_m)) calc((160ms - 80ms * var(--_t)) * var(--_m)) var(--_ease) both; }
349
+ .in { animation: in calc(360ms * var(--_m)) var(--ui-ease-out); }
350
+ .out { animation: in calc(360ms * var(--_m)) var(--ui-ease-out) reverse both; }
351
+ @keyframes in { from { opacity: 0; filter: blur(2px); } }
352
+ @keyframes pop { from { scale: calc(.6 + .4 * var(--_t)); } }
353
+ @container (width < 360px) { .head, .pad { --_px: 12px; --_g: 8px; } }
354
+ @media (pointer: coarse) { :host { --_hh: 52px; } .retry::after { content: ''; position: absolute; inset: -8px; } }
355
+ @media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
356
+ @container style(--ui-motion-scale: 0) { .spin { animation: none; } }
357
+ @media (forced-colors: active) { :host::after, .retry { border: 1px solid; } .err { border: 2px solid; } }
358
+ `,
359
+ })
360
+ export class UiToolCallCard {
361
+ /** The tool name as the agent calls it, shown in monospace. Also the card's name for screen readers. */
362
+ readonly name = input.required<string>();
363
+ /** `running` shows a spinner and a live timer; `success` a check and the duration; `error` "Failed". */
364
+ readonly status = input<ToolCallStatus>('running');
365
+ /** A short human summary after the name; it truncates. Present progressive while running, past tense once done. */
366
+ readonly summary = input<string>();
367
+ /** A built-in icon name, or your own 24 × 24 path data. The group shows it too. */
368
+ readonly icon = input<ToolCallIcon>('wrench');
369
+ /** The arguments. Objects and JSON strings are pretty-printed and highlighted; the section is hidden when undefined. */
370
+ readonly args = input<unknown>();
371
+ /** What the tool returned, shown like `args`. While running without one, "Waiting for result…" shows. */
372
+ readonly result = input<unknown>();
373
+ /** The error message, shown in the body when the status is `error`. */
374
+ readonly error = input<string>();
375
+ /** When the call started (ms since epoch). The live timer counts from here instead of from when it became running. */
376
+ readonly startedAt = input<number>();
377
+ /** The final duration in ms. Without it, the time measured while running is kept. */
378
+ readonly duration = input<number>();
379
+ /** Whether the body is open. Bind `[(open)]`, or set `[open]="true"` to start open. */
380
+ readonly open = model(false);
381
+ /** Opens the card when the call fails and closes it again when it reruns, unless someone toggled it by hand. */
382
+ readonly openOnError = input(true, { transform: booleanAttribute });
383
+ /** Shows a Retry button next to the error message. Listen to `(retry)`. */
384
+ readonly retryable = input(false, { transform: booleanAttribute });
385
+ /** Height in px after which arguments and result are capped with a fade and a "Show all" button. */
386
+ readonly maxCodeHeight = input(220, { transform: numberAttribute });
387
+ /** Every visible and spoken string, and the duration format. */
388
+ readonly labels = input<Partial<ToolCallLabels>>({});
389
+ /** Retry was pressed. Set the status back to `running` and rerun the call. */
390
+ readonly retry = output<void>();
391
+
392
+ protected readonly uid = `ui-tool-call-${nextId++}`;
393
+ protected readonly svg = SVG;
394
+ protected readonly alert = ALERT;
395
+ protected readonly clip = 'overflow: hidden; text-overflow: ellipsis; white-space: nowrap';
396
+ protected readonly stat = 'grid-area: 1 / 1; justify-self: end; display: flex; align-items: center; gap: 6px';
397
+ protected readonly disc = 'fill: var(--ui-hue-red); fill-opacity: var(--_f); stroke-width: calc(1.5px * var(--_t))';
398
+ protected readonly glyph = 'stroke: color-mix(in srgb, var(--ui-bg-knob) calc(100% * var(--_f)), currentColor)';
399
+ protected readonly l = computed(() => ({ ...LABELS, ...this.labels() }));
400
+ /** The path of the icon, for the group's tiles. */
401
+ readonly iconPath = computed(() => toolCallIconPath(this.icon()));
402
+ private readonly now = signal(Date.now());
403
+ private readonly since = signal(Date.now());
404
+ private readonly measured = signal<number | undefined>(undefined);
405
+ private readonly spent = signal(0);
406
+ /** Milliseconds of the current run: live while running, then the final duration. */
407
+ readonly elapsed = computed(() =>
408
+ this.status() === 'running' ? Math.max(0, this.now() - (this.startedAt() ?? this.since())) : (this.duration() ?? this.measured()),
409
+ );
410
+ /** All runs together, retries included. The group adds these up. */
411
+ readonly total = computed(() => this.spent() + (this.elapsed() ?? 0));
412
+ protected readonly time = computed(() => {
413
+ const ms = this.elapsed();
414
+ return ms === undefined ? '' : this.l().duration(ms);
415
+ });
416
+ protected readonly live = signal('');
417
+ private readonly head = viewChild.required<ElementRef<HTMLButtonElement>>('head');
418
+ private last?: ToolCallStatus;
419
+ private lastFinal = 0;
420
+ private autoOpened = false;
421
+ private toggled = false;
422
+
423
+ constructor() {
424
+ effect((onCleanup) => {
425
+ const status = this.status();
426
+ untracked(() => this.step(status));
427
+ if (status !== 'running') return;
428
+ const id = setInterval(() => this.now.set(Date.now()), 100);
429
+ onCleanup(() => clearInterval(id));
430
+ });
431
+ effect(() => {
432
+ if (this.status() !== 'running') this.lastFinal = this.elapsed() ?? 0;
433
+ });
434
+ afterNextRender(() => {
435
+ if (isDevMode() && !this.name().trim()) console.warn('ui-tool-call-card: give it a name, the tool name the agent called.');
436
+ });
437
+ }
438
+
439
+ protected retryIt() {
440
+ this.head().nativeElement.focus();
441
+ this.retry.emit();
442
+ }
443
+
444
+ protected toggle() {
445
+ this.toggled = true;
446
+ this.open.set(!this.open());
447
+ }
448
+
449
+ private step(status: ToolCallStatus) {
450
+ const prev = this.last;
451
+ this.last = status;
452
+ if (status === prev) return;
453
+ const at = Date.now();
454
+ if (status === 'running') {
455
+ if (prev) this.spent.update((v) => v + this.lastFinal);
456
+ this.since.set(at);
457
+ this.now.set(at);
458
+ this.measured.set(undefined);
459
+ if (this.autoOpened && !this.toggled) this.open.set(false);
460
+ this.autoOpened = false;
461
+ } else if (prev === 'running') {
462
+ this.measured.set(Math.max(0, at - (this.startedAt() ?? this.since())));
463
+ }
464
+ if (status === 'error' && this.openOnError() && !this.toggled && !this.open()) {
465
+ this.open.set(true);
466
+ this.autoOpened = true;
467
+ }
468
+ if (prev === undefined) return;
469
+ const l = this.l();
470
+ const error = this.error();
471
+ this.live.set(
472
+ `${this.name()} ${status === 'running' ? l.running : status === 'success' ? l.finished : l.failedAnnouncement + (error ? `: ${error}` : '')}`,
473
+ );
474
+ }
475
+ }
476
+
477
+ @Component({
478
+ selector: 'ui-tool-call-group',
479
+ host: {
480
+ style:
481
+ '--_t: var(--ui-look-tray, 0); --_f: calc(1 - var(--_t)); --_m: var(--ui-motion-scale); --_ease: cubic-bezier(.22, 1, .36, 1); color: var(--ui-text); font: calc(13px + .5px * var(--_t)) / calc(20px - 1.1px * var(--_t)) var(--ui-font-sans)',
482
+ '[attr.data-open]': 'open() ? "" : null',
483
+ '[attr.data-running]': 'running() ? "" : null',
484
+ },
485
+ template: `
486
+ <span class="ui-sr" role="status" aria-live="polite">{{ live() }}</span>
487
+ <button type="button" class="head" [attr.aria-expanded]="open()" [attr.aria-controls]="uid" (click)="open.set(!open())"
488
+ style="display: inline-flex; align-items: center; justify-self: start; gap: calc(8px + 1px * var(--_t)); box-sizing: border-box; max-inline-size: calc(100% + 6px * var(--_f)); min-block-size: calc(32px + 4px * var(--_t)); margin: 0; margin-inline-start: calc(-6px * var(--_f)); padding: 4px 10px; padding-inline-start: calc(6px - 1px * var(--_t)); border: 0; border-radius: calc(8px + 2px * var(--_t)); color: inherit; font: inherit; text-align: start; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background-color calc(160ms * var(--_m))">
489
+ <span aria-hidden="true" style="display: flex; flex: none; padding: .5px">
490
+ @for (c of tiles(); track c) {
491
+ <span class="tile" animate.enter="pop" [style]="tile"><svg viewBox="0 0 24 24" [style]="svg"><path [attr.d]="c.iconPath()" /></svg></span>
492
+ }
493
+ @if (more()) {<span class="tile" [style]="tile">+{{ more() }}</span>}
494
+ </span>
495
+ <span style="display: flex; align-items: baseline; gap: calc(6px - 1px * var(--_t)); min-inline-size: 0; white-space: nowrap">
496
+ @for (k of [head()]; track 'head:' + k) {
497
+ <span class="lb" dir="auto" animate.enter="in" style="overflow: hidden; text-overflow: ellipsis; font-weight: var(--ui-weight-medium)">{{ text() }}</span>
498
+ @if (failed()) {<bdi animate.enter="in" [style]="meta + '; color: color-mix(in oklab, var(--ui-hue-red), var(--ui-danger))'"> · {{ l().failed(failed()) }}</bdi>}
499
+ @if (total()) {<bdi animate.enter="in" [style]="meta"> · {{ l().duration(total()) }}</bdi>}
500
+ }
501
+ </span>
502
+ <svg class="chev" viewBox="0 0 16 16" aria-hidden="true" [style]="svg + '; inline-size: calc(12px + 2px * var(--_t)); stroke-width: 1.5'"><path d="M4.5 6.25L8 9.75l3.5-3.5" /></svg>
503
+ </button>
504
+ <div class="list" [id]="uid" [attr.inert]="open() ? null : ''">
505
+ <div style="overflow: hidden; min-block-size: 0; margin-inline: -4px">
506
+ <div style="display: grid; gap: 8px; padding: calc(6px + 2px * var(--_t)) 4px calc(6px - 2px * var(--_t))"><ng-content /></div>
507
+ </div>
508
+ </div>
509
+ `,
510
+ styles: `
511
+ :host { display: grid; }
512
+ .head { background: none; }
513
+ .head:focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
514
+ .tile + .tile { margin-inline-start: calc(-4px - 1px * var(--_t)); }
515
+ .pop { animation: pop calc(420ms * var(--_m)) var(--ui-ease-out); }
516
+ .lb { color: color-mix(in srgb, var(--ui-text-muted) calc(100% * var(--_t)), var(--ui-text)); }
517
+ .in { animation: in calc(360ms * var(--_m)) var(--ui-ease-out); }
518
+ :host([data-running]) .lb {
519
+ background: linear-gradient(100deg, var(--ui-text-muted) 40%, color-mix(in srgb, var(--ui-text-muted) 40%, var(--ui-bg-canvas)) 50%, var(--ui-text-muted) 60%) 0 0 / 250% 100%;
520
+ -webkit-background-clip: text; background-clip: text; color: transparent; animation: in calc(360ms * var(--_m)) var(--ui-ease-out), sh 1.8s linear infinite;
521
+ }
522
+ .chev { color: var(--ui-icon); transition: rotate calc(360ms * var(--_m)) var(--_ease), color calc(160ms * var(--_m)); }
523
+ @media (hover: hover) { .head:hover { background: rgb(from var(--ui-text) r g b / calc((.055 + .035 * r / 255) * var(--_f))); } .head:hover .chev { color: color-mix(in srgb, var(--ui-icon) calc(100% * var(--_t)), var(--ui-icon-active)); } }
524
+ :host([data-open]) .chev { rotate: .5turn; }
525
+ .list { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows calc(380ms * var(--_m)) var(--_ease), opacity calc(240ms * var(--_m)) var(--_ease), margin calc(380ms * var(--_m)) var(--_ease); }
526
+ :host([data-open]) .list { grid-template-rows: 1fr; opacity: 1; margin-block-end: -4px; }
527
+ @keyframes pop { from { opacity: 0; scale: .6; } }
528
+ @keyframes in { from { opacity: 0; filter: blur(2px); } }
529
+ @keyframes sh { from { background-position: 100% 0; } to { background-position: -50% 0; } }
530
+ @media (prefers-reduced-motion: reduce) { :host([data-running]) .lb { animation: none; background: none; color: var(--ui-text-muted); } }
531
+ @container style(--ui-motion-scale: 0) { :host([data-running]) .lb { animation: none; background: none; color: var(--ui-text-muted); } }
532
+ @media (forced-colors: active) { .tile { border: 1px solid; } }
533
+ `,
534
+ })
535
+ export class UiToolCallGroup {
536
+ /** The header once nothing runs. Default: "Used N tools". */
537
+ readonly label = input<string>();
538
+ /** Total time in ms. Default: the cards' times added up, retries included, live while any card runs. */
539
+ readonly duration = input<number>();
540
+ /** Whether the list is open. Bind `[(open)]`, or set `[open]="true"` to start open. */
541
+ readonly open = model(false);
542
+ /** Every visible and spoken string, and the duration format. */
543
+ readonly labels = input<Partial<ToolCallGroupLabels>>({});
544
+
545
+ protected readonly uid = `ui-tool-call-group-${nextId++}`;
546
+ protected readonly svg = `${SVG}; inline-size: 12px; stroke-width: 2.25`;
547
+ protected readonly tile =
548
+ 'display: grid; place-items: center; box-sizing: border-box; inline-size: calc(22px + 2px * var(--_t)); aspect-ratio: 1; border-radius: calc(6px + 1px * var(--_t)); background: color-mix(in srgb, var(--ui-bg-subtle) calc(100% * var(--_t)), var(--ui-bg-surface)); box-shadow: 0 0 0 calc(.5px * var(--_f)) color-mix(in srgb, var(--ui-bg-muted) 88%, var(--ui-bg-surface)), inset 0 0 0 calc(1px * var(--_t)) var(--ui-hairline), 0 0 0 calc(2px * var(--_t)) var(--ui-bg-canvas), 0 1px 2px calc(-1px * var(--_t)) color-mix(in srgb, var(--ui-bg-scrim) 15%, transparent); color: color-mix(in srgb, var(--ui-text) calc(100% * var(--_t)), var(--ui-icon)); font-size: 10px; font-weight: var(--ui-weight-medium)';
549
+ protected readonly meta = 'flex: none; color: var(--ui-text-muted); font-weight: var(--ui-weight-regular)';
550
+ private readonly cards = contentChildren(UiToolCallCard);
551
+ protected readonly l = computed(() => ({ ...GROUP_LABELS, ...this.labels() }));
552
+ protected readonly running = computed(() => this.cards().some((c) => c.status() === 'running'));
553
+ protected readonly failed = computed(() => this.cards().filter((c) => c.status() === 'error').length);
554
+ protected readonly total = computed(() => this.duration() ?? this.cards().reduce((sum, c) => sum + c.total(), 0));
555
+ protected readonly text = computed(() => (this.running() ? this.l().running : (this.label() ?? this.l().used(this.cards().length))));
556
+ protected readonly head = computed(() => `${this.text()}\n${this.failed()}`);
557
+ protected readonly tiles = computed(() => {
558
+ const cards = this.cards();
559
+ return cards.length > 5 ? cards.slice(0, 4) : cards;
560
+ });
561
+ protected readonly more = computed(() => this.cards().length - this.tiles().length);
562
+ protected readonly live = signal('');
563
+
564
+ constructor() {
565
+ let was: boolean | undefined;
566
+ effect(() => {
567
+ const running = this.running();
568
+ if (running === was) return;
569
+ const first = was === undefined;
570
+ was = running;
571
+ if (first) return;
572
+ untracked(() => {
573
+ const failed = this.failed();
574
+ this.live.set(running ? this.l().running : `${this.text()}${failed ? `, ${this.l().failed(failed)}` : ''}`);
575
+ });
576
+ });
577
+ }
578
+ }