@celljs/ta-web 4.15.1 → 4.16.0

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 (73) hide show
  1. package/esm/browser/components/access-view.d.ts +6 -0
  2. package/esm/browser/components/access-view.js +4 -4
  3. package/esm/browser/components/app-view.js +11 -1
  4. package/esm/browser/components/chat-list.d.ts +3 -1
  5. package/esm/browser/components/chat-list.js +9 -4
  6. package/esm/browser/components/chat-seen.d.ts +7 -0
  7. package/esm/browser/components/chat-seen.js +57 -10
  8. package/esm/browser/components/environment-view.js +59 -3
  9. package/esm/browser/components/folder-picker.js +3 -3
  10. package/esm/browser/components/host-tag.js +2 -2
  11. package/esm/browser/components/host-view.d.ts +1 -1
  12. package/esm/browser/components/remote-hosts.js +66 -5
  13. package/esm/browser/components/settings-parts.js +4 -1
  14. package/esm/browser/extension/icons.js +23 -4
  15. package/esm/browser/extension/web-extension-protocol.d.ts +6 -0
  16. package/esm/browser/extension/web-extensions.d.ts +3 -0
  17. package/esm/browser/extension/web-extensions.js +7 -0
  18. package/esm/browser/gateway/console-extension.d.ts +20 -0
  19. package/esm/browser/gateway/console-extension.js +75 -0
  20. package/esm/browser/gateway/console-parts.d.ts +64 -0
  21. package/esm/browser/gateway/console-parts.js +278 -0
  22. package/esm/browser/gateway/console-tenant.d.ts +22 -0
  23. package/esm/browser/gateway/console-tenant.js +286 -0
  24. package/esm/browser/gateway/console-util.d.ts +59 -0
  25. package/esm/browser/gateway/console-util.js +187 -0
  26. package/esm/browser/gateway/console-view.d.ts +2 -0
  27. package/esm/browser/gateway/console-view.js +226 -0
  28. package/esm/browser/i18n/locales.d.ts +201 -3
  29. package/esm/browser/i18n/messages-ja.js +198 -0
  30. package/esm/browser/i18n/messages-zh-tw.js +198 -0
  31. package/esm/browser/i18n/messages.d.ts +198 -0
  32. package/esm/browser/i18n/messages.js +396 -0
  33. package/esm/browser/index.d.ts +3 -0
  34. package/esm/browser/index.js +3 -0
  35. package/esm/browser/style/pages.d.ts +1 -1
  36. package/esm/browser/style/pages.js +141 -0
  37. package/lib/browser/components/access-view.d.ts +6 -0
  38. package/lib/browser/components/access-view.js +5 -4
  39. package/lib/browser/components/app-view.js +11 -1
  40. package/lib/browser/components/chat-list.d.ts +3 -1
  41. package/lib/browser/components/chat-list.js +9 -4
  42. package/lib/browser/components/chat-seen.d.ts +7 -0
  43. package/lib/browser/components/chat-seen.js +57 -10
  44. package/lib/browser/components/environment-view.js +58 -2
  45. package/lib/browser/components/folder-picker.js +2 -2
  46. package/lib/browser/components/host-tag.js +1 -1
  47. package/lib/browser/components/host-view.d.ts +1 -1
  48. package/lib/browser/components/remote-hosts.js +65 -4
  49. package/lib/browser/components/settings-parts.js +4 -1
  50. package/lib/browser/extension/icons.js +22 -3
  51. package/lib/browser/extension/web-extension-protocol.d.ts +6 -0
  52. package/lib/browser/extension/web-extensions.d.ts +3 -0
  53. package/lib/browser/extension/web-extensions.js +7 -0
  54. package/lib/browser/gateway/console-extension.d.ts +21 -0
  55. package/lib/browser/gateway/console-extension.js +111 -0
  56. package/lib/browser/gateway/console-parts.d.ts +65 -0
  57. package/lib/browser/gateway/console-parts.js +322 -0
  58. package/lib/browser/gateway/console-tenant.d.ts +23 -0
  59. package/lib/browser/gateway/console-tenant.js +327 -0
  60. package/lib/browser/gateway/console-util.d.ts +60 -0
  61. package/lib/browser/gateway/console-util.js +190 -0
  62. package/lib/browser/gateway/console-view.d.ts +3 -0
  63. package/lib/browser/gateway/console-view.js +262 -0
  64. package/lib/browser/i18n/locales.d.ts +201 -3
  65. package/lib/browser/i18n/messages-ja.js +198 -0
  66. package/lib/browser/i18n/messages-zh-tw.js +198 -0
  67. package/lib/browser/i18n/messages.d.ts +198 -0
  68. package/lib/browser/i18n/messages.js +396 -0
  69. package/lib/browser/index.d.ts +3 -0
  70. package/lib/browser/index.js +3 -0
  71. package/lib/browser/style/pages.d.ts +1 -1
  72. package/lib/browser/style/pages.js +141 -0
  73. package/package.json +7 -7
