@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.d.cts CHANGED
@@ -720,7 +720,7 @@ interface UseConversationsOptions {
720
720
  declare function useConversations({ productId, apiUrl }: UseConversationsOptions): {
721
721
  conversations: Conversation[];
722
722
  isLoadingHistory: boolean;
723
- loadConversations: () => Promise<void>;
723
+ loadConversations: () => Promise<Conversation[]>;
724
724
  loadConversationHistory: (conversationId: string) => Promise<Message[]>;
725
725
  loadAnonymousConversationHistory: (conversationId: string) => Promise<Message[]>;
726
726
  };
package/dist/index.d.ts CHANGED
@@ -720,7 +720,7 @@ interface UseConversationsOptions {
720
720
  declare function useConversations({ productId, apiUrl }: UseConversationsOptions): {
721
721
  conversations: Conversation[];
722
722
  isLoadingHistory: boolean;
723
- loadConversations: () => Promise<void>;
723
+ loadConversations: () => Promise<Conversation[]>;
724
724
  loadConversationHistory: (conversationId: string) => Promise<Message[]>;
725
725
  loadAnonymousConversationHistory: (conversationId: string) => Promise<Message[]>;
726
726
  };
package/dist/index.js CHANGED
@@ -911,18 +911,21 @@ function useConversations({ productId, apiUrl = "" }) {
911
911
  const [isLoadingHistory, setIsLoadingHistory] = useState(false);
912
912
  const loadConversations = useCallback(async () => {
913
913
  const token = window.__crow_identity_token;
914
- if (!token) return;
914
+ if (!token) return [];
915
915
  try {
916
916
  const res = await fetch(
917
917
  `${apiUrl}/api/chat/conversations?product_id=${productId}&identity_token=${encodeURIComponent(token)}`
918
918
  );
919
919
  if (res.ok) {
920
920
  const data = await res.json();
921
- setConversations(data.conversations || []);
921
+ const convs = data.conversations || [];
922
+ setConversations(convs);
923
+ return convs;
922
924
  }
923
925
  } catch (error) {
924
926
  console.error("[Crow] Failed to load conversations:", error);
925
927
  }
928
+ return [];
926
929
  }, [apiUrl, productId]);
927
930
  const loadConversationHistory = useCallback(
928
931
  async (conversationId) => {
@@ -3998,7 +4001,15 @@ function CrowWidget({
3998
4001
  const { executeClientTool } = useCrowAPI({
3999
4002
  onIdentified: async () => {
4000
4003
  setIsVerifiedUser(true);
4001
- await conversations.loadConversations();
4004
+ const convs = await conversations.loadConversations();
4005
+ if (convs.length > 0) {
4006
+ const mostRecent = convs[0];
4007
+ const historyMessages = await conversations.loadConversationHistory(mostRecent.id);
4008
+ if (historyMessages.length > 0) {
4009
+ chat.loadMessages(historyMessages);
4010
+ chat.setConversationId(mostRecent.id);
4011
+ }
4012
+ }
4002
4013
  },
4003
4014
  onReset: () => {
4004
4015
  setIsVerifiedUser(false);