@usecrow/ui 0.1.58 → 0.1.59
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 +14 -3
- 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 +14 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -937,18 +937,21 @@ function useConversations({ productId, apiUrl = "" }) {
|
|
|
937
937
|
const [isLoadingHistory, setIsLoadingHistory] = React3.useState(false);
|
|
938
938
|
const loadConversations = React3.useCallback(async () => {
|
|
939
939
|
const token = window.__crow_identity_token;
|
|
940
|
-
if (!token) return;
|
|
940
|
+
if (!token) return [];
|
|
941
941
|
try {
|
|
942
942
|
const res = await fetch(
|
|
943
943
|
`${apiUrl}/api/chat/conversations?product_id=${productId}&identity_token=${encodeURIComponent(token)}`
|
|
944
944
|
);
|
|
945
945
|
if (res.ok) {
|
|
946
946
|
const data = await res.json();
|
|
947
|
-
|
|
947
|
+
const convs = data.conversations || [];
|
|
948
|
+
setConversations(convs);
|
|
949
|
+
return convs;
|
|
948
950
|
}
|
|
949
951
|
} catch (error) {
|
|
950
952
|
console.error("[Crow] Failed to load conversations:", error);
|
|
951
953
|
}
|
|
954
|
+
return [];
|
|
952
955
|
}, [apiUrl, productId]);
|
|
953
956
|
const loadConversationHistory = React3.useCallback(
|
|
954
957
|
async (conversationId) => {
|
|
@@ -4024,7 +4027,15 @@ function CrowWidget({
|
|
|
4024
4027
|
const { executeClientTool } = useCrowAPI({
|
|
4025
4028
|
onIdentified: async () => {
|
|
4026
4029
|
setIsVerifiedUser(true);
|
|
4027
|
-
await conversations.loadConversations();
|
|
4030
|
+
const convs = await conversations.loadConversations();
|
|
4031
|
+
if (convs.length > 0) {
|
|
4032
|
+
const mostRecent = convs[0];
|
|
4033
|
+
const historyMessages = await conversations.loadConversationHistory(mostRecent.id);
|
|
4034
|
+
if (historyMessages.length > 0) {
|
|
4035
|
+
chat.loadMessages(historyMessages);
|
|
4036
|
+
chat.setConversationId(mostRecent.id);
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4028
4039
|
},
|
|
4029
4040
|
onReset: () => {
|
|
4030
4041
|
setIsVerifiedUser(false);
|