@micha.bigler/ui-core-micha 4.20.0 → 4.22.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/CHANGELOG.md +19 -0
- package/README.md +41 -1
- package/dist/chat/ChatComposer.js +22 -7
- package/dist/chat/ChatThread.js +6 -4
- package/dist/chat/ChatWorkspace.js +37 -7
- package/dist/chat/MarkdownReply.js +33 -2
- package/dist/chat/ModelPicker.js +4 -1
- package/dist/chat/api.js +1 -0
- package/dist/chat/kitSxRegistry.js +4 -2
- package/dist/chat/wire.js +1 -1
- package/dist/i18n/chatTranslations.js +6 -0
- package/dist/pages/AccountPage.js +73 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.22.0 - UCM-CHAT-9
|
|
4
|
+
|
|
5
|
+
Chat pieces for the DCM-CHAT-16 server data; without that data nothing changes. `ChatWorkspace` reads the per-user
|
|
6
|
+
period limit (`api.getLimit()`, `GET <apiBase>limit/`; a missing route counts as no limit) and passes it to
|
|
7
|
+
`ChatComposer`'s new `usageLimit` prop: a usage meter ("<used> of <limit> USD") below the limit, and at the limit a
|
|
8
|
+
disabled composer with "Monthly/Daily limit reached" and the reset date. Answers keep their stored tool steps
|
|
9
|
+
(`turn.tool_steps`) as chips after reload. The model picker shows "≈ <cost> USD per answer" from
|
|
10
|
+
`average_cost_usd_micros`. Visible change in every app: Markdown links in answers are links now. App links
|
|
11
|
+
(same origin) go through the new `ChatWorkspace` / `MarkdownReply` prop `onNavigate(path)` when given, external http(s)
|
|
12
|
+
links open in a new tab, and every other scheme stays text as before.
|
|
13
|
+
|
|
14
|
+
## 4.21.0 - UCM-SHELL-9
|
|
15
|
+
|
|
16
|
+
`AccountPage` accepts an optional `groups` declaration (`[{ key, label, order?, tabs?, visible? }]`) that replaces the
|
|
17
|
+
kit's My account / Management / Help groups: app labels, order, built-in tabs placed in any declared group (their own
|
|
18
|
+
permission checks unchanged), `extraTabs[].group` naming any declared key, and a `visible(context)` rule that hides a
|
|
19
|
+
group together with its tabs (also for `?tab=`). Empty groups stay hidden; unplaced tabs land in "More". Without
|
|
20
|
+
`groups` nothing changes.
|
|
21
|
+
|
|
3
22
|
## 4.20.0 - UCM-AUTH-15
|
|
4
23
|
|
|
5
24
|
`SignUpContent` and `SignUpPage` accept an optional `preferredSignupMode`: when the server offers that mode it is shown
|
package/README.md
CHANGED
|
@@ -18,11 +18,39 @@ The privacy and cookie consent controls and their submitted values remain availa
|
|
|
18
18
|
|
|
19
19
|
## Account page: extra tabs in a navigation group
|
|
20
20
|
|
|
21
|
-
An entry of `AccountPage`'s `extraTabs` (`{ value, label,
|
|
21
|
+
An entry of `AccountPage`'s `extraTabs` (`{ value, label, render, visible? }`) may carry an optional `group` naming one of
|
|
22
22
|
the kit's navigation groups: `my-account` (Profile, Security), `management` (Users, Invite) or `help` (Support). The tab
|
|
23
23
|
then appears in that group after the kit's own tabs, in the order of `extraTabs`, in the desktop sidebar and in the
|
|
24
24
|
phone navigation. Without `group`, or with `more` or an unknown value, it stays in "More" as before.
|
|
25
25
|
|
|
26
|
+
## Account page: app-defined groups
|
|
27
|
+
|
|
28
|
+
Since 4.21.0 `AccountPage` takes an optional `groups` declaration that replaces the kit's three groups:
|
|
29
|
+
`[{ key, label, order?, tabs?, visible? }]`. `label` is the app's text (or `(context) => string`); groups render by
|
|
30
|
+
`order` (array order when absent); `tabs` places the built-in tabs (`profile`, `security`, `users`, `invite`,
|
|
31
|
+
`support`), each still shown only when its own permission check passes; `extraTabs[].group` may name any declared key.
|
|
32
|
+
`visible(context)` (`context` = `{ user, perms, isSuperUser, t }`, as for `extraTabs`) hides a group and makes its tabs
|
|
33
|
+
unreachable, `?tab=` included. Empty groups are hidden; a tab placed in no declared group lands in "More". Without
|
|
34
|
+
`groups` the hub is unchanged.
|
|
35
|
+
|
|
36
|
+
```jsx
|
|
37
|
+
<AccountPage
|
|
38
|
+
groups={[
|
|
39
|
+
{ key: 'personal', label: 'Persönlich', tabs: ['profile', 'security'] },
|
|
40
|
+
{ key: 'collaboration', label: 'Zusammenarbeit', tabs: ['invite'] },
|
|
41
|
+
{ key: 'help', label: 'Hilfe', tabs: ['support'] },
|
|
42
|
+
{ key: 'operations', label: 'Betrieb', tabs: ['users'], visible: ({ user }) => isOperator(user) },
|
|
43
|
+
]}
|
|
44
|
+
extraTabs={[
|
|
45
|
+
{ value: 'subscription', label: 'Abo und Token', group: 'personal', render: () => <Subscription /> },
|
|
46
|
+
{ value: 'teams', label: 'Teams', group: 'collaboration', render: () => <Teams /> },
|
|
47
|
+
{ value: 'all-projects', label: 'Alle Projekte', group: 'operations', render: () => <AllProjects /> },
|
|
48
|
+
]}
|
|
49
|
+
/>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Labels are passed already translated (for example `t('Maana.GROUP_PERSONAL')`), so an app's own DE and EN texts apply.
|
|
53
|
+
|
|
26
54
|
## Users tab: access column and delete
|
|
27
55
|
|
|
28
56
|
With billing in the account page, the user list shows two columns: "Zugang", a short coloured status ("Freigeschaltet",
|
|
@@ -168,6 +196,18 @@ closed for that chat until the page reloads, and another chat shows it again. `r
|
|
|
168
196
|
above the composer. Without `composerLayout` the composer is unchanged. `ChatComposer` takes the same `layout`,
|
|
169
197
|
`context` and `notice` props directly; `ModelPicker` takes `shortLabel`.
|
|
170
198
|
|
|
199
|
+
## Shared chat: limit, links, tool steps, estimates
|
|
200
|
+
|
|
201
|
+
Since 4.22.0, with django-core-micha's DCM-CHAT-16 data:
|
|
202
|
+
|
|
203
|
+
- `ChatWorkspace` shows the per-user period limit (`GET <apiBase>limit/`) as a meter in the composer and disables the
|
|
204
|
+
composer at the limit with the reset date. Without a limit, or against an older backend, the composer is unchanged.
|
|
205
|
+
- Answers show their stored tool steps after reload.
|
|
206
|
+
- The model picker adds "≈ <cost> USD per answer" when the catalogue sends `average_cost_usd_micros`.
|
|
207
|
+
- Links in answers are clickable. Pass `onNavigate={(path) => navigate(path)}` to route same-origin links through the
|
|
208
|
+
app's router, which keeps the chat panel open. External http(s) links open in a new tab, and other schemes stay text.
|
|
209
|
+
`MarkdownReply` takes the same `onNavigate`.
|
|
210
|
+
|
|
171
211
|
## Shared chat: host controls
|
|
172
212
|
|
|
173
213
|
`ChatWorkspace` (from `@micha.bigler/ui-core-micha/chat`) takes optional props for apps that put UI around the surface;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { Box, Button, IconButton, Stack, TextField } from '@mui/material';
|
|
3
|
+
import { Box, Button, IconButton, LinearProgress, Stack, TextField, Typography } from '@mui/material';
|
|
4
4
|
import SendIcon from '@mui/icons-material/Send';
|
|
5
5
|
import StopIcon from '@mui/icons-material/Stop';
|
|
6
6
|
import CloseIcon from '@mui/icons-material/Close';
|
|
@@ -27,6 +27,7 @@ export const CHAT_COMPOSER_NOTICE_SX = { display: 'flex', alignItems: 'center',
|
|
|
27
27
|
export const CHAT_COMPOSER_NOTICE_TEXT_SX = { minWidth: 0, flex: '1 1 auto', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' };
|
|
28
28
|
export const CHAT_COMPOSER_NOTICE_ACTION_SX = { flex: '0 0 auto', minWidth: 0, p: 0.25, whiteSpace: 'nowrap' };
|
|
29
29
|
export const CHAT_COMPOSER_NOTICE_CLOSE_SX = { width: 28, height: 28, flex: '0 0 28px' };
|
|
30
|
+
export const CHAT_COMPOSER_USAGE_METER_SX = { height: 3 };
|
|
30
31
|
function CompactNotice({ notice, t }) {
|
|
31
32
|
if (!notice)
|
|
32
33
|
return null;
|
|
@@ -35,9 +36,23 @@ function CompactNotice({ notice, t }) {
|
|
|
35
36
|
return notice;
|
|
36
37
|
return (_jsxs(Box, { role: "status", sx: CHAT_COMPOSER_NOTICE_SX, children: [_jsx(Box, { component: "span", sx: CHAT_COMPOSER_NOTICE_TEXT_SX, children: details.text || details.content }), details.action ? _jsx(Button, { size: "small", color: "inherit", sx: CHAT_COMPOSER_NOTICE_ACTION_SX, onClick: details.onAction, children: details.action }) : null, _jsx(IconButton, { "aria-label": t('Chat.dismissNotice'), size: "small", sx: CHAT_COMPOSER_NOTICE_CLOSE_SX, onClick: details.onDismiss, children: _jsx(CloseIcon, { fontSize: "small" }) })] }));
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
function UsageLimit({ usageLimit, t, language }) {
|
|
40
|
+
if (!usageLimit)
|
|
41
|
+
return null;
|
|
42
|
+
const format = (micros) => new Intl.NumberFormat(language, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(micros / 1000000);
|
|
43
|
+
const reached = usageLimit.usedUsdMicros >= usageLimit.limitUsdMicros;
|
|
44
|
+
const date = new Date(usageLimit.resetsAt);
|
|
45
|
+
const resetDate = Number.isNaN(date.getTime()) ? usageLimit.resetsAt : new Intl.DateTimeFormat(language, { dateStyle: 'medium' }).format(date);
|
|
46
|
+
const usageText = t('Chat.limitUsage', { used: format(usageLimit.usedUsdMicros), limit: format(usageLimit.limitUsdMicros) });
|
|
47
|
+
return _jsxs(Stack, { spacing: 0.5, children: [reached
|
|
48
|
+
? _jsxs(_Fragment, { children: [_jsx(Typography, { variant: "caption", color: "text.secondary", children: t(`Chat.limitReached.${usageLimit.period}`) }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('Chat.limitResets', { date: resetDate }) })] })
|
|
49
|
+
: _jsx(Typography, { variant: "caption", color: "text.secondary", children: usageText }), _jsx(LinearProgress, { variant: "determinate", "aria-label": usageText, value: reached ? 100 : Math.min(100, (usageLimit.usedUsdMicros / usageLimit.limitUsdMicros) * 100), sx: CHAT_COMPOSER_USAGE_METER_SX })] });
|
|
50
|
+
}
|
|
51
|
+
export function ChatComposer({ value = '', onChange, onSend, onStop, running = false, archived = false, connected = true, inputRef, sx, actions, layout = 'standard', context, notice, usageLimit = null }) {
|
|
52
|
+
const { t, i18n } = useTranslation();
|
|
53
|
+
const limitReached = Boolean(usageLimit && usageLimit.usedUsdMicros >= usageLimit.limitUsdMicros);
|
|
54
|
+
const blocked = archived || !connected || limitReached;
|
|
55
|
+
const language = typeof (i18n === null || i18n === void 0 ? void 0 : i18n.language) === 'string' ? i18n.language.split('_')[0] || undefined : undefined;
|
|
41
56
|
const canSend = !running && !blocked && value.trim().length > 0;
|
|
42
57
|
const submit = () => { if (canSend)
|
|
43
58
|
onSend === null || onSend === void 0 ? void 0 : onSend(); };
|
|
@@ -49,9 +64,9 @@ export function ChatComposer({ value = '', onChange, onSend, onStop, running = f
|
|
|
49
64
|
}
|
|
50
65
|
};
|
|
51
66
|
if (layout === 'compact')
|
|
52
|
-
return (_jsxs(Stack, { sx: sx ? [CHAT_COMPOSER_COMPACT_ROOT_SX, sx] : CHAT_COMPOSER_COMPACT_ROOT_SX, children: [_jsx(CompactNotice, { notice: notice, t: t }), _jsxs(Stack, { direction: "row", alignItems: "center", sx: CHAT_COMPOSER_CONTEXT_ROW_SX, children: [_jsx(Box, { sx: CHAT_COMPOSER_CONTEXT_SX, children: context }), actions ? _jsx(Box, { sx: CHAT_COMPOSER_CONTEXT_ACTIONS_SX, children: actions }) : null] }), _jsxs(Stack, { direction: "row", alignItems: "flex-end", sx: CHAT_COMPOSER_INPUT_ROW_SX, children: [_jsx(TextField, { multiline: true, maxRows: 5, variant: "outlined", sx: CHAT_COMPOSER_COMPACT_FIELD_SX, size: "small", value: value, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onChange: (event) => onChange === null || onChange === void 0 ? void 0 : onChange(event.target.value), onKeyDown: handleKeyDown }), running
|
|
67
|
+
return (_jsxs(Stack, { sx: sx ? [CHAT_COMPOSER_COMPACT_ROOT_SX, sx] : CHAT_COMPOSER_COMPACT_ROOT_SX, children: [_jsx(CompactNotice, { notice: notice, t: t }), _jsx(UsageLimit, { usageLimit: usageLimit, t: t, language: language }), _jsxs(Stack, { direction: "row", alignItems: "center", sx: CHAT_COMPOSER_CONTEXT_ROW_SX, children: [_jsx(Box, { sx: CHAT_COMPOSER_CONTEXT_SX, children: context }), actions ? _jsx(Box, { sx: CHAT_COMPOSER_CONTEXT_ACTIONS_SX, children: actions }) : null] }), _jsxs(Stack, { direction: "row", alignItems: "flex-end", sx: CHAT_COMPOSER_INPUT_ROW_SX, children: [_jsx(TextField, { multiline: true, maxRows: 5, variant: "outlined", sx: CHAT_COMPOSER_COMPACT_FIELD_SX, size: "small", value: value, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onChange: (event) => onChange === null || onChange === void 0 ? void 0 : onChange(event.target.value), onKeyDown: handleKeyDown }), running
|
|
53
68
|
? _jsx(IconButton, { "aria-label": t('Chat.stopAnswer'), title: t('Chat.stopAnswer'), sx: CHAT_COMPOSER_ACTION_SX, onClick: onStop, children: _jsx(StopIcon, {}) })
|
|
54
69
|
: _jsx(IconButton, { "aria-label": t('Chat.send'), sx: CHAT_COMPOSER_SEND_SX, onClick: submit, disabled: !canSend, children: _jsx(SendIcon, { fontSize: "small" }) })] })] }));
|
|
55
|
-
return (_jsxs(Stack, { direction: "row", alignItems: "flex-end", flexWrap: "wrap", gap: 1, sx: Object.assign({ p: { xs: 1, md: 2 }, borderTop: 1, borderColor: 'divider' }, sx), children: [_jsx(TextField, { multiline: true, maxRows: 6, sx: CHAT_COMPOSER_INPUT_SX, size: "small", value: value, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onChange: (event) => onChange === null || onChange === void 0 ? void 0 : onChange(event.target.value), onKeyDown: handleKeyDown }), actions ? _jsx(Stack, { direction: "row", alignItems: "flex-end", children: actions }) : null, running ? _jsx(Button, { variant: "outlined", onClick: onStop, children: t('Chat.stop') }) : null, _jsx(Button, { variant: "contained", onClick: submit, disabled: !canSend, children: t('Chat.send') })] }));
|
|
70
|
+
return (_jsxs(Stack, { direction: "row", alignItems: "flex-end", flexWrap: "wrap", gap: 1, sx: Object.assign({ p: { xs: 1, md: 2 }, borderTop: 1, borderColor: 'divider' }, sx), children: [usageLimit ? _jsx(Stack, { flexBasis: "100%", children: _jsx(UsageLimit, { usageLimit: usageLimit, t: t, language: language }) }) : null, _jsx(TextField, { multiline: true, maxRows: 6, sx: CHAT_COMPOSER_INPUT_SX, size: "small", value: value, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onChange: (event) => onChange === null || onChange === void 0 ? void 0 : onChange(event.target.value), onKeyDown: handleKeyDown }), actions ? _jsx(Stack, { direction: "row", alignItems: "flex-end", children: actions }) : null, running ? _jsx(Button, { variant: "outlined", onClick: onStop, children: t('Chat.stop') }) : null, _jsx(Button, { variant: "contained", onClick: submit, disabled: !canSend, children: t('Chat.send') })] }));
|
|
56
71
|
}
|
|
57
72
|
export default ChatComposer;
|
package/dist/chat/ChatThread.js
CHANGED
|
@@ -6,6 +6,7 @@ import MarkdownReply from './MarkdownReply';
|
|
|
6
6
|
export const CHAT_THREAD_TOOL_CHIP_SX = { alignSelf: 'flex-start' };
|
|
7
7
|
export const CHAT_THREAD_NOTICE_SX = { mb: 2 };
|
|
8
8
|
export const CHAT_THREAD_TRIMMED_SX = { mb: 1.5 };
|
|
9
|
+
export const CHAT_THREAD_TOOL_STEPS_SX = { alignItems: 'flex-start' };
|
|
9
10
|
const selectionLine = (turn, t) => [turn.model, turn.effort && t(`Chat.effort.${turn.effort}`)].filter(Boolean).join(' · ');
|
|
10
11
|
const sameSelection = (a, b) => a.driver === b.driver && a.model === b.model && a.effort === b.effort;
|
|
11
12
|
function SourceChips({ sources }) {
|
|
@@ -14,8 +15,9 @@ function SourceChips({ sources }) {
|
|
|
14
15
|
return null;
|
|
15
16
|
return (_jsx(Stack, { direction: "row", flexWrap: "wrap", gap: 0.75, role: "list", "aria-label": t('Chat.sources'), children: sources.map((source, index) => (_jsx(Tooltip, { title: source.reference || '', describeChild: true, children: _jsx(Chip, { role: "listitem", size: "small", variant: "outlined", label: source.label }) }, `${source.label}-${index}`))) }));
|
|
16
17
|
}
|
|
17
|
-
function Answer({ turn, tool, onRetry, chat, renderAnswerExtra, usageToTokens }) {
|
|
18
|
+
function Answer({ turn, tool, onRetry, chat, renderAnswerExtra, usageToTokens, onNavigate }) {
|
|
18
19
|
var _a;
|
|
20
|
+
var _b;
|
|
19
21
|
const { t, i18n } = useTranslation();
|
|
20
22
|
const generating = turn.state === 'generating';
|
|
21
23
|
const failed = ['failed', 'cancelled'].includes(turn.state) && turn.error_code;
|
|
@@ -27,13 +29,13 @@ function Answer({ turn, tool, onRetry, chat, renderAnswerExtra, usageToTokens })
|
|
|
27
29
|
}
|
|
28
30
|
return selectionLine(turn, t);
|
|
29
31
|
};
|
|
30
|
-
return (_jsxs(Stack, { spacing: 1, "aria-busy": generating, children: [turn.assistant_text ? _jsx(MarkdownReply, { text: turn.assistant_text }) : null, generating && !turn.assistant_text && !tool ? _jsx(Typography, { variant: "body2", color: "text.secondary", children: t('Chat.typing') }) : null, generating && tool ? _jsx(Chip, { size: "small", color: "primary", variant: "outlined", label: tool.label, sx: CHAT_THREAD_TOOL_CHIP_SX }) : null, _jsx(SourceChips, { sources: turn.sources }), !generating && replyCaption(turn) ? _jsx(Typography, { variant: "caption", color: "text.secondary", children: replyCaption(turn) }) : null, renderAnswerExtra ? _jsx(React.Fragment, { children: renderAnswerExtra({ turn, chat, appFrames: (
|
|
32
|
+
return (_jsxs(Stack, { spacing: 1, "aria-busy": generating, children: [turn.assistant_text ? _jsx(MarkdownReply, { text: turn.assistant_text, onNavigate: onNavigate }) : null, generating && !turn.assistant_text && !tool ? _jsx(Typography, { variant: "body2", color: "text.secondary", children: t('Chat.typing') }) : null, generating && tool ? _jsx(Chip, { size: "small", color: "primary", variant: "outlined", label: tool.label, sx: CHAT_THREAD_TOOL_CHIP_SX }) : null, !generating && ((_a = turn.tool_steps) === null || _a === void 0 ? void 0 : _a.length) ? _jsx(Stack, { direction: "row", flexWrap: "wrap", gap: 0.75, role: "list", "aria-label": t('Chat.toolSteps'), sx: CHAT_THREAD_TOOL_STEPS_SX, children: turn.tool_steps.map((step, index) => _jsx(Chip, { role: "listitem", size: "small", variant: "outlined", label: step.label, sx: CHAT_THREAD_TOOL_CHIP_SX }, `${step.name || step.label}-${index}`)) }) : null, _jsx(SourceChips, { sources: turn.sources }), !generating && replyCaption(turn) ? _jsx(Typography, { variant: "caption", color: "text.secondary", children: replyCaption(turn) }) : null, renderAnswerExtra ? _jsx(React.Fragment, { children: renderAnswerExtra({ turn, chat, appFrames: (_b = turn.appFrames) !== null && _b !== void 0 ? _b : [] }) }, chat === null || chat === void 0 ? void 0 : chat.id) : null, turn.state === 'interrupted' ? (_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, children: [_jsx(Chip, { size: "small", color: "warning", label: t('Chat.interrupted') }), onRetry ? _jsx(Button, { size: "small", onClick: () => onRetry(turn), children: t('Chat.retry') }) : null] })) : null, failed ? (_jsx(Alert, { severity: "error", action: onRetry ? _jsx(Button, { color: "inherit", size: "small", onClick: () => onRetry(turn), children: t('Chat.retry') }) : null, children: t('Chat.answerIncomplete') })) : null] }));
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* The turns of one chat. The streaming answer is simply the last turn in state `generating`; the caller keeps its text
|
|
34
36
|
* up to date. `notice` is a connection or limit message shown under the last turn. `readOnly` (an archived chat) hides Retry.
|
|
35
37
|
*/
|
|
36
|
-
export function ChatThread({ turns = [], tool = null, notice = null, hasOlder = false, olderBusy = false, onLoadOlder, onRetry, readOnly = false, sx, chat, renderAnswerExtra, trimmedCount, summary = null, usageToTokens }) {
|
|
38
|
+
export function ChatThread({ turns = [], tool = null, notice = null, hasOlder = false, olderBusy = false, onLoadOlder, onRetry, readOnly = false, sx, chat, renderAnswerExtra, trimmedCount, summary = null, usageToTokens, onNavigate }) {
|
|
37
39
|
var _a, _b;
|
|
38
40
|
const { t } = useTranslation();
|
|
39
41
|
const end = useRef(null);
|
|
@@ -79,7 +81,7 @@ export function ChatThread({ turns = [], tool = null, notice = null, hasOlder =
|
|
|
79
81
|
}, role: "log", "aria-live": "polite", "aria-label": t('Chat.thread'), sx: Object.assign({ minHeight: 0, flex: 1, overflowY: 'auto', p: { xs: 1.5, md: 2.5 } }, sx), children: [hasOlder ? (_jsx(Box, { sx: { textAlign: 'center', mb: 2 }, children: _jsx(Button, { size: "small", onClick: loadOlder, disabled: olderBusy, children: t('Chat.loadOlder') }) })) : null, turns.length === 0 ? (_jsx(Typography, { variant: "h6", color: "text.secondary", align: "center", sx: { mt: 6 }, children: t('Chat.emptyTitle') })) : null, turns.map((turn, index) => {
|
|
80
82
|
var _a;
|
|
81
83
|
const previous = turns[index - 1];
|
|
82
|
-
return (_jsxs(Box, { sx: { mb: 3 }, children: [!summaryRendered && summaryVisible && turn.seq > summary.up_to_seq ? (summaryRendered = true, renderSummary()) : null, previous && !sameSelection(previous, turn) ? (_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, sx: { mb: 2, color: 'text.secondary' }, role: "separator", children: [_jsx(Box, { sx: { flex: 1, borderTop: 1, borderColor: 'divider' } }), _jsx(Typography, { variant: "caption", children: t('Chat.modelChanged', { model: selectionLine(turn, t) }) }), _jsx(Box, { sx: { flex: 1, borderTop: 1, borderColor: 'divider' } })] })) : null, _jsx(Box, { sx: { display: 'flex', justifyContent: 'flex-end', mb: 1.5 }, children: _jsx(Typography, { sx: { maxWidth: '85%', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', bgcolor: 'action.hover', borderRadius: 2, px: 1.5, py: 1 }, children: turn.user_text }) }), _jsx(Answer, { turn: turn, tool: index === turns.length - 1 ? tool : null, onRetry: readOnly ? undefined : onRetry, chat: chat, renderAnswerExtra: renderAnswerExtra, usageToTokens: usageToTokens })] }, (_a = turn.id) !== null && _a !== void 0 ? _a : index));
|
|
84
|
+
return (_jsxs(Box, { sx: { mb: 3 }, children: [!summaryRendered && summaryVisible && turn.seq > summary.up_to_seq ? (summaryRendered = true, renderSummary()) : null, previous && !sameSelection(previous, turn) ? (_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, sx: { mb: 2, color: 'text.secondary' }, role: "separator", children: [_jsx(Box, { sx: { flex: 1, borderTop: 1, borderColor: 'divider' } }), _jsx(Typography, { variant: "caption", children: t('Chat.modelChanged', { model: selectionLine(turn, t) }) }), _jsx(Box, { sx: { flex: 1, borderTop: 1, borderColor: 'divider' } })] })) : null, _jsx(Box, { sx: { display: 'flex', justifyContent: 'flex-end', mb: 1.5 }, children: _jsx(Typography, { sx: { maxWidth: '85%', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', bgcolor: 'action.hover', borderRadius: 2, px: 1.5, py: 1 }, children: turn.user_text }) }), _jsx(Answer, { turn: turn, tool: index === turns.length - 1 ? tool : null, onRetry: readOnly ? undefined : onRetry, chat: chat, renderAnswerExtra: renderAnswerExtra, usageToTokens: usageToTokens, onNavigate: onNavigate })] }, (_a = turn.id) !== null && _a !== void 0 ? _a : index));
|
|
83
85
|
}), !summaryRendered ? renderSummary() : null, trimmedCount ? _jsx(Chip, { size: "small", variant: "outlined", label: t(trimmedCount === 1 ? 'Chat.historyTrimmed_one' : 'Chat.historyTrimmed_other', { count: trimmedCount }), sx: CHAT_THREAD_TRIMMED_SX }) : null, notice ? (_jsx(Alert, { severity: notice.severity || 'warning', sx: CHAT_THREAD_NOTICE_SX, action: notice.action ? _jsx(Button, { color: "inherit", size: "small", onClick: notice.action.onClick, children: notice.action.label }) : null, children: notice.text })) : null, _jsx("div", { ref: end })] }));
|
|
84
86
|
}
|
|
85
87
|
export default ChatThread;
|
|
@@ -63,7 +63,7 @@ const appendDelta = (turns, text) => {
|
|
|
63
63
|
* calls; every function not given keeps its default), `scope` (passed when creating a chat),
|
|
64
64
|
* `preloadedChats` (optional active-list response `{ scope, results, next }` already loaded for that exact scope), `sx`.
|
|
65
65
|
*/
|
|
66
|
-
export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloadedChats, sx, unavailableReasonText, sidePanel, sidePanelLabel, renderAnswerExtra, renderComposerExtra, composerLayout = 'standard', renderComposerContext, onAppFrame, activeChatId, onActiveChatChange, composerPrefill, getSendContext, sendRequest, onSendRequestHandled, layout = 'viewport', compactBelow = 720, tokenBalance = null, usageToTokens, longChatTokens = 40000 }) {
|
|
66
|
+
export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloadedChats, sx, unavailableReasonText, sidePanel, sidePanelLabel, renderAnswerExtra, renderComposerExtra, composerLayout = 'standard', renderComposerContext, onAppFrame, onNavigate, activeChatId, onActiveChatChange, composerPrefill, getSendContext, sendRequest, onSendRequestHandled, layout = 'viewport', compactBelow = 720, tokenBalance = null, usageToTokens, longChatTokens = 40000 }) {
|
|
67
67
|
var _a;
|
|
68
68
|
const { t } = useTranslation();
|
|
69
69
|
const theme = useTheme();
|
|
@@ -89,6 +89,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
89
89
|
const api = useMemo(() => createChatApi(apiOverrides, { apiBase }), [apiOverrides, apiBase]);
|
|
90
90
|
const [catalogue, setCatalogue] = useState({ entries: [], default: null });
|
|
91
91
|
const [summary, setSummary] = useState(null);
|
|
92
|
+
const [usageLimit, setUsageLimit] = useState(null);
|
|
92
93
|
// The chat the current catalogue was requested for: a general catalogue must never drive the stored selection of a chat.
|
|
93
94
|
const [catalogueChatId, setCatalogueChatId] = useState(null);
|
|
94
95
|
const [chats, setChats] = useState([]);
|
|
@@ -131,6 +132,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
131
132
|
const [dismissedComposerNotices, setDismissedComposerNotices] = useState(() => new Set());
|
|
132
133
|
const running = turns.some(isGenerating);
|
|
133
134
|
const isArchived = Boolean(chat === null || chat === void 0 ? void 0 : chat.archived_at);
|
|
135
|
+
const usageLimitReached = Boolean(usageLimit && usageLimit.usedUsdMicros >= usageLimit.limitUsdMicros);
|
|
134
136
|
const selection = (chat === null || chat === void 0 ? void 0 : chat.selection) || catalogue.default;
|
|
135
137
|
const activeEntry = catalogue.entries.find((entry) => entry.id === (selection === null || selection === void 0 ? void 0 : selection.entry));
|
|
136
138
|
const latestUsageTurn = [...turns].reverse().find((turn) => turn.usage);
|
|
@@ -165,7 +167,31 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
165
167
|
const shownChatId = useRef(null);
|
|
166
168
|
// Bumped on every scope change so that a list response of the previous scope is dropped.
|
|
167
169
|
const scopeVersion = useRef(0);
|
|
168
|
-
|
|
170
|
+
const limitRequest = useRef(0);
|
|
171
|
+
const refreshLimit = useCallback(async (chatId) => {
|
|
172
|
+
const request = ++limitRequest.current;
|
|
173
|
+
const version = scopeVersion.current;
|
|
174
|
+
const current = () => request === limitRequest.current && version === scopeVersion.current
|
|
175
|
+
&& (chatId === undefined || String(shownChatId.current) === String(chatId));
|
|
176
|
+
try {
|
|
177
|
+
const data = await api.getLimit();
|
|
178
|
+
if (!current())
|
|
179
|
+
return;
|
|
180
|
+
if (!data || !['day', 'month'].includes(data.period)
|
|
181
|
+
|| !Number.isInteger(data.limit_usd_micros) || data.limit_usd_micros < 0
|
|
182
|
+
|| !Number.isInteger(data.used_usd_micros) || data.used_usd_micros < 0
|
|
183
|
+
|| typeof data.resets_at !== 'string') {
|
|
184
|
+
setUsageLimit(null);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
setUsageLimit({ period: data.period, limitUsdMicros: data.limit_usd_micros, usedUsdMicros: data.used_usd_micros, resetsAt: data.resets_at });
|
|
188
|
+
}
|
|
189
|
+
catch (_a) {
|
|
190
|
+
if (current())
|
|
191
|
+
setUsageLimit(null);
|
|
192
|
+
}
|
|
193
|
+
}, [api]);
|
|
194
|
+
useEffect(() => { scopeVersion.current += 1; limitRequest.current += 1; setUsageLimit(null); setChat(null); setListsLoaded(false); appliedId.current = undefined; unloadableIds.current.clear(); }, [scope]);
|
|
169
195
|
const loadLists = useCallback(async ({ initial = false, preloaded } = {}) => {
|
|
170
196
|
const version = scopeVersion.current;
|
|
171
197
|
// Without a scope the api is called exactly as before the scope existed.
|
|
@@ -208,6 +234,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
208
234
|
setUnavailableReason(state.reason || null);
|
|
209
235
|
return;
|
|
210
236
|
}
|
|
237
|
+
refreshLimit();
|
|
211
238
|
Promise.all([catalogueRequest, listsRequest]).then(([entries, lists]) => {
|
|
212
239
|
if (!live || lists === undefined)
|
|
213
240
|
return;
|
|
@@ -225,7 +252,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
225
252
|
.catch(() => { if (live)
|
|
226
253
|
setStatus('error'); });
|
|
227
254
|
return () => { live = false; };
|
|
228
|
-
}, [api, loadLists, scope]);
|
|
255
|
+
}, [api, loadLists, refreshLimit, scope]);
|
|
229
256
|
useEffect(() => { if ((chat === null || chat === void 0 ? void 0 : chat.id) !== undefined)
|
|
230
257
|
refreshCatalogue(chat.id); }, [chat === null || chat === void 0 ? void 0 : chat.id, refreshCatalogue]);
|
|
231
258
|
useEffect(() => { if (pickerOpen)
|
|
@@ -331,6 +358,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
331
358
|
setTool(null);
|
|
332
359
|
setTurns((current) => { const pending = current.findLast(isGenerating); return settleTurn(current, Object.assign(Object.assign({}, frame.turn), { appFrames: (pending === null || pending === void 0 ? void 0 : pending.appFrames) || [] })); });
|
|
333
360
|
refreshCatalogue(chatId);
|
|
361
|
+
refreshLimit(chatId);
|
|
334
362
|
if (frame.turn.error_code === 'quota_exceeded')
|
|
335
363
|
setProblem('quota_exceeded');
|
|
336
364
|
}
|
|
@@ -340,8 +368,10 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
340
368
|
setProblem(frame.code);
|
|
341
369
|
if (frame.code === 'unavailable')
|
|
342
370
|
setUnavailableReason(frame.reason || unavailableReason);
|
|
371
|
+
if (frame.code === 'quota_exceeded')
|
|
372
|
+
refreshLimit(chatId);
|
|
343
373
|
}
|
|
344
|
-
}, [chat === null || chat === void 0 ? void 0 : chat.id, api, refreshCatalogue]);
|
|
374
|
+
}, [chat === null || chat === void 0 ? void 0 : chat.id, api, refreshCatalogue, refreshLimit]);
|
|
345
375
|
const onOpen = useCallback((chatId) => { connectedChatId.current = String(chatId); setOpenedOnce(true); setProblem((current) => (current === 'connection_lost' ? null : current)); }, []);
|
|
346
376
|
const onClose = useCallback(({ reason, retrying }) => { connectedChatId.current = null; if (!retrying)
|
|
347
377
|
setProblem(reason); }, []);
|
|
@@ -527,7 +557,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
527
557
|
session_ended: 'Chat.sessionEnded', access_lost: 'Chat.accessLost', rate_limited: 'Chat.rateLimited',
|
|
528
558
|
load_error: 'Chat.loadError', action_error: 'Chat.actionError',
|
|
529
559
|
};
|
|
530
|
-
if (problem === 'quota_exceeded') {
|
|
560
|
+
if (problem === 'quota_exceeded' && !usageLimitReached) {
|
|
531
561
|
return { text: t('Chat.usageLimit', { model: (activeEntry === null || activeEntry === void 0 ? void 0 : activeEntry.label) || (activeEntry === null || activeEntry === void 0 ? void 0 : activeEntry.model) || '' }), action: { label: t('Chat.changeModel'), onClick: () => setPickerOpen(true) } };
|
|
532
562
|
}
|
|
533
563
|
if (problem === 'connection_lost')
|
|
@@ -552,9 +582,9 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
552
582
|
if (unavailable) {
|
|
553
583
|
return (_jsx(Stack, { alignItems: "center", justifyContent: "center", spacing: 1, sx: Object.assign({ minHeight: 320, p: 3, textAlign: 'center' }, sx), children: _jsx(Typography, { color: "text.secondary", children: unavailableText || t('Chat.notAvailableHere') }) }));
|
|
554
584
|
}
|
|
555
|
-
return (_jsxs(Box, { ref: rootRef, sx: Object.assign({ display: 'grid', gridTemplateColumns: narrow ? 'minmax(0, 1fr)' : `minmax(240px, 320px) minmax(0, 1fr)${chat && sidePanel ? ' minmax(240px, 320px)' : ''}`, height: '100%', minHeight: 480, border: 1, borderColor: 'divider', borderRadius: 1, overflow: 'hidden', bgcolor: 'background.paper' }, sx), children: [narrow ? null : _jsx(Box, { sx: { borderRight: 1, borderColor: 'divider', minHeight: 0 }, children: list }), _jsxs(Stack, { sx: { minWidth: 0, minHeight: 0 }, children: [_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, sx: { px: 1.5, py: 0.5, borderBottom: 1, borderColor: 'divider', minHeight: 56 }, children: [narrow ? _jsx(Button, { color: "inherit", onClick: () => setListOpen(true), children: t('Chat.chats') }) : null, _jsx(Typography, { noWrap: true, sx: { flex: 1, fontWeight: 600 }, children: chat ? (chat.title || t('Chat.untitled')) : '' }), socket.status === 'connecting' && openedOnce ? _jsx(Chip, { size: "small", color: "warning", variant: "outlined", label: t('Chat.reconnecting') }) : null, isArchived ? _jsx(Chip, { size: "small", label: t('Chat.archived') }) : null, isArchived ? _jsx(Button, { size: "small", onClick: () => updateChat(chat, { archived: false }), children: t('Chat.restore') }) : null, chat && sidePanel && narrow ? _jsx(Button, { color: "inherit", onClick: () => setSidePanelOpen(true), children: sidePanelLabel || t('Chat.sidePanel') }) : null] }), chat ? (_jsxs(_Fragment, { children: [_jsx(ChatThread, { turns: turns, chat: chat, renderAnswerExtra: answerExtra, trimmedCount: trimmedCount, tool: tool, notice: noticeFor(), hasOlder: Boolean(olderCursor), olderBusy: olderBusy, onLoadOlder: loadOlder, onRetry: retry, readOnly: isArchived, summary: summary, usageToTokens: usageToTokens }), isArchived ? _jsx(Typography, { variant: "caption", color: "text.secondary", sx: { px: 2, pb: 1 }, children: t('Chat.archivedReadOnly') }) : null, renderComposerExtra ? _jsx(Box, { children: renderComposerExtra({ chat }) }, chat.id) : null, composerLayout !== 'compact' && longChat ? _jsx(Alert, { severity: "info", action: _jsx(Button, { color: "inherit", size: "small", onClick: createChat, children: t('Chat.newConversation') }), children: t('Chat.longChat') }) : null, _jsx(ChatComposer, { layout: composerLayout, context: composerLayout === 'compact' ? renderComposerContext === null || renderComposerContext === void 0 ? void 0 : renderComposerContext({ chat }) : undefined, notice: composerLayout === 'compact' && longChat && !dismissedComposerNotices.has(`${chat.id}:long-chat`) ? {
|
|
585
|
+
return (_jsxs(Box, { ref: rootRef, sx: Object.assign({ display: 'grid', gridTemplateColumns: narrow ? 'minmax(0, 1fr)' : `minmax(240px, 320px) minmax(0, 1fr)${chat && sidePanel ? ' minmax(240px, 320px)' : ''}`, height: '100%', minHeight: 480, border: 1, borderColor: 'divider', borderRadius: 1, overflow: 'hidden', bgcolor: 'background.paper' }, sx), children: [narrow ? null : _jsx(Box, { sx: { borderRight: 1, borderColor: 'divider', minHeight: 0 }, children: list }), _jsxs(Stack, { sx: { minWidth: 0, minHeight: 0 }, children: [_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, sx: { px: 1.5, py: 0.5, borderBottom: 1, borderColor: 'divider', minHeight: 56 }, children: [narrow ? _jsx(Button, { color: "inherit", onClick: () => setListOpen(true), children: t('Chat.chats') }) : null, _jsx(Typography, { noWrap: true, sx: { flex: 1, fontWeight: 600 }, children: chat ? (chat.title || t('Chat.untitled')) : '' }), socket.status === 'connecting' && openedOnce ? _jsx(Chip, { size: "small", color: "warning", variant: "outlined", label: t('Chat.reconnecting') }) : null, isArchived ? _jsx(Chip, { size: "small", label: t('Chat.archived') }) : null, isArchived ? _jsx(Button, { size: "small", onClick: () => updateChat(chat, { archived: false }), children: t('Chat.restore') }) : null, chat && sidePanel && narrow ? _jsx(Button, { color: "inherit", onClick: () => setSidePanelOpen(true), children: sidePanelLabel || t('Chat.sidePanel') }) : null] }), chat ? (_jsxs(_Fragment, { children: [_jsx(ChatThread, { turns: turns, chat: chat, renderAnswerExtra: answerExtra, trimmedCount: trimmedCount, tool: tool, notice: noticeFor(), hasOlder: Boolean(olderCursor), olderBusy: olderBusy, onLoadOlder: loadOlder, onRetry: retry, readOnly: isArchived, summary: summary, usageToTokens: usageToTokens, onNavigate: onNavigate }), isArchived ? _jsx(Typography, { variant: "caption", color: "text.secondary", sx: { px: 2, pb: 1 }, children: t('Chat.archivedReadOnly') }) : null, renderComposerExtra ? _jsx(Box, { children: renderComposerExtra({ chat }) }, chat.id) : null, composerLayout !== 'compact' && longChat ? _jsx(Alert, { severity: "info", action: _jsx(Button, { color: "inherit", size: "small", onClick: createChat, children: t('Chat.newConversation') }), children: t('Chat.longChat') }) : null, _jsx(ChatComposer, { layout: composerLayout, context: composerLayout === 'compact' ? renderComposerContext === null || renderComposerContext === void 0 ? void 0 : renderComposerContext({ chat }) : undefined, notice: composerLayout === 'compact' && longChat && !dismissedComposerNotices.has(`${chat.id}:long-chat`) ? {
|
|
556
586
|
id: 'long-chat', text: t('Chat.longChatShort'), action: t('Chat.newChat'), onAction: createChat,
|
|
557
587
|
onDismiss: () => setDismissedComposerNotices((current) => new Set(current).add(`${chat.id}:long-chat`)),
|
|
558
|
-
} : null, value: draft, onChange: setDraft, onSend: send, onStop: () => socket.send({ type: 'stop' }), running: running, archived: isArchived, connected: socket.connected, inputRef: composerInputRef, actions: _jsx(ModelPicker, { entries: catalogue.entries, selection: selection, disabled: isArchived || running || (catalogueLoading && catalogueChatId !== chat.id), open: pickerOpen, onOpenChange: setPickerOpen, onChange: (next) => updateChat(chat, { selection: next }), sheet: narrow, balance: tokenBalance, longChat: longChat, onNewChat: createChat, shortLabel: composerLayout === 'compact' }) })] })) : (_jsxs(Stack, { alignItems: "center", justifyContent: "center", spacing: 2, sx: { flex: 1, p: 3 }, children: [_jsx(Typography, { color: "text.secondary", align: "center", children: t('Chat.selectChat') }), _jsx(Button, { variant: "contained", onClick: createChat, children: t('Chat.newChat') })] }))] }), chat && sidePanel && !narrow ? _jsx(Box, { sx: { borderLeft: 1, borderColor: 'divider', minHeight: 0, overflow: 'auto' }, children: sidePanel(chat) }, chat.id) : null, narrow && chat && sidePanel ? _jsx(Drawer, { anchor: "right", open: sidePanelOpen, onClose: () => setSidePanelOpen(false), slotProps: { paper: { 'aria-label': sidePanelLabel || t('Chat.sidePanel') } }, children: _jsx(Box, { children: sidePanel(chat) }, chat.id) }) : null, narrow ? _jsx(Drawer, { open: listOpen, onClose: () => setListOpen(false), slotProps: { paper: { sx: { width: 'min(320px, 86vw)' } } }, children: list }) : null] }));
|
|
588
|
+
} : null, value: draft, onChange: setDraft, onSend: send, onStop: () => socket.send({ type: 'stop' }), running: running, archived: isArchived, connected: socket.connected, inputRef: composerInputRef, usageLimit: usageLimit, actions: _jsx(ModelPicker, { entries: catalogue.entries, selection: selection, disabled: isArchived || running || (catalogueLoading && catalogueChatId !== chat.id), open: pickerOpen, onOpenChange: setPickerOpen, onChange: (next) => updateChat(chat, { selection: next }), sheet: narrow, balance: tokenBalance, longChat: longChat, onNewChat: createChat, shortLabel: composerLayout === 'compact' }) })] })) : (_jsxs(Stack, { alignItems: "center", justifyContent: "center", spacing: 2, sx: { flex: 1, p: 3 }, children: [_jsx(Typography, { color: "text.secondary", align: "center", children: t('Chat.selectChat') }), _jsx(Button, { variant: "contained", onClick: createChat, children: t('Chat.newChat') })] }))] }), chat && sidePanel && !narrow ? _jsx(Box, { sx: { borderLeft: 1, borderColor: 'divider', minHeight: 0, overflow: 'auto' }, children: sidePanel(chat) }, chat.id) : null, narrow && chat && sidePanel ? _jsx(Drawer, { anchor: "right", open: sidePanelOpen, onClose: () => setSidePanelOpen(false), slotProps: { paper: { 'aria-label': sidePanelLabel || t('Chat.sidePanel') } }, children: _jsx(Box, { children: sidePanel(chat) }, chat.id) }) : null, narrow ? _jsx(Drawer, { open: listOpen, onClose: () => setListOpen(false), slotProps: { paper: { sx: { width: 'min(320px, 86vw)' } } }, children: list }) : null] }));
|
|
559
589
|
}
|
|
560
590
|
export default ChatWorkspace;
|
|
@@ -7,12 +7,43 @@ import remarkGfm from 'remark-gfm';
|
|
|
7
7
|
export const MARKDOWN_LIMIT = 200000;
|
|
8
8
|
const allowed = ['p', 'br', 'hr', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'strong', 'em', 'del', 'ul', 'ol', 'li', 'blockquote', 'code', 'pre', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'a', 'img'];
|
|
9
9
|
const plainText = (children) => (Array.isArray(children) ? children : [children]).map((child) => typeof child === 'string' ? child : '').join('');
|
|
10
|
-
function
|
|
10
|
+
function classifyHref(href) {
|
|
11
|
+
if (typeof href !== 'string' || !href || typeof window === 'undefined')
|
|
12
|
+
return null;
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(href, window.location.origin);
|
|
15
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:')
|
|
16
|
+
return null;
|
|
17
|
+
const absolute = /^https?:\/\//i.test(href);
|
|
18
|
+
// Decide by the resolved origin, never by the raw prefix: "/\host" resolves to another host in browsers.
|
|
19
|
+
if (url.origin === window.location.origin && (absolute || (href.startsWith('/') && !href.startsWith('//')))) {
|
|
20
|
+
const path = url.pathname + url.search + url.hash;
|
|
21
|
+
return { type: 'app', href: path, path };
|
|
22
|
+
}
|
|
23
|
+
if (absolute)
|
|
24
|
+
return { type: 'external', href: url.href };
|
|
25
|
+
}
|
|
26
|
+
catch (_a) { /* Render malformed URLs as plain text. */ }
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function MarkdownReply({ text = '', onNavigate }) {
|
|
11
30
|
const { t } = useTranslation();
|
|
12
31
|
if (text.length > MARKDOWN_LIMIT)
|
|
13
32
|
return _jsx(Box, { sx: { whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' }, children: text });
|
|
14
33
|
return _jsx(Box, { sx: { minWidth: 0, overflowWrap: 'anywhere', '& p': { my: 1 }, '& table': { borderCollapse: 'collapse' }, '& th,& td': { border: 1, borderColor: 'divider', p: 1 }, '& pre': { overflowX: 'auto', bgcolor: 'action.hover', p: 1, borderRadius: 1 }, '& blockquote': { borderLeft: 2, borderColor: 'divider', pl: 1, color: 'text.secondary' } }, children: _jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], allowedElements: allowed, unwrapDisallowed: true, components: {
|
|
15
|
-
a: ({ href, children }) => {
|
|
34
|
+
a: ({ href, children }) => {
|
|
35
|
+
const label = plainText(children);
|
|
36
|
+
const link = classifyHref(href);
|
|
37
|
+
if (!link)
|
|
38
|
+
return _jsxs("span", { children: [children, href && href !== label ? ' (' + href + ')' : ''] });
|
|
39
|
+
const handleClick = (event) => {
|
|
40
|
+
if (link.type === 'app' && onNavigate && event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
onNavigate(link.path);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return _jsx("a", Object.assign({ href: link.href, onClick: handleClick }, (link.type === 'external' ? { target: '_blank', rel: 'noopener noreferrer' } : {}), { children: children }));
|
|
46
|
+
},
|
|
16
47
|
img: ({ alt, src }) => _jsx("span", { children: alt || src || '' }),
|
|
17
48
|
table: ({ children }) => _jsx(Box, { role: "region", tabIndex: 0, "aria-label": t('Chat.markdownTable'), sx: { overflowX: 'auto', maxWidth: '100%' }, children: _jsx("table", { children: children }) }),
|
|
18
49
|
pre: ({ children }) => _jsx("pre", { tabIndex: 0, "aria-label": t('Chat.markdownCode'), children: children }),
|
package/dist/chat/ModelPicker.js
CHANGED
|
@@ -64,9 +64,12 @@ export function ModelPicker({ entries = [], selection, onChange, disabled = fals
|
|
|
64
64
|
var _a;
|
|
65
65
|
const shown = supported(entry, effort) ? effort : (_a = entry.efforts) === null || _a === void 0 ? void 0 : _a[0];
|
|
66
66
|
const estimate = estimateText(entry, shown, t, language);
|
|
67
|
+
const averageCost = Number.isInteger(entry.average_cost_usd_micros) && entry.average_cost_usd_micros >= 0
|
|
68
|
+
? t('Chat.estimatePerAnswer', { cost: new Intl.NumberFormat(language, { maximumSignificantDigits: 2 }).format(entry.average_cost_usd_micros / 1000000) })
|
|
69
|
+
: null;
|
|
67
70
|
const provider = providerName(entry);
|
|
68
71
|
const checked = entry.id === (active === null || active === void 0 ? void 0 : active.id);
|
|
69
|
-
return _jsx(ListItemButton, { role: "radio", "aria-checked": checked, tabIndex: checked ? 0 : -1, "data-model-entry": entry.id, selected: checked, sx: CHAT_MODEL_ENTRY_SX, onClick: () => selectEntry(entry), children: _jsx(ListItemText, { primary: _jsx(Typography, { variant: "body2", sx: { fontWeight: 600 }, children: entry.label || entry.model }), secondary: _jsxs(_Fragment, { children: [provider ? t('Chat.by', { provider }) : null, estimate ? _jsx(Box, { component: "span", sx: { display: 'block' }, children: estimate }) : null] }) }) }, entry.id);
|
|
72
|
+
return _jsx(ListItemButton, { role: "radio", "aria-checked": checked, tabIndex: checked ? 0 : -1, "data-model-entry": entry.id, selected: checked, sx: CHAT_MODEL_ENTRY_SX, onClick: () => selectEntry(entry), children: _jsx(ListItemText, { primary: _jsx(Typography, { variant: "body2", sx: { fontWeight: 600 }, children: entry.label || entry.model }), secondary: _jsxs(_Fragment, { children: [provider ? t('Chat.by', { provider }) : null, estimate ? _jsx(Box, { component: "span", sx: { display: 'block' }, children: estimate }) : null, averageCost ? _jsx(Box, { component: "span", sx: { display: 'block' }, children: averageCost }) : null] }) }) }, entry.id);
|
|
70
73
|
};
|
|
71
74
|
// Radio-group keyboard behaviour: arrows move the focus and the choice, only the checked row is a tab stop.
|
|
72
75
|
const moveSelection = (event) => {
|
package/dist/chat/api.js
CHANGED
|
@@ -11,6 +11,7 @@ export function createChatApi(overrides = {}, { apiBase = '/api/assistant/' } =
|
|
|
11
11
|
deleteChat: (id) => data(apiClient.delete(urls.chat(id))),
|
|
12
12
|
listTurns: (id, { cursor } = {}) => data(apiClient.get(urls.turns(id), { params: cursor ? { cursor } : {} })),
|
|
13
13
|
getStatus: ({ scope } = {}) => data(scope !== undefined ? apiClient.get(urls.status, { params: { scope } }) : apiClient.get(urls.status)),
|
|
14
|
+
getLimit: () => data(apiClient.get(urls.limit)),
|
|
14
15
|
};
|
|
15
16
|
return Object.assign(Object.assign({}, defaults), overrides);
|
|
16
17
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createKitSxEntry } from '../theme/kitSxEntry';
|
|
2
|
-
import { CHAT_COMPOSER_INPUT_SX, CHAT_COMPOSER_COMPACT_ROOT_SX, CHAT_COMPOSER_CONTEXT_ROW_SX, CHAT_COMPOSER_CONTEXT_SX, CHAT_COMPOSER_CONTEXT_ACTIONS_SX, CHAT_COMPOSER_INPUT_ROW_SX, CHAT_COMPOSER_COMPACT_FIELD_SX, CHAT_COMPOSER_ACTION_SX, CHAT_COMPOSER_SEND_SX, CHAT_COMPOSER_NOTICE_SX, CHAT_COMPOSER_NOTICE_TEXT_SX, CHAT_COMPOSER_NOTICE_ACTION_SX, CHAT_COMPOSER_NOTICE_CLOSE_SX, } from './ChatComposer';
|
|
2
|
+
import { CHAT_COMPOSER_INPUT_SX, CHAT_COMPOSER_COMPACT_ROOT_SX, CHAT_COMPOSER_CONTEXT_ROW_SX, CHAT_COMPOSER_CONTEXT_SX, CHAT_COMPOSER_CONTEXT_ACTIONS_SX, CHAT_COMPOSER_INPUT_ROW_SX, CHAT_COMPOSER_COMPACT_FIELD_SX, CHAT_COMPOSER_ACTION_SX, CHAT_COMPOSER_SEND_SX, CHAT_COMPOSER_NOTICE_SX, CHAT_COMPOSER_NOTICE_TEXT_SX, CHAT_COMPOSER_NOTICE_ACTION_SX, CHAT_COMPOSER_NOTICE_CLOSE_SX, CHAT_COMPOSER_USAGE_METER_SX, } from './ChatComposer';
|
|
3
3
|
import { CHAT_LIST_ARCHIVED_ACTION_SX, CHAT_LIST_ROW_ACTION_SX } from './ChatList';
|
|
4
|
-
import { CHAT_THREAD_NOTICE_SX, CHAT_THREAD_TOOL_CHIP_SX, CHAT_THREAD_TRIMMED_SX } from './ChatThread';
|
|
4
|
+
import { CHAT_THREAD_NOTICE_SX, CHAT_THREAD_TOOL_CHIP_SX, CHAT_THREAD_TOOL_STEPS_SX, CHAT_THREAD_TRIMMED_SX } from './ChatThread';
|
|
5
5
|
import { CHAT_MODEL_TRIGGER_SX, CHAT_MODEL_TRIGGER_SHORT_SX, CHAT_MODEL_ENTRY_SX, CHAT_MODEL_EFFORT_SX, CHAT_MODEL_CLOSE_SX } from './ModelPicker';
|
|
6
6
|
export const CHAT_KIT_SX_REGISTRY = [
|
|
7
7
|
createKitSxEntry('ChatComposer.input', 'MuiTextField', CHAT_COMPOSER_INPUT_SX, 'CHAT_COMPOSER_INPUT_SX'),
|
|
@@ -17,6 +17,7 @@ export const CHAT_KIT_SX_REGISTRY = [
|
|
|
17
17
|
createKitSxEntry('ChatComposer.noticeText', 'MuiBox', CHAT_COMPOSER_NOTICE_TEXT_SX, 'CHAT_COMPOSER_NOTICE_TEXT_SX'),
|
|
18
18
|
createKitSxEntry('ChatComposer.noticeAction', 'MuiButton', CHAT_COMPOSER_NOTICE_ACTION_SX, 'CHAT_COMPOSER_NOTICE_ACTION_SX'),
|
|
19
19
|
createKitSxEntry('ChatComposer.noticeClose', 'MuiIconButton', CHAT_COMPOSER_NOTICE_CLOSE_SX, 'CHAT_COMPOSER_NOTICE_CLOSE_SX'),
|
|
20
|
+
createKitSxEntry('ChatComposer.usageMeter', 'MuiLinearProgress', CHAT_COMPOSER_USAGE_METER_SX, 'CHAT_COMPOSER_USAGE_METER_SX'),
|
|
20
21
|
createKitSxEntry('ModelPicker.trigger', 'MuiButton', CHAT_MODEL_TRIGGER_SX, 'CHAT_MODEL_TRIGGER_SX'),
|
|
21
22
|
createKitSxEntry('ModelPicker.triggerShort', 'MuiButton', CHAT_MODEL_TRIGGER_SHORT_SX, 'CHAT_MODEL_TRIGGER_SHORT_SX'),
|
|
22
23
|
createKitSxEntry('ModelPicker.entry', 'MuiListItemButton', CHAT_MODEL_ENTRY_SX, 'CHAT_MODEL_ENTRY_SX'),
|
|
@@ -25,6 +26,7 @@ export const CHAT_KIT_SX_REGISTRY = [
|
|
|
25
26
|
createKitSxEntry('ChatList.rowAction', 'MuiIconButton', CHAT_LIST_ROW_ACTION_SX, 'CHAT_LIST_ROW_ACTION_SX'),
|
|
26
27
|
createKitSxEntry('ChatList.archivedAction', 'MuiButton', CHAT_LIST_ARCHIVED_ACTION_SX, 'CHAT_LIST_ARCHIVED_ACTION_SX'),
|
|
27
28
|
createKitSxEntry('ChatThread.toolChip', 'MuiChip', CHAT_THREAD_TOOL_CHIP_SX, 'CHAT_THREAD_TOOL_CHIP_SX'),
|
|
29
|
+
createKitSxEntry('ChatThread.toolSteps', 'MuiStack', CHAT_THREAD_TOOL_STEPS_SX, 'CHAT_THREAD_TOOL_STEPS_SX'),
|
|
28
30
|
createKitSxEntry('ChatThread.trimmed', 'MuiChip', CHAT_THREAD_TRIMMED_SX, 'CHAT_THREAD_TRIMMED_SX'),
|
|
29
31
|
createKitSxEntry('ChatThread.notice', 'MuiAlert', CHAT_THREAD_NOTICE_SX, 'CHAT_THREAD_NOTICE_SX'),
|
|
30
32
|
];
|
package/dist/chat/wire.js
CHANGED
|
@@ -2,7 +2,7 @@ export const CHAT_CLOSE_CODES = { 4401: 'session_ended', 4403: 'access_lost', 44
|
|
|
2
2
|
export const CHAT_ERROR_CODES = ['quota_exceeded', 'provider_error', 'timeout', 'prompt_too_long', 'invalid_output', 'security_violation', 'not_configured', 'rate_limited', 'invalid_selection', 'archived', 'turn_active', 'invalid_frame', 'unavailable'];
|
|
3
3
|
export const chatApiUrls = (base = '/api/assistant/') => {
|
|
4
4
|
const root = base.replace(/\/$/, '') + '/';
|
|
5
|
-
return { catalogue: root + 'catalogue/', chats: root + 'chats/', chat: (id) => root + 'chats/' + encodeURIComponent(id) + '/', turns: (id) => root + 'chats/' + encodeURIComponent(id) + '/turns/', status: root + 'status/' };
|
|
5
|
+
return { catalogue: root + 'catalogue/', chats: root + 'chats/', chat: (id) => root + 'chats/' + encodeURIComponent(id) + '/', turns: (id) => root + 'chats/' + encodeURIComponent(id) + '/turns/', status: root + 'status/', limit: root + 'limit/' };
|
|
6
6
|
};
|
|
7
7
|
export const defaultChatWsUrl = (chatId) => (window.location.protocol === 'https:' ? 'wss:' : 'ws:') + '//' + window.location.host + '/ws/assistant/chats/' + encodeURIComponent(chatId) + '/';
|
|
8
8
|
export const CHAT_FRAME_TYPES = { APP: 'app', NOTICE: 'notice' };
|
|
@@ -55,6 +55,12 @@ export const chatTranslations = {
|
|
|
55
55
|
'Chat.markdownCode': { de: 'Codeblock', en: 'Code block', fr: 'Bloc de code', sw: 'Kizuizi cha msimbo' },
|
|
56
56
|
'Chat.changeModel': { de: 'Modell ändern', en: 'Change model', fr: 'Changer de modèle', sw: 'Badilisha modeli' },
|
|
57
57
|
'Chat.usageLimit': { de: 'Nutzungslimit für {{model}} erreicht. Wählen Sie ein anderes Modell oder versuchen Sie es später erneut.', en: 'Usage limit reached for {{model}}. Choose another model or try again later.', fr: 'Limite d’utilisation atteinte pour {{model}}. Choisissez un autre modèle ou réessayez plus tard.', sw: 'Kikomo cha matumizi kimefikiwa kwa {{model}}. Chagua modeli nyingine au jaribu tena baadaye.' },
|
|
58
|
+
'Chat.limitUsage': { de: '{{used}} von {{limit}} USD', en: '{{used}} of {{limit}} USD', fr: '{{used}} sur {{limit}} USD', sw: '{{used}} kati ya {{limit}} USD' },
|
|
59
|
+
'Chat.limitReached.month': { de: 'Monatslimit erreicht', en: 'Monthly limit reached', fr: 'Limite mensuelle atteinte', sw: 'Kikomo cha mwezi kimefikiwa' },
|
|
60
|
+
'Chat.limitReached.day': { de: 'Tageslimit erreicht', en: 'Daily limit reached', fr: 'Limite journalière atteinte', sw: 'Kikomo cha siku kimefikiwa' },
|
|
61
|
+
'Chat.limitResets': { de: 'Zurückgesetzt am {{date}}', en: 'Resets {{date}}', fr: 'Réinitialisation le {{date}}', sw: 'Huwekwa upya {{date}}' },
|
|
62
|
+
'Chat.estimatePerAnswer': { de: '≈ {{cost}} USD pro Antwort', en: '≈ {{cost}} USD per answer', fr: '≈ {{cost}} USD par réponse', sw: '≈ {{cost}} USD kwa jibu' },
|
|
63
|
+
'Chat.toolSteps': { de: 'Verwendete Werkzeuge', en: 'Tools used', fr: 'Outils utilisés', sw: 'Zana zilizotumika' },
|
|
58
64
|
'Chat.answerIncomplete': { de: 'Die Antwort konnte nicht abgeschlossen werden.', en: 'The answer could not be completed.', fr: 'La réponse n’a pas pu être terminée.', sw: 'Jibu halikuweza kukamilishwa.' },
|
|
59
65
|
'Chat.notAvailableHere': { de: 'Der Assistent ist hier nicht verfügbar.', en: 'The assistant is not available here.', fr: 'L’assistant n’est pas disponible ici.', sw: 'Msaidizi hapatikani hapa.' },
|
|
60
66
|
'Chat.historyTrimmed_one': { de: '{{count}} frühere Nachricht wurde ausgelassen', en: '{{count}} earlier message left out', fr: '{{count}} message précédent omis', sw: 'Ujumbe {{count}} wa awali umeachwa' },
|
|
@@ -31,8 +31,11 @@ import { useBillingUsersColumn } from '../billing/useBillingUsersColumn';
|
|
|
31
31
|
* `billingOperator({ user, account }) => boolean` (optional, UCM-BILL-10): the app's operator rule for the billing
|
|
32
32
|
* users columns built when `billingUsers` is set (status, badge and the "Ohne Abo" switch). Without it superusers are
|
|
33
33
|
* the operators. A new function on each render only recomputes the columns; it does not refetch the accounts.
|
|
34
|
+
* `groups` (optional): app-defined account navigation groups with `{ key, label, order?, tabs?, visible? }`. Labels
|
|
35
|
+
* may be strings or `(context) => string`; `tabs` assigns built-in tab values, and `visible(context)` can hide a group
|
|
36
|
+
* and its tabs. Without this prop, the default groups and placement are unchanged.
|
|
34
37
|
*/
|
|
35
|
-
export function AccountPage({ userListExtraColumns = [], userListExtraRowActions = [], userListExtraContext = null, userListRefreshTrigger = 0, userListCanEditUser = null, userListShowNewColumn = true, userListShowSuccessfulLoginColumn = true, userListShowRoleColumn = true, userListOnChangeRole = null, userListShowDeleteAction = true, userListCanDeleteUser = null, userListOnDeleteUser = null, showBulkInviteCsvTab = false, bulkInviteCsvProps = {}, extraTabs = [], showProfileStatements = true, billingUsers = false, billingOperator, }) {
|
|
38
|
+
export function AccountPage({ userListExtraColumns = [], userListExtraRowActions = [], userListExtraContext = null, userListRefreshTrigger = 0, userListCanEditUser = null, userListShowNewColumn = true, userListShowSuccessfulLoginColumn = true, userListShowRoleColumn = true, userListOnChangeRole = null, userListShowDeleteAction = true, userListCanDeleteUser = null, userListOnDeleteUser = null, showBulkInviteCsvTab = false, bulkInviteCsvProps = {}, extraTabs = [], showProfileStatements = true, billingUsers = false, billingOperator, groups: groupsProp, }) {
|
|
36
39
|
var _a;
|
|
37
40
|
const { t, i18n } = useTranslation();
|
|
38
41
|
const { user, login, loading } = useContext(AuthContext);
|
|
@@ -62,6 +65,25 @@ export function AccountPage({ userListExtraColumns = [], userListExtraRowActions
|
|
|
62
65
|
const canSendInvites = Boolean(isSuperUser || perms.can_send_invites);
|
|
63
66
|
const canManageAccessCodes = Boolean(isSuperUser || perms.can_manage_access_codes);
|
|
64
67
|
const canManageSignupQr = Boolean(isSuperUser || perms.can_manage_signup_qr);
|
|
68
|
+
const extensionContext = { user, perms, isSuperUser, t };
|
|
69
|
+
const declaredGroups = useMemo(() => {
|
|
70
|
+
if (!Array.isArray(groupsProp))
|
|
71
|
+
return null;
|
|
72
|
+
const definitions = groupsProp
|
|
73
|
+
.filter((group) => group && typeof group.key === 'string' && group.key.length > 0)
|
|
74
|
+
.map((group, index) => (Object.assign(Object.assign({}, group), { index, sortOrder: Number.isFinite(group.order) ? group.order : index, isVisible: typeof group.visible === 'function' ? Boolean(group.visible(extensionContext)) : true })))
|
|
75
|
+
.sort((left, right) => left.sortOrder - right.sortOrder || left.index - right.index);
|
|
76
|
+
const builtInAssignments = new Map();
|
|
77
|
+
definitions.forEach((group) => {
|
|
78
|
+
(Array.isArray(group.tabs) ? group.tabs : []).forEach((value) => {
|
|
79
|
+
if (['profile', 'security', 'users', 'invite', 'support'].includes(value)
|
|
80
|
+
&& !builtInAssignments.has(value)) {
|
|
81
|
+
builtInAssignments.set(value, group.key);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
return { definitions, builtInAssignments };
|
|
86
|
+
}, [groupsProp, user, perms, isSuperUser, t]);
|
|
65
87
|
const handleTabChange = (_event, newValue) => {
|
|
66
88
|
setSearchParams({ tab: newValue });
|
|
67
89
|
};
|
|
@@ -101,7 +123,6 @@ export function AccountPage({ userListExtraColumns = [], userListExtraRowActions
|
|
|
101
123
|
const tabs = useMemo(() => {
|
|
102
124
|
if (!user)
|
|
103
125
|
return [];
|
|
104
|
-
const extensionContext = { user, perms, isSuperUser, t };
|
|
105
126
|
const list = [
|
|
106
127
|
{ value: 'profile', label: t('Account.TAB_PROFILE', 'Profile') },
|
|
107
128
|
{ value: 'security', label: t('Account.TAB_SECURITY', 'Security') },
|
|
@@ -116,19 +137,65 @@ export function AccountPage({ userListExtraColumns = [], userListExtraRowActions
|
|
|
116
137
|
if (isSuperUser || perms.can_view_support) {
|
|
117
138
|
list.push({ value: 'support', label: t('Account.TAB_SUPPORT', 'Support') });
|
|
118
139
|
}
|
|
140
|
+
if (declaredGroups) {
|
|
141
|
+
for (let index = list.length - 1; index >= 0; index -= 1) {
|
|
142
|
+
const assignedGroupKey = declaredGroups.builtInAssignments.get(list[index].value);
|
|
143
|
+
const assignedGroup = declaredGroups.definitions.find((group) => group.key === assignedGroupKey);
|
|
144
|
+
if (assignedGroup && !assignedGroup.isVisible)
|
|
145
|
+
list.splice(index, 1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
119
148
|
extraTabs.forEach((tab) => {
|
|
120
149
|
if (!(tab === null || tab === void 0 ? void 0 : tab.value) || !(tab === null || tab === void 0 ? void 0 : tab.label))
|
|
121
150
|
return;
|
|
122
151
|
const isVisible = typeof tab.visible === 'function' ? tab.visible(extensionContext) : true;
|
|
152
|
+
const declaredGroup = declaredGroups === null || declaredGroups === void 0 ? void 0 : declaredGroups.definitions.find((group) => group.key === tab.group);
|
|
153
|
+
const collidesWithBuiltIn = declaredGroups
|
|
154
|
+
&& ['profile', 'security', 'users', 'invite', 'support'].includes(tab.value);
|
|
155
|
+
if (declaredGroups && (collidesWithBuiltIn || (declaredGroup && !declaredGroup.isVisible)))
|
|
156
|
+
return;
|
|
123
157
|
if (isVisible && !list.some((entry) => entry.value === tab.value)) {
|
|
124
|
-
//
|
|
125
|
-
const group =
|
|
158
|
+
// Legacy apps may join the three built-in groups; declared apps may use any declared group key.
|
|
159
|
+
const group = declaredGroups
|
|
160
|
+
? (declaredGroup ? tab.group : undefined)
|
|
161
|
+
: (['my-account', 'management', 'help'].includes(tab.group) ? tab.group : undefined);
|
|
126
162
|
list.push(Object.assign({ value: tab.value, label: typeof tab.label === 'function' ? tab.label(extensionContext) : tab.label }, (group ? { group } : {})));
|
|
127
163
|
}
|
|
128
164
|
});
|
|
129
165
|
return list;
|
|
130
|
-
}, [user, perms, t, isSuperUser, extraTabs, canViewUsers, canViewInvite]);
|
|
166
|
+
}, [user, perms, t, isSuperUser, extraTabs, canViewUsers, canViewInvite, declaredGroups]);
|
|
131
167
|
const groups = useMemo(() => {
|
|
168
|
+
if (declaredGroups) {
|
|
169
|
+
const placedValues = new Set();
|
|
170
|
+
const mappedGroups = declaredGroups.definitions
|
|
171
|
+
.filter((group) => group.isVisible)
|
|
172
|
+
.map((group) => {
|
|
173
|
+
const builtInValues = (Array.isArray(group.tabs) ? group.tabs : [])
|
|
174
|
+
.filter((value) => declaredGroups.builtInAssignments.get(value) === group.key);
|
|
175
|
+
const items = [
|
|
176
|
+
...builtInValues.map((value) => tabs.find((tab) => tab.value === value)).filter(Boolean),
|
|
177
|
+
...tabs.filter((tab) => tab.group === group.key),
|
|
178
|
+
].map((tab) => ({ key: tab.value, label: tab.label }));
|
|
179
|
+
items.forEach((item) => placedValues.add(item.key));
|
|
180
|
+
return {
|
|
181
|
+
key: group.key,
|
|
182
|
+
label: typeof group.label === 'function' ? group.label(extensionContext) : group.label,
|
|
183
|
+
items,
|
|
184
|
+
};
|
|
185
|
+
})
|
|
186
|
+
.filter((group) => group.items.length > 0);
|
|
187
|
+
const extraItems = tabs
|
|
188
|
+
.filter((tab) => !placedValues.has(tab.value))
|
|
189
|
+
.map((tab) => ({ key: tab.value, label: tab.label }));
|
|
190
|
+
if (extraItems.length > 0) {
|
|
191
|
+
mappedGroups.push({
|
|
192
|
+
key: 'more',
|
|
193
|
+
label: t('Account.GROUP_MORE', 'More'),
|
|
194
|
+
items: extraItems,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return mappedGroups;
|
|
198
|
+
}
|
|
132
199
|
const groupDefinitions = [
|
|
133
200
|
{
|
|
134
201
|
key: 'my-account',
|
|
@@ -168,7 +235,7 @@ export function AccountPage({ userListExtraColumns = [], userListExtraRowActions
|
|
|
168
235
|
});
|
|
169
236
|
}
|
|
170
237
|
return mappedGroups.filter((group) => group.items.length > 0);
|
|
171
|
-
}, [tabs, t]);
|
|
238
|
+
}, [tabs, t, declaredGroups, user, perms, isSuperUser]);
|
|
172
239
|
// 4. Loading & Auth Checks
|
|
173
240
|
if (loading) {
|
|
174
241
|
return (_jsx(Box, { sx: { display: 'flex', justifyContent: 'center', mt: 10 }, children: _jsx(CircularProgress, {}) }));
|