@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.d.cts
CHANGED
|
@@ -544,7 +544,7 @@ interface UseChatOptions {
|
|
|
544
544
|
onToolCall?: (toolCall: ToolCallEvent) => void;
|
|
545
545
|
onRestoredConversation?: (conversationId: string) => void;
|
|
546
546
|
}
|
|
547
|
-
declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
|
|
547
|
+
declare function useChat({ productId, apiUrl, persistAnonymousConversations: _persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
|
|
548
548
|
messages: Message[];
|
|
549
549
|
isLoading: boolean;
|
|
550
550
|
activeToolCalls: ToolCall[];
|
package/dist/index.d.ts
CHANGED
|
@@ -544,7 +544,7 @@ interface UseChatOptions {
|
|
|
544
544
|
onToolCall?: (toolCall: ToolCallEvent) => void;
|
|
545
545
|
onRestoredConversation?: (conversationId: string) => void;
|
|
546
546
|
}
|
|
547
|
-
declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
|
|
547
|
+
declare function useChat({ productId, apiUrl, persistAnonymousConversations: _persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
|
|
548
548
|
messages: Message[];
|
|
549
549
|
isLoading: boolean;
|
|
550
550
|
activeToolCalls: ToolCall[];
|
package/dist/index.js
CHANGED
|
@@ -42,11 +42,10 @@ var MESSAGES_CONTAINER_ID = "crow-messages-container";
|
|
|
42
42
|
|
|
43
43
|
// src/hooks/useChat.ts
|
|
44
44
|
var getConversationStorageKey = (productId) => `crow_conv_${productId}`;
|
|
45
|
-
var inMemoryConversations = {};
|
|
46
45
|
function useChat({
|
|
47
46
|
productId,
|
|
48
47
|
apiUrl = "",
|
|
49
|
-
persistAnonymousConversations,
|
|
48
|
+
persistAnonymousConversations: _persistAnonymousConversations,
|
|
50
49
|
welcomeMessage,
|
|
51
50
|
onVerificationStatus,
|
|
52
51
|
onConversationId,
|
|
@@ -65,10 +64,16 @@ function useChat({
|
|
|
65
64
|
]);
|
|
66
65
|
const [isLoading, setIsLoading] = useState(false);
|
|
67
66
|
const [activeToolCalls, setActiveToolCalls] = useState([]);
|
|
68
|
-
const [conversationId, setConversationId] = useState(
|
|
67
|
+
const [conversationId, setConversationId] = useState(() => {
|
|
68
|
+
try {
|
|
69
|
+
return localStorage.getItem(getConversationStorageKey(productId));
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
69
74
|
const [selectedModel, setSelectedModel] = useState(DEFAULT_MODEL);
|
|
70
75
|
const abortControllerRef = useRef(null);
|
|
71
|
-
const
|
|
76
|
+
const hasRestoredRef = useRef(false);
|
|
72
77
|
useEffect(() => {
|
|
73
78
|
if (messages.length === 1 && messages[0].id === "welcome" && !conversationId) {
|
|
74
79
|
setMessages([
|
|
@@ -82,28 +87,11 @@ function useChat({
|
|
|
82
87
|
}
|
|
83
88
|
}, [effectiveWelcomeMessage]);
|
|
84
89
|
useEffect(() => {
|
|
85
|
-
if (
|
|
86
|
-
|
|
90
|
+
if (conversationId && onRestoredConversation && !hasRestoredRef.current) {
|
|
91
|
+
hasRestoredRef.current = true;
|
|
92
|
+
onRestoredConversation(conversationId);
|
|
87
93
|
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
if (persistAnonymousConversations) {
|
|
91
|
-
const convId = localStorage.getItem(getConversationStorageKey(productId));
|
|
92
|
-
if (convId) {
|
|
93
|
-
setConversationId(convId);
|
|
94
|
-
onRestoredConversation?.(convId);
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
const convId = inMemoryConversations[productId];
|
|
98
|
-
if (convId) {
|
|
99
|
-
setConversationId(convId);
|
|
100
|
-
onRestoredConversation?.(convId);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
} catch (e) {
|
|
104
|
-
console.error("[Crow] Error initializing conversation:", e);
|
|
105
|
-
}
|
|
106
|
-
}, [persistAnonymousConversations, productId, onRestoredConversation]);
|
|
94
|
+
}, []);
|
|
107
95
|
const streamFromBackend = useCallback(
|
|
108
96
|
async (message, botMsgId) => {
|
|
109
97
|
let accumulatedText = "";
|
|
@@ -161,16 +149,12 @@ function useChat({
|
|
|
161
149
|
case "conversation_id":
|
|
162
150
|
if (parsed.conversation_id) {
|
|
163
151
|
setConversationId(parsed.conversation_id);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
} catch {
|
|
171
|
-
}
|
|
172
|
-
} else {
|
|
173
|
-
inMemoryConversations[productId] = parsed.conversation_id;
|
|
152
|
+
try {
|
|
153
|
+
localStorage.setItem(
|
|
154
|
+
getConversationStorageKey(productId),
|
|
155
|
+
parsed.conversation_id
|
|
156
|
+
);
|
|
157
|
+
} catch {
|
|
174
158
|
}
|
|
175
159
|
onConversationId?.(parsed.conversation_id);
|
|
176
160
|
}
|
|
@@ -308,7 +292,7 @@ function useChat({
|
|
|
308
292
|
abortControllerRef.current = null;
|
|
309
293
|
}
|
|
310
294
|
},
|
|
311
|
-
[apiUrl, productId, conversationId, selectedModel,
|
|
295
|
+
[apiUrl, productId, conversationId, selectedModel, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall]
|
|
312
296
|
);
|
|
313
297
|
const sendMessage = useCallback(
|
|
314
298
|
(content) => {
|
|
@@ -358,7 +342,6 @@ function useChat({
|
|
|
358
342
|
}
|
|
359
343
|
]);
|
|
360
344
|
setConversationId(null);
|
|
361
|
-
delete inMemoryConversations[productId];
|
|
362
345
|
try {
|
|
363
346
|
localStorage.removeItem(getConversationStorageKey(productId));
|
|
364
347
|
} catch {
|