@okf/ootils 1.31.2 → 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.
@@ -1388,8 +1388,203 @@ var compareAndGroupBlocks = (blocksPerTpl) => {
1388
1388
  return Array.from(templateGroupToFilters.values());
1389
1389
  };
1390
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
+
1391
1586
  // src/utils/autoGenFilterConfigsFromTpl/utils/extractAndOrganizeBlocks.ts
1392
- var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1587
+ var extractAndOrganizeBlocks = (selectedTpls, allTpls, { smTagTypesConfig } = {}) => {
1393
1588
  const extractedBlocks = {};
1394
1589
  const templateBlocksCache = /* @__PURE__ */ new Map();
1395
1590
  const getCachedBlocks = (tpl) => {
@@ -1400,7 +1595,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1400
1595
  };
1401
1596
  extractedBlocks.annoTagBlocks = selectedTpls.map((tpl) => {
1402
1597
  const allBlocks = getCachedBlocks(tpl);
1403
- 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));
1404
1599
  const uniqueTagTypes = [...new Set(allTagTypes)];
1405
1600
  return {
1406
1601
  contentType: tpl.kp_content_type,
@@ -1414,13 +1609,13 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
1414
1609
  const allBlocks = getCachedBlocks(tpl);
1415
1610
  return {
1416
1611
  contentType: tpl.kp_content_type,
1417
- blocks: allBlocks.filter((block) => block.props?.annotation?.enable)
1612
+ blocks: blockRegistry.getAnnotationEnabledBlocks(allBlocks)
1418
1613
  };
1419
1614
  });
