@adecore/agents-react 0.54.1 → 0.54.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.
@@ -1323,7 +1323,7 @@ function ContextUsage(t0) {
1323
1323
  } else {
1324
1324
  t6 = $[17];
1325
1325
  }
1326
- const t7 = disabled || usage.contextTokens === 0;
1326
+ const t7 = disabled || usage.contextTokens === 0 || usage.turns === 0;
1327
1327
  let t8;
1328
1328
  if ($[18] !== t) {
1329
1329
  t8 = t("contextMeter.compactNow");
@@ -1,4 +1,4 @@
1
- import type { UsageLimitsSnapshot, UsageSummaryPayload, UsageSummaryResult } from '@adecore/agent-contracts';
1
+ import { type UsageLimitsSnapshot, type UsageRate, type UsageSummaryPayload, type UsageSummaryResult } from '@adecore/agent-contracts';
2
2
  import type { UsageCurrency } from '../usage/format.js';
3
3
  export type UsagePeriod = 'today' | '7d' | '30d' | '90d';
4
4
  export type UsageMetric = 'cost' | 'tokens';
@@ -11,6 +11,7 @@ interface Preferences {
11
11
  period: UsagePeriod;
12
12
  metric: UsageMetric;
13
13
  currency: UsageCurrency;
14
+ rate: UsageRate | null;
14
15
  }
15
16
  export declare function dayOf(date: Date): string;
16
17
  export declare function windowFor(period: UsagePeriod, now?: Date): UsageSummaryPayload;
@@ -1,4 +1,5 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
+ import { UsageRateSchema } from '@adecore/agent-contracts';
2
3
  import { localTimeZone } from '@adecore/ui/format';
3
4
  import { persistedJson } from '../chat/persisted-json.js';
4
5
  import { useChatScope } from '../scope.js';
@@ -25,7 +26,8 @@ onChatStorageConfiguration(() => {
25
26
  const DEFAULTS = {
26
27
  period: '7d',
27
28
  metric: 'cost',
28
- currency: 'USD'
29
+ currency: 'USD',
30
+ rate: null
29
31
  };
30
32
  function parsePreferences(raw) {
31
33
  try {
@@ -33,19 +35,21 @@ function parsePreferences(raw) {
33
35
  return {
34
36
  period: USAGE_PERIODS.some(period => period.id === stored.period) ? stored.period : DEFAULTS.period,
35
37
  metric: stored.metric === 'tokens' || stored.metric === 'cost' ? stored.metric : DEFAULTS.metric,
36
- currency: stored.currency === 'EUR' ? 'EUR' : DEFAULTS.currency
38
+ currency: stored.currency === 'EUR' ? 'EUR' : DEFAULTS.currency,
39
+ rate: UsageRateSchema.safeParse(stored.rate).data ?? DEFAULTS.rate
37
40
  };
38
41
  } catch {
39
42
  return DEFAULTS;
40
43
  }
41
44
  }
42
45
  const storage = persistedJson(storageKey, parsePreferences, DEFAULTS, () => chatStorageLegacyKeys('usage'));
43
- /* The three stored choices out of the store, so a setter writes the other two back unchanged. */
46
+ /* What is stored, out of the store, so a setter writes the rest back unchanged. */
44
47
  function chosen(state) {
45
48
  return {
46
49
  period: state.period,
47
50
  metric: state.metric,
48
- currency: state.currency
51
+ currency: state.currency,
52
+ rate: state.rate
49
53
  };
50
54
  }
51
55
  function pad(value) {
@@ -144,6 +148,11 @@ export const useUsageStore = createChatStore((set, get) => {
144
148
  loading: false,
145
149
  failed: false
146
150
  });
151
+ if (summary.rate !== null && JSON.stringify(summary.rate) !== JSON.stringify(get().rate)) {
152
+ choosePreference({
153
+ rate: summary.rate
154
+ });
155
+ }
147
156
  },
148
157
  fail(scopeId) {
149
158
  patchRow(scopeId, {
@@ -178,6 +187,7 @@ export function useUsage(select) {
178
187
  period: s.period,
179
188
  metric: s.metric,
180
189
  currency: s.currency,
190
+ rate: s.rate,
181
191
  ...(s.byScope[id] ?? EMPTY)
182
192
  });
183
193
  $[0] = id;
@@ -169,7 +169,7 @@ function _temp3(id_0) {
169
169
  return useUsageStore.getState().setCurrency(id_0);
170
170
  }
171
171
  function _temp2(s_0) {
172
- return s_0.summary?.rate ?? null;
172
+ return s_0.summary?.rate ?? s_0.rate;
173
173
  }
174
174
  function _temp(s) {
175
175
  return s.currency;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/agents-react",
3
- "version": "0.54.1",
3
+ "version": "0.54.2",
4
4
  "description": "React agent chat threads, composers, approvals, provider accounts and usage views.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -72,12 +72,12 @@
72
72
  "test:visuals": "bun --config=integration.bunfig.toml --conditions=source test ./src/chat/visual-viewport.integration.test.ts"
73
73
  },
74
74
  "dependencies": {
75
- "@adecore/agent-contracts": "0.54.1",
76
- "@adecore/editor": "0.54.1",
77
- "@adecore/editor-react": "0.54.1",
78
- "@adecore/intelligent-ui": "0.54.1",
79
- "@adecore/merge": "0.54.1",
80
- "@adecore/utils": "0.54.1",
75
+ "@adecore/agent-contracts": "0.54.2",
76
+ "@adecore/editor": "0.54.2",
77
+ "@adecore/editor-react": "0.54.2",
78
+ "@adecore/intelligent-ui": "0.54.2",
79
+ "@adecore/merge": "0.54.2",
80
+ "@adecore/utils": "0.54.2",
81
81
  "@codemirror/commands": "^6.11.1",
82
82
  "@codemirror/language": "^6.13.1",
83
83
  "@codemirror/state": "^6.7.6",
@@ -101,14 +101,14 @@
101
101
  "zustand": "^5.0.16"
102
102
  },
103
103
  "peerDependencies": {
104
- "@adecore/ui": "^0.54.1",
104
+ "@adecore/ui": "^0.54.2",
105
105
  "i18next": "^26.4.2",
106
106
  "react": "^19.3.0",
107
107
  "react-dom": "^19.3.0",
108
108
  "react-i18next": "^17.0.15"
109
109
  },
110
110
  "devDependencies": {
111
- "@adecore/ui": "0.54.1",
111
+ "@adecore/ui": "0.54.2",
112
112
  "@types/bun": "^1.4.4",
113
113
  "@types/react": "^19.3.0",
114
114
  "@types/react-dom": "^19.3.0",
@@ -638,7 +638,8 @@ function ContextUsage({ usage, disabled, onCompact }: { usage: ChatUsage; disabl
638
638
  <Menu.Item
639
639
  unstyled
640
640
  className="flex shrink-0 cursor-default items-center gap-0.5 rounded font-medium text-accent outline-none data-disabled:opacity-50 data-highlighted:underline"
641
- disabled={disabled || usage.contextTokens === 0}
641
+ // A CLI can report the system prompt before any turn, which leaves nothing of the conversation to compact.
642
+ disabled={disabled || usage.contextTokens === 0 || usage.turns === 0}
642
643
  onClick={onCompact}
643
644
  >
644
645
  {t('contextMeter.compactNow')}
@@ -1,4 +1,4 @@
1
- import type { UsageLimitsSnapshot, UsageSummaryPayload, UsageSummaryResult } from '@adecore/agent-contracts';
1
+ import { UsageRateSchema, type UsageLimitsSnapshot, type UsageRate, type UsageSummaryPayload, type UsageSummaryResult } from '@adecore/agent-contracts';
2
2
  import { localTimeZone } from '@adecore/ui/format';
3
3
  import { persistedJson } from '../chat/persisted-json';
4
4
  import { useChatScope } from '../scope';
@@ -29,9 +29,12 @@ interface Preferences {
29
29
  metric: UsageMetric;
30
30
  /* Dollars until someone asks for euros; it is the viewer's setting, not the project's. */
31
31
  currency: UsageCurrency;
32
+
33
+ /* The last exchange rate a summary brought, so the settings can name it before the page is opened again. */
34
+ rate: UsageRate | null;
32
35
  }
33
36
 
34
- const DEFAULTS: Preferences = { period: '7d', metric: 'cost', currency: 'USD' };
37
+ const DEFAULTS: Preferences = { period: '7d', metric: 'cost', currency: 'USD', rate: null };
35
38
 
36
39
  function parsePreferences(raw: string | null): Preferences {
37
40
  try {
@@ -40,7 +43,8 @@ function parsePreferences(raw: string | null): Preferences {
40
43
  return {
41
44
  period: USAGE_PERIODS.some((period) => period.id === stored.period) ? stored.period! : DEFAULTS.period,
42
45
  metric: stored.metric === 'tokens' || stored.metric === 'cost' ? stored.metric : DEFAULTS.metric,
43
- currency: stored.currency === 'EUR' ? 'EUR' : DEFAULTS.currency
46
+ currency: stored.currency === 'EUR' ? 'EUR' : DEFAULTS.currency,
47
+ rate: UsageRateSchema.safeParse(stored.rate).data ?? DEFAULTS.rate
44
48
  };
45
49
  } catch {
46
50
  return DEFAULTS;
@@ -49,9 +53,9 @@ function parsePreferences(raw: string | null): Preferences {
49
53
 
50
54
  const storage = persistedJson(storageKey, parsePreferences, DEFAULTS, () => chatStorageLegacyKeys('usage'));
51
55
 
52
- /* The three stored choices out of the store, so a setter writes the other two back unchanged. */
56
+ /* What is stored, out of the store, so a setter writes the rest back unchanged. */
53
57
  function chosen(state: Preferences): Preferences {
54
- return { period: state.period, metric: state.metric, currency: state.currency };
58
+ return { period: state.period, metric: state.metric, currency: state.currency, rate: state.rate };
55
59
  }
56
60
 
57
61
  function pad(value: number): string {
@@ -158,6 +162,10 @@ export const useUsageStore = createChatStore<UsageStore>(
158
162
  },
159
163
  receive(scopeId, asked, summary) {
160
164
  patchRow(scopeId, { asked, summary, loading: false, failed: false });
165
+
166
+ if (summary.rate !== null && JSON.stringify(summary.rate) !== JSON.stringify(get().rate)) {
167
+ choosePreference({ rate: summary.rate });
168
+ }
161
169
  },
162
170
  fail(scopeId) {
163
171
  patchRow(scopeId, { loading: false, failed: true });
@@ -183,5 +191,5 @@ export type UsageView = Preferences & UsageRow;
183
191
  export function useUsage<T>(select: (view: UsageView) => T): T {
184
192
  const { id } = useChatScope();
185
193
 
186
- return useUsageStore((s) => select({ period: s.period, metric: s.metric, currency: s.currency, ...(s.byScope[id] ?? EMPTY) }));
194
+ return useUsageStore((s) => select({ period: s.period, metric: s.metric, currency: s.currency, rate: s.rate, ...(s.byScope[id] ?? EMPTY) }));
187
195
  }
@@ -14,7 +14,8 @@ const CURRENCIES: readonly UsageCurrency[] = ['USD', 'EUR'];
14
14
  export function UsagePane({ onOpenPage }: { onOpenPage(): void }) {
15
15
  const { t } = useTranslation('agent-usage');
16
16
  const currency = useUsage((s) => s.currency);
17
- const rate = useUsage((s) => s.summary?.rate ?? null);
17
+ // The summary on screen, or the rate the last one brought: the page may not have been opened since this window started.
18
+ const rate = useUsage((s) => s.summary?.rate ?? s.rate);
18
19
 
19
20
  return (
20
21
  <SettingsSection>