@usecrow/ui 0.1.15 → 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 +59 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -2
- package/dist/index.d.ts +19 -2
- package/dist/index.js +59 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -182,6 +182,9 @@ interface WidgetConfigResponse {
|
|
|
182
182
|
copilotStyles: CopilotStyleConfig;
|
|
183
183
|
browserUseEnabled?: boolean;
|
|
184
184
|
showThinking?: boolean;
|
|
185
|
+
persistAnonymousConversations?: boolean;
|
|
186
|
+
/** Custom welcome message shown when chat opens. Null uses SDK default. */
|
|
187
|
+
welcomeMessage?: string | null;
|
|
185
188
|
}
|
|
186
189
|
|
|
187
190
|
/** Identity data passed to the identify function */
|
|
@@ -212,6 +215,8 @@ interface CrowWidgetProps {
|
|
|
212
215
|
previewMode?: boolean;
|
|
213
216
|
/** Whether to show AI thinking/reasoning to users (overrides API setting if provided) */
|
|
214
217
|
showThinking?: boolean;
|
|
218
|
+
/** Custom welcome message (overrides API setting if provided) */
|
|
219
|
+
welcomeMessage?: string;
|
|
215
220
|
/** Callback when widget is ready */
|
|
216
221
|
onReady?: () => void;
|
|
217
222
|
/**
|
|
@@ -222,7 +227,7 @@ interface CrowWidgetProps {
|
|
|
222
227
|
/** Client-side tools the agent can call */
|
|
223
228
|
tools?: ToolsMap;
|
|
224
229
|
}
|
|
225
|
-
declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, onReady, onIdentify, tools, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
|
|
230
|
+
declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
|
|
226
231
|
|
|
227
232
|
interface CrowCopilotProps {
|
|
228
233
|
/** Product ID for this copilot */
|
|
@@ -529,13 +534,17 @@ interface ToolCallEvent {
|
|
|
529
534
|
interface UseChatOptions {
|
|
530
535
|
productId: string;
|
|
531
536
|
apiUrl?: string;
|
|
537
|
+
/** Whether to persist anonymous conversations across page refreshes (default: true) */
|
|
538
|
+
persistAnonymousConversations?: boolean;
|
|
539
|
+
/** Custom welcome message (uses SDK default if not provided) */
|
|
540
|
+
welcomeMessage?: string;
|
|
532
541
|
onVerificationStatus?: (isVerified: boolean) => void;
|
|
533
542
|
onConversationId?: (id: string) => void;
|
|
534
543
|
onWorkflowEvent?: (event: WorkflowEvent) => void;
|
|
535
544
|
onToolCall?: (toolCall: ToolCallEvent) => void;
|
|
536
545
|
onRestoredConversation?: (conversationId: string) => void;
|
|
537
546
|
}
|
|
538
|
-
declare function useChat({ productId, apiUrl, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
|
|
547
|
+
declare function useChat({ productId, apiUrl, persistAnonymousConversations: _persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
|
|
539
548
|
messages: Message[];
|
|
540
549
|
isLoading: boolean;
|
|
541
550
|
activeToolCalls: ToolCall[];
|
|
@@ -636,6 +645,10 @@ interface UseWidgetStylesResult {
|
|
|
636
645
|
browserUseEnabled: boolean;
|
|
637
646
|
/** Whether to show thinking/reasoning to users */
|
|
638
647
|
showThinking: boolean;
|
|
648
|
+
/** Whether to persist anonymous conversations across page refreshes (undefined while loading) */
|
|
649
|
+
persistAnonymousConversations: boolean | undefined;
|
|
650
|
+
/** Custom welcome message (undefined uses SDK default) */
|
|
651
|
+
welcomeMessage: string | undefined;
|
|
639
652
|
/** Refetch styles from API */
|
|
640
653
|
refetch: () => Promise<void>;
|
|
641
654
|
}
|
|
@@ -660,6 +673,10 @@ interface UseCopilotStylesResult {
|
|
|
660
673
|
error: Error | null;
|
|
661
674
|
/** Agent name from product config */
|
|
662
675
|
agentName: string;
|
|
676
|
+
/** Whether to persist anonymous conversations across page refreshes (undefined while loading) */
|
|
677
|
+
persistAnonymousConversations: boolean | undefined;
|
|
678
|
+
/** Custom welcome message (undefined uses SDK default) */
|
|
679
|
+
welcomeMessage: string | undefined;
|
|
663
680
|
/** Refetch styles from API */
|
|
664
681
|
refetch: () => Promise<void>;
|
|
665
682
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -182,6 +182,9 @@ interface WidgetConfigResponse {
|
|
|
182
182
|
copilotStyles: CopilotStyleConfig;
|
|
183
183
|
browserUseEnabled?: boolean;
|
|
184
184
|
showThinking?: boolean;
|
|
185
|
+
persistAnonymousConversations?: boolean;
|
|
186
|
+
/** Custom welcome message shown when chat opens. Null uses SDK default. */
|
|
187
|
+
welcomeMessage?: string | null;
|
|
185
188
|
}
|
|
186
189
|
|
|
187
190
|
/** Identity data passed to the identify function */
|
|
@@ -212,6 +215,8 @@ interface CrowWidgetProps {
|
|
|
212
215
|
previewMode?: boolean;
|
|
213
216
|
/** Whether to show AI thinking/reasoning to users (overrides API setting if provided) */
|
|
214
217
|
showThinking?: boolean;
|
|
218
|
+
/** Custom welcome message (overrides API setting if provided) */
|
|
219
|
+
welcomeMessage?: string;
|
|
215
220
|
/** Callback when widget is ready */
|
|
216
221
|
onReady?: () => void;
|
|
217
222
|
/**
|
|
@@ -222,7 +227,7 @@ interface CrowWidgetProps {
|
|
|
222
227
|
/** Client-side tools the agent can call */
|
|
223
228
|
tools?: ToolsMap;
|
|
224
229
|
}
|
|
225
|
-
declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, onReady, onIdentify, tools, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
|
|
230
|
+
declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
|
|
226
231
|
|
|
227
232
|
interface CrowCopilotProps {
|
|
228
233
|
/** Product ID for this copilot */
|
|
@@ -529,13 +534,17 @@ interface ToolCallEvent {
|
|
|
529
534
|
interface UseChatOptions {
|
|
530
535
|
productId: string;
|
|
531
536
|
apiUrl?: string;
|
|
537
|
+
/** Whether to persist anonymous conversations across page refreshes (default: true) */
|
|
538
|
+
persistAnonymousConversations?: boolean;
|
|
539
|
+
/** Custom welcome message (uses SDK default if not provided) */
|
|
540
|
+
welcomeMessage?: string;
|
|
532
541
|
onVerificationStatus?: (isVerified: boolean) => void;
|
|
533
542
|
onConversationId?: (id: string) => void;
|
|
534
543
|
onWorkflowEvent?: (event: WorkflowEvent) => void;
|
|
535
544
|
onToolCall?: (toolCall: ToolCallEvent) => void;
|
|
536
545
|
onRestoredConversation?: (conversationId: string) => void;
|
|
537
546
|
}
|
|
538
|
-
declare function useChat({ productId, apiUrl, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
|
|
547
|
+
declare function useChat({ productId, apiUrl, persistAnonymousConversations: _persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
|
|
539
548
|
messages: Message[];
|
|
540
549
|
isLoading: boolean;
|
|
541
550
|
activeToolCalls: ToolCall[];
|
|
@@ -636,6 +645,10 @@ interface UseWidgetStylesResult {
|
|
|
636
645
|
browserUseEnabled: boolean;
|
|
637
646
|
/** Whether to show thinking/reasoning to users */
|
|
638
647
|
showThinking: boolean;
|
|
648
|
+
/** Whether to persist anonymous conversations across page refreshes (undefined while loading) */
|
|
649
|
+
persistAnonymousConversations: boolean | undefined;
|
|
650
|
+
/** Custom welcome message (undefined uses SDK default) */
|
|
651
|
+
welcomeMessage: string | undefined;
|
|
639
652
|
/** Refetch styles from API */
|
|
640
653
|
refetch: () => Promise<void>;
|
|
641
654
|
}
|
|
@@ -660,6 +673,10 @@ interface UseCopilotStylesResult {
|
|
|
660
673
|
error: Error | null;
|
|
661
674
|
/** Agent name from product config */
|
|
662
675
|
agentName: string;
|
|
676
|
+
/** Whether to persist anonymous conversations across page refreshes (undefined while loading) */
|
|
677
|
+
persistAnonymousConversations: boolean | undefined;
|
|
678
|
+
/** Custom welcome message (undefined uses SDK default) */
|
|
679
|
+
welcomeMessage: string | undefined;
|
|
663
680
|
/** Refetch styles from API */
|
|
664
681
|
refetch: () => Promise<void>;
|
|
665
682
|
}
|
package/dist/index.js
CHANGED
|
@@ -45,16 +45,19 @@ var getConversationStorageKey = (productId) => `crow_conv_${productId}`;
|
|
|
45
45
|
function useChat({
|
|
46
46
|
productId,
|
|
47
47
|
apiUrl = "",
|
|
48
|
+
persistAnonymousConversations: _persistAnonymousConversations,
|
|
49
|
+
welcomeMessage,
|
|
48
50
|
onVerificationStatus,
|
|
49
51
|
onConversationId,
|
|
50
52
|
onWorkflowEvent,
|
|
51
53
|
onToolCall,
|
|
52
54
|
onRestoredConversation
|
|
53
55
|
}) {
|
|
56
|
+
const effectiveWelcomeMessage = welcomeMessage || DEFAULT_WELCOME_MESSAGE;
|
|
54
57
|
const [messages, setMessages] = useState([
|
|
55
58
|
{
|
|
56
59
|
id: "welcome",
|
|
57
|
-
content:
|
|
60
|
+
content: effectiveWelcomeMessage,
|
|
58
61
|
isBot: true,
|
|
59
62
|
timestamp: /* @__PURE__ */ new Date()
|
|
60
63
|
}
|
|
@@ -71,6 +74,18 @@ function useChat({
|
|
|
71
74
|
const [selectedModel, setSelectedModel] = useState(DEFAULT_MODEL);
|
|
72
75
|
const abortControllerRef = useRef(null);
|
|
73
76
|
const hasRestoredRef = useRef(false);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (messages.length === 1 && messages[0].id === "welcome" && !conversationId) {
|
|
79
|
+
setMessages([
|
|
80
|
+
{
|
|
81
|
+
id: "welcome",
|
|
82
|
+
content: effectiveWelcomeMessage,
|
|
83
|
+
isBot: true,
|
|
84
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
85
|
+
}
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
}, [effectiveWelcomeMessage]);
|
|
74
89
|
useEffect(() => {
|
|
75
90
|
if (conversationId && onRestoredConversation && !hasRestoredRef.current) {
|
|
76
91
|
hasRestoredRef.current = true;
|
|
@@ -321,7 +336,7 @@ function useChat({
|
|
|
321
336
|
setMessages([
|
|
322
337
|
{
|
|
323
338
|
id: "welcome",
|
|
324
|
-
content:
|
|
339
|
+
content: effectiveWelcomeMessage,
|
|
325
340
|
isBot: true,
|
|
326
341
|
timestamp: /* @__PURE__ */ new Date()
|
|
327
342
|
}
|
|
@@ -331,7 +346,7 @@ function useChat({
|
|
|
331
346
|
localStorage.removeItem(getConversationStorageKey(productId));
|
|
332
347
|
} catch {
|
|
333
348
|
}
|
|
334
|
-
}, [productId]);
|
|
349
|
+
}, [productId, effectiveWelcomeMessage]);
|
|
335
350
|
const loadMessages = useCallback((historyMessages) => {
|
|
336
351
|
setMessages(historyMessages);
|
|
337
352
|
}, []);
|
|
@@ -1016,6 +1031,12 @@ function useWidgetStyles({
|
|
|
1016
1031
|
const [showThinking, setShowThinking] = useState(
|
|
1017
1032
|
styleCache.get(key)?.showThinking ?? true
|
|
1018
1033
|
);
|
|
1034
|
+
const [persistAnonymousConversations, setPersistAnonymousConversations] = useState(
|
|
1035
|
+
styleCache.has(key) ? styleCache.get(key)?.persistAnonymousConversations ?? true : void 0
|
|
1036
|
+
);
|
|
1037
|
+
const [welcomeMessage, setWelcomeMessage] = useState(
|
|
1038
|
+
styleCache.get(key)?.welcomeMessage ?? void 0
|
|
1039
|
+
);
|
|
1019
1040
|
const hasFetchedRef = useRef(false);
|
|
1020
1041
|
const fetchStyles = async () => {
|
|
1021
1042
|
if (skip) return;
|
|
@@ -1028,6 +1049,8 @@ function useWidgetStyles({
|
|
|
1028
1049
|
setAgentName(config.agentName || "Assistant");
|
|
1029
1050
|
setBrowserUseEnabled(config.browserUseEnabled || false);
|
|
1030
1051
|
setShowThinking(config.showThinking ?? true);
|
|
1052
|
+
setPersistAnonymousConversations(config.persistAnonymousConversations ?? true);
|
|
1053
|
+
setWelcomeMessage(config.welcomeMessage ?? void 0);
|
|
1031
1054
|
} catch (err) {
|
|
1032
1055
|
console.error("[CrowWidget] Failed to fetch styles:", err);
|
|
1033
1056
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -1043,6 +1066,8 @@ function useWidgetStyles({
|
|
|
1043
1066
|
setAgentName(cached.agentName || "Assistant");
|
|
1044
1067
|
setBrowserUseEnabled(cached.browserUseEnabled || false);
|
|
1045
1068
|
setShowThinking(cached.showThinking ?? true);
|
|
1069
|
+
setPersistAnonymousConversations(cached.persistAnonymousConversations ?? true);
|
|
1070
|
+
setWelcomeMessage(cached.welcomeMessage ?? void 0);
|
|
1046
1071
|
setIsLoading(false);
|
|
1047
1072
|
return;
|
|
1048
1073
|
}
|
|
@@ -1057,6 +1082,8 @@ function useWidgetStyles({
|
|
|
1057
1082
|
agentName,
|
|
1058
1083
|
browserUseEnabled,
|
|
1059
1084
|
showThinking,
|
|
1085
|
+
persistAnonymousConversations,
|
|
1086
|
+
welcomeMessage,
|
|
1060
1087
|
refetch: fetchStyles
|
|
1061
1088
|
};
|
|
1062
1089
|
}
|
|
@@ -1076,6 +1103,12 @@ function useCopilotStyles({
|
|
|
1076
1103
|
const [agentName, setAgentName] = useState(
|
|
1077
1104
|
styleCache.get(key)?.agentName || "Assistant"
|
|
1078
1105
|
);
|
|
1106
|
+
const [persistAnonymousConversations, setPersistAnonymousConversations] = useState(
|
|
1107
|
+
styleCache.has(key) ? styleCache.get(key)?.persistAnonymousConversations ?? true : void 0
|
|
1108
|
+
);
|
|
1109
|
+
const [welcomeMessage, setWelcomeMessage] = useState(
|
|
1110
|
+
styleCache.get(key)?.welcomeMessage ?? void 0
|
|
1111
|
+
);
|
|
1079
1112
|
const hasFetchedRef = useRef(false);
|
|
1080
1113
|
const fetchStyles = async () => {
|
|
1081
1114
|
if (skip) return;
|
|
@@ -1086,6 +1119,8 @@ function useCopilotStyles({
|
|
|
1086
1119
|
styleCache.set(key, config);
|
|
1087
1120
|
setDbStyles(config.copilotStyles);
|
|
1088
1121
|
setAgentName(config.agentName || "Assistant");
|
|
1122
|
+
setPersistAnonymousConversations(config.persistAnonymousConversations ?? true);
|
|
1123
|
+
setWelcomeMessage(config.welcomeMessage ?? void 0);
|
|
1089
1124
|
} catch (err) {
|
|
1090
1125
|
console.error("[CrowCopilot] Failed to fetch styles:", err);
|
|
1091
1126
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -1099,6 +1134,8 @@ function useCopilotStyles({
|
|
|
1099
1134
|
if (cached) {
|
|
1100
1135
|
setDbStyles(cached.copilotStyles);
|
|
1101
1136
|
setAgentName(cached.agentName || "Assistant");
|
|
1137
|
+
setPersistAnonymousConversations(cached.persistAnonymousConversations ?? true);
|
|
1138
|
+
setWelcomeMessage(cached.welcomeMessage ?? void 0);
|
|
1102
1139
|
setIsLoading(false);
|
|
1103
1140
|
return;
|
|
1104
1141
|
}
|
|
@@ -1111,6 +1148,8 @@ function useCopilotStyles({
|
|
|
1111
1148
|
isLoading,
|
|
1112
1149
|
error,
|
|
1113
1150
|
agentName,
|
|
1151
|
+
persistAnonymousConversations,
|
|
1152
|
+
welcomeMessage,
|
|
1114
1153
|
refetch: fetchStyles
|
|
1115
1154
|
};
|
|
1116
1155
|
}
|
|
@@ -2423,16 +2462,27 @@ function CrowWidget({
|
|
|
2423
2462
|
styles: propStyles,
|
|
2424
2463
|
previewMode = false,
|
|
2425
2464
|
showThinking: showThinkingProp,
|
|
2465
|
+
welcomeMessage: welcomeMessageProp,
|
|
2426
2466
|
onReady,
|
|
2427
2467
|
onIdentify,
|
|
2428
2468
|
tools
|
|
2429
2469
|
}) {
|
|
2430
|
-
const {
|
|
2470
|
+
const {
|
|
2471
|
+
styles,
|
|
2472
|
+
isLoading: isLoadingStyles,
|
|
2473
|
+
agentName,
|
|
2474
|
+
browserUseEnabled,
|
|
2475
|
+
showThinking: showThinkingFromAPI,
|
|
2476
|
+
persistAnonymousConversations,
|
|
2477
|
+
welcomeMessage: welcomeMessageFromAPI
|
|
2478
|
+
} = useWidgetStyles({
|
|
2431
2479
|
productId,
|
|
2432
2480
|
apiUrl,
|
|
2433
2481
|
propStyles,
|
|
2434
2482
|
skip: previewMode
|
|
2435
2483
|
});
|
|
2484
|
+
const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
|
|
2485
|
+
console.log("[Crow Widget] persistAnonymousConversations from API:", persistAnonymousConversations, "isLoading:", isLoadingStyles);
|
|
2436
2486
|
const showThinking = showThinkingProp ?? showThinkingFromAPI;
|
|
2437
2487
|
const [autoTools, setAutoTools] = useState({});
|
|
2438
2488
|
const cssVars = stylesToCssVars(styles);
|
|
@@ -2460,6 +2510,8 @@ function CrowWidget({
|
|
|
2460
2510
|
const chat = useChat({
|
|
2461
2511
|
productId,
|
|
2462
2512
|
apiUrl,
|
|
2513
|
+
persistAnonymousConversations,
|
|
2514
|
+
welcomeMessage,
|
|
2463
2515
|
onVerificationStatus: (isVerified) => {
|
|
2464
2516
|
setIsVerifiedUser(isVerified);
|
|
2465
2517
|
},
|
|
@@ -2704,7 +2756,7 @@ function CrowCopilot({
|
|
|
2704
2756
|
className,
|
|
2705
2757
|
onReady
|
|
2706
2758
|
}) {
|
|
2707
|
-
const { styles, isLoading: isLoadingStyles, agentName } = useCopilotStyles({
|
|
2759
|
+
const { styles, isLoading: isLoadingStyles, agentName, persistAnonymousConversations, welcomeMessage } = useCopilotStyles({
|
|
2708
2760
|
productId,
|
|
2709
2761
|
apiUrl,
|
|
2710
2762
|
propStyles,
|
|
@@ -2720,6 +2772,8 @@ function CrowCopilot({
|
|
|
2720
2772
|
const chat = useChat({
|
|
2721
2773
|
productId,
|
|
2722
2774
|
apiUrl,
|
|
2775
|
+
persistAnonymousConversations,
|
|
2776
|
+
welcomeMessage,
|
|
2723
2777
|
onVerificationStatus: (isVerified) => {
|
|
2724
2778
|
setIsVerifiedUser(isVerified);
|
|
2725
2779
|
},
|