@okf/ootils 1.31.1 → 1.31.3

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.
@@ -730,6 +730,34 @@ var BASE_BULLMQ_CONFIG = {
730
730
  maxStalledCount: 3
731
731
  }
732
732
  },
733
+ SARVAM_TRANSCRIPTION_QUEUE: {
734
+ id: "sarvam-transcription-queue",
735
+ queueConfig: {
736
+ defaultJobOptions: {
737
+ attempts: 10,
738
+ // Sarvam jobs need many poll cycles, not retries per se
739
+ backoff: {
740
+ type: "exponential",
741
+ delay: 15e3
742
+ // First retry at 15s, then 30s, 60s, etc.
743
+ },
744
+ removeOnComplete: 50,
745
+ removeOnFail: 200
746
+ },
747
+ streams: {
748
+ events: {
749
+ maxLen: 10
750
+ }
751
+ }
752
+ },
753
+ workerConfig: {
754
+ concurrency: 5,
755
+ // Multiple transcription polls can run in parallel safely
756
+ lockDuration: 12e4,
757
+ // 2 min — fetching results from Sarvam can be slow
758
+ maxStalledCount: 3
759
+ }
760
+ },
733
761
  REINDEX_QUEUE: {
734
762
  id: "reindex-queue",
735
763
  queueConfig: {
@@ -1360,8 +1388,203 @@ var compareAndGroupBlocks = (blocksPerTpl) => {
1360
1388
  return Array.from(templateGroupToFilters.values());
1361
1389
  };
1362
1390
 
1391
+ // src/blockRegistry/schemaPresets.ts
1392
+ var MONGO_SCHEMA_PRESETS = {
1393
+ object: { type: Object },
1394
+ string: { type: String }
1395
+ };
1396
+ var ELASTIC_MAPPING_PRESETS = {
1397
+ largeText: {
1398
+ properties: {
1399
+ allText: {
1400
+ type: "text",
1401
+ analyzer: "LargeTextAnalyzer"
1402
+ }
1403
+ }
1404
+ }
1405
+ };
1406
+ var CHUNKING_PRESETS = {
1407
+ // Lexical-shaped text — uses semantic chunking on allText
1408
+ lexicalSemantic: {
1409
+ strategy: "semanticChunking",
1410
+ windowSize: 3,
1411
+ minSimilarityScore: 0.7
1412
+ },
1413
+ // Plain text input — single chunk per field
1414
+ simpleText: {
1415
+ strategy: "simpleChunking"
1416
+ }
1417
+ };
1418
+
1419
+ // src/blockRegistry/blocks/LexicalTextEditor.ts
1420
+ var LexicalTextEditor = {
1421
+ compName: "LexicalTextEditor",
1422
+ // Identity
1423
+ category: "text",
1424
+ qualQuant: "qual",
1425
+ // Schema
1426
+ mongoSchemaType: MONGO_SCHEMA_PRESETS.object,
1427
+ esMapping: ELASTIC_MAPPING_PRESETS.largeText,
1428
+ // Capabilities
1429
+ capabilities: {
1430
+ hasPlainText: true,
1431
+ annotation: true,
1432
+ aiAnnotation: true,
1433
+ aiEnrichment: true,
1434
+ searchable: true,
1435
+ directDataImport: true,
1436
+ csvExport: true,
1437
+ translatable: true,
1438
+ documentSummarizer: true,
1439
+ stripFromMainOnAnnoChunkSync: true,
1440
+ excludeFromListingProjection: true
1441
+ },
1442
+ // Field paths
1443
+ fieldPaths: {
1444
+ plainTextString: "allText",
1445
+ searchField: "allText",
1446
+ displayValue: "allText"
1447
+ },
1448
+ // Validation
1449
+ validation: {
1450
+ populatedCheckFn: "lexicalTextEditorHasValue",
1451
+ formValidationFn: "lexicalTextEditorHasValue"
1452
+ },
1453
+ // Translation
1454
+ translation: {
1455
+ handlerType: "LexicalBlockHandler"
1456
+ },
1457
+ // Table rendering
1458
+ tableCell: {
1459
+ cellComp: "RichTextAsPlainTextLex",
1460
+ sortPathSuffix: "editorState.root.children.0.children.0.text"
1461
+ },
1462
+ // CSV export
1463
+ csvExport: {
1464
+ transformFn: "KPRichLexicalEditor"
1465
+ },
1466
+ // Slack
1467
+ slackFormat: {
1468
+ handlerFn: "lexicalRichText"
1469
+ },
1470
+ // Batch import
1471
+ batchImport: {
1472
+ valueInjectorFn: "toLexicalValue"
1473
+ },
1474
+ // Content block option — TCI template builder & direct import UI
1475
+ contentBlockOption: {
1476
+ display: "Rich Text Field",
1477
+ icon: "TextAa",
1478
+ directImportGroupsIdx: [2, 2]
1479
+ },
1480
+ // Chunking config — used by okf-sub CreateChunksHandler
1481
+ chunkingConfig: CHUNKING_PRESETS.lexicalSemantic
1482
+ };
1483
+
1484
+ // src/blockRegistry/registry.ts
1485
+ var BlockRegistry = class {
1486
+ constructor() {
1487
+ this.blocks = /* @__PURE__ */ new Map();
1488
+ this.register(LexicalTextEditor);
1489
+ }
1490
+ /** Register a block descriptor. */
1491
+ register(descriptor) {
1492
+ this.blocks.set(descriptor.compName, descriptor);
1493
+ }
1494
+ /** Get the full descriptor for a block type. Returns undefined if not registered. */
1495
+ getBlock(compType) {
1496
+ return this.blocks.get(compType);
1497
+ }
1498
+ /** Check if a block type is registered in the registry. */
1499
+ isRegistered(compType) {
1500
+ return this.blocks.has(compType);
1501
+ }
1502
+ /**
1503
+ * Get all registered block descriptors that have a given capability set to a truthy value.
1504
+ * Optionally pass a specific value to match (e.g. for enum-style capabilities).
1505
+ */
1506
+ getBlocksByCapability(capability, value = true) {
1507
+ return Array.from(this.blocks.values()).filter((b) => {
1508
+ const cap = b.capabilities[capability];
1509
+ if (value === true) return !!cap;
1510
+ return cap === value;
1511
+ });
1512
+ }
1513
+ /**
1514
+ * Get compType strings for all registered blocks with a given capability.
1515
+ * Replaces scattered hardcoded arrays like:
1516
+ * const TEXT_FIELD_COMPONENTS = ["TextInput", "LexicalTextEditor", ...]
1517
+ * becomes:
1518
+ * const TEXT_FIELD_COMPONENTS = blockRegistry.getComps('aiTextExtraction')
1519
+ */
1520
+ getComps(capability, value = true) {
1521
+ return this.getBlocksByCapability(capability, value).map((b) => b.compName);
1522
+ }
1523
+ /** Get all registered blocks in a given category. */
1524
+ getBlocksByCategory(category) {
1525
+ return Array.from(this.blocks.values()).filter((b) => b.category === category);
1526
+ }
1527
+ /** Get compType strings for all qual blocks. */
1528
+ getQualBlocks() {
1529
+ return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "qual").map((b) => b.compName);
1530
+ }
1531
+ /** Get compType strings for all quant blocks. */
1532
+ getQuantBlocks() {
1533
+ return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "quant").map((b) => b.compName);
1534
+ }
1535
+ /** Check if a specific block has a specific capability. */
1536
+ hasCapability(compType, capability) {
1537
+ const block = this.blocks.get(compType);
1538
+ if (!block) return false;
1539
+ return !!block.capabilities[capability];
1540
+ }
1541
+ /** Get all registered block descriptors. */
1542
+ getAll() {
1543
+ return Array.from(this.blocks.values());
1544
+ }
1545
+ /**
1546
+ * Get compName strings for all registered blocks that have a chunking config.
1547
+ * Used by chunking pipelines and prompt-string injection (e.g. searchChunks tool
1548
+ * description) to know which fields actually have chunks to search.
1549
+ */
1550
+ getCompsWithChunking() {
1551
+ return Array.from(this.blocks.values()).filter((b) => !!b.chunkingConfig).map((b) => b.compName);
1552
+ }
1553
+ /**
1554
+ * Filter a list of block instances down to those where annotation is enabled.
1555
+ * A block is annotation-enabled if its registry capability `annotation` is true.
1556
+ * For backwards compat with un-migrated blocks (e.g. deprecated KPRichInput/RichTextEditor),
1557
+ * falls back to the legacy per-instance `props.annotation.enable` toggle.
1558
+ *
1559
+ * Today: every registered annotation-capable block (e.g. LexicalTextEditor) is auto-enabled.
1560
+ */
1561
+ getAnnotationEnabledBlocks(allBlocks) {
1562
+ return allBlocks.filter((block) => {
1563
+ const blockDef = this.blocks.get(block.comp);
1564
+ if (blockDef) return !!blockDef.capabilities.annotation;
1565
+ return block.props?.annotation?.enable === true;
1566
+ });
1567
+ }
1568
+ /**
1569
+ * Resolve the tagTypesConfig for a block instance.
1570
+ *
1571
+ * Resolution order:
1572
+ * 1. `hardCodedTagTypesConfigForSM` — the intended self-managed default, which takes
1573
+ * priority over per-instance values (justifies not persisting per-block on self-managed).
1574
+ * Sourced from `GET_SELF_MANAGED_BASE_CONFIGS().annotation_tagTypesConfig` on BE,
1575
+ * or `platformConfigs.SELF_MANAGED_BASE_CONFIGS.annotation_tagTypesConfig` on FE.
1576
+ * Pass null/undefined for non-SM tenants.
1577
+ * 2. `block.props.annotation.tagTypesConfig` — legacy per-instance persisted value.
1578
+ * 3. Empty array.
1579
+ */
1580
+ getTagTypesConfig(block, hardCodedTagTypesConfigForSM) {
1581
+ return hardCodedTagTypesConfigForSM || block.props?.annotation?.tagTypesConfig || [];
1582
+ }
1583
+ };
1584
+ var blockRegistry = new BlockRegistry();
1585
+
1363
1586
  // src/utils/autoGenFilterConfigsFromTpl/utils/extractAndOrganizeBlocks.ts
