@adecore/agents-react 0.54.0 → 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.
- package/dist/chat/ui/RunSettings.js +1 -1
- package/dist/state/usage.d.ts +2 -1
- package/dist/state/usage.js +14 -4
- package/dist/usage/UsagePage.js +2 -2
- package/dist/usage/UsagePane.js +3 -2
- package/dist/usage/format.d.ts +1 -0
- package/dist/usage/format.js +5 -0
- package/package.json +9 -9
- package/src/chat/ui/RunSettings.tsx +2 -1
- package/src/state/usage.ts +14 -6
- package/src/usage/UsagePage.tsx +3 -2
- package/src/usage/UsagePane.tsx +4 -3
- package/src/usage/format.ts +7 -0
|
@@ -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");
|
package/dist/state/usage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
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;
|
package/dist/state/usage.js
CHANGED
|
@@ -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
|
-
/*
|
|
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;
|
package/dist/usage/UsagePage.js
CHANGED
|
@@ -10,7 +10,7 @@ import { useChatScope } from '../scope.js';
|
|
|
10
10
|
import { useProvidersStore } from '../state/providers.js';
|
|
11
11
|
import { askedKey, summaryPayload, USAGE_PERIODS, useUsage, useUsageStore } from '../state/usage.js';
|
|
12
12
|
import { whenOpen } from '../transport.js';
|
|
13
|
-
import { formatClock, formatCount, formatDate, formatTokens, PROVIDER_LABELS } from './format.js';
|
|
13
|
+
import { formatClock, formatCount, formatDate, formatRateDate, formatTokens, PROVIDER_LABELS } from './format.js';
|
|
14
14
|
import { useMoney } from './money.js';
|
|
15
15
|
import { deriveUsage, labelEveryFor } from './summary.js';
|
|
16
16
|
import { UsageBreakdown } from './UsageBreakdown.js';
|
|
@@ -281,7 +281,7 @@ function Provenance() {
|
|
|
281
281
|
if ($[7] !== currency || $[8] !== summary.rate || $[9] !== t) {
|
|
282
282
|
t1 = currency === "USD" || summary.rate === null ? null : t("provenance.rate", {
|
|
283
283
|
currency: summary.rate.currency,
|
|
284
|
-
date: summary.rate.date
|
|
284
|
+
date: formatRateDate(summary.rate.date)
|
|
285
285
|
});
|
|
286
286
|
$[7] = currency;
|
|
287
287
|
$[8] = summary.rate;
|
package/dist/usage/UsagePane.js
CHANGED
|
@@ -4,6 +4,7 @@ import { SettingsRow, SettingsSection } from '@adecore/ui/settings';
|
|
|
4
4
|
import { ChartNoAxesColumn } from 'lucide-react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
import { useUsage, useUsageStore } from '../state/usage.js';
|
|
7
|
+
import { formatRateDate } from './format.js';
|
|
7
8
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
9
|
const CURRENCIES = ['USD', 'EUR'];
|
|
9
10
|
/*
|
|
@@ -31,7 +32,7 @@ export function UsagePane(t0) {
|
|
|
31
32
|
let t2;
|
|
32
33
|
if ($[2] !== currency || $[3] !== rate || $[4] !== t) {
|
|
33
34
|
t2 = currency === "USD" ? t("settings.currency.dollars") : rate === null ? t("settings.currency.noRate") : t("settings.currency.converted", {
|
|
34
|
-
date: rate.date
|
|
35
|
+
date: formatRateDate(rate.date)
|
|
35
36
|
});
|
|
36
37
|
$[2] = currency;
|
|
37
38
|
$[3] = rate;
|
|
@@ -168,7 +169,7 @@ function _temp3(id_0) {
|
|
|
168
169
|
return useUsageStore.getState().setCurrency(id_0);
|
|
169
170
|
}
|
|
170
171
|
function _temp2(s_0) {
|
|
171
|
-
return s_0.summary?.rate ??
|
|
172
|
+
return s_0.summary?.rate ?? s_0.rate;
|
|
172
173
|
}
|
|
173
174
|
function _temp(s) {
|
|
174
175
|
return s.currency;
|
package/dist/usage/format.d.ts
CHANGED
|
@@ -10,4 +10,5 @@ export declare const PROVIDER_COLORS: Record<UsageProvider, string>;
|
|
|
10
10
|
export declare function slotLabel(slot: string): string;
|
|
11
11
|
export declare function slotAxisLabel(slot: string): string;
|
|
12
12
|
export declare function formatDate(at: number): string;
|
|
13
|
+
export declare function formatRateDate(date: string): string;
|
|
13
14
|
export declare function shortPath(path: string): string;
|
package/dist/usage/format.js
CHANGED
|
@@ -62,6 +62,11 @@ export function slotAxisLabel(slot) {
|
|
|
62
62
|
export function formatDate(at) {
|
|
63
63
|
return formatDay(at);
|
|
64
64
|
}
|
|
65
|
+
/* The bank's day of a rate (`YYYY-MM-DD`), read in UTC so no zone moves it to the day before. */
|
|
66
|
+
export function formatRateDate(date) {
|
|
67
|
+
const at = Date.parse(`${date}T00:00:00Z`);
|
|
68
|
+
return Number.isNaN(at) ? date : formatDay(at, 'UTC');
|
|
69
|
+
}
|
|
65
70
|
/* Enough of a path's tail to tell two checkouts of the same repository apart, under a row that already carries the name. */
|
|
66
71
|
export function shortPath(path) {
|
|
67
72
|
const parts = path.split('/').filter(Boolean);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adecore/agents-react",
|
|
3
|
-
"version": "0.54.
|
|
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.
|
|
76
|
-
"@adecore/editor": "0.54.
|
|
77
|
-
"@adecore/editor-react": "0.54.
|
|
78
|
-
"@adecore/intelligent-ui": "0.54.
|
|
79
|
-
"@adecore/merge": "0.54.
|
|
80
|
-
"@adecore/utils": "0.54.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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')}
|
package/src/state/usage.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
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
|
-
/*
|
|
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
|
}
|
package/src/usage/UsagePage.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import { useChatScope } from '../scope';
|
|
|
9
9
|
import { useProvidersStore } from '../state/providers';
|
|
10
10
|
import { askedKey, summaryPayload, USAGE_PERIODS, useUsage, useUsageStore, type UsageMetric, type UsagePeriod } from '../state/usage';
|
|
11
11
|
import { whenOpen, type ChatTransport } from '../transport';
|
|
12
|
-
import { formatClock, formatCount, formatDate, formatTokens, PROVIDER_LABELS } from './format';
|
|
12
|
+
import { formatClock, formatCount, formatDate, formatRateDate, formatTokens, PROVIDER_LABELS } from './format';
|
|
13
13
|
import { useMoney } from './money';
|
|
14
14
|
import { deriveUsage, labelEveryFor } from './summary';
|
|
15
15
|
import { UsageBreakdown } from './UsageBreakdown';
|
|
@@ -121,7 +121,8 @@ function Provenance() {
|
|
|
121
121
|
summary.pricing.fetchedAt === null ? t('provenance.bundledPrices') : t('provenance.fetchedPrices', { date: formatDate(summary.pricing.fetchedAt) });
|
|
122
122
|
|
|
123
123
|
// The rate is named only when it is being used, so a page in dollars says nothing about euros.
|
|
124
|
-
const rate =
|
|
124
|
+
const rate =
|
|
125
|
+
currency === 'USD' || summary.rate === null ? null : t('provenance.rate', { currency: summary.rate.currency, date: formatRateDate(summary.rate.date) });
|
|
125
126
|
|
|
126
127
|
return (
|
|
127
128
|
<p className="mt-auto text-center text-xs text-text-muted">
|
package/src/usage/UsagePane.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { SettingsRow, SettingsSection } from '@adecore/ui/settings';
|
|
|
3
3
|
import { ChartNoAxesColumn } from 'lucide-react';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { useUsage, useUsageStore } from '../state/usage';
|
|
6
|
-
import type
|
|
6
|
+
import { formatRateDate, type UsageCurrency } from './format';
|
|
7
7
|
|
|
8
8
|
const CURRENCIES: readonly UsageCurrency[] = ['USD', 'EUR'];
|
|
9
9
|
|
|
@@ -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
|
-
|
|
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>
|
|
@@ -26,7 +27,7 @@ export function UsagePane({ onOpenPage }: { onOpenPage(): void }) {
|
|
|
26
27
|
? t('settings.currency.dollars')
|
|
27
28
|
: rate === null
|
|
28
29
|
? t('settings.currency.noRate')
|
|
29
|
-
: t('settings.currency.converted', { date: rate.date })
|
|
30
|
+
: t('settings.currency.converted', { date: formatRateDate(rate.date) })
|
|
30
31
|
}
|
|
31
32
|
control={
|
|
32
33
|
<Segmented
|
package/src/usage/format.ts
CHANGED
|
@@ -84,6 +84,13 @@ export function formatDate(at: number): string {
|
|
|
84
84
|
return formatDay(at);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/* The bank's day of a rate (`YYYY-MM-DD`), read in UTC so no zone moves it to the day before. */
|
|
88
|
+
export function formatRateDate(date: string): string {
|
|
89
|
+
const at = Date.parse(`${date}T00:00:00Z`);
|
|
90
|
+
|
|
91
|
+
return Number.isNaN(at) ? date : formatDay(at, 'UTC');
|
|
92
|
+
}
|
|
93
|
+
|
|
87
94
|
/* Enough of a path's tail to tell two checkouts of the same repository apart, under a row that already carries the name. */
|
|
88
95
|
export function shortPath(path: string): string {
|
|
89
96
|
const parts = path.split('/').filter(Boolean);
|