@micha.bigler/ui-core-micha 4.14.0 → 4.16.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,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.16.0 - UCM-CHAT-7
4
+
5
+ Opt-in compact chat composer: `ChatWorkspace` props `composerLayout` (`'standard'` default, `'compact'`) and
6
+ `renderComposerContext({ chat })`; `ChatComposer` props `layout`, `context`, `notice`; `ModelPicker` prop `shortLabel`.
7
+ Compact: a non-wrapping context row (host content, model choice at its end), a full-width input with an icon Send that
8
+ becomes Stop while running, the short model label, and the long-chat hint as one dismissible line per chat
9
+ (`Chat.longChatShort` with "Neuer Chat"). New keys `Chat.longChatShort`, `Chat.stopAnswer`, `Chat.dismissNotice`.
10
+ Without the option the composer, its texts and `renderComposerExtra` are unchanged.
11
+
12
+ ## 4.15.0 - UCM-PERF-4
13
+
14
+ Opt-in `AuthProvider` prop `bootstrap` (`true` for `/api/bootstrap/`, or a same-origin path; requires
15
+ `django-core-micha` >= 3.17.0): the app shell starts from one bootstrap request instead of CSRF, `users/current`,
16
+ `auth-methods`, feed and unread count; `NotificationsProvider` takes its initial feed and count from it once for the same
17
+ person and still opens the WebSocket only after that. Any bootstrap failure falls back to the separate start requests
18
+ exactly once. New hook `useBootstrapExtension(name)` for dcm bootstrap provider payloads. Without the prop nothing
19
+ changes.
20
+
3
21
  ## 4.14.0 - UCM-PERF-5
4
22
 
5
23
  New `installChunkLoadRecovery({ guardWindowMs?, reload? })` and `isChunkLoadError(error)`. Installed once at app
