@micha.bigler/ui-core-micha 4.18.0 → 4.19.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 +9 -0
- package/README.md +4 -1
- package/dist/chat/ChatWorkspace.js +47 -22
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.19.0 - UCM-CHAT-8
|
|
4
|
+
|
|
5
|
+
`ChatWorkspace` starts the status, catalogue and both chat-list requests together on mount and on every scope change,
|
|
6
|
+
instead of waiting for the status first; when the status is not `available` (or fails) the other answers are discarded
|
|
7
|
+
and the unavailable or error state is shown as before. New optional prop `preloadedChats` (`{ scope, results, next }`):
|
|
8
|
+
an active list the app already loaded for the same `scope` replaces the active-list request at the start; the archived
|
|
9
|
+
list is still requested, and later reloads are unchanged. Every consumer now sends catalogue and list requests also when
|
|
10
|
+
the assistant is not configured.
|
|
11
|
+
|
|
3
12
|
## 4.18.0 - UCM-BILL-10
|
|
4
13
|
|
|
5
14
|
`AccountPage` accepts an optional `billingOperator({ user, account }) => boolean` and passes it as the operator rule to
|
package/README.md
CHANGED
|
@@ -169,7 +169,10 @@ above the composer. Without `composerLayout` the composer is unchanged. `ChatCom
|
|
|
169
169
|
|
|
170
170
|
`ChatWorkspace` (from `@micha.bigler/ui-core-micha/chat`) takes optional props for apps that put UI around the surface;
|
|
171
171
|
without them it behaves as before. Each is described in `CHANGELOG.md` under the release that added it.
|
|
172
|
-
Since 4.
|
|
172
|
+
Since 4.19.0: `preloadedChats` (`{ scope, results, next }`, the active-list response the app already loaded for that
|
|
173
|
+
`scope`): the start then requests only the archived list. It is used once, at the start, and only when its `scope`
|
|
174
|
+
equals the workspace's `scope`; later reloads request both lists as before. The start requests status, catalogue and
|
|
175
|
+
both lists together; when the status is not available their answers are discarded. Since 4.3.0: `getSendContext()` (a plain object attached as `context` to every `send` frame, read by
|
|
173
176
|
`django-core-micha` 3.3.0), `sendRequest` (`{ id, text }`, sends a message on the host's behalf) and
|
|
174
177
|
`onSendRequestHandled({ id, sent })`. Since 4.2.0: `activeChatId`, `onActiveChatChange`, `composerPrefill` and
|
|
175
178
|
`send(text)` / `canSend` in `renderAnswerExtra`.
|
|
@@ -60,9 +60,10 @@ const appendDelta = (turns, text) => {
|
|
|
60
60
|
* The complete chat surface: chat list, thread, composer and model picker for one user.
|
|
61
61
|
*
|
|
62
62
|
* Props: `apiBase` and `wsUrl` (where the app mounted the chat routes), `api` (partial overrides of the REST
|
|
63
|
-
* calls; every function not given keeps its default), `scope` (passed when creating a chat),
|
|
63
|
+
* calls; every function not given keeps its default), `scope` (passed when creating a chat),
|
|
64
|
+
* `preloadedChats` (optional active-list response `{ scope, results, next }` already loaded for that exact scope), `sx`.
|
|
64
65
|
*/
|
|
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
|
+
export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloadedChats, 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
67
|
var _a;
|
|
67
68
|
const { t } = useTranslation();
|
|
68
69
|
const theme = useTheme();
|
|
@@ -165,37 +166,61 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, sx, un
|
|
|
165
166
|
// Bumped on every scope change so that a list response of the previous scope is dropped.
|
|
166
167
|
const scopeVersion = useRef(0);
|
|
167
168
|
useEffect(() => { scopeVersion.current += 1; setChat(null); setListsLoaded(false); appliedId.current = undefined; unloadableIds.current.clear(); }, [scope]);
|
|
168
|
-
const loadLists = useCallback(async () => {
|
|
169
|
+
const loadLists = useCallback(async ({ initial = false, preloaded } = {}) => {
|
|
169
170
|
const version = scopeVersion.current;
|
|
170
171
|
// Without a scope the api is called exactly as before the scope existed.
|
|
171
|
-
const
|
|
172
|
-
?
|
|
173
|
-
:
|
|
172
|
+
const activeRequest = preloaded === undefined
|
|
173
|
+
? (scope === undefined ? api.listChats() : api.listChats({ scope }))
|
|
174
|
+
: Promise.resolve(preloaded);
|
|
175
|
+
const archivedRequest = scope === undefined ? api.listChats({ archived: true }) : api.listChats({ scope, archived: true });
|
|
176
|
+
const [active, old] = await Promise.all([activeRequest, archivedRequest]);
|
|
174
177
|
if (version !== scopeVersion.current)
|
|
175
178
|
return undefined;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
if (!initial) {
|
|
180
|
+
setChats(active.results || []);
|
|
181
|
+
setNextChats(active.next || null);
|
|
182
|
+
setArchived(old.results || []);
|
|
183
|
+
}
|
|
184
|
+
return { active, old, all: [...(active.results || []), ...(old.results || [])] };
|
|
180
185
|
}, [api, scope]);
|
|
186
|
+
// Read through a ref: the preloaded list only matters when a start begins, and an inline object from the app must
|
|
187
|
+
// not restart the start requests on every render.
|
|
188
|
+
const preloadedChatsRef = useRef(preloadedChats);
|
|
189
|
+
preloadedChatsRef.current = preloadedChats;
|
|
181
190
|
useEffect(() => {
|
|
182
191
|
let live = true;
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
.
|
|
192
|
+
const offered = preloadedChatsRef.current;
|
|
193
|
+
const preloaded = offered && offered.scope === scope
|
|
194
|
+
? { results: offered.results, next: offered.next }
|
|
195
|
+
: undefined;
|
|
196
|
+
const statusRequest = Promise.resolve().then(() => (scope === undefined ? api.getStatus() : api.getStatus({ scope })));
|
|
197
|
+
const catalogueRequest = Promise.resolve().then(() => api.getCatalogue());
|
|
198
|
+
const listsRequest = Promise.resolve().then(() => loadLists({ initial: true, preloaded }));
|
|
199
|
+
// These may finish after an unavailable status; attach rejection handlers immediately and never expose their answers.
|
|
200
|
+
catalogueRequest.catch(() => { });
|
|
201
|
+
listsRequest.catch(() => { });
|
|
202
|
+
statusRequest
|
|
203
|
+
.then((state) => {
|
|
204
|
+
if (!live)
|
|
205
|
+
return;
|
|
186
206
|
if (state.status !== 'available') {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
setUnavailableReason(state.reason || null);
|
|
190
|
-
}
|
|
207
|
+
setStatus(state.status);
|
|
208
|
+
setUnavailableReason(state.reason || null);
|
|
191
209
|
return;
|
|
192
210
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
211
|
+
Promise.all([catalogueRequest, listsRequest]).then(([entries, lists]) => {
|
|
212
|
+
if (!live || lists === undefined)
|
|
213
|
+
return;
|
|
214
|
+
const { active, old } = lists;
|
|
196
215
|
setCatalogue(entries);
|
|
216
|
+
setChats(active.results || []);
|
|
217
|
+
setNextChats(active.next || null);
|
|
218
|
+
setArchived(old.results || []);
|
|
219
|
+
setStatus(state.status);
|
|
197
220
|
setListsLoaded(true);
|
|
198
|
-
|
|
221
|
+
setUnavailableReason(null);
|
|
222
|
+
}).catch(() => { if (live)
|
|
223
|
+
setStatus('error'); });
|
|
199
224
|
})
|
|
200
225
|
.catch(() => { if (live)
|
|
201
226
|
setStatus('error'); });
|
|
@@ -238,7 +263,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, sx, un
|
|
|
238
263
|
loadLists().then((loaded) => {
|
|
239
264
|
if (!live || loaded === undefined || latestWantedId.current === undefined || String(latestWantedId.current) !== wantedKey)
|
|
240
265
|
return;
|
|
241
|
-
const found = loaded.find((item) => String(item.id) === wantedKey);
|
|
266
|
+
const found = loaded.all.find((item) => String(item.id) === wantedKey);
|
|
242
267
|
if (!found)
|
|
243
268
|
unloadableIds.current.add(wantedKey);
|
|
244
269
|
setChat(found || null);
|