@adecore/agents-react 0.49.3 → 0.49.5

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 (52) hide show
  1. package/dist/chat/chat-references.d.ts +13 -1
  2. package/dist/chat/chat-references.js +13 -2
  3. package/dist/chat/ui/ReferenceChip.js +98 -77
  4. package/dist/chat/ui/ReferenceTrail.d.ts +11 -0
  5. package/dist/chat/ui/ReferenceTrail.js +65 -0
  6. package/dist/chat/ui/RunSettings.js +2 -2
  7. package/dist/chat/ui/SessionLine.js +1 -1
  8. package/dist/chat/ui/chips.d.ts +1 -0
  9. package/dist/chat/ui/chips.js +2 -0
  10. package/dist/chat/ui/composer/ComposerMenu.js +28 -22
  11. package/dist/chat/ui/composer/chips.d.ts +3 -2
  12. package/dist/chat/ui/composer/chips.js +21 -9
  13. package/dist/chat/ui/composer/use-prompt-menus.d.ts +1 -0
  14. package/dist/chat/ui/composer/use-prompt-menus.js +115 -121
  15. package/dist/chat/ui/reference-icons.js +3 -1
  16. package/dist/chat/ui/rows/MessageRows.js +21 -8
  17. package/dist/locales/en/agent-chat.d.ts +3 -0
  18. package/dist/locales/en/agent-chat.js +4 -1
  19. package/dist/locales/en/agent-usage.d.ts +0 -1
  20. package/dist/locales/en/agent-usage.js +0 -1
  21. package/dist/locales/nl/agent-chat.d.ts +3 -0
  22. package/dist/locales/nl/agent-chat.js +4 -1
  23. package/dist/locales/nl/agent-usage.d.ts +0 -1
  24. package/dist/locales/nl/agent-usage.js +0 -1
  25. package/dist/usage/LimitsList.d.ts +5 -2
  26. package/dist/usage/LimitsList.js +649 -231
  27. package/dist/usage/UsageBreakdown.js +1 -1
  28. package/dist/usage/UsageLimits.js +1 -1
  29. package/dist/usage/UsageLimitsCard.js +81 -54
  30. package/dist/usage/limit-groups.d.ts +4 -3
  31. package/dist/usage/limit-groups.js +21 -11
  32. package/package.json +8 -8
  33. package/src/chat/chat-references.ts +53 -4
  34. package/src/chat/ui/ReferenceChip.tsx +8 -2
  35. package/src/chat/ui/ReferenceTrail.tsx +29 -0
  36. package/src/chat/ui/RunSettings.tsx +2 -2
  37. package/src/chat/ui/SessionLine.tsx +1 -1
  38. package/src/chat/ui/chips.ts +3 -0
  39. package/src/chat/ui/composer/ComposerMenu.tsx +30 -11
  40. package/src/chat/ui/composer/chips.ts +29 -11
  41. package/src/chat/ui/composer/use-prompt-menus.ts +12 -7
  42. package/src/chat/ui/reference-icons.ts +18 -1
  43. package/src/chat/ui/rows/MessageRows.tsx +1 -0
  44. package/src/locales/en/agent-chat.ts +4 -1
  45. package/src/locales/en/agent-usage.ts +0 -1
  46. package/src/locales/nl/agent-chat.ts +4 -1
  47. package/src/locales/nl/agent-usage.ts +0 -1
  48. package/src/usage/LimitsList.tsx +183 -54
  49. package/src/usage/UsageBreakdown.tsx +1 -1
  50. package/src/usage/UsageLimits.tsx +1 -1
  51. package/src/usage/UsageLimitsCard.tsx +11 -7
  52. package/src/usage/limit-groups.ts +25 -8