package/README.md CHANGED
@@ -86,6 +86,16 @@ const setupBillingApi = createBillingApi({
86
86
  <PlanPicker api={setupBillingApi} plans={plans} />;
87
87
  ```
88
88
 
89
+ ## Start from one bootstrap request (opt-in)
90
+
91
+ With `django-core-micha` >= 3.17.0, `<AuthProvider bootstrap>` starts from `GET /api/bootstrap/` (or pass a same-origin
92
+ path instead of `true`): one request instead of CSRF, `users/current` + `auth-methods`, then the notification feed and
93
+ unread count. User, auth methods and the initial notifications end up as from the separate requests, `loading` ends at
94
+ the same point, and the notification WebSocket still connects only after that state is in place. If the bootstrap fails
95
+ in any way (a part failure, 501, 404, network), the provider runs today's separate start requests once. App start data
96
+ registered as dcm bootstrap providers is read with `useBootstrapExtension('application_access')` (`undefined` when
97
+ absent, `null`, the opt-in is off or the bootstrap failed). Without the prop nothing changes.
98
+
89
99
  ## Stale chunks after a deploy
90
100
 
91
101
  An app that lazy-loads code calls `installChunkLoadRecovery()` once at startup (before rendering). When a deploy has
@@ -131,6 +141,19 @@ extra peers are optional: `@micha.bigler/ui-core-micha/charts` (`@mui/x-charts`)
131
141
  (`react-markdown`, `remark-gfm`). Install those peers only in apps that import the sub-path. The 4.0.0 entry in
132
142
  `CHANGELOG.md` has the migration table.
133
143
 
144
+ ## Shared chat: compact composer (opt-in)
145
+
146
+ `<ChatWorkspace composerLayout="compact" renderComposerContext={({ chat }) => ...}>` lays the composer out in two
147
+ rows: a context row with the host's content (for example chips of what was added to the chat) and the model choice at
148
+ its end — one line that never wraps, the host content is clipped first (plain text gets an ellipsis; give element
149
+ items `minWidth: 0` and their own ellipsis, as MUI `Chip` labels have, and a "+n" item, so they shorten instead of
150
+ being cut) — and a full-width input with an icon Send that
151
+ becomes Stop ("Antwort stoppen") while an answer runs. The model button then shows a short label ("Sonnet · Gründlich")
152
+ without vendor and version. The long-chat hint becomes one line with "Neuer Chat" and a close button; closed, it stays
153
+ closed for that chat until the page reloads, and another chat shows it again. `renderComposerExtra` keeps rendering
154
+ above the composer. Without `composerLayout` the composer is unchanged. `ChatComposer` takes the same `layout`,
155
+ `context` and `notice` props directly; `ModelPicker` takes `shortLabel`.
156
+
134
157
  ## Shared chat: host controls
135
158
 
136
159
  `ChatWorkspace` (from `@micha.bigler/ui-core-micha/chat`) takes optional props for apps that put UI around the surface;
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  // src/auth/AuthContext.jsx
3
- import React, { createContext, useState, useEffect, } from 'react';
3
+ import React, { createContext, useState, useEffect, useCallback, } from 'react';
4
4
  import { ensureCsrfToken } from './apiClient'; // <--- IMPORT ADDED
5
- import { fetchAuthMethods, fetchCurrentUser, logoutSession, } from './authApi';
5
+ import { fetchAuthMethods, fetchCurrentUser, fetchBootstrap, logoutSession, } from './authApi';
6
6
  import { ReauthModal } from './ReauthModal';
7
7
  export const AuthContext = createContext(null);
8
8
  const DEFAULT_AUTH_METHODS = {
@@ -23,10 +23,15 @@ const DEFAULT_AUTH_METHODS = {
23
23
  two_factor_required: false,
24
24
  qr_signup_enabled: false,
25
25
  };
26
- export const AuthProvider = ({ children }) => {
26
+ export const AuthProvider = ({ children, bootstrap = false }) => {
27
27
  const [user, setUser] = useState(null);
28
28
  const [authMethods, setAuthMethods] = useState(DEFAULT_AUTH_METHODS);
29
29
  const [loading, setLoading] = useState(true);
30
+ const [notificationSeed, setNotificationSeed] = useState(null);
31
+ const [bootstrapExtensions, setBootstrapExtensions] = useState({});
32
+ const consumeBootstrapNotificationSeed = useCallback(() => {
33
+ setNotificationSeed(null);
34
+ }, []);
30
35
  const mapUserFromApi = (data) => {
31
36
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
32
37
  const profile = (data === null || data === void 0 ? void 0 : data.profile) || {};
@@ -34,7 +39,7 @@ export const AuthProvider = ({ children }) => {
34
39
  };
35
40
  useEffect(() => {
36
41
  let isMounted = true;
37
- const initAuth = async () => {
42
+ const initSeparateAuth = async () => {
38
43
  try {
39
44
  // 1) Ensure CSRF cookie exists using the specific client
40
45
  await ensureCsrfToken();
@@ -70,11 +75,49 @@ export const AuthProvider = ({ children }) => {
70
75
  setLoading(false);
71
76
  }
72
77
  };
78
+ const initAuth = async () => {
79
+ if (!bootstrap) {
80
+ await initSeparateAuth();
81
+ return;
82
+ }
83
+ try {
84
+ const data = await fetchBootstrap(bootstrap === true ? '/api/bootstrap/' : bootstrap);
85
+ if (!isMounted)
86
+ return;
87
+ const mappedUser = (data === null || data === void 0 ? void 0 : data.user) ? mapUserFromApi(data.user) : null;
88
+ const methods = data === null || data === void 0 ? void 0 : data.auth_methods;
89
+ if (methods && typeof methods === 'object') {
90
+ setAuthMethods((prev) => (Object.assign(Object.assign({}, prev), methods)));
91
+ }
92
+ setUser(mappedUser);
93
+ setBootstrapExtensions((data === null || data === void 0 ? void 0 : data.extensions) && typeof data.extensions === 'object'
94
+ ? data.extensions : {});
95
+ setNotificationSeed(mappedUser && (data === null || data === void 0 ? void 0 : data.notifications)
96
+ ? { userId: mappedUser.id, notifications: data.notifications }
97
+ : null);
98
+ setLoading(false);
99
+ }
100
+ catch (error) {
101
+ if (isMounted) {
102
+ setBootstrapExtensions({});
103
+ setNotificationSeed(null);
104
+ await initSeparateAuth();
105
+ }
106
+ }
107
+ };
73
108
  initAuth();
74
109
  return () => { isMounted = false; };
75
- }, []);
110
+ }, [bootstrap]);
111
+ // Bootstrap data belongs to the person it was loaded for; drop it when the session changes hands.
112
+ const clearBootstrapData = () => {
113
+ setBootstrapExtensions({});
114
+ setNotificationSeed(null);
115
+ };
76
116
  const login = (userData) => {
77
- setUser((prev) => (Object.assign(Object.assign({}, prev), mapUserFromApi(userData))));
117
+ const mapped = mapUserFromApi(userData);
118
+ if (user && mapped.id !== user.id)
119
+ clearBootstrapData();
120
+ setUser((prev) => (Object.assign(Object.assign({}, prev), mapped)));
78
121
  };
79
122
  const refreshUser = async () => {
80
123
  const data = await fetchCurrentUser();
@@ -90,6 +133,7 @@ export const AuthProvider = ({ children }) => {
90
133
  console.error('Error during logout:', error);
91
134
  }
92
135
  finally {
136
+ clearBootstrapData();
93
137
  setUser(null);
94
138
  }
95
139
  };
@@ -100,5 +144,14 @@ export const AuthProvider = ({ children }) => {
100
144
  login,
101
145
  logout,
102
146
  refreshUser,
147
+ bootstrapNotificationSeed: notificationSeed,
148
+ consumeBootstrapNotificationSeed,
149
+ bootstrapExtensions,
103
150
  }, children: [children, _jsx(ReauthModal, {})] }));
104
151
  };
152
+ export function useBootstrapExtension(name) {
153
+ var _a;
154
+ const context = React.useContext(AuthContext);
155
+ const payload = (_a = context === null || context === void 0 ? void 0 : context.bootstrapExtensions) === null || _a === void 0 ? void 0 : _a[name];
156
+ return payload == null ? undefined : payload;
157
+ }
@@ -20,6 +20,10 @@ export async function fetchCurrentUser() {
20
20
  });
21
21
  return res.data;
22
22
  }
23
+ export async function fetchBootstrap(url) {
24
+ const res = await apiClient.get(url, { skipAuthRedirect: true });
25
+ return res.data;
26
+ }
23
27
  export async function fetchAuthMethods() {
24
28
  const res = await apiClient.get('/api/auth-methods/');
25
29
  return res.data || {};
@@ -1,24 +1,57 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { Button, Stack, TextField } from '@mui/material';
3
+ import { Box, Button, IconButton, Stack, TextField } from '@mui/material';
4
+ import SendIcon from '@mui/icons-material/Send';
5
+ import StopIcon from '@mui/icons-material/Stop';
6
+ import CloseIcon from '@mui/icons-material/Close';
4
7
  import { useTranslation } from 'react-i18next';
5
8
  /**
6
9
  * Message input. Send is disabled while a turn runs, for an archived chat and while the connection is down;
7
10
  * Stop replaces it during a turn. Enter sends, Shift+Enter inserts a line break.
11
+ *
12
+ * `layout="compact"` (UCM-CHAT-7) stacks an optional one-line `notice` (`{ text, action, onAction, onDismiss }`),
13
+ * a context row (`context`, then `actions` at its end; never wraps, the context is clipped first) and a full-width
14
+ * input row with an icon Send that becomes Stop while running. The default `standard` layout is unchanged.
8
15
  */
9
16
  export const CHAT_COMPOSER_INPUT_SX = { flex: '1 1 12rem', minWidth: 0 };
10
- export function ChatComposer({ value = '', onChange, onSend, onStop, running = false, archived = false, connected = true, inputRef, sx, actions }) {
17
+ export const CHAT_COMPOSER_COMPACT_ROOT_SX = { display: 'flex', flexDirection: 'column', gap: 0.75, p: { xs: 1, md: 1.5 }, borderTop: 1, borderColor: 'divider', minWidth: 0 };
18
+ export const CHAT_COMPOSER_CONTEXT_ROW_SX = { display: 'flex', alignItems: 'center', gap: 0.75, minHeight: 30, minWidth: 0, flexWrap: 'nowrap' };
19
+ export const CHAT_COMPOSER_CONTEXT_SX = { minWidth: 0, flex: '1 1 auto', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' };
20
+ export const CHAT_COMPOSER_CONTEXT_ACTIONS_SX = { flex: '0 0 auto', minWidth: 0, whiteSpace: 'nowrap' };
21
+ export const CHAT_COMPOSER_INPUT_ROW_SX = { display: 'flex', alignItems: 'flex-end', gap: 0.5, minWidth: 0, p: '3px 3px 3px 10px', border: 1, borderColor: 'divider', borderRadius: 1, '&:focus-within': { borderColor: 'primary.main', boxShadow: (theme) => `0 0 0 2px ${theme.palette.primary.main}33` } };
22
+ export const CHAT_COMPOSER_COMPACT_FIELD_SX = { flex: '1 1 auto', minWidth: 0, '& .MuiOutlinedInput-root': { p: 0, alignItems: 'flex-end' }, '& .MuiOutlinedInput-notchedOutline': { border: 0 }, '& .MuiInputBase-inputMultiline': { px: 0, py: 1.5, maxHeight: '7.5em', overflowY: 'auto' } };
23
+ export const CHAT_COMPOSER_ACTION_SX = { width: 36, height: 36, flex: '0 0 36px' };
24
+ // Send is the filled primary action of the input row, as in the prototype; Stop keeps the plain icon button.
25
+ export const CHAT_COMPOSER_SEND_SX = Object.assign(Object.assign({}, CHAT_COMPOSER_ACTION_SX), { bgcolor: 'primary.main', color: 'primary.contrastText', '&:hover': { bgcolor: 'primary.dark' }, '&.Mui-disabled': { bgcolor: 'action.disabledBackground', color: 'action.disabled' } });
26
+ export const CHAT_COMPOSER_NOTICE_SX = { display: 'flex', alignItems: 'center', gap: 0.75, minWidth: 0, minHeight: 32, px: 1, color: 'text.secondary', bgcolor: 'action.hover', borderRadius: 1 };
27
+ export const CHAT_COMPOSER_NOTICE_TEXT_SX = { minWidth: 0, flex: '1 1 auto', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' };
28
+ export const CHAT_COMPOSER_NOTICE_ACTION_SX = { flex: '0 0 auto', minWidth: 0, p: 0.25, whiteSpace: 'nowrap' };
29
+ export const CHAT_COMPOSER_NOTICE_CLOSE_SX = { width: 28, height: 28, flex: '0 0 28px' };
30
+ function CompactNotice({ notice, t }) {
31
+ if (!notice)
32
+ return null;
33
+ const details = React.isValidElement(notice) ? { content: notice } : notice;
34
+ if (!details || typeof details !== 'object')
35
+ return notice;
36
+ 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
+ export function ChatComposer({ value = '', onChange, onSend, onStop, running = false, archived = false, connected = true, inputRef, sx, actions, layout = 'standard', context, notice }) {
11
39
  const { t } = useTranslation();
12
40
  const blocked = archived || !connected;
13
41
  const canSend = !running && !blocked && value.trim().length > 0;
14
42
  const submit = () => { if (canSend)
15
43
  onSend === null || onSend === void 0 ? void 0 : onSend(); };
16
- 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: (event) => {
17
- var _a;
18
- if (event.key === 'Enter' && !event.shiftKey && !((_a = event.nativeEvent) === null || _a === void 0 ? void 0 : _a.isComposing)) {
19
- event.preventDefault();
20
- submit();
21
- }
22
- } }), 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') })] }));
44
+ const handleKeyDown = (event) => {
45
+ var _a;
46
+ if (event.key === 'Enter' && !event.shiftKey && !((_a = event.nativeEvent) === null || _a === void 0 ? void 0 : _a.isComposing)) {
47
+ event.preventDefault();
48
+ submit();
49
+ }
50
+ };
51
+ 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
53
+ ? _jsx(IconButton, { "aria-label": t('Chat.stopAnswer'), title: t('Chat.stopAnswer'), sx: CHAT_COMPOSER_ACTION_SX, onClick: onStop, children: _jsx(StopIcon, {}) })
54
+ : _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') })] }));
23
56
  }
24
57
  export default ChatComposer;
@@ -62,7 +62,7 @@ const appendDelta = (turns, text) => {
62
62
  * Props: `apiBase` and `wsUrl` (where the app mounted the chat routes), `api` (partial overrides of the REST
63
63
  * calls; every function not given keeps its default), `scope` (passed when creating a chat), `sx`.
64
64
  */
65
- export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, sx, unavailableReasonText, sidePanel, sidePanelLabel, renderAnswerExtra, renderComposerExtra, onAppFrame, activeChatId, onActiveChatChange, composerPrefill, getSendContext, sendRequest, onSendRequestHandled, layout = 'viewport', compactBelow = 720, tokenBalance = null, usageToTokens, longChatTokens = 40000 }) {
65
+ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, 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
66
  var _a;
67
67
  const { t } = useTranslation();
68
68
  const theme = useTheme();
@@ -127,6 +127,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, sx, un
127
127
  const [listOpen, setListOpen] = useState(false);
128
128
  const [pickerOpen, setPickerOpen] = useState(false);
129
129
  const [openedOnce, setOpenedOnce] = useState(false); // distinguishes a reconnect from the first connect
130
+ const [dismissedComposerNotices, setDismissedComposerNotices] = useState(() => new Set());
130
131
  const running = turns.some(isGenerating);
131
132
  const isArchived = Boolean(chat === null || chat === void 0 ? void 0 : chat.archived_at);
132
133
  const selection = (chat === null || chat === void 0 ? void 0 : chat.selection) || catalogue.default;
@@ -526,6 +527,9 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, sx, un
526
527
  if (unavailable) {
527
528
  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') }) }));
528
529
  }
529
- 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, 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, { 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 }) })] })) : (_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] }));
530
+ 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`) ? {
531
+ id: 'long-chat', text: t('Chat.longChatShort'), action: t('Chat.newChat'), onAction: createChat,
532
+ onDismiss: () => setDismissedComposerNotices((current) => new Set(current).add(`${chat.id}:long-chat`)),
533
+ } : 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] }));
530
534
  }