1420
1615
  extractedBlocks.annoRollupBlocks = selectedTpls.map((tpl) => {
1421
1616
  const allBlocks = getCachedBlocks(tpl);
1422
1617
  const uniqueTagTypes = Array.from(new Set(
1423
- 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)
1424
1619
  ));
1425
1620
  return {
1426
1621
  contentType: tpl.kp_content_type,
@@ -2067,9 +2262,10 @@ var autoGenFilterConfigsFromTpl = ({
2067
2262
  allTpls,
2068
2263
  filterScopes,
2069
2264
  isSelfManagedTenant = false,
2070
- annotationTagsCount
2265
+ annotationTagsCount,
2266
+ smTagTypesConfig
2071
2267
  }) => {
2072
- const extractedBlocks = extractAndOrganizeBlocks(selectedTpls, allTpls);
2268
+ const extractedBlocks = extractAndOrganizeBlocks(selectedTpls, allTpls, { smTagTypesConfig });
2073
2269
  const allAnnoEnabledBlocks = filterScopes.includes("anno") ? extractedBlocks.annoEnabledBlocks.flatMap((item) => item.blocks).reduce((acc, block) => {
2074
2270
  if (!acc.find((b) => b.valuePath === block.valuePath)) {
2075
2271
  acc.push(block);
@@ -2190,186 +2386,6 @@ var genCleanCamelCaseId = (id) => {
2190
2386
  if (/^\d/.test(result)) result = "a" + result;
2191
2387
  return result.slice(0, MAX_LENGTH);
2192
2388
  };
2193
-
2194
- // src/blockRegistry/schemaPresets.ts
2195
- var MONGO_SCHEMA_PRESETS = {
2196
- object: { type: Object },
2197
- string: { type: String }
2198
- };
2199
- var ELASTIC_MAPPING_PRESETS = {
2200
- largeText: {
2201
- properties: {
2202
- allText: {
2203
- type: "text",
2204
- analyzer: "LargeTextAnalyzer"
2205
- }
2206
- }
2207
- }
2208
- };
2209
- var CHUNKING_PRESETS = {
2210
- // Lexical-shaped text — uses semantic chunking on allText
2211
- lexicalSemantic: {
2212
- strategy: "semanticChunking",
2213
- windowSize: 3,
2214
- minSimilarityScore: 0.7
2215
- },
2216
- // Plain text input — single chunk per field
2217
- simpleText: {
2218
- strategy: "simpleChunking"
2219
- }
2220
- };
2221
-
2222
- // src/blockRegistry/blocks/LexicalTextEditor.ts
2223
- var LexicalTextEditor = {
2224
- compName: "LexicalTextEditor",
2225
- // Identity
2226
- category: "text",
2227
- qualQuant: "qual",
2228
- // Schema
2229
- mongoSchemaType: MONGO_SCHEMA_PRESETS.object,
2230
- esMapping: ELASTIC_MAPPING_PRESETS.largeText,
2231
- // Capabilities
2232
- capabilities: {
2233
- hasPlainText: true,
2234
- annotation: true,
2235
- aiAnnotation: true,
2236
- aiEnrichment: true,
2237
- searchable: true,
2238
- directDataImport: true,
2239
- csvExport: true,
2240
- translatable: true,
2241
- documentSummarizer: true,
2242
- stripFromMainOnAnnoChunkSync: true,
2243
- excludeFromListingProjection: true
2244
- },
2245
- // Field paths
2246
- fieldPaths: {
2247
- plainTextString: "allText",
2248
- searchField: "allText",
2249
- displayValue: "allText"
2250
- },
2251
- // Validation
2252
- validation: {
2253
- populatedCheckFn: "lexicalTextEditorHasValue",
2254
- formValidationFn: "lexicalTextEditorHasValue"
2255
- },
2256
- // Translation
2257
- translation: {
2258
- handlerType: "LexicalBlockHandler"
2259
- },
2260
- // Table rendering
2261
- tableCell: {
2262
- cellComp: "RichTextAsPlainTextLex",
2263
- sortPathSuffix: "editorState.root.children.0.children.0.text"
2264
- },
2265
- // CSV export
2266
- csvExport: {
2267
- transformFn: "KPRichLexicalEditor"
2268
- },
2269
- // Slack
2270
- slackFormat: {
2271
- handlerFn: "lexicalRichText"
2272
- },
2273
- // Batch import
2274
- batchImport: {
2275
- valueInjectorFn: "toLexicalValue"
2276
- },
2277
- // Content block option — TCI template builder & direct import UI
2278
- contentBlockOption: {
2279
- display: "Rich Text Field",
2280
- icon: "TextAa",
2281
- directImportGroupsIdx: [2, 2]
2282
- },
2283
- // Chunking config — used by okf-sub CreateChunksHandler
2284
- chunkingConfig: CHUNKING_PRESETS.lexicalSemantic
2285
- };
2286
-
2287
- // src/blockRegistry/registry.ts
2288
- var BlockRegistry = class {
2289
- constructor() {
2290
- this.blocks = /* @__PURE__ */ new Map();
2291
- this.register(LexicalTextEditor);
2292
- }
2293
- /** Register a block descriptor. */
2294
- register(descriptor) {
2295
- this.blocks.set(descriptor.compName, descriptor);
2296
- }
2297
- /** Get the full descriptor for a block type. Returns undefined if not registered. */
2298
- getBlock(compType) {
2299
- return this.blocks.get(compType);
2300
- }
2301
- /** Check if a block type is registered in the registry. */
2302
- isRegistered(compType) {
2303
- return this.blocks.has(compType);
2304
- }
2305
- /**
2306
- * Get all registered block descriptors that have a given capability set to a truthy value.
2307
- * Optionally pass a specific value to match (e.g. for enum-style capabilities).
2308
- */
2309
- getBlocksByCapability(capability, value = true) {
2310
- return Array.from(this.blocks.values()).filter((b) => {
2311
- const cap = b.capabilities[capability];
2312
- if (value === true) return !!cap;
2313
- return cap === value;
2314
- });
2315
- }
2316
- /**
2317
- * Get compType strings for all registered blocks with a given capability.
2318
- * Replaces scattered hardcoded arrays like:
2319
- * const TEXT_FIELD_COMPONENTS = ["TextInput", "LexicalTextEditor", ...]
2320
- * becomes:
2321
- * const TEXT_FIELD_COMPONENTS = blockRegistry.getComps('aiTextExtraction')
2322
- */
2323
- getComps(capability, value = true) {
2324
- return this.getBlocksByCapability(capability, value).map((b) => b.compName);
2325
- }
2326
- /** Get all registered blocks in a given category. */
2327
- getBlocksByCategory(category) {
2328
- return Array.from(this.blocks.values()).filter((b) => b.category === category);
2329
- }
2330
- /** Get compType strings for all qual blocks. */
2331
- getQualBlocks() {
2332
- return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "qual").map((b) => b.compName);
2333
- }
2334
- /** Get compType strings for all quant blocks. */
2335
- getQuantBlocks() {
2336
- return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "quant").map((b) => b.compName);
2337
- }
2338
- /** Check if a specific block has a specific capability. */
2339
- hasCapability(compType, capability) {
2340
- const block = this.blocks.get(compType);
2341
- if (!block) return false;
2342
- return !!block.capabilities[capability];
2343
- }
2344
- /** Get all registered block descriptors. */
2345
- getAll() {
2346
- return Array.from(this.blocks.values());
2347
- }
2348
- /**
2349
- * Get compName strings for all registered blocks that have a chunking config.
2350
- * Used by chunking pipelines and prompt-string injection (e.g. searchChunks tool
2351
- * description) to know which fields actually have chunks to search.
2352
- */
2353
- getCompsWithChunking() {
2354
- return Array.from(this.blocks.values()).filter((b) => !!b.chunkingConfig).map((b) => b.compName);
2355
- }
2356
- /**
2357
- * Filter a list of block instances down to those where annotation is enabled.
2358
- * A block is annotation-enabled if its registry capability `annotation` is true.
2359
- * For backwards compat with un-migrated blocks (e.g. deprecated KPRichInput/RichTextEditor),
2360
- * falls back to the legacy per-instance `props.annotation.enable` toggle.
2361
- *
2362
- * Today: every registered annotation-capable block (e.g. LexicalTextEditor) is auto-enabled.
2363
- */
2364
- getAnnotationEnabledBlocks(allBlocks) {
2365
- return allBlocks.filter((block) => {
2366
- const blockDef = this.blocks.get(block.comp);
2367
- if (blockDef) return !!blockDef.capabilities.annotation;
2368
- return block.props?.annotation?.enable === true;
2369
- });
2370
- }
2371
- };
2372
- var blockRegistry = new BlockRegistry();
2373
2389
  export {
2374
2390
  BASE_BULLMQ_CONFIG,
2375
2391
  BlockRegistry,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.31.2",
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",