@usecrow/ui 0.1.55 → 0.1.56

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,8 @@ function CrowWidget({
3530
3538
  onToolResult,
3531
3539
  getIdentityToken,
3532
3540
  context,
3533
- toolRenderers
3541
+ toolRenderers,
3542
+ language
3534
3543
  }) {
3535
3544
  const effectiveGetIdentityToken = getIdentityToken || window.__crow_identity_token_fetcher;
3536
3545
  const effectiveOnToolResult = onToolResult || window.__crow_on_tool_result;
@@ -3552,7 +3561,8 @@ function CrowWidget({
3552
3561
  productId,
3553
3562
  apiUrl,
3554
3563
  propStyles,
3555
- skip: previewMode
3564
+ skip: previewMode,
3565
+ language
3556
3566
  });
3557
3567
  const agentName = agentNameProp ?? agentNameFromAPI;
3558
3568
  const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
@@ -3592,6 +3602,7 @@ function CrowWidget({
3592
3602
  selectedModel,
3593
3603
  subdomain,
3594
3604
  toolConsentSettings,
3605
+ language,
3595
3606
  onVerificationStatus: (isVerified) => {
3596
3607
  setIsVerifiedUser(isVerified);
3597
3608
  },
@@ -4352,7 +4363,8 @@ function CrowCopilot({
4352
4363
  onToolResult,
4353
4364
  toolRenderers,
4354
4365
  getIdentityToken,
4355
- context
4366
+ context,
4367
+ language
4356
4368
  }) {
4357
4369
  const effectiveGetIdentityToken = getIdentityToken || window.__crow_identity_token_fetcher;
4358
4370
  const effectiveOnToolResult = onToolResult || window.__crow_on_tool_result;
@@ -4372,7 +4384,8 @@ function CrowCopilot({
4372
4384
  productId,
4373
4385
  apiUrl,
4374
4386
  propStyles,
4375
- skip: previewMode
4387
+ skip: previewMode,
4388
+ language
4376
4389
  });
4377
4390
  const agentName = agentNameProp ?? agentNameFromAPI ?? title;
4378
4391
  const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
@@ -4560,6 +4573,7 @@ function CrowCopilot({
4560
4573
  selectedModel,
4561
4574
  subdomain,
4562
4575
  toolConsentSettings,
4576
+ language,
4563
4577
  onVerificationStatus: (isVerified) => {
4564
4578
  setIsVerifiedUser(isVerified);
4565
4579
  },