@micha.bigler/ui-core-micha 4.40.2 → 4.41.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 +11 -0
- package/dist/chat/ChatGroupGrants.js +127 -0
- package/dist/chat/ChatWorkspace.js +2 -1
- package/dist/chat/api.js +2 -0
- package/dist/chat/wire.js +1 -1
- package/dist/i18n/chatTranslations.js +18 -0
- package/dist/notifications/NotificationsProvider.js +37 -12
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.41.0 - UCM-CHAT-22
|
|
4
|
+
|
|
5
|
+
Chat workspaces support per-chat permission groups, including explicit
|
|
6
|
+
reauthorization when access has been withdrawn and restored.
|
|
7
|
+
|
|
8
|
+
## 4.40.3 - UCM-NOTIF-17
|
|
9
|
+
|
|
10
|
+
Notification feed, unread count and pagination state are cleared before the
|
|
11
|
+
first committed render for a different account. Delayed operations from the
|
|
12
|
+
previous account cannot restore its state or request further feed pages.
|
|
13
|
+
|
|
3
14
|
## 4.40.2 - UCM-SHELL-10
|
|
4
15
|
|
|
5
16
|
Notification and account menu buttons include their visible unread count or
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Alert, Box, Button, CircularProgress, Collapse, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, Stack, Switch, Tooltip, Typography } from '@mui/material';
|
|
4
|
+
import SettingsOutlinedIcon from '@mui/icons-material/SettingsOutlined';
|
|
5
|
+
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
6
|
+
import CloseIcon from '@mui/icons-material/Close';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
const policyKey = (members) => {
|
|
9
|
+
const policies = new Set(members.map((member) => member.confirmation).filter(Boolean));
|
|
10
|
+
return policies.size > 1 ? 'Chat.grantsMixed' : policies.has('confirmation_required') ? 'Chat.grantsConfirm' : policies.has('direct') ? 'Chat.grantsDirect' : null;
|
|
11
|
+
};
|
|
12
|
+
export default function ChatGroupGrants({ chatId, api }) {
|
|
13
|
+
const { t, i18n } = useTranslation();
|
|
14
|
+
const language = i18n === null || i18n === void 0 ? void 0 : i18n.language;
|
|
15
|
+
const [support, setSupport] = useState('loading');
|
|
16
|
+
const [open, setOpen] = useState(false);
|
|
17
|
+
const [projection, setProjection] = useState(null);
|
|
18
|
+
const [draft, setDraft] = useState([]);
|
|
19
|
+
const [disabledInitiallyEnabled, setDisabledInitiallyEnabled] = useState([]);
|
|
20
|
+
const [expanded, setExpanded] = useState([]);
|
|
21
|
+
const [state, setState] = useState('idle');
|
|
22
|
+
const generation = useRef(0);
|
|
23
|
+
const pendingSave = useRef(null);
|
|
24
|
+
const lastContext = useRef({ chatId, language });
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const previous = lastContext.current;
|
|
27
|
+
lastContext.current = { chatId, language };
|
|
28
|
+
const chatChanged = previous.chatId !== chatId;
|
|
29
|
+
let active = true;
|
|
30
|
+
generation.current += 1;
|
|
31
|
+
if (chatChanged) {
|
|
32
|
+
setOpen(false);
|
|
33
|
+
setProjection(null);
|
|
34
|
+
setDisabledInitiallyEnabled([]);
|
|
35
|
+
setSupport('loading');
|
|
36
|
+
}
|
|
37
|
+
if (open && !chatChanged) {
|
|
38
|
+
load(true);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
api.getGroupGrants(chatId, ...(language ? [{ language }] : [])).then((result) => {
|
|
42
|
+
if (active)
|
|
43
|
+
setSupport((result === null || result === void 0 ? void 0 : result.supported) ? 'supported' : 'unsupported');
|
|
44
|
+
}).catch((error) => {
|
|
45
|
+
var _a;
|
|
46
|
+
if (active)
|
|
47
|
+
setSupport(((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) === 404 ? 'unsupported' : 'error');
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return () => { active = false; generation.current += 1; };
|
|
51
|
+
}, [api, chatId, language]);
|
|
52
|
+
const load = async (preserveDraft = false) => {
|
|
53
|
+
const current = ++generation.current;
|
|
54
|
+
const saving = pendingSave.current;
|
|
55
|
+
setState('loading');
|
|
56
|
+
try {
|
|
57
|
+
let saveSucceeded = false;
|
|
58
|
+
if (saving) {
|
|
59
|
+
try {
|
|
60
|
+
await saving;
|
|
61
|
+
saveSucceeded = true;
|
|
62
|
+
}
|
|
63
|
+
catch (_a) { /* Keep the draft for retry. */ }
|
|
64
|
+
}
|
|
65
|
+
if (current !== generation.current)
|
|
66
|
+
return;
|
|
67
|
+
const result = await api.getGroupGrants(chatId, ...(language ? [{ language }] : []));
|
|
68
|
+
if (current !== generation.current)
|
|
69
|
+
return;
|
|
70
|
+
if (!(result === null || result === void 0 ? void 0 : result.supported)) {
|
|
71
|
+
setSupport('unsupported');
|
|
72
|
+
setOpen(false);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
setSupport('supported');
|
|
76
|
+
const sameRevision = projection && projection.grant_revision === result.grant_revision && projection.catalogue_revision === result.catalogue_revision;
|
|
77
|
+
setProjection(result);
|
|
78
|
+
if (!preserveDraft || saveSucceeded || !projection) {
|
|
79
|
+
setDraft(result.groups.filter((group) => group.enabled).map((group) => group.id));
|
|
80
|
+
setDisabledInitiallyEnabled([]);
|
|
81
|
+
}
|
|
82
|
+
if (!preserveDraft)
|
|
83
|
+
setExpanded([]);
|
|
84
|
+
setState(preserveDraft && !saveSucceeded && projection && !sameRevision ? 'stale' : 'idle');
|
|
85
|
+
}
|
|
86
|
+
catch (_b) {
|
|
87
|
+
if (current === generation.current)
|
|
88
|
+
setState('loadError');
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const close = () => { generation.current += 1; setOpen(false); setDisabledInitiallyEnabled([]); setState('idle'); };
|
|
92
|
+
const save = async () => {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const current = ++generation.current;
|
|
95
|
+
setState('saving');
|
|
96
|
+
try {
|
|
97
|
+
const reauthorizeGroupIds = disabledInitiallyEnabled.filter((id) => draft.includes(id));
|
|
98
|
+
const request = api.saveGroupGrants(chatId, Object.assign({ group_ids: draft, grant_revision: projection.grant_revision, catalogue_revision: projection.catalogue_revision }, (reauthorizeGroupIds.length ? { reauthorize_group_ids: reauthorizeGroupIds } : {})), ...(language ? [{ language }] : []));
|
|
99
|
+
pendingSave.current = request;
|
|
100
|
+
const result = await request;
|
|
101
|
+
if (current !== generation.current)
|
|
102
|
+
return;
|
|
103
|
+
setProjection(result);
|
|
104
|
+
setDraft(result.groups.filter((group) => group.enabled).map((group) => group.id));
|
|
105
|
+
setDisabledInitiallyEnabled([]);
|
|
106
|
+
setState('saved');
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
if (current === generation.current)
|
|
110
|
+
setState(((_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.code) === 'stale_grants' ? 'stale' : 'saveError');
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
pendingSave.current = null;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
if (support === 'loading' || support === 'unsupported')
|
|
117
|
+
return null;
|
|
118
|
+
return _jsxs(_Fragment, { children: [_jsx(Tooltip, { title: t('Chat.grants'), children: _jsx(IconButton, { "aria-label": t('Chat.grants'), onClick: () => { setOpen(true); load(); }, children: _jsx(SettingsOutlinedIcon, {}) }) }), _jsxs(Dialog, { open: open, onClose: close, "aria-labelledby": "chat-grants-title", fullWidth: true, maxWidth: "xs", children: [_jsxs(DialogTitle, { id: "chat-grants-title", sx: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 1 }, children: [t('Chat.grants'), _jsx(IconButton, { "aria-label": t('Chat.close'), onClick: close, children: _jsx(CloseIcon, {}) })] }), _jsxs(DialogContent, { dividers: true, children: [_jsx(Typography, { variant: "body2", color: "text.secondary", sx: { mb: 2 }, children: t('Chat.grantsScope') }), state === 'loading' ? _jsx(CircularProgress, { size: 24 }) : null, state === 'loadError' ? _jsx(Alert, { severity: "error", action: _jsx(Button, { onClick: () => load(), children: t('Chat.retry') }), children: t('Chat.grantsLoadError') }) : null, state === 'saveError' ? _jsx(Alert, { severity: "error", children: t('Chat.grantsSaveError') }) : null, state === 'stale' ? _jsx(Alert, { severity: "warning", action: _jsx(Button, { onClick: () => load(), children: t('Chat.grantsReload') }), children: t('Chat.grantsStale') }) : null, state === 'saved' ? _jsx(Alert, { severity: "success", children: t('Chat.grantsSaved') }) : null, projection && state !== 'loading' && state !== 'loadError' ? ['read', 'write'].map((kind) => {
|
|
119
|
+
const groups = projection.groups.filter((group) => group.kind === kind);
|
|
120
|
+
return _jsxs(Box, { sx: { mb: 2 }, children: [_jsx(Typography, { variant: "subtitle2", sx: { mb: 1 }, children: t(kind === 'read' ? 'Chat.grantsRead' : 'Chat.grantsWrite') }), !groups.length ? _jsx(Typography, { variant: "body2", color: "text.secondary", children: t(kind === 'read' ? 'Chat.grantsNoRead' : 'Chat.grantsNoWrite') }) : groups.map((group) => {
|
|
121
|
+
const isExpanded = expanded.includes(group.id);
|
|
122
|
+
const policy = kind === 'write' ? policyKey(group.members) : null;
|
|
123
|
+
return _jsxs(Box, { sx: { border: 1, borderColor: 'divider', borderRadius: 1, mb: 1, minWidth: 0 }, children: [_jsxs(Stack, { direction: "row", alignItems: "center", sx: { px: 1, py: 0.5 }, children: [_jsx(IconButton, { "aria-label": group.label, "aria-expanded": isExpanded, onClick: () => setExpanded((items) => isExpanded ? items.filter((id) => id !== group.id) : [...items, group.id]), children: _jsx(ExpandMoreIcon, { sx: { transform: isExpanded ? 'rotate(180deg)' : undefined } }) }), _jsxs(Box, { sx: { flex: 1, minWidth: 0, overflowWrap: 'anywhere' }, children: [_jsx(Typography, { variant: "body2", children: group.label }), _jsxs(Typography, { variant: "caption", color: "text.secondary", children: [t('Chat.grantsCount', { available: group.members.filter((member) => member.available).length, total: group.members.length }), policy ? ` · ${t(policy)}` : ''] })] }), _jsx(Switch, { checked: draft.includes(group.id), disabled: !group.editable || state === 'saving' || state === 'stale', onChange: (event) => { if (!event.target.checked && group.enabled)
|
|
124
|
+
setDisabledInitiallyEnabled((items) => items.includes(group.id) ? items : [...items, group.id]); setDraft((items) => event.target.checked ? [...items, group.id] : items.filter((id) => id !== group.id)); setState('idle'); }, slotProps: { input: { 'aria-label': group.label } } })] }), group.enabled && group.members.some((member) => member.available && !member.effective) ? _jsx(Typography, { variant: "caption", color: "text.secondary", sx: { display: 'block', px: 2, pb: 1 }, children: t('Chat.grantsReauthorizeHint') }) : null, _jsx(Collapse, { in: isExpanded, children: _jsx(Stack, { spacing: 0.5, sx: { px: 2, pb: 1 }, children: group.members.map((member) => _jsxs(Box, { sx: { overflowWrap: 'anywhere' }, children: [_jsx(Typography, { variant: "body2", children: member.label }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: [!member.available ? (member.unavailable_reason || t('Chat.grantsUnavailable')) : group.enabled && !member.effective ? t('Chat.grantsNotGranted') : null, member.confirmation ? t(member.confirmation === 'direct' ? 'Chat.grantsDirect' : 'Chat.grantsConfirm') : null].filter(Boolean).join(' · ') })] }, member.id)) }) })] }, group.id);
|
|
125
|
+
})] }, kind);
|
|
126
|
+
}) : null] }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: close, children: t('Chat.cancel') }), _jsx(Button, { variant: "contained", onClick: save, disabled: !projection || ['loading', 'loadError', 'saving', 'stale'].includes(state), children: t('Chat.save') })] })] })] });
|
|
127
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import ChatGroupGrants from './ChatGroupGrants';
|
|
2
3
|
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
3
4
|
import { Alert, Box, Button, Chip, Drawer, Stack, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
4
5
|
import { useTranslation } from 'react-i18next';
|
|
@@ -708,7 +709,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
708
709
|
if (unavailable) {
|
|
709
710
|
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') }) }));
|
|
710
711
|
}
|
|
711
|
-
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: narrow ? 44 : 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, renderTurnError: renderTurnError, tool: tool, notice: noticeFor(), hasOlder: Boolean(olderCursor), olderBusy: olderBusy, onLoadOlder: loadOlder, onRetry: retry, readOnly: isArchived, summary: summary, usageToTokens: usageToTokens, onNavigate: onNavigate, showReplyCaption: showReplyCaption }), 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, onComposeStart: composeStart, context: composerLayout === 'compact' ? renderComposerContext === null || renderComposerContext === void 0 ? void 0 : renderComposerContext({ chat }) : undefined, notice: composerLayout === 'compact' && longChat && !dismissedComposerNotices.has(`${chat.id}:long-chat`) ? {
|
|
712
|
+
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: narrow ? 44 : 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 && !isArchived && chat.id !== PENDING_ID ? _jsx(ChatGroupGrants, { chatId: chat.id, api: api }, String(chat.id)) : 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, renderTurnError: renderTurnError, tool: tool, notice: noticeFor(), hasOlder: Boolean(olderCursor), olderBusy: olderBusy, onLoadOlder: loadOlder, onRetry: retry, readOnly: isArchived, summary: summary, usageToTokens: usageToTokens, onNavigate: onNavigate, showReplyCaption: showReplyCaption }), 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, onComposeStart: composeStart, context: composerLayout === 'compact' ? renderComposerContext === null || renderComposerContext === void 0 ? void 0 : renderComposerContext({ chat }) : undefined, notice: composerLayout === 'compact' && longChat && !dismissedComposerNotices.has(`${chat.id}:long-chat`) ? {
|
|
712
713
|
id: 'long-chat', text: t('Chat.longChatShort'), action: t('Chat.newChat'), onAction: createChat,
|
|
713
714
|
onDismiss: () => setDismissedComposerNotices((current) => new Set(current).add(`${chat.id}:long-chat`)),
|
|
714
715
|
} : null, draftRequest: (draftRequest === null || draftRequest === void 0 ? void 0 : draftRequest.chatId) === chat.id ? draftRequest : null, onDraftRequestApplied: onDraftRequestApplied, onSend: (text) => startTurn(text), onStop: () => socket.send({ type: 'stop' }), running: running, archived: isArchived, connected: socket.connected, inputRef: composerInputRef, usageLimit: usageLimit, actions: _jsx(ModelPicker, { entries: catalogue.entries, selection: selection, managed: Object.prototype.hasOwnProperty.call(catalogue, 'policy'), disabled: isArchived || running || (catalogueLoading && catalogueChatId !== chat.id), open: pickerOpen, onOpenChange: setPickerOpen, onChange: (next) => updateChat(chat, { selection: next }), balance: tokenBalance, shortLabel: composerLayout === 'compact' }) }, `composer-${chat.id}`)] })) : (_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: CHAT_WORKSPACE_SIDE_PANEL_SX, 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] }));
|
package/dist/chat/api.js
CHANGED
|
@@ -9,6 +9,8 @@ export function createChatApi(overrides = {}, { apiBase = '/api/assistant/' } =
|
|
|
9
9
|
createChat: (payload = {}) => data(apiClient.post(urls.chats, payload)),
|
|
10
10
|
updateChat: (id, patch) => data(apiClient.patch(urls.chat(id), patch)),
|
|
11
11
|
deleteChat: (id) => data(apiClient.delete(urls.chat(id))),
|
|
12
|
+
getGroupGrants: (id, { language } = {}) => data(language ? apiClient.get(urls.groupGrants(id), { headers: { 'Accept-Language': language } }) : apiClient.get(urls.groupGrants(id))),
|
|
13
|
+
saveGroupGrants: (id, payload, { language } = {}) => data(language ? apiClient.put(urls.groupGrants(id), payload, { headers: { 'Accept-Language': language } }) : apiClient.put(urls.groupGrants(id), payload)),
|
|
12
14
|
listTurns: (id, { cursor } = {}) => data(apiClient.get(urls.turns(id), { params: cursor ? { cursor } : {} })),
|
|
13
15
|
getStatus: ({ scope } = {}) => data(scope !== undefined ? apiClient.get(urls.status, { params: { scope } }) : apiClient.get(urls.status)),
|
|
14
16
|
getLimit: () => data(apiClient.get(urls.limit)),
|
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/', limit: root + 'limit/' };
|
|
5
|
+
return { catalogue: root + 'catalogue/', chats: root + 'chats/', chat: (id) => root + 'chats/' + encodeURIComponent(id) + '/', groupGrants: (id) => root + 'chats/' + encodeURIComponent(id) + '/group-grants/', 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' };
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
export const chatTranslations = {
|
|
2
|
+
'Chat.grants': { de: 'Chat-Freigaben', en: 'Chat permissions', fr: 'Autorisations du chat', sw: 'Ruhusa za mazungumzo' },
|
|
3
|
+
'Chat.grantsScope': { de: 'Gilt für diesen Chat', en: 'Applies to this chat', fr: 'Pour cette discussion', sw: 'Inatumika kwa mazungumzo haya' },
|
|
4
|
+
'Chat.grantsRead': { de: 'Lesen', en: 'Read', fr: 'Lecture', sw: 'Kusoma' },
|
|
5
|
+
'Chat.grantsWrite': { de: 'Schreiben', en: 'Write', fr: 'Écriture', sw: 'Kuandika' },
|
|
6
|
+
'Chat.grantsNoRead': { de: 'Keine Leseaktionen im Chat', en: 'No read actions in this chat', fr: 'Aucune action de lecture dans cette discussion', sw: 'Hakuna vitendo vya kusoma katika mazungumzo haya' },
|
|
7
|
+
'Chat.grantsNoWrite': { de: 'Keine Schreibaktionen im Chat', en: 'No write actions in this chat', fr: 'Aucune action d’écriture dans cette discussion', sw: 'Hakuna vitendo vya kuandika katika mazungumzo haya' },
|
|
8
|
+
'Chat.grantsUnavailable': { de: 'App-Recht fehlt', en: 'App permission missing', fr: 'Autorisation de l’application manquante', sw: 'Ruhusa ya programu haipo' },
|
|
9
|
+
'Chat.grantsNotGranted': { de: 'Nicht freigegeben', en: 'Not granted', fr: 'Non autorisé', sw: 'Haijaruhusiwa' },
|
|
10
|
+
'Chat.grantsReauthorizeHint': { de: 'Zum erneuten Freigeben die Gruppe aus- und wieder einschalten und speichern.', en: 'To reauthorize, switch the group off and on, then save.', fr: 'Pour réautoriser, désactivez puis réactivez le groupe et enregistrez.', sw: 'Ili kuruhusu tena, zima na uwashe kikundi, kisha hifadhi.' },
|
|
11
|
+
'Chat.grantsDirect': { de: 'Direkt bei ausdrücklichem Auftrag', en: 'Directly on explicit request', fr: 'Directement sur demande explicite', sw: 'Moja kwa moja kwa ombi la wazi' },
|
|
12
|
+
'Chat.grantsConfirm': { de: 'Mit Bestätigung', en: 'With confirmation', fr: 'Avec confirmation', sw: 'Kwa uthibitisho' },
|
|
13
|
+
'Chat.grantsMixed': { de: 'Bestätigung je nach Aktion', en: 'Confirmation depends on the action', fr: 'Confirmation selon l’action', sw: 'Uthibitisho hutegemea kitendo' },
|
|
14
|
+
'Chat.grantsCount': { de: '{{available}} von {{total}} verfügbar', en: '{{available}} of {{total}} available', fr: '{{available}} sur {{total}} disponibles', sw: '{{available}} kati ya {{total}} zinapatikana' },
|
|
15
|
+
'Chat.grantsSaved': { de: 'Chat-Freigaben gespeichert.', en: 'Chat permissions saved.', fr: 'Autorisations enregistrées.', sw: 'Ruhusa za mazungumzo zimehifadhiwa.' },
|
|
16
|
+
'Chat.grantsLoadError': { de: 'Chat-Freigaben konnten nicht geladen werden.', en: 'Chat permissions could not be loaded.', fr: 'Impossible de charger les autorisations.', sw: 'Ruhusa za mazungumzo hazikuweza kupakiwa.' },
|
|
17
|
+
'Chat.grantsSaveError': { de: 'Chat-Freigaben konnten nicht gespeichert werden.', en: 'Chat permissions could not be saved.', fr: 'Impossible d’enregistrer les autorisations.', sw: 'Ruhusa za mazungumzo hazikuweza kuhifadhiwa.' },
|
|
18
|
+
'Chat.grantsStale': { de: 'Die Freigaben wurden geändert. Neu laden.', en: 'Permissions changed. Reload.', fr: 'Les autorisations ont changé. Rechargez.', sw: 'Ruhusa zimebadilika. Pakia upya.' },
|
|
19
|
+
'Chat.grantsReload': { de: 'Neu laden', en: 'Reload', fr: 'Recharger', sw: 'Pakia upya' },
|
|
2
20
|
'Chat.newChat': { de: 'Neuer Chat', en: 'New chat', fr: 'Nouveau chat', sw: 'Mazungumzo mapya' },
|
|
3
21
|
'Chat.chats': { de: 'Chats', en: 'Chats', fr: 'Discussions', sw: 'Mazungumzo' },
|
|
4
22
|
'Chat.archived': { de: 'Archiviert', en: 'Archived', fr: 'Archivé', sw: 'Imewekwa kwenye kumbukumbu' },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useInsertionEffect, useRef, useState } from 'react';
|
|
3
3
|
import { AuthContext } from '../auth/AuthContext';
|
|
4
4
|
import { getNotificationFeed, getUnreadCount, markNotifications, markAllNotificationsSeen } from './feedApi';
|
|
5
5
|
import { DEFAULT_ENVELOPE, RealtimeContext, useRealtimeCore } from './realtime';
|
|
@@ -43,14 +43,9 @@ function NotificationsScope({ children, wsUrlBase }) {
|
|
|
43
43
|
const auth = useContext(AuthContext);
|
|
44
44
|
const authenticated = Boolean(auth === null || auth === void 0 ? void 0 : auth.user);
|
|
45
45
|
const accountKey = (auth === null || auth === void 0 ? void 0 : auth.user) ? `user:${auth.user.id}` : 'logged-out';
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
accountRef.current = accountKey;
|
|
50
|
-
generation.current += 1;
|
|
51
|
-
}
|
|
52
|
-
const accountGeneration = generation.current;
|
|
53
|
-
const isCurrent = () => alive.current && generation.current === accountGeneration;
|
|
46
|
+
const [account, setAccount] = useState(() => ({ key: accountKey }));
|
|
47
|
+
const accountRef = useRef(account);
|
|
48
|
+
const isCurrent = () => alive.current && accountRef.current === account;
|
|
54
49
|
const bootstrapSeed = auth === null || auth === void 0 ? void 0 : auth.bootstrapNotificationSeed;
|
|
55
50
|
const consumeBootstrapSeed = auth === null || auth === void 0 ? void 0 : auth.consumeBootstrapNotificationSeed;
|
|
56
51
|
const [notifications, setNotifications] = useState([]);
|
|
@@ -69,6 +64,31 @@ function NotificationsScope({ children, wsUrlBase }) {
|
|
|
69
64
|
const [feedError, setFeedError] = useState(false);
|
|
70
65
|
const [markError, setMarkError] = useState(false);
|
|
71
66
|
const [marking, setMarking] = useState(false);
|
|
67
|
+
const [seeded, setSeeded] = useState(false);
|
|
68
|
+
if (account.key !== accountKey) {
|
|
69
|
+
setAccount({ key: accountKey });
|
|
70
|
+
setNotifications([]);
|
|
71
|
+
setUnreadCount(0);
|
|
72
|
+
setNext(null);
|
|
73
|
+
setCapable(false);
|
|
74
|
+
setLoadingMore(false);
|
|
75
|
+
setFeedError(false);
|
|
76
|
+
setMarkError(false);
|
|
77
|
+
setMarking(false);
|
|
78
|
+
setSeeded(false);
|
|
79
|
+
}
|
|
80
|
+
const accountGeneration = account;
|
|
81
|
+
useInsertionEffect(() => {
|
|
82
|
+
if (accountRef.current === account)
|
|
83
|
+
return;
|
|
84
|
+
accountRef.current = account;
|
|
85
|
+
notificationsRef.current = [];
|
|
86
|
+
nextRef.current = null;
|
|
87
|
+
loadingRef.current = false;
|
|
88
|
+
pageCount.current = 1;
|
|
89
|
+
pageVersion.current += 1;
|
|
90
|
+
pageEpoch.current += 1;
|
|
91
|
+
}, [account]);
|
|
72
92
|
useEffect(() => { alive.current = true; return () => { alive.current = false; }; }, []);
|
|
73
93
|
const setContinuation = (value) => { nextRef.current = value || null; setNext(value || null); };
|
|
74
94
|
const replaceNotifications = useCallback((nextNotifications) => {
|
|
@@ -77,6 +97,8 @@ function NotificationsScope({ children, wsUrlBase }) {
|
|
|
77
97
|
}, []);
|
|
78
98
|
const refresh = useCallback(async () => {
|
|
79
99
|
var _a;
|
|
100
|
+
if (!isCurrent())
|
|
101
|
+
return;
|
|
80
102
|
if (!authenticated) {
|
|
81
103
|
replaceNotifications([]);
|
|
82
104
|
setUnreadCount(0);
|
|
@@ -89,6 +111,8 @@ function NotificationsScope({ children, wsUrlBase }) {
|
|
|
89
111
|
let continuation = feed.next;
|
|
90
112
|
const rows = [...(feed.results || [])];
|
|
91
113
|
for (let page = 1; page < targetPages && continuation; page += 1) {
|
|
114
|
+
if (!isCurrent())
|
|
115
|
+
return;
|
|
92
116
|
const result = await getNotificationFeed({ next: continuation });
|
|
93
117
|
rows.push(...(result.results || []));
|
|
94
118
|
continuation = result.next;
|
|
@@ -117,7 +141,6 @@ function NotificationsScope({ children, wsUrlBase }) {
|
|
|
117
141
|
// Preserved here rather than connecting immediately, since `refresh()`'s
|
|
118
142
|
// `replaceNotifications(...)` is unconditional and would silently drop a message that
|
|
119
143
|
// arrived and patched state before the initial REST response landed.
|
|
120
|
-
const [seeded, setSeeded] = useState(false);
|
|
121
144
|
const { subscribe, onReconnect } = useRealtimeCore({
|
|
122
145
|
active: authenticated && seeded,
|
|
123
146
|
wsUrl: getWebSocketUrl(wsUrlBase),
|
|
@@ -221,6 +244,8 @@ function NotificationsScope({ children, wsUrlBase }) {
|
|
|
221
244
|
};
|
|
222
245
|
}, [authenticated, accountGeneration, refresh, replaceNotifications, consumeBootstrapSeed]);
|
|
223
246
|
const mark = useCallback((action, ids) => {
|
|
247
|
+
if (!isCurrent())
|
|
248
|
+
return Promise.resolve();
|
|
224
249
|
const selectedIds = Array.isArray(ids) ? ids : [];
|
|
225
250
|
const selected = new Set(selectedIds);
|
|
226
251
|
const current = notificationsRef.current;
|
|
@@ -273,7 +298,7 @@ function NotificationsScope({ children, wsUrlBase }) {
|
|
|
273
298
|
const markDismissed = useCallback((ids) => mark('dismissed', ids), [mark]);
|
|
274
299
|
const markDone = useCallback((ids) => mark('done', ids), [mark]);
|
|
275
300
|
const loadMore = useCallback(async () => {
|
|
276
|
-
if (!nextRef.current || loadingRef.current)
|
|
301
|
+
if (!isCurrent() || !nextRef.current || loadingRef.current)
|
|
277
302
|
return;
|
|
278
303
|
loadingRef.current = true;
|
|
279
304
|
setLoadingMore(true);
|
|
@@ -308,7 +333,7 @@ function NotificationsScope({ children, wsUrlBase }) {
|
|
|
308
333
|
}
|
|
309
334
|
}, [replaceNotifications, accountGeneration]);
|
|
310
335
|
const markAllSeen = useCallback(async () => {
|
|
311
|
-
if (!capable || marking)
|
|
336
|
+
if (!isCurrent() || !capable || marking)
|
|
312
337
|
return;
|
|
313
338
|
setMarking(true);
|
|
314
339
|
setMarkError(false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micha.bigler/ui-core-micha",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.41.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@mui/icons-material": "^7.3.11",
|
|
71
71
|
"@mui/x-charts": "^8.29.3",
|
|
72
72
|
"@testing-library/react": "^16.3.3",
|
|
73
|
-
"@testing-library/user-event": "14.6.
|
|
73
|
+
"@testing-library/user-event": "14.6.12",
|
|
74
74
|
"@vitejs/plugin-react": "^6.3.0",
|
|
75
75
|
"axe-core": "4.14.1",
|
|
76
76
|
"i18next": "^26.7.2",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"react-markdown": "^10.1.0",
|
|
80
80
|
"remark-gfm": "^4.0.1",
|
|
81
81
|
"typescript": "^7.0.2",
|
|
82
|
-
"vite": "^8.3.
|
|
82
|
+
"vite": "^8.3.8",
|
|
83
83
|
"vitest": "^5.1.0"
|
|
84
84
|
}
|
|
85
85
|
}
|