531
535
  export default ChatWorkspace;
@@ -6,6 +6,8 @@ import { useTranslation } from 'react-i18next';
6
6
  const LEVELS = ['top', 'best', 'balanced', 'fast'];
7
7
  const EFFORTS = ['low', 'medium', 'high', 'max'];
8
8
  export const CHAT_MODEL_TRIGGER_SX = { minWidth: 0, px: 1.25, color: 'text.secondary', whiteSpace: 'nowrap', flexShrink: 0, maxWidth: { xs: 140, sm: 'none' } };
9
+ // The short label sits at the end of the compact composer's context row, which clips the host content first.
10
+ export const CHAT_MODEL_TRIGGER_SHORT_SX = Object.assign(Object.assign({}, CHAT_MODEL_TRIGGER_SX), { maxWidth: 'none' });
9
11
  export const CHAT_MODEL_ENTRY_SX = { borderRadius: 1, alignItems: 'flex-start' };
10
12
  export const CHAT_MODEL_EFFORT_SX = { flex: 1, minWidth: 0 };
11
13
  export const CHAT_MODEL_CLOSE_SX = { ml: 'auto' };
@@ -19,7 +21,10 @@ const fallback = (entries) => {
19
21
  const entry = entries.find((item) => item.default) || entries[0];
20
22
  return entry ? { entry: entry.id, effort: (_a = entry.efforts) === null || _a === void 0 ? void 0 : _a[0] } : null;
21
23
  };
