@adecore/agents-react 0.55.1 → 0.55.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 (53) hide show
  1. package/dist/agents/account-limits.js +5 -2
  2. package/dist/chat/logic/resume-compaction.js +2 -2
  3. package/dist/chat/logic/timeline.d.ts +1 -0
  4. package/dist/chat/logic/timeline.js +4 -1
  5. package/dist/chat/ui/RunSettings.js +63 -58
  6. package/dist/chat/ui/index.d.ts +1 -1
  7. package/dist/chat/ui/intelligent-ui/UiBlockFrame.js +130 -121
  8. package/dist/chat/ui/intelligent-ui/UiReply.js +28 -9
  9. package/dist/chat/ui/intelligent-ui/render-context.d.ts +2 -0
  10. package/dist/chat/ui/intelligent-ui/renderers/data.js +124 -94
  11. package/dist/chat/ui/intelligent-ui/use-ui-queries.d.ts +8 -2
  12. package/dist/chat/ui/intelligent-ui/use-ui-queries.js +162 -74
  13. package/dist/chat/ui/rows/MessageRows.d.ts +2 -1
  14. package/dist/chat/ui/rows/MessageRows.js +48 -40
  15. package/dist/chat/ui/rows/Rows.js +32 -30
  16. package/dist/locales/en/agent-chat.d.ts +3 -0
  17. package/dist/locales/en/agent-chat.js +3 -0
  18. package/dist/locales/en/agent-usage.d.ts +10 -0
  19. package/dist/locales/en/agent-usage.js +10 -0
  20. package/dist/locales/nl/agent-chat.d.ts +3 -0
  21. package/dist/locales/nl/agent-chat.js +3 -0
  22. package/dist/locales/nl/agent-usage.d.ts +10 -0
  23. package/dist/locales/nl/agent-usage.js +10 -0
  24. package/dist/theme.css +9 -4
  25. package/dist/usage/LimitProvenance.d.ts +5 -0
  26. package/dist/usage/LimitProvenance.js +104 -0
  27. package/dist/usage/LimitsList.js +153 -131
  28. package/dist/usage/UsageLimits.d.ts +1 -1
  29. package/dist/usage/UsageLimits.js +241 -158
  30. package/dist/usage/limit-groups.d.ts +2 -0
  31. package/dist/usage/limit-groups.js +12 -3
  32. package/package.json +9 -9
  33. package/src/agents/account-limits.ts +6 -2
  34. package/src/chat/logic/resume-compaction.ts +2 -2
  35. package/src/chat/logic/timeline.ts +7 -2
  36. package/src/chat/ui/RunSettings.tsx +9 -3
  37. package/src/chat/ui/index.ts +1 -0
  38. package/src/chat/ui/intelligent-ui/UiBlockFrame.tsx +5 -2
  39. package/src/chat/ui/intelligent-ui/UiReply.tsx +25 -6
  40. package/src/chat/ui/intelligent-ui/render-context.ts +5 -0
  41. package/src/chat/ui/intelligent-ui/renderers/data.tsx +58 -27
  42. package/src/chat/ui/intelligent-ui/use-ui-queries.ts +81 -61
  43. package/src/chat/ui/rows/MessageRows.tsx +11 -2
  44. package/src/chat/ui/rows/Rows.tsx +1 -1
  45. package/src/locales/en/agent-chat.ts +3 -0
  46. package/src/locales/en/agent-usage.ts +10 -0
  47. package/src/locales/nl/agent-chat.ts +3 -0
  48. package/src/locales/nl/agent-usage.ts +10 -0
  49. package/src/theme.css +9 -4
  50. package/src/usage/LimitProvenance.tsx +23 -0
  51. package/src/usage/LimitsList.tsx +10 -4
  52. package/src/usage/UsageLimits.tsx +88 -18
  53. package/src/usage/limit-groups.ts +16 -3
