@micha.bigler/ui-core-micha 4.41.0 → 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 +11 -0
- package/dist/chat/ChatWorkspace.js +8 -3
- package/dist/chat/ModelPicker.js +37 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
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
|
+
|
|
3
14
|
## 4.41.0 - UCM-CHAT-22
|
|
4
15
|
|
|
5
16
|
Chat workspaces support per-chat permission groups, including explicit
|
|
@@ -8,7 +8,7 @@ import { useChatSocket } from './useChatSocket';
|
|
|
8
8
|
import ChatList from './ChatList';
|
|
9
9
|
import ChatThread from './ChatThread';
|
|
10
10
|
import ChatComposer from './ChatComposer';
|
|
11
|
-
import ModelPicker from './ModelPicker';
|
|
11
|
+
import ModelPicker, { publicFamilies } from './ModelPicker';
|
|
12
12
|
const PENDING_ID = 'pending';
|
|
13
13
|
const buildSendFrame = (message, getContext) => {
|
|
14
14
|
if (typeof getContext !== 'function')
|
|
@@ -206,10 +206,15 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
206
206
|
&& sameChatId(shownChatId.current, chatId);
|
|
207
207
|
if (!current || !validCatalogue(next))
|
|
208
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;
|
|
209
214
|
catalogueFor.current = chatId !== null && chatId !== void 0 ? chatId : null;
|
|
210
|
-
setCatalogue(
|
|
215
|
+
setCatalogue(safe);
|
|
211
216
|
setCatalogueChatId(chatId !== null && chatId !== void 0 ? chatId : null);
|
|
212
|
-
return
|
|
217
|
+
return safe;
|
|
213
218
|
}
|
|
214
219
|
catch (_b) {
|
|
215
220
|
// A failed load for another chat must not leave the previous chat's models on offer.
|
package/dist/chat/ModelPicker.js
CHANGED
|
@@ -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 =
|
|
82
|
-
|
|
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;
|