@okf/ootils 1.31.2 → 1.31.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.js CHANGED
@@ -2032,6 +2032,7 @@ __export(node_exports, {
2032
2032
  getRoutePathToTagCategoryLanding: () => getRoutePathToTagCategoryLanding,
2033
2033
  getTplModelByTenant: () => import_getModelByTenant2.getTplModelByTenant,
2034
2034
  getVal: () => getVal,
2035
+ isTplAnnotationEnabled: () => isTplAnnotationEnabled,
2035
2036
  mergeAnnoDataIntoAnnotationsTags: () => mergeAnnoDataIntoAnnotationsTags,
2036
2037
  parseSpecialConfigSyntax: () => parseSpecialConfigSyntax,
2037
2038
  processAuthorAndCommonFilters: () => processAuthorAndCommonFilters,
@@ -2353,6 +2354,210 @@ var _extractBlocksFromSomeBuilders = ({
2353
2354
  }
2354
2355
  };
2355
2356
 
2357
+ // src/blockRegistry/schemaPresets.ts
2358
+ var MONGO_SCHEMA_PRESETS = {
2359
+ object: { type: Object },
2360
+ string: { type: String }
2361
+ };
2362
+ var ELASTIC_MAPPING_PRESETS = {
2363
+ largeText: {
2364
+ properties: {
2365
+ allText: {
2366
+ type: "text",
2367
+ analyzer: "LargeTextAnalyzer"
2368
+ }
2369
+ }
2370
+ }
2371
+ };
2372
+ var CHUNKING_PRESETS = {
2373
+ // Lexical-shaped text — uses semantic chunking on allText
2374
+ lexicalSemantic: {
2375
+ strategy: "semanticChunking",
2376
+ windowSize: 3,
2377
+ minSimilarityScore: 0.7
2378
+ },
2379
+ // Plain text input — single chunk per field
2380
+ simpleText: {
2381
+ strategy: "simpleChunking"
2382
+ }
2383
+ };
2384
+
2385
+ // src/blockRegistry/blocks/LexicalTextEditor.ts
2386
+ var LexicalTextEditor = {
2387
+ compName: "LexicalTextEditor",
2388
+ // Identity
2389
+ category: "text",
2390
+ qualQuant: "qual",
2391
+ // Schema
2392
+ mongoSchemaType: MONGO_SCHEMA_PRESETS.object,
2393
+ esMapping: ELASTIC_MAPPING_PRESETS.largeText,
2394
+ // Capabilities
2395
+ capabilities: {
2396
+ hasPlainText: true,
2397
+ annotation: true,
2398
+ aiAnnotation: true,
2399
+ aiEnrichment: true,
2400
+ searchable: true,
2401
+ directDataImport: true,
2402
+ csvExport: true,
2403
+ translatable: true,
2404
+ documentSummarizer: true,
2405
+ stripFromMainOnAnnoChunkSync: true,
2406
+ excludeFromListingProjection: true
2407
+ },
2408
+ // Field paths
2409
+ fieldPaths: {
2410
+ plainTextString: "allText",
2411
+ searchField: "allText",
2412
+ displayValue: "allText"
2413
+ },
2414
+ // Validation
2415
+ validation: {
2416
+ populatedCheckFn: "lexicalTextEditorHasValue",
2417
+ formValidationFn: "lexicalTextEditorHasValue"
2418
+ },
2419
+ // Translation
2420
+ translation: {
2421
+ handlerType: "LexicalBlockHandler"
2422
+ },
2423
+ // Table rendering
2424
+ tableCell: {
2425
+ cellComp: "RichTextAsPlainTextLex",
2426
+ sortPathSuffix: "editorState.root.children.0.children.0.text"
2427
+ },
2428
+ // CSV export
2429
+ csvExport: {
2430
+ transformFn: "KPRichLexicalEditor"
2431
+ },
2432
+ // Slack
2433
+ slackFormat: {
2434
+ handlerFn: "lexicalRichText"
2435
+ },
2436
+ // Batch import
2437
+ batchImport: {
2438
+ valueInjectorFn: "toLexicalValue"
2439
+ },
2440
+ // Content block option — TCI template builder & direct import UI
2441
+ contentBlockOption: {
2442
+ display: "Rich Text Field",
2443
+ icon: "TextAa",
2444
+ directImportGroupsIdx: [2, 2]
2445
+ },
2446
+ // Chunking config — used by okf-sub CreateChunksHandler
2447
+ chunkingConfig: CHUNKING_PRESETS.lexicalSemantic
2448
+ };
2449
+
2450
+ // src/blockRegistry/registry.ts
2451
+ var BlockRegistry = class {
2452
+ constructor() {
2453
+ this.blocks = /* @__PURE__ */ new Map();
2454
+ this.register(LexicalTextEditor);
2455
+ }
2456
+ /** Register a block descriptor. */
2457
+ register(descriptor) {
2458
+ this.blocks.set(descriptor.compName, descriptor);
2459
+ }
2460
+ /** Get the full descriptor for a block type. Returns undefined if not registered. */
2461
+ getBlock(compType) {
2462
+ return this.blocks.get(compType);
2463
+ }
2464
+ /** Check if a block type is registered in the registry. */
2465
+ isRegistered(compType) {
2466
+ return this.blocks.has(compType);
2467
+ }
2468
+ /**
2469
+ * Get all registered block descriptors that have a given capability set to a truthy value.
2470
+ * Optionally pass a specific value to match (e.g. for enum-style capabilities).
2471
+ */
2472
+ getBlocksByCapability(capability, value = true) {
2473
+ return Array.from(this.blocks.values()).filter((b) => {
2474
+ const cap = b.capabilities[capability];
2475
+ if (value === true) return !!cap;
2476
+ return cap === value;
2477
+ });
2478
+ }
2479
+ /**
2480
+ * Get compType strings for all registered blocks with a given capability.
2481
+ * Replaces scattered hardcoded arrays like:
2482
+ * const TEXT_FIELD_COMPONENTS = ["TextInput", "LexicalTextEditor", ...]
2483
+ * becomes:
2484
+ * const TEXT_FIELD_COMPONENTS = blockRegistry.getComps('aiTextExtraction')
2485
+ */
2486
+ getComps(capability, value = true) {
2487
+ return this.getBlocksByCapability(capability, value).map((b) => b.compName);
2488
+ }
2489
+ /** Get all registered blocks in a given category. */
2490
+ getBlocksByCategory(category) {
2491
+ return Array.from(this.blocks.values()).filter((b) => b.category === category);
2492
+ }
2493
+ /** Get compType strings for all qual blocks. */
2494
+ getQualBlocks() {
2495
+ return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "qual").map((b) => b.compName);
2496
+ }
2497
+ /** Get compType strings for all quant blocks. */
2498
+ getQuantBlocks() {
2499
+ return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "quant").map((b) => b.compName);
2500
+ }
2501
+ /** Check if a specific block has a specific capability. */
2502
+ hasCapability(compType, capability) {
2503
+ const block = this.blocks.get(compType);
2504
+ if (!block) return false;
2505
+ return !!block.capabilities[capability];
2506
+ }
2507
+ /** Get all registered block descriptors. */
2508
+ getAll() {
2509
+ return Array.from(this.blocks.values());
2510
+ }
2511
+ /**
2512
+ * Get compName strings for all registered blocks that have a chunking config.
2513
+ * Used by chunking pipelines and prompt-string injection (e.g. searchChunks tool
2514
+ * description) to know which fields actually have chunks to search.
2515
+ */
2516
+ getCompsWithChunking() {
2517
+ return Array.from(this.blocks.values()).filter((b) => !!b.chunkingConfig).map((b) => b.compName);
2518
+ }
2519
+ /**
2520
+ * Filter a list of block instances down to those where annotation is enabled.
2521
+ * A block is annotation-enabled if its registry capability `annotation` is true.
2522
+ * For backwards compat with un-migrated blocks (e.g. deprecated KPRichInput/RichTextEditor),
2523
+ * falls back to the legacy per-instance `props.annotation.enable` toggle.
2524
+ *
2525
+ * Today: every registered annotation-capable block (e.g. LexicalTextEditor) is auto-enabled.
2526
+ */
2527
+ getAnnotationEnabledBlocks(allBlocks) {
2528
+ return allBlocks.filter((block) => {
2529
+ const blockDef = this.blocks.get(block.comp);
2530
+ if (blockDef) return !!blockDef.capabilities.annotation;
2531
+ return block.props?.annotation?.enable === true;
2532
+ });
2533
+ }
2534
+ /**
2535
+ * Resolve the tagTypesConfig for a block instance.
2536
+ *
2537
+ * Resolution order:
2538
+ * 1. `hardCodedTagTypesConfigForSM` — the intended self-managed default, which takes
2539
+ * priority over per-instance values (justifies not persisting per-block on self-managed).
2540
+ * Sourced from `GET_SELF_MANAGED_BASE_CONFIGS().annotation_tagTypesConfig` on BE,
2541
+ * or `platformConfigs.SELF_MANAGED_BASE_CONFIGS.annotation_tagTypesConfig` on FE.
2542
+ * Pass null/undefined for non-SM tenants.
2543
+ * 2. `block.props.annotation.tagTypesConfig` — legacy per-instance persisted value.
2544
+ * 3. Empty array.
2545
+ */
2546
+ getTagTypesConfig(block, hardCodedTagTypesConfigForSM) {
2547
+ return hardCodedTagTypesConfigForSM || block.props?.annotation?.tagTypesConfig || [];
2548
+ }
2549
+ };
2550
+ var blockRegistry = new BlockRegistry();
2551
+
2552
+ // src/utils/isTplAnnotationEnabled.ts
2553
+ var isTplAnnotationEnabled = (tpl) => {
2554
+ if (tpl?.general?.segment !== "publishing") return false;
2555
+ const allBlocks = extractAllBlocksFromTpl({ tpl }).filter(
2556
+ (b) => typeof b.comp === "string"
2557
+ );
2558
+ return blockRegistry.getAnnotationEnabledBlocks(allBlocks).length > 0;
2559
+ };
2560
+
2356
2561
  // src/utils/getRollupPossibilities.ts
