@usecrow/ui 0.1.40 → 0.1.41

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
@@ -243,8 +243,19 @@ interface CrowWidgetProps {
243
243
  navigate?: (path: string) => void;
244
244
  /** Callback fired when a server-side tool completes, with the tool name and full result data */
245
245
  onToolResult?: (toolName: string, result: Record<string, unknown>) => void;
246
+ /**
247
+ * Async function that returns a JWT for user identity verification.
248
+ * Called on mount and automatically on 401 (token refresh).
249
+ * Preferred over onIdentify for simpler integration.
250
+ */
251
+ getIdentityToken?: () => Promise<string>;
252
+ /**
253
+ * Page context data sent with every message. Reactive — updates whenever
254
+ * the object reference changes. Replaces window.crow('setContext', ...).
255
+ */
256
+ context?: Record<string, unknown>;
246
257
  }
247
- declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, navigate, onToolResult, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
258
+ declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, navigate, onToolResult, getIdentityToken, context, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
248
259
 
249
260
  /**
250
261
  * Shared TypeScript interfaces for the widget and copilot
@@ -399,8 +410,33 @@ interface CrowCopilotProps {
399
410
  * ```
400
411
  */
401
412
  toolRenderers?: ToolRenderers;
413
+ /**
414
+ * Async function that returns a JWT for user identity verification.
415
+ * Called on mount and automatically on 401 (token refresh).
416
+ * Replaces the need for a separate component calling window.crow('identify').
417
+ *
418
+ * @example
419
+ * ```tsx
420
+ * getIdentityToken={async () => {
421
+ * const res = await fetch('/api/crow-token');
422
+ * const { token } = await res.json();
423
+ * return token;
424
+ * }}
425
+ * ```
426
+ */
427
+ getIdentityToken?: () => Promise<string>;
428
+ /**
429
+ * Page context data sent with every message. Reactive — updates whenever
430
+ * the object reference changes. Replaces window.crow('setContext', ...).
431
+ *
432
+ * @example
433
+ * ```tsx
434
+ * context={{ cmsContentItemId: "abc-123", agentBlogId: "def-456" }}
435
+ * ```
436
+ */
437
+ context?: Record<string, unknown>;
402
438
  }
