@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.
- package/esm/browser/components/access-view.d.ts +6 -0
- package/esm/browser/components/access-view.js +4 -4
- package/esm/browser/components/account-menu.js +8 -1
- package/esm/browser/components/app-view.js +8 -1
- package/esm/browser/components/environment-view.js +9 -2
- package/esm/browser/components/face.js +7 -2
- package/esm/browser/components/gallery.d.ts +9 -0
- package/esm/browser/components/gallery.js +57 -0
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/lightbox.d.ts +8 -1
- package/esm/browser/components/lightbox.js +4 -1
- package/esm/browser/components/markdown.js +6 -1
- package/esm/browser/components/media.d.ts +12 -2
- package/esm/browser/components/media.js +55 -13
- package/esm/browser/components/message-list.js +3 -2
- package/esm/browser/components/notice-center.js +6 -2
- package/esm/browser/components/serve-restart.d.ts +26 -0
- package/esm/browser/components/serve-restart.js +91 -0
- package/esm/browser/components/session-view.js +19 -11
- package/esm/browser/components/settings-parts.js +18 -6
- package/esm/browser/extension/icons.js +3 -1
- 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 +62 -0
- package/esm/browser/gateway/console-parts.js +271 -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 +218 -0
- package/esm/browser/i18n/locales.d.ts +186 -3
- package/esm/browser/i18n/messages-ja.js +183 -0
- package/esm/browser/i18n/messages-zh-tw.js +183 -0
- package/esm/browser/i18n/messages.d.ts +183 -0
- package/esm/browser/i18n/messages.js +366 -0
- package/esm/browser/index.d.ts +3 -0
- package/esm/browser/index.js +3 -0
- package/esm/browser/style/conversation.d.ts +1 -1
- package/esm/browser/style/conversation.js +18 -0
- package/esm/browser/style/layout.d.ts +1 -1
- package/esm/browser/style/layout.js +2 -0
- package/esm/browser/style/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +140 -0
- package/esm/browser/style/shell.d.ts +1 -1
- package/esm/browser/style/shell.js +2 -0
- package/esm/browser/style/surfaces.d.ts +1 -1
- package/esm/browser/style/surfaces.js +1 -0
- package/esm/browser/util/desktop.d.ts +6 -1
- package/esm/browser/util/desktop.js +10 -0
- package/esm/browser/util/gallery.d.ts +18 -0
- package/esm/browser/util/gallery.js +123 -0
- package/esm/browser/util/link.d.ts +8 -0
- package/esm/browser/util/link.js +14 -0
- package/esm/browser/util/markdown.d.ts +11 -0
- package/esm/browser/util/markdown.js +4 -0
- package/esm/browser/util/thumbnail.d.ts +18 -0
- package/esm/browser/util/thumbnail.js +26 -0
- package/esm/browser/workbench-protocol.d.ts +8 -0
- package/esm/browser/workbench.d.ts +16 -0
- package/esm/browser/workbench.js +67 -0
- package/lib/browser/components/access-view.d.ts +6 -0
- package/lib/browser/components/access-view.js +5 -4
- package/lib/browser/components/account-menu.js +7 -0
- package/lib/browser/components/app-view.js +8 -1
- package/lib/browser/components/environment-view.js +9 -2
- package/lib/browser/components/face.js +7 -2
- package/lib/browser/components/gallery.d.ts +10 -0
- package/lib/browser/components/gallery.js +93 -0
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/lightbox.d.ts +8 -1
- package/lib/browser/components/lightbox.js +4 -1
- package/lib/browser/components/markdown.js +6 -1
- package/lib/browser/components/media.d.ts +12 -2
- package/lib/browser/components/media.js +57 -13
- package/lib/browser/components/message-list.js +3 -2
- package/lib/browser/components/notice-center.js +6 -2
- package/lib/browser/components/serve-restart.d.ts +27 -0
- package/lib/browser/components/serve-restart.js +129 -0
- package/lib/browser/components/session-view.js +21 -13
- package/lib/browser/components/settings-parts.js +17 -5
- package/lib/browser/extension/icons.js +2 -0
- 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 +63 -0
- package/lib/browser/gateway/console-parts.js +315 -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 +254 -0
- package/lib/browser/i18n/locales.d.ts +186 -3
- package/lib/browser/i18n/messages-ja.js +183 -0
- package/lib/browser/i18n/messages-zh-tw.js +183 -0
- package/lib/browser/i18n/messages.d.ts +183 -0
- package/lib/browser/i18n/messages.js +366 -0
- package/lib/browser/index.d.ts +3 -0
- package/lib/browser/index.js +3 -0
- package/lib/browser/style/conversation.d.ts +1 -1
- package/lib/browser/style/conversation.js +18 -0
- package/lib/browser/style/layout.d.ts +1 -1
- package/lib/browser/style/layout.js +2 -0
- package/lib/browser/style/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +140 -0
- package/lib/browser/style/shell.d.ts +1 -1
- package/lib/browser/style/shell.js +2 -0
- package/lib/browser/style/surfaces.d.ts +1 -1
- package/lib/browser/style/surfaces.js +1 -0
- package/lib/browser/util/desktop.d.ts +6 -1
- package/lib/browser/util/desktop.js +10 -0
- package/lib/browser/util/gallery.d.ts +19 -0
- package/lib/browser/util/gallery.js +126 -0
- package/lib/browser/util/link.d.ts +8 -0
- package/lib/browser/util/link.js +14 -0
- package/lib/browser/util/markdown.d.ts +11 -0
- package/lib/browser/util/markdown.js +4 -0
- package/lib/browser/util/thumbnail.d.ts +19 -0
- package/lib/browser/util/thumbnail.js +29 -0
- package/lib/browser/workbench-protocol.d.ts +8 -0
- package/lib/browser/workbench.d.ts +16 -0
- package/lib/browser/workbench.js +67 -0
- package/package.json +7 -7
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.REFRESH_MS = void 0;
|
|
37
|
+
exports.usePolled = usePolled;
|
|
38
|
+
exports.SectionTitle = SectionTitle;
|
|
39
|
+
exports.Bar = Bar;
|
|
40
|
+
exports.Meter = Meter;
|
|
41
|
+
exports.Stat = Stat;
|
|
42
|
+
exports.QuotaMeters = QuotaMeters;
|
|
43
|
+
exports.TrendCard = TrendCard;
|
|
44
|
+
exports.LimitsForm = LimitsForm;
|
|
45
|
+
const React = __importStar(require("react"));
|
|
46
|
+
const callout_1 = require("../components/callout");
|
|
47
|
+
const settings_controls_1 = require("../components/settings-controls");
|
|
48
|
+
const hooks_1 = require("../hooks");
|
|
49
|
+
const use_t_1 = require("../i18n/use-t");
|
|
50
|
+
const console_util_1 = require("./console-util");
|
|
51
|
+
/** How often what the console shows is read again while it is seen. */
|
|
52
|
+
exports.REFRESH_MS = 10000;
|
|
53
|
+
/** Reads `load` now and every `every` ms while the page is seen; again when `key` changes. */
|
|
54
|
+
function usePolled(load, key, every = exports.REFRESH_MS) {
|
|
55
|
+
const [value, setValue] = React.useState();
|
|
56
|
+
const [error, setError] = React.useState();
|
|
57
|
+
const [readAt, setReadAt] = React.useState();
|
|
58
|
+
const current = React.useRef(load);
|
|
59
|
+
current.current = load;
|
|
60
|
+
const read = React.useCallback(() => current.current().then(next => {
|
|
61
|
+
setValue(next);
|
|
62
|
+
setError(undefined);
|
|
63
|
+
setReadAt(Date.now());
|
|
64
|
+
}, (cause) => setError(cause.message)), []);
|
|
65
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: read again whenever what is read changes
|
|
66
|
+
React.useEffect(() => {
|
|
67
|
+
setValue(undefined);
|
|
68
|
+
void read();
|
|
69
|
+
const timer = setInterval(() => document.visibilityState === 'visible' && void read(), every);
|
|
70
|
+
return () => clearInterval(timer);
|
|
71
|
+
}, [key, read, every]);
|
|
72
|
+
return { value, error, read, readAt };
|
|
73
|
+
}
|
|
74
|
+
function SectionTitle({ children, action }) {
|
|
75
|
+
return (React.createElement("div", { className: "ta-console-section" },
|
|
76
|
+
React.createElement("span", { className: "ta-console-section-title" }, children),
|
|
77
|
+
action));
|
|
78
|
+
}
|
|
79
|
+
/** A bar that fills: of a limit (amber, then red, as it nears it), or a `part` of a whole, in one color. */
|
|
80
|
+
function Bar({ share, small, part }) {
|
|
81
|
+
return (React.createElement("span", { className: `ta-console-bar${small ? ' ta-console-bar-small' : ''}` },
|
|
82
|
+
React.createElement("span", { className: part ? 'ta-part' : console_util_1.ConsoleUtil.tone(share), style: { width: `${share}%` } })));
|
|
83
|
+
}
|
|
84
|
+
function Meter({ label, value, share, hint }) {
|
|
85
|
+
return (React.createElement("div", { className: "ta-console-meter" },
|
|
86
|
+
React.createElement("div", { className: "ta-console-meter-text" },
|
|
87
|
+
React.createElement("span", null, label),
|
|
88
|
+
React.createElement("span", { className: "ta-console-meter-value" }, value)),
|
|
89
|
+
share !== undefined && React.createElement(Bar, { share: share }),
|
|
90
|
+
hint && React.createElement("span", { className: "ta-console-meter-hint" }, hint)));
|
|
91
|
+
}
|
|
92
|
+
function Stat({ value, label, tone, onClick, title, }) {
|
|
93
|
+
const body = (React.createElement(React.Fragment, null,
|
|
94
|
+
React.createElement("span", { className: `ta-console-stat-value${tone ? ` ta-${tone}` : ''}` }, value),
|
|
95
|
+
React.createElement("span", { className: "ta-console-stat-label" }, label)));
|
|
96
|
+
return onClick ? (React.createElement("button", { type: "button", className: "ta-console-stat", onClick: onClick, title: title }, body)) : (React.createElement("div", { className: "ta-console-stat" }, body));
|
|
97
|
+
}
|
|
98
|
+
/** This month's minutes and tokens of an account, as bars; the limits of messages and pages in a line. */
|
|
99
|
+
function QuotaMeters({ quota }) {
|
|
100
|
+
const t = (0, use_t_1.useT)();
|
|
101
|
+
const language = (0, use_t_1.useLanguage)();
|
|
102
|
+
const { minutes, tokens } = quota;
|
|
103
|
+
const allowed = minutes.limit === undefined ? undefined : minutes.limit + minutes.bonus;
|
|
104
|
+
const resets = new Date(quota.resetsAt).toLocaleDateString(language, { month: 'short', day: 'numeric' });
|
|
105
|
+
return (React.createElement("div", { className: "ta-console-usage" },
|
|
106
|
+
React.createElement(Meter, { label: t('ta.console.freeMinutes'), value: allowed === undefined
|
|
107
|
+
? `${console_util_1.ConsoleUtil.minutes(minutes.used)} · ${t('ta.console.unlimited')}`
|
|
108
|
+
: `${console_util_1.ConsoleUtil.minutes(minutes.used)} / ${console_util_1.ConsoleUtil.minutes(allowed)}`, share: allowed === undefined ? undefined : console_util_1.ConsoleUtil.share(minutes.used, allowed), hint: [minutes.bonus > 0 ? t('ta.console.bonus', { minutes: minutes.bonus }) : '', t('ta.console.resets', { date: resets })]
|
|
109
|
+
.filter(Boolean)
|
|
110
|
+
.join(' · ') }),
|
|
111
|
+
React.createElement(Meter, { label: t('ta.console.monthTokens'), value: [console_util_1.ConsoleUtil.count(tokens.used), console_util_1.ConsoleUtil.cost(tokens.cost)].filter(Boolean).join(' · '), hint: [
|
|
112
|
+
quota.promptsPerMinute !== undefined ? t('ta.console.promptsLimit', { count: quota.promptsPerMinute }) : '',
|
|
113
|
+
quota.connections !== undefined ? t('ta.console.connectionsLimit', { count: quota.connections }) : '',
|
|
114
|
+
]
|
|
115
|
+
.filter(Boolean)
|
|
116
|
+
.join(' · ') })));
|
|
117
|
+
}
|
|
118
|
+
const RANGES = [
|
|
119
|
+
{ value: '1', label: 'ta.console.range1' },
|
|
120
|
+
{ value: '7', label: 'ta.console.range7' },
|
|
121
|
+
{ value: '30', label: 'ta.console.range30' },
|
|
122
|
+
];
|
|
123
|
+
function pointLabel(point, range, language) {
|
|
124
|
+
const date = new Date(point.at);
|
|
125
|
+
return range === 1
|
|
126
|
+
? date.toLocaleTimeString(language, { hour: '2-digit', minute: '2-digit' })
|
|
127
|
+
: date.toLocaleDateString(language, { month: 'numeric', day: 'numeric', weekday: range === 7 ? 'short' : undefined });
|
|
128
|
+
}
|
|
129
|
+
/** Bars of a trend, the one under the pointer said above them. */
|
|
130
|
+
function TrendBars({ points, metric, range }) {
|
|
131
|
+
const t = (0, use_t_1.useT)();
|
|
132
|
+
const language = (0, use_t_1.useLanguage)();
|
|
133
|
+
const [hovered, setHovered] = React.useState();
|
|
134
|
+
const values = points.map(point => (metric === 'tokens' ? point.tokens : point.cost));
|
|
135
|
+
const max = Math.max(...values, 0);
|
|
136
|
+
const shown = hovered !== undefined ? points[hovered] : undefined;
|
|
137
|
+
const format = (value) => { var _a; return (metric === 'tokens' ? console_util_1.ConsoleUtil.count(value) : ((_a = console_util_1.ConsoleUtil.cost(value)) !== null && _a !== void 0 ? _a : '$0')); };
|
|
138
|
+
const width = 600;
|
|
139
|
+
const height = 120;
|
|
140
|
+
const slot = width / points.length;
|
|
141
|
+
const gap = Math.min(4, slot * 0.25);
|
|
142
|
+
return (React.createElement("div", { className: "ta-console-chart" },
|
|
143
|
+
React.createElement("div", { className: "ta-console-chart-hover" }, shown ? (React.createElement(React.Fragment, null,
|
|
144
|
+
React.createElement("span", null, pointLabel(shown, range, language)),
|
|
145
|
+
React.createElement("strong", null, format(metric === 'tokens' ? shown.tokens : shown.cost)),
|
|
146
|
+
React.createElement("span", null, t('ta.console.turns', { count: shown.turns })))) : (React.createElement("span", null, t('ta.console.peak', { value: format(max) })))),
|
|
147
|
+
React.createElement("svg", { viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "none", role: "img", "aria-label": t('ta.console.trend'), onPointerMove: event => {
|
|
148
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
149
|
+
setHovered(Math.min(points.length - 1, Math.max(0, Math.floor(((event.clientX - box.left) / box.width) * points.length))));
|
|
150
|
+
}, onPointerLeave: () => setHovered(undefined) },
|
|
151
|
+
values.map((value, index) => {
|
|
152
|
+
const barHeight = max > 0 ? Math.max(value > 0 ? 2 : 0, (value / max) * (height - 4)) : 0;
|
|
153
|
+
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' }));
|
|
154
|
+
}),
|
|
155
|
+
React.createElement("line", { x1: 0, x2: width, y1: height - 0.5, y2: height - 0.5, className: "ta-console-chart-axis" })),
|
|
156
|
+
React.createElement("div", { className: "ta-console-chart-ticks" },
|
|
157
|
+
React.createElement("span", null, pointLabel(points[0], range, language)),
|
|
158
|
+
React.createElement("span", null, pointLabel(points[Math.floor(points.length / 2)], range, language)),
|
|
159
|
+
React.createElement("span", null, pointLabel(points[points.length - 1], range, language)))));
|
|
160
|
+
}
|
|
161
|
+
function Shares({ rows, total, metric }) {
|
|
162
|
+
return (React.createElement("div", { className: "ta-console-shares" }, rows.map(row => {
|
|
163
|
+
var _a;
|
|
164
|
+
const value = metric === 'tokens' ? row.tokens : row.cost;
|
|
165
|
+
return (React.createElement("div", { key: row.key, className: "ta-console-share" },
|
|
166
|
+
React.createElement("span", { className: "ta-console-share-label ta-ellipsis", title: row.label }, row.label),
|
|
167
|
+
React.createElement(Bar, { share: total > 0 ? Math.round((value / total) * 100) : 0, small: true, part: true }),
|
|
168
|
+
React.createElement("span", { className: "ta-console-share-value" }, metric === 'tokens' ? console_util_1.ConsoleUtil.count(value) : ((_a = console_util_1.ConsoleUtil.cost(value)) !== null && _a !== void 0 ? _a : '—'))));
|
|
169
|
+
})));
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* What agents took over time, of the gateway or of one account: tokens or dollars by hour (a day) or by day (a week,
|
|
173
|
+
* a month), the totals, and the models and accounts that took most.
|
|
174
|
+
*/
|
|
175
|
+
function TrendCard({ tenantId, tenants, onTenant }) {
|
|
176
|
+
var _a, _b, _c, _d, _e, _f;
|
|
177
|
+
const t = (0, use_t_1.useT)();
|
|
178
|
+
const [, bench] = (0, hooks_1.useWorkbench)();
|
|
179
|
+
const [range, setRange] = React.useState(7);
|
|
180
|
+
const [metric, setMetric] = React.useState('tokens');
|
|
181
|
+
const { value: trend, error } = usePolled(() => bench.gateway.getUsageTrend(range === 1 ? 2 : range, tenantId), `${range}|${tenantId}`, 60000);
|
|
182
|
+
const points = trend ? console_util_1.ConsoleUtil.points(trend, range) : undefined;
|
|
183
|
+
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 }), {
|
|
184
|
+
tokens: 0,
|
|
185
|
+
cost: 0,
|
|
186
|
+
turns: 0,
|
|
187
|
+
});
|
|
188
|
+
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);
|
|
189
|
+
const names = new Map(tenants === null || tenants === void 0 ? void 0 : tenants.map(tenant => [tenant.id, tenant.name || tenant.account]));
|
|
190
|
+
return (React.createElement("div", { className: "ta-console-card" },
|
|
191
|
+
React.createElement("div", { className: "ta-console-card-head" },
|
|
192
|
+
React.createElement("div", { className: "ta-console-total" },
|
|
193
|
+
React.createElement("strong", null, metric === 'tokens' ? console_util_1.ConsoleUtil.count((_c = totals === null || totals === void 0 ? void 0 : totals.tokens) !== null && _c !== void 0 ? _c : 0) : ((_e = console_util_1.ConsoleUtil.cost((_d = totals === null || totals === void 0 ? void 0 : totals.cost) !== null && _d !== void 0 ? _d : 0)) !== null && _e !== void 0 ? _e : '$0')),
|
|
194
|
+
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 }))),
|
|
195
|
+
React.createElement("div", { className: "ta-console-card-controls" },
|
|
196
|
+
React.createElement(settings_controls_1.Segmented, { label: t('ta.console.metric'), value: metric, onChange: setMetric, choices: [
|
|
197
|
+
{ value: 'tokens', label: 'ta.console.tokens' },
|
|
198
|
+
{ value: 'cost', label: 'ta.console.cost' },
|
|
199
|
+
] }),
|
|
200
|
+
React.createElement(settings_controls_1.Segmented, { label: t('ta.console.range'), value: String(range), onChange: value => setRange(Number(value)), choices: RANGES }))),
|
|
201
|
+
error && !trend ? (React.createElement(callout_1.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 })),
|
|
202
|
+
trend && trend.byModel.length > 0 && (React.createElement(React.Fragment, null,
|
|
203
|
+
React.createElement("span", { className: "ta-console-card-label" }, t('ta.console.byModel')),
|
|
204
|
+
React.createElement(Shares, { metric: metric, total: metric === 'tokens'
|
|
205
|
+
? trend.byModel.reduce((sum, row) => sum + row.tokens, 0)
|
|
206
|
+
: trend.byModel.reduce((sum, row) => sum + row.cost, 0), rows: trend.byModel
|
|
207
|
+
.slice(0, 5)
|
|
208
|
+
.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 }); }) }))),
|
|
209
|
+
trend && tenants && trend.byTenant.length > 0 && (React.createElement(React.Fragment, null,
|
|
210
|
+
React.createElement("span", { className: "ta-console-card-label" }, t('ta.console.byAccount')),
|
|
211
|
+
React.createElement("div", { className: "ta-console-shares" }, trend.byTenant.slice(0, 5).map(row => {
|
|
212
|
+
var _a, _b;
|
|
213
|
+
const value = metric === 'tokens' ? row.tokens : row.cost;
|
|
214
|
+
const all = metric === 'tokens'
|
|
215
|
+
? trend.byTenant.reduce((sum, each) => sum + each.tokens, 0)
|
|
216
|
+
: trend.byTenant.reduce((sum, each) => sum + each.cost, 0);
|
|
217
|
+
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) },
|
|
218
|
+
React.createElement("span", { className: "ta-console-share-label ta-ellipsis" }, (_a = names.get(row.tenantId)) !== null && _a !== void 0 ? _a : row.tenantId),
|
|
219
|
+
React.createElement(Bar, { share: all > 0 ? Math.round((value / all) * 100) : 0, small: true, part: true }),
|
|
220
|
+
React.createElement("span", { className: "ta-console-share-value" }, metric === 'tokens' ? console_util_1.ConsoleUtil.count(value) : ((_b = console_util_1.ConsoleUtil.cost(value)) !== null && _b !== void 0 ? _b : '—'))));
|
|
221
|
+
})))),
|
|
222
|
+
trend && trend.stale.length > 0 && React.createElement("p", { className: "ta-list-hint" }, t('ta.console.stale', { count: trend.stale.length })),
|
|
223
|
+
total === 0 && trend && React.createElement("p", { className: "ta-list-hint" }, t('ta.console.trendEmpty'))));
|
|
224
|
+
}
|
|
225
|
+
function modeOf(value, nullable) {
|
|
226
|
+
return value === null ? 'none' : value === undefined ? (nullable ? 'inherit' : 'none') : 'set';
|
|
227
|
+
}
|
|
228
|
+
/** A number of a limit: the default's (for an account), none, or one of its own. */
|
|
229
|
+
function NumberLimit({ label, hint, value, base, nullable, readOnly, onChange, }) {
|
|
230
|
+
const t = (0, use_t_1.useT)();
|
|
231
|
+
const mode = modeOf(value, nullable);
|
|
232
|
+
const [text, setText] = React.useState(console_util_1.ConsoleUtil.field(value));
|
|
233
|
+
React.useEffect(() => setText(console_util_1.ConsoleUtil.field(value)), [value]);
|
|
234
|
+
const parsed = console_util_1.ConsoleUtil.parse(text);
|
|
235
|
+
return (React.createElement("div", { className: "ta-console-limit" },
|
|
236
|
+
React.createElement("div", { className: "ta-console-limit-text" },
|
|
237
|
+
React.createElement("span", null, label),
|
|
238
|
+
React.createElement("span", { className: "ta-console-limit-hint" }, hint)),
|
|
239
|
+
React.createElement("div", { className: "ta-console-limit-control" },
|
|
240
|
+
React.createElement("select", { className: "ta-input ta-console-select", value: mode, disabled: readOnly, "aria-label": label, onChange: event => {
|
|
241
|
+
const next = event.target.value;
|
|
242
|
+
onChange(next === 'inherit' ? undefined : next === 'none' ? (nullable ? null : undefined) : (parsed !== null && parsed !== void 0 ? parsed : 0));
|
|
243
|
+
if (next === 'set' && parsed === undefined) {
|
|
244
|
+
setText('0');
|
|
245
|
+
}
|
|
246
|
+
} },
|
|
247
|
+
nullable && React.createElement("option", { value: "inherit" }, t('ta.console.limitDefault', { value: base !== null && base !== void 0 ? base : t('ta.console.unlimited') })),
|
|
248
|
+
React.createElement("option", { value: "none" }, t('ta.console.unlimited')),
|
|
249
|
+
React.createElement("option", { value: "set" }, t('ta.console.limitSet'))),
|
|
250
|
+
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 => {
|
|
251
|
+
setText(event.target.value);
|
|
252
|
+
const next = console_util_1.ConsoleUtil.parse(event.target.value);
|
|
253
|
+
if (next !== undefined && !Number.isNaN(next)) {
|
|
254
|
+
onChange(next);
|
|
255
|
+
}
|
|
256
|
+
} })))));
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Limits to change: the gateway's defaults (`nullable` false: a limit is a number or none), or an account's over them
|
|
260
|
+
* (each the default's, none, or its own). Saved as a whole.
|
|
261
|
+
*/
|
|
262
|
+
function LimitsForm({ value, defaults, providers, nullable, readOnly, onSave, }) {
|
|
263
|
+
const t = (0, use_t_1.useT)();
|
|
264
|
+
const [draft, setDraft] = React.useState(value);
|
|
265
|
+
const [busy, setBusy] = React.useState(false);
|
|
266
|
+
React.useEffect(() => setDraft(value), [value]);
|
|
267
|
+
const changed = JSON.stringify(draft) !== JSON.stringify(value);
|
|
268
|
+
const set = (change) => setDraft(current => Object.fromEntries(Object.entries({ ...current, ...change }).filter(([, item]) => item !== undefined)));
|
|
269
|
+
const base = (key) => (typeof (defaults === null || defaults === void 0 ? void 0 : defaults[key]) === 'number' ? String(defaults[key]) : undefined);
|
|
270
|
+
const providersMode = draft.providers === null ? 'none' : draft.providers === undefined ? (nullable ? 'inherit' : 'none') : 'set';
|
|
271
|
+
return (React.createElement("div", { className: "ta-console-card ta-console-limits" },
|
|
272
|
+
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 }) }),
|
|
273
|
+
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 }) }),
|
|
274
|
+
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 }) }),
|
|
275
|
+
React.createElement("div", { className: "ta-console-limit" },
|
|
276
|
+
React.createElement("div", { className: "ta-console-limit-text" },
|
|
277
|
+
React.createElement("span", null, t('ta.console.providersAllowed')),
|
|
278
|
+
React.createElement("span", { className: "ta-console-limit-hint" }, t('ta.console.providersAllowedHint'))),
|
|
279
|
+
React.createElement("div", { className: "ta-console-limit-control" },
|
|
280
|
+
React.createElement("select", { className: "ta-input ta-console-select", value: providersMode, disabled: readOnly, "aria-label": t('ta.console.providersAllowed'), onChange: event => {
|
|
281
|
+
const next = event.target.value;
|
|
282
|
+
set({
|
|
283
|
+
providers: next === 'inherit' ? undefined : next === 'none' ? (nullable ? null : undefined) : providers.map(provider => provider.id),
|
|
284
|
+
});
|
|
285
|
+
} },
|
|
286
|
+
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') }))),
|
|
287
|
+
React.createElement("option", { value: "none" }, t('ta.console.allProviders')),
|
|
288
|
+
React.createElement("option", { value: "set" }, t('ta.console.someProviders'))))),
|
|
289
|
+
providersMode === 'set' && (React.createElement("div", { className: "ta-console-chips" }, providers.map(provider => {
|
|
290
|
+
var _a;
|
|
291
|
+
var _b;
|
|
292
|
+
const on = (_b = (_a = draft.providers) === null || _a === void 0 ? void 0 : _a.includes(provider.id)) !== null && _b !== void 0 ? _b : false;
|
|
293
|
+
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({
|
|
294
|
+
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],
|
|
295
|
+
}); } }, provider.name));
|
|
296
|
+
}))),
|
|
297
|
+
React.createElement("div", { className: "ta-console-limit" },
|
|
298
|
+
React.createElement("div", { className: "ta-console-limit-text" },
|
|
299
|
+
React.createElement("span", null, t('ta.console.ownService')),
|
|
300
|
+
React.createElement("span", { className: "ta-console-limit-hint" }, t('ta.console.ownServiceHint'))),
|
|
301
|
+
React.createElement("div", { className: "ta-console-limit-control" },
|
|
302
|
+
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' }) },
|
|
303
|
+
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') }))),
|
|
304
|
+
React.createElement("option", { value: "yes" }, t('ta.console.yes')),
|
|
305
|
+
React.createElement("option", { value: "no" }, t('ta.console.no'))))),
|
|
306
|
+
!readOnly && (React.createElement("div", { className: "ta-console-actions ta-console-form-actions" },
|
|
307
|
+
React.createElement("button", { type: "button", className: "ta-button", disabled: !changed || busy, onClick: () => setDraft(value) }, t('ta.console.reset')),
|
|
308
|
+
React.createElement("button", { type: "button", className: "ta-button ta-primary", disabled: !changed ||
|
|
309
|
+
busy ||
|
|
310
|
+
[draft.freeMinutes, draft.promptsPerMinute, draft.connections].some(item => typeof item === 'number' && Number.isNaN(item)), onClick: () => {
|
|
311
|
+
setBusy(true);
|
|
312
|
+
void onSave(draft).finally(() => setBusy(false));
|
|
313
|
+
} }, busy ? React.createElement("span", { className: "ta-spinner" }) : t('ta.console.save'))))));
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=console-parts.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TaEnvironmentStatus, TaGatewayConsole, TaGatewayTenant } from '@celljs/ta-protocol';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import type { MessageId } from '../i18n/messages';
|
|
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;
|
|
23
|
+
//# sourceMappingURL=console-tenant.d.ts.map
|