@@ -0,0 +1,23 @@
1
+ import type { UsageLimitsProvider } from '@adecore/agent-contracts';
2
+ import clsx from 'clsx';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { checkedAge, checkedLabel, showsWindows } from './limit-groups';
5
+
6
+ export function LimitProvenance({ entry, now }: { entry: UsageLimitsProvider; now: number }) {
7
+ const { t } = useTranslation('agent-usage');
8
+ const age = checkedAge(entry, now);
9
+ const when = checkedLabel(entry, now);
10
+ const retained = entry.unavailable?.reason === 'failed' && entry.windows.length > 0;
11
+
12
+ if (!showsWindows(entry)) {
13
+ return null;
14
+ }
15
+
16
+ return (
17
+ <p className={clsx('flex flex-wrap gap-x-2 text-xs', age !== null && age >= 600_000 ? 'text-status-needs-you' : 'text-text-muted')}>
18
+ {retained && <span>{t('limits.lastKnown')}</span>}
19
+ <span>{when === null ? t('limits.checked.unknown') : t('limits.checked.updated', { when })}</span>
20
+ {age !== null && age >= 600_000 && <span>{t('limits.checked.old')}</span>}
21
+ </p>
22
+ );
23
+ }
@@ -21,10 +21,12 @@ import {
21
21
  noteIsWarning,
22
22
  paceText,
23
23
  ringWindows,
24
+ showsWindows,
24
25
  type LimitAccount,
25
26
  type LimitGroup,
26
27
  type PaceStanding
27
28
  } from './limit-groups';
29
+ import { LimitProvenance } from './LimitProvenance';
28
30
 
29
31
  /* Red where a window is nearly spent, amber where it is worth knowing; room to spare is not news and takes the text color. */
