@celljs/ta-web 4.15.0 → 4.15.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 (129) 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/account-menu.js +8 -1
  4. package/esm/browser/components/app-view.js +8 -1
  5. package/esm/browser/components/environment-view.js +9 -2
  6. package/esm/browser/components/face.js +7 -2
  7. package/esm/browser/components/gallery.d.ts +9 -0
  8. package/esm/browser/components/gallery.js +57 -0
  9. package/esm/browser/components/host-view.d.ts +1 -1
  10. package/esm/browser/components/lightbox.d.ts +8 -1
  11. package/esm/browser/components/lightbox.js +4 -1
  12. package/esm/browser/components/markdown.js +6 -1
  13. package/esm/browser/components/media.d.ts +12 -2
  14. package/esm/browser/components/media.js +55 -13
  15. package/esm/browser/components/message-list.js +3 -2
  16. package/esm/browser/components/notice-center.js +6 -2
  17. package/esm/browser/components/serve-restart.d.ts +26 -0
  18. package/esm/browser/components/serve-restart.js +91 -0
  19. package/esm/browser/components/session-view.js +19 -11
  20. package/esm/browser/components/settings-parts.js +18 -6
  21. package/esm/browser/extension/icons.js +3 -1
  22. package/esm/browser/extension/web-extension-protocol.d.ts +6 -0
  23. package/esm/browser/extension/web-extensions.d.ts +3 -0
  24. package/esm/browser/extension/web-extensions.js +7 -0
  25. package/esm/browser/gateway/console-extension.d.ts +20 -0
  26. package/esm/browser/gateway/console-extension.js +75 -0
  27. package/esm/browser/gateway/console-parts.d.ts +62 -0
  28. package/esm/browser/gateway/console-parts.js +271 -0
  29. package/esm/browser/gateway/console-tenant.d.ts +22 -0
  30. package/esm/browser/gateway/console-tenant.js +286 -0
  31. package/esm/browser/gateway/console-util.d.ts +59 -0
  32. package/esm/browser/gateway/console-util.js +187 -0
  33. package/esm/browser/gateway/console-view.d.ts +2 -0
  34. package/esm/browser/gateway/console-view.js +218 -0
  35. package/esm/browser/i18n/locales.d.ts +186 -3
  36. package/esm/browser/i18n/messages-ja.js +183 -0
  37. package/esm/browser/i18n/messages-zh-tw.js +183 -0
  38. package/esm/browser/i18n/messages.d.ts +183 -0
  39. package/esm/browser/i18n/messages.js +366 -0
  40. package/esm/browser/index.d.ts +3 -0
  41. package/esm/browser/index.js +3 -0
  42. package/esm/browser/style/conversation.d.ts +1 -1
  43. package/esm/browser/style/conversation.js +18 -0
  44. package/esm/browser/style/layout.d.ts +1 -1
  45. package/esm/browser/style/layout.js +2 -0
  46. package/esm/browser/style/pages.d.ts +1 -1
  47. package/esm/browser/style/pages.js +140 -0
  48. package/esm/browser/style/shell.d.ts +1 -1
  49. package/esm/browser/style/shell.js +2 -0
  50. package/esm/browser/style/surfaces.d.ts +1 -1
  51. package/esm/browser/style/surfaces.js +1 -0
  52. package/esm/browser/util/desktop.d.ts +6 -1
  53. package/esm/browser/util/desktop.js +10 -0
  54. package/esm/browser/util/gallery.d.ts +18 -0
  55. package/esm/browser/util/gallery.js +123 -0
  56. package/esm/browser/util/link.d.ts +8 -0
  57. package/esm/browser/util/link.js +14 -0
  58. package/esm/browser/util/markdown.d.ts +11 -0
  59. package/esm/browser/util/markdown.js +4 -0
  60. package/esm/browser/util/thumbnail.d.ts +18 -0
  61. package/esm/browser/util/thumbnail.js +26 -0
  62. package/esm/browser/workbench-protocol.d.ts +8 -0
  63. package/esm/browser/workbench.d.ts +16 -0
  64. package/esm/browser/workbench.js +67 -0
  65. package/lib/browser/components/access-view.d.ts +6 -0
  66. package/lib/browser/components/access-view.js +5 -4
  67. package/lib/browser/components/account-menu.js +7 -0
  68. package/lib/browser/components/app-view.js +8 -1
  69. package/lib/browser/components/environment-view.js +9 -2
  70. package/lib/browser/components/face.js +7 -2
  71. package/lib/browser/components/gallery.d.ts +10 -0
  72. package/lib/browser/components/gallery.js +93 -0
  73. package/lib/browser/components/host-view.d.ts +1 -1
  74. package/lib/browser/components/lightbox.d.ts +8 -1
  75. package/lib/browser/components/lightbox.js +4 -1
  76. package/lib/browser/components/markdown.js +6 -1
  77. package/lib/browser/components/media.d.ts +12 -2
  78. package/lib/browser/components/media.js +57 -13
  79. package/lib/browser/components/message-list.js +3 -2
  80. package/lib/browser/components/notice-center.js +6 -2
  81. package/lib/browser/components/serve-restart.d.ts +27 -0
  82. package/lib/browser/components/serve-restart.js +129 -0
  83. package/lib/browser/components/session-view.js +21 -13
  84. package/lib/browser/components/settings-parts.js +17 -5
  85. package/lib/browser/extension/icons.js +2 -0
  86. package/lib/browser/extension/web-extension-protocol.d.ts +6 -0
  87. package/lib/browser/extension/web-extensions.d.ts +3 -0
  88. package/lib/browser/extension/web-extensions.js +7 -0
  89. package/lib/browser/gateway/console-extension.d.ts +21 -0
  90. package/lib/browser/gateway/console-extension.js +111 -0
  91. package/lib/browser/gateway/console-parts.d.ts +63 -0
  92. package/lib/browser/gateway/console-parts.js +315 -0
  93. package/lib/browser/gateway/console-tenant.d.ts +23 -0
  94. package/lib/browser/gateway/console-tenant.js +327 -0
  95. package/lib/browser/gateway/console-util.d.ts +60 -0
  96. package/lib/browser/gateway/console-util.js +190 -0
  97. package/lib/browser/gateway/console-view.d.ts +3 -0
  98. package/lib/browser/gateway/console-view.js +254 -0
  99. package/lib/browser/i18n/locales.d.ts +186 -3
  100. package/lib/browser/i18n/messages-ja.js +183 -0
  101. package/lib/browser/i18n/messages-zh-tw.js +183 -0
  102. package/lib/browser/i18n/messages.d.ts +183 -0
  103. package/lib/browser/i18n/messages.js +366 -0
  104. package/lib/browser/index.d.ts +3 -0
  105. package/lib/browser/index.js +3 -0
  106. package/lib/browser/style/conversation.d.ts +1 -1
  107. package/lib/browser/style/conversation.js +18 -0
  108. package/lib/browser/style/layout.d.ts +1 -1
  109. package/lib/browser/style/layout.js +2 -0
  110. package/lib/browser/style/pages.d.ts +1 -1
  111. package/lib/browser/style/pages.js +140 -0
  112. package/lib/browser/style/shell.d.ts +1 -1
  113. package/lib/browser/style/shell.js +2 -0
  114. package/lib/browser/style/surfaces.d.ts +1 -1
  115. package/lib/browser/style/surfaces.js +1 -0
  116. package/lib/browser/util/desktop.d.ts +6 -1
  117. package/lib/browser/util/desktop.js +10 -0
  118. package/lib/browser/util/gallery.d.ts +19 -0
  119. package/lib/browser/util/gallery.js +126 -0
  120. package/lib/browser/util/link.d.ts +8 -0
  121. package/lib/browser/util/link.js +14 -0
  122. package/lib/browser/util/markdown.d.ts +11 -0
  123. package/lib/browser/util/markdown.js +4 -0
  124. package/lib/browser/util/thumbnail.d.ts +19 -0
  125. package/lib/browser/util/thumbnail.js +29 -0
  126. package/lib/browser/workbench-protocol.d.ts +8 -0
  127. package/lib/browser/workbench.d.ts +16 -0
  128. package/lib/browser/workbench.js +67 -0
  129. package/package.json +7 -7