22
- const cleanLabel = (entry) => ((entry === null || entry === void 0 ? void 0 : entry.label) || (entry === null || entry === void 0 ? void 0 : entry.model) || '').replace(/\s+\d+(?:\.\d+)*$/, '');
24
+ const cleanLabel = (entry, shortLabel = false) => {
25
+ const withoutVersion = ((entry === null || entry === void 0 ? void 0 : entry.label) || (entry === null || entry === void 0 ? void 0 : entry.model) || '').replace(/\s+\d+(?:\.\d+)*$/, '');
26
+ return shortLabel ? withoutVersion.replace(/^(?:(?:Claude|Anthropic|OpenAI)\s+)+/i, '') : withoutVersion;
27
+ };
23
28
  function estimateText(entry, effort, t, language) {
24
29
  var _a;
25
30
  if (entry.billing === 'subscription')
@@ -37,7 +42,7 @@ function estimateText(entry, effort, t, language) {
37
42
  }
38
43
  return null;
39
44
  }
40
- export function ModelPicker({ entries = [], selection, onChange, disabled = false, open, onOpenChange, sheet, balance = null, longChat = false, onNewChat }) {
45
+ export function ModelPicker({ entries = [], selection, onChange, disabled = false, open, onOpenChange, sheet, balance = null, longChat = false, onNewChat, shortLabel = false }) {
41
46
  const { t, i18n } = useTranslation();
42
47
  const language = typeof (i18n === null || i18n === void 0 ? void 0 : i18n.language) === 'string' ? i18n.language.split('_')[0] || undefined : undefined;
43
48
  const theme = useTheme();
@@ -80,7 +85,7 @@ export function ModelPicker({ entries = [], selection, onChange, disabled = fals
80
85
  };
81
86
  const content = (_jsx(Box, { role: "dialog", "aria-labelledby": "chat-model-picker-title", sx: { p: 2, width: narrow ? 'auto' : 360, maxWidth: '100%', maxHeight: narrow ? '82vh' : 'min(640px, 80vh)', overflowY: 'auto' }, 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" }) })] }), _jsxs(Box, { role: "radiogroup", "aria-labelledby": "chat-model-picker-title", onKeyDown: moveSelection, children: [grouped.map(([level, items]) => _jsxs(Box, { children: [_jsx(Typography, { variant: "subtitle2", children: t(`Chat.level.${level}`) }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t(`Chat.levelHint.${level}`) }), _jsx(List, { dense: true, disablePadding: true, children: items.map(entryRow) })] }, level)), unknown.length ? _jsx(List, { dense: true, disablePadding: true, children: unknown.map(entryRow) }) : null] }), active ? _jsxs(Box, { children: [_jsx(Typography, { variant: "subtitle2", sx: { mb: 0.75 }, children: t('Chat.effortQuestion') }), _jsx(ToggleButtonGroup, { exclusive: true, fullWidth: true, size: "small", value: effort || null, "aria-label": t('Chat.effortQuestion'), onChange: (_event, next) => { if (next)
82
87
  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: t(`Chat.effort.${item}`) }, item)) }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t(hasTokenEstimates ? 'Chat.effortHintTokens' : 'Chat.effortHint') })] }) : null, longChat ? _jsx(Alert, { severity: "warning", action: onNewChat ? _jsx(Button, { color: "inherit", size: "small", onClick: onNewChat, children: t('Chat.newConversation') }) : null, children: t('Chat.longChat') }) : 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] }) }));