30
32
  function toneOf(used: number): string {
@@ -139,14 +141,14 @@ export function LimitsList({ limits, now, compact = false }: LimitsListProps) {
139
141
  {PROVIDER_LABELS[provider.kind]}
140
142
  {provider.plan !== null && <span className="text-text-muted capitalize">· {provider.plan}</span>}
141
143
  </p>
142
- {note === null ? (
144
+ <LimitProvenance entry={provider} now={now} />
145
+ {note !== null && <p className="text-xs text-text-muted">{note}</p>}
146
+ {showsWindows(provider) && (
143
147
  <div className={clsx('flex flex-col', compact ? 'gap-3' : 'gap-4')}>
144
148
  {provider.windows.map((window) => (
145
149
  <WindowBar key={window.id} window={window} now={now} compact={compact} />
146
150
  ))}
147
151
  </div>
148
- ) : (
149
- <p className="text-xs text-text-faint">{note}</p>
150
152
  )}
151
153
  </div>
152
154
  );
@@ -280,7 +282,9 @@ function AccountRow({ group, account, now, folded, onToggle }: AccountRowProps)
280
282
  const empty = emptyWindows(group, account);
281
283
  const note = isSignedOut(account) ? t('limits.signedOut') : accountNote(account);
282
284
 
283
- if (note !== null && empty.length === 0) {
285
+ const retained = showsWindows(account.entry);
286
+
287
+ if (note !== null && empty.length === 0 && !retained) {
284
288
  return (
285
289
  <p className="flex min-h-7 min-w-0 items-center gap-2 px-1.5">
286
290
  <AccountLogo account={account} className="grid size-3.5 shrink-0" />
@@ -314,6 +318,8 @@ function AccountRow({ group, account, now, folded, onToggle }: AccountRowProps)
314
318
  </button>
315
319
  {!folded && (
316
320
  <div className="flex flex-col gap-0.75 pt-0.5 pr-1.5 pb-2 pl-7">
321
+ {retained && account.entry !== null && <LimitProvenance entry={account.entry} now={now} />}
322
+ {retained && note !== null && <p className="text-xs text-status-needs-you">{note}</p>}
317
323
  {empty.length > 0
318
324
  ? empty.map((window) => <EmptyWindowLine key={window.id} label={window.label} />)
319
325
  : windows.map((window) => <WindowLine key={window.id} window={window} now={now} />)}
@@ -1,16 +1,18 @@
1
- import type { UsageProvider } from '@adecore/agent-contracts';
1
+ import type { UsageLimitsSnapshot, UsageProvider } from '@adecore/agent-contracts';
2
2
  import { Button, Icon, SectionLabel, Segmented, Tooltip, useNow } from '@adecore/ui';
3
- import { LogIn } from 'lucide-react';
4
- import { useState } from 'react';
3
+ import { ListRestart, LogIn } from 'lucide-react';
4
+ import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { AccountDot } from '../agents/AccountDot';
7
7
  import { useChatHost } from '../host';
8
8
  import { useHostLoginBlocked } from '../host-hooks';
9
9
  import { useChatScope } from '../scope';
10
10
  import { useProviderAccounts } from '../state/provider-accounts';
11
+ import { useUsageStore } from '../state/usage';
11
12
  import { ChartLogo } from './ChartLogo';
12
13
  import { PROVIDER_LABELS } from './format';
13
- import { accountNote, checkedLabel, hasSeveralAccounts, isSignedOut, type LimitAccount } from './limit-groups';
14
+ import { accountNote, hasSeveralAccounts, isSignedOut, showsWindows, type LimitAccount } from './limit-groups';
15
+ import { LimitProvenance } from './LimitProvenance';
14
16
  import { useLimitGroups, useUsageLimits } from './limits';
15
17
  import { WindowBar } from './LimitsList';
16
18
 
@@ -55,7 +57,6 @@ function LimitCard({ account, named, now, login }: { account: LimitAccount; name
55
57
  const signedOut = isSignedOut(account);
56
58
  const note = signedOut ? null : accountNote(account);
57
59
  const plan = signedOut ? null : account.entry?.plan;
58
- const checked = signedOut || account.entry === null ? null : checkedLabel(account.entry, now);
59
60
 
60
61
  return (
61
62
  <div className="flex min-w-0 flex-col gap-3.5 rounded-xl border border-border bg-surface bg-clip-padding px-4 py-3.5">
@@ -70,21 +71,24 @@ function LimitCard({ account, named, now, login }: { account: LimitAccount; name
70
71
  </>
71
72
  )}
72
73
  {plan && <span className="shrink-0 font-normal text-text-muted capitalize">· {plan}</span>}
73
- {checked !== null && <span className="ml-auto shrink-0 pl-2 font-normal text-text-faint">{checked}</span>}
74
74
  </p>
75
+ {!signedOut && account.entry !== null && <LimitProvenance entry={account.entry} now={now} />}
75
76
  {signedOut ? (
76
77
  <>
77
78
  <p className="text-xs text-text-faint">{t('limits.signedOutDetail')}</p>
78
79
  {login !== null && <LoginButton account={account} login={login} />}
79
80
  </>
80
- ) : note !== null ? (
81
- <p className="text-xs text-text-faint">{note}</p>
82
81
  ) : (
83
- <div className="flex flex-col gap-4">
84
- {account.entry?.windows.map((window) => (
85
- <WindowBar key={window.id} window={window} now={now} compact={false} />
86
- ))}
87
- </div>
82
+ <>
83
+ {note !== null && <p className="text-xs text-text-muted">{note}</p>}
84
+ {showsWindows(account.entry) && (
85
+ <div className="flex flex-col gap-4">
86
+ {account.entry?.windows.map((window) => (
87
+ <WindowBar key={window.id} window={window} now={now} compact={false} />
88
+ ))}
89
+ </div>
90
+ )}
91
+ </>
88
92
  )}
89
93
  </div>
90
94
  );
@@ -106,10 +110,6 @@ export function UsageLimits() {
106
110
  const blocked = useHostLoginBlocked(scopeId);
107
111
  const [filter, setFilter] = useState<Filter>('all');
108
112
 
109
- if (limits === null) {
110
- return null;
111
- }
112
-
113
113
  const filterable = groups.length > 1 && hasSeveralAccounts(groups);
114
114
  const current = filterable && groups.some((group) => group.kind === filter) ? filter : 'all';
115
115
  const shown = current === 'all' ? groups : groups.filter((group) => group.kind === current);
@@ -125,6 +125,7 @@ export function UsageLimits() {
125
125
  <SectionLabel render={<h2 />} className="grow">
126
126
  {t('limits.title')}
127
127
  </SectionLabel>
128
+ <LimitsRefresh key={scopeId} limits={limits} />
128
129
  {filterable && (
129
130
  <Segmented<Filter>
130
131
  value={current}
@@ -138,7 +139,8 @@ export function UsageLimits() {
138
139
  )}
139
140
  </div>
140
141
  <p className="text-xs text-text-muted">{t('limits.explain')}</p>
141
- <div className="grid grid-cols-2 gap-3">
142
+ {limits === null && <p className="text-xs text-text-faint">{t('limits.notRead')}</p>}
143
+ <div className="grid grid-cols-2 gap-3 max-[640px]:grid-cols-1">
142
144
  {shown.flatMap((group) =>
143
145
  group.accounts.map((account) => (
144
146
  <LimitCard key={account.id} account={account} named={group.accounts.length > 1} now={now} login={loginFor(group.kind)} />
@@ -148,3 +150,71 @@ export function UsageLimits() {
148
150
  </section>
149
151
  );
150
152
  }
153
+
154
+ function LimitsRefresh({ limits }: { limits: UsageLimitsSnapshot | null }) {
155
+ const { t } = useTranslation('agent-usage');
156
+ const scope = useChatScope();
157
+ const [busy, setBusy] = useState(false);
158
+ const [failure, setFailure] = useState<{ snapshot: UsageLimitsSnapshot | null } | null>(null);
159
+ const pending = useRef(false);
160
+ const alive = useRef(true);
161
+ const answering = useSyncExternalStore(
162
+ (changed) => scope.transport.subscribeStatus(changed),
163
+ () => scope.transport.status === 'open',
164
+ () => false
165
+ );
166
+
167
+ useEffect(() => {
168
+ alive.current = true;
169
+
170
+ return () => {
171
+ alive.current = false;
172
+ };
173
+ }, []);
174
+
175
+ const read = async () => {
176
+ if (pending.current || scope.transport.status !== 'open') {
177
+ return;
178
+ }
179
+
180
+ pending.current = true;
181
+ setBusy(true);
182
+ setFailure(null);
183
+
184
+ try {
185
+ const snapshot = await scope.transport.request('usage.refreshLimits', {});
186
+
187
+ if (alive.current) {
188
+ useUsageStore.getState().setLimits(scope.id, snapshot);
189
+ }
190
+ } catch {
191
+ if (alive.current) {
192
+ setFailure({ snapshot: useUsageStore.getState().byScope[scope.id]?.limits ?? null });
193
+ }
194
+ } finally {
195
+ pending.current = false;
196
+
197
+ if (alive.current) {
198
+ setBusy(false);
199
+ }
200
+ }
201
+ };
202
+
203
+ return (
204
+ <div className="flex flex-col items-end gap-1">
205
+ <Tooltip label={answering ? t('limits.refreshHint') : t('limits.offline')}>
206
+ <span>
207
+ <Button size="sm" variant="secondary" disabled={!answering || busy} onClick={() => void read()}>
208
+ <Icon icon={ListRestart} size={14} />
209
+ {busy ? t('limits.reading') : t('limits.refresh')}
210
+ </Button>
211
+ </span>
212
+ </Tooltip>
213
+ {failure !== null && failure.snapshot === limits && (
214
+ <p role="alert" className="max-w-80 text-xs text-status-error">
215
+ {t('limits.refreshFailed')}
216
+ </p>
217
+ )}
218
+ </div>
219
+ );
220
+ }
@@ -144,13 +144,26 @@ export function paceText(window: UsageWindow, now: number): string {
144
144
  : i18next.t(`agent-usage:limits.pace.${pace.standing}`, { percent, pace: pace.percent });
145
145
  }
146
146
 
147
+ export function checkedAge(entry: UsageLimitsProvider, now: number): number | null {
148
+ if (!Number.isFinite(entry.checkedAt) || entry.checkedAt <= 0 || entry.checkedAt > now + MINUTE) {
149
+ return null;
150
+ }
151
+
152
+ return Math.max(0, now - entry.checkedAt);
153
+ }
154
+
155
+ export function showsWindows(entry: UsageLimitsProvider | null): boolean {
156
+ return entry !== null && entry.windows.length > 0 && (entry.unavailable === null || entry.unavailable.reason === 'failed');
157
+ }
158
+
147
159
  /* When the numbers came in and from where: a read of the machine's own, or a turn that reported them. Null before the first read. */
148
160
  export function checkedLabel(entry: UsageLimitsProvider, now: number): string | null {
149
- if (entry.checkedAt <= 0) {
161
+ const past = checkedAge(entry, now);
162
+
163
+ if (past === null) {
150
164
  return null;
151
165
  }
152
166
 
153
- const past = now - entry.checkedAt;
154
167
  const when = past < MINUTE ? i18next.t('agent-usage:limits.checked.now') : i18next.t('agent-usage:limits.checked.ago', { duration: formatDuration(past) });
155
168
 
156
169
  return entry.source === 'event' ? i18next.t('agent-usage:limits.checked.fromTurn', { when }) : when;
@@ -174,7 +187,7 @@ export function explain(provider: UsageLimitsProvider): string | null {
174
187
  return provider.unavailable.message ?? i18next.t('agent-usage:limits.unreachable');
175
188
  }
176
189
 
177
- /* Why an account has no bars, or null when it has them. An account the machine does not read says what its login is doing. */
190
+ /* The explanation for an account, including a failed read beside retained bars. An account the machine does not read says what its login is doing. */
178
191
  export function accountNote(account: LimitAccount): string | null {
179
192
  return account.entry === null ? accountStatusLine(account.status, true).text : explain(account.entry);
180
193
  }