@usecrow/ui 0.1.55 → 0.1.57

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
@@ -384,8 +384,18 @@ interface CrowWidgetProps {
384
384
  * exists for its name, that component is rendered inline in the chat.
385
385
  */
386
386
  toolRenderers?: ToolRenderers;
387
+ /**
388
+ * ISO 639-1 language code (e.g., "es", "fr", "ja"). When set, the AI
389
+ * responds in that language and the welcome message is translated.
390
+ */
391
+ language?: string;
392
+ /**
393
+ * Custom CSS to inject into the widget's Shadow DOM.
394
+ * Appended after default styles, allowing overrides.
395
+ */
396
+ customCss?: string;
387
397
  }
388
- declare function CrowWidget({ productId, apiUrl, subdomain, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, navigate, onToolResult, getIdentityToken, context, toolRenderers, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
398
+ declare function CrowWidget({ productId, apiUrl, subdomain, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, navigate, onToolResult, getIdentityToken, context, toolRenderers, language, customCss, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
389
399
 
390
400
  interface CrowCopilotProps {
391
401
  /** Product ID for this copilot */
@@ -462,8 +472,13 @@ interface CrowCopilotProps {
462
472
  * ```
463
473
  */
464
474
  context?: Record<string, unknown>;
475
+ /**
476
+ * ISO 639-1 language code (e.g., "es", "fr", "ja"). When set, the AI
477
+ * responds in that language and the welcome message is translated.
478
+ */
479
+ language?: string;
465
480
  }
466
- declare function CrowCopilot({ productId, apiUrl, subdomain, 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;
481
+ declare function CrowCopilot({ productId, apiUrl, subdomain, variant, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, defaultOpen, showClose, onClose, styles: propStyles, previewMode, className, onReady, navigate, onToolResult, toolRenderers, getIdentityToken, context, language, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
467
482
 
468
483
  interface CrowProviderProps extends CrowClientConfig {
469
484
  children: React.ReactNode;
@@ -663,6 +678,8 @@ interface UseChatOptions {
663
678
  toolConsentSettings?: Record<string, {
664
679
  requires_consent: boolean;
665
680
  }>;
681
+ /** ISO 639-1 language code (e.g., "es", "fr") — AI will respond in this language */
682
+ language?: string;
666
683
  onVerificationStatus?: (isVerified: boolean) => void;
667
684
  onConversationId?: (id: string) => void;
668
685
  onWorkflowEvent?: (event: WorkflowEvent) => void;
@@ -670,7 +687,7 @@ interface UseChatOptions {
670
687
  onToolResult?: (toolName: string, result: Record<string, unknown>) => void;
671
688
  onRestoredConversation?: (conversationId: string) => void;
672
689
  }
673
- declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, selectedModel: initialSelectedModel, subdomain, toolConsentSettings, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onToolResult, onRestoredConversation, }: UseChatOptions): {
690
+ declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, selectedModel: initialSelectedModel, subdomain, toolConsentSettings, language, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onToolResult, onRestoredConversation, }: UseChatOptions): {
674
691
  messages: Message[];
675
692
  isLoading: boolean;
676
693
  activeToolCalls: ToolCall[];
@@ -817,6 +834,8 @@ interface UseWidgetStylesOptions {
817
834
  skip?: boolean;
818
835
  /** Cache key override (defaults to productId) */
819
836
  cacheKey?: string;
837
+ /** ISO 639-1 language code for welcome message translation */
838
+ language?: string;
820
839
  }
821
840
  interface UseWidgetStylesResult {
822
841
  /** Fully resolved styles ready for use */
@@ -869,6 +888,8 @@ interface UseCopilotStylesOptions {
869
888
  skip?: boolean;
870
889
  /** Cache key override (defaults to productId) */
871
890
  cacheKey?: string;
891
+ /** ISO 639-1 language code for welcome message translation */
892
+ language?: string;
872
893
  }
873
894
  interface UseCopilotStylesResult {
874
895
  /** Fully resolved styles ready for use */
@@ -914,7 +935,7 @@ interface UseCopilotStylesResult {
914
935
  * });
915
936
  * ```
916
937
  */
917
- declare function useWidgetStyles$1({ productId, apiUrl, propStyles, skip, cacheKey, }: UseWidgetStylesOptions): UseWidgetStylesResult;
938
+ declare function useWidgetStyles$1({ productId, apiUrl, propStyles, skip, cacheKey, language, }: UseWidgetStylesOptions): UseWidgetStylesResult;
918
939
  /**
919
940
  * Hook to fetch and merge copilot styles
920
941
  *
@@ -926,7 +947,7 @@ declare function useWidgetStyles$1({ productId, apiUrl, propStyles, skip, cacheK
926
947
  * });
927
948
  * ```
928
949
  */
929
- declare function useCopilotStyles$1({ productId, apiUrl, propStyles, skip, cacheKey, }: UseCopilotStylesOptions): UseCopilotStylesResult;
950
+ declare function useCopilotStyles$1({ productId, apiUrl, propStyles, skip, cacheKey, language, }: UseCopilotStylesOptions): UseCopilotStylesResult;
930
951
  /**
931
952
  * Clear the style cache (useful for testing or forcing refetch)
932
953
  */
package/dist/index.d.ts CHANGED
@@ -384,8 +384,18 @@ interface CrowWidgetProps {
384
384
  * exists for its name, that component is rendered inline in the chat.
385
385
  */
386
386
  toolRenderers?: ToolRenderers;
387
+ /**
388
+ * ISO 639-1 language code (e.g., "es", "fr", "ja"). When set, the AI
389
+ * responds in that language and the welcome message is translated.
390
+ */
391
+ language?: string;
392
+ /**
393
+ * Custom CSS to inject into the widget's Shadow DOM.
394
+ * Appended after default styles, allowing overrides.
395
+ */
396
+ customCss?: string;
387
397
  }
388
- declare function CrowWidget({ productId, apiUrl, subdomain, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, navigate, onToolResult, getIdentityToken, context, toolRenderers, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
398
+ declare function CrowWidget({ productId, apiUrl, subdomain, variant, styles: propStyles, previewMode, showThinking: showThinkingProp, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, onReady, onIdentify, tools, navigate, onToolResult, getIdentityToken, context, toolRenderers, language, customCss, }: CrowWidgetProps): react_jsx_runtime.JSX.Element;
389
399
 
390
400
  interface CrowCopilotProps {
391
401
  /** Product ID for this copilot */
@@ -462,8 +472,13 @@ interface CrowCopilotProps {
462
472
  * ```
463
473
  */
464
474
  context?: Record<string, unknown>;
475
+ /**
476
+ * ISO 639-1 language code (e.g., "es", "fr", "ja"). When set, the AI
477
+ * responds in that language and the welcome message is translated.
478
+ */
479
+ language?: string;
465
480
  }
466
- declare function CrowCopilot({ productId, apiUrl, subdomain, 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;
481
+ declare function CrowCopilot({ productId, apiUrl, subdomain, variant, title, agentName: agentNameProp, welcomeMessage: welcomeMessageProp, position, width, defaultOpen, showClose, onClose, styles: propStyles, previewMode, className, onReady, navigate, onToolResult, toolRenderers, getIdentityToken, context, language, }: CrowCopilotProps): react_jsx_runtime.JSX.Element;
467
482
 
468
483
  interface CrowProviderProps extends CrowClientConfig {
469
484
  children: React.ReactNode;
@@ -663,6 +678,8 @@ interface UseChatOptions {
663
678
  toolConsentSettings?: Record<string, {
664
679
  requires_consent: boolean;
665
680
  }>;
681
+ /** ISO 639-1 language code (e.g., "es", "fr") — AI will respond in this language */
682
+ language?: string;
666
683
  onVerificationStatus?: (isVerified: boolean) => void;
667
684
  onConversationId?: (id: string) => void;
668
685
  onWorkflowEvent?: (event: WorkflowEvent) => void;
@@ -670,7 +687,7 @@ interface UseChatOptions {
670
687
  onToolResult?: (toolName: string, result: Record<string, unknown>) => void;
671
688
  onRestoredConversation?: (conversationId: string) => void;
672
689
  }
673
- declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, selectedModel: initialSelectedModel, subdomain, toolConsentSettings, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onToolResult, onRestoredConversation, }: UseChatOptions): {
690
+ declare function useChat({ productId, apiUrl, persistAnonymousConversations, welcomeMessage, selectedModel: initialSelectedModel, subdomain, toolConsentSettings, language, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onToolResult, onRestoredConversation, }: UseChatOptions): {
674
691
  messages: Message[];
675
692
  isLoading: boolean;
676
693
  activeToolCalls: ToolCall[];
@@ -817,6 +834,8 @@ interface UseWidgetStylesOptions {
817
834
  skip?: boolean;
818
835
  /** Cache key override (defaults to productId) */
819
836
  cacheKey?: string;
837
+ /** ISO 639-1 language code for welcome message translation */
838
+ language?: string;
820
839
  }
821
840
  interface UseWidgetStylesResult {
822
841
  /** Fully resolved styles ready for use */
@@ -869,6 +888,8 @@ interface UseCopilotStylesOptions {
869
888
  skip?: boolean;
870
889
  /** Cache key override (defaults to productId) */
871
890
  cacheKey?: string;
891
+ /** ISO 639-1 language code for welcome message translation */
892
+ language?: string;
872
893
  }
873
894
  interface UseCopilotStylesResult {
874
895
  /** Fully resolved styles ready for use */
@@ -914,7 +935,7 @@ interface UseCopilotStylesResult {
914
935
  * });
915
936
  * ```
916
937
  */
917
- declare function useWidgetStyles$1({ productId, apiUrl, propStyles, skip, cacheKey, }: UseWidgetStylesOptions): UseWidgetStylesResult;
938
+ declare function useWidgetStyles$1({ productId, apiUrl, propStyles, skip, cacheKey, language, }: UseWidgetStylesOptions): UseWidgetStylesResult;
918
939
  /**
919
940
  * Hook to fetch and merge copilot styles
920
941
  *
@@ -926,7 +947,7 @@ declare function useWidgetStyles$1({ productId, apiUrl, propStyles, skip, cacheK
926
947
  * });
927
948
  * ```
928
949
  */
929
- declare function useCopilotStyles$1({ productId, apiUrl, propStyles, skip, cacheKey, }: UseCopilotStylesOptions): UseCopilotStylesResult;
950
+ declare function useCopilotStyles$1({ productId, apiUrl, propStyles, skip, cacheKey, language, }: UseCopilotStylesOptions): UseCopilotStylesResult;
930
951
  /**
931
952
  * Clear the style cache (useful for testing or forcing refetch)
932
953
  */
package/dist/index.js CHANGED
@@ -46,6 +46,7 @@ function useChat({
46
46
  selectedModel: initialSelectedModel,
47
47
  subdomain,
48
48
  toolConsentSettings,
49
+ language,
49
50
  onVerificationStatus,
50
51
  onConversationId,
51
52
  onWorkflowEvent,
@@ -131,7 +132,8 @@ function useChat({
131
132
  user_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
132
133
  user_local_time: (/* @__PURE__ */ new Date()).toLocaleString("en-US", { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", hour12: true }),
133
134
  page_path: typeof window !== "undefined" ? window.location.pathname : void 0,
134
- context: typeof window !== "undefined" ? window.__crow_page_context : void 0
135
+ context: typeof window !== "undefined" ? window.__crow_page_context : void 0,
136
+ ...language && language !== "en" ? { language } : {}
135
137
  }),
136
138
  signal: abortControllerRef.current.signal
137
139
  });
@@ -553,7 +555,8 @@ function useChat({
553
555
  model: selectedModel,
554
556
  subdomain,
555
557
  user_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
556
- user_local_time: (/* @__PURE__ */ new Date()).toLocaleString("en-US", { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", hour12: true })
558
+ user_local_time: (/* @__PURE__ */ new Date()).toLocaleString("en-US", { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", hour12: true }),
559
+ ...language && language !== "en" ? { language } : {}
557
560
  })
558
561
  });
559
562
  if (!response.ok) {
@@ -1514,9 +1517,12 @@ function stylesToCSSVariables(styles) {
1514
1517
 
1515
1518
  // src/hooks/useWidgetStyles.ts
1516
1519
  var styleCache = /* @__PURE__ */ new Map();
1517
- async function fetchWidgetConfig(productId, apiUrl) {
1520
+ async function fetchWidgetConfig(productId, apiUrl, language) {
1518
1521
  const baseUrl = apiUrl || "";
1519
- const url = `${baseUrl}/api/products/${productId}/widget-config`;
1522
+ let url = `${baseUrl}/api/products/${productId}/widget-config`;
1523
+ if (language && language !== "en") {
1524
+ url += `?language=${encodeURIComponent(language)}`;
1525
+ }
1520
1526
  const response = await fetch(url);
1521
1527
  if (!response.ok) {
1522
1528
  throw new Error(`Failed to fetch widget config: ${response.status} ${response.statusText}`);
@@ -1528,9 +1534,10 @@ function useWidgetStyles({
1528
1534
  apiUrl,
1529
1535
  propStyles,
1530
1536
  skip = false,
1531
- cacheKey
1537
+ cacheKey,
1538
+ language
1532
1539
  }) {
1533
- const key = cacheKey || productId;
1540
+ const key = cacheKey || (language && language !== "en" ? `${productId}:${language}` : productId);
1534
1541
  const [isLoading, setIsLoading] = useState(!skip && !styleCache.has(key));
1535
1542
  const [error, setError] = useState(null);
1536
1543
  const [dbStyles, setDbStyles] = useState(
@@ -1570,7 +1577,7 @@ function useWidgetStyles({
1570
1577
  setIsLoading(true);
1571
1578
  setError(null);
1572
1579
  try {
1573
- const config = await fetchWidgetConfig(productId, apiUrl);
1580
+ const config = await fetchWidgetConfig(productId, apiUrl, language);
1574
1581
  styleCache.set(key, config);
1575
1582
  setDbStyles(config.widgetStyles);
1576
1583
  setAgentName(config.agentName || "Assistant");
@@ -1630,9 +1637,10 @@ function useCopilotStyles({
1630
1637
  apiUrl,
1631
1638
  propStyles,
1632
1639
  skip = false,
1633
- cacheKey
1640
+ cacheKey,
1641
+ language
1634
1642
  }) {
1635
- const key = cacheKey || productId;
1643
+ const key = cacheKey || (language && language !== "en" ? `${productId}:${language}` : productId);
1636
1644
  const [isLoading, setIsLoading] = useState(!skip && !styleCache.has(key));
1637
1645
  const [error, setError] = useState(null);
1638
1646
  const [dbStyles, setDbStyles] = useState(
@@ -1666,7 +1674,7 @@ function useCopilotStyles({
1666
1674
  setIsLoading(true);
1667
1675
  setError(null);
1668
1676
  try {
1669
- const config = await fetchWidgetConfig(productId, apiUrl);
1677
+ const config = await fetchWidgetConfig(productId, apiUrl, language);
1670
1678
  styleCache.set(key, config);
1671
1679
  setDbStyles(config.copilotStyles);
1672
1680
  setAgentName(config.agentName || "Assistant");
@@ -3504,7 +3512,9 @@ function CrowWidget({
3504
3512
  onToolResult,
3505
3513
  getIdentityToken,
3506
3514
  context,
3507
- toolRenderers
3515
+ toolRenderers,
3516
+ language,
3517
+ customCss
3508
3518
  }) {
3509
3519
  const effectiveGetIdentityToken = getIdentityToken || window.__crow_identity_token_fetcher;
3510
3520
  const effectiveOnToolResult = onToolResult || window.__crow_on_tool_result;
@@ -3526,7 +3536,8 @@ function CrowWidget({
3526
3536
  productId,
3527
3537
  apiUrl,
3528
3538
  propStyles,
3529
- skip: previewMode
3539
+ skip: previewMode,
3540
+ language
3530
3541
  });
3531
3542
  const agentName = agentNameProp ?? agentNameFromAPI;
3532
3543
  const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
@@ -3566,6 +3577,7 @@ function CrowWidget({
3566
3577
  selectedModel,
3567
3578
  subdomain,
3568
3579
  toolConsentSettings,
3580
+ language,
3569
3581
  onVerificationStatus: (isVerified) => {
3570
3582
  setIsVerifiedUser(isVerified);
3571
3583
  },
@@ -4028,7 +4040,14 @@ function CrowWidget({
4028
4040
  )
4029
4041
  ] })
4030
4042
  ] });
4031
- return /* @__PURE__ */ jsx(ShadowContainer, { styles: WIDGET_CSS, children: /* @__PURE__ */ jsx("div", { className: "crow-widget-root", style: cssVars, children: /* @__PURE__ */ jsxs(
4043
+ const combinedStyles = useMemo(
4044
+ () => customCss ? `${WIDGET_CSS}
4045
+
4046
+ /* Custom CSS */
4047
+ ${customCss}` : WIDGET_CSS,
4048
+ [customCss]
4049
+ );
4050
+ return /* @__PURE__ */ jsx(ShadowContainer, { styles: combinedStyles, children: /* @__PURE__ */ jsx("div", { className: "crow-widget-root", style: cssVars, children: /* @__PURE__ */ jsxs(
4032
4051
  WidgetStyleProvider,
4033
4052
  {
4034
4053
  styles,
@@ -4326,7 +4345,8 @@ function CrowCopilot({
4326
4345
  onToolResult,
4327
4346
  toolRenderers,
4328
4347
  getIdentityToken,
4329
- context
4348
+ context,
4349
+ language
4330
4350
  }) {
4331
4351
  const effectiveGetIdentityToken = getIdentityToken || window.__crow_identity_token_fetcher;
4332
4352
  const effectiveOnToolResult = onToolResult || window.__crow_on_tool_result;
@@ -4346,7 +4366,8 @@ function CrowCopilot({
4346
4366
  productId,
4347
4367
  apiUrl,
4348
4368
  propStyles,
4349
- skip: previewMode
4369
+ skip: previewMode,
4370
+ language
4350
4371
  });
4351
4372
  const agentName = agentNameProp ?? agentNameFromAPI ?? title;
4352
4373
  const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
@@ -4534,6 +4555,7 @@ function CrowCopilot({
4534
4555
  selectedModel,
4535
4556
  subdomain,
4536
4557
  toolConsentSettings,
4558
+ language,
4537
4559
  onVerificationStatus: (isVerified) => {
4538
4560
  setIsVerifiedUser(isVerified);
4539
4561
  },