@micha.bigler/ui-core-micha 4.38.0 → 4.39.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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.39.0 - UCM-CHAT-20
4
+
5
+ Chat workspaces refresh managed model catalogues in the foreground and identify the source when
6
+ display labels collide. A revoked selection follows the server's eligible standard without
7
+ persisting a new explicit choice. Requires a source-aware DCM catalogue for managed behavior.
8
+
3
9
  ## 4.37.1 - UCM-AUTH-16
4
10
 
5
11
  Setup wizard step labels use a wider three-column layout on narrow screens, keeping longer labels readable while retaining the desktop row and existing navigation behavior.
@@ -56,6 +56,23 @@ const appendDelta = (turns, text) => {
56
56
  return turns;
57
57
  return turns.map((turn, i) => (i === index ? Object.assign(Object.assign({}, turn), { assistant_text: `${turn.assistant_text || ''}${text}` }) : turn));
58
58
  };
59
+ const sameChatId = (left, right) => (left == null && right == null)
60
+ || (left != null && right != null && String(left) === String(right));
61
+ const validSelection = (entries, selection) => {
62
+ var _a;
63
+ const entry = entries.find((item) => item.id === (selection === null || selection === void 0 ? void 0 : selection.entry));
64
+ return entry && ((_a = entry.efforts) === null || _a === void 0 ? void 0 : _a.includes(selection === null || selection === void 0 ? void 0 : selection.effort)) ? selection : null;
65
+ };
66
+ const validCatalogue = (value) => {
67
+ if (!value || typeof value !== 'object' || !Array.isArray(value.entries)
68
+ || !Object.prototype.hasOwnProperty.call(value, 'default'))
69
+ return false;
70
+ if (!Object.prototype.hasOwnProperty.call(value, 'policy'))
71
+ return true;
72
+ return value.policy && typeof value.policy === 'object'
73
+ && Object.prototype.hasOwnProperty.call(value.policy, 'revision')
74
+ && (value.policy.revision === null || Number.isInteger(value.policy.revision));
75
+ };
59
76
  /**
60
77
  * The complete chat surface: chat list, thread, composer and model picker for one user.
61
78
  *
@@ -157,38 +174,57 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
157
174
  const running = turns.some(isGenerating);
158
175
  const isArchived = Boolean(chat === null || chat === void 0 ? void 0 : chat.archived_at);
159
176
  const usageLimitReached = Boolean(usageLimit && usageLimit.usedUsdMicros >= usageLimit.limitUsdMicros);
160
- const selection = (chat === null || chat === void 0 ? void 0 : chat.selection) || catalogue.default;
177
+ const selection = chat
178
+ ? (validSelection(catalogue.entries, chat.selection) || validSelection(catalogue.entries, catalogue.default))
179
+ : validSelection(catalogue.entries, catalogue.default);
161
180
  const activeEntry = catalogue.entries.find((entry) => entry.id === (selection === null || selection === void 0 ? void 0 : selection.entry));
181
+ const managedPolicy = catalogue.policy != null;
162
182
  const latestUsageTurn = [...turns].reverse().find((turn) => turn.usage);
163
183
  const longChat = longChatTokens > 0 && Number.isFinite((_a = latestUsageTurn === null || latestUsageTurn === void 0 ? void 0 : latestUsageTurn.usage) === null || _a === void 0 ? void 0 : _a.context_tokens) && latestUsageTurn.usage.context_tokens >= longChatTokens;
164
184
  // Only the newest catalogue request may update the state, so a slow answer for a chat that was left cannot overwrite the active one.
165
185
  const catalogueRequest = useRef(0);
186
+ const pendingCatalogue = useRef(null);
166
187
  const catalogueFor = useRef(null);
188
+ const shownChatId = useRef(null);
189
+ // Bumped on every scope change so that a list response of the previous scope is dropped.
190
+ const scopeVersion = useRef(0);
167
191
  const [catalogueLoading, setCatalogueLoading] = useState(false);
168
192
  const refreshCatalogue = useCallback(async (chatId) => {
193
+ var _a;
194
+ const version = scopeVersion.current;
195
+ const pending = pendingCatalogue.current;
196
+ if ((pending === null || pending === void 0 ? void 0 : pending.version) === version && sameChatId(pending.chatId, chatId))
197
+ return null;
169
198
  const request = ++catalogueRequest.current;
199
+ pendingCatalogue.current = { request, version, chatId };
170
200
  setCatalogueLoading(true);
171
201
  try {
172
202
  const next = await api.getCatalogue(chatId !== undefined ? { chat: chatId } : {});
173
- if (request !== catalogueRequest.current)
203
+ const current = request === catalogueRequest.current
204
+ && version === scopeVersion.current
205
+ && sameChatId(shownChatId.current, chatId);
206
+ if (!current || !validCatalogue(next))
174
207
  return null;
175
208
  catalogueFor.current = chatId !== null && chatId !== void 0 ? chatId : null;
176
209
  setCatalogue(next);
177
210
  setCatalogueChatId(chatId !== null && chatId !== void 0 ? chatId : null);
178
211
  return next;
179
212
  }
180
- catch (_a) {
213
+ catch (_b) {
181
214
  // A failed load for another chat must not leave the previous chat's models on offer.
182
- if (request === catalogueRequest.current && chatId !== undefined && catalogueFor.current !== chatId)
215
+ if (request === catalogueRequest.current && version === scopeVersion.current && chatId !== undefined
216
+ && sameChatId(shownChatId.current, chatId) && !sameChatId(catalogueFor.current, chatId)) {
183
217
  setCatalogue({ entries: [], default: null });
218
+ }
184
219
  return null;
185
220
  }
186
221
  finally {
222
+ if (((_a = pendingCatalogue.current) === null || _a === void 0 ? void 0 : _a.request) === request)
223
+ pendingCatalogue.current = null;
187
224
  if (request === catalogueRequest.current)
188
225
  setCatalogueLoading(false);
189
226
  }
190
227
  }, [api]);
191
- const shownChatId = useRef(null);
192
228
  const generalCatalogueRequested = useRef(false);
193
229
  const requestGeneralCatalogue = useCallback(() => {
194
230
  if (generalCatalogueRequested.current)
@@ -196,8 +232,6 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
196
232
  generalCatalogueRequested.current = true;
197
233
  return refreshCatalogue();
198
234
  }, [refreshCatalogue]);
199
- // Bumped on every scope change so that a list response of the previous scope is dropped.
200
- const scopeVersion = useRef(0);
201
235
  const limitRequest = useRef(0);
202
236
  const refreshLimit = useCallback(async (chatId) => {
203
237
  const request = ++limitRequest.current;
@@ -262,7 +296,8 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
262
296
  .then((state) => {
263
297
  if (!live)
264
298
  return;
265
- if (state.status !== 'available') {
299
+ const managedUnavailable = state.policy && ['policy_unavailable', 'no_model_enabled'].includes(state.reason);
300
+ if (state.status !== 'available' && !managedUnavailable) {
266
301
  setStatus(state.status);
267
302
  setUnavailableReason(state.reason || null);
268
303
  return;
@@ -275,7 +310,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
275
310
  setChats(active.results || []);
276
311
  setNextChats(active.next || null);
277
312
  setArchived(old.results || []);
278
- setStatus(state.status);
313
+ setStatus('available');
279
314
  setListsLoaded(true);
280
315
  setUnavailableReason(null);
281
316
  }).catch(() => { if (live)
@@ -299,6 +334,20 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
299
334
  }, [chat === null || chat === void 0 ? void 0 : chat.id, refreshCatalogue, requestGeneralCatalogue]);
300
335
  useEffect(() => { if (pickerOpen)
301
336
  refreshCatalogue(chat === null || chat === void 0 ? void 0 : chat.id); }, [pickerOpen]);
337
+ useEffect(() => {
338
+ const refreshIfForeground = () => {
339
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden')
340
+ return;
341
+ refreshCatalogue(chat === null || chat === void 0 ? void 0 : chat.id);
342
+ };
343
+ document.addEventListener('visibilitychange', refreshIfForeground);
344
+ const interval = managedPolicy ? window.setInterval(refreshIfForeground, 10000) : null;
345
+ return () => {
346
+ document.removeEventListener('visibilitychange', refreshIfForeground);
347
+ if (interval !== null)
348
+ window.clearInterval(interval);
349
+ };
350
+ }, [chat === null || chat === void 0 ? void 0 : chat.id, managedPolicy, refreshCatalogue]);
302
351
  useEffect(() => {
303
352
  var _a;
304
353
  var _b;
@@ -553,21 +602,20 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
553
602
  setChat(updated);
554
603
  await loadLists();
555
604
  });
556
- const fallbackApplied = useRef(new Set());
605
+ const legacyFallbackApplied = useRef(new Set());
557
606
  useEffect(() => {
558
607
  var _a;
559
- if (!chat || catalogueChatId !== chat.id || !catalogue.entries.length || fallbackApplied.current.has(chat.id))
560
- return;
561
- const valid = catalogue.entries.some((entry) => { var _a, _b, _c; return entry.id === ((_a = chat.selection) === null || _a === void 0 ? void 0 : _a.entry) && ((_b = entry.efforts) === null || _b === void 0 ? void 0 : _b.includes((_c = chat.selection) === null || _c === void 0 ? void 0 : _c.effort)); });
562
- if (valid)
608
+ if (managedPolicy || !chat || catalogueChatId !== chat.id || !catalogue.entries.length
609
+ || legacyFallbackApplied.current.has(chat.id) || validSelection(catalogue.entries, chat.selection))
563
610
  return;
564
- const served = catalogue.entries.find((item) => { var _a, _b, _c; return item.id === ((_a = catalogue.default) === null || _a === void 0 ? void 0 : _a.entry) && ((_b = item.efforts) === null || _b === void 0 ? void 0 : _b.includes((_c = catalogue.default) === null || _c === void 0 ? void 0 : _c.effort)); });
565
- const entry = served || catalogue.entries.find((item) => item.default) || catalogue.entries[0];
566
- if (!entry)
611
+ const served = validSelection(catalogue.entries, catalogue.default);
612
+ const fallback = catalogue.entries.find((entry) => entry.default) || catalogue.entries[0];
613
+ const next = served || (fallback && { entry: fallback.id, effort: (_a = fallback.efforts) === null || _a === void 0 ? void 0 : _a[0] });
614
+ if (!next)
567
615
  return;
568
- fallbackApplied.current.add(chat.id);
569
- updateChat(chat, { selection: { entry: entry.id, effort: served ? catalogue.default.effort : (_a = entry.efforts) === null || _a === void 0 ? void 0 : _a[0] } });
570
- }, [chat, catalogue, catalogueChatId, updateChat]);
616
+ legacyFallbackApplied.current.add(chat.id);
617
+ updateChat(chat, { selection: next });
618
+ }, [chat, catalogue, catalogueChatId, managedPolicy, updateChat]);
571
619
  const deleteChat = guarded(async (target) => {
572
620
  await api.deleteChat(target.id);
573
621
  setChats((current) => current.filter((item) => item.id !== target.id));
@@ -663,6 +711,6 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
663
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`) ? {
664
712
  id: 'long-chat', text: t('Chat.longChatShort'), action: t('Chat.newChat'), onAction: createChat,
665
713
  onDismiss: () => setDismissedComposerNotices((current) => new Set(current).add(`${chat.id}:long-chat`)),
666
- } : 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, 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] }));
714
+ } : 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] }));
667
715
  }
668
716
  export default ChatWorkspace;
@@ -30,6 +30,16 @@ const cleanLabel = (entry, shortLabel = false) => {
30
30
  const withoutVersion = ((entry === null || entry === void 0 ? void 0 : entry.label) || (entry === null || entry === void 0 ? void 0 : entry.model) || '').replace(/\s+\d+(?:\.\d+)*$/, '');
31
31
  return shortLabel ? withoutVersion.replace(/^(?:(?:Claude|Anthropic|OpenAI)\s+)+/i, '') : withoutVersion;
32
32
  };
33
+ const originalLabel = (entry) => (entry === null || entry === void 0 ? void 0 : entry.label) || (entry === null || entry === void 0 ? void 0 : entry.model) || '';
34
+ const sourceNamedLabel = (entry, label, duplicateLabels) => (duplicateLabels.has(label) && (entry === null || entry === void 0 ? void 0 : entry.source_label) ? `${label} · ${entry.source_label}` : label);
35
+ const repeatedLabels = (entries, getLabel) => {
36
+ const counts = new Map();
37
+ entries.forEach((entry) => {
38
+ const label = getLabel(entry);
39
+ counts.set(label, (counts.get(label) || 0) + 1);
40
+ });
41
+ return new Set([...counts].filter(([, count]) => count > 1).map(([label]) => label));
42
+ };
33
43
  function estimateText(entry, effort, t, language) {
34
44
  var _a;
35
45
  if (entry.billing === 'subscription')
@@ -52,7 +62,7 @@ function estimateText(entry, effort, t, language) {
52
62
  }
53
63
  return null;
54
64
  }
55
- export function ModelPicker({ entries = [], selection, onChange, disabled = false, open, onOpenChange, balance = null, shortLabel = false }) {
65
+ export function ModelPicker({ entries = [], selection, onChange, disabled = false, open, onOpenChange, balance = null, shortLabel = false, managed = false }) {
56
66
  const { t, i18n } = useTranslation();
57
67
  const language = typeof (i18n === null || i18n === void 0 ? void 0 : i18n.language) === 'string' ? i18n.language.split('_')[0] || undefined : undefined;
58
68
  const theme = useTheme();
@@ -63,19 +73,21 @@ export function ModelPicker({ entries = [], selection, onChange, disabled = fals
63
73
  const [innerOpen, setInnerOpen] = useState(false);
64
74
  const isOpen = open !== null && open !== void 0 ? open : innerOpen;
65
75
  const setOpen = (value) => { setInnerOpen(value); onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(value); };
66
- const activeSelection = useMemo(() => validSelection(entries, selection) || fallback(entries), [entries, selection]);
76
+ const activeSelection = useMemo(() => validSelection(entries, selection) || (!managed ? fallback(entries) : null), [entries, selection, managed]);
67
77
  const active = entries.find((entry) => entry.id === (activeSelection === null || activeSelection === void 0 ? void 0 : activeSelection.entry));
68
78
  const effort = activeSelection === null || activeSelection === void 0 ? void 0 : activeSelection.effort;
79
+ const duplicateRows = useMemo(() => repeatedLabels(entries, originalLabel), [entries]);
80
+ const duplicateTriggers = useMemo(() => repeatedLabels(entries, (entry) => cleanLabel(entry, shortLabel)), [entries, shortLabel]);
69
81
  const grouped = LEVELS.map((level) => [level, entries.filter((entry) => entry.level === level)]).filter(([, items]) => items.length);
70
82
  const unknown = entries.filter((entry) => !LEVELS.includes(entry.level));
71
83
  const orderedEntries = [...grouped.flatMap(([, items]) => items), ...unknown];
72
84
  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] }); };
73
- const entryRow = (entry) => {
85
+ const entryRow = (entry, index) => {
74
86
  var _a;
75
87
  const shown = supported(entry, effort) ? effort : (_a = entry.efforts) === null || _a === void 0 ? void 0 : _a[0];
76
88
  const estimate = estimateText(entry, shown, t, language);
77
89
  const checked = entry.id === (active === null || active === void 0 ? void 0 : active.id);
78
- return _jsx(ListItemButton, { role: "radio", "aria-checked": checked, tabIndex: checked ? 0 : -1, "data-model-entry": entry.id, selected: checked, sx: CHAT_MODEL_ENTRY_SX, onClick: () => selectEntry(entry), children: _jsxs(Box, { sx: CHAT_MODEL_ENTRY_CONTENT_SX, children: [_jsx(Typography, { variant: "body2", fontWeight: checked ? 600 : 400, children: entry.label || entry.model }), estimate ? _jsx(Typography, { variant: "caption", color: "text.secondary", sx: CHAT_MODEL_COST_SX, children: estimate }) : null] }) }, entry.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);
79
91
  };
80
92
  // Radio-group keyboard behaviour: arrows move the focus and the choice, only the checked row is a tab stop.
81
93
  const moveSelection = (event) => {
@@ -83,8 +95,11 @@ export function ModelPicker({ entries = [], selection, onChange, disabled = fals
83
95
  const keys = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 };
84
96
  if (!(event.key in keys))
85
97
  return;
98
+ if (!orderedEntries.length)
99
+ return;
86
100
  const at = orderedEntries.findIndex((entry) => entry.id === (active === null || active === void 0 ? void 0 : active.id));
87
- const next = orderedEntries[(at + keys[event.key] + orderedEntries.length) % orderedEntries.length];
101
+ const nextIndex = at < 0 ? (keys[event.key] > 0 ? 0 : orderedEntries.length - 1) : (at + keys[event.key] + orderedEntries.length) % orderedEntries.length;
102
+ const next = orderedEntries[nextIndex];
88
103
  if (!next)
89
104
  return;
90
105
  event.preventDefault();
@@ -93,7 +108,7 @@ export function ModelPicker({ entries = [], selection, onChange, disabled = fals
93
108
  };
94
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)
95
110
  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] }) }));
96
- 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') }) });
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') }) });
97
112
  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 })] });
98
113
  }
99
114
  export default ModelPicker;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "4.38.0",
3
+ "version": "4.39.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "exports": {