2357
2562
  var MAX_DEPTH_ROLLUP_POSSIBILITIES = 10;
2358
2563
  function getRollupPossibilities({
@@ -3053,7 +3258,7 @@ var compareAndGroupBlocks = (blocksPerTpl) => {
3053
3258
  };
3054
3259
 
3055
3260
  // src/utils/autoGenFilterConfigsFromTpl/utils/extractAndOrganizeBlocks.ts
3056
- var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
3261
+ var extractAndOrganizeBlocks = (selectedTpls, allTpls, { smTagTypesConfig } = {}) => {
3057
3262
  const extractedBlocks = {};
3058
3263
  const templateBlocksCache = /* @__PURE__ */ new Map();
3059
3264
  const getCachedBlocks = (tpl) => {
@@ -3064,7 +3269,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
3064
3269
  };
3065
3270
  extractedBlocks.annoTagBlocks = selectedTpls.map((tpl) => {
3066
3271
  const allBlocks = getCachedBlocks(tpl);
3067
- const allTagTypes = allBlocks.filter((block) => block.props?.annotation?.enable).flatMap((block) => block.props.annotation.tagTypesConfig?.map((d) => d.tagType) || []);
3272
+ const allTagTypes = blockRegistry.getAnnotationEnabledBlocks(allBlocks).flatMap((block) => blockRegistry.getTagTypesConfig(block, smTagTypesConfig).map((d) => d.tagType));
3068
3273
  const uniqueTagTypes = [...new Set(allTagTypes)];
3069
3274
  return {
3070
3275
  contentType: tpl.kp_content_type,
@@ -3078,13 +3283,13 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
3078
3283
  const allBlocks = getCachedBlocks(tpl);
3079
3284
  return {
3080
3285
  contentType: tpl.kp_content_type,
3081
- blocks: allBlocks.filter((block) => block.props?.annotation?.enable)
3286
+ blocks: blockRegistry.getAnnotationEnabledBlocks(allBlocks)
3082
3287
  };
3083
3288
  });
3084
3289
  extractedBlocks.annoRollupBlocks = selectedTpls.map((tpl) => {
3085
3290
  const allBlocks = getCachedBlocks(tpl);
3086
3291
  const uniqueTagTypes = Array.from(new Set(
3087
- allBlocks.filter((block) => block.props?.annotation?.enable).flatMap((block) => block.props.annotation.tagTypesConfig || []).map((conf) => conf.tagType)
3292
+ blockRegistry.getAnnotationEnabledBlocks(allBlocks).flatMap((block) => blockRegistry.getTagTypesConfig(block, smTagTypesConfig)).map((conf) => conf.tagType)
3088
3293
  ));
3089
3294
  return {
3090
3295
  contentType: tpl.kp_content_type,
@@ -3731,9 +3936,10 @@ var autoGenFilterConfigsFromTpl = ({
3731
3936
  allTpls,
3732
3937
  filterScopes,
3733
3938
  isSelfManagedTenant = false,
3734
- annotationTagsCount
3939
+ annotationTagsCount,
3940
+ smTagTypesConfig
3735
3941
  }) => {
3736
- const extractedBlocks = extractAndOrganizeBlocks(selectedTpls, allTpls);
3942
+ const extractedBlocks = extractAndOrganizeBlocks(selectedTpls, allTpls, { smTagTypesConfig });
3737
3943
  const allAnnoEnabledBlocks = filterScopes.includes("anno") ? extractedBlocks.annoEnabledBlocks.flatMap((item) => item.blocks).reduce((acc, block) => {
3738
3944
  if (!acc.find((b) => b.valuePath === block.valuePath)) {
3739
3945
  acc.push(block);
@@ -3855,186 +4061,6 @@ var genCleanCamelCaseId = (id) => {
3855
4061
  return result.slice(0, MAX_LENGTH);
3856
4062
  };
3857
4063
 
3858
- // src/blockRegistry/schemaPresets.ts
3859
- var MONGO_SCHEMA_PRESETS = {
3860
- object: { type: Object },
3861
- string: { type: String }
3862
- };
3863
- var ELASTIC_MAPPING_PRESETS = {
3864
- largeText: {
3865
- properties: {
3866
- allText: {
3867
- type: "text",
3868
- analyzer: "LargeTextAnalyzer"
3869
- }
3870
- }
3871
- }
3872
- };
3873
- var CHUNKING_PRESETS = {
3874
- // Lexical-shaped text — uses semantic chunking on allText
3875
- lexicalSemantic: {
3876
- strategy: "semanticChunking",
3877
- windowSize: 3,
3878
- minSimilarityScore: 0.7
3879
- },
3880
- // Plain text input — single chunk per field
3881
- simpleText: {
3882
- strategy: "simpleChunking"
3883
- }
3884
- };
3885
-
3886
- // src/blockRegistry/blocks/LexicalTextEditor.ts
3887
- var LexicalTextEditor = {
3888
- compName: "LexicalTextEditor",
3889
- // Identity
3890
- category: "text",
3891
- qualQuant: "qual",
3892
- // Schema
3893
- mongoSchemaType: MONGO_SCHEMA_PRESETS.object,
3894
- esMapping: ELASTIC_MAPPING_PRESETS.largeText,
3895
- // Capabilities
3896
- capabilities: {
3897
- hasPlainText: true,
3898
- annotation: true,
3899
- aiAnnotation: true,
3900
- aiEnrichment: true,
3901
- searchable: true,
3902
- directDataImport: true,
3903
- csvExport: true,
3904
- translatable: true,
3905
- documentSummarizer: true,
3906
- stripFromMainOnAnnoChunkSync: true,
3907
- excludeFromListingProjection: true
3908
- },
3909
- // Field paths
3910
- fieldPaths: {
3911
- plainTextString: "allText",
3912
- searchField: "allText",
3913
- displayValue: "allText"
3914
- },
3915
- // Validation
3916
- validation: {
3917
- populatedCheckFn: "lexicalTextEditorHasValue",
3918
- formValidationFn: "lexicalTextEditorHasValue"
3919
- },
3920
- // Translation
3921
- translation: {
3922
- handlerType: "LexicalBlockHandler"
3923
- },
3924
- // Table rendering
3925
- tableCell: {
3926
- cellComp: "RichTextAsPlainTextLex",
3927
- sortPathSuffix: "editorState.root.children.0.children.0.text"
3928
- },
3929
- // CSV export
3930
- csvExport: {
3931
- transformFn: "KPRichLexicalEditor"
3932
- },
3933
- // Slack
3934
- slackFormat: {
3935
- handlerFn: "lexicalRichText"
3936
- },
3937
- // Batch import
3938
- batchImport: {
3939
- valueInjectorFn: "toLexicalValue"
3940
- },
3941
- // Content block option — TCI template builder & direct import UI
3942
- contentBlockOption: {
3943
- display: "Rich Text Field",
3944
- icon: "TextAa",
3945
- directImportGroupsIdx: [2, 2]
3946
- },
3947
- // Chunking config — used by okf-sub CreateChunksHandler
3948
- chunkingConfig: CHUNKING_PRESETS.lexicalSemantic
3949
- };
3950
-
3951
- // src/blockRegistry/registry.ts
3952
- var BlockRegistry = class {
3953
- constructor() {
3954
- this.blocks = /* @__PURE__ */ new Map();
3955
- this.register(LexicalTextEditor);
3956
- }
3957
- /** Register a block descriptor. */
3958
- register(descriptor) {
3959
- this.blocks.set(descriptor.compName, descriptor);
3960
- }
3961
- /** Get the full descriptor for a block type. Returns undefined if not registered. */
3962
- getBlock(compType) {
3963
- return this.blocks.get(compType);
3964
- }
3965
- /** Check if a block type is registered in the registry. */
3966
- isRegistered(compType) {
3967
- return this.blocks.has(compType);
3968
- }
3969
- /**
3970
- * Get all registered block descriptors that have a given capability set to a truthy value.
3971
- * Optionally pass a specific value to match (e.g. for enum-style capabilities).
3972
- */
3973
- getBlocksByCapability(capability, value = true) {
3974
- return Array.from(this.blocks.values()).filter((b) => {
3975
- const cap = b.capabilities[capability];
3976
- if (value === true) return !!cap;
3977
- return cap === value;
3978
- });
3979
- }
3980
- /**
3981
- * Get compType strings for all registered blocks with a given capability.
3982
- * Replaces scattered hardcoded arrays like:
3983
- * const TEXT_FIELD_COMPONENTS = ["TextInput", "LexicalTextEditor", ...]
3984
- * becomes:
3985
- * const TEXT_FIELD_COMPONENTS = blockRegistry.getComps('aiTextExtraction')
3986
- */
3987
- getComps(capability, value = true) {
3988
- return this.getBlocksByCapability(capability, value).map((b) => b.compName);
3989
- }
3990
- /** Get all registered blocks in a given category. */
3991
- getBlocksByCategory(category) {
3992
- return Array.from(this.blocks.values()).filter((b) => b.category === category);
3993
- }
3994
- /** Get compType strings for all qual blocks. */
3995
- getQualBlocks() {
3996
- return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "qual").map((b) => b.compName);
3997
- }
3998
- /** Get compType strings for all quant blocks. */
3999
- getQuantBlocks() {
4000
- return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "quant").map((b) => b.compName);
4001
- }
4002
- /** Check if a specific block has a specific capability. */
4003
- hasCapability(compType, capability) {
4004
- const block = this.blocks.get(compType);
4005
- if (!block) return false;
4006
- return !!block.capabilities[capability];
4007
- }
4008
- /** Get all registered block descriptors. */
4009
- getAll() {
4010
- return Array.from(this.blocks.values());
4011
- }
4012
- /**
4013
- * Get compName strings for all registered blocks that have a chunking config.
4014
- * Used by chunking pipelines and prompt-string injection (e.g. searchChunks tool
4015
- * description) to know which fields actually have chunks to search.
4016
- */
4017
- getCompsWithChunking() {
4018
- return Array.from(this.blocks.values()).filter((b) => !!b.chunkingConfig).map((b) => b.compName);
4019
- }
4020
- /**
4021
- * Filter a list of block instances down to those where annotation is enabled.
4022
- * A block is annotation-enabled if its registry capability `annotation` is true.
4023
- * For backwards compat with un-migrated blocks (e.g. deprecated KPRichInput/RichTextEditor),
4024
- * falls back to the legacy per-instance `props.annotation.enable` toggle.
4025
- *
4026
- * Today: every registered annotation-capable block (e.g. LexicalTextEditor) is auto-enabled.
4027
- */
4028
- getAnnotationEnabledBlocks(allBlocks) {
4029
- return allBlocks.filter((block) => {
4030
- const blockDef = this.blocks.get(block.comp);
4031
- if (blockDef) return !!blockDef.capabilities.annotation;
4032
- return block.props?.annotation?.enable === true;
4033
- });
4034
- }
4035
- };
4036
- var blockRegistry = new BlockRegistry();
4037
-
4038
4064
  // src/node.ts
4039
4065
  var import_MongoConnector3 = __toESM(require_MongoConnector());
4040
4066
  var import_ElasticSearchConnector = __toESM(require_ElasticSearchConnector());
@@ -4479,6 +4505,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
4479
4505
  getRoutePathToTagCategoryLanding,
4480
4506
  getTplModelByTenant,
4481
4507
  getVal,
4508
+ isTplAnnotationEnabled,
4482
4509
  mergeAnnoDataIntoAnnotationsTags,
4483
4510
  parseSpecialConfigSyntax,
4484
4511
  processAuthorAndCommonFilters,