@okf/ootils 1.31.3 → 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({
@@ -3052,201 +3257,6 @@ var compareAndGroupBlocks = (blocksPerTpl) => {
3052
3257
  return Array.from(templateGroupToFilters.values());
3053
3258
  };
3054
3259
 
3055
- // src/blockRegistry/schemaPresets.ts
3056
- var MONGO_SCHEMA_PRESETS = {
3057
- object: { type: Object },
3058
- string: { type: String }
3059
- };
3060
- var ELASTIC_MAPPING_PRESETS = {
3061
- largeText: {
3062
- properties: {
3063
- allText: {
3064
- type: "text",
3065
- analyzer: "LargeTextAnalyzer"
3066
- }
3067
- }
3068
- }
3069
- };
3070
- var CHUNKING_PRESETS = {
3071
- // Lexical-shaped text — uses semantic chunking on allText
3072
- lexicalSemantic: {
3073
- strategy: "semanticChunking",
3074
- windowSize: 3,
3075
- minSimilarityScore: 0.7
3076
- },
3077
- // Plain text input — single chunk per field
3078
- simpleText: {
3079
- strategy: "simpleChunking"
3080
- }
3081
- };
3082
-
3083
- // src/blockRegistry/blocks/LexicalTextEditor.ts
3084
- var LexicalTextEditor = {
3085
- compName: "LexicalTextEditor",
3086
- // Identity
3087
- category: "text",
3088
- qualQuant: "qual",
3089
- // Schema
3090
- mongoSchemaType: MONGO_SCHEMA_PRESETS.object,
3091
- esMapping: ELASTIC_MAPPING_PRESETS.largeText,
3092
- // Capabilities
3093
- capabilities: {
3094
- hasPlainText: true,
3095
- annotation: true,
3096
- aiAnnotation: true,
3097
- aiEnrichment: true,
3098
- searchable: true,
3099
- directDataImport: true,
3100
- csvExport: true,
3101
- translatable: true,
3102
- documentSummarizer: true,
3103
- stripFromMainOnAnnoChunkSync: true,
3104
- excludeFromListingProjection: true
3105
- },
3106
- // Field paths
3107
- fieldPaths: {
3108
- plainTextString: "allText",
3109
- searchField: "allText",
3110
- displayValue: "allText"
3111
- },
3112
- // Validation
3113
- validation: {
3114
- populatedCheckFn: "lexicalTextEditorHasValue",
3115
- formValidationFn: "lexicalTextEditorHasValue"
3116
- },
3117
- // Translation
3118
- translation: {
3119
- handlerType: "LexicalBlockHandler"
3120
- },
3121
- // Table rendering
3122
- tableCell: {
3123
- cellComp: "RichTextAsPlainTextLex",
3124
- sortPathSuffix: "editorState.root.children.0.children.0.text"
3125
- },
3126
- // CSV export
3127
- csvExport: {
3128
- transformFn: "KPRichLexicalEditor"
3129
- },
3130
- // Slack
3131
- slackFormat: {
3132
- handlerFn: "lexicalRichText"
3133
- },
3134
- // Batch import
3135
- batchImport: {
3136
- valueInjectorFn: "toLexicalValue"
3137
- },
3138
- // Content block option — TCI template builder & direct import UI
3139
- contentBlockOption: {
3140
- display: "Rich Text Field",
3141
- icon: "TextAa",
3142
- directImportGroupsIdx: [2, 2]
3143
- },
3144
- // Chunking config — used by okf-sub CreateChunksHandler
3145
- chunkingConfig: CHUNKING_PRESETS.lexicalSemantic
3146
- };
3147
-
3148
- // src/blockRegistry/registry.ts
3149
- var BlockRegistry = class {
3150
- constructor() {
3151
- this.blocks = /* @__PURE__ */ new Map();
3152
- this.register(LexicalTextEditor);
3153
- }
3154
- /** Register a block descriptor. */
3155
- register(descriptor) {
3156
- this.blocks.set(descriptor.compName, descriptor);
3157
- }
3158
- /** Get the full descriptor for a block type. Returns undefined if not registered. */
3159
- getBlock(compType) {
3160
- return this.blocks.get(compType);
3161
- }
3162
- /** Check if a block type is registered in the registry. */
3163
- isRegistered(compType) {
3164
- return this.blocks.has(compType);
3165
- }
3166
- /**
3167
- * Get all registered block descriptors that have a given capability set to a truthy value.
3168
- * Optionally pass a specific value to match (e.g. for enum-style capabilities).
3169
- */
3170
- getBlocksByCapability(capability, value = true) {
3171
- return Array.from(this.blocks.values()).filter((b) => {
3172
- const cap = b.capabilities[capability];
3173
- if (value === true) return !!cap;
3174
- return cap === value;
3175
- });
3176
- }
3177
- /**
3178
- * Get compType strings for all registered blocks with a given capability.
3179
- * Replaces scattered hardcoded arrays like:
3180
- * const TEXT_FIELD_COMPONENTS = ["TextInput", "LexicalTextEditor", ...]
3181
- * becomes:
3182
- * const TEXT_FIELD_COMPONENTS = blockRegistry.getComps('aiTextExtraction')
3183
- */
3184
- getComps(capability, value = true) {
3185
- return this.getBlocksByCapability(capability, value).map((b) => b.compName);
3186
- }
3187
- /** Get all registered blocks in a given category. */
3188
- getBlocksByCategory(category) {
3189
- return Array.from(this.blocks.values()).filter((b) => b.category === category);
3190
- }
3191
- /** Get compType strings for all qual blocks. */
3192
- getQualBlocks() {
3193
- return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "qual").map((b) => b.compName);
3194
- }
3195
- /** Get compType strings for all quant blocks. */
3196
- getQuantBlocks() {
3197
- return Array.from(this.blocks.values()).filter((b) => b.qualQuant === "quant").map((b) => b.compName);
3198
- }
3199
- /** Check if a specific block has a specific capability. */
3200
- hasCapability(compType, capability) {
3201
- const block = this.blocks.get(compType);
3202
- if (!block) return false;
3203
- return !!block.capabilities[capability];
3204
- }
3205
- /** Get all registered block descriptors. */
3206
- getAll() {
3207
- return Array.from(this.blocks.values());
3208
- }
3209
- /**
3210
- * Get compName strings for all registered blocks that have a chunking config.
3211
- * Used by chunking pipelines and prompt-string injection (e.g. searchChunks tool
3212
- * description) to know which fields actually have chunks to search.
3213
- */
3214
- getCompsWithChunking() {
3215
- return Array.from(this.blocks.values()).filter((b) => !!b.chunkingConfig).map((b) => b.compName);
3216
- }
3217
- /**
3218
- * Filter a list of block instances down to those where annotation is enabled.
3219
- * A block is annotation-enabled if its registry capability `annotation` is true.
3220
- * For backwards compat with un-migrated blocks (e.g. deprecated KPRichInput/RichTextEditor),
3221
- * falls back to the legacy per-instance `props.annotation.enable` toggle.
3222
- *
3223
- * Today: every registered annotation-capable block (e.g. LexicalTextEditor) is auto-enabled.
3224
- */
3225
- getAnnotationEnabledBlocks(allBlocks) {
3226
- return allBlocks.filter((block) => {
3227
- const blockDef = this.blocks.get(block.comp);
3228
- if (blockDef) return !!blockDef.capabilities.annotation;
3229
- return block.props?.annotation?.enable === true;
3230
- });
3231
- }
3232
- /**
3233
- * Resolve the tagTypesConfig for a block instance.
3234
- *
3235
- * Resolution order:
3236
- * 1. `hardCodedTagTypesConfigForSM` — the intended self-managed default, which takes
3237
- * priority over per-instance values (justifies not persisting per-block on self-managed).
3238
- * Sourced from `GET_SELF_MANAGED_BASE_CONFIGS().annotation_tagTypesConfig` on BE,
3239
- * or `platformConfigs.SELF_MANAGED_BASE_CONFIGS.annotation_tagTypesConfig` on FE.
3240
- * Pass null/undefined for non-SM tenants.
3241
- * 2. `block.props.annotation.tagTypesConfig` — legacy per-instance persisted value.
3242
- * 3. Empty array.
3243
- */
3244
- getTagTypesConfig(block, hardCodedTagTypesConfigForSM) {
3245
- return hardCodedTagTypesConfigForSM || block.props?.annotation?.tagTypesConfig || [];
3246
- }
3247
- };
3248
- var blockRegistry = new BlockRegistry();
3249
-
3250
3260
  // src/utils/autoGenFilterConfigsFromTpl/utils/extractAndOrganizeBlocks.ts
3251
3261
  var extractAndOrganizeBlocks = (selectedTpls, allTpls, { smTagTypesConfig } = {}) => {
3252
3262
  const extractedBlocks = {};
@@ -4495,6 +4505,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
4495
4505
  getRoutePathToTagCategoryLanding,
4496
4506
  getTplModelByTenant,
4497
4507
  getVal,
4508
+ isTplAnnotationEnabled,
4498
4509
  mergeAnnoDataIntoAnnotationsTags,
4499
4510
  parseSpecialConfigSyntax,
4500
4511
  processAuthorAndCommonFilters,