@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.
- package/esm/browser/components/access-view.d.ts +6 -0
- package/esm/browser/components/access-view.js +4 -4
- package/esm/browser/components/app-view.js +11 -1
- package/esm/browser/components/chat-list.d.ts +3 -1
- package/esm/browser/components/chat-list.js +9 -4
- package/esm/browser/components/chat-seen.d.ts +7 -0
- package/esm/browser/components/chat-seen.js +57 -10
- package/esm/browser/components/environment-view.js +59 -3
- package/esm/browser/components/folder-picker.js +3 -3
- package/esm/browser/components/host-tag.js +2 -2
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/remote-hosts.js +66 -5
- package/esm/browser/components/settings-parts.js +4 -1
- package/esm/browser/extension/icons.js +23 -4
- package/esm/browser/extension/web-extension-protocol.d.ts +6 -0
- package/esm/browser/extension/web-extensions.d.ts +3 -0
- package/esm/browser/extension/web-extensions.js +7 -0
- package/esm/browser/gateway/console-extension.d.ts +20 -0
- package/esm/browser/gateway/console-extension.js +75 -0
- package/esm/browser/gateway/console-parts.d.ts +64 -0
- package/esm/browser/gateway/console-parts.js +278 -0
- package/esm/browser/gateway/console-tenant.d.ts +22 -0
- package/esm/browser/gateway/console-tenant.js +286 -0
- package/esm/browser/gateway/console-util.d.ts +59 -0
- package/esm/browser/gateway/console-util.js +187 -0
- package/esm/browser/gateway/console-view.d.ts +2 -0
- package/esm/browser/gateway/console-view.js +226 -0
- package/esm/browser/i18n/locales.d.ts +201 -3
- package/esm/browser/i18n/messages-ja.js +198 -0
- package/esm/browser/i18n/messages-zh-tw.js +198 -0
- package/esm/browser/i18n/messages.d.ts +198 -0
- package/esm/browser/i18n/messages.js +396 -0
- package/esm/browser/index.d.ts +3 -0
- package/esm/browser/index.js +3 -0
- package/esm/browser/style/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +141 -0
- package/lib/browser/components/access-view.d.ts +6 -0
- package/lib/browser/components/access-view.js +5 -4
- package/lib/browser/components/app-view.js +11 -1
- package/lib/browser/components/chat-list.d.ts +3 -1
- package/lib/browser/components/chat-list.js +9 -4
- package/lib/browser/components/chat-seen.d.ts +7 -0
- package/lib/browser/components/chat-seen.js +57 -10
- package/lib/browser/components/environment-view.js +58 -2
- package/lib/browser/components/folder-picker.js +2 -2
- package/lib/browser/components/host-tag.js +1 -1
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/remote-hosts.js +65 -4
- package/lib/browser/components/settings-parts.js +4 -1
- package/lib/browser/extension/icons.js +22 -3
- package/lib/browser/extension/web-extension-protocol.d.ts +6 -0
- package/lib/browser/extension/web-extensions.d.ts +3 -0
- package/lib/browser/extension/web-extensions.js +7 -0
- package/lib/browser/gateway/console-extension.d.ts +21 -0
- package/lib/browser/gateway/console-extension.js +111 -0
- package/lib/browser/gateway/console-parts.d.ts +65 -0
- package/lib/browser/gateway/console-parts.js +322 -0
- package/lib/browser/gateway/console-tenant.d.ts +23 -0
- package/lib/browser/gateway/console-tenant.js +327 -0
- package/lib/browser/gateway/console-util.d.ts +60 -0
- package/lib/browser/gateway/console-util.js +190 -0
- package/lib/browser/gateway/console-view.d.ts +3 -0
- package/lib/browser/gateway/console-view.js +262 -0
- package/lib/browser/i18n/locales.d.ts +201 -3
- package/lib/browser/i18n/messages-ja.js +198 -0
- package/lib/browser/i18n/messages-zh-tw.js +198 -0
- package/lib/browser/i18n/messages.d.ts +198 -0
- package/lib/browser/i18n/messages.js +396 -0
- package/lib/browser/index.d.ts +3 -0
- package/lib/browser/index.js +3 -0
- package/lib/browser/style/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +141 -0
- package/package.json +7 -7
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { TaGatewayConsole, TaGatewayTenant, TaQuotaState, TaUsageTrend } from '@celljs/ta-protocol';
|
|
2
|
+
/** A bar of a trend: an hour or a day of the page's time zone. */
|
|
3
|
+
export interface TrendPoint {
|
|
4
|
+
/** Its start. */
|
|
5
|
+
at: number;
|
|
6
|
+
tokens: number;
|
|
7
|
+
input: number;
|
|
8
|
+
output: number;
|
|
9
|
+
cost: number;
|
|
10
|
+
turns: number;
|
|
11
|
+
}
|
|
12
|
+
export type TrendRange = 1 | 7 | 30;
|
|
13
|
+
export type TrendMetric = 'tokens' | 'cost';
|
|
14
|
+
export type AccountFilter = 'all' | 'running' | 'working' | 'limited' | 'admins';
|
|
15
|
+
export type AccountSort = 'active' | 'minutes' | 'name';
|
|
16
|
+
export declare namespace ConsoleUtil {
|
|
17
|
+
/** 512 MB, 1.5 GB: as a person reads an amount of memory. */
|
|
18
|
+
function bytes(value: number): string;
|
|
19
|
+
/** The share of the limit in use, 0 to 100; undefined without both. */
|
|
20
|
+
function share(used?: number, limit?: number): number | undefined;
|
|
21
|
+
/** The class of a bar that fills: amber from 70%, red from 90%. */
|
|
22
|
+
function tone(share: number): string;
|
|
23
|
+
/** Whether the query is in its name, its account or where it runs. */
|
|
24
|
+
function matches(tenant: TaGatewayTenant, query: string): boolean;
|
|
25
|
+
function filter(tenant: TaGatewayTenant, by: AccountFilter): boolean;
|
|
26
|
+
function sort(tenants: TaGatewayTenant[], by: AccountSort): TaGatewayTenant[];
|
|
27
|
+
/** The free minutes of the month in use, 0 to 100, when there is a limit. */
|
|
28
|
+
function minutesShare(quota: TaQuotaState): number | undefined;
|
|
29
|
+
function counts(info: TaGatewayConsole): {
|
|
30
|
+
accounts: number;
|
|
31
|
+
running: number;
|
|
32
|
+
connections: number;
|
|
33
|
+
working: number;
|
|
34
|
+
limited: number;
|
|
35
|
+
};
|
|
36
|
+
/** 12.3k, 4.5M: as a person reads a count of tokens. */
|
|
37
|
+
function count(value: number): string;
|
|
38
|
+
/** $0.42, $12: what a model's prices made; none for nothing. */
|
|
39
|
+
function cost(value: number): string | undefined;
|
|
40
|
+
/** 1 h 20 min, 45 min: minutes as a person reads them. */
|
|
41
|
+
function minutes(value: number): string;
|
|
42
|
+
/** The last folder of a path: where a conversation works. */
|
|
43
|
+
function folder(cwd: string): string;
|
|
44
|
+
/** 3 minutes ago, yesterday: in the language of the page. */
|
|
45
|
+
function ago(time: number, language: string, now?: number): string;
|
|
46
|
+
/** Where a link of the gateway goes: its public address, else the one the page was loaded from. */
|
|
47
|
+
function link(path: string, publicUrl: string | undefined, origin: string): string;
|
|
48
|
+
/** The start of the day of `time` in the page's time zone. */
|
|
49
|
+
function dayStart(time: number): number;
|
|
50
|
+
/**
|
|
51
|
+
* The bars of a trend: the last 24 hours by hour, else the last days by day of the page's time zone, today last;
|
|
52
|
+
* those with nothing are there too, at zero.
|
|
53
|
+
*/
|
|
54
|
+
function points(trend: TaUsageTrend, range: TrendRange, now?: number): TrendPoint[];
|
|
55
|
+
/** A number of a limit as a field holds it: empty for none. */
|
|
56
|
+
function field(value: number | null | undefined): string;
|
|
57
|
+
/** What a field of a limit says: a whole number, none (empty), or wrong (NaN). */
|
|
58
|
+
function parse(text: string): number | undefined;
|
|
59
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
const HOUR = 3600000;
|
|
2
|
+
export var ConsoleUtil;
|
|
3
|
+
(function (ConsoleUtil) {
|
|
4
|
+
/** 512 MB, 1.5 GB: as a person reads an amount of memory. */
|
|
5
|
+
function bytes(value) {
|
|
6
|
+
if (value >= 1024 ** 3) {
|
|
7
|
+
return `${(value / 1024 ** 3).toFixed(value >= 10 * 1024 ** 3 ? 0 : 1)} GB`;
|
|
8
|
+
}
|
|
9
|
+
return `${Math.max(1, Math.round(value / 1024 ** 2))} MB`;
|
|
10
|
+
}
|
|
11
|
+
ConsoleUtil.bytes = bytes;
|
|
12
|
+
/** The share of the limit in use, 0 to 100; undefined without both. */
|
|
13
|
+
function share(used, limit) {
|
|
14
|
+
if (used === undefined || limit === undefined) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
return limit <= 0 ? 100 : Math.min(100, Math.round((used / limit) * 100));
|
|
18
|
+
}
|
|
19
|
+
ConsoleUtil.share = share;
|
|
20
|
+
/** The class of a bar that fills: amber from 70%, red from 90%. */
|
|
21
|
+
function tone(share) {
|
|
22
|
+
return share >= 90 ? 'ta-high' : share >= 70 ? 'ta-warm' : '';
|
|
23
|
+
}
|
|
24
|
+
ConsoleUtil.tone = tone;
|
|
25
|
+
/** Whether the query is in its name, its account or where it runs. */
|
|
26
|
+
function matches(tenant, query) {
|
|
27
|
+
const words = query.trim().toLowerCase();
|
|
28
|
+
return !words || [tenant.name, tenant.account, tenant.environment.name].some(text => text === null || text === void 0 ? void 0 : text.toLowerCase().includes(words));
|
|
29
|
+
}
|
|
30
|
+
ConsoleUtil.matches = matches;
|
|
31
|
+
function filter(tenant, by) {
|
|
32
|
+
var _a;
|
|
33
|
+
var _b, _c, _d;
|
|
34
|
+
switch (by) {
|
|
35
|
+
case 'running':
|
|
36
|
+
return tenant.environment.status === 'running';
|
|
37
|
+
case 'working':
|
|
38
|
+
return ((_b = (_a = tenant.agents) === null || _a === void 0 ? void 0 : _a.working) !== null && _b !== void 0 ? _b : 0) > 0;
|
|
39
|
+
case 'limited':
|
|
40
|
+
return (!!tenant.quota.blocked || ((_c = minutesShare(tenant.quota)) !== null && _c !== void 0 ? _c : 0) >= 80 || ((_d = share(tenant.quota.tokens.used, tenant.quota.tokens.limit)) !== null && _d !== void 0 ? _d : 0) >= 80);
|
|
41
|
+
case 'admins':
|
|
42
|
+
return tenant.role !== 'member';
|
|
43
|
+
default:
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
ConsoleUtil.filter = filter;
|
|
48
|
+
function sort(tenants, by) {
|
|
49
|
+
const name = (tenant) => (tenant.name || tenant.account).toLowerCase();
|
|
50
|
+
return [...tenants].sort((a, b) => { var _a, _b; return by === 'name'
|
|
51
|
+
? name(a).localeCompare(name(b))
|
|
52
|
+
: by === 'minutes'
|
|
53
|
+
? b.quota.minutes.used - a.quota.minutes.used
|
|
54
|
+
: ((_a = b.lastActiveAt) !== null && _a !== void 0 ? _a : b.createdAt) - ((_b = a.lastActiveAt) !== null && _b !== void 0 ? _b : a.createdAt); });
|
|
55
|
+
}
|
|
56
|
+
ConsoleUtil.sort = sort;
|
|
57
|
+
/** The free minutes of the month in use, 0 to 100, when there is a limit. */
|
|
58
|
+
function minutesShare(quota) {
|
|
59
|
+
const { used, limit, bonus } = quota.minutes;
|
|
60
|
+
return limit === undefined ? undefined : share(used, limit + bonus);
|
|
61
|
+
}
|
|
62
|
+
ConsoleUtil.minutesShare = minutesShare;
|
|
63
|
+
function counts(info) {
|
|
64
|
+
return {
|
|
65
|
+
accounts: info.tenants.length,
|
|
66
|
+
running: info.tenants.filter(tenant => tenant.environment.status === 'running').length,
|
|
67
|
+
connections: info.tenants.reduce((sum, tenant) => sum + tenant.connections, 0),
|
|
68
|
+
working: info.tenants.reduce((sum, tenant) => { var _a; var _b; return sum + ((_b = (_a = tenant.agents) === null || _a === void 0 ? void 0 : _a.working) !== null && _b !== void 0 ? _b : 0); }, 0),
|
|
69
|
+
limited: info.tenants.filter(tenant => !!tenant.quota.blocked).length,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
ConsoleUtil.counts = counts;
|
|
73
|
+
/** 12.3k, 4.5M: as a person reads a count of tokens. */
|
|
74
|
+
function count(value) {
|
|
75
|
+
if (value >= 1e9) {
|
|
76
|
+
return `${(value / 1e9).toFixed(1)}B`;
|
|
77
|
+
}
|
|
78
|
+
if (value >= 1e6) {
|
|
79
|
+
return `${(value / 1e6).toFixed(value >= 1e7 ? 0 : 1)}M`;
|
|
80
|
+
}
|
|
81
|
+
if (value >= 1e3) {
|
|
82
|
+
return `${(value / 1e3).toFixed(value >= 1e4 ? 0 : 1)}k`;
|
|
83
|
+
}
|
|
84
|
+
return String(Math.round(value));
|
|
85
|
+
}
|
|
86
|
+
ConsoleUtil.count = count;
|
|
87
|
+
/** $0.42, $12: what a model's prices made; none for nothing. */
|
|
88
|
+
function cost(value) {
|
|
89
|
+
if (value <= 0) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
return value < 0.01 ? '<$0.01' : `$${value.toFixed(value >= 10 ? 0 : 2)}`;
|
|
93
|
+
}
|
|
94
|
+
ConsoleUtil.cost = cost;
|
|
95
|
+
/** 1 h 20 min, 45 min: minutes as a person reads them. */
|
|
96
|
+
function minutes(value) {
|
|
97
|
+
const hours = Math.floor(value / 60);
|
|
98
|
+
const rest = value % 60;
|
|
99
|
+
return hours > 0 ? (rest > 0 ? `${hours} h ${rest} min` : `${hours} h`) : `${value} min`;
|
|
100
|
+
}
|
|
101
|
+
ConsoleUtil.minutes = minutes;
|
|
102
|
+
/** The last folder of a path: where a conversation works. */
|
|
103
|
+
function folder(cwd) {
|
|
104
|
+
var _a;
|
|
105
|
+
return (_a = cwd.split(/[\\/]/).filter(Boolean).pop()) !== null && _a !== void 0 ? _a : cwd;
|
|
106
|
+
}
|
|
107
|
+
ConsoleUtil.folder = folder;
|
|
108
|
+
/** 3 minutes ago, yesterday: in the language of the page. */
|
|
109
|
+
function ago(time, language, now = Date.now()) {
|
|
110
|
+
const seconds = Math.round((time - now) / 1000);
|
|
111
|
+
const format = new Intl.RelativeTimeFormat(language, { numeric: 'auto' });
|
|
112
|
+
const units = [
|
|
113
|
+
['day', 86400],
|
|
114
|
+
['hour', 3600],
|
|
115
|
+
['minute', 60],
|
|
116
|
+
];
|
|
117
|
+
for (const [unit, size] of units) {
|
|
118
|
+
if (Math.abs(seconds) >= size) {
|
|
119
|
+
return format.format(Math.round(seconds / size), unit);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return format.format(0, 'second');
|
|
123
|
+
}
|
|
124
|
+
ConsoleUtil.ago = ago;
|
|
125
|
+
/** Where a link of the gateway goes: its public address, else the one the page was loaded from. */
|
|
126
|
+
function link(path, publicUrl, origin) {
|
|
127
|
+
return `${(publicUrl !== null && publicUrl !== void 0 ? publicUrl : origin).replace(/\/+$/, '')}${path}`;
|
|
128
|
+
}
|
|
129
|
+
ConsoleUtil.link = link;
|
|
130
|
+
/** The start of the day of `time` in the page's time zone. */
|
|
131
|
+
function dayStart(time) {
|
|
132
|
+
const date = new Date(time);
|
|
133
|
+
date.setHours(0, 0, 0, 0);
|
|
134
|
+
return date.getTime();
|
|
135
|
+
}
|
|
136
|
+
ConsoleUtil.dayStart = dayStart;
|
|
137
|
+
/**
|
|
138
|
+
* The bars of a trend: the last 24 hours by hour, else the last days by day of the page's time zone, today last;
|
|
139
|
+
* those with nothing are there too, at zero.
|
|
140
|
+
*/
|
|
141
|
+
function points(trend, range, now = Date.now()) {
|
|
142
|
+
const empty = (at) => ({ at, tokens: 0, input: 0, output: 0, cost: 0, turns: 0 });
|
|
143
|
+
const slots = [];
|
|
144
|
+
if (range === 1) {
|
|
145
|
+
const last = Math.floor(now / HOUR) * HOUR;
|
|
146
|
+
for (let index = 23; index >= 0; index--) {
|
|
147
|
+
slots.push(empty(last - index * HOUR));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const today = dayStart(now);
|
|
152
|
+
for (let index = range - 1; index >= 0; index--) {
|
|
153
|
+
const date = new Date(today);
|
|
154
|
+
date.setDate(date.getDate() - index);
|
|
155
|
+
slots.push(empty(date.getTime()));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const slotOf = new Map(slots.map(slot => [slot.at, slot]));
|
|
159
|
+
for (const hour of trend.hours) {
|
|
160
|
+
const slot = slotOf.get(range === 1 ? hour.at : dayStart(hour.at));
|
|
161
|
+
if (slot) {
|
|
162
|
+
slot.tokens += hour.tokens;
|
|
163
|
+
slot.input += hour.input;
|
|
164
|
+
slot.output += hour.output;
|
|
165
|
+
slot.cost += hour.cost;
|
|
166
|
+
slot.turns += hour.turns;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return slots;
|
|
170
|
+
}
|
|
171
|
+
ConsoleUtil.points = points;
|
|
172
|
+
/** A number of a limit as a field holds it: empty for none. */
|
|
173
|
+
function field(value) {
|
|
174
|
+
return typeof value === 'number' ? String(value) : '';
|
|
175
|
+
}
|
|
176
|
+
ConsoleUtil.field = field;
|
|
177
|
+
/** What a field of a limit says: a whole number, none (empty), or wrong (NaN). */
|
|
178
|
+
function parse(text) {
|
|
179
|
+
const trimmed = text.trim();
|
|
180
|
+
if (!trimmed) {
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
return /^\d+$/.test(trimmed) ? Number(trimmed) : Number.NaN;
|
|
184
|
+
}
|
|
185
|
+
ConsoleUtil.parse = parse;
|
|
186
|
+
})(ConsoleUtil || (ConsoleUtil = {}));
|
|
187
|
+
//# sourceMappingURL=console-util.js.map
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { Bot, ChevronLeft, Copy, RefreshCw, Search, Server, ShieldCheck, UserPlus } from 'lucide-react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useBusy } from '../components/busy.js';
|
|
4
|
+
import { Callout } from '../components/callout.js';
|
|
5
|
+
import { EmptyState } from '../components/empty-state.js';
|
|
6
|
+
import { Icon, IconButton } from '../components/icon.js';
|
|
7
|
+
import { ListGroup, ListRow } from '../components/list-rows.js';
|
|
8
|
+
import { PhoneStack } from '../components/phone-shell.js';
|
|
9
|
+
import { Segmented } from '../components/settings-controls.js';
|
|
10
|
+
import { WorkbenchToggle } from '../components/workbench-toggle.js';
|
|
11
|
+
import { useNotices, useWebExtensions, useWorkbench } from '../hooks.js';
|
|
12
|
+
import { useLanguage, useT } from '../i18n/use-t.js';
|
|
13
|
+
import { LimitsForm, REFRESH_MS, SectionTitle, Stat, TrendCard, usePolled } from './console-parts.js';
|
|
14
|
+
import { TenantDetail, TenantRow } from './console-tenant.js';
|
|
15
|
+
import { ConsoleUtil } from './console-util.js';
|
|
16
|
+
const FILTERS = [
|
|
17
|
+
{ value: 'all', label: 'ta.console.filterAll' },
|
|
18
|
+
{ value: 'running', label: 'ta.console.filterRunning' },
|
|
19
|
+
{ value: 'working', label: 'ta.console.filterWorking' },
|
|
20
|
+
{ value: 'limited', label: 'ta.console.filterLimited' },
|
|
21
|
+
{ value: 'admins', label: 'ta.console.filterAdmins' },
|
|
22
|
+
];
|
|
23
|
+
const ACTIONS = {
|
|
24
|
+
startTenant: 'ta.console.auditStart',
|
|
25
|
+
stopTenant: 'ta.console.auditStop',
|
|
26
|
+
restartTenant: 'ta.console.auditRestart',
|
|
27
|
+
getTenantLogs: 'ta.console.auditLogs',
|
|
28
|
+
getAgentActivity: 'ta.console.auditActivity',
|
|
29
|
+
createSignInLink: 'ta.console.auditInvite',
|
|
30
|
+
setTenantLimits: 'ta.console.auditLimits',
|
|
31
|
+
grantMinutes: 'ta.console.auditGrant',
|
|
32
|
+
setSuspended: 'ta.console.auditSuspend',
|
|
33
|
+
setDefaultLimits: 'ta.console.auditDefaults',
|
|
34
|
+
setRole: 'ta.console.auditRole',
|
|
35
|
+
allow: 'ta.console.auditAllow',
|
|
36
|
+
dismiss: 'ta.console.auditDismiss',
|
|
37
|
+
disallow: 'ta.console.auditDisallow',
|
|
38
|
+
};
|
|
39
|
+
/** A link of the gateway that lets a new account in, made here, as `ta gateway link` prints. */
|
|
40
|
+
function Invite({ info }) {
|
|
41
|
+
const t = useT();
|
|
42
|
+
const [, bench] = useWorkbench();
|
|
43
|
+
const [, notices] = useNotices();
|
|
44
|
+
const [invite, setInvite] = React.useState();
|
|
45
|
+
const start = async () => {
|
|
46
|
+
var _a;
|
|
47
|
+
const account = (_a = (await notices.input({ title: t('ta.console.inviteTitle'), placeholder: t('ta.console.invitePlaceholder') }))) === null || _a === void 0 ? void 0 : _a.trim();
|
|
48
|
+
if (!account) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const path = await bench.gateway.createSignInLink(account);
|
|
53
|
+
setInvite({ account, url: ConsoleUtil.link(path, info.publicUrl, location.origin) });
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
notices.error(error);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return invite ? (React.createElement("div", { className: "ta-console-invite" },
|
|
60
|
+
React.createElement("span", { className: "ta-console-section-title" }, t('ta.console.inviteLink', { account: invite.account })),
|
|
61
|
+
React.createElement("code", { className: "ta-console-mono" }, invite.url),
|
|
62
|
+
React.createElement("span", { className: "ta-list-hint" }, t('ta.console.inviteHint')),
|
|
63
|
+
React.createElement("div", { className: "ta-console-actions" },
|
|
64
|
+
React.createElement("button", { type: "button", className: "ta-button ta-primary", onClick: () => { var _a; return void ((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(invite.url).then(() => notices.notify(t('ta.console.copied'), { level: 'success' })).catch(() => undefined)); } },
|
|
65
|
+
React.createElement(Icon, { icon: Copy, size: 15 }),
|
|
66
|
+
" ",
|
|
67
|
+
t('ta.console.copy')),
|
|
68
|
+
React.createElement("button", { type: "button", className: "ta-button", onClick: () => setInvite(undefined) }, t('ta.relay.done'))))) : (React.createElement(ListGroup, null,
|
|
69
|
+
React.createElement(ListRow, { icon: UserPlus, label: t('ta.console.invite'), onClick: start, action: true })));
|
|
70
|
+
}
|
|
71
|
+
function Overview({ info, onTenant, onTab }) {
|
|
72
|
+
const t = useT();
|
|
73
|
+
const [, host] = useWebExtensions();
|
|
74
|
+
const counts = ConsoleUtil.counts(info);
|
|
75
|
+
return (React.createElement(React.Fragment, null,
|
|
76
|
+
React.createElement("div", { className: "ta-console-stats" },
|
|
77
|
+
React.createElement(Stat, { value: counts.accounts, label: t('ta.console.accounts'), onClick: () => onTab('accounts') }),
|
|
78
|
+
React.createElement(Stat, { value: counts.running, label: t('ta.console.running'), tone: counts.running ? 'good' : undefined }),
|
|
79
|
+
React.createElement(Stat, { value: counts.working, label: t('ta.console.agentsWorking'), tone: counts.working ? 'good' : undefined }),
|
|
80
|
+
React.createElement(Stat, { value: counts.connections, label: t('ta.console.connectionsLabel') }),
|
|
81
|
+
React.createElement(Stat, { value: info.requests, label: t('ta.console.requests'), tone: info.requests > 0 ? 'warn' : undefined, onClick: info.requests > 0 ? () => host.openSettings('access') : undefined, title: t('ta.access.title') })),
|
|
82
|
+
counts.limited > 0 && (React.createElement(Callout, { level: "warning", action: React.createElement("button", { type: "button", className: "ta-link-button", onClick: () => onTab('accounts') }, t('ta.console.view')) }, t('ta.console.limitedCount', { count: counts.limited }))),
|
|
83
|
+
React.createElement(SectionTitle, null, t('ta.console.trend')),
|
|
84
|
+
React.createElement(TrendCard, { tenants: info.tenants, onTenant: onTenant }),
|
|
85
|
+
React.createElement(SectionTitle, null, t('ta.console.sandboxes')),
|
|
86
|
+
React.createElement(ListGroup, null, info.providers.map(provider => (React.createElement("div", { key: provider.id, className: "ta-console-provider" },
|
|
87
|
+
React.createElement(Icon, { icon: Server, size: 18, className: "ta-list-icon" }),
|
|
88
|
+
React.createElement("span", { className: "ta-console-tenant-text" },
|
|
89
|
+
React.createElement("span", { className: "ta-console-tenant-name ta-ellipsis" },
|
|
90
|
+
provider.name,
|
|
91
|
+
provider.default && React.createElement("span", { className: "ta-console-chip" }, t('ta.console.default'))),
|
|
92
|
+
React.createElement("span", { className: "ta-console-tenant-state" }, t('ta.console.providerTenants', { type: provider.type, count: provider.tenants }))))))),
|
|
93
|
+
React.createElement("p", { className: "ta-list-hint" },
|
|
94
|
+
info.own ? t('ta.console.ownAllowed') : t('ta.console.ownNot'),
|
|
95
|
+
" \u00B7",
|
|
96
|
+
' ',
|
|
97
|
+
info.idleMinutes > 0 ? t('ta.console.idle', { minutes: info.idleMinutes }) : t('ta.console.idleNever'))));
|
|
98
|
+
}
|
|
99
|
+
function Accounts({ info, onOpen }) {
|
|
100
|
+
const t = useT();
|
|
101
|
+
const [query, setQuery] = React.useState('');
|
|
102
|
+
const [filter, setFilter] = React.useState('all');
|
|
103
|
+
const [sort, setSort] = React.useState('active');
|
|
104
|
+
const shown = ConsoleUtil.sort(info.tenants.filter(tenant => ConsoleUtil.matches(tenant, query) && ConsoleUtil.filter(tenant, filter)), sort);
|
|
105
|
+
return (React.createElement(React.Fragment, null,
|
|
106
|
+
React.createElement(Invite, { info: info }),
|
|
107
|
+
React.createElement("div", { className: "ta-console-toolbar" },
|
|
108
|
+
React.createElement("label", { className: "ta-field ta-console-search" },
|
|
109
|
+
React.createElement(Icon, { icon: Search, size: 15 }),
|
|
110
|
+
React.createElement("input", { value: query, placeholder: t('ta.console.search'), "aria-label": t('ta.console.search'), onChange: event => setQuery(event.target.value) })),
|
|
111
|
+
React.createElement("select", { className: "ta-input ta-console-select", value: sort, "aria-label": t('ta.console.sort'), onChange: event => setSort(event.target.value) },
|
|
112
|
+
React.createElement("option", { value: "active" }, t('ta.console.sortActive')),
|
|
113
|
+
React.createElement("option", { value: "minutes" }, t('ta.console.sortMinutes')),
|
|
114
|
+
React.createElement("option", { value: "name" }, t('ta.console.sortName')))),
|
|
115
|
+
React.createElement("div", { className: "ta-console-chips" }, FILTERS.map(each => {
|
|
116
|
+
const count = info.tenants.filter(tenant => ConsoleUtil.filter(tenant, each.value)).length;
|
|
117
|
+
return (React.createElement("button", { key: each.value, type: "button", className: filter === each.value ? 'ta-console-chip-toggle ta-on' : 'ta-console-chip-toggle', "aria-pressed": filter === each.value, onClick: () => setFilter(each.value) },
|
|
118
|
+
t(each.label),
|
|
119
|
+
" ",
|
|
120
|
+
React.createElement("span", { className: "ta-console-chip-count" }, count)));
|
|
121
|
+
})),
|
|
122
|
+
info.tenants.length === 0 ? (React.createElement(EmptyState, { title: t('ta.console.empty'), hint: t('ta.console.emptyHint') })) : shown.length === 0 ? (React.createElement(EmptyState, { compact: true, title: t('ta.console.noMatch') })) : (React.createElement("div", { className: "ta-list-group" }, shown.map(tenant => (React.createElement(TenantRow, { key: tenant.id, tenant: tenant, onOpen: () => onOpen(tenant.id) })))))));
|
|
123
|
+
}
|
|
124
|
+
function Audit() {
|
|
125
|
+
const t = useT();
|
|
126
|
+
const language = useLanguage();
|
|
127
|
+
const [, bench] = useWorkbench();
|
|
128
|
+
const { value } = usePolled(() => bench.gateway.getAudit(50), 'audit', REFRESH_MS * 3);
|
|
129
|
+
if (!value) {
|
|
130
|
+
return React.createElement("span", { className: "ta-spinner ta-later ta-console-loading" });
|
|
131
|
+
}
|
|
132
|
+
if (value.length === 0) {
|
|
133
|
+
return React.createElement("p", { className: "ta-list-hint" }, t('ta.console.auditNone'));
|
|
134
|
+
}
|
|
135
|
+
return (React.createElement("div", { className: "ta-list-group" }, value.map((entry, index) => (React.createElement("div", { key: `${entry.at}-${index}`, className: "ta-console-audit" },
|
|
136
|
+
React.createElement("span", { className: "ta-console-audit-text ta-ellipsis" },
|
|
137
|
+
React.createElement("strong", null, entry.actor),
|
|
138
|
+
" ",
|
|
139
|
+
ACTIONS[entry.action] ? t(ACTIONS[entry.action]) : entry.action,
|
|
140
|
+
entry.target && React.createElement("span", { className: "ta-console-account" },
|
|
141
|
+
" ",
|
|
142
|
+
entry.target),
|
|
143
|
+
entry.detail && React.createElement("span", { className: "ta-console-mono ta-console-audit-detail" },
|
|
144
|
+
" ",
|
|
145
|
+
entry.detail)),
|
|
146
|
+
React.createElement("span", { className: "ta-console-activity-time" }, ConsoleUtil.ago(entry.at, language)))))));
|
|
147
|
+
}
|
|
148
|
+
function Policy({ info, onChanged }) {
|
|
149
|
+
const t = useT();
|
|
150
|
+
const [, bench] = useWorkbench();
|
|
151
|
+
const [, notices] = useNotices();
|
|
152
|
+
const owner = info.role === 'owner';
|
|
153
|
+
return (React.createElement(React.Fragment, null,
|
|
154
|
+
React.createElement(SectionTitle, null, t('ta.console.defaults')),
|
|
155
|
+
React.createElement("p", { className: "ta-list-hint" }, t(owner ? 'ta.console.defaultsHint' : 'ta.console.defaultsReadOnly')),
|
|
156
|
+
React.createElement(LimitsForm, { value: info.policy.defaults, providers: info.providers, nullable: false, readOnly: !owner, metered: info.models.length > 0, onSave: limits => bench.gateway
|
|
157
|
+
.setDefaultLimits(limits)
|
|
158
|
+
.then(() => notices.notify(t('ta.console.saved'), { level: 'success' }))
|
|
159
|
+
.then(onChanged)
|
|
160
|
+
.catch(error => notices.error(error)) }),
|
|
161
|
+
React.createElement(SectionTitle, null, t('ta.console.models')),
|
|
162
|
+
info.models.length === 0 ? (React.createElement("p", { className: "ta-list-hint" }, t('ta.console.modelsNone'))) : (React.createElement(React.Fragment, null,
|
|
163
|
+
React.createElement(ListGroup, null, info.models.map(provider => (React.createElement("div", { key: provider.id, className: "ta-console-provider" },
|
|
164
|
+
React.createElement(Icon, { icon: Bot, size: 18, className: "ta-list-icon" }),
|
|
165
|
+
React.createElement("span", { className: "ta-console-tenant-text" },
|
|
166
|
+
React.createElement("span", { className: "ta-console-tenant-name ta-ellipsis" }, provider.name || provider.id),
|
|
167
|
+
React.createElement("span", { className: "ta-console-tenant-state" }, t('ta.console.modelsOf', { api: provider.api, count: provider.models }))))))),
|
|
168
|
+
React.createElement("p", { className: "ta-list-hint" }, t('ta.console.modelsHint')))),
|
|
169
|
+
React.createElement(SectionTitle, null, t('ta.console.managers')),
|
|
170
|
+
React.createElement("div", { className: "ta-list-group" }, info.policy.admins.map(admin => (React.createElement("div", { key: admin.account, className: "ta-console-audit" },
|
|
171
|
+
React.createElement("span", { className: "ta-console-audit-text ta-ellipsis" },
|
|
172
|
+
React.createElement(Icon, { icon: ShieldCheck, size: 15 }),
|
|
173
|
+
" ",
|
|
174
|
+
admin.account),
|
|
175
|
+
React.createElement("span", { className: `ta-console-chip ta-console-role-${admin.role}` }, t(admin.role === 'owner' ? 'ta.console.roleOwner' : 'ta.console.roleAdmin')))))),
|
|
176
|
+
React.createElement("p", { className: "ta-list-hint" }, t('ta.console.managersHint')),
|
|
177
|
+
React.createElement(SectionTitle, null, t('ta.console.audit')),
|
|
178
|
+
React.createElement(Audit, null)));
|
|
179
|
+
}
|
|
180
|
+
export function ConsolePage() {
|
|
181
|
+
var _a;
|
|
182
|
+
const t = useT();
|
|
183
|
+
const language = useLanguage();
|
|
184
|
+
const [, bench] = useWorkbench();
|
|
185
|
+
const { value: info, error, read, readAt } = usePolled(() => bench.gateway.getConsole(), 'console');
|
|
186
|
+
const [tab, setTab] = React.useState('overview');
|
|
187
|
+
const [openId, setOpenId] = React.useState();
|
|
188
|
+
// Kept while the level slides away, so that it does not empty as it goes.
|
|
189
|
+
const [shownId, setShownId] = React.useState();
|
|
190
|
+
const [refreshing, refresh] = useBusy();
|
|
191
|
+
const open = (id) => {
|
|
192
|
+
setShownId(id);
|
|
193
|
+
setOpenId(id);
|
|
194
|
+
};
|
|
195
|
+
const tenant = info === null || info === void 0 ? void 0 : info.tenants.find(each => each.id === shownId);
|
|
196
|
+
const sub = info ? [info.version && `v${info.version}`, (_a = info.publicUrl) === null || _a === void 0 ? void 0 : _a.replace(/^https?:\/\//, '')].filter(Boolean).join(' · ') : '';
|
|
197
|
+
const list = (React.createElement("div", { className: "ta-list-scroll" },
|
|
198
|
+
React.createElement("div", { className: "ta-list-content ta-console-content" },
|
|
199
|
+
error !== undefined && !info && (React.createElement(Callout, { level: "error", action: React.createElement(IconButton, { icon: RefreshCw, label: t('ta.console.refresh'), onClick: () => void read() }) }, t('ta.console.failed'))),
|
|
200
|
+
info && (React.createElement(React.Fragment, null,
|
|
201
|
+
React.createElement(Segmented, { label: t('ta.console.title'), value: tab, onChange: setTab, choices: [
|
|
202
|
+
{ value: 'overview', label: 'ta.console.tabOverview' },
|
|
203
|
+
{ value: 'accounts', label: 'ta.console.tabAccounts' },
|
|
204
|
+
{ value: 'policy', label: 'ta.console.tabPolicy' },
|
|
205
|
+
] }),
|
|
206
|
+
tab === 'overview' && React.createElement(Overview, { info: info, onTenant: open, onTab: setTab }),
|
|
207
|
+
tab === 'accounts' && React.createElement(Accounts, { info: info, onOpen: open }),
|
|
208
|
+
tab === 'policy' && React.createElement(Policy, { info: info, onChanged: read }),
|
|
209
|
+
React.createElement("p", { className: "ta-list-hint ta-console-foot" }, [
|
|
210
|
+
t('ta.console.since', { time: new Date(info.startedAt).toLocaleString(language, { dateStyle: 'medium', timeStyle: 'short' }) }),
|
|
211
|
+
readAt ? t('ta.console.updated', { time: ConsoleUtil.ago(readAt, language) }) : '',
|
|
212
|
+
]
|
|
213
|
+
.filter(Boolean)
|
|
214
|
+
.join(' · ')))),
|
|
215
|
+
!info && error === undefined && React.createElement("span", { className: "ta-spinner ta-later ta-console-loading" }))));
|
|
216
|
+
return (React.createElement("section", { className: "ta-list-page ta-console", "aria-label": t('ta.console.title') },
|
|
217
|
+
React.createElement("header", { className: "ta-main-head ta-list-head ta-wide-only" },
|
|
218
|
+
openId ? React.createElement(IconButton, { icon: ChevronLeft, label: t('ta.back'), onClick: () => setOpenId(undefined) }) : React.createElement("span", { className: "ta-head-spacer" }),
|
|
219
|
+
React.createElement("div", { className: "ta-main-title" },
|
|
220
|
+
React.createElement("span", null, openId && tenant ? tenant.name || tenant.account : t('ta.console.title')),
|
|
221
|
+
!openId && sub && React.createElement("span", { className: "ta-main-sub" }, sub)),
|
|
222
|
+
React.createElement(IconButton, { icon: RefreshCw, label: t('ta.console.refresh'), busy: refreshing, onClick: () => void refresh(read) }),
|
|
223
|
+
React.createElement(WorkbenchToggle, null)),
|
|
224
|
+
React.createElement(PhoneStack, { base: list, top: tenant && info ? React.createElement(TenantDetail, { tenant: tenant, info: info, onChanged: read }) : null, open: openId !== undefined && tenant !== undefined, onClose: () => setOpenId(undefined) })));
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=console-view.js.map
|