83
- const trigger = _jsx(Button, { ref: anchor, size: "small", color: "inherit", 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 ? `${cleanLabel(active)} · ${t(`Chat.effort.${effort}`)} ▾` : t('Chat.chooseModel') }) });
88
+ 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 ? `${cleanLabel(active, shortLabel)} · ${t(`Chat.effort.${effort}`)} ▾` : t('Chat.chooseModel') }) });
84
89
  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 })] });
85
90
  }
86
91
  export default ModelPicker;
@@ -1,11 +1,24 @@
1
1
  import { createKitSxEntry } from '../theme/kitSxEntry';
2
- import { CHAT_COMPOSER_INPUT_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, } from './ChatComposer';
3
3
  import { CHAT_LIST_ARCHIVED_ACTION_SX, CHAT_LIST_ROW_ACTION_SX } from './ChatList';
4
4
  import { CHAT_THREAD_NOTICE_SX, CHAT_THREAD_TOOL_CHIP_SX, CHAT_THREAD_TRIMMED_SX } from './ChatThread';
5
- import { CHAT_MODEL_TRIGGER_SX, CHAT_MODEL_ENTRY_SX, CHAT_MODEL_EFFORT_SX, CHAT_MODEL_CLOSE_SX } from './ModelPicker';
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'),
8
+ createKitSxEntry('ChatComposer.compactRoot', 'MuiStack', CHAT_COMPOSER_COMPACT_ROOT_SX, 'CHAT_COMPOSER_COMPACT_ROOT_SX'),
9
+ createKitSxEntry('ChatComposer.contextRow', 'MuiStack', CHAT_COMPOSER_CONTEXT_ROW_SX, 'CHAT_COMPOSER_CONTEXT_ROW_SX'),
10
+ createKitSxEntry('ChatComposer.context', 'MuiBox', CHAT_COMPOSER_CONTEXT_SX, 'CHAT_COMPOSER_CONTEXT_SX'),
11
+ createKitSxEntry('ChatComposer.contextActions', 'MuiBox', CHAT_COMPOSER_CONTEXT_ACTIONS_SX, 'CHAT_COMPOSER_CONTEXT_ACTIONS_SX'),
12
+ createKitSxEntry('ChatComposer.inputRow', 'MuiStack', CHAT_COMPOSER_INPUT_ROW_SX, 'CHAT_COMPOSER_INPUT_ROW_SX'),
13
+ createKitSxEntry('ChatComposer.compactField', 'MuiTextField', CHAT_COMPOSER_COMPACT_FIELD_SX, 'CHAT_COMPOSER_COMPACT_FIELD_SX'),
14
+ createKitSxEntry('ChatComposer.action', 'MuiIconButton', CHAT_COMPOSER_ACTION_SX, 'CHAT_COMPOSER_ACTION_SX'),
15
+ createKitSxEntry('ChatComposer.send', 'MuiIconButton', CHAT_COMPOSER_SEND_SX, 'CHAT_COMPOSER_SEND_SX'),
16
+ createKitSxEntry('ChatComposer.notice', 'MuiBox', CHAT_COMPOSER_NOTICE_SX, 'CHAT_COMPOSER_NOTICE_SX'),
17
+ createKitSxEntry('ChatComposer.noticeText', 'MuiBox', CHAT_COMPOSER_NOTICE_TEXT_SX, 'CHAT_COMPOSER_NOTICE_TEXT_SX'),
18
+ createKitSxEntry('ChatComposer.noticeAction', 'MuiButton', CHAT_COMPOSER_NOTICE_ACTION_SX, 'CHAT_COMPOSER_NOTICE_ACTION_SX'),
19
+ createKitSxEntry('ChatComposer.noticeClose', 'MuiIconButton', CHAT_COMPOSER_NOTICE_CLOSE_SX, 'CHAT_COMPOSER_NOTICE_CLOSE_SX'),
8
20
  createKitSxEntry('ModelPicker.trigger', 'MuiButton', CHAT_MODEL_TRIGGER_SX, 'CHAT_MODEL_TRIGGER_SX'),