1364
- var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1587
+ var extractAndOrganizeBlocks = (selectedTpls, allTpls, { smTagTypesConfig } = {}) => {
1365
1588
  const extractedBlocks = {};
1366
1589
  const templateBlocksCache = /* @__PURE__ */ new Map();
1367
1590
  const getCachedBlocks = (tpl) => {
@@ -1372,7 +1595,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1372
1595
  };
1373
1596
  extractedBlocks.annoTagBlocks = selectedTpls.map((tpl) => {
1374
1597
  const allBlocks = getCachedBlocks(tpl);
1375
- const allTagTypes = allBlocks.filter((block) => block.props?.annotation?.enable).flatMap((block) => block.props.annotation.tagTypesConfig?.map((d) => d.tagType) || []);
1598
+ const allTagTypes = blockRegistry.getAnnotationEnabledBlocks(allBlocks).flatMap((block) => blockRegistry.getTagTypesConfig(block, smTagTypesConfig).map((d) => d.tagType));
1376
1599
  const uniqueTagTypes = [...new Set(allTagTypes)];
1377
1600
  return {
1378
1601
  contentType: tpl.kp_content_type,
@@ -1386,13 +1609,13 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1386
1609
  const allBlocks = getCachedBlocks(tpl);
1387
1610
  return {
1388
1611
  contentType: tpl.kp_content_type,
1389
- blocks: allBlocks.filter((block) => block.props?.annotation?.enable)
1612
+ blocks: blockRegistry.getAnnotationEnabledBlocks(allBlocks)
1390
1613
  };
1391
1614
  });
1392
1615
  extractedBlocks.annoRollupBlocks = selectedTpls.map((tpl) => {
1393
1616
  const allBlocks = getCachedBlocks(tpl);
1394
1617
  const uniqueTagTypes = Array.from(new Set(
1395
- allBlocks.filter((block) => block.props?.annotation?.enable).flatMap((block) => block.props.annotation.tagTypesConfig || []).map((conf) => conf.tagType)
1618
+ blockRegistry.getAnnotationEnabledBlocks(allBlocks).flatMap((block) => blockRegistry.getTagTypesConfig(block, smTagTypesConfig)).map((conf) => conf.tagType)
1396
1619
  ));
1397
1620
  return {
1398
1621
  contentType: tpl.kp_content_type,
@@ -2039,9 +2262,10 @@ var autoGenFilterConfigsFromTpl = ({
2039
2262
  allTpls,
2040
2263
  filterScopes,
2041
2264
  isSelfManagedTenant = false,
2042
- annotationTagsCount
2265
+ annotationTagsCount,
2266
+ smTagTypesConfig
2043
2267
  }) => {
2044
- const extractedBlocks = extractAndOrganizeBlocks(selectedTpls, allTpls);
2268
+ const extractedBlocks = extractAndOrganizeBlocks(selectedTpls, allTpls, { smTagTypesConfig });
2045
2269
  const allAnnoEnabledBlocks = filterScopes.includes("anno") ? extractedBlocks.annoEnabledBlocks.flatMap((item) => item.blocks).reduce((acc, block) => {
2046
2270
  if (!acc.find((b) => b.valuePath === block.valuePath)) {
2047
2271
  acc.push(block);
@@ -2162,186 +2386,6 @@ var genCleanCamelCaseId = (id) => {
2162
2386
  if (/^\d/.test(result)) result = "a" + result;
2163
2387
  return result.slice(0, MAX_LENGTH);
2164
2388
  };
2165
-
2166
- // src/blockRegistry/schemaPresets.ts
2167
- var MONGO_SCHEMA_PRESETS = {
2168
- object: { type: Object },
2169
- string: { type: String }
2170
- };
2171
- var ELASTIC_MAPPING_PRESETS = {
2172
- largeText: {
2173
- properties: {
2174
- allText: {
2175
- type: "text",
2176
- analyzer: "LargeTextAnalyzer"
2177
- }
2178
- }
2179
- }
2180
- };
2181
- var CHUNKING_PRESETS = {
2182
- // Lexical-shaped text — uses semantic chunking on allText
2183
- lexicalSemantic: {
2184
- strategy: "semanticChunking",
2185
- windowSize: 3,
2186
- minSimilarityScore: 0.7
2187
- },
2188
- // Plain text input — single chunk per field
2189
- simpleText: {
2190
- strategy: "simpleChunking"
2191
- }
2192
- };
2193
-
2194
- // src/blockRegistry/blocks/LexicalTextEditor.ts
2195
- var LexicalTextEditor = {
2196
- compName: "LexicalTextEditor",
2197
- // Identity
2198
- category: "text",
2199
- qualQuant: "qual",
2200
- // Schema
2201
- mongoSchemaType: MONGO_SCHEMA_PRESETS.object,
2202
- esMapping: ELASTIC_MAPPING_PRESETS.largeText,
2203
- // Capabilities
2204
- capabilities: {
2205
- hasPlainText: true,
2206
- annotation: true,
2207
- aiAnnotation: true,
2208
- aiEnrichment: true,
2209
- searchable: true,
2210
- directDataImport: true,
2211
- csvExport: true,
2212
- translatable: true,
2213
- documentSummarizer: true,
2214
- stripFromMainOnAnnoChunkSync: true,
2215
- excludeFromListingProjection: true
2216
- },
2217
- // Field paths
2218
- fieldPaths: {
2219
- plainTextString: "allText",
2220
- searchField: "allText",
2221
- displayValue: "allText"
2222
- },
2223
- // Validation
2224
- validation: {
2225
- populatedCheckFn: "lexicalTextEditorHasValue",
2226
- formValidationFn: "lexicalTextEditorHasValue"
2227
- },
2228
- // Translation
2229
- translation: {
2230
- handlerType: "LexicalBlockHandler"
2231
- },
2232
- // Table rendering
2233
- tableCell: {
2234
- cellComp: "RichTextAsPlainTextLex",
2235
- sortPathSuffix: "editorState.root.children.0.children.0.text"
2236
- },
2237
- // CSV export
2238
- csvExport: {
2239
- transformFn: "KPRichLexicalEditor"
2240
- },
2241
- // Slack
2242
- slackFormat: {
2243
- handlerFn: "lexicalRichText"
2244
- },
2245
- // Batch import
2246
- batchImport: {
2247
- valueInjectorFn: "toLexicalValue"
2248
- },
2249
- // Content block option — TCI template builder & direct import UI
2250
- contentBlockOption: {
2251
- display: "Rich Text Field",
2252
- icon: "TextAa",
2253
- directImportGroupsIdx: [2, 2]
2254
- },
2255
- // Chunking config — used by okf-sub CreateChunksHandler
2256
- chunkingConfig: CHUNKING_PRESETS.lexicalSemantic
2257
- };
2258
-
2259
- // src/blockRegistry/registry.ts
2260
- var BlockRegistry = class {
2261
- constructor() {
2262
- this.blocks = /* @__PURE__ */ new Map();
2263
- this.register(LexicalTextEditor);
2264
- }
2265
- /** Register a block descriptor. */
2266
- register(descriptor) {
2267
- this.blocks.set(descriptor.compName, descriptor);
2268
- }
2269
- /** Get the full descriptor for a block type. Returns undefined if not registered. */
2270
- getBlock(compType) {
2271
- return this.blocks.get(compType);
2272
- }
2273
- /** Check if a block type is registered in the registry. */
2274
- isRegistered(compType) {
2275
- return this.blocks.has(compType);
2276
- }
2277
- /**
2278
- * Get all registered block descriptors that have a given capability set to a truthy value.
2279
- * Optionally pass a specific value to match (e.g. for enum-style capabilities).
2280
- */
2281
- getBlocksByCapability(capability, value = true) {
2282
- return Array.from(this.blocks.values()).filter((b) => {
2283
- const cap = b.capabilities[capability];
2284
- if (value === true) return !!cap;
2285
- return cap === value;
2286
- });
2287
- }
2288
- /**
2289
- * Get compType strings for all registered blocks with a given capability.
2290
- * Replaces scattered hardcoded arrays like:
2291
- * const TEXT_FIELD_COMPONENTS = ["TextInput", "LexicalTextEditor", ...]
2292
- * becomes:
2293
- * const TEXT_FIELD_COMPONENTS = blockRegistry.getComps('aiTextExtraction')
2294
- */
2295
- getComps(capability, value = true) {
2296
- return this.getBlocksByCapability(capability, value).map((b) => b.compName);
2297
- }
2298
- /** Get all registered blocks in a given category. */
2299
- getBlocksByCategory(category) {
2300
- return Array.from(this.blocks.values()).filter((b) => b.category === category);
2301
- }
2302
- /** Get compType strings for all qual blocks. */
2303
- getQualBlocks() {
2304
- return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "qual").map((b) => b.compName);
2305
- }
2306
- /** Get compType strings for all quant blocks. */
2307
- getQuantBlocks() {
2308
- return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "quant").map((b) => b.compName);
2309
- }
2310
- /** Check if a specific block has a specific capability. */
2311
- hasCapability(compType, capability) {
2312
- const block = this.blocks.get(compType);
2313
- if (!block) return false;
2314
- return !!block.capabilities[capability];
2315
- }
2316
- /** Get all registered block descriptors. */
2317
- getAll() {
2318
- return Array.from(this.blocks.values());
2319
- }
2320
- /**
2321
- * Get compName strings for all registered blocks that have a chunking config.
2322
- * Used by chunking pipelines and prompt-string injection (e.g. searchChunks tool
2323
- * description) to know which fields actually have chunks to search.
2324
- */
2325
- getCompsWithChunking() {
2326
- return Array.from(this.blocks.values()).filter((b) => !!b.chunkingConfig).map((b) => b.compName);
2327
- }
2328
- /**
2329
- * Filter a list of block instances down to those where annotation is enabled.
2330
- * A block is annotation-enabled if its registry capability `annotation` is true.
2331
- * For backwards compat with un-migrated blocks (e.g. deprecated KPRichInput/RichTextEditor),
2332
- * falls back to the legacy per-instance `props.annotation.enable` toggle.
2333
- *
2334
- * Today: every registered annotation-capable block (e.g. LexicalTextEditor) is auto-enabled.
2335
- */
2336
- getAnnotationEnabledBlocks(allBlocks) {
2337
- return allBlocks.filter((block) => {
2338
- const blockDef = this.blocks.get(block.comp);
2339
- if (blockDef) return !!blockDef.capabilities.annotation;
2340
- return block.props?.annotation?.enable === true;
2341
- });
2342
- }
2343
- };
2344
- var blockRegistry = new BlockRegistry();
2345
2389
  export {
2346
2390
  BASE_BULLMQ_CONFIG,
2347
2391
  BlockRegistry,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.31.1",
6
+ "version": "1.31.3",
7
7
  "description": "Utility functions for both browser and Node.js",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.mjs",