@usecrow/ui 0.1.16 → 0.1.17
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/dist/index.cjs +20 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -37
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -68,11 +68,10 @@ var MESSAGES_CONTAINER_ID = "crow-messages-container";
|
|
|
68
68
|
|
|
69
69
|
// src/hooks/useChat.ts
|
|
70
70
|
var getConversationStorageKey = (productId) => `crow_conv_${productId}`;
|
|
71
|
-
var inMemoryConversations = {};
|
|
72
71
|
function useChat({
|
|
73
72
|
productId,
|
|
74
73
|
apiUrl = "",
|
|
75
|
-
persistAnonymousConversations,
|
|
74
|
+
persistAnonymousConversations: _persistAnonymousConversations,
|
|
76
75
|
welcomeMessage,
|
|
77
76
|
onVerificationStatus,
|
|
78
77
|
onConversationId,
|
|
@@ -91,10 +90,16 @@ function useChat({
|
|
|
91
90
|
]);
|
|
92
91
|
const [isLoading, setIsLoading] = React3.useState(false);
|
|
93
92
|
const [activeToolCalls, setActiveToolCalls] = React3.useState([]);
|
|
94
|
-
const [conversationId, setConversationId] = React3.useState(
|
|
93
|
+
const [conversationId, setConversationId] = React3.useState(() => {
|
|
94
|
+
try {
|
|
95
|
+
return localStorage.getItem(getConversationStorageKey(productId));
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
95
100
|
const [selectedModel, setSelectedModel] = React3.useState(DEFAULT_MODEL);
|
|
96
101
|
const abortControllerRef = React3.useRef(null);
|
|
97
|
-
const
|
|
102
|
+
const hasRestoredRef = React3.useRef(false);
|
|
98
103
|
React3.useEffect(() => {
|
|
99
104
|
if (messages.length === 1 && messages[0].id === "welcome" && !conversationId) {
|
|
100
105
|
setMessages([
|
|
@@ -108,28 +113,11 @@ function useChat({
|
|
|
108
113
|
}
|
|
109
114
|
}, [effectiveWelcomeMessage]);
|
|
110
115
|
React3.useEffect(() => {
|
|
111
|
-
if (
|
|
112
|
-
|
|
116
|
+
if (conversationId && onRestoredConversation && !hasRestoredRef.current) {
|
|
117
|
+
hasRestoredRef.current = true;
|
|
118
|
+
onRestoredConversation(conversationId);
|
|
113
119
|
}
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
if (persistAnonymousConversations) {
|
|
117
|
-
const convId = localStorage.getItem(getConversationStorageKey(productId));
|
|
118
|
-
if (convId) {
|
|
119
|
-
setConversationId(convId);
|
|
120
|
-
onRestoredConversation?.(convId);
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
const convId = inMemoryConversations[productId];
|
|
124
|
-
if (convId) {
|
|
125
|
-
setConversationId(convId);
|
|
126
|
-
onRestoredConversation?.(convId);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
} catch (e) {
|
|
130
|
-
console.error("[Crow] Error initializing conversation:", e);
|
|
131
|
-
}
|
|
132
|
-
}, [persistAnonymousConversations, productId, onRestoredConversation]);
|
|
120
|
+
}, []);
|
|
133
121
|
const streamFromBackend = React3.useCallback(
|
|
134
122
|
async (message, botMsgId) => {
|
|
135
123
|
let accumulatedText = "";
|
|
@@ -187,16 +175,12 @@ function useChat({
|
|
|
187
175
|
case "conversation_id":
|
|
188
176
|
if (parsed.conversation_id) {
|
|
189
177
|
setConversationId(parsed.conversation_id);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
} catch {
|
|
197
|
-
}
|
|
198
|
-
} else {
|
|
199
|
-
inMemoryConversations[productId] = parsed.conversation_id;
|
|
178
|
+
try {
|
|
179
|
+
localStorage.setItem(
|
|
180
|
+
getConversationStorageKey(productId),
|
|
181
|
+
parsed.conversation_id
|
|
182
|
+
);
|
|
183
|
+
} catch {
|
|
200
184
|
}
|
|
201
185
|
onConversationId?.(parsed.conversation_id);
|
|
202
186
|
}
|
|
@@ -334,7 +318,7 @@ function useChat({
|
|
|
334
318
|
abortControllerRef.current = null;
|
|
335
319
|
}
|
|
336
320
|
},
|
|
337
|
-
[apiUrl, productId, conversationId, selectedModel,
|
|
321
|
+
[apiUrl, productId, conversationId, selectedModel, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall]
|
|
338
322
|
);
|
|
339
323
|
const sendMessage = React3.useCallback(
|
|
340
324
|
(content) => {
|
|
@@ -384,7 +368,6 @@ function useChat({
|
|
|
384
368
|
}
|
|
385
369
|
]);
|
|
386
370
|
setConversationId(null);
|
|
387
|
-
delete inMemoryConversations[productId];
|
|
388
371
|
try {
|
|
389
372
|
localStorage.removeItem(getConversationStorageKey(productId));
|
|
390
373
|
} catch {
|