@usecrow/ui 0.1.24 → 0.1.26
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 +31 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +31 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -185,6 +185,8 @@ interface WidgetConfigResponse {
|
|
|
185
185
|
persistAnonymousConversations?: boolean;
|
|
186
186
|
/** Custom welcome message shown when chat opens. Null uses SDK default. */
|
|
187
187
|
welcomeMessage?: string | null;
|
|
188
|
+
/** AI model to use for this product */
|
|
189
|
+
model?: string;
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
/** Identity data passed to the identify function */
|
|
@@ -228,8 +230,10 @@ interface CrowWidgetProps {
|
|
|
228
230
|
onIdentify?: (identify: IdentifyFunction) => void;
|
|
229
231
|
/** Client-side tools the agent can call */
|
|
230
232
|
tools?: ToolsMap;
|
|
233
|
+
/** Callback fired when a server-side tool completes, with the tool name and full result data */
|
|
234
|
+
onToolResult?: (toolName: string, result: Record<string, unknown>) => void;
|
|
231
235
|
}
|
|
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;
|
|
236
|
+
declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, onToolResult, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
|
|
233
237
|
|
|
234
238
|
interface CrowCopilotProps {
|
|
235
239
|
/** Product ID for this copilot */
|
|
@@ -262,8 +266,10 @@ interface CrowCopilotProps {
|
|
|
262
266
|
className?: string;
|
|
263
267
|
/** Callback when copilot is ready */
|
|
264
268
|
onReady?: () => void;
|
|
269
|
+
/** Callback fired when a server-side tool completes, with the tool name and full result data */
|
|
270
|
+
onToolResult?: (toolName: string, result: Record<string, unknown>) => void;
|
|
265
271
|
}
|
|
266
|
-
declare function CrowCopilot({ productId, apiUrl, variant, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, defaultOpen, showClose, onClose, styles: propStyles, previewMode, className, onReady, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
|
|
272
|
+
declare function CrowCopilot({ productId, apiUrl, variant, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, defaultOpen, showClose, onClose, styles: propStyles, previewMode, className, onReady, onToolResult, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
|
|
267
273
|
|
|
268
274
|
interface CrowProviderProps extends CrowClientConfig {
|
|
269
275
|
children: React.ReactNode;
|
|
@@ -547,13 +553,16 @@ interface UseChatOptions {
|
|
|
547
553
|
persistAnonymousConversations?: boolean;
|
|
548
554
|
/** Custom welcome message (uses SDK default if not provided) */
|
|
549
555
|
welcomeMessage?: string;
|
|
556
|
+
/** AI model to use for this chat (defaults to DEFAULT_MODEL) */
|
|
557
|
+
selectedModel?: string;
|
|
550
558
|
onVerificationStatus?: (isVerified: boolean) => void;
|
|
551
559
|
onConversationId?: (id: string) => void;
|
|
552
560
|
onWorkflowEvent?: (event: WorkflowEvent) => void;
|
|
553
561
|
onToolCall?: (toolCall: ToolCallEvent) => void;
|
|
562
|
+
onToolResult?: (toolName: string, result: Record<string, unknown>) => void;
|
|
554
563
|
onRestoredConversation?: (conversationId: string) => void;
|
|
555
564
|
}
|
|
556
|
-
declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
|
|
565
|
+
declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, selectedModel: initialSelectedModel, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onToolResult, onRestoredConversation, }: UseChatOptions): {
|
|
557
566
|
messages: Message[];
|
|
558
567
|
isLoading: boolean;
|
|
559
568
|
activeToolCalls: ToolCall[];
|
|
@@ -659,6 +668,8 @@ interface UseWidgetStylesResult {
|
|
|
659
668
|
persistAnonymousConversations: boolean | undefined;
|
|
660
669
|
/** Custom welcome message (undefined uses SDK default) */
|
|
661
670
|
welcomeMessage: string | undefined;
|
|
671
|
+
/** AI model configured for this product */
|
|
672
|
+
selectedModel: string | undefined;
|
|
662
673
|
/** Refetch styles from API */
|
|
663
674
|
refetch: () => Promise<void>;
|
|
664
675
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -185,6 +185,8 @@ interface WidgetConfigResponse {
|
|
|
185
185
|
persistAnonymousConversations?: boolean;
|
|
186
186
|
/** Custom welcome message shown when chat opens. Null uses SDK default. */
|
|
187
187
|
welcomeMessage?: string | null;
|
|
188
|
+
/** AI model to use for this product */
|
|
189
|
+
model?: string;
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
/** Identity data passed to the identify function */
|
|
@@ -228,8 +230,10 @@ interface CrowWidgetProps {
|
|
|
228
230
|
onIdentify?: (identify: IdentifyFunction) => void;
|
|
229
231
|
/** Client-side tools the agent can call */
|
|
230
232
|
tools?: ToolsMap;
|
|
233
|
+
/** Callback fired when a server-side tool completes, with the tool name and full result data */
|
|
234
|
+
onToolResult?: (toolName: string, result: Record<string, unknown>) => void;
|
|
231
235
|
}
|
|
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;
|
|
236
|
+
declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, onToolResult, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
|
|
233
237
|
|
|
234
238
|
interface CrowCopilotProps {
|
|
235
239
|
/** Product ID for this copilot */
|
|
@@ -262,8 +266,10 @@ interface CrowCopilotProps {
|
|
|
262
266
|
className?: string;
|
|
263
267
|
/** Callback when copilot is ready */
|
|
264
268
|
onReady?: () => void;
|
|
269
|
+
/** Callback fired when a server-side tool completes, with the tool name and full result data */
|
|
270
|
+
onToolResult?: (toolName: string, result: Record<string, unknown>) => void;
|
|
265
271
|
}
|
|
266
|
-
declare function CrowCopilot({ productId, apiUrl, variant, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, defaultOpen, showClose, onClose, styles: propStyles, previewMode, className, onReady, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
|
|
272
|
+
declare function CrowCopilot({ productId, apiUrl, variant, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, defaultOpen, showClose, onClose, styles: propStyles, previewMode, className, onReady, onToolResult, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
|
|
267
273
|
|
|
268
274
|
interface CrowProviderProps extends CrowClientConfig {
|
|
269
275
|
children: React.ReactNode;
|
|
@@ -547,13 +553,16 @@ interface UseChatOptions {
|
|
|
547
553
|
persistAnonymousConversations?: boolean;
|
|
548
554
|
/** Custom welcome message (uses SDK default if not provided) */
|
|
549
555
|
welcomeMessage?: string;
|
|
556
|
+
/** AI model to use for this chat (defaults to DEFAULT_MODEL) */
|
|
557
|
+
selectedModel?: string;
|
|
550
558
|
onVerificationStatus?: (isVerified: boolean) => void;
|
|
551
559
|
onConversationId?: (id: string) => void;
|
|
552
560
|
onWorkflowEvent?: (event: WorkflowEvent) => void;
|
|
553
561
|
onToolCall?: (toolCall: ToolCallEvent) => void;
|
|
562
|
+
onToolResult?: (toolName: string, result: Record<string, unknown>) => void;
|
|
554
563
|
onRestoredConversation?: (conversationId: string) => void;
|
|
555
564
|
}
|
|
556
|
-
declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onRestoredConversation, }: UseChatOptions): {
|
|
565
|
+
declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, selectedModel: initialSelectedModel, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onToolResult, onRestoredConversation, }: UseChatOptions): {
|
|
557
566
|
messages: Message[];
|
|
558
567
|
isLoading: boolean;
|
|
559
568
|
activeToolCalls: ToolCall[];
|
|
@@ -659,6 +668,8 @@ interface UseWidgetStylesResult {
|
|
|
659
668
|
persistAnonymousConversations: boolean | undefined;
|
|
660
669
|
/** Custom welcome message (undefined uses SDK default) */
|
|
661
670
|
welcomeMessage: string | undefined;
|
|
671
|
+
/** AI model configured for this product */
|
|
672
|
+
selectedModel: string | undefined;
|
|
662
673
|
/** Refetch styles from API */
|
|
663
674
|
refetch: () => Promise<void>;
|
|
664
675
|
}
|
package/dist/index.js
CHANGED
|
@@ -47,10 +47,12 @@ function useChat({
|
|
|
47
47
|
apiUrl = "",
|
|
48
48
|
persistAnonymousConversations,
|
|
49
49
|
welcomeMessage,
|
|
50
|
+
selectedModel: initialSelectedModel,
|
|
50
51
|
onVerificationStatus,
|
|
51
52
|
onConversationId,
|
|
52
53
|
onWorkflowEvent,
|
|
53
54
|
onToolCall,
|
|
55
|
+
onToolResult,
|
|
54
56
|
onRestoredConversation
|
|
55
57
|
}) {
|
|
56
58
|
const effectiveWelcomeMessage = welcomeMessage || DEFAULT_WELCOME_MESSAGE;
|
|
@@ -65,9 +67,14 @@ function useChat({
|
|
|
65
67
|
const [isLoading, setIsLoading] = useState(false);
|
|
66
68
|
const [activeToolCalls, setActiveToolCalls] = useState([]);
|
|
67
69
|
const [conversationId, setConversationId] = useState(null);
|
|
68
|
-
const [selectedModel, setSelectedModel] = useState(DEFAULT_MODEL);
|
|
70
|
+
const [selectedModel, setSelectedModel] = useState(initialSelectedModel || DEFAULT_MODEL);
|
|
69
71
|
const abortControllerRef = useRef(null);
|
|
70
72
|
const hasCheckedPersistRef = useRef(false);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (initialSelectedModel) {
|
|
75
|
+
setSelectedModel((prev) => prev !== initialSelectedModel ? initialSelectedModel : prev);
|
|
76
|
+
}
|
|
77
|
+
}, [initialSelectedModel]);
|
|
71
78
|
useEffect(() => {
|
|
72
79
|
if (messages.length === 1 && messages[0].id === "welcome" && !conversationId) {
|
|
73
80
|
setMessages([
|
|
@@ -258,6 +265,11 @@ function useChat({
|
|
|
258
265
|
);
|
|
259
266
|
}
|
|
260
267
|
break;
|
|
268
|
+
case "tool_result":
|
|
269
|
+
if (parsed.tool_name && parsed.result) {
|
|
270
|
+
onToolResult?.(parsed.tool_name, parsed.result);
|
|
271
|
+
}
|
|
272
|
+
break;
|
|
261
273
|
case "client_tool_call":
|
|
262
274
|
pendingClientTools.push({
|
|
263
275
|
toolName: parsed.tool_name,
|
|
@@ -317,7 +329,7 @@ function useChat({
|
|
|
317
329
|
abortControllerRef.current = null;
|
|
318
330
|
}
|
|
319
331
|
},
|
|
320
|
-
[apiUrl, productId, conversationId, selectedModel, persistAnonymousConversations, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall]
|
|
332
|
+
[apiUrl, productId, conversationId, selectedModel, persistAnonymousConversations, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onToolResult]
|
|
321
333
|
);
|
|
322
334
|
const sendMessage = useCallback(
|
|
323
335
|
(content) => {
|
|
@@ -1102,6 +1114,9 @@ function useWidgetStyles({
|
|
|
1102
1114
|
const [welcomeMessage, setWelcomeMessage] = useState(
|
|
1103
1115
|
styleCache.get(key)?.welcomeMessage ?? void 0
|
|
1104
1116
|
);
|
|
1117
|
+
const [selectedModel, setSelectedModel] = useState(
|
|
1118
|
+
styleCache.get(key)?.model ?? void 0
|
|
1119
|
+
);
|
|
1105
1120
|
const hasFetchedRef = useRef(false);
|
|
1106
1121
|
const fetchStyles = async () => {
|
|
1107
1122
|
if (skip) return;
|
|
@@ -1116,6 +1131,7 @@ function useWidgetStyles({
|
|
|
1116
1131
|
setShowThinking(config.showThinking ?? true);
|
|
1117
1132
|
setPersistAnonymousConversations(config.persistAnonymousConversations ?? true);
|
|
1118
1133
|
setWelcomeMessage(config.welcomeMessage ?? void 0);
|
|
1134
|
+
setSelectedModel(config.model ?? void 0);
|
|
1119
1135
|
} catch (err) {
|
|
1120
1136
|
console.error("[CrowWidget] Failed to fetch styles:", err);
|
|
1121
1137
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -1133,6 +1149,7 @@ function useWidgetStyles({
|
|
|
1133
1149
|
setShowThinking(cached.showThinking ?? true);
|
|
1134
1150
|
setPersistAnonymousConversations(cached.persistAnonymousConversations ?? true);
|
|
1135
1151
|
setWelcomeMessage(cached.welcomeMessage ?? void 0);
|
|
1152
|
+
setSelectedModel(cached.model ?? void 0);
|
|
1136
1153
|
setIsLoading(false);
|
|
1137
1154
|
return;
|
|
1138
1155
|
}
|
|
@@ -1149,6 +1166,7 @@ function useWidgetStyles({
|
|
|
1149
1166
|
showThinking,
|
|
1150
1167
|
persistAnonymousConversations,
|
|
1151
1168
|
welcomeMessage,
|
|
1169
|
+
selectedModel,
|
|
1152
1170
|
refetch: fetchStyles
|
|
1153
1171
|
};
|
|
1154
1172
|
}
|
|
@@ -2735,7 +2753,8 @@ function CrowWidget({
|
|
|
2735
2753
|
welcomeMessage: welcomeMessageProp,
|
|
2736
2754
|
onReady,
|
|
2737
2755
|
onIdentify,
|
|
2738
|
-
tools
|
|
2756
|
+
tools,
|
|
2757
|
+
onToolResult
|
|
2739
2758
|
}) {
|
|
2740
2759
|
const {
|
|
2741
2760
|
styles,
|
|
@@ -2744,7 +2763,8 @@ function CrowWidget({
|
|
|
2744
2763
|
browserUseEnabled,
|
|
2745
2764
|
showThinking: showThinkingFromAPI,
|
|
2746
2765
|
persistAnonymousConversations,
|
|
2747
|
-
welcomeMessage: welcomeMessageFromAPI
|
|
2766
|
+
welcomeMessage: welcomeMessageFromAPI,
|
|
2767
|
+
selectedModel: selectedModelFromAPI
|
|
2748
2768
|
} = useWidgetStyles({
|
|
2749
2769
|
productId,
|
|
2750
2770
|
apiUrl,
|
|
@@ -2753,6 +2773,7 @@ function CrowWidget({
|
|
|
2753
2773
|
});
|
|
2754
2774
|
const agentName = agentNameProp ?? agentNameFromAPI;
|
|
2755
2775
|
const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
|
|
2776
|
+
const selectedModel = selectedModelFromAPI ?? DEFAULT_MODEL;
|
|
2756
2777
|
const showThinking = showThinkingProp ?? showThinkingFromAPI;
|
|
2757
2778
|
const [autoTools, setAutoTools] = useState({});
|
|
2758
2779
|
const cssVars = stylesToCssVars(styles);
|
|
@@ -2775,7 +2796,7 @@ function CrowWidget({
|
|
|
2775
2796
|
productId,
|
|
2776
2797
|
apiUrl,
|
|
2777
2798
|
conversationId: null,
|
|
2778
|
-
selectedModel
|
|
2799
|
+
selectedModel
|
|
2779
2800
|
});
|
|
2780
2801
|
const conversations = useConversations({ productId, apiUrl });
|
|
2781
2802
|
const [shouldRestoreHistory, setShouldRestoreHistory] = useState(false);
|
|
@@ -2785,6 +2806,7 @@ function CrowWidget({
|
|
|
2785
2806
|
apiUrl,
|
|
2786
2807
|
persistAnonymousConversations,
|
|
2787
2808
|
welcomeMessage,
|
|
2809
|
+
selectedModel,
|
|
2788
2810
|
onVerificationStatus: (isVerified) => {
|
|
2789
2811
|
setIsVerifiedUser(isVerified);
|
|
2790
2812
|
},
|
|
@@ -2810,6 +2832,7 @@ function CrowWidget({
|
|
|
2810
2832
|
break;
|
|
2811
2833
|
}
|
|
2812
2834
|
},
|
|
2835
|
+
onToolResult,
|
|
2813
2836
|
onToolCall: async (event) => {
|
|
2814
2837
|
if (event.type === "client_call" && event.toolName && event.toolCallId) {
|
|
2815
2838
|
try {
|
|
@@ -3249,7 +3272,8 @@ function CrowCopilot({
|
|
|
3249
3272
|
styles: propStyles,
|
|
3250
3273
|
previewMode = false,
|
|
3251
3274
|
className,
|
|
3252
|
-
onReady
|
|
3275
|
+
onReady,
|
|
3276
|
+
onToolResult
|
|
3253
3277
|
}) {
|
|
3254
3278
|
const {
|
|
3255
3279
|
styles,
|
|
@@ -3290,6 +3314,7 @@ function CrowCopilot({
|
|
|
3290
3314
|
},
|
|
3291
3315
|
onConversationId: () => {
|
|
3292
3316
|
},
|
|
3317
|
+
onToolResult,
|
|
3293
3318
|
onToolCall: (event) => {
|
|
3294
3319
|
if (event.type === "client_call" && event.toolName) {
|
|
3295
3320
|
console.log(
|