403
- declare function CrowCopilot({ productId, apiUrl, variant, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, defaultOpen, showClose, onClose, styles: propStyles, previewMode, className, onReady, navigate, onToolResult, toolRenderers, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
439
+ declare function CrowCopilot({ productId, apiUrl, variant, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, defaultOpen, showClose, onClose, styles: propStyles, previewMode, className, onReady, navigate, onToolResult, toolRenderers, getIdentityToken, context, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
404
440
 
405
441
  interface CrowProviderProps extends CrowClientConfig {
406
442
  children: React.ReactNode;
package/dist/index.d.ts CHANGED
@@ -243,8 +243,19 @@ interface CrowWidgetProps {
243
243
  navigate?: (path: string) => void;
244
244
  /** Callback fired when a server-side tool completes, with the tool name and full result data */
245
245
  onToolResult?: (toolName: string, result: Record<string, unknown>) => void;
246
+ /**
247
+ * Async function that returns a JWT for user identity verification.
248
+ * Called on mount and automatically on 401 (token refresh).
249
+ * Preferred over onIdentify for simpler integration.
250
+ */
251
+ getIdentityToken?: () => Promise<string>;
252
+ /**
253
+ * Page context data sent with every message. Reactive — updates whenever
254
+ * the object reference changes. Replaces window.crow('setContext', ...).
255
+ */
256
+ context?: Record<string, unknown>;
246
257
  }
247
- declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, navigate, onToolResult, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
258
+ declare function CrowWidget({ productId, apiUrl, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, navigate, onToolResult, getIdentityToken, context, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
248
259
 
249
260
  /**
250
261
  * Shared TypeScript interfaces for the widget and copilot
@@ -399,8 +410,33 @@ interface CrowCopilotProps {
399
410
  * ```
400
411
  */
401
412
  toolRenderers?: ToolRenderers;
413
+ /**
414
+ * Async function that returns a JWT for user identity verification.
415
+ * Called on mount and automatically on 401 (token refresh).
416
+ * Replaces the need for a separate component calling window.crow('identify').
417
+ *
418
+ * @example
419
+ * ```tsx
420
+ * getIdentityToken={async () => {
421
+ * const res = await fetch('/api/crow-token');
422
+ * const { token } = await res.json();
423
+ * return token;
424
+ * }}
425
+ * ```
426
+ */
427
+ getIdentityToken?: () => Promise<string>;
428
+ /**
429
+ * Page context data sent with every message. Reactive — updates whenever
430
+ * the object reference changes. Replaces window.crow('setContext', ...).
431
+ *
432
+ * @example
433
+ * ```tsx
434
+ * context={{ cmsContentItemId: "abc-123", agentBlogId: "def-456" }}
435
+ * ```
436
+ */
437
+ context?: Record<string, unknown>;
402
438
  }
403
- declare function CrowCopilot({ productId, apiUrl, variant, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, defaultOpen, showClose, onClose, styles: propStyles, previewMode, className, onReady, navigate, onToolResult, toolRenderers, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
439
+ declare function CrowCopilot({ productId, apiUrl, variant, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, defaultOpen, showClose, onClose, styles: propStyles, previewMode, className, onReady, navigate, onToolResult, toolRenderers, getIdentityToken, context, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
404
440
 
405
441
  interface CrowProviderProps extends CrowClientConfig {
406
442
  children: React.ReactNode;
package/dist/index.js CHANGED
@@ -2898,7 +2898,9 @@ function CrowWidget({
2898
2898
  onIdentify,
2899
2899
  tools,
2900
2900
  navigate,
2901
- onToolResult
2901
+ onToolResult,
2902
+ getIdentityToken,
2903
+ context
2902
2904
  }) {
2903
2905
  const {
2904
2906
  styles,
@@ -3076,6 +3078,35 @@ function CrowWidget({
3076
3078
  onIdentify(identify);
3077
3079
  }
3078
3080
  }, [isLoadingStyles, onIdentify]);
3081
+ useEffect(() => {
3082
+ if (!getIdentityToken || isLoadingStyles) return;
3083
+ let cancelled = false;
3084
+ const identify = async () => {
3085
+ try {
3086
+ const token = await getIdentityToken();
3087
+ if (!cancelled && token) {
3088
+ window.crow?.("identify", { token });
3089
+ }
3090
+ } catch (e) {
3091
+ console.error("[Crow] getIdentityToken failed:", e);
3092
+ }
3093
+ };
3094
+ identify();
3095
+ const handleRefresh = () => identify();
3096
+ window.addEventListener("crow:token-refresh-needed", handleRefresh);
3097
+ return () => {
3098
+ cancelled = true;
3099
+ window.removeEventListener("crow:token-refresh-needed", handleRefresh);
3100
+ };
3101
+ }, [getIdentityToken, isLoadingStyles]);
3102
+ useEffect(() => {
3103
+ if (typeof window === "undefined") return;
3104
+ if (context && Object.keys(context).length > 0) {
3105
+ window.__crow_page_context = context;
3106
+ } else {
3107
+ window.__crow_page_context = void 0;
3108
+ }
3109
+ }, [context]);
3079
3110
  const handleBrowserConfirmation = useCallback(
3080
3111
  (instruction) => {
3081
3112
  return new Promise((resolve) => {
@@ -3437,7 +3468,9 @@ function CrowCopilot({
3437
3468
  onReady,
3438
3469
  navigate,
3439
3470
  onToolResult,
3440
- toolRenderers
3471
+ toolRenderers,
3472
+ getIdentityToken,
3473
+ context
3441
3474
  }) {
3442
3475
  const {
3443
3476
  styles,
@@ -3654,6 +3687,35 @@ function CrowCopilot({
3654
3687
  onReady?.();
3655
3688
  }
3656
3689
  }, [isLoadingStyles, onReady]);
3690
+ useEffect(() => {
3691
+ if (!getIdentityToken || isLoadingStyles) return;
3692
+ let cancelled = false;
3693
+ const identify = async () => {
3694
+ try {
3695
+ const token = await getIdentityToken();
3696
+ if (!cancelled && token) {
3697
+ window.crow?.("identify", { token });
3698
+ }
3699
+ } catch (e) {
3700
+ console.error("[Crow] getIdentityToken failed:", e);
3701
+ }
3702
+ };
3703
+ identify();
3704
+ const handleRefresh = () => identify();
3705
+ window.addEventListener("crow:token-refresh-needed", handleRefresh);
3706
+ return () => {
3707
+ cancelled = true;
3708
+ window.removeEventListener("crow:token-refresh-needed", handleRefresh);
3709
+ };
3710
+ }, [getIdentityToken, isLoadingStyles]);
3711
+ useEffect(() => {
3712
+ if (typeof window === "undefined") return;
3713
+ if (context && Object.keys(context).length > 0) {
3714
+ window.__crow_page_context = context;
3715
+ } else {
3716
+ window.__crow_page_context = void 0;
3717
+ }
3718
+ }, [context]);
3657
3719
  const handleSend = (message) => {
3658
3720
  if (!message.trim()) return;
3659
3721
  chat.sendMessage(message);