@usecrow/ui 0.1.32 → 0.1.33

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
@@ -699,6 +699,8 @@ interface UseCopilotStylesResult {
699
699
  persistAnonymousConversations: boolean | undefined;
700
700
  /** Custom welcome message (undefined uses SDK default) */
701
701
  welcomeMessage: string | undefined;
702
+ /** AI model configured for this product */
703
+ selectedModel: string | undefined;
702
704
  /** Refetch styles from API */
703
705
  refetch: () => Promise<void>;
704
706
  }
package/dist/index.d.ts CHANGED
@@ -699,6 +699,8 @@ interface UseCopilotStylesResult {
699
699
  persistAnonymousConversations: boolean | undefined;
700
700
  /** Custom welcome message (undefined uses SDK default) */
701
701
  welcomeMessage: string | undefined;
702
+ /** AI model configured for this product */
703
+ selectedModel: string | undefined;
702
704
  /** Refetch styles from API */
703
705
  refetch: () => Promise<void>;
704
706
  }
package/dist/index.js CHANGED
@@ -1251,6 +1251,9 @@ function useCopilotStyles({
1251
1251
  const [welcomeMessage, setWelcomeMessage] = useState(
1252
1252
  styleCache.get(key)?.welcomeMessage ?? void 0
1253
1253
  );
1254
+ const [selectedModel, setSelectedModel] = useState(
1255
+ styleCache.get(key)?.model ?? void 0
1256
+ );
1254
1257
  const hasFetchedRef = useRef(false);
1255
1258
  const fetchStyles = async () => {
1256
1259
  if (skip) return;
@@ -1263,6 +1266,7 @@ function useCopilotStyles({
1263
1266
  setAgentName(config.agentName || "Assistant");
1264
1267
  setPersistAnonymousConversations(config.persistAnonymousConversations ?? true);
1265
1268
  setWelcomeMessage(config.welcomeMessage ?? void 0);
1269
+ setSelectedModel(config.model ?? void 0);
1266
1270
  } catch (err) {
1267
1271
  console.error("[CrowCopilot] Failed to fetch styles:", err);
1268
1272
  setError(err instanceof Error ? err : new Error(String(err)));
@@ -1278,6 +1282,7 @@ function useCopilotStyles({
1278
1282
  setAgentName(cached.agentName || "Assistant");
1279
1283
  setPersistAnonymousConversations(cached.persistAnonymousConversations ?? true);
1280
1284
  setWelcomeMessage(cached.welcomeMessage ?? void 0);
1285
+ setSelectedModel(cached.model ?? void 0);
1281
1286
  setIsLoading(false);
1282
1287
  return;
1283
1288
  }
@@ -1292,6 +1297,7 @@ function useCopilotStyles({
1292
1297
  agentName,
1293
1298
  persistAnonymousConversations,
1294
1299
  welcomeMessage,
1300
+ selectedModel,
1295
1301
  refetch: fetchStyles
1296
1302
  };
1297
1303
  }
@@ -3362,7 +3368,8 @@ function CrowCopilot({
3362
3368
  isLoading: isLoadingStyles,
3363
3369
  agentName: agentNameFromAPI,
3364
3370
  persistAnonymousConversations,
3365
- welcomeMessage: welcomeMessageFromAPI
3371
+ welcomeMessage: welcomeMessageFromAPI,
3372
+ selectedModel
3366
3373
  } = useCopilotStyles({
3367
3374
  productId,
3368
3375
  apiUrl,
@@ -3374,6 +3381,7 @@ function CrowCopilot({
3374
3381
  const messagesContainerRef = useRef(null);
3375
3382
  const tabsScrollRef = useRef(null);
3376
3383
  const executeClientToolRef = useRef(null);
3384
+ const submitToolResultRef = useRef(null);
3377
3385
  const [showConversationList, setShowConversationList] = useState(false);
3378
3386
  const [isVerifiedUser, setIsVerifiedUser] = useState(false);
3379
3387
  const [localTabs, setLocalTabs] = useState([
@@ -3392,24 +3400,71 @@ function CrowCopilot({
3392
3400
  apiUrl,
3393
3401
  persistAnonymousConversations,
3394
3402
  welcomeMessage,
3403
+ selectedModel,
3395
3404
  onVerificationStatus: (isVerified) => {
3396
3405
  setIsVerifiedUser(isVerified);
3397
3406
  },
3398
3407
  onConversationId: () => {
3399
3408
  },
3409
+ onWorkflowEvent: (event) => {
3410
+ switch (event.type) {
3411
+ case "started":
3412
+ if (event.name && event.todos) {
3413
+ startWorkflow(event.name, event.todos);
3414
+ }
3415
+ break;
3416
+ case "todo_updated":
3417
+ if (event.todoId && event.todoStatus) {
3418
+ updateTodo(event.todoId, event.todoStatus);
3419
+ }
3420
+ break;
3421
+ case "ended":
3422
+ endWorkflow(2e3);
3423
+ break;
3424
+ case "complete_prompt":
3425
+ markComplete();
3426
+ break;
3427
+ }
3428
+ },
3400
3429
  onToolResult,
3401
- onToolCall: (event) => {
3402
- if (event.type === "client_call" && event.toolName) {
3403
- console.log(
3404
- "[Crow Copilot] Executing client tool:",
3405
- event.toolName,
3406
- event.arguments
3407
- );
3408
- const result = executeClientToolRef.current?.(
3409
- event.toolName,
3410
- event.arguments || {}
3411
- );
3412
- result?.then((r) => console.log("[Crow Copilot] Tool result:", r)).catch((e) => console.error("[Crow Copilot] Tool error:", e));
3430
+ onToolCall: async (event) => {
3431
+ if (event.type === "client_call" && event.toolName && event.toolCallId) {
3432
+ try {
3433
+ const result = await executeClientToolRef.current?.(
3434
+ event.toolName,
3435
+ event.arguments || {}
3436
+ );
3437
+ const resultObj = result;
3438
+ const dataObj = resultObj?.data;
3439
+ const wasUserCancelled = dataObj?.declined === true || typeof resultObj?.error === "string" && resultObj.error.includes("cancelled by user") || typeof resultObj?.error === "string" && resultObj.error.includes("declined");
3440
+ if (wasUserCancelled) {
3441
+ console.log("[Crow Copilot] Tool was cancelled by user");
3442
+ if (submitToolResultRef.current) {
3443
+ await submitToolResultRef.current(
3444
+ event.toolCallId,
3445
+ event.toolName,
3446
+ { success: false, cancelled: true, error: "Action was cancelled by the user." }
3447
+ );
3448
+ }
3449
+ return;
3450
+ }
3451
+ if (result && submitToolResultRef.current) {
3452
+ await submitToolResultRef.current(
3453
+ event.toolCallId,
3454
+ event.toolName,
3455
+ result
3456
+ );
3457
+ }
3458
+ } catch (e) {
3459
+ console.error("[Crow Copilot] Tool error:", e);
3460
+ if (submitToolResultRef.current) {
3461
+ await submitToolResultRef.current(
3462
+ event.toolCallId,
3463
+ event.toolName,
3464
+ { success: false, error: String(e) }
3465
+ );
3466
+ }
3467
+ }
3413
3468
  }
3414
3469
  },
3415
3470
  onRestoredConversation: () => {
@@ -3431,6 +3486,30 @@ function CrowCopilot({
3431
3486
  injectCopilotBodyStyles();
3432
3487
  }
3433
3488
  }, [variant]);
3489
+ const {
3490
+ activeWorkflow,
3491
+ startWorkflow,
3492
+ updateTodo,
3493
+ markComplete,
3494
+ endWorkflow,
3495
+ exitWorkflow
3496
+ } = useWorkflow({
3497
+ productId,
3498
+ apiUrl,
3499
+ conversationId: chat.conversationId,
3500
+ selectedModel: chat.selectedModel,
3501
+ onMessage: (content) => {
3502
+ chat.loadMessages([
3503
+ ...chat.messages,
3504
+ {
3505
+ id: `bot-${Date.now()}`,
3506
+ content,
3507
+ isBot: true,
3508
+ timestamp: /* @__PURE__ */ new Date()
3509
+ }
3510
+ ]);
3511
+ }
3512
+ });
3434
3513
  const { executeClientTool } = useCrowAPI({
3435
3514
  onIdentified: async () => {
3436
3515
  setIsVerifiedUser(true);
@@ -3442,6 +3521,7 @@ function CrowCopilot({
3442
3521
  }
3443
3522
  });
3444
3523
  executeClientToolRef.current = executeClientTool;
3524
+ submitToolResultRef.current = chat.submitToolResult;
3445
3525
  const handleBrowserConfirmation = useCallback(
3446
3526
  (instruction) => {
3447
3527
  return new Promise((resolve) => {
@@ -3458,6 +3538,9 @@ function CrowCopilot({
3458
3538
  },
3459
3539
  []
3460
3540
  );
3541
+ const handleExitWorkflow = async () => {
3542
+ await exitWorkflow();
3543
+ };
3461
3544
  useEffect(() => {
3462
3545
  window.__crow_browser_callbacks = {
3463
3546
  onConfirmation: handleBrowserConfirmation,
@@ -3783,6 +3866,13 @@ function CrowCopilot({
3783
3866
  ),
3784
3867
  showConversationList && !isVerifiedUser && /* @__PURE__ */ jsx("div", { className: "crow-mb-3 crow-rounded-xl crow-bg-gray-50 crow-border crow-border-gray-200 crow-p-4", children: /* @__PURE__ */ jsx("div", { className: "crow-text-sm crow-text-gray-600", children: "Sign in to view conversation history." }) })
3785
3868
  ] }),
3869
+ /* @__PURE__ */ jsx(AnimatePresence, { children: activeWorkflow && /* @__PURE__ */ jsx(
3870
+ WorkflowPanel,
3871
+ {
3872
+ workflow: activeWorkflow,
3873
+ onExit: handleExitWorkflow
3874
+ }
3875
+ ) }),
3786
3876
  /* @__PURE__ */ jsxs(MessagesContainer, { ref: messagesContainerRef, children: [
3787
3877
  /* @__PURE__ */ jsx(
3788
3878
  MessageList,