@usecrow/ui 0.1.54 → 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
@@ -70,7 +70,9 @@ function useChat({
70
70
  persistAnonymousConversations,
71
71
  welcomeMessage,
72
72
  selectedModel: initialSelectedModel,
73
+ subdomain,
73
74
  toolConsentSettings,
75
+ language,
74
76
  onVerificationStatus,
75
77
  onConversationId,
76
78
  onWorkflowEvent,
@@ -152,10 +154,12 @@ function useChat({
152
154
  conversation_id: conversationId,
153
155
  identity_token: identityToken,
154
156
  model: selectedModel,
157
+ subdomain,
155
158
  user_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
156
159
  user_local_time: (/* @__PURE__ */ new Date()).toLocaleString("en-US", { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric", hour12: true }),
157
160
  page_path: typeof window !== "undefined" ? window.location.pathname : void 0,
158
- 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 } : {}
159
163
  }),
160
164
  signal: abortControllerRef.current.signal
161
165
  });
@@ -484,7 +488,7 @@ function useChat({
484
488
  abortControllerRef.current = null;
485
489
  }
486
490
  },
487
- [apiUrl, productId, conversationId, selectedModel, persistAnonymousConversations, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onToolResult]
491
+ [apiUrl, productId, conversationId, selectedModel, subdomain, persistAnonymousConversations, onVerificationStatus, onConversationId, onWorkflowEvent, onToolCall, onToolResult]
488
492
  );
489
493
  const sendMessage = React3.useCallback(
490
494
  (content) => {
@@ -575,8 +579,10 @@ function useChat({
575
579
  result,
576
580
  identity_token: identityToken,
577
581
  model: selectedModel,
582
+ subdomain,
578
583
  user_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
579
- 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 } : {}
580
586
  })
581
587
  });
582
588
  if (!response.ok) {
@@ -853,7 +859,7 @@ function useChat({
853
859
  setIsLoading(false);
854
860
  }
855
861
  },
856
- [apiUrl, productId, conversationId, selectedModel]
862
+ [apiUrl, productId, conversationId, selectedModel, subdomain]
857
863
  );
