@intlayer/cli 8.9.6 → 8.9.8

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.
Files changed (207) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  2. package/dist/cjs/auth/login.cjs +74 -76
  3. package/dist/cjs/auth/login.cjs.map +1 -1
  4. package/dist/cjs/auth/sessionToken.cjs +43 -0
  5. package/dist/cjs/auth/sessionToken.cjs.map +1 -0
  6. package/dist/cjs/build.cjs.map +1 -1
  7. package/dist/cjs/bundle.cjs.map +1 -1
  8. package/dist/cjs/ci.cjs.map +1 -1
  9. package/dist/cjs/cli.cjs.map +1 -1
  10. package/dist/cjs/config.cjs +1 -1
  11. package/dist/cjs/config.cjs.map +1 -1
  12. package/dist/cjs/editor.cjs.map +1 -1
  13. package/dist/cjs/extract.cjs.map +1 -1
  14. package/dist/cjs/fill/deepMergeContent.cjs.map +1 -1
  15. package/dist/cjs/fill/extractTranslatableContent.cjs.map +1 -1
  16. package/dist/cjs/fill/fill.cjs.map +1 -1
  17. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  18. package/dist/cjs/fill/formatFillData.cjs.map +1 -1
  19. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs.map +1 -1
  20. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs.map +1 -1
  21. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
  22. package/dist/cjs/fill/translateDictionary.cjs +2 -2
  23. package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
  24. package/dist/cjs/fill/writeFill.cjs.map +1 -1
  25. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  26. package/dist/cjs/init.cjs.map +1 -1
  27. package/dist/cjs/initMCP.cjs.map +1 -1
  28. package/dist/cjs/initSkills.cjs.map +1 -1
  29. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  30. package/dist/cjs/listProjects.cjs.map +1 -1
  31. package/dist/cjs/liveSync.cjs.map +1 -1
  32. package/dist/cjs/pull.cjs +3 -4
  33. package/dist/cjs/pull.cjs.map +1 -1
  34. package/dist/cjs/push/pullLog.cjs.map +1 -1
  35. package/dist/cjs/push/push.cjs +1 -2
  36. package/dist/cjs/push/push.cjs.map +1 -1
  37. package/dist/cjs/pushConfig.cjs +6 -4
  38. package/dist/cjs/pushConfig.cjs.map +1 -1
  39. package/dist/cjs/pushLog.cjs.map +1 -1
  40. package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
  41. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
  42. package/dist/cjs/searchDoc.cjs.map +1 -1
  43. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  44. package/dist/cjs/test/test.cjs.map +1 -1
  45. package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
  46. package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
  47. package/dist/cjs/translateDoc/validation.cjs.map +1 -1
  48. package/dist/cjs/translation-alignment/alignBlocks.cjs.map +1 -1
  49. package/dist/cjs/translation-alignment/computeSimilarity.cjs.map +1 -1
  50. package/dist/cjs/translation-alignment/fingerprintBlock.cjs.map +1 -1
  51. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs.map +1 -1
  52. package/dist/cjs/translation-alignment/normalizeBlock.cjs.map +1 -1
  53. package/dist/cjs/translation-alignment/pipeline.cjs.map +1 -1
  54. package/dist/cjs/translation-alignment/planActions.cjs.map +1 -1
  55. package/dist/cjs/translation-alignment/rebuildDocument.cjs.map +1 -1
  56. package/dist/cjs/translation-alignment/segmentDocument.cjs.map +1 -1
  57. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  58. package/dist/cjs/utils/checkAccess.cjs +57 -30
  59. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  60. package/dist/cjs/utils/checkConfigConsistency.cjs.map +1 -1
  61. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  62. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  63. package/dist/cjs/utils/chunkInference.cjs +2 -2
  64. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  65. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  66. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  67. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  68. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  69. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  70. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  71. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  72. package/dist/cjs/utils/openBrowser.cjs.map +1 -1
  73. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
  74. package/dist/cjs/utils/setupAI.cjs.map +1 -1
  75. package/dist/cjs/watch.cjs.map +1 -1
  76. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  77. package/dist/esm/auth/login.mjs +74 -76
  78. package/dist/esm/auth/login.mjs.map +1 -1
  79. package/dist/esm/auth/sessionToken.mjs +39 -0
  80. package/dist/esm/auth/sessionToken.mjs.map +1 -0
  81. package/dist/esm/build.mjs.map +1 -1
  82. package/dist/esm/bundle.mjs.map +1 -1
  83. package/dist/esm/ci.mjs.map +1 -1
  84. package/dist/esm/cli.mjs.map +1 -1
  85. package/dist/esm/config.mjs +2 -2
  86. package/dist/esm/config.mjs.map +1 -1
  87. package/dist/esm/editor.mjs.map +1 -1
  88. package/dist/esm/extract.mjs.map +1 -1
  89. package/dist/esm/fill/deepMergeContent.mjs.map +1 -1
  90. package/dist/esm/fill/extractTranslatableContent.mjs.map +1 -1
  91. package/dist/esm/fill/fill.mjs.map +1 -1
  92. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  93. package/dist/esm/fill/formatFillData.mjs.map +1 -1
  94. package/dist/esm/fill/getAvailableLocalesInDictionary.mjs.map +1 -1
  95. package/dist/esm/fill/getFilterMissingContentPerLocale.mjs.map +1 -1
  96. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -1
  97. package/dist/esm/fill/translateDictionary.mjs +2 -2
  98. package/dist/esm/fill/translateDictionary.mjs.map +1 -1
  99. package/dist/esm/fill/writeFill.mjs.map +1 -1
  100. package/dist/esm/getTargetDictionary.mjs.map +1 -1
  101. package/dist/esm/init.mjs.map +1 -1
  102. package/dist/esm/initMCP.mjs.map +1 -1
  103. package/dist/esm/initSkills.mjs.map +1 -1
  104. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  105. package/dist/esm/listProjects.mjs.map +1 -1
  106. package/dist/esm/liveSync.mjs.map +1 -1
  107. package/dist/esm/pull.mjs +4 -5
  108. package/dist/esm/pull.mjs.map +1 -1
  109. package/dist/esm/push/pullLog.mjs.map +1 -1
  110. package/dist/esm/push/push.mjs +2 -3
  111. package/dist/esm/push/push.mjs.map +1 -1
  112. package/dist/esm/pushConfig.mjs +8 -6
  113. package/dist/esm/pushConfig.mjs.map +1 -1
  114. package/dist/esm/pushLog.mjs.map +1 -1
  115. package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
  116. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
  117. package/dist/esm/searchDoc.mjs.map +1 -1
  118. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  119. package/dist/esm/test/test.mjs.map +1 -1
  120. package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
  121. package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
  122. package/dist/esm/translateDoc/validation.mjs.map +1 -1
  123. package/dist/esm/translation-alignment/alignBlocks.mjs.map +1 -1
  124. package/dist/esm/translation-alignment/computeSimilarity.mjs.map +1 -1
  125. package/dist/esm/translation-alignment/fingerprintBlock.mjs.map +1 -1
  126. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs.map +1 -1
  127. package/dist/esm/translation-alignment/normalizeBlock.mjs.map +1 -1
  128. package/dist/esm/translation-alignment/pipeline.mjs.map +1 -1
  129. package/dist/esm/translation-alignment/planActions.mjs.map +1 -1
  130. package/dist/esm/translation-alignment/rebuildDocument.mjs.map +1 -1
  131. package/dist/esm/translation-alignment/segmentDocument.mjs.map +1 -1
  132. package/dist/esm/utils/calculateChunks.mjs.map +1 -1
  133. package/dist/esm/utils/checkAccess.mjs +57 -31
  134. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  135. package/dist/esm/utils/checkConfigConsistency.mjs.map +1 -1
  136. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  137. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
  138. package/dist/esm/utils/chunkInference.mjs +2 -2
  139. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  140. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
  141. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
  142. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
  143. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  144. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
  145. package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
  146. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
  147. package/dist/esm/utils/openBrowser.mjs.map +1 -1
  148. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
  149. package/dist/esm/utils/setupAI.mjs.map +1 -1
  150. package/dist/esm/watch.mjs.map +1 -1
  151. package/dist/types/IntlayerEventListener.d.ts.map +1 -1
  152. package/dist/types/auth/login.d.ts.map +1 -1
  153. package/dist/types/auth/sessionToken.d.ts +13 -0
  154. package/dist/types/auth/sessionToken.d.ts.map +1 -0
  155. package/dist/types/build.d.ts.map +1 -1
  156. package/dist/types/bundle.d.ts.map +1 -1
  157. package/dist/types/cli.d.ts.map +1 -1
  158. package/dist/types/config.d.ts.map +1 -1
  159. package/dist/types/editor.d.ts.map +1 -1
  160. package/dist/types/extract.d.ts.map +1 -1
  161. package/dist/types/fill/extractTranslatableContent.d.ts.map +1 -1
  162. package/dist/types/fill/fill.d.ts.map +1 -1
  163. package/dist/types/fill/formatFillData.d.ts.map +1 -1
  164. package/dist/types/fill/getAvailableLocalesInDictionary.d.ts.map +1 -1
  165. package/dist/types/fill/translateDictionary.d.ts +1 -2
  166. package/dist/types/fill/translateDictionary.d.ts.map +1 -1
  167. package/dist/types/index.d.ts +4 -4
  168. package/dist/types/init.d.ts.map +1 -1
  169. package/dist/types/initSkills.d.ts.map +1 -1
  170. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  171. package/dist/types/listProjects.d.ts.map +1 -1
  172. package/dist/types/liveSync.d.ts.map +1 -1
  173. package/dist/types/pull.d.ts.map +1 -1
  174. package/dist/types/push/pullLog.d.ts.map +1 -1
  175. package/dist/types/push/push.d.ts.map +1 -1
  176. package/dist/types/pushConfig.d.ts.map +1 -1
  177. package/dist/types/pushLog.d.ts.map +1 -1
  178. package/dist/types/searchDoc.d.ts.map +1 -1
  179. package/dist/types/test/test.d.ts.map +1 -1
  180. package/dist/types/translateDoc/types.d.ts.map +1 -1
  181. package/dist/types/translateDoc/validation.d.ts.map +1 -1
  182. package/dist/types/translation-alignment/computeSimilarity.d.ts.map +1 -1
  183. package/dist/types/translation-alignment/normalizeBlock.d.ts.map +1 -1
  184. package/dist/types/translation-alignment/pipeline.d.ts.map +1 -1
  185. package/dist/types/translation-alignment/rebuildDocument.d.ts.map +1 -1
  186. package/dist/types/translation-alignment/segmentDocument.d.ts.map +1 -1
  187. package/dist/types/translation-alignment/types.d.ts.map +1 -1
  188. package/dist/types/utils/calculateChunks.d.ts.map +1 -1
  189. package/dist/types/utils/checkAccess.d.ts +3 -2
  190. package/dist/types/utils/checkAccess.d.ts.map +1 -1
  191. package/dist/types/utils/checkConfigConsistency.d.ts.map +1 -1
  192. package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
  193. package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
  194. package/dist/types/utils/chunkInference.d.ts.map +1 -1
  195. package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
  196. package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
  197. package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
  198. package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
  199. package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
  200. package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
  201. package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
  202. package/dist/types/utils/openBrowser.d.ts.map +1 -1
  203. package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
  204. package/dist/types/utils/setupAI.d.ts +1 -2
  205. package/dist/types/utils/setupAI.d.ts.map +1 -1
  206. package/dist/types/watch.d.ts.map +1 -1
  207. package/package.json +12 -12