@@ -18,6 +18,7 @@ import {
18
18
  insertSkill,
19
19
  mentionPick,
20
20
  NO_MENTION_SEARCH,
21
+ presentReferences,
21
22
  queryOutsideChips,
22
23
  type MentionQuery,
23
24
  type MentionSearch,
@@ -30,7 +31,7 @@ import { clampMenuIndex, composerMenuAria } from './menu-aria';
30
31
  const SEARCH_DEBOUNCE_MS = 80;
31
32
  // What fits above the box without turning the picker into a file tree.
32
33
  const MENTION_RESULTS = 8;
33
- const REFERENCE_RESULTS = 8;
34
+ const REFERENCE_RESULTS = 20;
34
35
 
35
36
  /* The text of a prompt and what the person picked in it with `@`, `$` and `#`. */
36
37
  export type PromptDraft = Pick<ChatDraft, 'text' | 'mentions' | 'skills' | 'chats' | 'references' | 'referenceNames'>;
@@ -175,14 +176,18 @@ export function usePromptMenus<D extends PromptDraft>({
175
176
  // A host with nothing to point at keeps `#fff` out of the way rather than saying nothing matches.
176
177
  const offersReferences = referables.items.some((item) => !referables.chatsOnly || item.kind === 'chat');
177
178
  const referenceMenuOpen = !commandMenuOpen && !skillMenuOpen && !mentionMenuOpen && referenceQuery !== null && offersReferences;
178
- const excluded = ownId === undefined ? [...draft.chats, ...draft.references] : [ownId, ...draft.chats, ...draft.references];
179
- const referenceMatches = referenceMenuOpen ? referenceSuggestions(referables, referenceQuery.query, excluded, REFERENCE_RESULTS) : [];
180
179
 
181
180
  // What the editor draws as chips and the send checks are still in the text, under the name each was picked with.
182
- const referenceChips = referenceTokens([...draft.chats, ...draft.references], referables.items, draft.referenceNames).map((token) => ({
183
- ...token,
184
- kind: referables.items.find((item) => item.id === token.id)?.kind ?? null
185
- }));
181
+ const referenceChips = referenceTokens([...draft.chats, ...draft.references], referables.items, draft.referenceNames).map((token) => {
182
+ const item = referables.items.find((candidate) => candidate.id === token.id);
183
+
184
+ return { ...token, kind: item?.kind ?? null, trail: item?.trail };
185
+ });
186
+
187
+ // Only what is still in the text: a pick a person deleted stays in the draft, and would stay out of the menu for good.
188
+ const picked = presentReferences(text, [...draft.chats, ...draft.references], referenceChips);
189
+ const excluded = ownId === undefined ? picked : [ownId, ...picked];
190
+ const referenceMatches = referenceMenuOpen ? referenceSuggestions(referables, referenceQuery.query, excluded, REFERENCE_RESULTS) : [];
186
191
 
187
192
  // One menu is open at a time, so they share an id.
188
193
  const listId = useId();
@@ -1,12 +1,29 @@
1
1
  import { createElement, type ComponentType, type ReactNode } from 'react';
2
- import { Database, FileText, Frame, Globe, MessageSquare, PenTool, Smartphone, StickyNote, Terminal, Type, Workflow, type LucideIcon } from 'lucide-react';
2
+ import {
3
+ Database,
4
+ FileText,
5
+ Folder,
6
+ Frame,
7
+ Globe,
8
+ MessageSquare,
9
+ PenTool,
10
+ Smartphone,
11
+ StickyNote,
12
+ SwatchBook,
13
+ Terminal,
14
+ Type,
15
+ Workflow,
16
+ type LucideIcon
17
+ } from 'lucide-react';
3
18
  import { Icon } from '@adecore/ui';
4
19
  import type { ReferenceIconProps } from '../../host';
5
20
  import type { ReferableKind } from '../chat-references';
6
21
 
7
22
  /* The mark of what a `#` points at, in the picker and on its chip, when the host draws none of its own. */
8
23
  export const REFERENCE_ICONS: Record<ReferableKind, LucideIcon> = {
24
+ project: Folder,
9
25
  canvas: Frame,
26
+ design: SwatchBook,
10
27
  chat: MessageSquare,
11
28
  terminal: Terminal,
12
29
  note: StickyNote,
@@ -205,6 +205,7 @@ export function SentMessageRow({ chatId, id, message }: { chatId: string; id: st
205
205
  chip={<ReferenceChip id={message.from} lastName={message.title} />}
206
206
  text={message.text}
207
207
  />
208
+ {message.state !== undefined && <div className="mt-1 text-xs text-text-muted">{t(`rows.message.${message.state}`)}</div>}
208
209
  </ReferenceLookupContext>
209
210
  );
210
211
  }
@@ -122,7 +122,9 @@ export default {
122
122
  },
123
123
  message: {
124
124
  heading: 'Message from {{name}}',
125
- unnamed: 'another node'
125
+ unnamed: 'another node',
126
+ waiting: 'Waiting for the next turn',
127
+ dropped: 'Expired before the agent read it'
126
128
  },
127
129
  report: {
128
130
  heading: 'Report'
@@ -368,6 +370,7 @@ export default {
368
370
  canvas: 'On this canvas',
369
371
  views: 'Views',
370
372
  noMatch: 'No view or node matches',
373
+ currentProject: 'This project',
371
374
  kinds: {
372
375
  canvas: 'canvas',
373
376
  chat: 'chat',
@@ -23,7 +23,6 @@ export default {
23
23
  signedOut: 'Not logged in',
24
24
  signedOutDetail: 'Not logged in. Log in to see limits.',
25
25
  logIn: 'Log in',
26
- nextReset: '{{window}} resets {{at}}',
27
26
  checked: {
28
27
  now: 'now',
29
28
  ago: '{{duration}} ago',
@@ -122,7 +122,9 @@ export default {
122
122
  },
123
123
  message: {
124
124
  heading: 'Bericht van {{name}}',
125
- unnamed: 'een andere node'
125
+ unnamed: 'een andere node',
126
+ waiting: 'Wacht op de volgende beurt',
127
+ dropped: 'Vervallen voordat de agent het las'
126
128
  },
127
129
  report: {
128
130
  heading: 'Rapport'
@@ -368,6 +370,7 @@ export default {
368
370
  canvas: 'Op dit canvas',
369
371
  views: 'Views',
370
372
  noMatch: 'Geen view of node gevonden',
373
+ currentProject: 'Dit project',
371
374
  kinds: {
372
375
  canvas: 'canvas',
373
376
  chat: 'chat',
@@ -23,7 +23,6 @@ export default {
23
23
  signedOut: 'Niet ingelogd',
24
24
  signedOutDetail: 'Niet ingelogd. Log in om limieten te zien.',
25
25
  logIn: 'Inloggen',
26
- nextReset: '{{window}} reset {{at}}',
27
26
  checked: {
28
27
  now: 'nu',
29
28
  ago: '{{duration}} geleden',
@@ -2,13 +2,29 @@ import { Fragment } from 'react';
2
2
  import clsx from 'clsx';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import type { UsageLimitsSnapshot, UsageWindow } from '@adecore/agent-contracts';
5
+ import { ChevronRight } from 'lucide-react';
5
6
  import { limitsAccountId } from '../agents/account-limits';
6
- import { AccountDot } from '../agents/AccountDot';
7
- import { Tooltip } from '@adecore/ui';
7
+ import { accountColor } from '../agents/accounts';
8
+ import { ProviderLogo } from '../agents/ProviderLogo';
9
+ import { Icon, Tooltip } from '@adecore/ui';
8
10
  import { formatClock, formatWeekdayClock, isSameDay, formatCountdown, formatPercent } from '@adecore/ui/format';
11
+ import { useChatHost } from '../host';
9
12
  import { ChartLogo } from './ChartLogo';
10
- import { PROVIDER_LABELS } from './format';
11
- import { accountNote, evenPace, explain, isSignedOut, nextReset, paceText, type LimitAccount, type LimitGroup, type PaceStanding } from './limit-groups';
13
+ import { PROVIDER_COLORS, PROVIDER_LABELS } from './format';
14
+ import {
15
+ accountNote,
16
+ emptyWindows,
17
+ evenPace,
18
+ explain,
19
+ isSignedOut,
20
+ limitAccountKey,
21
+ noteIsWarning,
22
+ paceText,
23
+ ringWindows,
24
+ type LimitAccount,
25
+ type LimitGroup,
26
+ type PaceStanding
27
+ } from './limit-groups';
12
28
 
13
29
  /* Red where a window is nearly spent, amber where it is worth knowing; room to spare is not news and takes the text color. */
14
30
  function toneOf(used: number): string {
@@ -50,7 +66,7 @@ export function WindowBar({ window, now, compact }: { window: UsageWindow; now:
50
66
  aria-valuemax={100}
51
67
  className={clsx('relative cursor-default', compact ? 'h-4' : 'h-6')}
52
68
  >
53
- <div className={clsx('absolute inset-x-0 rounded-full bg-surface-sunken', compact ? 'inset-y-1' : 'inset-y-1.5')} />
69
+ <div className={clsx('absolute inset-x-0 rounded-full bg-track', compact ? 'inset-y-1' : 'inset-y-1.5')} />
54
70
  {/* Past a hundred there is nothing left to fill, so the bar stops rather than overflows. */}
55
71
  <div
56
72
  className={clsx('absolute left-0 rounded-full', compact ? 'inset-y-1' : 'inset-y-1.5', toneOf(window.used))}
@@ -121,7 +137,7 @@ export function LimitsList({ limits, now, compact = false }: LimitsListProps) {
121
137
  <p className="flex items-center gap-2 text-xs font-medium">
122
138
  <ChartLogo provider={provider.kind} />
123
139
  {PROVIDER_LABELS[provider.kind]}
124
- {provider.plan !== null && <span className="text-text-muted">· {provider.plan}</span>}
140
+ {provider.plan !== null && <span className="text-text-muted capitalize">· {provider.plan}</span>}
125
141
  </p>
126
142
  {note === null ? (
127
143
  <div className={clsx('flex flex-col', compact ? 'gap-3' : 'gap-4')}>
@@ -139,15 +155,28 @@ export function LimitsList({ limits, now, compact = false }: LimitsListProps) {
139
155
  );
140
156
  }
141
157
 
142
- /* One window on one line, for a card that holds several accounts: the label, a thin bar with the elapsed mark, the percent. */
158
+ /* Red where a window is nearly spent, amber where it is worth knowing, in the color of a word. */
159
+ function textToneOf(used: number): string {
160
+ return used >= 0.9 ? 'text-status-error' : used >= 0.7 ? 'text-status-needs-you' : 'text-text';
161
+ }
162
+
163
+ function strokeToneOf(used: number): string {
164
+ return used >= 0.9 ? 'stroke-status-error' : used >= 0.7 ? 'stroke-status-needs-you' : 'stroke-text';
165
+ }
166
+
167
+ const WINDOW_LINE = 'grid grid-cols-[104px_minmax(0,1fr)_34px_50px] items-center gap-x-2';
168
+ const RING_RADII = [8.75, 5.25, 1.75];
169
+
170
+ /* One window on one line: the label, a thin bar with the elapsed mark, the percent, the time left. Fixed columns, so the bars of every account line up. */
143
171
  function WindowLine({ window, now }: { window: UsageWindow; now: number }) {
144
172
  const { t } = useTranslation('agent-usage');
145
173
  const percent = Math.round(window.used * 100);
146
174
  const mark = evenPace(window, now)?.percent ?? null;
175
+ const resetsIn = window.resetsAt === null ? null : resetInLabel(window.resetsAt, now);
147
176
 
148
177
  return (
149
- <>
150
- <span className="text-text-muted">{window.label}</span>
178
+ <div className={WINDOW_LINE}>
179
+ <span className="truncate text-text-muted">{window.label}</span>
151
180
  <div
152
181
  role="progressbar"
153
182
  aria-label={t('limits.bar', { window: window.label, percent })}
@@ -155,7 +184,7 @@ function WindowLine({ window, now }: { window: UsageWindow; now: number }) {
155
184
  aria-valuetext={paceText(window, now)}
156
185
  aria-valuemin={0}
157
186
  aria-valuemax={100}
158
- className="relative h-1.5 rounded-full bg-surface-sunken"
187
+ className="relative h-1.5 rounded-full bg-track"
159
188
  >
160
189
  <div className={clsx('absolute inset-y-0 left-0 rounded-full', toneOf(window.used))} style={{ width: `${Math.min(100, percent)}%` }} />
161
190
  {mark !== null && (
@@ -167,62 +196,162 @@ function WindowLine({ window, now }: { window: UsageWindow; now: number }) {
167
196
  />
168
197
  )}
169
198
  </div>
170
- <span className={clsx('text-right tabular-nums', window.used >= 0.9 ? 'text-status-error' : 'text-text')}>{formatPercent(percent)}</span>
171
- </>
199
+ <span className={clsx('text-right tabular-nums', textToneOf(window.used))}>{formatPercent(percent)}</span>
200
+ <span className="text-right whitespace-nowrap text-text-faint tabular-nums">{resetsIn ?? '-'}</span>
201
+ </div>
202
+ );
203
+ }
204
+
205
+ /* A window this account has not reported on: no number to draw, so an empty bar and a dash. */
206
+ function EmptyWindowLine({ label }: { label: string }) {
207
+ return (
208
+ <div className={WINDOW_LINE}>
209
+ <span className="truncate text-text-muted">{label}</span>
210
+ <div className="h-1.5 rounded-full bg-track" />
211
+ <span className="text-right text-text-faint">-</span>
212
+ <span className="text-right text-text-faint">-</span>
213
+ </div>
172
214
  );
173
215
  }
174
216
 
175
- function AccountLines({ account, now }: { account: LimitAccount; now: number }) {
217
+ /* A ring per window, what a folded account keeps of its bars. The largest is the first window. */
218
+ function WindowRings({ windows, empty }: { windows: readonly UsageWindow[]; empty: boolean }) {
176
219
  const { t } = useTranslation('agent-usage');
177
- const signedOut = isSignedOut(account);
178
- const note = signedOut ? null : accountNote(account);
179
- const windows = signedOut || note !== null ? [] : (account.entry?.windows ?? []);
180
- const next = nextReset(windows, now);
181
- const resetsIn = next === null ? null : resetInLabel(next.resetsAt, now);
220
+ const rings = ringWindows(windows);
221
+ const label = rings.map((window) => t('limits.bar', { window: window.label, percent: Math.round(window.used * 100) })).join(', ');
182
222
 
183
223
  return (
184
- <>
185
- <p className="col-span-full mt-2 flex min-w-0 items-center gap-2">
186
- <AccountDot color={account.color} />
187
- <span className="truncate">{account.name}</span>
188
- {signedOut ? (
189
- <span className="shrink-0 text-text-faint">· {t('limits.signedOut')}</span>
190
- ) : (
191
- account.entry?.plan && <span className="shrink-0 text-text-muted">· {account.entry.plan}</span>
192
- )}
224
+ <svg
225
+ viewBox="0 0 20 20"
226
+ width="20"
227
+ height="20"
228
+ fill="none"
229
+ strokeWidth="2.5"
230
+ role={empty ? undefined : 'img'}
231
+ aria-hidden={empty ? true : undefined}
232
+ aria-label={empty ? undefined : label}
233
+ className={clsx('ml-auto shrink-0', empty && 'opacity-50')}
234
+ >
235
+ {rings.map((window, index) => {
236
+ const radius = RING_RADII[index] ?? 0;
237
+ const circumference = 2 * Math.PI * radius;
238
+
239
+ return (
240
+ <Fragment key={window.id}>
241
+ <circle cx="10" cy="10" r={radius} className="stroke-track" />
242
+ {!empty && (
243
+ <circle
244
+ cx="10"
245
+ cy="10"
246
+ r={radius}
247
+ strokeDasharray={`${Math.min(1, window.used) * circumference} ${circumference}`}
248
+ transform="rotate(-90 10 10)"
249
+ className={strokeToneOf(window.used)}
250
+ />
251
+ )}
252
+ </Fragment>
253
+ );
254
+ })}
255
+ </svg>
256
+ );
257
+ }
258
+
259
+ function AccountLogo({ account, className }: { account: LimitAccount; className?: string }) {
260
+ const { accents } = useChatHost();
261
+
262
+ return (
263
+ <span className={className} style={{ color: accountColor(account.color, accents.all) ?? PROVIDER_COLORS[account.kind] }}>
264
+ <ProviderLogo provider={account.kind} />
265
+ </span>
266
+ );
267
+ }
268
+
269
+ interface AccountRowProps {
270
+ group: LimitGroup;
271
+ account: LimitAccount;
272
+ now: number;
273
+ folded: boolean;
274
+ onToggle: () => void;
275
+ }
276
+
277
+ /* One account: a row that folds its windows away, or only a row with the words for why it has none. */
278
+ function AccountRow({ group, account, now, folded, onToggle }: AccountRowProps) {
279
+ const { t } = useTranslation('agent-usage');
280
+ const empty = emptyWindows(group, account);
281
+ const note = isSignedOut(account) ? t('limits.signedOut') : accountNote(account);
282
+
283
+ if (note !== null && empty.length === 0) {
284
+ return (
285
+ <p className="flex min-h-7 min-w-0 items-center gap-2 px-1.5">
286
+ <AccountLogo account={account} className="grid size-3.5 shrink-0" />
287
+ <span className="max-w-1/2 shrink-0 truncate font-medium">{account.name}</span>
288
+ <span className={clsx('ml-auto min-w-0 text-right', noteIsWarning(account) ? 'text-status-needs-you' : 'text-text-faint')}>{note}</span>
193
289
  </p>
194
- {note !== null && <p className="col-span-full text-text-faint">{note}</p>}
195
- {windows.map((window) => (
196
- <WindowLine key={window.id} window={window} now={now} />
197
- ))}
198
- {next !== null && (
199
- <p className="col-span-full whitespace-nowrap text-text-faint">
200
- {t('limits.nextReset', { window: next.label, at: resetAtLabel(next.resetsAt, now) })}
201
- {resetsIn !== null && ` · ${resetsIn}`}
202
- </p>
290
+ );
291
+ }
292
+
293
+ const windows = empty.length > 0 ? empty : (account.entry?.windows ?? []);
294
+
295
+ return (
296
+ <div className="flex flex-col">
297
+ <button
298
+ type="button"
299
+ aria-expanded={!folded}
300
+ className="group flex min-h-7 w-full min-w-0 items-center gap-2 rounded-md px-1.5 text-left hover:bg-surface-hover focus-visible:bg-surface-hover"
301
+ onClick={onToggle}
302
+ >
303
+ <span className="grid size-3.5 shrink-0">
304
+ <AccountLogo account={account} className="grid group-hover:hidden group-focus-visible:hidden" />
305
+ <Icon
306
+ icon={ChevronRight}
307
+ size={14}
308
+ className={clsx('hidden text-text-muted group-hover:block group-focus-visible:block', !folded && 'rotate-90')}
309
+ />
310
+ </span>
311
+ <span className="min-w-0 truncate font-medium">{account.name}</span>
312
+ {account.entry?.plan && <span className="shrink-0 text-text-muted capitalize">{account.entry.plan}</span>}
313
+ {folded && <WindowRings windows={windows} empty={empty.length > 0} />}
314
+ </button>
315
+ {!folded && (
316
+ <div className="flex flex-col gap-0.75 pt-0.5 pr-1.5 pb-2 pl-7">
317
+ {empty.length > 0
318
+ ? empty.map((window) => <EmptyWindowLine key={window.id} label={window.label} />)
319
+ : windows.map((window) => <WindowLine key={window.id} window={window} now={now} />)}
320
+ </div>
203
321
  )}
204
- </>
322
+ </div>
205
323
  );
206
324
  }
207
325
 
208
- /*
209
- * The hover card once a CLI has several accounts: a block per account, a line per window. One grid over
210
- * the whole card, so the bars of every account start and end at the same place whatever their labels.
211
- */
212
- export function AccountLimitsList({ groups, now }: { groups: readonly LimitGroup[]; now: number }) {
326
+ interface AccountLimitsListProps {
327
+ groups: readonly LimitGroup[];
328
+ now: number;
329
+ /* The accounts folded to their row, by `limitAccountKey`; held by the caller, so they stay folded when the list is drawn again. */
330
+ folded: ReadonlySet<string>;
331
+ onFoldedChange: (folded: ReadonlySet<string>) => void;
332
+ }
333
+
334
+ /* A flat list of accounts for a hover card, whichever CLI they belong to; the logo says which. */
335
+ export function AccountLimitsList({ groups, now, folded, onFoldedChange }: AccountLimitsListProps) {
336
+ const toggle = (key: string) => {
337
+ const next = new Set(folded);
338
+
339
+ if (!next.delete(key)) {
340
+ next.add(key);
341
+ }
342
+
343
+ onFoldedChange(next);
344
+ };
345
+
213
346
  return (
214
- <div className="grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-2 gap-y-1 text-xs">
215
- {groups.map((group) => (
216
- <Fragment key={group.kind}>
217
- <p className="col-span-full mt-3 flex items-center gap-2 font-medium first:mt-0">
218
- <ChartLogo provider={group.kind} />
219
- {PROVIDER_LABELS[group.kind]}
220
- </p>
221
- {group.accounts.map((account) => (
222
- <AccountLines key={account.id} account={account} now={now} />
223
- ))}
224
- </Fragment>
225
- ))}
347
+ <div className="flex flex-col gap-0.5 text-xs">
348
+ {groups.flatMap((group) =>
349
+ group.accounts.map((account) => {
350
+ const key = limitAccountKey(account);
351
+
352
+ return <AccountRow key={key} group={group} account={account} now={now} folded={folded.has(key)} onToggle={() => toggle(key)} />;
353
+ })
354
+ )}
226
355
  </div>
227
356
  );
228
357
  }
@@ -127,7 +127,7 @@ function ProjectRow({ project, top, money }: { project: UsageProject; top: numbe
127
127
  <span className="truncate">{look?.name ?? project.name}</span>
128
128
  <span className="truncate text-text-faint">{shortPath(project.folder)}</span>
129
129
  </span>
130
- <span className="mt-1 flex h-[9px] w-32 shrink-0 overflow-hidden rounded-full bg-surface-sunken">
130
+ <span className="mt-1 flex h-[9px] w-32 shrink-0 overflow-hidden rounded-full bg-track">
131
131
  {USAGE_PROVIDERS.map((provider) => {
132
132
  const share = project.byProvider[provider];
133
133
  const width = barWidth(share?.costUsd ?? 0, top);
@@ -69,7 +69,7 @@ function LimitCard({ account, named, now, login }: { account: LimitAccount; name
69
69
  <span className="truncate">{account.name}</span>
70
70
  </>
71
71
  )}
72
- {plan && <span className="shrink-0 font-normal text-text-muted">· {plan}</span>}
72
+ {plan && <span className="shrink-0 font-normal text-text-muted capitalize">· {plan}</span>}
73
73
  {checked !== null && <span className="ml-auto shrink-0 pl-2 font-normal text-text-faint">{checked}</span>}
74
74
  </p>
75
75
  {signedOut ? (
@@ -1,23 +1,26 @@
1
1
  import i18next from 'i18next';
2
2
  import { useState, type ReactElement } from 'react';
3
- import { hasSeveralAccounts } from './limit-groups';
4
- import { AccountLimitsList, LimitsList } from './LimitsList';
3
+ import { AccountLimitsList } from './LimitsList';
5
4
  import { useLimitGroups, useUsageLimits } from './limits';
6
5
  import { useNow, PreviewCard } from '@adecore/ui';
7
6
 
8
7
  const MINUTE_MS = 60_000;
9
8
 
10
9
  /* Asking the CLIs starts a process each, so the question waits until the card is actually opened. */
11
- function CardBody() {
10
+ function CardBody({ folded, onFoldedChange }: { folded: ReadonlySet<string>; onFoldedChange: (folded: ReadonlySet<string>) => void }) {
12
11
  const limits = useUsageLimits();
13
12
  const groups = useLimitGroups(limits);
14
13
  const now = useNow(MINUTE_MS);
15
14
 
16
15
  if (limits === null) {
17
- return <p className="text-xs text-text-faint">{i18next.t('agent-usage:limits.loading')}</p>;
16
+ return <p className="px-1.5 py-1 text-xs text-text-faint">{i18next.t('agent-usage:limits.loading')}</p>;
18
17
  }
19
18
 
20
- return hasSeveralAccounts(groups) ? <AccountLimitsList groups={groups} now={now} /> : <LimitsList limits={limits} now={now} compact />;
19
+ if (groups.length === 0) {
20
+ return <p className="px-1.5 py-1 text-xs text-text-faint">{i18next.t('agent-usage:limits.none')}</p>;
21
+ }
22
+
23
+ return <AccountLimitsList groups={groups} now={now} folded={folded} onFoldedChange={onFoldedChange} />;
21
24
  }
22
25
 
23
26
  /*
@@ -26,12 +29,13 @@ function CardBody() {
26
29
  */
27
30
  export function UsageLimitsCard({ children }: { children: ReactElement<Record<string, unknown>> }) {
28
31
  const [opened, setOpened] = useState(false);
32
+ const [folded, setFolded] = useState<ReadonlySet<string>>(new Set());
29
33
 
30
34
  return (
31
35
  <PreviewCard.Root onOpenChange={(open) => open && setOpened(true)}>
32
36
  <PreviewCard.Trigger render={children} delay={500} />
33
- <PreviewCard.Popup side="top" align="end" className="w-64 p-3">
34
- {opened && <CardBody />}
37
+ <PreviewCard.Popup side="top" align="end" className="w-85 p-2">
38
+ {opened && <CardBody folded={folded} onFoldedChange={setFolded} />}
35
39
  </PreviewCard.Popup>
36
40
  </PreviewCard.Root>
37
41
  );
@@ -104,17 +104,34 @@ export function isSignedOut(account: LimitAccount): boolean {
104
104
  return account.status?.state === 'signed-out';
105
105
  }
106
106
 
107
- /* The window that resets first from now, the one reset a line per window has no room to repeat. */
108
- export function nextReset(windows: readonly UsageWindow[], now: number): (UsageWindow & { resetsAt: number }) | null {
109
- let next: (UsageWindow & { resetsAt: number }) | null = null;
107
+ /* An account in a list across CLIs, where two CLIs may name an account alike. */
108
+ export function limitAccountKey(account: LimitAccount): string {
109
+ return `${account.kind}:${account.id}`;
110
+ }
110
111
 
111
- for (const window of windows) {
112
- if (window.resetsAt !== null && window.resetsAt > now && (next === null || window.resetsAt < next.resetsAt)) {
113
- next = { ...window, resetsAt: window.resetsAt };
114
- }
112
+ /* Whether an account's words are a problem to solve, rather than how the account simply is. */
113
+ export function noteIsWarning(account: LimitAccount): boolean {
114
+ return isSignedOut(account) || account.entry?.unavailable?.reason === 'failed';
115
+ }
116
+
117
+ /* The windows a signed-in account with no numbers yet will have, as far as another account of its CLI shows them. */
118
+ export function emptyWindows(group: LimitGroup, account: LimitAccount): readonly UsageWindow[] {
119
+ if (isSignedOut(account) || account.entry === null || account.entry.unavailable !== null || account.entry.windows.length > 0) {
120
+ return [];
115
121
  }
116
122
 
117
- return next;
123
+ return group.accounts.find((other) => (other.entry?.windows.length ?? 0) > 0)?.entry?.windows ?? [];
124
+ }
125
+
126
+ /* The windows a folded account draws a ring for. Three fit; past that the ones nearest their limit. */
127
+ export function ringWindows(windows: readonly UsageWindow[]): readonly UsageWindow[] {
128
+ if (windows.length <= 3) {
129
+ return windows;
130
+ }
131
+
132
+ const fullest = [...windows].sort((a, b) => b.used - a.used).slice(0, 3);
133
+
134
+ return windows.filter((window) => fullest.includes(window));
118
135
  }
119
136
 
120
137
  /* The bar as words for whoever cannot see the mark: how much is used and how that stands against an even pace. */