@@ -0,0 +1,278 @@
1
+ import * as React from 'react';
2
+ import { Callout } from '../components/callout.js';
3
+ import { Segmented } from '../components/settings-controls.js';
4
+ import { useWorkbench } from '../hooks.js';
5
+ import { useLanguage, useT } from '../i18n/use-t.js';
6
+ import { ConsoleUtil } from './console-util.js';
7
+ /** How often what the console shows is read again while it is seen. */
8
+ export const REFRESH_MS = 10000;
9
+ /** Reads `load` now and every `every` ms while the page is seen; again when `key` changes. */
10
+ export function usePolled(load, key, every = REFRESH_MS) {
11
+ const [value, setValue] = React.useState();
12
+ const [error, setError] = React.useState();
13
+ const [readAt, setReadAt] = React.useState();
14
+ const current = React.useRef(load);
15
+ current.current = load;
16
+ const read = React.useCallback(() => current.current().then(next => {
17
+ setValue(next);
18
+ setError(undefined);
19
+ setReadAt(Date.now());
20
+ }, (cause) => setError(cause.message)), []);
21
+ // biome-ignore lint/correctness/useExhaustiveDependencies: read again whenever what is read changes
22
+ React.useEffect(() => {
23
+ setValue(undefined);
24
+ void read();
25
+ const timer = setInterval(() => document.visibilityState === 'visible' && void read(), every);
26
+ return () => clearInterval(timer);
27
+ }, [key, read, every]);
28
+ return { value, error, read, readAt };
29
+ }
30
+ export function SectionTitle({ children, action }) {
31
+ return (React.createElement("div", { className: "ta-console-section" },
32
+ React.createElement("span", { className: "ta-console-section-title" }, children),
33
+ action));
34
+ }
35
+ /** A bar that fills: of a limit (amber, then red, as it nears it), or a `part` of a whole, in one color. */
36
+ export function Bar({ share, small, part }) {
37
+ return (React.createElement("span", { className: `ta-console-bar${small ? ' ta-console-bar-small' : ''}` },
38
+ React.createElement("span", { className: part ? 'ta-part' : ConsoleUtil.tone(share), style: { width: `${share}%` } })));
39
+ }
40
+ export function Meter({ label, value, share, hint }) {
41
+ return (React.createElement("div", { className: "ta-console-meter" },
42
+ React.createElement("div", { className: "ta-console-meter-text" },
43
+ React.createElement("span", null, label),
44
+ React.createElement("span", { className: "ta-console-meter-value" }, value)),
45
+ share !== undefined && React.createElement(Bar, { share: share }),
46
+ hint && React.createElement("span", { className: "ta-console-meter-hint" }, hint)));
47
+ }
48
+ export function Stat({ value, label, tone, onClick, title, }) {
49
+ const body = (React.createElement(React.Fragment, null,
50
+ React.createElement("span", { className: `ta-console-stat-value${tone ? ` ta-${tone}` : ''}` }, value),
51
+ React.createElement("span", { className: "ta-console-stat-label" }, label)));
52
+ return onClick ? (React.createElement("button", { type: "button", className: "ta-console-stat", onClick: onClick, title: title }, body)) : (React.createElement("div", { className: "ta-console-stat" }, body));
53
+ }
54
+ /** This month's minutes and tokens of an account, as bars; the limits of messages and pages in a line. */
55
+ export function QuotaMeters({ quota }) {
56
+ const t = useT();
57
+ const language = useLanguage();
58
+ const { minutes, tokens } = quota;
59
+ const allowed = minutes.limit === undefined ? undefined : minutes.limit + minutes.bonus;
60
+ const resets = new Date(quota.resetsAt).toLocaleDateString(language, { month: 'short', day: 'numeric' });
61
+ return (React.createElement("div", { className: "ta-console-usage" },
62
+ React.createElement(Meter, { label: t('ta.console.freeMinutes'), value: allowed === undefined
63
+ ? `${ConsoleUtil.minutes(minutes.used)} · ${t('ta.console.unlimited')}`
64
+ : `${ConsoleUtil.minutes(minutes.used)} / ${ConsoleUtil.minutes(allowed)}`, share: allowed === undefined ? undefined : ConsoleUtil.share(minutes.used, allowed), hint: [minutes.bonus > 0 ? t('ta.console.bonus', { minutes: minutes.bonus }) : '', t('ta.console.resets', { date: resets })]
65
+ .filter(Boolean)
66
+ .join(' · ') }),
67
+ React.createElement(Meter, { label: t('ta.console.monthTokens'), value: [
68
+ tokens.limit === undefined ? ConsoleUtil.count(tokens.used) : `${ConsoleUtil.count(tokens.used)} / ${ConsoleUtil.count(tokens.limit)}`,
69
+ ConsoleUtil.cost(tokens.cost),
70
+ ]
71
+ .filter(Boolean)
72
+ .join(' · '), share: tokens.limit === undefined ? undefined : ConsoleUtil.share(tokens.used, tokens.limit), hint: [
73
+ t(tokens.metered ? 'ta.console.tokensMetered' : 'ta.console.tokensReported'),
74
+ quota.promptsPerMinute !== undefined ? t('ta.console.promptsLimit', { count: quota.promptsPerMinute }) : '',
75
+ quota.connections !== undefined ? t('ta.console.connectionsLimit', { count: quota.connections }) : '',
76
+ ]
77
+ .filter(Boolean)
78
+ .join(' · ') })));
79
+ }
80
+ const RANGES = [
81
+ { value: '1', label: 'ta.console.range1' },
82
+ { value: '7', label: 'ta.console.range7' },
83
+ { value: '30', label: 'ta.console.range30' },
84
+ ];
85
+ function pointLabel(point, range, language) {
86
+ const date = new Date(point.at);
87
+ return range === 1
88
+ ? date.toLocaleTimeString(language, { hour: '2-digit', minute: '2-digit' })
89
+ : date.toLocaleDateString(language, { month: 'numeric', day: 'numeric', weekday: range === 7 ? 'short' : undefined });
90
+ }
91
+ /** Bars of a trend, the one under the pointer said above them. */
92
+ function TrendBars({ points, metric, range }) {
93
+ const t = useT();
94
+ const language = useLanguage();
95
+ const [hovered, setHovered] = React.useState();
96
+ const values = points.map(point => (metric === 'tokens' ? point.tokens : point.cost));
97
+ const max = Math.max(...values, 0);
98
+ const shown = hovered !== undefined ? points[hovered] : undefined;
99
+ const format = (value) => { var _a; return (metric === 'tokens' ? ConsoleUtil.count(value) : ((_a = ConsoleUtil.cost(value)) !== null && _a !== void 0 ? _a : '$0')); };
100
+ const width = 600;
101
+ const height = 120;
102
+ const slot = width / points.length;
103
+ const gap = Math.min(4, slot * 0.25);
104
+ return (React.createElement("div", { className: "ta-console-chart" },
105
+ React.createElement("div", { className: "ta-console-chart-hover" }, shown ? (React.createElement(React.Fragment, null,
106
+ React.createElement("span", null, pointLabel(shown, range, language)),
107
+ React.createElement("strong", null, format(metric === 'tokens' ? shown.tokens : shown.cost)),
108
+ React.createElement("span", null, t('ta.console.turns', { count: shown.turns })))) : (React.createElement("span", null, t('ta.console.peak', { value: format(max) })))),
109
+ React.createElement("svg", { viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "none", role: "img", "aria-label": t('ta.console.trend'), onPointerMove: event => {
110
+ const box = event.currentTarget.getBoundingClientRect();
111
+ setHovered(Math.min(points.length - 1, Math.max(0, Math.floor(((event.clientX - box.left) / box.width) * points.length))));
112
+ }, onPointerLeave: () => setHovered(undefined) },
113
+ values.map((value, index) => {
114
+ const barHeight = max > 0 ? Math.max(value > 0 ? 2 : 0, (value / max) * (height - 4)) : 0;
115
+ return (React.createElement("rect", { key: points[index].at, x: index * slot + gap / 2, y: height - barHeight, width: Math.max(1, slot - gap), height: barHeight, rx: Math.min(3, (slot - gap) / 3), className: hovered === index ? 'ta-console-chart-bar ta-on' : 'ta-console-chart-bar' }));
116
+ }),
117
+ React.createElement("line", { x1: 0, x2: width, y1: height - 0.5, y2: height - 0.5, className: "ta-console-chart-axis" })),
118
+ React.createElement("div", { className: "ta-console-chart-ticks" },
119
+ React.createElement("span", null, pointLabel(points[0], range, language)),
120
+ React.createElement("span", null, pointLabel(points[Math.floor(points.length / 2)], range, language)),
121
+ React.createElement("span", null, pointLabel(points[points.length - 1], range, language)))));
122
+ }
123
+ function Shares({ rows, total, metric }) {
124
+ return (React.createElement("div", { className: "ta-console-shares" }, rows.map(row => {
125
+ var _a;
126
+ const value = metric === 'tokens' ? row.tokens : row.cost;
127
+ return (React.createElement("div", { key: row.key, className: "ta-console-share" },
128
+ React.createElement("span", { className: "ta-console-share-label ta-ellipsis", title: row.label }, row.label),
129
+ React.createElement(Bar, { share: total > 0 ? Math.round((value / total) * 100) : 0, small: true, part: true }),
130
+ React.createElement("span", { className: "ta-console-share-value" }, metric === 'tokens' ? ConsoleUtil.count(value) : ((_a = ConsoleUtil.cost(value)) !== null && _a !== void 0 ? _a : '—'))));
131
+ })));
132
+ }
133
+ /**
134
+ * What agents took over time, of the gateway or of one account: tokens or dollars by hour (a day) or by day (a week,
135
+ * a month), the totals, and the models and accounts that took most.
136
+ */
137
+ export function TrendCard({ tenantId, tenants, onTenant }) {
138
+ var _a, _b, _c, _d, _e, _f;
139
+ const t = useT();
140
+ const [, bench] = useWorkbench();
141
+ const [range, setRange] = React.useState(7);
142
+ const [metric, setMetric] = React.useState('tokens');
143
+ const { value: trend, error } = usePolled(() => bench.gateway.getUsageTrend(range === 1 ? 2 : range, tenantId), `${range}|${tenantId}`, 60000);
144
+ const points = trend ? ConsoleUtil.points(trend, range) : undefined;
145
+ const totals = points === null || points === void 0 ? void 0 : points.reduce((sum, point) => ({ tokens: sum.tokens + point.tokens, cost: sum.cost + point.cost, turns: sum.turns + point.turns }), {
146
+ tokens: 0,
147
+ cost: 0,
148
+ turns: 0,
149
+ });
150
+ const total = metric === 'tokens' ? ((_a = totals === null || totals === void 0 ? void 0 : totals.tokens) !== null && _a !== void 0 ? _a : 0) : ((_b = totals === null || totals === void 0 ? void 0 : totals.cost) !== null && _b !== void 0 ? _b : 0);
151
+ const names = new Map(tenants === null || tenants === void 0 ? void 0 : tenants.map(tenant => [tenant.id, tenant.name || tenant.account]));
152
+ return (React.createElement("div", { className: "ta-console-card" },
153
+ React.createElement("div", { className: "ta-console-card-head" },
154
+ React.createElement("div", { className: "ta-console-total" },
155
+ React.createElement("strong", null, metric === 'tokens' ? ConsoleUtil.count((_c = totals === null || totals === void 0 ? void 0 : totals.tokens) !== null && _c !== void 0 ? _c : 0) : ((_e = ConsoleUtil.cost((_d = totals === null || totals === void 0 ? void 0 : totals.cost) !== null && _d !== void 0 ? _d : 0)) !== null && _e !== void 0 ? _e : '$0')),
156
+ React.createElement("span", null, t('ta.console.turns', { count: (_f = totals === null || totals === void 0 ? void 0 : totals.turns) !== null && _f !== void 0 ? _f : 0 }))),
157
+ React.createElement("div", { className: "ta-console-card-controls" },
158
+ React.createElement(Segmented, { label: t('ta.console.metric'), value: metric, onChange: setMetric, choices: [
159
+ { value: 'tokens', label: 'ta.console.tokens' },
160
+ { value: 'cost', label: 'ta.console.cost' },
161
+ ] }),
162
+ React.createElement(Segmented, { label: t('ta.console.range'), value: String(range), onChange: value => setRange(Number(value)), choices: RANGES }))),
163
+ error && !trend ? (React.createElement(Callout, { level: "warning" }, error)) : !points ? (React.createElement("div", { className: "ta-console-chart ta-console-chart-loading" })) : (React.createElement(TrendBars, { points: points, metric: metric, range: range })),
164
+ trend && trend.byModel.length > 0 && (React.createElement(React.Fragment, null,
165
+ React.createElement("span", { className: "ta-console-card-label" }, t('ta.console.byModel')),
166
+ React.createElement(Shares, { metric: metric, total: metric === 'tokens'
167
+ ? trend.byModel.reduce((sum, row) => sum + row.tokens, 0)
168
+ : trend.byModel.reduce((sum, row) => sum + row.cost, 0), rows: trend.byModel
169
+ .slice(0, 5)
170
+ .map(row => { var _a; return ({ key: row.model, label: (_a = row.model.split('/').pop()) !== null && _a !== void 0 ? _a : row.model, tokens: row.tokens, cost: row.cost }); }) }))),
171
+ trend && tenants && trend.byTenant.length > 0 && (React.createElement(React.Fragment, null,
172
+ React.createElement("span", { className: "ta-console-card-label" }, t('ta.console.byAccount')),
173
+ React.createElement("div", { className: "ta-console-shares" }, trend.byTenant.slice(0, 5).map(row => {
174
+ var _a, _b;
175
+ const value = metric === 'tokens' ? row.tokens : row.cost;
176
+ const all = metric === 'tokens'
177
+ ? trend.byTenant.reduce((sum, each) => sum + each.tokens, 0)
178
+ : trend.byTenant.reduce((sum, each) => sum + each.cost, 0);
179
+ return (React.createElement("button", { key: row.tenantId, type: "button", className: "ta-console-share ta-console-share-button", onClick: () => onTenant === null || onTenant === void 0 ? void 0 : onTenant(row.tenantId) },
180
+ React.createElement("span", { className: "ta-console-share-label ta-ellipsis" }, (_a = names.get(row.tenantId)) !== null && _a !== void 0 ? _a : row.tenantId),
181
+ React.createElement(Bar, { share: all > 0 ? Math.round((value / all) * 100) : 0, small: true, part: true }),
182
+ React.createElement("span", { className: "ta-console-share-value" }, metric === 'tokens' ? ConsoleUtil.count(value) : ((_b = ConsoleUtil.cost(value)) !== null && _b !== void 0 ? _b : '—'))));
183
+ })))),
184
+ trend && trend.stale.length > 0 && React.createElement("p", { className: "ta-list-hint" }, t('ta.console.stale', { count: trend.stale.length })),
185
+ total === 0 && trend && React.createElement("p", { className: "ta-list-hint" }, t('ta.console.trendEmpty'))));
186
+ }
187
+ function modeOf(value, nullable) {
188
+ return value === null ? 'none' : value === undefined ? (nullable ? 'inherit' : 'none') : 'set';
189
+ }
190
+ /** A number of a limit: the default's (for an account), none, or one of its own. */
191
+ function NumberLimit({ label, hint, value, base, nullable, readOnly, onChange, }) {
192
+ const t = useT();
193
+ const mode = modeOf(value, nullable);
194
+ const [text, setText] = React.useState(ConsoleUtil.field(value));
195
+ React.useEffect(() => setText(ConsoleUtil.field(value)), [value]);
196
+ const parsed = ConsoleUtil.parse(text);
197
+ return (React.createElement("div", { className: "ta-console-limit" },
198
+ React.createElement("div", { className: "ta-console-limit-text" },
199
+ React.createElement("span", null, label),
200
+ React.createElement("span", { className: "ta-console-limit-hint" }, hint)),
201
+ React.createElement("div", { className: "ta-console-limit-control" },
202
+ React.createElement("select", { className: "ta-input ta-console-select", value: mode, disabled: readOnly, "aria-label": label, onChange: event => {
203
+ const next = event.target.value;
204
+ onChange(next === 'inherit' ? undefined : next === 'none' ? (nullable ? null : undefined) : (parsed !== null && parsed !== void 0 ? parsed : 0));
205
+ if (next === 'set' && parsed === undefined) {
206
+ setText('0');
207
+ }
208
+ } },
209
+ nullable && React.createElement("option", { value: "inherit" }, t('ta.console.limitDefault', { value: base !== null && base !== void 0 ? base : t('ta.console.unlimited') })),
210
+ React.createElement("option", { value: "none" }, t('ta.console.unlimited')),
211
+ React.createElement("option", { value: "set" }, t('ta.console.limitSet'))),
212
+ mode === 'set' && (React.createElement("input", { className: `ta-input ta-console-number${Number.isNaN(parsed) ? ' ta-invalid' : ''}`, inputMode: "numeric", value: text, disabled: readOnly, "aria-label": label, onChange: event => {
213
+ setText(event.target.value);
214
+ const next = ConsoleUtil.parse(event.target.value);
215
+ if (next !== undefined && !Number.isNaN(next)) {
216
+ onChange(next);
217
+ }
218
+ } })))));
219
+ }
220
+ /**
221
+ * Limits to change: the gateway's defaults (`nullable` false: a limit is a number or none), or an account's over them
222
+ * (each the default's, none, or its own). Saved as a whole.
223
+ */
224
+ export function LimitsForm({ value, defaults, providers, nullable, readOnly, metered, onSave, }) {
225
+ const t = useT();
226
+ const [draft, setDraft] = React.useState(value);
227
+ const [busy, setBusy] = React.useState(false);
228
+ React.useEffect(() => setDraft(value), [value]);
229
+ const changed = JSON.stringify(draft) !== JSON.stringify(value);
230
+ const set = (change) => setDraft(current => Object.fromEntries(Object.entries({ ...current, ...change }).filter(([, item]) => item !== undefined)));
231
+ const base = (key) => typeof (defaults === null || defaults === void 0 ? void 0 : defaults[key]) === 'number' ? String(defaults[key]) : undefined;
232
+ const providersMode = draft.providers === null ? 'none' : draft.providers === undefined ? (nullable ? 'inherit' : 'none') : 'set';
233
+ return (React.createElement("div", { className: "ta-console-card ta-console-limits" },
234
+ React.createElement(NumberLimit, { label: t('ta.console.freeMinutes'), hint: t('ta.console.freeMinutesHint'), value: draft.freeMinutes, base: base('freeMinutes'), nullable: nullable, readOnly: readOnly, onChange: freeMinutes => set({ freeMinutes }) }),
235
+ React.createElement(NumberLimit, { label: t('ta.console.monthlyTokens'), hint: t(metered ? 'ta.console.monthlyTokensHint' : 'ta.console.monthlyTokensOff'), value: draft.monthlyTokens, base: base('monthlyTokens'), nullable: nullable, readOnly: readOnly, onChange: monthlyTokens => set({ monthlyTokens }) }),
236
+ React.createElement(NumberLimit, { label: t('ta.console.promptsPerMinute'), hint: t('ta.console.promptsPerMinuteHint'), value: draft.promptsPerMinute, base: base('promptsPerMinute'), nullable: nullable, readOnly: readOnly, onChange: promptsPerMinute => set({ promptsPerMinute }) }),
237
+ React.createElement(NumberLimit, { label: t('ta.console.connectionsMax'), hint: t('ta.console.connectionsMaxHint'), value: draft.connections, base: base('connections'), nullable: nullable, readOnly: readOnly, onChange: connections => set({ connections }) }),
238
+ React.createElement("div", { className: "ta-console-limit" },
239
+ React.createElement("div", { className: "ta-console-limit-text" },
240
+ React.createElement("span", null, t('ta.console.providersAllowed')),
241
+ React.createElement("span", { className: "ta-console-limit-hint" }, t('ta.console.providersAllowedHint'))),
242
+ React.createElement("div", { className: "ta-console-limit-control" },
243
+ React.createElement("select", { className: "ta-input ta-console-select", value: providersMode, disabled: readOnly, "aria-label": t('ta.console.providersAllowed'), onChange: event => {
244
+ const next = event.target.value;
245
+ set({
246
+ providers: next === 'inherit' ? undefined : next === 'none' ? (nullable ? null : undefined) : providers.map(provider => provider.id),
247
+ });
248
+ } },
249
+ nullable && (React.createElement("option", { value: "inherit" }, t('ta.console.limitDefault', { value: (defaults === null || defaults === void 0 ? void 0 : defaults.providers) ? defaults.providers.join(', ') : t('ta.console.allProviders') }))),
250
+ React.createElement("option", { value: "none" }, t('ta.console.allProviders')),
251
+ React.createElement("option", { value: "set" }, t('ta.console.someProviders'))))),
252
+ providersMode === 'set' && (React.createElement("div", { className: "ta-console-chips" }, providers.map(provider => {
253
+ var _a;
254
+ var _b;
255
+ const on = (_b = (_a = draft.providers) === null || _a === void 0 ? void 0 : _a.includes(provider.id)) !== null && _b !== void 0 ? _b : false;
256
+ return (React.createElement("button", { key: provider.id, type: "button", disabled: readOnly, className: on ? 'ta-console-chip-toggle ta-on' : 'ta-console-chip-toggle', "aria-pressed": on, onClick: () => { var _a, _b; return set({
257
+ providers: on ? ((_a = draft.providers) !== null && _a !== void 0 ? _a : []).filter(id => id !== provider.id) : [...((_b = draft.providers) !== null && _b !== void 0 ? _b : []), provider.id],
258
+ }); } }, provider.name));
259
+ }))),
260
+ React.createElement("div", { className: "ta-console-limit" },
261
+ React.createElement("div", { className: "ta-console-limit-text" },
262
+ React.createElement("span", null, t('ta.console.ownService')),
263
+ React.createElement("span", { className: "ta-console-limit-hint" }, t('ta.console.ownServiceHint'))),
264
+ React.createElement("div", { className: "ta-console-limit-control" },
265
+ React.createElement("select", { className: "ta-input ta-console-select", value: draft.own === undefined || draft.own === null ? (nullable && draft.own === undefined ? 'inherit' : 'yes') : draft.own ? 'yes' : 'no', disabled: readOnly, "aria-label": t('ta.console.ownService'), onChange: event => set({ own: event.target.value === 'inherit' ? undefined : event.target.value === 'yes' }) },
266
+ nullable && (React.createElement("option", { value: "inherit" }, t('ta.console.limitDefault', { value: (defaults === null || defaults === void 0 ? void 0 : defaults.own) === false ? t('ta.console.no') : t('ta.console.yes') }))),
267
+ React.createElement("option", { value: "yes" }, t('ta.console.yes')),
268
+ React.createElement("option", { value: "no" }, t('ta.console.no'))))),
269
+ !readOnly && (React.createElement("div", { className: "ta-console-actions ta-console-form-actions" },
270
+ React.createElement("button", { type: "button", className: "ta-button", disabled: !changed || busy, onClick: () => setDraft(value) }, t('ta.console.reset')),
271
+ React.createElement("button", { type: "button", className: "ta-button ta-primary", disabled: !changed ||
272
+ busy ||
273
+ [draft.freeMinutes, draft.monthlyTokens, draft.promptsPerMinute, draft.connections].some(item => typeof item === 'number' && Number.isNaN(item)), onClick: () => {
274
+ setBusy(true);
275
+ void onSave(draft).finally(() => setBusy(false));
276
+ } }, busy ? React.createElement("span", { className: "ta-spinner" }) : t('ta.console.save'))))));
277
+ }
278
+ //# sourceMappingURL=console-parts.js.map
@@ -0,0 +1,22 @@
1
+ import type { TaEnvironmentStatus, TaGatewayConsole, TaGatewayTenant } from '@celljs/ta-protocol';
2
+ import * as React from 'react';
3
+ import type { MessageId } from '../i18n/messages.js';
4
+ export declare const STATUS: Record<TaEnvironmentStatus, MessageId>;
5
+ export declare function StatusDot({ status }: {
6
+ status: TaEnvironmentStatus;
7
+ }): React.JSX.Element;
8
+ export declare function RoleChip({ role }: {
9
+ role: TaGatewayTenant['role'];
10
+ }): React.JSX.Element | null;
11
+ /** Whether one of `viewer` may change the account: an owner any, an admin members only. */
12
+ export declare function canManage(viewer: TaGatewayTenant['role'], tenant: TaGatewayTenant): boolean;
13
+ export declare function TenantRow({ tenant, onOpen }: {
14
+ tenant: TaGatewayTenant;
15
+ onOpen(): void;
16
+ }): React.JSX.Element;
17
+ /** One account's Ta: what it is and may use, what it took, its agents, its actions and its log. */
18
+ export declare function TenantDetail({ tenant, info, onChanged }: {
19
+ tenant: TaGatewayTenant;
20
+ info: TaGatewayConsole;
21
+ onChanged(): Promise<unknown>;
22
+ }): React.JSX.Element;
@@ -0,0 +1,286 @@
1
+ import { ChevronDown, ChevronRight, Gift, Pause, Play, Power, RefreshCw, RotateCw, ShieldCheck, ShieldOff } from 'lucide-react';
2
+ import * as React from 'react';
3
+ import { AccountAvatar } from '../components/access-view.js';
4
+ import { useBusy } from '../components/busy.js';
5
+ import { Callout } from '../components/callout.js';
6
+ import { Icon, IconButton } from '../components/icon.js';
7
+ import { useNotices, useWorkbench } from '../hooks.js';
8
+ import { useLanguage, useT } from '../i18n/use-t.js';
9
+ import { TerminalText } from '../util/terminal-text.js';
10
+ import { Bar, LimitsForm, Meter, QuotaMeters, SectionTitle, Stat, TrendCard, usePolled } from './console-parts.js';
11
+ import { ConsoleUtil } from './console-util.js';
12
+ export const STATUS = {
13
+ starting: 'ta.environment.starting',
14
+ running: 'ta.environment.running',
15
+ stopped: 'ta.environment.stopped',
16
+ failed: 'ta.environment.failed',
17
+ };
18
+ const AGENT_STATUS = {
19
+ working: 'ta.console.agentWorking',
20
+ waiting: 'ta.console.agentWaiting',
21
+ asking: 'ta.console.agentAsking',
22
+ idle: 'ta.console.agentIdle',
23
+ };
24
+ const ROLE = {
25
+ owner: 'ta.console.roleOwner',
26
+ admin: 'ta.console.roleAdmin',
27
+ member: 'ta.console.roleMember',
28
+ };
29
+ export function StatusDot({ status }) {
30
+ return React.createElement("span", { className: `ta-console-dot ta-console-${status}` });
31
+ }
32
+ export function RoleChip({ role }) {
33
+ const t = useT();
34
+ return role === 'member' ? null : React.createElement("span", { className: `ta-console-chip ta-console-role-${role}` }, t(ROLE[role]));
35
+ }
36
+ /** Whether one of `viewer` may change the account: an owner any, an admin members only. */
37
+ export function canManage(viewer, tenant) {
38
+ return viewer === 'owner' || (viewer === 'admin' && tenant.role === 'member');
39
+ }
40
+ export function TenantRow({ tenant, onOpen }) {
41
+ var _a, _b;
42
+ const t = useT();
43
+ const language = useLanguage();
44
+ const { environment, quota } = tenant;
45
+ const label = tenant.name && tenant.name !== tenant.account ? tenant.name : tenant.account;
46
+ const minutes = ConsoleUtil.minutesShare(quota);
47
+ return (React.createElement("button", { type: "button", className: "ta-console-tenant", onClick: onOpen },
48
+ React.createElement(AccountAvatar, { id: tenant.account, avatar: tenant.avatar, className: "ta-console-avatar" }),
49
+ React.createElement("span", { className: "ta-console-tenant-text" },
50
+ React.createElement("span", { className: "ta-console-tenant-name ta-ellipsis" },
51
+ label,
52
+ React.createElement(RoleChip, { role: tenant.role }),
53
+ quota.blocked && (React.createElement("span", { className: "ta-console-chip ta-console-chip-warn" }, t(quota.blocked === 'suspended' ? 'ta.console.suspended' : 'ta.console.outOfMinutes'))),
54
+ label !== tenant.account && React.createElement("span", { className: "ta-console-account" },
55
+ " ",
56
+ tenant.account)),
57
+ React.createElement("span", { className: "ta-console-tenant-state ta-ellipsis" },
58
+ React.createElement(StatusDot, { status: environment.status }),
59
+ [
60
+ t(STATUS[environment.status]),
61
+ ((_a = tenant.agents) === null || _a === void 0 ? void 0 : _a.working) ? t('ta.console.rowWorking', { count: tenant.agents.working }) : '',
62
+ ((_b = tenant.agents) === null || _b === void 0 ? void 0 : _b.waiting) ? t('ta.console.rowWaiting', { count: tenant.agents.waiting }) : '',
63
+ tenant.connections > 0 ? t('ta.environment.connections', { count: tenant.connections }) : '',
64
+ tenant.lastActiveAt ? ConsoleUtil.ago(tenant.lastActiveAt, language) : '',
65
+ ]
66
+ .filter(Boolean)
67
+ .join(' · '))),
68
+ React.createElement("span", { className: "ta-console-tenant-usage" },
69
+ React.createElement("span", null, quota.minutes.limit === undefined
70
+ ? ConsoleUtil.minutes(quota.minutes.used)
71
+ : `${quota.minutes.used} / ${quota.minutes.limit + quota.minutes.bonus} min`),
72
+ minutes !== undefined && React.createElement(Bar, { share: minutes, small: true }))));
73
+ }
74
+ /** What an agent did lately: its tool calls and the failures of its model, newest first. */
75
+ function ActivityList({ tenantId, sessionId }) {
76
+ const t = useT();
77
+ const language = useLanguage();
78
+ const [, bench] = useWorkbench();
79
+ const { value, error } = usePolled(() => bench.gateway.getAgentActivity(tenantId, sessionId), `${tenantId}|${sessionId}`);
80
+ if (error && !value) {
81
+ return React.createElement("p", { className: "ta-list-hint ta-console-activity-empty" }, error);
82
+ }
83
+ if (!value) {
84
+ return React.createElement("span", { className: "ta-spinner ta-later ta-console-loading" });
85
+ }
86
+ if (value.length === 0) {
87
+ return React.createElement("p", { className: "ta-list-hint ta-console-activity-empty" }, t('ta.console.activityNone'));
88
+ }
89
+ const failures = value.filter(each => !each.ok).length;
90
+ return (React.createElement("div", { className: "ta-console-activity" },
91
+ React.createElement("span", { className: "ta-console-activity-summary" }, t('ta.console.activitySummary', { count: value.length, failed: failures })),
92
+ value.slice(0, 30).map((each, index) => (React.createElement("div", { key: `${each.at}-${index}`, className: `ta-console-activity-row${each.ok ? '' : ' ta-failed'}` },
93
+ React.createElement("span", { className: `ta-console-dot ${each.running ? 'ta-console-agent-working' : each.ok ? 'ta-console-running' : 'ta-console-failed'}` }),
94
+ React.createElement("span", { className: "ta-console-activity-name" }, each.kind === 'model' ? t('ta.console.modelFailed', { model: each.name }) : each.name),
95
+ each.error && (React.createElement("span", { className: "ta-console-activity-error ta-ellipsis", title: each.error }, each.error)),
96
+ React.createElement("span", { className: "ta-console-activity-time" }, [
97
+ each.running
98
+ ? t('ta.console.activityRunning')
99
+ : each.ms !== undefined
100
+ ? `${(each.ms / 1000).toFixed(each.ms >= 10000 ? 0 : 1)} s`
101
+ : '',
102
+ ConsoleUtil.ago(each.at, language),
103
+ ]
104
+ .filter(Boolean)
105
+ .join(' · ')))))));
106
+ }
107
+ function AgentRow({ tenantId, session }) {
108
+ var _a;
109
+ const t = useT();
110
+ const language = useLanguage();
111
+ const [open, setOpen] = React.useState(false);
112
+ const { stats } = session;
113
+ const model = (_a = session.model) === null || _a === void 0 ? void 0 : _a.split('/').pop();
114
+ const parts = [
115
+ t('ta.console.messages', { count: session.messageCount }),
116
+ stats && stats.toolCalls > 0 ? t('ta.console.toolCalls', { count: stats.toolCalls }) : '',
117
+ stats && stats.tokens.total > 0 ? `${ConsoleUtil.count(stats.tokens.total)} tokens` : '',
118
+ stats ? ConsoleUtil.cost(stats.cost) : '',
119
+ ].filter(Boolean);
120
+ return (React.createElement("div", { className: "ta-console-agent-block" },
121
+ React.createElement("button", { type: "button", className: "ta-console-agent", "aria-expanded": open, onClick: () => setOpen(!open) },
122
+ React.createElement("span", { className: `ta-console-dot ta-console-agent-${session.status}` }),
123
+ React.createElement("span", { className: "ta-console-tenant-text" },
124
+ React.createElement("span", { className: "ta-console-tenant-name ta-ellipsis" },
125
+ session.name || ConsoleUtil.folder(session.cwd),
126
+ model && React.createElement("span", { className: "ta-console-chip" }, model)),
127
+ React.createElement("span", { className: "ta-console-tenant-state ta-ellipsis" }, [t(AGENT_STATUS[session.status]), ...parts, ConsoleUtil.ago(session.updatedAt, language)].join(' · '))),
128
+ (stats === null || stats === void 0 ? void 0 : stats.context) !== undefined && (React.createElement("span", { className: "ta-console-tenant-usage", title: t('ta.console.context') },
129
+ React.createElement("span", null,
130
+ stats.context,
131
+ "%"),
132
+ React.createElement(Bar, { share: stats.context, small: true }))),
133
+ React.createElement(Icon, { icon: open ? ChevronDown : ChevronRight, size: 15, className: "ta-list-chevron" })),
134
+ open && React.createElement(ActivityList, { tenantId: tenantId, sessionId: session.sessionId })));
135
+ }
136
+ /** The agents of a tenant's Ta: totals, then each conversation open, the latest first; one opens what it did lately. */
137
+ function AgentsSection({ tenant }) {
138
+ var _a, _b, _c, _d, _e;
139
+ const t = useT();
140
+ const [, bench] = useWorkbench();
141
+ const own = tenant.environment.provider === 'own';
142
+ const running = tenant.environment.status === 'running' && !own;
143
+ const { value: agents, error } = usePolled(() => (running ? bench.gateway.getTenantAgents(tenant.id) : Promise.resolve(undefined)), `${tenant.id}|${running}`);
144
+ const totals = agents === null || agents === void 0 ? void 0 : agents.totals;
145
+ return (React.createElement(React.Fragment, null,
146
+ React.createElement(SectionTitle, null, t('ta.console.agents')),
147
+ !running ? (React.createElement("p", { className: "ta-list-hint" }, own ? t('ta.console.agentsOwn') : t('ta.console.agentsStopped'))) : error && !agents ? (React.createElement(Callout, { level: "warning" }, error)) : !agents ? (React.createElement("span", { className: "ta-spinner ta-later ta-console-loading" })) : (React.createElement(React.Fragment, null,
148
+ React.createElement("div", { className: "ta-console-stats ta-console-stats-small" },
149
+ React.createElement(Stat, { value: (_a = totals === null || totals === void 0 ? void 0 : totals.sessions) !== null && _a !== void 0 ? _a : 0, label: t('ta.console.sessions') }),
150
+ React.createElement(Stat, { value: (_b = totals === null || totals === void 0 ? void 0 : totals.working) !== null && _b !== void 0 ? _b : 0, label: t('ta.console.agentWorking'), tone: (totals === null || totals === void 0 ? void 0 : totals.working) ? 'good' : undefined }),
151
+ React.createElement(Stat, { value: (_c = totals === null || totals === void 0 ? void 0 : totals.toolCalls) !== null && _c !== void 0 ? _c : 0, label: t('ta.console.toolCallsLabel') }),
152
+ React.createElement(Stat, { value: (_e = ConsoleUtil.cost((_d = totals === null || totals === void 0 ? void 0 : totals.cost) !== null && _d !== void 0 ? _d : 0)) !== null && _e !== void 0 ? _e : '—', label: t('ta.console.cost') })),
153
+ agents.sessions.length === 0 ? (React.createElement("p", { className: "ta-list-hint" }, t('ta.console.agentsNone'))) : (React.createElement("div", { className: "ta-list-group" }, agents.sessions.map(session => (React.createElement(AgentRow, { key: session.sessionId, tenantId: tenant.id, session: session }))))),
154
+ React.createElement("p", { className: "ta-list-hint" }, t('ta.console.agentsPrivacy'))))));
155
+ }
156
+ function Logs({ tenant, info }) {
157
+ const t = useT();
158
+ const [, bench] = useWorkbench();
159
+ const [, notices] = useNotices();
160
+ const [logs, setLogs] = React.useState();
161
+ const [busy, run] = useBusy();
162
+ const box = React.useRef(null);
163
+ const hasLogs = tenant.environment.provider !== 'own' && info.providers.some(provider => provider.id === tenant.environment.provider && provider.logs);
164
+ const read = React.useCallback(() => run(() => bench.gateway.getTenantLogs(tenant.id, 300).then(text => setLogs(TerminalText.plain(text).trimEnd()), error => notices.error(error))), [bench, tenant.id, notices, run]);
165
+ // The latest lines are what one looks for: the box starts at its end.
166
+ // biome-ignore lint/correctness/useExhaustiveDependencies: scrolled again when the lines change
167
+ React.useLayoutEffect(() => {
168
+ if (box.current) {
169
+ box.current.scrollTop = box.current.scrollHeight;
170
+ }
171
+ }, [logs]);
172
+ return (React.createElement(React.Fragment, null,
173
+ React.createElement(SectionTitle, { action: hasLogs && logs !== undefined ? (React.createElement(IconButton, { icon: RefreshCw, label: t('ta.console.refresh'), busy: busy, onClick: () => void read() })) : undefined }, t('ta.console.logs')),
174
+ !hasLogs ? (React.createElement("p", { className: "ta-list-hint" }, t('ta.console.logsNone'))) : logs === undefined ? (React.createElement("div", { className: "ta-console-actions" },
175
+ React.createElement("button", { type: "button", className: "ta-button", disabled: busy, onClick: () => void read() }, busy ? React.createElement("span", { className: "ta-spinner" }) : t('ta.console.logsShow')),
176
+ React.createElement("span", { className: "ta-list-hint" }, t('ta.console.logsAudited')))) : (React.createElement("pre", { ref: box, className: "ta-console-logs" }, logs || t('ta.console.logsEmpty')))));
177
+ }
178
+ /** One account's Ta: what it is and may use, what it took, its agents, its actions and its log. */
179
+ export function TenantDetail({ tenant, info, onChanged }) {
180
+ var _a;
181
+ const t = useT();
182
+ const language = useLanguage();
183
+ const [, bench] = useWorkbench();
184
+ const [, notices] = useNotices();
185
+ const [busy, run] = useBusy();
186
+ const [doing, setDoing] = React.useState();
187
+ const [editing, setEditing] = React.useState(false);
188
+ const { environment, usage } = tenant;
189
+ const own = environment.provider === 'own';
190
+ const manage = canManage(info.role, tenant);
191
+ const act = (key, action, done) => {
192
+ setDoing(key);
193
+ void run(() => action()
194
+ .then(() => done && notices.notify(done, { level: 'success' }))
195
+ .catch(error => notices.error(error))
196
+ .then(onChanged)
197
+ .finally(() => setDoing(undefined)));
198
+ };
199
+ const confirmThen = async (key, title, message, label, action, danger = false) => {
200
+ if (await notices.confirm({ title, message, confirmLabel: label, danger })) {
201
+ act(key, action);
202
+ }
203
+ };
204
+ const date = (time) => (time ? new Date(time).toLocaleString(language, { dateStyle: 'medium', timeStyle: 'short' }) : t('ta.console.never'));
205
+ const spinner = (key, icon) => (busy && doing === key ? React.createElement("span", { className: "ta-spinner" }) : React.createElement(Icon, { icon: icon, size: 15 }));
206
+ const memory = ConsoleUtil.share(usage === null || usage === void 0 ? void 0 : usage.memory, usage === null || usage === void 0 ? void 0 : usage.memoryLimit);
207
+ const name = tenant.name || tenant.account;
208
+ return (React.createElement("div", { className: "ta-list-scroll" },
209
+ React.createElement("div", { className: "ta-list-content ta-console-content" },
210
+ React.createElement("div", { className: "ta-console-person" },
211
+ React.createElement(AccountAvatar, { id: tenant.account, avatar: tenant.avatar, className: "ta-console-avatar ta-console-avatar-large" }),
212
+ React.createElement("div", { className: "ta-console-person-text" },
213
+ React.createElement("span", { className: "ta-console-person-name ta-ellipsis" },
214
+ name,
215
+ React.createElement(RoleChip, { role: tenant.role })),
216
+ React.createElement("span", { className: "ta-console-account ta-ellipsis" }, tenant.account),
217
+ React.createElement("span", { className: "ta-console-tenant-state" },
218
+ React.createElement(StatusDot, { status: environment.status }),
219
+ [t(STATUS[environment.status]), environment.name].filter(Boolean).join(' · ')))),
220
+ tenant.quota.blocked ? (React.createElement(Callout, { level: "warning" }, t(tenant.quota.blocked === 'suspended' ? 'ta.console.blockedSuspended' : 'ta.console.blockedMinutes'))) : (environment.error && React.createElement(Callout, { level: "error" }, environment.error)),
221
+ manage ? (React.createElement("div", { className: "ta-console-actions" },
222
+ environment.status !== 'running' && !tenant.quota.blocked && (React.createElement("button", { type: "button", className: "ta-button ta-primary", disabled: busy || environment.status === 'starting', onClick: () => act('start', () => bench.gateway.startTenant(tenant.id)) },
223
+ spinner('start', Play),
224
+ " ",
225
+ t('ta.console.start'))),
226
+ environment.status === 'running' && (React.createElement("button", { type: "button", className: "ta-button", disabled: busy, onClick: () => confirmThen('restart', t('ta.console.restartConfirm', { account: name }), t('ta.console.restartDetail'), t('ta.environment.restart'), () => bench.gateway.restartTenant(tenant.id)) },
227
+ spinner('restart', RotateCw),
228
+ " ",
229
+ t('ta.environment.restart'))),
230
+ environment.status === 'running' && !own && (React.createElement("button", { type: "button", className: "ta-button", disabled: busy, onClick: () => confirmThen('stop', t('ta.environment.stopConfirm', { account: name }), t('ta.environment.stopDetail'), t('ta.environment.stop'), () => bench.gateway.stopTenant(tenant.id)) },
231
+ spinner('stop', Power),
232
+ " ",
233
+ t('ta.environment.stop'))),
234
+ tenant.role !== 'owner' && (React.createElement("button", { type: "button", className: tenant.suspended ? 'ta-button' : 'ta-button ta-danger', disabled: busy, onClick: () => tenant.suspended
235
+ ? act('suspend', () => bench.gateway.setSuspended(tenant.id, false), t('ta.console.resumed', { account: name }))
236
+ : confirmThen('suspend', t('ta.console.suspendConfirm', { account: name }), t('ta.console.suspendDetail'), t('ta.console.suspend'), () => bench.gateway.setSuspended(tenant.id, true), true) },
237
+ spinner('suspend', tenant.suspended ? Play : Pause),
238
+ " ",
239
+ t(tenant.suspended ? 'ta.console.resume' : 'ta.console.suspend'))))) : (React.createElement("p", { className: "ta-list-hint" }, t('ta.console.cannotManage'))),
240
+ React.createElement(SectionTitle, { action: manage && tenant.role !== 'owner' ? (React.createElement("div", { className: "ta-console-actions" },
241
+ React.createElement("button", { type: "button", className: "ta-link-button", onClick: async () => {
242
+ const given = await notices.input({ title: t('ta.console.grantTitle', { account: name }), placeholder: '60' });
243
+ const minutes = given === undefined ? undefined : Number(given.trim());
244
+ if (minutes !== undefined && Number.isInteger(minutes) && minutes !== 0) {
245
+ act('grant', () => bench.gateway.grantMinutes(tenant.id, minutes), t('ta.console.granted', { minutes }));
246
+ }
247
+ } },
248
+ React.createElement(Icon, { icon: Gift, size: 14 }),
249
+ " ",
250
+ t('ta.console.grant')),
251
+ React.createElement("button", { type: "button", className: "ta-link-button", onClick: () => setEditing(!editing) }, t(editing ? 'ta.console.limitsDone' : 'ta.console.limitsEdit')))) : undefined }, t('ta.console.quota')),
252
+ React.createElement(QuotaMeters, { quota: tenant.quota }),
253
+ editing && manage && (React.createElement(LimitsForm, { value: (_a = tenant.limits) !== null && _a !== void 0 ? _a : {}, defaults: info.policy.defaults, providers: info.providers, nullable: true, metered: info.models.length > 0, onSave: limits => bench.gateway
254
+ .setTenantLimits(tenant.id, Object.keys(limits).length ? limits : null)
255
+ .then(() => notices.notify(t('ta.console.saved'), { level: 'success' }))
256
+ .then(onChanged)
257
+ .catch(error => notices.error(error)) })),
258
+ info.role === 'owner' && tenant.role !== 'owner' && (React.createElement("div", { className: "ta-console-role-row" },
259
+ React.createElement(Icon, { icon: tenant.role === 'admin' ? ShieldCheck : ShieldOff, size: 16 }),
260
+ React.createElement("span", null, t(tenant.role === 'admin' ? 'ta.console.isAdmin' : 'ta.console.isMember')),
261
+ React.createElement("button", { type: "button", className: "ta-link-button", disabled: busy, onClick: () => confirmThen('role', t(tenant.role === 'admin' ? 'ta.console.demoteConfirm' : 'ta.console.promoteConfirm', { account: name }), t(tenant.role === 'admin' ? 'ta.console.demoteDetail' : 'ta.console.promoteDetail'), t(tenant.role === 'admin' ? 'ta.console.demote' : 'ta.console.promote'), () => bench.gateway.setRole(tenant.account, tenant.role === 'admin' ? 'member' : 'admin')) }, t(tenant.role === 'admin' ? 'ta.console.demote' : 'ta.console.promote')))),
262
+ React.createElement(SectionTitle, null, t('ta.console.trend')),
263
+ React.createElement(TrendCard, { tenantId: tenant.id }),
264
+ React.createElement(AgentsSection, { tenant: tenant }),
265
+ usage && (React.createElement(React.Fragment, null,
266
+ React.createElement(SectionTitle, null, t('ta.console.sandboxNow')),
267
+ React.createElement("div", { className: "ta-console-usage" },
268
+ usage.cpu !== undefined && (React.createElement(Meter, { label: t('ta.console.cpu'), value: `${usage.cpu.toFixed(1)}%`, share: Math.min(100, usage.cpu) })),
269
+ usage.memory !== undefined && (React.createElement(Meter, { label: t('ta.console.memory'), value: usage.memoryLimit
270
+ ? `${ConsoleUtil.bytes(usage.memory)} / ${ConsoleUtil.bytes(usage.memoryLimit)}`
271
+ : ConsoleUtil.bytes(usage.memory), share: memory }))))),
272
+ React.createElement(Logs, { key: tenant.id, tenant: tenant, info: info }),
273
+ React.createElement(SectionTitle, null, t('ta.console.about')),
274
+ React.createElement("dl", { className: "ta-console-facts" },
275
+ React.createElement("dt", null, t('ta.console.environment')),
276
+ React.createElement("dd", { className: "ta-ellipsis" }, environment.url ? `${environment.name} · ${environment.url}` : environment.name),
277
+ React.createElement("dt", null, t('ta.console.connectionsLabel')),
278
+ React.createElement("dd", null, tenant.connections),
279
+ React.createElement("dt", null, t('ta.console.active')),
280
+ React.createElement("dd", null, date(tenant.lastActiveAt)),
281
+ React.createElement("dt", null, t('ta.console.created')),
282
+ React.createElement("dd", null, date(tenant.createdAt)),
283
+ React.createElement("dt", null, t('ta.console.tenantId')),
284
+ React.createElement("dd", { className: "ta-console-mono" }, tenant.id)))));
285
+ }
286
+ //# sourceMappingURL=console-tenant.js.map