@sybilion/uilib 1.4.31 → 1.4.32
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.
|
@@ -5,6 +5,7 @@ import { isGraphIntakeAssistantStepComplete, matchUserTextToQuickReply, isPreset
|
|
|
5
5
|
import { loadingLabelFromSendPayload, displayTextFromSendPayload, buildChatSendMessagePayload } from '../buildChatSendMessagePayload.js';
|
|
6
6
|
import { usedPresetIdsFromMessages } from '../chat-preset-utils.js';
|
|
7
7
|
import { useChatsForScopeId, useChat, useChatOutboundPending, useSyncChatPanelBusy, isChatEmpty } from '../../../../contexts/chat-context.js';
|
|
8
|
+
import { loadScopeIndex } from '../../../../contexts/chatSessionStorage.js';
|
|
8
9
|
import { shellFitsSidebarsLayout } from '../../../../hooks/panelWidth.js';
|
|
9
10
|
import useEvent from '../../../../hooks/useEvent.js';
|
|
10
11
|
import { useIsMobile } from '../../../../hooks/useIsMobile.js';
|
|
@@ -60,7 +61,7 @@ function useChatPanelChromeModel({ embedAsPage, presets, scopeId, onMessage, onS
|
|
|
60
61
|
const { setOpen: setSidebarNavOpen, setChatWidthPx, getShellWidth, setChatPanelOpen, } = useSidebarActions();
|
|
61
62
|
const [localUiBusy, setLocalUiBusy] = useState(false);
|
|
62
63
|
const [outboundLoadingLabel, setOutboundLoadingLabel] = useState();
|
|
63
|
-
const { chats, currentChatId, setCurrentChatId, newChat, sendMessage, addMessage, removeMessageById, } = useChatsForScopeId(effectiveScopeId);
|
|
64
|
+
const { chats, currentChatId, setCurrentChatId, newChat, linkSessionToScope, sendMessage, addMessage, removeMessageById, } = useChatsForScopeId(effectiveScopeId);
|
|
64
65
|
const chat = useChat(effectiveScopeId, currentChatId);
|
|
65
66
|
const isOutboundPending = useChatOutboundPending(effectiveScopeId, currentChatId);
|
|
66
67
|
const isLoading = isOutboundPending || localUiBusy;
|
|
@@ -90,11 +91,24 @@ function useChatPanelChromeModel({ embedAsPage, presets, scopeId, onMessage, onS
|
|
|
90
91
|
return;
|
|
91
92
|
if (chats.length > 0) {
|
|
92
93
|
setCurrentChatId(chats[0].session_id);
|
|
94
|
+
return;
|
|
93
95
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
const index = loadScopeIndex(effectiveScopeId);
|
|
97
|
+
const persistedSessionId = index?.currentSessionId ?? index?.sessionIds[0] ?? null;
|
|
98
|
+
if (persistedSessionId) {
|
|
99
|
+
linkSessionToScope(persistedSessionId);
|
|
100
|
+
return;
|
|
96
101
|
}
|
|
97
|
-
|
|
102
|
+
newChat();
|
|
103
|
+
}, [
|
|
104
|
+
panelActive,
|
|
105
|
+
currentChatId,
|
|
106
|
+
chats,
|
|
107
|
+
effectiveScopeId,
|
|
108
|
+
setCurrentChatId,
|
|
109
|
+
linkSessionToScope,
|
|
110
|
+
newChat,
|
|
111
|
+
]);
|
|
98
112
|
const [scriptByChatId, setScriptByChatId] = useState({});
|
|
99
113
|
/** Local demo: `[Label]` in assistant text → next assistant body from map. */
|
|
100
114
|
const [quickReplyBranchesByChat, setQuickReplyBranchesByChat] = useState({});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { createContext, useState, useCallback,
|
|
2
|
+
import { createContext, useState, useCallback, useLayoutEffect, useContext, useMemo, useEffect } from 'react';
|
|
3
3
|
import { MessageRole } from '../components/ui/Chat/Chat.types.js';
|
|
4
4
|
import { normalizeUserTextFileAttachments } from '../components/ui/Chat/buildChatSendMessagePayload.js';
|
|
5
5
|
import { normalizeJsonDashboardChatText, stripJsonDashboardFences } from '../lib/dashboard-spec/jsonDashboardFence.js';
|
|
@@ -363,7 +363,9 @@ function ChatProvider({ children, userSwitchKey, sendChatMessage: sendChatMessag
|
|
|
363
363
|
setCurrentChatId,
|
|
364
364
|
userSwitchKey,
|
|
365
365
|
]);
|
|
366
|
-
useEffect
|
|
366
|
+
// Layout effect so LS hydration finishes before child `useEffect` hooks that
|
|
367
|
+
// may call `newChat()` when `?chat=open` opens the panel on first mount.
|
|
368
|
+
useLayoutEffect(() => {
|
|
367
369
|
if (userSwitchKey === null) {
|
|
368
370
|
setChats({});
|
|
369
371
|
setCurrentChatIdState({});
|
package/package.json
CHANGED
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
useChatsForScopeId,
|
|
41
41
|
useSyncChatPanelBusy,
|
|
42
42
|
} from '#uilib/contexts/chat-context';
|
|
43
|
+
import { loadScopeIndex } from '#uilib/contexts/chatSessionStorage';
|
|
43
44
|
import { shellFitsSidebarsLayout } from '#uilib/hooks/panelWidth';
|
|
44
45
|
import useEvent from '#uilib/hooks/useEvent';
|
|
45
46
|
import { useIsMobile } from '#uilib/hooks/useIsMobile';
|
|
@@ -204,6 +205,7 @@ export function useChatPanelChromeModel({
|
|
|
204
205
|
currentChatId,
|
|
205
206
|
setCurrentChatId,
|
|
206
207
|
newChat,
|
|
208
|
+
linkSessionToScope,
|
|
207
209
|
sendMessage,
|
|
208
210
|
addMessage,
|
|
209
211
|
removeMessageById,
|
|
@@ -253,10 +255,27 @@ export function useChatPanelChromeModel({
|
|
|
253
255
|
|
|
254
256
|
if (chats.length > 0) {
|
|
255
257
|
setCurrentChatId(chats[0].session_id);
|
|
256
|
-
|
|
257
|
-
newChat();
|
|
258
|
+
return;
|
|
258
259
|
}
|
|
259
|
-
|
|
260
|
+
|
|
261
|
+
const index = loadScopeIndex(effectiveScopeId);
|
|
262
|
+
const persistedSessionId =
|
|
263
|
+
index?.currentSessionId ?? index?.sessionIds[0] ?? null;
|
|
264
|
+
if (persistedSessionId) {
|
|
265
|
+
linkSessionToScope(persistedSessionId);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
newChat();
|
|
270
|
+
}, [
|
|
271
|
+
panelActive,
|
|
272
|
+
currentChatId,
|
|
273
|
+
chats,
|
|
274
|
+
effectiveScopeId,
|
|
275
|
+
setCurrentChatId,
|
|
276
|
+
linkSessionToScope,
|
|
277
|
+
newChat,
|
|
278
|
+
]);
|
|
260
279
|
const [scriptByChatId, setScriptByChatId] = useState<
|
|
261
280
|
Record<string, PresetScriptState>
|
|
262
281
|
>({});
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
useCallback,
|
|
5
5
|
useContext,
|
|
6
6
|
useEffect,
|
|
7
|
+
useLayoutEffect,
|
|
7
8
|
useMemo,
|
|
8
9
|
useState,
|
|
9
10
|
} from 'react';
|
|
@@ -651,7 +652,9 @@ export function ChatProvider({
|
|
|
651
652
|
],
|
|
652
653
|
);
|
|
653
654
|
|
|
654
|
-
useEffect
|
|
655
|
+
// Layout effect so LS hydration finishes before child `useEffect` hooks that
|
|
656
|
+
// may call `newChat()` when `?chat=open` opens the panel on first mount.
|
|
657
|
+
useLayoutEffect(() => {
|
|
655
658
|
if (userSwitchKey === null) {
|
|
656
659
|
setChats({});
|
|
657
660
|
setCurrentChatIdState({});
|