@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.d.cts CHANGED
@@ -215,6 +215,8 @@ interface CrowWidgetProps {
215
215
  previewMode?: boolean;
216
216
  /** Whether to show AI thinking/reasoning to users (overrides API setting if provided) */
217
217
  showThinking?: boolean;
218
+ /** Custom agent name shown in header (overrides API setting if provided) */
219
+ agentName?: string;
218
220
  /** Custom welcome message (overrides API setting if provided) */
219
221
  welcomeMessage?: string;
220
222
  /** Callback when widget is ready */
@@ -227,15 +229,19 @@ interface CrowWidgetProps {
227
229
  /** Client-side tools the agent can call */
228
230
  tools?: ToolsMap;
229
231
  }
230
- declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
232
+ declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
231
233
 
232
234
  interface CrowCopilotProps {
233
235
  /** Product ID for this copilot */
234
236
  productId: string;
235
237
  /** API URL (defaults to relative path) */
236
238
  apiUrl?: string;
237
- /** Title shown in header */
239
+ /** Title shown in header (fallback if agentName not provided) */
238
240
  title?: string;
241
+ /** Custom agent name shown in header (overrides API setting if provided) */
242
+ agentName?: string;
243
+ /** Custom welcome message (overrides API setting if provided) */
244
+ welcomeMessage?: string;
239
245
  /** Position of the sidebar */
240
246
  position?: "left" | "right";
241
247
  /** Width of the sidebar */
@@ -253,7 +259,7 @@ interface CrowCopilotProps {
253
259
  /** Callback when copilot is ready */
254
260
  onReady?: () => void;
255
261
  }
256
- declare function CrowCopilot({ productId, apiUrl, title, position, width, showClose, onClose, styles: propStyles, previewMode, className, onReady, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
262
+ declare function CrowCopilot({ productId, apiUrl, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, showClose, onClose, styles: propStyles, previewMode, className, onReady, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
257
263
 
258
264
  interface CrowProviderProps extends CrowClientConfig {
259
265
  children: React.ReactNode;
@@ -544,7 +550,7 @@ interface UseChatOptions {
544
550
  onToolCall?: (toolCall: ToolCallEvent) => void;
545
551
  onRestoredConversation?: (conversationId: string) => void;
546
552
  }
547
- declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
553
+ declare function useChat({ productId, apiUrl, persistAnonymousConversations: _persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
548
554
  messages: Message[];
549
555
  isLoading: boolean;
550
556
  activeToolCalls: ToolCall[];
package/dist/index.d.ts CHANGED
@@ -215,6 +215,8 @@ interface CrowWidgetProps {
215
215
  previewMode?: boolean;
216
216
  /** Whether to show AI thinking/reasoning to users (overrides API setting if provided) */
217
217
  showThinking?: boolean;
218
+ /** Custom agent name shown in header (overrides API setting if provided) */
219
+ agentName?: string;
218
220
  /** Custom welcome message (overrides API setting if provided) */
219
221
  welcomeMessage?: string;
220
222
  /** Callback when widget is ready */
@@ -227,15 +229,19 @@ interface CrowWidgetProps {
227
229
  /** Client-side tools the agent can call */
228
230
  tools?: ToolsMap;
229
231
  }
230
- declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
232
+ declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
231
233
 
232
234
  interface CrowCopilotProps {
233
235
  /** Product ID for this copilot */
234
236
  productId: string;
235
237
  /** API URL (defaults to relative path) */
236
238
  apiUrl?: string;
237
- /** Title shown in header */
239
+ /** Title shown in header (fallback if agentName not provided) */
238
240
  title?: string;
241
+ /** Custom agent name shown in header (overrides API setting if provided) */
242
+ agentName?: string;
243
+ /** Custom welcome message (overrides API setting if provided) */
244
+ welcomeMessage?: string;
239
245
  /** Position of the sidebar */
240
246
  position?: "left" | "right";
241
247
  /** Width of the sidebar */
@@ -253,7 +259,7 @@ interface CrowCopilotProps {
253
259
  /** Callback when copilot is ready */
254
260
  onReady?: () => void;
255
261
  }
256
- declare function CrowCopilot({ productId, apiUrl, title, position, width, showClose, onClose, styles: propStyles, previewMode, className, onReady, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
262
+ declare function CrowCopilot({ productId, apiUrl, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, showClose, onClose, styles: propStyles, previewMode, className, onReady, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
257
263
 
258
264
  interface CrowProviderProps extends CrowClientConfig {
259
265
  children: React.ReactNode;
@@ -544,7 +550,7 @@ interface UseChatOptions {
544
550
  onToolCall?: (toolCall: ToolCallEvent) => void;
545
551
  onRestoredConversation?: (conversationId: string) => void;
546
552
  }
547
- declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
553
+ declare function useChat({ productId, apiUrl, persistAnonymousConversations: _persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
548
554
  messages: Message[];
549
555
  isLoading: boolean;
550
556
  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(null);
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 hasInitializedConversationRef = useRef(false);
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 (hasInitializedConversationRef.current || persistAnonymousConversations === void 0) {
86
- return;
90
+ if (conversationId && onRestoredConversation && !hasRestoredRef.current) {
91
+ hasRestoredRef.current = true;
92
+ onRestoredConversation(conversationId);
87
93
  }
88
- hasInitializedConversationRef.current = true;
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
- if (persistAnonymousConversations) {
165
- try {
166
- localStorage.setItem(
167
- getConversationStorageKey(productId),
168
- parsed.conversation_id
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, persistAnonymousConversations, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall]
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 {
@@ -2479,6 +2462,7 @@ function CrowWidget({
2479
2462
  styles: propStyles,
2480
2463
  previewMode = false,
2481
2464
  showThinking: showThinkingProp,
2465
+ agentName: agentNameProp,
2482
2466
  welcomeMessage: welcomeMessageProp,
2483
2467
  onReady,
2484
2468
  onIdentify,
@@ -2487,7 +2471,7 @@ function CrowWidget({
2487
2471
  const {
2488
2472
  styles,
2489
2473
  isLoading: isLoadingStyles,
2490
- agentName,
2474
+ agentName: agentNameFromAPI,
2491
2475
  browserUseEnabled,
2492
2476
  showThinking: showThinkingFromAPI,
2493
2477
  persistAnonymousConversations,
@@ -2498,6 +2482,7 @@ function CrowWidget({
2498
2482
  propStyles,
2499
2483
  skip: previewMode
2500
2484
  });
2485
+ const agentName = agentNameProp ?? agentNameFromAPI;
2501
2486
  const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
2502
2487
  console.log("[Crow Widget] persistAnonymousConversations from API:", persistAnonymousConversations, "isLoading:", isLoadingStyles);
2503
2488
  const showThinking = showThinkingProp ?? showThinkingFromAPI;
@@ -2764,6 +2749,8 @@ function CrowCopilot({
2764
2749
  productId,
2765
2750
  apiUrl = "",
2766
2751
  title = "Copilot",
2752
+ agentName: agentNameProp,
2753
+ welcomeMessage: welcomeMessageProp,
2767
2754
  position = "right",
2768
2755
  width = 400,
2769
2756
  showClose = false,
@@ -2773,12 +2760,14 @@ function CrowCopilot({
2773
2760
  className,
2774
2761
  onReady
2775
2762
  }) {
2776
- const { styles, isLoading: isLoadingStyles, agentName, persistAnonymousConversations, welcomeMessage } = useCopilotStyles({
2763
+ const { styles, isLoading: isLoadingStyles, agentName: agentNameFromAPI, persistAnonymousConversations, welcomeMessage: welcomeMessageFromAPI } = useCopilotStyles({
2777
2764
  productId,
2778
2765
  apiUrl,
2779
2766
  propStyles,
2780
2767
  skip: previewMode
2781
2768
  });
2769
+ const agentName = agentNameProp ?? agentNameFromAPI ?? title;
2770
+ const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
2782
2771
  const messagesContainerRef = useRef(null);
2783
2772
  const executeClientToolRef = useRef(null);
2784
2773
  const [showConversationList, setShowConversationList] = useState(false);
@@ -2865,7 +2854,7 @@ function CrowCopilot({
2865
2854
  CopilotStyleProvider,
2866
2855
  {
2867
2856
  styles,
2868
- agentName: agentName || title,
2857
+ agentName,
2869
2858
  isLoading: isLoadingStyles,
2870
2859
  children: /* @__PURE__ */ jsxs(
2871
2860
  "div",
@@ -2899,7 +2888,7 @@ function CrowCopilot({
2899
2888
  color: styles.colors.text,
2900
2889
  fontSize: styles.typography.headerFontSize
2901
2890
  },
2902
- children: agentName || title
2891
+ children: agentName
2903
2892
  }
2904
2893
  ),
2905
2894
  /* @__PURE__ */ jsxs("div", { className: "crow-flex crow-items-center crow-gap-1", children: [