@procore/ai-translations 0.5.0 → 0.6.1

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.
@@ -46,6 +46,9 @@ var Config = class _Config {
46
46
  setToolName(name) {
47
47
  this.toolName = name;
48
48
  }
49
+ isBackendTranslationStrategy() {
50
+ return this.ToolConfig.strategy === "backend_translations";
51
+ }
49
52
  getToolName() {
50
53
  return this.toolName;
51
54
  }
@@ -389,6 +392,19 @@ var Storage = class _Storage {
389
392
  }
390
393
  }
391
394
  // ------------------------------------
395
+ // 🗑️ Clear Translation by ID
396
+ // ------------------------------------
397
+ static async deleteById(id) {
398
+ try {
399
+ const db = await _Storage.getDB();
400
+ await db.delete(_Storage.STORE_NAME, id);
401
+ return true;
402
+ } catch (error) {
403
+ console.error("[Storage] Failed to delete by id:", error);
404
+ return false;
405
+ }
406
+ }
407
+ // ------------------------------------
392
408
  // 🗑️ Clear All Translations
393
409
  // ------------------------------------
394
410
  static async clearAll() {
@@ -483,7 +499,9 @@ var TranslationRegistry = class _TranslationRegistry {
483
499
  async removeTextsFromEnqueued(texts, targetLanguage, strategy) {
484
500
  for (const text of texts) {
485
501
  const id = await Storage.generateId(text, targetLanguage, this.tool);
486
- _TranslationRegistry.enqueuedItems.delete(`${id}:${strategy}`);
502
+ _TranslationRegistry.enqueuedItems.delete(
503
+ this.generateEnqueuedKey(id, strategy)
504
+ );
487
505
  }
488
506
  }
489
507
  static removeFromEnqueued(key) {
@@ -492,10 +510,19 @@ var TranslationRegistry = class _TranslationRegistry {
492
510
  generateEnqueuedKey(id, strategy) {
493
511
  return `${id}:${strategy}`;
494
512
  }
495
- async get(text, targetLanguage, tool) {
513
+ async get(text, targetLanguage, tool, config2) {
496
514
  const key = await Hash.generateFromMultiple([text, targetLanguage, tool]);
497
- if (_TranslationRegistry.memoryCache.has(key)) {
498
- return _TranslationRegistry.memoryCache.get(key);
515
+ const cached = _TranslationRegistry.memoryCache.get(key);
516
+ if (cached) {
517
+ if (cached.translationStrategy === "frontend_translations" && config2.isBackendTranslationStrategy()) {
518
+ _TranslationRegistry.memoryCache.delete(key);
519
+ if (cached.translatedText) {
520
+ _TranslationRegistry.originalTextIndex.delete(cached.translatedText);
521
+ }
522
+ await Storage.deleteById(key);
523
+ return void 0;
524
+ }
525
+ return cached;
499
526
  }
500
527
  const translation = await Storage.getTranslation(
501
528
  text,
@@ -503,6 +530,10 @@ var TranslationRegistry = class _TranslationRegistry {
503
530
  tool
504
531
  );
505
532
  if (translation !== void 0) {
533
+ if (translation.translation_strategy === "frontend_translations" && config2.isBackendTranslationStrategy()) {
534
+ await Storage.deleteById(translation.id);
535
+ return void 0;
536
+ }
506
537
  return this.toTranslationRegistryEntry(translation);
507
538
  }
508
539
  return void 0;
@@ -749,19 +780,21 @@ var TranslationManager = class {
749
780
  this.translationProgress.total = queueManager.queueSize(
750
781
  this.currentTranslatorStrategy
751
782
  );
752
- for (const batch of queueManager.generateBatches(
753
- this.translator.getConfig()
754
- )) {
755
- batch.forEach((entry) => this.mfeToBeNotified.add(entry.tool));
756
- const result = await this.translator.processTranslations(
757
- batch.map(
758
- (entry) => this.convertTranslationQueueEntryToTranslationRequest(entry)
759
- )
760
- );
761
- this.setTranslationProgress(batch.length);
762
- await this.updateDatabaseWithTranslations(result);
763
- await this.notifyTranslationCompleted();
764
- }
783
+ do {
784
+ for (const batch of queueManager.generateBatches(
785
+ this.translator.getConfig()
786
+ )) {
787
+ batch.forEach((entry) => this.mfeToBeNotified.add(entry.tool));
788
+ const result = await this.translator.processTranslations(
789
+ batch.map(
790
+ (entry) => this.convertTranslationQueueEntryToTranslationRequest(entry)
791
+ )
792
+ );
793
+ this.setTranslationProgress(batch.length);
794
+ await this.updateDatabaseWithTranslations(result);
795
+ await this.notifyTranslationCompleted();
796
+ }
797
+ } while (queueManager.queueSize(this.currentTranslatorStrategy) > 0);
765
798
  this.resetTranslationProgress();
766
799
  this.publishTranslationProgress();
767
800
  if (this.currentTranslatorStrategy === "frontend_translations") {
@@ -915,8 +948,16 @@ var Client = class {
915
948
  method: "POST",
916
949
  body: JSON.stringify(requests)
917
950
  });
951
+ const responseBody = Array.isArray(data) ? data.map((group) => ({
952
+ ...group,
953
+ translations: Array.isArray(group.translations) ? group.translations.map((t) => ({
954
+ ...t,
955
+ isTranslated: t.isTranslated ?? (!!t.translation && t.translation !== ""),
956
+ retryable: t.retryable ?? true
957
+ })) : []
958
+ })) : data;
918
959
  return {
919
- responseBody: data,
960
+ responseBody,
920
961
  success: true
921
962
  };
922
963
  } catch (error) {
@@ -993,12 +1034,55 @@ var getModelDownloadEventHandler = () => {
993
1034
  }
994
1035
  return _modelDownloadEventHandler;
995
1036
  };
1037
+ var SUPPORTED_LANGUAGES = /* @__PURE__ */ new Set([
1038
+ "ar",
1039
+ "bn",
1040
+ "bg",
1041
+ "zh",
1042
+ "hr",
1043
+ "cs",
1044
+ "da",
1045
+ "nl",
1046
+ "en",
1047
+ "fi",
1048
+ "fr",
1049
+ "de",
1050
+ "el",
1051
+ "he",
1052
+ "hi",
1053
+ "hu",
1054
+ "id",
1055
+ "it",
1056
+ "ja",
1057
+ "kn",
1058
+ "ko",
1059
+ "lt",
1060
+ "mr",
1061
+ "no",
1062
+ "pl",
1063
+ "pt",
1064
+ "ro",
1065
+ "ru",
1066
+ "sk",
1067
+ "sl",
1068
+ "es",
1069
+ "sv",
1070
+ "ta",
1071
+ "te",
1072
+ "th",
1073
+ "tr",
1074
+ "uk",
1075
+ "vi"
1076
+ ]);
996
1077
  var ChromeTranslator = class _ChromeTranslator {
997
1078
  translator;
998
1079
  constructor(translator) {
999
1080
  this.translator = translator;
1000
1081
  }
1001
- static translatorReadyPromise = Promise.resolve();
1082
+ static translatorReadyPromises = /* @__PURE__ */ new Map();
1083
+ static isSupportedLanguage(lang) {
1084
+ return SUPPORTED_LANGUAGES.has(lang) || SUPPORTED_LANGUAGES.has(lang.split("-")[0] ?? "");
1085
+ }
1002
1086
  static ensureRegistry() {
1003
1087
  if (!globalThis.chromeTranslatorRegistry) {
1004
1088
  globalThis.chromeTranslatorRegistry = /* @__PURE__ */ new Map();
@@ -1020,30 +1104,31 @@ var ChromeTranslator = class _ChromeTranslator {
1020
1104
  );
1021
1105
  }
1022
1106
  static async createTranslator(source, target) {
1107
+ const key = this.generateKey(source, target);
1023
1108
  let resolveReady;
1024
- this.translatorReadyPromise = new Promise((resolve) => {
1109
+ const readyPromise = new Promise((resolve) => {
1025
1110
  resolveReady = resolve;
1026
1111
  });
1112
+ this.translatorReadyPromises.set(key, readyPromise);
1027
1113
  let isDownloading = false;
1028
1114
  const translator = await Translator.create({
1029
1115
  sourceLanguage: source,
1030
1116
  targetLanguage: target,
1031
1117
  monitor(m) {
1032
- m.addEventListener(
1033
- "downloadprogress",
1034
- (e) => {
1035
- isDownloading = true;
1036
- const progress = e.total > 0 ? Math.round(e.loaded / e.total * 100) : 0;
1037
- getModelDownloadEventHandler().publishModelDownloadProgressEvent(
1038
- e.loaded,
1039
- e.total,
1040
- progress
1041
- );
1042
- if (e.loaded === e.total) {
1043
- resolveReady();
1044
- }
1118
+ m.addEventListener("downloadprogress", (e) => {
1119
+ isDownloading = true;
1120
+ const loaded = e.loaded ?? 0;
1121
+ const total = e.total ?? 0;
1122
+ const progress = total > 0 ? Math.round(loaded / total * 100) : 0;
1123
+ getModelDownloadEventHandler().publishModelDownloadProgressEvent(
1124
+ loaded,
1125
+ total,
1126
+ progress
1127
+ );
1128
+ if (total > 0 && loaded >= total) {
1129
+ resolveReady();
1045
1130
  }
1046
- );
1131
+ });
1047
1132
  }
1048
1133
  });
1049
1134
  if (!isDownloading) {
@@ -1051,8 +1136,8 @@ var ChromeTranslator = class _ChromeTranslator {
1051
1136
  }
1052
1137
  return translator;
1053
1138
  }
1054
- static waitForReady() {
1055
- return this.translatorReadyPromise;
1139
+ static waitForReady(key) {
1140
+ return this.translatorReadyPromises.get(key) ?? Promise.resolve();
1056
1141
  }
1057
1142
  static async translate(text, targetLanguage) {
1058
1143
  this.ensureRegistry();
@@ -1060,8 +1145,17 @@ var ChromeTranslator = class _ChromeTranslator {
1060
1145
  const detector = await ChromeLanguageDetector.getInstance();
1061
1146
  const sourceLanguage = await detector.detectLanguage(text);
1062
1147
  const key = this.generateKey(sourceLanguage, targetLanguage);
1063
- let instance = globalThis.chromeTranslatorRegistry.get(key);
1064
- if (!instance) {
1148
+ if (!this.isSupportedLanguage(sourceLanguage) || !this.isSupportedLanguage(targetLanguage)) {
1149
+ return {
1150
+ translation: text,
1151
+ sourceLanguage,
1152
+ success: false,
1153
+ retryable: false,
1154
+ errorMessage: `Unsupported language pair: ${sourceLanguage} \u2192 ${targetLanguage}`
1155
+ };
1156
+ }
1157
+ const existingInstance = globalThis.chromeTranslatorRegistry.get(key);
1158
+ if (!existingInstance) {
1065
1159
  const translatorCapabilities = await Translator.availability({
1066
1160
  sourceLanguage,
1067
1161
  targetLanguage
@@ -1079,10 +1173,16 @@ var ChromeTranslator = class _ChromeTranslator {
1079
1173
  sourceLanguage,
1080
1174
  targetLanguage
1081
1175
  );
1082
- instance = new _ChromeTranslator(chromeTranslator);
1083
- globalThis.chromeTranslatorRegistry.set(key, instance);
1176
+ if (!globalThis.chromeTranslatorRegistry.has(key)) {
1177
+ globalThis.chromeTranslatorRegistry.set(
1178
+ key,
1179
+ new _ChromeTranslator(chromeTranslator)
1180
+ );
1181
+ }
1084
1182
  }
1085
- await this.waitForReady();
1183
+ const instance = globalThis.chromeTranslatorRegistry.get(key);
1184
+ await this.waitForReady(key);
1185
+ this.translatorReadyPromises.delete(key);
1086
1186
  const translation = await instance.translator?.translate(text);
1087
1187
  if (!translation) {
1088
1188
  return {
@@ -1090,7 +1190,7 @@ var ChromeTranslator = class _ChromeTranslator {
1090
1190
  sourceLanguage,
1091
1191
  success: false,
1092
1192
  errorMessage: "Translation failed",
1093
- retryable: true
1193
+ retryable: false
1094
1194
  };
1095
1195
  }
1096
1196
  return {
@@ -1100,11 +1200,12 @@ var ChromeTranslator = class _ChromeTranslator {
1100
1200
  retryable: true
1101
1201
  };
1102
1202
  } catch (error) {
1203
+ const message = error instanceof Error ? error.message : "Unknown error";
1103
1204
  return {
1104
1205
  translation: text,
1105
1206
  sourceLanguage: targetLanguage,
1106
1207
  success: false,
1107
- errorMessage: error instanceof Error ? error.message : "Unknown error",
1208
+ errorMessage: message,
1108
1209
  retryable: true
1109
1210
  };
1110
1211
  }
@@ -1261,7 +1362,8 @@ var aitFunction = async (text, translationRegistry, config2, tool) => {
1261
1362
  const existingByOriginal = await translationRegistry.get(
1262
1363
  text,
1263
1364
  targetLanguage,
1264
- tool
1365
+ tool,
1366
+ config2
1265
1367
  );
1266
1368
  if (existingByOriginal && existingByOriginal.isTranslated && existingByOriginal.translatedText && existingByOriginal.translatedText.trim() !== "") {
1267
1369
  return existingByOriginal.translatedText;
@@ -1322,7 +1424,12 @@ function AITranslationInnerProvider(props) {
1322
1424
  companyId,
1323
1425
  userId,
1324
1426
  projectId,
1325
- enableAIT = true
1427
+ enableAIT = true,
1428
+ companyLocale,
1429
+ projectLocale,
1430
+ onTrackAnalyticsEvent,
1431
+ page,
1432
+ scope
1326
1433
  } = props;
1327
1434
  const [translationProgress, setTranslationProgress] = useState(null);
1328
1435
  const [modelDownloadProgress, setModelDownloadProgress] = useState(null);
@@ -1378,15 +1485,15 @@ function AITranslationInnerProvider(props) {
1378
1485
  return () => unsubscribe();
1379
1486
  }, []);
1380
1487
  useEffect(() => {
1381
- if (isFetched && remoteConfig && remoteConfig[tool]) {
1382
- setConfig((prevConfig) => {
1383
- const clonedConfig = prevConfig.clone();
1384
- clonedConfig.setTargetLanguage(locale);
1385
- clonedConfig.setToolConfig(remoteConfig[tool]);
1386
- translator.current.updateConfig(clonedConfig);
1387
- return clonedConfig;
1388
- });
1389
- }
1488
+ if (!isFetched || !remoteConfig) return;
1489
+ const toolConfig = remoteConfig[tool] ?? remoteConfig;
1490
+ setConfig((prevConfig) => {
1491
+ const clonedConfig = prevConfig.clone();
1492
+ clonedConfig.setTargetLanguage(locale);
1493
+ clonedConfig.setToolConfig(toolConfig);
1494
+ translator.current.updateConfig(clonedConfig);
1495
+ return clonedConfig;
1496
+ });
1390
1497
  }, [tool, remoteConfig, isFetched, locale]);
1391
1498
  config2.setTargetLanguage(locale);
1392
1499
  config2.setToolName(tool);
@@ -1399,10 +1506,15 @@ function AITranslationInnerProvider(props) {
1399
1506
  const contextValue = {
1400
1507
  ait,
1401
1508
  locale,
1509
+ companyLocale,
1510
+ projectLocale,
1402
1511
  renderVersion: renderVersionManager.getVersion(),
1403
1512
  translationProgress,
1404
1513
  modelDownloadProgress,
1405
- tool
1514
+ tool,
1515
+ onTrackAnalyticsEvent,
1516
+ page,
1517
+ scope
1406
1518
  };
1407
1519
  return /* @__PURE__ */ jsx(AITranslationContext.Provider, { value: contextValue, children });
1408
1520
  }
@@ -1422,12 +1534,140 @@ function useAITranslation() {
1422
1534
  return ctx;
1423
1535
  }
1424
1536
 
1537
+ // src/hooks/useAIAnalytics.ts
1538
+ import { useContext as useContext2, useCallback as useCallback2 } from "react";
1539
+
1540
+ // src/analytics/events.ts
1541
+ var BUTTON_TYPE = {
1542
+ TRANSLATE: "translate",
1543
+ HIGHLIGHT: "highlight"
1544
+ };
1545
+ var ACTION = {
1546
+ CLICKED: "clicked"
1547
+ };
1548
+ function buildObject(pageContext, buttonType) {
1549
+ return `${pageContext}_${buttonType}_button`;
1550
+ }
1551
+ function buildEventKey(parts) {
1552
+ const { scope, tool, object, action } = parts;
1553
+ return `ux.web.feature.${scope}.${tool}.${object}.${action}`;
1554
+ }
1555
+ function buildAnalyticEvent(params) {
1556
+ const {
1557
+ scope,
1558
+ tool,
1559
+ pageContext,
1560
+ buttonType,
1561
+ baseProperties,
1562
+ action,
1563
+ additionalProperties
1564
+ } = params;
1565
+ const resolvedAction = action ?? ACTION.CLICKED;
1566
+ const object = buildObject(pageContext, buttonType);
1567
+ const key = buildEventKey({
1568
+ scope,
1569
+ tool,
1570
+ object,
1571
+ action: resolvedAction
1572
+ });
1573
+ const properties = {
1574
+ ...baseProperties,
1575
+ ...additionalProperties
1576
+ };
1577
+ return { key, properties };
1578
+ }
1579
+
1580
+ // src/hooks/useAIAnalytics.ts
1581
+ function useAIAnalytics() {
1582
+ const ctx = useContext2(AITranslationContext);
1583
+ if (!ctx) {
1584
+ throw new Error(
1585
+ "useAIAnalytics must be used inside an AITranslationProvider"
1586
+ );
1587
+ }
1588
+ const {
1589
+ locale,
1590
+ companyLocale,
1591
+ projectLocale,
1592
+ tool,
1593
+ page,
1594
+ scope,
1595
+ onTrackAnalyticsEvent
1596
+ } = ctx;
1597
+ const isTrackingEnabled = Boolean(onTrackAnalyticsEvent);
1598
+ const buildBaseProperties = useCallback2(() => {
1599
+ const props = {
1600
+ user_locale: locale,
1601
+ tool,
1602
+ page: page ?? ""
1603
+ };
1604
+ if (companyLocale) props.company_locale = companyLocale;
1605
+ if (projectLocale) props.project_locale = projectLocale;
1606
+ return props;
1607
+ }, [locale, tool, page, companyLocale, projectLocale]);
1608
+ const trackTranslateButtonClicked = useCallback2(
1609
+ (additionalProperties) => {
1610
+ if (!onTrackAnalyticsEvent || !page || !scope) return;
1611
+ onTrackAnalyticsEvent(
1612
+ buildAnalyticEvent({
1613
+ scope,
1614
+ tool,
1615
+ pageContext: page,
1616
+ buttonType: BUTTON_TYPE.TRANSLATE,
1617
+ baseProperties: buildBaseProperties(),
1618
+ additionalProperties
1619
+ })
1620
+ );
1621
+ },
1622
+ [onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
1623
+ );
1624
+ const trackHighlightButtonClicked = useCallback2(
1625
+ (additionalProperties) => {
1626
+ if (!onTrackAnalyticsEvent || !page || !scope) return;
1627
+ onTrackAnalyticsEvent(
1628
+ buildAnalyticEvent({
1629
+ scope,
1630
+ tool,
1631
+ pageContext: page,
1632
+ buttonType: BUTTON_TYPE.HIGHLIGHT,
1633
+ baseProperties: buildBaseProperties(),
1634
+ additionalProperties
1635
+ })
1636
+ );
1637
+ },
1638
+ [onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
1639
+ );
1640
+ const trackCustomEvent = useCallback2(
1641
+ (buttonType, action, additionalProperties) => {
1642
+ if (!onTrackAnalyticsEvent || !page || !scope) return;
1643
+ onTrackAnalyticsEvent(
1644
+ buildAnalyticEvent({
1645
+ scope,
1646
+ tool,
1647
+ pageContext: page,
1648
+ buttonType,
1649
+ baseProperties: buildBaseProperties(),
1650
+ action,
1651
+ additionalProperties
1652
+ })
1653
+ );
1654
+ },
1655
+ [onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
1656
+ );
1657
+ return {
1658
+ trackTranslateButtonClicked,
1659
+ trackHighlightButtonClicked,
1660
+ trackCustomEvent,
1661
+ isTrackingEnabled
1662
+ };
1663
+ }
1664
+
1425
1665
  // src/components/AITranslateText.tsx
1426
1666
  import {
1427
1667
  useState as useState2,
1428
1668
  useEffect as useEffect2,
1429
- useContext as useContext2,
1430
- useCallback as useCallback2,
1669
+ useContext as useContext3,
1670
+ useCallback as useCallback3,
1431
1671
  useRef as useRef2
1432
1672
  } from "react";
1433
1673
 
@@ -1435,8 +1675,8 @@ import {
1435
1675
  import "react";
1436
1676
  import { jsx as jsx2 } from "react/jsx-runtime";
1437
1677
  var TranslatedIcon = ({
1438
- width = 14,
1439
- height = 14,
1678
+ width = 24,
1679
+ height = 24,
1440
1680
  className,
1441
1681
  color = "#000000"
1442
1682
  }) => {
@@ -1449,11 +1689,12 @@ var TranslatedIcon = ({
1449
1689
  className,
1450
1690
  xmlns: "http://www.w3.org/2000/svg",
1451
1691
  "aria-hidden": "true",
1692
+ style: { marginRight: "10px", flexShrink: 0 },
1452
1693
  children: /* @__PURE__ */ jsx2(
1453
1694
  "path",
1454
1695
  {
1455
1696
  fill: color,
1456
- d: "M12.87,15.07l-2.54,-2.51 0.03,-0.03c1.74,-1.94 2.98,-4.17 3.71,-6.53L17,6L17,4h-7L10,2L8,2v2L1,4v1.99h11.17C11.5,7.92 10.44,9.75 9,11.35 8.07,10.32 7.3,9.19 6.69,8h-2c0.73,1.63 1.73,3.17 2.98,4.56l-5.09,5.02L4,19l5,-5 3.11,3.11 0.76,-2.04zM18.5,10h-2L12,22h2l1.12,-3h4.75L21,22h2l-4.5,-12zM15.88,17l1.62,-4.33L19.12,17h-3.24z"
1697
+ d: "M11.99 2C6.47 2 2 6.48 2 12C2 17.52 6.47 22 11.99 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 11.99 2ZM18.92 8H15.97C15.65 6.75 15.19 5.55 14.59 4.44C16.43 5.07 17.96 6.35 18.92 8ZM12 4.04C12.83 5.24 13.48 6.57 13.91 8H10.09C10.52 6.57 11.17 5.24 12 4.04ZM4.26 14C4.1 13.36 4 12.69 4 12C4 11.31 4.1 10.64 4.26 10H7.64C7.56 10.66 7.5 11.32 7.5 12C7.5 12.68 7.56 13.34 7.64 14H4.26ZM5.08 16H8.03C8.35 17.25 8.81 18.45 9.41 19.56C7.57 18.93 6.04 17.66 5.08 16ZM8.03 8H5.08C6.04 6.34 7.57 5.07 9.41 4.44C8.81 5.55 8.35 6.75 8.03 8ZM12 19.96C11.17 18.76 10.52 17.43 10.09 16H13.91C13.48 17.43 12.83 18.76 12 19.96ZM14.34 14H9.66C9.57 13.34 9.5 12.68 9.5 12C9.5 11.32 9.57 10.65 9.66 10H14.34C14.43 10.65 14.5 11.32 14.5 12C14.5 12.68 14.43 13.34 14.34 14ZM14.59 19.56C15.19 18.45 15.65 17.25 15.97 16H18.92C17.96 17.65 16.43 18.93 14.59 19.56ZM16.36 14C16.44 13.34 16.5 12.68 16.5 12C16.5 11.32 16.44 10.66 16.36 10H19.74C19.9 10.64 20 11.31 20 12C20 12.69 19.9 13.36 19.74 14H16.36Z"
1457
1698
  }
1458
1699
  )
1459
1700
  }
@@ -1468,7 +1709,7 @@ var AITranslateText = ({
1468
1709
  showHighlight = false,
1469
1710
  translatedIconProps
1470
1711
  }) => {
1471
- const context = useContext2(AITranslationContext);
1712
+ const context = useContext3(AITranslationContext);
1472
1713
  const [displayText, setDisplayText] = useState2(text ?? "");
1473
1714
  const [showHighlightState, setShowHighlightState] = useState2(showHighlight);
1474
1715
  const eventHandlerRef = useRef2(null);
@@ -1491,7 +1732,7 @@ var AITranslateText = ({
1491
1732
  );
1492
1733
  return () => unsubscribe();
1493
1734
  }, [context, text, showHighlight]);
1494
- const reset = useCallback2(
1735
+ const reset = useCallback3(
1495
1736
  (displayValue = text) => {
1496
1737
  setDisplayText(displayValue);
1497
1738
  setShowHighlightState(false);
@@ -1525,8 +1766,8 @@ var AITranslateText = ({
1525
1766
  };
1526
1767
  }, [text, shouldTranslate, context, showHighlight, reset]);
1527
1768
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1528
- displayText,
1529
- showHighlightState && /* @__PURE__ */ jsx3(TranslatedIcon, { ...translatedIconProps })
1769
+ showHighlightState && /* @__PURE__ */ jsx3(TranslatedIcon, { ...translatedIconProps }),
1770
+ displayText
1530
1771
  ] });
1531
1772
  };
1532
1773
 
@@ -1549,10 +1790,16 @@ var getAITranslationLDId = (domain) => {
1549
1790
  }
1550
1791
  };
1551
1792
  export {
1793
+ ACTION,
1552
1794
  AITranslateText,
1553
1795
  AITranslationProvider,
1554
1796
  AI_TRANSLATION_FEATURE_FLAG_KEY,
1797
+ BUTTON_TYPE,
1798
+ buildAnalyticEvent,
1799
+ buildEventKey,
1800
+ buildObject,
1555
1801
  getAITranslationLDId,
1802
+ useAIAnalytics,
1556
1803
  useAITranslation,
1557
1804
  useConfig
1558
1805
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@procore/ai-translations",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Library that provides a solution to use AI to translate text into a language",
5
5
  "main": "dist/legacy/index.js",
6
6
  "types": "dist/legacy/index.d.ts",