@usecrow/ui 0.1.16 → 0.1.18

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 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(null);
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 hasInitializedConversationRef = React3.useRef(false);
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 (hasInitializedConversationRef.current || persistAnonymousConversations === void 0) {
112
- return;
116
+ if (conversationId && onRestoredConversation && !hasRestoredRef.current) {
117
+ hasRestoredRef.current = true;
118
+ onRestoredConversation(conversationId);
113
119
  }
114
- hasInitializedConversationRef.current = true;
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
- if (persistAnonymousConversations) {
191
- try {
192
- localStorage.setItem(
193
- getConversationStorageKey(productId),
194
- parsed.conversation_id
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, persistAnonymousConversations, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall]
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 {
@@ -2505,6 +2488,7 @@ function CrowWidget({
2505
2488
  styles: propStyles,
2506
2489
  previewMode = false,
2507
2490
  showThinking: showThinkingProp,
2491
+ agentName: agentNameProp,
2508
2492
  welcomeMessage: welcomeMessageProp,
2509
2493
  onReady,
2510
2494
  onIdentify,
@@ -2513,7 +2497,7 @@ function CrowWidget({
2513
2497
  const {
2514
2498
  styles,
2515
2499
  isLoading: isLoadingStyles,
2516
- agentName,
2500
+ agentName: agentNameFromAPI,
2517
2501
  browserUseEnabled,
2518
2502
  showThinking: showThinkingFromAPI,
2519
2503
  persistAnonymousConversations,
@@ -2524,6 +2508,7 @@ function CrowWidget({
2524
2508
  propStyles,
2525
2509
  skip: previewMode
2526
2510
  });
2511
+ const agentName = agentNameProp ?? agentNameFromAPI;
2527
2512
  const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
2528
2513
  console.log("[Crow Widget] persistAnonymousConversations from API:", persistAnonymousConversations, "isLoading:", isLoadingStyles);
2529
2514
  const showThinking = showThinkingProp ?? showThinkingFromAPI;
@@ -2790,6 +2775,8 @@ function CrowCopilot({
2790
2775
  productId,
2791
2776
  apiUrl = "",
2792
2777
  title = "Copilot",
2778
+ agentName: agentNameProp,
2779
+ welcomeMessage: welcomeMessageProp,
2793
2780
  position = "right",
2794
2781
  width = 400,
2795
2782
  showClose = false,
@@ -2799,12 +2786,14 @@ function CrowCopilot({
2799
2786
  className,
2800
2787
  onReady
2801
2788
  }) {
2802
- const { styles, isLoading: isLoadingStyles, agentName, persistAnonymousConversations, welcomeMessage } = useCopilotStyles({
2789
+ const { styles, isLoading: isLoadingStyles, agentName: agentNameFromAPI, persistAnonymousConversations, welcomeMessage: welcomeMessageFromAPI } = useCopilotStyles({
2803
2790
  productId,
2804
2791
  apiUrl,
2805
2792
  propStyles,
2806
2793
  skip: previewMode
2807
2794
  });
2795
+ const agentName = agentNameProp ?? agentNameFromAPI ?? title;
2796
+ const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
2808
2797
  const messagesContainerRef = React3.useRef(null);
2809
2798
  const executeClientToolRef = React3.useRef(null);
2810
2799
  const [showConversationList, setShowConversationList] = React3.useState(false);
@@ -2891,7 +2880,7 @@ function CrowCopilot({
2891
2880
  CopilotStyleProvider,
2892
2881
  {
2893
2882
  styles,
2894
- agentName: agentName || title,
2883
+ agentName,
2895
2884
  isLoading: isLoadingStyles,
2896
2885
  children: /* @__PURE__ */ jsxRuntime.jsxs(
2897
2886
  "div",
@@ -2925,7 +2914,7 @@ function CrowCopilot({
2925
2914
  color: styles.colors.text,
2926
2915
  fontSize: styles.typography.headerFontSize
2927
2916
  },
2928
- children: agentName || title
2917
+ children: agentName
2929
2918
  }
2930
2919
  ),
2931
2920
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "crow-flex crow-items-center crow-gap-1", children: [