@micha.bigler/ui-core-micha 4.40.3 → 4.42.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.42.0 - UCM-CHAT-21
4
+
5
+ In managed mode the chat model picker lists the offered families grouped by
6
+ provider (OpenAI: Astra, Sol, Terra, Luna; Claude: Fable, Opus, Sonnet,
7
+ Haiku), one row per provider/family, and sends the stable public ID
8
+ `provider:family` with the effort. Route, account, billing and model-version
9
+ fields of the catalogue are neither rendered nor kept, so a route-only change
10
+ keeps the explicit selection. Requires the managed public catalogue of
11
+ django-core-micha 3.32.0 (`entries[].{id, provider, family, efforts}`); the
12
+ unmanaged picker is unchanged.
13
+
14
+ ## 4.41.0 - UCM-CHAT-22
15
+
16
+ Chat workspaces support per-chat permission groups, including explicit
17
+ reauthorization when access has been withdrawn and restored.
18
+
3
19
  ## 4.40.3 - UCM-NOTIF-17
4
20
 
5
21
  Notification feed, unread count and pagination state are cleared before the
@@ -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';
@@ -7,7 +8,7 @@ import { useChatSocket } from './useChatSocket';
7
8
  import ChatList from './ChatList';
8
9
  import ChatThread from './ChatThread';
9
10
  import ChatComposer from './ChatComposer';
10
- import ModelPicker from './ModelPicker';
11
+ import ModelPicker, { publicFamilies } from './ModelPicker';
11
12
  const PENDING_ID = 'pending';
12
13
  const buildSendFrame = (message, getContext) => {
13
14
  if (typeof getContext !== 'function')
@@ -205,10 +206,15 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
205
206
  && sameChatId(shownChatId.current, chatId);
206
207
  if (!current || !validCatalogue(next))
207
208
  return null;
209
+ const safe = Object.prototype.hasOwnProperty.call(next, 'policy') ? {
210
+ entries: publicFamilies(next.entries),
211
+ default: next.default ? { entry: next.default.entry, effort: next.default.effort } : null,
212
+ policy: { revision: next.policy.revision },
213
+ } : next;
208
214
  catalogueFor.current = chatId !== null && chatId !== void 0 ? chatId : null;
209
- setCatalogue(next);
215
+ setCatalogue(safe);
210
216
  setCatalogueChatId(chatId !== null && chatId !== void 0 ? chatId : null);
211
- return next;
217
+ return safe;
212
218
  }
