@micha.bigler/ui-core-micha 4.27.0 → 4.28.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 +16 -0
- package/README.md +7 -0
- package/dist/chat/ChatComposer.js +35 -8
- package/dist/chat/ChatThread.js +6 -1
- package/dist/chat/ChatWorkspace.js +37 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.28.0 - UCM-CHAT-15
|
|
4
|
+
|
|
5
|
+
New optional `ChatWorkspace` prop `onComposeStart({ chatId })`: called when the composer of a shown chat gains focus
|
|
6
|
+
and when its draft goes from empty to non-empty, once each until the draft is cleared again (sent or emptied); never
|
|
7
|
+
per keystroke and without re-rendering the workspace. `ChatComposer` takes the matching optional `onComposeStart()`.
|
|
8
|
+
A shown chat now costs one catalogue request: the general catalogue is requested only while no chat is shown (at start
|
|
9
|
+
only when no `activeChatId` names a chat, and again when the requested chat cannot be shown); the picker-open and
|
|
10
|
+
after-turn refreshes are unchanged.
|
|
11
|
+
|
|
12
|
+
## 4.27.1 - UCM-CHAT-14 follow-up
|
|
13
|
+
|
|
14
|
+
The thread's bottom pin no longer depends on scroll events: switching chats re-pins explicitly, and the thread also
|
|
15
|
+
observes its own scroll region, so a chat mounted in a hidden host panel goes to the bottom when the panel is shown.
|
|
16
|
+
Found in the Maana staging acceptance of 4.27.0 (thread opened far above the bottom after mounting in a not-yet-shown
|
|
17
|
+
tab, and after switching chats).
|
|
18
|
+
|
|
3
19
|
## 4.27.0 - UCM-CHAT-14
|
|
4
20
|
|
|
5
21
|
Typing in a long chat relayouts only the composer. The thread's scroll region and the wide side panel are CSS
|
package/README.md
CHANGED
|
@@ -222,6 +222,13 @@ codes it knows; return `null` for everything else:
|
|
|
222
222
|
/>
|
|
223
223
|
```
|
|
224
224
|
|
|
225
|
+
## Shared chat: composer start signal
|
|
226
|
+
|
|
227
|
+
Since 4.28.0 `onComposeStart({ chatId })` tells the host that the person started composing in a chat: on the first
|
|
228
|
+
focus of the composer and when the draft goes from empty to non-empty, again after it was cleared. Use it to prepare
|
|
229
|
+
something before the send (for example a context-size check), not per keystroke. A shown chat requests its catalogue
|
|
230
|
+
once; the general catalogue is only requested while no chat is shown.
|
|
231
|
+
|
|
225
232
|
## Shared chat: host controls
|
|
226
233
|
|
|
227
234
|
`ChatWorkspace` (from `@micha.bigler/ui-core-micha/chat`) takes optional props for apps that put UI around the surface;
|
|
@@ -49,12 +49,20 @@ function UsageLimit({ usageLimit, t, language }) {
|
|
|
49
49
|
? _jsxs(_Fragment, { children: [_jsx(Typography, { variant: "caption", color: "text.secondary", children: t(`Chat.limitReached.${usageLimit.period}`) }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('Chat.limitResets', { date: resetDate }) })] })
|
|
50
50
|
: _jsx(Typography, { variant: "caption", color: "text.secondary", children: usageText }), _jsx(LinearProgress, { variant: "determinate", "aria-label": usageText, value: reached ? 100 : Math.min(100, (usageLimit.usedUsdMicros / usageLimit.limitUsdMicros) * 100), sx: CHAT_COMPOSER_USAGE_METER_SX })] });
|
|
51
51
|
}
|
|
52
|
-
export function ChatComposer({ value, onChange, onSend, onStop, running = false, archived = false, connected = true, inputRef, sx, actions, layout = 'standard', context, notice, usageLimit = null, draftRequest, onDraftRequestApplied }) {
|
|
52
|
+
export function ChatComposer({ value, onChange, onSend, onStop, onComposeStart, running = false, archived = false, connected = true, inputRef, sx, actions, layout = 'standard', context, notice, usageLimit = null, draftRequest, onDraftRequestApplied }) {
|
|
53
53
|
const { t, i18n } = useTranslation();
|
|
54
54
|
const [internalDraft, setInternalDraft] = React.useState('');
|
|
55
55
|
const appliedDraftRequest = React.useRef(undefined);
|
|
56
|
+
const focusSignalled = React.useRef(false);
|
|
57
|
+
const draftSignalled = React.useRef(false);
|
|
56
58
|
const controlled = value !== undefined;
|
|
57
59
|
const draft = controlled ? value : internalDraft;
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
if (draft === '') {
|
|
62
|
+
focusSignalled.current = false;
|
|
63
|
+
draftSignalled.current = false;
|
|
64
|
+
}
|
|
65
|
+
}, [draft]);
|
|
58
66
|
React.useLayoutEffect(() => {
|
|
59
67
|
if (controlled || !draftRequest || draftRequest.seq === appliedDraftRequest.current)
|
|
60
68
|
return;
|
|
@@ -66,17 +74,36 @@ export function ChatComposer({ value, onChange, onSend, onStop, running = false,
|
|
|
66
74
|
const blocked = archived || !connected || limitReached;
|
|
67
75
|
const language = typeof (i18n === null || i18n === void 0 ? void 0 : i18n.language) === 'string' ? i18n.language.split('_')[0] || undefined : undefined;
|
|
68
76
|
const canSend = !running && !blocked && draft.trim().length > 0;
|
|
69
|
-
const changeDraft = (next) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
const changeDraft = (next) => {
|
|
78
|
+
if (next === '') {
|
|
79
|
+
focusSignalled.current = false;
|
|
80
|
+
draftSignalled.current = false;
|
|
81
|
+
}
|
|
82
|
+
if (next !== '' && draft === '' && !draftSignalled.current) {
|
|
83
|
+
draftSignalled.current = true;
|
|
84
|
+
onComposeStart === null || onComposeStart === void 0 ? void 0 : onComposeStart();
|
|
85
|
+
}
|
|
86
|
+
if (controlled)
|
|
87
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(next);
|
|
88
|
+
else
|
|
89
|
+
setInternalDraft(next);
|
|
90
|
+
};
|
|
91
|
+
const handleFocus = () => {
|
|
92
|
+
if (!focusSignalled.current) {
|
|
93
|
+
focusSignalled.current = true;
|
|
94
|
+
onComposeStart === null || onComposeStart === void 0 ? void 0 : onComposeStart();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
73
97
|
const submit = () => {
|
|
74
98
|
if (!canSend)
|
|
75
99
|
return;
|
|
76
100
|
if (controlled)
|
|
77
101
|
onSend === null || onSend === void 0 ? void 0 : onSend();
|
|
78
|
-
else if ((onSend === null || onSend === void 0 ? void 0 : onSend(draft)) === true)
|
|
102
|
+
else if ((onSend === null || onSend === void 0 ? void 0 : onSend(draft)) === true) {
|
|
103
|
+
focusSignalled.current = false;
|
|
104
|
+
draftSignalled.current = false;
|
|
79
105
|
setInternalDraft('');
|
|
106
|
+
}
|
|
80
107
|
};
|
|
81
108
|
const handleKeyDown = (event) => {
|
|
82
109
|
var _a;
|
|
@@ -86,9 +113,9 @@ export function ChatComposer({ value, onChange, onSend, onStop, running = false,
|
|
|
86
113
|
}
|
|
87
114
|
};
|
|
88
115
|
if (layout === 'compact')
|
|
89
|
-
return (_jsxs(Stack, { sx: sx ? [CHAT_COMPOSER_COMPACT_ROOT_SX, sx] : CHAT_COMPOSER_COMPACT_ROOT_SX, children: [_jsx(CompactNotice, { notice: notice, t: t }), _jsx(UsageLimit, { usageLimit: usageLimit, t: t, language: language }), _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: draft, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onChange: (event) => changeDraft(event.target.value), onKeyDown: handleKeyDown }), running
|
|
116
|
+
return (_jsxs(Stack, { sx: sx ? [CHAT_COMPOSER_COMPACT_ROOT_SX, sx] : CHAT_COMPOSER_COMPACT_ROOT_SX, children: [_jsx(CompactNotice, { notice: notice, t: t }), _jsx(UsageLimit, { usageLimit: usageLimit, t: t, language: language }), _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: draft, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onFocus: handleFocus, onChange: (event) => changeDraft(event.target.value), onKeyDown: handleKeyDown }), running
|
|
90
117
|
? _jsx(IconButton, { "aria-label": t('Chat.stopAnswer'), title: t('Chat.stopAnswer'), sx: CHAT_COMPOSER_ACTION_SX, onClick: onStop, children: _jsx(StopIcon, {}) })
|
|
91
118
|
: _jsx(IconButton, { "aria-label": t('Chat.send'), sx: CHAT_COMPOSER_SEND_SX, onClick: submit, disabled: !canSend, children: _jsx(SendIcon, { fontSize: "small" }) })] })] }));
|
|
92
|
-
return (_jsxs(Stack, { direction: "row", alignItems: "flex-end", flexWrap: "wrap", gap: 1, sx: Object.assign(Object.assign({}, CHAT_COMPOSER_STANDARD_ROOT_SX), sx), children: [usageLimit ? _jsx(Stack, { flexBasis: "100%", children: _jsx(UsageLimit, { usageLimit: usageLimit, t: t, language: language }) }) : null, _jsx(TextField, { multiline: true, maxRows: 6, sx: CHAT_COMPOSER_INPUT_SX, size: "small", value: draft, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onChange: (event) => changeDraft(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') })] }));
|
|
119
|
+
return (_jsxs(Stack, { direction: "row", alignItems: "flex-end", flexWrap: "wrap", gap: 1, sx: Object.assign(Object.assign({}, CHAT_COMPOSER_STANDARD_ROOT_SX), sx), children: [usageLimit ? _jsx(Stack, { flexBasis: "100%", children: _jsx(UsageLimit, { usageLimit: usageLimit, t: t, language: language }) }) : null, _jsx(TextField, { multiline: true, maxRows: 6, sx: CHAT_COMPOSER_INPUT_SX, size: "small", value: draft, inputRef: inputRef, disabled: blocked, placeholder: t('Chat.message'), slotProps: { htmlInput: { 'aria-label': t('Chat.message') } }, onFocus: handleFocus, onChange: (event) => changeDraft(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') })] }));
|
|
93
120
|
}
|
|
94
121
|
export default ChatComposer;
|
package/dist/chat/ChatThread.js
CHANGED
|
@@ -52,7 +52,8 @@ export function ChatThread({ turns = [], tool = null, notice = null, hasOlder =
|
|
|
52
52
|
useEffect(() => { var _a, _b; if (pinned.current)
|
|
53
53
|
(_b = (_a = end.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView) === null || _b === void 0 ? void 0 : _b.call(_a, { block: 'end' }); }, [last === null || last === void 0 ? void 0 : last.id, last === null || last === void 0 ? void 0 : last.assistant_text, last === null || last === void 0 ? void 0 : last.state]);
|
|
54
54
|
// Turns skip layout off-screen (content-visibility, UCM-CHAT-14) and take their real height only once rendered, so the
|
|
55
|
-
// content can still grow after the scroll above. While pinned, follow that growth to stay at the bottom.
|
|
55
|
+
// content can still grow after the scroll above. While pinned, follow that growth to stay at the bottom. The scroll
|
|
56
|
+
// region itself is observed too: a thread mounted in a hidden host panel gets its real size only when shown.
|
|
56
57
|
const content = useRef(null);
|
|
57
58
|
useEffect(() => {
|
|
58
59
|
const el = scroller.current;
|
|
@@ -61,8 +62,12 @@ export function ChatThread({ turns = [], tool = null, notice = null, hasOlder =
|
|
|
61
62
|
const observer = new ResizeObserver(() => { if (pinned.current)
|
|
62
63
|
el.scrollTop = el.scrollHeight; });
|
|
63
64
|
observer.observe(content.current);
|
|
65
|
+
observer.observe(el);
|
|
64
66
|
return () => observer.disconnect();
|
|
65
67
|
}, []);
|
|
68
|
+
// Another chat opens at its bottom, whatever the reader did in the previous one; do not rely on the scroll event that
|
|
69
|
+
// emptying the thread may (or, in a background page, may not) produce.
|
|
70
|
+
useLayoutEffect(() => { pinned.current = true; }, [chat === null || chat === void 0 ? void 0 : chat.id]);
|
|
66
71
|
// Keep the reader's position when older turns are prepended.
|
|
67
72
|
useLayoutEffect(() => {
|
|
68
73
|
const el = scroller.current;
|
|
@@ -65,7 +65,7 @@ const appendDelta = (turns, text) => {
|
|
|
65
65
|
* `renderTurnError({ turn, chat, retry })` (optional failed-turn message; return `null` to show the default alert).
|
|
66
66
|
*/
|
|
67
67
|
export const CHAT_WORKSPACE_SIDE_PANEL_SX = { borderLeft: 1, borderColor: 'divider', minHeight: 0, overflow: 'auto', contain: 'strict' };
|
|
68
|
-
export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloadedChats, sx, unavailableReasonText, sidePanel, sidePanelLabel, renderAnswerExtra, renderTurnError, renderComposerExtra, composerLayout = 'standard', renderComposerContext, onAppFrame, onNavigate, activeChatId, onActiveChatChange, composerPrefill, getSendContext, sendRequest, onSendRequestHandled, layout = 'viewport', compactBelow = 720, tokenBalance = null, usageToTokens, longChatTokens = 40000 }) {
|
|
68
|
+
export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloadedChats, sx, unavailableReasonText, sidePanel, sidePanelLabel, renderAnswerExtra, renderTurnError, renderComposerExtra, composerLayout = 'standard', renderComposerContext, onAppFrame, onNavigate, activeChatId, onActiveChatChange, onComposeStart, composerPrefill, getSendContext, sendRequest, onSendRequestHandled, layout = 'viewport', compactBelow = 720, tokenBalance = null, usageToTokens, longChatTokens = 40000 }) {
|
|
69
69
|
var _a;
|
|
70
70
|
const { t } = useTranslation();
|
|
71
71
|
const theme = useTheme();
|
|
@@ -76,6 +76,10 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
76
76
|
const narrow = layout === 'compact' || (layout === 'container' ? containerNarrow : viewportNarrow);
|
|
77
77
|
const appFrameCallback = useRef(onAppFrame);
|
|
78
78
|
useEffect(() => { appFrameCallback.current = onAppFrame; }, [onAppFrame]);
|
|
79
|
+
const composeStartCallback = useRef(onComposeStart);
|
|
80
|
+
composeStartCallback.current = onComposeStart;
|
|
81
|
+
const composeChatRef = useRef(null);
|
|
82
|
+
const composeStart = useCallback(() => { var _a; return (_a = composeStartCallback.current) === null || _a === void 0 ? void 0 : _a.call(composeStartCallback, { chatId: composeChatRef.current }); }, []);
|
|
79
83
|
useEffect(() => {
|
|
80
84
|
if (layout !== 'container')
|
|
81
85
|
return undefined;
|
|
@@ -170,6 +174,13 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
170
174
|
}
|
|
171
175
|
}, [api]);
|
|
172
176
|
const shownChatId = useRef(null);
|
|
177
|
+
const generalCatalogueRequested = useRef(false);
|
|
178
|
+
const requestGeneralCatalogue = useCallback(() => {
|
|
179
|
+
if (generalCatalogueRequested.current)
|
|
180
|
+
return null;
|
|
181
|
+
generalCatalogueRequested.current = true;
|
|
182
|
+
return refreshCatalogue();
|
|
183
|
+
}, [refreshCatalogue]);
|
|
173
184
|
// Bumped on every scope change so that a list response of the previous scope is dropped.
|
|
174
185
|
const scopeVersion = useRef(0);
|
|
175
186
|
const limitRequest = useRef(0);
|
|
@@ -225,7 +236,9 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
225
236
|
? { results: offered.results, next: offered.next }
|
|
226
237
|
: undefined;
|
|
227
238
|
const statusRequest = Promise.resolve().then(() => (scope === undefined ? api.getStatus() : api.getStatus({ scope })));
|
|
228
|
-
const catalogueRequest =
|
|
239
|
+
const catalogueRequest = latestWantedId.current == null
|
|
240
|
+
? Promise.resolve().then(() => requestGeneralCatalogue())
|
|
241
|
+
: Promise.resolve(null);
|
|
229
242
|
const listsRequest = Promise.resolve().then(() => loadLists({ initial: true, preloaded }));
|
|
230
243
|
// These may finish after an unavailable status; attach rejection handlers immediately and never expose their answers.
|
|
231
244
|
catalogueRequest.catch(() => { });
|
|
@@ -240,11 +253,10 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
240
253
|
return;
|
|
241
254
|
}
|
|
242
255
|
refreshLimit();
|
|
243
|
-
Promise.all([catalogueRequest, listsRequest]).then(([
|
|
256
|
+
Promise.all([catalogueRequest, listsRequest]).then(([, lists]) => {
|
|
244
257
|
if (!live || lists === undefined)
|
|
245
258
|
return;
|
|
246
259
|
const { active, old } = lists;
|
|
247
|
-
setCatalogue(entries);
|
|
248
260
|
setChats(active.results || []);
|
|
249
261
|
setNextChats(active.next || null);
|
|
250
262
|
setArchived(old.results || []);
|
|
@@ -257,9 +269,19 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
257
269
|
.catch(() => { if (live)
|
|
258
270
|
setStatus('error'); });
|
|
259
271
|
return () => { live = false; };
|
|
260
|
-
}, [api, loadLists, refreshLimit, scope]);
|
|
261
|
-
|
|
262
|
-
|
|
272
|
+
}, [api, loadLists, refreshLimit, requestGeneralCatalogue, scope]);
|
|
273
|
+
// Once a chat was shown, closing it needs the general catalogue again (also when that chat's own request failed);
|
|
274
|
+
// before any chat was shown, the start effect has already decided about the general request.
|
|
275
|
+
const chatWasShown = useRef(false);
|
|
276
|
+
useEffect(() => {
|
|
277
|
+
if ((chat === null || chat === void 0 ? void 0 : chat.id) !== undefined) {
|
|
278
|
+
chatWasShown.current = true;
|
|
279
|
+
generalCatalogueRequested.current = false;
|
|
280
|
+
refreshCatalogue(chat.id);
|
|
281
|
+
}
|
|
282
|
+
else if (!generalCatalogueRequested.current && chatWasShown.current)
|
|
283
|
+
requestGeneralCatalogue();
|
|
284
|
+
}, [chat === null || chat === void 0 ? void 0 : chat.id, refreshCatalogue, requestGeneralCatalogue]);
|
|
263
285
|
useEffect(() => { if (pickerOpen)
|
|
264
286
|
refreshCatalogue(chat === null || chat === void 0 ? void 0 : chat.id); }, [pickerOpen]);
|
|
265
287
|
useEffect(() => {
|
|
@@ -296,22 +318,26 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
296
318
|
if (!live || loaded === undefined || latestWantedId.current === undefined || String(latestWantedId.current) !== wantedKey)
|
|
297
319
|
return;
|
|
298
320
|
const found = loaded.all.find((item) => String(item.id) === wantedKey);
|
|
299
|
-
if (!found)
|
|
321
|
+
if (!found) {
|
|
300
322
|
unloadableIds.current.add(wantedKey);
|
|
323
|
+
requestGeneralCatalogue();
|
|
324
|
+
}
|
|
301
325
|
setChat(found || null);
|
|
302
326
|
}).catch(() => {
|
|
303
327
|
if (live && latestWantedId.current !== undefined && String(latestWantedId.current) === wantedKey) {
|
|
304
328
|
unloadableIds.current.add(wantedKey);
|
|
329
|
+
requestGeneralCatalogue();
|
|
305
330
|
setChat(null);
|
|
306
331
|
}
|
|
307
332
|
});
|
|
308
333
|
return () => { live = false; };
|
|
309
|
-
}, [activeChatId, status, listsLoaded]);
|
|
334
|
+
}, [activeChatId, status, listsLoaded, requestGeneralCatalogue]);
|
|
310
335
|
// Clear the previous chat's content before the browser paints, so a host-driven switch never flashes it under the new title.
|
|
311
336
|
useLayoutEffect(() => {
|
|
312
|
-
var _a;
|
|
337
|
+
var _a, _b;
|
|
313
338
|
connectedChatId.current = null; // the socket of the new chat has not opened yet
|
|
314
339
|
shownChatId.current = (_a = chat === null || chat === void 0 ? void 0 : chat.id) !== null && _a !== void 0 ? _a : null;
|
|
340
|
+
composeChatRef.current = (_b = chat === null || chat === void 0 ? void 0 : chat.id) !== null && _b !== void 0 ? _b : null;
|
|
315
341
|
setTurns([]);
|
|
316
342
|
setOlderCursor(null);
|
|
317
343
|
setTool(null);
|
|
@@ -583,7 +609,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
|
|
|
583
609
|
if (unavailable) {
|
|
584
610
|
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') }) }));
|
|
585
611
|
}
|
|
586
|
-
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, renderTurnError: renderTurnError, tool: tool, notice: noticeFor(), hasOlder: Boolean(olderCursor), olderBusy: olderBusy, onLoadOlder: loadOlder, onRetry: retry, readOnly: isArchived, summary: summary, usageToTokens: usageToTokens, onNavigate: onNavigate }), 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`) ? {
|
|
612
|
+
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, renderTurnError: renderTurnError, tool: tool, notice: noticeFor(), hasOlder: Boolean(olderCursor), olderBusy: olderBusy, onLoadOlder: loadOlder, onRetry: retry, readOnly: isArchived, summary: summary, usageToTokens: usageToTokens, onNavigate: onNavigate }), 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`) ? {
|
|
587
613
|
id: 'long-chat', text: t('Chat.longChatShort'), action: t('Chat.newChat'), onAction: createChat,
|
|
588
614
|
onDismiss: () => setDismissedComposerNotices((current) => new Set(current).add(`${chat.id}:long-chat`)),
|
|
589
615
|
} : 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] }));
|