@@ -1 +1 @@
1
- {"version":3,"file":"listMissingTranslations.cjs","names":[],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import { logConfigDetails } from '@intlayer/chokidar/cli';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getMissingLocalesContentFromDictionary } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslationsWithConfig = (\n configuration: IntlayerConfig\n) => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const mergedDictionaries = getDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n id?: string;\n locales: Locale[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n // Use the union of keys from both unmerged and merged dictionaries so that\n // dictionaries compiled only as merged (no per-locale split) are still checked.\n const dictionariesKeys = new Set([\n ...Object.keys(unmergedDictionariesRecord),\n ...Object.keys(mergedDictionaries),\n ]);\n\n for (const dictionaryKey of dictionariesKeys) {\n const dictionaries: Dictionary[] =\n unmergedDictionariesRecord[dictionaryKey] ?? [];\n\n const multilingualDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => !dictionary.locale\n );\n\n // Test all by merging all dictionaries to ensure no per-locale dictionary is missing\n for (const dictionary of multilingualDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n dictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: dictionary.id,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n const perLocaleDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => dictionary.locale\n );\n\n // If there are no unmerged dictionaries for this key, fall back to the\n // merged dictionary directly (covers the case where the dict was compiled\n // as merged-only and unmerged_dictionaries.cjs is empty for this key).\n if (dictionaries.length === 0) {\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n if (mergedDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: mergedDictionary.id,\n filePath: mergedDictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n continue;\n }\n\n if (perLocaleDictionary.length === 0) {\n continue;\n }\n\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n locales: missingLocales,\n });\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap(\n (missingTranslation) => missingTranslation.locales\n )\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n\nexport const listMissingTranslations = (\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n logConfigDetails(configurationOptions);\n\n return listMissingTranslationsWithConfig(configuration);\n};\n"],"mappings":";;;;;;;;;AAYA,MAAa,qCACX,kBACG;CACH,MAAM,gGAAqD,cAAc;CACzE,MAAM,uEAAqC,cAAc;CAEzD,MAAM,sBAKA,EAAE;CAER,MAAM,EAAE,SAAS,oBAAoB,cAAc;CAInD,MAAM,mBAAmB,IAAI,IAAI,CAC/B,GAAG,OAAO,KAAK,2BAA2B,EAC1C,GAAG,OAAO,KAAK,mBAAmB,CACnC,CAAC;CAEF,KAAK,MAAM,iBAAiB,kBAAkB;EAC5C,MAAM,eACJ,2BAA2B,kBAAkB,EAAE;EAEjD,MAAM,yBAAuC,aAAa,QACvD,eAAe,CAAC,WAAW,OAC7B;EAGD,KAAK,MAAM,cAAc,wBAAwB;GAC/C,MAAM,oFACJ,YACA,QACD;GAED,IAAI,eAAe,SAAS,GAC1B,oBAAoB,KAAK;IACvB,KAAK;IACL,IAAI,WAAW;IACf,UAAU,WAAW;IACrB,SAAS;IACV,CAAC;;EAIN,MAAM,sBAAoC,aAAa,QACpD,eAAe,WAAW,OAC5B;EAKD,IAAI,aAAa,WAAW,GAAG;GAC7B,MAAM,mBAAmB,mBAAmB;GAE5C,IAAI,kBAAkB;IACpB,MAAM,oFACJ,kBACA,QACD;IAED,IAAI,eAAe,SAAS,GAC1B,oBAAoB,KAAK;KACvB,KAAK;KACL,IAAI,iBAAiB;KACrB,UAAU,iBAAiB;KAC3B,SAAS;KACV,CAAC;;GAIN;;EAGF,IAAI,oBAAoB,WAAW,GACjC;EAGF,MAAM,mBAAmB,mBAAmB;EAE5C,MAAM,oFACJ,kBACA,QACD;EAED,IAAI,eAAe,SAAS,GAC1B,oBAAoB,KAAK;GACvB,KAAK;GACL,SAAS;GACV,CAAC;;CAIN,MAAM,oBAAoB,IAAI,IAC5B,oBAAoB,SACjB,uBAAuB,mBAAmB,QAC5C,CACF;CACD,MAAM,iBAAiB,MAAM,KAAK,kBAAkB;CAMpD,OAAO;EAAE;EAAqB;EAAgB,wBAJf,eAAe,QAAQ,YACnD,mBAAmB,SAAS,SAAS,OAAO,CAGqB;EAAE;;AAGxE,MAAa,2BACX,yBACG;CACH,MAAM,4DAAiC,qBAAqB;CAC5D,6CAAiB,qBAAqB;CAEtC,OAAO,kCAAkC,cAAc"}
1
+ {"version":3,"file":"listMissingTranslations.cjs","names":[],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import { logConfigDetails } from '@intlayer/chokidar/cli';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getMissingLocalesContentFromDictionary } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslationsWithConfig = (\n configuration: IntlayerConfig\n) => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const mergedDictionaries = getDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n id?: string;\n locales: Locale[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n // Use the union of keys from both unmerged and merged dictionaries so that\n // dictionaries compiled only as merged (no per-locale split) are still checked.\n const dictionariesKeys = new Set([\n ...Object.keys(unmergedDictionariesRecord),\n ...Object.keys(mergedDictionaries),\n ]);\n\n for (const dictionaryKey of dictionariesKeys) {\n const dictionaries: Dictionary[] =\n unmergedDictionariesRecord[dictionaryKey] ?? [];\n\n const multilingualDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => !dictionary.locale\n );\n\n // Test all by merging all dictionaries to ensure no per-locale dictionary is missing\n for (const dictionary of multilingualDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n dictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: dictionary.id,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n const perLocaleDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => dictionary.locale\n );\n\n // If there are no unmerged dictionaries for this key, fall back to the\n // merged dictionary directly (covers the case where the dict was compiled\n // as merged-only and unmerged_dictionaries.cjs is empty for this key).\n if (dictionaries.length === 0) {\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n if (mergedDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: mergedDictionary.id,\n filePath: mergedDictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n continue;\n }\n\n if (perLocaleDictionary.length === 0) {\n continue;\n }\n\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n locales: missingLocales,\n });\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap(\n (missingTranslation) => missingTranslation.locales\n )\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n\nexport const listMissingTranslations = (\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n logConfigDetails(configurationOptions);\n\n return listMissingTranslationsWithConfig(configuration);\n};\n"],"mappings":";;;;;;;;;AAYA,MAAa,qCACX,kBACG;CACH,MAAM,gGAAqD,aAAa;CACxE,MAAM,uEAAqC,aAAa;CAExD,MAAM,sBAKA,CAAC;CAEP,MAAM,EAAE,SAAS,oBAAoB,cAAc;CAInD,MAAM,mBAAmB,IAAI,IA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"version":3,"file":"test.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/test.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { listMissingTranslations } from './listMissingTranslations';\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n build?: boolean;\n};\n\nexport const testMissingTranslations = async (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config);\n\n if (options?.build === true) {\n await prepareIntlayer(config, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(config);\n }\n\n const result = listMissingTranslations(options?.configOptions);\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n\n translation.filePath ? ` - ${formatPath(translation.filePath)}` : '',\n translation.id ? ' - remote' : '',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n\n if (result.missingRequiredLocales.length > 0) {\n process.exit(1);\n }\n};\n"],"mappings":";;;;;;;;;;;AAqBA,MAAa,0BAA0B,OACrC,YACG;CACH,MAAM,qDAA0B,SAAS,cAAc;CACvD,MAAM,EAAE,SAAS,oBAAoB,OAAO;CAE5C,MAAM,sDAAyB,OAAO;CAEtC,IAAI,SAAS,UAAU,MACrB,oDAAsB,QAAQ,EAAE,UAAU,MAAM,CAAC;MAC5C,IAAI,OAAO,SAAS,UAAU,aACnC,oDAAsB,OAAO;CAG/B,MAAM,SAASA,6DAAwB,SAAS,cAAc;CAE9D,MAAM,gBAAgB,OAAO,oBAC1B,KAAK,MAAM,MAAM,EAAE,MAAM,CACzB,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,OAAO,EAAE,EAAE;CACjD,MAAM,oBAAoB,OAAO,oBAC9B,KAAK,iDAAmB,EAAE,SAAS,MAAM,CAAC,CAC1C,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,OAAO,EAAE,EAAE;CAEjD,MAAM,+BAA+B,OAAO,oBAAoB,KAC7D,gBACC;qCACQ,+CAAkB,YAAY,IAAI,IAAI;GAC1C,SAAS;GACT,SAAS;GACV,CAAC;EACF;gFACmB,YAAY,SAASC,wBAAW,IAAI,EAAE;GACvD,SAAS;GACT,SAAS;GACV,CAAC;EAEF,YAAY,WAAW,+CAAiB,YAAY,SAAS,KAAK;EAClE,YAAY,KAAK,cAAc;EAChC,CAAC,KAAK,GAAG,CACb;CAED,UAAU,yBAAyB,EACjC,OAAO,QACR,CAAC;CAEF,6BAA6B,SAAS,MAAM;EAC1C,UAAU,GAAG,EACX,OAAO,QACR,CAAC;GACF;CAEF,UAAU,uDAAyB,QAAQ,GAAG;CAC9C,UAAU,gEAAkC,mBAAmB,QAAQ,GAAG;CAC1E,UACE,oBAAoB,OAAO,eAAe,WAAW,0CAAa,KAAKA,wBAAW,MAAM,8CAAgB,OAAO,gBAAgBA,wBAAW,IAAI,GAC/I;CAED,UACE,6BAA6B,OAAO,uBAAuB,WAAW,0CAAa,KAAKA,wBAAW,MAAM,8CAAgB,OAAO,wBAAwBA,wBAAW,IAAI,GACxK;CACD,UACE,sEAAyC,OAAO,eAAe,QAAQ;EACrE,KAAKA,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;EAClB,CAAC,GACH;CACD,UACE,+EACE,OAAO,uBAAuB,QAC9B;EACE,KAAKA,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;EAClB,CACF,GACF;CAED,IAAI,OAAO,uBAAuB,SAAS,GACzC,QAAQ,KAAK,EAAE"}
1
+ {"version":3,"file":"test.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/test.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { listMissingTranslations } from './listMissingTranslations';\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n build?: boolean;\n};\n\nexport const testMissingTranslations = async (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config);\n\n if (options?.build === true) {\n await prepareIntlayer(config, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(config);\n }\n\n const result = listMissingTranslations(options?.configOptions);\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n\n translation.filePath ? ` - ${formatPath(translation.filePath)}` : '',\n translation.id ? ' - remote' : '',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n one: ANSIColors.RED,\n other: AN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CAAiB,OAAO,gBAAgBA,wBAAW,GAAG,GAC/I;CAEA,UACE,6BAA6B,OAAO,uBAAuB,WAAW,0CAAa,KAAKA,wBAAW,KAAK,+CAAiB,OAAO,wBAAwBA,wBAAW,GAAG,GACxK;CACA,UACE,sEAAyC,OAAO,eAAe,QAAQ;EACrE,KAAKA,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;CACnB,CAAC,GACH;CACA,UACE,+EACE,OAAO,uBAAuB,QAC9B;EACE,KAAKA,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;CACnB,CACF,GACF;CAEA,IAAI,OAAO,uBAAuB,SAAS,GACzC,QAAQ,KAAK,CAAC;AAElB"}
@@ -1 +1 @@
1
- {"version":3,"file":"translateDoc.cjs","names":["setupAI","x","performance","getOutputFilePath","checkFileModifiedRange","translateFile","ANSIColors"],"sources":["../../../src/translateDoc/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { performance } from 'node:perf_hooks';\n\nimport { listGitFiles, logConfigDetails } from '@intlayer/chokidar/cli';\nimport { parallelize, pLimit } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeNumber,\n getAppLogger,\n x,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport fg from 'fast-glob';\nimport { checkFileModifiedRange } from '../utils/checkFileModifiedRange';\nimport { getOutputFilePath } from '../utils/getOutputFilePath';\nimport { setupAI } from '../utils/setupAI';\nimport { translateFile } from './translateFile';\nimport type { ErrorState, TranslateDocOptions } from './types';\n\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed = 20, // Default to a higher concurrency for chunks\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n flushStrategy = 'incremental',\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n // 1. GLOBAL QUEUE SETUP\n // We use pLimit to create a single bottleneck for AI requests.\n // This queue is shared across all files and locales.\n const maxConcurrentChunks = nbSimultaneousFileProcessed;\n const globalChunkLimiter = pLimit(maxConcurrentChunks);\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const aiResult = await setupAI(configuration, aiOptions);\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig, isCustomAI } = aiResult;\n if (isCustomAI && aiClient && aiConfig) {\n const { hasAIAccess, error } = await aiClient.checkAISDKAccess(aiConfig);\n if (!hasAIAccess) {\n appLogger(`${x} ${error}`);\n return;\n }\n }\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n if (gitChangedFiles) {\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n const batchStartTime = performance.now();\n\n appLogger(\n `Translating ${colorizeNumber(docList.length)} files to ${colorizeNumber(locales.length)} locales. \\n` +\n `Global Concurrency: ${colorizeNumber(maxConcurrentChunks)} chunks in parallel.`\n );\n\n const errorState: ErrorState = {\n count: 0,\n maxErrors: 5,\n shouldStop: false,\n };\n\n // FLATTENED TASK LIST\n // We create a task for every File x Locale combination.\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n if (errorState.shouldStop) return;\n\n const absoluteBaseFilePath = join(configuration.system.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip logic\n if (skipIfExists && existsSync(outputFilePath)) return;\n\n if (flushStrategy === 'incremental' && !existsSync(outputFilePath)) {\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n // Execute translation using the SHARED limiter\n await translateFile({\n baseFilePath: absoluteBaseFilePath,\n outputFilePath,\n locale: locale as Locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy,\n limit: globalChunkLimiter, // Pass the global queue\n });\n })\n );\n\n // HIGH-THROUGHPUT FILE OPENER\n // We open many files simultaneously (e.g., 50) to ensure the global chunk queue\n // is always saturated with work.\n // If we open too few files, the chunk queue might drain faster than we can read new files.\n const FILE_OPEN_LIMIT = 50;\n\n await parallelize(allTasks, (task) => task(), FILE_OPEN_LIMIT);\n\n const batchEndTime = performance.now();\n const batchDuration = ((batchEndTime - batchStartTime) / 1000).toFixed(2);\n\n if (errorState.count > 0) {\n appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);\n } else {\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} Batch completed successfully in ${colorizeNumber(batchDuration)}s.`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,MAAa,eAAe,OAAO,EACjC,YACA,SACA,qBACA,YACA,WACA,8BAA8B,IAC9B,eACA,oBACA,sBACA,qBACA,cACA,YACA,gBAAgB,oBACS;CACzB,MAAM,4DAAiC,cAAc;CACrD,6CAAiB,cAAc;CAE/B,MAAM,sDAAyB,cAAc;CAK7C,MAAM,sBAAsB;CAC5B,MAAM,0DAA4B,oBAAoB;CAEtD,IAAI,UAAoB,6BAAS,YAAY,EAC3C,QAAQ,qBACT,CAAC;CAEF,MAAM,WAAW,MAAMA,8BAAQ,eAAe,UAAU;CACxD,IAAI,CAAC,UAAU,aAAa;CAE5B,MAAM,EAAE,UAAU,UAAU,eAAe;CAC3C,IAAI,cAAc,YAAY,UAAU;EACtC,MAAM,EAAE,aAAa,UAAU,MAAM,SAAS,iBA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,+EAAkD,cAAc,CAAC,IACrG"}
1
+ {"version":3,"file":"translateDoc.cjs","names":["setupAI","x","performance","getOutputFilePath","checkFileModifiedRange","translateFile","ANSIColors"],"sources":["../../../src/translateDoc/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { performance } from 'node:perf_hooks';\n\nimport { listGitFiles, logConfigDetails } from '@intlayer/chokidar/cli';\nimport { parallelize, pLimit } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeNumber,\n getAppLogger,\n x,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport fg from 'fast-glob';\nimport { checkFileModifiedRange } from '../utils/checkFileModifiedRange';\nimport { getOutputFilePath } from '../utils/getOutputFilePath';\nimport { setupAI } from '../utils/setupAI';\nimport { translateFile } from './translateFile';\nimport type { ErrorState, TranslateDocOptions } from './types';\n\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed = 20, // Default to a higher concurrency for chunks\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n flushStrategy = 'incremental',\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n // 1. GLOBAL QUEUE SETUP\n // We use pLimit to create a single bottleneck for AI requests.\n // This queue is shared across all files and locales.\n const maxConcurrentChunks = nbSimultaneousFileProcessed;\n const globalChunkLimiter = pLimit(maxConcurrentChunks);\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const aiResult = await setupAI(configuration, aiOptions);\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig, isCustomAI } = aiResult;\n if (isCustomAI && aiClient && aiConfig) {\n const { hasAIAccess, error } = await aiClient.checkAISDKAccess(aiConfig);\n if (!hasAIAccess) {\n appLogger(`${x} ${error}`);\n return;\n }\n }\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n if (gitChangedFiles) {\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n const batchStartTime = performance.now();\n\n appLogger(\n `Translating ${colorizeNumber(docList.length)} files to ${colorizeNumber(locales.length)} locales. \\n` +\n `Global Concurrency: ${colorizeNumber(maxConcurrentChunks)} chunks in parallel.`\n );\n\n const errorState: ErrorState = {\n count: 0,\n maxErrors: 5,\n shouldStop: false,\n };\n\n // FLATTENED TASK LIST\n // We create a task for every File x Locale combination.\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n if (errorState.shouldStop) return;\n\n const absoluteBaseFilePath = join(configuration.system.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip logic\n if (skipIfExists && existsSync(outputFilePath)) return;\n\n if (flushStrategy === 'incremental' && !existsSync(outputFilePath)) {\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n // Execute translation using the SHARED limiter\n await translateFile({\n baseFilePath: absoluteBaseFilePath,\n outputFilePath,\n locale: locale as Locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy,\n limit: globalChunkLimiter, // Pass the global queue\n });\n })\n );\n\n // HIGH-THROUGHPUT FILE OPENER\n // We open many files simultaneously (e.g., 50) to ensure the global chunk queue\n // is always saturated with work.\n // If we open too few files, the chunk queue might drain faster than we can read new files.\n const FILE_OPEN_LIMIT = 50;\n\n await parallelize(allTasks, (task) => task(), FILE_OPEN_LIMIT);\n\n const batchEndTime = performance.now();\n const batchDuration = ((batchEndTime - batchStartTime) / 1000).toFixed(2);\n\n if (errorState.count > 0) {\n appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);\n } else {\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} Batch completed successfully in ${colorizeNumber(batchDuration)}s.`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,MAAa,eAAe,OAAO,EACjC,YACA,SACA,qBACA,YACA,WACA,8BAA8B,IAC9B,eACA,oBACA,sBACA,qBACA,cACA,YACA,gBAAgB,oBACS;CACzB,MAAM,4DAAiC,aAAa;CACpD,6CAAiB,aAAa;CAE9B,MAAM,sDAAyB,aAAa;CAK5C,MAAM,sBAAsB;CAC5B,MAAM,0DAA4B,mBAAmB;CAErD,IAAI,UAAoB,6BAAS,YAAY,EAC3C,QAAQ,oBACV,CAAC;CAED,MAAM,WAAW,MAAMA,8BAAQ,eAAe,SAAS;CACvD,IAAI,CAAC,UAAU,aAAa;CAE5B,MAAM,EAAE,UAAU,UAAU,eAAe;CAC3C,IAAI,cAAc,YAAY,UAAU;EACtC,MAAM,EAAE,aAAa,UAAU,MAAM,SAAS,iBAAiB,QAAQ;EACvE,IAAI,CAAC,aAAa;GAChB,UAAU,GAAGC,0BAAE,GAAG,OAAO;GACzB;EACF;CACF;CAEA,IAAI,YAAY;EACd,MAAM,kBAAkB,+CAAmB,UAAU;EACrD,IAAI,iBACF,UAAU,QAAQ,QAAQ,SACxB,gBAAgB,MAAM,gCAAiB,QAAQ,IAAI,GAAG,IAAI,MAAM,OAAO,CACzE;CAEJ;CAEA,MAAM,iBAAiBC,4BAAY,IAAI;CAEvC,UACE,2DAA8B,QAAQ,MAAM,EAAE,wDAA2B,QAAQ,MAAM,EAAE,8EACjD,mBAAmB,EAAE,qBAC/D;CAEA,MAAM,aAAyB;EAC7B,OAAO;EACP,WAAW;EACX,YAAY;CACd;CAyDA,gDArDiB,QAAQ,SAAS,YAChC,QAAQ,KAAK,WAAW,YAAY;EAClC,IAAI,WAAW,YAAY;EAE3B,MAAM,2CAA4B,cAAc,OAAO,SAAS,OAAO;EACvE,MAAM,iBAAiBC,kDACrB,sBACA,QACA,UACF;EAGA,IAAI,wCAA2B,cAAc,GAAG;EAEhD,IAAI,kBAAkB,iBAAiB,yBAAY,cAAc,GAAG;GAClE,8CAAkB,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;GACtD,2BAAc,gBAAgB,EAAE;EAClC;EAEA,MAAM,uBAAuBC,4DAAuB,gBAAgB;GAClE;GACA;EACF,CAAC;EAED,IAAI,qBAAqB,WAAW;GAClC,UAAU,qBAAqB,OAAO;GACtC;EACF;EAGA,MAAMC,iDAAc;GAClB,cAAc;GACd;GACQ;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,OAAO;EACT,CAAC;CACH,CAAC,CASsB,IAAI,SAAS,KAAK,GAAG,EAAe;CAG7D,MAAM,kBADeH,4BAAY,IACE,IAAI,kBAAkB,KAAM,QAAQ,CAAC;CAExE,IAAI,WAAW,QAAQ,GACrB,UAAU,iBAAiB,WAAW,MAAM,aAAa,cAAc,GAAG;MAE1E,UACE,yCAAY,KAAKI,wBAAW,KAAK,EAAE,+EAAkD,aAAa,EAAE,GACtG;AAEJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"translateFile.cjs","names":["performance","chunkText","ANSIColors","readAsset","chunkInference","sanitizeChunk","fixChunkStartEndChars","validateTranslation"],"sources":["../../../src/translateDoc/translateFile.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, relative } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport { readAsset } from 'utils:asset';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport { chunkText } from '../utils/calculateChunks';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { TranslateFileOptions } from './types';\nimport { sanitizeChunk, validateTranslation } from './validation';\n\nexport const translateFile = async ({\n baseFilePath,\n outputFilePath,\n locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy = 'incremental',\n onChunkReceive,\n limit, // The Global Limiter\n}: TranslateFileOptions): Promise<string | null> => {\n if (errorState.shouldStop) return null;\n\n const appLogger = getAppLogger(configuration, { config: { prefix: '' } });\n const fileStartTime = performance.now();\n\n try {\n const fileContent = await readFile(baseFilePath, 'utf-8');\n const chunks = chunkText(fileContent);\n const totalChunks = chunks.length;\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = `${colon(filePrefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = `${colon(prefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n\n appLogger(\n `${filePrefix}Split into ${colorizeNumber(totalChunks)} chunks. Queuing...`\n );\n\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const translatedParts: string[] = new Array(totalChunks).fill('');\n\n // Fallback if no limiter is provided (runs immediately)\n const runTask = limit ?? ((fn) => fn());\n\n // MAP CHUNKS TO GLOBAL TASKS\n // This pushes ALL chunks for this file into the Global Queue immediately.\n // They will execute whenever the global concurrency slots open up.\n const tasks = chunks.map((chunk, i) =>\n runTask(async () => {\n if (errorState.shouldStop) return null;\n\n const chunkLogger = getAppLogger(configuration, {\n config: {\n prefix: `${prefix} ${ANSIColors.GREY_DARK}[${i + 1}/${totalChunks}] ${ANSIColors.RESET}`,\n },\n });\n\n const chunkStartTime = performance.now();\n const isFirstChunk = i === 0;\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Context Preparation\n const getPrevChunkPrompt = () =>\n `>>> CONTEXT: PREVIOUS SOURCE CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i - 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END PREVIOUS CONTEXT <<<`;\n\n const getBaseChunkContextPrompt = () =>\n `>>> CONTEXT: NEXT CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i + 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END NEXT CONTEXT <<<`;\n\n chunkLogger('Process started');\n\n const chunkTranslation = retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n ...(chunks[i + 1]\n ? [\n {\n role: 'system',\n content: getBaseChunkContextPrompt(),\n } as const,\n ]\n : []),\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: [\n `You are translating TARGET CHUNK (${i + 1}/${totalChunks}).`,\n `Translate ONLY the target chunk. Preserve frontmatter/code exactly.`,\n ].join('\\n'),\n },\n ],\n [\n {\n role: 'user',\n content: `>>> TARGET CHUNK START <<<\\n${fileToTranslateCurrentChunk}\\n>>> TARGET CHUNK END <<<`,\n },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n processedChunk = fixChunkStartEndChars(\n processedChunk,\n fileToTranslateCurrentChunk\n );\n\n const isValid = validateTranslation(\n fileToTranslateCurrentChunk,\n processedChunk,\n chunkLogger\n );\n\n if (!isValid) {\n // Throwing an error here signals retryManager to try again\n throw new Error(\n `Validation failed for chunk ${i + 1}/${totalChunks}`\n );\n }\n\n return { content: processedChunk, tokens: result.tokenUsed };\n });\n\n const { content: translatedChunk, tokens } = await chunkTranslation();\n const chunkEndTime = performance.now();\n const chunkDuration = (chunkEndTime - chunkStartTime).toFixed(0);\n\n // Store Result\n translatedParts[i] = translatedChunk;\n\n if (onChunkReceive) {\n onChunkReceive(translatedChunk, i, totalChunks);\n }\n\n // Incremental Flush Strategy\n if (flushStrategy === 'incremental') {\n const isContiguous = translatedParts\n .slice(0, i + 1)\n .every((p) => p && p !== '');\n\n if (isContiguous) {\n let endIdx = 0;\n while (\n endIdx < totalChunks &&\n translatedParts[endIdx] &&\n translatedParts[endIdx] !== ''\n ) {\n endIdx++;\n }\n const currentContent = translatedParts.slice(0, endIdx).join('');\n // Write asynchronously/sync is fine here as node handles file locks reasonably well for single process\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, currentContent);\n }\n }\n\n chunkLogger(\n [\n `${colorizeNumber(tokens)} tokens used `,\n `${ANSIColors.GREY_DARK}in ${colorizeNumber(chunkDuration)}ms${ANSIColors.RESET}`,\n ].join('')\n );\n })\n );\n\n // Wait for all chunks for this specific file/locale to finish\n await Promise.all(tasks);\n\n // Final Flush\n const fullContent = translatedParts.join('');\n if (flushStrategy === 'end' || flushStrategy === 'incremental') {\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, fullContent);\n }\n\n const fileEndTime = performance.now();\n const totalDuration = ((fileEndTime - fileStartTime) / 1000).toFixed(2);\n const relativePath = relative(configuration.system.baseDir, outputFilePath);\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} completed in ${colorizeNumber(totalDuration)}s.`\n );\n\n return fullContent;\n } catch (error: any) {\n errorState.count++;\n const errorMessage = error?.message ?? JSON.stringify(error);\n appLogger(`${colorize('✖', ANSIColors.RED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,MAAM,GAEX,EAAE;KAChB,IAAI,SAAS;KACb,OACE,SAAS,eACT,gBAAgB,WAChB,gBAAgB,YAAY,IAE5B;KAEF,MAAM,iBAAiB,gBAAgB,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG;KAEhE,yDAAoB,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;KACzD,sCAAgB,gBAAgB,eAAe;;;GAInD,YACE,CACE,+CAAkB,OAAO,CAAC,gBAC1B,GAAGE,wBAAW,UAAU,iDAAoB,cAAc,CAAC,IAAIA,wBAAW,QAC3E,CAAC,KAAK,GAAG,CACX;IACD,CACH;EAGD,MAAM,QAAQ,IAAI,MAAM;EAGxB,MAAM,cAAc,gBAAgB,KAAK,GAAG;EAC5C,IAAI,kBAAkB,SAAS,kBAAkB,eAAe;GAC9D,yDAAoB,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;GACzD,sCAAgB,gBAAgB,YAAY;;EAI9C,MAAM,kBADcF,4BAAY,KACG,GAAG,iBAAiB,KAAM,QAAQ,EAAE;EACvE,MAAM,uCAAwB,cAAc,OAAO,SAAS,eAAe;EAE3E,UACE,yCAAY,KAAKE,wBAAW,MAAM,CAAC,iDAAmB,aAAa,CAAC,4DAA+B,cAAc,CAAC,IACnH;EAED,OAAO;UACA,OAAY;EACnB,WAAW;EACX,MAAM,eAAe,OAAO,WAAW,KAAK,UAAU,MAAM;EAC5D,UAAU,yCAAY,KAAKA,wBAAW,IAAI,CAAC,UAAU,eAAe;EACpE,IAAI,WAAW,SAAS,WAAW,WAAW,WAAW,aAAa;EACtE,OAAO"}
1
+ {"version":3,"file":"translateFile.cjs","names":["performance","chunkText","ANSIColors","readAsset","chunkInference","sanitizeChunk","fixChunkStartEndChars","validateTranslation"],"sources":["../../../src/translateDoc/translateFile.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, relative } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport { readAsset } from 'utils:asset';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport { chunkText } from '../utils/calculateChunks';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { TranslateFileOptions } from './types';\nimport { sanitizeChunk, validateTranslation } from './validation';\n\nexport const translateFile = async ({\n baseFilePath,\n outputFilePath,\n locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy = 'incremental',\n onChunkReceive,\n limit, // The Global Limiter\n}: TranslateFileOptions): Promise<string | null> => {\n if (errorState.shouldStop) return null;\n\n const appLogger = getAppLogger(configuration, { config: { prefix: '' } });\n const fileStartTime = performance.now();\n\n try {\n const fileContent = await readFile(baseFilePath, 'utf-8');\n const chunks = chunkText(fileContent);\n const totalChunks = chunks.length;\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = `${colon(filePrefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = `${colon(prefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n\n appLogger(\n `${filePrefix}Split into ${colorizeNumber(totalChunks)} chunks. Queuing...`\n );\n\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const translatedParts: string[] = new Array(totalChunks).fill('');\n\n // Fallback if no limiter is provided (runs immediately)\n const runTask = limit ?? ((fn) => fn());\n\n // MAP CHUNKS TO GLOBAL TASKS\n // This pushes ALL chunks for this file into the Global Queue immediately.\n // They will execute whenever the global concurrency slots open up.\n const tasks = chunks.map((chunk, i) =>\n runTask(async () => {\n if (errorState.shouldStop) return null;\n\n const chunkLogger = getAppLogger(configuration, {\n config: {\n prefix: `${prefix} ${ANSIColors.GREY_DARK}[${i + 1}/${totalChunks}] ${ANSIColors.RESET}`,\n },\n });\n\n const chunkStartTime = performance.now();\n const isFirstChunk = i === 0;\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Context Preparation\n const getPrevChunkPrompt = () =>\n `>>> CONTEXT: PREVIOUS SOURCE CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i - 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END PREVIOUS CONTEXT <<<`;\n\n const getBaseChunkContextPrompt = () =>\n `>>> CONTEXT: NEXT CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i + 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END NEXT CONTEXT <<<`;\n\n chunkLogger('Process started');\n\n const chunkTranslation = retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n ...(chunks[i + 1]\n ? [\n {\n role: 'system',\n content: getBaseChunkContextPrompt(),\n } as const,\n ]\n : []),\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: [\n `You are translating TARGET CHUNK (${i + 1}/${totalChunks}).`,\n `Translate ONLY the target chunk. Preserve frontmatter/code exactly.`,\n ].join('\\n'),\n },\n ],\n [\n {\n role: 'user',\n content: `>>> TARGET CHUNK START <<<\\n${fileToTranslateCurrentChunk}\\n>>> TARGET CHUNK END <<<`,\n },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n processedChunk = fixChunkStartEndChars(\n processedChunk,\n fileToTranslateCurrentChunk\n );\n\n const isValid = validateTranslation(\n fileToTranslateCurrentChunk,\n processedChunk,\n chunkLogger\n );\n\n if (!isValid) {\n // Throwing an error here signals retryManager to try again\n throw new Error(\n `Validation failed for chunk ${i + 1}/${totalChunks}`\n );\n }\n\n return { content: processedChunk, tokens: result.tokenUsed };\n });\n\n const { content: translatedChunk, tokens } = await chunkTranslation();\n const chunkEndTime = performance.now();\n const chunkDuration = (chunkEndTime - chunkStartTime).toFixed(0);\n\n // Store Result\n translatedParts[i] = translatedChunk;\n\n if (onChunkReceive) {\n onChunkReceive(translatedChunk, i, totalChunks);\n }\n\n // Incremental Flush Strategy\n if (flushStrategy === 'incremental') {\n const isContiguous = translatedParts\n .slice(0, i + 1)\n .every((p) => p && p !== '');\n\n if (isContiguous) {\n let endIdx = 0;\n while (\n endIdx < totalChunks &&\n translatedParts[endIdx] &&\n translatedParts[endIdx] !== ''\n ) {\n endIdx++;\n }\n const currentContent = translatedParts.slice(0, endIdx).join('');\n // Write asynchronously/sync is fine here as node handles file locks reasonably well for single process\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, currentContent);\n }\n }\n\n chunkLogger(\n [\n `${colorizeNumber(tokens)} tokens used `,\n `${ANSIColors.GREY_DARK}in ${colorizeNumber(chunkDuration)}ms${ANSIColors.RESET}`,\n ].join('')\n );\n })\n );\n\n // Wait for all chunks for this specific file/locale to finish\n await Promise.all(tasks);\n\n // Final Flush\n const fullContent = translatedParts.join('');\n if (flushStrategy === 'end' || flushStrategy === 'incremental') {\n await mkdir(dirname(outputFilePath), { recursive: true });\n await writeFile(outputFilePath, fullContent);\n }\n\n const fileEndTime = performance.now();\n const totalDuration = ((fileEndTime - fileStartTime) / 1000).toFixed(2);\n const relativePath = relative(configuration.system.baseDir, outputFilePath);\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} completed in ${colorizeNumber(totalDuration)}s.`\n );\n\n return fullContent;\n } catch (error: any) {\n errorState.count++;\n const errorMessage = error?.message ?? JSON.stringify(error);\n appLogger(`${colorize('✖', ANSIColors.RED)} Error: ${errorMessage}`);\n if (errorState.count >= errorState.maxErrors) errorState.shouldStop = true;\n return null;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,MAAa,gBAAgB,OAAO,EAClC,cACA,gBACA,QACA,YACA,eACA,YACA,WACA,oBACA,UACA,UACA,gBAAgB,eAChB,gBACA,YACkD;CAClD,IAAI,WAAW,YAAY,OAAO;CAElC,MAAM,sDAAyB,eAAe,EAAE,QAAQ,EAAE,QAAQ,GAAG,EAAE,CAAC;CACxE,MAAM,gBAAgBA,4BAAY,IAAI;CAEtC,IAAI;EAEF,MAAM,SAASC,wCAAU,qCADU,cAAc,OAAO,CACpB;EACpC,MAAM,cAAc,OAAO;EAG3B,MAAM,aAAa,sCAAS,GADFC,wBAAW,UAAU,4CAAc,YAAY,IAAIA,wBAAW,UAAU,KACtD,EAAE,SAAS,GAAG,CAAC,IAAIA,wBAAW;EAE1E,MAAM,SAAS,sCAAS,GADFA,wBAAW,UAAU,4CAAc,YAAY,IAAIA,wBAAW,UAAU,+CAAiB,MAAM,IAAIA,wBAAW,UAAU,KAC1G,EAAE,SAAS,GAAG,CAAC,IAAIA,wBAAW;EAElE,UACE,GAAG,WAAW,yDAA4B,WAAW,EAAE,oBACzD;EAEA,MAAM,aAAaC,+BAAU,iCAAiC,OAAO,EAClE,WAAW,kBAAkB,8CAAgB,QAAQ,KAAK,GAAG,EAC7D,WAAW,sBAAsB,8CAAgB,YAAY,KAAK,GAAG,EACrE,QAAQ,0BAA0B,WAAW,sBAAsB,GAAG,EACtE,QAAQ,0BAA0B,sBAAsB,GAAG;EAE9D,MAAM,kBAA4B,IAAI,MAAM,WAAW,EAAE,KAAK,EAAE;EAGhE,MAAM,UAAU,WAAW,OAAO,GAAG;EAKrC,MAAM,QAAQ,OAAO,KAAK,OAAO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I,gBACF,eAAe,iBAAiB,GAAG,WAAW;GAIhD,IAAI,kBAAkB,eAKpB;QAJqB,gBAClB,MAAM,GAAG,IAAI,CAAC,EACd,OAAO,MAAM,KAAK,MAAM,EAEZ,GAAG;KAChB,IAAI,SAAS;KACb,OACE,SAAS,eACT,gBAAgB,WAChB,gBAAgB,YAAY,IAE5B;KAEF,MAAM,iBAAiB,gBAAgB,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE;KAE/D,yDAAoB,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;KACxD,sCAAgB,gBAAgB,cAAc;IAChD;;GAGF,YACE,CACE,+CAAkB,MAAM,EAAE,gBAC1B,GAAGE,wBAAW,UAAU,iDAAoB,aAAa,EAAE,IAAIA,wBAAW,OAC5E,EAAE,KAAK,EAAE,CACX;EACF,CAAC,CACH;EAGA,MAAM,QAAQ,IAAI,KAAK;EAGvB,MAAM,cAAc,gBAAgB,KAAK,EAAE;EAC3C,IAAI,kBAAkB,SAAS,kBAAkB,eAAe;GAC9D,yDAAoB,cAAc,GAAG,EAAE,WAAW,KAAK,CAAC;GACxD,sCAAgB,gBAAgB,WAAW;EAC7C;EAGA,MAAM,kBADcF,4BAAY,IACE,IAAI,iBAAiB,KAAM,QAAQ,CAAC;EACtE,MAAM,uCAAwB,cAAc,OAAO,SAAS,cAAc;EAE1E,UACE,yCAAY,KAAKE,wBAAW,KAAK,EAAE,iDAAmB,YAAY,EAAE,4DAA+B,aAAa,EAAE,GACpH;EAEA,OAAO;CACT,SAAS,OAAY;EACnB,WAAW;EACX,MAAM,eAAe,OAAO,WAAW,KAAK,UAAU,KAAK;EAC3D,UAAU,yCAAY,KAAKA,wBAAW,GAAG,EAAE,UAAU,cAAc;EACnE,IAAI,WAAW,SAAS,WAAW,WAAW,WAAW,aAAa;EACtE,OAAO;CACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"validation.cjs","names":[],"sources":["../../../src/translateDoc/validation.ts"],"sourcesContent":["import type { Logger } from '@intlayer/config/logger';\n\n/**\n * Validates that the translated content matches the structure of the original.\n * Throws an error if a mismatch is found, triggering a retry.\n */\nexport const validateTranslation = (\n original: string,\n translated: string,\n logger: Logger\n): boolean => {\n const errors: string[] = [];\n\n // YAML Frontmatter Integrity (CRITICAL)\n if (original.trimStart().startsWith('---')) {\n if (!translated.trimStart().startsWith('---')) {\n errors.push(\n 'YAML Frontmatter missing: Input starts with \"---\", output does not.'\n );\n }\n const originalDashes = (original.match(/^---$/gm) || []).length;\n const translatedDashes = (translated.match(/^---$/gm) || []).length;\n if (originalDashes >= 2 && translatedDashes < 2) {\n errors.push(\n 'YAML Frontmatter unclosed: Input has closing \"---\", output is missing it.'\n );\n }\n }\n\n // Code Fence Check\n const fenceRegex = /^\\s*```/gm;\n const originalFences = (original.match(fenceRegex) || []).length;\n const translatedFences = (translated.match(fenceRegex) || []).length;\n\n if (originalFences !== translatedFences) {\n errors.push(\n `Code fence mismatch: Input has ${originalFences}, output has ${translatedFences}`\n );\n }\n\n // Length/Duplication Check\n const ratio = translated.length / (original.length || 1);\n const isTooLong = ratio > 2.5;\n const isSignificantLength = original.length > 50;\n\n if (isTooLong && isSignificantLength) {\n errors.push(\n `Length deviation: Output is ${translated.length} chars vs Input ${original.length} (${ratio.toFixed(1)}x). Likely included context.`\n );\n }\n\n // Line Count Heuristic\n const originalLines = original.split('\\n').length;\n const translatedLines = translated.split('\\n').length;\n\n if (originalLines > 5) {\n if (translatedLines < originalLines * 0.4) {\n errors.push(\n `Line count deviation: Output has ${translatedLines} lines, Input has ${originalLines}. Likely content deletion.`\n );\n }\n }\n\n if (errors.length > 0) {\n logger(`Validation Failed: ${errors.join(', ')}`);\n return false;\n }\n\n return true;\n};\n\n/**\n * Clean common AI artifacts\n */\nexport const sanitizeChunk = (translated: string, original: string): string => {\n let cleaned = translated;\n const wrapRegex = /^```(?:markdown|md|txt)?\\n([\\s\\S]*?)\\n```$/i;\n const match = cleaned.match(wrapRegex);\n if (match) cleaned = match[1];\n\n if (!original.startsWith('\\n') && cleaned.startsWith('\\n')) {\n cleaned = cleaned.replace(/^\\n+/, '');\n }\n if (!original.startsWith(' ') && cleaned.startsWith(' ')) {\n cleaned = cleaned.trimStart();\n }\n return cleaned;\n};\n"],"mappings":";;;;;;;AAMA,MAAa,uBACX,UACA,YACA,WACY;CACZ,MAAM,SAAmB,EAAE;CAG3B,IAAI,SAAS,WAAW,CAAC,WAAW,MAAM,EAAE;EAC1C,IAAI,CAAC,WAAW,WAAW,CAAC,WAAW,MAAM,EAC3C,OAAO,KACL,wEACD;EAEH,MAAM,kBAAkB,SAAS,MAAM,UAAU,IAAI,EAAE,EAAE;EACzD,MAAM,oBAAoB,WAAW,MAAM,UAAU,IAAI,EAAE,EAAE;EAC7D,IAAI,kBAAkB,KAAK,mBAAmB,GAC5C,OAAO,KACL,8EACD;;CAKL,MAAM,aAAa;CACnB,MAAM,kBAAkB,SAAS,MAAM,WAAW,IAAI,EAAE,EAAE;CAC1D,MAAM,oBAAoB,WAAW,MAAM,WAAW,IAAI,EAAE,EAAE;CAE9D,IAAI,mBAAmB,kBACrB,OAAO,KACL,kCAAkC,eAAe,eAAe,mBACjE;CAIH,MAAM,QAAQ,WAAW,UAAU,SAAS,UAAU;CACtD,MAAM,YAAY,QAAQ;CAC1B,MAAM,sBAAsB,SAAS,SAAS;CAE9C,IAAI,aAAa,qBACf,OAAO,KACL,+BAA+B,WAAW,OAAO,kBAAkB,SAAS,OAAO,IAAI,MAAM,QAAQ,EAAE,CAAC,8BACzG;CAIH,MAAM,gBAAgB,SAAS,MAAM,KAAK,CAAC;CAC3C,MAAM,kBAAkB,WAAW,MAAM,KAAK,CAAC;CAE/C,IAAI,gBAAgB,GAClB;MAAI,kBAAkB,gBAAgB,IACpC,OAAO,KACL,oCAAoC,gBAAgB,oBAAoB,cAAc,4BACvF;;CAIL,IAAI,OAAO,SAAS,GAAG;EACrB,OAAO,sBAAsB,OAAO,KAAK,KAAK,GAAG;EACjD,OAAO;;CAGT,OAAO;;;;;AAMT,MAAa,iBAAiB,YAAoB,aAA6B;CAC7E,IAAI,UAAU;CAEd,MAAM,QAAQ,QAAQ,MAAM,8CAAU;CACtC,IAAI,OAAO,UAAU,MAAM;CAE3B,IAAI,CAAC,SAAS,WAAW,KAAK,IAAI,QAAQ,WAAW,KAAK,EACxD,UAAU,QAAQ,QAAQ,QAAQ,GAAG;CAEvC,IAAI,CAAC,SAAS,WAAW,IAAI,IAAI,QAAQ,WAAW,IAAI,EACtD,UAAU,QAAQ,WAAW;CAE/B,OAAO"}
1
+ {"version":3,"file":"validation.cjs","names":[],"sources":["../../../src/translateDoc/validation.ts"],"sourcesContent":["import type { Logger } from '@intlayer/config/logger';\n\n/**\n * Validates that the translated content matches the structure of the original.\n * Throws an error if a mismatch is found, triggering a retry.\n */\nexport const validateTranslation = (\n original: string,\n translated: string,\n logger: Logger\n): boolean => {\n const errors: string[] = [];\n\n // YAML Frontmatter Integrity (CRITICAL)\n if (original.trimStart().startsWith('---')) {\n if (!translated.trimStart().startsWith('---')) {\n errors.push(\n 'YAML Frontmatter missing: Input starts with \"---\", output does not.'\n );\n }\n const originalDashes = (original.match(/^---$/gm) || []).length;\n const translatedDashes = (translated.match(/^---$/gm) || []).length;\n if (originalDashes >= 2 && translatedDashes < 2) {\n errors.push(\n 'YAML Frontmatter unclosed: Input has closing \"---\", output is missing it.'\n );\n }\n }\n\n // Code Fence Check\n const fenceRegex = /^\\s*```/gm;\n const originalFences = (original.match(fenceRegex) || []).length;\n const translatedFences = (translated.match(fenceRegex) || []).length;\n\n if (originalFences !== translatedFences) {\n errors.push(\n `Code fence mismatch: Input has ${originalFences}, output has ${translatedFences}`\n );\n }\n\n // Length/Duplication Check\n const ratio = translated.length / (original.length || 1);\n const isTooLong = ratio > 2.5;\n const isSignificantLength = original.length > 50;\n\n if (isTooLong && isSignificantLength) {\n errors.push(\n `Length deviation: Output is ${translated.length} chars vs Input ${original.length} (${ratio.toFixed(1)}x). Likely included context.`\n );\n }\n\n // Line Count Heuristic\n const originalLines = original.split('\\n').length;\n const translatedLines = translated.split('\\n').length;\n\n if (originalLines > 5) {\n if (translatedLines < originalLines * 0.4) {\n errors.push(\n `Line count deviation: Output has ${translatedLines} lines, Input has ${originalLines}. Likely content deletion.`\n );\n }\n }\n\n if (errors.length > 0) {\n logger(`Validation Failed: ${errors.join(', ')}`);\n return false;\n }\n\n return true;\n};\n\n/**\n * Clean common AI artifacts\n */\nexport const sanitizeChunk = (translated: string, original: string): string => {\n let cleaned = translated;\n const wrapRegex = /^```(?:markdown|md|txt)?\\n([\\s\\S]*?)\\n```$/i;\n const match = cleaned.match(wrapRegex);\n if (match) cleaned = match[1];\n\n if (!original.startsWith('\\n') && cleaned.startsWith('\\n')) {\n cleaned = cleaned.replace(/^\\n+/, '');\n }\n if (!original.startsWith(' ') && cleaned.startsWith(' ')) {\n cleaned = cleaned.trimStart();\n }\n return cleaned;\n};\n"],"mappings":";;;;;;;AAMA,MAAa,uBACX,UACA,YACA,WACY;CACZ,MAAM,SAAmB,CAAC;CAG1B,IAAI,SAAS,UAAU,EAAE,WAAW,KAAK,GAAG;EAC1C,IAAI,CAAC,WAAW,UAAU,EAAE,WAAW,KAAK,GAC1C,OAAO,KACL,uEACF;EAEF,MAAM,kBAAkB,SAAS,MAAM,SAAS,KAAK,CAAC,GAAG;EACzD,MAAM,oBAAoB,WAAW,MAAM,SAAS,KAAK,CAAC,GAAG;EAC7D,IAAI,kBAAkB,KAAK,mBAAmB,GAC5C,OAAO,KACL,6EACF;CAEJ;CAGA,MAAM,aAAa;CACnB,MAAM,kBAAkB,SAAS,MAAM,UAAU,KAAK,CAAC,GAAG;CAC1D,MAAM,oBAAoB,WAAW,MAAM,UAAU,KAAK,CAAC,GAAG;CAE9D,IAAI,mBAAmB,kBACrB,OAAO,KACL,kCAAkC,eAAe,eAAe,kBAClE;CAIF,MAAM,QAAQ,WAAW,UAAU,SAAS,UAAU;CACtD,MAAM,YAAY,QAAQ;CAC1B,MAAM,sBAAsB,SAAS,SAAS;CAE9C,IAAI,aAAa,qBACf,OAAO,KACL,+BAA+B,WAAW,OAAO,kBAAkB,SAAS,OAAO,IAAI,MAAM,QAAQ,CAAC,EAAE,6BAC1G;CAIF,MAAM,gBAAgB,SAAS,MAAM,IAAI,EAAE;CAC3C,MAAM,kBAAkB,WAAW,MAAM,IAAI,EAAE;CAE/C,IAAI,gBAAgB,GAClB;MAAI,kBAAkB,gBAAgB,IACpC,OAAO,KACL,oCAAoC,gBAAgB,oBAAoB,cAAc,2BACxF;CACF;CAGF,IAAI,OAAO,SAAS,GAAG;EACrB,OAAO,sBAAsB,OAAO,KAAK,IAAI,GAAG;EAChD,OAAO;CACT;CAEA,OAAO;AACT;;;;AAKA,MAAa,iBAAiB,YAAoB,aAA6B;CAC7E,IAAI,UAAU;CAEd,MAAM,QAAQ,QAAQ,MAAM,6CAAS;CACrC,IAAI,OAAO,UAAU,MAAM;CAE3B,IAAI,CAAC,SAAS,WAAW,IAAI,KAAK,QAAQ,WAAW,IAAI,GACvD,UAAU,QAAQ,QAAQ,QAAQ,EAAE;CAEtC,IAAI,CAAC,SAAS,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GACrD,UAAU,QAAQ,UAAU;CAE9B,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"alignBlocks.cjs","names":["computeJaccardSimilarity"],"sources":["../../../src/translation-alignment/alignBlocks.ts"],"sourcesContent":["import { computeJaccardSimilarity } from './computeSimilarity';\nimport type { AlignmentPair, FingerprintedBlock } from './types';\n\nexport const alignEnglishAndFrenchBlocks = (\n defaultBlocks: FingerprintedBlock[],\n secondaryBlocks: FingerprintedBlock[]\n): AlignmentPair[] => {\n // Needleman–Wunsch style global alignment using anchor similarity and type equality\n const defaultLength = defaultBlocks.length;\n const secondaryLength = secondaryBlocks.length;\n\n const scoreMatrix: number[][] = Array.from(\n { length: defaultLength + 1 },\n () => Array.from({ length: secondaryLength + 1 }, () => 0)\n );\n const traceMatrix: ('diagonal' | 'up' | 'left')[][] = Array.from(\n { length: defaultLength + 1 },\n () => Array.from({ length: secondaryLength + 1 }, () => 'diagonal')\n );\n\n const gapPenalty = -2;\n\n const computeMatchScore = (\n defaultIndex: number,\n secondaryIndex: number\n ): number => {\n const defaultBlock = defaultBlocks[defaultIndex];\n const secondaryBlock = secondaryBlocks[secondaryIndex];\n const typeBonus = defaultBlock.type === secondaryBlock.type ? 2 : 0;\n const anchorSimilarity = computeJaccardSimilarity(\n defaultBlock.anchorText,\n secondaryBlock.anchorText,\n 3\n );\n const lengthRatio =\n Math.min(defaultBlock.content.length, secondaryBlock.content.length) /\n Math.max(defaultBlock.content.length, secondaryBlock.content.length);\n const lengthBonus = lengthRatio > 0.75 ? 1 : 0;\n return typeBonus + lengthBonus + anchorSimilarity * 8; // weighted toward anchor similarity\n };\n\n // initialize first row and column\n for (let i = 1; i <= defaultLength; i += 1) {\n scoreMatrix[i][0] = scoreMatrix[i - 1][0] + gapPenalty;\n traceMatrix[i][0] = 'up';\n }\n for (let j = 1; j <= secondaryLength; j += 1) {\n scoreMatrix[0][j] = scoreMatrix[0][j - 1] + gapPenalty;\n traceMatrix[0][j] = 'left';\n }\n\n // fill\n for (let i = 1; i <= defaultLength; i += 1) {\n for (let j = 1; j <= secondaryLength; j += 1) {\n const match = scoreMatrix[i - 1][j - 1] + computeMatchScore(i - 1, j - 1);\n const deleteGap = scoreMatrix[i - 1][j] + gapPenalty;\n const insertGap = scoreMatrix[i][j - 1] + gapPenalty;\n\n const best = Math.max(match, deleteGap, insertGap);\n scoreMatrix[i][j] = best;\n traceMatrix[i][j] =\n best === match ? 'diagonal' : best === deleteGap ? 'up' : 'left';\n }\n }\n\n // traceback\n const result: AlignmentPair[] = [];\n let i = defaultLength;\n let j = secondaryLength;\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && traceMatrix[i][j] === 'diagonal') {\n const englishIndex = i - 1;\n const frenchIndex = j - 1;\n const similarityScore = computeJaccardSimilarity(\n defaultBlocks[englishIndex].anchorText,\n secondaryBlocks[frenchIndex].anchorText,\n 3\n );\n result.unshift({ englishIndex, frenchIndex, similarityScore });\n i -= 1;\n j -= 1;\n } else if (i > 0 && (j === 0 || traceMatrix[i][j] === 'up')) {\n result.unshift({\n englishIndex: i - 1,\n frenchIndex: null,\n similarityScore: 0,\n });\n i -= 1;\n } else if (j > 0 && (i === 0 || traceMatrix[i][j] === 'left')) {\n // french block has no corresponding english block (deleted)\n result.unshift({\n englishIndex: -1,\n frenchIndex: j - 1,\n similarityScore: 0,\n });\n j -= 1;\n }\n }\n return result;\n};\n"],"mappings":";;;;AAGA,MAAa,+BACX,eACA,oBACoB;CAEpB,MAAM,gBAAgB,cAAc;CACpC,MAAM,kBAAkB,gBAAgB;CAExC,MAAM,cAA0B,MAAM,KACpC,EAAE,QAAQ,gBAAgB,GAAG,QACvB,MAAM,KAAK,EAAE,QAAQ,kBAAkB,GAAG,QAAQ,EAAE,CAC3D;CACD,MAAM,cAAgD,MAAM,KAC1D,EAAE,QAAQ,gBAAgB,GAAG,QACvB,MAAM,KAAK,EAAE,QAAQ,kBAAkB,GAAG,QAAQ,WAAW,CACpE;CAED,MAAM,aAAa;CAEnB,MAAM,qBACJ,cACA,mBACW;EACX,MAAM,eAAe,cAAc;EACnC,MAAM,iBAAiB,gBAAgB;EACvC,MAAM,YAAY,aAAa,SAAS,eAAe,OAAO,IAAI;EAClE,MAAM,mBAAmBA,yEACvB,aAAa,YACb,eAAe,YACf,EACD;EAKD,OAAO,aAHL,KAAK,IAAI,aAAa,QAAQ,QAAQ,eAAe,QAAQ,OAAO,GACpE,KAAK,IAAI,aAAa,QAAQ,QAAQ,eAAe,QAAQ,OAAO,GACpC,MAAO,IAAI,KACZ,mBAAmB;;CAItD,KAAK,IAAI,IAAI,GAAG,KAAK,eAAe,KAAK,GAAG;EAC1C,YAAY,GAAG,KAAK,YAAY,IAAI,GAAG,KAAK;EAC5C,YAAY,GAAG,KAAK;;CAEtB,KAAK,IAAI,IAAI,G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ignment/alignBlocks.ts"],"sourcesContent":["import { computeJaccardSimilarity } from './computeSimilarity';\nimport type { AlignmentPair, FingerprintedBlock } from './types';\n\nexport const alignEnglishAndFrenchBlocks = (\n defaultBlocks: FingerprintedBlock[],\n secondaryBlocks: FingerprintedBlock[]\n): AlignmentPair[] => {\n // Needleman–Wunsch style global alignment using anchor similarity and type equality\n const defaultLength = defaultBlocks.length;\n const secondaryLength = secondaryBlocks.length;\n\n const scoreMatrix: number[][] = Array.from(\n { length: defaultLength + 1 },\n () => Array.from({ length: secondaryLength + 1 }, () => 0)\n );\n const traceMatrix: ('diagonal' | 'up' | 'left')[][] = Array.from(\n { length: defaultLength + 1 },\n () => Array.from({ length: secondaryLength + 1 }, () => 'diagonal')\n );\n\n const gapPenalty = -2;\n\n const computeMatchScore = (\n defaultIndex: number,\n secondaryIndex: number\n ): number => {\n const defaultBlock = defaultBlocks[defaultIndex];\n const secondaryBlock = secondaryBlocks[secondaryIndex];\n const typeBonus = defaultBlock.type === secondaryBlock.type ? 2 : 0;\n const anchorSimilarity = computeJaccardSimilarity(\n defaultBlock.anchorText,\n secondaryBlock.anchorText,\n 3\n );\n const lengthRatio =\n Math.min(defaultBlock.content.length, secondaryBlock.content.length) /\n Math.max(defaultBlock.content.length, secondaryBlock.content.length);\n const lengthBonus = lengthRatio > 0.75 ? 1 : 0;\n return typeBonus + lengthBonus + anchorSimilarity * 8; // weighted toward anchor similarity\n };\n\n // initialize first row and column\n for (let i = 1; i <= defaultLength; i += 1) {\n scoreMatrix[i][0] = scoreMatrix[i - 1][0] + gapPenalty;\n traceMatrix[i][0] = 'up';\n }\n for (let j = 1; j <= secondaryLength; j += 1) {\n scoreMatrix[0][j] = scoreMatrix[0][j - 1] + gapPenalty;\n traceMatrix[0][j] = 'left';\n }\n\n // fill\n for (let i = 1; i <= defaultLength; i += 1) {\n for (let j = 1; j <= secondaryLength; j += 1) {\n const match = scoreMatrix[i - 1][j - 1] + computeMatchScore(i - 1, j - 1);\n const deleteGap = scoreMatrix[i - 1][j] + gapPenalty;\n const insertGap = scoreMatrix[i][j - 1] + gapPenalty;\n\n const best = Math.max(match, deleteGap, insertGap);\n scoreMatrix[i][j] = best;\n traceMatrix[i][j] =\n best === match ? 'diagonal' : best === deleteGap ? 'up' : 'left';\n }\n }\n\n // traceback\n const result: AlignmentPair[] = [];\n let i = defaultLength;\n let j = secondaryLength;\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && traceMatrix[i][j] === 'diagonal') {\n const englishIndex = i - 1;\n const frenchIndex = j - 1;\n const similarityScore = computeJaccardSimilarity(\n defaultBlocks[englishIndex].anchorText,\n secondaryBlocks[frenchIndex].anchorText,\n 3\n );\n result.unshift({ englishIndex, frenchIndex, similarityScore });\n i -= 1;\n j -= 1;\n } else if (i > 0 && (j === 0 || traceMatrix[i][j] === 'up')) {\n result.unshift({\n englishIndex: i - 1,\n frenchIndex: null,\n similarityScore: 0,\n });\n i -= 1;\n } else if (j > 0 && (i === 0 || traceMatrix[i][j] === 'left')) {\n // french block has no corresponding english block (deleted)\n result.unshift({\n englishIndex: -1,\n frenchIndex: j - 1,\n similarityScore: 0,\n });\n j -= 1;\n }\n }\n return result;\n};\n"],"mappings":";;;;AAGA,MAAa,+BACX,eACA,oBACoB;CAEpB,MAAM,gBAAgB,cAAc;CACpC,MAAM,kBAAkB,gBAAgB;CAExC,MAAM,cAA0B,MAAM,KACpC,EAAE,QAAQ,gBAAgB,EAAE,SACtB,MAAM,KAAK,EAAE,QAAQ,kBAAkB,EAAE,SAAS,CAAC,CAC3D;CACA,MAAM,cAAgD,MAAM,KAC1D,EAAE,QAAQ,gBAAgB,EAAE,SACtB,MAAM,KAAK,EAAE,QAAQ,kBAAkB,EAAE,SAAS,UAAU,CACpE;CAEA,MAAM,aAAa;CAEnB,MAAM,qBACJ,cACA,mBACW;EACX,MAAM,eAAe,cAAc;EACnC,MAAM,iBAAiB,gBAAgB;EACvC,MAAM,YAAY,aAAa,SAAS,eAAe,OAAO,IAAI;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D,KAAK;EACL,KAAK;CACP,OAAO,IAAI,IAAI,MAAM,MAAM,KAAK,YAAY,GAAG,OAAO,OAAO;EAC3D,OAAO,QAAQ;GACb,cAAc,IAAI;GAClB,aAAa;GACb,iBAAiB;EACnB,CAAC;EACD,KAAK;CACP,OAAO,IAAI,IAAI,MAAM,MAAM,KAAK,YAAY,GAAG,OAAO,SAAS;EAE7D,OAAO,QAAQ;GACb,cAAc;GACd,aAAa,IAAI;GACjB,iBAAiB;EACnB,CAAC;EACD,KAAK;CACP;CAEF,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"computeSimilarity.cjs","names":[],"sources":["../../../src/translation-alignment/computeSimilarity.ts"],"sourcesContent":["// Character shingle Jaccard similarity (language agnostic)\nexport const generateCharacterShingles = (\n text: string,\n shingleLength: number\n): Set<string> => {\n const normalized = text.replace(/\\s+/g, ' ').trim();\n const set = new Set<string>();\n if (normalized.length < shingleLength) {\n if (normalized.length > 0) {\n set.add(normalized);\n }\n return set;\n }\n for (let index = 0; index <= normalized.length - shingleLength; index += 1) {\n set.add(normalized.slice(index, index + shingleLength));\n }\n return set;\n};\n\nexport const computeJaccardSimilarity = (\n a: string,\n b: string,\n shingleLength: number = 3\n): number => {\n const setA = generateCharacterShingles(a, shingleLength);\n const setB = generateCharacterShingles(b, shingleLength);\n if (setA.size === 0 && setB.size === 0) return 1;\n const intersectionSize = Array.from(setA).filter((token) =>\n setB.has(token)\n ).length;\n const unionSize = new Set([...Array.from(setA), ...Array.from(setB)]).size;\n return unionSize === 0 ? 0 : intersectionSize / unionSize;\n};\n"],"mappings":";;;AACA,MAAa,6BACX,MACA,kBACgB;CAChB,MAAM,aAAa,KAAK,QAAQ,QAAQ,IAAI,CAAC,MAAM;CACnD,MAAM,sBAAM,IAAI,KAAa;CAC7B,IAAI,WAAW,SAAS,eAAe;EACrC,IAAI,WAAW,SAAS,GACtB,IAAI,IAAI,WAAW;EAErB,OAAO;;CAET,KAAK,IAAI,QAAQ,GAAG,SAAS,WAAW,SAAS,eAAe,SAAS,GACvE,IAAI,IAAI,WAAW,MAAM,OAAO,QAAQ,cAAc,CAAC;CAEzD,OAAO;;AAGT,MAAa,4BACX,GACA,GACA,gBAAwB,MACb;CACX,MAAM,OAAO,0BAA0B,GAAG,cAAc;CACxD,MAAM,OAAO,0BAA0B,GAAG,cAAc;CACxD,IAAI,KAAK,SAAS,KAAK,KAAK,SAAS,GAAG,OAAO;CAC/C,MAAM,mBAAmB,MAAM,KAAK,KAAK,CAAC,QAAQ,UAChD,KAAK,IAAI,MAAM,CAChB,CAAC;CACF,MAAM,YAAY,IAAI,IAAI,CAAC,GAAG,MAAM,KAAK,KAAK,EAAE,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC;CACtE,OAAO,cAAc,IAAI,IAAI,mBAAmB"}
1
+ {"version":3,"file":"computeSimilarity.cjs","names":[],"sources":["../../../src/translation-alignment/computeSimilarity.ts"],"sourcesContent":["// Character shingle Jaccard similarity (language agnostic)\nexport const generateCharacterShingles = (\n text: string,\n shingleLength: number\n): Set<string> => {\n const normalized = text.replace(/\\s+/g, ' ').trim();\n const set = new Set<string>();\n if (normalized.length < shingleLength) {\n if (normalized.length > 0) {\n set.add(normalized);\n }\n return set;\n }\n for (let index = 0; index <= normalized.length - shingleLength; index += 1) {\n set.add(normalized.slice(index, index + shingleLength));\n }\n return set;\n};\n\nexport const computeJaccardSimilarity = (\n a: string,\n b: string,\n shingleLength: number = 3\n): number => {\n const setA = generateCharacterShingles(a, shingleLength);\n const setB = generateCharacterShingles(b, shingleLength);\n if (setA.size === 0 && setB.size === 0) return 1;\n const intersectionSize = Array.from(setA).filter((token) =>\n setB.has(token)\n ).length;\n const unionSize = new Set([...Array.from(setA), ...Array.from(setB)]).size;\n return unionSize === 0 ? 0 : intersectionSize / unionSize;\n};\n"],"mappings":";;;AACA,MAAa,6BACX,MACA,kBACgB;CAChB,MAAM,aAAa,KAAK,QAAQ,QAAQ,GAAG,EAAE,KAAK;CAClD,MAAM,sBAAM,IAAI,IAAY;CAC5B,IAAI,WAAW,SAAS,eAAe;EACrC,IAAI,WAAW,SAAS,GACtB,IAAI,IAAI,UAAU;EAEpB,OAAO;CACT;CACA,KAAK,IAAI,QAAQ,GAAG,SAAS,WAAW,SAAS,eAAe,SAAS,GACvE,IAAI,IAAI,WAAW,MAAM,OAAO,QAAQ,aAAa,CAAC;CAExD,OAAO;AACT;AAEA,MAAa,4BACX,GACA,GACA,gBAAwB,MACb;CACX,MAAM,OAAO,0BAA0B,GAAG,aAAa;CACvD,MAAM,OAAO,0BAA0B,GAAG,aAAa;CACvD,IAAI,KAAK,SAAS,KAAK,KAAK,SAAS,GAAG,OAAO;CAC/C,MAAM,mBAAmB,MAAM,KAAK,IAAI,EAAE,QAAQ,UAChD,KAAK,IAAI,KAAK,CAChB,EAAE;CACF,MAAM,YAAY,IAAI,IAAI,CAAC,GAAG,MAAM,KAAK,IAAI,GAAG,GAAG,MAAM,KAAK,IAAI,CAAC,CAAC,EAAE;CACtE,OAAO,cAAc,IAAI,IAAI,mBAAmB;AAClD"}
@@ -1 +1 @@
1
- {"version":3,"file":"fingerprintBlock.cjs","names":["crypto"],"sources":["../../../src/translation-alignment/fingerprintBlock.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport type { FingerprintedBlock, NormalizedBlock } from './types';\n\nconst computeStringDigest = (text: string): string =>\n crypto.createHash('sha256').update(text).digest('hex');\n\nexport const fingerprintBlock = (\n block: NormalizedBlock,\n previousBlock: NormalizedBlock | null,\n nextBlock: NormalizedBlock | null\n): FingerprintedBlock => {\n const semanticDigest = computeStringDigest(block.semanticText);\n const anchorDigest = computeStringDigest(block.anchorText);\n const compositeKey = `${semanticDigest}:${anchorDigest}`;\n\n const previousDigest = computeStringDigest(previousBlock?.semanticText ?? '');\n const nextDigest = computeStringDigest(nextBlock?.semanticText ?? '');\n const contextKey = computeStringDigest(`${previousDigest}:${nextDigest}`);\n\n return {\n ...block,\n semanticDigest,\n anchorDigest,\n compositeKey,\n contextKey,\n };\n};\n"],"mappings":";;;;;;AAGA,MAAM,uBAAuB,SAC3BA,oBAAO,WAAW,SAAS,CAAC,OAAO,KAAK,CAAC,OAAO,MAAM;AAExD,MAAa,oBACX,OACA,eACA,cACuB;CACvB,MAAM,iBAAiB,oBAAoB,MAAM,aAAa;CAC9D,MAAM,eAAe,oBAAoB,MAAM,WAAW;CAC1D,MAAM,eAAe,GAAG,eAAe,GAAG;CAI1C,MAAM,aAAa,oBAAoB,GAFhB,oBAAoB,eAAe,gBAAgB,GAElB,CAAC,GADtC,oBAAoB,WAAW,gBAAgB,GACI,GAAG;CAEzE,OAAO;EACL,GAAG;EACH;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"fingerprintBlock.cjs","names":["crypto"],"sources":["../../../src/translation-alignment/fingerprintBlock.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport type { FingerprintedBlock, NormalizedBlock } from './types';\n\nconst computeStringDigest = (text: string): string =>\n crypto.createHash('sha256').update(text).digest('hex');\n\nexport const fingerprintBlock = (\n block: NormalizedBlock,\n previousBlock: NormalizedBlock | null,\n nextBlock: NormalizedBlock | null\n): FingerprintedBlock => {\n const semanticDigest = computeStringDigest(block.semanticText);\n const anchorDigest = computeStringDigest(block.anchorText);\n const compositeKey = `${semanticDigest}:${anchorDigest}`;\n\n const previousDigest = computeStringDigest(previousBlock?.semanticText ?? '');\n const nextDigest = computeStringDigest(nextBlock?.semanticText ?? '');\n const contextKey = computeStringDigest(`${previousDigest}:${nextDigest}`);\n\n return {\n ...block,\n semanticDigest,\n anchorDigest,\n compositeKey,\n contextKey,\n };\n};\n"],"mappings":";;;;;;AAGA,MAAM,uBAAuB,SAC3BA,oBAAO,WAAW,QAAQ,EAAE,OAAO,IAAI,EAAE,OAAO,KAAK;AAEvD,MAAa,oBACX,OACA,eACA,cACuB;CACvB,MAAM,iBAAiB,oBAAoB,MAAM,YAAY;CAC7D,MAAM,eAAe,oBAAoB,MAAM,UAAU;CACzD,MAAM,eAAe,GAAG,eAAe,GAAG;CAI1C,MAAM,aAAa,oBAAoB,GAFhB,oBAAoB,eAAe,gBAAgB,EAEnB,EAAE,GADtC,oBAAoB,WAAW,gBAAgB,EACG,GAAG;CAExE,OAAO;EACL,GAAG;EACH;EACA;EACA;EACA;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"mapChangedLinesToBlocks.cjs","names":[],"sources":["../../../src/translation-alignment/mapChangedLinesToBlocks.ts"],"sourcesContent":["import type { Block, LineChange } from './types';\n\nexport const mapChangedLinesToBlocks = (\n blocks: Block[],\n changedLines: LineChange[]\n): Set<number> => {\n const changedSet = new Set<number>();\n if (!changedLines || changedLines.length === 0) return changedSet;\n\n const changedLookup = new Set<number>(changedLines);\n\n blocks.forEach((block, index) => {\n for (let line = block.lineStart; line <= block.lineEnd; line += 1) {\n if (changedLookup.has(line)) {\n changedSet.add(index);\n break;\n }\n }\n });\n\n return changedSet;\n};\n"],"mappings":";;;AAEA,MAAa,2BACX,QACA,iBACgB;CAChB,MAAM,6BAAa,IAAI,KAAa;CACpC,IAAI,CAAC,gBAAgB,aAAa,WAAW,GAAG,OAAO;CAEvD,MAAM,gBAAgB,IAAI,IAAY,aAAa;CAEnD,OAAO,SAAS,OAAO,UAAU;EAC/B,KAAK,IAAI,OAAO,MAAM,WAAW,QAAQ,MAAM,SAAS,QAAQ,GAC9D,IAAI,cAAc,IAAI,KAAK,EAAE;GAC3B,WAAW,IAAI,MAAM;GACrB;;GAGJ;CAEF,OAAO"}
1
+ {"version":3,"file":"mapChangedLinesToBlocks.cjs","names":[],"sources":["../../../src/translation-alignment/mapChangedLinesToBlocks.ts"],"sourcesContent":["import type { Block, LineChange } from './types';\n\nexport const mapChangedLinesToBlocks = (\n blocks: Block[],\n changedLines: LineChange[]\n): Set<number> => {\n const changedSet = new Set<number>();\n if (!changedLines || changedLines.length === 0) return changedSet;\n\n const changedLookup = new Set<number>(changedLines);\n\n blocks.forEach((block, index) => {\n for (let line = block.lineStart; line <= block.lineEnd; line += 1) {\n if (changedLookup.has(line)) {\n changedSet.add(index);\n break;\n }\n }\n });\n\n return changedSet;\n};\n"],"mappings":";;;AAEA,MAAa,2BACX,QACA,iBACgB;CAChB,MAAM,6BAAa,IAAI,IAAY;CACnC,IAAI,CAAC,gBAAgB,aAAa,WAAW,GAAG,OAAO;CAEvD,MAAM,gBAAgB,IAAI,IAAY,YAAY;CAElD,OAAO,SAAS,OAAO,UAAU;EAC/B,KAAK,IAAI,OAAO,MAAM,WAAW,QAAQ,MAAM,SAAS,QAAQ,GAC9D,IAAI,cAAc,IAAI,IAAI,GAAG;GAC3B,WAAW,IAAI,KAAK;GACpB;EACF;CAEJ,CAAC;CAED,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeBlock.cjs","names":[],"sources":["../../../src/translation-alignment/normalizeBlock.ts"],"sourcesContent":["import type { Block, NormalizedBlock } from './types';\n\nconst removeMarkdownFormatting = (text: string): string => {\n return text\n .replace(/`{1,3}[^`]*`{1,3}/g, ' ')\n .replace(/\\*\\*([^*]+)\\*\\*/g, '$1')\n .replace(/\\*([^*]+)\\*/g, '$1')\n .replace(/_([^_]+)_/g, '$1')\n .replace(/~~([^~]+)~~/g, '$1')\n .replace(/!?\\[[^\\]]*\\]\\([^)]*\\)/g, ' ')\n .replace(/^\\s*#{1,6}\\s+/gm, '')\n .replace(/^\\s*>\\s?/gm, '')\n .replace(/^\\s*[-*+]\\s+/gm, '')\n .replace(/^\\s*\\d+\\.\\s+/gm, '');\n};\n\nconst collapseWhitespace = (text: string): string =>\n text.replace(/\\s+/g, ' ').trim();\n\nconst stripLettersKeepDigitsAndSymbols = (text: string): string => {\n // Keep digits and non-letter characters, remove all letters (including accents)\n return text.replace(/\\p{L}+/gu, '');\n};\n\nexport const normalizeBlock = (block: Block): NormalizedBlock => {\n const contentWithoutMarkdown = removeMarkdownFormatting(block.content);\n const semanticLowercased = contentWithoutMarkdown.toLowerCase();\n const semanticCollapsed = collapseWhitespace(semanticLowercased);\n\n const anchorOnlySymbols = stripLettersKeepDigitsAndSymbols(block.content);\n const anchorCollapsed = collapseWhitespace(anchorOnlySymbols);\n\n return {\n ...block,\n semanticText: semanticCollapsed,\n anchorText: anchorCollapsed,\n };\n};\n"],"mappings":";;;AAEA,MAAM,4BAA4B,SAAyB;CACzD,OAAO,KACJ,QAAQ,sBAAsB,IAAI,CAClC,QAAQ,oBAAoB,KAAK,CACjC,QAAQ,gBAAgB,KAAK,CAC7B,QAAQ,cAAc,KAAK,CAC3B,QAAQ,gBAAgB,KAAK,CAC7B,QAAQ,0BAA0B,IAAI,CACtC,QAAQ,mBAAmB,GAAG,CAC9B,QAAQ,cAAc,GAAG,CACzB,QAAQ,kBAAkB,GAAG,CAC7B,QAAQ,kBAAkB,GAAG;;AAGlC,MAAM,sBAAsB,SAC1B,KAAK,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAElC,MAAM,oCAAoC,SAAyB;CAEjE,OAAO,KAAK,QAAQ,YAAY,GAAG;;AAGrC,MAAa,kBAAkB,UAAkC;CAG/D,MAAM,oBAAoB,mBAFK,yBAAyB,MAAM,QACb,CAAC,aACa,CAAC;CAGhE,MAAM,kBAAkB,mBADE,iCAAiC,MAAM,QACL,CAAC;CAE7D,OAAO;EACL,GAAG;EACH,cAAc;EACd,YAAY;EACb"}
1
+ {"version":3,"file":"normalizeBlock.cjs","names":[],"sources":["../../../src/translation-alignment/normalizeBlock.ts"],"sourcesContent":["import type { Block, NormalizedBlock } from './types';\n\nconst removeMarkdownFormatting = (text: string): string => {\n return text\n .replace(/`{1,3}[^`]*`{1,3}/g, ' ')\n .replace(/\\*\\*([^*]+)\\*\\*/g, '$1')\n .replace(/\\*([^*]+)\\*/g, '$1')\n .replace(/_([^_]+)_/g, '$1')\n .replace(/~~([^~]+)~~/g, '$1')\n .replace(/!?\\[[^\\]]*\\]\\([^)]*\\)/g, ' ')\n .replace(/^\\s*#{1,6}\\s+/gm, '')\n .replace(/^\\s*>\\s?/gm, '')\n .replace(/^\\s*[-*+]\\s+/gm, '')\n .replace(/^\\s*\\d+\\.\\s+/gm, '');\n};\n\nconst collapseWhitespace = (text: string): string =>\n text.replace(/\\s+/g, ' ').trim();\n\nconst stripLettersKeepDigitsAndSymbols = (text: string): string => {\n // Keep digits and non-letter characters, remove all letters (including accents)\n return text.replace(/\\p{L}+/gu, '');\n};\n\nexport const normalizeBlock = (block: Block): NormalizedBlock => {\n const contentWithoutMarkdown = removeMarkdownFormatting(block.content);\n const semanticLowercased = contentWithoutMarkdown.toLowerCase();\n const semanticCollapsed = collapseWhitespace(semanticLowercased);\n\n const anchorOnlySymbols = stripLettersKeepDigitsAndSymbols(block.content);\n const anchorCollapsed = collapseWhitespace(anchorOnlySymbols);\n\n return {\n ...block,\n semanticText: semanticCollapsed,\n anchorText: anchorCollapsed,\n };\n};\n"],"mappings":";;;AAEA,MAAM,4BAA4B,SAAyB;CACzD,OAAO,KACJ,QAAQ,sBAAsB,GAAG,EACjC,QAAQ,oBAAoB,IAAI,EAChC,QAAQ,gBAAgB,IAAI,EAC5B,QAAQ,cAAc,IAAI,EAC1B,QAAQ,gBAAgB,IAAI,EAC5B,QAAQ,0BAA0B,GAAG,EACrC,QAAQ,mBAAmB,EAAE,EAC7B,QAAQ,cAAc,EAAE,EACxB,QAAQ,kBAAkB,EAAE,EAC5B,QAAQ,kBAAkB,EAAE;AACjC;AAEA,MAAM,sBAAsB,SAC1B,KAAK,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAEjC,MAAM,oCAAoC,SAAyB;CAEjE,OAAO,KAAK,QAAQ,YAAY,EAAE;AACpC;AAEA,MAAa,kBAAkB,UAAkC;CAG/D,MAAM,oBAAoB,mBAFK,yBAAyB,MAAM,OACd,EAAE,YACY,CAAC;CAG/D,MAAM,kBAAkB,mBADE,iCAAiC,MAAM,OACN,CAAC;CAE5D,OAAO;EACL,GAAG;EACH,cAAc;EACd,YAAY;CACd;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline.cjs","names":["segmentDocument","normalizeBlock","fingerprintBlock","planAlignmentActions","alignEnglishAndFrenchBlocks","mapChangedLinesToBlocks","identifySegmentsToReview"],"sources":["../../../src/translation-alignment/pipeline.ts"],"sourcesContent":["import { alignEnglishAndFrenchBlocks } from './alignBlocks';\nimport { fingerprintBlock } from './fingerprintBlock';\nimport { mapChangedLinesToBlocks } from './mapChangedLinesToBlocks';\nimport { normalizeBlock } from './normalizeBlock';\nimport { planAlignmentActions } from './planActions';\nimport {\n identifySegmentsToReview,\n mergeReviewedSegments,\n type SegmentToReview,\n} from './rebuildDocument';\nimport { segmentDocument } from './segmentDocument';\nimport type {\n AlignmentPlan,\n FingerprintedBlock,\n SimilarityOptions,\n} from './types';\n\nexport type BuildAlignmentPlanInput = {\n englishText: string;\n frenchText: string;\n changedLines: number[] | undefined;\n similarityOptions?: Partial<SimilarityOptions>;\n};\n\nexport type BuildAlignmentPlanOutput = {\n englishBlocks: FingerprintedBlock[];\n frenchBlocks: FingerprintedBlock[];\n plan: AlignmentPlan;\n segmentsToReview: SegmentToReview[];\n};\n\nexport const buildAlignmentPlan = ({\n englishText,\n frenchText,\n changedLines,\n similarityOptions,\n}: BuildAlignmentPlanInput): BuildAlignmentPlanOutput => {\n const englishBlocksRaw = segmentDocument(englishText);\n const frenchBlocksRaw = segmentDocument(frenchText);\n\n const englishNormalized = englishBlocksRaw.map(normalizeBlock);\n const frenchNormalized = frenchBlocksRaw.map(normalizeBlock);\n\n const englishBlocks: FingerprintedBlock[] = englishNormalized.map(\n (block, index, array) =>\n fingerprintBlock(\n block,\n array[index - 1] ?? null,\n array[index + 1] ?? null\n )\n );\n const frenchBlocks: FingerprintedBlock[] = frenchNormalized.map(\n (block, index, array) =>\n fingerprintBlock(\n block,\n array[index - 1] ?? null,\n array[index + 1] ?? null\n )\n );\n\n const alignment = alignEnglishAndFrenchBlocks(englishBlocks, frenchBlocks);\n\n const changedIndexes = mapChangedLinesToBlocks(\n englishBlocks,\n Array.isArray(changedLines) ? changedLines : []\n );\n\n const plan = planAlignmentActions(alignment, changedIndexes, {\n minimumMatchForReuse: similarityOptions?.minimumMatchForReuse ?? 0.9,\n minimumMatchForNearDuplicate:\n similarityOptions?.minimumMatchForNearDuplicate ?? 0.8,\n });\n\n const { segmentsToReview } = identifySegmentsToReview({\n englishBlocks,\n frenchBlocks,\n plan,\n });\n\n return { englishBlocks, frenchBlocks, plan, segmentsToReview };\n};\n\nexport { mergeReviewedSegments };\nexport type { SegmentToReview };\n"],"mappings":";;;;;;;;;;AA+BA,MAAa,sBAAsB,EACjC,aACA,YACA,cACA,wBACuD;CACvD,MAAM,mBAAmBA,8DAAgB,YAAY;CACrD,MAAM,kBAAkBA,8DAAgB,WAAW;CAEnD,MAAM,oBAAoB,iBAAiB,IAAIC,4DAAe;CAC9D,MAAM,mBAAmB,gBAAgB,IAAIA,4DAAe;CAE5D,MAAM,gBAAsC,kBAAkB,KAC3D,OAAO,OAAO,UACbC,gEACE,OACA,MAAM,QAAQ,MAAM,MACpB,MAAM,QAAQ,MAAM,KACrB,CACJ;CACD,MAAM,eAAqC,iBAAiB,KACzD,OAAO,OAAO,UACbA,gEACE,OACA,MAAM,QAAQ,MAAM,MACpB,MAAM,QAAQ,MAAM,KACrB,CACJ;CASD,MAAM,OAAOC,+DAPKC,sEAA4B,eAAe,aAOlB,EALpBC,8EACrB,eACA,MAAM,QAAQ,aAAa,GAAG,eAAe,EAAE,CAGU,EAAE;EAC3D,sBAAsB,mBAAmB,wBAAwB;EACjE,8BACE,mBAAmB,gCAAgC;EACtD,CAAC;CAEF,MAAM,EAAE,qBAAqBC,uEAAyB;EACpD;EACA;EACA;EACD,CAAC;CAEF,OAAO;EAAE;EAAe;EAAc;EAAM;EAAkB"}
1
+ {"version":3,"file":"pipeline.cjs","names":["segmentDocument","normalizeBlock","fingerprintBlock","planAlignmentActions","alignEnglishAndFrenchBlocks","mapChangedLinesToBlocks","identifySegmentsToReview"],"sources":["../../../src/translation-alignment/pipeline.ts"],"sourcesContent":["import { alignEnglishAndFrenchBlocks } from './alignBlocks';\nimport { fingerprintBlock } from './fingerprintBlock';\nimport { mapChangedLinesToBlocks } from './mapChangedLinesToBlocks';\nimport { normalizeBlock } from './normalizeBlock';\nimport { planAlignmentActions } from './planActions';\nimport {\n identifySegmentsToReview,\n mergeReviewedSegments,\n type SegmentToReview,\n} from './rebuildDocument';\nimport { segmentDocument } from './segmentDocument';\nimport type {\n AlignmentPlan,\n FingerprintedBlock,\n SimilarityOptions,\n} from './types';\n\nexport type BuildAlignmentPlanInput = {\n englishText: string;\n frenchText: string;\n changedLines: number[] | undefined;\n similarityOptions?: Partial<SimilarityOptions>;\n};\n\nexport type BuildAlignmentPlanOutput = {\n englishBlocks: FingerprintedBlock[];\n frenchBlocks: FingerprintedBlock[];\n plan: AlignmentPlan;\n segmentsToReview: SegmentToReview[];\n};\n\nexport const buildAlignmentPlan = ({\n englishText,\n frenchText,\n changedLines,\n similarityOptions,\n}: BuildAlignmentPlanInput): BuildAlignmentPlanOutput => {\n const englishBlocksRaw = segmentDocument(englishText);\n const frenchBlocksRaw = segmentDocument(frenchText);\n\n const englishNormalized = englishBlocksRaw.map(normalizeBlock);\n const frenchNormalized = frenchBlocksRaw.map(normalizeBlock);\n\n const englishBlocks: FingerprintedBlock[] = englishNormalized.map(\n (block, index, array) =>\n fingerprintBlock(\n block,\n array[index - 1] ?? null,\n array[index + 1] ?? null\n )\n );\n const frenchBlocks: FingerprintedBlock[] = frenchNormalized.map(\n (block, index, array) =>\n fingerprintBlock(\n block,\n array[index - 1] ?? null,\n array[index + 1] ?? null\n )\n );\n\n const alignment = alignEnglishAndFrenchBlocks(englishBlocks, frenchBlocks);\n\n const changedIndexes = mapChangedLinesToBlocks(\n englishBlocks,\n Array.isArray(changedLines) ? changedLines : []\n );\n\n const plan = planAlignmentActions(alignment, changedIndexes, {\n minimumMatchForReuse: similarityOptions?.minimumMatchForReuse ?? 0.9,\n minimumMatchForNearDuplicate:\n similarityOptions?.minimumMatchForNearDuplicate ?? 0.8,\n });\n\n const { segmentsToReview } = identifySegmentsToReview({\n englishBlocks,\n frenchBlocks,\n plan,\n });\n\n return { englishBlocks, frenchBlocks, plan, segmentsToReview };\n};\n\nexport type { SegmentToReview };\nexport { mergeReviewedSegments };\n"],"mappings":";;;;;;;;;;AA+BA,MAAa,sBAAsB,EACjC,aACA,YACA,cACA,wBACuD;CACvD,MAAM,mBAAmBA,8DAAgB,WAAW;CACpD,MAAM,kBAAkBA,8DAAgB,UAAU;CAElD,MAAM,oBAAoB,iBAAiB,IAAIC,2DAAc;CAC7D,MAAM,mBAAmB,gBAAgB,IAAIA,2DAAc;CAE3D,MAAM,gBAAsC,kBAAkB,KAC3D,OAAO,OAAO,UACbC,gEACE,OACA,MAAM,QAAQ,MAAM,MACpB,MAAM,QAAQ,MAAM,IACtB,CACJ;CACA,MAAM,eAAqC,iBAAiB,KACzD,OAAO,OAAO,UACbA,gEACE,OACA,MAAM,QAAQ,MAAM,MACpB,MAAM,QAAQ,MAAM,IACtB,CACJ;CASA,MAAM,OAAOC,+DAPKC,sEAA4B,eAAe,YAOnB,GALnBC,8EACrB,eACA,MAAM,QAAQ,YAAY,IAAI,eAAe,CAAC,CAGU,GAAG;EAC3D,sBAAsB,mBAAmB,wBAAwB;EACjE,8BACE,mBAAmB,gCAAgC;CACvD,CAAC;CAED,MAAM,EAAE,qBAAqBC,uEAAyB;EACpD;EACA;EACA;CACF,CAAC;CAED,OAAO;EAAE;EAAe;EAAc;EAAM;CAAiB;AAC/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"planActions.cjs","names":[],"sources":["../../../src/translation-alignment/planActions.ts"],"sourcesContent":["import type { AlignmentPair, AlignmentPlan, PlannedAction } from './types';\n\nexport const planAlignmentActions = (\n alignment: AlignmentPair[],\n changedEnglishBlockIndexes: Set<number>\n): AlignmentPlan => {\n const actions: PlannedAction[] = [];\n const seenFrench = new Set<number>();\n\n alignment.forEach((pair) => {\n const englishIndex = pair.englishIndex;\n const frenchIndex = pair.frenchIndex;\n\n // Case 1: Deletion (Exists in FR, not in EN)\n if (englishIndex === -1 && frenchIndex !== null) {\n if (!seenFrench.has(frenchIndex)) {\n actions.push({ kind: 'delete', frenchIndex });\n seenFrench.add(frenchIndex);\n }\n return;\n }\n\n // Case 2: New Insertion (Exists in EN, not in FR)\n if (englishIndex >= 0 && frenchIndex === null) {\n actions.push({ kind: 'insert_new', englishIndex });\n return;\n }\n\n // Case 3: Alignment (Exists in both)\n if (englishIndex >= 0 && frenchIndex !== null) {\n const isChanged = changedEnglishBlockIndexes.has(englishIndex);\n\n // If the block is NOT marked as changed by Git, we REUSE it.\n // We assume the existing translation is correct because the source hasn't been touched.\n // We ignore 'similarityScore' here because EN vs UK text will always have low similarity.\n if (!isChanged) {\n actions.push({ kind: 'reuse', englishIndex, frenchIndex });\n } else {\n // If the block IS changed, we normally Review.\n // OPTIONAL: You could add a check here for 'similarityScore > 0.99'\n // to detect whitespace-only changes, but generally, if Git says changed, we Review.\n actions.push({ kind: 'review', englishIndex, frenchIndex });\n }\n\n seenFrench.add(frenchIndex);\n return;\n }\n });\n\n return { actions };\n};\n"],"mappings":";;;AAEA,MAAa,wBACX,WACA,+BACkB;CAClB,MAAM,UAA2B,EAAE;CACnC,MAAM,6BAAa,IAAI,KAAa;CAEpC,UAAU,SAAS,SAAS;EAC1B,MAAM,eAAe,KAAK;EAC1B,MAAM,cAAc,KAAK;EAGzB,IAAI,iBAAiB,MAAM,gBAAgB,MAAM;GAC/C,IAAI,CAAC,WAAW,IAAI,YAAY,EAAE;IAChC,QAAQ,KAAK;KAAE,MAAM;KAAU;KAAa,CAAC;IAC7C,WAAW,IAAI,YAAY;;GAE7B;;EAIF,IAAI,gBAAgB,KAAK,gBAAgB,MAAM;GAC7C,QAAQ,KAAK;IAAE,MAAM;IAAc;IAAc,CAAC;GAClD;;EAIF,IAAI,gBAAgB,KAAK,gBAAgB,MAAM;GAM7C,IAAI,CALc,2BAA2B,IAAI,aAKnC,EACZ,QAAQ,KAAK;IAAE,MAAM;IAAS;IAAc;IAAa,CAAC;QAK1D,QAAQ,KAAK;IAAE,MAAM;IAAU;IAAc;IAAa,CAAC;GAG7D,WAAW,IAAI,YAAY;GAC3B;;GAEF;CAEF,OAAO,EAAE,SAAS"}
1
+ {"version":3,"file":"planActions.cjs","names":[],"sources":["../../../src/translation-alignment/planActions.ts"],"sourcesContent":["import type { AlignmentPair, AlignmentPlan, PlannedAction } from './types';\n\nexport const planAlignmentActions = (\n alignment: AlignmentPair[],\n changedEnglishBlockIndexes: Set<number>\n): AlignmentPlan => {\n const actions: PlannedAction[] = [];\n const seenFrench = new Set<number>();\n\n alignment.forEach((pair) => {\n const englishIndex = pair.englishIndex;\n const frenchIndex = pair.frenchIndex;\n\n // Case 1: Deletion (Exists in FR, not in EN)\n if (englishIndex === -1 && frenchIndex !== null) {\n if (!seenFrench.has(frenchIndex)) {\n actions.push({ kind: 'delete', frenchIndex });\n seenFrench.add(frenchIndex);\n }\n return;\n }\n\n // Case 2: New Insertion (Exists in EN, not in FR)\n if (englishIndex >= 0 && frenchIndex === null) {\n actions.push({ kind: 'insert_new', englishIndex });\n return;\n }\n\n // Case 3: Alignment (Exists in both)\n if (englishIndex >= 0 && frenchIndex !== null) {\n const isChanged = changedEnglishBlockIndexes.has(englishIndex);\n\n // If the block is NOT marked as changed by Git, we REUSE it.\n // We assume the existing translation is correct because the source hasn't been touched.\n // We ignore 'similarityScore' here because EN vs UK text will always have low similarity.\n if (!isChanged) {\n actions.push({ kind: 'reuse', englishIndex, frenchIndex });\n } else {\n // If the block IS changed, we normally Review.\n // OPTIONAL: You could add a check here for 'similarityScore > 0.99'\n // to detect whitespace-only changes, but generally, if Git says changed, we Review.\n actions.push({ kind: 'review', englishIndex, frenchIndex });\n }\n\n seenFrench.add(frenchIndex);\n return;\n }\n });\n\n return { actions };\n};\n"],"mappings":";;;AAEA,MAAa,wBACX,WACA,+BACkB;CAClB,MAAM,UAA2B,CAAC;CAClC,MAAM,6BAAa,IAAI,IAAY;CAEnC,UAAU,SAAS,SAAS;EAC1B,MAAM,eAAe,KAAK;EAC1B,MAAM,cAAc,KAAK;EAGzB,IAAI,iBAAiB,MAAM,gBAAgB,MAAM;GAC/C,IAAI,CAAC,WAAW,IAAI,WAAW,GAAG;IAChC,QAAQ,KAAK;KAAE,MAAM;KAAU;IAAY,CAAC;IAC5C,WAAW,IAAI,WAAW;GAC5B;GACA;EACF;EAGA,IAAI,gBAAgB,KAAK,gBAAgB,MAAM;GAC7C,QAAQ,KAAK;IAAE,MAAM;IAAc;GAAa,CAAC;GACjD;EACF;EAGA,IAAI,gBAAgB,KAAK,gBAAgB,MAAM;GAM7C,IAAI,CALc,2BAA2B,IAAI,YAKpC,GACX,QAAQ,KAAK;IAAE,MAAM;IAAS;IAAc;GAAY,CAAC;QAKzD,QAAQ,KAAK;IAAE,MAAM;IAAU;IAAc;GAAY,CAAC;GAG5D,WAAW,IAAI,WAAW;GAC1B;EACF;CACF,CAAC;CAED,OAAO,EAAE,QAAQ;AACnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"rebuildDocument.cjs","names":[],"sources":["../../../src/translation-alignment/rebuildDocument.ts"],"sourcesContent":["import type { AlignmentPlan, FingerprintedBlock } from './types';\n\nexport type SegmentToReview = {\n englishBlock: FingerprintedBlock;\n frenchBlockText: string | null;\n actionIndex: number;\n};\n\nexport type RebuildInput = {\n englishBlocks: FingerprintedBlock[];\n frenchBlocks: FingerprintedBlock[];\n plan: AlignmentPlan;\n};\n\nexport type RebuildResult = {\n segmentsToReview: SegmentToReview[];\n};\n\n/**\n * Analyzes the alignment plan and returns only the segments that need review/translation.\n * Does not generate output text - that's done by mergeReviewedSegments after translation.\n */\nexport const identifySegmentsToReview = ({\n englishBlocks,\n frenchBlocks,\n plan,\n}: RebuildInput): RebuildResult => {\n const segmentsToReview: SegmentToReview[] = [];\n\n plan.actions.forEach((action, actionIndex) => {\n if (action.kind === 'review') {\n const englishBlock = englishBlocks[action.englishIndex];\n const frenchBlockText =\n action.frenchIndex !== null\n ? frenchBlocks[action.frenchIndex].content\n : null;\n\n segmentsToReview.push({ englishBlock, frenchBlockText, actionIndex });\n } else if (action.kind === 'insert_new') {\n const englishBlock = englishBlocks[action.englishIndex];\n\n segmentsToReview.push({\n englishBlock,\n frenchBlockText: null,\n actionIndex,\n });\n }\n });\n\n return { segmentsToReview };\n};\n\n/**\n * Merges reviewed translations back into the final document following the alignment plan.\n */\nexport const mergeReviewedSegments = (\n plan: AlignmentPlan,\n frenchBlocks: FingerprintedBlock[],\n reviewedSegments: Map<number, string>\n): string => {\n const outputParts: string[] = [];\n\n plan.actions.forEach((action, actionIndex) => {\n if (action.kind === 'reuse') {\n outputParts.push(frenchBlocks[action.frenchIndex].content);\n } else if (action.kind === 'review' || action.kind === 'insert_new') {\n const reviewedContent = reviewedSegments.get(actionIndex);\n\n if (reviewedContent !== undefined) {\n outputParts.push(reviewedContent);\n } else {\n // Fallback: if review failed, use existing or blank\n if (action.kind === 'review' && action.frenchIndex !== null) {\n outputParts.push(frenchBlocks[action.frenchIndex].content);\n } else {\n outputParts.push('\\n');\n }\n }\n }\n // \"delete\" actions are simply skipped - no output\n });\n\n return outputParts.join('');\n};\n"],"mappings":";;;;;;;AAsBA,MAAa,4BAA4B,EACvC,eACA,cACA,WACiC;CACjC,MAAM,mBAAsC,EAAE;CAE9C,KAAK,QAAQ,SAAS,QAAQ,gBAAgB;EAC5C,IAAI,OAAO,SAAS,UAAU;GAC5B,MAAM,eAAe,cAAc,OAAO;GAC1C,MAAM,kBACJ,OAAO,gBAAgB,OACnB,aAAa,OAAO,aAAa,UACjC;GAEN,iBAAiB,KAAK;IAAE;IAAc;IAAiB;IAAa,CAAC;SAChE,IAAI,OAAO,SAAS,cAAc;GACvC,MAAM,eAAe,cAAc,OAAO;GAE1C,iBAAiB,KAAK;IACpB;IACA,iBAAiB;IACjB;IACD,CAAC;;GAEJ;CAEF,OAAO,EAAE,kBAAkB;;;;;AAM7B,MAAa,yBACX,MACA,cACA,qBACW;CACX,MAAM,cAAwB,EAAE;CAEhC,KAAK,QAAQ,SAAS,QAAQ,gBAAgB;EAC5C,IAAI,OAAO,SAAS,SAClB,YAAY,KAAK,aAAa,OAAO,aAAa,QAAQ;OACrD,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,cAAc;GACnE,MAAM,kBAAkB,iBAAiB,IAAI,YAAY;GAEzD,IAAI,oBAAoB,QACtB,YAAY,KAAK,gBAAgB;QAGjC,IAAI,OAAO,SAAS,YAAY,OAAO,gBAAgB,MACrD,YAAY,KAAK,aAAa,OAAO,aAAa,QAAQ;QAE1D,YAAY,KAAK,KAAK;;GAK5B;CAEF,OAAO,YAAY,KAAK,GAAG"}
1
+ {"version":3,"file":"rebuildDocument.cjs","names":[],"sources":["../../../src/translation-alignment/rebuildDocument.ts"],"sourcesContent":["import type { AlignmentPlan, FingerprintedBlock } from './types';\n\nexport type SegmentToReview = {\n englishBlock: FingerprintedBlock;\n frenchBlockText: string | null;\n actionIndex: number;\n};\n\nexport type RebuildInput = {\n englishBlocks: FingerprintedBlock[];\n frenchBlocks: FingerprintedBlock[];\n plan: AlignmentPlan;\n};\n\nexport type RebuildResult = {\n segmentsToReview: SegmentToReview[];\n};\n\n/**\n * Analyzes the alignment plan and returns only the segments that need review/translation.\n * Does not generate output text - that's done by mergeReviewedSegments after translation.\n */\nexport const identifySegmentsToReview = ({\n englishBlocks,\n frenchBlocks,\n plan,\n}: RebuildInput): RebuildResult => {\n const segmentsToReview: SegmentToReview[] = [];\n\n plan.actions.forEach((action, actionIndex) => {\n if (action.kind === 'review') {\n const englishBlock = englishBlocks[action.englishIndex];\n const frenchBlockText =\n action.frenchIndex !== null\n ? frenchBlocks[action.frenchIndex].content\n : null;\n\n segmentsToReview.push({ englishBlock, frenchBlockText, actionIndex });\n } else if (action.kind === 'insert_new') {\n const englishBlock = englishBlocks[action.englishIndex];\n\n segmentsToReview.push({\n englishBlock,\n frenchBlockText: null,\n actionIndex,\n });\n }\n });\n\n return { segmentsToReview };\n};\n\n/**\n * Merges reviewed translations back into the final document following the alignment plan.\n */\nexport const mergeReviewedSegments = (\n plan: AlignmentPlan,\n frenchBlocks: FingerprintedBlock[],\n reviewedSegments: Map<number, string>\n): string => {\n const outputParts: string[] = [];\n\n plan.actions.forEach((action, actionIndex) => {\n if (action.kind === 'reuse') {\n outputParts.push(frenchBlocks[action.frenchIndex].content);\n } else if (action.kind === 'review' || action.kind === 'insert_new') {\n const reviewedContent = reviewedSegments.get(actionIndex);\n\n if (reviewedContent !== undefined) {\n outputParts.push(reviewedContent);\n } else {\n // Fallback: if review failed, use existing or blank\n if (action.kind === 'review' && action.frenchIndex !== null) {\n outputParts.push(frenchBlocks[action.frenchIndex].content);\n } else {\n outputParts.push('\\n');\n }\n }\n }\n // \"delete\" actions are simply skipped - no output\n });\n\n return outputParts.join('');\n};\n"],"mappings":";;;;;;;AAsBA,MAAa,4BAA4B,EACvC,eACA,cACA,WACiC;CACjC,MAAM,mBAAsC,CAAC;CAE7C,KAAK,QAAQ,SAAS,QAAQ,gBAAgB;EAC5C,IAAI,OAAO,SAAS,UAAU;GAC5B,MAAM,eAAe,cAAc,OAAO;GAC1C,MAAM,kBACJ,OAAO,gBAAgB,OACnB,aAAa,OAAO,aAAa,UACjC;GAEN,iBAAiB,KAAK;IAAE;IAAc;IAAiB;GAAY,CAAC;EACtE,OAAO,IAAI,OAAO,SAAS,cAAc;GACvC,MAAM,eAAe,cAAc,OAAO;GAE1C,iBAAiB,KAAK;IACpB;IACA,iBAAiB;IACjB;GACF,CAAC;EACH;CACF,CAAC;CAED,OAAO,EAAE,iBAAiB;AAC5B;;;;AAKA,MAAa,yBACX,MACA,cACA,qBACW;CACX,MAAM,cAAwB,CAAC;CAE/B,KAAK,QAAQ,SAAS,QAAQ,gBAAgB;EAC5C,IAAI,OAAO,SAAS,SAClB,YAAY,KAAK,aAAa,OAAO,aAAa,OAAO;OACpD,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,cAAc;GACnE,MAAM,kBAAkB,iBAAiB,IAAI,WAAW;GAExD,IAAI,oBAAoB,QACtB,YAAY,KAAK,eAAe;QAGhC,IAAI,OAAO,SAAS,YAAY,OAAO,gBAAgB,MACrD,YAAY,KAAK,aAAa,OAAO,aAAa,OAAO;QAEzD,YAAY,KAAK,IAAI;EAG3B;CAEF,CAAC;CAED,OAAO,YAAY,KAAK,EAAE;AAC5B"}
@@ -1 +1 @@
1
- {"version":3,"file":"segmentDocument.cjs","names":[],"sources":["../../../src/translation-alignment/segmentDocument.ts"],"sourcesContent":["import type { Block } from './types';\n\nconst isBlankLine = (line: string): boolean => line.trim().length === 0;\nconst isFencedCodeDelimiter = (line: string): boolean => /^\\s*```/.test(line);\nconst isHeading = (line: string): boolean => /^\\s*#{1,6}\\s+/.test(line);\nconst isFrontmatterDelimiter = (line: string): boolean =>\n /^\\s*---\\s*$/.test(line);\nconst trimTrailingNewlines = (text: string): string =>\n text.replace(/\\n+$/g, '\\n');\n\nexport const segmentDocument = (text: string): Block[] => {\n const lines = text.split('\\n');\n const blocks: Block[] = [];\n\n let index = 0;\n let insideCodeBlock = false;\n\n // Buffers\n let currentSectionLines: string[] = [];\n let currentSectionStartLine = 1;\n\n const flushCurrentSection = (endIndex: number) => {\n if (currentSectionLines.length > 0) {\n // Filter out leading blank lines from the block content to keep it clean,\n // but strictly speaking, we just want to ensure non-empty content.\n const rawContent = currentSectionLines.join('\\n');\n\n if (rawContent.trim().length > 0) {\n blocks.push({\n type: 'paragraph', // Generic type\n content: `${trimTrailingNewlines(rawContent)}\\n`,\n lineStart: currentSectionStartLine,\n lineEnd: endIndex,\n });\n }\n currentSectionLines = [];\n }\n };\n\n while (index < lines.length) {\n const currentLine = lines[index];\n\n // 1. Handle Frontmatter (Must be at start of file)\n if (blocks.length === 0 && isFrontmatterDelimiter(currentLine)) {\n const startLine = index + 1;\n const contentLines: string[] = [currentLine];\n index++;\n\n while (index < lines.length && !isFrontmatterDelimiter(lines[index])) {\n contentLines.push(lines[index]);\n index++;\n }\n\n if (index < lines.length && isFrontmatterDelimiter(lines[index])) {\n contentLines.push(lines[index]);\n index++;\n }\n\n blocks.push({\n type: 'paragraph',\n content: `${trimTrailingNewlines(contentLines.join('\\n'))}\\n`,\n lineStart: startLine,\n lineEnd: index,\n });\n continue;\n }\n\n // 2. Track Code Blocks (Headers inside code blocks are ignored)\n if (isFencedCodeDelimiter(currentLine)) {\n insideCodeBlock = !insideCodeBlock;\n }\n\n const isHeader = !insideCodeBlock && isHeading(currentLine);\n\n // 3. Split on Headers\n if (isHeader) {\n // If we have accumulated content, flush it as the previous block\n if (currentSectionLines.length > 0) {\n flushCurrentSection(index);\n }\n // Start a new section with this header\n currentSectionStartLine = index + 1;\n currentSectionLines = [currentLine];\n } else {\n // Accumulate content\n if (currentSectionLines.length === 0 && !isBlankLine(currentLine)) {\n currentSectionStartLine = index + 1;\n }\n currentSectionLines.push(currentLine);\n }\n\n index++;\n }\n\n // Flush remaining content\n flushCurrentSection(index);\n\n return blocks;\n};\n"],"mappings":";;;AAEA,MAAM,eAAe,SAA0B,KAAK,MAAM,CAAC,WAAW;AACtE,MAAM,yBAAyB,SAA0B,UAAU,KAAK,KAAK;AAC7E,MAAM,aAAa,SAA0B,gBAAgB,KAAK,KAAK;AACvE,MAAM,0BAA0B,SAC9B,cAAc,KAAK,KAAK;AAC1B,MAAM,wBAAwB,SAC5B,KAAK,QAAQ,SAAS,KAAK;AAE7B,MAAa,mBAAmB,SAA0B;CACxD,MAAM,QAAQ,KAAK,MAAM,KAAK;CAC9B,MAAM,SAAkB,EAAE;CAE1B,IAAI,QAAQ;CACZ,IAAI,kBAAkB;CAGtB,IAAI,sBAAgC,EAAE;CACtC,IAAI,0BAA0B;CAE9B,MAAM,uBAAuB,aAAqB;EAChD,IAAI,oBAAoB,SAAS,GAAG;GAGlC,MAAM,aAAa,oBAAoB,KAAK,KAAK;GAEjD,IAAI,WAAW,MAAM,CAAC,SAAS,GAC7B,OAAO,KAAK;IACV,MAAM;IACN,SAAS,GAAG,qBAAqB,WAAW,CAAC;IAC7C,WAAW;IACX,SAAS;IACV,CAAC;GAEJ,sBAAsB,EAAE;;;CAI5B,OAAO,QAAQ,MAAM,QAAQ;EAC3B,MAAM,cAAc,MAAM;EAG1B,IAAI,OAAO,WAAW,KAAK,uBAAuB,YAAY,EAAE;GAC9D,MAAM,YAAY,QAAQ;GAC1B,MAAM,eAAyB,CAAC,YAAY;GAC5C;GAEA,OAAO,QAAQ,MAAM,UAAU,CAAC,uBAAuB,MAAM,OAAO,EAAE;IACpE,aAAa,KAAK,MAAM,OAAO;IAC/B;;GAGF,IAAI,QAAQ,MAAM,UAAU,uBAAuB,MAAM,OAAO,EAAE;IAChE,aAAa,KAAK,MAAM,OAAO;IAC/B;;GAGF,OAAO,KAAK;IACV,MAAM;IACN,SAAS,GAAG,qBAAqB,aAAa,KAAK,KAAK,CAAC,CAAC;IAC1D,WAAW;IACX,SAAS;IACV,CAAC;GACF;;EAIF,IAAI,sBAAsB,YAAY,EACpC,kBAAkB,CAAC;EAMrB,IAHiB,CAAC,mBAAmB,UAAU,YAAY,EAG7C;GAEZ,IAAI,oBAAoB,SAAS,GAC/B,oBAAoB,MAAM;GAG5B,0BAA0B,QAAQ;GAClC,sBAAsB,CAAC,YAAY;SAC9B;GAEL,IAAI,oBAAoB,WAAW,KAAK,CAAC,YAAY,YAAY,EAC/D,0BAA0B,QAAQ;GAEpC,oBAAoB,KAAK,YAAY;;EAGvC;;CAIF,oBAAoB,MAAM;CAE1B,OAAO"}
1
+ {"version":3,"file":"segmentDocument.cjs","names":[],"sources":["../../../src/translation-alignment/segmentDocument.ts"],"sourcesContent":["import type { Block } from './types';\n\nconst isBlankLine = (line: string): boolean => line.trim().length === 0;\nconst isFencedCodeDelimiter = (line: string): boolean => /^\\s*```/.test(line);\nconst isHeading = (line: string): boolean => /^\\s*#{1,6}\\s+/.test(line);\nconst isFrontmatterDelimiter = (line: string): boolean =>\n /^\\s*---\\s*$/.test(line);\nconst trimTrailingNewlines = (text: string): string =>\n text.replace(/\\n+$/g, '\\n');\n\nexport const segmentDocument = (text: string): Block[] => {\n const lines = text.split('\\n');\n const blocks: Block[] = [];\n\n let index = 0;\n let insideCodeBlock = false;\n\n // Buffers\n let currentSectionLines: string[] = [];\n let currentSectionStartLine = 1;\n\n const flushCurrentSection = (endIndex: number) => {\n if (currentSectionLines.length > 0) {\n // Filter out leading blank lines from the block content to keep it clean,\n // but strictly speaking, we just want to ensure non-empty content.\n const rawContent = currentSectionLines.join('\\n');\n\n if (rawContent.trim().length > 0) {\n blocks.push({\n type: 'paragraph', // Generic type\n content: `${trimTrailingNewlines(rawContent)}\\n`,\n lineStart: currentSectionStartLine,\n lineEnd: endIndex,\n });\n }\n currentSectionLines = [];\n }\n };\n\n while (index < lines.length) {\n const currentLine = lines[index];\n\n // 1. Handle Frontmatter (Must be at start of file)\n if (blocks.length === 0 && isFrontmatterDelimiter(currentLine)) {\n const startLine = index + 1;\n const contentLines: string[] = [currentLine];\n index++;\n\n while (index < lines.length && !isFrontmatterDelimiter(lines[index])) {\n contentLines.push(lines[index]);\n index++;\n }\n\n if (index < lines.length && isFrontmatterDelimiter(lines[index])) {\n contentLines.push(lines[index]);\n index++;\n }\n\n blocks.push({\n type: 'paragraph',\n content: `${trimTrailingNewlines(contentLines.join('\\n'))}\\n`,\n lineStart: startLine,\n lineEnd: index,\n });\n continue;\n }\n\n // 2. Track Code Blocks (Headers inside code blocks are ignored)\n if (isFencedCodeDelimiter(currentLine)) {\n insideCodeBlock = !insideCodeBlock;\n }\n\n const isHeader = !insideCodeBlock && isHeading(currentLine);\n\n // 3. Split on Headers\n if (isHeader) {\n // If we have accumulated content, flush it as the previous block\n if (currentSectionLines.length > 0) {\n flushCurrentSection(index);\n }\n // Start a new section with this header\n currentSectionStartLine = index + 1;\n currentSectionLines = [currentLine];\n } else {\n // Accumulate content\n if (currentSectionLines.length === 0 && !isBlankLine(currentLine)) {\n currentSectionStartLine = index + 1;\n }\n currentSectionLines.push(currentLine);\n }\n\n index++;\n }\n\n // Flush remaining content\n flushCurrentSection(index);\n\n return blocks;\n};\n"],"mappings":";;;AAEA,MAAM,eAAe,SAA0B,KAAK,KAAK,EAAE,WAAW;AACtE,MAAM,yBAAyB,SAA0B,UAAU,KAAK,IAAI;AAC5E,MAAM,aAAa,SAA0B,gBAAgB,KAAK,IAAI;AACtE,MAAM,0BAA0B,SAC9B,cAAc,KAAK,IAAI;AACzB,MAAM,wBAAwB,SAC5B,KAAK,QAAQ,SAAS,IAAI;AAE5B,MAAa,mBAAmB,SAA0B;CACxD,MAAM,QAAQ,KAAK,MAAM,IAAI;CAC7B,MAAM,SAAkB,CAAC;CAEzB,IAAI,QAAQ;CACZ,IAAI,kBAAkB;CAGtB,IAAI,sBAAgC,CAAC;CACrC,IAAI,0BAA0B;CAE9B,MAAM,uBAAuB,aAAqB;EAChD,IAAI,oBAAoB,SAAS,GAAG;GAGlC,MAAM,aAAa,oBAAoB,KAAK,IAAI;GAEhD,IAAI,WAAW,KAAK,EAAE,SAAS,GAC7B,OAAO,KAAK;IACV,MAAM;IACN,SAAS,GAAG,qBAAqB,UAAU,EAAE;IAC7C,WAAW;IACX,SAAS;GACX,CAAC;GAEH,sBAAsB,CAAC;EACzB;CACF;CAEA,OAAO,QAAQ,MAAM,QAAQ;EAC3B,MAAM,cAAc,MAAM;EAG1B,IAAI,OAAO,WAAW,KAAK,uBAAuB,WAAW,GAAG;GAC9D,MAAM,YAAY,QAAQ;GAC1B,MAAM,eAAyB,CAAC,WAAW;GAC3C;GAEA,OAAO,QAAQ,MAAM,UAAU,CAAC,uBAAuB,MAAM,MAAM,GAAG;IACpE,aAAa,KAAK,MAAM,MAAM;IAC9B;GACF;GAEA,IAAI,QAAQ,MAAM,UAAU,uBAAuB,MAAM,MAAM,GAAG;IAChE,aAAa,KAAK,MAAM,MAAM;IAC9B;GACF;GAEA,OAAO,KAAK;IACV,MAAM;IACN,SAAS,GAAG,qBAAqB,aAAa,KAAK,IAAI,CAAC,EAAE;IAC1D,WAAW;IACX,SAAS;GACX,CAAC;GACD;EACF;EAGA,IAAI,sBAAsB,WAAW,GACnC,kBAAkB,CAAC;EAMrB,IAHiB,CAAC,mBAAmB,UAAU,WAAW,GAG5C;GAEZ,IAAI,oBAAoB,SAAS,GAC/B,oBAAoB,KAAK;GAG3B,0BAA0B,QAAQ;GAClC,sBAAsB,CAAC,WAAW;EACpC,OAAO;GAEL,IAAI,oBAAoB,WAAW,KAAK,CAAC,YAAY,WAAW,GAC9D,0BAA0B,QAAQ;GAEpC,oBAAoB,KAAK,WAAW;EACtC;EAEA;CACF;CAGA,oBAAoB,KAAK;CAEzB,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"calculateChunks.cjs","names":[],"sources":["../../../src/utils/calculateChunks.ts"],"sourcesContent":["import { splitTextByLines } from '@intlayer/chokidar/utils';\n\nexport type ChunkLineResult = {\n lineStart: number;\n lineLength: number;\n charStart: number;\n charLength: number;\n content: string;\n};\n\nconst DEFAULT_MAX_CHARS_PER_CHUNK = 800;\nconst DEFAULT_OVERLAP_CHARS = 0;\n\nexport const chunkText = (\n text: string,\n maxCharsPerChunk: number = DEFAULT_MAX_CHARS_PER_CHUNK,\n overlapChars: number = DEFAULT_OVERLAP_CHARS\n): ChunkLineResult[] => {\n if (maxCharsPerChunk <= 0) {\n throw new Error('maxCharsPerChunk must be greater than 0');\n }\n\n const splittedText = splitTextByLines(text);\n\n // Split text into lines to facilitate the translation\n const lines: ChunkLineResult[] = [];\n let charStartAcc = 0;\n\n splittedText.forEach((line, index) => {\n lines.push({\n content: line,\n lineStart: index,\n lineLength: 1,\n charStart: charStartAcc,\n charLength: line.length,\n });\n charStartAcc += line.length;\n });\n\n // Group lines\n // as long as the chunk length is less than maxCharsPerChunk\n // if a line longer than maxCharsPerChunk, keep it alone\n // if a line is not longer than maxCharsPerChunk, it is grouped\n const groupedLines: ChunkLineResult[] = lines.reduce(\n (acc: ChunkLineResult[], line) => {\n // If this line alone exceeds maxCharsPerChunk, keep it separate\n if (line.content.length > maxCharsPerChunk) {\n acc.push(line);\n return acc;\n }\n\n // If we have no chunks yet, start with this line\n if (acc.length === 0) {\n acc.push(line);\n return acc;\n }\n\n // Get the last chunk\n const lastChunk = acc[acc.length - 1];\n\n // Calculate what the combined length would be (including newline character)\n const combinedLength = lastChunk.content.length + line.content.length;\n\n // If combining would exceed the limit, start a new chunk\n if (combinedLength > maxCharsPerChunk) {\n acc.push(line);\n return acc;\n }\n\n // Otherwise, combine with the last chunk\n const combinedContent = lastChunk.content + line.content;\n const updatedChunk = {\n content: combinedContent,\n lineStart: lastChunk.lineStart,\n lineLength: lastChunk.lineLength + line.lineLength,\n charStart: lastChunk.charStart,\n charLength: combinedContent.length,\n };\n\n acc[acc.length - 1] = updatedChunk;\n return acc;\n },\n []\n );\n\n // If one line is longer than maxCharsPerChunk, split it into multiple chunks\n const splittedLines: ChunkLineResult[] = groupedLines.flatMap((line) => {\n const chunk: ChunkLineResult[] = [];\n\n if (line.content.length <= maxCharsPerChunk) {\n chunk.push(line);\n return chunk;\n }\n\n for (let i = 0; i < line.content.length; i += maxCharsPerChunk) {\n const slicedContent = line.content.slice(i, i + maxCharsPerChunk);\n chunk.push({\n content: slicedContent,\n lineStart: line.lineStart,\n lineLength: 1,\n charStart: line.charStart + i,\n charLength: slicedContent.length,\n });\n }\n return chunk;\n });\n\n if (overlapChars === 0) return splittedLines;\n\n const overlapChunks: ChunkLineResult[] =\n splittedLines.length > 0 ? [splittedLines[0]] : [];\n\n for (let i = 1; i < splittedLines.length; i++) {\n const previousChunk = splittedLines[i - 1];\n const chunk = splittedLines[i];\n\n const overlapContent = previousChunk.content.slice(-overlapChars);\n const overlapLineNb = splitTextByLines(overlapContent).length;\n\n const overlapContentWithoutPartialLine = overlapContent.slice(\n overlapLineNb > 1 ? overlapContent.indexOf('\\n') + 1 : 0,\n overlapContent.length\n );\n\n const newContent = overlapContentWithoutPartialLine + chunk.content;\n const newLineLength = splitTextByLines(newContent).length;\n const lineDiff = chunk.lineLength - newLineLength;\n\n const overlappedChunk = {\n content: newContent,\n lineStart: chunk.lineStart + lineDiff,\n lineLength: chunk.lineLength - lineDiff,\n charStart: chunk.charStart - overlapContentWithoutPartialLine.length,\n charLength: newContent.length,\n };\n\n overlapChunks.push(overlappedChunk);\n }\n\n return overlapChunks;\n};\n"],"mappings":";;;;;AAUA,MAAM,8BAA8B;AACpC,MAAM,wBAAwB;AAE9B,MAAa,aACX,MACA,mBAA2B,6BAC3B,eAAuB,0BACD;CACtB,IAAI,oBAAoB,GACtB,MAAM,IAAI,MAAM,0CAA0C;CAG5D,MAAM,8DAAgC,KAAK;CAG3C,MAAM,QAA2B,EAAE;CACnC,IAAI,eAAe;CAEnB,aAAa,SAAS,MAAM,UAAU;EACpC,MAAM,KAAK;GACT,SAAS;GACT,WAAW;GACX,YAAY;GACZ,WAAW;GACX,YAAY,KAAK;GAClB,CAAC;EACF,gBAAgB,KAAK;GACrB;CAiDF,MAAM,gBA3CkC,MAAM,QAC3C,KAAwB,SAAS;EAEhC,IAAI,KAAK,QAAQ,SAAS,kBAAkB;GAC1C,IAAI,KAAK,KAAK;GACd,OAAO;;EAIT,IAAI,IAAI,WAAW,GAAG;GACpB,IAAI,KAAK,KAAK;GACd,OAAO;;EAIT,MAAM,YAAY,IAAI,IAAI,SAAS;EAMnC,IAHuB,UAAU,QAAQ,SAAS,KAAK,QAAQ,SAG1C,kBAAkB;GACrC,IAAI,KAAK,KAAK;GACd,OAAO;;EAIT,MAAM,kBAAkB,UAAU,UAAU,KAAK;EACjD,MAAM,eAAe;GACnB,SAAS;GACT,WAAW,UAAU;GACrB,YAAY,UAAU,aAAa,KAAK;GACxC,WAAW,UAAU;GACrB,YAAY,gBAAgB;GAC7B;EAED,IAAI,IAAI,SAAS,KAAK;EACtB,OAAO;IAET,EAAE,CAIiD,CAAC,SAAS,SAAS;EACtE,MAAM,QAA2B,EAAE;EAEnC,IAAI,KAAK,QAAQ,UAAU,kBAAkB;GAC3C,MAAM,KAAK,KAAK;GAChB,OAAO;;EAGT,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,QAAQ,KAAK,kBAAkB;GAC9D,MAAM,gBAAgB,KAAK,QAAQ,MAAM,GAAG,IAAI,iBAAiB;GACjE,MAAM,KAAK;IACT,SAAS;IACT,WAAW,KAAK;IAChB,YAAY;IACZ,WAAW,KAAK,YAAY;IAC5B,YAAY,cAAc;IAC3B,CAAC;;EAEJ,OAAO;GACP;CAEF,IAAI,iBAAiB,GAAG,OAAO;CAE/B,MAAM,gBACJ,cAAc,SAAS,IAAI,CAAC,cAAc,GAAG,GAAG,EAAE;CAEpD,KAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KAAK;EAC7C,MAAM,gBAAgB,cAAc,IAAI;EACxC,MAAM,QAAQ,cAAc;EAE5B,MAAM,iBAAiB,cAAc,QAAQ,MAAM,CAAC,aAAa;EACjE,MAAM,+DAAiC,eAAe,CAAC;EAEvD,MAAM,mCAAmC,eAAe,MACtD,gBAAgB,IAAI,eAAe,QAAQ,KAAK,GAAG,IAAI,GACvD,eAAe,OAChB;EAED,MAAM,aAAa,mCAAmC,MAAM;EAC5D,MAAM,+DAAiC,WAAW,CAAC;EACnD,MAAM,WAAW,MAAM,aAAa;EAEpC,MAAM,kBAAkB;GACtB,SAAS;GACT,WAAW,MAAM,YAAY;GAC7B,YAAY,MAAM,aAAa;GAC/B,WAAW,MAAM,YAAY,iCAAiC;GAC9D,YAAY,WAAW;GACxB;EAED,cAAc,KAAK,gBAAgB;;CAGrC,OAAO"}
1
+ {"version":3,"file":"calculateChunks.cjs","names":[],"sources":["../../../src/utils/calculateChunks.ts"],"sourcesContent":["import { splitTextByLines } from '@intlayer/chokidar/utils';\n\nexport type ChunkLineResult = {\n lineStart: number;\n lineLength: number;\n charStart: number;\n charLength: number;\n content: string;\n};\n\nconst DEFAULT_MAX_CHARS_PER_CHUNK = 800;\nconst DEFAULT_OVERLAP_CHARS = 0;\n\nexport const chunkText = (\n text: string,\n maxCharsPerChunk: number = DEFAULT_MAX_CHARS_PER_CHUNK,\n overlapChars: number = DEFAULT_OVERLAP_CHARS\n): ChunkLineResult[] => {\n if (maxCharsPerChunk <= 0) {\n throw new Error('maxCharsPerChunk must be greater than 0');\n }\n\n const splittedText = splitTextByLines(text);\n\n // Split text into lines to facilitate the translation\n const lines: ChunkLineResult[] = [];\n let charStartAcc = 0;\n\n splittedText.forEach((line, index) => {\n lines.push({\n content: line,\n lineStart: index,\n lineLength: 1,\n charStart: charStartAcc,\n charLength: line.length,\n });\n charStartAcc += line.length;\n });\n\n // Group lines\n // as long as the chunk length is less than maxCharsPerChunk\n // if a line longer than maxCharsPerChunk, keep it alone\n // if a line is not longer than maxCharsPerChunk, it is grouped\n const groupedLines: ChunkLineResult[] = lines.reduce(\n (acc: ChunkLineResult[], line) => {\n // If this line alone exceeds maxCharsPerChunk, keep it separate\n if (line.content.length > maxCharsPerChunk) {\n acc.push(line);\n return acc;\n }\n\n // If we have no chunks yet, start with this line\n if (acc.length === 0) {\n acc.push(line);\n return acc;\n }\n\n // Get the last chunk\n const lastChunk = acc[acc.length - 1];\n\n // Calculate what the combined length would be (including newline character)\n const combinedLength = lastChunk.content.length + line.content.length;\n\n // If combining would exceed the limit, start a new chunk\n if (combinedLength > maxCharsPerChunk) {\n acc.push(line);\n return acc;\n }\n\n // Otherwise, combine with the last chunk\n const combinedContent = lastChunk.content + line.content;\n const updatedChunk = {\n content: combinedContent,\n lineStart: lastChunk.lineStart,\n lineLength: lastChunk.lineLength + line.lineLength,\n charStart: lastChunk.charStart,\n charLength: combinedContent.length,\n };\n\n acc[acc.length - 1] = updatedChunk;\n return acc;\n },\n []\n );\n\n // If one line is longer than maxCharsPerChunk, split it into multiple chunks\n const splittedLines: ChunkLineResult[] = groupedLines.flatMap((line) => {\n const chunk: ChunkLineResult[] = [];\n\n if (line.content.length <= maxCharsPerChunk) {\n chunk.push(line);\n return chunk;\n }\n\n for (let i = 0; i < line.content.length; i += maxCharsPerChunk) {\n const slicedContent = line.content.slice(i, i + maxCharsPerChunk);\n chunk.push({\n content: slicedContent,\n lineStart: line.lineStart,\n lineLength: 1,\n charStart: line.charStart + i,\n charLength: slicedContent.length,\n });\n }\n return chunk;\n });\n\n if (overlapChars === 0) return splittedLines;\n\n const overlapChunks: ChunkLineResult[] =\n splittedLines.length > 0 ? [splittedLines[0]] : [];\n\n for (let i = 1; i < splittedLines.length; i++) {\n const previousChunk = splittedLines[i - 1];\n const chunk = splittedLines[i];\n\n const overlapContent = previousChunk.content.slice(-overlapChars);\n const overlapLineNb = splitTextByLines(overlapContent).length;\n\n const overlapContentWithoutPartialLine = overlapContent.slice(\n overlapLineNb > 1 ? overlapContent.indexOf('\\n') + 1 : 0,\n overlapContent.length\n );\n\n const newContent = overlapContentWithoutPartialLine + chunk.content;\n const newLineLength = splitTextByLines(newContent).length;\n const lineDiff = chunk.lineLength - newLineLength;\n\n const overlappedChunk = {\n content: newContent,\n lineStart: chunk.lineStart + lineDiff,\n lineLength: chunk.lineLength - lineDiff,\n charStart: chunk.charStart - overlapContentWithoutPartialLine.length,\n charLength: newContent.length,\n };\n\n overlapChunks.push(overlappedChunk);\n }\n\n return overlapChunks;\n};\n"],"mappings":";;;;;AAUA,MAAM,8BAA8B;AACpC,MAAM,wBAAwB;AAE9B,MAAa,aACX,MACA,mBAA2B,6BAC3B,eAAuB,0BACD;CACtB,IAAI,oBAAoB,GACtB,MAAM,IAAI,MAAM,yCAAyC;CAG3D,MAAM,8DAAgC,IAAI;CAG1C,MAAM,QAA2B,CAAC;CAClC,IAAI,eAAe;CAEnB,aAAa,SAAS,MAAM,UAAU;EACpC,MAAM,KAAK;GACT,SAAS;GACT,WAAW;GACX,YAAY;GACZ,WAAW;GACX,YAAY,KAAK;EACnB,CAAC;EACD,gBAAgB,KAAK;CACvB,CAAC;CAiDD,MAAM,gBA3CkC,MAAM,QAC3C,KAAwB,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,mCAAmC,eAAe,MACtD,gBAAgB,IAAI,eAAe,QAAQ,IAAI,IAAI,IAAI,GACvD,eAAe,MACjB;EAEA,MAAM,aAAa,mCAAmC,MAAM;EAC5D,MAAM,+DAAiC,UAAU,EAAE;EACnD,MAAM,WAAW,MAAM,aAAa;EAEpC,MAAM,kBAAkB;GACtB,SAAS;GACT,WAAW,MAAM,YAAY;GAC7B,YAAY,MAAM,aAAa;GAC/B,WAAW,MAAM,YAAY,iCAAiC;GAC9D,YAAY,WAAW;EACzB;EAEA,cAAc,KAAK,eAAe;CACpC;CAEA,OAAO;AACT"}
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_auth_sessionToken = require('../auth/sessionToken.cjs');
3
4
  const require_utils_checkConfigConsistency = require('./checkConfigConsistency.cjs');
4
5
  let _intlayer_config_colors = require("@intlayer/config/colors");
5
6
  _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
@@ -8,12 +9,58 @@ let _intlayer_api = require("@intlayer/api");
8
9
  let _intlayer_config_utils = require("@intlayer/config/utils");
9
10
 
10
11
  //#region src/utils/checkAccess.ts
12
+ const getAuthenticatedAPI = async (configuration) => {
13
+ let sessionData = null;
14
+ if (configuration) sessionData = await require_auth_sessionToken.readCliSessionToken(configuration);
15
+ return (0, _intlayer_api.getIntlayerAPIProxy)(void 0, configuration, sessionData?.token);
16
+ };
17
+ const checkProjectConfigConsistency = (project, configuration, appLogger) => {
18
+ if (!project?.configuration) return;
19
+ try {
20
+ let remoteConfigToCheck = project.configuration;
21
+ if (remoteConfigToCheck.ai && "apiKeyConfigured" in remoteConfigToCheck.ai) {
22
+ const { apiKeyConfigured, ...restAi } = remoteConfigToCheck.ai;
23
+ remoteConfigToCheck = {
24
+ ...remoteConfigToCheck,
25
+ ai: restAi
26
+ };
27
+ }
28
+ require_utils_checkConfigConsistency.checkConfigConsistency(remoteConfigToCheck, configuration);
29
+ } catch {
30
+ appLogger([
31
+ "Remote configuration is not up to date. The project configuration does not match the local configuration.",
32
+ "You can push the configuration by running",
33
+ (0, _intlayer_config_logger.colorize)("npx intlayer configuration push", _intlayer_config_colors.CYAN),
34
+ (0, _intlayer_config_logger.colorize)("(see doc:", _intlayer_config_colors.GREY_DARK),
35
+ (0, _intlayer_config_logger.colorize)("https://intlayer.org/doc/concept/cli/push", _intlayer_config_colors.GREY),
36
+ (0, _intlayer_config_logger.colorize)(")", _intlayer_config_colors.GREY_DARK),
37
+ "."
38
+ ], { level: "warn" });
39
+ }
40
+ };
11
41
  const checkCMSAuth = async (configuration, shouldCheckConfigConsistency = true) => {
12
42
  const appLogger = (0, _intlayer_config_logger.getAppLogger)(configuration);
43
+ const sessionData = await require_auth_sessionToken.readCliSessionToken(configuration);
44
+ if (sessionData) {
45
+ const intlayerAPI = (0, _intlayer_api.getIntlayerAPIProxy)(void 0, configuration, sessionData.token);
46
+ try {
47
+ const project = (await intlayerAPI.oAuth.getCliSessionMe()).data?.project;
48
+ if (project && shouldCheckConfigConsistency) checkProjectConfigConsistency(project, configuration, appLogger);
49
+ return true;
50
+ } catch (error) {
51
+ appLogger((0, _intlayer_config_utils.extractErrorMessage)(error), { level: "error" });
52
+ return false;
53
+ }
54
+ }
13
55
  if (!(configuration.editor.clientId && configuration.editor.clientSecret)) {
14
56
  appLogger([
15
- "CMS auth not provided. You can either retreive the CMS access key on",
16
- (0, _intlayer_config_logger.colorize)("https://intlayer.org/dahboard", _intlayer_config_colors.GREY),
57
+ "CMS auth not provided. Run",
58
+ (0, _intlayer_config_logger.colorize)("npx intlayer login", _intlayer_config_colors.CYAN),
59
+ "to authenticate, or set",
60
+ (0, _intlayer_config_logger.colorize)("INTLAYER_CLIENT_ID", _intlayer_config_colors.GREY_LIGHT),
61
+ "and",
62
+ (0, _intlayer_config_logger.colorize)("INTLAYER_CLIENT_SECRET", _intlayer_config_colors.GREY_LIGHT),
63
+ "in your .env file",
17
64
  (0, _intlayer_config_logger.colorize)("(see doc:", _intlayer_config_colors.GREY_DARK),
18
65
  (0, _intlayer_config_logger.colorize)("https://intlayer.org/doc/concept/cms", _intlayer_config_colors.GREY),
19
66
  (0, _intlayer_config_logger.colorize)(")", _intlayer_config_colors.GREY_DARK),
@@ -28,27 +75,7 @@ const checkCMSAuth = async (configuration, shouldCheckConfigConsistency = true)
28
75
  appLogger("Project not found");
29
76
  return true;
30
77
  }
31
- if (project.configuration && shouldCheckConfigConsistency) try {
32
- let remoteConfigToCheck = project.configuration;
33
- if (remoteConfigToCheck.ai && "apiKeyConfigured" in remoteConfigToCheck.ai) {
34
- const { apiKeyConfigured, ...restAi } = remoteConfigToCheck.ai;
35
- remoteConfigToCheck = {
36
- ...remoteConfigToCheck,
37
- ai: restAi
38
- };
39
- }
40
- require_utils_checkConfigConsistency.checkConfigConsistency(remoteConfigToCheck, configuration);
41
- } catch {
42
- appLogger([
43
- "Remote configuration is not up to date. The project configuration does not match the local configuration.",
44
- "You can push the configuration by running",
45
- (0, _intlayer_config_logger.colorize)("npx intlayer configuration push", _intlayer_config_colors.CYAN),
46
- (0, _intlayer_config_logger.colorize)("(see doc:", _intlayer_config_colors.GREY_DARK),
47
- (0, _intlayer_config_logger.colorize)("https://intlayer.org/doc/concept/cli/push", _intlayer_config_colors.GREY),
48
- (0, _intlayer_config_logger.colorize)(")", _intlayer_config_colors.GREY_DARK),
49
- "."
50
- ], { level: "warn" });
51
- }
78
+ if (shouldCheckConfigConsistency) checkProjectConfigConsistency(project, configuration, appLogger);
52
79
  } catch (error) {
53
80
  appLogger((0, _intlayer_config_utils.extractErrorMessage)(error), { level: "error" });
54
81
  return false;
@@ -58,16 +85,15 @@ const checkCMSAuth = async (configuration, shouldCheckConfigConsistency = true)
58
85
  const checkAIAccess = async (configuration, aiOptions, shouldCheckConfigConsistency = true) => {
59
86
  const appLogger = (0, _intlayer_config_logger.getAppLogger)(configuration);
60
87
  const hasCMSAuth = Boolean(configuration.editor.clientId && configuration.editor.clientSecret);
88
+ const sessionData = await require_auth_sessionToken.readCliSessionToken(configuration);
89
+ const hasSessionToken = Boolean(sessionData);
61
90
  const isOllama = configuration.ai?.provider === "ollama" || aiOptions?.provider === "ollama";
62
91
  if (Boolean(configuration.ai?.apiKey || aiOptions?.apiKey) || isOllama) return true;
63
- if (!hasCMSAuth) {
92
+ if (!hasCMSAuth && !hasSessionToken) {
64
93
  appLogger([
65
- "AI options or API key not provided. You can either retreive the CMS access key on",
66
- (0, _intlayer_config_logger.colorize)("https://intlayer.org/dahboard", _intlayer_config_colors.GREY),
67
- (0, _intlayer_config_logger.colorize)("(see doc:", _intlayer_config_colors.GREY_DARK),
68
- (0, _intlayer_config_logger.colorize)("https://intlayer.org/doc/concept/cms", _intlayer_config_colors.GREY),
69
- (0, _intlayer_config_logger.colorize)(")", _intlayer_config_colors.GREY_DARK),
70
- ". Alternatively, you can add your own OpenAI API key in the settings",
94
+ "AI options or API key not provided. Run",
95
+ (0, _intlayer_config_logger.colorize)("npx intlayer login", _intlayer_config_colors.CYAN),
96
+ "to authenticate, or provide an API key",
71
97
  (0, _intlayer_config_logger.colorize)("(see doc:", _intlayer_config_colors.GREY_DARK),
72
98
  (0, _intlayer_config_logger.colorize)("https://intlayer.org/doc/concept/configuration", _intlayer_config_colors.GREY),
73
99
  (0, _intlayer_config_logger.colorize)(")", _intlayer_config_colors.GREY_DARK),
@@ -81,4 +107,5 @@ const checkAIAccess = async (configuration, aiOptions, shouldCheckConfigConsiste
81
107
  //#endregion
82
108
  exports.checkAIAccess = checkAIAccess;
83
109
  exports.checkCMSAuth = checkCMSAuth;
110
+ exports.getAuthenticatedAPI = getAuthenticatedAPI;
84
111
  //# sourceMappingURL=checkAccess.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkAccess.cjs","names":["ANSIColors"],"sources":["../../../src/utils/checkAccess.ts"],"sourcesContent":["import type { AIOptions } from '@intlayer/api';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { extractErrorMessage } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { checkConfigConsistency } from './checkConfigConsistency';\n\nexport const checkCMSAuth = async (\n configuration: IntlayerConfig,\n shouldCheckConfigConsistency: boolean = true\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n const hasCMSAuth =\n configuration.editor.clientId && configuration.editor.clientSecret;\n if (!hasCMSAuth) {\n appLogger(\n [\n 'CMS auth not provided. You can either retreive the CMS access key on',\n colorize('https://intlayer.org/dahboard', ANSIColors.GREY),\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize('https://intlayer.org/doc/concept/cms', ANSIColors.GREY),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n {\n level: 'error',\n }\n );\n\n return false;\n }\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n try {\n const result = await intlayerAPI.oAuth.getOAuth2AccessToken();\n\n const project = result.data?.project;\n\n if (!project) {\n appLogger('Project not found');\n\n return true;\n }\n\n if (project.configuration && shouldCheckConfigConsistency) {\n try {\n let remoteConfigToCheck = project.configuration;\n\n // Remove server-side computed flags (apiKeyConfigured)\n // We use destructuring + spread to avoid the 'delete' operator (performance)\n if (\n remoteConfigToCheck.ai &&\n 'apiKeyConfigured' in remoteConfigToCheck.ai\n ) {\n const { apiKeyConfigured, ...restAi } = remoteConfigToCheck.ai as any;\n\n remoteConfigToCheck = {\n ...remoteConfigToCheck,\n ai: restAi,\n };\n }\n\n // Recursively check if project.configuration (subset) matches configuration (superset)\n checkConfigConsistency(remoteConfigToCheck, configuration);\n } catch {\n appLogger(\n [\n 'Remote configuration is not up to date. The project configuration does not match the local configuration.',\n 'You can push the configuration by running',\n colorize('npx intlayer configuration push', ANSIColors.CYAN),\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize(\n 'https://intlayer.org/doc/concept/cli/push',\n ANSIColors.GREY\n ),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n {\n level: 'warn',\n }\n );\n }\n }\n } catch (error) {\n const message = extractErrorMessage(error);\n\n appLogger(message, {\n level: 'error',\n });\n return false;\n }\n\n return true;\n};\n\nexport const checkAIAccess = async (\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n shouldCheckConfigConsistency: boolean = true\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n const hasCMSAuth = Boolean(\n configuration.editor.clientId && configuration.editor.clientSecret\n );\n const isOllama =\n configuration.ai?.provider === 'ollama' || aiOptions?.provider === 'ollama';\n const hasHisOwnAIAPIKey = Boolean(\n configuration.ai?.apiKey || aiOptions?.apiKey\n );\n\n if (hasHisOwnAIAPIKey || isOllama) {\n return true;\n }\n\n // User need to provide either his own AI API key or the CMS auth\n if (!hasCMSAuth) {\n appLogger(\n [\n 'AI options or API key not provided. You can either retreive the CMS access key on',\n colorize('https://intlayer.org/dahboard', ANSIColors.GREY),\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize('https://intlayer.org/doc/concept/cms', ANSIColors.GREY),\n colorize(')', ANSIColors.GREY_DARK),\n '. Alternatively, you can add your own OpenAI API key in the settings',\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize(\n 'https://intlayer.org/doc/concept/configuration',\n ANSIColors.GREY\n ),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n {\n level: 'error',\n }\n );\n\n return false;\n }\n\n // If the user do not have his own AI API key, we need to check the CMS auth\n return await checkCMSAuth(configuration, shouldCheckConfigConsistency);\n};\n"],"mappings":";;;;;;;;;;AAQA,MAAa,eAAe,OAC1B,eACA,+BAAwC,SACnB;CACrB,MAAM,sDAAyB,cAAc;CAI7C,IAAI,EADF,cAAc,OAAO,YAAY,cAAc,OAAO,eACvC;EACf,UACE;GACE;yCACS,iCAAiCA,wBAAW,KAAK;yCACjD,aAAaA,wBAAW,UAAU;yCAClC,wCAAwC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;yCACQ,KAAKA,wBAAW,UAAU;GACnC;GACD,EACD,EACE,OAAO,SACR,CACF;EAED,OAAO;;CAIT,OAAO,MAAM,aAAa,eAAe,6BAA6B"}
1
+ {"version":3,"file":"checkAccess.cjs","names":["readCliSessionToken","ANSIColors"],"sources":["../../../src/utils/checkAccess.ts"],"sourcesContent":["import type { AIOptions, IntlayerAPIProxy } from '@intlayer/api';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { extractErrorMessage } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type CliSessionData, readCliSessionToken } from '../auth/sessionToken';\nimport { checkConfigConsistency } from './checkConfigConsistency';\n\nexport const getAuthenticatedAPI = async (\n configuration?: IntlayerConfig\n): Promise<IntlayerAPIProxy> => {\n let sessionData: CliSessionData | null = null;\n\n // First use session data if it exists\n if (configuration) {\n sessionData = await readCliSessionToken(configuration);\n }\n\n return getIntlayerAPIProxy(undefined, configuration, sessionData?.token);\n};\n\nconst checkProjectConfigConsistency = (\n project: { configuration?: any } | null | undefined,\n configuration: IntlayerConfig,\n appLogger: ReturnType<typeof getAppLogger>\n): void => {\n if (!project?.configuration) return;\n\n try {\n let remoteConfigToCheck = project.configuration;\n\n if (\n remoteConfigToCheck.ai &&\n 'apiKeyConfigured' in remoteConfigToCheck.ai\n ) {\n const { apiKeyConfigured, ...restAi } = remoteConfigToCheck.ai as any;\n remoteConfigToCheck = { ...remoteConfigToCheck, ai: restAi };\n }\n\n checkConfigConsistency(remoteConfigToCheck, configuration);\n } catch {\n appLogger(\n [\n 'Remote configuration is not up to date. The project configuration does not match the local configuration.',\n 'You can push the configuration by running',\n colorize('npx intlayer configuration push', ANSIColors.CYAN),\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize('https://intlayer.org/doc/concept/cli/push', ANSIColors.GREY),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n { level: 'warn' }\n );\n }\n};\n\nexport const checkCMSAuth = async (\n configuration: IntlayerConfig,\n shouldCheckConfigConsistency: boolean = true\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n // Try CLI session token first (short-lived 2h token stored in tempDir)\n const sessionData = await readCliSessionToken(configuration);\n if (sessionData) {\n const intlayerAPI = getIntlayerAPIProxy(\n undefined,\n configuration,\n sessionData.token\n );\n\n try {\n const result = await intlayerAPI.oAuth.getCliSessionMe();\n const project = result.data?.project;\n\n if (project && shouldCheckConfigConsistency) {\n checkProjectConfigConsistency(project, configuration, appLogger);\n }\n\n return true;\n } catch (error) {\n const message = extractErrorMessage(error);\n appLogger(message, { level: 'error' });\n return false;\n }\n }\n\n // Fall back to client_credentials (access key)\n const hasCMSAuth =\n configuration.editor.clientId && configuration.editor.clientSecret;\n if (!hasCMSAuth) {\n appLogger(\n [\n 'CMS auth not provided. Run',\n colorize('npx intlayer login', ANSIColors.CYAN),\n 'to authenticate, or set',\n colorize('INTLAYER_CLIENT_ID', ANSIColors.GREY_LIGHT),\n 'and',\n colorize('INTLAYER_CLIENT_SECRET', ANSIColors.GREY_LIGHT),\n 'in your .env file',\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize('https://intlayer.org/doc/concept/cms', ANSIColors.GREY),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n { level: 'error' }\n );\n\n return false;\n }\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n try {\n const result = await intlayerAPI.oAuth.getOAuth2AccessToken();\n\n const project = result.data?.project;\n\n if (!project) {\n appLogger('Project not found');\n return true;\n }\n\n if (shouldCheckConfigConsistency) {\n checkProjectConfigConsistency(project, configuration, appLogger);\n }\n } catch (error) {\n const message = extractErrorMessage(error);\n appLogger(message, { level: 'error' });\n return false;\n }\n\n return true;\n};\n\nexport const checkAIAccess = async (\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n shouldCheckConfigConsistency: boolean = true\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n const hasCMSAuth = Boolean(\n configuration.editor.clientId && configuration.editor.clientSecret\n );\n\n const sessionData = await readCliSessionToken(configuration);\n const hasSessionToken = Boolean(sessionData);\n const isOllama =\n configuration.ai?.provider === 'ollama' || aiOptions?.provider === 'ollama';\n const hasHisOwnAIAPIKey = Boolean(\n configuration.ai?.apiKey || aiOptions?.apiKey\n );\n\n if (hasHisOwnAIAPIKey || isOllama) {\n return true;\n }\n\n // User need to provide either his own AI API key or the CMS auth\n if (!hasCMSAuth && !hasSessionToken) {\n appLogger(\n [\n 'AI options or API key not provided. Run',\n colorize('npx intlayer login', ANSIColors.CYAN),\n 'to authenticate, or provide an API key',\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize(\n 'https://intlayer.org/doc/concept/configuration',\n ANSIColors.GREY\n ),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n { level: 'error' }\n );\n\n return false;\n }\n\n // If the user do not have his own AI API key, we need to check the CMS auth\n return await checkCMSAuth(configuration, shouldCheckConfigConsistency);\n};\n"],"mappings":";;;;;;;;;;;AASA,MAAa,sBAAsB,OACjC,kBAC8B;CAC9B,IAAI,cAAqC;CAGzC,IAAI,eACF,cAAc,MAAMA,8CAAoB,aAAa;CAGvD,8CAA2B,QAAW,eAAe,aAAa,KAAK;AACzE;AAEA,MAAM,iCACJ,SACA,eACA,cACS;CACT,IAAI,CAAC,SAAS,eAAe;CAE7B,IAAI;EACF,IAAI,sBAAsB,QAAQ;EAElC,IACE,oBAAoB,MACpB,sBAAsB,oBAAoB,IAC1C;GACA,MAAM,EAAE,kBAAkB,GAAG,WAAW,oBAAoB;GAC5D,sBAAsB;IAAE,GAAG;IAAqB,IAAI;GAAO;EAC7D;EAEA,4DAAuB,qBAAqB,aAAa;CAC3D,QAAQ;EACN,UACE;GACE;GACA;yCACS,mCAAmCC,wBAAW,IAAI;yCAClD,aAAaA,wBAAW,SAAS;yCACjC,6CAA6CA,wB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AAc,OAAO,YACxD;CAEA,MAAM,cAAc,MAAMD,8CAAoB,aAAa;CAC3D,MAAM,kBAAkB,QAAQ,WAAW;CAC3C,MAAM,WACJ,cAAc,IAAI,aAAa,YAAY,WAAW,aAAa;CAKrE,IAJ0B,QACxB,cAAc,IAAI,UAAU,WAAW,MAGrB,KAAK,UACvB,OAAO;CAIT,IAAI,CAAC,cAAc,CAAC,iBAAiB;EACnC,UACE;GACE;yCACS,sBAAsBC,wBAAW,IAAI;GAC9C;yCACS,aAAaA,wBAAW,SAAS;yCAExC,kDACAA,wBAAW,IACb;yCACS,KAAKA,wBAAW,SAAS;GAClC;EACF,GACA,EAAE,OAAO,QAAQ,CACnB;EAEA,OAAO;CACT;CAGA,OAAO,MAAM,aAAa,eAAe,4BAA4B;AACvE"}
@@ -1 +1 @@
1
- {"version":3,"file":"checkConfigConsistency.cjs","names":[],"sources":["../../../src/utils/checkConfigConsistency.ts"],"sourcesContent":["export const checkConfigConsistency = (subset: any, superset: any) => {\n for (const key in subset) {\n const val1 = subset[key];\n const val2 = superset[key];\n\n if (Array.isArray(val1) && Array.isArray(val2)) {\n // Check if arrays are identical in content\n if (JSON.stringify(val1) !== JSON.stringify(val2)) {\n throw new Error(`Configuration mismatch at key \"${key}\"`);\n }\n } else if (typeof val1 === 'object' && val1 !== null) {\n checkConfigConsistency(val1, val2);\n } else if (val1 !== val2) {\n throw new Error(`Configuration mismatch at key \"${key}\"`);\n }\n }\n};\n"],"mappings":";;;AAAA,MAAa,0BAA0B,QAAa,aAAkB;CACpE,KAAK,MAAM,OAAO,QAAQ;EACxB,MAAM,OAAO,OAAO;EACpB,MAAM,OAAO,SAAS;EAEtB,IAAI,MAAM,QAAQ,KAAK,IAAI,MAAM,QAAQ,KAAK,EAE5C;OAAI,KAAK,UAAU,KAAK,KAAK,KAAK,UAAU,KAAK,EAC/C,MAAM,IAAI,MAAM,kCAAkC,IAAI,GAAG;SAEtD,IAAI,OAAO,SAAS,YAAY,SAAS,MAC9C,uBAAuB,MAAM,KAAK;OAC7B,IAAI,SAAS,MAClB,MAAM,IAAI,MAAM,kCAAkC,IAAI,GAAG"}
1
+ {"version":3,"file":"checkConfigConsistency.cjs","names":[],"sources":["../../../src/utils/checkConfigConsistency.ts"],"sourcesContent":["export const checkConfigConsistency = (subset: any, superset: any) => {\n for (const key in subset) {\n const val1 = subset[key];\n const val2 = superset[key];\n\n if (Array.isArray(val1) && Array.isArray(val2)) {\n // Check if arrays are identical in content\n if (JSON.stringify(val1) !== JSON.stringify(val2)) {\n throw new Error(`Configuration mismatch at key \"${key}\"`);\n }\n } else if (typeof val1 === 'object' && val1 !== null) {\n checkConfigConsistency(val1, val2);\n } else if (val1 !== val2) {\n throw new Error(`Configuration mismatch at key \"${key}\"`);\n }\n }\n};\n"],"mappings":";;;AAAA,MAAa,0BAA0B,QAAa,aAAkB;CACpE,KAAK,MAAM,OAAO,QAAQ;EACxB,MAAM,OAAO,OAAO;EACpB,MAAM,OAAO,SAAS;EAEtB,IAAI,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,IAAI,GAE3C;OAAI,KAAK,UAAU,IAAI,MAAM,KAAK,UAAU,IAAI,GAC9C,MAAM,IAAI,MAAM,kCAAkC,IAAI,EAAE;EAC1D,OACK,IAAI,OAAO,SAAS,YAAY,SAAS,MAC9C,uBAAuB,MAAM,IAAI;OAC5B,IAAI,SAAS,MAClB,MAAM,IAAI,MAAM,kCAAkC,IAAI,EAAE;CAE5D;AACF"}