21
+ createKitSxEntry('ModelPicker.triggerShort', 'MuiButton', CHAT_MODEL_TRIGGER_SHORT_SX, 'CHAT_MODEL_TRIGGER_SHORT_SX'),
9
22
  createKitSxEntry('ModelPicker.entry', 'MuiListItemButton', CHAT_MODEL_ENTRY_SX, 'CHAT_MODEL_ENTRY_SX'),
10
23
  createKitSxEntry('ModelPicker.effort', 'MuiToggleButton', CHAT_MODEL_EFFORT_SX, 'CHAT_MODEL_EFFORT_SX'),
11
24
  createKitSxEntry('ModelPicker.close', 'MuiIconButton', CHAT_MODEL_CLOSE_SX, 'CHAT_MODEL_CLOSE_SX'),
@@ -14,6 +14,8 @@ export const chatTranslations = {
14
14
  'Chat.loadOlder': { de: 'Ältere laden', en: 'Load older', fr: 'Charger les plus anciens', sw: 'Pakia za zamani' },
15
15
  'Chat.send': { de: 'Senden', en: 'Send', fr: 'Envoyer', sw: 'Tuma' },
16
16
  'Chat.stop': { de: 'Stoppen', en: 'Stop', fr: 'Arrêter', sw: 'Simamisha' },
17
+ 'Chat.stopAnswer': { de: 'Antwort stoppen', en: 'Stop answer', fr: 'Arrêter la réponse', sw: 'Simamisha jibu' },
18
+ 'Chat.dismissNotice': { de: 'Hinweis schliessen', en: 'Dismiss notice', fr: 'Fermer la notification', sw: 'Funga taarifa' },
17
19
  'Chat.message': { de: 'Nachricht', en: 'Message', fr: 'Message', sw: 'Ujumbe' },
18
20
  'Chat.typing': { de: 'Antwort wird erstellt …', en: 'Thinking…', fr: 'Réflexion…', sw: 'Inafikiria…' },
19
21
  'Chat.retry': { de: 'Erneut versuchen', en: 'Retry', fr: 'Réessayer', sw: 'Jaribu tena' },
@@ -44,6 +46,7 @@ export const chatTranslations = {
44
46
  'Chat.effortHintTokens': { de: 'Gründlicher heisst bessere Antworten, aber längere Wartezeit und mehr Token.', en: 'More thorough means better answers, but longer waits and more tokens.', fr: 'Une réponse plus approfondie est meilleure, mais prend plus de temps et consomme plus de jetons.', sw: 'Jibu lenye kina zaidi huwa bora, lakini husubiriwa muda mrefu na hutumia tokeni zaidi.' },
45
47
  'Chat.effortHint': { de: 'Gründlicher heisst bessere Antworten, aber längere Wartezeit.', en: 'More thorough means better answers, but longer waits.', fr: 'Une réponse plus approfondie est meilleure, mais prend plus de temps.', sw: 'Jibu lenye kina zaidi huwa bora, lakini husubiriwa muda mrefu.' },
46
48
  'Chat.longChat': { de: 'Diese Unterhaltung ist lang. Ältere Teile werden zusammengefasst; eine neue Unterhaltung ist günstiger.', en: 'This conversation is long. Older parts will be summarized; a new conversation costs less.', fr: 'Cette conversation est longue. Les anciens passages seront résumés ; une nouvelle conversation coûte moins cher.', sw: 'Mazungumzo haya ni marefu. Sehemu za awali zitafupishwa; mazungumzo mapya yatagharimu kidogo.' },
49
+ 'Chat.longChatShort': { de: 'Lange Unterhaltung: ältere Teile werden zusammengefasst.', en: 'Long conversation: older parts will be summarized.', fr: 'Discussion longue : les anciens passages seront résumés.', sw: 'Mazungumzo marefu: sehemu za awali zitafupishwa.' },
47
50
  'Chat.newConversation': { de: 'Neue Unterhaltung', en: 'New conversation', fr: 'Nouvelle conversation', sw: 'Mazungumzo mapya' },
48
51
  'Chat.balanceLabel': { de: 'Guthaben {{n}} Token', en: 'Balance: {{n}} tokens', fr: 'Solde : {{n}} jetons', sw: 'Salio: tokeni {{n}}' },
49
52
  'Chat.summaryUntilHere': { de: 'Zusammenfassung bis hier', en: 'Summary so far', fr: 'Résumé jusqu’ici', sw: 'Muhtasari hadi hapa' },
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ export { createAppTheme, assertThemeComplete, assertKitSxDisjoint, calculateCont
10
10
  export { checkKitIntegration } from './testing/checkKitIntegration';
11
11
  export { installChunkLoadRecovery, isChunkLoadError } from './utils/chunkLoadRecovery';
12
12
  // --- 1. Auth Context (Essentiell für den Wrapper) ---
13
- export { AuthContext, AuthProvider } from './auth/AuthContext';
13
+ export { AuthContext, AuthProvider, useBootstrapExtension } from './auth/AuthContext';
14
14
  export { UserMenu } from './auth/UserMenu';
15
15
  export { default as apiClient, ensureCsrfToken, addPublicPath, removePublicPath, } from "./auth/apiClient";
16
16
  // --- 2. API & Services (Neue Struktur) ---
@@ -39,6 +39,8 @@ function patchStatus(notification, status) {
39
39
  export function NotificationsProvider({ children, wsUrlBase }) {
40
40
  const auth = useContext(AuthContext);
41
41
  const authenticated = Boolean(auth === null || auth === void 0 ? void 0 : auth.user);
42
+ const bootstrapSeed = auth === null || auth === void 0 ? void 0 : auth.bootstrapNotificationSeed;
43
+ const consumeBootstrapSeed = auth === null || auth === void 0 ? void 0 : auth.consumeBootstrapNotificationSeed;
42
44
  const [notifications, setNotifications] = useState([]);
43
45
  const [unreadCount, setUnreadCount] = useState(0);
44
46
  const notificationsRef = useRef([]);
@@ -113,12 +115,24 @@ export function NotificationsProvider({ children, wsUrlBase }) {
113
115
  return subscribe(DEFAULT_ENVELOPE, handleRealtimeMessage);
114
116
  }, [authenticated, subscribe, handleRealtimeMessage]);
115
117
  useEffect(() => {
118
+ var _a, _b, _c;
116
119
  if (!authenticated) {
117
120
  replaceNotifications([]);
118
121
  setUnreadCount(0);
119
122
  setSeeded(false);
120
123
  return undefined;
121
124
  }
125
+ if (bootstrapSeed && bootstrapSeed.userId === ((_a = auth === null || auth === void 0 ? void 0 : auth.user) === null || _a === void 0 ? void 0 : _a.id)) {
126
+ const feed = (_b = bootstrapSeed.notifications) === null || _b === void 0 ? void 0 : _b.feed;
127
+ const unread = (_c = bootstrapSeed.notifications) === null || _c === void 0 ? void 0 : _c.unread_count;
128
+ const nextNotifications = ((feed === null || feed === void 0 ? void 0 : feed.results) || []).map(normalizeNotification);
129
+ notificationsRef.current = nextNotifications;
130
+ setNotifications(nextNotifications);
131
+ setUnreadCount((unread === null || unread === void 0 ? void 0 : unread.count) || 0);
132
+ setSeeded(true);
133
+ consumeBootstrapSeed === null || consumeBootstrapSeed === void 0 ? void 0 : consumeBootstrapSeed();
134
+ return undefined;
135
+ }
122
136
  let cancelled = false;
123
137
  refresh()
124
138
  .catch(() => {
@@ -131,7 +145,9 @@ export function NotificationsProvider({ children, wsUrlBase }) {
131
145
  return () => {
132
146
  cancelled = true;
133
147
  };
134
- }, [authenticated, refresh, replaceNotifications]);
148
+ // The seed and the user id are read when the provider becomes authenticated; adding the user id as
149
+ // a dependency would refetch on a user switch without logout, which is not today's behaviour.
150
+ }, [authenticated, refresh, replaceNotifications, consumeBootstrapSeed]);
135
151
  const mark = useCallback((action, ids) => {
136
152
  const selectedIds = Array.isArray(ids) ? ids : [];
137
153
  const selected = new Set(selectedIds);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "4.14.0",
3
+ "version": "4.16.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "exports": {