@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,327 @@
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.STATUS = void 0;
37
+ exports.StatusDot = StatusDot;
38
+ exports.RoleChip = RoleChip;
39
+ exports.canManage = canManage;
40
+ exports.TenantRow = TenantRow;
41
+ exports.TenantDetail = TenantDetail;
42
+ const lucide_react_1 = require("lucide-react");
43
+ const React = __importStar(require("react"));
44
+ const access_view_1 = require("../components/access-view");
45
+ const busy_1 = require("../components/busy");
46
+ const callout_1 = require("../components/callout");
47
+ const icon_1 = require("../components/icon");
48
+ const hooks_1 = require("../hooks");
49
+ const use_t_1 = require("../i18n/use-t");
50
+ const terminal_text_1 = require("../util/terminal-text");
51
+ const console_parts_1 = require("./console-parts");
52
+ const console_util_1 = require("./console-util");
53
+ exports.STATUS = {
54
+ starting: 'ta.environment.starting',
55
+ running: 'ta.environment.running',
56
+ stopped: 'ta.environment.stopped',
57
+ failed: 'ta.environment.failed',
58
+ };
59
+ const AGENT_STATUS = {
60
+ working: 'ta.console.agentWorking',
61
+ waiting: 'ta.console.agentWaiting',
62
+ asking: 'ta.console.agentAsking',
63
+ idle: 'ta.console.agentIdle',
64
+ };
65
+ const ROLE = {
66
+ owner: 'ta.console.roleOwner',
67
+ admin: 'ta.console.roleAdmin',
68
+ member: 'ta.console.roleMember',
69
+ };
70
+ function StatusDot({ status }) {
71
+ return React.createElement("span", { className: `ta-console-dot ta-console-${status}` });
72
+ }
73
+ function RoleChip({ role }) {
74
+ const t = (0, use_t_1.useT)();
75
+ return role === 'member' ? null : React.createElement("span", { className: `ta-console-chip ta-console-role-${role}` }, t(ROLE[role]));
76
+ }
77
+ /** Whether one of `viewer` may change the account: an owner any, an admin members only. */
78
+ function canManage(viewer, tenant) {
79
+ return viewer === 'owner' || (viewer === 'admin' && tenant.role === 'member');
80
+ }
81
+ function TenantRow({ tenant, onOpen }) {
82
+ var _a, _b;
83
+ const t = (0, use_t_1.useT)();
84
+ const language = (0, use_t_1.useLanguage)();
85
+ const { environment, quota } = tenant;
86
+ const label = tenant.name && tenant.name !== tenant.account ? tenant.name : tenant.account;
87
+ const minutes = console_util_1.ConsoleUtil.minutesShare(quota);
88
+ return (React.createElement("button", { type: "button", className: "ta-console-tenant", onClick: onOpen },
89
+ React.createElement(access_view_1.AccountAvatar, { id: tenant.account, avatar: tenant.avatar, className: "ta-console-avatar" }),
90
+ React.createElement("span", { className: "ta-console-tenant-text" },
91
+ React.createElement("span", { className: "ta-console-tenant-name ta-ellipsis" },
92
+ label,
93
+ React.createElement(RoleChip, { role: tenant.role }),
94
+ quota.blocked && (React.createElement("span", { className: "ta-console-chip ta-console-chip-warn" }, t(quota.blocked === 'suspended' ? 'ta.console.suspended' : 'ta.console.outOfMinutes'))),
95
+ label !== tenant.account && React.createElement("span", { className: "ta-console-account" },
96
+ " ",
97
+ tenant.account)),
98
+ React.createElement("span", { className: "ta-console-tenant-state ta-ellipsis" },
99
+ React.createElement(StatusDot, { status: environment.status }),
100
+ [
101
+ t(exports.STATUS[environment.status]),
102
+ ((_a = tenant.agents) === null || _a === void 0 ? void 0 : _a.working) ? t('ta.console.rowWorking', { count: tenant.agents.working }) : '',
103
+ ((_b = tenant.agents) === null || _b === void 0 ? void 0 : _b.waiting) ? t('ta.console.rowWaiting', { count: tenant.agents.waiting }) : '',
104
+ tenant.connections > 0 ? t('ta.environment.connections', { count: tenant.connections }) : '',
105
+ tenant.lastActiveAt ? console_util_1.ConsoleUtil.ago(tenant.lastActiveAt, language) : '',
106
+ ]
107
+ .filter(Boolean)
108
+ .join(' · '))),
109
+ React.createElement("span", { className: "ta-console-tenant-usage" },
110
+ React.createElement("span", null, quota.minutes.limit === undefined
111
+ ? console_util_1.ConsoleUtil.minutes(quota.minutes.used)
112
+ : `${quota.minutes.used} / ${quota.minutes.limit + quota.minutes.bonus} min`),
113
+ minutes !== undefined && React.createElement(console_parts_1.Bar, { share: minutes, small: true }))));
114
+ }
115
+ /** What an agent did lately: its tool calls and the failures of its model, newest first. */
116
+ function ActivityList({ tenantId, sessionId }) {
117
+ const t = (0, use_t_1.useT)();
118
+ const language = (0, use_t_1.useLanguage)();
119
+ const [, bench] = (0, hooks_1.useWorkbench)();
120
+ const { value, error } = (0, console_parts_1.usePolled)(() => bench.gateway.getAgentActivity(tenantId, sessionId), `${tenantId}|${sessionId}`);
121
+ if (error && !value) {
122
+ return React.createElement("p", { className: "ta-list-hint ta-console-activity-empty" }, error);
123
+ }
124
+ if (!value) {
125
+ return React.createElement("span", { className: "ta-spinner ta-later ta-console-loading" });
126
+ }
127
+ if (value.length === 0) {
128
+ return React.createElement("p", { className: "ta-list-hint ta-console-activity-empty" }, t('ta.console.activityNone'));
129
+ }
130
+ const failures = value.filter(each => !each.ok).length;
131
+ return (React.createElement("div", { className: "ta-console-activity" },
132
+ React.createElement("span", { className: "ta-console-activity-summary" }, t('ta.console.activitySummary', { count: value.length, failed: failures })),
133
+ value.slice(0, 30).map((each, index) => (React.createElement("div", { key: `${each.at}-${index}`, className: `ta-console-activity-row${each.ok ? '' : ' ta-failed'}` },
134
+ React.createElement("span", { className: `ta-console-dot ${each.running ? 'ta-console-agent-working' : each.ok ? 'ta-console-running' : 'ta-console-failed'}` }),
135
+ React.createElement("span", { className: "ta-console-activity-name" }, each.kind === 'model' ? t('ta.console.modelFailed', { model: each.name }) : each.name),
136
+ each.error && (React.createElement("span", { className: "ta-console-activity-error ta-ellipsis", title: each.error }, each.error)),
137
+ React.createElement("span", { className: "ta-console-activity-time" }, [
138
+ each.running
139
+ ? t('ta.console.activityRunning')
140
+ : each.ms !== undefined
141
+ ? `${(each.ms / 1000).toFixed(each.ms >= 10000 ? 0 : 1)} s`
142
+ : '',
143
+ console_util_1.ConsoleUtil.ago(each.at, language),
144
+ ]
145
+ .filter(Boolean)
146
+ .join(' · ')))))));
147
+ }
148
+ function AgentRow({ tenantId, session }) {
149
+ var _a;
150
+ const t = (0, use_t_1.useT)();
151
+ const language = (0, use_t_1.useLanguage)();
152
+ const [open, setOpen] = React.useState(false);
153
+ const { stats } = session;
154
+ const model = (_a = session.model) === null || _a === void 0 ? void 0 : _a.split('/').pop();
155
+ const parts = [
156
+ t('ta.console.messages', { count: session.messageCount }),
157
+ stats && stats.toolCalls > 0 ? t('ta.console.toolCalls', { count: stats.toolCalls }) : '',
158
+ stats && stats.tokens.total > 0 ? `${console_util_1.ConsoleUtil.count(stats.tokens.total)} tokens` : '',
159
+ stats ? console_util_1.ConsoleUtil.cost(stats.cost) : '',
160
+ ].filter(Boolean);
161
+ return (React.createElement("div", { className: "ta-console-agent-block" },
162
+ React.createElement("button", { type: "button", className: "ta-console-agent", "aria-expanded": open, onClick: () => setOpen(!open) },
163
+ React.createElement("span", { className: `ta-console-dot ta-console-agent-${session.status}` }),
164
+ React.createElement("span", { className: "ta-console-tenant-text" },
165
+ React.createElement("span", { className: "ta-console-tenant-name ta-ellipsis" },
166
+ session.name || console_util_1.ConsoleUtil.folder(session.cwd),
167
+ model && React.createElement("span", { className: "ta-console-chip" }, model)),
168
+ React.createElement("span", { className: "ta-console-tenant-state ta-ellipsis" }, [t(AGENT_STATUS[session.status]), ...parts, console_util_1.ConsoleUtil.ago(session.updatedAt, language)].join(' · '))),
169
+ (stats === null || stats === void 0 ? void 0 : stats.context) !== undefined && (React.createElement("span", { className: "ta-console-tenant-usage", title: t('ta.console.context') },
170
+ React.createElement("span", null,
171
+ stats.context,
172
+ "%"),
173
+ React.createElement(console_parts_1.Bar, { share: stats.context, small: true }))),
174
+ React.createElement(icon_1.Icon, { icon: open ? lucide_react_1.ChevronDown : lucide_react_1.ChevronRight, size: 15, className: "ta-list-chevron" })),
175
+ open && React.createElement(ActivityList, { tenantId: tenantId, sessionId: session.sessionId })));
176
+ }
177
+ /** The agents of a tenant's Ta: totals, then each conversation open, the latest first; one opens what it did lately. */
178
+ function AgentsSection({ tenant }) {
179
+ var _a, _b, _c, _d, _e;
180
+ const t = (0, use_t_1.useT)();
181
+ const [, bench] = (0, hooks_1.useWorkbench)();
182
+ const own = tenant.environment.provider === 'own';
183
+ const running = tenant.environment.status === 'running' && !own;
184
+ const { value: agents, error } = (0, console_parts_1.usePolled)(() => (running ? bench.gateway.getTenantAgents(tenant.id) : Promise.resolve(undefined)), `${tenant.id}|${running}`);
185
+ const totals = agents === null || agents === void 0 ? void 0 : agents.totals;
186
+ return (React.createElement(React.Fragment, null,
187
+ React.createElement(console_parts_1.SectionTitle, null, t('ta.console.agents')),
188
+ !running ? (React.createElement("p", { className: "ta-list-hint" }, own ? t('ta.console.agentsOwn') : t('ta.console.agentsStopped'))) : error && !agents ? (React.createElement(callout_1.Callout, { level: "warning" }, error)) : !agents ? (React.createElement("span", { className: "ta-spinner ta-later ta-console-loading" })) : (React.createElement(React.Fragment, null,
189
+ React.createElement("div", { className: "ta-console-stats ta-console-stats-small" },
190
+ React.createElement(console_parts_1.Stat, { value: (_a = totals === null || totals === void 0 ? void 0 : totals.sessions) !== null && _a !== void 0 ? _a : 0, label: t('ta.console.sessions') }),
191
+ React.createElement(console_parts_1.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 }),
192
+ React.createElement(console_parts_1.Stat, { value: (_c = totals === null || totals === void 0 ? void 0 : totals.toolCalls) !== null && _c !== void 0 ? _c : 0, label: t('ta.console.toolCallsLabel') }),
193
+ React.createElement(console_parts_1.Stat, { value: (_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 : '—', label: t('ta.console.cost') })),
194
+ 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 }))))),
195
+ React.createElement("p", { className: "ta-list-hint" }, t('ta.console.agentsPrivacy'))))));
196
+ }
197
+ function Logs({ tenant, info }) {
198
+ const t = (0, use_t_1.useT)();
199
+ const [, bench] = (0, hooks_1.useWorkbench)();
200
+ const [, notices] = (0, hooks_1.useNotices)();
201
+ const [logs, setLogs] = React.useState();
202
+ const [busy, run] = (0, busy_1.useBusy)();
203
+ const box = React.useRef(null);
204
+ const hasLogs = tenant.environment.provider !== 'own' && info.providers.some(provider => provider.id === tenant.environment.provider && provider.logs);
205
+ const read = React.useCallback(() => run(() => bench.gateway.getTenantLogs(tenant.id, 300).then(text => setLogs(terminal_text_1.TerminalText.plain(text).trimEnd()), error => notices.error(error))), [bench, tenant.id, notices, run]);
206
+ // The latest lines are what one looks for: the box starts at its end.
207
+ // biome-ignore lint/correctness/useExhaustiveDependencies: scrolled again when the lines change
208
+ React.useLayoutEffect(() => {
209
+ if (box.current) {
210
+ box.current.scrollTop = box.current.scrollHeight;
211
+ }
212
+ }, [logs]);
213
+ return (React.createElement(React.Fragment, null,
214
+ React.createElement(console_parts_1.SectionTitle, { action: hasLogs && logs !== undefined ? (React.createElement(icon_1.IconButton, { icon: lucide_react_1.RefreshCw, label: t('ta.console.refresh'), busy: busy, onClick: () => void read() })) : undefined }, t('ta.console.logs')),
215
+ !hasLogs ? (React.createElement("p", { className: "ta-list-hint" }, t('ta.console.logsNone'))) : logs === undefined ? (React.createElement("div", { className: "ta-console-actions" },
216
+ React.createElement("button", { type: "button", className: "ta-button", disabled: busy, onClick: () => void read() }, busy ? React.createElement("span", { className: "ta-spinner" }) : t('ta.console.logsShow')),
217
+ 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')))));
218
+ }
219
+ /** One account's Ta: what it is and may use, what it took, its agents, its actions and its log. */
220
+ function TenantDetail({ tenant, info, onChanged }) {
221
+ var _a;
222
+ const t = (0, use_t_1.useT)();
223
+ const language = (0, use_t_1.useLanguage)();
224
+ const [, bench] = (0, hooks_1.useWorkbench)();
225
+ const [, notices] = (0, hooks_1.useNotices)();
226
+ const [busy, run] = (0, busy_1.useBusy)();
227
+ const [doing, setDoing] = React.useState();
228
+ const [editing, setEditing] = React.useState(false);
229
+ const { environment, usage } = tenant;
230
+ const own = environment.provider === 'own';
231
+ const manage = canManage(info.role, tenant);
232
+ const act = (key, action, done) => {
233
+ setDoing(key);
234
+ void run(() => action()
235
+ .then(() => done && notices.notify(done, { level: 'success' }))
236
+ .catch(error => notices.error(error))
237
+ .then(onChanged)
238
+ .finally(() => setDoing(undefined)));
239
+ };
240
+ const confirmThen = async (key, title, message, label, action, danger = false) => {
241
+ if (await notices.confirm({ title, message, confirmLabel: label, danger })) {
242
+ act(key, action);
243
+ }
244
+ };
245
+ const date = (time) => (time ? new Date(time).toLocaleString(language, { dateStyle: 'medium', timeStyle: 'short' }) : t('ta.console.never'));
246
+ const spinner = (key, icon) => (busy && doing === key ? React.createElement("span", { className: "ta-spinner" }) : React.createElement(icon_1.Icon, { icon: icon, size: 15 }));
247
+ const memory = console_util_1.ConsoleUtil.share(usage === null || usage === void 0 ? void 0 : usage.memory, usage === null || usage === void 0 ? void 0 : usage.memoryLimit);
248
+ const name = tenant.name || tenant.account;
249
+ return (React.createElement("div", { className: "ta-list-scroll" },
250
+ React.createElement("div", { className: "ta-list-content ta-console-content" },
251
+ React.createElement("div", { className: "ta-console-person" },
252
+ React.createElement(access_view_1.AccountAvatar, { id: tenant.account, avatar: tenant.avatar, className: "ta-console-avatar ta-console-avatar-large" }),
253
+ React.createElement("div", { className: "ta-console-person-text" },
254
+ React.createElement("span", { className: "ta-console-person-name ta-ellipsis" },
255
+ name,
256
+ React.createElement(RoleChip, { role: tenant.role })),
257
+ React.createElement("span", { className: "ta-console-account ta-ellipsis" }, tenant.account),
258
+ React.createElement("span", { className: "ta-console-tenant-state" },
259
+ React.createElement(StatusDot, { status: environment.status }),
260
+ [t(exports.STATUS[environment.status]), environment.name].filter(Boolean).join(' · ')))),
261
+ tenant.quota.blocked ? (React.createElement(callout_1.Callout, { level: "warning" }, t(tenant.quota.blocked === 'suspended' ? 'ta.console.blockedSuspended' : 'ta.console.blockedMinutes'))) : (environment.error && React.createElement(callout_1.Callout, { level: "error" }, environment.error)),
262
+ manage ? (React.createElement("div", { className: "ta-console-actions" },
263
+ 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)) },
264
+ spinner('start', lucide_react_1.Play),
265
+ " ",
266
+ t('ta.console.start'))),
267
+ 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)) },
268
+ spinner('restart', lucide_react_1.RotateCw),
269
+ " ",
270
+ t('ta.environment.restart'))),
271
+ 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)) },
272
+ spinner('stop', lucide_react_1.Power),
273
+ " ",
274
+ t('ta.environment.stop'))),
275
+ tenant.role !== 'owner' && (React.createElement("button", { type: "button", className: tenant.suspended ? 'ta-button' : 'ta-button ta-danger', disabled: busy, onClick: () => tenant.suspended
276
+ ? act('suspend', () => bench.gateway.setSuspended(tenant.id, false), t('ta.console.resumed', { account: name }))
277
+ : confirmThen('suspend', t('ta.console.suspendConfirm', { account: name }), t('ta.console.suspendDetail'), t('ta.console.suspend'), () => bench.gateway.setSuspended(tenant.id, true), true) },
278
+ spinner('suspend', tenant.suspended ? lucide_react_1.Play : lucide_react_1.Pause),
279
+ " ",
280
+ t(tenant.suspended ? 'ta.console.resume' : 'ta.console.suspend'))))) : (React.createElement("p", { className: "ta-list-hint" }, t('ta.console.cannotManage'))),
281
+ React.createElement(console_parts_1.SectionTitle, { action: manage && tenant.role !== 'owner' ? (React.createElement("div", { className: "ta-console-actions" },
282
+ React.createElement("button", { type: "button", className: "ta-link-button", onClick: async () => {
283
+ const given = await notices.input({ title: t('ta.console.grantTitle', { account: name }), placeholder: '60' });
284
+ const minutes = given === undefined ? undefined : Number(given.trim());
285
+ if (minutes !== undefined && Number.isInteger(minutes) && minutes !== 0) {
286
+ act('grant', () => bench.gateway.grantMinutes(tenant.id, minutes), t('ta.console.granted', { minutes }));
287
+ }
288
+ } },
289
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.Gift, size: 14 }),
290
+ " ",
291
+ t('ta.console.grant')),
292
+ 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')),
293
+ React.createElement(console_parts_1.QuotaMeters, { quota: tenant.quota }),
294
+ editing && manage && (React.createElement(console_parts_1.LimitsForm, { value: (_a = tenant.limits) !== null && _a !== void 0 ? _a : {}, defaults: info.policy.defaults, providers: info.providers, nullable: true, onSave: limits => bench.gateway
295
+ .setTenantLimits(tenant.id, Object.keys(limits).length ? limits : null)
296
+ .then(() => notices.notify(t('ta.console.saved'), { level: 'success' }))
297
+ .then(onChanged)
298
+ .catch(error => notices.error(error)) })),
299
+ info.role === 'owner' && tenant.role !== 'owner' && (React.createElement("div", { className: "ta-console-role-row" },
300
+ React.createElement(icon_1.Icon, { icon: tenant.role === 'admin' ? lucide_react_1.ShieldCheck : lucide_react_1.ShieldOff, size: 16 }),
301
+ React.createElement("span", null, t(tenant.role === 'admin' ? 'ta.console.isAdmin' : 'ta.console.isMember')),
302
+ 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')))),
303
+ React.createElement(console_parts_1.SectionTitle, null, t('ta.console.trend')),
304
+ React.createElement(console_parts_1.TrendCard, { tenantId: tenant.id }),
305
+ React.createElement(AgentsSection, { tenant: tenant }),
306
+ usage && (React.createElement(React.Fragment, null,
307
+ React.createElement(console_parts_1.SectionTitle, null, t('ta.console.sandboxNow')),
308
+ React.createElement("div", { className: "ta-console-usage" },
309
+ usage.cpu !== undefined && (React.createElement(console_parts_1.Meter, { label: t('ta.console.cpu'), value: `${usage.cpu.toFixed(1)}%`, share: Math.min(100, usage.cpu) })),
310
+ usage.memory !== undefined && (React.createElement(console_parts_1.Meter, { label: t('ta.console.memory'), value: usage.memoryLimit
311
+ ? `${console_util_1.ConsoleUtil.bytes(usage.memory)} / ${console_util_1.ConsoleUtil.bytes(usage.memoryLimit)}`
312
+ : console_util_1.ConsoleUtil.bytes(usage.memory), share: memory }))))),
313
+ React.createElement(Logs, { key: tenant.id, tenant: tenant, info: info }),
314
+ React.createElement(console_parts_1.SectionTitle, null, t('ta.console.about')),
315
+ React.createElement("dl", { className: "ta-console-facts" },
316
+ React.createElement("dt", null, t('ta.console.environment')),
317
+ React.createElement("dd", { className: "ta-ellipsis" }, environment.url ? `${environment.name} · ${environment.url}` : environment.name),
318
+ React.createElement("dt", null, t('ta.console.connectionsLabel')),
319
+ React.createElement("dd", null, tenant.connections),
320
+ React.createElement("dt", null, t('ta.console.active')),
321
+ React.createElement("dd", null, date(tenant.lastActiveAt)),
322
+ React.createElement("dt", null, t('ta.console.created')),
323
+ React.createElement("dd", null, date(tenant.createdAt)),
324
+ React.createElement("dt", null, t('ta.console.tenantId')),
325
+ React.createElement("dd", { className: "ta-console-mono" }, tenant.id)))));
326
+ }
327
+ //# sourceMappingURL=console-tenant.js.map
@@ -0,0 +1,60 @@
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
+ }
60
+ //# sourceMappingURL=console-util.d.ts.map
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleUtil = void 0;
4
+ const HOUR = 3600000;
5
+ var ConsoleUtil;
6
+ (function (ConsoleUtil) {
7
+ /** 512 MB, 1.5 GB: as a person reads an amount of memory. */
8
+ function bytes(value) {
9
+ if (value >= 1024 ** 3) {
10
+ return `${(value / 1024 ** 3).toFixed(value >= 10 * 1024 ** 3 ? 0 : 1)} GB`;
11
+ }
12
+ return `${Math.max(1, Math.round(value / 1024 ** 2))} MB`;
13
+ }
14
+ ConsoleUtil.bytes = bytes;
15
+ /** The share of the limit in use, 0 to 100; undefined without both. */
16
+ function share(used, limit) {
17
+ if (used === undefined || limit === undefined) {
18
+ return undefined;
19
+ }
20
+ return limit <= 0 ? 100 : Math.min(100, Math.round((used / limit) * 100));
21
+ }
22
+ ConsoleUtil.share = share;
23
+ /** The class of a bar that fills: amber from 70%, red from 90%. */
24
+ function tone(share) {
25
+ return share >= 90 ? 'ta-high' : share >= 70 ? 'ta-warm' : '';
26
+ }
27
+ ConsoleUtil.tone = tone;
28
+ /** Whether the query is in its name, its account or where it runs. */
29
+ function matches(tenant, query) {
30
+ const words = query.trim().toLowerCase();
31
+ return !words || [tenant.name, tenant.account, tenant.environment.name].some(text => text === null || text === void 0 ? void 0 : text.toLowerCase().includes(words));
32
+ }
33
+ ConsoleUtil.matches = matches;
34
+ function filter(tenant, by) {
35
+ var _a;
36
+ var _b, _c;
37
+ switch (by) {
38
+ case 'running':
39
+ return tenant.environment.status === 'running';
40
+ case 'working':
41
+ return ((_b = (_a = tenant.agents) === null || _a === void 0 ? void 0 : _a.working) !== null && _b !== void 0 ? _b : 0) > 0;
42
+ case 'limited':
43
+ return !!tenant.quota.blocked || ((_c = minutesShare(tenant.quota)) !== null && _c !== void 0 ? _c : 0) >= 80;
44
+ case 'admins':
45
+ return tenant.role !== 'member';
46
+ default:
47
+ return true;
48
+ }
49
+ }
50
+ ConsoleUtil.filter = filter;
51
+ function sort(tenants, by) {
52
+ const name = (tenant) => (tenant.name || tenant.account).toLowerCase();
53
+ return [...tenants].sort((a, b) => { var _a, _b; return by === 'name'
54
+ ? name(a).localeCompare(name(b))
55
+ : by === 'minutes'
56
+ ? b.quota.minutes.used - a.quota.minutes.used
57
+ : ((_a = b.lastActiveAt) !== null && _a !== void 0 ? _a : b.createdAt) - ((_b = a.lastActiveAt) !== null && _b !== void 0 ? _b : a.createdAt); });
58
+ }
59
+ ConsoleUtil.sort = sort;
60
+ /** The free minutes of the month in use, 0 to 100, when there is a limit. */
61
+ function minutesShare(quota) {
62
+ const { used, limit, bonus } = quota.minutes;
63
+ return limit === undefined ? undefined : share(used, limit + bonus);
64
+ }
65
+ ConsoleUtil.minutesShare = minutesShare;
66
+ function counts(info) {
67
+ return {
68
+ accounts: info.tenants.length,
69
+ running: info.tenants.filter(tenant => tenant.environment.status === 'running').length,
70
+ connections: info.tenants.reduce((sum, tenant) => sum + tenant.connections, 0),
71
+ 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),
72
+ limited: info.tenants.filter(tenant => !!tenant.quota.blocked).length,
73
+ };
74
+ }
75
+ ConsoleUtil.counts = counts;
76
+ /** 12.3k, 4.5M: as a person reads a count of tokens. */
77
+ function count(value) {
78
+ if (value >= 1e9) {
79
+ return `${(value / 1e9).toFixed(1)}B`;
80
+ }
81
+ if (value >= 1e6) {
82
+ return `${(value / 1e6).toFixed(value >= 1e7 ? 0 : 1)}M`;
83
+ }
84
+ if (value >= 1e3) {
85
+ return `${(value / 1e3).toFixed(value >= 1e4 ? 0 : 1)}k`;
86
+ }
87
+ return String(Math.round(value));
88
+ }
89
+ ConsoleUtil.count = count;
90
+ /** $0.42, $12: what a model's prices made; none for nothing. */
91
+ function cost(value) {
92
+ if (value <= 0) {
93
+ return undefined;
94
+ }
95
+ return value < 0.01 ? '<$0.01' : `$${value.toFixed(value >= 10 ? 0 : 2)}`;
96
+ }
97
+ ConsoleUtil.cost = cost;
98
+ /** 1 h 20 min, 45 min: minutes as a person reads them. */
99
+ function minutes(value) {
100
+ const hours = Math.floor(value / 60);
101
+ const rest = value % 60;
102
+ return hours > 0 ? (rest > 0 ? `${hours} h ${rest} min` : `${hours} h`) : `${value} min`;
103
+ }
104
+ ConsoleUtil.minutes = minutes;
105
+ /** The last folder of a path: where a conversation works. */
106
+ function folder(cwd) {
107
+ var _a;
108
+ return (_a = cwd.split(/[\\/]/).filter(Boolean).pop()) !== null && _a !== void 0 ? _a : cwd;
109
+ }
110
+ ConsoleUtil.folder = folder;
111
+ /** 3 minutes ago, yesterday: in the language of the page. */
112
+ function ago(time, language, now = Date.now()) {
113
+ const seconds = Math.round((time - now) / 1000);
114
+ const format = new Intl.RelativeTimeFormat(language, { numeric: 'auto' });
115
+ const units = [
116
+ ['day', 86400],
117
+ ['hour', 3600],
118
+ ['minute', 60],
119
+ ];
120
+ for (const [unit, size] of units) {
121
+ if (Math.abs(seconds) >= size) {
122
+ return format.format(Math.round(seconds / size), unit);
123
+ }
124
+ }
125
+ return format.format(0, 'second');
126
+ }
127
+ ConsoleUtil.ago = ago;
128
+ /** Where a link of the gateway goes: its public address, else the one the page was loaded from. */
129
+ function link(path, publicUrl, origin) {
130
+ return `${(publicUrl !== null && publicUrl !== void 0 ? publicUrl : origin).replace(/\/+$/, '')}${path}`;
131
+ }
132
+ ConsoleUtil.link = link;
133
+ /** The start of the day of `time` in the page's time zone. */
134
+ function dayStart(time) {
135
+ const date = new Date(time);
136
+ date.setHours(0, 0, 0, 0);
137
+ return date.getTime();
138
+ }
139
+ ConsoleUtil.dayStart = dayStart;
140
+ /**
141
+ * 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;
142
+ * those with nothing are there too, at zero.
143
+ */
144
+ function points(trend, range, now = Date.now()) {
145
+ const empty = (at) => ({ at, tokens: 0, input: 0, output: 0, cost: 0, turns: 0 });
146
+ const slots = [];
147
+ if (range === 1) {
148
+ const last = Math.floor(now / HOUR) * HOUR;
149
+ for (let index = 23; index >= 0; index--) {
150
+ slots.push(empty(last - index * HOUR));
151
+ }
152
+ }
153
+ else {
154
+ const today = dayStart(now);
155
+ for (let index = range - 1; index >= 0; index--) {
156
+ const date = new Date(today);
157
+ date.setDate(date.getDate() - index);
158
+ slots.push(empty(date.getTime()));
159
+ }
160
+ }
161
+ const slotOf = new Map(slots.map(slot => [slot.at, slot]));
162
+ for (const hour of trend.hours) {
163
+ const slot = slotOf.get(range === 1 ? hour.at : dayStart(hour.at));
164
+ if (slot) {
165
+ slot.tokens += hour.tokens;
166
+ slot.input += hour.input;
167
+ slot.output += hour.output;
168
+ slot.cost += hour.cost;
169
+ slot.turns += hour.turns;
170
+ }
171
+ }
172
+ return slots;
173
+ }
174
+ ConsoleUtil.points = points;
175
+ /** A number of a limit as a field holds it: empty for none. */
176
+ function field(value) {
177
+ return typeof value === 'number' ? String(value) : '';
178
+ }
179
+ ConsoleUtil.field = field;
180
+ /** What a field of a limit says: a whole number, none (empty), or wrong (NaN). */
181
+ function parse(text) {
182
+ const trimmed = text.trim();
183
+ if (!trimmed) {
184
+ return undefined;
185
+ }
186
+ return /^\d+$/.test(trimmed) ? Number(trimmed) : Number.NaN;
187
+ }
188
+ ConsoleUtil.parse = parse;
189
+ })(ConsoleUtil || (exports.ConsoleUtil = ConsoleUtil = {}));
190
+ //# sourceMappingURL=console-util.js.map
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ export declare function ConsolePage(): React.JSX.Element;
3
+ //# sourceMappingURL=console-view.d.ts.map