@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.cjs CHANGED
@@ -2924,7 +2924,9 @@ function CrowWidget({
2924
2924
  onIdentify,
2925
2925
  tools,
2926
2926
  navigate,
2927
- onToolResult
2927
+ onToolResult,
2928
+ getIdentityToken,
2929
+ context
2928
2930
  }) {
2929
2931
  const {
2930
2932
  styles,
@@ -3102,6 +3104,35 @@ function CrowWidget({
3102
3104
  onIdentify(identify);
3103
3105
  }
3104
3106
  }, [isLoadingStyles, onIdentify]);
3107
+ React3.useEffect(() => {
3108
+ if (!getIdentityToken || isLoadingStyles) return;
3109
+ let cancelled = false;
3110
+ const identify = async () => {
3111
+ try {
3112
+ const token = await getIdentityToken();
3113
+ if (!cancelled && token) {
3114
+ window.crow?.("identify", { token });
3115
+ }
3116
+ } catch (e) {
3117
+ console.error("[Crow] getIdentityToken failed:", e);
3118
+ }
3119
+ };
3120
+ identify();
3121
+ const handleRefresh = () => identify();
3122
+ window.addEventListener("crow:token-refresh-needed", handleRefresh);
3123
+ return () => {
3124
+ cancelled = true;
3125
+ window.removeEventListener("crow:token-refresh-needed", handleRefresh);
3126
+ };
3127
+ }, [getIdentityToken, isLoadingStyles]);
3128
+ React3.useEffect(() => {
3129
+ if (typeof window === "undefined") return;
3130
+ if (context && Object.keys(context).length > 0) {
3131
+ window.__crow_page_context = context;
3132
+ } else {
3133
+ window.__crow_page_context = void 0;
3134
+ }
3135
+ }, [context]);
3105
3136
  const handleBrowserConfirmation = React3.useCallback(
3106
3137
  (instruction) => {
3107
3138
  return new Promise((resolve) => {
@@ -3463,7 +3494,9 @@ function CrowCopilot({
3463
3494
  onReady,
3464
3495
  navigate,
3465
3496
  onToolResult,
3466
- toolRenderers
3497
+ toolRenderers,
3498
+ getIdentityToken,
3499
+ context
3467
3500
  }) {
3468
3501
  const {
3469
3502
  styles,
@@ -3680,6 +3713,35 @@ function CrowCopilot({
3680
3713
  onReady?.();
3681
3714
  }
3682
3715
  }, [isLoadingStyles, onReady]);
3716
+ React3.useEffect(() => {
3717
+ if (!getIdentityToken || isLoadingStyles) return;
3718
+ let cancelled = false;
3719
+ const identify = async () => {
3720
+ try {
3721
+ const token = await getIdentityToken();
3722
+ if (!cancelled && token) {
3723
+ window.crow?.("identify", { token });
3724
+ }
3725
+ } catch (e) {
3726
+ console.error("[Crow] getIdentityToken failed:", e);
3727
+ }
3728
+ };
3729
+ identify();
3730
+ const handleRefresh = () => identify();
3731
+ window.addEventListener("crow:token-refresh-needed", handleRefresh);
3732
+ return () => {
3733
+ cancelled = true;
3734
+ window.removeEventListener("crow:token-refresh-needed", handleRefresh);
3735
+ };
3736
+ }, [getIdentityToken, isLoadingStyles]);
3737
+ React3.useEffect(() => {
3738
+ if (typeof window === "undefined") return;
3739
+ if (context && Object.keys(context).length > 0) {
3740
+ window.__crow_page_context = context;
3741
+ } else {
3742
+ window.__crow_page_context = void 0;
3743
+ }
3744
+ }, [context]);
3683
3745
  const handleSend = (message) => {
3684
3746
  if (!message.trim()) return;
3685
3747
  chat.sendMessage(message);