@mulingai-npm/redis 2.9.1 → 2.10.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.
@@ -10,6 +10,7 @@ export type MulingstreamChunkData = {
10
10
  shortCodeTargetLanguages: string[];
11
11
  finalTranscription: string;
12
12
  sttStatus: StepStatus;
13
+ createdAt: number;
13
14
  audioChunk: {
14
15
  start: number;
15
16
  end: number;
@@ -123,4 +124,5 @@ export declare class MulingstreamChunkManager {
123
124
  }): Promise<MulingstreamChunkData | null>;
124
125
  increaseTotalCheck(roomId: string, chunkNumber: number, language: string): Promise<MulingstreamChunkData | null>;
125
126
  areTranslationsProcessed(roomId: string, chunkNumber: number): Promise<boolean>;
127
+ getAllReadyTts(roomId: string, language: string, timeoutMs?: number): Promise<MulingstreamChunkData[]>;
126
128
  }
@@ -92,6 +92,7 @@ class MulingstreamChunkManager {
92
92
  shortCodeTargetLanguages,
93
93
  finalTranscription: '',
94
94
  sttStatus: 'INIT',
95
+ createdAt: Date.now(),
95
96
  audioChunk,
96
97
  stt,
97
98
  translation,
@@ -398,5 +399,64 @@ class MulingstreamChunkManager {
398
399
  }
399
400
  return Object.values(chunk.translation).every((t) => t.status !== 'INIT');
400
401
  }
402
+ async getAllReadyTts(roomId, language, timeoutMs = 15000) {
403
+ const chunks = await this.getMulingstreamChunksByRoom(roomId);
404
+ if (!(chunks === null || chunks === void 0 ? void 0 : chunks.length))
405
+ return [];
406
+ chunks.sort((a, b) => a.chunkNumber - b.chunkNumber);
407
+ /* ---- isolate the tail where the language exists ---- */
408
+ let lastLangIdx = -1;
409
+ for (let i = chunks.length - 1; i >= 0; i--) {
410
+ if (chunks[i].tts[language]) {
411
+ lastLangIdx = i;
412
+ break;
413
+ }
414
+ }
415
+ if (lastLangIdx === -1)
416
+ return [];
417
+ let firstLangIdx = lastLangIdx;
418
+ for (let i = lastLangIdx - 1; i >= 0; i--) {
419
+ if (!chunks[i].tts[language])
420
+ break;
421
+ firstLangIdx = i;
422
+ }
423
+ const window = chunks.slice(firstLangIdx, lastLangIdx + 1);
424
+ /* ---- find last USED / DISCARDED in that window ---- */
425
+ let lastDone = -1;
426
+ for (let i = window.length - 1; i >= 0; i--) {
427
+ const st = window[i].tts[language].status;
428
+ if (st === 'USED' || st === 'DISCARDED') {
429
+ lastDone = i;
430
+ break;
431
+ }
432
+ }
433
+ const ready = [];
434
+ let blocked = false;
435
+ const now = Date.now();
436
+ for (let i = lastDone + 1; i < window.length; i++) {
437
+ const entry = window[i].tts[language];
438
+ if (entry.status === 'INIT') {
439
+ if (now - window[i].createdAt > timeoutMs) {
440
+ entry.status = 'DISCARDED';
441
+ }
442
+ else {
443
+ blocked = true; // still waiting ⇒ cannot emit READYs
444
+ }
445
+ continue;
446
+ }
447
+ if (entry.status === 'READY') {
448
+ if (blocked)
449
+ break; // earlier INIT still pending
450
+ ready.push(window[i]);
451
+ continue;
452
+ }
453
+ break; // unexpected USED / DISCARDED
454
+ }
455
+ // persist any DISCARDED changes we made
456
+ if (ready.length === 0 || blocked) {
457
+ await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
458
+ }
459
+ return ready;
460
+ }
401
461
  }
402
462
  exports.MulingstreamChunkManager = MulingstreamChunkManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "2.9.1",
3
+ "version": "2.10.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {