@okf/ootils 1.41.1 → 1.42.0

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.mjs CHANGED
@@ -198,6 +198,58 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
198
198
  }
199
199
  }
200
200
  },
201
+ AI_AUTO_ANNOTATE_PREP_QUEUE: {
202
+ // PREP queue — the front of the per-doc Flow pipeline. The FE-facing
203
+ // /AIAutoAnnotate handler no longer fetches + summarizes + chunks +
204
+ // enqueues each doc inline (that serial, LLM-heavy loop blocked the HTTP
205
+ // request and risked App Engine clipping large batches mid-loop, silently
206
+ // dropping every doc past the cutoff). Instead the handler computes the
207
+ // batch-level prereqs ONCE (7th criterion + platform-derived categories)
208
+ // and enqueues one PREP job per doc here, then returns fast.
209
+ //
210
+ // Each prep job's worker (okf-sub) calls okf-be /internal/prepDoc, which
211
+ // does the per-doc work: fetch → summarizeDocument (warms the doc-level
212
+ // summary cache) → chunk fields → enqueue that doc's Flow (parent on
213
+ // AI_AUTO_ANNOTATE_QUEUE + one child per chunk on the CHUNK queue). So the
214
+ // Flow parents now get created rolling, as each prep job completes, rather
215
+ // than all up-front in the request. A prep failure isolates to its one doc
216
+ // (that doc is skipped); sibling prep jobs keep going.
217
+ id: "ai-auto-annotate-prep-queue",
218
+ queueConfig: {
219
+ defaultJobOptions: {
220
+ // attempts:1 — a retry would re-summarize (cache-HIT, cheap) but then
221
+ // re-enqueue the doc's Flow, double-annotating the doc. The rest of
222
+ // the per-doc Flow pipeline is attempts:1 for the same fail-loud
223
+ // reason (a retry just re-fires expensive LLM work).
224
+ attempts: 1,
225
+ backoff: {
226
+ type: "exponential",
227
+ delay: 5e3
228
+ },
229
+ removeOnComplete: 30,
230
+ removeOnFail: 100
231
+ },
232
+ streams: {
233
+ events: {
234
+ maxLen: 10
235
+ }
236
+ }
237
+ },
238
+ workerConfig: {
239
+ // Each prep job = one Mongo doc fetch + ONE summarize LLM call + a
240
+ // deterministic chunk + a Flow enqueue. It's lighter than a chunk job
241
+ // (which does ~4 LLM calls), so we can run more in parallel — 10 keeps
242
+ // prep comfortably AHEAD of the downstream chunk queue (concurrency 5),
243
+ // which is the real throughput cap. Going much higher than that buys
244
+ // little: prep would just drain faster into a chunk queue that still
245
+ // processes 5 at a time, while adding concurrent okf-be /internal/prepDoc
246
+ // load + concurrent summarize calls against the shared OpenAI TPM budget.
247
+ concurrency: 10,
248
+ lockDuration: 3e5,
249
+ // 5 min — generous ceiling over the 180s summarizer timeout
250
+ maxStalledCount: 1
251
+ }
252
+ },
201
253
  AI_AUTO_ANNOTATE_QUEUE: {
202
254
  // PARENT queue in the per-doc Flow. One job per doc; child jobs (one
203
255
  // per chunk) live on AI_AUTO_ANNOTATE_CHUNK_QUEUE. BullMQ Flow fires
@@ -2233,6 +2285,91 @@ var require_AnnosElasticSyncProducer = __commonJS({
2233
2285
  }
2234
2286
  });
2235
2287
 
2288
+ // src/bullmq/ContentElasticSyncProducer.js
2289
+ var require_ContentElasticSyncProducer = __commonJS({
2290
+ "src/bullmq/ContentElasticSyncProducer.js"(exports, module) {
2291
+ "use strict";
2292
+ var { BaseProducer: BaseProducer2 } = require_BaseProducer();
2293
+ var { GET_GLOBAL_BULLMQ_CONFIG: GET_GLOBAL_BULLMQ_CONFIG2 } = require_GET_GLOBAL_BULLMQ_CONFIG();
2294
+ var { SecretManagerConnector: SecretManagerConnector2 } = (init_SecretManagerConnector(), __toCommonJS(SecretManagerConnector_exports));
2295
+ var ContentElasticSyncProducer2 = class _ContentElasticSyncProducer extends BaseProducer2 {
2296
+ // Preserve class name through minification for ProducerManager lookup
2297
+ static get name() {
2298
+ return "ContentElasticSyncProducer";
2299
+ }
2300
+ // env is OPTIONAL — cross-env routing: jobs land in the target env's Redis
2301
+ // so that env's deployed workers pick them up (see okf-be
2302
+ // CreateChunksProducer for the rationale and the localhost `_local_<user>`
2303
+ // queue-id quirk).
2304
+ constructor(options = {}) {
2305
+ const env = options.env || process.env.ENV;
2306
+ const c = SecretManagerConnector2.getEnvSpecificConfigs(env);
2307
+ const redisCredentials = options.redisCredentials || {
2308
+ REDIS_HOST: c.REDIS_HOST,
2309
+ REDIS_PORT: c.REDIS_PORT,
2310
+ REDIS_PASSWORD: c.REDIS_PASSWORD
2311
+ };
2312
+ const GLOBAL_BULLMQ_CONFIG = GET_GLOBAL_BULLMQ_CONFIG2({
2313
+ env,
2314
+ redisCredentials
2315
+ });
2316
+ super(GLOBAL_BULLMQ_CONFIG.CONTENT_ELASTIC_SYNC_QUEUE);
2317
+ this.env = env;
2318
+ }
2319
+ async addJobs({ documents, tenant, contentType, operationType, sourceMetadata }) {
2320
+ if (!documents || documents.length === 0 || contentType === "staticPages") {
2321
+ return { jobCount: 0, jobIds: [] };
2322
+ }
2323
+ const batchSize = 200;
2324
+ let jobs = [];
2325
+ for (let i = 0; i < documents.length; i += batchSize) {
2326
+ const batch = documents.slice(i, i + batchSize);
2327
+ jobs.push({
2328
+ name: "processContentElasticSync",
2329
+ data: {
2330
+ docIds: batch.map((doc) => doc._id),
2331
+ tenant,
2332
+ env: this.env,
2333
+ contentType,
2334
+ operationType,
2335
+ sourceMetadata: {
2336
+ ...sourceMetadata,
2337
+ contentId: batch.map((d) => d._id)
2338
+ }
2339
+ }
2340
+ });
2341
+ }
2342
+ const addedJobs = await this.addBulkJobs(jobs);
2343
+ const jobIds = addedJobs.map((job) => job.id);
2344
+ console.log(`\u{1F4E6} Added ${addedJobs.length} jobs for ${contentType} contents sync atomically`);
2345
+ return {
2346
+ jobCount: addedJobs.length,
2347
+ jobIds
2348
+ };
2349
+ }
2350
+ static async addJobsAndClose(params) {
2351
+ const producer = new _ContentElasticSyncProducer({ env: params?.env });
2352
+ try {
2353
+ return await producer.addJobs(params);
2354
+ } finally {
2355
+ await producer.stop();
2356
+ }
2357
+ }
2358
+ static async removeJobsAndClose(jobIds, env) {
2359
+ const producer = new _ContentElasticSyncProducer({ env });
2360
+ try {
2361
+ return await producer.removeJobs(jobIds);
2362
+ } finally {
2363
+ await producer.stop();
2364
+ }
2365
+ }
2366
+ };
2367
+ module.exports = {
2368
+ ContentElasticSyncProducer: ContentElasticSyncProducer2
2369
+ };
2370
+ }
2371
+ });
2372
+
2236
2373
  // src/utils/getterSetterDeleter/utils/set_deleteVal.ts
2237
2374
  var set_deleteVal = (action, data, valuePath, value) => {
2238
2375
  if (valuePath === void 0) return;
@@ -4891,12 +5028,14 @@ var import_BaseFlowProducer = __toESM(require_BaseFlowProducer());
4891
5028
  var import_BaseWorker = __toESM(require_BaseWorker());
4892
5029
  var import_ChunksElasticSyncProducer = __toESM(require_ChunksElasticSyncProducer());
4893
5030
  var import_AnnosElasticSyncProducer = __toESM(require_AnnosElasticSyncProducer());
5031
+ var import_ContentElasticSyncProducer = __toESM(require_ContentElasticSyncProducer());
4894
5032
  var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
4895
5033
  var export_AnnosElasticSyncProducer = import_AnnosElasticSyncProducer.AnnosElasticSyncProducer;
4896
5034
  var export_BaseFlowProducer = import_BaseFlowProducer.BaseFlowProducer;
4897
5035
  var export_BaseProducer = import_BaseProducer.BaseProducer;
4898
5036
  var export_BaseWorker = import_BaseWorker.BaseWorker;
4899
5037
  var export_ChunksElasticSyncProducer = import_ChunksElasticSyncProducer.ChunksElasticSyncProducer;
5038
+ var export_ContentElasticSyncProducer = import_ContentElasticSyncProducer.ContentElasticSyncProducer;
4900
5039
  var export_ElasticSearchConnector = import_ElasticSearchConnector.ElasticSearchConnector;
4901
5040
  var export_GET_GLOBAL_BULLMQ_CONFIG = import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG;
4902
5041
  var export_MongoConnector = import_MongoConnector3.MongoConnector;
@@ -4920,6 +5059,7 @@ export {
4920
5059
  BlockRegistry,
4921
5060
  CHUNKING_PRESETS,
4922
5061
  export_ChunksElasticSyncProducer as ChunksElasticSyncProducer,
5062
+ export_ContentElasticSyncProducer as ContentElasticSyncProducer,
4923
5063
  ELASTIC_MAPPING_PRESETS,
4924
5064
  export_ElasticSearchConnector as ElasticSearchConnector,
4925
5065
  FILTER_IDS,
@@ -487,7 +487,7 @@ declare namespace BASE_BULLMQ_CONFIG {
487
487
  }
488
488
  export { workerConfig_4 as workerConfig };
489
489
  }
490
- namespace AI_AUTO_ANNOTATE_QUEUE {
490
+ namespace AI_AUTO_ANNOTATE_PREP_QUEUE {
491
491
  let id_5: string;
492
492
  export { id_5 as id };
493
493
  export namespace queueConfig_5 {
@@ -527,7 +527,7 @@ declare namespace BASE_BULLMQ_CONFIG {
527
527
  }
528
528
  export { workerConfig_5 as workerConfig };
529
529
  }
530
- namespace AI_AUTO_ANNOTATE_CHUNK_QUEUE {
530
+ namespace AI_AUTO_ANNOTATE_QUEUE {
531
531
  let id_6: string;
532
532
  export { id_6 as id };
533
533
  export namespace queueConfig_6 {
@@ -567,7 +567,7 @@ declare namespace BASE_BULLMQ_CONFIG {
567
567
  }
568
568
  export { workerConfig_6 as workerConfig };
569
569
  }
570
- namespace ANNOS_ELASTIC_SYNC_QUEUE {
570
+ namespace AI_AUTO_ANNOTATE_CHUNK_QUEUE {
571
571
  let id_7: string;
572
572
  export { id_7 as id };
573
573
  export namespace queueConfig_7 {
@@ -607,7 +607,7 @@ declare namespace BASE_BULLMQ_CONFIG {
607
607
  }
608
608
  export { workerConfig_7 as workerConfig };
609
609
  }
610
- namespace CHUNKS_ELASTIC_SYNC_QUEUE {
610
+ namespace ANNOS_ELASTIC_SYNC_QUEUE {
611
611
  let id_8: string;
612
612
  export { id_8 as id };
613
613
  export namespace queueConfig_8 {
@@ -647,7 +647,7 @@ declare namespace BASE_BULLMQ_CONFIG {
647
647
  }
648
648
  export { workerConfig_8 as workerConfig };
649
649
  }
650
- namespace USERS_ELASTIC_SYNC_QUEUE {
650
+ namespace CHUNKS_ELASTIC_SYNC_QUEUE {
651
651
  let id_9: string;
652
652
  export { id_9 as id };
653
653
  export namespace queueConfig_9 {
@@ -687,7 +687,7 @@ declare namespace BASE_BULLMQ_CONFIG {
687
687
  }
688
688
  export { workerConfig_9 as workerConfig };
689
689
  }
690
- namespace CONTENT_ELASTIC_SYNC_QUEUE {
690
+ namespace USERS_ELASTIC_SYNC_QUEUE {
691
691
  let id_10: string;
692
692
  export { id_10 as id };
693
693
  export namespace queueConfig_10 {
@@ -727,7 +727,7 @@ declare namespace BASE_BULLMQ_CONFIG {
727
727
  }
728
728
  export { workerConfig_10 as workerConfig };
729
729
  }
730
- namespace SARVAM_TRANSCRIPTION_QUEUE {
730
+ namespace CONTENT_ELASTIC_SYNC_QUEUE {
731
731
  let id_11: string;
732
732
  export { id_11 as id };
733
733
  export namespace queueConfig_11 {
@@ -767,7 +767,7 @@ declare namespace BASE_BULLMQ_CONFIG {
767
767
  }
768
768
  export { workerConfig_11 as workerConfig };
769
769
  }
770
- namespace INTERCOM_CONVERSATIONS_QUEUE {
770
+ namespace SARVAM_TRANSCRIPTION_QUEUE {
771
771
  let id_12: string;
772
772
  export { id_12 as id };
773
773
  export namespace queueConfig_12 {
@@ -807,7 +807,7 @@ declare namespace BASE_BULLMQ_CONFIG {
807
807
  }
808
808
  export { workerConfig_12 as workerConfig };
809
809
  }
810
- namespace TAG_SYNC_PLAN_QUEUE {
810
+ namespace INTERCOM_CONVERSATIONS_QUEUE {
811
811
  let id_13: string;
812
812
  export { id_13 as id };
813
813
  export namespace queueConfig_13 {
@@ -847,7 +847,7 @@ declare namespace BASE_BULLMQ_CONFIG {
847
847
  }
848
848
  export { workerConfig_13 as workerConfig };
849
849
  }
850
- namespace TAG_SYNC_BATCH_QUEUE {
850
+ namespace TAG_SYNC_PLAN_QUEUE {
851
851
  let id_14: string;
852
852
  export { id_14 as id };
853
853
  export namespace queueConfig_14 {
@@ -887,11 +887,13 @@ declare namespace BASE_BULLMQ_CONFIG {
887
887
  }
888
888
  export { workerConfig_14 as workerConfig };
889
889
  }
890
- namespace SCHEDULED_EXTERNAL_SYNC_QUEUE {
890
+ namespace TAG_SYNC_BATCH_QUEUE {
891
891
  let id_15: string;
892
892
  export { id_15 as id };
893
893
  export namespace queueConfig_15 {
894
894
  export namespace defaultJobOptions_15 {
895
+ let attempts_15: number;
896
+ export { attempts_15 as attempts };
895
897
  export namespace backoff_15 {
896
898
  let type_15: string;
897
899
  export { type_15 as type };
@@ -899,8 +901,6 @@ declare namespace BASE_BULLMQ_CONFIG {
899
901
  export { delay_15 as delay };
900
902
  }
901
903
  export { backoff_15 as backoff };
902
- let attempts_15: number;
903
- export { attempts_15 as attempts };
904
904
  let removeOnComplete_15: number;
905
905
  export { removeOnComplete_15 as removeOnComplete };
906
906
  let removeOnFail_15: number;
@@ -927,13 +927,11 @@ declare namespace BASE_BULLMQ_CONFIG {
927
927
  }
928
928
  export { workerConfig_15 as workerConfig };
929
929
  }
930
- namespace REINDEX_QUEUE {
930
+ namespace SCHEDULED_EXTERNAL_SYNC_QUEUE {
931
931
  let id_16: string;
932
932
  export { id_16 as id };
933
933
  export namespace queueConfig_16 {
934
934
  export namespace defaultJobOptions_16 {
935
- let attempts_16: number;
936
- export { attempts_16 as attempts };
937
935
  export namespace backoff_16 {
938
936
  let type_16: string;
939
937
  export { type_16 as type };
@@ -941,8 +939,8 @@ declare namespace BASE_BULLMQ_CONFIG {
941
939
  export { delay_16 as delay };
942
940
  }
943
941
  export { backoff_16 as backoff };
944
- let delay_17: number;
945
- export { delay_17 as delay };
942
+ let attempts_16: number;
943
+ export { attempts_16 as attempts };
946
944
  let removeOnComplete_16: number;
947
945
  export { removeOnComplete_16 as removeOnComplete };
948
946
  let removeOnFail_16: number;
@@ -969,6 +967,48 @@ declare namespace BASE_BULLMQ_CONFIG {
969
967
  }
970
968
  export { workerConfig_16 as workerConfig };
971
969
  }
970
+ namespace REINDEX_QUEUE {
971
+ let id_17: string;
972
+ export { id_17 as id };
973
+ export namespace queueConfig_17 {
974
+ export namespace defaultJobOptions_17 {
975
+ let attempts_17: number;
976
+ export { attempts_17 as attempts };
977
+ export namespace backoff_17 {
978
+ let type_17: string;
979
+ export { type_17 as type };
980
+ let delay_17: number;
981
+ export { delay_17 as delay };
982
+ }
983
+ export { backoff_17 as backoff };
984
+ let delay_18: number;
985
+ export { delay_18 as delay };
986
+ let removeOnComplete_17: number;
987
+ export { removeOnComplete_17 as removeOnComplete };
988
+ let removeOnFail_17: number;
989
+ export { removeOnFail_17 as removeOnFail };
990
+ }
991
+ export { defaultJobOptions_17 as defaultJobOptions };
992
+ export namespace streams_17 {
993
+ export namespace events_17 {
994
+ let maxLen_17: number;
995
+ export { maxLen_17 as maxLen };
996
+ }
997
+ export { events_17 as events };
998
+ }
999
+ export { streams_17 as streams };
1000
+ }
1001
+ export { queueConfig_17 as queueConfig };
1002
+ export namespace workerConfig_17 {
1003
+ let concurrency_17: number;
1004
+ export { concurrency_17 as concurrency };
1005
+ let lockDuration_17: number;
1006
+ export { lockDuration_17 as lockDuration };
1007
+ let maxStalledCount_17: number;
1008
+ export { maxStalledCount_17 as maxStalledCount };
1009
+ }
1010
+ export { workerConfig_17 as workerConfig };
1011
+ }
972
1012
  }
973
1013
 
974
1014
  interface PlatformContextContentItem {
@@ -487,7 +487,7 @@ declare namespace BASE_BULLMQ_CONFIG {
487
487
  }
488
488
  export { workerConfig_4 as workerConfig };
489
489
  }
490
- namespace AI_AUTO_ANNOTATE_QUEUE {
490
+ namespace AI_AUTO_ANNOTATE_PREP_QUEUE {
491
491
  let id_5: string;
492
492
  export { id_5 as id };
493
493
  export namespace queueConfig_5 {
@@ -527,7 +527,7 @@ declare namespace BASE_BULLMQ_CONFIG {
527
527
  }
528
528
  export { workerConfig_5 as workerConfig };
529
529
  }
530
- namespace AI_AUTO_ANNOTATE_CHUNK_QUEUE {
530
+ namespace AI_AUTO_ANNOTATE_QUEUE {
531
531
  let id_6: string;
532
532
  export { id_6 as id };
533
533
  export namespace queueConfig_6 {
@@ -567,7 +567,7 @@ declare namespace BASE_BULLMQ_CONFIG {
567
567
  }
568
568
  export { workerConfig_6 as workerConfig };
569
569
  }
570
- namespace ANNOS_ELASTIC_SYNC_QUEUE {
570
+ namespace AI_AUTO_ANNOTATE_CHUNK_QUEUE {
571
571
  let id_7: string;
572
572
  export { id_7 as id };
573
573
  export namespace queueConfig_7 {
@@ -607,7 +607,7 @@ declare namespace BASE_BULLMQ_CONFIG {
607
607
  }
608
608
  export { workerConfig_7 as workerConfig };
609
609
  }
610
- namespace CHUNKS_ELASTIC_SYNC_QUEUE {
610
+ namespace ANNOS_ELASTIC_SYNC_QUEUE {
611
611
  let id_8: string;
612
612
  export { id_8 as id };
613
613
  export namespace queueConfig_8 {
@@ -647,7 +647,7 @@ declare namespace BASE_BULLMQ_CONFIG {
647
647
  }
648
648
  export { workerConfig_8 as workerConfig };
649
649
  }
650
- namespace USERS_ELASTIC_SYNC_QUEUE {
650
+ namespace CHUNKS_ELASTIC_SYNC_QUEUE {
651
651
  let id_9: string;
652
652
  export { id_9 as id };
653
653
  export namespace queueConfig_9 {
@@ -687,7 +687,7 @@ declare namespace BASE_BULLMQ_CONFIG {
687
687
  }
688
688
  export { workerConfig_9 as workerConfig };
689
689
  }
690
- namespace CONTENT_ELASTIC_SYNC_QUEUE {
690
+ namespace USERS_ELASTIC_SYNC_QUEUE {
691
691
  let id_10: string;
692
692
  export { id_10 as id };
693
693
  export namespace queueConfig_10 {
@@ -727,7 +727,7 @@ declare namespace BASE_BULLMQ_CONFIG {
727
727
  }
728
728
  export { workerConfig_10 as workerConfig };
729
729
  }
730
- namespace SARVAM_TRANSCRIPTION_QUEUE {
730
+ namespace CONTENT_ELASTIC_SYNC_QUEUE {
731
731
  let id_11: string;
732
732
  export { id_11 as id };
733
733
  export namespace queueConfig_11 {
@@ -767,7 +767,7 @@ declare namespace BASE_BULLMQ_CONFIG {
767
767
  }
768
768
  export { workerConfig_11 as workerConfig };
769
769
  }
770
- namespace INTERCOM_CONVERSATIONS_QUEUE {
770
+ namespace SARVAM_TRANSCRIPTION_QUEUE {
771
771
  let id_12: string;
772
772
  export { id_12 as id };
773
773
  export namespace queueConfig_12 {
@@ -807,7 +807,7 @@ declare namespace BASE_BULLMQ_CONFIG {
807
807
  }
808
808
  export { workerConfig_12 as workerConfig };
809
809
  }
810
- namespace TAG_SYNC_PLAN_QUEUE {
810
+ namespace INTERCOM_CONVERSATIONS_QUEUE {
811
811
  let id_13: string;
812
812
  export { id_13 as id };
813
813
  export namespace queueConfig_13 {
@@ -847,7 +847,7 @@ declare namespace BASE_BULLMQ_CONFIG {
847
847
  }
848
848
  export { workerConfig_13 as workerConfig };
849
849
  }
850
- namespace TAG_SYNC_BATCH_QUEUE {
850
+ namespace TAG_SYNC_PLAN_QUEUE {
851
851
  let id_14: string;
852
852
  export { id_14 as id };
853
853
  export namespace queueConfig_14 {
@@ -887,11 +887,13 @@ declare namespace BASE_BULLMQ_CONFIG {
887
887
  }
888
888
  export { workerConfig_14 as workerConfig };
889
889
  }
890
- namespace SCHEDULED_EXTERNAL_SYNC_QUEUE {
890
+ namespace TAG_SYNC_BATCH_QUEUE {
891
891
  let id_15: string;
892
892
  export { id_15 as id };
893
893
  export namespace queueConfig_15 {
894
894
  export namespace defaultJobOptions_15 {
895
+ let attempts_15: number;
896
+ export { attempts_15 as attempts };
895
897
  export namespace backoff_15 {
896
898
  let type_15: string;
897
899
  export { type_15 as type };
@@ -899,8 +901,6 @@ declare namespace BASE_BULLMQ_CONFIG {
899
901
  export { delay_15 as delay };
900
902
  }
901
903
  export { backoff_15 as backoff };
902
- let attempts_15: number;
903
- export { attempts_15 as attempts };
904
904
  let removeOnComplete_15: number;
905
905
  export { removeOnComplete_15 as removeOnComplete };
906
906
  let removeOnFail_15: number;
@@ -927,13 +927,11 @@ declare namespace BASE_BULLMQ_CONFIG {
927
927
  }
928
928
  export { workerConfig_15 as workerConfig };
929
929
  }
930
- namespace REINDEX_QUEUE {
930
+ namespace SCHEDULED_EXTERNAL_SYNC_QUEUE {
931
931
  let id_16: string;
932
932
  export { id_16 as id };
933
933
  export namespace queueConfig_16 {
934
934
  export namespace defaultJobOptions_16 {
935
- let attempts_16: number;
936
- export { attempts_16 as attempts };
937
935
  export namespace backoff_16 {
938
936
  let type_16: string;
939
937
  export { type_16 as type };
@@ -941,8 +939,8 @@ declare namespace BASE_BULLMQ_CONFIG {
941
939
  export { delay_16 as delay };
942
940
  }
943
941
  export { backoff_16 as backoff };
944
- let delay_17: number;
945
- export { delay_17 as delay };
942
+ let attempts_16: number;
943
+ export { attempts_16 as attempts };
946
944
  let removeOnComplete_16: number;
947
945
  export { removeOnComplete_16 as removeOnComplete };
948
946
  let removeOnFail_16: number;
@@ -969,6 +967,48 @@ declare namespace BASE_BULLMQ_CONFIG {
969
967
  }
970
968
  export { workerConfig_16 as workerConfig };
971
969
  }
970
+ namespace REINDEX_QUEUE {
971
+ let id_17: string;
972
+ export { id_17 as id };
973
+ export namespace queueConfig_17 {
974
+ export namespace defaultJobOptions_17 {
975
+ let attempts_17: number;
976
+ export { attempts_17 as attempts };
977
+ export namespace backoff_17 {
978
+ let type_17: string;
979
+ export { type_17 as type };
980
+ let delay_17: number;
981
+ export { delay_17 as delay };
982
+ }
983
+ export { backoff_17 as backoff };
984
+ let delay_18: number;
985
+ export { delay_18 as delay };
986
+ let removeOnComplete_17: number;
987
+ export { removeOnComplete_17 as removeOnComplete };
988
+ let removeOnFail_17: number;
989
+ export { removeOnFail_17 as removeOnFail };
990
+ }
991
+ export { defaultJobOptions_17 as defaultJobOptions };
992
+ export namespace streams_17 {
993
+ export namespace events_17 {
994
+ let maxLen_17: number;
995
+ export { maxLen_17 as maxLen };
996
+ }
997
+ export { events_17 as events };
998
+ }
999
+ export { streams_17 as streams };
1000
+ }
1001
+ export { queueConfig_17 as queueConfig };
1002
+ export namespace workerConfig_17 {
1003
+ let concurrency_17: number;
1004
+ export { concurrency_17 as concurrency };
1005
+ let lockDuration_17: number;
1006
+ export { lockDuration_17 as lockDuration };
1007
+ let maxStalledCount_17: number;
1008
+ export { maxStalledCount_17 as maxStalledCount };
1009
+ }
1010
+ export { workerConfig_17 as workerConfig };
1011
+ }
972
1012
  }
973
1013
 
974
1014
  interface PlatformContextContentItem {
package/dist/universal.js CHANGED
@@ -966,6 +966,58 @@ var BASE_BULLMQ_CONFIG = {
966
966
  }
967
967
  }
968
968
  },
969
+ AI_AUTO_ANNOTATE_PREP_QUEUE: {
970
+ // PREP queue — the front of the per-doc Flow pipeline. The FE-facing
971
+ // /AIAutoAnnotate handler no longer fetches + summarizes + chunks +
972
+ // enqueues each doc inline (that serial, LLM-heavy loop blocked the HTTP
973
+ // request and risked App Engine clipping large batches mid-loop, silently
974
+ // dropping every doc past the cutoff). Instead the handler computes the
975
+ // batch-level prereqs ONCE (7th criterion + platform-derived categories)
976
+ // and enqueues one PREP job per doc here, then returns fast.
977
+ //
978
+ // Each prep job's worker (okf-sub) calls okf-be /internal/prepDoc, which
979
+ // does the per-doc work: fetch → summarizeDocument (warms the doc-level
980
+ // summary cache) → chunk fields → enqueue that doc's Flow (parent on
981
+ // AI_AUTO_ANNOTATE_QUEUE + one child per chunk on the CHUNK queue). So the
982
+ // Flow parents now get created rolling, as each prep job completes, rather
983
+ // than all up-front in the request. A prep failure isolates to its one doc
984
+ // (that doc is skipped); sibling prep jobs keep going.
985
+ id: "ai-auto-annotate-prep-queue",
986
+ queueConfig: {
987
+ defaultJobOptions: {
988
+ // attempts:1 — a retry would re-summarize (cache-HIT, cheap) but then
989
+ // re-enqueue the doc's Flow, double-annotating the doc. The rest of
990
+ // the per-doc Flow pipeline is attempts:1 for the same fail-loud
991
+ // reason (a retry just re-fires expensive LLM work).
992
+ attempts: 1,
993
+ backoff: {
994
+ type: "exponential",
995
+ delay: 5e3
996
+ },
997
+ removeOnComplete: 30,
998
+ removeOnFail: 100
999
+ },
1000
+ streams: {
1001
+ events: {
1002
+ maxLen: 10
1003
+ }
1004
+ }
1005
+ },
1006
+ workerConfig: {
1007
+ // Each prep job = one Mongo doc fetch + ONE summarize LLM call + a
1008
+ // deterministic chunk + a Flow enqueue. It's lighter than a chunk job
1009
+ // (which does ~4 LLM calls), so we can run more in parallel — 10 keeps
1010
+ // prep comfortably AHEAD of the downstream chunk queue (concurrency 5),
1011
+ // which is the real throughput cap. Going much higher than that buys
1012
+ // little: prep would just drain faster into a chunk queue that still
1013
+ // processes 5 at a time, while adding concurrent okf-be /internal/prepDoc
1014
+ // load + concurrent summarize calls against the shared OpenAI TPM budget.
1015
+ concurrency: 10,
1016
+ lockDuration: 3e5,
1017
+ // 5 min — generous ceiling over the 180s summarizer timeout
1018
+ maxStalledCount: 1
1019
+ }
1020
+ },
969
1021
  AI_AUTO_ANNOTATE_QUEUE: {
970
1022
  // PARENT queue in the per-doc Flow. One job per doc; child jobs (one
971
1023
  // per chunk) live on AI_AUTO_ANNOTATE_CHUNK_QUEUE. BullMQ Flow fires
@@ -896,6 +896,58 @@ var BASE_BULLMQ_CONFIG = {
896
896
  }
897
897
  }
898
898
  },
899
+ AI_AUTO_ANNOTATE_PREP_QUEUE: {
900
+ // PREP queue — the front of the per-doc Flow pipeline. The FE-facing
901
+ // /AIAutoAnnotate handler no longer fetches + summarizes + chunks +
902
+ // enqueues each doc inline (that serial, LLM-heavy loop blocked the HTTP
903
+ // request and risked App Engine clipping large batches mid-loop, silently
904
+ // dropping every doc past the cutoff). Instead the handler computes the
905
+ // batch-level prereqs ONCE (7th criterion + platform-derived categories)
906
+ // and enqueues one PREP job per doc here, then returns fast.
907
+ //
908
+ // Each prep job's worker (okf-sub) calls okf-be /internal/prepDoc, which
909
+ // does the per-doc work: fetch → summarizeDocument (warms the doc-level
910
+ // summary cache) → chunk fields → enqueue that doc's Flow (parent on
911
+ // AI_AUTO_ANNOTATE_QUEUE + one child per chunk on the CHUNK queue). So the
912
+ // Flow parents now get created rolling, as each prep job completes, rather
913
+ // than all up-front in the request. A prep failure isolates to its one doc
914
+ // (that doc is skipped); sibling prep jobs keep going.
915
+ id: "ai-auto-annotate-prep-queue",
916
+ queueConfig: {
917
+ defaultJobOptions: {
918
+ // attempts:1 — a retry would re-summarize (cache-HIT, cheap) but then
919
+ // re-enqueue the doc's Flow, double-annotating the doc. The rest of
920
+ // the per-doc Flow pipeline is attempts:1 for the same fail-loud
921
+ // reason (a retry just re-fires expensive LLM work).
922
+ attempts: 1,
923
+ backoff: {
924
+ type: "exponential",
925
+ delay: 5e3
926
+ },
927
+ removeOnComplete: 30,
928
+ removeOnFail: 100
929
+ },
930
+ streams: {
931
+ events: {
932
+ maxLen: 10
933
+ }
934
+ }
935
+ },
936
+ workerConfig: {
937
+ // Each prep job = one Mongo doc fetch + ONE summarize LLM call + a
938
+ // deterministic chunk + a Flow enqueue. It's lighter than a chunk job
939
+ // (which does ~4 LLM calls), so we can run more in parallel — 10 keeps
940
+ // prep comfortably AHEAD of the downstream chunk queue (concurrency 5),
941
+ // which is the real throughput cap. Going much higher than that buys
942
+ // little: prep would just drain faster into a chunk queue that still
943
+ // processes 5 at a time, while adding concurrent okf-be /internal/prepDoc
944
+ // load + concurrent summarize calls against the shared OpenAI TPM budget.
945
+ concurrency: 10,
946
+ lockDuration: 3e5,
947
+ // 5 min — generous ceiling over the 180s summarizer timeout
948
+ maxStalledCount: 1
949
+ }
950
+ },
899
951
  AI_AUTO_ANNOTATE_QUEUE: {
900
952
  // PARENT queue in the per-doc Flow. One job per doc; child jobs (one
901
953
  // per chunk) live on AI_AUTO_ANNOTATE_CHUNK_QUEUE. BullMQ Flow fires
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.41.1",
6
+ "version": "1.42.0",
7
7
  "description": "Utility functions for both browser and Node.js",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.mjs",