@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.cjs CHANGED
@@ -72,6 +72,7 @@ function useChat({
72
72
  selectedModel: initialSelectedModel,
73
73
  subdomain,
74
74
  toolConsentSettings,
75
+ language,
75
76
  onVerificationStatus,
76
77
  onConversationId,
77
78
  onWorkflowEvent,
@@ -157,7 +158,8 @@ function useChat({
157
158
  user_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
158
159
  user_local_time: (/* @__PURE__ */ new Date()).toLocaleString("en-US", { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", hour12: true }),
159
160
  page_path: typeof window !== "undefined" ? window.location.pathname : void 0,
160
- context: typeof window !== "undefined" ? window.__crow_page_context : void 0
161
+ context: typeof window !== "undefined" ? window.__crow_page_context : void 0,
162
+ ...language && language !== "en" ? { language } : {}
161
163
  }),
162
164
  signal: abortControllerRef.current.signal
163
165
  });
@@ -579,7 +581,8 @@ function useChat({
579
581
  model: selectedModel,
580
582
  subdomain,
581
583
  user_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
582
- user_local_time: (/* @__PURE__ */ new Date()).toLocaleString("en-US", { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", hour12: true })
584
+ user_local_time: (/* @__PURE__ */ new Date()).toLocaleString("en-US", { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", hour12: true }),
585
+ ...language && language !== "en" ? { language } : {}
583
586
  })
584
587
  });
585
588
  if (!response.ok) {
@@ -1540,9 +1543,12 @@ function stylesToCSSVariables(styles) {
1540
1543
 
1541
1544
  // src/hooks/useWidgetStyles.ts
1542
1545
  var styleCache = /* @__PURE__ */ new Map();
1543
- async function fetchWidgetConfig(productId, apiUrl) {
1546
+ async function fetchWidgetConfig(productId, apiUrl, language) {
1544
1547
  const baseUrl = apiUrl || "";
1545
- const url = `${baseUrl}/api/products/${productId}/widget-config`;
1548
+ let url = `${baseUrl}/api/products/${productId}/widget-config`;
1549
+ if (language && language !== "en") {
1550
+ url += `?language=${encodeURIComponent(language)}`;
1551
+ }
1546
1552
  const response = await fetch(url);
1547
1553
  if (!response.ok) {
1548
1554
  throw new Error(`Failed to fetch widget config: ${response.status} ${response.statusText}`);
@@ -1554,9 +1560,10 @@ function useWidgetStyles({
1554
1560
  apiUrl,
1555
1561
  propStyles,
1556
1562
  skip = false,
1557
- cacheKey
1563
+ cacheKey,
1564
+ language
1558
1565
  }) {
1559
- const key = cacheKey || productId;
1566
+ const key = cacheKey || (language && language !== "en" ? `${productId}:${language}` : productId);
1560
1567
  const [isLoading, setIsLoading] = React3.useState(!skip && !styleCache.has(key));
1561
1568
  const [error, setError] = React3.useState(null);
1562
1569
  const [dbStyles, setDbStyles] = React3.useState(
@@ -1596,7 +1603,7 @@ function useWidgetStyles({
1596
1603
  setIsLoading(true);
1597
1604
  setError(null);
1598
1605
  try {
1599
- const config = await fetchWidgetConfig(productId, apiUrl);
1606
+ const config = await fetchWidgetConfig(productId, apiUrl, language);
1600
1607
  styleCache.set(key, config);
1601
1608
  setDbStyles(config.widgetStyles);
1602
1609
  setAgentName(config.agentName || "Assistant");
@@ -1656,9 +1663,10 @@ function useCopilotStyles({
1656
1663
  apiUrl,
1657
1664
  propStyles,
1658
1665
  skip = false,
1659
- cacheKey
1666
+ cacheKey,
1667
+ language
1660
1668
  }) {
1661
- const key = cacheKey || productId;
1669
+ const key = cacheKey || (language && language !== "en" ? `${productId}:${language}` : productId);
1662
1670
  const [isLoading, setIsLoading] = React3.useState(!skip && !styleCache.has(key));
1663
1671
  const [error, setError] = React3.useState(null);
1664
1672
  const [dbStyles, setDbStyles] = React3.useState(
@@ -1692,7 +1700,7 @@ function useCopilotStyles({
1692
1700
  setIsLoading(true);
1693
1701
  setError(null);
1694
1702
  try {
1695
- const config = await fetchWidgetConfig(productId, apiUrl);
1703
+ const config = await fetchWidgetConfig(productId, apiUrl, language);
1696
1704
  styleCache.set(key, config);
1697
1705
  setDbStyles(config.copilotStyles);
1698
1706
  setAgentName(config.agentName || "Assistant");
@@ -3530,7 +3538,9 @@ function CrowWidget({
3530
3538
  onToolResult,
3531
3539
  getIdentityToken,
3532
3540
  context,
3533
- toolRenderers
3541
+ toolRenderers,
3542
+ language,
3543
+ customCss
3534
3544
  }) {
3535
3545
  const effectiveGetIdentityToken = getIdentityToken || window.__crow_identity_token_fetcher;
3536
3546
  const effectiveOnToolResult = onToolResult || window.__crow_on_tool_result;
@@ -3552,7 +3562,8 @@ function CrowWidget({
3552
3562
  productId,
3553
3563
  apiUrl,
3554
3564
  propStyles,
3555
- skip: previewMode
3565
+ skip: previewMode,
3566
+ language
3556
3567
  });
3557
3568
  const agentName = agentNameProp ?? agentNameFromAPI;
3558
3569
  const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
@@ -3592,6 +3603,7 @@ function CrowWidget({
3592
3603
  selectedModel,
3593
3604
  subdomain,
3594
3605
  toolConsentSettings,
3606
+ language,
3595
3607
  onVerificationStatus: (isVerified) => {
3596
3608
  setIsVerifiedUser(isVerified);
3597
3609
  },
@@ -4054,7 +4066,14 @@ function CrowWidget({
4054
4066
  )
4055
4067
  ] })
4056
4068
  ] });
4057
- return /* @__PURE__ */ jsxRuntime.jsx(ShadowContainer, { styles: WIDGET_CSS, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "crow-widget-root", style: cssVars, children: /* @__PURE__ */ jsxRuntime.jsxs(
4069
+ const combinedStyles = React3.useMemo(
4070
+ () => customCss ? `${WIDGET_CSS}
4071
+
4072
+ /* Custom CSS */
4073
+ ${customCss}` : WIDGET_CSS,
4074
+ [customCss]
4075
+ );
4076
+ return /* @__PURE__ */ jsxRuntime.jsx(ShadowContainer, { styles: combinedStyles, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "crow-widget-root", style: cssVars, children: /* @__PURE__ */ jsxRuntime.jsxs(
4058
4077
  WidgetStyleProvider,
4059
4078
  {
4060
4079
  styles,
@@ -4352,7 +4371,8 @@ function CrowCopilot({
4352
4371
  onToolResult,
4353
4372
  toolRenderers,
4354
4373
  getIdentityToken,
4355
- context
4374
+ context,
4375
+ language
4356
4376
  }) {
4357
4377
  const effectiveGetIdentityToken = getIdentityToken || window.__crow_identity_token_fetcher;
4358
4378
  const effectiveOnToolResult = onToolResult || window.__crow_on_tool_result;
@@ -4372,7 +4392,8 @@ function CrowCopilot({
4372
4392
  productId,
4373
4393
  apiUrl,
4374
4394
  propStyles,
4375
- skip: previewMode
4395
+ skip: previewMode,
4396
+ language
4376
4397
  });
4377
4398
  const agentName = agentNameProp ?? agentNameFromAPI ?? title;
4378
4399
  const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
@@ -4560,6 +4581,7 @@ function CrowCopilot({
4560
4581
  selectedModel,
4561
4582
  subdomain,
4562
4583
  toolConsentSettings,
4584
+ language,
4563
4585
  onVerificationStatus: (isVerified) => {
4564
4586
  setIsVerifiedUser(isVerified);
4565
4587
  },