213
219
  catch (_b) {
214
220
  // A failed load for another chat must not leave the previous chat's models on offer.
@@ -708,7 +714,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
708
714
  if (unavailable) {
709
715
  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
716
  }
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`) ? {
717
+ 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
718
  id: 'long-chat', text: t('Chat.longChatShort'), action: t('Chat.newChat'), onAction: createChat,
713
719
  onDismiss: () => setDismissedComposerNotices((current) => new Set(current).add(`${chat.id}:long-chat`)),
714
720
  } : 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] }));
@@ -1,11 +1,31 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useMemo, useRef, useState } from 'react';
2
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { Box, Button, Drawer, IconButton, List, ListItemButton, Popover, Stack, ToggleButton, ToggleButtonGroup, Typography, useMediaQuery, useTheme } from '@mui/material';
4
4
  import CloseIcon from '@mui/icons-material/Close';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  const LEVELS = ['top', 'best', 'balanced', 'fast'];
7
7
  const EFFORTS = ['low', 'medium', 'high', 'max'];
8
8
  const EFFORT_LABELS = { low: 'Low', medium: 'Medium', high: 'High', max: 'Max' };
9
+ const MANAGED_FAMILIES = {
10
+ openai: { astra: 'Astra', sol: 'Sol', terra: 'Terra', luna: 'Luna' },
11
+ claude: { fable: 'Fable', opus: 'Opus', sonnet: 'Sonnet', haiku: 'Haiku' },
12
+ };
13
+ const PROVIDER_LABELS = { openai: 'OpenAI', claude: 'Claude' };
14
+ export function publicFamilies(entries) {
15
+ const seen = new Set();
16
+ return entries.flatMap((entry) => {
17
+ var _a;
18
+ const label = (_a = MANAGED_FAMILIES[entry === null || entry === void 0 ? void 0 : entry.provider]) === null || _a === void 0 ? void 0 : _a[entry === null || entry === void 0 ? void 0 : entry.family];
19
+ const id = `${entry === null || entry === void 0 ? void 0 : entry.provider}:${entry === null || entry === void 0 ? void 0 : entry.family}`;
20
+ if (!label || entry.id !== id || seen.has(id) || !Array.isArray(entry.efforts))
21
+ return [];
22
+ const efforts = EFFORTS.filter((effort) => entry.efforts.includes(effort));
23
+ if (!efforts.length)
24
+ return [];
25
+ seen.add(id);
26
+ return [{ id, provider: entry.provider, family: entry.family, label, efforts }];
27
+ });
28
+ }
9
29
  export const CHAT_MODEL_TRIGGER_SX = { minWidth: 0, px: 1.25, color: 'text.secondary', whiteSpace: 'nowrap', flexShrink: 0, maxWidth: { xs: 140, sm: 'none' } };
10
30
  // The short label sits at the end of the compact composer's context row, which clips the host content first.
11
31
  export const CHAT_MODEL_TRIGGER_SHORT_SX = Object.assign(Object.assign({}, CHAT_MODEL_TRIGGER_SX), { maxWidth: 'none' });
@@ -62,7 +82,7 @@ function estimateText(entry, effort, t, language) {
62
82
  }
63
83
  return null;
64
84
  }
65
- export function ModelPicker({ entries = [], selection, onChange, disabled = false, open, onOpenChange, balance = null, shortLabel = false, managed = false }) {
85
+ export function ModelPicker({ entries: rawEntries = [], selection, onChange, disabled = false, open, onOpenChange, balance = null, shortLabel = false, managed = false }) {
66
86
  const { t, i18n } = useTranslation();
67
87
  const language = typeof (i18n === null || i18n === void 0 ? void 0 : i18n.language) === 'string' ? i18n.language.split('_')[0] || undefined : undefined;
68
88
  const theme = useTheme();
@@ -70,24 +90,33 @@ export function ModelPicker({ entries = [], selection, onChange, disabled = fals
70
90
  // The bottom sheet only on a narrow viewport, whatever the chat container's width (UCM-CHAT-12).
71
91
  const narrow = viewportNarrow;
72
92
  const anchor = useRef(null);
93
+ const choices = useRef(null);
73
94
  const [innerOpen, setInnerOpen] = useState(false);
74
95
  const isOpen = open !== null && open !== void 0 ? open : innerOpen;
96
+ useEffect(() => {
97
+ if (!isOpen)
98
+ return undefined;
99
+ const timer = window.setTimeout(() => { var _a, _b; return (_b = (_a = choices.current) === null || _a === void 0 ? void 0 : _a.querySelector('[role="radio"][aria-checked="true"]')) === null || _b === void 0 ? void 0 : _b.focus(); }, 0);
100
+ return () => window.clearTimeout(timer);
101
+ }, [isOpen]);
75
102
  const setOpen = (value) => { setInnerOpen(value); onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(value); };
103
+ const entries = useMemo(() => managed ? publicFamilies(rawEntries) : rawEntries, [managed, rawEntries]);
76
104
  const activeSelection = useMemo(() => validSelection(entries, selection) || (!managed ? fallback(entries) : null), [entries, selection, managed]);
77
105
  const active = entries.find((entry) => entry.id === (activeSelection === null || activeSelection === void 0 ? void 0 : activeSelection.entry));
78
106
  const effort = activeSelection === null || activeSelection === void 0 ? void 0 : activeSelection.effort;
79
107
  const duplicateRows = useMemo(() => repeatedLabels(entries, originalLabel), [entries]);
80
108
  const duplicateTriggers = useMemo(() => repeatedLabels(entries, (entry) => cleanLabel(entry, shortLabel)), [entries, shortLabel]);
81
- const grouped = LEVELS.map((level) => [level, entries.filter((entry) => entry.level === level)]).filter(([, items]) => items.length);
82
- const unknown = entries.filter((entry) => !LEVELS.includes(entry.level));
109
+ const grouped = (managed ? Object.keys(PROVIDER_LABELS).map((provider) => [provider, entries.filter((entry) => entry.provider === provider)])
110
+ : LEVELS.map((level) => [level, entries.filter((entry) => entry.level === level)])).filter(([, items]) => items.length);
111
+ const unknown = managed ? [] : entries.filter((entry) => !LEVELS.includes(entry.level));
83
112
  const orderedEntries = [...grouped.flatMap(([, items]) => items), ...unknown];
84
113
  const selectEntry = (entry) => { var _a; return onChange === null || onChange === void 0 ? void 0 : onChange({ entry: entry.id, effort: supported(entry, effort) ? effort : (_a = entry.efforts) === null || _a === void 0 ? void 0 : _a[0] }); };
85
114
  const entryRow = (entry, index) => {
86
115
  var _a;
87
116
  const shown = supported(entry, effort) ? effort : (_a = entry.efforts) === null || _a === void 0 ? void 0 : _a[0];
88
- const estimate = estimateText(entry, shown, t, language);
117
+ const estimate = managed ? null : estimateText(entry, shown, t, language);
89
118
  const checked = entry.id === (active === null || active === void 0 ? void 0 : active.id);
90
- return _jsx(ListItemButton, { role: "radio", "aria-checked": checked, tabIndex: checked || (!active && index === 0) ? 0 : -1, "data-model-entry": entry.id, selected: checked, sx: CHAT_MODEL_ENTRY_SX, onClick: () => selectEntry(entry), children: _jsxs(Box, { sx: CHAT_MODEL_ENTRY_CONTENT_SX, children: [_jsx(Typography, { variant: "body2", fontWeight: checked ? 600 : 400, children: sourceNamedLabel(entry, originalLabel(entry), duplicateRows) }), estimate ? _jsx(Typography, { variant: "caption", color: "text.secondary", sx: CHAT_MODEL_COST_SX, children: estimate }) : null] }) }, entry.id);
119
+ return _jsx(ListItemButton, { role: "radio", "aria-label": managed ? `${PROVIDER_LABELS[entry.provider]} ${entry.label}` : undefined, "aria-checked": checked, tabIndex: checked || (!active && index === 0) ? 0 : -1, "data-model-entry": entry.id, selected: checked, sx: managed && checked ? Object.assign(Object.assign({}, CHAT_MODEL_ENTRY_SX), { position: 'relative', '&::before': { content: '""', position: 'absolute', left: 0, top: 4, bottom: 4, width: 3, bgcolor: 'primary.main' } }) : CHAT_MODEL_ENTRY_SX, onClick: () => selectEntry(entry), children: _jsxs(Box, { sx: CHAT_MODEL_ENTRY_CONTENT_SX, children: [_jsx(Typography, { variant: "body2", fontWeight: checked ? 600 : 400, children: managed ? entry.label : sourceNamedLabel(entry, originalLabel(entry), duplicateRows) }), estimate ? _jsx(Typography, { variant: "caption", color: "text.secondary", sx: CHAT_MODEL_COST_SX, children: estimate }) : null] }) }, entry.id);
91
120
  };
92
121
  // Radio-group keyboard behaviour: arrows move the focus and the choice, only the checked row is a tab stop.
93
122
  const moveSelection = (event) => {
@@ -106,9 +135,9 @@ export function ModelPicker({ entries = [], selection, onChange, disabled = fals
106
135
  selectEntry(next);
107
136
  (_a = [...event.currentTarget.querySelectorAll('[data-model-entry]')].find((node) => node.dataset.modelEntry === next.id)) === null || _a === void 0 ? void 0 : _a.focus();
108
137
  };
109
- const content = (_jsx(Box, { role: "dialog", "aria-labelledby": "chat-model-picker-title", sx: narrow ? CHAT_MODEL_PANEL_SHEET_SX : CHAT_MODEL_PANEL_SX, children: _jsxs(Stack, { spacing: 1.25, children: [_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, children: [_jsx(Typography, { id: "chat-model-picker-title", variant: "subtitle1", sx: { fontWeight: 600 }, children: t('Chat.pickerTitle') }), _jsx(IconButton, { "aria-label": t('Chat.close'), size: "small", sx: CHAT_MODEL_CLOSE_SX, onClick: () => setOpen(false), children: _jsx(CloseIcon, { fontSize: "small" }) })] }), _jsx(Box, { role: "radiogroup", "aria-labelledby": "chat-model-picker-title", onKeyDown: moveSelection, children: _jsx(List, { dense: true, disablePadding: true, children: orderedEntries.map(entryRow) }) }), active ? _jsxs(Box, { children: [_jsx(Typography, { variant: "subtitle2", sx: { mb: 0.75 }, children: t('Chat.effortLabel') }), _jsx(ToggleButtonGroup, { exclusive: true, fullWidth: true, size: "small", value: effort || null, "aria-label": t('Chat.effortLabel'), onChange: (_event, next) => { if (next)
138
+ const content = (_jsx(Box, { role: "dialog", "aria-labelledby": "chat-model-picker-title", sx: narrow ? CHAT_MODEL_PANEL_SHEET_SX : CHAT_MODEL_PANEL_SX, children: _jsxs(Stack, { spacing: 1.25, children: [_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, children: [_jsx(Typography, { id: "chat-model-picker-title", variant: "subtitle1", sx: { fontWeight: 600 }, children: t('Chat.pickerTitle') }), _jsx(IconButton, { "aria-label": t('Chat.close'), size: "small", sx: CHAT_MODEL_CLOSE_SX, onClick: () => setOpen(false), children: _jsx(CloseIcon, { fontSize: "small" }) })] }), _jsx(Box, { ref: choices, role: "radiogroup", "aria-labelledby": "chat-model-picker-title", onKeyDown: moveSelection, children: managed ? (grouped.length ? grouped.map(([provider, items]) => _jsxs(Box, { sx: { my: 1 }, children: [_jsx(Typography, { variant: "subtitle2", sx: { ml: 1, mb: 0.5, fontWeight: 600 }, children: PROVIDER_LABELS[provider] }), _jsx(List, { dense: true, disablePadding: true, children: items.map((entry) => entryRow(entry, orderedEntries.indexOf(entry))) })] }, provider)) : _jsx(Typography, { variant: "body2", color: "text.secondary", children: t('Chat.unavailable') })) : _jsx(List, { dense: true, disablePadding: true, children: orderedEntries.map(entryRow) }) }), active ? _jsxs(Box, { children: [_jsx(Typography, { variant: "subtitle2", sx: { mb: 0.75 }, children: t('Chat.effortLabel') }), _jsx(ToggleButtonGroup, { exclusive: true, fullWidth: true, size: "small", value: effort || null, "aria-label": t('Chat.effortLabel'), onChange: (_event, next) => { if (next)
110
139
  onChange === null || onChange === void 0 ? void 0 : onChange({ entry: active.id, effort: next }); }, children: EFFORTS.filter((item) => { var _a; return (_a = active.efforts) === null || _a === void 0 ? void 0 : _a.includes(item); }).map((item) => _jsx(ToggleButton, { value: item, sx: CHAT_MODEL_EFFORT_SX, children: EFFORT_LABELS[item] }, item)) })] }) : null, Number.isInteger(balance) && balance >= 0 ? _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('Chat.balanceLabel', { n: new Intl.NumberFormat(language).format(balance) }) }) : null] }) }));
111
- const trigger = _jsx(Button, { ref: anchor, size: "small", color: "inherit", sx: shortLabel ? CHAT_MODEL_TRIGGER_SHORT_SX : CHAT_MODEL_TRIGGER_SX, disabled: disabled || !entries.length, onClick: () => setOpen(true), "aria-haspopup": "dialog", children: _jsx(Box, { component: "span", sx: { overflow: 'hidden', textOverflow: 'ellipsis' }, children: active ? `${sourceNamedLabel(active, cleanLabel(active, shortLabel), duplicateTriggers)} · ${t(`Chat.effort.${effort}`)} ▾` : t('Chat.unavailable') }) });
140
+ const trigger = _jsx(Button, { ref: anchor, size: "small", color: "inherit", sx: shortLabel ? CHAT_MODEL_TRIGGER_SHORT_SX : CHAT_MODEL_TRIGGER_SX, disabled: disabled || (!managed && !entries.length), onClick: () => setOpen(true), "aria-haspopup": "dialog", children: _jsx(Box, { component: "span", sx: { overflow: 'hidden', textOverflow: 'ellipsis' }, children: active ? `${managed ? `${PROVIDER_LABELS[active.provider]} · ${active.label}` : sourceNamedLabel(active, cleanLabel(active, shortLabel), duplicateTriggers)} · ${t(`Chat.effort.${effort}`)} ▾` : t('Chat.unavailable') }) });
112
141
  return _jsxs(_Fragment, { children: [trigger, narrow ? _jsx(Drawer, { anchor: "bottom", open: isOpen, onClose: () => setOpen(false), children: content }) : _jsx(Popover, { open: isOpen, anchorEl: anchor.current, onClose: () => setOpen(false), anchorOrigin: { vertical: 'top', horizontal: 'left' }, transformOrigin: { vertical: 'bottom', horizontal: 'left' }, children: content })] });
113
142
  }
114
143
  export default ModelPicker;
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' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "4.40.3",
3
+ "version": "4.42.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.9",
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.7",
82
+ "vite": "^8.3.8",
83
83
  "vitest": "^5.1.0"
84
84
  }
85
85
  }