@@ -0,0 +1,271 @@
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: [ConsoleUtil.count(tokens.used), ConsoleUtil.cost(tokens.cost)].filter(Boolean).join(' · '), hint: [
68
+ quota.promptsPerMinute !== undefined ? t('ta.console.promptsLimit', { count: quota.promptsPerMinute }) : '',
69
+ quota.connections !== undefined ? t('ta.console.connectionsLimit', { count: quota.connections }) : '',
70
+ ]
71
+ .filter(Boolean)
72
+ .join(' · ') })));
73
+ }
74
+ const RANGES = [
75
+ { value: '1', label: 'ta.console.range1' },
76
+ { value: '7', label: 'ta.console.range7' },
77
+ { value: '30', label: 'ta.console.range30' },
78
+ ];
79
+ function pointLabel(point, range, language) {
80
+ const date = new Date(point.at);
81
+ return range === 1
82
+ ? date.toLocaleTimeString(language, { hour: '2-digit', minute: '2-digit' })
83
+ : date.toLocaleDateString(language, { month: 'numeric', day: 'numeric', weekday: range === 7 ? 'short' : undefined });
84
+ }
85
+ /** Bars of a trend, the one under the pointer said above them. */
86
+ function TrendBars({ points, metric, range }) {
87
+ const t = useT();
88
+ const language = useLanguage();
89
+ const [hovered, setHovered] = React.useState();
90
+ const values = points.map(point => (metric === 'tokens' ? point.tokens : point.cost));
91
+ const max = Math.max(...values, 0);
92
+ const shown = hovered !== undefined ? points[hovered] : undefined;
93
+ const format = (value) => { var _a; return (metric === 'tokens' ? ConsoleUtil.count(value) : ((_a = ConsoleUtil.cost(value)) !== null && _a !== void 0 ? _a : '$0')); };
94
+ const width = 600;
95
+ const height = 120;
96
+ const slot = width / points.length;
97
+ const gap = Math.min(4, slot * 0.25);
98
+ return (React.createElement("div", { className: "ta-console-chart" },
99
+ React.createElement("div", { className: "ta-console-chart-hover" }, shown ? (React.createElement(React.Fragment, null,
100
+ React.createElement("span", null, pointLabel(shown, range, language)),
101
+ React.createElement("strong", null, format(metric === 'tokens' ? shown.tokens : shown.cost)),
102
+ React.createElement("span", null, t('ta.console.turns', { count: shown.turns })))) : (React.createElement("span", null, t('ta.console.peak', { value: format(max) })))),
103
+ React.createElement("svg", { viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "none", role: "img", "aria-label": t('ta.console.trend'), onPointerMove: event => {
104
+ const box = event.currentTarget.getBoundingClientRect();
105
+ setHovered(Math.min(points.length - 1, Math.max(0, Math.floor(((event.clientX - box.left) / box.width) * points.length))));
106
+ }, onPointerLeave: () => setHovered(undefined) },
107
+ values.map((value, index) => {
108
+ const barHeight = max > 0 ? Math.max(value > 0 ? 2 : 0, (value / max) * (height - 4)) : 0;
109
+ 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' }));
110
+ }),
111
+ React.createElement("line", { x1: 0, x2: width, y1: height - 0.5, y2: height - 0.5, className: "ta-console-chart-axis" })),
112
+ React.createElement("div", { className: "ta-console-chart-ticks" },
113
+ React.createElement("span", null, pointLabel(points[0], range, language)),
114
+ React.createElement("span", null, pointLabel(points[Math.floor(points.length / 2)], range, language)),
115
+ React.createElement("span", null, pointLabel(points[points.length - 1], range, language)))));
116
+ }
117
+ function Shares({ rows, total, metric }) {
118
+ return (React.createElement("div", { className: "ta-console-shares" }, rows.map(row => {
119
+ var _a;
120
+ const value = metric === 'tokens' ? row.tokens : row.cost;
121
+ return (React.createElement("div", { key: row.key, className: "ta-console-share" },
122
+ React.createElement("span", { className: "ta-console-share-label ta-ellipsis", title: row.label }, row.label),
123
+ React.createElement(Bar, { share: total > 0 ? Math.round((value / total) * 100) : 0, small: true, part: true }),
124
+ React.createElement("span", { className: "ta-console-share-value" }, metric === 'tokens' ? ConsoleUtil.count(value) : ((_a = ConsoleUtil.cost(value)) !== null && _a !== void 0 ? _a : '—'))));
125
+ })));
126
+ }
127
+ /**
128
+ * What agents took over time, of the gateway or of one account: tokens or dollars by hour (a day) or by day (a week,
129
+ * a month), the totals, and the models and accounts that took most.
130
+ */
131
+ export function TrendCard({ tenantId, tenants, onTenant }) {
132
+ var _a, _b, _c, _d, _e, _f;
133
+ const t = useT();
134
+ const [, bench] = useWorkbench();
135
+ const [range, setRange] = React.useState(7);
136
+ const [metric, setMetric] = React.useState('tokens');
137
+ const { value: trend, error } = usePolled(() => bench.gateway.getUsageTrend(range === 1 ? 2 : range, tenantId), `${range}|${tenantId}`, 60000);
138
+ const points = trend ? ConsoleUtil.points(trend, range) : undefined;
139
+ 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 }), {
140
+ tokens: 0,
141
+ cost: 0,
142
+ turns: 0,
143
+ });
144
+ 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);
145
+ const names = new Map(tenants === null || tenants === void 0 ? void 0 : tenants.map(tenant => [tenant.id, tenant.name || tenant.account]));
146
+ return (React.createElement("div", { className: "ta-console-card" },
147
+ React.createElement("div", { className: "ta-console-card-head" },
148
+ React.createElement("div", { className: "ta-console-total" },
149
+ 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')),
150
+ 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 }))),
151
+ React.createElement("div", { className: "ta-console-card-controls" },
152
+ React.createElement(Segmented, { label: t('ta.console.metric'), value: metric, onChange: setMetric, choices: [
153
+ { value: 'tokens', label: 'ta.console.tokens' },
154
+ { value: 'cost', label: 'ta.console.cost' },
155
+ ] }),
156
+ React.createElement(Segmented, { label: t('ta.console.range'), value: String(range), onChange: value => setRange(Number(value)), choices: RANGES }))),
157
+ 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 })),
158
+ trend && trend.byModel.length > 0 && (React.createElement(React.Fragment, null,
159
+ React.createElement("span", { className: "ta-console-card-label" }, t('ta.console.byModel')),
160
+ React.createElement(Shares, { metric: metric, total: metric === 'tokens'
161
+ ? trend.byModel.reduce((sum, row) => sum + row.tokens, 0)
162
+ : trend.byModel.reduce((sum, row) => sum + row.cost, 0), rows: trend.byModel
163
+ .slice(0, 5)
164
+ .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 }); }) }))),
165
+ trend && tenants && trend.byTenant.length > 0 && (React.createElement(React.Fragment, null,
166
+ React.createElement("span", { className: "ta-console-card-label" }, t('ta.console.byAccount')),
167
+ React.createElement("div", { className: "ta-console-shares" }, trend.byTenant.slice(0, 5).map(row => {
168
+ var _a, _b;
169
+ const value = metric === 'tokens' ? row.tokens : row.cost;
170
+ const all = metric === 'tokens'
171
+ ? trend.byTenant.reduce((sum, each) => sum + each.tokens, 0)
172
+ : trend.byTenant.reduce((sum, each) => sum + each.cost, 0);
173
+ 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) },
174
+ React.createElement("span", { className: "ta-console-share-label ta-ellipsis" }, (_a = names.get(row.tenantId)) !== null && _a !== void 0 ? _a : row.tenantId),
175
+ React.createElement(Bar, { share: all > 0 ? Math.round((value / all) * 100) : 0, small: true, part: true }),
176
+ React.createElement("span", { className: "ta-console-share-value" }, metric === 'tokens' ? ConsoleUtil.count(value) : ((_b = ConsoleUtil.cost(value)) !== null && _b !== void 0 ? _b : '—'))));
177
+ })))),
178
+ trend && trend.stale.length > 0 && React.createElement("p", { className: "ta-list-hint" }, t('ta.console.stale', { count: trend.stale.length })),
179
+ total === 0 && trend && React.createElement("p", { className: "ta-list-hint" }, t('ta.console.trendEmpty'))));
180
+ }
181
+ function modeOf(value, nullable) {
182
+ return value === null ? 'none' : value === undefined ? (nullable ? 'inherit' : 'none') : 'set';
183
+ }
184
+ /** A number of a limit: the default's (for an account), none, or one of its own. */
185
+ function NumberLimit({ label, hint, value, base, nullable, readOnly, onChange, }) {
186
+ const t = useT();
187
+ const mode = modeOf(value, nullable);
188
+ const [text, setText] = React.useState(ConsoleUtil.field(value));
189
+ React.useEffect(() => setText(ConsoleUtil.field(value)), [value]);
190
+ const parsed = ConsoleUtil.parse(text);
191
+ return (React.createElement("div", { className: "ta-console-limit" },
192
+ React.createElement("div", { className: "ta-console-limit-text" },
193
+ React.createElement("span", null, label),
194
+ React.createElement("span", { className: "ta-console-limit-hint" }, hint)),
195
+ React.createElement("div", { className: "ta-console-limit-control" },
196
+ React.createElement("select", { className: "ta-input ta-console-select", value: mode, disabled: readOnly, "aria-label": label, onChange: event => {
197
+ const next = event.target.value;
198
+ onChange(next === 'inherit' ? undefined : next === 'none' ? (nullable ? null : undefined) : (parsed !== null && parsed !== void 0 ? parsed : 0));
199
+ if (next === 'set' && parsed === undefined) {
200
+ setText('0');
201
+ }
202
+ } },
203
+ nullable && React.createElement("option", { value: "inherit" }, t('ta.console.limitDefault', { value: base !== null && base !== void 0 ? base : t('ta.console.unlimited') })),
204
+ React.createElement("option", { value: "none" }, t('ta.console.unlimited')),
205
+ React.createElement("option", { value: "set" }, t('ta.console.limitSet'))),
206
+ 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 => {
207
+ setText(event.target.value);
208
+ const next = ConsoleUtil.parse(event.target.value);
209
+ if (next !== undefined && !Number.isNaN(next)) {
210
+ onChange(next);
211
+ }
212
+ } })))));
213
+ }
214
+ /**
215
+ * Limits to change: the gateway's defaults (`nullable` false: a limit is a number or none), or an account's over them
216
+ * (each the default's, none, or its own). Saved as a whole.
217
+ */
218
+ export function LimitsForm({ value, defaults, providers, nullable, readOnly, onSave, }) {
219
+ const t = useT();
220
+ const [draft, setDraft] = React.useState(value);
221
+ const [busy, setBusy] = React.useState(false);
222
+ React.useEffect(() => setDraft(value), [value]);
223
+ const changed = JSON.stringify(draft) !== JSON.stringify(value);
224
+ const set = (change) => setDraft(current => Object.fromEntries(Object.entries({ ...current, ...change }).filter(([, item]) => item !== undefined)));
225
+ const base = (key) => (typeof (defaults === null || defaults === void 0 ? void 0 : defaults[key]) === 'number' ? String(defaults[key]) : undefined);
226
+ const providersMode = draft.providers === null ? 'none' : draft.providers === undefined ? (nullable ? 'inherit' : 'none') : 'set';
227
+ return (React.createElement("div", { className: "ta-console-card ta-console-limits" },
228
+ 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 }) }),
229
+ 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 }) }),
230
+ 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 }) }),
231
+ React.createElement("div", { className: "ta-console-limit" },
232
+ React.createElement("div", { className: "ta-console-limit-text" },
233
+ React.createElement("span", null, t('ta.console.providersAllowed')),
234
+ React.createElement("span", { className: "ta-console-limit-hint" }, t('ta.console.providersAllowedHint'))),
235
+ React.createElement("div", { className: "ta-console-limit-control" },
236
+ React.createElement("select", { className: "ta-input ta-console-select", value: providersMode, disabled: readOnly, "aria-label": t('ta.console.providersAllowed'), onChange: event => {
237
+ const next = event.target.value;
238
+ set({
239
+ providers: next === 'inherit' ? undefined : next === 'none' ? (nullable ? null : undefined) : providers.map(provider => provider.id),
240
+ });
241
+ } },
242
+ 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') }))),
243
+ React.createElement("option", { value: "none" }, t('ta.console.allProviders')),
244
+ React.createElement("option", { value: "set" }, t('ta.console.someProviders'))))),
245
+ providersMode === 'set' && (React.createElement("div", { className: "ta-console-chips" }, providers.map(provider => {
246
+ var _a;
247
+ var _b;
248
+ const on = (_b = (_a = draft.providers) === null || _a === void 0 ? void 0 : _a.includes(provider.id)) !== null && _b !== void 0 ? _b : false;
249
+ 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({
250
+ 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],
251
+ }); } }, provider.name));
252
+ }))),
253
+ React.createElement("div", { className: "ta-console-limit" },
254
+ React.createElement("div", { className: "ta-console-limit-text" },
255
+ React.createElement("span", null, t('ta.console.ownService')),
256
+ React.createElement("span", { className: "ta-console-limit-hint" }, t('ta.console.ownServiceHint'))),
257
+ React.createElement("div", { className: "ta-console-limit-control" },
258
+ 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' }) },
259
+ 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') }))),
260
+ React.createElement("option", { value: "yes" }, t('ta.console.yes')),
261
+ React.createElement("option", { value: "no" }, t('ta.console.no'))))),
262
+ !readOnly && (React.createElement("div", { className: "ta-console-actions ta-console-form-actions" },
263
+ React.createElement("button", { type: "button", className: "ta-button", disabled: !changed || busy, onClick: () => setDraft(value) }, t('ta.console.reset')),
264
+ React.createElement("button", { type: "button", className: "ta-button ta-primary", disabled: !changed ||
265
+ busy ||
266
+ [draft.freeMinutes, draft.promptsPerMinute, draft.connections].some(item => typeof item === 'number' && Number.isNaN(item)), onClick: () => {
267
+ setBusy(true);
268
+ void onSave(draft).finally(() => setBusy(false));
269
+ } }, busy ? React.createElement("span", { className: "ta-spinner" }) : t('ta.console.save'))))));
270
+ }
271
+ //# 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, 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