858
864
  const addMessage = React3.useCallback(
859
865
  async (role, content) => {
@@ -1537,9 +1543,12 @@ function stylesToCSSVariables(styles) {
1537
1543
 
1538
1544
  // src/hooks/useWidgetStyles.ts
1539
1545
  var styleCache = /* @__PURE__ */ new Map();
1540
- async function fetchWidgetConfig(productId, apiUrl) {
1546
+ async function fetchWidgetConfig(productId, apiUrl, language) {
1541
1547
  const baseUrl = apiUrl || "";
1542
- 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
+ }
1543
1552
  const response = await fetch(url);
1544
1553
  if (!response.ok) {
1545
1554
  throw new Error(`Failed to fetch widget config: ${response.status} ${response.statusText}`);
@@ -1551,9 +1560,10 @@ function useWidgetStyles({
1551
1560
  apiUrl,
1552
1561
  propStyles,
1553
1562
  skip = false,
1554
- cacheKey
1563
+ cacheKey,
1564
+ language
1555
1565
  }) {
1556
- const key = cacheKey || productId;
1566
+ const key = cacheKey || (language && language !== "en" ? `${productId}:${language}` : productId);
1557
1567
  const [isLoading, setIsLoading] = React3.useState(!skip && !styleCache.has(key));
1558
1568
  const [error, setError] = React3.useState(null);
1559
1569
  const [dbStyles, setDbStyles] = React3.useState(
@@ -1593,7 +1603,7 @@ function useWidgetStyles({
1593
1603
  setIsLoading(true);
1594
1604
  setError(null);
1595
1605
  try {
1596
- const config = await fetchWidgetConfig(productId, apiUrl);
1606
+ const config = await fetchWidgetConfig(productId, apiUrl, language);
1597
1607
  styleCache.set(key, config);
1598
1608
  setDbStyles(config.widgetStyles);
1599
1609
  setAgentName(config.agentName || "Assistant");
@@ -1653,9 +1663,10 @@ function useCopilotStyles({
1653
1663
  apiUrl,
1654
1664
  propStyles,
1655
1665
  skip = false,
1656
- cacheKey
1666
+ cacheKey,
1667
+ language
1657
1668
  }) {
1658
- const key = cacheKey || productId;
1669
+ const key = cacheKey || (language && language !== "en" ? `${productId}:${language}` : productId);
1659
1670
  const [isLoading, setIsLoading] = React3.useState(!skip && !styleCache.has(key));
1660
1671
  const [error, setError] = React3.useState(null);
1661
1672
  const [dbStyles, setDbStyles] = React3.useState(
@@ -1689,7 +1700,7 @@ function useCopilotStyles({
1689
1700
  setIsLoading(true);
1690
1701
  setError(null);
1691
1702
  try {
1692
- const config = await fetchWidgetConfig(productId, apiUrl);
1703
+ const config = await fetchWidgetConfig(productId, apiUrl, language);
1693
1704
  styleCache.set(key, config);
1694
1705
  setDbStyles(config.copilotStyles);
1695
1706
  setAgentName(config.agentName || "Assistant");
@@ -3513,6 +3524,7 @@ function injectStyles(target = document) {
3513
3524
  function CrowWidget({
3514
3525
  productId,
3515
3526
  apiUrl = "",
3527
+ subdomain,
3516
3528
  variant = "floating",
3517
3529
  styles: propStyles,
3518
3530
  previewMode = false,
@@ -3526,7 +3538,8 @@ function CrowWidget({
3526
3538
  onToolResult,
3527
3539
  getIdentityToken,
3528
3540
  context,
3529
- toolRenderers
3541
+ toolRenderers,
3542
+ language
3530
3543
  }) {
3531
3544
  const effectiveGetIdentityToken = getIdentityToken || window.__crow_identity_token_fetcher;
3532
3545
  const effectiveOnToolResult = onToolResult || window.__crow_on_tool_result;
@@ -3548,7 +3561,8 @@ function CrowWidget({
3548
3561
  productId,
3549
3562
  apiUrl,
3550
3563
  propStyles,
3551
- skip: previewMode
3564
+ skip: previewMode,
3565
+ language
3552
3566
  });
3553
3567
  const agentName = agentNameProp ?? agentNameFromAPI;
3554
3568
  const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
@@ -3586,7 +3600,9 @@ function CrowWidget({
3586
3600
  persistAnonymousConversations,
3587
3601
  welcomeMessage,
3588
3602
  selectedModel,
3603
+ subdomain,
3589
3604
  toolConsentSettings,
3605
+ language,
3590
3606
  onVerificationStatus: (isVerified) => {
3591
3607
  setIsVerifiedUser(isVerified);
3592
3608
  },
@@ -4329,6 +4345,7 @@ function CopilotContainer({
4329
4345
  function CrowCopilot({
4330
4346
  productId,
4331
4347
  apiUrl = "",
4348
+ subdomain,
4332
4349
  variant = "embedded",
4333
4350
  title = "Copilot",
4334
4351
  agentName: agentNameProp,
@@ -4346,7 +4363,8 @@ function CrowCopilot({
4346
4363
  onToolResult,
4347
4364
  toolRenderers,
4348
4365
  getIdentityToken,
4349
- context
4366
+ context,
4367
+ language
4350
4368
  }) {
4351
4369
  const effectiveGetIdentityToken = getIdentityToken || window.__crow_identity_token_fetcher;
4352
4370
  const effectiveOnToolResult = onToolResult || window.__crow_on_tool_result;
@@ -4366,7 +4384,8 @@ function CrowCopilot({
4366
4384
  productId,
4367
4385
  apiUrl,
4368
4386
  propStyles,
4369
- skip: previewMode
4387
+ skip: previewMode,
4388
+ language
4370
4389
  });
4371
4390
  const agentName = agentNameProp ?? agentNameFromAPI ?? title;
4372
4391
  const welcomeMessage = welcomeMessageProp ?? welcomeMessageFromAPI;
@@ -4552,7 +4571,9 @@ function CrowCopilot({
4552
4571
  persistAnonymousConversations,
4553
4572
  welcomeMessage,
4554
4573
  selectedModel,
4574
+ subdomain,
4555
4575
  toolConsentSettings,
4576
+ language,
4556
4577
  onVerificationStatus: (isVerified) => {
4557
4578
  setIsVerifiedUser(isVerified);
4558
4579
  },
@@ -5439,11 +5460,12 @@ function CrowProvider({
5439
5460
  children,
5440
5461
  productId,
5441
5462
  apiUrl,
5442
- model
5463
+ model,
5464
+ subdomain
5443
5465
  }) {
5444
5466
  const clientRef = React3.useRef(null);
5445
5467
  if (!clientRef.current) {
5446
- clientRef.current = new client.CrowClient({ productId, apiUrl, model });
5468
+ clientRef.current = new client.CrowClient({ productId, apiUrl, model, subdomain });
5447
5469
  }
5448
5470
  const client$1 = clientRef.current;
5449
5471
  React3.useEffect(() => {